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