Skip to content

Commit

Permalink
platform, add virtual keyboard support
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Jan 22, 2025
1 parent fabe161 commit bac44b1
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ ifeq "$(USE_FRONTEND)" "1"

# common
OBJS += platform/common/main.o platform/common/emu.o platform/common/upscale.o \
platform/common/menu_pico.o platform/common/config_file.o
platform/common/menu_pico.o platform/common/keyboard.o platform/common/config_file.o

# libpicofe
OBJS += platform/libpicofe/input.o platform/libpicofe/readpng.o \
Expand Down
2 changes: 1 addition & 1 deletion pico/pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +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 POPT_EN_KBD (1<<26)

#define PAHW_MCD (1<<0)
#define PAHW_32X (1<<1)
Expand Down
2 changes: 1 addition & 1 deletion pico/pico/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void PicoWrite16_pico(u32 a, u32 d)
static u32 PicoRead8_pico_kb(u32 a)
{
u32 d = 0;
if (!(PicoIn.opt & POPT_EN_PICO_KBD)) {
if (!(PicoIn.opt & POPT_EN_KBD)) {
elprintf(EL_PICOHW, "kb: r @%06X %04X = %04X\n", SekPc, a, d);
return d;
}
Expand Down
6 changes: 6 additions & 0 deletions platform/common/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
currentConfig.max_skip = atoi(val);
return 1;

case MA_CTRL_KEYBOARD:
currentConfig.keyboard = 0;
if (strcasecmp(val, "virtual") == 0)
currentConfig.keyboard = 1;
return 1;

/* PSP */
case MA_OPT3_VSYNC:
// XXX: use enum
Expand Down
41 changes: 31 additions & 10 deletions platform/common/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../libpicofe/readpng.h"
#include "../libpicofe/plat.h"
#include "emu.h"
#include "keyboard.h"
#include "input_pico.h"
#include "menu_pico.h"
#include "config_file.h"
Expand Down Expand Up @@ -59,7 +60,8 @@ int pico_inp_mode;
int flip_after_sync;
int engineState = PGS_Menu;

static int kbd_mode;
int kbd_mode;
struct vkbd *vkbd;

static int pico_page;
static int pico_w, pico_h;
Expand Down Expand Up @@ -1168,7 +1170,7 @@ void run_events_pico(unsigned int events)
emu_status_msg("Input: D-Pad");
}

PicoPicohw.kb.active = (PicoIn.opt & POPT_EN_PICO_KBD ? kbd_mode : 0);
PicoPicohw.kb.active = (PicoIn.opt & POPT_EN_KBD ? kbd_mode : 0);

if (pico_inp_mode == 0)
return;
Expand Down Expand Up @@ -1284,8 +1286,15 @@ static void run_events_ui(unsigned int which)
}
if (which & PEV_SWITCH_KBD)
{
kbd_mode = !kbd_mode;
emu_status_msg("Keyboard %s", kbd_mode ? "on" : "off");
if (! (PicoIn.opt & POPT_EN_KBD)) {
kbd_mode = 0;
emu_status_msg("Keyboard not enabled");
} else {
kbd_mode = !kbd_mode;
emu_status_msg("Keyboard %s", kbd_mode ? "on" : "off");
}
if (! kbd_mode)
plat_video_clear_buffers();
}
if (which & PEV_RESET)
emu_reset_game();
Expand All @@ -1299,6 +1308,7 @@ void emu_update_input(void)
int actions[IN_BINDTYPE_COUNT] = { 0, };
int actions_kbd[IN_BIND_LAST] = { 0, };
int pl_actions[4];
int count_kbd = 0;
int events, i;

in_update(actions);
Expand All @@ -1312,7 +1322,10 @@ void emu_update_input(void)

if (kbd_mode) {
int mask = (PicoIn.AHW & PAHW_PICO ? 0xf : 0x0);
in_update_kbd(actions_kbd);
if (currentConfig.keyboard == 0)
count_kbd = in_update_kbd(actions_kbd);
else if (currentConfig.keyboard == 1)
count_kbd = vkbd_update(vkbd, pl_actions[0], actions_kbd);

// FIXME: Only passthrough joystick input to avoid collisions
// with PS/2 bindings. Ideally we should check if the device this
Expand Down Expand Up @@ -1357,15 +1370,14 @@ void emu_update_input(void)

// update keyboard input, actions only updated if keyboard mode active
PicoIn.kbd = 0;
for (i = 0; i < IN_BIND_LAST; i++) {
for (i = 0; i < count_kbd; i++) {
if (actions_kbd[i]) {
unsigned int action = actions_kbd[i];
unsigned int key = (action & 0xff);
unsigned int key = (actions_kbd[i] & 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);
PicoIn.kbd = (PicoIn.kbd & 0x00ff) | (key << 8);
} else {
PicoIn.kbd = (PicoIn.kbd & 0xff00) | action;
PicoIn.kbd = (PicoIn.kbd & 0xff00) | key;
}
}
}
Expand Down Expand Up @@ -1534,6 +1546,15 @@ static void emu_loop_prep(void)

plat_target_gamma_set(currentConfig.gamma, 0);

vkbd = NULL;
if (currentConfig.keyboard == 1) {
if (PicoIn.AHW & PAHW_SMS) vkbd = &vkbd_sc3000;
else if (PicoIn.AHW & PAHW_PICO) vkbd = &vkbd_pico;
}
PicoIn.opt &= ~POPT_EN_KBD;
if ((currentConfig.EmuOpt & EOPT_PICO_KBD) || (PicoIn.AHW & PAHW_SMS))
PicoIn.opt |= POPT_EN_KBD;

pemu_loop_prep();
}

Expand Down
4 changes: 4 additions & 0 deletions platform/common/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern int g_screen_ppitch; // pitch in pixels
#define EOPT_WIZ_TEAR_FIX (1<<19)
#define EOPT_EXT_FRMLIMIT (1<<20) // no internal frame limiter (limited by snd, etc)
#define EOPT_PICO_PEN (1<<21)
#define EOPT_PICO_KBD (1<<22)

enum {
EOPT_SCALE_NONE = 0,
Expand Down Expand Up @@ -93,6 +94,7 @@ typedef struct _currentConfig_t {
int filter; // EOPT_FILTER_* video filter
int ghosting;
int analog_deadzone;
int keyboard;
int msh2_khz;
int ssh2_khz;
int overclock_68k;
Expand All @@ -106,6 +108,8 @@ extern int config_slot, config_slot_current;
extern unsigned char *movie_data;
extern int reset_timing;
extern int flip_after_sync;
extern int kbd_mode;
extern struct vkbd *vkbd;

#define PICO_PEN_ADJUST_X 1
#define PICO_PEN_ADJUST_Y 1
Expand Down
Loading

0 comments on commit bac44b1

Please sign in to comment.