accurate_sprites performance improvement, PSP is untested
[picodrive.git] / platform / gp2x / emu.c
index e3f1148..5f4a0e2 100644 (file)
@@ -53,7 +53,9 @@ char noticeMsg[64];                   // notice msg to draw
 unsigned char *PicoDraw2FB = NULL;  // temporary buffer for alt renderer\r
 int reset_timing = 0;\r
 \r
-static int pico_pen_x = 0, pico_pen_y = 0, pico_inp_mode = 0;\r
+#define PICO_PEN_ADJUST_X 4\r
+#define PICO_PEN_ADJUST_Y 2\r
+static int pico_pen_x = 320/2, pico_pen_y = 240/2, pico_inp_mode = 0;\r
 \r
 static void emu_msg_cb(const char *msg);\r
 static void emu_msg_tray_open(void);\r
@@ -199,7 +201,7 @@ void osd_text(int x, int y, const char *text)
        }\r
 }\r
 \r
-static void cd_leds(void)\r
+static void draw_cd_leds(void)\r
 {\r
 //     static\r
        int old_reg;\r
@@ -227,6 +229,25 @@ static void cd_leds(void)
        }\r
 }\r
 \r
+static void draw_pico_ptr(void)\r
+{\r
+       unsigned short *p = (unsigned short *)gp2x_screen;\r
+\r
+       // only if pen enabled and for 16bit modes\r
+       if (pico_inp_mode == 0 || (PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) return;\r
+\r
+       if (!(Pico.video.reg[12]&1) && !(PicoOpt&POPT_DIS_32C_BORDER))\r
+               p += 32;\r
+\r
+       p += 320 * (pico_pen_y + PICO_PEN_ADJUST_Y);\r
+       p += pico_pen_x + PICO_PEN_ADJUST_X;\r
+       p[0]   ^= 0xffff;\r
+       p[319] ^= 0xffff;\r
+       p[320] ^= 0xffff;\r
+       p[321] ^= 0xffff;\r
+       p[640] ^= 0xffff;\r
+}\r
+\r
 static int EmuScanBegin16(unsigned int num)\r
 {\r
        if (!(Pico.video.reg[1]&8)) num += 8;\r
@@ -270,26 +291,39 @@ static void blit(const char *fps, const char *notice)
                // 8bit accurate renderer\r
                if (Pico.m.dirtyPal)\r
                {\r
+                       int pallen = 0x40;\r
                        Pico.m.dirtyPal = 0;\r
-                       if(Pico.video.reg[0xC]&8) { // shadow/hilight mode\r
+                       if (Pico.video.reg[0xC]&8) // shadow/hilight mode\r
+                       {\r
                                vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
                                vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);\r
                                vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40);\r
                                memcpy32(localPal+0xc0, localPal+0x40, 0x40);\r
-                               localPal[0xc0] = 0x0000c000;\r
-                               localPal[0xd0] = 0x00c00000;\r
-                               localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
-                               localPal[0xf0] = 0x00ffffff;\r
-                               gp2x_video_setpalette(localPal, 0x100);\r
-                       } else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
+                               pallen = 0x100;\r
+                       }\r
+                       else if (rendstatus & PDRAW_ACC_SPRITES) {\r
+                               vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
+                               memcpy32(localPal+0x40, localPal, 0x40);\r
+                               memcpy32(localPal+0x80, localPal, 0x40);\r
+                               memcpy32(localPal+0xc0, localPal, 0x40);\r
+                               pallen = 0x100;\r
+                       }\r
+                       else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
                                vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
                                vidConvCpyRGB32(localPal+0x40, HighPal, 0x40);\r
                                vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40);\r
-                               gp2x_video_setpalette(localPal, 0xc0);\r
-                       } else {\r
+                               pallen = 0xc0;\r
+                       }\r
+                       else {\r
                                vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
-                               gp2x_video_setpalette(localPal, 0x40);\r
                        }\r
