mirror of
https://github.com/pevans/erc-c.git
synced 2024-12-22 14:30:45 +00:00
68b1b79549
It's really wrong, because we _should_ be storing PC + 2 in the stack. And software's definitely gonna bork when we try emulating them, because they will invariably inspect the stack and assume that's what we have in there. But the proper fix is to not actually do next_byte(), and to never advance PC outside of the execute function. But that's a bigger change than I want to do at this specific moment. So, in the meantime, you have me prattling on in a commit message. Lucky you!
68 lines
1.4 KiB
C
68 lines
1.4 KiB
C
#include <criterion/criterion.h>
|
|
|
|
#include "mos6502.h"
|
|
#include "mos6502.enums.h"
|
|
#include "mos6502.tests.h"
|
|
|
|
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 & MOS_INTERRUPT, MOS_INTERRUPT);
|
|
|
|
cr_assert_eq(mos6502_pop_stack(cpu), orig_P);
|
|
cr_assert_eq(mos6502_pop_stack(cpu), 123);
|
|
}
|
|
|
|
Test(mos6502_exec, jmp)
|
|
{
|
|
cpu->PC = 123;
|
|
cpu->last_addr = 234;
|
|
mos6502_handle_jmp(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->PC, 234);
|
|
}
|
|
|
|
Test(mos6502_exec, jsr)
|
|
{
|
|
cpu->PC = 123;
|
|
cpu->last_addr = 235;
|
|
mos6502_handle_jsr(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->PC, 235);
|
|
|
|
// FIXME: this behavior is wrong. People will expect the stack to
|
|
// contain 125 in this instance. This might correct execution but
|
|
// that just means that execution is the thing that's wrong!
|
|
cr_assert_eq(mos6502_pop_stack(cpu), 123);
|
|
}
|
|
|
|
Test(mos6502_exec, nop)
|
|
{
|
|
// currently this test does nothing -- we _should_ test to see if we
|
|
// pass the right number of cycles, though.
|
|
}
|
|
|
|
Test(mos6502_exec, rti)
|
|
{
|
|
mos6502_push_stack(cpu, 222);
|
|
mos6502_push_stack(cpu, cpu->P);
|
|
|
|
mos6502_handle_rti(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->PC, 222);
|
|
}
|
|
|
|
Test(mos6502_exec, rts)
|
|
{
|
|
mos6502_push_stack(cpu, 333);
|
|
mos6502_handle_rts(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->PC, 333);
|
|
}
|