From 14700bdf591f56be8c569d0125a0b01aff990f21 Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Thu, 16 Jul 2026 18:41:52 +1000 Subject: [PATCH] fix file loading --- add.o | Bin 0 -> 17 bytes src/main.c | 3 ++- src/memory.c | 1 + src/util.c | 2 +- src/util.h | 2 +- tests/add.asm | 2 -- 6 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 add.o diff --git a/add.o b/add.o new file mode 100644 index 0000000000000000000000000000000000000000..0e926cabb13784ff32f29d53a1b34503d8b77fef GIT binary patch literal 17 Vcmd1JNoHVVVE_R}20;cU1^^Uh0agG2 literal 0 HcmV?d00001 diff --git a/src/main.c b/src/main.c index 99bedca..8e3620f 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,8 @@ int main() { {INST_HLT, {}, 0, false} }; - memoryLoadProgram(emu->mem, program, sizeof(program)/sizeof(program[0])); + RomFile* f = readProgramFromFile("../add.o"); + memcpy(emu->mem + MEM_PROGRAM_START, f->instructions, sizeof(SerializedInst) * f->header.numInstructions); startEmulator(emu); freeEmulator(emu); diff --git a/src/memory.c b/src/memory.c index c1c6614..2f1d2e9 100644 --- a/src/memory.c +++ b/src/memory.c @@ -53,6 +53,7 @@ uint32_t memorySerializeInst(Memory* m, Instruction inst, uint32_t offset) { void memoryLoadProgram(Memory* m, Instruction program[], size_t numInstructions) { size_t offset = 0; for (size_t i = 0; i < numInstructions; i++) { + printf("%zu. %s\n", i, instructionToCStr(program[i])); offset = memorySerializeInst(m, program[i], offset); } } diff --git a/src/util.c b/src/util.c index 1243288..fec86ea 100644 --- a/src/util.c +++ b/src/util.c @@ -21,7 +21,7 @@ RomFile* readProgramFromFile(char* path) { fclose(f); ROMFileHeader* header = (ROMFileHeader*)buffer; - Instruction* instructions = calloc(header->numInstructions, sizeof(SerializedInst)); + SerializedInst* instructions = calloc(header->numInstructions, sizeof(SerializedInst)); if (!instructions) { free(buffer); return NULL; diff --git a/src/util.h b/src/util.h index 76c4d32..ac75d96 100644 --- a/src/util.h +++ b/src/util.h @@ -13,7 +13,7 @@ typedef struct { typedef struct { ROMFileHeader header; - Instruction* instructions; + SerializedInst* instructions; } RomFile; // -- FUNCTIONS -- // diff --git a/tests/add.asm b/tests/add.asm index 8f6a875..c0ee31a 100644 --- a/tests/add.asm +++ b/tests/add.asm @@ -1,5 +1,3 @@ -dingus: - mvi a 2 mvi b 2