1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-24 14:32:08 +00:00
erc-c/tests/mos6502.bits.c

112 lines
2.5 KiB
C
Raw Normal View History

2017-12-04 02:19:17 +00:00
#include <criterion/criterion.h>
#include "mos6502.h"
#include "mos6502.enums.h"
#include "mos6502.tests.h"
2017-12-04 02:19:17 +00:00
TestSuite(mos6502_bits, .init = setup, .fini = teardown);
2017-12-04 02:19:17 +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);
}
Test(mos6502_bits, asl)
2017-12-04 02:19:17 +00:00
{
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);
}
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
}
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);
}
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
cpu->last_addr = 123;
mos6502_handle_lsr(cpu, 22);
cr_assert_eq(vm_segment_get(cpu->memory, 123), 11);
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
}
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);
}
Test(mos6502_bits, rol)
2017-12-04 02:19:17 +00:00
{
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);
}
Test(mos6502_bits, ror)
2017-12-04 02:19:17 +00:00
{
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);
}