Skip to content

Commit

Permalink
MEGA65: adding option to disable mouse emulation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lgblgblgb committed Oct 21, 2024
1 parent 9b89f57 commit 7394989
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions targets/mega65/configdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static const struct xemutools_configdef_switch_st switch_options[] = {
{ "matrixstart", "Start with matrix-mode activated", &configdb.matrixstart },
{ "matrixdisable", "Disable the matrix hotkey", &configdb.matrixdisable },
{ "ramcheckread", "Enabled warnings on reading unwritten memory (first 126K only)", &configdb.ramcheckread },
{ "nomouseemu", "Disable mouse emulation", &configdb.nomouseemu },
{ NULL }
};

Expand Down
1 change: 1 addition & 0 deletions targets/mega65/configdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ struct configdb_st {
int ramcheckread;
char *init_attic;
int joyport;
int nomouseemu;
};

extern struct configdb_st configdb;
Expand Down
24 changes: 18 additions & 6 deletions targets/mega65/input_devices.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore-65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -519,9 +519,15 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )
if (pos == RESTORE_KEY_POS)
restore_is_held = 0;
if (pos == -2 && key == 0) { // special case pos = -2, key = 0, handled = mouse button (which?) and release event!
if ((handled == SDL_BUTTON_LEFT) && set_mouse_grab(SDL_TRUE, 0)) {
OSD(-1, -1, " Mouse grab activated. Press \n both SHIFTs together to cancel.");
DEBUGPRINT("UI: mouse grab activated" NL);
if ((handled == SDL_BUTTON_LEFT)) {
if (configdb.nomouseemu) {
OSD(-1, -1, "Mouse emulation is disabled.\nCannot enter mouse grab mode.");
} else {
if (set_mouse_grab(SDL_TRUE, 0)) {
OSD(-1, -1, "Mouse grab activated. Press\nboth SHIFTs together to cancel.");
DEBUGPRINT("UI: mouse grab activated" NL);
}
}
}
if (handled == SDL_BUTTON_RIGHT) {
ui_enter();
Expand All @@ -534,26 +540,32 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )

Uint8 get_mouse_x_via_sid ( void )
{
static Uint8 result = 0;
if (is_mouse_grab()) {
static Uint8 result = 0;
static int mouse_x = 0;
mouse_x = (mouse_x + (hid_read_mouse_rel_x(-23, 23) / 3)) & 0x3F;
DEBUG("MOUSE: X is %d, result byte is %d" NL, mouse_x, result);
result = mouse_x << 1;
return result;
}
const Uint8 result = configdb.nomouseemu ? 0xFF : 0x00;
DEBUG("MOUSE: X query without mouse-grab is $%02X" NL, result);
return result;
}


Uint8 get_mouse_y_via_sid ( void )
{
static Uint8 result = 0;
if (is_mouse_grab()) {
static Uint8 result = 0;
static int mouse_y = 0;
mouse_y = (mouse_y - (hid_read_mouse_rel_y(-23, 23) / 3)) & 0x3F;
DEBUG("MOUSE: Y is %d, result byte is %d" NL, mouse_y, result);
result = mouse_y << 1;
return result;
}
const Uint8 result = configdb.nomouseemu ? 0xFF : 0x00;
DEBUG("MOUSE: Y query without mouse-grab is $%02X" NL, result);
return result;
}

Expand Down
4 changes: 3 additions & 1 deletion targets/mega65/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,10 @@ static const struct menu_st menu_reset[] = {
{ NULL }
};
static const struct menu_st menu_inputdevices[] = {
{ "Enable mouse grab + emu", XEMUGUI_MENUID_CALLABLE |
{ "Enable mouse grab", XEMUGUI_MENUID_CALLABLE |
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_set_mouse_grab, NULL },
{ "Disable mouse emulation", XEMUGUI_MENUID_CALLABLE |
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_toggle_int, (void*)&configdb.nomouseemu },
{ "Use OSD key debugger", XEMUGUI_MENUID_CALLABLE |
XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_osd_key_debugger, NULL },
{ "Cursor keys as joystick", XEMUGUI_MENUID_CALLABLE |
Expand Down

0 comments on commit 7394989

Please sign in to comment.