mirror of https://github.com/mgba-emu/mgba.git
Move main emulation into thread
This commit is contained in:
parent
ff03bcf0f0
commit
cb48145ea3
|
@ -109,6 +109,8 @@ void ARMReset(struct ARMCore* cpu) {
|
|||
cpu->executionMode = MODE_THUMB;
|
||||
_ARMSetMode(cpu, MODE_ARM);
|
||||
|
||||
ARM_WRITE_PC;
|
||||
|
||||
cpu->board->reset(cpu->board);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#include "gba-thread.h"
|
||||
|
||||
#include "arm.h"
|
||||
#include "debugger.h"
|
||||
#include "gba.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
static void* _GBAThreadRun(void* context) {
|
||||
struct ARMDebugger debugger;
|
||||
struct GBA gba;
|
||||
struct GBAThread* threadContext = context;
|
||||
|
||||
sigset_t signals;
|
||||
sigfillset(&signals);
|
||||
pthread_sigmask(SIG_UNBLOCK, &signals, 0);
|
||||
|
||||
GBAInit(&gba);
|
||||
threadContext->gba = &gba;
|
||||
threadContext->debugger = &debugger;
|
||||
if (threadContext->fd >= 0) {
|
||||
GBALoadROM(&gba, threadContext->fd);
|
||||
}
|
||||
GBAAttachDebugger(&gba, &debugger);
|
||||
ARMDebuggerRun(&debugger);
|
||||
GBADeinit(&gba);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GBAThreadStart(struct GBAThread* threadContext, pthread_t* thread) {
|
||||
return pthread_create(thread, 0, _GBAThreadRun, threadContext);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef GBA_THREAD_H
|
||||
#define GBA_THREAD_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
struct GBAThread {
|
||||
struct GBA* gba;
|
||||
struct ARMDebugger* debugger;
|
||||
int fd;
|
||||
};
|
||||
|
||||
int GBAThreadStart(struct GBAThread* threadContext, pthread_t* thread);
|
||||
|
||||
#endif
|
29
src/main.c
29
src/main.c
|
@ -1,22 +1,25 @@
|
|||
#include "arm.h"
|
||||
#include "debugger.h"
|
||||
#include "gba.h"
|
||||
#include "gba-thread.h"
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
struct ARMDebugger debugger;
|
||||
struct GBA gba;
|
||||
GBAInit(&gba);
|
||||
int fd = open("test.rom", O_RDONLY);
|
||||
GBALoadROM(&gba, fd);
|
||||
gba.cpu.gprs[ARM_PC] = 0x08000004;
|
||||
gba.memory.d.setActiveRegion(&gba.memory.d, gba.cpu.gprs[ARM_PC]);
|
||||
GBAAttachDebugger(&gba, &debugger);
|
||||
ARMDebuggerRun(&debugger);
|
||||
GBADeinit(&gba);
|
||||
|
||||
sigset_t signals;
|
||||
sigaddset(&signals, SIGINT);
|
||||
sigaddset(&signals, SIGTRAP);
|
||||
pthread_sigmask(SIG_BLOCK, &signals, 0);
|
||||
|
||||
struct GBAThread context;
|
||||
context.fd = fd;
|
||||
pthread_t thread;
|
||||
GBAThreadStart(&context, &thread);
|
||||
|
||||
pthread_join(thread, 0);
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue