1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-06-11 05:29:33 +00:00

Tests for the new mos6502 functions

This commit is contained in:
Peter Evans 2017-12-02 13:27:30 -06:00
parent 3cebed2377
commit fe9ce3aca3
4 changed files with 91 additions and 4 deletions

View File

@ -24,6 +24,13 @@
#define END_ADDR_MODE() \
mos6502_free(cpu)
#define START_CPU_TEST(t) \
t *cpu; \
cpu = t##_create()
#define END_CPU_TEST(t) \
t##_free(cpu)
#define DEFINE_INST(inst) \
void mos6502_handle_##inst (mos6502 *cpu, vm_8bit oper)

View File

@ -20,6 +20,7 @@
* pointers to all of that in the chip structure
*/
#include <stdio.h>
#include <stdlib.h>
#include "log.h"
@ -141,17 +142,39 @@ mos6502_modify_status(mos6502 *cpu, int statuses, vm_8bit oper)
}
}
if (statuses & ZERO) {
cpu->P &= ~ZERO;
if (oper == 0) {
cpu->P |= ZERO;
if (statuses & 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) {
cpu->P &= ~CARRY;
if (oper > 0) {
cpu->P |= CARRY;
}
}
if (statuses & ZERO) {
cpu->P &= ~ZERO;
if (oper == 0) {
cpu->P |= ZERO;
}
}
}

View File

@ -35,3 +35,56 @@ Test(mos6502, next_byte) {
END_ADDR_MODE();
}
Test(mos6502, push_stack)
{
START_CPU_TEST(mos6502);
mos6502_push_stack(cpu, 0x1234);
cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x12);
cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x34);
END_CPU_TEST(mos6502);
}
Test(mos6502, pop_stack)
{
START_CPU_TEST(mos6502);
mos6502_push_stack(cpu, 0x1234);
cr_assert_eq(mos6502_pop_stack(cpu), 0x1234);
END_CPU_TEST(mos6502);
}
Test(mos6502, modify_status)
{
START_CPU_TEST(mos6502);
mos6502_modify_status(cpu, NEGATIVE, 130);
cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE);
mos6502_modify_status(cpu, NEGATIVE, 123);
cr_assert_neq(cpu->P & NEGATIVE, NEGATIVE);
mos6502_modify_status(cpu, OVERFLOW, 123);
cr_assert_eq(cpu->P & OVERFLOW, OVERFLOW);
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);
cr_assert_neq(cpu->P & CARRY, CARRY);
mos6502_modify_status(cpu, ZERO, 0);
cr_assert_eq(cpu->P & ZERO, ZERO);
mos6502_modify_status(cpu, ZERO, 1);
cr_assert_neq(cpu->P & ZERO, ZERO);
END_CPU_TEST(mos6502);
}

4
tests/mos6502.loadstor.c Normal file
View File

@ -0,0 +1,4 @@
#include <criterion/criterion.h>
#include "mos6502.h"
#include "mos6502.enums.h"