bring pandora to buildable state. Some cleanups and fixes along the way.
[libpicofe.git] / pandora / emu.c
index 673c963..3b9e62c 100644 (file)
 \r
 #include <stdarg.h>\r
 \r
-#include "../gp2x/emu.h"\r
-#include "../gp2x/menu.h"\r
-#include "../gp2x/gp2x.h"\r
 #include "../common/arm_utils.h"\r
 #include "../common/fonts.h"\r
 #include "../common/emu.h"\r
+#include "../common/menu.h"\r
 #include "../common/config.h"\r
 #include "../common/common.h"\r
 #include "../common/input.h"\r
@@ -182,7 +180,7 @@ void osd_text(int x, int y, const char *text)
                x &= ~3; // align x\r
                len = (len+3) >> 2;\r
                for (h = 0; h < 8; h++) {\r
-                       p = (int *) ((unsigned char *) gp2x_screen+x+g_screen_width*(y+h));\r
+                       p = (int *) ((unsigned char *) g_screen_ptr+x+g_screen_width*(y+h));\r
                        for (i = len; i; i--, p++) *p = 0xe0e0e0e0;\r
                }\r
                emu_textOut8(x, y, text);\r
@@ -191,7 +189,7 @@ void osd_text(int x, int y, const char *text)
                x &= ~1; // align x\r
                len++;\r
                for (h = 0; h < 16; h++) {\r
-                       p = (int *) ((unsigned short *) gp2x_screen+x+g_screen_width*(y+h));\r
+                       p = (int *) ((unsigned short *) g_screen_ptr+x+g_screen_width*(y+h));\r
                        for (i = len; i; i--, p++) *p = 0;//(*p>>2)&0x39e7;\r
                }\r
                textOut16(x, y, text);\r
@@ -209,15 +207,15 @@ static void draw_cd_leds(void)
                // 8-bit modes\r
                unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r
                unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r
-               *(unsigned int *)((char *)gp2x_screen + g_screen_width*2+ 4) =\r
-               *(unsigned int *)((char *)gp2x_screen + g_screen_width*3+ 4) =\r
-               *(unsigned int *)((char *)gp2x_screen + g_screen_width*4+ 4) = col_g;\r
-               *(unsigned int *)((char *)gp2x_screen + g_screen_width*2+12) =\r
-               *(unsigned int *)((char *)gp2x_screen + g_screen_width*3+12) =\r
-               *(unsigned int *)((char *)gp2x_screen + g_screen_width*4+12) = col_r;\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+ 4) =\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+ 4) =\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+ 4) = col_g;\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+12) =\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+12) =\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+12) = col_r;\r
        } else {\r
                // 16-bit modes\r
-               unsigned int *p = (unsigned int *)((short *)gp2x_screen + g_screen_width*2+4);\r
+               unsigned int *p = (unsigned int *)((short *)g_screen_ptr + g_screen_width*2+4);\r
                unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;\r
                unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;\r
                *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;\r
@@ -228,7 +226,7 @@ static void draw_cd_leds(void)
 \r
 static void draw_pico_ptr(void)\r
 {\r
-       unsigned short *p = (unsigned short *)gp2x_screen;\r
+       unsigned short *p = (unsigned short *)g_screen_ptr;\r
 \r
        // only if pen enabled and for 16bit modes\r
        if (pico_inp_mode == 0 || (PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) return;\r
@@ -250,9 +248,9 @@ static void draw_pico_ptr(void)
 static int EmuScanBegin16(unsigned int num)\r
 {\r
        if (!(Pico.video.reg[1]&8)) num += 8;\r
-       DrawLineDest = (unsigned short *)gp2x_screen + num*800 + 800/2 - 320/2;\r
+       DrawLineDest = (unsigned short *)g_screen_ptr + num*800 + 800/2 - 320/2;\r
        //int w = (Pico.video.reg[12]&1) ? 320 : 256;\r
-       //DrawLineDest = (unsigned short *)gp2x_screen + num*w;\r
+       //DrawLineDest = (unsigned short *)g_screen_ptr + num*w;\r
 \r
        return 0;\r
 }\r
@@ -268,7 +266,7 @@ static int EmuScanEnd16(unsigned int num)
        int len, mask = 0xff;\r
 \r
        if (!(Pico.video.reg[1]&8)) num += 8;\r
-       pd=(unsigned short *)gp2x_screen + num*800*2 + 800/2 - 320*2/2;\r
+       pd=(unsigned short *)g_screen_ptr + num*800*2 + 800/2 - 320*2/2;\r
 \r
        if (Pico.m.dirtyPal)\r
                PicoDoHighPal555(sh);\r
@@ -301,14 +299,6 @@ static int EmuScanEnd16(unsigned int num)
 \r
 #endif // USE_320_SCREEN\r
 \r
-static int EmuScanBegin8(unsigned int num)\r
-{\r
-       if (!(Pico.video.reg[1]&8)) num += 8;\r
-       DrawLineDest = (unsigned char *)  gp2x_screen + g_screen_width * num;\r
-\r
-       return 0;\r
-}\r
-\r
 int localPal[0x100];\r
 static void (*vidCpyM2)(void *dest, void *src) = NULL;\r
 \r
@@ -323,13 +313,13 @@ static void blit(const char *fps, const char *notice)
                        Pico.m.dirtyPal = 0;\r
                        vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
                        // feed new palette to our device\r
-                       gp2x_video_setpalette(localPal, 0x40);\r
+                       // gp2x_video_setpalette(localPal, 0x40);\r
                }\r
                // a hack for VR\r
                if (PicoRead16Hook == PicoSVPRead16)\r
                        memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);\r
                // do actual copy\r
-               vidCpyM2((unsigned char *)gp2x_screen+g_screen_width*8, PicoDraw2FB+328*8);\r
+               vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8);\r
        }\r
        else if (!(emu_opt&0x80))\r
        {\r
@@ -362,7 +352,7 @@ static void blit(const char *fps, const char *notice)
                                localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
                                localPal[0xf0] = 0x00ffffff;\r
                        }\r
