From 90326ea1f9c9b4396b9b5e82f78112c4e8e9ce6d Mon Sep 17 00:00:00 2001 From: rofl0r Date: Mon, 25 Oct 2021 03:21:34 +0000 Subject: [PATCH] cli: add scaling the new command line parameter --scale allows to scale the window by a floating point factor. SDL2 stretches it in hardware to the desired size, which makes the scaled window run at almost identical speed to 1x scale. --- desmume/src/commandline.cpp | 5 +++++ desmume/src/commandline.h | 1 + desmume/src/frontend/posix/cli/main.cpp | 21 ++++++++++--------- .../src/frontend/posix/shared/ctrlssdl.cpp | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/desmume/src/commandline.cpp b/desmume/src/commandline.cpp index 2404c45c7..5d6f488b2 100644 --- a/desmume/src/commandline.cpp +++ b/desmume/src/commandline.cpp @@ -81,6 +81,7 @@ CommandLine::CommandLine() , disable_limiter(0) , windowed_fullscreen(0) , frameskip(0) +, scale(1.0) , _rtc_day(-1) , _rtc_hour(-1) { @@ -123,6 +124,7 @@ static const char* help_string = \ " --windowed-fullscreen" ENDL " Launches in windowed fullscreen (same as alt+enter)" ENDL #else +" --scale N scale factor for window; default 1.0" ENDL " --nojoy Disables joystick support" ENDL #endif " --disable-sound Disables the sound output" ENDL @@ -198,6 +200,7 @@ ENDL #define OPT_3D_TEXTURE_UPSCALE 81 #define OPT_GPU_RESOLUTION_MULTIPLIER 82 #define OPT_FRAMESKIP 83 +#define OPT_SCALE 84 #define OPT_JIT_SIZE 100 #define OPT_CONSOLE_TYPE 200 @@ -261,6 +264,7 @@ bool CommandLine::parse(int argc,char **argv) { "windowed-fullscreen", no_argument, &windowed_fullscreen, 1 }, #else { "nojoy", no_argument, &_commandline_linux_nojoy, 1}, + { "scale", required_argument, NULL, OPT_SCALE}, #endif { "frameskip", required_argument, NULL, OPT_FRAMESKIP}, { "disable-sound", no_argument, &disable_sound, 1}, @@ -339,6 +343,7 @@ bool CommandLine::parse(int argc,char **argv) case OPT_3D_RENDER: _render3d = optarg; break; case OPT_3D_TEXTURE_UPSCALE: texture_upscale = atoi(optarg); break; case OPT_GPU_RESOLUTION_MULTIPLIER: gpu_resolution_multiplier = atoi(optarg); break; + case OPT_SCALE: scale = atof(optarg); break; case OPT_FRAMESKIP: frameskip = atoi(optarg); break; //RTC settings diff --git a/desmume/src/commandline.h b/desmume/src/commandline.h index 4f87f8a6e..e75bd795c 100644 --- a/desmume/src/commandline.h +++ b/desmume/src/commandline.h @@ -49,6 +49,7 @@ public: int texture_upscale; int gpu_resolution_multiplier; int language; + float scale; std::string nds_file; std::string play_movie_file; std::string record_movie_file; diff --git a/desmume/src/frontend/posix/cli/main.cpp b/desmume/src/frontend/posix/cli/main.cpp index 0d3d03530..f012cef5a 100644 --- a/desmume/src/frontend/posix/cli/main.cpp +++ b/desmume/src/frontend/posix/cli/main.cpp @@ -262,17 +262,17 @@ static void resizeWindow_stub (u16 width, u16 height, void *screen_texture) { } -static void -Draw( void) { +static void Draw(class configured_features *cfg) { + const float scale = cfg->scale; + const unsigned w = GPU_FRAMEBUFFER_NATIVE_WIDTH, h = GPU_FRAMEBUFFER_NATIVE_HEIGHT; + const int ws = w * scale, hs = h * scale; const NDSDisplayInfo &displayInfo = GPU->GetDisplayInfo(); - const size_t pixCount = GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT; + const size_t pixCount = w * h; ColorspaceApplyIntensityToBuffer16(displayInfo.nativeBuffer16[NDSDisplayID_Main], pixCount, displayInfo.backlightIntensity[NDSDisplayID_Main]); ColorspaceApplyIntensityToBuffer16(displayInfo.nativeBuffer16[NDSDisplayID_Touch], pixCount, displayInfo.backlightIntensity[NDSDisplayID_Touch]); - static const SDL_Rect destrect[2] = { - { 0,0, - GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT}, - { 0, GPU_FRAMEBUFFER_NATIVE_HEIGHT, - GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT}, + SDL_Rect destrect[2] = { + { 0, 0 , ws, hs}, + { 0, hs, ws, hs}, }; unsigned i, off = 0, n = pixCount*2; for(i = 0; i < 2; ++i) { @@ -481,9 +481,10 @@ int main(int argc, char ** argv) { return 1; } + nds_screen_size_ratio = my_config.scale; sdl_videoFlags |= SDL_WINDOW_OPENGL; window = SDL_CreateWindow( "Desmume SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - 256, 384, sdl_videoFlags ); + 256*my_config.scale, 384*my_config.scale, sdl_videoFlags ); if ( !window ) { fprintf( stderr, "Window creation failed: %s\n", SDL_GetError( ) ); @@ -541,7 +542,7 @@ int main(int argc, char ** argv) { DrawHUD(); #endif - Draw(); + Draw(&my_config); #ifdef HAVE_LIBAGG osd->clear(); diff --git a/desmume/src/frontend/posix/shared/ctrlssdl.cpp b/desmume/src/frontend/posix/shared/ctrlssdl.cpp index febf08e27..bc073b43b 100644 --- a/desmume/src/frontend/posix/shared/ctrlssdl.cpp +++ b/desmume/src/frontend/posix/shared/ctrlssdl.cpp @@ -259,7 +259,7 @@ u16 get_set_joy_key(int index) { static signed long screen_to_touch_range( signed long scr, float size_ratio) { - return (signed long)((float)scr * size_ratio); + return (signed long)((float)scr / size_ratio); } /* Set mouse coordinates */