ui, fix for SDL emulation display if resolution != 320x240
authorkub <derkub@gmail.com>
Sun, 31 Jan 2021 19:14:49 +0000 (20:14 +0100)
committerkub <derkub@gmail.com>
Sun, 31 Jan 2021 19:14:49 +0000 (20:14 +0100)
platform/common/emu.c
platform/common/emu.h
platform/common/plat_sdl.c
platform/gp2x/emu.c
platform/linux/emu.c
platform/pandora/plat.c
platform/psp/emu.c

index af07bd5..089189d 100644 (file)
@@ -1212,7 +1212,7 @@ static void mkdir_path(char *path_with_reserve, int pos, const char *name)
                lprintf("failed to create: %s\n", path_with_reserve);\r
 }\r
 \r
-void emu_cmn_forced_frame(int no_scale, int do_emu)\r
+void emu_cmn_forced_frame(int no_scale, int do_emu, void *buf)\r
 {\r
        int po_old = PicoIn.opt;\r
        int y;\r
@@ -1227,7 +1227,7 @@ void emu_cmn_forced_frame(int no_scale, int do_emu)
                PicoIn.opt |= POPT_EN_SOFTSCALE;\r
 \r
        PicoDrawSetOutFormat(PDF_RGB555, 1);\r
-       PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);\r
+       PicoDrawSetOutBuf(buf, g_screen_ppitch * 2);\r
        Pico.m.dirtyPal = 1;\r
        Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
        if (do_emu)\r
index af857bc..512ed71 100644 (file)
@@ -146,7 +146,7 @@ void  emu_sound_stop(void);
 void  emu_sound_wait(void);
 
 /* used by some (but not all) platforms */
-void  emu_cmn_forced_frame(int no_scale, int do_emu);
+void  emu_cmn_forced_frame(int no_scale, int do_emu, void *buf);
 
 /* stuff to be implemented by platform code */
 extern const char *renderer_names[];
index 75dda2c..9557997 100644 (file)
@@ -211,17 +211,23 @@ void plat_video_menu_leave(void)
 
 void plat_video_loop_prepare(void)
 {
-       plat_sdl_change_video_mode(g_screen_width, g_screen_height, 0);
-
        if (plat_sdl_overlay != NULL || plat_sdl_gl_active) {
                g_screen_ptr = shadow_fb;
+               g_screen_width = 320;
+               g_screen_height = 240;
+               g_screen_ppitch = g_screen_width;
        }
        else {
                if (SDL_MUSTLOCK(plat_sdl_screen))
                        SDL_LockSurface(plat_sdl_screen);
                g_screen_ptr = plat_sdl_screen->pixels;
+               g_screen_width = g_menuscreen_w;
+               g_screen_height = g_menuscreen_h;
+               g_screen_ppitch = g_menuscreen_pp;
        }
        plat_video_set_buffer(g_screen_ptr);
+
+       plat_sdl_change_video_mode(g_screen_width, g_screen_height, 0);
 }
 
 void plat_early_init(void)
index d60177e..8837998 100644 (file)
@@ -732,7 +732,7 @@ void pemu_forced_frame(int no_scale, int do_emu)
 \r
        if (!no_scale)\r
                no_scale = currentConfig.scaling == EOPT_SCALE_NONE;\r
-       emu_cmn_forced_frame(no_scale, do_emu);\r
+       emu_cmn_forced_frame(no_scale, do_emu, g_screen_ptr);\r
 \r
        g_menubg_src_ptr = g_screen_ptr;\r
        doing_bg_frame = 0;\r
index b8645b1..bc71f0e 100644 (file)
@@ -81,6 +81,13 @@ static void draw_cd_leds(void)
 #undef p\r
 }\r
 \r
