1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-12-21 08:30:55 +00:00

Vastly simplify unit tests for mos6502

Criterion's init and fini config options allow us to register setup and
teardown functions. We now use this to register the common cpu variable
for the mos6502 tests, albeit through the use of a global variable.

Doing so necessitated that each of the different test files have their
own suites, due to some implementation details in Criterion, but this is
No Big Deal.
This commit is contained in:
Peter Evans 2017-12-06 15:57:15 -06:00
parent 98f70e0a9a
commit 00ff9f069d
10 changed files with 134 additions and 410 deletions

View File

@ -21,20 +21,6 @@
#define SET_PC_BYTE(cpu, off, byte) \ #define SET_PC_BYTE(cpu, off, byte) \
vm_segment_set(cpu->memory, cpu->PC + off, byte) vm_segment_set(cpu->memory, cpu->PC + off, byte)
#define INIT_ADDR_MODE() \
mos6502 *cpu; \
cpu = mos6502_create()
#define END_ADDR_MODE() \
mos6502_free(cpu)
#define START_CPU_TEST(t) \
t *cpu; \
cpu = t##_create()
#define END_CPU_TEST(t) \
t##_free(cpu)
#define DEFINE_INST(inst) \ #define DEFINE_INST(inst) \
void mos6502_handle_##inst (mos6502 *cpu, vm_8bit oper) void mos6502_handle_##inst (mos6502 *cpu, vm_8bit oper)

18
include/mos6502.tests.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef _MOS6502_TESTS_H
#define _MOS6502_TESTS_H
static mos6502 *cpu;
static void
setup()
{
cpu = mos6502_create();
}
static void
teardown()
{
mos6502_free(cpu);
}
#endif

View File

