annotate io.c @ 619:3072fb746601

Added support for JR and JRcc in Z80 test generator
author Michael Pavone <pavone@retrodev.com>
date Mon, 29 Dec 2014 21:36:17 -0800
parents 7b0df1aaf384
children d77c79cec800
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 */
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #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
7 #include "blastem.h"
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "render.h"
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 enum {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 BIND_NONE,
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 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
13 BIND_GAMEPAD2,
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 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
15 };
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 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
18 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
19 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
20 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
21 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
22 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
23 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
24 UI_PREV_SPEED,
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
25 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
26 } 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
27
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 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
29 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
30 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
31 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
32 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
33 } keybinding;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
35 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
36 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
37 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
38 } joydpad;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 keybinding * bindings[256];
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 keybinding * joybindings[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
42 joydpad * joydpads[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
43 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
44
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45 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
46 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 int bucket = keycode >> 8 & 0xFF;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 if (!bindings[bucket]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 bindings[bucket] = malloc(sizeof(keybinding) * 256);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 memset(bindings[bucket], 0, sizeof(keybinding) * 256);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 int idx = keycode & 0xFF;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 bindings[bucket][idx].bind_type = 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
54 bindings[bucket][idx].subtype_a = 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
55 bindings[bucket][idx].subtype_b = 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
56 bindings[bucket][idx].value = value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 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
60 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61 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
62 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
64 if (!joybindings[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 int num = render_joystick_num_buttons(joystick);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 if (!num) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 joybindings[joystick] = malloc(sizeof(keybinding)*num);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 memset(joybindings[joystick], 0, sizeof(keybinding)*num);
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 joybindings[joystick][button].bind_type = 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
73 joybindings[joystick][button].subtype_a = 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
74 joybindings[joystick][button].subtype_b = 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
75 joybindings[joystick][button].value = value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
76 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
77
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
78 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
79 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 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
81 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
82 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
83 if (!joydpads[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84 int num = render_joystick_num_hats(joystick);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
85 if (!num) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
86 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 joydpads[joystick] = malloc(sizeof(joydpad)*num);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
89 memset(joydpads[joystick], 0, sizeof(joydpad)*num);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 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
92 if (dpadbits[i] & direction) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
93 joydpads[joystick][dpad].bindings[i].bind_type = 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
94 joydpads[joystick][dpad].bindings[i].subtype_a = 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
95 joydpads[joystick][dpad].bindings[i].subtype_b = 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
96 joydpads[joystick][dpad].bindings[i].value = value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
97 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
99 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 #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
103
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 #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
105 #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
106 #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
107 #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
108 #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
109 #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
110 #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
111 #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
112 #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
113 #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
114 #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
115 #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
116
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 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
118 {
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
119
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 if (gamepadnum < 1 || gamepadnum > 2) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
121 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
122 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 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
124 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
125 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
127 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
128 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129 if (gamepadnum < 1 || gamepadnum > 2) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
131 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
132 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
133 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
134 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
135
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
136 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
137 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
138 if (gamepadnum < 1 || gamepadnum > 2) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
139 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 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
142 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
143 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
144
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
145 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
146 {
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
147 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
148 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
149
493
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
150 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
151 {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
152 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
153 }
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
154
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
155 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
156 {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
157 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
158 }
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
159
421
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 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
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 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
163 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
164 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
165 case BIND_GAMEPAD2:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
166 if (binding->subtype_a <= GAMEPAD_EXTRA) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
167 genesis->ports[binding->bind_type - BIND_GAMEPAD1].input[binding->subtype_a] |= binding->value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
168 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169 if (binding->subtype_b <= GAMEPAD_EXTRA) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
170 genesis->ports[binding->bind_type - BIND_GAMEPAD1].input[binding->subtype_b] |= binding->value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
171 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
173 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
174 }
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 void handle_keydown(int keycode)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
177 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
178 int bucket = keycode >> 8 & 0xFF;
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 (!bindings[bucket]) {
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 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
182 int idx = keycode & 0xFF;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
183 keybinding * binding = bindings[bucket] + idx;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
184 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
185 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
186
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 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
188 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 if (!joybindings[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
190 return;
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 keybinding * binding = joybindings[joystick] + button;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
193 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
194 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
195
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 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
197 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
198
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
199 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
200 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
201 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
202
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
203 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
204 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
205 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
206 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
207 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
208 case BIND_GAMEPAD2:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
209 if (binding->subtype_a <= GAMEPAD_EXTRA) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
210 genesis->ports[binding->bind_type - BIND_GAMEPAD1].input[binding->subtype_a] &= ~binding->value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
211 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
212 if (binding->subtype_b <= GAMEPAD_EXTRA) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
213 genesis->ports[binding->bind_type - BIND_GAMEPAD1].input[binding->subtype_b] &= ~binding->value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
214 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
215 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
216 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
217 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
218 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
219 case 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
220 ui_debug_mode++;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
221 if (ui_debug_mode == 4) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
222 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
223 }
437
afbea09d7fb4 Restore one of the VDP debugging modes
Mike Pavone <pavone@retrodev.com>
parents: 432
diff changeset
224 genesis->vdp->debug = ui_debug_mode;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
225 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
226 case UI_DEBUG_PAL_INC:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
227 ui_debug_pal++;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
228 if (ui_debug_pal == 4) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
229 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
230 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
231 render_debug_pal(ui_debug_pal);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
232 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
233 case UI_ENTER_DEBUGGER:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
234 break_on_sync = 1;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
235 break;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
236 case UI_SAVE_STATE:
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
237 save_state = 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
238 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
239 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
240 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
241 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
242 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
243 }
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
244 printf("Setting speed to %d: %d\n", current_speed, speeds[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
245 set_speed_percent(genesis, speeds[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
246 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
247 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
248 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
249 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
250 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
251 }
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
252 printf("Setting speed to %d: %d\n", current_speed, speeds[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
253 set_speed_percent(genesis, speeds[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
254 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
255 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
256 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
257 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
258 printf("Setting speed to %d: %d\n", current_speed, speeds[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
259 set_speed_percent(genesis, speeds[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
260 } 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
261 printf("Setting speed to %d\n", speeds[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
262 set_speed_percent(genesis, 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
263 }
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
264 break;
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
265 case UI_EXIT:
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
266 exit(0);
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
267 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
268 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
269 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
270 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
271
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 handle_keyup(int keycode)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
273 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
274 int bucket = keycode >> 8 & 0xFF;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
275 if (!bindings[bucket]) {
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 int idx = keycode & 0xFF;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
279 keybinding * binding = bindings[bucket] + idx;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
280 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
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
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
283 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
284 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
285 if (!joybindings[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
286 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
287 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
288 keybinding * binding = joybindings[joystick] + button;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
289 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
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
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
292 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
293 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
294 if (!joydpads[joystick]) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
295 return;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
296 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
297 joydpad * dpad = joydpads[joystick] + dpadnum;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
298 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
299 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
300 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
301 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
302 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
303 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
304 } 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
305 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
306 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
307 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
308 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
309
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
310 int parse_binding_target(char * target, tern_node * padbuttons, int * ui_out, int * padnum_out, int * padbutton_out)
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
311 {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
312 int gpadslen = strlen("gamepads.");
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
313 if (!memcmp(target, "gamepads.", gpadslen)) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
314 if (target[gpadslen] >= '1' && target[gpadslen] <= '8') {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
315 int padnum = target[gpadslen] - '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
316 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
317 if (button) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
318 *padnum_out = padnum;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
319 *padbutton_out = button;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
320 return 1;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
321 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
322 if (target[gpadslen+1]) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
323 fprintf(stderr, "Gamepad mapping string '%s' refers to an invalid button '%s'\n", target, target + gpadslen + 1);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
324 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
325 fprintf(stderr, "Gamepad mapping string '%s' has no button component\n", target);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
326 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
327 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
328 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
329 fprintf(stderr, "Gamepad mapping string '%s' refers to an invalid gamepad number %c\n", target, target[gpadslen]);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
330 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
331 } else if(!memcmp(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
332 *padbutton_out = 0;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
333 if (!strcmp(target + 3, "vdp_debug_mode")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
334 *ui_out = UI_DEBUG_MODE_INC;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
335 } else if(!strcmp(target + 3, "vdp_debug_pal")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
336 *ui_out = UI_DEBUG_PAL_INC;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
337 } else if(!strcmp(target + 3, "enter_debugger")) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
338 *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
339 } 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
340 *ui_out = UI_SAVE_STATE;
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
341 } else if(!memcmp(target + 3, "set_speed.", 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
342 *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
343 *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
344 } 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
345 *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
346 } 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
347 *ui_out = UI_PREV_SPEED;
444
cc754a309ead Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents: 437
diff changeset
348 } 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
349 *ui_out = UI_EXIT;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
350 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
351 fprintf(stderr, "Unreconized UI binding type %s\n", target);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
352 return 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
353 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
354 return 2;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
355 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
356 fprintf(stderr, "Unrecognized binding type %s\n", target);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
357 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
358 return 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
359 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
360
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
361 void process_keys(tern_node * cur, tern_node * special, tern_node * padbuttons, char * prefix)
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
362 {
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
363 char * curstr = NULL;
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
364 int len;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
365 if (!cur) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
366 return;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
367 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
368 char onec[2];
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
369 if (prefix) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
370 len = strlen(prefix);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
371 curstr = malloc(len + 2);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
372 memcpy(curstr, prefix, len);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
373 } else {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
374 curstr = onec;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
375 len = 0;
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
376 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
377 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
378 curstr[len+1] = 0;
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
379 if (cur->el) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
380 process_keys(cur->straight.next, special, padbuttons, curstr);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
381 } else {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
382 int keycode = tern_find_int(special, curstr, 0);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
383 if (!keycode) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
384 keycode = curstr[0];
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
385 if (curstr[1] != 0) {
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
386 fprintf(stderr, "%s is not recognized as a key identifier, truncating to %c\n", curstr, curstr[0]);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
387 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
388 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
389 char * target = cur->straight.value.ptrval;
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
390 int ui_func, padnum, button;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
391 int bindtype = parse_binding_target(target, padbuttons, &ui_func, &padnum, &button);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
392 if (bindtype == 1) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
393 bind_gamepad(keycode, padnum, button);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
394 } else if(bindtype == 2) {
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
395 bind_ui(keycode, ui_func, button);
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
396 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
397 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
398 process_keys(cur->left, special, padbuttons, prefix);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
399 process_keys(cur->right, special, padbuttons, 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
400 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
401 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
402 }
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
403 }
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
404
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 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
406 {
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 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
408 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
409 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
410 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
411 }
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
412 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
413 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
414 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
415 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
416 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
417 } 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
418 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
419 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
420 }
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
421 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
422 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
423 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
424 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
425 } 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
426 int speed_index = atoi(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
427 if (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
428 if (!strcmp(curstr, "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
429 fputs("Speed index 0 cannot be set to a custom value\n", stderr);
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
430 } 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
431 fprintf(stderr, "%s is not a valid speed index", 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
432 }
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
433 } 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
434 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
435 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
436 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
437 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
438 }
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
439 }
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
440 speeds[speed_index] = atoi(cur->straight.value.ptrval);
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
441 }
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
442 }
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
443 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
444 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
445 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
446 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
447 }
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
448 }
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
449
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
450 void set_keybindings()
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
451 {
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
452 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
453 special = tern_insert_int(special, "down", RENDERKEY_DOWN);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
454 special = tern_insert_int(special, "left", RENDERKEY_LEFT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
455 special = tern_insert_int(special, "right", RENDERKEY_RIGHT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
456 special = tern_insert_int(special, "enter", '\r');
504
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
457 special = tern_insert_int(special, "esc", RENDERKEY_ESC);
7b0df1aaf384 Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents: 493
diff changeset
458 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
459 special = tern_insert_int(special, "rshift", RENDERKEY_RSHIFT);
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
460
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
461 tern_node * padbuttons = tern_insert_int(NULL, ".up", DPAD_UP);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
462 padbuttons = tern_insert_int(padbuttons, ".down", DPAD_DOWN);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
463 padbuttons = tern_insert_int(padbuttons, ".left", DPAD_LEFT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
464 padbuttons = tern_insert_int(padbuttons, ".right", DPAD_RIGHT);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
465 padbuttons = tern_insert_int(padbuttons, ".a", BUTTON_A);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
466 padbuttons = tern_insert_int(padbuttons, ".b", BUTTON_B);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
467 padbuttons = tern_insert_int(padbuttons, ".c", BUTTON_C);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
468 padbuttons = tern_insert_int(padbuttons, ".x", BUTTON_X);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
469 padbuttons = tern_insert_int(padbuttons, ".y", BUTTON_Y);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
470 padbuttons = tern_insert_int(padbuttons, ".z", BUTTON_Z);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
471 padbuttons = tern_insert_int(padbuttons, ".start", BUTTON_START);
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
472 padbuttons = tern_insert_int(padbuttons, ".mode", BUTTON_MODE);
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
473
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
474 tern_node * keys = tern_find_prefix(config, "bindingskeys");
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 421
diff changeset
475 process_keys(keys, special, padbuttons, NULL);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
476 char prefix[] = "bindingspads00";
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
477 for (int i = 0; i < 100 && i < render_num_joysticks(); i++)
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
478 {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
479 if (i < 10) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
480 prefix[strlen("bindingspads")] = i + '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
481 prefix[strlen("bindingspads")+1] = 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
482 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
483 prefix[strlen("bindingspads")] = i/10 + '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
484 prefix[strlen("bindingspads")+1] = i%10 + '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
485 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
486 tern_node * pad = tern_find_prefix(config, prefix);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
487 if (pad) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
488 char dprefix[] = "dpads0";
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
489 for (int dpad = 0; dpad < 10 && dpad < render_joystick_num_hats(i); dpad++)
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
490 {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
491 dprefix[strlen("dpads")] = dpad + '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
492 tern_node * pad_dpad = tern_find_prefix(pad, dprefix);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
493 char * dirs[] = {"up", "down", "left", "right"};
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
494 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
495 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
496 char * target = tern_find_ptr(pad_dpad, dirs[dir]);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
497 if (target) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
498 int ui_func, padnum, button;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
499 int bindtype = parse_binding_target(target, padbuttons, &ui_func, &padnum, &button);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
500 if (bindtype == 1) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
501 bind_dpad_gamepad(i, dpad, dirnums[dir], padnum, button);
493
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
502 } else if (bindtype == 2) {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
503 bind_dpad_ui(i, dpad, dirnums[dir], ui_func, button);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
504 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
505 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
506 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
507 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
508 char bprefix[] = "buttons00";
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
509 for (int but = 0; but < 100 && but < render_joystick_num_buttons(i); but++)
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
510 {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
511 if (but < 10) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
512 bprefix[strlen("buttons")] = but + '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
513 bprefix[strlen("buttons")+1] = 0;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
514 } else {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
515 bprefix[strlen("buttons")] = but/10 + '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
516 bprefix[strlen("buttons")+1] = but%10 + '0';
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
517 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
518 char * target = tern_find_ptr(pad, bprefix);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
519 if (target) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
520 int ui_func, padnum, button;
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
521 int bindtype = parse_binding_target(target, padbuttons, &ui_func, &padnum, &button);
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
522 if (bindtype == 1) {
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
523 bind_button_gamepad(i, but, padnum, button);
493
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
524 } else if (bindtype == 2) {
36c080ece4ed Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents: 483
diff changeset
525 bind_button_ui(i, but, ui_func, button);
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
526 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
527 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
528 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
529 }
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
530 }
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
531 tern_node * speed_nodes = tern_find_prefix(config, "clocksspeeds");
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
532 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
533 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
534 process_speeds(speed_nodes, 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
535 for (int i = 0; i < num_speeds; i++) {
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
536 if (!speeds[i]) {
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
537 fprintf(stderr, "Speed index %d was not set to a valid percentage!", i);
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
538 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
539 }
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
540 }
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
541 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
542
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
543 #define TH 0x40
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
544 #define TH_TIMEOUT 8000
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
545
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
546 void io_adjust_cycles(io_port * pad, uint32_t current_cycle, uint32_t deduction)
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
547 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
548 /*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
549 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
550 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
551 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
552 }*/
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
553 if (current_cycle >= pad->timeout_cycle) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
554 pad->th_counter = 0;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
555 } else {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
556 pad->timeout_cycle -= deduction;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
557 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
558 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
559
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
560 void io_data_write(io_port * pad, uint8_t value, uint32_t 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
561 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
562 if (pad->control & TH) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
563 //check if TH has changed
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
564 if ((pad->output & TH) ^ (value & TH)) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
565 if (current_cycle >= pad->timeout_cycle) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
566 pad->th_counter = 0;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
567 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
568 if (!(value & TH)) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
569 pad->th_counter++;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
570 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
571 pad->timeout_cycle = current_cycle + TH_TIMEOUT;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
572 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
573 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
574 pad->output = value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
575 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
576
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
577 uint8_t io_data_read(io_port * pad, uint32_t 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
578 {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
579 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
580 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
581 uint8_t input;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
582 if (current_cycle >= pad->timeout_cycle) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
583 pad->th_counter = 0;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
584 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
585 /*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
586 printf("io_data_read | 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, context->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
587 }*/
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
588 if (th) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
589 if (pad->th_counter == 3) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
590 input = pad->input[GAMEPAD_EXTRA];
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
591 } else {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
592 input = 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
593 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
594 } else {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
595 if (pad->th_counter == 3) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
596 input = pad->input[GAMEPAD_TH0] | 0xF;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
597 } else if(pad->th_counter == 4) {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
598 input = pad->input[GAMEPAD_TH0] & 0x30;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
599 } else {
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
600 input = pad->input[GAMEPAD_TH0] | 0xC;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
601 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
602 }
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
603 uint8_t value = ((~input) & (~control)) | (pad->output & control);
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
604 /*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
605 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
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 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
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
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
610