2019-04-16 06:25:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "dmg.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "rom.h"
|
2019-10-22 06:30:19 +00:00
|
|
|
#include "lcd.h"
|
2019-04-16 06:25:00 +00:00
|
|
|
|
2022-07-09 06:18:56 +00:00
|
|
|
int emulator_main(int argc, char *argv[])
|
2019-04-16 06:25:00 +00:00
|
|
|
{
|
|
|
|
struct cpu cpu;
|
|
|
|
struct rom rom;
|
|
|
|
struct dmg dmg;
|
2019-10-22 06:30:19 +00:00
|
|
|
struct lcd lcd;
|
|
|
|
|
|
|
|
int executed;
|
2019-04-16 06:25:00 +00:00
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("no rom specified\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rom_load(&rom, argv[1])) {
|
|
|
|
printf("error loading rom\n");
|
|
|
|
return 1;
|
2022-06-21 00:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lcd_new(&lcd);
|
2019-04-16 06:25:00 +00:00
|
|
|
|
|
|
|
// this might be too much abstraction but it'll let me
|
|
|
|
// test the cpu, rom, and dmg independently and use the cpu
|
|
|
|
// for other non-GB stuff
|
2019-10-22 06:30:19 +00:00
|
|
|
dmg_new(&dmg, &cpu, &rom, &lcd);
|
2019-04-16 06:25:00 +00:00
|
|
|
cpu_bind_mem_model(&cpu, &dmg, dmg_read, dmg_write);
|
|
|
|
|
2022-06-29 03:41:26 +00:00
|
|
|
cpu.pc = 0x100;
|
2019-04-16 06:25:00 +00:00
|
|
|
|
2022-06-29 03:41:26 +00:00
|
|
|
// for (executed = 0; executed < 1000; executed++) {
|
2022-06-21 00:46:32 +00:00
|
|
|
while (1) {
|
2019-10-22 07:30:25 +00:00
|
|
|
dmg_step(&dmg);
|
2019-04-16 06:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rom_free(&rom);
|
|
|
|
return 0;
|
|
|
|
}
|