From c87e36d750d712d199df366cf7d74f778b34f1f0 Mon Sep 17 00:00:00 2001 From: kub Date: Sun, 17 Mar 2024 10:44:57 +0100 Subject: [PATCH] core+platforms, revise pico pen handling 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. --- pico/pico/pico.c | 2 ++ platform/common/emu.c | 26 +++++++++------ platform/common/emu.h | 4 +-- platform/common/input_pico.h | 10 +++--- platform/common/inputmap_kbd.c | 3 +- platform/common/menu_pico.c | 3 +- platform/gp2x/emu.c | 19 ++++++----- platform/libretro/libretro.c | 60 +++++++++++++++++++++++++--------- platform/linux/emu.c | 12 ++++--- platform/pandora/plat.c | 15 +++++---- platform/ps2/emu.c | 23 +++++++------ platform/psp/emu.c | 20 +++++++----- 12 files changed, 127 insertions(+), 70 deletions(-) diff --git a/pico/pico/pico.c b/pico/pico/pico.c index d190a940..99f21f4a 100644 --- a/pico/pico/pico.c +++ b/pico/pico/pico.c @@ -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); diff --git a/platform/common/emu.c b/platform/common/emu.c index 6895498c..d576b439 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -1050,10 +1050,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 & PEV_PICO_PPREV) { PicoPicohw.page--; @@ -1067,10 +1066,15 @@ void run_events_pico(unsigned int events) PicoPicohw.page = 6; emu_status_msg("Page %i", PicoPicohw.page); } - if (events & PEV_PICO_PEN) { + if (events & PEV_PICO_SHPEN) { currentConfig.EmuOpt ^= EOPT_PICO_PEN; emu_status_msg("%s Pen", currentConfig.EmuOpt & EOPT_PICO_PEN ? "Show" : "Hide"); } + if (events & PEV_PICO_PPOSV) { + 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; @@ -1084,15 +1088,17 @@ void run_events_pico(unsigned int events) 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 > 320 - PICO_PEN_ADJUST_X) - pico_pen_x = 320 - 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] = 0x03c + pico_pen_x; - 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] |= 0x03c + pico_pen_x; + PicoPicohw.pen_pos[1] |= (pico_inp_mode == 1 ? 0x2f8 : 0x1fc) + pico_pen_y; } static void do_turbo(unsigned short *pad, int acts) diff --git a/platform/common/emu.h b/platform/common/emu.h index d32cf705..959ce0b5 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -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; diff --git a/platform/common/input_pico.h b/platform/common/input_pico.h index b3138d0b..10d65118 100644 --- a/platform/common/input_pico.h +++ b/platform/common/input_pico.h @@ -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) @@ -43,9 +44,10 @@ #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 */ diff --git a/platform/common/inputmap_kbd.c b/platform/common/inputmap_kbd.c index 03865112..821a8ee0 100644 --- a/platform/common/inputmap_kbd.c +++ b/platform/common/inputmap_kbd.c @@ -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 } }; diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index 78dfcc33..ffd91612 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -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 } }; diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 460b1541..f20f29a2 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -194,10 +194,11 @@ static void draw_cd_leds(void) static void draw_pico_ptr(void) { + int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000; int x, y, pitch = 320, offs; - x = ((pico_pen_x * colcount * ((1ULL<<32) / 320)) >> 32) + firstcol; - y = ((pico_pen_y * linecount * ((1ULL<<32) / 224)) >> 32) + firstline; + x = ((pico_pen_x * colcount * ((1ULL<<32)/320 + 1)) >> 32) + firstcol; + y = ((pico_pen_y * linecount * ((1ULL<<32)/224 + 1)) >> 32) + firstline; if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { pitch = 240; @@ -207,16 +208,18 @@ static void draw_pico_ptr(void) if (is_16bit_mode()) { unsigned short *p = (unsigned short *)g_screen_ptr + offs; + int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000); - p[0] ^= 0xffff; - p[pitch-1] ^= 0xffff; p[pitch] ^= 0xffff; p[pitch+1] ^= 0xffff; - p[pitch*2] ^= 0xffff; + 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; + int o = (up ? 0xe0 : 0xf0), _ = (up ? 0xf0 : 0xe0); - p[-1] = 0xe0; p[0] = 0xf0; p[1] = 0xe0; - p[pitch-1] = 0xf0; p[pitch] = 0xf0; p[pitch+1] = 0xf0; - p[2*pitch-1] = 0xe0; p[2*pitch] = 0xf0; p[2*pitch+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] = _; } } diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index 600c0159..26b89ac1 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -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 diff --git a/platform/linux/emu.c b/platform/linux/emu.c index 9519a6bf..ba384ba4 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -87,17 +87,19 @@ static void draw_cd_leds(void) static void draw_pico_ptr(void) { + int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000; + int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000); int pitch = g_screen_ppitch; u16 *p = g_screen_ptr; int x = pico_pen_x, y = pico_pen_y; - 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; p += (screen_y+y)*pitch + (screen_x+x); - p[-pitch] ^= 0xffff; - p[-1] ^= 0xffff; p[0] ^= 0xffff; p[1] ^= 0xffff; - p[pitch] ^= 0xffff; + 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] ^= _; } /* render/screen buffer handling: diff --git a/platform/pandora/plat.c b/platform/pandora/plat.c index 575f1612..32177ace 100644 --- a/platform/pandora/plat.c +++ b/platform/pandora/plat.c @@ -76,7 +76,8 @@ static struct in_default_bind in_evdev_defbinds[] = { KEY_5, IN_BINDTYPE_EMU, PEVB_PICO_PPREV }, { KEY_6, IN_BINDTYPE_EMU, PEVB_PICO_PNEXT }, { KEY_7, IN_BINDTYPE_EMU, PEVB_PICO_SWINP }, - { KEY_8, IN_BINDTYPE_EMU, PEVB_PICO_PEN }, + { KEY_8, IN_BINDTYPE_EMU, PEVB_PICO_SHPEN }, + { KEY_9, IN_BINDTYPE_EMU, PEVB_PICO_PPOSV }, { 0, 0, 0 } }; @@ -138,16 +139,18 @@ static void draw_cd_leds(void) static void draw_pico_ptr(void) { + int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000; + int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000); int x = pico_pen_x, y = pico_pen_y, pitch = g_screen_ppitch; unsigned short *p = (unsigned short *)g_screen_ptr; - x = (x * saved_col_count * ((1ULL<<32) / 320)) >> 32; - y = (y * saved_line_count * ((1ULL<<32) / 224)) >> 32; + x = (x * saved_col_count * ((1ULL<<32) / 320 + 1)) >> 32; + y = (y * saved_line_count * ((1ULL<<32) / 224 + 1)) >> 32; p += (saved_start_col+x) + (saved_start_line+y) * pitch; - p[-pitch] ^= 0xffff; - p[-1] ^= 0xffff; p[0] ^= 0xffff; p[1] ^= 0xffff; - p[pitch] ^= 0xffff; + 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 pemu_finalize_frame(const char *fps, const char *notice) diff --git a/platform/ps2/emu.c b/platform/ps2/emu.c index 6eb4dcc4..b15c6036 100644 --- a/platform/ps2/emu.c +++ b/platform/ps2/emu.c @@ -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] = _; } } diff --git a/platform/psp/emu.c b/platform/psp/emu.c index b53a0f91..624d02a9 100644 --- a/platform/psp/emu.c +++ b/platform/psp/emu.c @@ -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] = _; } } -- 2.39.5