Skip to content

Commit

Permalink
core+platforms, revise pico pen handling
Browse files Browse the repository at this point in the history
the sign bit in the tablet position register denotes pen on surface.
add some logic and a hotkey for handling pen not on surface. This allows
for repositioning of the pen without the storyware taking note of it.
  • Loading branch information
irixxxx committed Mar 18, 2024
1 parent 9f29605 commit e806a02
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 45 deletions.
18 changes: 12 additions & 6 deletions platform/common/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand All @@ -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;
Expand All @@ -1091,8 +1095,10 @@ void run_events_pico(unsigned int events)
if (pico_pen_x > 320 - PICO_PEN_ADJUST_X)
pico_pen_x = 320 - 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)
Expand Down
10 changes: 6 additions & 4 deletions platform/common/input_pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 */
3 changes: 2 additions & 1 deletion platform/common/inputmap_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};
Expand Down
3 changes: 2 additions & 1 deletion platform/common/menu_pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

Expand Down
15 changes: 9 additions & 6 deletions platform/gp2x/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ 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;
Expand All @@ -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] = _;
}
}

Expand Down
19 changes: 13 additions & 6 deletions platform/libretro/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,7 @@ 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_L, "Previous page" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Next page" },

Expand Down Expand Up @@ -2066,10 +2067,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--;
Expand All @@ -2083,6 +2083,11 @@ void run_events_pico(unsigned int events)
PicoPicohw.page = 6;
emu_status_msg("Page %i", PicoPicohw.page);
}
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;
Expand All @@ -2104,11 +2109,13 @@ void run_events_pico(unsigned int events)
if (pico_pen_x > lim_x - PICO_PEN_ADJUST_X)
pico_pen_x = lim_x - PICO_PEN_ADJUST_X;

PicoPicohw.pen_pos[0] = pico_pen_x;
PicoPicohw.pen_pos[0] &= 0x8000;
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[1] &= 0x8000;
PicoPicohw.pen_pos[1] |= pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);
}

void retro_run(void)
Expand Down Expand Up @@ -2158,7 +2165,7 @@ 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_SELECT) | (1 << RETRO_DEVICE_ID_JOYPAD_START));
uint16_t new_ev = ev & ~pico_events;
pico_events = ev;
run_events_pico(new_ev);
Expand Down
8 changes: 5 additions & 3 deletions platform/linux/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ 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;
Expand All @@ -95,9 +97,9 @@ static void draw_pico_ptr(void)
y = (y * out_h * ((1ULL<<32) / 224)) >> 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:
Expand Down
11 changes: 7 additions & 4 deletions platform/pandora/plat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

Expand Down Expand Up @@ -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;
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)
Expand Down
19 changes: 11 additions & 8 deletions platform/ps2/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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] = _;
}
}

Expand Down
16 changes: 10 additions & 6 deletions platform/psp/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ 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;
Expand All @@ -379,16 +381,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[ -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] = _;
}
}

Expand Down

0 comments on commit e806a02

Please sign in to comment.