diff --git a/src/emulate.c b/src/emulate.c index e2ad1c8..0868d32 100755 --- a/src/emulate.c +++ b/src/emulate.c @@ -1,5 +1,53 @@ #include +#include +#include +#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 []"); + 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; }