core+platforms, revise pico pen handling
authorkub <derkub@gmail.com>
Sun, 17 Mar 2024 09:44:57 +0000 (10:44 +0100)
committerkub <derkub@gmail.com>
Mon, 18 Mar 2024 17:24:54 +0000 (18:24 +0100)
the MSB in the tablet position register denotes pen on surface.
add logic and a hotkey for handling pen not on surface. This allows
for repositioning of the pen without the storyware reacting to it.

12 files changed:
pico/pico/pico.c
platform/common/emu.c
platform/common/emu.h
platform/common/input_pico.h
platform/common/inputmap_kbd.c
platform/common/menu_pico.c
platform/gp2x/emu.c
platform/libretro/libretro.c
platform/linux/emu.c
platform/pandora/plat.c
platform/ps2/emu.c
platform/psp/emu.c

index d190a94..99f21f4 100644 (file)
@@ -36,6 +36,8 @@ static void PicoResetPico(void)
   PicoPicohw.fifo_bytes = 0;
   PicoPicohw.r12 = 0;
 
+  PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;
+
   PicoPicoPCMIrqEn(0);
   PicoPicoPCMFilter(0);
   PicoPicoPCMGain(8);
index 6895498..d576b43 100644 (file)
@@ -1050,10 +1050,9 @@ void run_events_pico(unsigned int events)
                switch (pico_inp_mode) {\r
                        case 2: emu_status_msg("Input: Pen on Pad"); break;\r
                        case 1: emu_status_msg("Input: Pen on Storyware"); break;\r
-                       case 0: emu_status_msg("Input: Joystick");\r
-                               PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
-                               break;\r
+                       case 0: emu_status_msg("Input: Joystick"); break;\r
                }\r
+               PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
        }\r
        if (events & PEV_PICO_PPREV) {\r
                PicoPicohw.page--;\r
@@ -1067,10 +1066,15 @@ void run_events_pico(unsigned int events)
                        PicoPicohw.page = 6;\r
                emu_status_msg("Page %i", PicoPicohw.page);\r
        }\r
-       if (events & PEV_PICO_PEN) {\r
+       if (events & PEV_PICO_SHPEN) {\r
                currentConfig.EmuOpt ^= EOPT_PICO_PEN;\r
                emu_status_msg("%s Pen", currentConfig.EmuOpt & EOPT_PICO_PEN ? "Show" : "Hide");\r
        }\r
+       if (events & PEV_PICO_PPOSV) {\r
+               PicoPicohw.pen_pos[0] ^= 0x8000;\r
+               PicoPicohw.pen_pos[1] ^= 0x8000;\r
+               emu_status_msg("Pen %s", PicoPicohw.pen_pos[0] & 0x8000 ? "Up" : "Down");\r
+       }\r
 \r
        if (pico_inp_mode == 0)\r
                return;\r
@@ -1084,15 +1088,17 @@ void run_events_pico(unsigned int events)
 \r
        if (pico_pen_y < PICO_PEN_ADJUST_Y)\r
                pico_pen_y = PICO_PEN_ADJUST_Y;\r
-       if (pico_pen_y > 224 - PICO_PEN_ADJUST_Y)\r
-               pico_pen_y = 224 - PICO_PEN_ADJUST_Y;\r
+       if (pico_pen_y > 224-1 - PICO_PEN_ADJUST_Y)\r
+               pico_pen_y = 224-1 - PICO_PEN_ADJUST_Y;\r
        if (pico_pen_x < PICO_PEN_ADJUST_X)\r
                pico_pen_x = PICO_PEN_ADJUST_X;\r
-       if (pico_pen_x > 320 - PICO_PEN_ADJUST_X)\r
-               pico_pen_x = 320 - PICO_PEN_ADJUST_X;\r
+       if (pico_pen_x > 320-1 - PICO_PEN_ADJUST_X)\r
+               pico_pen_x = 320-1 - PICO_PEN_ADJUST_X;\r
 \r
-       PicoPicohw.pen_pos[0] = 0x03c + pico_pen_x;\r
-       PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
+       PicoPicohw.pen_pos[0] &= 0x8000;\r
+       PicoPicohw.pen_pos[1] &= 0x8000;\r
+       PicoPicohw.pen_pos[0] |= 0x03c + pico_pen_x;\r
+       PicoPicohw.pen_pos[1] |= (pico_inp_mode == 1 ? 0x2f8 : 0x1fc) + pico_pen_y;\r
 }\r
 \r
 static void do_turbo(unsigned short *pad, int acts)\r
