diff --git a/src/NDS.h b/src/NDS.h index 6b764510..71f6d411 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -92,6 +92,8 @@ extern u32 IE[2]; extern u32 IF[2]; extern Timer Timers[8]; +extern u16 PowerControl9; + extern u16 ExMemCnt[2]; extern u8 ROMSeed0[2*8]; extern u8 ROMSeed1[2*8]; diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index d3184db8..55e95268 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -64,6 +64,9 @@ int ScreenGap = 0; int ScreenLayout = 0; int ScreenSizing = 0; +int MainScreenPos[3]; +int AutoScreenSizing; + uiRect TopScreenRect; uiRect BottomScreenRect; @@ -73,6 +76,9 @@ u32 KeyInputMask; SDL_Joystick* Joystick; +void SetupScreenRects(int width, int height); + + void UpdateWindowTitle(void* data) { @@ -88,6 +94,11 @@ int EmuThreadFunc(void* burp) { NDS::Init(); + MainScreenPos[0] = 0; + MainScreenPos[1] = 0; + MainScreenPos[2] = 0; + AutoScreenSizing = 0; + ScreenDrawInited = false; Touching = false; @@ -174,6 +185,35 @@ int EmuThreadFunc(void* burp) if (EmuRunning == 0) break; + // auto screen layout + { + MainScreenPos[2] = MainScreenPos[1]; + MainScreenPos[1] = MainScreenPos[0]; + MainScreenPos[0] = NDS::PowerControl9 >> 15; + + int guess; + if (MainScreenPos[0] == MainScreenPos[2] && + MainScreenPos[0] != MainScreenPos[1]) + { + // constant flickering, likely displaying 3D on both screens + // TODO: when both screens are used for 2D only...??? + guess = 0; + } + else + { + if (MainScreenPos[0] == 1) + guess = 1; + else + guess = 2; + } + + if (guess != AutoScreenSizing) + { + AutoScreenSizing = guess; + SetupScreenRects(Config::WindowWidth, Config::WindowHeight); + } + } + memcpy(ScreenBuffer, GPU::Framebuffer, 256*384*4); uiAreaQueueRedrawAll(MainDrawArea); @@ -346,10 +386,7 @@ void SetupScreenRects(int width, int height) int sizemode; if (ScreenSizing == 3) - { - // TODO!! auto mode - sizemode = 0; - } + sizemode = AutoScreenSizing; else sizemode = ScreenSizing;