diff --git a/src/mos6502.exec.c b/src/mos6502.exec.c index 306e74a..fe20253 100644 --- a/src/mos6502.exec.c +++ b/src/mos6502.exec.c @@ -14,9 +14,9 @@ */ DEFINE_INST(brk) { - cpu->P |= INTERRUPT; mos6502_push_stack(cpu, cpu->PC); mos6502_push_stack(cpu, cpu->P); + cpu->P |= INTERRUPT; cpu->PC += 2; } diff --git a/tests/mos6502.exec.c b/tests/mos6502.exec.c index 25e6631..7732ca2 100644 --- a/tests/mos6502.exec.c +++ b/tests/mos6502.exec.c @@ -8,10 +8,14 @@ TestSuite(mos6502_exec, .init = setup, .fini = teardown); Test(mos6502_exec, brk) { + vm_8bit orig_P = cpu->P; + cpu->PC = 123; mos6502_handle_brk(cpu, 0); cr_assert_eq(cpu->PC, 125); cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT); + + cr_assert_eq(mos6502_pop_stack(cpu), orig_P); cr_assert_eq(mos6502_pop_stack(cpu), 123); }