From c798a2d88615a7aba14d2c89cd5adfa0ab08692e Mon Sep 17 00:00:00 2001 From: Brad Grantham Date: Sun, 27 Dec 2020 18:18:13 -0800 Subject: [PATCH] take bin file name as an argument --- test6502.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test6502.cpp b/test6502.cpp index 5cbc10b..97848e7 100644 --- a/test6502.cpp +++ b/test6502.cpp @@ -61,10 +61,18 @@ std::string read_bus_and_disassemble(const BUS &bus, int pc) int main(int argc, const char **argv) { + if(argc < 2) { + fprintf(stderr, "usage: %s testfile.bin\n", argv[0]); + } + bus machine; - FILE *testbin = fopen("6502_functional_test.bin", "rb"); - assert(testbin); + FILE *testbin = fopen(argv[1], "rb"); + if(!testbin) { + printf("couldn't open \"%s\" for reading\n", argv[1]); + exit(EXIT_FAILURE); + } + fseek(testbin, 0, SEEK_END); long length = ftell(testbin); fseek(testbin, 0, SEEK_SET); @@ -87,4 +95,5 @@ int main(int argc, const char **argv) cpu.cycle(); } while(cpu.pc != oldpc); print_cpu_state(cpu); + exit(EXIT_SUCCESS); }