@ -2,17 +2,19 @@
#include "mos6502.h" #include "mos6502.h"
#include "mos6502.enums.h" #include "mos6502.enums.h"
#include "mos6502.tests.h"
Test(mos6502, addr_mode) TestSuite(mos6502_addr, .init = setup, .fini = teardown);
Test(mos6502_addr, addr_mode)
{ {
cr_assert_eq(mos6502_addr_mode(0xEA), IMP); cr_assert_eq(mos6502_addr_mode(0xEA), IMP);
cr_assert_eq(mos6502_addr_mode(0xD6), ZPX); cr_assert_eq(mos6502_addr_mode(0xD6), ZPX);
cr_assert_eq(mos6502_addr_mode(0xF0), REL); cr_assert_eq(mos6502_addr_mode(0xF0), REL);
} }
Test(mos6502, get_address_resolver) { Test(mos6502_addr, get_address_resolver)
INIT_ADDR_MODE(); {
cr_assert_eq(mos6502_get_address_resolver(0x0A), mos6502_resolve_acc); cr_assert_eq(mos6502_get_address_resolver(0x0A), mos6502_resolve_acc);
cr_assert_eq(mos6502_get_address_resolver(0x20), mos6502_resolve_abs); cr_assert_eq(mos6502_get_address_resolver(0x20), mos6502_resolve_abs);
cr_assert_eq(mos6502_get_address_resolver(0xBC), mos6502_resolve_abx); cr_assert_eq(mos6502_get_address_resolver(0xBC), mos6502_resolve_abx);
@ -25,118 +27,88 @@ Test(mos6502, get_address_resolver) {
cr_assert_eq(mos6502_get_address_resolver(0x05), mos6502_resolve_zpg); cr_assert_eq(mos6502_get_address_resolver(0x05), mos6502_resolve_zpg);
cr_assert_eq(mos6502_get_address_resolver(0x15), mos6502_resolve_zpx); cr_assert_eq(mos6502_get_address_resolver(0x15), mos6502_resolve_zpx);
cr_assert_eq(mos6502_get_address_resolver(0x96), mos6502_resolve_zpy); cr_assert_eq(mos6502_get_address_resolver(0x96), mos6502_resolve_zpy);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_acc) { Test(mos6502_addr, addr_mode_acc)
INIT_ADDR_MODE(); {
cpu->A = 123; cpu->A = 123;
cr_assert_eq(mos6502_resolve_acc(cpu), 123); cr_assert_eq(mos6502_resolve_acc(cpu), 123);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_abs) { Test(mos6502_addr, addr_mode_abs)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x1234, 111); vm_segment_set(cpu->memory, 0x1234, 111);
SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 0, 0x12);
SET_PC_BYTE(cpu, 1, 0x34); SET_PC_BYTE(cpu, 1, 0x34);
cr_assert_eq(mos6502_resolve_abs(cpu), 111); cr_assert_eq(mos6502_resolve_abs(cpu), 111);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_abx_carry0) { Test(mos6502_addr, addr_mode_abx_carry0)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x1234, 111); vm_segment_set(cpu->memory, 0x1234, 111);
SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 0, 0x12);
SET_PC_BYTE(cpu, 1, 0x30); SET_PC_BYTE(cpu, 1, 0x30);
cpu->X = 4; cpu->X = 4;
cr_assert_eq(mos6502_resolve_abx(cpu), 111); cr_assert_eq(mos6502_resolve_abx(cpu), 111);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_abx_carry1) { Test(mos6502_addr, addr_mode_abx_carry1)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x1234, 111); vm_segment_set(cpu->memory, 0x1234, 111);
SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 0, 0x12);
SET_PC_BYTE(cpu, 1, 0x30); SET_PC_BYTE(cpu, 1, 0x30);
cpu->X = 3; cpu->X = 3;
cpu->P = cpu->P | CARRY; cpu->P = cpu->P | CARRY;
cr_assert_eq(mos6502_resolve_abx(cpu), 111); cr_assert_eq(mos6502_resolve_abx(cpu), 111);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_aby_carry0) { Test(mos6502_addr, addr_mode_aby_carry0)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x1234, 111); vm_segment_set(cpu->memory, 0x1234, 111);
SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 0, 0x12);
SET_PC_BYTE(cpu, 1, 0x30); SET_PC_BYTE(cpu, 1, 0x30);
cpu->Y = 4; cpu->Y = 4;
cr_assert_eq(mos6502_resolve_aby(cpu), 111); cr_assert_eq(mos6502_resolve_aby(cpu), 111);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_aby_carry1) { Test(mos6502_addr, addr_mode_aby_carry1)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x1234, 111); vm_segment_set(cpu->memory, 0x1234, 111);
SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 0, 0x12);
SET_PC_BYTE(cpu, 1, 0x30); SET_PC_BYTE(cpu, 1, 0x30);
cpu->Y = 3; cpu->Y = 3;
cpu->P = cpu->P | CARRY; cpu->P = cpu->P | CARRY;
cr_assert_eq(mos6502_resolve_aby(cpu), 111); cr_assert_eq(mos6502_resolve_aby(cpu), 111);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_imm) { Test(mos6502_addr, addr_mode_imm)
INIT_ADDR_MODE(); {
SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 0, 0x12);
cr_assert_eq(mos6502_resolve_imm(cpu), 0x12); cr_assert_eq(mos6502_resolve_imm(cpu), 0x12);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_idx) { Test(mos6502_addr, addr_mode_idx)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x17, 0x23); vm_segment_set(cpu->memory, 0x17, 0x23);
vm_segment_set(cpu->memory, 0x23, 123); vm_segment_set(cpu->memory, 0x23, 123);
SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 0, 0x12);
cpu->X = 5; cpu->X = 5;
cr_assert_eq(mos6502_resolve_idx(cpu), 123); cr_assert_eq(mos6502_resolve_idx(cpu), 123);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_idy) { Test(mos6502_addr, addr_mode_idy)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x12, 0x23); vm_segment_set(cpu->memory, 0x12, 0x23);
vm_segment_set(cpu->memory, 0x28, 123); vm_segment_set(cpu->memory, 0x28, 123);
SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 0, 0x12);
cpu->Y = 5; cpu->Y = 5;
cr_assert_eq(mos6502_resolve_idy(cpu), 123); cr_assert_eq(mos6502_resolve_idy(cpu), 123);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_ind) { Test(mos6502_addr, addr_mode_ind)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x1234, 0x23); vm_segment_set(cpu->memory, 0x1234, 0x23);
vm_segment_set(cpu->memory, 0x1235, 0x45); vm_segment_set(cpu->memory, 0x1235, 0x45);
vm_segment_set(cpu->memory, 0x2345, 123); vm_segment_set(cpu->memory, 0x2345, 123);
@ -144,61 +116,44 @@ Test(mos6502, addr_mode_ind) {
SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 0, 0x12);
SET_PC_BYTE(cpu, 1, 0x34); SET_PC_BYTE(cpu, 1, 0x34);
cr_assert_eq(mos6502_resolve_ind(cpu), 123); cr_assert_eq(mos6502_resolve_ind(cpu), 123);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_rel_positive) { Test(mos6502_addr, addr_mode_rel_positive)
INIT_ADDR_MODE(); {
cpu->PC = 123; cpu->PC = 123;
SET_PC_BYTE(cpu, 0, 88); SET_PC_BYTE(cpu, 0, 88);
cr_assert_eq(mos6502_resolve_rel(cpu), 0); cr_assert_eq(mos6502_resolve_rel(cpu), 0);
cr_assert_eq(cpu->last_addr, 211); cr_assert_eq(cpu->last_addr, 211);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_rel_negative) { Test(mos6502_addr, addr_mode_rel_negative)
INIT_ADDR_MODE(); {
cpu->PC = 123; cpu->PC = 123;
SET_PC_BYTE(cpu, 0, 216); SET_PC_BYTE(cpu, 0, 216);
cr_assert_eq(mos6502_resolve_rel(cpu), 0); cr_assert_eq(mos6502_resolve_rel(cpu), 0);
cr_assert_eq(cpu->last_addr, 34); cr_assert_eq(cpu->last_addr, 34);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_zpg) { Test(mos6502_addr, addr_mode_zpg)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x0034, 222); vm_segment_set(cpu->memory, 0x0034, 222);
SET_PC_BYTE(cpu, 0, 0x34); SET_PC_BYTE(cpu, 0, 0x34);
cr_assert_eq(mos6502_resolve_zpg(cpu), 222); cr_assert_eq(mos6502_resolve_zpg(cpu), 222);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_zpx) { Test(mos6502_addr, addr_mode_zpx)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x0034, 222); vm_segment_set(cpu->memory, 0x0034, 222);
SET_PC_BYTE(cpu, 0, 0x30); SET_PC_BYTE(cpu, 0, 0x30);
cpu->X = 4; cpu->X = 4;
cr_assert_eq(mos6502_resolve_zpx(cpu), 222); cr_assert_eq(mos6502_resolve_zpx(cpu), 222);
END_ADDR_MODE();
} }
Test(mos6502, addr_mode_zpy) { Test(mos6502_addr, addr_mode_zpy)
INIT_ADDR_MODE(); {
vm_segment_set(cpu->memory, 0x0034, 222); vm_segment_set(cpu->memory, 0x0034, 222);
SET_PC_BYTE(cpu, 0, 0x2F); SET_PC_BYTE(cpu, 0, 0x2F);
cpu->Y = 5; cpu->Y = 5;
cr_assert_eq(mos6502_resolve_zpy(cpu), 222); cr_assert_eq(mos6502_resolve_zpy(cpu), 222);
END_ADDR_MODE();
} }

View File

