2017-12-02 19:05:53 +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-02 19:05:53 +00:00
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
TestSuite(mos6502_addr, .init = setup, .fini = teardown);
|
|
|
|
|
2018-01-07 21:48:19 +00:00
|
|
|
Test(mos6502_addr, mode)
|
2017-12-05 05:30:18 +00:00
|
|
|
{
|
|
|
|
cr_assert_eq(mos6502_addr_mode(0xEA), IMP);
|
|
|
|
cr_assert_eq(mos6502_addr_mode(0xD6), ZPX);
|
|
|
|
cr_assert_eq(mos6502_addr_mode(0xF0), REL);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_acc)
|
|
|
|
{
|
2017-12-02 19:05:53 +00:00
|
|
|
cpu->A = 123;
|
|
|
|
cr_assert_eq(mos6502_resolve_acc(cpu), 123);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_abs)
|
|
|
|
{
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 0x1234, 111);
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x34);
|
|
|
|
SET_PC_BYTE(cpu, 2, 0x12);
|
2017-12-02 19:05:53 +00:00
|
|
|
cr_assert_eq(mos6502_resolve_abs(cpu), 111);
|
|
|
|
}
|
|
|
|
|
2018-01-27 06:16:39 +00:00
|
|
|
Test(mos6502_addr, addr_mode_abx)
|
2017-12-06 21:57:15 +00:00
|
|
|
{
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 0x1234, 111);
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x30);
|
|
|
|
SET_PC_BYTE(cpu, 2, 0x12);
|
2017-12-02 19:05:53 +00:00
|
|
|
cpu->X = 4;
|
|
|
|
cr_assert_eq(mos6502_resolve_abx(cpu), 111);
|
|
|
|
}
|
|
|
|
|
2018-01-27 06:16:39 +00:00
|
|
|
Test(mos6502_addr, addr_mode_aby)
|
2017-12-06 21:57:15 +00:00
|
|
|
{
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 0x1234, 111);
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x30);
|
|
|
|
SET_PC_BYTE(cpu, 2, 0x12);
|
2018-01-27 04:04:47 +00:00
|
|
|
cpu->Y = 4;
|
2017-12-02 19:05:53 +00:00
|
|
|
cr_assert_eq(mos6502_resolve_aby(cpu), 111);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_imm)
|
|
|
|
{
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x12);
|
2017-12-02 19:05:53 +00:00
|
|
|
cr_assert_eq(mos6502_resolve_imm(cpu), 0x12);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_idx)
|
|
|
|
{
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 0x17, 0x23);
|
|
|
|
mos6502_set(cpu, 0x23, 123);
|
2017-12-02 19:05:53 +00:00
|
|
|
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x12);
|
2017-12-02 19:05:53 +00:00
|
|
|
cpu->X = 5;
|
|
|
|
cr_assert_eq(mos6502_resolve_idx(cpu), 123);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_idy)
|
|
|
|
{
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 0x12, 0x23);
|
|
|
|
mos6502_set(cpu, 0x28, 123);
|
2017-12-02 19:05:53 +00:00
|
|
|
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x12);
|
2017-12-02 19:05:53 +00:00
|
|
|
cpu->Y = 5;
|
|
|
|
cr_assert_eq(mos6502_resolve_idy(cpu), 123);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_ind)
|
|
|
|
{
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 0x1234, 0x45);
|
|
|
|
mos6502_set(cpu, 0x1235, 0x23);
|
|
|
|
mos6502_set(cpu, 0x2345, 123);
|
2017-12-02 19:05:53 +00:00
|
|
|
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x34);
|
|
|
|
SET_PC_BYTE(cpu, 2, 0x12);
|
2017-12-02 19:05:53 +00:00
|
|
|
cr_assert_eq(mos6502_resolve_ind(cpu), 123);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_rel_positive)
|
|
|
|
{
|
2017-12-02 19:05:53 +00:00
|
|
|
cpu->PC = 123;
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 88);
|
2017-12-02 19:05:53 +00:00
|
|
|
cr_assert_eq(mos6502_resolve_rel(cpu), 0);
|
2018-01-12 19:57:48 +00:00
|
|
|
cr_assert_eq(cpu->eff_addr, 213);
|
2017-12-02 19:05:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_rel_negative)
|
|
|
|
{
|
2017-12-02 19:05:53 +00:00
|
|
|
cpu->PC = 123;
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 216);
|
2017-12-02 19:05:53 +00:00
|
|
|
cr_assert_eq(mos6502_resolve_rel(cpu), 0);
|
2018-01-12 19:57:48 +00:00
|
|
|
cr_assert_eq(cpu->eff_addr, 85);
|
2017-12-02 19:05:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_zpg)
|
|
|
|
{
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 0x0034, 222);
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x34);
|
2017-12-02 19:05:53 +00:00
|
|
|
cr_assert_eq(mos6502_resolve_zpg(cpu), 222);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_zpx)
|
|
|
|
{
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 0x0034, 222);
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x30);
|
2017-12-02 19:05:53 +00:00
|
|
|
cpu->X = 4;
|
|
|
|
cr_assert_eq(mos6502_resolve_zpx(cpu), 222);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_addr, addr_mode_zpy)
|
|
|
|
{
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 0x0034, 222);
|
2018-01-10 02:59:14 +00:00
|
|
|
SET_PC_BYTE(cpu, 1, 0x2F);
|
2017-12-02 19:05:53 +00:00
|
|
|
cpu->Y = 5;
|
|
|
|
cr_assert_eq(mos6502_resolve_zpy(cpu), 222);
|
|
|
|
}
|
|
|
|
|