+static unsigned short *get_16bit_start(unsigned short *buf)\r
+{\r
+       // center the output on the screen\r
+       int offs = (g_screen_height-240)/2 * g_screen_ppitch + (g_screen_width-320)/2;\r
+       return buf + offs;\r
+}\r
+\r
 void pemu_finalize_frame(const char *fps, const char *notice)\r
 {\r
        if (!is_16bit_mode()) {\r
@@ -91,11 +98,12 @@ void pemu_finalize_frame(const char *fps, const char *notice)
                unsigned short *pal = Pico.est.HighPal;\r
                int i, x;\r
 \r
+               pd = get_16bit_start(pd);\r
                PicoDrawUpdateHighPal();\r
                for (i = 0; i < out_h; i++, ps += 8) {\r
                        for (x = 0; x < out_w; x++)\r
                                *pd++ = pal[*ps++];\r
-                       pd += 320 - out_w;\r
+                       pd += g_screen_ppitch - out_w;\r
                        ps += 320 - out_w;\r
                }\r
        }\r
@@ -111,7 +119,7 @@ void pemu_finalize_frame(const char *fps, const char *notice)
 void plat_video_set_buffer(void *buf)\r
 {\r
        if (is_16bit_mode())\r
-               PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);\r
+               PicoDrawSetOutBuf(get_16bit_start(buf), g_screen_ppitch * 2);\r
 }\r
 \r
 static void apply_renderer(void)\r
@@ -121,7 +129,7 @@ static void apply_renderer(void)
                PicoIn.opt &= ~POPT_ALT_RENDERER;\r
                PicoIn.opt &= ~POPT_DIS_32C_BORDER;\r
                PicoDrawSetOutFormat(PDF_RGB555, 0);\r
-               PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);\r
+               PicoDrawSetOutBuf(get_16bit_start(g_screen_ptr), g_screen_ppitch * 2);\r
                break;\r
        case RT_8BIT_ACC:\r
                PicoIn.opt &= ~POPT_ALT_RENDERER;\r
@@ -137,7 +145,7 @@ static void apply_renderer(void)
        }\r
 \r
        if (PicoIn.AHW & PAHW_32X)\r
-               PicoDrawSetOutBuf(g_screen_ptr, g_screen_ppitch * 2);\r
+               PicoDrawSetOutBuf(get_16bit_start(g_screen_ptr), g_screen_ppitch * 2);\r
 \r
        Pico.m.dirtyPal = 1;\r
 }\r
@@ -181,11 +189,13 @@ void plat_update_volume(int has_changed, int is_up)
 \r
 void pemu_forced_frame(int no_scale, int do_emu)\r
 {\r
+       unsigned short *pd = get_16bit_start(g_screen_ptr);\r
+\r
        PicoIn.opt &= ~POPT_DIS_32C_BORDER;\r
        PicoDrawSetCallbacks(NULL, NULL);\r
        Pico.m.dirtyPal = 1;\r
 \r
-       emu_cmn_forced_frame(no_scale, do_emu);\r
+       emu_cmn_forced_frame(no_scale, do_emu, pd);\r
 \r
        g_menubg_src_ptr = g_screen_ptr;\r
 }\r
index 5f10b17..0bd151c 100644 (file)
@@ -233,11 +233,10 @@ void plat_update_volume(int has_changed, int is_up)
 void pemu_forced_frame(int no_scale, int do_emu)\r
 {\r
        doing_bg_frame = 1;\r
-       emu_cmn_forced_frame(no_scale, do_emu);\r
+       // making a copy because enabling the layer clears it's mem\r
+       emu_cmn_forced_frame(no_scale, do_emu, fb_copy);\r
        doing_bg_frame = 0;\r
 \r
-       // making a copy because enabling the layer clears it's mem\r
-       memcpy((void *)fb_copy, g_screen_ptr, sizeof(fb_copy));\r
        g_menubg_src_ptr = fb_copy;\r
 }\r
 \r
index 99bca5a..7400873 100644 (file)
@@ -665,7 +665,7 @@ void pemu_forced_frame(int no_scale, int do_emu)
 
        if (!no_scale)
                no_scale = currentConfig.scaling == EOPT_SCALE_NONE;
-       emu_cmn_forced_frame(no_scale, do_emu);
+       emu_cmn_forced_frame(no_scale, do_emu, g_screen_ptr);
 }
 
 /* change the platform output rendering */