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