@ -2,11 +2,12 @@
#include "mos6502.h" #include "mos6502.h"
#include "mos6502.enums.h" #include "mos6502.enums.h"
#include "mos6502.tests.h"
Test(mos6502, adc) TestSuite(mos6502_arith, .init = setup, .fini = teardown);
Test(mos6502_arith, adc)
{ {
START_CPU_TEST(mos6502);
cpu->A = 5; cpu->A = 5;
mos6502_handle_adc(cpu, 3); mos6502_handle_adc(cpu, 3);
cr_assert_eq(cpu->A, 8); cr_assert_eq(cpu->A, 8);
@ -14,14 +15,10 @@ Test(mos6502, adc)
cpu->P |= CARRY; cpu->P |= CARRY;
mos6502_handle_adc(cpu, 64); mos6502_handle_adc(cpu, 64);
cr_assert_eq(cpu->A, 73); cr_assert_eq(cpu->A, 73);
END_CPU_TEST(mos6502);
} }
Test(mos6502, cmp) Test(mos6502_arith, cmp)
{ {
START_CPU_TEST(mos6502);
cpu->A = 5; cpu->A = 5;
mos6502_handle_cmp(cpu, 3); mos6502_handle_cmp(cpu, 3);
cr_assert_eq(cpu->P & CARRY, CARRY); cr_assert_eq(cpu->P & CARRY, CARRY);
@ -39,40 +36,28 @@ Test(mos6502, cmp)
cr_assert_eq(cpu->P & CARRY, CARRY); cr_assert_eq(cpu->P & CARRY, CARRY);
cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE);
cr_assert_eq(cpu->P & ZERO, 0); cr_assert_eq(cpu->P & ZERO, 0);
END_CPU_TEST(mos6502);
} }
Test(mos6502, cpx) Test(mos6502_arith, cpx)
{ {
START_CPU_TEST(mos6502);
cpu->X = 5; cpu->X = 5;
mos6502_handle_cpx(cpu, 3); mos6502_handle_cpx(cpu, 3);
cr_assert_eq(cpu->P & CARRY, CARRY); cr_assert_eq(cpu->P & CARRY, CARRY);
cr_assert_eq(cpu->P & NEGATIVE, 0); cr_assert_eq(cpu->P & NEGATIVE, 0);
cr_assert_eq(cpu->P & ZERO, 0); cr_assert_eq(cpu->P & ZERO, 0);
END_CPU_TEST(mos6502);
} }
Test(mos6502, cpy) Test(mos6502_arith, cpy)
{ {
START_CPU_TEST(mos6502);
cpu->Y = 5; cpu->Y = 5;
mos6502_handle_cpy(cpu, 3); mos6502_handle_cpy(cpu, 3);
cr_assert_eq(cpu->P & CARRY, CARRY); cr_assert_eq(cpu->P & CARRY, CARRY);
cr_assert_eq(cpu->P & NEGATIVE, 0); cr_assert_eq(cpu->P & NEGATIVE, 0);
cr_assert_eq(cpu->P & ZERO, 0); cr_assert_eq(cpu->P & ZERO, 0);
END_CPU_TEST(mos6502);
} }
Test(mos6502, dec) Test(mos6502_arith, dec)
{ {
START_CPU_TEST(mos6502);
// Note that DEC does NOT decrement the accumulator if the last // Note that DEC does NOT decrement the accumulator if the last
// address is not set. It does _nothing_. // address is not set. It does _nothing_.
cpu->A = 5; cpu->A = 5;
@ -87,69 +72,45 @@ Test(mos6502, dec)
// necessarily need for that to be so. // necessarily need for that to be so.
mos6502_handle_dec(cpu, 44); mos6502_handle_dec(cpu, 44);
cr_assert_eq(vm_segment_get(cpu->memory, 123), 43); cr_assert_eq(vm_segment_get(cpu->memory, 123), 43);
END_CPU_TEST(mos6502);
} }
Test(mos6502, dex) Test(mos6502_arith, dex)
{ {
START_CPU_TEST(mos6502);
cpu->X = 5; cpu->X = 5;
mos6502_handle_dex(cpu, 0); mos6502_handle_dex(cpu, 0);
cr_assert_eq(cpu->X, 4); cr_assert_eq(cpu->X, 4);
END_CPU_TEST(mos6502);
} }
Test(mos6502, dey) Test(mos6502_arith, dey)
{ {
START_CPU_TEST(mos6502);
cpu->Y = 5; cpu->Y = 5;
mos6502_handle_dey(cpu, 0); mos6502_handle_dey(cpu, 0);
cr_assert_eq(cpu->Y, 4); cr_assert_eq(cpu->Y, 4);
END_CPU_TEST(mos6502);
} }
Test(mos6502, inc) Test(mos6502_arith, inc)
{ {
START_CPU_TEST(mos6502);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_inc(cpu, 55); mos6502_handle_inc(cpu, 55);
cr_assert_eq(vm_segment_get(cpu->memory, 123), 56); cr_assert_eq(vm_segment_get(cpu->memory, 123), 56);
END_CPU_TEST(mos6502);
} }
Test(mos6502, inx) Test(mos6502_arith, inx)
{ {
START_CPU_TEST(mos6502);
cpu->X = 5; cpu->X = 5;
mos6502_handle_inx(cpu, 0); mos6502_handle_inx(cpu, 0);
cr_assert_eq(cpu->X, 6); cr_assert_eq(cpu->X, 6);
END_CPU_TEST(mos6502);
} }
Test(mos6502, iny) Test(mos6502_arith, iny)
{ {
START_CPU_TEST(mos6502);
cpu->Y = 5; cpu->Y = 5;
mos6502_handle_iny(cpu, 0); mos6502_handle_iny(cpu, 0);
cr_assert_eq(cpu->Y, 6); cr_assert_eq(cpu->Y, 6);
END_CPU_TEST(mos6502);
} }
Test(mos6502, sbc) Test(mos6502_arith, sbc)
{ {
START_CPU_TEST(mos6502);
cpu->A = 5; cpu->A = 5;
mos6502_handle_sbc(cpu, 3); mos6502_handle_sbc(cpu, 3);
cr_assert_eq(cpu->A, 2); cr_assert_eq(cpu->A, 2);
@ -158,6 +119,4 @@ Test(mos6502, sbc)
cpu->A = 16; cpu->A = 16;
mos6502_handle_sbc(cpu, 8); mos6502_handle_sbc(cpu, 8);
cr_assert_eq(cpu->A, 7); cr_assert_eq(cpu->A, 7);
END_CPU_TEST(mos6502);
} }

View File

