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