Skip to content

Commit

Permalink
Support for acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanizag committed Sep 9, 2021
1 parent 872c9f9 commit da5de51
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 33 deletions.
3 changes: 3 additions & 0 deletions bbz.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
*/

func RunMOS(env *environment) {

env.initUpperLanguage()

// Execute
for !env.stop {
env.cpu.ExecuteInstruction()
Expand Down
44 changes: 44 additions & 0 deletions consoleMock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

type consoleMock struct {
linesIn []string
lineIn int
output string
env *environment
}

func newConsoleMock(env *environment, linesIn []string) *consoleMock {
var c consoleMock
c.linesIn = linesIn
c.output = ""
c.env = env
return &c
}

func (c *consoleMock) readline() (string, bool) {
if c.lineIn >= len(c.linesIn) {
c.env.stop = true
return "", true
}
line := c.linesIn[c.lineIn]
c.env.writeSpool(line)
c.env.writeSpool("\n")
c.lineIn++
return line, false
}

func (c *consoleMock) readChar() (uint8, bool) {
s, stop := c.readline()
if s == "" {
return ' ', stop
} else {
return s[0], stop
}
}

func (c *consoleMock) write(s string) {
c.output += s
c.env.writeSpool(s)
}

func (c *consoleMock) close() {}
21 changes: 13 additions & 8 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ type environment struct {
panicOnErr bool
}

func newEnvironment(cpuLog bool, apiLog bool, apiLogIO bool, memLog bool, panicOnErr bool, rawline bool) *environment {
func newEnvironment(roms []*string, cpuLog bool, apiLog bool, apiLogIO bool, memLog bool, panicOnErr bool) *environment {
var env environment
if rawline {
env.con = newConsoleSimple(&env)
} else {
env.con = newConsoleLiner(&env)
}
env.referenceTime = time.Now()
env.timer = 0
env.lastTimerUpdate = time.Now()
Expand All @@ -49,10 +44,20 @@ func newEnvironment(cpuLog bool, apiLog bool, apiLogIO bool, memLog bool, panicO
env.cpu = core6502.NewNMOS6502(env.mem)
//env.cpu = core6502.NewCMOS65c02(env.mem)
env.cpu.SetTrace(cpuLog)
env.vdu = newVdu(env.con)
env.vdu = newVdu(&env)
env.apiLog = apiLog
env.apiLogIO = apiLogIO
env.panicOnErr = panicOnErr

env.mem.loadFirmware()

for i, rom := range roms {
if *rom != "" {
env.mem.loadRom(*rom, uint8(0xf-i))
}
}
env.mem.completeWithRam()

return &env
}

Expand Down Expand Up @@ -98,7 +103,7 @@ func (env *environment) initLanguage(slot uint8) {
The MOS also automatically prints the ROM's title string (&8009) so that the user is acknowledged.
*/
language := env.mem.peekString(romTitleString, 0)
fmt.Printf("%s\n", language)
env.con.write(fmt.Sprintf("%s\n", language))

_, x, y, p := env.cpu.GetAXYP()
env.cpu.SetAXYP(1, x, y, p)
Expand Down
18 changes: 6 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,20 @@ func main() {

}

env := newEnvironment(*traceCPU,
env := newEnvironment(roms, *traceCPU,
(*traceMOS) || (*traceMOSFull),
*traceMOSFull,
*traceMemory,
*panicOnErr,
*rawline)
*panicOnErr)
defer env.close()
handleControlC(env)

env.mem.loadFirmware()

for i, rom := range roms {
if *rom != "" {
env.mem.loadRom(*rom, uint8(0xf-i))
}
if *rawline {
env.con = newConsoleSimple(env)
} else {
env.con = newConsoleLiner(env)
}

env.initUpperLanguage()
env.mem.completeWithRam()

RunMOS(env)
}

Expand Down
18 changes: 10 additions & 8 deletions osCLI.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func execOSCLI(env *environment) {

case "CAT":
// TODO
fmt.Println("\n<<directory placeholder>>")
env.con.write("\n<<placeholder>>\n")

case "CODE":
execOSCLIfx(env, 0x88, line, pos)
Expand Down Expand Up @@ -175,7 +175,7 @@ func execOSCLI(env *environment) {
//case "EXEC":

case "HELP":
fmt.Println("\nBBZ 0.0")
env.con.write("\nBBZ 0.0\n")

// Send to the other ROMS if available.
env.mem.pokeWord(zpStr, xy)
Expand All @@ -195,7 +195,8 @@ func execOSCLI(env *environment) {
if err != nil {
env.raiseError(errorTodo, err.Error())
}
fmt.Println(string(stdout))
env.con.write(string(stdout))
env.con.write("\n")

case "INFO":
filename := ""
Expand All @@ -207,9 +208,10 @@ func execOSCLI(env *environment) {

attr := getFileAttributes(env, filename)
if attr.hasMetadata {
fmt.Printf("%s\t %06X %06X %06X\n", filename, attr.loadAddress, attr.executionAddress, attr.fileSize)
env.con.write(fmt.Sprintf("%s\t %06X %06X %06X\n", filename,
attr.loadAddress, attr.executionAddress, attr.fileSize))
} else {
fmt.Printf("%s\t ?????? ?????? %06X\n", filename, attr.fileSize)
env.con.write(fmt.Sprintf("%s\t ?????? ?????? %06X\n", filename, attr.fileSize))
}

// case "KEY":
Expand Down Expand Up @@ -267,7 +269,7 @@ func execOSCLI(env *environment) {
env.mem.Poke(sheilaRomLatch, uint8(i))
name := env.mem.peekString(romTitleString, 0)
if name == "" {
fmt.Printf("ROM %X ?\n", i)
env.con.write(fmt.Sprintf("ROM %X ?\n", i))
} else {
version := env.mem.Peek(romVersion)
romType := env.mem.Peek(romTypeByte)
Expand All @@ -280,10 +282,10 @@ func execOSCLI(env *environment) {
}
attributes += ")"

fmt.Printf("ROM %X %s %02v %s\n", i, name, version, attributes)
env.con.write(fmt.Sprintf("ROM %X %s %02v %s\n", i, name, version, attributes))
}
} else {
fmt.Printf("RAM %X 16K\n", i)
env.con.write(fmt.Sprintf("RAM %X 16K\n", i))
}
}
env.mem.Poke(sheilaRomLatch, selectedROM)
Expand Down
25 changes: 25 additions & 0 deletions osCLI_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"strings"
"testing"
)

func Test_OSCLI_HELP(t *testing.T) {

def := "BASIC.ROM"
roms := []*string{&def}

env := newEnvironment(roms, false, false, false, false, false)
con := newConsoleMock(env, []string{
"*HELP",
})
env.con = con

RunMOS(env)

if !strings.Contains(con.output, "BBZ") {
t.Log(con.output)
t.Error("*HELP is not returning BBZ")
}
}
10 changes: 5 additions & 5 deletions vdu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import "fmt"

type vdu struct {
con console
env *environment
queue []uint8
mode uint8

Expand All @@ -25,7 +25,7 @@ type vdu struct {

var argsNeeded [256]int

func newVdu(con console) *vdu {
func newVdu(env *environment) *vdu {
// Init args needed array, 0 for all except:
argsNeeded[1] = 1
argsNeeded[17] = 1
Expand All @@ -41,7 +41,7 @@ func newVdu(con console) *vdu {
argsNeeded[31] = 2

var v vdu
v.con = con
v.env = env
// Mode 7 on startup
v.mode = 7
v.m7fgColour = 7 // white
Expand Down Expand Up @@ -479,7 +479,7 @@ func (v *vdu) writeInternal(cmd uint8, q []uint8) {
}

if out != "" && !v.ignore {
v.con.write(out)
v.env.con.write(out)
}
}

Expand All @@ -504,7 +504,7 @@ func (v *vdu) mode7ResetCode() string {
}

func (v *vdu) mode7Reset() {
fmt.Print(v.mode7ResetCode())
v.env.con.write(v.mode7ResetCode())
}

func adjustAscii(ch uint8) string {
Expand Down

0 comments on commit da5de51

Please sign in to comment.