Debian Codegraph @

mednafen/hw_misc/arcade_card/arcade_card.cpp

raw symbols SCIP
1 /* Mednafen - Multi-system Emulator
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17 /*
18 Arcade Card emulation based on information provided by Ki and David Shadoff
19 */
20
21 #include "../../mednafen.h"cxx . . $ `<file>/mednafen/mednafen.h`/
22
23 //#include "pce.h"
24 //#include "huc.h"
25 #include "arcade_card.h"cxx . . $ `<file>/mednafen/hw_misc/arcade_card/arcade_card.h`/
26
27 #include <errno.h>
28 #include <string.h>
29
30 static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void ACAutoIncrementcxx . . $ ACAutoIncrement(fe2cb034830aa8af).(ACPort_tcxx . . $ ACPort_t# *port)
31 {
32 if(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x1)
33 {
34 if(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x10)
35 {
36 //if(port->control & 0x4)
37 //{
38 // printf("BOONY: %04x\n", port->increment);
39 // port->base = (port->base + port->increment + 0xFF0000) & 0xFFFFFF;
40 // printf("%04x\n", port->base);
41 //}
42 //else
43 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. = (port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. + port->incrementcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#increment.) & 0xFFFFFF;
44 }
45 else
46 {
47 port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset. = (port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset. + port->incrementcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#increment.) & 0xFFFF;
48 }
49 }
50 }
51
52 uint8cxx . . $ uint8# ArcadeCardcxx . . $ ArcadeCard#::Readcxx . . $ ArcadeCard#Read(caa7d1c0e7e3236b).(uint32cxx . . $ uint32# A, bool peek)
53 {
54 //printf("AC Read: %04x\n", A);
55 if((A & 0x1F00) != 0x1A00)
56 {
57 //if(!peek)
58 // printf("AC unknown read: %08x\n", A);
59 return(0xFF);
60 }
61 if(A < 0x1A80)
62 {
63 ACPort_tcxx . . $ ACPort_t# *port = &ACcxx . . $ ArcadeCard#AC..portscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#ports.[(A >> 4) & 0x3];
64
65 // if(!peek)
66 // if(A & 0x40)
67 // printf("AC mirrored port read: %08x\n", A); // Madou Monogatari does!
68
69 switch(A & 0xF)
70 {
71 case 0x00:
72 case 0x01:
73 {
74 uint32cxx . . $ uint32# aci;
75 uint8cxx . . $ uint8# ret;
76
77 aci = port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base.;
78 if(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x2)
79 {
80 aci += port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset.;
81 if(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x8)
82 aci += 0xFF0000;
83 }
84 aci &= 0x1FFFFF;
85 ret = ACRAMcxx . . $ ArcadeCard#ACRAM.[aci];
86 if(!peek)
87 ACAutoIncrementcxx . . $ ACAutoIncrement(fe2cb034830aa8af).(port);
88 return(ret);
89 }
90 case 0x02: return(port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. >> 0);
91 case 0x03: return(port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. >> 8);
92 case 0x04: return(port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. >> 16);
93
94 case 0x05: return(port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset. >> 0);
95 case 0x06: return(port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset. >> 8);
96
97 case 0x07: return(port->incrementcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#increment. >> 0);
98 case 0x08: return(port->incrementcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#increment. >> 8);
99 case 0x09: return(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control.);
100 }
101 }
102 else if(A >= 0x1AE0)
103 {
104 switch(A & 0x1F)
105 {
106 case 0x00:
107 case 0x01:
108 case 0x02:
109 case 0x03: return((ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. >> (A & 3) * 8) & 0xFF);
110
111 case 0x04: return(ACcxx . . $ ArcadeCard#AC..shift_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_bits.);
112
113 case 0x05: return(ACcxx . . $ ArcadeCard#AC..rotate_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#rotate_bits.);
114
115 case 0x1C: return(0x00);
116
117 case 0x1D: return(0x00);
118
119 case 0x1E: return(0x10); // Version number. We should verify this!
120
121 case 0x1F: return(0x51); // Arcade Card ID
122 }
123 }
124
125 //if(!peek)
126 // printf("AC unknown read: %08x\n", A);
127 return(0xFF);
128 }
129
130 void ArcadeCardcxx . . $ ArcadeCard#::Writecxx . . $ ArcadeCard#Write(cc289a6b3dfc48da).(uint32cxx . . $ uint32# A, uint8cxx . . $ uint8# V)
131 {
132 //printf("AC Write: %04x %02x\n", A, V);
133 if((A & 0x1F00) != 0x1A00)
134 {
135 //printf("AC unknown write: %08x:%02x\n", A, V);
136 return;
137 }
138
139 if(A < 0x1A80)
140 {
141 ACPort_tcxx . . $ ACPort_t# *port = &ACcxx . . $ ArcadeCard#AC..portscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#ports.[(A >> 4) & 0x3];
142
143 switch(A & 0xF)
144 {
145 default: //printf("AC unknown write: %08x:%02x\n", A, V);
146 break;
147
148 case 0x00:
149 case 0x01:
150 {
151 uint32cxx . . $ uint32# aci;
152
153 aci = port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base.;
154 if(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x2)
155 {
156 aci += port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset.;
157 if(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x8)
158 aci += 0xFF0000;
159 }
160 aci &= 0x1FFFFF;
161
162 ACRAMUsedcxx . . $ ArcadeCard#ACRAMUsed. = true;
163 ACRAMcxx . . $ ArcadeCard#ACRAM.[aci] = V;
164 ACAutoIncrementcxx . . $ ACAutoIncrement(fe2cb034830aa8af).(port);
165 }
166 break;
167
168 case 0x02: port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. &= ~0xFF;
169 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. |= V << 0;
170 break;
171
172 case 0x03: port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. &= ~0xFF00;
173 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. |= V << 8;
174 break;
175
176 case 0x04: port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. &= ~0xFF0000;
177 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. |= V << 16;
178 break;
179
180 case 0x05: port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset. &= ~0xFF;
181 port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset. |= V << 0;
182 if((port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x60) == 0x20)
183 {
184 if(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x08)
185 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. += 0xFF0000;
186
187 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. = (port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. + port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset.) & 0xFFFFFF;
188 }
189 break;
190
191 case 0x06: port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset. &= ~0xFF00;
192 port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset. |= V << 8;
193 if((port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x60) == 0x40)
194 {
195 if(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x08)
196 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. += 0xFF0000;
197
198 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. = (port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. + port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset.) & 0xFFFFFF;
199 }
200 break;
201
202 case 0x07: port->incrementcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#increment. &= ~0xFF;
203 port->incrementcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#increment. |= V << 0;
204 break;
205
206 case 0x08: port->incrementcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#increment. &= ~0xFF00;
207 port->incrementcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#increment. |= V << 8;
208 break;
209
210 case 0x09: port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. = V & 0x7F;
211 break;
212
213 case 0x0A: if((port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x60) == 0x60)
214 {
215 if(port->controlcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#control. & 0x08)
216 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. += 0xFF0000;
217
218 port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. = (port->basecxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#base. + port->offsetcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_0#offset.) & 0xFFFFFF;
219 }
220 break;
221 }
222
223 //if(A & 0x40)
224 // printf("AC mirrored port write: %08x:%02x\n", A, V);
225 }
226 else if(A >= 0x1AE0)
227 {
228 switch(A & 0x1F)
229 {
230 default: //printf("Unknown AC write: %04x %02x\n", A, V);
231 break;
232
233 case 0x00:
234 case 0x01:
235 case 0x02:
236 case 0x03: ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. &= ~(0xFF << (A & 3) * 8);
237 ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. |= (V << (A & 3) * 8);
238 break;
239
240 case 0x04: ACcxx . . $ ArcadeCard#AC..shift_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_bits. = V & 0xF;
241 if(ACcxx . . $ ArcadeCard#AC..shift_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_bits.)
242 {
243 if(ACcxx . . $ ArcadeCard#AC..shift_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_bits. & 0x8)
244 ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. >>= 16 - ACcxx . . $ ArcadeCard#AC..shift_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_bits.;
245 else
246 ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. <<= ACcxx . . $ ArcadeCard#AC..shift_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_bits.;
247 }
248 break;
249
250 case 0x05: ACcxx . . $ ArcadeCard#AC..rotate_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#rotate_bits. = V & 0xF; // Untested code follows:
251 if(ACcxx . . $ ArcadeCard#AC..rotate_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#rotate_bits.)
252 {
253 if(ACcxx . . $ ArcadeCard#AC..rotate_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#rotate_bits. & 0x8)
254 {
255 unsigned int sa = 16 - ACcxx . . $ ArcadeCard#AC..rotate_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#rotate_bits.;
256 unsigned int orv;
257
258 orv = ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. << (32 - sa);
259
260 ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. = (ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. >> sa) | orv;
261 }
262 else
263 {
264 unsigned int sa = ACcxx . . $ ArcadeCard#AC..rotate_bitscxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#rotate_bits.;
265 unsigned int orv;
266
267 orv = (ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. >> (32 - sa)) & ((1 << sa) - 1);
268
269 ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. = (ACcxx . . $ ArcadeCard#AC..shift_latchcxx . . $ $anonymous_type_ea7f61dba9a6a9bb_1#shift_latch. << sa) | orv;
270 }
271 }
272 break;
273 }
274 }
275 }
276
277 ArcadeCardcxx . . $ ArcadeCard#::ArcadeCardcxx . . $ ArcadeCard#ArcadeCard(49f6e7a06ebc5aa8).(void)
278 {
279 ACRAMUsedcxx . . $ ArcadeCard#ACRAMUsed. = false;
280
281 memset(&ACcxx . . $ ArcadeCard#AC., 0, sizeof(ACcxx . . $ ArcadeCard#AC.));
282
283 memset(ACRAMcxx . . $ ArcadeCard#ACRAM., 0, sizeof(ACRAMcxx . . $ ArcadeCard#ACRAM.));
284 }
285
286 ArcadeCardcxx . . $ ArcadeCard#::~cxx . . $ ArcadeCard#`~ArcadeCard`(ced63f7c635d850d).ArcadeCardcxx . . $ ArcadeCard#()
287 {
288
289 }
290
291 void ArcadeCardcxx . . $ ArcadeCard#::Powercxx . . $ ArcadeCard#Power(49f6e7a06ebc5aa8).(void)
292 {
293 memset(ACRAMcxx . . $ ArcadeCard#ACRAM., 0, 0x200000);
294 ACRAMUsedcxx . . $ ArcadeCard#ACRAMUsed. = false;
295 }
296
297 int ArcadeCardcxx . . $ ArcadeCard#::StateActioncxx . . $ ArcadeCard#StateAction(a45b884b8cf568d5).(StateMemcxx . . $ StateMem# *sm, int load, int data_only)
298 {
299 SFORMATcxx . . $ SFORMAT# ACUsedRegs[] =
300 {
301 SFVARcxx . . $ `mednafen/state.h:70:9`!(ACRAMUsed),
302 SFENDcxx . . $ `mednafen/state.h:94:9`!
303 };
304
305 if(!MDFNSS_StateActioncxx . . $ MDFNSS_StateAction(3f628545d3b0df83).(sm, load, data_only, ACUsedRegs, "ArcadeCardUsed"))
306 return(0);
307
308 SFORMATcxx . . $ SFORMAT# ACStateRegs[] =
309 {
310 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[0].base, "AC[0].base"), SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[0].offset, "AC[0].offset"),
311 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[0].increment, "AC[0].increment"), SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[0].control, "AC[0].control"),
312
313 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[1].base, "AC[1].base"), SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[1].offset, "AC[1].offset"),
314 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[1].increment, "AC[1].increment"), SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[1].control, "AC[1].control"),
315
316 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[2].base, "AC[2].base"), SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[2].offset, "AC[2].offset"),
317 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[2].increment, "AC[2].increment"), SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[2].control, "AC[2].control"),
318
319 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[3].base, "AC[3].base"), SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[3].offset, "AC[3].offset"),
320 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[3].increment, "AC[3].increment"), SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.ports[3].control, "AC[3].control"),
321
322 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.shift_bits, "ACShiftBits"),
323 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.shift_latch, "ACShift"),
324 SFVARNcxx . . $ `mednafen/state.h:69:9`!(AC.rotate_bits, "ACRotateBits"),
325 SFARRAYcxx . . $ `mednafen/state.h:73:9`!(ACRAM, ACRAMUsed ? 0x200000 : 0x0),
326 SFENDcxx . . $ `mednafen/state.h:94:9`!
327 };
328 int ret = MDFNSS_StateActioncxx . . $ MDFNSS_StateAction(3f628545d3b0df83).(sm, load, data_only, ACStateRegs, "ArcadeCard");
329
330
331 return(ret);
332 }
333
334
335 void ArcadeCardcxx . . $ ArcadeCard#::PeekRAMcxx . . $ ArcadeCard#PeekRAM(f9255d7bf06fcbb).(uint32cxx . . $ uint32# Address, uint32cxx . . $ uint32# Length, uint8cxx . . $ uint8# *Buffer)
336 {
337 while(Length--)
338 {
339 Address &= (1 << 21) - 1;
340
341 *Buffer = ACRAMcxx . . $ ArcadeCard#ACRAM.[Address];
342
343 Address++;
344 Buffer++;
345 }
346 }
347
348 void ArcadeCardcxx . . $ ArcadeCard#::PokeRAMcxx . . $ ArcadeCard#PokeRAM(ab4d47735551dc1b).(uint32cxx . . $ uint32# Address, uint32cxx . . $ uint32# Length, const uint8cxx . . $ uint8# *Buffer)
349 {
350 uint8cxx . . $ uint8# used = 0;
351
352 while(Length--)
353 {
354 Address &= (1 << 21) - 1;
355
356 ACRAMcxx . . $ ArcadeCard#ACRAM.[Address] = *Buffer;
357 used |= ACRAMcxx . . $ ArcadeCard#ACRAM.[Address];
358
359 Address++;
360 Buffer++;
361 }
362
363 if(used)
364 ACRAMUsedcxx . . $ ArcadeCard#ACRAMUsed. = true;
365 }
366