-                       gp2x_video_setpalette(localPal, pallen);\r
+                       // gp2x_video_setpalette(localPal, pallen);\r
                }\r
        }\r
 \r
@@ -377,33 +367,24 @@ static void blit(const char *fps, const char *notice)
                draw_cd_leds();\r
        if (PicoAHW & PAHW_PICO)\r
                draw_pico_ptr();\r
-{\r
-//static int u=0;\r
-//memset((char *)gp2x_screen+800*471*2, (u++)>>1, 800*9*2);\r
-}\r
 \r
        //gp2x_video_wait_vsync();\r
-       gp2x_video_flip();\r
+       // gp2x_video_flip();\r
 }\r
 \r
 \r
 // clears whole screen or just the notice area (in all buffers)\r
 static void clearArea(int full)\r
 {\r
-       if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
-               // 8-bit renderers\r
-               if (full) gp2x_memset_all_buffers(0, 0xe0, g_screen_width*240);\r
-               else      gp2x_memset_all_buffers(g_screen_width*232, 0xe0, g_screen_width*8);\r
-       } else {\r
-               // 16bit accurate renderer\r
-               if (full) gp2x_memset_all_buffers(0, 0, g_screen_width*g_screen_height*2);\r
-               else      gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16)*2, 0, g_screen_width*16*2);\r
-       }\r
+       if (full) memset(g_screen_ptr, 0, g_screen_width*g_screen_height*2);\r
+       else      memset((short *)g_screen_ptr + g_screen_width * (g_screen_height - 16), 0,\r
+                       g_screen_width * 16 * 2);\r
 }\r
 \r
 \r
 static void vidResetMode(void)\r
 {\r
+#if 0\r
        if (PicoOpt&0x10) {\r
                gp2x_video_changemode(8);\r
        } else if (currentConfig.EmuOpt&0x80) {\r
@@ -435,27 +416,37 @@ static void vidResetMode(void)
        if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8))\r
             gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224);\r
        else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240);\r
