From 0de4957a22dd408793d0526351bcb7d61786fe86 Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Fri, 7 Feb 2025 22:15:57 +0100 Subject: add sdl implementation --- app/sdl/main.cc | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 app/sdl/main.cc (limited to 'app/sdl/main.cc') diff --git a/app/sdl/main.cc b/app/sdl/main.cc new file mode 100644 index 0000000..f2c3621 --- /dev/null +++ b/app/sdl/main.cc @@ -0,0 +1,40 @@ +#include "state.hh" +#include + +#define SDL_MAIN_USE_CALLBACKS +#include + +auto SDL_AppInit(void** appstate, int argc, char** argv) -> SDL_AppResult +{ + (void)argc; + (void)argv; + + auto const state = new nes::app::sdl::state; + *appstate = state; + + return state->get_status() == nes::status::success ? SDL_APP_CONTINUE : SDL_APP_FAILURE; +} + +auto SDL_AppIterate(void* appstate) -> SDL_AppResult +{ + auto const state = static_cast(appstate); + state->handle_iterate(); + return state->get_status() == nes::status::success ? SDL_APP_CONTINUE : SDL_APP_FAILURE; +} + +auto SDL_AppEvent(void* appstate, SDL_Event* event) -> SDL_AppResult +{ + if (event->type == SDL_EVENT_QUIT) + { + return SDL_APP_SUCCESS; + } + + auto const state = static_cast(appstate); + state->handle_event(event); + return state->get_status() == nes::status::success ? SDL_APP_CONTINUE : SDL_APP_FAILURE; +} + +auto SDL_AppQuit(void* appstate, SDL_AppResult) -> void +{ + delete static_cast(appstate); +} -- cgit v1.3.1