-
Notifications
You must be signed in to change notification settings - Fork 90
/
dongle.cpp
362 lines (326 loc) · 6.35 KB
/
dongle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*
* UAE - The Un*x Amiga Emulator
*
* Emulates simple protection dongles
*
* Copyright 2009 Toni Wilen
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include "options.h"
#include "dongle.h"
#include "events.h"
#include "uae.h"
#include "debug.h"
#define ROBOCOP3 1
#define LEADERBOARD 2
#define BAT2 3
#define ITALY90 4
#define DAMESGRANDMAITRE 5
#define RUGBYCOACH 6
#define CRICKETCAPTAIN 7
#define LEVIATHAN 8
#define MUSICMASTER 9
#define LOGISTIX 10
#define SCALA_RED 11
#define SCALA_GREEN 12
#define STRIKERMANAGER 13
#define MPSOCCERMANAGER 14
#define FOOTBALLDIRECTOR2 15
static int dflag;
static frame_time_t cycles;
/*
RoboCop 3
- set firebutton as output
- read JOY1DAT
- pulse firebutton (high->low)
- read JOY1DAT
- JOY1DAT bit 8 must toggle
Leader Board
- JOY1DAT, both up and down active (0x0101)
B.A.T. II
- set all serial pins as output except CTS
- game pulses DTR (high->low)
- CTS must be one
- delay
- CTS must be zero
Italy '90 Soccer
- 220k resistor between pins 5 (+5v) and 7 (POTX)
- POT1DAT POTX must be between 0x32 and 0x60
Dames Grand Maitre
- read POT1
- POT1X != POT1Y
- POT1Y * 256 / POT1X must be between 450 and 500
Rugby Coach
- JOY1DAT, left, up and down active (0x0301)
Cricket Captain
- JOY0DAT bits 0 and 1:
- 10 01 11 allowed
- must continuously change state
Leviathan
- same as Leaderboard but in mouse port
Logistix/SuperBase
- second button must be high
- POT1X = 150k
- POT1Y = 100k
- POT1X * 10 / POT1Y must be between 12 and 33
Music Master
- sets joystick port 2 fire button output + low
- first JOY1DAT AND 0x0303 must be zero.
- following JOY1DAT AND 0x0303 reads must be nonzero.
Scala MM (Green)
- 470nF Capacitor between fire button and second button pin
- Drives firebutton high, then low
- Polls POTGOR second button pin, it must go low between about 30000-150000 DMA cycles.
Scala MM (Red)
- 10uF Capacitor between fire button and second button pin
- Drives firebutton high, then low
- Polls POTGOR second button pin, it must go low between about 350000-540000 DMA cycles.
Striker Manager
- Writes 0x0F00 to POTGO few times
- Reads JOY1DAT, expects AND 0x303 == 0x200 or 0x203
- Reads JOY1DAT in a loop until AND 0x303 == 0x200 or 0x203 (opposite from previous read)
- Resets the system if wrong value after 200 000 read attemps.
Multi-Player Soccer Manager
- Writes 0x0F00 to POTGO few times
- Reads JOY1DAT, expects AND 0x303 == 0x301 or 0x302
- Reads JOY1DAT in a loop until AND 0x303 == 0x301 or 0x302 (opposite from previous read)
- Resets the system if wrong value after 200 000 read attemps.
*/
static uae_u8 oldcia[2][16];
void dongle_reset (void)
{
dflag = 0;
memset (oldcia, 0, sizeof oldcia);
}
uae_u8 dongle_cia_read (int cia, int reg, uae_u8 extra, uae_u8 val)
{
if (!currprefs.dongle)
return val;
switch (currprefs.dongle)
{
case BAT2:
if (cia == 1 && reg == 0) {
if (!dflag || get_cycles () > cycles + CYCLE_UNIT * 200) {
val &= ~0x10;
dflag = 0;
} else {
val |= 0x10;
}
}
break;
}
return val;
}
void dongle_cia_write (int cia, int reg, uae_u8 extra, uae_u8 val)
{
if (!currprefs.dongle)
return;
switch (currprefs.dongle)
{
case SCALA_GREEN:
case SCALA_RED:
if (cia == 0 && reg == 0) {
if ((val & 0x80) != dflag) {
dflag = val & 0x80;
cycles = get_cycles();
}
}
break;
case ROBOCOP3:
if (cia == 0 && reg == 0 && (val & 0x80))
dflag ^= 1;
break;
case BAT2:
if (cia == 1 && reg == 0 && !(val & 0x80)) {
dflag = 1;
cycles = get_cycles ();
}
break;
case MUSICMASTER:
if (cia == 0 && reg == 0) {
if (!(val & 0x80) && (extra & 0x80)) {
dflag = 1;
} else {
dflag = 0;
}
}
break;
}
oldcia[cia][reg] = val;
}
void dongle_joytest (uae_u16 val)
{
}
uae_u16 dongle_joydat (int port, uae_u16 val)
{
if (!currprefs.dongle)
return val;
switch (currprefs.dongle)
{
case ROBOCOP3:
if (port == 1 && dflag)
val += 0x100;
break;
case LEADERBOARD:
if (port == 1) {
val &= ~0x0303;
val |= 0x0101;
}
break;
case LEVIATHAN:
if (port == 0) {
val &= ~0x0303;
val |= 0x0101;
}
break;
case RUGBYCOACH:
if (port == 1) {
val &= ~0x0303;
val|= 0x0301;
}
break;
case CRICKETCAPTAIN:
if (port == 0) {
val &= ~0x0003;
if (dflag == 0)
val |= 0x0001;
else
val |= 0x0002;
}
dflag ^= 1;
break;
case MUSICMASTER:
if (port == 1 && !dflag) {
val = 0;
} else if (port == 1 && dflag == 1) {
val = 0;
dflag++;
} else if (port == 1 && dflag == 2) {
val = 0x0303;
}
break;
case STRIKERMANAGER:
if (port == 1) {
if (dflag >= 4) {
val &= ~0x0303;
val |= 0x0203;
dflag--;
} else if (dflag > 0) {
val &= ~0x0303;
val |= 0x0200;
}
}
break;
case MPSOCCERMANAGER:
if (port == 1) {
if (dflag >= 4) {
val &= ~0x0303;
val |= 0x0302;
dflag--;
} else if (dflag > 0) {
val &= ~0x0303;
val |= 0x0301;
}
}
break;
case FOOTBALLDIRECTOR2:
if (port == 1) {
if (dflag >= 4) {
val &= ~0x0303;
val |= 0x0300;
dflag--;
} else if (dflag > 0) {
val &= ~0x0303;
val |= 0x0303;
}
}
break;
}
return val;
}
void dongle_potgo (uae_u16 val)
{
if (!currprefs.dongle)
return;
switch (currprefs.dongle)
{
case ITALY90:
case LOGISTIX:
case DAMESGRANDMAITRE:
dflag = (uaerand () & 7) - 3;
break;
case STRIKERMANAGER:
case MPSOCCERMANAGER:
case FOOTBALLDIRECTOR2:
if ((val & 0x0500) == 0x0500) {
dflag++;
} else {
if (dflag > 0) {
dflag--;
}
}
break;
}
}
uae_u16 dongle_potgor (uae_u16 val)
{
if (!currprefs.dongle)
return val;
switch (currprefs.dongle)
{
case LOGISTIX:
val |= 1 << 14;
break;
case SCALA_RED:
case SCALA_GREEN:
{
uae_u8 mode = 0x80;
if ((dflag & 1) || get_cycles() >= cycles + CYCLE_UNIT * (currprefs.dongle == SCALA_RED ? 450000 : 80000)) {
mode = 0x00;
dflag |= 1;
}
if (((dflag & 0x80) ^ mode) == 0x80)
val |= 1 << 14;
else
val &= ~(1 << 14);
break;
}
}
return val;
}
int dongle_analogjoy (int joy, int axis)
{
int v = -1;
if (!currprefs.dongle)
return -1;
switch (currprefs.dongle)
{
case ITALY90:
if (joy == 1 && axis == 0)
v = 73;
break;
case LOGISTIX:
if (joy == 1) {
if (axis == 0)
v = 21;
if (axis == 1)
v = 10;
}
break;
case DAMESGRANDMAITRE:
if (joy == 1) {
if (axis == 1)
v = 80;
if (axis == 0)
v = 43;
}
break;
}
if (v >= 0) {
v += dflag;
if (v < 0)
v = 0;
}
return v;
}