index d32cf70..959ce0b 100644 (file)
@@ -107,8 +107,8 @@ extern unsigned char *movie_data;
 extern int reset_timing;
 extern int flip_after_sync;
 
-#define PICO_PEN_ADJUST_X 2
-#define PICO_PEN_ADJUST_Y 2
+#define PICO_PEN_ADJUST_X 1
+#define PICO_PEN_ADJUST_Y 1
 extern int pico_pen_x, pico_pen_y;
 extern int pico_inp_mode;
 
index b3138d0..10d6511 100644 (file)
@@ -28,8 +28,9 @@
 #define PEVB_PICO_PNEXT 21
 #define PEVB_PICO_PPREV 20
 #define PEVB_PICO_SWINP 19
-#define PEVB_PICO_PEN   18
-#define PEVB_RESET      17
+#define PEVB_PICO_SHPEN 18
+#define PEVB_PICO_PPOSV 17
+#define PEVB_RESET      16
 
 #define PEV_VOL_DOWN    (1 << PEVB_VOL_DOWN)
 #define PEV_VOL_UP      (1 << PEVB_VOL_UP)
 #define PEV_PICO_PNEXT  (1 << PEVB_PICO_PNEXT)
 #define PEV_PICO_PPREV  (1 << PEVB_PICO_PPREV)
 #define PEV_PICO_SWINP  (1 << PEVB_PICO_SWINP)
-#define PEV_PICO_PEN    (1 << PEVB_PICO_PEN)
+#define PEV_PICO_SHPEN  (1 << PEVB_PICO_SHPEN)
+#define PEV_PICO_PPOSV  (1 << PEVB_PICO_PPOSV)
 #define PEV_RESET       (1 << PEVB_RESET)
 
-#define PEV_MASK 0x7ffe0000
+#define PEV_MASK 0x7fff0000
 
 #endif /* INCLUDE_c48097f3ff2a6a9af1cce8fd7a9b3f0c */
index 0386511..821a8ee 100644 (file)
@@ -30,7 +30,8 @@ const struct in_default_bind in_sdl_defbinds[] = {
        { SDLK_F6,     IN_BINDTYPE_EMU, PEVB_PICO_PPREV },
        { SDLK_F7,     IN_BINDTYPE_EMU, PEVB_PICO_PNEXT },
        { SDLK_F8,     IN_BINDTYPE_EMU, PEVB_PICO_SWINP },
-       { SDLK_F9,     IN_BINDTYPE_EMU, PEVB_PICO_PEN },
+       { SDLK_F9,     IN_BINDTYPE_EMU, PEVB_PICO_SHPEN },
+       { SDLK_F10,    IN_BINDTYPE_EMU, PEVB_PICO_PPOSV },
        { SDLK_BACKSPACE, IN_BINDTYPE_EMU, PEVB_FF },
        { 0, 0, 0 }
 };
index 78dfcc3..ffd9161 100644 (file)
@@ -362,7 +362,8 @@ me_bind_action emuctrl_actions[] =
        { "Pico Next page   ", PEV_PICO_PNEXT },
        { "Pico Prev page   ", PEV_PICO_PPREV },
        { "Pico Switch input", PEV_PICO_SWINP },
-       { "Pico Display pen ", PEV_PICO_PEN },
+       { "Pico Pen sensor  ", PEV_PICO_PPOSV },
+       { "Pico Show pen    ", PEV_PICO_SHPEN },
        { NULL,                0 }
 };
 
