Update main.c to accept command line input
This commit is contained in:
18
src/main.c
18
src/main.c
@@ -2,13 +2,20 @@
|
|||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
fprintf(stderr, "Usage: %s <ROM to emulate>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
Emulator* emu = initEmulator(0x00010FFF);
|
Emulator* emu = initEmulator(0x00010FFF);
|
||||||
if (!emu) {
|
if (!emu) {
|
||||||
fprintf(stderr, "emu: error: failed to allocate memory for emulator\n");
|
fprintf(stderr, "emu: error: failed to allocate memory for emulator\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
Instruction program[] = {
|
Instruction program[] = {
|
||||||
{INST_MVI, {REG_A}, 0, true},
|
{INST_MVI, {REG_A}, 0, true},
|
||||||
{INST_MVI, {REG_B}, 123, true},
|
{INST_MVI, {REG_B}, 123, true},
|
||||||
@@ -18,6 +25,15 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
memoryLoadProgram(emu->mem, program, sizeof(program)/sizeof(program[0]));
|
memoryLoadProgram(emu->mem, program, sizeof(program)/sizeof(program[0]));
|
||||||
|
*/
|
||||||
|
|
||||||
|
RomFile* rom = readProgramFromFile(argv[1]);
|
||||||
|
if (rom == NULL) {
|
||||||
|
fprintf(stderr, "Failed to read rom from %s\n", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memoryLoadProgram(emu->mem, rom->instructions, rom->header.numInstructions);
|
||||||
|
|
||||||
startEmulator(emu);
|
startEmulator(emu);
|
||||||
freeEmulator(emu);
|
freeEmulator(emu);
|
||||||
|
|||||||
Reference in New Issue
Block a user