2025-01-30 14:30:19 -07:00
|
|
|
#include <emu.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <cart.h>
|
|
|
|
#include <cpu.h>
|
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_ttf.h>
|
|
|
|
|
|
|
|
static emu_context ctx;
|
|
|
|
|
|
|
|
emu_context *emu_get_context() {
|
|
|
|
return &ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void delay(u32 ms) {
|
|
|
|
SDL_Delay(ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
int emu_run(int argc, char **argv) {
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("Usage: gbemu <rom_file>\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!cart_load(argv[1])) {
|
|
|
|
printf("Failed to load ROM file: %s\n", argv[1]);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Cart loaded..\n");
|
|
|
|
|
|
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
|
|
printf("SDL INIT\n");
|
|
|
|
TTF_Init();
|
|
|
|
printf("TTF INIT\n");
|
|
|
|
|
|
|
|
cpu_init();
|
|
|
|
|
|
|
|
ctx.running = true;
|
|
|
|
ctx.paused = false;
|
|
|
|
ctx.ticks = 0;
|
|
|
|
|
|
|
|
while (ctx.running) {
|
|
|
|
if (ctx.paused) {
|
|
|
|
delay(10);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cpu_step()) {
|
|
|
|
printf("CPU stopped\n");
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ticks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2025-01-30 16:27:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void emu_cycles(int cpu_cycles) {
|
|
|
|
//TODO
|
2025-01-30 14:30:19 -07:00
|
|
|
}
|