diff --git a/ion/src/simulator/shared/main_sdl.cpp b/ion/src/simulator/shared/main_sdl.cpp index 78c3fa00a..0c9ce6315 100644 --- a/ion/src/simulator/shared/main_sdl.cpp +++ b/ion/src/simulator/shared/main_sdl.cpp @@ -1,24 +1,51 @@ #include "main.h" #include "display.h" #include "platform.h" -#if !EPSILON_SDL_SCREEN_ONLY #include "layout.h" -#endif #include +#include #include +#include #include #include #include #include +static bool argument_screen_only = false; +static bool argument_fullscreen = false; + void Ion::Timing::msleep(uint32_t ms) { SDL_Delay(ms); } +void print_help(char * program_name) { + printf("Usage: %s [options]\n", program_name); + printf("Options:\n"); + printf(" -f, --fullscreen Starts the emulator in fullscreen\n"); + printf(" -s, --screen-only Disable the keyboard.\n"); + printf(" -h, --help Show this help menu.\n"); +} + int main(int argc, char * argv[]) { std::vector arguments(argv, argv + argc); + for(int i = 1; i < argc; i++) { + if(strcmp(argv[i], "-h")==0 || strcmp(argv[i], "--help")==0) { + print_help(argv[0]); + return 0; + } else if(strcmp(argv[i], "-s")==0 || strcmp(argv[i], "--screen-only")==0) { + argument_screen_only = true; + } else if(strcmp(argv[i], "-f")==0 || strcmp(argv[i], "--fullscreen")==0) { + argument_fullscreen = true; + } + } + +#if EPSILON_SDL_SCREEN_ONLY + // Still allow the use of EPSILON_SDL_SCREEN_ONLY. + argument_screen_only = true; +#endif + char * language = IonSimulatorGetLanguageCode(); if (language != nullptr) { arguments.push_back("--language"); @@ -41,13 +68,9 @@ namespace Main { static SDL_Window * sWindow = nullptr; static SDL_Renderer * sRenderer = nullptr; -#if !EPSILON_SDL_SCREEN_ONLY static SDL_Texture * sBackgroundTexture = nullptr; -#endif static bool sNeedsRefresh = false; -#if EPSILON_SDL_SCREEN_ONLY static SDL_Rect sScreenRect; -#endif void init() { if (SDL_Init(SDL_INIT_VIDEO) != 0) { @@ -55,26 +78,33 @@ void init() { return; } - sWindow = SDL_CreateWindow( - "Epsilon", - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, + uint32_t sdl_window_args = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE; + + if (argument_fullscreen) { + sdl_window_args = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_FULLSCREEN; + } + + if (argument_screen_only) { + sWindow = SDL_CreateWindow( + "Epsilon", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + Ion::Display::Width, Ion::Display::Height, #if EPSILON_SDL_SCREEN_ONLY - // When rendering the screen only, make a non-resizeable window that whose - // size matches the screen's - Ion::Display::Width, - Ion::Display::Height, - 0 // Default flags: no high-dpi, not resizeable. + 0 #else - 290, 555, // Otherwise use a default size that matches the whole calculator - SDL_WINDOW_ALLOW_HIGHDPI -#if EPSILON_SDL_FULLSCREEN - | SDL_WINDOW_FULLSCREEN -#else - | SDL_WINDOW_RESIZABLE + sdl_window_args #endif -#endif - ); + ); + } else { + sWindow = SDL_CreateWindow( + "Epsilon", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + 290, 555, + sdl_window_args + ); + } SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); @@ -88,9 +118,9 @@ void init() { Display::init(sRenderer); -#if !EPSILON_SDL_SCREEN_ONLY - sBackgroundTexture = IonSimulatorLoadImage(sRenderer, "background.jpg"); -#endif + if (!argument_screen_only) { + sBackgroundTexture = IonSimulatorLoadImage(sRenderer, "background.jpg"); + } relayout(); } @@ -101,19 +131,19 @@ void relayout() { SDL_GetWindowSize(sWindow, &windowWidth, &windowHeight); SDL_RenderSetLogicalSize(sRenderer, windowWidth, windowHeight); -#if EPSILON_SDL_SCREEN_ONLY - sScreenRect.x = 0; - sScreenRect.y = 0; - sScreenRect.w = windowWidth; - sScreenRect.h = windowHeight; -#else - Layout::recompute(windowWidth, windowHeight); - SDL_Rect backgroundRect; - Layout::getBackgroundRect(&backgroundRect); + if (argument_screen_only) { + sScreenRect.x = 0; + sScreenRect.y = 0; + sScreenRect.w = windowWidth; + sScreenRect.h = windowHeight; + } else { + Layout::recompute(windowWidth, windowHeight); + SDL_Rect backgroundRect; + Layout::getBackgroundRect(&backgroundRect); - SDL_RenderCopy(sRenderer, sBackgroundTexture, nullptr, &backgroundRect); - SDL_RenderPresent(sRenderer); -#endif + SDL_RenderCopy(sRenderer, sBackgroundTexture, nullptr, &backgroundRect); + SDL_RenderPresent(sRenderer); + } setNeedsRefresh(); } @@ -126,19 +156,21 @@ void refresh() { if (!sNeedsRefresh) { return; } -#if EPSILON_SDL_SCREEN_ONLY - Display::draw(sRenderer, &sScreenRect); -#else - SDL_Rect screenRect; - Layout::getScreenRect(&screenRect); - SDL_Rect backgroundRect; - Layout::getBackgroundRect(&backgroundRect); - SDL_SetRenderDrawColor(sRenderer, 194, 194, 194, 255); - SDL_RenderClear(sRenderer); - SDL_RenderCopy(sRenderer, sBackgroundTexture, nullptr, &backgroundRect); - Display::draw(sRenderer, &screenRect); -#endif + if (argument_screen_only) { + Display::draw(sRenderer, &sScreenRect); + } else { + SDL_Rect screenRect; + Layout::getScreenRect(&screenRect); + SDL_Rect backgroundRect; + Layout::getBackgroundRect(&backgroundRect); + + SDL_SetRenderDrawColor(sRenderer, 194, 194, 194, 255); + SDL_RenderClear(sRenderer); + SDL_RenderCopy(sRenderer, sBackgroundTexture, nullptr, &backgroundRect); + Display::draw(sRenderer, &screenRect); + } + SDL_RenderPresent(sRenderer); IonSimulatorCallbackDidRefresh(); diff --git a/ion/src/simulator/shared/platform.h b/ion/src/simulator/shared/platform.h index 4b8e461cb..740eb4b0f 100644 --- a/ion/src/simulator/shared/platform.h +++ b/ion/src/simulator/shared/platform.h @@ -17,15 +17,11 @@ void IonSimulatorTelemetryInit(); void IonSimulatorTelemetryEvent(const char * eventName); void IonSimulatorTelemetryDeinit(); -#if EPSILON_SDL_SCREEN_ONLY - void IonSimulatorKeyboardKeyDown(int keyNumber); void IonSimulatorKeyboardKeyUp(int keyNumber); void IonSimulatorEventsPushEvent(int eventNumber); -#endif - void IonSimulatorCallbackDidRefresh(); void IonSimulatorCallbackDidScanKeyboard();