@ -2,11 +2,12 @@
#include "mos6502.h" #include "mos6502.h"
#include "mos6502.enums.h" #include "mos6502.enums.h"
#include "mos6502.tests.h"
Test(mos6502, and) TestSuite(mos6502_bits, .init = setup, .fini = teardown);
Test(mos6502_bits, and)
{ {
START_CPU_TEST(mos6502);
cpu->A = 5; cpu->A = 5;
mos6502_handle_and(cpu, 1); mos6502_handle_and(cpu, 1);
cr_assert_eq(cpu->A, 1); cr_assert_eq(cpu->A, 1);
@ -14,28 +15,20 @@ Test(mos6502, and)
cpu->A = 5; cpu->A = 5;
mos6502_handle_and(cpu, 4); mos6502_handle_and(cpu, 4);
cr_assert_eq(cpu->A, 4); cr_assert_eq(cpu->A, 4);
END_CPU_TEST(mos6502);
} }
Test(mos6502, asl) Test(mos6502_bits, asl)
{ {
START_CPU_TEST(mos6502);
mos6502_handle_asl(cpu, 5); mos6502_handle_asl(cpu, 5);
cr_assert_eq(cpu->A, 10); cr_assert_eq(cpu->A, 10);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_asl(cpu, 22); mos6502_handle_asl(cpu, 22);
cr_assert_eq(vm_segment_get(cpu->memory, 123), 44); cr_assert_eq(vm_segment_get(cpu->memory, 123), 44);
END_CPU_TEST(mos6502);
} }
Test(mos6502, bit) Test(mos6502_bits, bit)
{ {
START_CPU_TEST(mos6502);
cpu->A = 5; cpu->A = 5;
mos6502_handle_bit(cpu, 129); mos6502_handle_bit(cpu, 129);
cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE);
@ -61,14 +54,10 @@ Test(mos6502, bit)
cr_assert_eq(cpu->P & NEGATIVE, 0); cr_assert_eq(cpu->P & NEGATIVE, 0);
cr_assert_eq(cpu->P & OVERFLOW, 0); cr_assert_eq(cpu->P & OVERFLOW, 0);
cr_assert_eq(cpu->P & ZERO, ZERO); cr_assert_eq(cpu->P & ZERO, ZERO);
END_CPU_TEST(mos6502);
} }
Test(mos6502, eor) Test(mos6502_bits, eor)
{ {
START_CPU_TEST(mos6502);
cpu->A = 5; cpu->A = 5;
mos6502_handle_eor(cpu, 4); mos6502_handle_eor(cpu, 4);
cr_assert_eq(cpu->A, 1); cr_assert_eq(cpu->A, 1);
@ -76,14 +65,10 @@ Test(mos6502, eor)
cpu->A = 5; cpu->A = 5;
mos6502_handle_eor(cpu, 1); mos6502_handle_eor(cpu, 1);
cr_assert_eq(cpu->A, 4); cr_assert_eq(cpu->A, 4);
END_CPU_TEST(mos6502);
} }
Test(mos6502, lsr) Test(mos6502_bits, lsr)
{ {
START_CPU_TEST(mos6502);
mos6502_handle_lsr(cpu, 5); mos6502_handle_lsr(cpu, 5);
cr_assert_eq(cpu->A, 2); cr_assert_eq(cpu->A, 2);
cr_assert_eq(cpu->P & CARRY, CARRY); cr_assert_eq(cpu->P & CARRY, CARRY);
@ -92,14 +77,10 @@ Test(mos6502, lsr)
mos6502_handle_lsr(cpu, 22); mos6502_handle_lsr(cpu, 22);
cr_assert_eq(vm_segment_get(cpu->memory, 123), 11); cr_assert_eq(vm_segment_get(cpu->memory, 123), 11);
cr_assert_eq(cpu->P & CARRY, 0); cr_assert_eq(cpu->P & CARRY, 0);
END_CPU_TEST(mos6502);
} }
Test(mos6502, ora) Test(mos6502_bits, ora)
{ {
START_CPU_TEST(mos6502);
cpu->A = 5; cpu->A = 5;
mos6502_handle_ora(cpu, 4); mos6502_handle_ora(cpu, 4);
cr_assert_eq(cpu->A, 5); cr_assert_eq(cpu->A, 5);
@ -107,34 +88,24 @@ Test(mos6502, ora)
cpu->A = 5; cpu->A = 5;
mos6502_handle_ora(cpu, 10); mos6502_handle_ora(cpu, 10);
cr_assert_eq(cpu->A, 15); cr_assert_eq(cpu->A, 15);
END_CPU_TEST(mos6502);
} }
Test(mos6502, rol) Test(mos6502_bits, rol)
{ {
START_CPU_TEST(mos6502);
mos6502_handle_rol(cpu, 8); mos6502_handle_rol(cpu, 8);
cr_assert_eq(cpu->A, 16); cr_assert_eq(cpu->A, 16);
cpu->last_addr = 234; cpu->last_addr = 234;
mos6502_handle_rol(cpu, 128); mos6502_handle_rol(cpu, 128);
cr_assert_eq(vm_segment_get(cpu->memory, 234), 1); cr_assert_eq(vm_segment_get(cpu->memory, 234), 1);
END_CPU_TEST(mos6502);
} }
Test(mos6502, ror) Test(mos6502_bits, ror)
{ {
START_CPU_TEST(mos6502);
mos6502_handle_ror(cpu, 64); mos6502_handle_ror(cpu, 64);
cr_assert_eq(cpu->A, 32); cr_assert_eq(cpu->A, 32);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_ror(cpu, 1); mos6502_handle_ror(cpu, 1);
cr_assert_eq(vm_segment_get(cpu->memory, 123), 128); cr_assert_eq(vm_segment_get(cpu->memory, 123), 128);
END_CPU_TEST(mos6502);
} }

View File

