Skip to content

Commit 50290c9

Browse files
committed
bugfix: Virtual keyboard input would pass through
Virtual keyboard input from the controller, would also pass through the emulation as controller input.
1 parent 39f4f9c commit 50290c9

File tree

1 file changed

+99
-101
lines changed

1 file changed

+99
-101
lines changed

src/inputdevice.cpp

Lines changed: 99 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "options.h"
2828
#include "keyboard.h"
2929
#include "inputdevice.h"
30+
31+
#include <algorithm>
3032
#include "inputrecord.h"
3133
#include "keybuf.h"
3234
#include "custom.h"
@@ -210,6 +212,42 @@ extern int draco_keyboard_get_rate(void);
210212
static int draco_keybord_repeat_cnt, draco_keybord_repeat_code;
211213
#endif
212214

215+
static void osk_control(int x, int y, int button, int buttonstate)
216+
{
217+
if (vkbd_allowed(0) && vkbd_is_active())
218+
{
219+
int vkbd_state = 0;
220+
if (button && buttonstate)
221+
{
222+
vkbd_state |= VKBD_BUTTON;
223+
}
224+
x = std::min(x, 1);
225+
x = std::max(x, -1);
226+
y = std::min(y, 1);
227+
y = std::max(y, -1);
228+
if (x < 0) {
229+
vkbd_state |= VKBD_LEFT;
230+
}
231+
if (x > 0) {
232+
vkbd_state |= VKBD_RIGHT;
233+
}
234+
if (y < 0) {
235+
vkbd_state |= VKBD_UP;
236+
}
237+
if (y > 0) {
238+
vkbd_state |= VKBD_DOWN;
239+
}
240+
241+
int code;
242+
int pressed;
243+
if (vkbd_process(vkbd_state, &code, &pressed))
244+
{
245+
inputdevice_do_keyboard(code, pressed);
246+
}
247+
vkbd_process(0, &code, &pressed);
248+
}
249+
}
250+
213251
static int isdevice (struct uae_input_device *id)
214252
{
215253
int i, j;
@@ -5252,64 +5290,6 @@ static uae_u64 isqual (int evt)
52525290
return ID_FLAG_QUALIFIER1 << (num * 2);
52535291
}
52545292

