Full savestating to memory
This commit is contained in:
33
lib/emu.c
33
lib/emu.c
@ -7,6 +7,7 @@
|
||||
#include <dma.h>
|
||||
#include <ppu.h>
|
||||
#include <audio.h>
|
||||
#include <cart.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@ -16,6 +17,7 @@
|
||||
#endif
|
||||
|
||||
static emu_context ctx;
|
||||
static HANDLE thread;
|
||||
|
||||
emu_context *emu_get_context() {
|
||||
return &ctx;
|
||||
@ -26,10 +28,6 @@ DWORD WINAPI cpu_run(void *p) {
|
||||
#else
|
||||
void *cpu_run(void *p) {
|
||||
#endif
|
||||
ppu_init();
|
||||
timer_init();
|
||||
cpu_init();
|
||||
audio_init();
|
||||
|
||||
ctx.running = true;
|
||||
ctx.paused = false;
|
||||
@ -59,6 +57,26 @@ void sleep_ms(int milis) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void emu_stop() {
|
||||
ctx.running = false;
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
}
|
||||
|
||||
void emu_reset() {
|
||||
ppu_init();
|
||||
timer_init();
|
||||
cpu_init();
|
||||
audio_init();
|
||||
cart_init();
|
||||
}
|
||||
|
||||
void emu_start() {
|
||||
thread = CreateThread(NULL, 0, cpu_run, NULL, 0, NULL);
|
||||
if(!thread) {
|
||||
fprintf(stderr, "Unable to create main CPU thread!\n");
|
||||
}
|
||||
}
|
||||
|
||||
int emu_run(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: gbemu <rom_file>\n");
|
||||
@ -75,11 +93,8 @@ int emu_run(int argc, char **argv) {
|
||||
|
||||
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;
|
||||
}
|
||||
emu_reset();
|
||||
emu_start();
|
||||
#else
|
||||
pthread_t t1;
|
||||
if(pthread_create(&t1, NULL, cpu_run, NULL)) {
|
||||
|
Reference in New Issue
Block a user