Update emulate.c to read binary file and initalise state

This commit is contained in:
sBubshait 2024-05-29 14:30:35 +01:00
parent d7f56e47f7
commit 4710c72938

View File

@ -1,5 +1,53 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "emulator/defs.h"
#include "emulator/objectloader.h"
int main(int argc, char **argv) {
// Check the arguments
if (argc == 1) {
fprintf(stderr, "Error: An object file is required. Syntax: ./emulate <file_in> [<file_out>]");
return EXIT_FAILURE;
}
FILE *out = stdout;
if (argc > 2) {
out = fopen(argv[2], "w");
if (out == NULL) {
fprintf(stderr, "Error: Could not open file %s\n", argv[2]);
return EXIT_FAILURE;
}
}
// Allocate Memory for the machine
Machine *state = malloc(sizeof(Machine));
// Read the binary file into the memory of the machine.
loadObjectFile(argv[1], state->memory);
// Initialise memory state
memset(state->registers, 0, sizeof(state->registers));
memset(state->memory, 0, sizeof(state->memory));
state->PC = 0x0;
state->conditionCodes = (PSTATE){0, 0, 0, 0};
// Start Execution Cycle.
/**
* PIPELINE: WHILE():
* FETCH()
* DECODE()
* EXECUTE()
*/
/**
* PRINT_STATE();
*/
/**
* FREE MEMORY!!!
*/
return EXIT_SUCCESS;
}