add savestate preview
authornotaz <notasas@gmail.com>
Tue, 4 Jan 2011 17:36:35 +0000 (19:36 +0200)
committernotaz <notasas@gmail.com>
Tue, 4 Jan 2011 17:36:35 +0000 (19:36 +0200)
frontend/common/menu.c
frontend/menu.c

index f7085fa..ae1ff57 100644 (file)
@@ -653,7 +653,7 @@ static void draw_menu_credits(void (*draw_more)(void))
                p++;\r
        }\r
 \r
                p++;\r
        }\r
 \r
-       x = g_menuscreen_w  / 2 - w * me_mfont_w / 2;\r
+       x = g_menuscreen_w / 2 - w * me_mfont_w / 2;\r
        y = g_menuscreen_h / 2 - h * me_mfont_h / 2;\r
        if (x < 0) x = 0;\r
        if (y < 0) y = 0;\r
        y = g_menuscreen_h / 2 - h * me_mfont_h / 2;\r
        if (x < 0) x = 0;\r
        if (y < 0) y = 0;\r
@@ -949,6 +949,10 @@ static void draw_savestate_menu(int menu_sel, int is_loading)
        if (x < 0) x = 0;\r
        y = g_menuscreen_h / 2 - h / 2;\r
        if (y < 0) y = 0;\r
        if (x < 0) x = 0;\r
        y = g_menuscreen_h / 2 - h / 2;\r
        if (y < 0) y = 0;\r
+#ifdef MENU_ALIGN_LEFT\r
+       if (x > 12 + me_mfont_w * 2)\r
+               x = 12 + me_mfont_w * 2;\r
+#endif\r
 \r
        menu_draw_begin(1);\r
 \r
 \r
        menu_draw_begin(1);\r
 \r
index e04d19e..9036d5f 100644 (file)
@@ -12,6 +12,7 @@
 #include <string.h>
 #include <errno.h>
 #include <dlfcn.h>
 #include <string.h>
 #include <errno.h>
 #include <dlfcn.h>
+#include <zlib.h>
 
 #include "main.h"
 #include "menu.h"
 
 #include "main.h"
 #include "menu.h"
@@ -128,10 +129,6 @@ static int emu_save_load_game(int load, int sram)
        return ret;
 }
 
        return ret;
 }
 
-static void draw_savestate_bg(int slot)
-{
-}
-
 static void menu_set_defconfig(void)
 {
        scaling = SCALE_4_3;
 static void menu_set_defconfig(void)
 {
        scaling = SCALE_4_3;
@@ -389,11 +386,80 @@ static unsigned short fname2color(const char *fname)
        return 0xffff;
 }
 
        return 0xffff;
 }
 
+static void draw_savestate_bg(int slot);
+
 #define MENU_ALIGN_LEFT
 #define menu_init menu_init_common
 #include "common/menu.c"
 #undef menu_init
 
 #define MENU_ALIGN_LEFT
 #define menu_init menu_init_common
 #include "common/menu.c"
 #undef menu_init
 
+// a bit of black magic here
+static void draw_savestate_bg(int slot)
+{
+       extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
+       static const int psx_widths[8]  = { 256, 368, 320, 384, 512, 512, 640, 640 };
+       int x, y, w, h;
+       char fname[MAXPATHLEN];
+       GPUFreeze_t *gpu;
+       u16 *s, *d;
+       gzFile f;
+       int ret;
+       u32 tmp;
+
+       ret = get_state_filename(fname, sizeof(fname), slot);
+       if (ret != 0)
+               return;
+
+       f = gzopen(fname, "rb");
+       if (f == NULL)
+               return;
+
+       if (gzseek(f, 0x29933d, SEEK_SET) != 0x29933d) {
+               fprintf(stderr, "gzseek failed\n");
+               gzclose(f);
+               return;
+       }
+
+       gpu = malloc(sizeof(*gpu));
+       if (gpu == NULL) {
+               gzclose(f);
+               return;
+       }
+
+       ret = gzread(f, gpu, sizeof(*gpu));
+       gzclose(f);
+       if (ret != sizeof(*gpu)) {
+               fprintf(stderr, "gzread failed\n");
+               goto out;
+       }
+
+       memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
+
+       if ((gpu->ulStatus & 0x800000) || (gpu->ulStatus & 0x200000))
+               goto out; // disabled || 24bpp (NYET)
+
+       x = gpu->ulControl[5] & 0x3ff;
+       y = (gpu->ulControl[5] >> 10) & 0x1ff;
+       s = (u16 *)gpu->psxVRam + y * 1024 + (x & ~3);
+       w = psx_widths[(gpu->ulStatus >> 16) & 7];
+       tmp = gpu->ulControl[7];
+       h = ((tmp >> 10) & 0x3ff) - (tmp & 0x3ff);
+       if (gpu->ulStatus & 0x80000) // doubleheight
+               h *= 2;
+
+       x = max(0, g_menuscreen_w - w) & ~3;
+       y = max(0, g_menuscreen_h / 2 - h / 2);
+       w = min(g_menuscreen_w, w);
+       h = min(g_menuscreen_h, h);
+       d = (u16 *)g_menubg_ptr + g_menuscreen_w * y + x;
+
+       for (; h > 0; h--, d += g_menuscreen_w, s += 1024)
+               bgr555_to_rgb565(d, s, w * 2);
+
+out:
+       free(gpu);
+}
+
 // ---------- pandora specific -----------
 
 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";
 // ---------- pandora specific -----------
 
 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";