2017-12-04 02:19:17 +00:00
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
|
|
|
#include "mos6502.h"
|
|
|
|
#include "mos6502.enums.h"
|
2017-12-06 21:57:15 +00:00
|
|
|
#include "mos6502.tests.h"
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
TestSuite(mos6502_exec, .init = setup, .fini = teardown);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_exec, brk)
|
|
|
|
{
|
2018-02-22 19:44:13 +00:00
|
|
|
// Start out with the decimal bit high so we can test it gets turned
|
|
|
|
// off; this assignment also guarantees the I bit is low, and that
|
|
|
|
// should be set high by the handler as well.
|
|
|
|
cpu->P = MOS_DECIMAL;
|
|
|
|
|
2017-12-09 20:50:33 +00:00
|
|
|
vm_8bit orig_P = cpu->P;
|
|
|
|
|
2017-12-04 02:19:17 +00:00
|
|
|
cpu->PC = 123;
|
|
|
|
mos6502_handle_brk(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->PC, 125);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_INTERRUPT, MOS_INTERRUPT);
|
2018-02-22 19:44:13 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_DECIMAL, 0);
|
2017-12-09 20:50:33 +00:00
|
|
|
|
|
|
|
cr_assert_eq(mos6502_pop_stack(cpu), orig_P);
|
2017-12-04 02:19:17 +00:00
|
|
|
cr_assert_eq(mos6502_pop_stack(cpu), 123);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_exec, jmp)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->PC = 123;
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 234;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_jmp(cpu, 0);
|
|
|
|
|
|
|
|
cr_assert_eq(cpu->PC, 234);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_exec, jsr)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->PC = 123;
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 235;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_jsr(cpu, 0);
|
|
|
|
|
|
|
|
cr_assert_eq(cpu->PC, 235);
|
2018-01-09 22:26:21 +00:00
|
|
|
|
2018-01-24 03:35:59 +00:00
|
|
|
cr_assert_eq(mos6502_pop_stack(cpu), 125);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 20:07:05 +00:00
|
|
|
/*
|
|
|
|
* In addition to nop, we also have np2 and np3 which also do nothing.
|
|
|
|
* We're just passing on those.
|
|
|
|
*
|
|
|
|
* Test(mos6502_exec, np2)
|
|
|
|
* Test(mos6502_exec, np3)
|
|
|
|
*/
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_exec, nop)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
// currently this test does nothing -- we _should_ test to see if we
|
|
|
|
// pass the right number of cycles, though.
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_exec, rti)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
mos6502_push_stack(cpu, 222);
|
2017-12-09 20:52:55 +00:00
|
|
|
mos6502_push_stack(cpu, cpu->P);
|
|
|
|
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_rti(cpu, 0);
|
|
|
|
|
|
|
|
cr_assert_eq(cpu->PC, 222);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_exec, rts)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
2018-01-24 03:35:59 +00:00
|
|
|
mos6502_push_stack(cpu, 233);
|
2017-12-09 20:53:18 +00:00
|
|
|
mos6502_handle_rts(cpu, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-24 03:35:59 +00:00
|
|
|
cr_assert_eq(cpu->PC, 234);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|