Finished CPU instructions and created ui window.
This commit is contained in:
81
lib/emu.c
81
lib/emu.c
@ -2,8 +2,15 @@
|
||||
#include <stdio.h>
|
||||
#include <cart.h>
|
||||
#include <cpu.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include <ui.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef _UNIX
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
static emu_context ctx;
|
||||
|
||||
@ -11,28 +18,7 @@ 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");
|
||||
|
||||
DWORD WINAPI cpu_run(void *p) {
|
||||
cpu_init();
|
||||
|
||||
ctx.running = true;
|
||||
@ -56,6 +42,53 @@ int emu_run(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sleep_ms(int milis) {
|
||||
#ifdef _WIN32
|
||||
Sleep(milis);
|
||||
#endif
|
||||
#ifdef _UNIX
|
||||
usleep(milis * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
ui_init();
|
||||
#ifdef _WIN32
|
||||
HANDLE thread = CreateThread(NULL, 0, cpu_run, NULL, 0, NULL);
|
||||
if(!thread) {
|
||||
fprintf(stderr, "Unable to create main CPU thread!\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#ifdef _UNIX
|
||||
pthread_t t1;
|
||||
if(pthread_create(&t1, NULL, cpu_run, NULL)) {
|
||||
fprintf(stderr, "Unable to create main CPU thread!\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
while(!ctx.die) {
|
||||
sleep_ms(1);
|
||||
ui_handle_events();
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void emu_cycles(int cpu_cycles) {
|
||||
//TODO
|
||||
}
|
Reference in New Issue
Block a user