1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-27 20:51:17 +00:00
erc-c/tests/mos6502.bits.c
Peter Evans 00ff9f069d 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.
2017-12-06 15:57:15 -06:00

112 lines
2.4 KiB
C

#include <criterion/criterion.h>
#include "mos6502.h"
#include "mos6502.enums.h"
#include "mos6502.tests.h"
TestSuite(mos6502_bits, .init = setup, .fini = teardown);
Test(mos6502_bits, and)
{
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)
{
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)
{
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);
}
Test(mos6502_bits, eor)
{
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)
{
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);
}
Test(mos6502_bits, ora)
{
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)
{
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)
{
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);
}