index 460b154..f20f29a 100644 (file)
@@ -194,10 +194,11 @@ static void draw_cd_leds(void)
 \r
 static void draw_pico_ptr(void)\r
 {\r
+       int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000;\r
        int x, y, pitch = 320, offs;\r
 \r
-       x = ((pico_pen_x * colcount * ((1ULL<<32) / 320)) >> 32) + firstcol;\r
-       y = ((pico_pen_y * linecount * ((1ULL<<32) / 224)) >> 32) + firstline;\r
+       x = ((pico_pen_x * colcount  * ((1ULL<<32)/320 + 1)) >> 32) + firstcol;\r
+       y = ((pico_pen_y * linecount * ((1ULL<<32)/224 + 1)) >> 32) + firstline;\r
 \r
        if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {\r
                pitch = 240;\r
@@ -207,16 +208,18 @@ static void draw_pico_ptr(void)
 \r
        if (is_16bit_mode()) {\r
                unsigned short *p = (unsigned short *)g_screen_ptr + offs;\r
+               int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000);\r
 \r
-                                       p[0]       ^= 0xffff;\r
-               p[pitch-1] ^= 0xffff;   p[pitch]   ^= 0xffff;   p[pitch+1] ^= 0xffff;\r
-                                       p[pitch*2] ^= 0xffff;\r
+               p[-pitch-1] ^= _; p[-pitch] ^= o; p[-pitch+1] ^= _;\r
+               p[1]        ^= o; p[0]      ^= o; p[1]        ^= o;\r
+               p[pitch-1]  ^= _; p[pitch]  ^= o; p[pitch+1]  ^= _;\r
        } else {\r
                unsigned char *p = (unsigned char *)g_screen_ptr + offs;\r
+               int o = (up ? 0xe0 : 0xf0), _ = (up ? 0xf0 : 0xe0);\r
 \r
-               p[-1]        = 0xe0;    p[0]       = 0xf0;      p[1]         = 0xe0;\r
-               p[pitch-1]   = 0xf0;    p[pitch]   = 0xf0;      p[pitch+1]   = 0xf0;\r
-               p[2*pitch-1] = 0xe0;    p[2*pitch] = 0xf0;      p[2*pitch+1] = 0xe0;\r
+               p[-pitch-1]  = _; p[-pitch]  = o; p[-pitch+1]  = _;\r
+               p[-1]        = o; p[0]       = o; p[1]         = o;\r
+               p[pitch-1]   = _; p[pitch]   = o; p[pitch+1]   = _;\r
        }\r
 }\r
 \r
index 600c015..26b89ac 100644 (file)
@@ -154,7 +154,7 @@ static bool retro_audio_buff_underrun      = false;
 static unsigned audio_latency              = 0;
 static bool update_audio_latency           = false;
 static uint16_t pico_events;
-int pico_inp_mode;
+int pico_inp_mode, pico_pen_visible;
 int pico_pen_x = 320/2, pico_pen_y = 240/2;
 
 static void retro_audio_buff_status_cb(
@@ -1455,6 +1455,8 @@ bool retro_load_game(const struct retro_game_info *info)
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B,     "Red Button" },
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "Pen Button" },
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT,"Switch input" },
+      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Pen sensor" },
+      { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X,     "Pen visibility" },
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L,     "Previous page" },
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R,     "Next page" },
 
@@ -2055,6 +2057,22 @@ void emu_status_msg(const char *format, ...)
     environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &rmsg);
 }
 
+static void draw_pico_ptr(void)
+{
+   int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000;
+   int x, y, pitch = vout_width, offs;
+   unsigned short *p = (unsigned short *)((char *)vout_buf + vout_offset);
+   int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000);
+
+   x = ((pico_pen_x * vout_width  * ((1ULL<<32) / 320 + 1)) >> 32);
+   y = ((pico_pen_y * vout_height * ((1ULL<<32) / 224 + 1)) >> 32);
+   p += x + y * pitch;
+
+   p[-pitch-1] ^= _; p[-pitch] ^= o; p[-pitch+1] ^= _;
+   p[-1]       ^= o; p[0]      ^= o; p[1]        ^= o;
+   p[pitch-1]  ^= _; p[pitch]  ^= o; p[pitch+1]  ^= _;
+}
+
 void run_events_pico(unsigned int events)
 {
     int lim_x;
@@ -2066,10 +2084,9 @@ void run_events_pico(unsigned int events)
        switch (pico_inp_mode) {
        case 2: emu_status_msg("Input: Pen on Pad"); break;
        case 1: emu_status_msg("Input: Pen on Storyware"); break;
-       case 0: emu_status_msg("Input: Joystick");
-           PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;
-           break;
+       case 0: emu_status_msg("Input: Joystick"); break;
        }
+       PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;
     }
     if (events & (1 << RETRO_DEVICE_ID_JOYPAD_L)) {
        PicoPicohw.page--;
@@ -2083,6 +2100,15 @@ void run_events_pico(unsigned int events)
            PicoPicohw.page = 6;
        emu_status_msg("Page %i", PicoPicohw.page);
     }
