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_arith, .init = setup, .fini = teardown);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, adc)
|
|
|
|
{
|
2017-12-04 02:19:17 +00:00
|
|
|
cpu->A = 5;
|
|
|
|
mos6502_handle_adc(cpu, 3);
|
2018-01-23 22:28:39 +00:00
|
|
|
cr_assert_eq(cpu->A, 9);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-23 22:28:39 +00:00
|
|
|
cpu->P &= ~MOS_CARRY;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_adc(cpu, 64);
|
|
|
|
cr_assert_eq(cpu->A, 73);
|
2018-02-27 02:02:58 +00:00
|
|
|
|
|
|
|
// This should handle decimal mode without complaint
|
|
|
|
cpu->P |= MOS_DECIMAL;
|
|
|
|
cpu->A = 0x18;
|
|
|
|
mos6502_handle_adc(cpu, 0x3);
|
|
|
|
cr_assert_eq(cpu->A, 0x21);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 06:46:07 +00:00
|
|
|
Test(mos6502_arith, adc_dec)
|
|
|
|
{
|
|
|
|
cpu->P &= ~MOS_CARRY;
|
|
|
|
cpu->A = 0x05;
|
|
|
|
mos6502_handle_adc_dec(cpu, 0x10);
|
|
|
|
cr_assert_eq(cpu->A, 0x15);
|
|
|
|
|
|
|
|
// Test that A + M + 1 works for carry
|
|
|
|
cpu->P |= MOS_CARRY;
|
|
|
|
mos6502_handle_adc_dec(cpu, 0x13);
|
|
|
|
cr_assert_eq(cpu->A, 0x29);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, cmp)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->A = 5;
|
|
|
|
mos6502_handle_cmp(cpu, 3);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY);
|
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
|
|
|
cpu->A = 3;
|
2018-01-23 22:29:08 +00:00
|
|
|
mos6502_handle_cmp(cpu, 4);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_CARRY, 0);
|
2018-01-23 22:29:53 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
|
|
|
cpu->A = 192;
|
|
|
|
mos6502_handle_cmp(cpu, 3);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY);
|
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, cpx)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->X = 5;
|
|
|
|
mos6502_handle_cpx(cpu, 3);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY);
|
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, cpy)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->Y = 5;
|
|
|
|
mos6502_handle_cpy(cpu, 3);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY);
|
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, dec)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->A = 5;
|
|
|
|
mos6502_handle_dec(cpu, 0);
|
2018-02-22 03:20:05 +00:00
|
|
|
cr_assert_eq(cpu->A, 4);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2018-01-11 03:28:05 +00:00
|
|
|
mos6502_set(cpu, 123, 44);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
|
|
|
// 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);
|
2018-01-11 03:28:05 +00:00
|
|
|
cr_assert_eq(mos6502_get(cpu, 123), 43);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, dex)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->X = 5;
|
|
|
|
mos6502_handle_dex(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->X, 4);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, dey)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->Y = 5;
|
|
|
|
mos6502_handle_dey(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->Y, 4);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, inc)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_inc(cpu, 55);
|
2018-01-11 03:28:05 +00:00
|
|
|
cr_assert_eq(mos6502_get(cpu, 123), 56);
|
2018-02-22 03:20:05 +00:00
|
|
|
|
|
|
|
cpu->A = 8;
|
|
|
|
cpu->eff_addr = 0;
|
|
|
|
mos6502_handle_inc(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->A, 9);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, inx)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->X = 5;
|
|
|
|
mos6502_handle_inx(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->X, 6);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, iny)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->Y = 5;
|
|
|
|
mos6502_handle_iny(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->Y, 6);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_arith, sbc)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->A = 5;
|
|
|
|
mos6502_handle_sbc(cpu, 3);
|
2018-02-27 00:58:35 +00:00
|
|
|
cr_assert_eq(cpu->A, 2);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-23 22:30:52 +00:00
|
|
|
cpu->P &= ~MOS_CARRY;
|
2017-12-04 02:19:17 +00:00
|
|
|
cpu->A = 16;
|
|
|
|
mos6502_handle_sbc(cpu, 8);
|
2018-02-27 00:58:35 +00:00
|
|
|
cr_assert_eq(cpu->A, 7);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
2018-02-23 06:46:07 +00:00
|
|
|
|
|
|
|
Test(mos6502_arith, sbc_dec)
|
|
|
|
{
|
|
|
|
cpu->P = 0;
|
|
|
|
cpu->A = 0x15;
|
|
|
|
mos6502_handle_sbc_dec(cpu, 0x6);
|
2018-02-27 00:58:35 +00:00
|
|
|
cr_assert_eq(cpu->A, 0x8);
|
2018-02-23 06:46:07 +00:00
|
|
|
|
|
|
|
cpu->P |= MOS_CARRY;
|
|
|
|
cpu->A = 0x12;
|
|
|
|
mos6502_handle_sbc_dec(cpu, 0x2);
|
2018-02-27 00:58:35 +00:00
|
|
|
cr_assert_eq(cpu->A, 0x10);
|
2018-02-23 06:46:07 +00:00
|
|
|
}
|