diff --git a/include/mos6502.h b/include/mos6502.h index 66805bb..9f097cf 100644 --- a/include/mos6502.h +++ b/include/mos6502.h @@ -82,7 +82,8 @@ extern void mos6502_free(mos6502 *); extern vm_8bit mos6502_next_byte(mos6502 *); extern void mos6502_push_stack(mos6502 *, vm_16bit); extern vm_16bit mos6502_pop_stack(mos6502 *); -extern void mos6502_modify_status(mos6502 *, int, vm_8bit); +extern void mos6502_set_status(mos6502 *, vm_8bit); +extern void mos6502_modify_status(mos6502 *, vm_8bit, vm_8bit); extern mos6502_address_resolver mos6502_get_address_resolver(int); diff --git a/src/mos6502.arith.c b/src/mos6502.arith.c index 83693a7..72744d7 100644 --- a/src/mos6502.arith.c +++ b/src/mos6502.arith.c @@ -63,5 +63,5 @@ DEFINE_INST(iny) DEFINE_INST(sbc) { CARRY_BIT(); - cpu->A -= oper - carry; + cpu->A = cpu->A - oper - carry; } diff --git a/src/mos6502.bits.c b/src/mos6502.bits.c index 8f9fbce..a81f5e0 100644 --- a/src/mos6502.bits.c +++ b/src/mos6502.bits.c @@ -12,12 +12,13 @@ DEFINE_INST(and) DEFINE_INST(asl) { - oper <<= 1; - + cpu->P &= ~CARRY; if (oper & 0x80) { cpu->P |= CARRY; } + oper <<= 1; + if (cpu->last_addr) { vm_segment_set(cpu->memory, cpu->last_addr, oper); } else { @@ -27,18 +28,20 @@ DEFINE_INST(asl) DEFINE_INST(bit) { + cpu->P &= ~NEGATIVE; if (oper & NEGATIVE) { cpu->P |= NEGATIVE; } + cpu->P &= ~OVERFLOW; if (oper & OVERFLOW) { cpu->P |= OVERFLOW; } if (oper & cpu->A) { - cpu->P |= ZERO; - } else { cpu->P &= ~ZERO; + } else { + cpu->P |= ZERO; } } @@ -49,12 +52,13 @@ DEFINE_INST(eor) DEFINE_INST(lsr) { - oper >>= 1; - + cpu->P &= ~CARRY; if (oper & 0x01) { cpu->P |= CARRY; } + oper >>= 1; + if (cpu->last_addr) { vm_segment_set(cpu->memory, cpu->last_addr, oper); } else { diff --git a/src/mos6502.c b/src/mos6502.c index c6b06c7..d945afc 100644 --- a/src/mos6502.c +++ b/src/mos6502.c @@ -133,48 +133,39 @@ mos6502_pop_stack(mos6502 *cpu) } void -mos6502_modify_status(mos6502 *cpu, int statuses, vm_8bit oper) +mos6502_set_status(mos6502 *cpu, vm_8bit status) { - if (statuses & NEGATIVE) { + cpu->P = status; +} + +void +mos6502_modify_status(mos6502 *cpu, vm_8bit status, vm_8bit oper) +{ + if (status & NEGATIVE) { cpu->P &= ~NEGATIVE; if (oper & 0x80) { cpu->P |= NEGATIVE; } } - if (statuses & OVERFLOW) { + if (status & OVERFLOW) { cpu->P &= ~OVERFLOW; if (oper & OVERFLOW) { cpu->P |= OVERFLOW; } } - // We're kind of dumb about break, decimal and interrupt. I'm - // probably lacking some knowledge about how these work... - if (statuses & BREAK) { - cpu->P |= BREAK; - } - - if (statuses & DECIMAL) { - cpu->P |= DECIMAL; - } - - if (statuses & INTERRUPT) { - cpu->P |= INTERRUPT; - } - - if (statuses & CARRY) { + if (status & CARRY) { cpu->P &= ~CARRY; if (oper > 0) { cpu->P |= CARRY; } } - if (statuses & ZERO) { + if (status & ZERO) { cpu->P &= ~ZERO; if (oper == 0) { cpu->P |= ZERO; } } - } diff --git a/tests/mos6502.arith.c b/tests/mos6502.arith.c new file mode 100644 index 0000000..931d5f7 --- /dev/null +++ b/tests/mos6502.arith.c @@ -0,0 +1,163 @@ +#include + +#include "mos6502.h" +#include "mos6502.enums.h" + +Test(mos6502, adc) +{ + START_CPU_TEST(mos6502); + + cpu->A = 5; + mos6502_handle_adc(cpu, 3); + cr_assert_eq(cpu->A, 8); + + cpu->P |= CARRY; + mos6502_handle_adc(cpu, 64); + cr_assert_eq(cpu->A, 73); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, cmp) +{ + START_CPU_TEST(mos6502); + + cpu->A = 5; + mos6502_handle_cmp(cpu, 3); + cr_assert_eq(cpu->P & CARRY, CARRY); + cr_assert_eq(cpu->P & NEGATIVE, 0); + cr_assert_eq(cpu->P & ZERO, 0); + + cpu->A = 3; + mos6502_handle_cmp(cpu, 3); + cr_assert_eq(cpu->P & CARRY, 0); + cr_assert_eq(cpu->P & NEGATIVE, 0); + cr_assert_eq(cpu->P & ZERO, ZERO); + + cpu->A = 192; + mos6502_handle_cmp(cpu, 3); + cr_assert_eq(cpu->P & CARRY, CARRY); + cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); + cr_assert_eq(cpu->P & ZERO, 0); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, cpx) +{ + START_CPU_TEST(mos6502); + + cpu->X = 5; + mos6502_handle_cpx(cpu, 3); + cr_assert_eq(cpu->P & CARRY, CARRY); + cr_assert_eq(cpu->P & NEGATIVE, 0); + cr_assert_eq(cpu->P & ZERO, 0); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, cpy) +{ + START_CPU_TEST(mos6502); + + cpu->Y = 5; + mos6502_handle_cpy(cpu, 3); + cr_assert_eq(cpu->P & CARRY, CARRY); + cr_assert_eq(cpu->P & NEGATIVE, 0); + cr_assert_eq(cpu->P & ZERO, 0); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, dec) +{ + START_CPU_TEST(mos6502); + + // Note that DEC does NOT decrement the accumulator if the last + // address is not set. It does _nothing_. + cpu->A = 5; + mos6502_handle_dec(cpu, 0); + cr_assert_neq(cpu->A, 4); + + cpu->last_addr = 123; + vm_segment_set(cpu->memory, 123, 44); + + // Note _also_ that DEC expects the number to be decremented will be + // passed in as the effective operand, although it doesn't + // necessarily need for that to be so. + mos6502_handle_dec(cpu, 44); + cr_assert_eq(vm_segment_get(cpu->memory, 123), 43); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, dex) +{ + START_CPU_TEST(mos6502); + + cpu->X = 5; + mos6502_handle_dex(cpu, 0); + cr_assert_eq(cpu->X, 4); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, dey) +{ + START_CPU_TEST(mos6502); + + cpu->Y = 5; + mos6502_handle_dey(cpu, 0); + cr_assert_eq(cpu->Y, 4); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, inc) +{ + START_CPU_TEST(mos6502); + + cpu->last_addr = 123; + mos6502_handle_inc(cpu, 55); + cr_assert_eq(vm_segment_get(cpu->memory, 123), 56); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, inx) +{ + START_CPU_TEST(mos6502); + + cpu->X = 5; + mos6502_handle_inx(cpu, 0); + cr_assert_eq(cpu->X, 6); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, iny) +{ + START_CPU_TEST(mos6502); + + cpu->Y = 5; + mos6502_handle_iny(cpu, 0); + cr_assert_eq(cpu->Y, 6); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, sbc) +{ + START_CPU_TEST(mos6502); + + cpu->A = 5; + mos6502_handle_sbc(cpu, 3); + cr_assert_eq(cpu->A, 2); + + cpu->P |= CARRY; + cpu->A = 16; + mos6502_handle_sbc(cpu, 8); + cr_assert_eq(cpu->A, 7); + + END_CPU_TEST(mos6502); +} diff --git a/tests/mos6502.bits.c b/tests/mos6502.bits.c new file mode 100644 index 0000000..666f2fd --- /dev/null +++ b/tests/mos6502.bits.c @@ -0,0 +1,140 @@ +#include + +#include "mos6502.h" +#include "mos6502.enums.h" + +Test(mos6502, and) +{ + START_CPU_TEST(mos6502); + + cpu->A = 5; + mos6502_handle_and(cpu, 1); + cr_assert_eq(cpu->A, 1); + + cpu->A = 5; + mos6502_handle_and(cpu, 4); + cr_assert_eq(cpu->A, 4); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, asl) +{ + START_CPU_TEST(mos6502); + + mos6502_handle_asl(cpu, 5); + cr_assert_eq(cpu->A, 10); + + cpu->last_addr = 123; + mos6502_handle_asl(cpu, 22); + cr_assert_eq(vm_segment_get(cpu->memory, 123), 44); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, bit) +{ + START_CPU_TEST(mos6502); + + cpu->A = 5; + mos6502_handle_bit(cpu, 129); + cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); + cr_assert_eq(cpu->P & OVERFLOW, 0); + cr_assert_eq(cpu->P & ZERO, 0); + + mos6502_handle_bit(cpu, 193); + cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); + cr_assert_eq(cpu->P & OVERFLOW, OVERFLOW); + cr_assert_eq(cpu->P & ZERO, 0); + + mos6502_handle_bit(cpu, 65); + cr_assert_eq(cpu->P & NEGATIVE, 0); + cr_assert_eq(cpu->P & OVERFLOW, OVERFLOW); + cr_assert_eq(cpu->P & ZERO, 0); + + mos6502_handle_bit(cpu, 33); + cr_assert_eq(cpu->P & NEGATIVE, 0); + cr_assert_eq(cpu->P & OVERFLOW, 0); + cr_assert_eq(cpu->P & ZERO, 0); + + mos6502_handle_bit(cpu, 0); + cr_assert_eq(cpu->P & NEGATIVE, 0); + cr_assert_eq(cpu->P & OVERFLOW, 0); + cr_assert_eq(cpu->P & ZERO, ZERO); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, eor) +{ + START_CPU_TEST(mos6502); + + cpu->A = 5; + mos6502_handle_eor(cpu, 4); + cr_assert_eq(cpu->A, 1); + + cpu->A = 5; + mos6502_handle_eor(cpu, 1); + cr_assert_eq(cpu->A, 4); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, lsr) +{ + START_CPU_TEST(mos6502); + + mos6502_handle_lsr(cpu, 5); + cr_assert_eq(cpu->A, 2); + cr_assert_eq(cpu->P & CARRY, CARRY); + + cpu->last_addr = 123; + mos6502_handle_lsr(cpu, 22); + cr_assert_eq(vm_segment_get(cpu->memory, 123), 11); + cr_assert_eq(cpu->P & CARRY, 0); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, ora) +{ + START_CPU_TEST(mos6502); + + cpu->A = 5; + mos6502_handle_ora(cpu, 4); + cr_assert_eq(cpu->A, 5); + + cpu->A = 5; + mos6502_handle_ora(cpu, 10); + cr_assert_eq(cpu->A, 15); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, rol) +{ + START_CPU_TEST(mos6502); + + mos6502_handle_rol(cpu, 8); + cr_assert_eq(cpu->A, 16); + + cpu->last_addr = 234; + mos6502_handle_rol(cpu, 128); + cr_assert_eq(vm_segment_get(cpu->memory, 234), 1); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, ror) +{ + START_CPU_TEST(mos6502); + + mos6502_handle_ror(cpu, 64); + cr_assert_eq(cpu->A, 32); + + cpu->last_addr = 123; + mos6502_handle_ror(cpu, 1); + cr_assert_eq(vm_segment_get(cpu->memory, 123), 128); + + END_CPU_TEST(mos6502); +} diff --git a/tests/mos6502.branch.c b/tests/mos6502.branch.c new file mode 100644 index 0000000..e3f7ed1 --- /dev/null +++ b/tests/mos6502.branch.c @@ -0,0 +1,132 @@ +#include + +#include "mos6502.h" +#include "mos6502.enums.h" + +Test(mos6502, bcc) +{ + START_CPU_TEST(mos6502); + + cpu->last_addr = 123; + mos6502_handle_bcc(cpu, 0); + cr_assert_eq(cpu->PC, 123); + + cpu->P |= CARRY; + cpu->last_addr = 125; + mos6502_handle_bcc(cpu, 0); + cr_assert_neq(cpu->PC, 125); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, bcs) +{ + START_CPU_TEST(mos6502); + + cpu->last_addr = 123; + mos6502_handle_bcs(cpu, 0); + cr_assert_neq(cpu->PC, 123); + + cpu->P |= CARRY; + cpu->last_addr = 125; + mos6502_handle_bcs(cpu, 0); + cr_assert_eq(cpu->PC, 125); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, beq) +{ + START_CPU_TEST(mos6502); + + cpu->last_addr = 123; + mos6502_handle_beq(cpu, 0); + cr_assert_neq(cpu->PC, 123); + + cpu->P |= ZERO; + cpu->last_addr = 125; + mos6502_handle_beq(cpu, 0); + cr_assert_eq(cpu->PC, 125); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, bmi) +{ + START_CPU_TEST(mos6502); + + cpu->last_addr = 123; + mos6502_handle_bmi(cpu, 0); + cr_assert_neq(cpu->PC, 123); + + cpu->P |= NEGATIVE; + cpu->last_addr = 125; + mos6502_handle_bmi(cpu, 0); + cr_assert_eq(cpu->PC, 125); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, bne) +{ + START_CPU_TEST(mos6502); + + cpu->last_addr = 123; + mos6502_handle_bne(cpu, 0); + cr_assert_eq(cpu->PC, 123); + + cpu->P |= ZERO; + cpu->last_addr = 125; + mos6502_handle_bne(cpu, 0); + cr_assert_neq(cpu->PC, 125); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, bpl) +{ + START_CPU_TEST(mos6502); + + cpu->last_addr = 123; + mos6502_handle_bpl(cpu, 0); + cr_assert_eq(cpu->PC, 123); + + cpu->P |= NEGATIVE; + cpu->last_addr = 125; + mos6502_handle_bpl(cpu, 0); + cr_assert_neq(cpu->PC, 125); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, bvc) +{ + START_CPU_TEST(mos6502); + + cpu->last_addr = 123; + mos6502_handle_bvc(cpu, 0); + cr_assert_eq(cpu->PC, 123); + + cpu->P |= OVERFLOW; + cpu->last_addr = 125; + mos6502_handle_bvc(cpu, 0); + cr_assert_neq(cpu->PC, 125); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, bvs) +{ + START_CPU_TEST(mos6502); + + cpu->last_addr = 123; + mos6502_handle_bvs(cpu, 0); + cr_assert_neq(cpu->PC, 123); + + cpu->P |= OVERFLOW; + cpu->last_addr = 125; + mos6502_handle_bvs(cpu, 0); + cr_assert_eq(cpu->PC, 125); + + END_CPU_TEST(mos6502); +} diff --git a/tests/mos6502.c b/tests/mos6502.c index 3454249..4d24b17 100644 --- a/tests/mos6502.c +++ b/tests/mos6502.c @@ -71,11 +71,6 @@ Test(mos6502, modify_status) mos6502_modify_status(cpu, OVERFLOW, 44); cr_assert_neq(cpu->P & OVERFLOW, OVERFLOW); - mos6502_modify_status(cpu, BREAK, 0); - mos6502_modify_status(cpu, INTERRUPT, 0); - mos6502_modify_status(cpu, DECIMAL, 0); - cr_assert_eq(cpu->P & BREAK & INTERRUPT & DECIMAL, BREAK & INTERRUPT & DECIMAL); - mos6502_modify_status(cpu, CARRY, 23); cr_assert_eq(cpu->P & CARRY, CARRY); mos6502_modify_status(cpu, CARRY, 0); @@ -88,3 +83,13 @@ Test(mos6502, modify_status) END_CPU_TEST(mos6502); } + +Test(mos6502, set_status) +{ + START_CPU_TEST(mos6502); + + mos6502_set_status(cpu, BREAK | INTERRUPT | DECIMAL); + cr_assert_eq(cpu->P & (BREAK | INTERRUPT | DECIMAL), BREAK | INTERRUPT | DECIMAL); + + END_CPU_TEST(mos6502); +} diff --git a/tests/mos6502.exec.c b/tests/mos6502.exec.c new file mode 100644 index 0000000..e2954f1 --- /dev/null +++ b/tests/mos6502.exec.c @@ -0,0 +1,74 @@ +#include + +#include "mos6502.h" +#include "mos6502.enums.h" + +Test(mos6502, brk) +{ + START_CPU_TEST(mos6502); + + 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), 123); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, jmp) +{ + START_CPU_TEST(mos6502); + + cpu->PC = 123; + cpu->last_addr = 234; + mos6502_handle_jmp(cpu, 0); + + cr_assert_eq(cpu->PC, 234); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, jsr) +{ + START_CPU_TEST(mos6502); + + cpu->PC = 123; + cpu->last_addr = 235; + mos6502_handle_jsr(cpu, 0); + + cr_assert_eq(cpu->PC, 235); + cr_assert_eq(mos6502_pop_stack(cpu), 125); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, nop) +{ + // currently this test does nothing -- we _should_ test to see if we + // pass the right number of cycles, though. +} + +Test(mos6502, rti) +{ + START_CPU_TEST(mos6502); + + mos6502_push_stack(cpu, 222); + mos6502_handle_rti(cpu, 0); + + cr_assert_eq(cpu->PC, 222); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, rts) +{ + START_CPU_TEST(mos6502); + + mos6502_push_stack(cpu, 333); + mos6502_handle_rti(cpu, 0); + + cr_assert_eq(cpu->PC, 333); + + END_CPU_TEST(mos6502); +} diff --git a/tests/mos6502.loadstor.c b/tests/mos6502.loadstor.c index d6e062a..ae45054 100644 --- a/tests/mos6502.loadstor.c +++ b/tests/mos6502.loadstor.c @@ -2,3 +2,191 @@ #include "mos6502.h" #include "mos6502.enums.h" + +Test(mos6502, lda) +{ + START_CPU_TEST(mos6502); + + mos6502_handle_lda(cpu, 123); + cr_assert_eq(cpu->A, 123); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, ldx) +{ + START_CPU_TEST(mos6502); + + mos6502_handle_ldx(cpu, 123); + cr_assert_eq(cpu->X, 123); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, ldy) +{ + START_CPU_TEST(mos6502); + + mos6502_handle_ldy(cpu, 123); + cr_assert_eq(cpu->Y, 123); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, pha) +{ + START_CPU_TEST(mos6502); + + cpu->A = 0x24; + mos6502_handle_pha(cpu, 0); + + cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x00); + cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x24); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, php) +{ + START_CPU_TEST(mos6502); + + cpu->P = 0x43; + mos6502_handle_php(cpu, 0); + + cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x00); + cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x43); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, pla) +{ + START_CPU_TEST(mos6502); + + mos6502_push_stack(cpu, 0x0033); + mos6502_handle_pla(cpu, 0); + + cr_assert_eq(cpu->A, 0x33); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, plp) +{ + START_CPU_TEST(mos6502); + + mos6502_push_stack(cpu, 0x0052); + mos6502_handle_plp(cpu, 0); + + cr_assert_eq(cpu->P, 0x52); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, sta) +{ + START_CPU_TEST(mos6502); + + cpu->A = 123; + cpu->last_addr = 555; + mos6502_handle_sta(cpu, 0); + cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->A); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, stx) +{ + START_CPU_TEST(mos6502); + + cpu->X = 222; + cpu->last_addr = 444; + mos6502_handle_stx(cpu, 0); + cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->X); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, sty) +{ + START_CPU_TEST(mos6502); + + cpu->Y = 111; + cpu->last_addr = 253; + mos6502_handle_sty(cpu, 0); + cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->Y); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, tax) +{ + START_CPU_TEST(mos6502); + + cpu->A = 111; + cpu->X = 222; + mos6502_handle_tax(cpu, 0); + cr_assert_eq(cpu->X, 111); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, tay) +{ + START_CPU_TEST(mos6502); + + cpu->A = 111; + cpu->Y = 115; + mos6502_handle_tay(cpu, 0); + cr_assert_eq(cpu->Y, 111); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, tsx) +{ + START_CPU_TEST(mos6502); + + cpu->S = 111; + cpu->X = 222; + mos6502_handle_tsx(cpu, 0); + cr_assert_eq(cpu->X, 111); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, txa) +{ + START_CPU_TEST(mos6502); + + cpu->A = 111; + cpu->X = 222; + mos6502_handle_txa(cpu, 0); + cr_assert_eq(cpu->A, 222); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, txs) +{ + START_CPU_TEST(mos6502); + + cpu->S = 111; + cpu->X = 222; + mos6502_handle_txs(cpu, 0); + cr_assert_eq(cpu->S, 222); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, tya) +{ + START_CPU_TEST(mos6502); + + cpu->A = 111; + cpu->Y = 222; + mos6502_handle_tya(cpu, 0); + cr_assert_eq(cpu->A, 222); + + END_CPU_TEST(mos6502); +} diff --git a/tests/mos6502.stat.c b/tests/mos6502.stat.c new file mode 100644 index 0000000..47d0de8 --- /dev/null +++ b/tests/mos6502.stat.c @@ -0,0 +1,82 @@ +#include + +#include "mos6502.h" +#include "mos6502.enums.h" + +Test(mos6502, clc) +{ + START_CPU_TEST(mos6502); + + cpu->P = CARRY | DECIMAL; + mos6502_handle_clc(cpu, 0); + cr_assert_eq(cpu->P & CARRY, 0); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, cld) +{ + START_CPU_TEST(mos6502); + + cpu->P = DECIMAL | CARRY; + mos6502_handle_cld(cpu, 0); + cr_assert_eq(cpu->P & DECIMAL, 0); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, cli) +{ + START_CPU_TEST(mos6502); + + cpu->P = CARRY | INTERRUPT; + mos6502_handle_cli(cpu, 0); + cr_assert_eq(cpu->P & INTERRUPT, 0); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, clv) +{ + START_CPU_TEST(mos6502); + + cpu->P = CARRY | OVERFLOW; + mos6502_handle_clv(cpu, 0); + cr_assert_eq(cpu->P & OVERFLOW, 0); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, sec) +{ + START_CPU_TEST(mos6502); + + cpu->P = 0; + mos6502_handle_sec(cpu, 0); + cr_assert_eq(cpu->P & CARRY, CARRY); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, sed) +{ + START_CPU_TEST(mos6502); + + cpu->P = 0; + mos6502_handle_sed(cpu, 0); + cr_assert_eq(cpu->P & DECIMAL, DECIMAL); + + END_CPU_TEST(mos6502); +} + +Test(mos6502, sei) +{ + START_CPU_TEST(mos6502); + + cpu->P = 0; + mos6502_handle_sei(cpu, 0); + cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT); + + END_CPU_TEST(mos6502); +} +