src/gba/gba.c (view raw)
1#include "gba.h"
2
3#include "gba-bios.h"
4#include "gba-io.h"
5#include "gba-sio.h"
6#include "gba-thread.h"
7
8#include "util/memory.h"
9
10#include "debugger/debugger.h"
11
12#include <sys/stat.h>
13
14const uint32_t GBA_ARM7TDMI_FREQUENCY = 0x1000000;
15
16enum {
17 SP_BASE_SYSTEM = 0x03FFFF00,
18 SP_BASE_IRQ = 0x03FFFFA0,
19 SP_BASE_SUPERVISOR = 0x03FFFFE0
20};
21
22struct GBACartridgeOverride {
23 const char id[4];
24 enum SavedataType type;
25 int gpio;
26};
27
28static const struct GBACartridgeOverride _overrides[] = {
29 // Boktai: The Sun is in Your Hand
30 { "U3IE", SAVEDATA_EEPROM, GPIO_RTC | GPIO_LIGHT_SENSOR },
31 { "U3IP", SAVEDATA_EEPROM, GPIO_RTC | GPIO_LIGHT_SENSOR },
32
33 // Boktai 2: Solar Boy Django
34 { "U32E", SAVEDATA_EEPROM, GPIO_RTC | GPIO_LIGHT_SENSOR },
35 { "U32P", SAVEDATA_EEPROM, GPIO_RTC | GPIO_LIGHT_SENSOR },
36
37 // Drill Dozer
38 { "V49J", SAVEDATA_SRAM, GPIO_RUMBLE },
39 { "V49E", SAVEDATA_SRAM, GPIO_RUMBLE },
40
41 // Pokemon Ruby
42 { "AXVJ", SAVEDATA_FLASH1M, GPIO_RTC },
43 { "AXVE", SAVEDATA_FLASH1M, GPIO_RTC },
44 { "AXVP", SAVEDATA_FLASH1M, GPIO_RTC },
45 { "AXVI", SAVEDATA_FLASH1M, GPIO_RTC },
46 { "AXVS", SAVEDATA_FLASH1M, GPIO_RTC },
47 { "AXVD", SAVEDATA_FLASH1M, GPIO_RTC },
48 { "AXVF", SAVEDATA_FLASH1M, GPIO_RTC },
49
50 // Pokemon Sapphire
51 { "AXPJ", SAVEDATA_FLASH1M, GPIO_RTC },
52 { "AXPE", SAVEDATA_FLASH1M, GPIO_RTC },
53 { "AXPP", SAVEDATA_FLASH1M, GPIO_RTC },
54 { "AXPI", SAVEDATA_FLASH1M, GPIO_RTC },
55 { "AXPS", SAVEDATA_FLASH1M, GPIO_RTC },
56 { "AXPD", SAVEDATA_FLASH1M, GPIO_RTC },
57 { "AXPF", SAVEDATA_FLASH1M, GPIO_RTC },
58
59 // Pokemon Emerald
60 { "BPEJ", SAVEDATA_FLASH1M, GPIO_RTC },
61 { "BPEE", SAVEDATA_FLASH1M, GPIO_RTC },
62 { "BPEP", SAVEDATA_FLASH1M, GPIO_RTC },
63 { "BPEI", SAVEDATA_FLASH1M, GPIO_RTC },
64 { "BPES", SAVEDATA_FLASH1M, GPIO_RTC },
65 { "BPED", SAVEDATA_FLASH1M, GPIO_RTC },
66 { "BPEF", SAVEDATA_FLASH1M, GPIO_RTC },
67
68 // Pokemon FireRed
69 { "BPRJ", SAVEDATA_FLASH1M, GPIO_NONE },
70 { "BPRE", SAVEDATA_FLASH1M, GPIO_NONE },
71 { "BPRP", SAVEDATA_FLASH1M, GPIO_NONE },
72
73 // Pokemon LeafGreen
74 { "BPGJ", SAVEDATA_FLASH1M, GPIO_NONE },
75 { "BPGE", SAVEDATA_FLASH1M, GPIO_NONE },
76 { "BPGP", SAVEDATA_FLASH1M, GPIO_NONE },
77
78 // RockMan EXE 4.5 - Real Operation
79 { "BR4J", SAVEDATA_FLASH512, GPIO_RTC },
80
81 // Super Mario Advance 4
82 { "AX4J", SAVEDATA_FLASH1M, GPIO_NONE },
83 { "AX4E", SAVEDATA_FLASH1M, GPIO_NONE },
84 { "AX4P", SAVEDATA_FLASH1M, GPIO_NONE },
85
86 // Wario Ware Twisted
87 { "RWZJ", SAVEDATA_SRAM, GPIO_RUMBLE | GPIO_GYRO },
88 { "RWZE", SAVEDATA_SRAM, GPIO_RUMBLE | GPIO_GYRO },
89 { "RWZP", SAVEDATA_SRAM, GPIO_RUMBLE | GPIO_GYRO },
90
91 { { 0, 0, 0, 0 }, 0, 0 }
92};
93
94static void GBAProcessEvents(struct ARMBoard* board);
95static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles);
96static void GBAHitStub(struct ARMBoard* board, uint32_t opcode);
97static void GBAIllegal(struct ARMBoard* board, uint32_t opcode);
98
99static void _checkOverrides(struct GBA* gba, uint32_t code);
100
101void GBAInit(struct GBA* gba) {
102 gba->debugger = 0;
103 gba->savefile = 0;
104
105 ARMInit(&gba->cpu);
106
107 gba->memory.p = gba;
108 GBAMemoryInit(&gba->memory);
109 ARMAssociateMemory(&gba->cpu, &gba->memory.d);
110
111 gba->board.p = gba;
112 GBABoardInit(&gba->board);
113 ARMAssociateBoard(&gba->cpu, &gba->board.d);
114
115 gba->video.p = gba;
116 GBAVideoInit(&gba->video);
117
118 gba->audio.p = gba;
119 GBAAudioInit(&gba->audio);
120
121 GBAIOInit(gba);
122
123 gba->sio.p = gba;
124 GBASIOInit(&gba->sio);
125
126 gba->timersEnabled = 0;
127 memset(gba->timers, 0, sizeof(gba->timers));
128
129 gba->springIRQ = 0;
130 gba->keySource = 0;
131 gba->rotationSource = 0;
132 gba->rumble = 0;
133
134 gba->logLevel = GBA_LOG_INFO | GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL;
135
136 gba->biosChecksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);
137
138 ARMReset(&gba->cpu);
139}
140
141void GBADeinit(struct GBA* gba) {
142 GBAMemoryDeinit(&gba->memory);
143 GBAVideoDeinit(&gba->video);
144 GBAAudioDeinit(&gba->audio);
145}
146
147void GBABoardInit(struct GBABoard* board) {
148 board->d.reset = GBABoardReset;
149 board->d.processEvents = GBAProcessEvents;
150 board->d.swi16 = GBASwi16;
151 board->d.swi32 = GBASwi32;
152 board->d.hitIllegal = GBAIllegal;
153 board->d.readCPSR = GBATestIRQ;
154 board->d.hitStub = GBAHitStub;
155}
156
157void GBABoardReset(struct ARMBoard* board) {
158 struct ARMCore* cpu = board->cpu;
159 ARMSetPrivilegeMode(cpu, MODE_IRQ);
160 cpu->gprs[ARM_SP] = SP_BASE_IRQ;
161 ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR);
162 cpu->gprs[ARM_SP] = SP_BASE_SUPERVISOR;
163 ARMSetPrivilegeMode(cpu, MODE_SYSTEM);
164 cpu->gprs[ARM_SP] = SP_BASE_SYSTEM;
165}
166
167static void GBAProcessEvents(struct ARMBoard* board) {
168 do {
169 struct GBABoard* gbaBoard = (struct GBABoard*) board;
170 int32_t cycles = board->cpu->cycles;
171 int32_t nextEvent = INT_MAX;
172 int32_t testEvent;
173
174 if (gbaBoard->p->springIRQ) {
175 ARMRaiseIRQ(&gbaBoard->p->cpu);
176 gbaBoard->p->springIRQ = 0;
177 }
178
179 testEvent = GBAVideoProcessEvents(&gbaBoard->p->video, cycles);
180 if (testEvent < nextEvent) {
181 nextEvent = testEvent;
182 }
183
184 testEvent = GBAAudioProcessEvents(&gbaBoard->p->audio, cycles);
185 if (testEvent < nextEvent) {
186 nextEvent = testEvent;
187 }
188
189 testEvent = GBATimersProcessEvents(gbaBoard->p, cycles);
190 if (testEvent < nextEvent) {
191 nextEvent = testEvent;
192 }
193
194 testEvent = GBAMemoryRunDMAs(&gbaBoard->p->memory, cycles);
195 if (testEvent < nextEvent) {
196 nextEvent = testEvent;
197 }
198
199 testEvent = GBASIOProcessEvents(&gbaBoard->p->sio, cycles);
200 if (testEvent < nextEvent) {
201 nextEvent = testEvent;
202 }
203
204 board->cpu->cycles -= cycles;
205 board->cpu->nextEvent = nextEvent;
206 } while (board->cpu->cycles >= board->cpu->nextEvent);
207}
208
209static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
210 int32_t nextEvent = INT_MAX;
211 if (gba->timersEnabled) {
212 struct GBATimer* timer;
213 struct GBATimer* nextTimer;
214
215 timer = &gba->timers[0];
216 if (timer->enable) {
217 timer->nextEvent -= cycles;
218 timer->lastEvent -= cycles;
219 if (timer->nextEvent <= 0) {
220 timer->lastEvent = timer->nextEvent;
221 timer->nextEvent += timer->overflowInterval;
222 gba->memory.io[REG_TM0CNT_LO >> 1] = timer->reload;
223 timer->oldReload = timer->reload;
224
225 if (timer->doIrq) {
226 GBARaiseIRQ(gba, IRQ_TIMER0);
227 }
228
229 if (gba->audio.enable) {
230 if ((gba->audio.chALeft || gba->audio.chARight) && gba->audio.chATimer == 0) {
231 GBAAudioSampleFIFO(&gba->audio, 0, timer->lastEvent);
232 }
233
234 if ((gba->audio.chBLeft || gba->audio.chBRight) && gba->audio.chBTimer == 0) {
235 GBAAudioSampleFIFO(&gba->audio, 1, timer->lastEvent);
236 }
237 }
238
239 nextTimer = &gba->timers[1];
240 if (nextTimer->countUp) {
241 ++gba->memory.io[REG_TM1CNT_LO >> 1];
242 if (!gba->memory.io[REG_TM1CNT_LO >> 1]) {
243 nextTimer->nextEvent = 0;
244 }
245 }
246 }
247 nextEvent = timer->nextEvent;
248 }
249
250 timer = &gba->timers[1];
251 if (timer->enable) {
252 timer->nextEvent -= cycles;
253 timer->lastEvent -= cycles;
254 if (timer->nextEvent <= 0) {
255 timer->lastEvent = timer->nextEvent;
256 timer->nextEvent += timer->overflowInterval;
257 gba->memory.io[REG_TM1CNT_LO >> 1] = timer->reload;
258 timer->oldReload = timer->reload;
259
260 if (timer->doIrq) {
261 GBARaiseIRQ(gba, IRQ_TIMER1);
262 }
263
264 if (gba->audio.enable) {
265 if ((gba->audio.chALeft || gba->audio.chARight) && gba->audio.chATimer == 1) {
266 GBAAudioSampleFIFO(&gba->audio, 0, timer->lastEvent);
267 }
268
269 if ((gba->audio.chBLeft || gba->audio.chBRight) && gba->audio.chBTimer == 1) {
270 GBAAudioSampleFIFO(&gba->audio, 1, timer->lastEvent);
271 }
272 }
273
274 if (timer->countUp) {
275 timer->nextEvent = INT_MAX;
276 }
277
278 nextTimer = &gba->timers[2];
279 if (nextTimer->countUp) {
280 ++gba->memory.io[REG_TM2CNT_LO >> 1];
281 if (!gba->memory.io[REG_TM2CNT_LO >> 1]) {
282 nextTimer->nextEvent = 0;
283 }
284 }
285 }
286 if (timer->nextEvent < nextEvent) {
287 nextEvent = timer->nextEvent;
288 }
289 }
290
291 timer = &gba->timers[2];
292 if (timer->enable) {
293 timer->nextEvent -= cycles;
294 timer->lastEvent -= cycles;
295 nextEvent = timer->nextEvent;
296 if (timer->nextEvent <= 0) {
297 timer->lastEvent = timer->nextEvent;
298 timer->nextEvent += timer->overflowInterval;
299 gba->memory.io[REG_TM2CNT_LO >> 1] = timer->reload;
300 timer->oldReload = timer->reload;
301
302 if (timer->doIrq) {
303 GBARaiseIRQ(gba, IRQ_TIMER2);
304 }
305
306 if (timer->countUp) {
307 timer->nextEvent = INT_MAX;
308 }
309
310 nextTimer = &gba->timers[3];
311 if (nextTimer->countUp) {
312 ++gba->memory.io[REG_TM3CNT_LO >> 1];
313 if (!gba->memory.io[REG_TM3CNT_LO >> 1]) {
314 nextTimer->nextEvent = 0;
315 }
316 }
317 }
318 if (timer->nextEvent < nextEvent) {
319 nextEvent = timer->nextEvent;
320 }
321 }
322
323 timer = &gba->timers[3];
324 if (timer->enable) {
325 timer->nextEvent -= cycles;
326 timer->lastEvent -= cycles;
327 nextEvent = timer->nextEvent;
328 if (timer->nextEvent <= 0) {
329 timer->lastEvent = timer->nextEvent;
330 timer->nextEvent += timer->overflowInterval;
331 gba->memory.io[REG_TM3CNT_LO >> 1] = timer->reload;
332 timer->oldReload = timer->reload;
333
334 if (timer->doIrq) {
335 GBARaiseIRQ(gba, IRQ_TIMER3);
336 }
337
338 if (timer->countUp) {
339 timer->nextEvent = INT_MAX;
340 }
341 }
342 if (timer->nextEvent < nextEvent) {
343 nextEvent = timer->nextEvent;
344 }
345 }
346 }
347 return nextEvent;
348}
349
350void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger) {
351 ARMDebuggerInit(debugger, &gba->cpu);
352 gba->debugger = debugger;
353}
354
355void GBADetachDebugger(struct GBA* gba) {
356 ARMDebuggerDeinit(gba->debugger);
357 gba->debugger = 0;
358}
359
360void GBALoadROM(struct GBA* gba, int fd, const char* fname) {
361 struct stat info;
362 gba->memory.rom = fileMemoryMap(fd, SIZE_CART0, MEMORY_READ);
363 gba->activeFile = fname;
364 fstat(fd, &info);
365 gba->memory.romSize = info.st_size;
366 if (gba->savefile) {
367 GBASavedataInit(&gba->memory.savedata, gba->savefile);
368 }
369 GBAGPIOInit(&gba->memory.gpio, &((uint16_t*) gba->memory.rom)[GPIO_REG_DATA >> 1]);
370 _checkOverrides(gba, ((struct GBACartridge*) gba->memory.rom)->id);
371 // TODO: error check
372}
373
374void GBALoadBIOS(struct GBA* gba, int fd) {
375 gba->memory.bios = fileMemoryMap(fd, SIZE_BIOS, MEMORY_READ);
376 gba->memory.fullBios = 1;
377 uint32_t checksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);
378 GBALog(gba, GBA_LOG_DEBUG, "BIOS Checksum: 0x%X", checksum);
379 if (checksum == GBA_BIOS_CHECKSUM) {
380 GBALog(gba, GBA_LOG_INFO, "Official GBA BIOS detected");
381 } else if (checksum == GBA_DS_BIOS_CHECKSUM) {
382 GBALog(gba, GBA_LOG_INFO, "Official GBA (DS) BIOS detected");
383 } else {
384 GBALog(gba, GBA_LOG_WARN, "BIOS checksum incorrect");
385 }
386 gba->biosChecksum = checksum;
387 if ((gba->cpu.gprs[ARM_PC] >> BASE_OFFSET) == BASE_BIOS) {
388 gba->memory.d.setActiveRegion(&gba->memory.d, gba->cpu.gprs[ARM_PC]);
389 }
390 // TODO: error check
391}
392
393void GBATimerUpdateRegister(struct GBA* gba, int timer) {
394 struct GBATimer* currentTimer = &gba->timers[timer];
395 if (currentTimer->enable && !currentTimer->countUp) {
396 gba->memory.io[(REG_TM0CNT_LO + (timer << 2)) >> 1] = currentTimer->oldReload + ((gba->cpu.cycles - currentTimer->lastEvent) >> currentTimer->prescaleBits);
397 }
398}
399
400void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t reload) {
401 gba->timers[timer].reload = reload;
402}
403
404void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t control) {
405 struct GBATimer* currentTimer = &gba->timers[timer];
406 GBATimerUpdateRegister(gba, timer);
407
408 int oldPrescale = currentTimer->prescaleBits;
409 switch (control & 0x0003) {
410 case 0x0000:
411 currentTimer->prescaleBits = 0;
412 break;
413 case 0x0001:
414 currentTimer->prescaleBits = 6;
415 break;
416 case 0x0002:
417 currentTimer->prescaleBits = 8;
418 break;
419 case 0x0003:
420 currentTimer->prescaleBits = 10;
421 break;
422 }
423 currentTimer->countUp = !!(control & 0x0004);
424 currentTimer->doIrq = !!(control & 0x0040);
425 currentTimer->overflowInterval = (0x10000 - currentTimer->reload) << currentTimer->prescaleBits;
426 int wasEnabled = currentTimer->enable;
427 currentTimer->enable = !!(control & 0x0080);
428 if (!wasEnabled && currentTimer->enable) {
429 if (!currentTimer->countUp) {
430 currentTimer->nextEvent = gba->cpu.cycles + currentTimer->overflowInterval;
431 } else {
432 currentTimer->nextEvent = INT_MAX;
433 }
434 gba->memory.io[(REG_TM0CNT_LO + (timer << 2)) >> 1] = currentTimer->reload;
435 currentTimer->oldReload = currentTimer->reload;
436 gba->timersEnabled |= 1 << timer;
437 } else if (wasEnabled && !currentTimer->enable) {
438 if (!currentTimer->countUp) {
439 gba->memory.io[(REG_TM0CNT_LO + (timer << 2)) >> 1] = currentTimer->oldReload + ((gba->cpu.cycles - currentTimer->lastEvent) >> oldPrescale);
440 }
441 gba->timersEnabled &= ~(1 << timer);
442 } else if (currentTimer->prescaleBits != oldPrescale && !currentTimer->countUp) {
443 // FIXME: this might be before present
444 currentTimer->nextEvent = currentTimer->lastEvent + currentTimer->overflowInterval;
445 }
446
447 if (currentTimer->nextEvent < gba->cpu.nextEvent) {
448 gba->cpu.nextEvent = currentTimer->nextEvent;
449 }
450};
451
452void GBAWriteIE(struct GBA* gba, uint16_t value) {
453 if (value & (1 << IRQ_KEYPAD)) {
454 GBALog(gba, GBA_LOG_STUB, "Keypad interrupts not implemented");
455 }
456
457 if (value & (1 << IRQ_GAMEPAK)) {
458 GBALog(gba, GBA_LOG_STUB, "Gamepak interrupts not implemented");
459 }
460
461 if (gba->memory.io[REG_IME >> 1] && value & gba->memory.io[REG_IF >> 1]) {
462 ARMRaiseIRQ(&gba->cpu);
463 }
464}
465
466void GBAWriteIME(struct GBA* gba, uint16_t value) {
467 if (value && gba->memory.io[REG_IE >> 1] & gba->memory.io[REG_IF >> 1]) {
468 ARMRaiseIRQ(&gba->cpu);
469 }
470}
471
472void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq) {
473 gba->memory.io[REG_IF >> 1] |= 1 << irq;
474
475 if (gba->memory.io[REG_IME >> 1] && (gba->memory.io[REG_IE >> 1] & 1 << irq)) {
476 ARMRaiseIRQ(&gba->cpu);
477 }
478}
479
480void GBATestIRQ(struct ARMBoard* board) {
481 struct GBABoard* gbaBoard = (struct GBABoard*) board;
482 struct GBA* gba = gbaBoard->p;
483 if (gba->memory.io[REG_IME >> 1] && gba->memory.io[REG_IE >> 1] & gba->memory.io[REG_IF >> 1]) {
484 gba->springIRQ = 1;
485 gba->cpu.nextEvent = 0;
486 }
487}
488
489int GBAWaitForIRQ(struct GBA* gba) {
490 int irqs = gba->memory.io[REG_IF >> 1];
491 int newIRQs = 0;
492 gba->memory.io[REG_IF >> 1] = 0;
493 while (1) {
494 if (gba->cpu.nextEvent == INT_MAX) {
495 break;
496 } else {
497 gba->cpu.cycles = gba->cpu.nextEvent;
498 GBAProcessEvents(&gba->board.d);
499 if (gba->memory.io[REG_IF >> 1]) {
500 newIRQs = gba->memory.io[REG_IF >> 1];
501 break;
502 }
503 }
504 }
505 gba->memory.io[REG_IF >> 1] = newIRQs | irqs;
506 return newIRQs;
507}
508
509int GBAHalt(struct GBA* gba) {
510 return GBAWaitForIRQ(gba);
511}
512
513static void _GBAVLog(struct GBA* gba, enum GBALogLevel level, const char* format, va_list args) {
514 if (!gba) {
515 struct GBAThread* threadContext = GBAThreadGetContext();
516 if (threadContext) {
517 gba = threadContext->gba;
518 }
519 }
520
521 if (gba && gba->logHandler) {
522 gba->logHandler(gba, level, format, args);
523 return;
524 }
525
526 if (gba && !(level & gba->logLevel) && level != GBA_LOG_FATAL) {
527 return;
528 }
529
530 vprintf(format, args);
531 printf("\n");
532
533 if (level == GBA_LOG_FATAL) {
534 abort();
535 }
536}
537
538void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...) {
539 va_list args;
540 va_start(args, format);
541 _GBAVLog(gba, level, format, args);
542 va_end(args);
543}
544
545void GBADebuggerLogShim(struct ARMDebugger* debugger, enum DebuggerLogLevel level, const char* format, ...) {
546 struct GBABoard* gbaBoard = 0;
547 if (debugger->cpu && debugger->cpu->board) {
548 gbaBoard = (struct GBABoard*) debugger->cpu->board;
549 }
550
551 enum GBALogLevel gbaLevel;
552 switch (level) {
553 case DEBUGGER_LOG_DEBUG:
554 gbaLevel = GBA_LOG_DEBUG;
555 break;
556 case DEBUGGER_LOG_INFO:
557 gbaLevel = GBA_LOG_INFO;
558 break;
559 case DEBUGGER_LOG_WARN:
560 gbaLevel = GBA_LOG_WARN;
561 break;
562 case DEBUGGER_LOG_ERROR:
563 gbaLevel = GBA_LOG_ERROR;
564 break;
565 }
566 va_list args;
567 va_start(args, format);
568 _GBAVLog(gbaBoard ? gbaBoard->p : 0, gbaLevel, format, args);
569 va_end(args);
570}
571
572
573void GBAHitStub(struct ARMBoard* board, uint32_t opcode) {
574 struct GBABoard* gbaBoard = (struct GBABoard*) board;
575 enum GBALogLevel level = GBA_LOG_FATAL;
576 if (gbaBoard->p->debugger) {
577 level = GBA_LOG_STUB;
578 ARMDebuggerEnter(gbaBoard->p->debugger, DEBUGGER_ENTER_ILLEGAL_OP);
579 }
580 GBALog(gbaBoard->p, level, "Stub opcode: %08x", opcode);
581}
582
583void GBAIllegal(struct ARMBoard* board, uint32_t opcode) {
584 struct GBABoard* gbaBoard = (struct GBABoard*) board;
585 GBALog(gbaBoard->p, GBA_LOG_WARN, "Illegal opcode: %08x", opcode);
586 if (gbaBoard->p->debugger) {
587 ARMDebuggerEnter(gbaBoard->p->debugger, DEBUGGER_ENTER_ILLEGAL_OP);
588 }
589}
590
591void _checkOverrides(struct GBA* gba, uint32_t id) {
592 int i;
593 for (i = 0; _overrides[i].id[0]; ++i) {
594 const uint32_t* overrideId = (const uint32_t*) _overrides[i].id;
595 if (*overrideId == id) {
596 switch (_overrides[i].type) {
597 case SAVEDATA_FLASH512:
598 case SAVEDATA_FLASH1M:
599 gba->memory.savedata.type = _overrides[i].type;
600 GBASavedataInitFlash(&gba->memory.savedata);
601 break;
602 case SAVEDATA_EEPROM:
603 GBASavedataInitEEPROM(&gba->memory.savedata);
604 break;
605 case SAVEDATA_SRAM:
606 GBASavedataInitSRAM(&gba->memory.savedata);
607 break;
608 case SAVEDATA_NONE:
609 break;
610 }
611
612 if (_overrides[i].gpio & GPIO_RTC) {
613 GBAGPIOInitRTC(&gba->memory.gpio);
614 }
615
616 if (_overrides[i].gpio & GPIO_GYRO) {
617 GBAGPIOInitGyro(&gba->memory.gpio);
618 }
619
620 if (_overrides[i].gpio & GPIO_RUMBLE) {
621 GBAGPIOInitRumble(&gba->memory.gpio);
622 }
623 return;
624 }
625 }
626}