all repos — mgba @ 012f0a33296c79f1717c09c4d2e9cbc9957a85dc

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