mirror of https://github.com/jborza/emu6502.git
split test framework code into test_framework.c+h, leaving test6502 just for tests
This commit is contained in:
parent
836a076d1c
commit
295f73e874
|
@ -156,7 +156,6 @@
|
||||||
<ClCompile Include="disassembler.c" />
|
<ClCompile Include="disassembler.c" />
|
||||||
<ClCompile Include="emu6502.c" />
|
<ClCompile Include="emu6502.c" />
|
||||||
<ClCompile Include="memory.c" />
|
<ClCompile Include="memory.c" />
|
||||||
<ClCompile Include="test6502.c" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="cpu.h" />
|
<ClInclude Include="cpu.h" />
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
138
test6502.c
138
test6502.c
|
@ -7,146 +7,10 @@
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "disassembler.h"
|
#include "disassembler.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#ifdef _DEBUG
|
#include "test_framework.h"
|
||||||
#include <signal.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void print_state(State6502* state) {
|
|
||||||
printf("\tC=%d,Z=%d,I=%d,D=%d,B=%d,V=%d,N=%d\n", state->flags.c, state->flags.z, state->flags.i, state->flags.d, state->flags.b, state->flags.v, state->flags.n);
|
|
||||||
printf("\tA $%02X X $%02X Y $%02X SP $%02X PC $%04X\n", state->a, state->x, state->y, state->sp, state->pc);
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_memory(State6502* state, word offset) {
|
|
||||||
printf("$%04X: ", offset);
|
|
||||||
for (byte i = 0; i < 32; i++) {
|
|
||||||
printf("%02X", state->memory[offset + i]);
|
|
||||||
if (i % 8 == 7)
|
|
||||||
printf("|");
|
|
||||||
else
|
|
||||||
printf(" ");
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_all(State6502 * state) {
|
|
||||||
print_state(state);
|
|
||||||
print_memory(state, 0);
|
|
||||||
//print_memory(state, 0x20);
|
|
||||||
//print_memory(state, 0x40);
|
|
||||||
//print_memory(state, 0x80);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_step(State6502 * state) {
|
|
||||||
print_all(state);
|
|
||||||
disassemble_6502(state->memory, state->pc);
|
|
||||||
printf("\n");
|
|
||||||
emulate_6502_op(state);
|
|
||||||
print_all(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_step_until_break(State6502 * state) {
|
|
||||||
do {
|
|
||||||
print_all(state);
|
|
||||||
disassemble_6502(state->memory, state->pc);
|
|
||||||
printf("\n");
|
|
||||||
emulate_6502_op(state);
|
|
||||||
} while (state->flags.b != 1);
|
|
||||||
print_all(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_cleanup(State6502 * state) {
|
|
||||||
free(state->memory);
|
|
||||||
}
|
|
||||||
|
|
||||||
State6502 create_blank_state() {
|
|
||||||
State6502 state;
|
|
||||||
clear_state(&state);
|
|
||||||
const int memory_size = 65536;
|
|
||||||
state.memory = malloc(memory_size);
|
|
||||||
memset(state.memory, 0, sizeof(byte) * memory_size);
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
void exit_or_break() {
|
|
||||||
#ifdef _DEBUG
|
|
||||||
raise(SIGINT);
|
|
||||||
#endif
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_register(State6502 * state, byte expected, byte actual, char* name) {
|
|
||||||
if (actual != expected) {
|
|
||||||
printf("Unexpected value in %s, expected %02X, was %02X", name, expected, actual);
|
|
||||||
exit_or_break();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void assertA(State6502 * state, byte expected) {
|
|
||||||
assert_register(state, expected, state->a, "A");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assertX(State6502 * state, byte expected) {
|
|
||||||
assert_register(state, expected, state->x, "X");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assertY(State6502 * state, byte expected) {
|
|
||||||
assert_register(state, expected, state->y, "Y");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_sp(State6502 * state, byte expected) {
|
|
||||||
assert_register(state, expected, state->sp, "SP");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_pc(State6502 * state, word expected) {
|
|
||||||
if (state->pc != expected) {
|
|
||||||
printf("Unexpected value in SP, expected %02X, was %02X", expected, state->pc);
|
|
||||||
exit_or_break();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//assert_memory(&state, 0xFF, 0x99)
|
|
||||||
void assert_memory(State6502 * state, word address, byte expected) {
|
|
||||||
if (state->memory[address] != expected) {
|
|
||||||
printf("Unexpected value in $%04X, expected %02X, was %02X", address, expected, state->memory[address]);
|
|
||||||
exit_or_break();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_flag(byte flag_value, byte expected, char* flag_name) {
|
|
||||||
if (flag_value != expected) {
|
|
||||||
printf("Unexpected value in flag %s, expected %d, was %d", flag_name, expected, flag_value);
|
|
||||||
exit_or_break();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_flag_n(State6502 * state, byte expected) {
|
|
||||||
assert_flag(state->flags.n, expected, "N");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_flag_z(State6502 * state, byte expected) {
|
|
||||||
assert_flag(state->flags.z, expected, "Z");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_flag_c(State6502 * state, byte expected) {
|
|
||||||
assert_flag(state->flags.c, expected, "C");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_flag_i(State6502 * state, byte expected) {
|
|
||||||
assert_flag(state->flags.i, expected, "I");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_flag_d(State6502 * state, byte expected) {
|
|
||||||
assert_flag(state->flags.d, expected, "D");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_flag_v(State6502 * state, byte expected) {
|
|
||||||
assert_flag(state->flags.v, expected, "V");
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_flag_b(State6502 * state, byte expected) {
|
|
||||||
assert_flag(state->flags.b, expected, "B");
|
|
||||||
}
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,3 @@
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
void run_tests();
|
void run_tests();
|
||||||
void print_memory(State6502* state, word offset);
|
|
||||||
void print_state(State6502* state);
|
|
|
@ -131,6 +131,7 @@
|
||||||
<ClCompile Include="disassembler.c" />
|
<ClCompile Include="disassembler.c" />
|
||||||
<ClCompile Include="memory.c" />
|
<ClCompile Include="memory.c" />
|
||||||
<ClCompile Include="test6502.c" />
|
<ClCompile Include="test6502.c" />
|
||||||
|
<ClCompile Include="test_framework.c" />
|
||||||
<ClCompile Include="test_main.c" />
|
<ClCompile Include="test_main.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -141,6 +142,7 @@
|
||||||
<ClInclude Include="opcodes.h" />
|
<ClInclude Include="opcodes.h" />
|
||||||
<ClInclude Include="state.h" />
|
<ClInclude Include="state.h" />
|
||||||
<ClInclude Include="test6502.h" />
|
<ClInclude Include="test6502.h" />
|
||||||
|
<ClInclude Include="test_framework.h" />
|
||||||
<ClInclude Include="types.h" />
|
<ClInclude Include="types.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup />
|
||||||
|
</Project>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Source Files">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Resource Files">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup />
|
||||||
|
</Project>
|
|
@ -0,0 +1,146 @@
|
||||||
|
#include "test_framework.h"
|
||||||
|
#include "disassembler.h"
|
||||||
|
#include "cpu.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#include <signal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void print_state(State6502* state) {
|
||||||
|
printf("\tC=%d,Z=%d,I=%d,D=%d,B=%d,V=%d,N=%d\n", state->flags.c, state->flags.z, state->flags.i, state->flags.d, state->flags.b, state->flags.v, state->flags.n);
|
||||||
|
printf("\tA $%02X X $%02X Y $%02X SP $%02X PC $%04X\n", state->a, state->x, state->y, state->sp, state->pc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_memory(State6502* state, word offset) {
|
||||||
|
printf("$%04X: ", offset);
|
||||||
|
for (byte i = 0; i < 32; i++) {
|
||||||
|
printf("%02X", state->memory[offset + i]);
|
||||||
|
if (i % 8 == 7)
|
||||||
|
printf("|");
|
||||||
|
else
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_all(State6502 * state) {
|
||||||
|
print_state(state);
|
||||||
|
print_memory(state, 0);
|
||||||
|
//print_memory(state, 0x20);
|
||||||
|
//print_memory(state, 0x40);
|
||||||
|
//print_memory(state, 0x80);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_step(State6502 * state) {
|
||||||
|
print_all(state);
|
||||||
|
disassemble_6502(state->memory, state->pc);
|
||||||
|
printf("\n");
|
||||||
|
emulate_6502_op(state);
|
||||||
|
print_all(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_step_until_break(State6502 * state) {
|
||||||
|
do {
|
||||||
|
print_all(state);
|
||||||
|
disassemble_6502(state->memory, state->pc);
|
||||||
|
printf("\n");
|
||||||
|
emulate_6502_op(state);
|
||||||
|
} while (state->flags.b != 1);
|
||||||
|
print_all(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_cleanup(State6502 * state) {
|
||||||
|
free(state->memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
State6502 create_blank_state() {
|
||||||
|
State6502 state;
|
||||||
|
clear_state(&state);
|
||||||
|
const int memory_size = 65536;
|
||||||
|
state.memory = malloc(memory_size);
|
||||||
|
memset(state.memory, 0, sizeof(byte) * memory_size);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void exit_or_break() {
|
||||||
|
#ifdef _DEBUG
|
||||||
|
raise(SIGINT);
|
||||||
|
#endif
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_register(State6502 * state, byte expected, byte actual, char* name) {
|
||||||
|
if (actual != expected) {
|
||||||
|
printf("Unexpected value in %s, expected %02X, was %02X", name, expected, actual);
|
||||||
|
exit_or_break();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void assertA(State6502 * state, byte expected) {
|
||||||
|
assert_register(state, expected, state->a, "A");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assertX(State6502 * state, byte expected) {
|
||||||
|
assert_register(state, expected, state->x, "X");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assertY(State6502 * state, byte expected) {
|
||||||
|
assert_register(state, expected, state->y, "Y");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_sp(State6502 * state, byte expected) {
|
||||||
|
assert_register(state, expected, state->sp, "SP");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_pc(State6502 * state, word expected) {
|
||||||
|
if (state->pc != expected) {
|
||||||
|
printf("Unexpected value in SP, expected %02X, was %02X", expected, state->pc);
|
||||||
|
exit_or_break();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//assert_memory(&state, 0xFF, 0x99)
|
||||||
|
void assert_memory(State6502 * state, word address, byte expected) {
|
||||||
|
if (state->memory[address] != expected) {
|
||||||
|
printf("Unexpected value in $%04X, expected %02X, was %02X", address, expected, state->memory[address]);
|
||||||
|
exit_or_break();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_flag(byte flag_value, byte expected, char* flag_name) {
|
||||||
|
if (flag_value != expected) {
|
||||||
|
printf("Unexpected value in flag %s, expected %d, was %d", flag_name, expected, flag_value);
|
||||||
|
exit_or_break();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_flag_n(State6502 * state, byte expected) {
|
||||||
|
assert_flag(state->flags.n, expected, "N");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_flag_z(State6502 * state, byte expected) {
|
||||||
|
assert_flag(state->flags.z, expected, "Z");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_flag_c(State6502 * state, byte expected) {
|
||||||
|
assert_flag(state->flags.c, expected, "C");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_flag_i(State6502 * state, byte expected) {
|
||||||
|
assert_flag(state->flags.i, expected, "I");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_flag_d(State6502 * state, byte expected) {
|
||||||
|
assert_flag(state->flags.d, expected, "D");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_flag_v(State6502 * state, byte expected) {
|
||||||
|
assert_flag(state->flags.v, expected, "V");
|
||||||
|
}
|
||||||
|
|
||||||
|
void assert_flag_b(State6502 * state, byte expected) {
|
||||||
|
assert_flag(state->flags.b, expected, "B");
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
#include "state.h"
|
||||||
|
|
||||||
|
void print_memory(State6502* state, word offset);
|
||||||
|
void print_state(State6502* state);
|
||||||
|
State6502 create_blank_state();
|
Loading…
Reference in New Issue