Initial Project Setup
This commit is contained in:
57
lib/emu.c
Normal file
57
lib/emu.c
Normal file
@ -0,0 +1,57 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user