+    if (events & (1 << RETRO_DEVICE_ID_JOYPAD_X)) {
+        pico_pen_visible = !pico_pen_visible;
+        emu_status_msg("%s Pen", pico_pen_visible ? "Show" : "Hide");
+    }
+    if (events & (1 << RETRO_DEVICE_ID_JOYPAD_START)) {
+        PicoPicohw.pen_pos[0] ^= 0x8000;
+        PicoPicohw.pen_pos[1] ^= 0x8000;
+        emu_status_msg("Pen %s", PicoPicohw.pen_pos[0] & 0x8000 ? "Up" : "Down");
+    }
 
     if (pico_inp_mode == 0)
        return;
@@ -2094,21 +2120,19 @@ void run_events_pico(unsigned int events)
     if (PicoIn.pad[0] & 8) pico_pen_x++;
     PicoIn.pad[0] &= ~0x0f; // release UDLR
 
-    lim_x = (Pico.video.reg[12]&1) ? 319 : 255;
     if (pico_pen_y < PICO_PEN_ADJUST_Y)
        pico_pen_y = PICO_PEN_ADJUST_Y;
-    if (pico_pen_y > 224 - PICO_PEN_ADJUST_Y)
-       pico_pen_y = 224 - PICO_PEN_ADJUST_Y;
+    if (pico_pen_y > 224-1 - PICO_PEN_ADJUST_Y)
+       pico_pen_y = 224-1 - PICO_PEN_ADJUST_Y;
     if (pico_pen_x < PICO_PEN_ADJUST_X)
        pico_pen_x = PICO_PEN_ADJUST_X;
-    if (pico_pen_x > lim_x - PICO_PEN_ADJUST_X)
-       pico_pen_x = lim_x - PICO_PEN_ADJUST_X;
+    if (pico_pen_x > 320-1 - PICO_PEN_ADJUST_X)
+       pico_pen_x = 320-1 - PICO_PEN_ADJUST_X;
 
-    PicoPicohw.pen_pos[0] = pico_pen_x;
-    if (!(Pico.video.reg[12] & 1))
-       PicoPicohw.pen_pos[0] += pico_pen_x / 4;
-    PicoPicohw.pen_pos[0] += 0x3c;
-    PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);
+    PicoPicohw.pen_pos[0] &= 0x8000;
+    PicoPicohw.pen_pos[1] &= 0x8000;
+    PicoPicohw.pen_pos[0] |= 0x3c + pico_pen_x;
+    PicoPicohw.pen_pos[1] |= (pico_inp_mode == 1 ? 0x2f8 : 0x1fc) + pico_pen_y;
 }
 
 void retro_run(void)
@@ -2158,7 +2182,10 @@ void retro_run(void)
             PicoIn.pad[pad] |= retro_pico_map[i];
 
    if (PicoIn.AHW == PAHW_PICO) {
-       uint16_t ev = input[0] & ((1 << RETRO_DEVICE_ID_JOYPAD_L) | (1 << RETRO_DEVICE_ID_JOYPAD_R) | (1 << RETRO_DEVICE_ID_JOYPAD_SELECT));
+       uint16_t ev = input[0] &
+             ((1 << RETRO_DEVICE_ID_JOYPAD_L) | (1 << RETRO_DEVICE_ID_JOYPAD_R) |
+              (1 << RETRO_DEVICE_ID_JOYPAD_X) | (1 << RETRO_DEVICE_ID_JOYPAD_SELECT) |
+              (1 << RETRO_DEVICE_ID_JOYPAD_START));
        uint16_t new_ev = ev & ~pico_events;
        pico_events = ev;
        run_events_pico(new_ev);
@@ -2305,6 +2332,9 @@ void retro_run(void)
       }
    }
 
+   if ((PicoIn.AHW & PAHW_PICO) && pico_pen_visible)
+      if (pico_inp_mode) draw_pico_ptr();
+
    buff = (char*)vout_buf + vout_offset;
 #endif
 
