all repos — mgba @ 5f62e33717f8da0b22673621253cf2e265a71603

mGBA Game Boy Advance Emulator

src/gba/gba.c (view raw)

  1/* Copyright (c) 2013-2014 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#include "gba.h"
  7
  8#include "gba-bios.h"
  9#include "gba-io.h"
 10#include "gba-rr.h"
 11#include "gba-sio.h"
 12#include "gba-thread.h"
 13
 14#include "isa-inlines.h"
 15
 16#include "util/crc32.h"
 17#include "util/memory.h"
 18#include "util/patch.h"
 19#include "util/vfs.h"
 20
 21const uint32_t GBA_ARM7TDMI_FREQUENCY = 0x1000000;
 22const uint32_t GBA_COMPONENT_MAGIC = 0x1000000;
 23
 24static const size_t GBA_ROM_MAGIC_OFFSET = 2;
 25static const uint8_t GBA_ROM_MAGIC[] = { 0x00, 0xEA };
 26
 27static void GBAInit(struct ARMCore* cpu, struct ARMComponent* component);
 28static void GBAInterruptHandlerInit(struct ARMInterruptHandler* irqh);
 29static void GBAProcessEvents(struct ARMCore* cpu);
 30static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles);
 31static void GBAHitStub(struct ARMCore* cpu, uint32_t opcode);
 32static void GBAIllegal(struct ARMCore* cpu, uint32_t opcode);
 33
 34void GBACreate(struct GBA* gba) {
 35	gba->d.id = GBA_COMPONENT_MAGIC;
 36	gba->d.init = GBAInit;
 37	gba->d.deinit = 0;
 38}
 39
 40static void GBAInit(struct ARMCore* cpu, struct ARMComponent* component) {
 41	struct GBA* gba = (struct GBA*) component;
 42	gba->cpu = cpu;
 43	gba->debugger = 0;
 44
 45	GBAInterruptHandlerInit(&cpu->irqh);
 46	GBAMemoryInit(gba);
 47	GBASavedataInit(&gba->memory.savedata, 0);
 48
 49	gba->video.p = gba;
 50	GBAVideoInit(&gba->video);
 51
 52	gba->audio.p = gba;
 53	GBAAudioInit(&gba->audio, GBA_AUDIO_SAMPLES);
 54
 55	GBAIOInit(gba);
 56
 57	gba->sio.p = gba;
 58	GBASIOInit(&gba->sio);
 59
 60	gba->timersEnabled = 0;
 61	memset(gba->timers, 0, sizeof(gba->timers));
 62
 63	gba->springIRQ = 0;
 64	gba->keySource = 0;
 65	gba->rotationSource = 0;
 66	gba->luminanceSource = 0;
 67	gba->rtcSource = 0;
 68	gba->rumble = 0;
 69	gba->rr = 0;
 70
 71	gba->romVf = 0;
 72	gba->biosVf = 0;
 73
 74	gba->logLevel = GBA_LOG_INFO | GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL;
 75
 76	gba->biosChecksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);
 77
 78	gba->busyLoop = -1;
 79}
 80
 81void GBADestroy(struct GBA* gba) {
 82	if (gba->pristineRom == gba->memory.rom) {
 83		gba->memory.rom = 0;
 84	}
 85
 86	if (gba->romVf) {
 87		gba->romVf->unmap(gba->romVf, gba->pristineRom, gba->pristineRomSize);
 88	}
 89
 90	if (gba->biosVf) {
 91		gba->biosVf->unmap(gba->biosVf, gba->memory.bios, SIZE_BIOS);
 92	}
 93
 94	GBAMemoryDeinit(gba);
 95	GBAVideoDeinit(&gba->video);
 96	GBAAudioDeinit(&gba->audio);
 97	GBARRContextDestroy(gba);
 98}
 99
100void GBAInterruptHandlerInit(struct ARMInterruptHandler* irqh) {
101	irqh->reset = GBAReset;
102	irqh->processEvents = GBAProcessEvents;
103	irqh->swi16 = GBASwi16;
104	irqh->swi32 = GBASwi32;
105	irqh->hitIllegal = GBAIllegal;
106	irqh->readCPSR = GBATestIRQ;
107	irqh->hitStub = GBAHitStub;
108}
109
110void GBAReset(struct ARMCore* cpu) {
111	ARMSetPrivilegeMode(cpu, MODE_IRQ);
112	cpu->gprs[ARM_SP] = SP_BASE_IRQ;
113	ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR);
114	cpu->gprs[ARM_SP] = SP_BASE_SUPERVISOR;
115	ARMSetPrivilegeMode(cpu, MODE_SYSTEM);
116	cpu->gprs[ARM_SP] = SP_BASE_SYSTEM;
117
118	struct GBA* gba = (struct GBA*) cpu->master;
119	if (!GBARRIsPlaying(gba->rr) && !GBARRIsRecording(gba->rr)) {
120		GBASavedataUnmask(&gba->memory.savedata);
121	}
122	GBAMemoryReset(gba);
123	GBAVideoReset(&gba->video);
124	GBAAudioReset(&gba->audio);
125	GBAIOInit(gba);
126
127	GBASIODeinit(&gba->sio);
128	GBASIOInit(&gba->sio);
129
130	gba->timersEnabled = 0;
131	memset(gba->timers, 0, sizeof(gba->timers));
132}
133
134void GBASkipBIOS(struct ARMCore* cpu) {
135	if (cpu->gprs[ARM_PC] == BASE_RESET + WORD_SIZE_ARM) {
136		cpu->gprs[ARM_PC] = BASE_CART0;
137		int currentCycles = 0;
138		ARM_WRITE_PC;
139	}
140}
141
142static void GBAProcessEvents(struct ARMCore* cpu) {
143	do {
144		struct GBA* gba = (struct GBA*) cpu->master;
145		int32_t cycles = cpu->cycles;
146		int32_t nextEvent = INT_MAX;
147		int32_t testEvent;
148
149		gba->bus = cpu->prefetch[1];
150		if (cpu->executionMode == MODE_THUMB) {
151			gba->bus |= cpu->prefetch[1] << 16;
152		}
153
154		if (gba->springIRQ) {
155			ARMRaiseIRQ(cpu);
156			gba->springIRQ = 0;
157		}
158
159		testEvent = GBAVideoProcessEvents(&gba->video, cycles);
160		if (testEvent < nextEvent) {
161			nextEvent = testEvent;
162		}
163
164		testEvent = GBAAudioProcessEvents(&gba->audio, cycles);
165		if (testEvent < nextEvent) {
166			nextEvent = testEvent;
167		}
168
169		testEvent = GBATimersProcessEvents(gba, cycles);
170		if (testEvent < nextEvent) {
171			nextEvent = testEvent;
172		}
173
174		testEvent = GBAMemoryRunDMAs(gba, cycles);
175		if (testEvent < nextEvent) {
176			nextEvent = testEvent;
177		}
178
179		testEvent = GBASIOProcessEvents(&gba->sio, cycles);
180		if (testEvent < nextEvent) {
181			nextEvent = testEvent;
182		}
183
184		cpu->cycles -= cycles;
185		cpu->nextEvent = nextEvent;
186
187		if (cpu->halted) {
188			cpu->cycles = cpu->nextEvent;
189		}
190	} while (cpu->cycles >= cpu->nextEvent);
191}
192
193static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
194	int32_t nextEvent = INT_MAX;
195	if (gba->timersEnabled) {
196		struct GBATimer* timer;
197		struct GBATimer* nextTimer;
198
199		timer = &gba->timers[0];
200		if (timer->enable) {
201			timer->nextEvent -= cycles;
202			timer->lastEvent -= cycles;
203			if (timer->nextEvent <= 0) {
204				timer->lastEvent = timer->nextEvent;
205				timer->nextEvent += timer->overflowInterval;
206				gba->memory.io[REG_TM0CNT_LO >> 1] = timer->reload;
207				timer->oldReload = timer->reload;
208
209				if (timer->doIrq) {
210					GBARaiseIRQ(gba, IRQ_TIMER0);
211				}
212
213				if (gba->audio.enable) {
214					if ((gba->audio.chALeft || gba->audio.chARight) && gba->audio.chATimer == 0) {
215						GBAAudioSampleFIFO(&gba->audio, 0, timer->lastEvent);
216					}
217
218					if ((gba->audio.chBLeft || gba->audio.chBRight) && gba->audio.chBTimer == 0) {
219						GBAAudioSampleFIFO(&gba->audio, 1, timer->lastEvent);
220					}
221				}
222
223				nextTimer = &gba->timers[1];
224				if (nextTimer->countUp) {
225					++gba->memory.io[REG_TM1CNT_LO >> 1];
226					if (!gba->memory.io[REG_TM1CNT_LO >> 1]) {
227						nextTimer->nextEvent = 0;
228					}
229				}
230			}
231			nextEvent = timer->nextEvent;
232		}
233
234		timer = &gba->timers[1];
235		if (timer->enable) {
236			timer->nextEvent -= cycles;
237			timer->lastEvent -= cycles;
238			if (timer->nextEvent <= 0) {
239				timer->lastEvent = timer->nextEvent;
240				timer->nextEvent += timer->overflowInterval;
241				gba->memory.io[REG_TM1CNT_LO >> 1] = timer->reload;
242				timer->oldReload = timer->reload;
243
244				if (timer->doIrq) {
245					GBARaiseIRQ(gba, IRQ_TIMER1);
246				}
247
248				if (gba->audio.enable) {
249					if ((gba->audio.chALeft || gba->audio.chARight) && gba->audio.chATimer == 1) {
250						GBAAudioSampleFIFO(&gba->audio, 0, timer->lastEvent);
251					}
252
253					if ((gba->audio.chBLeft || gba->audio.chBRight) && gba->audio.chBTimer == 1) {
254						GBAAudioSampleFIFO(&gba->audio, 1, timer->lastEvent);
255					}
256				}
257
258				if (timer->countUp) {
259					timer->nextEvent = INT_MAX;
260				}
261
262				nextTimer = &gba->timers[2];
263				if (nextTimer->countUp) {
264					++gba->memory.io[REG_TM2CNT_LO >> 1];
265					if (!gba->memory.io[REG_TM2CNT_LO >> 1]) {
266						nextTimer->nextEvent = 0;
267					}
268				}
269			}
270			if (timer->nextEvent < nextEvent) {
271				nextEvent = timer->nextEvent;
272			}
273		}
274
275		timer = &gba->timers[2];
276		if (timer->enable) {
277			timer->nextEvent -= cycles;
278			timer->lastEvent -= cycles;
279			nextEvent = timer->nextEvent;
280			if (timer->nextEvent <= 0) {
281				timer->lastEvent = timer->nextEvent;
282				timer->nextEvent += timer->overflowInterval;
283				gba->memory.io[REG_TM2CNT_LO >> 1] = timer->reload;
284				timer->oldReload = timer->reload;
285
286				if (timer->doIrq) {
287					GBARaiseIRQ(gba, IRQ_TIMER2);
288				}
289
290				if (timer->countUp) {
291					timer->nextEvent = INT_MAX;
292				}
293
294				nextTimer = &gba->timers[3];
295				if (nextTimer->countUp) {
296					++gba->memory.io[REG_TM3CNT_LO >> 1];
297					if (!gba->memory.io[REG_TM3CNT_LO >> 1]) {
298						nextTimer->nextEvent = 0;
299					}
300				}
301			}
302			if (timer->nextEvent < nextEvent) {
303				nextEvent = timer->nextEvent;
304			}
305		}
306
307		timer = &gba->timers[3];
308		if (timer->enable) {
309			timer->nextEvent -= cycles;
310			timer->lastEvent -= cycles;
311			nextEvent = timer->nextEvent;
312			if (timer->nextEvent <= 0) {
313				timer->lastEvent = timer->nextEvent;
314				timer->nextEvent += timer->overflowInterval;
315				gba->memory.io[REG_TM3CNT_LO >> 1] = timer->reload;
316				timer->oldReload = timer->reload;
317
318				if (timer->doIrq) {
319					GBARaiseIRQ(gba, IRQ_TIMER3);
320				}
321
322				if (timer->countUp) {
323					timer->nextEvent = INT_MAX;
324				}
325			}
326			if (timer->nextEvent < nextEvent) {
327				nextEvent = timer->nextEvent;
328			}
329		}
330	}
331	return nextEvent;
332}
333
334void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger) {
335	gba->debugger = debugger;
336	gba->cpu->components[GBA_COMPONENT_DEBUGGER] = &debugger->d;
337	ARMHotplugAttach(gba->cpu, GBA_COMPONENT_DEBUGGER);
338}
339
340void GBADetachDebugger(struct GBA* gba) {
341	gba->debugger = 0;
342	ARMHotplugDetach(gba->cpu, GBA_COMPONENT_DEBUGGER);
343	gba->cpu->components[GBA_COMPONENT_DEBUGGER] = 0;
344}
345
346void GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char* fname) {
347	gba->romVf = vf;
348	gba->pristineRomSize = vf->size(vf);
349	vf->seek(vf, 0, SEEK_SET);
350	if (gba->pristineRomSize > SIZE_CART0) {
351		gba->pristineRomSize = SIZE_CART0;
352	}
353	gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ);
354	if (!gba->pristineRom) {
355		GBALog(gba, GBA_LOG_WARN, "Couldn't map ROM");
356		return;
357	}
358	gba->memory.rom = gba->pristineRom;
359	gba->activeFile = fname;
360	gba->memory.romSize = gba->pristineRomSize;
361	gba->romCrc32 = doCrc32(gba->memory.rom, gba->memory.romSize);
362	GBASavedataInit(&gba->memory.savedata, sav);
363	GBAGPIOInit(&gba->memory.gpio, &((uint16_t*) gba->memory.rom)[GPIO_REG_DATA >> 1]);
364	// TODO: error check
365}
366
367void GBALoadBIOS(struct GBA* gba, struct VFile* vf) {
368	gba->biosVf = vf;
369	uint32_t* bios = vf->map(vf, SIZE_BIOS, MAP_READ);
370	if (!bios) {
371		GBALog(gba, GBA_LOG_WARN, "Couldn't map BIOS");
372		return;
373	}
374	gba->memory.bios = bios;
375	gba->memory.fullBios = 1;
376	uint32_t checksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);
377	GBALog(gba, GBA_LOG_DEBUG, "BIOS Checksum: 0x%X", checksum);
378	if (checksum == GBA_BIOS_CHECKSUM) {
379		GBALog(gba, GBA_LOG_INFO, "Official GBA BIOS detected");
380	} else if (checksum == GBA_DS_BIOS_CHECKSUM) {
381		GBALog(gba, GBA_LOG_INFO, "Official GBA (DS) BIOS detected");
382	} else {
383		GBALog(gba, GBA_LOG_WARN, "BIOS checksum incorrect");
384	}
385	gba->biosChecksum = checksum;
386	if (gba->memory.activeRegion == REGION_BIOS) {
387		gba->cpu->memory.activeRegion = gba->memory.bios;
388	}
389	// TODO: error check
390}
391
392void GBAApplyPatch(struct GBA* gba, struct Patch* patch) {
393	size_t patchedSize = patch->outputSize(patch, gba->memory.romSize);
394	if (!patchedSize) {
395		return;
396	}
397	gba->memory.rom = anonymousMemoryMap(patchedSize);
398	if (!patch->applyPatch(patch, gba->pristineRom, gba->pristineRomSize, gba->memory.rom, patchedSize)) {
399		mappedMemoryFree(gba->memory.rom, patchedSize);
400		gba->memory.rom = gba->pristineRom;
401		return;
402	}
403	gba->memory.romSize = patchedSize;
404	gba->romCrc32 = doCrc32(gba->memory.rom, gba->memory.romSize);
405}
406
407void GBATimerUpdateRegister(struct GBA* gba, int timer) {
408	struct GBATimer* currentTimer = &gba->timers[timer];
409	if (currentTimer->enable && !currentTimer->countUp) {
410		gba->memory.io[(REG_TM0CNT_LO + (timer << 2)) >> 1] = currentTimer->oldReload + ((gba->cpu->cycles - currentTimer->lastEvent) >> currentTimer->prescaleBits);
411	}
412}
413
414void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t reload) {
415	gba->timers[timer].reload = reload;
416}
417
418void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t control) {
419	struct GBATimer* currentTimer = &gba->timers[timer];
420	GBATimerUpdateRegister(gba, timer);
421
422	int oldPrescale = currentTimer->prescaleBits;
423	switch (control & 0x0003) {
424	case 0x0000:
425		currentTimer->prescaleBits = 0;
426		break;
427	case 0x0001:
428		currentTimer->prescaleBits = 6;
429		break;
430	case 0x0002:
431		currentTimer->prescaleBits = 8;
432		break;
433	case 0x0003:
434		currentTimer->prescaleBits = 10;
435		break;
436	}
437	currentTimer->countUp = !!(control & 0x0004);
438	currentTimer->doIrq = !!(control & 0x0040);
439	currentTimer->overflowInterval = (0x10000 - currentTimer->reload) << currentTimer->prescaleBits;
440	int wasEnabled = currentTimer->enable;
441	currentTimer->enable = !!(control & 0x0080);
442	if (!wasEnabled && currentTimer->enable) {
443		if (!currentTimer->countUp) {
444			currentTimer->nextEvent = gba->cpu->cycles + currentTimer->overflowInterval;
445		} else {
446			currentTimer->nextEvent = INT_MAX;
447		}
448		gba->memory.io[(REG_TM0CNT_LO + (timer << 2)) >> 1] = currentTimer->reload;
449		currentTimer->oldReload = currentTimer->reload;
450		currentTimer->lastEvent = 0;
451		gba->timersEnabled |= 1 << timer;
452	} else if (wasEnabled && !currentTimer->enable) {
453		if (!currentTimer->countUp) {
454			gba->memory.io[(REG_TM0CNT_LO + (timer << 2)) >> 1] = currentTimer->oldReload + ((gba->cpu->cycles - currentTimer->lastEvent) >> oldPrescale);
455		}
456		gba->timersEnabled &= ~(1 << timer);
457	} else if (currentTimer->prescaleBits != oldPrescale && !currentTimer->countUp) {
458		// FIXME: this might be before present
459		currentTimer->nextEvent = currentTimer->lastEvent + currentTimer->overflowInterval;
460	}
461
462	if (currentTimer->nextEvent < gba->cpu->nextEvent) {
463		gba->cpu->nextEvent = currentTimer->nextEvent;
464	}
465};
466
467void GBAWriteIE(struct GBA* gba, uint16_t value) {
468	if (value & (1 << IRQ_KEYPAD)) {
469		GBALog(gba, GBA_LOG_STUB, "Keypad interrupts not implemented");
470	}
471
472	if (value & (1 << IRQ_GAMEPAK)) {
473		GBALog(gba, GBA_LOG_STUB, "Gamepak interrupts not implemented");
474	}
475
476	if (gba->memory.io[REG_IME >> 1] && value & gba->memory.io[REG_IF >> 1]) {
477		ARMRaiseIRQ(gba->cpu);
478	}
479}
480
481void GBAWriteIME(struct GBA* gba, uint16_t value) {
482	if (value && gba->memory.io[REG_IE >> 1] & gba->memory.io[REG_IF >> 1]) {
483		ARMRaiseIRQ(gba->cpu);
484	}
485}
486
487void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq) {
488	gba->memory.io[REG_IF >> 1] |= 1 << irq;
489	gba->cpu->halted = 0;
490
491	if (gba->memory.io[REG_IME >> 1] && (gba->memory.io[REG_IE >> 1] & 1 << irq)) {
492		ARMRaiseIRQ(gba->cpu);
493	}
494}
495
496void GBATestIRQ(struct ARMCore* cpu) {
497	struct GBA* gba = (struct GBA*) cpu->master;
498	if (gba->memory.io[REG_IME >> 1] && gba->memory.io[REG_IE >> 1] & gba->memory.io[REG_IF >> 1]) {
499		gba->springIRQ = 1;
500		gba->cpu->nextEvent = 0;
501	}
502}
503
504void GBAHalt(struct GBA* gba) {
505	gba->cpu->nextEvent = 0;
506	gba->cpu->halted = 1;
507}
508
509static void _GBAVLog(struct GBA* gba, enum GBALogLevel level, const char* format, va_list args) {
510	struct GBAThread* threadContext = GBAThreadGetContext();
511	enum GBALogLevel logLevel = -1;
512
513	if (gba) {
514		logLevel = gba->logLevel;
515	}
516
517	if (threadContext) {
518		logLevel = threadContext->logLevel;
519		gba = threadContext->gba;
520	}
521
522	if (!(level & logLevel) && level != GBA_LOG_FATAL) {
523		return;
524	}
525
526	if (level == GBA_LOG_FATAL && gba) {
527		gba->cpu->nextEvent = 0;
528	}
529
530	if (threadContext) {
531		if (level == GBA_LOG_FATAL) {
532			MutexLock(&threadContext->stateMutex);
533			threadContext->state = THREAD_CRASHED;
534			MutexUnlock(&threadContext->stateMutex);
535		}
536		if (threadContext->logHandler) {
537			threadContext->logHandler(threadContext, level, format, args);
538			return;
539		}
540	}
541
542	vprintf(format, args);
543	printf("\n");
544
545	if (level == GBA_LOG_FATAL && !threadContext) {
546		abort();
547	}
548}
549
550void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...) {
551	va_list args;
552	va_start(args, format);
553	_GBAVLog(gba, level, format, args);
554	va_end(args);
555}
556
557void GBADebuggerLogShim(struct ARMDebugger* debugger, enum DebuggerLogLevel level, const char* format, ...) {
558	struct GBA* gba = 0;
559	if (debugger->cpu) {
560		gba = (struct GBA*) debugger->cpu->master;
561	}
562
563	enum GBALogLevel gbaLevel;
564	switch (level) {
565	default: // Avoids compiler warning
566	case DEBUGGER_LOG_DEBUG:
567		gbaLevel = GBA_LOG_DEBUG;
568		break;
569	case DEBUGGER_LOG_INFO:
570		gbaLevel = GBA_LOG_INFO;
571		break;
572	case DEBUGGER_LOG_WARN:
573		gbaLevel = GBA_LOG_WARN;
574		break;
575	case DEBUGGER_LOG_ERROR:
576		gbaLevel = GBA_LOG_ERROR;
577		break;
578	}
579	va_list args;
580	va_start(args, format);
581	_GBAVLog(gba, gbaLevel, format, args);
582	va_end(args);
583}
584
585bool GBAIsROM(struct VFile* vf) {
586	if (vf->seek(vf, GBA_ROM_MAGIC_OFFSET, SEEK_SET) < 0) {
587		return false;
588	}
589	uint8_t signature[sizeof(GBA_ROM_MAGIC)];
590	if (vf->read(vf, &signature, sizeof(signature)) != sizeof(signature)) {
591		return false;
592	}
593	return memcmp(signature, GBA_ROM_MAGIC, sizeof(signature)) == 0;
594}
595
596bool GBAIsBIOS(struct VFile* vf) {
597	if (vf->seek(vf, 0, SEEK_SET) < 0) {
598		return false;
599	}
600	uint32_t interruptTable[7];
601	if (vf->read(vf, &interruptTable, sizeof(interruptTable)) != sizeof(interruptTable)) {
602		return false;
603	}
604	int i;
605	for (i = 0; i < 7; ++i) {
606		if ((interruptTable[i] & 0xFFFF0000) != 0xEA000000) {
607			return false;
608		}
609	}
610	return true;
611}
612
613void GBAGetGameCode(struct GBA* gba, char* out) {
614	memcpy(out, &((struct GBACartridge*) gba->memory.rom)->id, 4);
615}
616
617void GBAGetGameTitle(struct GBA* gba, char* out) {
618	memcpy(out, &((struct GBACartridge*) gba->memory.rom)->title, 12);
619}
620
621void GBAHitStub(struct ARMCore* cpu, uint32_t opcode) {
622	struct GBA* gba = (struct GBA*) cpu->master;
623	enum GBALogLevel level = GBA_LOG_FATAL;
624	if (gba->debugger) {
625		level = GBA_LOG_STUB;
626		ARMDebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP);
627	}
628	GBALog(gba, level, "Stub opcode: %08x", opcode);
629}
630
631void GBAIllegal(struct ARMCore* cpu, uint32_t opcode) {
632	struct GBA* gba = (struct GBA*) cpu->master;
633	GBALog(gba, GBA_LOG_WARN, "Illegal opcode: %08x", opcode);
634	if (gba->debugger) {
635		ARMDebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP);
636	}
637}