Files
MyLittleCPU/src/main.c

45 lines
1.2 KiB
C
Raw Normal View History

2026-07-15 15:02:54 +10:00
#include <stdio.h>
#include "emu.h"
2026-07-16 12:04:17 +10:00
#include "util.h"
2026-07-15 15:02:54 +10:00
int main(int argc, char** argv) {
if (argc < 2) {
fprintf(stderr, "Usage: %s <ROM to emulate>\n", argv[0]);
return 1;
}
2026-07-15 15:02:54 +10:00
Emulator* emu = initEmulator(0x00010FFF);
if (!emu) {
fprintf(stderr, "emu: error: failed to allocate memory for emulator\n");
return 1;
}
/*
2026-07-16 14:05:01 +10:00
Instruction program[] = {
{INST_MVI, {REG_A}, 0, true},
{INST_MVI, {REG_B}, 123, true},
{INST_PORT, {REG_A, REG_B, 0}, 0, false},
{INST_PORT, {REG_A, REG_B, 1}, 0, false},
{INST_HLT, {}, 0, false}
};
2026-07-15 15:54:51 +10:00
2026-07-16 18:41:52 +10:00
RomFile* f = readProgramFromFile("../add.o");
memcpy(emu->mem + MEM_PROGRAM_START, f->instructions, sizeof(SerializedInst) * f->header.numInstructions);
2026-07-16 14:05:01 +10:00
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;
}
memcpy(emu->mem + MEM_PROGRAM_START, rom->instructions, sizeof(SerializedInst) * rom->header.numInstructions);
2026-07-16 14:05:01 +10:00
startEmulator(emu);
2026-07-15 15:54:51 +10:00
freeEmulator(emu);
2026-07-15 15:02:54 +10:00
return 0;
}