all repos — mgba @ af2db9073c10043143eac79bd2f3ced9c36fb0e9

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