From d1a4c35f9a6206f065afddbdacc7a4a2e6321666 Mon Sep 17 00:00:00 2001 From: jborza Date: Tue, 7 May 2019 21:10:28 +0200 Subject: [PATCH] added a 'nestest' vc++ solution for executing the nestest --- .gitignore | 1 + debugger_windows.c | 4 +- emu6502.c | 3 +- emu6502.sln | 10 +++ emu6502.vcxproj | 1 - nestest.vcxproj | 147 +++++++++++++++++++++++++++++++++++++++++++++ nestest_main.c | 56 +++++++++++++++++ 7 files changed, 218 insertions(+), 4 deletions(-) create mode 100644 nestest.vcxproj create mode 100644 nestest_main.c diff --git a/.gitignore b/.gitignore index 3fdd7cb..3bbc8c8 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ dkms.conf /emu6502.vcxproj.filters /data/.vscode/ipch /x64/ +/nestest.vcxproj.user diff --git a/debugger_windows.c b/debugger_windows.c index f737cbd..8d341b6 100644 --- a/debugger_windows.c +++ b/debugger_windows.c @@ -89,7 +89,7 @@ byte * read_bin() { rewind(file); byte* buffer = malloc(glob_file_size); - int read = fread(buffer, sizeof(byte), glob_file_size, file); + size_t read = fread(buffer, sizeof(byte), glob_file_size, file); fclose(file); return buffer; } @@ -134,7 +134,7 @@ void print_frame() { } } -int main2(int argc, char* argv[]) { +int main(int argc, char* argv[]) { State6502 state; clear_state(&state); state.memory = malloc(MEMORY_SIZE); diff --git a/emu6502.c b/emu6502.c index 73d281e..3ef70d6 100644 --- a/emu6502.c +++ b/emu6502.c @@ -17,9 +17,10 @@ #define MEMORY_SIZE 0xFFFF byte* read_nestest() { - FILE* file = fopen("nestest\\nestest.bin", "rb"); + FILE* file = fopen("nestest/nestest.bin", "rb"); if (!file) { int err = errno; + printf("Couldn't load nestest.bin!"); exit(1); } static byte buffer[NESTEST_SIZE]; diff --git a/emu6502.sln b/emu6502.sln index ae7b4fc..8bb3c00 100644 --- a/emu6502.sln +++ b/emu6502.sln @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "emu6502", "emu6502.vcxproj" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test6502", "test6502.vcxproj", "{259880CE-646B-48DB-8961-32397CE32005}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nestest", "nestest.vcxproj", "{45934D07-B04C-4348-AC1F-8953CFFD5F8F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -31,6 +33,14 @@ Global {259880CE-646B-48DB-8961-32397CE32005}.Release|x64.Build.0 = Release|x64 {259880CE-646B-48DB-8961-32397CE32005}.Release|x86.ActiveCfg = Release|Win32 {259880CE-646B-48DB-8961-32397CE32005}.Release|x86.Build.0 = Release|Win32 + {45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Debug|x64.ActiveCfg = Debug|x64 + {45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Debug|x64.Build.0 = Debug|x64 + {45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Debug|x86.ActiveCfg = Debug|Win32 + {45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Debug|x86.Build.0 = Debug|Win32 + {45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Release|x64.ActiveCfg = Release|x64 + {45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Release|x64.Build.0 = Release|x64 + {45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Release|x86.ActiveCfg = Release|Win32 + {45934D07-B04C-4348-AC1F-8953CFFD5F8F}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/emu6502.vcxproj b/emu6502.vcxproj index bc31e01..21b09ed 100644 --- a/emu6502.vcxproj +++ b/emu6502.vcxproj @@ -154,7 +154,6 @@ - diff --git a/nestest.vcxproj b/nestest.vcxproj new file mode 100644 index 0000000..a09a4d8 --- /dev/null +++ b/nestest.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {45934D07-B04C-4348-AC1F-8953CFFD5F8F} + nestest + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + Console + + + + + Level3 + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + Console + true + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nestest_main.c b/nestest_main.c new file mode 100644 index 0000000..5cf79dc --- /dev/null +++ b/nestest_main.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include "state.h" +#include "cpu.h" +#include "disassembler.h" +#include "opcodes.h" +#include + +#define NESTEST_SIZE 0x4000 +#define NESTEST_DST 0xC000 +#define MEMORY_SIZE 0xFFFF + +byte* read_nestest() { + FILE* file = fopen("nestest/nestest.bin", "rb"); + if (!file) { + printf("Couldn't load nestest.bin!"); + exit(1); + } + static byte buffer[NESTEST_SIZE]; + int read = fread(&buffer, sizeof(byte), NESTEST_SIZE, file); + fclose(file); + return buffer; +} + +byte debug_flags_as_byte(State6502* state) { + byte flags_value = 0; + memcpy(&flags_value, &state->flags, sizeof(Flags)); + return flags_value; +} + +void run_nestest() { + State6502 state; + clear_state(&state); + state.memory = malloc(MEMORY_SIZE); + memset(state.memory, 0, MEMORY_SIZE); + byte* bin = read_nestest(); + //const word TARGET = 0xC000; + memcpy(state.memory + NESTEST_DST, bin, NESTEST_SIZE); + memcpy(state.memory + 0x8000, bin, NESTEST_SIZE); + state.pc = NESTEST_DST; + //a little cheat to simulate probably a JSR and SEI at the beginning + state.sp = 0xfd; + state.flags.i = 1; + do { + char* dasm = disassemble_6502_to_string(state.memory, state.pc); + printf("%-50s A:%02X X:%02X Y:%02X P:%02X SP:%02X\n", dasm, state.a, state.x, state.y, debug_flags_as_byte(&state), state.sp); + emulate_6502_op(&state); + } while (state.flags.b != 1); +} + +int main() +{ + run_nestest(); + return 0; +} \ No newline at end of file