Skip to content

Commit

Permalink
pico, revisit kbd handling
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Jan 7, 2025
1 parent dcc492b commit 3fc7e6e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 26 deletions.
4 changes: 2 additions & 2 deletions pico/pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extern void *p32x_bios_g, *p32x_bios_m, *p32x_bios_s;
#define POPT_DIS_FM_SSGEG (1<<23)
#define POPT_EN_FM_DAC (1<<24) //x00 0000
#define POPT_EN_FM_FILTER (1<<25)
#define POPT_EN_PICO_KBD (1<<26)

#define PAHW_MCD (1<<0)
#define PAHW_32X (1<<1)
Expand Down Expand Up @@ -178,6 +179,7 @@ typedef struct
uint64_t time_keydown;
uint8_t key_state;
uint8_t shift_state;
uint8_t active;
} picohw_kb;
typedef struct
{
Expand All @@ -188,8 +190,6 @@ typedef struct
unsigned int reserved[3];
unsigned char xpcm_buffer[XPCM_BUFFER_SIZE+4];
unsigned char *xpcm_ptr;
int is_kb_active;
int inp_mode;
picohw_kb kb;
} picohw_state;
extern picohw_state PicoPicohw;
Expand Down
14 changes: 5 additions & 9 deletions pico/pico/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ static u32 PicoRead16_pico(u32 a)
case 0x08: d = (PicoPicohw.pen_pos[1] >> 8); break;
case 0x0a: d = PicoPicohw.pen_pos[1] & 0xff; break;
case 0x0c: d = (1 << (PicoPicohw.page & 7)) - 1;
if (PicoPicohw.page == 7) {
d = 0x2a; // 0b00101010
} else {
d = ((1 << (PicoPicohw.page & 7)) - 1);
}
if (PicoPicohw.page == 7) d = 0x2a; // 0b00101010
break;
case 0x10: d = (PicoPicohw.fifo_bytes > 0x3f) ? 0 : (0x3f - PicoPicohw.fifo_bytes); break;
case 0x12: d = (PicoPicohw.fifo_bytes | !PicoPicoPCMBusyN()) ? 0 : 0x8000;
Expand Down Expand Up @@ -127,7 +123,7 @@ static void PicoWrite16_pico(u32 a, u32 d)
PicoPicohw.fifo_bytes = 0;
PicoPicoPCMResetN(1);
}
// other bits used in software: 0x3f00.
// TODO: other bits used in software: 0x3f00.
}
else
elprintf(EL_UIO, "m68k unmapped w16 [%06x] %04x @%06x", a, d & 0xffff, SekPc);
Expand All @@ -136,7 +132,7 @@ static void PicoWrite16_pico(u32 a, u32 d)
static u32 PicoRead8_pico_kb(u32 a)
{
u32 d = 0;
if (PicoPicohw.is_kb_active == 0) {
if (!(PicoIn.opt & POPT_EN_PICO_KBD)) {
elprintf(EL_PICOHW, "kb: r @%06X %04X = %04X\n", SekPc, a, d);
return d;
}
Expand Down Expand Up @@ -178,7 +174,7 @@ static u32 PicoRead8_pico_kb(u32 a)
case 0x6: d = 0; // l&kbtype
break;
case 0x7: // cap/num/scr
if (PicoPicohw.inp_mode == 3) {
if (PicoPicohw.kb.active) {
if (key == PEVB_PICO_PS2_CAPSLOCK && PicoPicohw.kb.has_caps_lock == 1) {
PicoPicohw.kb.caps_lock = PicoPicohw.kb.caps_lock == 4 ? 0 : 4;
PicoPicohw.kb.has_caps_lock = 0;
Expand All @@ -188,7 +184,7 @@ static u32 PicoRead8_pico_kb(u32 a)
break;
case 0x8:
d = 6;
if (PicoPicohw.inp_mode == 3) {
if (PicoPicohw.kb.active) {
if (key) {
PicoPicohw.kb.key_state = KEY_DOWN;
}
Expand Down
14 changes: 5 additions & 9 deletions platform/common/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ void run_events_pico(unsigned int events)
}
if (events & PEV_PICO_PAD) {
if (pico_inp_mode == 2) {
pico_inp_mode = (PicoPicohw.is_kb_active ? 3 : 0);
pico_inp_mode = (PicoIn.opt & POPT_EN_PICO_KBD ? 3 : 0);
emu_status_msg("Input: %s", pico_inp_mode ? "Keyboard" : "D-Pad");
} else if (pico_inp_mode == 3) {
pico_inp_mode = 0;
Expand All @@ -1164,18 +1164,14 @@ void run_events_pico(unsigned int events)
emu_status_msg("Pen %s", PicoPicohw.pen_pos[0] & 0x8000 ? "Up" : "Down");
}

if ((currentConfig.EmuOpt & EOPT_PICO_PEN) &&
(PicoIn.pad[0]&0x20) && pico_inp_mode && pico_overlay) {
if (((currentConfig.EmuOpt & EOPT_PICO_PEN) &&
(PicoIn.pad[0]&0x20) && pico_inp_mode && pico_overlay) ||
(!(PicoIn.opt & POPT_EN_PICO_KBD) && pico_inp_mode == 3)) {
pico_inp_mode = 0;
emu_status_msg("Input: D-Pad");
}
if (events & PEV_PICO_SWPS2) {
PicoPicohw.is_kb_active = !PicoPicohw.is_kb_active;
if (pico_inp_mode == 3) pico_inp_mode = 0;
emu_status_msg("Keyboard %sconnected", PicoPicohw.is_kb_active ? "" : "dis");
}

PicoPicohw.inp_mode = pico_inp_mode;
PicoPicohw.kb.active = pico_inp_mode == 3;

if (pico_inp_mode == 0 || pico_inp_mode == 3)
return;
Expand Down
6 changes: 2 additions & 4 deletions platform/common/input_pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
#define PEVB_PICO_STORY 19
#define PEVB_PICO_PAD 18
#define PEVB_PICO_PENST 17
#define PEVB_PICO_SWPS2 16
#define PEVB_RESET 15
#define PEVB_RESET 16

#define PEV_VOL_DOWN (1 << PEVB_VOL_DOWN)
#define PEV_VOL_UP (1 << PEVB_VOL_UP)
Expand All @@ -47,10 +46,9 @@
#define PEV_PICO_STORY (1 << PEVB_PICO_STORY)
#define PEV_PICO_PAD (1 << PEVB_PICO_PAD)
#define PEV_PICO_PENST (1 << PEVB_PICO_PENST)
#define PEV_PICO_SWPS2 (1 << PEVB_PICO_SWPS2)
#define PEV_RESET (1 << PEVB_RESET)

#define PEV_MASK 0x7fff8000
#define PEV_MASK 0x7fff0000

/* Keyboard Pico */

Expand Down
1 change: 0 additions & 1 deletion platform/common/inputmap_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const struct in_default_bind _in_sdl_defbinds[] = {
{ SDLK_F8, IN_BINDTYPE_EMU, PEVB_PICO_STORY },
{ SDLK_F9, IN_BINDTYPE_EMU, PEVB_PICO_PAD },
{ SDLK_F10, IN_BINDTYPE_EMU, PEVB_PICO_PENST },
{ SDLK_F12, IN_BINDTYPE_EMU, PEVB_PICO_SWPS2 },
{ SDLK_BACKSPACE, IN_BINDTYPE_EMU, PEVB_FF },

{ 0, 0, 0 }
Expand Down
2 changes: 1 addition & 1 deletion platform/common/menu_pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ me_bind_action emuctrl_actions[] =
{ "Pico Storyware ", PEV_PICO_STORY },
{ "Pico Pad ", PEV_PICO_PAD },
{ "Pico Pen state ", PEV_PICO_PENST },
{ "Pico Keyboard ", PEV_PICO_SWPS2 },
{ NULL, 0 }
};

Expand Down Expand Up @@ -486,6 +485,7 @@ static menu_entry e_menu_md_options[] =
mee_onoff_h ("FM filter", MA_OPT_FM_FILTER, PicoIn.opt, POPT_EN_FM_FILTER, h_fmfilter),
mee_onoff_h ("FM DAC noise", MA_OPT2_ENABLE_YM_DAC, PicoIn.opt, POPT_EN_FM_DAC, h_dacnoise),
mee_onoff_h ("Pen button shows screen", MA_OPT_PICO_PEN, currentConfig.EmuOpt, EOPT_PICO_PEN, h_picopen),
mee_onoff ("Pico Keyboard", MA_OPT_PICO_KBD, PicoIn.opt, POPT_EN_PICO_KBD),
mee_end,
};

Expand Down
1 change: 1 addition & 0 deletions platform/common/menu_pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef enum
MA_OPT_SOUND_ALPHA,
MA_OPT_FM_FILTER,
MA_OPT_PICO_PEN,
MA_OPT_PICO_KBD,
MA_OPT2_GAMMA,
MA_OPT2_A_SN_GAMMA,
MA_OPT2_DBLBUFF, /* giz */
Expand Down

0 comments on commit 3fc7e6e

Please sign in to comment.