@ -2,11 +2,12 @@
#include "mos6502.h" #include "mos6502.h"
#include "mos6502.enums.h" #include "mos6502.enums.h"
#include "mos6502.tests.h"
Test(mos6502, bcc) TestSuite(mos6502_branch, .init = setup, .fini = teardown);
Test(mos6502_branch, bcc)
{ {
START_CPU_TEST(mos6502);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_bcc(cpu, 0); mos6502_handle_bcc(cpu, 0);
cr_assert_eq(cpu->PC, 123); cr_assert_eq(cpu->PC, 123);
@ -15,14 +16,10 @@ Test(mos6502, bcc)
cpu->last_addr = 125; cpu->last_addr = 125;
mos6502_handle_bcc(cpu, 0); mos6502_handle_bcc(cpu, 0);
cr_assert_neq(cpu->PC, 125); cr_assert_neq(cpu->PC, 125);
END_CPU_TEST(mos6502);
} }
Test(mos6502, bcs) Test(mos6502_branch, bcs)
{ {
START_CPU_TEST(mos6502);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_bcs(cpu, 0); mos6502_handle_bcs(cpu, 0);
cr_assert_neq(cpu->PC, 123); cr_assert_neq(cpu->PC, 123);
@ -31,14 +28,10 @@ Test(mos6502, bcs)
cpu->last_addr = 125; cpu->last_addr = 125;
mos6502_handle_bcs(cpu, 0); mos6502_handle_bcs(cpu, 0);
cr_assert_eq(cpu->PC, 125); cr_assert_eq(cpu->PC, 125);
END_CPU_TEST(mos6502);
} }
Test(mos6502, beq) Test(mos6502_branch, beq)
{ {
START_CPU_TEST(mos6502);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_beq(cpu, 0); mos6502_handle_beq(cpu, 0);
cr_assert_neq(cpu->PC, 123); cr_assert_neq(cpu->PC, 123);
@ -47,14 +40,10 @@ Test(mos6502, beq)
cpu->last_addr = 125; cpu->last_addr = 125;
mos6502_handle_beq(cpu, 0); mos6502_handle_beq(cpu, 0);
cr_assert_eq(cpu->PC, 125); cr_assert_eq(cpu->PC, 125);
END_CPU_TEST(mos6502);
} }
Test(mos6502, bmi) Test(mos6502_branch, bmi)
{ {
START_CPU_TEST(mos6502);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_bmi(cpu, 0); mos6502_handle_bmi(cpu, 0);
cr_assert_neq(cpu->PC, 123); cr_assert_neq(cpu->PC, 123);
@ -63,14 +52,10 @@ Test(mos6502, bmi)
cpu->last_addr = 125; cpu->last_addr = 125;
mos6502_handle_bmi(cpu, 0); mos6502_handle_bmi(cpu, 0);
cr_assert_eq(cpu->PC, 125); cr_assert_eq(cpu->PC, 125);
END_CPU_TEST(mos6502);
} }
Test(mos6502, bne) Test(mos6502_branch, bne)
{ {
START_CPU_TEST(mos6502);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_bne(cpu, 0); mos6502_handle_bne(cpu, 0);
cr_assert_eq(cpu->PC, 123); cr_assert_eq(cpu->PC, 123);
@ -79,14 +64,10 @@ Test(mos6502, bne)
cpu->last_addr = 125; cpu->last_addr = 125;
mos6502_handle_bne(cpu, 0); mos6502_handle_bne(cpu, 0);
cr_assert_neq(cpu->PC, 125); cr_assert_neq(cpu->PC, 125);
END_CPU_TEST(mos6502);
} }
Test(mos6502, bpl) Test(mos6502_branch, bpl)
{ {
START_CPU_TEST(mos6502);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_bpl(cpu, 0); mos6502_handle_bpl(cpu, 0);
cr_assert_eq(cpu->PC, 123); cr_assert_eq(cpu->PC, 123);
@ -95,14 +76,10 @@ Test(mos6502, bpl)
cpu->last_addr = 125; cpu->last_addr = 125;
mos6502_handle_bpl(cpu, 0); mos6502_handle_bpl(cpu, 0);
cr_assert_neq(cpu->PC, 125); cr_assert_neq(cpu->PC, 125);
END_CPU_TEST(mos6502);
} }
Test(mos6502, bvc) Test(mos6502_branch, bvc)
{ {
START_CPU_TEST(mos6502);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_bvc(cpu, 0); mos6502_handle_bvc(cpu, 0);
cr_assert_eq(cpu->PC, 123); cr_assert_eq(cpu->PC, 123);
@ -111,14 +88,10 @@ Test(mos6502, bvc)
cpu->last_addr = 125; cpu->last_addr = 125;
mos6502_handle_bvc(cpu, 0); mos6502_handle_bvc(cpu, 0);
cr_assert_neq(cpu->PC, 125); cr_assert_neq(cpu->PC, 125);
END_CPU_TEST(mos6502);
} }
Test(mos6502, bvs) Test(mos6502_branch, bvs)
{ {
START_CPU_TEST(mos6502);
cpu->last_addr = 123; cpu->last_addr = 123;
mos6502_handle_bvs(cpu, 0); mos6502_handle_bvs(cpu, 0);
cr_assert_neq(cpu->PC, 123); cr_assert_neq(cpu->PC, 123);
@ -127,6 +100,4 @@ Test(mos6502, bvs)
cpu->last_addr = 125; cpu->last_addr = 125;
mos6502_handle_bvs(cpu, 0); mos6502_handle_bvs(cpu, 0);
cr_assert_eq(cpu->PC, 125); cr_assert_eq(cpu->PC, 125);
END_CPU_TEST(mos6502);
} }

View File

