5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes by James Hammons
7 // (C) 2010 Underground Software
9 // JLH = James Hammons <jlhamm@acm.org>
12 // --- ---------- -------------------------------------------------------------
13 // JLH 01/16/2010 Created this log ;-)
20 #include <string.h> // For memset()
28 static uint8_t joystick_ram[4];
29 uint8_t joypad_0_buttons[21];
30 uint8_t joypad_1_buttons[21];
34 //SDL_Joystick * joystick1;
36 bool GUIKeyHeld = false;
37 extern int start_logging;
38 int gpu_start_log = 0;
40 int blit_start_log = 0;
42 int effect_start2 = 0, effect_start3 = 0, effect_start4 = 0, effect_start5 = 0, effect_start6 = 0;
43 bool interactiveMode = false;
44 bool iLeft, iRight, iToggle = false;
45 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
47 bool startMemLog = false;
48 extern bool doDSPDis, doGPUDis;
50 bool blitterSingleStep = false;
55 void JoystickInit(void)
61 void JoystickExec(void)
63 gpu_start_log = 0; // Only log while key down!
65 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
67 iLeft = iRight = false;
71 void JoystickReset(void)
73 memset(joystick_ram, 0x00, 4);
74 memset(joypad_0_buttons, 0, 21);
75 memset(joypad_1_buttons, 0, 21);
79 void JoystickDone(void)
84 uint8_t JoystickReadByte(uint32_t offset)
86 // For now, until we can fix the 2nd controller... :-P
87 //memset(joypad_1_buttons, 0, 21);
89 #warning "No bounds checking done in JoystickReadByte!"
90 // extern bool hardwareTypeNTSC;
96 int pad0Index = joystick_ram[1] & 0x0F;
97 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
99 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
100 // NOTE: values $7, B, D, & E are only legal ones for pad 0, (rows 3 to 0, in both cases)
101 // $E, D, B, & 7 are only legal ones for pad 1
102 // So the following code is WRONG! (now fixed! ;-)
103 // Also: we should explicitly check for those bit patterns, as other patterns
104 // are legal and yield other controllers... !!! FIX !!!
105 #warning "!!! Need to explicitly check for the proper bit combinations! !!!"
107 if (!(pad0Index & 0x01))
109 else if (!(pad0Index & 0x02))
111 else if (!(pad0Index & 0x04))
113 else if (!(pad0Index & 0x08))
116 if (!(pad1Index & 0x01))
118 else if (!(pad1Index & 0x02))
120 else if (!(pad1Index & 0x04))
122 else if (!(pad1Index & 0x08))
125 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
126 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
127 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
128 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
129 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
130 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
131 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
132 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
136 else if (offset == 3)
138 // Hardware ID returns NTSC/PAL identification bit here
139 uint8_t data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
140 int pad0Index = joystick_ram[1] & 0x0F;
141 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
143 //This is more stuff to add to the button reading, as the preceeding only
144 //yields 16 buttons...
145 #warning "!!! This reports TeamTap incorrectly when PAUSE pressed on controller #1 or #2 !!!"
146 if (!(pad0Index & 0x01))
148 if (joypad_0_buttons[BUTTON_PAUSE])
150 if (joypad_0_buttons[BUTTON_A])
153 else if (!(pad0Index & 0x02))
155 if (joypad_0_buttons[BUTTON_B])
158 else if (!(pad0Index & 0x04))
160 if (joypad_0_buttons[BUTTON_C])
163 else if (!(pad0Index & 0x08))
165 if (joypad_0_buttons[BUTTON_OPTION])
169 if (!(pad1Index & 0x08))
171 if (joypad_1_buttons[BUTTON_PAUSE])
173 if (joypad_1_buttons[BUTTON_A])
176 else if (!(pad1Index & 0x04))
178 if (joypad_1_buttons[BUTTON_B])
181 else if (!(pad1Index & 0x02))
183 if (joypad_1_buttons[BUTTON_C])
186 else if (!(pad1Index & 0x01))
188 if (joypad_1_buttons[BUTTON_OPTION])
195 return joystick_ram[offset];
199 uint16_t JoystickReadWord(uint32_t offset)
201 return ((uint16_t)JoystickReadByte((offset + 0) & 0x03) << 8) | JoystickReadByte((offset + 1) & 0x03);
205 void JoystickWriteByte(uint32_t offset, uint8_t data)
207 joystick_ram[offset & 0x03] = data;
211 void JoystickWriteWord(uint32_t offset, uint16_t data)
213 #warning "No bounds checking done for JoystickWriteWord!"
215 joystick_ram[offset + 0] = (data >> 8) & 0xFF;
216 joystick_ram[offset + 1] = data & 0xFF;