From afa45ea82d7ee7cdb68cc262737ffb2c5dd224ba Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Thu, 16 Jul 2026 18:41:14 +1000 Subject: [PATCH] Update main.c to accept command line input --- src/main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 99bedca..c0fb2ec 100644 --- a/src/main.c +++ b/src/main.c @@ -2,13 +2,20 @@ #include "emu.h" #include "util.h" -int main() { +int main(int argc, char** argv) { + + if (argc < 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + Emulator* emu = initEmulator(0x00010FFF); if (!emu) { fprintf(stderr, "emu: error: failed to allocate memory for emulator\n"); return 1; } + /* Instruction program[] = { {INST_MVI, {REG_A}, 0, true}, {INST_MVI, {REG_B}, 123, true}, @@ -18,9 +25,18 @@ int main() { }; memoryLoadProgram(emu->mem, program, sizeof(program)/sizeof(program[0])); + */ + + RomFile* rom = readProgramFromFile(argv[1]); + if (rom == NULL) { + fprintf(stderr, "Failed to read rom from %s\n", argv[1]); + return 1; + } + + memoryLoadProgram(emu->mem, rom->instructions, rom->header.numInstructions); startEmulator(emu); freeEmulator(emu); return 0; -} \ No newline at end of file +}