Skip to content

Commit 7394989

Browse files
committed
MEGA65: adding option to disable mouse emulation
The problem: Xemu user may leave mouse grab mode to do something with their mouse. To avoid bothering the mouse-aware MEGA65 program running, I returned zero for relative mouse position change in this case. However that can cause problems with certain programs which are not mouse based and expecting $FF if mouse is not there.
1 parent 9b89f57 commit 7394989

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

targets/mega65/configdb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static const struct xemutools_configdef_switch_st switch_options[] = {
114114
{ "matrixstart", "Start with matrix-mode activated", &configdb.matrixstart },
115115
{ "matrixdisable", "Disable the matrix hotkey", &configdb.matrixdisable },
116116
{ "ramcheckread", "Enabled warnings on reading unwritten memory (first 126K only)", &configdb.ramcheckread },
117+
{ "nomouseemu", "Disable mouse emulation", &configdb.nomouseemu },
117118
{ NULL }
118119
};
119120

targets/mega65/configdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct configdb_st {
115115
int ramcheckread;
116116
char *init_attic;
117117
int joyport;
118+
int nomouseemu;
118119
};
119120

120121
extern struct configdb_st configdb;

targets/mega65/input_devices.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* A work-in-progess MEGA65 (Commodore-65 clone origins) emulator
22
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
3-
Copyright (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
3+
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -519,9 +519,15 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )
519519
if (pos == RESTORE_KEY_POS)
520520
restore_is_held = 0;
521521
if (pos == -2 && key == 0) { // special case pos = -2, key = 0, handled = mouse button (which?) and release event!
522-
if ((handled == SDL_BUTTON_LEFT) && set_mouse_grab(SDL_TRUE, 0)) {
523-
OSD(-1, -1, " Mouse grab activated. Press \n both SHIFTs together to cancel.");
524-
DEBUGPRINT("UI: mouse grab activated" NL);
522+
if ((handled == SDL_BUTTON_LEFT)) {
523+
if (configdb.nomouseemu) {
524+
OSD(-1, -1, "Mouse emulation is disabled.\nCannot enter mouse grab mode.");
525+
} else {
526+
if (set_mouse_grab(SDL_TRUE, 0)) {
527+
OSD(-1, -1, "Mouse grab activated. Press\nboth SHIFTs together to cancel.");
528+
DEBUGPRINT("UI: mouse grab activated" NL);
529+
}
530+
}
525531
}
526532
if (handled == SDL_BUTTON_RIGHT) {
527533
ui_enter();
@@ -534,26 +540,32 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )
534540

535541
Uint8 get_mouse_x_via_sid ( void )
536542
{
537-
static Uint8 result = 0;
538543
if (is_mouse_grab()) {
544+
static Uint8 result = 0;
539545
static int mouse_x = 0;
540546
mouse_x = (mouse_x + (hid_read_mouse_rel_x(-23, 23) / 3)) & 0x3F;
541547
DEBUG("MOUSE: X is %d, result byte is %d" NL, mouse_x, result);
542548
result = mouse_x << 1;
549+
return result;
543550
}
551+
const Uint8 result = configdb.nomouseemu ? 0xFF : 0x00;
552+
DEBUG("MOUSE: X query without mouse-grab is $%02X" NL, result);
544553
return result;
545554
}
546555

547556

548557
Uint8 get_mouse_y_via_sid ( void )
549558
{
550-
static Uint8 result = 0;
551559
if (is_mouse_grab()) {
560+
static Uint8 result = 0;
552561
static int mouse_y = 0;
553562
mouse_y = (mouse_y - (hid_read_mouse_rel_y(-23, 23) / 3)) & 0x3F;
554563
DEBUG("MOUSE: Y is %d, result byte is %d" NL, mouse_y, result);
555564
result = mouse_y << 1;
565+
return result;
556566
}
567+
const Uint8 result = configdb.nomouseemu ? 0xFF : 0x00;
568+
DEBUG("MOUSE: Y query without mouse-grab is $%02X" NL, result);
557569
return result;
558570
}
559571

targets/mega65/ui.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,10 @@ static const struct menu_st menu_reset[] = {
862862
{ NULL }
863863
};
864864
static const struct menu_st menu_inputdevices[] = {
865-
{ "Enable mouse grab + emu", XEMUGUI_MENUID_CALLABLE |
865+
{ "Enable mouse grab", XEMUGUI_MENUID_CALLABLE |
866866
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_set_mouse_grab, NULL },
867+
{ "Disable mouse emulation", XEMUGUI_MENUID_CALLABLE |
868+
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_toggle_int, (void*)&configdb.nomouseemu },
867869
{ "Use OSD key debugger", XEMUGUI_MENUID_CALLABLE |
868870
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_osd_key_debugger, NULL },
869871
{ "Cursor keys as joystick", XEMUGUI_MENUID_CALLABLE |

0 commit comments

Comments
 (0)