apple2-go/cpu/cpu_test.go

83 lines
2.0 KiB
Go
Raw Normal View History

package cpu_test
2018-04-29 19:41:11 +00:00
// Test the CPU using the functional and interrupt tests defined in the *.a65
// files and compiled to bin.gz files. The cpu package is aware of tests being run and
// will exit or bail on success and failure certain conditions.
2018-04-29 19:41:11 +00:00
import (
"flag"
2018-05-04 14:47:22 +00:00
"fmt"
"testing"
2018-05-27 10:05:00 +00:00
2019-11-02 13:33:05 +00:00
"github.com/freewilll/apple2-go/cpu"
"github.com/freewilll/apple2-go/mmu"
"github.com/freewilll/apple2-go/system"
"github.com/freewilll/apple2-go/utils"
2018-04-29 19:41:11 +00:00
)
func TestCPU(t *testing.T) {
2018-04-29 19:41:11 +00:00
showInstructions := flag.Bool("show-instructions", false, "Show instructions code while running")
2018-05-04 14:47:22 +00:00
skipTest0 := flag.Bool("skip-functional-test", false, "Skip functional test")
skipTest1 := flag.Bool("skip-interrupt-test", false, "Skip interrupt test")
2018-04-29 19:41:11 +00:00
breakAddressString := flag.String("break", "", "Break on address")
flag.Parse()
2018-05-10 12:32:42 +00:00
breakAddress := utils.DecodeCmdLineAddress(breakAddressString)
cpu.InitInstructionDecoder()
mmu.InitRAM()
2018-05-04 14:47:22 +00:00
var Roms = []string{
"6502_functional_test.bin.gz",
"6502_interrupt_test.bin.gz",
}
for i, rom := range Roms {
if (i == 0) && *skipTest0 {
continue
}
if (i == 1) && *skipTest1 {
continue
}
fmt.Printf("Running %s\n", rom)
cpu.Init()
cpu.State.PC = 0x800
system.RunningTests = true
2018-05-04 14:47:22 +00:00
if i == 0 {
system.RunningFunctionalTests = true
2018-05-04 14:47:22 +00:00
}
if i == 1 {
system.RunningInterruptTests = true
2018-05-04 14:47:22 +00:00
}
bytes, err := utils.ReadMemoryFromGzipFile(rom)
2018-04-29 19:41:11 +00:00
if err != nil {
panic(err)
}
// Copy main RAM area 0x0000-0xbfff
for i := 0; i < 0xc000; i++ {
mmu.PhysicalMemory.MainMemory[i] = bytes[i]
2018-04-29 19:41:11 +00:00
}
// Map writable RAM area in 0xc000-0xffff
var RomPretendingToBeRAM [0x4000]uint8
for i := 0x0; i < 0x4000; i++ {
RomPretendingToBeRAM[i] = bytes[0xc000+i]
}
for i := 0x0; i < 0x40; i++ {
2018-05-20 10:02:08 +00:00
mmu.ReadPageTable[0xc0+i] = RomPretendingToBeRAM[i*0x100 : i*0x100+0x100]
mmu.WritePageTable[0xc0+i] = RomPretendingToBeRAM[i*0x100 : i*0x100+0x100]
}
2019-11-10 12:32:16 +00:00
cpu.Run(*showInstructions, breakAddress, true, false, false, 0)
2018-05-04 14:47:22 +00:00
fmt.Printf("Finished running %s\n\n", rom)
}
2018-04-29 19:41:11 +00:00
}