@ -2,11 +2,12 @@
#include "mos6502.h" #include "mos6502.h"
#include "mos6502.enums.h" #include "mos6502.enums.h"
#include "mos6502.tests.h"
Test(mos6502, create) { TestSuite(mos6502, .init = setup, .fini = teardown);
mos6502 *cpu;
cpu = mos6502_create(); Test(mos6502, create)
{
cr_assert_neq(cpu, NULL); cr_assert_neq(cpu, NULL);
cr_assert_eq(cpu->memory->size, MOS6502_MEMSIZE); cr_assert_eq(cpu->memory->size, MOS6502_MEMSIZE);
@ -17,13 +18,10 @@ Test(mos6502, create) {
cr_assert_eq(cpu->Y, 0); cr_assert_eq(cpu->Y, 0);
cr_assert_eq(cpu->P, 0); cr_assert_eq(cpu->P, 0);
cr_assert_eq(cpu->S, 0); cr_assert_eq(cpu->S, 0);
mos6502_free(cpu);
} }
Test(mos6502, next_byte) { Test(mos6502, next_byte)
INIT_ADDR_MODE(); {
cpu->PC = 128; cpu->PC = 128;
vm_segment_set(cpu->memory, cpu->PC, 123); vm_segment_set(cpu->memory, cpu->PC, 123);
vm_segment_set(cpu->memory, cpu->PC + 1, 234); vm_segment_set(cpu->memory, cpu->PC + 1, 234);
@ -32,35 +30,23 @@ Test(mos6502, next_byte) {
cr_assert_eq(mos6502_next_byte(cpu), 123); cr_assert_eq(mos6502_next_byte(cpu), 123);
cr_assert_eq(mos6502_next_byte(cpu), 234); cr_assert_eq(mos6502_next_byte(cpu), 234);
cr_assert_eq(mos6502_next_byte(cpu), 12); cr_assert_eq(mos6502_next_byte(cpu), 12);
END_ADDR_MODE();
} }
Test(mos6502, push_stack) Test(mos6502, push_stack)
{ {
START_CPU_TEST(mos6502);
mos6502_push_stack(cpu, 0x1234); mos6502_push_stack(cpu, 0x1234);
cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x12); cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x12);
cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x34); cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x34);
END_CPU_TEST(mos6502);
} }
Test(mos6502, pop_stack) Test(mos6502, pop_stack)
{ {
START_CPU_TEST(mos6502);
mos6502_push_stack(cpu, 0x1234); mos6502_push_stack(cpu, 0x1234);
cr_assert_eq(mos6502_pop_stack(cpu), 0x1234); cr_assert_eq(mos6502_pop_stack(cpu), 0x1234);
END_CPU_TEST(mos6502);
} }
Test(mos6502, modify_status) Test(mos6502, modify_status)
{ {
START_CPU_TEST(mos6502);
mos6502_modify_status(cpu, NEGATIVE, 130); mos6502_modify_status(cpu, NEGATIVE, 130);
cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE);
mos6502_modify_status(cpu, NEGATIVE, 123); mos6502_modify_status(cpu, NEGATIVE, 123);
@ -80,18 +66,12 @@ Test(mos6502, modify_status)
cr_assert_eq(cpu->P & ZERO, ZERO); cr_assert_eq(cpu->P & ZERO, ZERO);
mos6502_modify_status(cpu, ZERO, 1); mos6502_modify_status(cpu, ZERO, 1);
cr_assert_neq(cpu->P & ZERO, ZERO); cr_assert_neq(cpu->P & ZERO, ZERO);
END_CPU_TEST(mos6502);
} }
Test(mos6502, set_status) Test(mos6502, set_status)
{ {
START_CPU_TEST(mos6502);
mos6502_set_status(cpu, BREAK | INTERRUPT | DECIMAL); mos6502_set_status(cpu, BREAK | INTERRUPT | DECIMAL);
cr_assert_eq(cpu->P & (BREAK | INTERRUPT | DECIMAL), BREAK | INTERRUPT | DECIMAL); cr_assert_eq(cpu->P & (BREAK | INTERRUPT | DECIMAL), BREAK | INTERRUPT | DECIMAL);
END_CPU_TEST(mos6502);
} }
Test(mos6502, instruction) Test(mos6502, instruction)
@ -103,8 +83,6 @@ Test(mos6502, instruction)
Test(mos6502, cycles) Test(mos6502, cycles)
{ {
START_CPU_TEST(mos6502);
cr_assert_eq(mos6502_cycles(cpu, 0x76), 6); cr_assert_eq(mos6502_cycles(cpu, 0x76), 6);
cr_assert_eq(mos6502_cycles(cpu, 0xBA), 2); cr_assert_eq(mos6502_cycles(cpu, 0xBA), 2);
@ -118,8 +96,6 @@ Test(mos6502, cycles)
// cycles // cycles
cpu->X = 200; cpu->X = 200;
cr_assert_eq(mos6502_cycles(cpu, 0x1D), 5); cr_assert_eq(mos6502_cycles(cpu, 0x1D), 5);
END_CPU_TEST(mos6502);
} }
Test(mos6502, get_instruction_handler) Test(mos6502, get_instruction_handler)
@ -131,21 +107,13 @@ Test(mos6502, get_instruction_handler)
Test(mos6502, execute) Test(mos6502, execute)
{ {
START_CPU_TEST(mos6502);
vm_segment_set(cpu->memory, 0, 34); vm_segment_set(cpu->memory, 0, 34);
mos6502_execute(cpu, 0x69); mos6502_execute(cpu, 0x69);
cr_assert_eq(cpu->A, 34); cr_assert_eq(cpu->A, 34);
END_CPU_TEST(mos6502);
} }
Test(mos6502, read_byte) Test(mos6502, read_byte)
{ {
START_CPU_TEST(mos6502);
vm_segment_set(cpu->memory, 0, 0x54); vm_segment_set(cpu->memory, 0, 0x54);
cr_assert_eq(mos6502_read_byte(cpu), 0x54); cr_assert_eq(mos6502_read_byte(cpu), 0x54);
END_CPU_TEST(mos6502);
} }

View File

