aboutsummaryrefslogtreecommitdiff
path: root/tests/cpu_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cpu_test.go')
-rw-r--r--tests/cpu_test.go36
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")
+ }
+}