Skip to content

Commit

Permalink
Merge branch 'sf/mousestick'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Fosdick committed Dec 1, 2023
2 parents c4ea698 + 849e38e commit f5dacef
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ void config_load(void)
mem_jim_setsize(get_config_int(NULL, "jim_mem_size", 0));

mouse_amx = get_config_bool(NULL, "mouse_amx", 0);
mouse_stick = get_config_bool(NULL, "mouse_stick", 0);
kbdips = get_config_int(NULL, "kbdips", 0);

for (int act = 0; act < KEY_ACTION_MAX; act++) {
Expand Down Expand Up @@ -369,6 +370,7 @@ void config_save(void)
set_config_int(NULL, "jim_mem_size", mem_jim_size);

set_config_bool(NULL, "mouse_amx", mouse_amx);
set_config_bool(NULL, "mouse_stick", mouse_stick);

for (int c = 0; c < KEY_ACTION_MAX; c++) {
if (keyactions[c].keycode == keyact_const[c].keycode && keyactions[c].altstate == keyact_const[c].altstate)
Expand Down
3 changes: 3 additions & 0 deletions src/gui-allegro.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ static ALLEGRO_MENU *create_settings_menu(void)
add_checkbox_item(menu, "Mouse (AMX)", IDM_MOUSE_AMX, mouse_amx);
if (joystick_count > 0)
al_append_menu_item(menu, "Joysticks", 0, 0, NULL, create_joysticks_menu());
add_checkbox_item(menu, "Joystick Mouse", IDM_MOUSE_STICK, mouse_stick);
return menu;
}

Expand Down Expand Up @@ -1539,6 +1540,8 @@ void gui_allegro_event(ALLEGRO_EVENT *event)
break;
case IDM_JOYSTICK2:
change_joystick(1, radio_event_with_deselect(event, joystick_index[1]));
case IDM_MOUSE_STICK:
mouse_stick = !mouse_stick;
break;
case IDM_JOYMAP:
joymap_index[0] = radio_event_simple(event, joymap_index[0]);
Expand Down
1 change: 1 addition & 0 deletions src/gui-allegro.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ typedef enum {
IDM_AUTO_PAUSE,
IDM_MOUSE_AMX,
IDM_TRIACK_SEGA_ADAPTER,
IDM_MOUSE_STICK,
IDM_JOYMAP,
IDM_JOYMAP2,
IDM_JOYSTICK,
Expand Down
28 changes: 26 additions & 2 deletions src/mouse.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
#define _DEBUG
#include "b-em.h"

#include "mouse.h"
#include "mem.h"
#include "model.h"
#include "via.h"
#include "uservia.h"
#include "video_render.h"

bool mouse_amx;
bool mouse_amx, mouse_stick;
int mcount = 8;

uint8_t mouse_portb = 0xff;

static int mx = 0, my = 0;
static int mouse_xff = 0, mouse_yff = 0;

static float stick_calc(double posn, double limit)
{
double value = posn / limit;
value = (value - 0.5) * 2.2;
if (value > 1.0)
value = 1.0;
else if (value < -1.0)
value = -1.0;
return value;
}

void mouse_axes(ALLEGRO_EVENT *event)
{
log_debug("mouse: axes event, x=%d, y=%d, dx=%d, mx=%d, dy=%d, my=%d", event->mouse.x, event->mouse.y, event->mouse.dx, mx, event->mouse.dy, my);
if (curtube == 3) {
mx += event->mouse.dx;
my += event->mouse.dy;
Expand All @@ -24,7 +38,10 @@ void mouse_axes(ALLEGRO_EVENT *event)
mx += event->mouse.dx * 2;
my += event->mouse.dy * 2;
}
log_debug("mouse: axes event, dx=%d, mx=%d, dy=%d, my=%d", event->mouse.dx, mx, event->mouse.dy, my);
if (mouse_stick) {
joyaxes[0] = stick_calc(event->mouse.x, winsizex);
joyaxes[1] = stick_calc(event->mouse.y, winsizey);
}
}

void mouse_btn_down(ALLEGRO_EVENT *event)
Expand All @@ -51,6 +68,11 @@ void mouse_btn_down(ALLEGRO_EVENT *event)
mouse_portb &= ~0x40;
break;
}
if (mouse_stick) {
int btn = (button & 1) ^ 1;
log_debug("mouse: stick button %d down", btn);
joybutton[btn] = 1;
}
}

void mouse_btn_up(ALLEGRO_EVENT *event) {
Expand All @@ -76,6 +98,8 @@ void mouse_btn_up(ALLEGRO_EVENT *event) {
mouse_portb |= 0x40;
break;
}
if (mouse_stick)
joybutton[(button & 1) ^ 1] = 0;
}

static void mouse_poll_x86(int xmask, int ymask)
Expand Down
1 change: 1 addition & 0 deletions src/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ void mouse_poll(void);
extern int mcount;
extern uint8_t mouse_portb;
extern bool mouse_amx;
extern bool mouse_stick;

#endif

0 comments on commit f5dacef

Please sign in to comment.