3 * (C) 2018 by Andreas Eversberg <jolly@eversberg.eu>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 static int joystick_left = 0;
26 static int joystick_right = 0;
27 static int joystick_up = 0;
28 static int joystick_down = 0;
29 static int joystick_fire = 0;
30 static int joystick_left_reset = 0;
31 static int joystick_right_reset = 0;
32 static int joystick_up_reset = 0;
33 static int joystick_down_reset = 0;
34 static int joystick_fire_reset = 0;
36 #define CIAAPRA 0xbfe000
37 #define JOYDAT1 0xdff00c
39 uint16_t emulate_joystick_read(uint32_t address)
41 if (address == CIAAPRA) {
47 if (address == JOYDAT1) {
48 uint16_t joydat = 0x0000;
51 /* make bit 0 and 1 equal */
55 /* make bit 0 and 1 odd */
61 /* make bit 8 and 9 equal */
65 /* make bit 8 and 9 odd */
75 /* use -1 to keep state unchanged */
76 /* NOTE: a pressed and then released button/stick will sustain until reset_joystick() is called after rendering was done.
77 * this ensures that a short press (during rendering one frame) will not get lost.
79 void set_joystick(int left, int right, int up, int down, int fire)
84 joystick_left_reset = left;
88 joystick_right_reset = right;
92 joystick_up_reset = up;
96 joystick_down_reset = down;
100 joystick_fire_reset = fire;
103 void reset_joystick(void)
105 joystick_left = joystick_left_reset;
106 joystick_right = joystick_right_reset;
107 joystick_up = joystick_up_reset;
108 joystick_down = joystick_down_reset;
109 joystick_fire = joystick_fire_reset;