Fix emulate to properly initialise state, w/ T

This commit is contained in:
sBubshait 2024-06-03 17:55:54 +01:00
parent 3a20190f4f
commit 5fd5c512e6

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include "emulator.h"
#include "fileio.h"
#include "global.h"
#include "print.h"
#include "decode.h"
#include "execute.h"
@ -26,10 +27,11 @@ int main(int argc, char **argv) {
}
// Initialising the machine state
Machine *state = {0};
state->memory = fileio_loadBin(argv[1], MEMORY_SIZE);
state->conditionCodes = (PState){0, 1, 0, 0};
state->pc = 0x0;
Machine state = {0};
state.memory = fileio_loadBin(argv[1], MEMORY_SIZE);
state.conditionCodes = (PState){0, 1, 0, 0};
state.pc = 0x0;
// Fetch-decode-execute cycle
word wrd;
@ -37,18 +39,21 @@ int main(int argc, char **argv) {
do {
// Step 1: Fetch instruction at PC's address
wrd = readWord(state->memory, state->pc);
wrd = readWord(state.memory, state.pc);
// Step 2: Decode instruction to internal representation
inst = decode(wrd);
// Step 3: Update processor state to reflect executing the instruction, and increment PC
execute(state, inst);
state->pc += 1;
execute(&state, inst);
state.pc += sizeof(word);
} while (inst->type != a64inst_HALT);
printState(state, out);
free(state->memory);
state.pc -= sizeof(word);
printState(&state, out);
free(state.memory);
return EXIT_SUCCESS;
}