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_bits, .init = setup, .fini = teardown);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_bits, and)
|
|
|
|
{
|
2017-12-04 02:19:17 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_bits, asl)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
mos6502_handle_asl(cpu, 5);
|
|
|
|
cr_assert_eq(cpu->A, 10);
|
|
|
|
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_asl(cpu, 22);
|
2018-01-11 03:28:05 +00:00
|
|
|
cr_assert_eq(mos6502_get(cpu, 123), 44);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_bits, bit)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
cpu->A = 5;
|
|
|
|
mos6502_handle_bit(cpu, 129);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE);
|
|
|
|
cr_assert_eq(cpu->P & MOS_OVERFLOW, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
|
|
|
mos6502_handle_bit(cpu, 193);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE);
|
|
|
|
cr_assert_eq(cpu->P & MOS_OVERFLOW, MOS_OVERFLOW);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
|
|
|
mos6502_handle_bit(cpu, 65);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_OVERFLOW, MOS_OVERFLOW);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
|
|
|
mos6502_handle_bit(cpu, 33);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_OVERFLOW, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
|
|
|
mos6502_handle_bit(cpu, 0);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_OVERFLOW, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, MOS_ZERO);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:01:46 +00:00
|
|
|
Test(mos6502_bits, bim)
|
|
|
|
{
|
|
|
|
// This version of BIT should not modify the NV flags
|
|
|
|
cpu->P |= MOS_NEGATIVE;
|
|
|
|
cpu->P |= MOS_OVERFLOW;
|
|
|
|
|
|
|
|
cpu->A = 63;
|
|
|
|
mos6502_handle_bim(cpu, 123);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
|
|
|
cr_assert_eq(cpu->P & MOS_NEGATIVE, MOS_NEGATIVE);
|
|
|
|
cr_assert_eq(cpu->P & MOS_OVERFLOW, MOS_OVERFLOW);
|
|
|
|
|
|
|
|
cpu->A = 4;
|
|
|
|
mos6502_handle_bim(cpu, 123);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, MOS_ZERO);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_bits, eor)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_bits, lsr)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
mos6502_handle_lsr(cpu, 5);
|
|
|
|
cr_assert_eq(cpu->A, 2);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2018-01-24 02:26:01 +00:00
|
|
|
mos6502_handle_lsr(cpu, 11);
|
|
|
|
cr_assert_eq(mos6502_get(cpu, 123), 5);
|
2018-01-05 20:18:39 +00:00
|
|
|
cr_assert_eq(cpu->P & MOS_CARRY, MOS_CARRY);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_bits, ora)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_bits, rol)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
mos6502_handle_rol(cpu, 8);
|
2018-01-24 02:26:01 +00:00
|
|
|
cr_assert_eq(cpu->A, 17);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 234;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_rol(cpu, 128);
|
2018-02-20 03:59:55 +00:00
|
|
|
cr_assert_eq(mos6502_get(cpu, 234), 0);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_bits, ror)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
|
|
|
mos6502_handle_ror(cpu, 64);
|
2018-01-24 02:26:01 +00:00
|
|
|
cr_assert_eq(cpu->A, 160);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2018-02-20 04:01:30 +00:00
|
|
|
mos6502_handle_ror(cpu, 1);
|
2018-02-20 03:59:55 +00:00
|
|
|
mos6502_handle_ror(cpu, 0);
|
2018-01-11 03:28:05 +00:00
|
|
|
cr_assert_eq(mos6502_get(cpu, 123), 128);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
2018-02-22 19:39:48 +00:00
|
|
|
|
|
|
|
Test(mos6502_bits, trb)
|
|
|
|
{
|
|
|
|
cpu->A = 6;
|
|
|
|
mos6502_handle_trb(cpu, 3);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
|
|
|
cpu->A = 9;
|
|
|
|
mos6502_handle_trb(cpu, 2);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, MOS_ZERO);
|
|
|
|
|
|
|
|
cpu->eff_addr = 111;
|
|
|
|
mos6502_set(cpu, cpu->eff_addr, 123);
|
|
|
|
mos6502_handle_trb(cpu, 123);
|
|
|
|
|
|
|
|
cr_assert_eq(mos6502_get(cpu, cpu->eff_addr),
|
|
|
|
(cpu->A ^ 0xff) & 123);
|
|
|
|
}
|
|
|
|
|
|
|
|
Test(mos6502_bits, tsb)
|
|
|
|
{
|
|
|
|
// I borrowed this code from the trb test; TSB and TRB do exactly
|
|
|
|
// the same thing in regards to the zero bit.
|
|
|
|
cpu->A = 6;
|
|
|
|
mos6502_handle_trb(cpu, 3);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, 0);
|
|
|
|
cpu->A = 9;
|
|
|
|
mos6502_handle_trb(cpu, 2);
|
|
|
|
cr_assert_eq(cpu->P & MOS_ZERO, MOS_ZERO);
|
|
|
|
|
|
|
|
// This is similar to the segment in the trb test that focuses on
|
|
|
|
// the resetting (clearing) of bits, but modified to account for the
|
|
|
|
// differing result that tsb would provide--namely that the 1s in A
|
|
|
|
// will be set in the location in memory, rather than cleared.
|
|
|
|
cpu->eff_addr = 111;
|
|
|
|
mos6502_set(cpu, cpu->eff_addr, 123);
|
|
|
|
mos6502_handle_tsb(cpu, 123);
|
|
|
|
|
|
|
|
cr_assert_eq(mos6502_get(cpu, cpu->eff_addr), cpu->A | 123);
|
|
|
|
}
|
|
|
|
|