Skip to content

Commit

Permalink
platform, keyboard improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Jan 15, 2025
1 parent 4b18df5 commit 4cd399e
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 64 deletions.
4 changes: 2 additions & 2 deletions pico/pico/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down
7 changes: 4 additions & 3 deletions pico/sms.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}
Expand Down
81 changes: 46 additions & 35 deletions platform/common/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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" };
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions platform/common/input_pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 */

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion platform/common/inputmap_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 },
Expand Down
12 changes: 6 additions & 6 deletions platform/common/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 },
Expand Down Expand Up @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
};
Expand Down
33 changes: 20 additions & 13 deletions platform/common/menu_pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -1412,17 +1418,18 @@ 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;
}

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;
Expand Down
2 changes: 1 addition & 1 deletion platform/libpicofe
Submodule libpicofe updated 1 files
+5 −3 input.c

0 comments on commit 4cd399e

Please sign in to comment.