Modernize egl-main

This commit is contained in:
Jeffrey Pfau 2014-07-23 22:57:58 -07:00
parent 754d3f50ce
commit 6c9ee4c212
1 changed files with 22 additions and 19 deletions

View File

@ -68,41 +68,46 @@ static void _GBASDLStart(struct GBAThread* context);
static void _GBASDLClean(struct GBAThread* context);
int main(int argc, char** argv) {
const char* fname = "test.rom";
if (argc > 1) {
fname = argv[1];
}
int fd = open(fname, O_RDONLY);
if (fd < 0) {
struct GBAVideoEGLRenderer renderer;
struct StartupOptions opts;
if (!parseCommandArgs(&opts, argc, argv, 0)) {
usage(argv[0], 0);
freeOptions(&opts);
return 1;
}
struct GBAVideoEGLRenderer renderer;
if (!_GBAEGLInit(&renderer)) {
return 1;
}
GBAVideoSoftwareRendererCreate(&renderer.d);
struct GBAThread context = {
.fd = fd,
.fname = fname,
.biosFd = -1,
.useDebugger = 0,
.renderer = &renderer.d.d,
.frameskip = 0,
.sync.videoFrameWait = 0,
.sync.audioWait = 0,
.sync.audioWait = 1,
.startCallback = _GBASDLStart,
.cleanCallback = _GBASDLClean,
.userData = &renderer
};
context.debugger = createDebugger(&opts);
GBAMapOptionsToContext(&opts, &context);
renderer.audio.samples = context.audioBuffers;
GBASDLInitAudio(&renderer.audio);
renderer.events.bindings = &context.inputMap;
GBASDLInitEvents(&renderer.events);
GBAThreadStart(&context);
_GBAEGLRunloop(&context, &renderer);
GBAThreadJoin(&context);
close(fd);
freeOptions(&opts);
free(context.debugger);
_GBAEGLDeinit(&renderer);
@ -114,9 +119,6 @@ static int _GBAEGLInit(struct GBAVideoEGLRenderer* renderer) {
return 0;
}
GBASDLInitEvents(&renderer->events);
GBASDLInitAudio(&renderer->audio);
bcm_host_init();
renderer->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
int major, minor;
@ -238,7 +240,7 @@ static void _GBAEGLRunloop(struct GBAThread* context, struct GBAVideoEGLRenderer
GBASyncWaitFrameEnd(&context->sync);
while (SDL_PollEvent(&event)) {
GBASDLHandleEvent(context, &event);
GBASDLHandleEvent(context, &renderer->events, &event);
}
}
}
@ -259,6 +261,7 @@ static void _GBAEGLDeinit(struct GBAVideoEGLRenderer* renderer) {
static void _GBASDLStart(struct GBAThread* threadContext) {
struct GBAVideoEGLRenderer* renderer = threadContext->userData;
renderer->audio.audio = &threadContext->gba->audio;
renderer->audio.thread = threadContext;
}
static void _GBASDLClean(struct GBAThread* threadContext) {