diff --git a/pico/pico/memory.c b/pico/pico/memory.c index bbe0c2b26..a97df6547 100644 --- a/pico/pico/memory.c +++ b/pico/pico/memory.c @@ -155,7 +155,7 @@ static u32 PicoRead8_pico_kb(u32 a) && PicoPicohw.kb.key_state != KEY_UP && PicoPicohw.kb.shift_state != SHIFT_UP_HELD_DOWN) ? key_shift - : PicoPicohw.kb.shift_state == SHIFT_UP ? PEVB_KBD_SHIFT : key; + : PicoPicohw.kb.shift_state == SHIFT_UP ? PEVB_KBD_LSHIFT : key; u32 key_code_7654 = (key_code & 0xf0) >> 4; u32 key_code_3210 = (key_code & 0x0f); switch(PicoPicohw.kb.i) { @@ -217,7 +217,7 @@ static u32 PicoRead8_pico_kb(u32 a) if (PicoPicohw.kb.time_keydown > 350 // Modifier keys don't have typematic && key_code != PEVB_KBD_CAPSLOCK - && key_code != PEVB_KBD_SHIFT) { + && key_code != PEVB_KBD_LSHIFT) { d |= 8; // Send key down a.k.a. make if (PicoPicohw.kb.key_state == KEY_DOWN) elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: KEY DOWN\n"); diff --git a/pico/sms.c b/pico/sms.c index 0608d7842..3ecb35a27 100644 --- a/pico/sms.c +++ b/pico/sms.c @@ -1,7 +1,7 @@ /* * SMS emulation * (C) notaz, 2009-2010 - * (C) irixxxx, 2021-2024 + * (C) irixxxx, 2021-2025 * * This work is licensed under the terms of MAME license. * See COPYING file in the top-level directory. @@ -219,7 +219,8 @@ static unsigned char kbd_map[] = { [PEVB_KBD_SOUND] = 0x96, // graph [PEVB_KBD_CAPSLOCK] = 0xa6, // ctrl [PEVB_KBD_FUNC] = 0xb5, // func - [PEVB_KBD_SHIFT] = 0xb6, // shift + [PEVB_KBD_LSHIFT] = 0xb6, // shift (both keys on the same column) + [PEVB_KBD_RSHIFT] = 0xb6, }; static void kbd_update(void) @@ -390,7 +391,7 @@ static void z80_sms_out(unsigned short a, unsigned char d) case 0xc0: // SG-1000 has a 8255 chip, mapped to 0xdc-0xdf if ((PicoIn.AHW & PAHW_SC) && (a & 0x2)) - Pico.ms.io_sg = d; // 0xc2 = kbd/pad select + Pico.ms.io_sg = d; // 0xc2 = kbd/pad matrix column select } } } diff --git a/platform/common/emu.c b/platform/common/emu.c index a7cae06ab..65f633527 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -59,6 +59,12 @@ int pico_inp_mode; int flip_after_sync; int engineState = PGS_Menu; +static int kbd_mode; + +static int pico_page; +static int pico_w, pico_h; +static u16 *pico_overlay; + static short __attribute__((aligned(4))) sndBuffer[2*54000/50]; /* tmp buff to reduce stack usage for plats with small stack */ @@ -1049,10 +1055,6 @@ void emu_reset_game(void) reset_timing = 1; } -static int pico_page; -static int pico_w, pico_h; -static u16 *pico_overlay; - static u16 *load_pico_overlay(int page, int w, int h) { static const char *pic_exts[] = { "png", "PNG" }; @@ -1129,13 +1131,12 @@ void run_events_pico(unsigned int events) PicoPicohw.page++; if (PicoPicohw.page > 7) PicoPicohw.page = 7; - if (PicoPicohw.page == 7) { - // Used in games that require the Keyboard Pico peripheral - emu_status_msg("Test Page"); - } - else { - emu_status_msg("Page %i", PicoPicohw.page); - } + if (PicoPicohw.page == 7) { + // Used in games that require the Keyboard Pico peripheral + emu_status_msg("Test Page"); + } else { + emu_status_msg("Page %i", PicoPicohw.page); + } } if (events & PEV_PICO_STORY) { if (pico_inp_mode == 1) { @@ -1266,10 +1267,6 @@ static void run_events_ui(unsigned int which) } plat_status_msg_busy_done(); } - if (which & PEV_SWITCH_RND) - { - plat_video_toggle_renderer(1, 0); - } if (which & (PEV_SSLOT_PREV|PEV_SSLOT_NEXT)) { if (which & PEV_SSLOT_PREV) { @@ -1285,6 +1282,15 @@ static void run_events_ui(unsigned int which) emu_status_msg("SAVE SLOT %i [%s]", state_slot, emu_check_save_file(state_slot, NULL) ? "USED" : "FREE"); } + if (which & PEV_SWITCH_RND) + { + plat_video_toggle_renderer(1, 0); + } + if (which & PEV_SWITCH_KBD) + { + kbd_mode = !kbd_mode; + emu_status_msg("Keyboard %s", kbd_mode ? "on" : "off"); + } if (which & PEV_RESET) emu_reset_game(); if (which & PEV_MENU) @@ -1300,19 +1306,6 @@ void emu_update_input(void) int events; in_update(actions); - in_update_kbd(actions_kbd); - PicoIn.kbd = 0; - for (int i = 0; i < IN_BIND_LAST; i++) { - if (actions_kbd[i]) { - unsigned int action = actions_kbd[i]; - unsigned int key = (action & 0xff); - if (key == PEVB_KBD_SHIFT || key == PEVB_KBD_CTRL || key == PEVB_KBD_FUNC) { - PicoIn.kbd = (PicoIn.kbd & 0x00ff) | (action << 8); - } else { - PicoIn.kbd = (PicoIn.kbd & 0xff00) | action; - } - } - } pl_actions[0] = actions[IN_BINDTYPE_PLAYER12]; pl_actions[1] = actions[IN_BINDTYPE_PLAYER12] >> 16; @@ -1321,20 +1314,23 @@ void emu_update_input(void) events = actions[IN_BINDTYPE_EMU] & PEV_MASK; - if (pico_inp_mode == 3) { + if (kbd_mode) { + int mask = (PicoIn.AHW & PAHW_PICO ? 0xf : 0x0); + in_update_kbd(actions_kbd); + // FIXME: Only passthrough joystick input to avoid collisions // with PS/2 bindings. Ideally we should check if the device this // input originated from is the same as the device used for // PS/2 input, and passthrough if they are different devices. - PicoIn.pad[0] = pl_actions[0] & 0xf; - PicoIn.pad[1] = pl_actions[1] & 0xf; - PicoIn.pad[2] = pl_actions[2] & 0xf; - PicoIn.pad[3] = pl_actions[3] & 0xf; + PicoIn.pad[0] = pl_actions[0] & mask; + PicoIn.pad[1] = pl_actions[1] & mask; + PicoIn.pad[2] = pl_actions[2] & mask; + PicoIn.pad[3] = pl_actions[3] & mask; // Ignore events mapped to bindings that collide with PS/2 peripherals. // Note that calls to emu_set_fastforward() should be avoided as well, // since fast-forward activates even with parameter set_on = 0. - events &= ~PEV_MENU; + events &= PEV_SWITCH_KBD; } else { PicoIn.pad[0] = pl_actions[0] & 0xfff; PicoIn.pad[1] = pl_actions[1] & 0xfff; @@ -1363,7 +1359,22 @@ void emu_update_input(void) events &= ~prev_events; - if (PicoIn.AHW == PAHW_PICO) + // update keyboard input, actions only updated if keyboard mode active + PicoIn.kbd = 0; + for (int i = 0; i < IN_BIND_LAST; i++) { + if (actions_kbd[i]) { + unsigned int action = actions_kbd[i]; + unsigned int key = (action & 0xff); + if (key == PEVB_KBD_LSHIFT || key == PEVB_KBD_RSHIFT || + key == PEVB_KBD_CTRL || key == PEVB_KBD_FUNC) { + PicoIn.kbd = (PicoIn.kbd & 0x00ff) | (action << 8); + } else { + PicoIn.kbd = (PicoIn.kbd & 0xff00) | action; + } + } + } + + if (PicoIn.AHW & PAHW_PICO) run_events_pico(events); if (events) run_events_ui(events); diff --git a/platform/common/input_pico.h b/platform/common/input_pico.h index 0ecbee0e5..369a6fc17 100644 --- a/platform/common/input_pico.h +++ b/platform/common/input_pico.h @@ -30,7 +30,8 @@ #define PEVB_PICO_STORY 19 #define PEVB_PICO_PAD 18 #define PEVB_PICO_PENST 17 -#define PEVB_RESET 16 +#define PEVB_SWITCH_KBD 16 +#define PEVB_RESET 15 #define PEV_VOL_DOWN (1 << PEVB_VOL_DOWN) #define PEV_VOL_UP (1 << PEVB_VOL_UP) @@ -46,9 +47,10 @@ #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_SWITCH_KBD (1 << PEVB_SWITCH_KBD) #define PEV_RESET (1 << PEVB_RESET) -#define PEV_MASK 0x7fff0000 +#define PEV_MASK 0x7fff8000 /* Keyboard Pico */ @@ -112,7 +114,7 @@ // Orange buttons on left #define PEVB_KBD_CAPSLOCK 0x58 -#define PEVB_KBD_SHIFT 0x12 // left shift +#define PEVB_KBD_LSHIFT 0x12 // left shift // Green buttons on right #define PEVB_KBD_BACKSPACE 0x66 @@ -129,6 +131,7 @@ #define PEVB_KBD_ROMAJI 0x17 // Other buttons for SC-3000 +#define PEVB_KBD_RSHIFT 0x59 // right shift #define PEVB_KBD_CTRL 0x14 #define PEVB_KBD_FUNC 0x11 #define PEVB_KBD_UP 0x75 diff --git a/platform/common/inputmap_kbd.c b/platform/common/inputmap_kbd.c index eaefc2ddb..497a5df48 100644 --- a/platform/common/inputmap_kbd.c +++ b/platform/common/inputmap_kbd.c @@ -32,6 +32,7 @@ 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_SWITCH_KBD }, { SDLK_BACKSPACE, IN_BINDTYPE_EMU, PEVB_FF }, { 0, 0, 0 } @@ -103,7 +104,7 @@ const struct in_default_bind in_sdl_kbd_map[] = { // NB caps lock generates only a pulse on most keyboards, even if the // button is kept pressed. Using ctrl key for complete up/down handling. { SDLK_LCTRL, IN_BINDTYPE_KEYBOARD, PEVB_KBD_CAPSLOCK }, // Also switches english input - { SDLK_LSHIFT, IN_BINDTYPE_KEYBOARD, PEVB_KBD_SHIFT }, + { SDLK_LSHIFT, IN_BINDTYPE_KEYBOARD, PEVB_KBD_LSHIFT }, // Green buttons on right { SDLK_BACKSPACE, IN_BINDTYPE_KEYBOARD, PEVB_KBD_BACKSPACE }, diff --git a/platform/common/keyboard.c b/platform/common/keyboard.c index 8cfd514fe..3b4a5f37f 100644 --- a/platform/common/keyboard.c +++ b/platform/common/keyboard.c @@ -60,7 +60,7 @@ static struct key kbd_pico_row3[] = { { 0 }, }; static struct key kbd_pico_row4[] = { - { 0, "shift", "shift", PEVB_KBD_SHIFT }, + { 0, "shift", "shift", PEVB_KBD_LSHIFT }, { 7, "z", "Z", PEVB_KBD_z }, { 10, "x", "X", PEVB_KBD_x }, { 13, "c", "C", PEVB_KBD_c }, @@ -76,9 +76,9 @@ static struct key kbd_pico_row4[] = { { 0 }, }; static struct key kbd_pico_row5[] = { - { 0, "muhenkan", "muhenkan", PEVB_KBD_SOUND }, + { 0, "muhenkan", "muhenkan", PEVB_KBD_SOUND }, // Korean: sound { 13, "space", "space", PEVB_KBD_SPACE }, - { 22, "henkan", "henkan", PEVB_KBD_HOME }, + { 22, "henkan", "henkan", PEVB_KBD_HOME }, // Korean: home { 29, "kana", "kana", PEVB_KBD_CJK }, { 34, "romaji", "romaji", PEVB_KBD_ROMAJI }, { 0 }, @@ -123,7 +123,7 @@ static struct key kbd_sc3000_row2[] = { { 0 }, }; static struct key kbd_sc3000_row3[] = { - { 0, "ctrl", "ctrl", PEVB_KBD_CTRL }, + { 0, "ctrl", "ctrl", PEVB_KBD_CAPSLOCK }, { 6, "a", "A", PEVB_KBD_a }, { 9, "s", "S", PEVB_KBD_s }, { 12, "d", "D", PEVB_KBD_d }, @@ -142,7 +142,7 @@ static struct key kbd_sc3000_row3[] = { { 0 }, }; static struct key kbd_sc3000_row4[] = { - { 0, "shift", "shift", PEVB_KBD_SHIFT }, + { 0, "shift", "shift", PEVB_KBD_LSHIFT }, { 7, "z", "Z", PEVB_KBD_z }, { 10, "x", "X", PEVB_KBD_x }, { 13, "c", "C", PEVB_KBD_c }, @@ -154,7 +154,7 @@ static struct key kbd_sc3000_row4[] = { { 31, ".", ">", PEVB_KBD_PERIOD }, { 34, "/", "?", PEVB_KBD_SLASH }, { 37, "pi", "pi", PEVB_KBD_RO }, - { 41, "shift", "shift", PEVB_KBD_SHIFT }, + { 41, "shift", "shift", PEVB_KBD_RSHIFT }, { 50, "v", "v", PEVB_KBD_DOWN }, { 0 }, }; diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index d5be80090..ab639c556 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -375,6 +375,7 @@ me_bind_action emuctrl_actions[] = { "Pico Storyware ", PEV_PICO_STORY }, { "Pico Pad ", PEV_PICO_PAD }, { "Pico Pen state ", PEV_PICO_PENST }, + { "Switch Keyboard", PEV_SWITCH_KBD }, { NULL, 0 } }; @@ -443,8 +444,8 @@ int key_config_kbd_loop(int id, int keys) int inp; int dev; - int w = 30 * me_mfont_w; - int x = g_menuscreen_w / 2 - w / 2; + int w = 20 * me_mfont_w / 2; + int x = g_menuscreen_w / 2; struct key *key; const int *binds; @@ -454,7 +455,6 @@ int key_config_kbd_loop(int id, int keys) snprintf(ma2, sizeof(ma2), "%s", in_get_key_name(-1, -PBTN_MA2)); snprintf(r, sizeof(r), "%s", in_get_key_name(-1, -PBTN_R)); snprintf(l, sizeof(r), "%s", in_get_key_name(-1, -PBTN_L)); - w = (strlen(mok)+strlen(ma2)) * me_mfont_w / 2; for (dev = 0; dev < IN_MAX_DEVS-1; dev++) if ((binds = in_get_dev_kbd_binds(dev))) break; @@ -468,14 +468,16 @@ int key_config_kbd_loop(int id, int keys) for (bc--; bc >= 0 && binds[bc] != key->key; bc--) ; menu_draw_begin(1, 0); - text_out16(x, 2 * me_mfont_h, "-- %s Keyboard --", toggle ? "SC-3000" : "Pico"); + text_out16(x - w, 2 * me_mfont_h, "Keyboard type: %s", toggle ? "SC-3000" : "Pico"); kbd_draw(kbd, shift, (g_menuscreen_w - 320)/2, 4 * me_mfont_h, key); - text_out16(x - w, g_menuscreen_h - 7 * me_mfont_h, "currently bound to %s", in_get_key_name(-1, bc)); - text_out16(x - w, g_menuscreen_h - 5 * me_mfont_h, "%s - bind, %s - clear", mok, ma2); - text_out16(x - w, g_menuscreen_h - 4 * me_mfont_h, "%s - toggle, %s - shift", r, l); + text_out16(x - 2*w, g_menuscreen_h - 7 * me_mfont_h, "currently bound to %s", + bc >= 0 ? in_get_key_name(-1, bc) : "nothing"); + if (!shift) + text_out16(x - 2*w, g_menuscreen_h - 5 * me_mfont_h, "%s - bind, %s - clear", mok, ma2); + text_out16(x - 2*w, g_menuscreen_h - 4 * me_mfont_h, "%s - swap type, %s - shift view", r, l); menu_draw_end(); - inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT| + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MA2| PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, NULL, 70); if (inp & (PBTN_MENU|PBTN_MBACK)) break; @@ -508,6 +510,7 @@ int key_config_kbd_loop(int id, int keys) while (in_menu_wait_any(NULL, 30) & PBTN_MOK) ; + if (shift) continue; key = &kbd[keyy][keyx]; menu_draw_begin(1, 0); @@ -520,9 +523,12 @@ int key_config_kbd_loop(int id, int keys) for (is_down = 1; is_down; ) kc = in_update_keycode(&bind_dev_id, &is_down, NULL, -1); - in_bind_kbd_key(bind_dev_id, bc, 0); /* ?? */ + in_bind_kbd_key(dev, bc, -1); in_bind_kbd_key(bind_dev_id, kc, kbd[keyy][keyx].key); } + if (inp & PBTN_MA2) { + in_bind_kbd_key(dev, bc, -1); + } } return 0; @@ -1412,8 +1418,9 @@ static int main_menu_handler(int id, int keys) static const char *mgn_picopage(int id, int *offs) { - strcpy(static_buff, " "); - sprintf(static_buff, "%i", PicoPicohw.page); + if (PicoPicohw.page != 7) + sprintf(static_buff, "%i", PicoPicohw.page); + else sprintf(static_buff, "Test"); return static_buff; } @@ -1421,8 +1428,8 @@ static int mh_picopage(int id, int keys) { if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice PicoPicohw.page += (keys & PBTN_LEFT) ? -1 : 1; - if (PicoPicohw.page < 0) PicoPicohw.page = 6; - else if (PicoPicohw.page > 6) PicoPicohw.page = 0; + if (PicoPicohw.page < 0) PicoPicohw.page = 7; + else if (PicoPicohw.page > 7) PicoPicohw.page = 0; return 0; } return 1; diff --git a/platform/libpicofe b/platform/libpicofe index 4acbd7fec..d4428e4e2 160000 --- a/platform/libpicofe +++ b/platform/libpicofe @@ -1 +1 @@ -Subproject commit 4acbd7fec908288d3ba134c3ee17e05d3b3adddc +Subproject commit d4428e4e21c79064dea669dfc6c93f1a1cb9c536