diff options
| author | crecher <crecher@crecher.net> | 2026-10-12 04:40:11 +0200 |
|---|---|---|
| committer | crecher <crecher@crecher.net> | 2026-10-12 04:40:11 +0200 |
| commit | e30df212d6a5ec5f60a8b1d52e491e32fe6a4572 (patch) | |
| tree | 8d882db4a4c88ba7f72a0298acdd788e84ead745 /tests/cpu_test.go | |
| parent | 2898f6c0f962035f03f410dbebbc868767d2e4bf (diff) | |
| download | gones-e30df212d6a5ec5f60a8b1d52e491e32fe6a4572.tar.gz gones-e30df212d6a5ec5f60a8b1d52e491e32fe6a4572.zip | |
cpu: add JAM instructions
Diffstat (limited to 'tests/cpu_test.go')
| -rw-r--r-- | tests/cpu_test.go | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/cpu_test.go b/tests/cpu_test.go index 87743b1..269f9ee 100644 --- a/tests/cpu_test.go +++ b/tests/cpu_test.go @@ -232,6 +232,40 @@ func TestUnimplementedOpcodePanics(t *testing.T) { t.Fatalf("expected panic for illegal opcode") } }() - c, _ := newTestCPU([]uint8{0x02}) + c, _ := newTestCPU([]uint8{0x8B}) c.Step() } + +func TestJamStopsCPU(t *testing.T) { + c, _ := newTestCPU([]uint8{0xA9, 0x42, 0x02, 0xEA}) + c.Step() + c.Step() + if !c.Jammed { + t.Fatal("Jammed = false, want true") + } + if c.PC != 0x8002 { + t.Fatalf("PC = 0x%04X, want 0x8002", c.PC) + } + for i := 0; i < 3; i++ { + if cycles := c.Step(); cycles != 1 { + t.Fatalf("cycles = %d, want 1", cycles) + } + } + if c.PC != 0x8002 || c.A != 0x42 { + t.Fatalf("PC = 0x%04X, A = 0x%02X; want 0x8002, 0x42", c.PC, c.A) + } +} + +func TestJammedIgnoresInterruptsUntilReset(t *testing.T) { + c, bus := newTestCPU([]uint8{0x02}) + bus.mem[0xFFFA], bus.mem[0xFFFB] = 0x00, 0x90 + c.Step() + c.NMI() + if c.PC != 0x8000 { + t.Fatalf("PC after NMI = 0x%04X, want 0x8000", c.PC) + } + c.Reset() + if c.Jammed { + t.Fatal("Jammed = true after Reset, want false") + } +} |