all repos — mgba @ bc9fdc12497f0ed721fad8e7212925012659337a

mGBA Game Boy Advance Emulator

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