linux compat
This commit is contained in:
32
lib/emu.c
32
lib/emu.c
@ -16,10 +16,15 @@
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
static emu_context ctx;
|
||||
#ifdef __windows__
|
||||
static HANDLE thread;
|
||||
#else
|
||||
static pthread_t thread;
|
||||
#endif
|
||||
|
||||
emu_context *emu_get_context() {
|
||||
return &ctx;
|
||||
@ -61,7 +66,12 @@ void sleep_ms(int milis) {
|
||||
|
||||
void emu_stop() {
|
||||
ctx.running = false;
|
||||
#ifdef __windows__
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
#else
|
||||
pthread_join(thread, NULL);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void emu_reset() {
|
||||
@ -74,7 +84,11 @@ void emu_reset() {
|
||||
}
|
||||
|
||||
void emu_start() {
|
||||
#ifdef __windows__
|
||||
thread = CreateThread(NULL, 0, cpu_run, NULL, 0, NULL);
|
||||
#else
|
||||
pthread_create(&thread, NULL, cpu_run, NULL);
|
||||
#endif
|
||||
if(!thread) {
|
||||
fprintf(stderr, "Unable to create main CPU thread!\n");
|
||||
}
|
||||
@ -92,6 +106,7 @@ int emu_run(int argc, char **argv) {
|
||||
}
|
||||
|
||||
char fn[1048];
|
||||
#ifdef __windows__
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s\\Documents\\gbemu", profile);
|
||||
CreateDirectory(fn, NULL);
|
||||
@ -99,21 +114,22 @@ int emu_run(int argc, char **argv) {
|
||||
CreateDirectory(fn, NULL);
|
||||
sprintf(fn, "%s\\Documents\\gbemu\\states", profile);
|
||||
CreateDirectory(fn, NULL);
|
||||
#else
|
||||
char *profile = getenv("HOME");
|
||||
sprintf(fn, "%s/.config/gbemu", profile);
|
||||
mkdir(fn, 0755);
|
||||
sprintf(fn, "%s/.config/gbemu/saves", profile);
|
||||
mkdir(fn, 0755);
|
||||
sprintf(fn, "%s/.config/gbemu/states", profile);
|
||||
mkdir(fn, 0755);
|
||||
#endif
|
||||
|
||||
printf("Cart loaded..\n");
|
||||
ctx.app_path = argv[0];
|
||||
|
||||
ui_init();
|
||||
#ifdef _WIN32
|
||||
emu_reset();
|
||||
emu_start();
|
||||
#else
|
||||
pthread_t t1;
|
||||
if(pthread_create(&t1, NULL, cpu_run, NULL)) {
|
||||
fprintf(stderr, "Unable to create main CPU thread!\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
u32 prev_frame = 0;
|
||||
debug_init();
|
||||
|
Reference in New Issue
Block a user