+                       if (pallen > 0xc0) {\r
+                               localPal[0xc0] = 0x0000c000;\r
+                               localPal[0xd0] = 0x00c00000;\r
+                               localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
+                               localPal[0xf0] = 0x00ffffff;\r
+                       }\r
+                       gp2x_video_setpalette(localPal, pallen);\r
                }\r
        }\r
 \r
@@ -301,7 +335,9 @@ static void blit(const char *fps, const char *notice)
                        osd_text(osd_fps_x, h, fps);\r
        }\r
        if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))\r
-               cd_leds();\r
+               draw_cd_leds();\r
+       if (PicoAHW & PAHW_PICO)\r
+               draw_pico_ptr();\r
 \r
        //gp2x_video_wait_vsync();\r
        gp2x_video_flip();\r
@@ -404,9 +440,11 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)
                pico_inp_mode++;\r
                if (pico_inp_mode > 2) pico_inp_mode = 0;\r
                switch (pico_inp_mode) {\r
-                       case 0: strcpy(noticeMsg, "Input: Joytick         "); break;\r
-                       case 1: strcpy(noticeMsg, "Input: Pen on Storyware"); break;\r
                        case 2: strcpy(noticeMsg, "Input: Pen on Pad      "); break;\r
+                       case 1: strcpy(noticeMsg, "Input: Pen on Storyware"); break;\r
+                       case 0: strcpy(noticeMsg, "Input: Joytick         ");\r
+                               PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
+                               break;\r
                }\r
                gettimeofday(&noticeMsgTime, 0);\r
        }\r
@@ -424,11 +462,18 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)
        }\r
        if (pico_inp_mode != 0) {\r
                PicoPad[0] &= ~0x0f; // release UDLR\r
-               if (gp2x_keys & GP2X_UP)   { pico_pen_y--; if (pico_pen_y <   0) pico_pen_y =   0; }\r
-               if (gp2x_keys & GP2X_DOWN) { pico_pen_y++; if (pico_pen_y > 251) pico_pen_y = 251; }\r
-               if (gp2x_keys & GP2X_LEFT) { pico_pen_x--; if (pico_pen_x <   0) pico_pen_x =   0; }\r
-               if (gp2x_keys & GP2X_RIGHT){ pico_pen_x++; if (pico_pen_x > 353) pico_pen_x = 353; }\r
-               PicoPicohw.pen_pos[0] = 0x03c + pico_pen_x;\r
+               if (gp2x_keys & GP2X_UP)   { pico_pen_y--; if (pico_pen_y < 0) pico_pen_y = 0; }\r
+               if (gp2x_keys & GP2X_DOWN) { pico_pen_y++; if (pico_pen_y > 239-PICO_PEN_ADJUST_Y) pico_pen_y = 239-PICO_PEN_ADJUST_Y; }\r
+               if (gp2x_keys & GP2X_LEFT) { pico_pen_x--; if (pico_pen_x < 0) pico_pen_x = 0; }\r
+               if (gp2x_keys & GP2X_RIGHT) {\r
+                       int lim = (Pico.video.reg[12]&1) ? 319 : 255;\r
+                       pico_pen_x++;\r
+                       if (pico_pen_x > lim-PICO_PEN_ADJUST_X)\r
+                               pico_pen_x = lim-PICO_PEN_ADJUST_X;\r
+               }\r
+               PicoPicohw.pen_pos[0] = pico_pen_x;\r
+               if (!(Pico.video.reg[12]&1)) PicoPicohw.pen_pos[0] += pico_pen_x/4;\r
+               PicoPicohw.pen_pos[0] += 0x3c;\r
                PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
        }\r
 }\r
@@ -554,7 +599,6 @@ static void RunEvents(unsigned int which)
        }\r
 }\r
 \r
-\r
 static void updateKeys(void)\r
 {\r
        unsigned int keys, keys2, allActions[2] = { 0, 0 }, events;\r