pandora: handle custom size fb for menu layer
[libpicofe.git] / pandora / plat.c
index 7ba6c57..a24e3ba 100644 (file)
 static struct vout_fbdev *main_fb, *layer_fb;\r
 static int g_layer_x, g_layer_y;\r
 static int g_layer_w = 320, g_layer_h = 240;\r
-static int g_osd_fps_x, g_osd_y;\r
+static int g_osd_fps_x, g_osd_y, doing_bg_frame;\r
 \r
 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";\r
 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
-static unsigned char __attribute__((aligned(4))) temp_frame[g_menuscreen_w * g_menuscreen_h * 2];\r
 static unsigned char __attribute__((aligned(4))) fb_copy[g_screen_width * g_screen_height * 2];\r
-unsigned char *PicoDraw2FB = temp_frame;\r
+static void *temp_frame;\r
+unsigned char *PicoDraw2FB;\r
 const char *renderer_names[] = { NULL };\r
 const char *renderer_names32x[] = { NULL };\r
 \r
@@ -207,20 +207,34 @@ void plat_update_volume(int has_changed, int is_up)
        }\r
 }\r
 \r
-static void make_bg(void)\r
+static void make_bg(int no_scale)\r
 {\r
        unsigned short *s = (void *)fb_copy;\r
-       unsigned int t, *d = (unsigned int *)g_menubg_src_ptr + 80 / 2;\r
        int x, y;\r
 \r
-       memset32(g_menubg_src_ptr, 0, 800 * 480 * 2 / 4);\r
-\r
-       for (y = 0; y < 240; y++, s += 320, d += 800*2/2) {\r
-               for (x = 0; x < 320; x++) {\r
-                       t = s[x];\r
-                       t |= t << 16;\r
-                       d[x] = d[x + 800 / 2] = t;\r
+       memset32(g_menubg_src_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2 / 4);\r
+\r
+       if (!no_scale && g_menuscreen_w >= 640 && g_menuscreen_h >= 480) {\r
+               unsigned int t, *d = g_menubg_src_ptr;\r
+               d += (g_menuscreen_h / 2 - 480 / 2) * g_menuscreen_w / 2;\r
+               d += (g_menuscreen_w / 2 - 640 / 2) / 2;\r
+               for (y = 0; y < 240; y++, s += 320, d += g_menuscreen_w*2/2) {\r
+                       for (x = 0; x < 320; x++) {\r
+                               t = s[x];\r
+                               t |= t << 16;\r
+                               d[x] = d[x + g_menuscreen_w / 2] = t;\r
+                       }\r
                }\r
+               return;\r
+       }\r
+\r
+       if (g_menuscreen_w >= 320 && g_menuscreen_h >= 240) {\r
+               unsigned short *d = g_menubg_src_ptr;\r
+               d += (g_menuscreen_h / 2 - 240 / 2) * g_menuscreen_w;\r
+               d += (g_menuscreen_w / 2 - 320 / 2);\r
+               for (y = 0; y < 240; y++, s += 320, d += g_menuscreen_w)\r
+                       memcpy(d, s, 320*2);\r
+               return;\r
        }\r
 }\r
 \r
@@ -236,14 +250,16 @@ void pemu_forced_frame(int no_scale, int do_emu)
 \r
        PicoDrawSetOutFormat(PDF_RGB555, 1);\r
        Pico.m.dirtyPal = 1;\r
+       doing_bg_frame = 1;\r
        if (do_emu)\r
                PicoFrame();\r
        else\r
                PicoFrameDrawOnly();\r
+       doing_bg_frame = 0;\r
 \r
        // making a copy because enabling the layer clears it's mem\r
        memcpy32((void *)fb_copy, g_screen_ptr, sizeof(fb_copy) / 4);\r
-       make_bg(); // FIXME: honour no_scale\r
+       make_bg(no_scale);\r
 \r
        PicoOpt = po_old;\r
 }\r
@@ -273,32 +289,24 @@ static void updateSound(int len)
 \r
 void pemu_sound_start(void)\r
 {\r
-       int target_fps = Pico.m.pal ? 50 : 60;\r
-\r
        PsndOut = NULL;\r
 \r
        if (currentConfig.EmuOpt & EOPT_EN_SOUND)\r
        {\r
-               int snd_excess_add, frame_samples;\r
                int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;\r
 \r
                PsndRerate(Pico.m.frame_count ? 1 : 0);\r
 \r
-               frame_samples = PsndLen;\r
-               snd_excess_add = ((PsndRate - PsndLen * target_fps)<<16) / target_fps;\r
-               if (snd_excess_add != 0)\r
-                       frame_samples++;\r
-\r
                /*\r
-                * for 44k stereo, we do 1470 samples/frame\r
+                * for 44k stereo, we do 1470 samples/emu_frame\r
                 * OMAP driver does power of 2 buffers, so we need at least 4K buffer.\r
                 * The most we can lag is 1K samples, size of OMAP's McBSP FIFO,\r
                 * with 2K sample buffer we might sometimes lag more than that,\r
                 * thus causing underflows.\r
                 */\r
-               printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
-                       PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal);\r
-               sndout_oss_start(PsndRate, frame_samples * 2, is_stereo);\r
+               printf("starting audio: %i len: %i stereo: %i, pal: %i\n",\r
+                       PsndRate, PsndLen, is_stereo, Pico.m.pal);\r
+               sndout_oss_start(PsndRate, is_stereo, 2);\r
                //sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
                PicoWriteSound = updateSound;\r
                plat_update_volume(0, 0);\r
@@ -410,6 +418,9 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols)
 {\r
        int fb_w = 320, fb_h = 240, fb_left = 0, fb_right = 0, fb_top = 0, fb_bottom = 0;\r
 \r
+       if (doing_bg_frame)\r
+               return;\r
+\r
        PicoDrawSetOutFormat(PDF_RGB555, 1);\r
        PicoDrawSetCallbacks(emuscan, NULL);\r
 \r
@@ -490,7 +501,7 @@ void pemu_loop_prep(void)
        }\r
 \r
        // make sure there is no junk left behind the layer\r
-       memset32(g_menuscreen_ptr, 0, 800 * 480 * 2 / 4);\r
+       memset32(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2 / 4);\r
        g_menuscreen_ptr = vout_fbdev_flip(main_fb);\r
 \r
        // emu_video_mode_change will call pnd_setup_layer()\r
@@ -596,10 +607,8 @@ void plat_init(void)
                exit(1);\r
        }\r
 \r
-       if (w != g_menuscreen_w || h != g_menuscreen_h) {\r
-               fprintf(stderr, "%dx%d not supported on %s\n", w, h, main_fb_name);\r
-               goto fail0;\r
-       }\r
+       g_menuscreen_w = w;\r
+       g_menuscreen_h = h;\r
        g_menuscreen_ptr = vout_fbdev_flip(main_fb);\r
 \r
        w = 320; h = 240;\r
@@ -615,8 +624,14 @@ void plat_init(void)
        }\r
        g_screen_ptr = vout_fbdev_flip(layer_fb);\r
 \r
+       temp_frame = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);\r
+       if (temp_frame == NULL) {\r
+               fprintf(stderr, "OOM\n");\r
+               goto fail1;\r
+       }\r
        g_menubg_ptr = temp_frame;\r
        g_menubg_src_ptr = temp_frame;\r
+       PicoDraw2FB = temp_frame;\r
 \r
        sndout_oss_init();\r
        pnd_menu_init();\r