@ -2,73 +2,56 @@
#include "mos6502.h" #include "mos6502.h"
#include "mos6502.enums.h" #include "mos6502.enums.h"
#include "mos6502.tests.h"
Test(mos6502, brk) TestSuite(mos6502_exec, .init = setup, .fini = teardown);
Test(mos6502_exec, brk)
{ {
START_CPU_TEST(mos6502);
cpu->PC = 123; cpu->PC = 123;
mos6502_handle_brk(cpu, 0); mos6502_handle_brk(cpu, 0);
cr_assert_eq(cpu->PC, 125); cr_assert_eq(cpu->PC, 125);
cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT); cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT);
cr_assert_eq(mos6502_pop_stack(cpu), 123); cr_assert_eq(mos6502_pop_stack(cpu), 123);
END_CPU_TEST(mos6502);
} }
Test(mos6502, jmp) Test(mos6502_exec, jmp)
{ {
START_CPU_TEST(mos6502);
cpu->PC = 123; cpu->PC = 123;
cpu->last_addr = 234; cpu->last_addr = 234;
mos6502_handle_jmp(cpu, 0); mos6502_handle_jmp(cpu, 0);
cr_assert_eq(cpu->PC, 234); cr_assert_eq(cpu->PC, 234);
END_CPU_TEST(mos6502);
} }
Test(mos6502, jsr) Test(mos6502_exec, jsr)
{ {
START_CPU_TEST(mos6502);
cpu->PC = 123; cpu->PC = 123;
cpu->last_addr = 235; cpu->last_addr = 235;
mos6502_handle_jsr(cpu, 0); mos6502_handle_jsr(cpu, 0);
cr_assert_eq(cpu->PC, 235); cr_assert_eq(cpu->PC, 235);
cr_assert_eq(mos6502_pop_stack(cpu), 125); cr_assert_eq(mos6502_pop_stack(cpu), 125);
END_CPU_TEST(mos6502);
} }
Test(mos6502, nop) Test(mos6502_exec, nop)
{ {
// currently this test does nothing -- we _should_ test to see if we // currently this test does nothing -- we _should_ test to see if we
// pass the right number of cycles, though. // pass the right number of cycles, though.
} }
Test(mos6502, rti) Test(mos6502_exec, rti)
{ {
START_CPU_TEST(mos6502);
mos6502_push_stack(cpu, 222); mos6502_push_stack(cpu, 222);
mos6502_handle_rti(cpu, 0); mos6502_handle_rti(cpu, 0);
cr_assert_eq(cpu->PC, 222); cr_assert_eq(cpu->PC, 222);
END_CPU_TEST(mos6502);
} }
Test(mos6502, rts) Test(mos6502_exec, rts)
{ {
START_CPU_TEST(mos6502);
mos6502_push_stack(cpu, 333); mos6502_push_stack(cpu, 333);
mos6502_handle_rti(cpu, 0); mos6502_handle_rti(cpu, 0);
cr_assert_eq(cpu->PC, 333); cr_assert_eq(cpu->PC, 333);
END_CPU_TEST(mos6502);
} }

View File

@ -2,191 +2,130 @@
#include "mos6502.h" #include "mos6502.h"
#include "mos6502.enums.h" #include "mos6502.enums.h"
#include "mos6502.tests.h"
Test(mos6502, lda) TestSuite(mos6502_loadstor, .init = setup, .fini = teardown);
Test(mos6502_loadstor, lda)
{ {
START_CPU_TEST(mos6502);
mos6502_handle_lda(cpu, 123); mos6502_handle_lda(cpu, 123);
cr_assert_eq(cpu->A, 123); cr_assert_eq(cpu->A, 123);
END_CPU_TEST(mos6502);
} }
Test(mos6502, ldx) Test(mos6502_loadstor, ldx)
{ {
START_CPU_TEST(mos6502);
mos6502_handle_ldx(cpu, 123); mos6502_handle_ldx(cpu, 123);
cr_assert_eq(cpu->X, 123); cr_assert_eq(cpu->X, 123);
END_CPU_TEST(mos6502);
} }
Test(mos6502, ldy) Test(mos6502_loadstor, ldy)
{ {
START_CPU_TEST(mos6502);
mos6502_handle_ldy(cpu, 123); mos6502_handle_ldy(cpu, 123);
cr_assert_eq(cpu->Y, 123); cr_assert_eq(cpu->Y, 123);
END_CPU_TEST(mos6502);
} }
Test(mos6502, pha) Test(mos6502_loadstor, pha)
{ {
START_CPU_TEST(mos6502);
cpu->A = 0x24; cpu->A = 0x24;
mos6502_handle_pha(cpu, 0); mos6502_handle_pha(cpu, 0);
cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x00); cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x00);
cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x24); cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x24);
END_CPU_TEST(mos6502);
} }
Test(mos6502, php) Test(mos6502_loadstor, php)
{ {
START_CPU_TEST(mos6502);
cpu->P = 0x43; cpu->P = 0x43;
mos6502_handle_php(cpu, 0); mos6502_handle_php(cpu, 0);
cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x00); cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x00);
cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x43); cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x43);
END_CPU_TEST(mos6502);
} }
Test(mos6502, pla) Test(mos6502_loadstor, pla)
{ {
START_CPU_TEST(mos6502);
mos6502_push_stack(cpu, 0x0033); mos6502_push_stack(cpu, 0x0033);
mos6502_handle_pla(cpu, 0); mos6502_handle_pla(cpu, 0);
cr_assert_eq(cpu->A, 0x33); cr_assert_eq(cpu->A, 0x33);
END_CPU_TEST(mos6502);
} }
Test(mos6502, plp) Test(mos6502_loadstor, plp)
{ {
START_CPU_TEST(mos6502);
mos6502_push_stack(cpu, 0x0052); mos6502_push_stack(cpu, 0x0052);
mos6502_handle_plp(cpu, 0); mos6502_handle_plp(cpu, 0);
cr_assert_eq(cpu->P, 0x52); cr_assert_eq(cpu->P, 0x52);
END_CPU_TEST(mos6502);
} }
Test(mos6502, sta) Test(mos6502_loadstor, sta)
{ {
START_CPU_TEST(mos6502);
cpu->A = 123; cpu->A = 123;
cpu->last_addr = 555; cpu->last_addr = 555;
mos6502_handle_sta(cpu, 0); mos6502_handle_sta(cpu, 0);
cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->A); cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->A);
END_CPU_TEST(mos6502);
} }
Test(mos6502, stx) Test(mos6502_loadstor, stx)
{ {
START_CPU_TEST(mos6502);
cpu->X = 222; cpu->X = 222;
cpu->last_addr = 444; cpu->last_addr = 444;
mos6502_handle_stx(cpu, 0); mos6502_handle_stx(cpu, 0);
cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->X); cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->X);
END_CPU_TEST(mos6502);
} }
Test(mos6502, sty) Test(mos6502_loadstor, sty)
{ {
START_CPU_TEST(mos6502);
cpu->Y = 111; cpu->Y = 111;
cpu->last_addr = 253; cpu->last_addr = 253;
mos6502_handle_sty(cpu, 0); mos6502_handle_sty(cpu, 0);
cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->Y); cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->Y);
END_CPU_TEST(mos6502);
} }
Test(mos6502, tax) Test(mos6502_loadstor, tax)
{ {
START_CPU_TEST(mos6502);
cpu->A = 111; cpu->A = 111;
cpu->X = 222; cpu->X = 222;
mos6502_handle_tax(cpu, 0); mos6502_handle_tax(cpu, 0);
cr_assert_eq(cpu->X, 111); cr_assert_eq(cpu->X, 111);
END_CPU_TEST(mos6502);
} }
Test(mos6502, tay) Test(mos6502_loadstor, tay)
{ {
START_CPU_TEST(mos6502);
cpu->A = 111; cpu->A = 111;
cpu->Y = 115; cpu->Y = 115;
mos6502_handle_tay(cpu, 0); mos6502_handle_tay(cpu, 0);
cr_assert_eq(cpu->Y, 111); cr_assert_eq(cpu->Y, 111);
END_CPU_TEST(mos6502);
} }
Test(mos6502, tsx) Test(mos6502_loadstor, tsx)
{ {
START_CPU_TEST(mos6502);
cpu->S = 111; cpu->S = 111;
cpu->X = 222; cpu->X = 222;
mos6502_handle_tsx(cpu, 0); mos6502_handle_tsx(cpu, 0);
cr_assert_eq(cpu->X, 111); cr_assert_eq(cpu->X, 111);
END_CPU_TEST(mos6502);
} }
Test(mos6502, txa) Test(mos6502_loadstor, txa)
{ {
START_CPU_TEST(mos6502);
cpu->A = 111; cpu->A = 111;
cpu->X = 222; cpu->X = 222;
mos6502_handle_txa(cpu, 0); mos6502_handle_txa(cpu, 0);
cr_assert_eq(cpu->A, 222); cr_assert_eq(cpu->A, 222);
END_CPU_TEST(mos6502);
} }
Test(mos6502, txs) Test(mos6502_loadstor, txs)
{ {
START_CPU_TEST(mos6502);
cpu->S = 111; cpu->S = 111;
cpu->X = 222; cpu->X = 222;
mos6502_handle_txs(cpu, 0); mos6502_handle_txs(cpu, 0);
cr_assert_eq(cpu->S, 222); cr_assert_eq(cpu->S, 222);
END_CPU_TEST(mos6502);
} }
Test(mos6502, tya) Test(mos6502_loadstor, tya)
{ {
START_CPU_TEST(mos6502);
cpu->A = 111; cpu->A = 111;
cpu->Y = 222; cpu->Y = 222;
mos6502_handle_tya(cpu, 0); mos6502_handle_tya(cpu, 0);
cr_assert_eq(cpu->A, 222); cr_assert_eq(cpu->A, 222);
END_CPU_TEST(mos6502);
} }

