mirror of
https://github.com/zellyn/go6502.git
synced 2025-03-16 09:29:48 +00:00
tests: add custom offset-wrap tests
This commit is contained in:
parent
d880332268
commit
0a208481df
@ -5,10 +5,15 @@ Tests for the 6502 CPU emulator, comparing it with the transistor-level simulati
|
||||
package tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/zellyn/go6502/asm"
|
||||
"github.com/zellyn/go6502/asm/flavors/scma"
|
||||
"github.com/zellyn/go6502/asm/lines"
|
||||
"github.com/zellyn/go6502/cpu"
|
||||
"github.com/zellyn/go6502/opcodes"
|
||||
"github.com/zellyn/go6502/visual"
|
||||
)
|
||||
|
||||
@ -84,3 +89,101 @@ func TestFunctionalTestCompare(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getTestProgram() ([]byte, error) {
|
||||
o := lines.NewTestOpener()
|
||||
a := asm.NewAssembler(scma.New(opcodes.SetSweet16), o)
|
||||
o["FILE"] = `
|
||||
cld
|
||||
ldx #$ff
|
||||
txs
|
||||
lda #$ff
|
||||
sta $70
|
||||
lda #$0e
|
||||
sta $71
|
||||
ldy #0
|
||||
adc ($70),Y
|
||||
ldy #1
|
||||
clc
|
||||
adc ($70),Y
|
||||
sec
|
||||
adc ($70),Y
|
||||
ldx #0
|
||||
inc $3412,X
|
||||
ldx $ff
|
||||
clc
|
||||
inc $3412,X
|
||||
sec
|
||||
inc $3412,X
|
||||
jmp 0
|
||||
`
|
||||
if err := a.Load("FILE", 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := a.Pass2(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bb, err := a.RawBytes()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("a.RawBytes() failed: %v", err)
|
||||
}
|
||||
return bb, nil
|
||||
}
|
||||
|
||||
// Test a custom test program against the instruction- and gate-level
|
||||
// CPU emulations, making sure they have the same memory access
|
||||
// patterns.
|
||||
func TestCustomTestCompare(t *testing.T) {
|
||||
bytes, err := getTestProgram()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to assemble test program: %v", err)
|
||||
}
|
||||
var m Memorizer
|
||||
START := 0x6000
|
||||
copy(m.mem1[START:], bytes)
|
||||
copy(m.mem2[START:], bytes)
|
||||
// Set the RESET vector to jump to the tests
|
||||
m.mem1[0xFFFC] = byte(START % 256)
|
||||
m.mem1[0xFFFD] = byte(START / 256)
|
||||
m.mem2[0xFFFC] = byte(START % 256)
|
||||
m.mem2[0xFFFD] = byte(START / 256)
|
||||
|
||||
v := visual.NewCPU(&m)
|
||||
v.Reset()
|
||||
for i := 0; i < 8; i++ {
|
||||
v.Step()
|
||||
}
|
||||
|
||||
var cc CycleCount
|
||||
c := cpu.NewCPU(&m, cc.Tick, cpu.VERSION_6502)
|
||||
c.Reset()
|
||||
|
||||
m.Reset(MODE_RECORD)
|
||||
v.Step()
|
||||
v.Step()
|
||||
m.Verify()
|
||||
c.Step()
|
||||
if len(m.errors) > 0 {
|
||||
t.Fatal("Errors on reset", m.errors)
|
||||
}
|
||||
|
||||
for {
|
||||
m.Record()
|
||||
for i := 0; i < 1000; i++ {
|
||||
v.Step()
|
||||
}
|
||||
m.Verify()
|
||||
for len(m.ops) > 7 {
|
||||
s := status(c, &m.mem2, uint64(cc))
|
||||
c.Step()
|
||||
if len(m.errors) > 0 {
|
||||
t.Fatalf("Error at %v: %v", s, m.errors)
|
||||
}
|
||||
pc := c.PC()
|
||||
fmt.Printf("%04X\n", pc)
|
||||
if pc == 0x00 {
|
||||
t.Fatalf("bang")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user