+#else\r
+#ifdef USE_320_SCREEN\r
+       PicoDrawSetColorFormat(1);\r
+       PicoScanBegin = EmuScanBegin16;\r
+#else\r
+       PicoDrawSetColorFormat(-1);\r
+       PicoScanEnd = EmuScanEnd16;\r
+#endif\r
+#endif\r
 }\r
 \r
 \r
 static void emu_msg_cb(const char *msg)\r
 {\r
+/*\r
        if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
                // 8-bit renderers\r
                gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16), 0xe0, g_screen_width*16);\r
                osd_text(4, g_screen_height-16, msg);\r
-               gp2x_memcpy_all_buffers((char *)gp2x_screen+g_screen_width*(g_screen_height-16),\r
+               gp2x_memcpy_all_buffers((char *)g_screen_ptr+g_screen_width*(g_screen_height-16),\r
                        g_screen_width*(g_screen_height-16), g_screen_width*16);\r
        } else {\r
                // 16bit accurate renderer\r
                gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16)*2, 0, g_screen_width*16*2);\r
                osd_text(4, g_screen_height-16, msg);\r
-               gp2x_memcpy_all_buffers((char *)gp2x_screen+g_screen_width*(g_screen_height-16)*2,\r
+               gp2x_memcpy_all_buffers((char *)g_screen_ptr+g_screen_width*(g_screen_height-16)*2,\r
                        g_screen_width*(g_screen_height-16)*2, g_screen_width*16*2);\r
        }\r
        gettimeofday(&noticeMsgTime, 0);\r
        noticeMsgTime.tv_sec -= 2;\r
-\r
+*/\r
        /* assumption: emu_msg_cb gets called only when something slow is about to happen */\r
        reset_timing = 1;\r
 }\r
@@ -582,7 +573,7 @@ static void RunEvents(unsigned int which)
                if (do_it) {\r
                        osd_text(4, g_screen_height-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");\r
                        PicoStateProgressCB = emu_state_cb;\r
-                       gp2x_memcpy_all_buffers(gp2x_screen, 0, g_screen_width*g_screen_height*2);\r
+                       //gp2x_memcpy_all_buffers(g_screen_ptr, 0, g_screen_width*g_screen_height*2);\r
                        emu_SaveLoadGame((which & 0x1000) >> 12, 0);\r
                        PicoStateProgressCB = NULL;\r
                }\r
@@ -707,7 +698,7 @@ void emu_forcedFrame(int opts)
                clearArea(1);\r
        } else  vidCpyM2 = vidCpyM2_40col;\r
 \r
-       vidCpyM2((unsigned char *)gp2x_screen+g_screen_width*8, PicoDraw2FB+328*8);\r
+       vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8);\r
        vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
        gp2x_video_setpalette(localPal, 0x40);\r
 */\r
@@ -806,7 +797,7 @@ void emu_Loop(void)
        // calc vsync offset to sync timing code with vsync\r
        if (currentConfig.EmuOpt&0x2000) {\r
                gettimeofday(&tval, 0);\r
-               gp2x_video_wait_vsync();\r
+               //gp2x_video_wait_vsync();\r
                gettimeofday(&tval, 0);\r
                vsync_offset = tval.tv_usec;\r
                while (vsync_offset >= target_frametime)\r
@@ -863,9 +854,9 @@ void emu_Loop(void)
                                        vidCpyM2 = vidCpyM2_32col;\r
                                }\r
                        }\r
-                       if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode\r
-                            gp2x_video_RGB_setscaling(8, scalex, 224);\r
-                       else gp2x_video_RGB_setscaling(0, scalex, 240);\r
+                       //if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode\r
+                       //      gp2x_video_RGB_setscaling(8, scalex, 224);\r
+                       // else gp2x_video_RGB_setscaling(0, scalex, 240);\r
                        oldmodes = modes;\r
                        clearArea(1);\r
                }\r
@@ -966,7 +957,7 @@ void emu_Loop(void)
                                if (vsync_offset) {\r
                                        if (lim_time - tval.tv_usec > target_frametime/2)\r
                                                simpleWait(pthissec, lim_time - target_frametime/4);\r
-                                       gp2x_video_wait_vsync();\r
+                                       // gp2x_video_wait_vsync();\r
                                } else {\r
                                        simpleWait(pthissec, lim_time);\r
                                }\r