annotate io.c @ 1576:2b132d894d76

Release capture of mouse and keyboard when entering UI
author Michael Pavone <pavone@retrodev.com>
date Tue, 01 May 2018 09:44:44 -0700
parents 577253765192
children 430dd12e4010
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 451
diff changeset
1 /*
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 451
diff changeset
2 Copyright 2013 Michael Pavone
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
3 This file is part of BlastEm.
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 451
diff changeset
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 451
diff changeset
5 */
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
6 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
7 #include <unistd.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
8 #include <fcntl.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
9 #include <sys/socket.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
10 #include <sys/un.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
11 #include <sys/types.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
12 #include <sys/stat.h>
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
13 #include <errno.h>
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
14 #endif
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
15 #include <string.h>
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
16 #include <stdlib.h>
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
17
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
18 #include "serialize.h"
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 #include "io.h"
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 #include "blastem.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
21 #include "genesis.h"
1377
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
22 #include "sms.h"
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 #include "render.h"
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
24 #include "util.h"
1435
178de1432291 Using ui.exit to abort loading or saving a state via menu will no longer cause you to return to those sub-menus the next time the menu is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1427
diff changeset
25 #include "menu.h"
1478
da1dce39e846 Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents: 1477
diff changeset
26 #include "saves.h"
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
27 #ifndef DISABLE_NUKLEAR
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
28 #include "nuklear_ui/blastem_nuklear.h"
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
29 #endif
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
31 #define CYCLE_NEVER 0xFFFFFFFF
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
32 #define MIN_POLL_INTERVAL 6840
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
33
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
34 const char * device_type_names[] = {
1146
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
35 "SMS gamepad",
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
36 "3-button gamepad",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
37 "6-button gamepad",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
38 "Mega Mouse",
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
39 "Saturn Keyboard",
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
40 "XBAND Keyboard",
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
41 "Menacer",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
42 "Justifier",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
43 "Sega multi-tap",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
44 "EA 4-way Play cable A",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
45 "EA 4-way Play cable B",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
46 "Sega Parallel Transfer Board",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
47 "Generic Device",
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
48 "None"
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
49 };
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
50
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 enum {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 BIND_NONE,
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
53 BIND_UI,
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54 BIND_GAMEPAD1,
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 BIND_GAMEPAD2,
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
56 BIND_GAMEPAD3,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
57 BIND_GAMEPAD4,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
58 BIND_GAMEPAD5,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
59 BIND_GAMEPAD6,
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
60 BIND_GAMEPAD7,
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
61 BIND_GAMEPAD8,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
62 BIND_MOUSE1,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
63 BIND_MOUSE2,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
64 BIND_MOUSE3,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
65 BIND_MOUSE4,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
66 BIND_MOUSE5,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
67 BIND_MOUSE6,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
68 BIND_MOUSE7,
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
69 BIND_MOUSE8
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 };
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 typedef enum {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 UI_DEBUG_MODE_INC,
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 UI_DEBUG_PAL_INC,
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
75 UI_ENTER_DEBUGGER,
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
76 UI_SAVE_STATE,
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
77 UI_SET_SPEED,
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
78 UI_NEXT_SPEED,
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
79 UI_PREV_SPEED,
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
80 UI_RELEASE_MOUSE,
1254
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
81 UI_TOGGLE_KEYBOARD_CAPTURE,
1202
a6ae693974e0 Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents: 1197
diff changeset
82 UI_TOGGLE_FULLSCREEN,
1208
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1207
diff changeset
83 UI_SOFT_RESET,
1438
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1435
diff changeset
84 UI_RELOAD,
1377
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
85 UI_SMS_PAUSE,
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
86 UI_SCREENSHOT,
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
87 UI_EXIT
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 } ui_action;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
89
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
90 typedef enum {
1396
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
91 MOUSE_NONE, //mouse is ignored
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
92 MOUSE_ABSOLUTE, //really only useful for menu ROM
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
93 MOUSE_RELATIVE, //for full screen
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
94 MOUSE_CAPTURE //for windowed mode
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
95 } mouse_modes;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
96
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
97
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 typedef struct {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
99 io_port *port;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 uint8_t bind_type;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 uint8_t subtype_a;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 uint8_t subtype_b;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
103 uint8_t value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 } keybinding;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 typedef struct {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 keybinding bindings[4];
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 uint8_t state;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 } joydpad;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
110
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
111 typedef struct {
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
112 keybinding positive;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
113 keybinding negative;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
114 int16_t value;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
115 } joyaxis;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
116
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
117 typedef struct {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
118 keybinding *buttons;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
119 joydpad *dpads;
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
120 joyaxis *axes;
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
121 uint32_t num_buttons; //number of entries in the buttons array, not necessarily the number of buttons on the device
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
122 uint32_t num_dpads; //number of entries in the dpads array, not necessarily the number of dpads on the device
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
123 uint32_t num_axes; //number of entries in the axes array, not necessarily the number of dpads on the device
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
124 } joystick;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
125
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
126 typedef struct {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
127 io_port *motion_port;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
128 keybinding buttons[MAX_MOUSE_BUTTONS];
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
129 uint8_t bind_type;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
130 } mousebinding;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
131
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
132 #define DEFAULT_JOYBUTTON_ALLOC 12
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
133
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
134 static sega_io *current_io;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
135 static keybinding *bindings[0x10000];
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
136 static joystick joysticks[MAX_JOYSTICKS];
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
137 static mousebinding mice[MAX_MICE];
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
138 static io_port *keyboard_port;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
139 const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
141 static void do_bind(keybinding *binding, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
142 {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
143 binding->bind_type = bind_type;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
144 binding->subtype_a = subtype_a;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
145 binding->subtype_b = subtype_b;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
146 binding->value = value;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
147 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
148
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
149 void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
150 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
151 int bucket = keycode >> 15 & 0xFFFF;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
152 if (!bindings[bucket]) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
153 bindings[bucket] = malloc(sizeof(keybinding) * 0x8000);
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
154 memset(bindings[bucket], 0, sizeof(keybinding) * 0x8000);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
155 }
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
156 int idx = keycode & 0x7FFF;
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
157 do_bind(bindings[bucket] + idx, bind_type, subtype_a, subtype_b, value);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
158 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
159
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
160 void bind_button(int joystick, int button, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
161 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
162 if (joystick >= MAX_JOYSTICKS) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
163 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
164 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
165 if (!joysticks[joystick].buttons) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
166 joysticks[joystick].num_buttons = button < DEFAULT_JOYBUTTON_ALLOC ? DEFAULT_JOYBUTTON_ALLOC : button + 1;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
167 joysticks[joystick].buttons = calloc(joysticks[joystick].num_buttons, sizeof(keybinding));
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
168 } else if (joysticks[joystick].num_buttons <= button) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
169 uint32_t old_capacity = joysticks[joystick].num_buttons;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
170 joysticks[joystick].num_buttons *= 2;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
171 joysticks[joystick].buttons = realloc(joysticks[joystick].buttons, sizeof(keybinding) * joysticks[joystick].num_buttons);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
172 memset(joysticks[joystick].buttons + old_capacity, 0, joysticks[joystick].num_buttons - old_capacity);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
173 }
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
174 do_bind(joysticks[joystick].buttons + button, bind_type, subtype_a, subtype_b, value);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
175 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
176
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
177 void bind_dpad(int joystick, int dpad, int direction, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
178 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
179 if (joystick >= MAX_JOYSTICKS) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
181 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
182 if (!joysticks[joystick].dpads) {
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
183 //multiple D-pads/hats are not common, so don't allocate any extra space
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
184 joysticks[joystick].dpads = calloc(dpad+1, sizeof(joydpad));
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
185 joysticks[joystick].num_dpads = dpad+1;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
186 } else if (joysticks[joystick].num_dpads <= dpad) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
187 uint32_t old_capacity = joysticks[joystick].num_dpads;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
188 joysticks[joystick].num_dpads *= 2;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
189 joysticks[joystick].dpads = realloc(joysticks[joystick].dpads, sizeof(joydpad) * joysticks[joystick].num_dpads);
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
190 memset(joysticks[joystick].dpads + old_capacity, 0, (joysticks[joystick].num_dpads - old_capacity) * sizeof(joydpad));
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
191 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
192 for (int i = 0; i < 4; i ++) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
193 if (dpadbits[i] & direction) {
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
194 do_bind(joysticks[joystick].dpads[dpad].bindings + i, bind_type, subtype_a, subtype_b, value);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
195 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
197 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
198 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
199
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
200 void bind_axis(int joystick, int axis, int positive, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
201 {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
202 if (joystick >= MAX_JOYSTICKS) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
203 return;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
204 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
205 if (!joysticks[joystick].axes) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
206 //typical gamepad has 4 axes
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
207 joysticks[joystick].num_axes = axis+1 > 4 ? axis+1 : 4;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
208 joysticks[joystick].axes = calloc(joysticks[joystick].num_axes, sizeof(joyaxis));
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
209 } else if (joysticks[joystick].num_axes <= axis) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
210 uint32_t old_capacity = joysticks[joystick].num_axes;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
211 joysticks[joystick].num_axes *= 2;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
212 joysticks[joystick].axes = realloc(joysticks[joystick].axes, sizeof(joyaxis) * joysticks[joystick].num_axes);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
213 memset(joysticks[joystick].axes + old_capacity, 0, (joysticks[joystick].num_axes - old_capacity) * sizeof(joyaxis));
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
214 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
215 if (positive) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
216 do_bind(&joysticks[joystick].axes[axis].positive, bind_type, subtype_a, subtype_b, value);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
217 } else {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
218 do_bind(&joysticks[joystick].axes[axis].negative, bind_type, subtype_a, subtype_b, value);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
219 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
220 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
221
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
222 void reset_joystick_bindings(int joystick)
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
223 {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
224 if (joystick >= MAX_JOYSTICKS) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
225 return;
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
226 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
227 if (joysticks[joystick].buttons) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
228 for (int i = 0; i < joysticks[joystick].num_buttons; i++)
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
229 {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
230 joysticks[joystick].buttons[i].bind_type = BIND_NONE;
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
231 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
232 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
233 if (joysticks[joystick].dpads) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
234 for (int i = 0; i < joysticks[joystick].num_dpads; i++)
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
235 {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
236 for (int dir = 0; dir < 4; dir++)
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
237 {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
238 joysticks[joystick].dpads[i].bindings[dir].bind_type = BIND_NONE;
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
239 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
240 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
241 }
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
242 if (joysticks[joystick].axes) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
243 for (int i = 0; i < joysticks[joystick].num_axes; i++)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
244 {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
245 joysticks[joystick].axes[i].positive.bind_type = BIND_NONE;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
246 joysticks[joystick].axes[i].negative.bind_type = BIND_NONE;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
247 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
248 }
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
249 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
250
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
251 #define GAMEPAD_BUTTON(PRI_SLOT, SEC_SLOT, VALUE) (PRI_SLOT << 12 | SEC_SLOT << 8 | VALUE)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
252
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
253 #define DPAD_UP GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_TH1, 0x01)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
254 #define BUTTON_Z GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x01)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
255 #define DPAD_DOWN GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_TH1, 0x02)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
256 #define BUTTON_Y GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x02)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
257 #define DPAD_LEFT GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x04)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
258 #define BUTTON_X GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x04)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
259 #define DPAD_RIGHT GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x08)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
260 #define BUTTON_MODE GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x08)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
261 #define BUTTON_A GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_NONE, 0x10)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
262 #define BUTTON_B GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x10)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
263 #define BUTTON_START GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_NONE, 0x20)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
264 #define BUTTON_C GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x20)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
265
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
266 #define PSEUDO_BUTTON_MOTION 0xFFFF
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
267 #define MOUSE_LEFT 1
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
268 #define MOUSE_RIGHT 2
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
269 #define MOUSE_MIDDLE 4
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
270 #define MOUSE_START 8
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
271
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
272 void bind_gamepad(int keycode, int gamepadnum, int button)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
273 {
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
274
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
275 if (gamepadnum < 1 || gamepadnum > 8) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
276 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
277 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
278 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
279 bind_key(keycode, bind_type, button >> 12, button >> 8 & 0xF, button & 0xFF);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
280 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
281
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
282 void bind_button_gamepad(int joystick, int joybutton, int gamepadnum, int padbutton)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
283 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
284 if (gamepadnum < 1 || gamepadnum > 8) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
285 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
286 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
287 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
288 bind_button(joystick, joybutton, bind_type, padbutton >> 12, padbutton >> 8 & 0xF, padbutton & 0xFF);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
289 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
290
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
291 void bind_dpad_gamepad(int joystick, int dpad, uint8_t direction, int gamepadnum, int button)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
292 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
293 if (gamepadnum < 1 || gamepadnum > 8) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
294 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
295 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
296 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
297 bind_dpad(joystick, dpad, direction, bind_type, button >> 12, button >> 8 & 0xF, button & 0xFF);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
298 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
299
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
300 void bind_axis_gamepad(int joystick, int axis, uint8_t positive, int gamepadnum, int button)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
301 {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
302 if (gamepadnum < 1 || gamepadnum > 8) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
303 return;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
304 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
305 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
306 bind_axis(joystick, axis, positive, bind_type, button >> 12, button >> 8 & 0xF, button & 0xFF);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
307 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
308
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
309 void bind_ui(int keycode, ui_action action, uint8_t param)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
310 {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
311 bind_key(keycode, BIND_UI, action, 0, param);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
312 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
313
493
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
314 void bind_button_ui(int joystick, int joybutton, ui_action action, uint8_t param)
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
315 {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
316 bind_button(joystick, joybutton, BIND_UI, action, 0, param);
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
317 }
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
318
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
319 void bind_dpad_ui(int joystick, int dpad, uint8_t direction, ui_action action, uint8_t param)
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
320 {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
321 bind_dpad(joystick, dpad, direction, BIND_UI, action, 0, param);
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
322 }
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
323
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
324 void bind_axis_ui(int joystick, int axis, uint8_t positive, ui_action action, uint8_t param)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
325 {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
326 bind_axis(joystick, axis, positive, BIND_UI, action, 0, param);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
327 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
328
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
329 void handle_binding_down(keybinding * binding)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
330 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
331 if (binding->bind_type >= BIND_GAMEPAD1 && binding->bind_type <= BIND_GAMEPAD8)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
332 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
333 if (binding->subtype_a <= GAMEPAD_EXTRA && binding->port) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
334 binding->port->input[binding->subtype_a] |= binding->value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
335 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
336 if (binding->subtype_b <= GAMEPAD_EXTRA && binding->port) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
337 binding->port->input[binding->subtype_b] |= binding->value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
338 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
339 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
340 else if (binding->bind_type >= BIND_MOUSE1 && binding->bind_type <= BIND_MOUSE8)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
341 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
342 if (binding->port) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
343 binding->port->input[0] |= binding->value;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
344 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
345 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
346 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
347
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
348 void store_key_event(uint16_t code)
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
349 {
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
350 if (keyboard_port && keyboard_port->device.keyboard.write_pos != keyboard_port->device.keyboard.read_pos) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
351 //there's room in the buffer, record this event
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
352 keyboard_port->device.keyboard.events[keyboard_port->device.keyboard.write_pos] = code;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
353 if (keyboard_port->device.keyboard.read_pos == 0xFF) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
354 //ring buffer was empty, update read_pos to indicate there is now data
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
355 keyboard_port->device.keyboard.read_pos = keyboard_port->device.keyboard.write_pos;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
356 }
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
357 keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos + 1) & 7;
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
358 }
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
359 }
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
360
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
361 void handle_keydown(int keycode, uint8_t scancode)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
362 {
1488
f29bd94ffa76 Don't crash when keys are pressed before ROM is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
363 if (!current_io) {
f29bd94ffa76 Don't crash when keys are pressed before ROM is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
364 return;
f29bd94ffa76 Don't crash when keys are pressed before ROM is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
365 }
1266
a4fa897c99ce Don't allow the keyboard capture key to get passed to the emulated keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1263
diff changeset
366 int bucket = keycode >> 15 & 0xFFFF;
a4fa897c99ce Don't allow the keyboard capture key to get passed to the emulated keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1263
diff changeset
367 int idx = keycode & 0x7FFF;
a4fa897c99ce Don't allow the keyboard capture key to get passed to the emulated keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1263
diff changeset
368 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL;
a4fa897c99ce Don't allow the keyboard capture key to get passed to the emulated keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1263
diff changeset
369 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) {
a4fa897c99ce Don't allow the keyboard capture key to get passed to the emulated keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1263
diff changeset
370 handle_binding_down(binding);
a4fa897c99ce Don't allow the keyboard capture key to get passed to the emulated keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1263
diff changeset
371 } else if (current_io->keyboard_captured) {
1254
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
372 store_key_event(scancode);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
373 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
374 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
375
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
376 void handle_joydown(int joystick, int button)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
377 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
378 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
379 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
380 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
381 keybinding * binding = joysticks[joystick].buttons + button;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
382 handle_binding_down(binding);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
383 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
384
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
385 void handle_mousedown(int mouse, int button)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
386 {
1483
001120e91fed Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
387 if (!current_io) {
001120e91fed Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
388 return;
001120e91fed Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
389 }
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
390 if (current_io->mouse_mode == MOUSE_CAPTURE && !current_io->mouse_captured) {
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
391 current_io->mouse_captured = 1;
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
392 render_relative_mouse(1);
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
393 return;
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
394 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
395 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
396 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
397 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
398 keybinding * binding = mice[mouse].buttons + button - 1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
399 handle_binding_down(binding);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
400 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
401
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
402 uint8_t ui_debug_mode = 0;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
403 uint8_t ui_debug_pal = 0;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
404
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
405 int current_speed = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
406 int num_speeds = 1;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
407 uint32_t * speeds = NULL;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
408
1256
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
409 uint8_t is_keyboard(io_port *port)
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
410 {
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
411 return port->device_type == IO_SATURN_KEYBOARD || port->device_type == IO_XBAND_KEYBOARD;
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
412 }
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
413
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
414 uint8_t keyboard_connected(sega_io *io)
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
415 {
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
416 return is_keyboard(io->ports) || is_keyboard(io->ports+1) || is_keyboard(io->ports+2);
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
417 }
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
418
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
419 #ifdef _WIN32
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
420 #define localtime_r(a,b) localtime(a)
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
421 #endif
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
422
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
423 void handle_binding_up(keybinding * binding)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
424 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
425 switch(binding->bind_type)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
426 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
427 case BIND_GAMEPAD1:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
428 case BIND_GAMEPAD2:
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
429 case BIND_GAMEPAD3:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
430 case BIND_GAMEPAD4:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
431 case BIND_GAMEPAD5:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
432 case BIND_GAMEPAD6:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
433 case BIND_GAMEPAD7:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
434 case BIND_GAMEPAD8:
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
435 if (binding->subtype_a <= GAMEPAD_EXTRA && binding->port) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
436 binding->port->input[binding->subtype_a] &= ~binding->value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
437 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
438 if (binding->subtype_b <= GAMEPAD_EXTRA && binding->port) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
439 binding->port->input[binding->subtype_b] &= ~binding->value;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
440 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
441 break;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
442 case BIND_MOUSE1:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
443 case BIND_MOUSE2:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
444 case BIND_MOUSE3:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
445 case BIND_MOUSE4:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
446 case BIND_MOUSE5:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
447 case BIND_MOUSE6:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
448 case BIND_MOUSE7:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
449 case BIND_MOUSE8:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
450 if (binding->port) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
451 binding->port->input[0] &= ~binding->value;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
452 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
453 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
454 case BIND_UI:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
455 switch (binding->subtype_a)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
456 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
457 case UI_DEBUG_MODE_INC:
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
458 current_system->inc_debug_mode(current_system);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
459 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
460 case UI_DEBUG_PAL_INC:
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
461 current_system->inc_debug_pal(current_system);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
462 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
463 case UI_ENTER_DEBUGGER:
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
464 current_system->enter_debugger = 1;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
465 break;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
466 case UI_SAVE_STATE:
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
467 current_system->save_state = QUICK_SAVE_SLOT+1;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
468 break;
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
469 case UI_NEXT_SPEED:
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
470 current_speed++;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
471 if (current_speed >= num_speeds) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
472 current_speed = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
473 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
474 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
475 current_system->set_speed_percent(current_system, speeds[current_speed]);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
476 break;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
477 case UI_PREV_SPEED:
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
478 current_speed--;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
479 if (current_speed < 0) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
480 current_speed = num_speeds - 1;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
481 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
482 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
483 current_system->set_speed_percent(current_system, speeds[current_speed]);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
484 break;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
485 case UI_SET_SPEED:
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
486 if (binding->value < num_speeds) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
487 current_speed = binding->value;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
488 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
489 current_system->set_speed_percent(current_system, speeds[current_speed]);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
490 } else {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
491 printf("Setting speed to %d\n", speeds[current_speed]);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
492 current_system->set_speed_percent(current_system, speeds[current_speed]);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
493 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
494 break;
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
495 case UI_RELEASE_MOUSE:
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
496 if (current_io->mouse_captured) {
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
497 current_io->mouse_captured = 0;
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
498 render_relative_mouse(0);
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
499 }
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
500 break;
1254
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
501 case UI_TOGGLE_KEYBOARD_CAPTURE:
1256
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
502 if (keyboard_connected(current_io)) {
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
503 current_io->keyboard_captured = !current_io->keyboard_captured;
ccf5c02610c6 Only allow keyboard capture if the emulated system has a keyboard attached
Michael Pavone <pavone@retrodev.com>
parents: 1254
diff changeset
504 }
1254
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
505 break;
1202
a6ae693974e0 Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents: 1197
diff changeset
506 case UI_TOGGLE_FULLSCREEN:
a6ae693974e0 Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents: 1197
diff changeset
507 render_toggle_fullscreen();
a6ae693974e0 Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents: 1197
diff changeset
508 break;
1208
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1207
diff changeset
509 case UI_SOFT_RESET:
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1207
diff changeset
510 current_system->soft_reset(current_system);
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1207
diff changeset
511 break;
1438
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1435
diff changeset
512 case UI_RELOAD:
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1435
diff changeset
513 reload_media();
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1435
diff changeset
514 break;
1377
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
515 case UI_SMS_PAUSE:
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
516 if (current_system->type == SYSTEM_SMS) {
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
517 sms_context *sms = (sms_context *)current_system;
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
518 vdp_pbc_pause(sms->vdp);
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
519 }
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
520 break;
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
521 case UI_SCREENSHOT: {
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
522 char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval;
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
523 if (!screenshot_base) {
1294
a719e2c98b54 Allow variables in screenshot_path like initial_path
Michael Pavone <pavone@retrodev.com>
parents: 1266
diff changeset
524 screenshot_base = "$HOME";
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
525 }
1294
a719e2c98b54 Allow variables in screenshot_path like initial_path
Michael Pavone <pavone@retrodev.com>
parents: 1266
diff changeset
526 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir());
a719e2c98b54 Allow variables in screenshot_path like initial_path
Michael Pavone <pavone@retrodev.com>
parents: 1266
diff changeset
527 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
a719e2c98b54 Allow variables in screenshot_path like initial_path
Michael Pavone <pavone@retrodev.com>
parents: 1266
diff changeset
528 screenshot_base = replace_vars(screenshot_base, vars, 1);
a719e2c98b54 Allow variables in screenshot_path like initial_path
Michael Pavone <pavone@retrodev.com>
parents: 1266
diff changeset
529 tern_free(vars);
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
530 time_t now = time(NULL);
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
531 struct tm local_store;
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
532 char fname_part[256];
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
533 char *template = tern_find_path(config, "ui\0screenshot_template\0", TVAL_PTR).ptrval;
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
534 if (!template) {
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
535 template = "blastem_%c.ppm";
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
536 }
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
537 strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store));
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
538 char const *parts[] = {screenshot_base, PATH_SEP, fname_part};
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
539 char *path = alloc_concat_m(3, parts);
1294
a719e2c98b54 Allow variables in screenshot_path like initial_path
Michael Pavone <pavone@retrodev.com>
parents: 1266
diff changeset
540 free(screenshot_base);
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
541 render_save_screenshot(path);
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
542 break;
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
543 }
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
544 case UI_EXIT:
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
545 #ifndef DISABLE_NUKLEAR
1483
001120e91fed Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
546 if (is_nuklear_active()) {
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
547 show_pause_menu();
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
548 } else {
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
549 #endif
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
550 current_system->request_exit(current_system);
1435
178de1432291 Using ui.exit to abort loading or saving a state via menu will no longer cause you to return to those sub-menus the next time the menu is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1427
diff changeset
551 if (current_system->type == SYSTEM_GENESIS) {
178de1432291 Using ui.exit to abort loading or saving a state via menu will no longer cause you to return to those sub-menus the next time the menu is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1427
diff changeset
552 genesis_context *gen = (genesis_context *)current_system;
178de1432291 Using ui.exit to abort loading or saving a state via menu will no longer cause you to return to those sub-menus the next time the menu is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1427
diff changeset
553 if (gen->extra) {
178de1432291 Using ui.exit to abort loading or saving a state via menu will no longer cause you to return to those sub-menus the next time the menu is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1427
diff changeset
554 //TODO: More robust mechanism for detecting menu
178de1432291 Using ui.exit to abort loading or saving a state via menu will no longer cause you to return to those sub-menus the next time the menu is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1427
diff changeset
555 menu_context *menu = gen->extra;
178de1432291 Using ui.exit to abort loading or saving a state via menu will no longer cause you to return to those sub-menus the next time the menu is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1427
diff changeset
556 menu->external_game_load = 1;
178de1432291 Using ui.exit to abort loading or saving a state via menu will no longer cause you to return to those sub-menus the next time the menu is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1427
diff changeset
557 }
178de1432291 Using ui.exit to abort loading or saving a state via menu will no longer cause you to return to those sub-menus the next time the menu is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1427
diff changeset
558 }
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
559 #ifndef DISABLE_NUKLEAR
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
560 }
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1453
diff changeset
561 #endif
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
562 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
563 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
564 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
565 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
566 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
567
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
568 void handle_keyup(int keycode, uint8_t scancode)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
569 {
1488
f29bd94ffa76 Don't crash when keys are pressed before ROM is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
570 if (!current_io) {
f29bd94ffa76 Don't crash when keys are pressed before ROM is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
571 return;
f29bd94ffa76 Don't crash when keys are pressed before ROM is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
572 }
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
573 int bucket = keycode >> 15 & 0xFFFF;
1254
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
574 int idx = keycode & 0x7FFF;
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
575 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL;
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
576 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) {
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
577 handle_binding_up(binding);
1266
a4fa897c99ce Don't allow the keyboard capture key to get passed to the emulated keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1263
diff changeset
578 } else if (current_io->keyboard_captured) {
1254
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
579 store_key_event(0xF000 | scancode);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
580 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
581 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
582
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
583 void handle_joyup(int joystick, int button)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
584 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
585 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
586 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
587 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
588 keybinding * binding = joysticks[joystick].buttons + button;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
589 handle_binding_up(binding);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
590 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
591
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
592 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
593 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
594 if (joystick >= MAX_JOYSTICKS || dpadnum >= joysticks[joystick].num_dpads) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
595 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
596 }
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
597 joydpad * dpad = joysticks[joystick].dpads + dpadnum;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
598 uint8_t newdown = (value ^ dpad->state) & value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
599 uint8_t newup = ((~value) ^ (~dpad->state)) & (~value);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
600 dpad->state = value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
601 for (int i = 0; i < 4; i++) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
602 if (newdown & dpadbits[i]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
603 handle_binding_down(dpad->bindings + i);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
604 } else if(newup & dpadbits[i]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
605 handle_binding_up(dpad->bindings + i);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
606 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
607 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
608 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
609
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
610 #define JOY_AXIS_THRESHOLD 2000
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
611
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
612 void handle_joy_axis(int joystick, int axis, int16_t value)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
613 {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
614 if (joystick >= MAX_JOYSTICKS || axis >= joysticks[joystick].num_axes) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
615 return;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
616 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
617 joyaxis *jaxis = joysticks[joystick].axes + axis;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
618 int old_active = abs(jaxis->value) > JOY_AXIS_THRESHOLD;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
619 int new_active = abs(value) > JOY_AXIS_THRESHOLD;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
620 int old_pos = jaxis->value > 0;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
621 int new_pos = value > 0;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
622 jaxis->value = value;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
623 if (old_active && (!new_active || old_pos != new_pos)) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
624 //previously activated direction is no longer active
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
625 handle_binding_up(old_pos ? &jaxis->positive : &jaxis->negative);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
626 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
627 if (new_active && (!old_active || old_pos != new_pos)) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
628 //previously unactivated direction is now active
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
629 handle_binding_down(new_pos ? &jaxis->positive : &jaxis->negative);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
630 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
631 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
632
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
633 void handle_mouseup(int mouse, int button)
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
634 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
635 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
636 return;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
637 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
638 keybinding * binding = mice[mouse].buttons + button - 1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
639 handle_binding_up(binding);
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
640 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
641
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
642 void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16_t deltay)
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
643 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
644 if (mouse >= MAX_MICE || !mice[mouse].motion_port) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
645 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
646 }
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
647 switch(current_io->mouse_mode)
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
648 {
1396
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
649 case MOUSE_NONE:
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
650 break;
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
651 case MOUSE_ABSOLUTE: {
1398
08116cb5ffaa Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents: 1396
diff changeset
652 float scale_x = (render_emulated_width() * 2.0f) / ((float)render_width());
08116cb5ffaa Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents: 1396
diff changeset
653 float scale_y = (render_emulated_height() * 2.0f) / ((float)render_height());
08116cb5ffaa Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents: 1396
diff changeset
654 int32_t adj_x = x * scale_x + 2 * render_overscan_left() - 2 * BORDER_LEFT;
08116cb5ffaa Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents: 1396
diff changeset
655 int32_t adj_y = y * scale_y + 2 * render_overscan_top() - 4;
08116cb5ffaa Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents: 1396
diff changeset
656 if (adj_x >= 0 && adj_y >= 0) {
08116cb5ffaa Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents: 1396
diff changeset
657 mice[mouse].motion_port->device.mouse.cur_x = adj_x;
08116cb5ffaa Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents: 1396
diff changeset
658 mice[mouse].motion_port->device.mouse.cur_y = adj_y;
08116cb5ffaa Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents: 1396
diff changeset
659 }
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
660 break;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
661 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
662 case MOUSE_RELATIVE: {
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
663 mice[mouse].motion_port->device.mouse.cur_x += deltax;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
664 mice[mouse].motion_port->device.mouse.cur_y += deltay;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
665 break;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
666 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
667 case MOUSE_CAPTURE: {
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
668 if (current_io->mouse_captured) {
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
669 mice[mouse].motion_port->device.mouse.cur_x += deltax;
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
670 mice[mouse].motion_port->device.mouse.cur_y += deltay;
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
671 }
1197
9bc78bd89567 Minor cleanup to handle_mouse_moved
Michael Pavone <pavone@retrodev.com>
parents: 1194
diff changeset
672 break;
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
673 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
674 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
675 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
676
1576
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
677 void io_release_capture(sega_io *io)
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
678 {
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
679 if (io->mouse_mode == MOUSE_RELATIVE || (io->mouse_mode == MOUSE_CAPTURE && io->mouse_captured)) {
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
680 render_relative_mouse(0);
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
681 }
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
682 current_io->keyboard_captured = 0;
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
683 }
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
684
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
685 void io_reacquire_capture(sega_io *io)
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
686 {
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
687 if (io->mouse_mode == MOUSE_RELATIVE || (io->mouse_mode == MOUSE_CAPTURE && io->mouse_captured)) {
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
688 render_relative_mouse(1);
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
689 }
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
690 }
2b132d894d76 Release capture of mouse and keyboard when entering UI
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
691
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
692 int parse_binding_target(char * target, tern_node * padbuttons, tern_node *mousebuttons, int * ui_out, int * padnum_out, int * padbutton_out)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
693 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
694 const int gpadslen = strlen("gamepads.");
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
695 const int mouselen = strlen("mouse.");
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 771
diff changeset
696 if (!strncmp(target, "gamepads.", gpadslen)) {
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
697 if (target[gpadslen] >= '1' && target[gpadslen] <= '8') {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
698 int padnum = target[gpadslen] - '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
699 int button = tern_find_int(padbuttons, target + gpadslen + 1, 0);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
700 if (button) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
701 *padnum_out = padnum;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
702 *padbutton_out = button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
703 return BIND_GAMEPAD1;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
704 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
705 if (target[gpadslen+1]) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
706 warning("Gamepad mapping string '%s' refers to an invalid button '%s'\n", target, target + gpadslen + 1);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
707 } else {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
708 warning("Gamepad mapping string '%s' has no button component\n", target);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
709 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
710 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
711 } else {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
712 warning("Gamepad mapping string '%s' refers to an invalid gamepad number %c\n", target, target[gpadslen]);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
713 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
714 } else if(!strncmp(target, "mouse.", mouselen)) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
715 if (target[mouselen] >= '1' && target[mouselen] <= '8') {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
716 int mousenum = target[mouselen] - '0';
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
717 int button = tern_find_int(mousebuttons, target + mouselen + 1, 0);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
718 if (button) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
719 *padnum_out = mousenum;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
720 *padbutton_out = button;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
721 return BIND_MOUSE1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
722 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
723 if (target[mouselen+1]) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
724 warning("Mouse mapping string '%s' refers to an invalid button '%s'\n", target, target + mouselen + 1);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
725 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
726 warning("Mouse mapping string '%s' has no button component\n", target);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
727 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
728 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
729 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
730 warning("Gamepad mapping string '%s' refers to an invalid mouse number %c\n", target, target[mouselen]);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
731 }
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 771
diff changeset
732 } else if(!strncmp(target, "ui.", strlen("ui."))) {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
733 *padbutton_out = 0;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
734 if (!strcmp(target + 3, "vdp_debug_mode")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
735 *ui_out = UI_DEBUG_MODE_INC;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
736 } else if(!strcmp(target + 3, "vdp_debug_pal")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
737 *ui_out = UI_DEBUG_PAL_INC;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
738 } else if(!strcmp(target + 3, "enter_debugger")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
739 *ui_out = UI_ENTER_DEBUGGER;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
740 } else if(!strcmp(target + 3, "save_state")) {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
741 *ui_out = UI_SAVE_STATE;
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 771
diff changeset
742 } else if(!strncmp(target + 3, "set_speed.", strlen("set_speed."))) {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
743 *ui_out = UI_SET_SPEED;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
744 *padbutton_out = atoi(target + 3 + strlen("set_speed."));
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
745 } else if(!strcmp(target + 3, "next_speed")) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
746 *ui_out = UI_NEXT_SPEED;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
747 } else if(!strcmp(target + 3, "prev_speed")) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
748 *ui_out = UI_PREV_SPEED;
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
749 } else if(!strcmp(target + 3, "release_mouse")) {
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
750 *ui_out = UI_RELEASE_MOUSE;
1254
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
751 } else if(!strcmp(target + 3, "toggle_keyboard_captured")) {
d966298442d4 Implement keyboard capture functionality
Michael Pavone <pavone@retrodev.com>
parents: 1232
diff changeset
752 *ui_out = UI_TOGGLE_KEYBOARD_CAPTURE;
1202
a6ae693974e0 Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents: 1197
diff changeset
753 } else if (!strcmp(target + 3, "toggle_fullscreen")) {
a6ae693974e0 Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents: 1197
diff changeset
754 *ui_out = UI_TOGGLE_FULLSCREEN;
1208
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1207
diff changeset
755 } else if (!strcmp(target + 3, "soft_reset")) {
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1207
diff changeset
756 *ui_out = UI_SOFT_RESET;
1438
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1435
diff changeset
757 } else if (!strcmp(target + 3, "reload")) {
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1435
diff changeset
758 *ui_out = UI_RELOAD;
1377
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
759 } else if (!strcmp(target + 3, "sms_pause")) {
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1348
diff changeset
760 *ui_out = UI_SMS_PAUSE;
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
761 } else if (!strcmp(target + 3, "screenshot")) {
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents: 1257
diff changeset
762 *ui_out = UI_SCREENSHOT;
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
763 } else if(!strcmp(target + 3, "exit")) {
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
764 *ui_out = UI_EXIT;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
765 } else {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
766 warning("Unreconized UI binding type %s\n", target);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
767 return 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
768 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
769 return BIND_UI;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
770 } else {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
771 warning("Unrecognized binding type %s\n", target);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
772 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
773 return 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
774 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
775
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
776 void process_keys(tern_node * cur, tern_node * special, tern_node * padbuttons, tern_node *mousebuttons, char * prefix)
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
777 {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
778 char * curstr = NULL;
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
779 int len;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
780 if (!cur) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
781 return;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
782 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
783 char onec[2];
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
784 if (prefix) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
785 len = strlen(prefix);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
786 curstr = malloc(len + 2);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
787 memcpy(curstr, prefix, len);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
788 } else {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
789 curstr = onec;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
790 len = 0;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
791 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
792 curstr[len] = cur->el;
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
793 curstr[len+1] = 0;
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
794 if (cur->el) {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
795 process_keys(cur->straight.next, special, padbuttons, mousebuttons, curstr);
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
796 } else {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
797 int keycode = tern_find_int(special, curstr, 0);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
798 if (!keycode) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
799 keycode = curstr[0];
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
800 if (curstr[1] != 0) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
801 warning("%s is not recognized as a key identifier, truncating to %c\n", curstr, curstr[0]);
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
802 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
803 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
804 char * target = cur->straight.value.ptrval;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
805 int ui_func, padnum, button;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
806 int bindtype = parse_binding_target(target, padbuttons, mousebuttons, &ui_func, &padnum, &button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
807 if (bindtype == BIND_GAMEPAD1) {
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
808 bind_gamepad(keycode, padnum, button);
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
809 } else if(bindtype == BIND_UI) {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
810 bind_ui(keycode, ui_func, button);
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
811 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
812 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
813 process_keys(cur->left, special, padbuttons, mousebuttons, prefix);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
814 process_keys(cur->right, special, padbuttons, mousebuttons, prefix);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
815 if (curstr && len) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
816 free(curstr);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
817 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
818 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
819
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
820 void process_speeds(tern_node * cur, char * prefix)
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
821 {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
822 char * curstr = NULL;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
823 int len;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
824 if (!cur) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
825 return;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
826 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
827 char onec[2];
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
828 if (prefix) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
829 len = strlen(prefix);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
830 curstr = malloc(len + 2);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
831 memcpy(curstr, prefix, len);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
832 } else {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
833 curstr = onec;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
834 len = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
835 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
836 curstr[len] = cur->el;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
837 curstr[len+1] = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
838 if (cur->el) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
839 process_speeds(cur->straight.next, curstr);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
840 } else {
1005
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
841 char *end;
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
842 long speed_index = strtol(curstr, &end, 10);
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
843 if (speed_index < 0 || end == curstr || *end) {
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
844 warning("%s is not a valid speed index", curstr);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
845 } else {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
846 if (speed_index >= num_speeds) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
847 speeds = realloc(speeds, sizeof(uint32_t) * (speed_index+1));
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
848 for(; num_speeds < speed_index + 1; num_speeds++) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
849 speeds[num_speeds] = 0;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
850 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
851 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
852 speeds[speed_index] = atoi(cur->straight.value.ptrval);
1005
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
853 if (speeds[speed_index] < 1) {
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
854 warning("%s is not a valid speed percentage, setting speed %d to 100", cur->straight.value.ptrval, speed_index);
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
855 speeds[speed_index] = 100;
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
856 }
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
857 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
858 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
859 process_speeds(cur->left, prefix);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
860 process_speeds(cur->right, prefix);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
861 if (curstr && len) {
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
862 free(curstr);
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
863 }
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
864 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
865
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
866 void process_device(char * device_type, io_port * port)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
867 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
868 port->device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
869 if (!device_type)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
870 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
871 return;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
872 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
873
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
874 const int gamepad_len = strlen("gamepad");
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
875 const int mouse_len = strlen("mouse");
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
876 if (!strncmp(device_type, "gamepad", gamepad_len))
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
877 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
878 if (
1146
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
879 (device_type[gamepad_len] != '3' && device_type[gamepad_len] != '6' && device_type[gamepad_len] != '2')
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
880 || device_type[gamepad_len+1] != '.' || device_type[gamepad_len+2] < '1'
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
881 || device_type[gamepad_len+2] > '8' || device_type[gamepad_len+3] != 0
1146
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
882 ) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
883 warning("%s is not a valid gamepad type\n", device_type);
1146
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
884 } else if (device_type[gamepad_len] == '3') {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
885 port->device_type = IO_GAMEPAD3;
1146
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
886 } else if (device_type[gamepad_len] == '2') {
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
887 port->device_type = IO_GAMEPAD2;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
888 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
889 port->device_type = IO_GAMEPAD6;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
890 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
891 port->device.pad.gamepad_num = device_type[gamepad_len+2] - '1';
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
892 } else if(!strncmp(device_type, "mouse", mouse_len)) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
893 port->device_type = IO_MOUSE;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
894 port->device.mouse.mouse_num = device_type[mouse_len+1] - '1';
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
895 port->device.mouse.last_read_x = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
896 port->device.mouse.last_read_y = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
897 port->device.mouse.cur_x = 0;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
898 port->device.mouse.cur_y = 0;
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
899 port->device.mouse.latched_x = 0;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
900 port->device.mouse.latched_y = 0;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
901 port->device.mouse.ready_cycle = CYCLE_NEVER;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
902 port->device.mouse.tr_counter = 0;
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
903 } else if(!strcmp(device_type, "saturn keyboard")) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
904 port->device_type = IO_SATURN_KEYBOARD;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
905 port->device.keyboard.read_pos = 0xFF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
906 port->device.keyboard.write_pos = 0;
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
907 } else if(!strcmp(device_type, "xband keyboard")) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
908 port->device_type = IO_XBAND_KEYBOARD;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
909 port->device.keyboard.read_pos = 0xFF;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
910 port->device.keyboard.write_pos = 0;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
911 } else if(!strcmp(device_type, "sega_parallel")) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
912 port->device_type = IO_SEGA_PARALLEL;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
913 port->device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
914 port->device.stream.listen_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
915 } else if(!strcmp(device_type, "generic")) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
916 port->device_type = IO_GENERIC;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
917 port->device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
918 port->device.stream.listen_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
919 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
920 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
921
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
922 char * io_name(int i)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
923 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
924 switch (i)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
925 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
926 case 0:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
927 return "1";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
928 case 1:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
929 return "2";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
930 case 2:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
931 return "EXT";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
932 default:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
933 return "invalid";
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
934 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
935 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
936
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
937 static char * sockfile_name;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
938 static void cleanup_sockfile()
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
939 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
940 unlink(sockfile_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
941 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
942
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
943 void setup_io_devices(tern_node * config, rom_info *rom, sega_io *io)
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
944 {
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
945 current_io = io;
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
946 io_port * ports = current_io->ports;
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
947 tern_node *io_nodes = tern_find_path(config, "io\0devices\0", TVAL_NODE).ptrval;
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
948 char * io_1 = rom->port1_override ? rom->port1_override : io_nodes ? tern_find_ptr(io_nodes, "1") : NULL;
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
949 char * io_2 = rom->port2_override ? rom->port2_override : io_nodes ? tern_find_ptr(io_nodes, "2") : NULL;
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
950 char * io_ext = rom->ext_override ? rom->ext_override : io_nodes ? tern_find_ptr(io_nodes, "ext") : NULL;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
951
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
952 process_device(io_1, ports);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
953 process_device(io_2, ports+1);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
954 process_device(io_ext, ports+2);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
955
1396
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
956 if (ports[0].device_type == IO_MOUSE || ports[1].device_type == IO_MOUSE || ports[2].device_type == IO_MOUSE) {
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
957 if (render_fullscreen()) {
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
958 current_io->mouse_mode = MOUSE_RELATIVE;
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
959 render_relative_mouse(1);
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
960 } else {
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
961 if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) {
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
962 current_io->mouse_mode = MOUSE_ABSOLUTE;
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
963 } else {
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
964 current_io->mouse_mode = MOUSE_CAPTURE;
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
965 }
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
966 }
916
20c464dbae8f Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
967 } else {
1396
aca496957999 Only capture mouse if an emulated mouse is attached
Michael Pavone <pavone@retrodev.com>
parents: 1379
diff changeset
968 current_io->mouse_mode = MOUSE_NONE;
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
969 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
970
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
971 for (int i = 0; i < 3; i++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
972 {
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
973 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
974 if (ports[i].device_type == IO_SEGA_PARALLEL)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
975 {
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
976 char *pipe_name = tern_find_path(config, "io\0parallel_pipe\0", TVAL_PTR).ptrval;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
977 if (!pipe_name)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
978 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
979 warning("IO port %s is configured to use the sega parallel board, but no paralell_pipe is set!\n", io_name(i));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
980 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
981 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
982 printf("IO port: %s connected to device '%s' with pipe name: %s\n", io_name(i), device_type_names[ports[i].device_type], pipe_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
983 if (!strcmp("stdin", pipe_name))
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
984 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
985 ports[i].device.stream.data_fd = STDIN_FILENO;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
986 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
987 if (mkfifo(pipe_name, 0666) && errno != EEXIST)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
988 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
989 warning("Failed to create fifo %s for Sega parallel board emulation: %d %s\n", pipe_name, errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
990 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
991 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
992 ports[i].device.stream.data_fd = open(pipe_name, O_NONBLOCK | O_RDONLY);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
993 if (ports[i].device.stream.data_fd == -1)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
994 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
995 warning("Failed to open fifo %s for Sega parallel board emulation: %d %s\n", pipe_name, errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
996 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
997 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
998 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
999 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1000 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1001 } else if (ports[i].device_type == IO_GENERIC) {
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1002 char *sock_name = tern_find_path(config, "io\0socket\0", TVAL_PTR).ptrval;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1003 if (!sock_name)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1004 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1005 warning("IO port %s is configured to use generic IO, but no socket is set!\n", io_name(i));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1006 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1007 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1008 printf("IO port: %s connected to device '%s' with socket name: %s\n", io_name(i), device_type_names[ports[i].device_type], sock_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1009 ports[i].device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1010 ports[i].device.stream.listen_fd = socket(AF_UNIX, SOCK_STREAM, 0);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1011 size_t pathlen = strlen(sock_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1012 size_t addrlen = offsetof(struct sockaddr_un, sun_path) + pathlen + 1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1013 struct sockaddr_un *saddr = malloc(addrlen);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1014 saddr->sun_family = AF_UNIX;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1015 memcpy(saddr->sun_path, sock_name, pathlen+1);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1016 if (bind(ports[i].device.stream.listen_fd, (struct sockaddr *)saddr, addrlen))
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1017 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1018 warning("Failed to bind socket for IO Port %s to path %s: %d %s\n", io_name(i), sock_name, errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1019 goto cleanup_sock;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1020 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1021 if (listen(ports[i].device.stream.listen_fd, 1))
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1022 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1023 warning("Failed to listen on socket for IO Port %s: %d %s\n", io_name(i), errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1024 goto cleanup_sockfile;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1025 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1026 sockfile_name = sock_name;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1027 atexit(cleanup_sockfile);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1028 continue;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1029 cleanup_sockfile:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1030 unlink(sock_name);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1031 cleanup_sock:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1032 close(ports[i].device.stream.listen_fd);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1033 ports[i].device_type = IO_NONE;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1034 }
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 796
diff changeset
1035 } else
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1036 #endif
1146
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
1037 if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6 || ports[i].device_type == IO_GAMEPAD2) {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1038 printf("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num + 1, device_type_names[ports[i].device_type]);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1039 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1040 printf("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1041 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1042 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1043 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1044
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1045 void map_bindings(io_port *ports, keybinding *bindings, int numbindings)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1046 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1047 for (int i = 0; i < numbindings; i++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1048 {
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1049 if (bindings[i].bind_type >= BIND_GAMEPAD1 && bindings[i].bind_type <= BIND_GAMEPAD8)
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1050 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1051 int num = bindings[i].bind_type - BIND_GAMEPAD1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1052 for (int j = 0; j < 3; j++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1053 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1054 if ((ports[j].device_type == IO_GAMEPAD3
1146
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
1055 || ports[j].device_type == IO_GAMEPAD6
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
1056 || ports[j].device_type == IO_GAMEPAD2)
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1057 && ports[j].device.pad.gamepad_num == num
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1058 )
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1059 {
886
fb1f11fd0692 Clear out IO port input state when setting bindings. This fixes a bug where pressing start in the menu after returning to it only worked on the second try.
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
1060 memset(ports[j].input, 0, sizeof(ports[j].input));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1061 bindings[i].port = ports + j;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1062 break;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1063 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1064 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1065 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1066 else if (bindings[i].bind_type >= BIND_MOUSE1 && bindings[i].bind_type <= BIND_MOUSE8)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1067 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1068 int num = bindings[i].bind_type - BIND_MOUSE1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1069 for (int j = 0; j < 3; j++)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1070 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1071 if (ports[j].device_type == IO_MOUSE && ports[j].device.mouse.mouse_num == num)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1072 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1073 memset(ports[j].input, 0, sizeof(ports[j].input));
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1074 bindings[i].port = ports + j;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1075 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1076 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1077 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1078 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1079 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1080 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1081
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1082 typedef struct {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1083 tern_node *padbuttons;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1084 tern_node *mousebuttons;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1085 int mouseidx;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1086 } pmb_state;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1087
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1088 void process_mouse_button(char *buttonstr, tern_val value, uint8_t valtype, void *data)
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1089 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1090 pmb_state *state = data;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1091 int buttonnum = atoi(buttonstr);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1092 if (buttonnum < 1 || buttonnum > MAX_MOUSE_BUTTONS) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1093 warning("Mouse button %s is out of the supported range of 1-8\n", buttonstr);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1094 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1095 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1096 if (valtype != TVAL_PTR) {
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1097 warning("Mouse button %s is not a scalar value!\n", buttonstr);
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1098 return;
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1099 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1100 buttonnum--;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1101 int ui_func, devicenum, button;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1102 int bindtype = parse_binding_target(value.ptrval, state->padbuttons, state->mousebuttons, &ui_func, &devicenum, &button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1103 switch (bindtype)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1104 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1105 case BIND_UI:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1106 mice[state->mouseidx].buttons[buttonnum].subtype_a = ui_func;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1107 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1108 case BIND_GAMEPAD1:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1109 mice[state->mouseidx].buttons[buttonnum].subtype_a = button >> 12;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1110 mice[state->mouseidx].buttons[buttonnum].subtype_b = button >> 8 & 0xF;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1111 mice[state->mouseidx].buttons[buttonnum].value = button & 0xFF;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1112 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1113 case BIND_MOUSE1:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1114 mice[state->mouseidx].buttons[buttonnum].value = button & 0xFF;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1115 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1116 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1117 if (bindtype != BIND_UI) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1118 bindtype += devicenum-1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1119 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1120 mice[state->mouseidx].buttons[buttonnum].bind_type = bindtype;
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
1121
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1122 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1123
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1124 void process_mouse(char *mousenum, tern_val value, uint8_t valtype, void *data)
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1125 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1126 tern_node **buttonmaps = data;
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1127 if (valtype != TVAL_NODE) {
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1128 warning("Binding for mouse %s is a scalar!\n", mousenum);
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1129 return;
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1130 }
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1131 tern_node *mousedef = value.ptrval;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1132 tern_node *padbuttons = buttonmaps[0];
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1133 tern_node *mousebuttons = buttonmaps[1];
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
1134
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1135 int mouseidx = atoi(mousenum);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1136 if (mouseidx < 0 || mouseidx >= MAX_MICE) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1137 warning("Mouse numbers must be between 0 and %d, but %d is not\n", MAX_MICE, mouseidx);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1138 return;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1139 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1140 char *motion = tern_find_ptr(mousedef, "motion");
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1141 if (motion) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1142 int ui_func,devicenum,button;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1143 int bindtype = parse_binding_target(motion, padbuttons, mousebuttons, &ui_func, &devicenum, &button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1144 if (bindtype != BIND_UI) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1145 bindtype += devicenum-1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1146 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1147 if (button == PSEUDO_BUTTON_MOTION) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1148 mice[mouseidx].bind_type = bindtype;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1149 } else {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1150 warning("Mouse motion can't be bound to target %s\n", motion);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1151 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1152 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1153 tern_node *buttons = tern_find_path(mousedef, "buttons\0\0", TVAL_NODE).ptrval;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1154 if (buttons) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1155 pmb_state state = {padbuttons, mousebuttons, mouseidx};
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1156 tern_foreach(buttons, process_mouse_button, &state);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1157 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1158 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1159
1187
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1160 typedef struct {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1161 int padnum;
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1162 tern_node *padbuttons;
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1163 tern_node *mousebuttons;
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1164 } pad_button_state;
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1165
1400
6a0e3bb6981f Only complain about the first missing mapping for a given gamepad so a user does not get inundated with warning modals when their gamepad lacks a mapping entry
Michael Pavone <pavone@retrodev.com>
parents: 1398
diff changeset
1166
6a0e3bb6981f Only complain about the first missing mapping for a given gamepad so a user does not get inundated with warning modals when their gamepad lacks a mapping entry
Michael Pavone <pavone@retrodev.com>
parents: 1398
diff changeset
1167 static long map_warning_pad = -1;
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1168 void process_pad_button(char *key, tern_val val, uint8_t valtype, void *data)
1187
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1169 {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1170 pad_button_state *state = data;
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1171 int hostpadnum = state->padnum;
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1172 int ui_func, padnum, button;
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1173 if (valtype != TVAL_PTR) {
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1174 warning("Pad button %s has a non-scalar value\n", key);
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1175 return;
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1176 }
1187
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1177 int bindtype = parse_binding_target(val.ptrval, state->padbuttons, state->mousebuttons, &ui_func, &padnum, &button);
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1178 char *end;
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1179 long hostbutton = strtol(key, &end, 10);
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1180 if (*end) {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1181 //key is not a valid base 10 integer
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1182 hostbutton = render_translate_input_name(hostpadnum, key, 0);
1187
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1183 if (hostbutton < 0) {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1184 if (hostbutton == RENDER_INVALID_NAME) {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1185 warning("%s is not a valid gamepad input name\n", key);
1400
6a0e3bb6981f Only complain about the first missing mapping for a given gamepad so a user does not get inundated with warning modals when their gamepad lacks a mapping entry
Michael Pavone <pavone@retrodev.com>
parents: 1398
diff changeset
1186 } else if (hostbutton == RENDER_NOT_MAPPED && hostpadnum != map_warning_pad) {
6a0e3bb6981f Only complain about the first missing mapping for a given gamepad so a user does not get inundated with warning modals when their gamepad lacks a mapping entry
Michael Pavone <pavone@retrodev.com>
parents: 1398
diff changeset
1187 warning("No SDL 2 mapping exists for input %s on gamepad %d\n", key, hostpadnum);
6a0e3bb6981f Only complain about the first missing mapping for a given gamepad so a user does not get inundated with warning modals when their gamepad lacks a mapping entry
Michael Pavone <pavone@retrodev.com>
parents: 1398
diff changeset
1188 map_warning_pad = hostpadnum;
1187
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1189 }
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1190 return;
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1191 }
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1192 if (hostbutton & RENDER_DPAD_BIT) {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1193 if (bindtype == BIND_GAMEPAD1) {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1194 bind_dpad_gamepad(hostpadnum, render_dpad_part(hostbutton), render_direction_part(hostbutton), padnum, button);
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1195 } else {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1196 bind_dpad_ui(hostpadnum, render_dpad_part(hostbutton), render_direction_part(hostbutton), ui_func, button);
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1197 }
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1198 return;
1187
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1199 } else if (hostbutton & RENDER_AXIS_BIT) {
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1200 if (bindtype == BIND_GAMEPAD1) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1201 bind_axis_gamepad(hostpadnum, render_axis_part(hostbutton), 1, padnum, button);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1202 } else {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1203 bind_axis_ui(hostpadnum, render_axis_part(hostbutton), 1, padnum, button);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1204 }
1187
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1205 return;
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1206 }
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1207 }
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1208 if (bindtype == BIND_GAMEPAD1) {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1209 bind_button_gamepad(hostpadnum, hostbutton, padnum, button);
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1210 } else if (bindtype == BIND_UI) {
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1211 bind_button_ui(hostpadnum, hostbutton, ui_func, button);
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1212 }
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1213 }
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1214
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1215 void process_pad_axis(char *key, tern_val val, uint8_t valtype, void *data)
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1216 {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1217 key = strdup(key);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1218 pad_button_state *state = data;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1219 int hostpadnum = state->padnum;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1220 int ui_func, padnum, button;
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1221 if (valtype != TVAL_PTR) {
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1222 warning("Mapping for axis %s has a non-scalar value", key);
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1223 return;
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1224 }
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1225 int bindtype = parse_binding_target(val.ptrval, state->padbuttons, state->mousebuttons, &ui_func, &padnum, &button);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1226 char *modifier = strchr(key, '.');
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1227 int positive = 1;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1228 if (modifier) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1229 *modifier = 0;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1230 modifier++;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1231 if (!strcmp("negative", modifier)) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1232 positive = 0;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1233 } else if(strcmp("positive", modifier)) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1234 warning("Invalid axis modifier %s for axis %s on pad %d\n", modifier, key, hostpadnum);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1235 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1236 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1237 char *end;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1238 long axis = strtol(key, &end, 10);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1239 if (*end) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1240 //key is not a valid base 10 integer
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1241 axis = render_translate_input_name(hostpadnum, key, 1);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1242 if (axis < 0) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1243 if (axis == RENDER_INVALID_NAME) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1244 warning("%s is not a valid gamepad input name\n", key);
1400
6a0e3bb6981f Only complain about the first missing mapping for a given gamepad so a user does not get inundated with warning modals when their gamepad lacks a mapping entry
Michael Pavone <pavone@retrodev.com>
parents: 1398
diff changeset
1245 } else if (axis == RENDER_NOT_MAPPED && hostpadnum != map_warning_pad) {
6a0e3bb6981f Only complain about the first missing mapping for a given gamepad so a user does not get inundated with warning modals when their gamepad lacks a mapping entry
Michael Pavone <pavone@retrodev.com>
parents: 1398
diff changeset
1246 warning("No SDL 2 mapping exists for input %s on gamepad %d\n", key, hostpadnum);
6a0e3bb6981f Only complain about the first missing mapping for a given gamepad so a user does not get inundated with warning modals when their gamepad lacks a mapping entry
Michael Pavone <pavone@retrodev.com>
parents: 1398
diff changeset
1247 map_warning_pad = hostpadnum;
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1248 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1249 goto done;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1250 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1251 if (axis & RENDER_DPAD_BIT) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1252 if (bindtype == BIND_GAMEPAD1) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1253 bind_dpad_gamepad(hostpadnum, render_dpad_part(axis), render_direction_part(axis), padnum, button);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1254 } else {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1255 bind_dpad_ui(hostpadnum, render_dpad_part(axis), render_direction_part(axis), ui_func, button);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1256 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1257 goto done;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1258 } else if (axis & RENDER_AXIS_BIT) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1259 axis = render_axis_part(axis);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1260 } else {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1261 if (bindtype == BIND_GAMEPAD1) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1262 bind_button_gamepad(hostpadnum, axis, padnum, button);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1263 } else if (bindtype == BIND_UI) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1264 bind_button_ui(hostpadnum, axis, ui_func, button);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1265 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1266 goto done;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1267 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1268 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1269 if (bindtype == BIND_GAMEPAD1) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1270 bind_axis_gamepad(hostpadnum, axis, positive, padnum, button);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1271 } else {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1272 bind_axis_ui(hostpadnum, axis, positive, ui_func, button);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1273 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1274 done:
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1275 free(key);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1276 return;
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1277 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1278
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1279 static tern_node *get_pad_buttons()
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1280 {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1281 static tern_node *padbuttons;
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1282 if (!padbuttons) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1283 padbuttons = tern_insert_int(NULL, ".up", DPAD_UP);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1284 padbuttons = tern_insert_int(padbuttons, ".down", DPAD_DOWN);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1285 padbuttons = tern_insert_int(padbuttons, ".left", DPAD_LEFT);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1286 padbuttons = tern_insert_int(padbuttons, ".right", DPAD_RIGHT);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1287 padbuttons = tern_insert_int(padbuttons, ".a", BUTTON_A);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1288 padbuttons = tern_insert_int(padbuttons, ".b", BUTTON_B);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1289 padbuttons = tern_insert_int(padbuttons, ".c", BUTTON_C);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1290 padbuttons = tern_insert_int(padbuttons, ".x", BUTTON_X);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1291 padbuttons = tern_insert_int(padbuttons, ".y", BUTTON_Y);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1292 padbuttons = tern_insert_int(padbuttons, ".z", BUTTON_Z);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1293 padbuttons = tern_insert_int(padbuttons, ".start", BUTTON_START);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1294 padbuttons = tern_insert_int(padbuttons, ".mode", BUTTON_MODE);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1295 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1296 return padbuttons;
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1297 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1298
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1299 static tern_node *get_mouse_buttons()
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1300 {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1301 static tern_node *mousebuttons;
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1302 if (!mousebuttons) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1303 mousebuttons = tern_insert_int(NULL, ".left", MOUSE_LEFT);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1304 mousebuttons = tern_insert_int(mousebuttons, ".middle", MOUSE_MIDDLE);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1305 mousebuttons = tern_insert_int(mousebuttons, ".right", MOUSE_RIGHT);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1306 mousebuttons = tern_insert_int(mousebuttons, ".start", MOUSE_START);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1307 mousebuttons = tern_insert_int(mousebuttons, ".motion", PSEUDO_BUTTON_MOTION);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1308 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1309 return mousebuttons;
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1310 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1311
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1312 void handle_joy_added(int joystick)
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1313 {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1314 if (joystick > MAX_JOYSTICKS) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1315 return;
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1316 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1317 tern_node * pads = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval;
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1318 if (pads) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1319 char numstr[11];
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1320 sprintf(numstr, "%d", joystick);
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1321 tern_node * pad = tern_find_node(pads, numstr);
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1322 if (pad) {
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1323 tern_node * dpad_node = tern_find_node(pad, "dpads");
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1324 if (dpad_node) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1325 for (int dpad = 0; dpad < 10; dpad++)
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1326 {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1327 numstr[0] = dpad + '0';
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1328 numstr[1] = 0;
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1329 tern_node * pad_dpad = tern_find_node(dpad_node, numstr);
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1330 char * dirs[] = {"up", "down", "left", "right"};
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1331 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1332 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1333 char * target = tern_find_ptr(pad_dpad, dirs[dir]);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1334 if (target) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1335 int ui_func, padnum, button;
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1336 int bindtype = parse_binding_target(target, get_pad_buttons(), get_mouse_buttons(), &ui_func, &padnum, &button);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1337 if (bindtype == BIND_GAMEPAD1) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1338 bind_dpad_gamepad(joystick, dpad, dirnums[dir], padnum, button);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1339 } else if (bindtype == BIND_UI) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1340 bind_dpad_ui(joystick, dpad, dirnums[dir], ui_func, button);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1341 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1342 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1343 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1344 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1345 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1346 tern_node *button_node = tern_find_node(pad, "buttons");
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1347 if (button_node) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1348 pad_button_state state = {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1349 .padnum = joystick,
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1350 .padbuttons = get_pad_buttons(),
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1351 .mousebuttons = get_mouse_buttons()
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1352 };
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1353 tern_foreach(button_node, process_pad_button, &state);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1354 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1355 tern_node *axes_node = tern_find_node(pad, "axes");
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1356 if (axes_node) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1357 pad_button_state state = {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1358 .padnum = joystick,
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1359 .padbuttons = get_pad_buttons(),
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1360 .mousebuttons = get_mouse_buttons()
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1361 };
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1362 tern_foreach(axes_node, process_pad_axis, &state);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1363 }
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1364 if (current_io) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1365 if (joysticks[joystick].buttons) {
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1366 map_bindings(current_io->ports, joysticks[joystick].buttons, joysticks[joystick].num_buttons);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1367 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1368 if (joysticks[joystick].dpads)
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1369 {
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1370 for (uint32_t i = 0; i < joysticks[joystick].num_dpads; i++)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1371 {
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1372 map_bindings(current_io->ports, joysticks[joystick].dpads[i].bindings, 4);
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1373 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1374 }
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1375 if (joysticks[joystick].axes) {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1376 for (uint32_t i = 0; i < joysticks[joystick].num_axes; i++)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1377 {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1378 map_bindings(current_io->ports, &joysticks[joystick].axes[i].positive, 1);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1379 map_bindings(current_io->ports, &joysticks[joystick].axes[i].negative, 1);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1380 }
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1381 }
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1382 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1383 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1384 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1385
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1386 }
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1387
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1388 void set_keybindings(sega_io *io)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1389 {
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1390 static uint8_t already_done;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1391 if (already_done) {
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1392 map_all_bindings(io);
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1393 return;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1394 }
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1395 already_done = 1;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1396 io_port *ports = io->ports;
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
1397 tern_node * special = tern_insert_int(NULL, "up", RENDERKEY_UP);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
1398 special = tern_insert_int(special, "down", RENDERKEY_DOWN);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
1399 special = tern_insert_int(special, "left", RENDERKEY_LEFT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
1400 special = tern_insert_int(special, "right", RENDERKEY_RIGHT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
1401 special = tern_insert_int(special, "enter", '\r');
1035
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1402 special = tern_insert_int(special, "space", ' ');
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1403 special = tern_insert_int(special, "tab", '\t');
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1404 special = tern_insert_int(special, "backspace", '\b');
504
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
1405 special = tern_insert_int(special, "esc", RENDERKEY_ESC);
1035
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1406 special = tern_insert_int(special, "delete", RENDERKEY_DEL);
504
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
1407 special = tern_insert_int(special, "lshift", RENDERKEY_LSHIFT);
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
1408 special = tern_insert_int(special, "rshift", RENDERKEY_RSHIFT);
1035
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1409 special = tern_insert_int(special, "lctrl", RENDERKEY_LCTRL);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1410 special = tern_insert_int(special, "rctrl", RENDERKEY_RCTRL);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1411 special = tern_insert_int(special, "lalt", RENDERKEY_LALT);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1412 special = tern_insert_int(special, "ralt", RENDERKEY_RALT);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1413 special = tern_insert_int(special, "home", RENDERKEY_HOME);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1414 special = tern_insert_int(special, "end", RENDERKEY_END);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1415 special = tern_insert_int(special, "pageup", RENDERKEY_PAGEUP);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1416 special = tern_insert_int(special, "pagedown", RENDERKEY_PAGEDOWN);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1417 special = tern_insert_int(special, "f1", RENDERKEY_F1);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1418 special = tern_insert_int(special, "f2", RENDERKEY_F2);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1419 special = tern_insert_int(special, "f3", RENDERKEY_F3);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1420 special = tern_insert_int(special, "f4", RENDERKEY_F4);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1421 special = tern_insert_int(special, "f5", RENDERKEY_F5);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1422 special = tern_insert_int(special, "f6", RENDERKEY_F6);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1423 special = tern_insert_int(special, "f7", RENDERKEY_F7);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1424 special = tern_insert_int(special, "f8", RENDERKEY_F8);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1425 special = tern_insert_int(special, "f9", RENDERKEY_F9);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1426 special = tern_insert_int(special, "f10", RENDERKEY_F10);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1427 special = tern_insert_int(special, "f11", RENDERKEY_F11);
284d905ca582 Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
1428 special = tern_insert_int(special, "f12", RENDERKEY_F12);
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1429 special = tern_insert_int(special, "select", RENDERKEY_SELECT);
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1430 special = tern_insert_int(special, "play", RENDERKEY_PLAY);
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1431 special = tern_insert_int(special, "search", RENDERKEY_SEARCH);
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1432 special = tern_insert_int(special, "back", RENDERKEY_BACK);
1549
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1433 special = tern_insert_int(special, "np0", RENDERKEY_NP0);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1434 special = tern_insert_int(special, "np1", RENDERKEY_NP1);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1435 special = tern_insert_int(special, "np2", RENDERKEY_NP2);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1436 special = tern_insert_int(special, "np3", RENDERKEY_NP3);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1437 special = tern_insert_int(special, "np4", RENDERKEY_NP4);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1438 special = tern_insert_int(special, "np5", RENDERKEY_NP5);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1439 special = tern_insert_int(special, "np6", RENDERKEY_NP6);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1440 special = tern_insert_int(special, "np7", RENDERKEY_NP7);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1441 special = tern_insert_int(special, "np8", RENDERKEY_NP8);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1442 special = tern_insert_int(special, "np9", RENDERKEY_NP9);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1443 special = tern_insert_int(special, "np/", RENDERKEY_NP_DIV);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1444 special = tern_insert_int(special, "np*", RENDERKEY_NP_MUL);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1445 special = tern_insert_int(special, "np-", RENDERKEY_NP_MIN);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1446 special = tern_insert_int(special, "np+", RENDERKEY_NP_PLUS);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1447 special = tern_insert_int(special, "npenter", RENDERKEY_NP_ENTER);
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1488
diff changeset
1448 special = tern_insert_int(special, "np.", RENDERKEY_NP_STOP);
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
1449
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1450 tern_node *padbuttons = get_pad_buttons();
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
1451
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1452 tern_node *mousebuttons = get_mouse_buttons();
1187
6a4503fad67e Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents: 1146
diff changeset
1453
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1454 tern_node * keys = tern_find_path(config, "bindings\0keys\0", TVAL_NODE).ptrval;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1455 process_keys(keys, special, padbuttons, mousebuttons, NULL);
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1456 char numstr[] = "00";
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1457 tern_node * pads = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1458 if (pads) {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1459 for (int i = 0; i < MAX_JOYSTICKS; i++)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1460 {
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 796
diff changeset
1461
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1462 if (i < 10) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1463 numstr[0] = i + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1464 numstr[1] = 0;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1465 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1466 numstr[0] = i/10 + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1467 numstr[1] = i%10 + '0';
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 745
diff changeset
1468 }
1194
1ad0ec7e3939 Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents: 1187
diff changeset
1469
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1470 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1471 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1472 memset(mice, 0, sizeof(mice));
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1473 tern_node * mice = tern_find_path(config, "bindings\0mice\0", TVAL_NODE).ptrval;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1474 if (mice) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1475 tern_node *buttonmaps[2] = {padbuttons, mousebuttons};
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1476 tern_foreach(mice, process_mouse, buttonmaps);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1477 }
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1294
diff changeset
1478 tern_node * speed_nodes = tern_find_path(config, "clocks\0speeds\0", TVAL_NODE).ptrval;
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1479 speeds = malloc(sizeof(uint32_t));
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1480 speeds[0] = 100;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1481 process_speeds(speed_nodes, NULL);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1482 for (int i = 0; i < num_speeds; i++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1483 {
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1484 if (!speeds[i]) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1485 warning("Speed index %d was not set to a valid percentage!", i);
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1486 speeds[i] = 100;
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1487 }
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
1488 }
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1489 map_all_bindings(io);
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1490 }
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1491
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1492 void map_all_bindings(sega_io *io)
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1493 {
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1494 current_io = io;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1495 io_port *ports = io->ports;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1496
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1497 for (int bucket = 0; bucket < 0x10000; bucket++)
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1498 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1499 if (bindings[bucket])
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1500 {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1501 map_bindings(ports, bindings[bucket], 0x8000);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1502 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1503 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1504 for (int stick = 0; stick < MAX_JOYSTICKS; stick++)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1505 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1506 if (joysticks[stick].buttons) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1507 map_bindings(ports, joysticks[stick].buttons, joysticks[stick].num_buttons);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1508 }
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1509 if (joysticks[stick].dpads)
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1510 {
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1511 for (uint32_t i = 0; i < joysticks[stick].num_dpads; i++)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1512 {
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1513 map_bindings(ports, joysticks[stick].dpads[i].bindings, 4);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 916
diff changeset
1514 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1515 }
1207
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1516 for (uint32_t i = 0; i < joysticks[stick].num_axes; i++)
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1517 {
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1518 map_bindings(current_io->ports, &joysticks[stick].axes[i].positive, 1);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1519 map_bindings(current_io->ports, &joysticks[stick].axes[i].negative, 1);
9d6f155732ed Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents: 1202
diff changeset
1520 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1521 }
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1522 for (int mouse = 0; mouse < MAX_MICE; mouse++)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1523 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1524 if (mice[mouse].bind_type >= BIND_MOUSE1 && mice[mouse].bind_type <= BIND_MOUSE8) {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1525 int num = mice[mouse].bind_type - BIND_MOUSE1;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1526 for (int j = 0; j < 3; j++)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1527 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1528 if (ports[j].device_type == IO_MOUSE && ports[j].device.mouse.mouse_num == num)
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1529 {
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1530 memset(ports[j].input, 0, sizeof(ports[j].input));
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1531 mice[mouse].motion_port = ports + j;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1532 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1533 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1534 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1535 }
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1536 map_bindings(ports, mice[mouse].buttons, MAX_MOUSE_BUTTONS);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 903
diff changeset
1537 }
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1538 keyboard_port = NULL;
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1539 for (int i = 0; i < 3; i++)
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1540 {
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1541 if (ports[i].device_type == IO_SATURN_KEYBOARD || ports[i].device_type == IO_XBAND_KEYBOARD) {
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1542 keyboard_port = ports + i;
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1543 break;
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1544 }
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1005
diff changeset
1545 }
1005
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
1546 //not really related to the intention of this function, but the best place to do this currently
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
1547 if (speeds[0] != 100) {
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1548 current_system->set_speed_percent(current_system, speeds[0]);
1005
580a806aef6a Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
1549 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1550 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1551
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1552 #define TH 0x40
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1553 #define TR 0x20
694
7497334bb548 Adjust TH timeout value to take into account the move to master clock cycles
Michael Pavone <pavone@retrodev.com>
parents: 645
diff changeset
1554 #define TH_TIMEOUT 56000
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1555
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1556 void mouse_check_ready(io_port *port, uint32_t current_cycle)
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1557 {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1558 if (current_cycle >= port->device.mouse.ready_cycle) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1559 port->device.mouse.tr_counter++;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1560 port->device.mouse.ready_cycle = CYCLE_NEVER;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1561 if (port->device.mouse.tr_counter == 3) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1562 port->device.mouse.latched_x = port->device.mouse.cur_x;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1563 port->device.mouse.latched_y = port->device.mouse.cur_y;
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
1564 if (current_io->mouse_mode == MOUSE_ABSOLUTE) {
915
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1565 //avoid overflow in absolute mode
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1566 int deltax = port->device.mouse.latched_x - port->device.mouse.last_read_x;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1567 if (abs(deltax) > 255) {
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1568 port->device.mouse.latched_x = port->device.mouse.last_read_x + (deltax > 0 ? 255 : -255);
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1569 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1570 int deltay = port->device.mouse.latched_y - port->device.mouse.last_read_y;
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1571 if (abs(deltay) > 255) {
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1572 port->device.mouse.latched_y = port->device.mouse.last_read_y + (deltay > 0 ? 255 : -255);
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1573 }
9e882eca717e Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents: 914
diff changeset
1574 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1575 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1576 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1577 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1578
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1579 uint32_t last_poll_cycle;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1580 void io_adjust_cycles(io_port * port, uint32_t current_cycle, uint32_t deduction)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1581 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1582 /*uint8_t control = pad->control | 0x80;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1583 uint8_t th = control & pad->output;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1584 if (pad->input[GAMEPAD_TH0] || pad->input[GAMEPAD_TH1]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1585 printf("adjust_cycles | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, pad->input[GAMEPAD_TH0], pad->input[GAMEPAD_TH1], pad->th_counter,pad->timeout_cycle, current_cycle);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1586 }*/
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1587 if (port->device_type == IO_GAMEPAD6)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1588 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1589 if (current_cycle >= port->device.pad.timeout_cycle)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1590 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1591 port->device.pad.th_counter = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1592 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1593 port->device.pad.timeout_cycle -= deduction;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1594 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1595 } else if (port->device_type == IO_MOUSE) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1596 mouse_check_ready(port, current_cycle);
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1597 if (port->device.mouse.ready_cycle != CYCLE_NEVER) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1598 port->device.mouse.ready_cycle -= deduction;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1599 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1600 }
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1601 for (int i = 0; i < 8; i++)
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1602 {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1603 if (port->slow_rise_start[i] != CYCLE_NEVER) {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1604 if (port->slow_rise_start[i] >= deduction) {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1605 port->slow_rise_start[i] -= deduction;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1606 } else {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1607 port->slow_rise_start[i] = CYCLE_NEVER;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1608 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1609 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1610 }
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1611 if (last_poll_cycle >= deduction) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1612 last_poll_cycle -= deduction;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1613 } else {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1614 last_poll_cycle = 0;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1615 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1616 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1617
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1618 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1619 static void wait_for_connection(io_port * port)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1620 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1621 if (port->device.stream.data_fd == -1)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1622 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1623 puts("Waiting for socket connection...");
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1624 port->device.stream.data_fd = accept(port->device.stream.listen_fd, NULL, NULL);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1625 fcntl(port->device.stream.data_fd, F_SETFL, O_NONBLOCK | O_RDWR);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1626 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1627 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1628
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1629 static void service_pipe(io_port * port)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1630 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1631 uint8_t value;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1632 int numRead = read(port->device.stream.data_fd, &value, sizeof(value));
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1633 if (numRead > 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1634 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1635 port->input[IO_TH0] = (value & 0xF) | 0x10;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1636 port->input[IO_TH1] = (value >> 4) | 0x10;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1637 } else if(numRead == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1638 warning("Error reading pipe for IO port: %d %s\n", errno, strerror(errno));
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1639 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1640 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1641
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1642 static void service_socket(io_port *port)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1643 {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1644 uint8_t buf[32];
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1645 uint8_t blocking = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1646 int numRead = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1647 while (numRead <= 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1648 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1649 numRead = recv(port->device.stream.data_fd, buf, sizeof(buf), 0);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1650 if (numRead > 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1651 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1652 port->input[IO_TH0] = buf[numRead-1];
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1653 if (port->input[IO_STATE] == IO_READ_PENDING)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1654 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1655 port->input[IO_STATE] = IO_READ;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1656 if (blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1657 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1658 //pending read satisfied, back to non-blocking mode
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1659 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR | O_NONBLOCK);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1660 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1661 } else if (port->input[IO_STATE] == IO_WRITTEN) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1662 port->input[IO_STATE] = IO_READ;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1663 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1664 } else if (numRead == 0) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1665 port->device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1666 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1667 } else if (errno != EAGAIN && errno != EWOULDBLOCK) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1668 warning("Error reading from socket for IO port: %d %s\n", errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1669 close(port->device.stream.data_fd);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1670 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1671 } else if (port->input[IO_STATE] == IO_READ_PENDING) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1672 //clear the nonblocking flag so the next read will block
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1673 if (!blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1674 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1675 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1676 blocking = 1;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1677 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1678 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1679 //no new data, but that's ok
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1680 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1681 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1682 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1683
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1684 if (port->input[IO_STATE] == IO_WRITE_PENDING)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1685 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1686 uint8_t value = port->output & port->control;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1687 int written = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1688 blocking = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1689 while (written <= 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1690 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1691 send(port->device.stream.data_fd, &value, sizeof(value), 0);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1692 if (written > 0)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1693 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1694 port->input[IO_STATE] = IO_WRITTEN;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1695 if (blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1696 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1697 //pending write satisfied, back to non-blocking mode
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1698 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR | O_NONBLOCK);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1699 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1700 } else if (written == 0) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1701 port->device.stream.data_fd = -1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1702 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1703 } else if (errno != EAGAIN && errno != EWOULDBLOCK) {
903
0e5f9d6135be Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents: 897
diff changeset
1704 warning("Error writing to socket for IO port: %d %s\n", errno, strerror(errno));
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1705 close(port->device.stream.data_fd);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1706 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1707 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1708 //clear the nonblocking flag so the next write will block
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1709 if (!blocking)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1710 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1711 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1712 blocking = 1;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1713 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1714 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1715 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1716 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1717 }
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1718 #endif
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1719
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1720 const int mouse_delays[] = {112*7, 120*7, 96*7, 132*7, 104*7, 96*7, 112*7, 96*7};
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1721
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1722 enum {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1723 KB_SETUP,
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1724 KB_READ,
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1725 KB_WRITE
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1726 };
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1727
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1728 void io_control_write(io_port *port, uint8_t value, uint32_t current_cycle)
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1729 {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1730 uint8_t changes = value ^ port->control;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1731 if (changes) {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1732 for (int i = 0; i < 8; i++)
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1733 {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1734 if (!(value & 1 << i) && !(port->output & 1 << i)) {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1735 //port switched from output to input and the output value was 0
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1736 //since there is a weak pull-up on input pins, this will lead
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1737 //to a slow rise from 0 to 1 if the pin isn't being externally driven
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1738 port->slow_rise_start[i] = current_cycle;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1739 } else {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1740 port->slow_rise_start[i] = CYCLE_NEVER;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1741 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1742 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1743 port->control = value;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1744 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1745 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1746
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1747 void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle)
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1748 {
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1749 uint8_t old_output = (port->control & port->output) | (~port->control & 0xFF);
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1750 uint8_t output = (port->control & value) | (~port->control & 0xFF);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1751 switch (port->device_type)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1752 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1753 case IO_GAMEPAD6:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1754 //check if TH has changed
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1755 if ((old_output & TH) ^ (output & TH)) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1756 if (current_cycle >= port->device.pad.timeout_cycle) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1757 port->device.pad.th_counter = 0;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1758 }
1144
be3df2d8530a Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents: 1116
diff changeset
1759 if ((output & TH)) {
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1760 port->device.pad.th_counter++;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1761 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1762 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1763 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1764 break;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1765 case IO_MOUSE:
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1766 mouse_check_ready(port, current_cycle);
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1767 if (output & TH) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1768 //request is over or mouse is being reset
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1769 if (port->device.mouse.tr_counter) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1770 //request is over
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1771 port->device.mouse.last_read_x = port->device.mouse.latched_x;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1772 port->device.mouse.last_read_y = port->device.mouse.latched_y;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1773 }
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1774 port->device.mouse.tr_counter = 0;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1775 port->device.mouse.ready_cycle = CYCLE_NEVER;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1776 } else {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1777 if ((output & TR) != (old_output & TR)) {
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1778 int delay_index = port->device.mouse.tr_counter >= sizeof(mouse_delays) ? sizeof(mouse_delays)-1 : port->device.mouse.tr_counter;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1779 port->device.mouse.ready_cycle = current_cycle + mouse_delays[delay_index];
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1780 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1781 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1782 break;
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1783 case IO_SATURN_KEYBOARD:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1784 if (output & TH) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1785 //request is over
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1786 if (port->device.keyboard.tr_counter >= 10 && port->device.keyboard.read_pos != 0xFF) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1787 //remove scan code from buffer
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1788 port->device.keyboard.read_pos++;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1789 port->device.keyboard.read_pos &= 7;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1790 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1791 port->device.keyboard.read_pos = 0xFF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1792 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1793 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1794 port->device.keyboard.tr_counter = 0;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1795 } else {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1796 if ((output & TR) != (old_output & TR)) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1797 port->device.keyboard.tr_counter++;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1798 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1799 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
1800 break;
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1801 case IO_XBAND_KEYBOARD:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1802 if (output & TH) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1803 //request is over
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1804 if (
1257
db28178bd2a1 Fix removal of scan codes from buffer in XBAND keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1256
diff changeset
1805 port->device.keyboard.mode == KB_READ && port->device.keyboard.tr_counter > 6
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1806 && (port->device.keyboard.tr_counter & 1)
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1807 ) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1808 if (port->device.keyboard.events[port->device.keyboard.read_pos] & 0xFF00) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1809 port->device.keyboard.events[port->device.keyboard.read_pos] &= 0xFF;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1810 } else {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1811 port->device.keyboard.read_pos++;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1812 port->device.keyboard.read_pos &= 7;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1813 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1814 port->device.keyboard.read_pos = 0xFF;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1815 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1816 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1817 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1818 port->device.keyboard.tr_counter = 0;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1819 port->device.keyboard.mode = KB_SETUP;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1820 } else {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1821 if ((output & TR) != (old_output & TR)) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1822 port->device.keyboard.tr_counter++;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1823 if (port->device.keyboard.tr_counter == 2) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1824 port->device.keyboard.mode = (output & 0xF) ? KB_READ : KB_WRITE;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1825 } else if (port->device.keyboard.mode == KB_WRITE) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1826 switch (port->device.keyboard.tr_counter)
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1827 {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1828 case 3:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1829 //host writes 0b0001
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1830 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1831 case 4:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1832 //host writes 0b0000
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1833 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1834 case 5:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1835 //host writes 0b0000
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1836 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1837 case 6:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1838 port->device.keyboard.cmd = output << 4;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1839 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1840 case 7:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1841 port->device.keyboard.cmd |= output & 0xF;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1842 //TODO: actually do something with the command
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1843 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1844 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1845 } else if (
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1846 port->device.keyboard.mode == KB_READ && port->device.keyboard.tr_counter > 7
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1847 && !(port->device.keyboard.tr_counter & 1)
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1848 ) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1849
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1850 if (port->device.keyboard.events[port->device.keyboard.read_pos] & 0xFF00) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1851 port->device.keyboard.events[port->device.keyboard.read_pos] &= 0xFF;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1852 } else {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1853 port->device.keyboard.read_pos++;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1854 port->device.keyboard.read_pos &= 7;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1855 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1856 port->device.keyboard.read_pos = 0xFF;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1857 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1858 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1859 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1860 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1861 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1862 break;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1863 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1864 case IO_GENERIC:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1865 wait_for_connection(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1866 port->input[IO_STATE] = IO_WRITE_PENDING;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1867 service_socket(port);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1868 break;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
1869 #endif
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1870 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1871 port->output = value;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1872
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1873 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1874
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1875 uint8_t get_scancode_bytes(io_port *port)
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1876 {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1877 if (port->device.keyboard.read_pos == 0xFF) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1878 return 0;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1879 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1880 uint8_t bytes = 0, read_pos = port->device.keyboard.read_pos;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1881 do {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1882 bytes += port->device.keyboard.events[read_pos] & 0xFF00 ? 2 : 1;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1883 read_pos++;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1884 read_pos &= 7;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1885 } while (read_pos != port->device.keyboard.write_pos);
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1886
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1887 return bytes;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1888 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
1889
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1890 #define SLOW_RISE_DEVICE (30*7)
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1891 #define SLOW_RISE_INPUT (12*7)
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1892
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1893 static uint8_t get_output_value(io_port *port, uint32_t current_cycle, uint32_t slow_rise_delay)
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1894 {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1895 uint8_t output = (port->control | 0x80) & port->output;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1896 for (int i = 0; i < 8; i++)
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1897 {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1898 if (!(port->control & 1 << i)) {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1899 if (port->slow_rise_start[i] != CYCLE_NEVER) {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1900 if (current_cycle - port->slow_rise_start[i] >= slow_rise_delay) {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1901 output |= 1 << i;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1902 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1903 } else {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1904 output |= 1 << i;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1905 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1906 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1907 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1908 return output;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1909 }
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1910
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1911 uint8_t io_data_read(io_port * port, uint32_t current_cycle)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1912 {
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1913 uint8_t output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE);
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1914 uint8_t control = port->control | 0x80;
911
73732ae76fa8 IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents: 910
diff changeset
1915 uint8_t th = output & 0x40;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1916 uint8_t input;
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1917 uint8_t device_driven;
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1918 if (current_cycle - last_poll_cycle > MIN_POLL_INTERVAL) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1919 process_events();
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1920 last_poll_cycle = current_cycle;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1035
diff changeset
1921 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1922 switch (port->device_type)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1923 {
1146
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
1924 case IO_GAMEPAD2:
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
1925 input = ~port->input[GAMEPAD_TH1];
1379
65f1d6558e9e Update SMS code for changes supporting slow rise time emulation in IO code
Michael Pavone <pavone@retrodev.com>
parents: 1377
diff changeset
1926 device_driven = 0x3F;
1146
3e24de8d8073 Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents: 1144
diff changeset
1927 break;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1928 case IO_GAMEPAD3:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1929 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1930 input = port->input[th ? GAMEPAD_TH1 : GAMEPAD_TH0];
888
bc127fa1f800 Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents: 886
diff changeset
1931 if (!th) {
bc127fa1f800 Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents: 886
diff changeset
1932 input |= 0xC;
bc127fa1f800 Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents: 886
diff changeset
1933 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1934 //controller output is logically inverted
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1935 input = ~input;
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1936 device_driven = 0x3F;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1937 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1938 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1939 case IO_GAMEPAD6:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1940 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1941 if (current_cycle >= port->device.pad.timeout_cycle) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1942 port->device.pad.th_counter = 0;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1943 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1944 /*if (port->input[GAMEPAD_TH0] || port->input[GAMEPAD_TH1]) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1945 printf("io_data_read | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, port->input[GAMEPAD_TH0], port->input[GAMEPAD_TH1], port->th_counter,port->timeout_cycle, context->current_cycle);
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1946 }*/
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1947 if (th) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1948 if (port->device.pad.th_counter == 3) {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1949 input = port->input[GAMEPAD_EXTRA];
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1950 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1951 input = port->input[GAMEPAD_TH1];
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1952 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1953 } else {
1144
be3df2d8530a Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents: 1116
diff changeset
1954 if (port->device.pad.th_counter == 2) {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1955 input = port->input[GAMEPAD_TH0] | 0xF;
1144
be3df2d8530a Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents: 1116
diff changeset
1956 } else if(port->device.pad.th_counter == 3) {
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1957 input = port->input[GAMEPAD_TH0] & 0x30;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1958 } else {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1959 input = port->input[GAMEPAD_TH0] | 0xC;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
1960 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1961 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1962 //controller output is logically inverted
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1963 input = ~input;
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
1964 device_driven = 0x3F;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1965 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1966 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1967 case IO_MOUSE:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1968 {
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1969 mouse_check_ready(port, current_cycle);
911
73732ae76fa8 IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents: 910
diff changeset
1970 uint8_t tr = output & TR;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1971 if (th) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1972 if (tr) {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1973 input = 0x10;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1974 } else {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1975 input = 0;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1976 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1977 } else {
913
a5a51465f8b0 Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 912
diff changeset
1978
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1979 int16_t delta_x = port->device.mouse.latched_x - port->device.mouse.last_read_x;
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1980 int16_t delta_y = port->device.mouse.last_read_y - port->device.mouse.latched_y;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1981 switch (port->device.mouse.tr_counter)
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1982 {
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1983 case 0:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1984 input = 0xB;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1985 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1986 case 1:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1987 case 2:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1988 input = 0xF;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1989 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1990 case 3:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1991 input = 0;
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1992 if (delta_y > 255 || delta_y < -255) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1993 input |= 8;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1994 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1995 if (delta_x > 255 || delta_x < -255) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1996 input |= 4;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1997 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
1998 if (delta_y < 0) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
1999 input |= 2;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2000 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
2001 if (delta_x < 0) {
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2002 input |= 1;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2003 }
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2004 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2005 case 4:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2006 input = port->input[0];
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2007 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2008 case 5:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
2009 input = delta_x >> 4 & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2010 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2011 case 6:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
2012 input = delta_x & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2013 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2014 case 7:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
2015 input = delta_y >> 4 & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2016 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2017 case 8:
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2018 default:
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
2019 input = delta_y & 0xF;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2020 break;
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2021 }
912
599e2861f484 Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents: 911
diff changeset
2022 input |= ((port->device.mouse.tr_counter & 1) == 0) << 4;
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2023 }
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2024 device_driven = 0x1F;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2025 break;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2026 }
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2027 case IO_SATURN_KEYBOARD:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2028 {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2029 if (th) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2030 input = 0x11;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2031 } else {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2032 uint8_t tr = output & TR;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2033 uint16_t code = port->device.keyboard.read_pos == 0xFF ? 0
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2034 : port->device.keyboard.events[port->device.keyboard.read_pos];
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2035 switch (port->device.keyboard.tr_counter)
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2036 {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2037 case 0:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2038 input = 1;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2039 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2040 case 1:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2041 //Saturn peripheral ID
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2042 input = 3;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2043 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2044 case 2:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2045 //data size
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2046 input = 4;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2047 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2048 case 3:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2049 //d-pad
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2050 //TODO: set these based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2051 input = 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2052 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2053 case 4:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2054 //Start ABC
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2055 //TODO: set these based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2056 input = 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2057 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2058 case 5:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2059 //R XYZ
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2060 //TODO: set these based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2061 input = 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2062 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2063 case 6:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2064 //L and KBID
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2065 //TODO: set L based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2066 input = 0x8;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2067 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2068 case 7:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2069 //Capslock, Numlock, Scrolllock
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2070 //TODO: set these based on keyboard state
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2071 input = 0;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2072 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2073 case 8:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2074 input = 6;
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2075 if (code & 0xFF00) {
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2076 //break
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2077 input |= 1;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2078 } else if (code) {
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2079 input |= 8;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2080 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2081 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2082 case 9:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2083 input = code >> 4 & 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2084 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2085 case 10:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2086 input = code & 0xF;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2087 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2088 case 11:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2089 input = 0;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2090 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2091 default:
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2092 input = 1;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2093 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2094 }
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2095 input |= ((port->device.keyboard.tr_counter & 1) == 0) << 4;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2096 }
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2097 device_driven = 0x1F;
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2098 break;
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
2099 }
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2100 case IO_XBAND_KEYBOARD:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2101 {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2102 if (th) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2103 input = 0x1C;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2104 } else {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2105 uint8_t size;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2106 if (port->device.keyboard.mode == KB_SETUP || port->device.keyboard.mode == KB_READ) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2107 switch (port->device.keyboard.tr_counter)
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2108 {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2109 case 0:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2110 input = 0x3;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2111 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2112 case 1:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2113 input = 0x6;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2114 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2115 case 2:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2116 //This is where thoe host indicates a read or write
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2117 //presumably, the keyboard only outputs this if the host
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2118 //is not already driving the data bus low
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2119 input = 0x9;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2120 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2121 case 3:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2122 size = get_scancode_bytes(port);
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2123 if (size) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2124 ++size;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2125 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2126 if (size > 15) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2127 size = 15;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2128 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2129 input = size;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2130 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2131 case 4:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2132 case 5:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2133 //always send packet type 0 for now
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2134 input = 0;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2135 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2136 default:
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2137 if (port->device.keyboard.read_pos == 0xFF) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2138 //we've run out of bytes
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2139 input = 0;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2140 } else if (port->device.keyboard.events[port->device.keyboard.read_pos] & 0xFF00) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2141 if (port->device.keyboard.tr_counter & 1) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2142 input = port->device.keyboard.events[port->device.keyboard.read_pos] >> 8 & 0xF;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2143 } else {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2144 input = port->device.keyboard.events[port->device.keyboard.read_pos] >> 12;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2145 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2146 } else {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2147 if (port->device.keyboard.tr_counter & 1) {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2148 input = port->device.keyboard.events[port->device.keyboard.read_pos] & 0xF;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2149 } else {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2150 input = port->device.keyboard.events[port->device.keyboard.read_pos] >> 4;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2151 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2152 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2153 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2154 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2155 } else {
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2156 input = 0xF;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2157 }
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2158 input |= ((port->device.keyboard.tr_counter & 1) == 0) << 4;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2159 }
1453
cd6e566eb6b9 Fix regression in XBAND keyboard support. Fixes ticket:33
Michael Pavone <pavone@retrodev.com>
parents: 1438
diff changeset
2160 //this is not strictly correct at all times, but good enough for now
cd6e566eb6b9 Fix regression in XBAND keyboard support. Fixes ticket:33
Michael Pavone <pavone@retrodev.com>
parents: 1438
diff changeset
2161 device_driven = 0x1F;
1232
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2162 break;
c0120977eeea Initial implementation of the XBAND "Eric Smith" keyboard
Michael Pavone <pavone@retrodev.com>
parents: 1208
diff changeset
2163 }
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
2164 #ifndef _WIN32
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2165 case IO_SEGA_PARALLEL:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2166 if (!th)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2167 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2168 service_pipe(port);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2169 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2170 input = port->input[th ? IO_TH1 : IO_TH0];
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2171 device_driven = 0x3F;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2172 break;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2173 case IO_GENERIC:
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2174 if (port->input[IO_TH0] & 0x80 && port->input[IO_STATE] == IO_WRITTEN)
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2175 {
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2176 //device requested a blocking read after writes
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2177 port->input[IO_STATE] = IO_READ_PENDING;
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2178 }
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2179 service_socket(port);
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 888
diff changeset
2180 input = port->input[IO_TH0];
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2181 device_driven = 0x7F;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2182 break;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 722
diff changeset
2183 #endif
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2184 default:
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2185 input = 0;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2186 device_driven = 0;
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2187 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2188 }
1348
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2189 uint8_t value = (input & (~control) & device_driven) | (port->output & control);
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2190 //deal with pins that are configured as inputs, but not being actively driven by the device
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2191 uint8_t floating = (~device_driven) & (~control);
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2192 if (floating) {
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2193 value |= get_output_value(port, current_cycle, SLOW_RISE_INPUT) & floating;
040c5600e2d9 Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents: 1326
diff changeset
2194 }
645
d77c79cec800 Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents: 504
diff changeset
2195 /*if (port->input[GAMEPAD_TH0] || port->input[GAMEPAD_TH1]) {
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2196 printf ("value: %X\n", value);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2197 }*/
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2198 return value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2199 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2200
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2201 void io_serialize(io_port *port, serialize_buffer *buf)
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2202 {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2203 save_int8(buf, port->output);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2204 save_int8(buf, port->control);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2205 save_int8(buf, port->serial_out);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2206 save_int8(buf, port->serial_in);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2207 save_int8(buf, port->serial_ctrl);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2208 save_int8(buf, port->device_type);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2209 save_buffer32(buf, port->slow_rise_start, 8);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2210 switch (port->device_type)
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2211 {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2212 case IO_GAMEPAD6:
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2213 save_int32(buf, port->device.pad.timeout_cycle);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2214 save_int16(buf, port->device.pad.th_counter);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2215 break;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2216 case IO_MOUSE:
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2217 save_int32(buf, port->device.mouse.ready_cycle);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2218 save_int16(buf, port->device.mouse.last_read_x);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2219 save_int16(buf, port->device.mouse.last_read_y);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2220 save_int16(buf, port->device.mouse.latched_x);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2221 save_int16(buf, port->device.mouse.latched_y);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2222 save_int8(buf, port->device.mouse.tr_counter);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2223 break;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2224 case IO_SATURN_KEYBOARD:
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2225 case IO_XBAND_KEYBOARD:
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2226 save_int8(buf, port->device.keyboard.tr_counter);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2227 if (port->device_type == IO_XBAND_KEYBOARD) {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2228 save_int8(buf, port->device.keyboard.mode);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2229 save_int8(buf, port->device.keyboard.cmd);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2230 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2231 break;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2232 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2233 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2234
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2235 void io_deserialize(deserialize_buffer *buf, void *vport)
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2236 {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2237 io_port *port = vport;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2238 port->output = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2239 port->control = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2240 port->serial_out = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2241 port->serial_in = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2242 port->serial_ctrl = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2243 uint8_t device_type = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2244 if (device_type != port->device_type) {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2245 warning("Loaded save state has a different device type from the current configuration");
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2246 return;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2247 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2248 switch (port->device_type)
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2249 {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2250 case IO_GAMEPAD6:
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2251 port->device.pad.timeout_cycle = load_int32(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2252 port->device.pad.th_counter = load_int16(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2253 break;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2254 case IO_MOUSE:
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2255 port->device.mouse.ready_cycle = load_int32(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2256 port->device.mouse.last_read_x = load_int16(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2257 port->device.mouse.last_read_y = load_int16(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2258 port->device.mouse.latched_x = load_int16(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2259 port->device.mouse.latched_y = load_int16(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2260 port->device.mouse.tr_counter = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2261 break;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2262 case IO_SATURN_KEYBOARD:
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2263 case IO_XBAND_KEYBOARD:
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2264 port->device.keyboard.tr_counter = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2265 if (port->device_type == IO_XBAND_KEYBOARD) {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2266 port->device.keyboard.mode = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2267 port->device.keyboard.cmd = load_int8(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2268 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2269 break;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2270 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1400
diff changeset
2271 }