From 78d1f5588f299f370e1b7cbef14a45a5614b7d9d Mon Sep 17 00:00:00 2001 From: sBubshait Date: Sun, 2 Jun 2024 21:45:57 +0100 Subject: [PATCH] Update read word to be utility func, w/ T --- src/print.c | 8 ++++---- src/print.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/print.c b/src/print.c index c12322e..f70eb86 100644 --- a/src/print.c +++ b/src/print.c @@ -1,4 +1,5 @@ #include +#include #include #include "print.h" #include "emulator.h" @@ -25,12 +26,11 @@ void printRegisters(Machine *state, FILE *stream) { } // Returns the word starting at the provided address -// Converts 4 bytes into one word -word readWord(Machine *state, word address) { +word readWord(byte *memory, uint32_t address) { word result = 0; int bytesPerWord = WORD_BITS / BYTE_BITS - 1; for (int i = 0; i <= bytesPerWord; i++) - result |= (word) state->memory[address + i] << (BYTE_BITS * (bytesPerWord - i)); + result |= (word) memory[address + i] << (BYTE_BITS * (bytesPerWord - i)); return result; } @@ -40,7 +40,7 @@ void printMemory(Machine *state, FILE *stream) { // print memory 4 byte aligned for (int addr = 0; addr < MEMORY_SIZE; addr+= 4) { - word data = readWord(state, addr); + word data = readWord(state->memory, addr); if (data != 0) { fprintf(stream, "0x%08x: 0x%08x\n", addr, data); } diff --git a/src/print.h b/src/print.h index f344731..f3a411f 100644 --- a/src/print.h +++ b/src/print.h @@ -1,6 +1,7 @@ #include #include "emulator.h" +word readWord(byte *memory, uint32_t address); void printState(Machine *state, FILE *stream); void printRegisters(Machine *state, FILE *stream); void printMemory(Machine *state, FILE *stream);