29 static int move_dx, move_dy, nibble_counter;
31 static int wheel_dx, wheel_dy;
33 static int mouse_button1, mouse_button2;
34 static int rts_old_level = -1;
35 static int mouse_pulse = 0;
38 static Uint32 watchdog_mouse;
39 static Uint32 watchdog_xep128;
42 static int control_port_emu_mode = -1;
46 static Uint8 mouse_buffer[] = {
57 #define WATCHDOG_USEC(n) (n / 64)
64 #define BUTTON_OTHER 2
86 .
name =
"BoxSoft J-col",
93 .name =
"ExtMSX J-col",
100 .name =
"EnterMice J-col",
107 .name =
"BoxSoft K-col",
114 .name =
"ExtMSX K-col",
121 .name =
"EnterMice K-col",
130 #define LAST_MOUSE_MODE ((sizeof(mouse_modes) / sizeof(const struct mouse_modes_st)) - 1)
135 #define JOYSTICK_SCAN(num, dir) joystick_scan(num, dir)
144 sprintf(buffer,
"#%d *** Invalid mouse mode ***", cfg);
149 "#%d (%s) nibbles=%d wrap=%d watchdog=%d mask=%d",
151 mouse_modes[cfg].
name,
153 mouse_modes[cfg].
wrap,
167 mouse_buffer[2] &= 0xF0;
172 static inline void set_button (
Uint8 *storage,
int mask,
int pressed )
177 *storage &= 255 -
mask;
186 switch (sdl_button) {
187 case SDL_BUTTON_LEFT:
191 case SDL_BUTTON_MIDDLE:
195 case SDL_BUTTON_RIGHT:
212 DEBUG(
"MOUSE: BUTTON: event: SDL#%d XEP#%d (%s) %s" NL, sdl_button,
id,
name, press ?
"pressed" :
"released");
214 DEBUG(
"MOUSE: BUTTON: unknown button on SDL level (see previous MOUSE: line)!!" NL);
217 if (sdl_button == SDL_BUTTON_LEFT && press &&
mouse_grab == 0) {
224 DEBUG(
"MOUSE: BUTTON: not in grab mode, do not forward event" NL);
227 switch (
mode->buttons[
id]) {
229 mouse_button1 = press;
232 mouse_button2 = press;
235 set_button(&mouse_buffer[2], 1, press);
238 set_button(&mouse_buffer[2], 2, press);
241 set_button(&mouse_buffer[2], 4, press);
244 DEBUG(
"MOUSE: used mouse button cannot be mapped for the given mouse mode (map=%d), ignored" NL,
mode->buttons[
id]);
253 DEBUG(
"MOUSE: MOTION: event: dx = %d, dy = %d" NL, dx, dy);
255 DEBUG(
"MOUSE: MOTION: not in grab mode, do not forward event" NL);
259 if (move_dx > 127) move_dx = 127;
260 else if (move_dx < -128) move_dx = -128;
262 if (move_dy > 127) move_dy = 127;
263 else if (move_dy < -128) move_dy = -128;
270 DEBUG(
"MOUSE: WHEEL: event: x = %d, y = %d, flipped = %d" NL,
x,
y, flipped);
272 DEBUG(
"MOUSE: WHEEL: not in grab mode, do not forward event" NL);
275 flipped = flipped ? -1 : 1;
276 wheel_dx -=
x * flipped;
277 if (wheel_dx > 127) wheel_dx = 127;
278 else if (wheel_dx < -128) wheel_dx = -128;
279 wheel_dy -=
y * flipped;
280 if (wheel_dy > 127) wheel_dy = 127;
281 else if (wheel_dy < -128) wheel_dy = -128;
300 mouse_buffer[0] = mouse_buffer[1] = mouse_buffer[3] = 0;
305 static inline void check_mouse_watchdog (
void )
309 if (
mode->watchdog >= 0 && (time >
mode->watchdog || time < 0))
319 int mouse_ok, joy1_ok;
327 }
else if (mouse_pulse && (time <
WATCHDOG_USEC(100000) || time < 0)) {
335 if (control_port_emu_mode != mouse_ok + joy1_ok) {
336 static const char *m[] = {
"joystick",
"Mouse",
"dual (K-col)" };
337 control_port_emu_mode = mouse_ok + joy1_ok;
338 OSD(
"Control port: %s mode", m[control_port_emu_mode - 1 ]);
344 (mouse_ok ? ((mouse_button1 ? 0 :
mode->data_mask) | (7 -
mode->data_mask - 4) | (mouse_button2 ? 0 : 4)) : 7) &
366 if ((val & 2) == rts_old_level)
368 rts_old_level = val & 2;
371 check_mouse_watchdog();
372 if (nibble_counter >=
mode->nibbles &&
mode->wrap)
376 if (nibble_counter == 0) {
379 mouse_buffer[0] = move_dx;
381 }
else if (nibble_counter == 2) {
384 mouse_buffer[1] = move_dy;
386 }
else if (nibble_counter == 6) {
387 mouse_buffer[3] = wheel_dy;
390 if (nibble_counter < mode->
nibbles) {
393 nibble = ((nibble_counter & 1) ? (mouse_buffer[nibble_counter >> 1] & 15) : (mouse_buffer[nibble_counter >> 1] >> 4));
409 mode = &mouse_modes[cfg];
411 DEBUG(
"MOUSE: SETUP: %s" NL, buffer);
423 OSD(
"SDL scancode is \"%s\" (%d)", SDL_GetScancodeName(sym.scancode), sym.scancode);
424 if (
mouse_grab && sym.scancode == SDL_SCANCODE_ESCAPE && press) {
430 int sel = ke->
posep >> 4;