all repos — mgba @ 473ae29d821bd7b24c78d08e74ea4673eeb64a1b

mGBA Game Boy Advance Emulator

src/gb/core.c (view raw)

  1/* Copyright (c) 2013-2016 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 <mgba/gb/core.h>
  7
  8#include <mgba/core/core.h>
  9#include <mgba/internal/gb/cheats.h>
 10#include <mgba/internal/gb/extra/cli.h>
 11#include <mgba/internal/gb/gb.h>
 12#include <mgba/internal/gb/mbc.h>
 13#include <mgba/internal/gb/overrides.h>
 14#include <mgba/internal/gb/renderers/software.h>
 15#include <mgba/internal/gb/serialize.h>
 16#include <mgba/internal/lr35902/lr35902.h>
 17#include <mgba/internal/lr35902/debugger/debugger.h>
 18#include <mgba-util/crc32.h>
 19#include <mgba-util/memory.h>
 20#include <mgba-util/patch.h>
 21#include <mgba-util/vfs.h>
 22
 23struct GBCore {
 24	struct mCore d;
 25	struct GBVideoSoftwareRenderer renderer;
 26	uint8_t keys;
 27	struct mCPUComponent* components[CPU_COMPONENT_MAX];
 28	const struct Configuration* overrides;
 29	struct mDebuggerPlatform* debuggerPlatform;
 30	struct mCheatDevice* cheatDevice;
 31};
 32
 33static bool _GBCoreInit(struct mCore* core) {
 34	struct GBCore* gbcore = (struct GBCore*) core;
 35
 36	struct LR35902Core* cpu = anonymousMemoryMap(sizeof(struct LR35902Core));
 37	struct GB* gb = anonymousMemoryMap(sizeof(struct GB));
 38	if (!cpu || !gb) {
 39		free(cpu);
 40		free(gb);
 41		return false;
 42	}
 43	core->cpu = cpu;
 44	core->board = gb;
 45	gbcore->overrides = NULL;
 46	gbcore->debuggerPlatform = NULL;
 47	gbcore->cheatDevice = NULL;
 48
 49	GBCreate(gb);
 50	memset(gbcore->components, 0, sizeof(gbcore->components));
 51	LR35902SetComponents(cpu, &gb->d, CPU_COMPONENT_MAX, gbcore->components);
 52	LR35902Init(cpu);
 53	mRTCGenericSourceInit(&core->rtc, core);
 54	gb->memory.rtc = &core->rtc.d;
 55
 56	GBVideoSoftwareRendererCreate(&gbcore->renderer);
 57	gbcore->renderer.outputBuffer = NULL;
 58
 59	gbcore->keys = 0;
 60	gb->keySource = &gbcore->keys;
 61
 62#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
 63	mDirectorySetInit(&core->dirs);
 64#endif
 65	
 66	return true;
 67}
 68
 69static void _GBCoreDeinit(struct mCore* core) {
 70	LR35902Deinit(core->cpu);
 71	GBDestroy(core->board);
 72	mappedMemoryFree(core->cpu, sizeof(struct LR35902Core));
 73	mappedMemoryFree(core->board, sizeof(struct GB));
 74#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
 75	mDirectorySetDeinit(&core->dirs);
 76#endif
 77
 78	struct GBCore* gbcore = (struct GBCore*) core;
 79	free(gbcore->debuggerPlatform);
 80	if (gbcore->cheatDevice) {
 81		mCheatDeviceDestroy(gbcore->cheatDevice);
 82	}
 83	free(gbcore->cheatDevice);
 84	mCoreConfigFreeOpts(&core->opts);
 85	free(core);
 86}
 87
 88static enum mPlatform _GBCorePlatform(const struct mCore* core) {
 89	UNUSED(core);
 90	return PLATFORM_GB;
 91}
 92
 93static void _GBCoreSetSync(struct mCore* core, struct mCoreSync* sync) {
 94	struct GB* gb = core->board;
 95	gb->sync = sync;
 96}
 97
 98static void _GBCoreLoadConfig(struct mCore* core, const struct mCoreConfig* config) {
 99	UNUSED(config);
100
101	struct GB* gb = core->board;
102	if (core->opts.mute) {
103		gb->audio.masterVolume = 0;
104	} else {
105		gb->audio.masterVolume = core->opts.volume;
106	}
107	gb->video.frameskip = core->opts.frameskip;
108
109	int color;
110	if (mCoreConfigGetIntValue(&core->config, "gb.pal[0]", &color)) {
111			GBVideoSetPalette(&gb->video, 0, color);
112	}
113	if (mCoreConfigGetIntValue(&core->config, "gb.pal[1]", &color)) {
114			GBVideoSetPalette(&gb->video, 1, color);
115	}
116	if (mCoreConfigGetIntValue(&core->config, "gb.pal[2]", &color)) {
117			GBVideoSetPalette(&gb->video, 2, color);
118	}
119	if (mCoreConfigGetIntValue(&core->config, "gb.pal[3]", &color)) {
120			GBVideoSetPalette(&gb->video, 3, color);
121	}
122
123	mCoreConfigCopyValue(&core->config, config, "gb.bios");
124	mCoreConfigCopyValue(&core->config, config, "gbc.bios");
125
126#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
127	struct GBCore* gbcore = (struct GBCore*) core;
128	gbcore->overrides = mCoreConfigGetOverridesConst(config);
129#endif
130}
131
132static void _GBCoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) {
133	UNUSED(core);
134	*width = GB_VIDEO_HORIZONTAL_PIXELS;
135	*height = GB_VIDEO_VERTICAL_PIXELS;
136}
137
138static void _GBCoreSetVideoBuffer(struct mCore* core, color_t* buffer, size_t stride) {
139	struct GBCore* gbcore = (struct GBCore*) core;
140	gbcore->renderer.outputBuffer = buffer;
141	gbcore->renderer.outputBufferStride = stride;
142}
143
144static void _GBCoreGetPixels(struct mCore* core, const void** buffer, size_t* stride) {
145	struct GBCore* gbcore = (struct GBCore*) core;
146	gbcore->renderer.d.getPixels(&gbcore->renderer.d, stride, buffer);
147}
148
149static void _GBCorePutPixels(struct mCore* core, const void* buffer, size_t stride) {
150	struct GBCore* gbcore = (struct GBCore*) core;
151	gbcore->renderer.d.putPixels(&gbcore->renderer.d, stride, buffer);
152}
153
154static struct blip_t* _GBCoreGetAudioChannel(struct mCore* core, int ch) {
155	struct GB* gb = core->board;
156	switch (ch) {
157	case 0:
158		return gb->audio.left;
159	case 1:
160		return gb->audio.right;
161	default:
162		return NULL;
163	}
164}
165
166static void _GBCoreSetAudioBufferSize(struct mCore* core, size_t samples) {
167	struct GB* gb = core->board;
168	GBAudioResizeBuffer(&gb->audio, samples);
169}
170
171static size_t _GBCoreGetAudioBufferSize(struct mCore* core) {
172	struct GB* gb = core->board;
173	return gb->audio.samples;
174}
175
176static void _GBCoreAddCoreCallbacks(struct mCore* core, struct mCoreCallbacks* coreCallbacks) {
177	struct GB* gb = core->board;
178	*mCoreCallbacksListAppend(&gb->coreCallbacks) = *coreCallbacks;
179}
180
181static void _GBCoreClearCoreCallbacks(struct mCore* core) {
182	struct GB* gb = core->board;
183	mCoreCallbacksListClear(&gb->coreCallbacks);
184}
185
186static void _GBCoreSetAVStream(struct mCore* core, struct mAVStream* stream) {
187	struct GB* gb = core->board;
188	gb->stream = stream;
189	if (stream && stream->videoDimensionsChanged) {
190		stream->videoDimensionsChanged(stream, GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS);
191	}
192}
193
194static bool _GBCoreLoadROM(struct mCore* core, struct VFile* vf) {
195	return GBLoadROM(core->board, vf);
196}
197
198static bool _GBCoreLoadBIOS(struct mCore* core, struct VFile* vf, int type) {
199	UNUSED(type);
200	GBLoadBIOS(core->board, vf);
201	return true;
202}
203
204static bool _GBCoreLoadSave(struct mCore* core, struct VFile* vf) {
205	return GBLoadSave(core->board, vf);
206}
207
208static bool _GBCoreLoadTemporarySave(struct mCore* core, struct VFile* vf) {
209	struct GB* gb = core->board;
210	GBSavedataMask(gb, vf, false);
211	return true; // TODO: Return a real value
212}
213
214static bool _GBCoreLoadPatch(struct mCore* core, struct VFile* vf) {
215	if (!vf) {
216		return false;
217	}
218	struct Patch patch;
219	if (!loadPatch(vf, &patch)) {
220		return false;
221	}
222	GBApplyPatch(core->board, &patch);
223	return true;
224}
225
226static void _GBCoreUnloadROM(struct mCore* core) {
227	struct GBCore* gbcore = (struct GBCore*) core;
228	struct LR35902Core* cpu = core->cpu;
229	if (gbcore->cheatDevice) {
230		LR35902HotplugDetach(cpu, CPU_COMPONENT_CHEAT_DEVICE);
231		cpu->components[CPU_COMPONENT_CHEAT_DEVICE] = NULL;
232		mCheatDeviceDestroy(gbcore->cheatDevice);
233		gbcore->cheatDevice = NULL;
234	}
235	return GBUnloadROM(core->board);
236}
237
238static void _GBCoreChecksum(const struct mCore* core, void* data, enum mCoreChecksumType type) {
239	struct GB* gb = (struct GB*) core->board;
240	switch (type) {
241	case CHECKSUM_CRC32:
242		memcpy(data, &gb->romCrc32, sizeof(gb->romCrc32));
243		break;
244	}
245	return;
246}
247
248static void _GBCoreReset(struct mCore* core) {
249	struct GBCore* gbcore = (struct GBCore*) core;
250	struct GB* gb = (struct GB*) core->board;
251	if (gbcore->renderer.outputBuffer) {
252		GBVideoAssociateRenderer(&gb->video, &gbcore->renderer.d);
253	}
254
255	if (gb->memory.rom) {
256		struct GBCartridgeOverride override;
257		const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100];
258		override.headerCrc32 = doCrc32(cart, sizeof(*cart));
259		if (GBOverrideFind(gbcore->overrides, &override)) {
260			GBOverrideApply(gb, &override);
261		}
262	}
263
264#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
265	if (!gb->biosVf && core->opts.useBios) {
266		struct VFile* bios = NULL;
267		bool found = false;
268		if (core->opts.bios) {
269			bios = VFileOpen(core->opts.bios, O_RDONLY);
270			if (bios && GBIsBIOS(bios)) {
271				found = true;
272			} else if (bios) {
273				bios->close(bios);
274				bios = NULL;
275			}
276		}
277		if (!found) {
278			GBDetectModel(gb);
279			const char* configPath = NULL;
280
281			switch (gb->model) {
282			case GB_MODEL_DMG:
283			case GB_MODEL_SGB: // TODO
284				configPath = mCoreConfigGetValue(&core->config, "gb.bios");
285				break;
286			case GB_MODEL_CGB:
287			case GB_MODEL_AGB:
288				configPath = mCoreConfigGetValue(&core->config, "gbc.bios");
289				break;
290			default:
291				break;
292			};
293			if (configPath) {
294				bios = VFileOpen(configPath, O_RDONLY);
295			}
296			if (bios && GBIsBIOS(bios)) {
297				found = true;
298			} else if (bios) {
299				bios->close(bios);
300				bios = NULL;
301			}
302		}
303		if (!found) {
304			char path[PATH_MAX];
305			mCoreConfigDirectory(path, PATH_MAX);
306			switch (gb->model) {
307			case GB_MODEL_DMG:
308			case GB_MODEL_SGB: // TODO
309				strncat(path, PATH_SEP "gb_bios.bin", PATH_MAX - strlen(path));
310				break;
311			case GB_MODEL_CGB:
312			case GB_MODEL_AGB:
313				strncat(path, PATH_SEP "gbc_bios.bin", PATH_MAX - strlen(path));
314				break;
315			default:
316				break;
317			};
318			bios = VFileOpen(path, O_RDONLY);
319			if (bios && GBIsBIOS(bios)) {
320				found = true;
321			} else if (bios) {
322				bios->close(bios);
323				bios = NULL;
324			}
325		}
326		if (bios) {
327			GBLoadBIOS(gb, bios);
328		}
329	}
330#endif
331
332	LR35902Reset(core->cpu);
333}
334
335static void _GBCoreRunFrame(struct mCore* core) {
336	struct GB* gb = core->board;
337	int32_t frameCounter = gb->video.frameCounter;
338	while (gb->video.frameCounter == frameCounter) {
339		LR35902Run(core->cpu);
340	}
341}
342
343static void _GBCoreRunLoop(struct mCore* core) {
344	LR35902Run(core->cpu);
345}
346
347static void _GBCoreStep(struct mCore* core) {
348	struct LR35902Core* cpu = core->cpu;
349	do {
350		LR35902Tick(cpu);
351	} while (cpu->executionState != LR35902_CORE_FETCH);
352}
353
354static size_t _GBCoreStateSize(struct mCore* core) {
355	UNUSED(core);
356	return sizeof(struct GBSerializedState);
357}
358
359static bool _GBCoreLoadState(struct mCore* core, const void* state) {
360	return GBDeserialize(core->board, state);
361}
362
363static bool _GBCoreSaveState(struct mCore* core, void* state) {
364	struct LR35902Core* cpu = core->cpu;
365	while (cpu->executionState != LR35902_CORE_FETCH) {
366		LR35902Tick(cpu);
367	}
368	GBSerialize(core->board, state);
369	return true;
370}
371
372static void _GBCoreSetKeys(struct mCore* core, uint32_t keys) {
373	struct GBCore* gbcore = (struct GBCore*) core;
374	gbcore->keys = keys;
375}
376
377static void _GBCoreAddKeys(struct mCore* core, uint32_t keys) {
378	struct GBCore* gbcore = (struct GBCore*) core;
379	gbcore->keys |= keys;
380}
381
382static void _GBCoreClearKeys(struct mCore* core, uint32_t keys) {
383	struct GBCore* gbcore = (struct GBCore*) core;
384	gbcore->keys &= ~keys;
385}
386
387static int32_t _GBCoreFrameCounter(const struct mCore* core) {
388	const struct GB* gb = core->board;
389	return gb->video.frameCounter;
390}
391
392static int32_t _GBCoreFrameCycles(const  struct mCore* core) {
393	UNUSED(core);
394	return GB_VIDEO_TOTAL_LENGTH;
395}
396
397static int32_t _GBCoreFrequency(const struct mCore* core) {
398	UNUSED(core);
399	// TODO: GB differences
400	return DMG_LR35902_FREQUENCY;
401}
402
403static void _GBCoreGetGameTitle(const struct mCore* core, char* title) {
404	GBGetGameTitle(core->board, title);
405}
406
407static void _GBCoreGetGameCode(const struct mCore* core, char* title) {
408	GBGetGameCode(core->board, title);
409}
410
411static void _GBCoreSetPeripheral(struct mCore* core, int type, void* periph) {
412	struct GB* gb = core->board;
413	switch (type) {
414	case mPERIPH_ROTATION:
415		gb->memory.rotation = periph;
416		break;
417	case mPERIPH_RUMBLE:
418		gb->memory.rumble = periph;
419		break;
420	default:
421		return;
422	}
423}
424
425static uint32_t _GBCoreBusRead8(struct mCore* core, uint32_t address) {
426	struct LR35902Core* cpu = core->cpu;
427	return cpu->memory.load8(cpu, address);
428}
429
430static uint32_t _GBCoreBusRead16(struct mCore* core, uint32_t address) {
431	struct LR35902Core* cpu = core->cpu;
432	return cpu->memory.load8(cpu, address) | (cpu->memory.load8(cpu, address + 1) << 8);
433}
434
435static uint32_t _GBCoreBusRead32(struct mCore* core, uint32_t address) {
436	struct LR35902Core* cpu = core->cpu;
437	return cpu->memory.load8(cpu, address) | (cpu->memory.load8(cpu, address + 1) << 8) |
438	       (cpu->memory.load8(cpu, address + 2) << 16) | (cpu->memory.load8(cpu, address + 3) << 24);
439}
440
441static void _GBCoreBusWrite8(struct mCore* core, uint32_t address, uint8_t value) {
442	struct LR35902Core* cpu = core->cpu;
443	cpu->memory.store8(cpu, address, value);
444}
445
446static void _GBCoreBusWrite16(struct mCore* core, uint32_t address, uint16_t value) {
447	struct LR35902Core* cpu = core->cpu;
448	cpu->memory.store8(cpu, address, value);
449	cpu->memory.store8(cpu, address + 1, value >> 8);
450}
451
452static void _GBCoreBusWrite32(struct mCore* core, uint32_t address, uint32_t value) {
453	struct LR35902Core* cpu = core->cpu;
454	cpu->memory.store8(cpu, address, value);
455	cpu->memory.store8(cpu, address + 1, value >> 8);
456	cpu->memory.store8(cpu, address + 2, value >> 16);
457	cpu->memory.store8(cpu, address + 3, value >> 24);
458}
459
460static uint32_t _GBCoreRawRead8(struct mCore* core, uint32_t address, int segment) {
461	struct LR35902Core* cpu = core->cpu;
462	return GBView8(cpu, address, segment);
463}
464
465static uint32_t _GBCoreRawRead16(struct mCore* core, uint32_t address, int segment) {
466	struct LR35902Core* cpu = core->cpu;
467	return GBView8(cpu, address, segment) | (GBView8(cpu, address + 1, segment) << 8);
468}
469
470static uint32_t _GBCoreRawRead32(struct mCore* core, uint32_t address, int segment) {
471	struct LR35902Core* cpu = core->cpu;
472	return GBView8(cpu, address, segment) | (GBView8(cpu, address + 1, segment) << 8) |
473	       (GBView8(cpu, address + 2, segment) << 16) | (GBView8(cpu, address + 3, segment) << 24);
474}
475
476static void _GBCoreRawWrite8(struct mCore* core, uint32_t address, int segment, uint8_t value) {
477	struct LR35902Core* cpu = core->cpu;
478	GBPatch8(cpu, address, value, NULL, segment);
479}
480
481static void _GBCoreRawWrite16(struct mCore* core, uint32_t address, int segment, uint16_t value) {
482	struct LR35902Core* cpu = core->cpu;
483	GBPatch8(cpu, address, value, NULL, segment);
484	GBPatch8(cpu, address + 1, value >> 8, NULL, segment);
485}
486
487static void _GBCoreRawWrite32(struct mCore* core, uint32_t address, int segment, uint32_t value) {
488	struct LR35902Core* cpu = core->cpu;
489	GBPatch8(cpu, address, value, NULL, segment);
490	GBPatch8(cpu, address + 1, value >> 8, NULL, segment);
491	GBPatch8(cpu, address + 2, value >> 16, NULL, segment);
492	GBPatch8(cpu, address + 3, value >> 24, NULL, segment);
493}
494
495#ifdef USE_DEBUGGERS
496static bool _GBCoreSupportsDebuggerType(struct mCore* core, enum mDebuggerType type) {
497	UNUSED(core);
498	switch (type) {
499	case DEBUGGER_CLI:
500		return true;
501	default:
502		return false;
503	}
504}
505
506static struct mDebuggerPlatform* _GBCoreDebuggerPlatform(struct mCore* core) {
507	struct GBCore* gbcore = (struct GBCore*) core;
508	if (!gbcore->debuggerPlatform) {
509		gbcore->debuggerPlatform = LR35902DebuggerPlatformCreate();
510	}
511	return gbcore->debuggerPlatform;
512}
513
514static struct CLIDebuggerSystem* _GBCoreCliDebuggerSystem(struct mCore* core) {
515	return GBCLIDebuggerCreate(core);
516}
517
518static void _GBCoreAttachDebugger(struct mCore* core, struct mDebugger* debugger) {
519	struct LR35902Core* cpu = core->cpu;
520	if (core->debugger) {
521		LR35902HotplugDetach(cpu, CPU_COMPONENT_DEBUGGER);
522	}
523	cpu->components[CPU_COMPONENT_DEBUGGER] = &debugger->d;
524	LR35902HotplugAttach(cpu, CPU_COMPONENT_DEBUGGER);
525	core->debugger = debugger;
526}
527
528static void _GBCoreDetachDebugger(struct mCore* core) {
529	struct LR35902Core* cpu = core->cpu;
530	if (core->debugger) {
531		LR35902HotplugDetach(cpu, CPU_COMPONENT_DEBUGGER);
532	}
533	cpu->components[CPU_COMPONENT_DEBUGGER] = NULL;
534	core->debugger = NULL;
535}
536#endif
537
538static struct mCheatDevice* _GBCoreCheatDevice(struct mCore* core) {
539	struct GBCore* gbcore = (struct GBCore*) core;
540	if (!gbcore->cheatDevice) {
541		gbcore->cheatDevice = GBCheatDeviceCreate();
542		((struct LR35902Core*) core->cpu)->components[CPU_COMPONENT_CHEAT_DEVICE] = &gbcore->cheatDevice->d;
543		LR35902HotplugAttach(core->cpu, CPU_COMPONENT_CHEAT_DEVICE);
544		gbcore->cheatDevice->p = core;
545	}
546	return gbcore->cheatDevice;
547}
548
549static size_t _GBCoreSavedataClone(struct mCore* core, void** sram) {
550	struct GB* gb = core->board;
551	struct VFile* vf = gb->sramVf;
552	if (vf) {
553		*sram = malloc(vf->size(vf));
554		vf->seek(vf, 0, SEEK_SET);
555		return vf->read(vf, *sram, vf->size(vf));
556	}
557	*sram = malloc(gb->sramSize);
558	memcpy(*sram, gb->memory.sram, gb->sramSize);
559	return gb->sramSize;
560}
561
562static bool _GBCoreSavedataRestore(struct mCore* core, const void* sram, size_t size, bool writeback) {
563	struct GB* gb = core->board;
564	if (!writeback) {
565		struct VFile* vf = VFileMemChunk(sram, size);
566		GBSavedataMask(gb, vf, true);
567		return true;
568	}
569	struct VFile* vf = gb->sramVf;
570	if (vf) {
571		vf->seek(vf, 0, SEEK_SET);
572		return vf->write(vf, sram, size) > 0;
573	}
574	if (size > 0x20000) {
575		size = 0x20000;
576	}
577	GBResizeSram(gb, size);
578	memcpy(gb->memory.sram, sram, size);
579	return true;
580}
581
582struct mCore* GBCoreCreate(void) {
583	struct GBCore* gbcore = malloc(sizeof(*gbcore));
584	struct mCore* core = &gbcore->d;
585	memset(&core->opts, 0, sizeof(core->opts));
586	core->cpu = NULL;
587	core->board = NULL;
588	core->debugger = NULL;
589	core->init = _GBCoreInit;
590	core->deinit = _GBCoreDeinit;
591	core->platform = _GBCorePlatform;
592	core->setSync = _GBCoreSetSync;
593	core->loadConfig = _GBCoreLoadConfig;
594	core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions;
595	core->setVideoBuffer = _GBCoreSetVideoBuffer;
596	core->getPixels = _GBCoreGetPixels;
597	core->putPixels = _GBCorePutPixels;
598	core->getAudioChannel = _GBCoreGetAudioChannel;
599	core->setAudioBufferSize = _GBCoreSetAudioBufferSize;
600	core->getAudioBufferSize = _GBCoreGetAudioBufferSize;
601	core->setAVStream = _GBCoreSetAVStream;
602	core->addCoreCallbacks = _GBCoreAddCoreCallbacks;
603	core->clearCoreCallbacks = _GBCoreClearCoreCallbacks;
604	core->isROM = GBIsROM;
605	core->loadROM = _GBCoreLoadROM;
606	core->loadBIOS = _GBCoreLoadBIOS;
607	core->loadSave = _GBCoreLoadSave;
608	core->loadTemporarySave = _GBCoreLoadTemporarySave;
609	core->loadPatch = _GBCoreLoadPatch;
610	core->unloadROM = _GBCoreUnloadROM;
611	core->checksum = _GBCoreChecksum;
612	core->reset = _GBCoreReset;
613	core->runFrame = _GBCoreRunFrame;
614	core->runLoop = _GBCoreRunLoop;
615	core->step = _GBCoreStep;
616	core->stateSize = _GBCoreStateSize;
617	core->loadState = _GBCoreLoadState;
618	core->saveState = _GBCoreSaveState;
619	core->setKeys = _GBCoreSetKeys;
620	core->addKeys = _GBCoreAddKeys;
621	core->clearKeys = _GBCoreClearKeys;
622	core->frameCounter = _GBCoreFrameCounter;
623	core->frameCycles = _GBCoreFrameCycles;
624	core->frequency = _GBCoreFrequency;
625	core->getGameTitle = _GBCoreGetGameTitle;
626	core->getGameCode = _GBCoreGetGameCode;
627	core->setPeripheral = _GBCoreSetPeripheral;
628	core->busRead8 = _GBCoreBusRead8;
629	core->busRead16 = _GBCoreBusRead16;
630	core->busRead32 = _GBCoreBusRead32;
631	core->busWrite8 = _GBCoreBusWrite8;
632	core->busWrite16 = _GBCoreBusWrite16;
633	core->busWrite32 = _GBCoreBusWrite32;
634	core->rawRead8 = _GBCoreRawRead8;
635	core->rawRead16 = _GBCoreRawRead16;
636	core->rawRead32 = _GBCoreRawRead32;
637	core->rawWrite8 = _GBCoreRawWrite8;
638	core->rawWrite16 = _GBCoreRawWrite16;
639	core->rawWrite32 = _GBCoreRawWrite32;
640#ifdef USE_DEBUGGERS
641	core->supportsDebuggerType = _GBCoreSupportsDebuggerType;
642	core->debuggerPlatform = _GBCoreDebuggerPlatform;
643	core->cliDebuggerSystem = _GBCoreCliDebuggerSystem;
644	core->attachDebugger = _GBCoreAttachDebugger;
645	core->detachDebugger = _GBCoreDetachDebugger;
646#endif
647	core->cheatDevice = _GBCoreCheatDevice;
648	core->savedataClone = _GBCoreSavedataClone;
649	core->savedataRestore = _GBCoreSavedataRestore;
650	return core;
651}