Update emulate.c to read binary file and initalise state
This commit is contained in:
parent
d7f56e47f7
commit
4710c72938
@ -1,5 +1,53 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "emulator/defs.h"
|
||||||
|
#include "emulator/objectloader.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
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;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user