index 9519a6b..ba384ba 100644 (file)
@@ -87,17 +87,19 @@ static void draw_cd_leds(void)
 \r
 static void draw_pico_ptr(void)\r
 {\r
+       int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000;\r
+       int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000);\r
        int pitch = g_screen_ppitch;\r
        u16 *p = g_screen_ptr;\r
        int x = pico_pen_x, y = pico_pen_y;\r
 \r
-       x = (x * out_w * ((1ULL<<32) / 320)) >> 32;\r
-       y = (y * out_h * ((1ULL<<32) / 224)) >> 32;\r
+       x = (x * out_w * ((1ULL<<32) / 320 + 1)) >> 32;\r
+       y = (y * out_h * ((1ULL<<32) / 224 + 1)) >> 32;\r
        p += (screen_y+y)*pitch + (screen_x+x);\r
 \r
-                               p[-pitch] ^= 0xffff;\r
-       p[-1] ^= 0xffff;        p[0]      ^= 0xffff;    p[1] ^= 0xffff;\r
-                               p[pitch]  ^= 0xffff;\r
+       p[-pitch-1] ^= _; p[-pitch] ^= o; p[-pitch+1] ^= _;\r
+       p[-1]       ^= o; p[0]      ^= o; p[1]        ^= o;\r
+       p[pitch-1]  ^= _; p[pitch]  ^= o; p[pitch+1]  ^= _;\r
 }\r
 \r
 /* render/screen buffer handling:\r
index 575f161..32177ac 100644 (file)
@@ -76,7 +76,8 @@ static struct in_default_bind in_evdev_defbinds[] =
        { KEY_5,        IN_BINDTYPE_EMU, PEVB_PICO_PPREV },\r
        { KEY_6,        IN_BINDTYPE_EMU, PEVB_PICO_PNEXT },\r
        { KEY_7,        IN_BINDTYPE_EMU, PEVB_PICO_SWINP },\r
-       { KEY_8,        IN_BINDTYPE_EMU, PEVB_PICO_PEN },\r
+       { KEY_8,        IN_BINDTYPE_EMU, PEVB_PICO_SHPEN },\r
+       { KEY_9,        IN_BINDTYPE_EMU, PEVB_PICO_PPOSV },\r
        { 0, 0, 0 }\r
 };\r
 \r
@@ -138,16 +139,18 @@ static void draw_cd_leds(void)
 \r
 static void draw_pico_ptr(void)\r
 {\r
+       int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000;\r
+       int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000);\r
        int x = pico_pen_x, y = pico_pen_y, pitch = g_screen_ppitch;\r
        unsigned short *p = (unsigned short *)g_screen_ptr;\r
 \r
-       x = (x * saved_col_count * ((1ULL<<32) / 320)) >> 32;\r
-       y = (y * saved_line_count * ((1ULL<<32) / 224)) >> 32;\r
+       x = (x * saved_col_count  * ((1ULL<<32) / 320 + 1)) >> 32;\r
+       y = (y * saved_line_count * ((1ULL<<32) / 224 + 1)) >> 32;\r
        p += (saved_start_col+x) + (saved_start_line+y) * pitch;\r
 \r
-                               p[-pitch] ^= 0xffff;\r
-       p[-1] ^= 0xffff;        p[0]      ^= 0xffff;    p[1] ^= 0xffff;\r
-                               p[pitch]  ^= 0xffff;\r
+       p[-pitch-1] ^= _; p[-pitch] ^= o; p[-pitch+1] ^= _;\r
+       p[-1]       ^= o; p[0]      ^= o; p[1]        ^= o;\r
+       p[pitch-1]  ^= _; p[pitch]  ^= o; p[pitch+1]  ^= _;\r
 }\r
 \r
 void pemu_finalize_frame(const char *fps, const char *notice)\r
index 6eb4dcc..b15c603 100644 (file)
@@ -710,26 +710,29 @@ static void blit_cdleds(void)
 
 static void draw_pico_ptr(void)
 {
+       int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000;
        int x = pico_pen_x, y = pico_pen_y, offs;
-       int pp = g_screen_ppitch;
+       int pitch = g_screen_ppitch;
 
-       x = (x * out_w * ((1ULL<<32) / 320)) >> 32;
-       y = (y * out_h * ((1ULL<<32) / 224)) >> 32;
+       x = (x * out_w * ((1ULL<<32) / 320 + 1)) >> 32;
+       y = (y * out_h * ((1ULL<<32) / 224 + 1)) >> 32;
 
-       offs = g_screen_ppitch * (out_y+y) + (out_x+x);
+       offs = pitch * (out_y+y) + (out_x+x);
 
        if (is_16bit_mode()) {
                unsigned short *p = (unsigned short *)g_screen_ptr + offs;
+               int o = (up ? 0x0000 : 0x7fff), _ = (up ? 0x7fff : 0x0000);
 
-               p[    -1] = 0x0000; p[   0] = 0x001f; p[     1] = 0x0000;
-               p[  pp-1] = 0x001f; p[  pp] = 0x001f; p[  pp+1] = 0x001f;
-               p[2*pp-1] = 0x0000; p[2*pp] = 0x001f; p[2*pp+1] = 0x0000;
+               p[-pitch-1] ^= _; p[-pitch] ^= o; p[-pitch+1] ^= _;
+               p[1]        ^= o; p[0]      ^= o; p[1]        ^= o;
+               p[pitch-1]  ^= _; p[pitch]  ^= o; p[pitch+1]  ^= _;
        } else {
                unsigned char *p = (unsigned char *)g_screen_ptr + offs + 8;
+               int o = (up ? 0xe0 : 0xf0), _ = (up ? 0xf0 : 0xe0);
 
-               p[    -1] = 0xe0; p[   0] = 0xf0; p[     1] = 0xe0;
-               p[  pp-1] = 0xf0; p[  pp] = 0xf0; p[  pp+1] = 0xf0;
-               p[2*pp-1] = 0xe0; p[2*pp] = 0xf0; p[2*pp+1] = 0xe0;
+               p[-pitch-1]  = _; p[-pitch]  = o; p[-pitch+1]  = _;
+               p[-1]        = o; p[0]       = o; p[1]         = o;
+               p[pitch-1]   = _; p[pitch]   = o; p[pitch+1]   = _;
        }
 }
 
index b53a0f9..624d02a 100644 (file)
@@ -370,25 +370,29 @@ void blitscreen_clut(void)
 
 static void draw_pico_ptr(void)
 {
+       int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000;
        int x = pico_pen_x, y = pico_pen_y, offs;
+       int pitch = g_screen_ppitch;
 
-       x = (x * out_w * ((1ULL<<32) / 320)) >> 32;
-       y = (y * out_h * ((1ULL<<32) / 224)) >> 32;
+       x = (x * out_w * ((1ULL<<32) / 320 + 1)) >> 32;
+       y = (y * out_h * ((1ULL<<32) / 224 + 1)) >> 32;
 
        offs = 512 * (out_y+y) + (out_x+x);
 
        if (is_16bit_mode()) {
                unsigned short *p = (unsigned short *)g_screen_ptr + offs;
+               int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000);
 
-               p[  -1] = 0x0000; p[   0] = 0x001f; p[   1] = 0x0000;
-               p[ 511] = 0x001f; p[ 512] = 0x001f; p[ 513] = 0x001f;
-               p[1023] = 0x0000; p[1024] = 0x001f; p[1025] = 0x0000;
+               p[-pitch-1] ^= _; p[-pitch] ^= o; p[-pitch+1] ^= _;
+               p[1]        ^= o; p[0]      ^= o; p[1]        ^= o;
+               p[pitch-1]  ^= _; p[pitch]  ^= o; p[pitch+1]  ^= _;
        } else {
                unsigned char *p = (unsigned char *)g_screen_ptr + offs + 8;
+               int o = (up ? 0xe0 : 0xf0), _ = (up ? 0xf0 : 0xe0);
 
-               p[  -1] = 0xe0; p[   0] = 0xf0; p[   1] = 0xe0;
-               p[ 511] = 0xf0; p[ 512] = 0xf0; p[ 513] = 0xf0;
-               p[1023] = 0xe0; p[1024] = 0xf0; p[1025] = 0xe0;
+               p[-pitch-1]  = _; p[-pitch]  = o; p[-pitch+1]  = _;
+               p[-1]        = o; p[0]       = o; p[1]         = o;
+               p[pitch-1]   = _; p[pitch]   = o; p[pitch+1]   = _;
        }
 }