5255-
#ifdef AMIBERRY
5256-
// Pass the joystick state (joybutton and joydir) to vkbd subsystem and clear them for the emulator.
5257-
static void handle_vkbd()
5258-
{
5259-
if (!vkbd_is_active()) return;
5260-
5261-
int vkbd_state = 0;
5262-
for (int joy = 0; joy < 2; ++joy)
5263-
{
5264-
oleft[joy] = 0;
5265-
oright[joy] = 0;
5266-
otop[joy] = 0;
5267-
obot[joy] = 0;
5268-
horizclear[joy] = 0;
5269-
vertclear[joy] = 0;
5270-
5271-
int mask_button;
5272-
if (cd32_pad_enabled[joy])
5273-
mask_button = 1 << JOYBUTTON_CD32_RED;
5274-
else
5275-
mask_button = 1 << JOYBUTTON_1;
5276-
5277-
if (joybutton[joy] & mask_button)
5278-
{
5279-
vkbd_state |= VKBD_BUTTON;
5280-
joybutton[joy] &= ~mask_button;
5281-
}
5282-
if (joydir[joy] & DIR_LEFT)
5283-
{
5284-
vkbd_state |= VKBD_LEFT;
5285-
joydir[joy] &= ~DIR_LEFT;
5286-
}
5287-
if (joydir[joy] & DIR_RIGHT)
5288-
{
5289-
vkbd_state |= VKBD_RIGHT;
5290-
joydir[joy] &= ~DIR_RIGHT;
5291-
}
5292-
if (joydir[joy] & DIR_UP)
5293-
{
5294-
vkbd_state |= VKBD_UP;
5295-
joydir[joy] &= ~DIR_UP;
5296-
}
5297-
if (joydir[joy] & DIR_DOWN)
5298-
{
5299-
vkbd_state |= VKBD_DOWN;
5300-
joydir[joy] &= ~DIR_DOWN;
5301-
}
5302-
}
5303-
5304-
int code;
5305-
int pressed;
5306-
if (vkbd_process(vkbd_state, &code, &pressed))
5307-
{
5308-
inputdevice_do_keyboard(code, pressed);
5309-
}
5310-
}
5311-
#endif
5312-
53135293
static int handle_input_event2(int nr, int state, int max, int flags, int extra)
53145294
{
53155295
struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo;
@@ -5474,21 +5454,26 @@ static int handle_input_event2(int nr, int state, int max, int flags, int extra)
54745454
case 4: /* ->Parallel port joystick adapter port #2 */
54755455
joy = ie->unit - 1;
54765456
if (ie->type & 4) {
5477-
int old = joybutton[joy] & (1 << ie->data);
5478-
5479-
if (state) {
5480-
joybutton[joy] |= 1 << ie->data;
5481-
//gui_gameport_button_change (joy, ie->data, 1);
5482-
} else {
5483-
joybutton[joy] &= ~(1 << ie->data);
5484-
//gui_gameport_button_change (joy, ie->data, 0);
5457+
if (vkbd_allowed(0) && vkbd_is_active()) {
5458+
osk_control(0, 0, 1 << ie->data, state);
54855459
}
5460+
else {
5461+
int old = joybutton[joy] & (1 << ie->data);
5462+
if (state) {
5463+
joybutton[joy] |= 1 << ie->data;
5464+
//gui_gameport_button_change(joy, ie->data, 1);
5465+
}
5466+
else {
5467+
joybutton[joy] &= ~(1 << ie->data);
5468+
//gui_gameport_button_change(joy, ie->data, 0);
5469+
}
54865470

5487-
if (ie->data == 0 && old != (joybutton[joy] & (1 << ie->data)) && currprefs.cpu_cycle_exact) {
5488-
if (!input_record && !input_play && currprefs.input_contact_bounce) {
5489-
// emulate contact bounce, 1st button only, others have capacitors
5490-
bouncy = 1;
5491-
bouncy_cycles = get_cycles () + CYCLE_UNIT * currprefs.input_contact_bounce;
5471+
if (ie->data == 0 && old != (joybutton[joy] & (1 << ie->data)) && currprefs.cpu_cycle_exact) {
5472+
if (!input_record && !input_play && currprefs.input_contact_bounce) {
5473+
// emulate contact bounce, 1st button only, others have capacitors
5474+
bouncy = 1;
5475+
bouncy_cycles = get_cycles() + CYCLE_UNIT * currprefs.input_contact_bounce;
5476+
}
54925477
}
54935478
}
54945479

@@ -5720,48 +5705,61 @@ static int handle_input_event2(int nr, int state, int max, int flags, int extra)
57205705
}
57215706
mouse_deltanoreset[joy][0] = 1;
57225707
mouse_deltanoreset[joy][1] = 1;
5723-
joydir[joy] = 0;
5724-
if (left) {
5725-
if (!allowoppositestick) {
5726-
joydir[joy] &= ~DIR_RIGHT;
5708+
if (vkbd_allowed(0) && vkbd_is_active()) {
5709+
if (left) {
5710+
osk_control(-1, 0, 0, 0);
57275711
}
5728-
joydir[joy] |= DIR_LEFT;
5729-
}
5730-
if (right) {
5731-
if (!allowoppositestick) {
5732-
joydir[joy] &= ~DIR_LEFT;
5712+
if (right) {
5713+
osk_control(1, 0, 0, 0);
57335714
}
5734-
joydir[joy] |= DIR_RIGHT;
5735-
}
5736-
if (top) {
5737-
if (!allowoppositestick) {
5738-
joydir[joy] &= ~DIR_DOWN;
5715+
if (top) {
5716+
osk_control(0, -1, 0, 0);
57395717
}
5740-
joydir[joy] |= DIR_UP;
5741-
}
5742-
if (bot) {
5743-
if (!allowoppositestick) {
5744-
joydir[joy] &= ~DIR_UP;
5718+
if (bot) {
5719+
osk_control(0, 1, 0, 0);
57455720
}
5746-
joydir[joy] |= DIR_DOWN;
57475721
}
5748-
if (joy == 0 || joy == 1)
5749-
joymousecounter (joy);
5722+
else {
5723+
joydir[joy] = 0;
5724+
if (left) {
5725+
if (!allowoppositestick) {
5726+
joydir[joy] &= ~DIR_RIGHT;
5727+
}
5728+
joydir[joy] |= DIR_LEFT;
5729+
}
5730+
if (right) {
5731+
if (!allowoppositestick) {
5732+
joydir[joy] &= ~DIR_LEFT;
5733+
}
5734+
joydir[joy] |= DIR_RIGHT;
5735+
}
5736+
if (top) {
5737+
if (!allowoppositestick) {
5738+
joydir[joy] &= ~DIR_DOWN;
5739+
}
5740+
joydir[joy] |= DIR_UP;
5741+
}
5742+
if (bot) {
5743+
if (!allowoppositestick) {
5744+
joydir[joy] &= ~DIR_UP;
5745+
}
5746+
joydir[joy] |= DIR_DOWN;
5747+
}
5748+
if (joy == 0 || joy == 1)
5749+
joymousecounter(joy);
57505750

5751-
//gui_gameport_axis_change (joy, DIR_LEFT_BIT, left, 0);
5752-
//gui_gameport_axis_change (joy, DIR_RIGHT_BIT, right, 0);
5753-
//gui_gameport_axis_change (joy, DIR_UP_BIT, top, 0);
5754-
//gui_gameport_axis_change (joy, DIR_DOWN_BIT, bot, 0);
5751+
//gui_gameport_axis_change(joy, DIR_LEFT_BIT, left, 0);
5752+
//gui_gameport_axis_change(joy, DIR_RIGHT_BIT, right, 0);
5753+
//gui_gameport_axis_change(joy, DIR_UP_BIT, top, 0);
5754+
//gui_gameport_axis_change(joy, DIR_DOWN_BIT, bot, 0);
5755+
}
57555756
}
57565757
break;
57575758
case 0: /* ->KEY */
57585759
inputdevice_do_keyboard (ie->data, state);
57595760
break;
57605761
}
5761-
#ifdef AMIBERRY
5762-
if (vkbd_allowed(0) && vkbd_is_active())
5763-
handle_vkbd();
5764-
#endif
5762+
57655763
return 1;
57665764
}
57675765

0 commit comments

Comments
 (0)