View File

@ -2,81 +2,55 @@
#include "mos6502.h" #include "mos6502.h"
#include "mos6502.enums.h" #include "mos6502.enums.h"
#include "mos6502.tests.h"
Test(mos6502, clc) TestSuite(mos6502_stat, .init = setup, .fini = teardown);
Test(mos6502_stat, clc)
{ {
START_CPU_TEST(mos6502);
cpu->P = CARRY | DECIMAL; cpu->P = CARRY | DECIMAL;
mos6502_handle_clc(cpu, 0); mos6502_handle_clc(cpu, 0);
cr_assert_eq(cpu->P & CARRY, 0); cr_assert_eq(cpu->P & CARRY, 0);
END_CPU_TEST(mos6502);
} }
Test(mos6502, cld) Test(mos6502_stat, cld)
{ {
START_CPU_TEST(mos6502);
cpu->P = DECIMAL | CARRY; cpu->P = DECIMAL | CARRY;
mos6502_handle_cld(cpu, 0); mos6502_handle_cld(cpu, 0);
cr_assert_eq(cpu->P & DECIMAL, 0); cr_assert_eq(cpu->P & DECIMAL, 0);
END_CPU_TEST(mos6502);
} }
Test(mos6502, cli) Test(mos6502_stat, cli)
{ {
START_CPU_TEST(mos6502);
cpu->P = CARRY | INTERRUPT; cpu->P = CARRY | INTERRUPT;
mos6502_handle_cli(cpu, 0); mos6502_handle_cli(cpu, 0);
cr_assert_eq(cpu->P & INTERRUPT, 0); cr_assert_eq(cpu->P & INTERRUPT, 0);
END_CPU_TEST(mos6502);
} }
Test(mos6502, clv) Test(mos6502_stat, clv)
{ {
START_CPU_TEST(mos6502);
cpu->P = CARRY | OVERFLOW; cpu->P = CARRY | OVERFLOW;
mos6502_handle_clv(cpu, 0); mos6502_handle_clv(cpu, 0);
cr_assert_eq(cpu->P & OVERFLOW, 0); cr_assert_eq(cpu->P & OVERFLOW, 0);
END_CPU_TEST(mos6502);
} }
Test(mos6502, sec) Test(mos6502_stat, sec)
{ {
START_CPU_TEST(mos6502);
cpu->P = 0; cpu->P = 0;
mos6502_handle_sec(cpu, 0); mos6502_handle_sec(cpu, 0);
cr_assert_eq(cpu->P & CARRY, CARRY); cr_assert_eq(cpu->P & CARRY, CARRY);
END_CPU_TEST(mos6502);
} }
Test(mos6502, sed) Test(mos6502_stat, sed)
{ {
START_CPU_TEST(mos6502);
cpu->P = 0; cpu->P = 0;
mos6502_handle_sed(cpu, 0); mos6502_handle_sed(cpu, 0);
cr_assert_eq(cpu->P & DECIMAL, DECIMAL); cr_assert_eq(cpu->P & DECIMAL, DECIMAL);
END_CPU_TEST(mos6502);
} }
Test(mos6502, sei) Test(mos6502_stat, sei)
{ {
START_CPU_TEST(mos6502);
cpu->P = 0; cpu->P = 0;
mos6502_handle_sei(cpu, 0); mos6502_handle_sei(cpu, 0);
cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT); cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT);
END_CPU_TEST(mos6502);
} }