all repos — mgba @ d03528d4daf55a2b64f47562c36663ba2318d0fe

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
 23#ifndef MINIMAL_CORE
 24#include <mgba/internal/gba/input.h>
 25#endif
 26
 27struct GBCore {
 28	struct mCore d;
 29	struct GBVideoSoftwareRenderer renderer;
 30	uint8_t keys;
 31	struct mCPUComponent* components[CPU_COMPONENT_MAX];
 32	const struct Configuration* overrides;
 33	struct mDebuggerPlatform* debuggerPlatform;
 34	struct mCheatDevice* cheatDevice;
 35};
 36
 37static bool _GBCoreInit(struct mCore* core) {
 38	struct GBCore* gbcore = (struct GBCore*) core;
 39
 40	struct LR35902Core* cpu = anonymousMemoryMap(sizeof(struct LR35902Core));
 41	struct GB* gb = anonymousMemoryMap(sizeof(struct GB));
 42	if (!cpu || !gb) {
 43		free(cpu);
 44		free(gb);
 45		return false;
 46	}
 47	core->cpu = cpu;
 48	core->board = gb;
 49	gbcore->overrides = NULL;
 50	gbcore->debuggerPlatform = NULL;
 51	gbcore->cheatDevice = NULL;
 52
 53	GBCreate(gb);
 54	memset(gbcore->components, 0, sizeof(gbcore->components));
 55	LR35902SetComponents(cpu, &gb->d, CPU_COMPONENT_MAX, gbcore->components);
 56	LR35902Init(cpu);
 57	mRTCGenericSourceInit(&core->rtc, core);
 58	gb->memory.rtc = &core->rtc.d;
 59
 60	GBVideoSoftwareRendererCreate(&gbcore->renderer);
 61	gbcore->renderer.outputBuffer = NULL;
 62
 63	gbcore->keys = 0;
 64	gb->keySource = &gbcore->keys;
 65
 66#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
 67	mDirectorySetInit(&core->dirs);
 68#endif
 69
 70#ifndef MINIMAL_CORE
 71	core->inputInfo = &GBAInputInfo; // TODO: GBInputInfo
 72#endif
 73
 74	return true;
 75}
 76
 77static void _GBCoreDeinit(struct mCore* core) {
 78	LR35902Deinit(core->cpu);
 79	GBDestroy(core->board);
 80	mappedMemoryFree(core->cpu, sizeof(struct LR35902Core));
 81	mappedMemoryFree(core->board, sizeof(struct GB));
 82#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
 83	mDirectorySetDeinit(&core->dirs);
 84#endif
 85
 86	struct GBCore* gbcore = (struct GBCore*) core;
 87	free(gbcore->debuggerPlatform);
 88	if (gbcore->cheatDevice) {
 89		mCheatDeviceDestroy(gbcore->cheatDevice);
 90	}
 91	free(gbcore->cheatDevice);
 92	mCoreConfigFreeOpts(&core->opts);
 93	free(core);
 94}
 95
 96static enum mPlatform _GBCorePlatform(const struct mCore* core) {
 97	UNUSED(core);
 98	return PLATFORM_GB;
 99}
100
101static void _GBCoreSetSync(struct mCore* core, struct mCoreSync* sync) {
102	struct GB* gb = core->board;
103	gb->sync = sync;
104}
105
106static void _GBCoreLoadConfig(struct mCore* core, const struct mCoreConfig* config) {
107	UNUSED(config);
108
109	struct GB* gb = core->board;
110	if (core->opts.mute) {
111		gb->audio.masterVolume = 0;
112	} else {
113		gb->audio.masterVolume = core->opts.volume;
114	}
115	gb->video.frameskip = core->opts.frameskip;
116	mCoreConfigCopyValue(&core->config, config, "gb.bios");
117	mCoreConfigCopyValue(&core->config, config, "gbc.bios");
118
119#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
120	struct GBCore* gbcore = (struct GBCore*) core;
121	gbcore->overrides = mCoreConfigGetOverridesConst(config);
122#endif
123}
124
125static void _GBCoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) {
126	UNUSED(core);
127	*width = GB_VIDEO_HORIZONTAL_PIXELS;
128	*height = GB_VIDEO_VERTICAL_PIXELS;
129}
130
131static void _GBCoreSetVideoBuffer(struct mCore* core, color_t* buffer, size_t stride) {
132	struct GBCore* gbcore = (struct GBCore*) core;
133	gbcore->renderer.outputBuffer = buffer;
134	gbcore->renderer.outputBufferStride = stride;
135}
136
137static void _GBCoreGetPixels(struct mCore* core, const void** buffer, size_t* stride) {
138	struct GBCore* gbcore = (struct GBCore*) core;
139	gbcore->renderer.d.getPixels(&gbcore->renderer.d, stride, buffer);
140}
141
142static void _GBCorePutPixels(struct mCore* core, const void* buffer, size_t stride) {
143	struct GBCore* gbcore = (struct GBCore*) core;
144	gbcore->renderer.d.putPixels(&gbcore->renderer.d, stride, buffer);
145}
146
147static struct blip_t* _GBCoreGetAudioChannel(struct mCore* core, int ch) {
148	struct GB* gb = core->board;
149	switch (ch) {
150	case 0:
151		return gb->audio.left;
152	case 1:
153		return gb->audio.right;
154	default:
155		return NULL;
156	}
157}
158
159static void _GBCoreSetAudioBufferSize(struct mCore* core, size_t samples) {
160	struct GB* gb = core->board;
161	GBAudioResizeBuffer(&gb->audio, samples);
162}
163
164static size_t _GBCoreGetAudioBufferSize(struct mCore* core) {
165	struct GB* gb = core->board;
166	return gb->audio.samples;
167}
168
169static void _GBCoreAddCoreCallbacks(struct mCore* core, struct mCoreCallbacks* coreCallbacks) {
170	struct GB* gb = core->board;
171	*mCoreCallbacksListAppend(&gb->coreCallbacks) = *coreCallbacks;
172}
173
174static void _GBCoreClearCoreCallbacks(struct mCore* core) {
175	struct GB* gb = core->board;
176	mCoreCallbacksListClear(&gb->coreCallbacks);
177}
178
179static void _GBCoreSetAVStream(struct mCore* core, struct mAVStream* stream) {
180	struct GB* gb = core->board;
181	gb->stream = stream;
182	if (stream && stream->videoDimensionsChanged) {
183		stream->videoDimensionsChanged(stream, GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS);
184	}
185}
186
187static bool _GBCoreLoadROM(struct mCore* core, struct VFile* vf) {
188	return GBLoadROM(core->board, vf);
189}
190
191static bool _GBCoreLoadBIOS(struct mCore* core, struct VFile* vf, int type) {
192	UNUSED(type);
193	GBLoadBIOS(core->board, vf);
194	return true;
195}
196
197static bool _GBCoreLoadSave(struct mCore* core, struct VFile* vf) {
198	return GBLoadSave(core->board, vf);
199}
200
201static bool _GBCoreLoadTemporarySave(struct mCore* core, struct VFile* vf) {
202	struct GB* gb = core->board;
203	GBSavedataMask(gb, vf, false);
204	return true; // TODO: Return a real value
205}
206
207static bool _GBCoreLoadPatch(struct mCore* core, struct VFile* vf) {
208	if (!vf) {
209		return false;
210	}
211	struct Patch patch;
212	if (!loadPatch(vf, &patch)) {
213		return false;
214	}
215	GBApplyPatch(core->board, &patch);
216	return true;
217}
218
219static void _GBCoreUnloadROM(struct mCore* core) {
220	struct GBCore* gbcore = (struct GBCore*) core;
221	struct LR35902Core* cpu = core->cpu;
222	if (gbcore->cheatDevice) {
223		LR35902HotplugDetach(cpu, CPU_COMPONENT_CHEAT_DEVICE);
224		cpu->components[CPU_COMPONENT_CHEAT_DEVICE] = NULL;
225		mCheatDeviceDestroy(gbcore->cheatDevice);
226		gbcore->cheatDevice = NULL;
227	}
228	return GBUnloadROM(core->board);
229}
230
231static void _GBCoreChecksum(const struct mCore* core, void* data, enum mCoreChecksumType type) {
232	struct GB* gb = (struct GB*) core->board;
233	switch (type) {
234	case CHECKSUM_CRC32:
235		memcpy(data, &gb->romCrc32, sizeof(gb->romCrc32));
236		break;
237	}
238	return;
239}
240
241static void _GBCoreReset(struct mCore* core) {
242	struct GBCore* gbcore = (struct GBCore*) core;
243	struct GB* gb = (struct GB*) core->board;
244	if (gbcore->renderer.outputBuffer) {
245		GBVideoAssociateRenderer(&gb->video, &gbcore->renderer.d);
246	}
247
248	if (gb->memory.rom) {
249		struct GBCartridgeOverride override;
250		const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100];
251		override.headerCrc32 = doCrc32(cart, sizeof(*cart));
252		if (GBOverrideFind(gbcore->overrides, &override)) {
253			GBOverrideApply(gb, &override);
254		}
255	}
256
257#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
258	if (!gb->biosVf && core->opts.useBios) {
259		struct VFile* bios = NULL;
260		bool found = false;
261		if (core->opts.bios) {
262			bios = VFileOpen(core->opts.bios, O_RDONLY);
263			if (bios && GBIsBIOS(bios)) {
264				found = true;
265			} else if (bios) {
266				bios->close(bios);
267				bios = NULL;
268			}
269		}
270		if (!found) {
271			GBDetectModel(gb);
272			const char* configPath;
273
274			switch (gb->model) {
275			case GB_MODEL_DMG:
276			case GB_MODEL_SGB: // TODO
277				configPath = mCoreConfigGetValue(&core->config, "gb.bios");
278				break;
279			case GB_MODEL_CGB:
280			case GB_MODEL_AGB:
281				configPath = mCoreConfigGetValue(&core->config, "gbc.bios");
282				break;
283			default:
284				break;
285			};
286			if (configPath) {
287				bios = VFileOpen(configPath, O_RDONLY);
288			}
289			if (bios && GBIsBIOS(bios)) {
290				found = true;
291			} else if (bios) {
292				bios->close(bios);
293				bios = NULL;
294			}
295		}
296		if (!found) {
297			char path[PATH_MAX];
298			mCoreConfigDirectory(path, PATH_MAX);
299			switch (gb->model) {
300			case GB_MODEL_DMG:
301			case GB_MODEL_SGB: // TODO
302				strncat(path, PATH_SEP "gb_bios.bin", PATH_MAX - strlen(path));
303				break;
304			case GB_MODEL_CGB:
305			case GB_MODEL_AGB:
306				strncat(path, PATH_SEP "gbc_bios.bin", PATH_MAX - strlen(path));
307				break;
308			default:
309				break;
310			};
311			bios = VFileOpen(path, O_RDONLY);
312			if (bios && GBIsBIOS(bios)) {
313				found = true;
314			} else if (bios) {
315				bios->close(bios);
316				bios = NULL;
317			}
318		}
319		if (bios) {
320			GBLoadBIOS(gb, bios);
321		}
322	}
323#endif
324
325	LR35902Reset(core->cpu);
326}
327
328static void _GBCoreRunFrame(struct mCore* core) {
329	struct GB* gb = core->board;
330	int32_t frameCounter = gb->video.frameCounter;
331	while (gb->video.frameCounter == frameCounter) {
332		LR35902Run(core->cpu);
333	}
334}
335
336static void _GBCoreRunLoop(struct mCore* core) {
337	LR35902Run(core->cpu);
338}
339
340static void _GBCoreStep(struct mCore* core) {
341	struct LR35902Core* cpu = core->cpu;
342	do {
343		LR35902Tick(cpu);
344	} while (cpu->executionState != LR35902_CORE_FETCH);
345}
346
347static size_t _GBCoreStateSize(struct mCore* core) {
348	UNUSED(core);
349	return sizeof(struct GBSerializedState);
350}
351
352static bool _GBCoreLoadState(struct mCore* core, const void* state) {
353	return GBDeserialize(core->board, state);
354}
355
356static bool _GBCoreSaveState(struct mCore* core, void* state) {
357	struct LR35902Core* cpu = core->cpu;
358	while (cpu->executionState != LR35902_CORE_FETCH) {
359		LR35902Tick(cpu);
360	}
361	GBSerialize(core->board, state);
362	return true;
363}
364
365static void _GBCoreSetKeys(struct mCore* core, uint32_t keys) {
366	struct GBCore* gbcore = (struct GBCore*) core;
367	gbcore->keys = keys;
368}
369
370static void _GBCoreAddKeys(struct mCore* core, uint32_t keys) {
371	struct GBCore* gbcore = (struct GBCore*) core;
372	gbcore->keys |= keys;
373}
374
375static void _GBCoreClearKeys(struct mCore* core, uint32_t keys) {
376	struct GBCore* gbcore = (struct GBCore*) core;
377	gbcore->keys &= ~keys;
378}
379
380static void _GBCoreSetCursorLocation(struct mCore* core, int x, int y) {
381	UNUSED(core);
382	UNUSED(x);
383	UNUSED(y);
384}
385
386static void _GBCoreSetCursorDown(struct mCore* core, bool down) {
387	UNUSED(core);
388	UNUSED(down);
389}
390
391static int32_t _GBCoreFrameCounter(const struct mCore* core) {
392	const struct GB* gb = core->board;
393	return gb->video.frameCounter;
394}
395
396static int32_t _GBCoreFrameCycles(const  struct mCore* core) {
397	UNUSED(core);
398	return GB_VIDEO_TOTAL_LENGTH;
399}
400
401static int32_t _GBCoreFrequency(const struct mCore* core) {
402	UNUSED(core);
403	// TODO: GB differences
404	return DMG_LR35902_FREQUENCY;
405}
406
407static void _GBCoreGetGameTitle(const struct mCore* core, char* title) {
408	GBGetGameTitle(core->board, title);
409}
410
411static void _GBCoreGetGameCode(const struct mCore* core, char* title) {
412	GBGetGameCode(core->board, title);
413}
414
415static void _GBCoreSetRotation(struct mCore* core, struct mRotationSource* rotation) {
416	struct GB* gb = core->board;
417	gb->memory.rotation = rotation;
418}
419
420static void _GBCoreSetRumble(struct mCore* core, struct mRumble* rumble) {
421	struct GB* gb = core->board;
422	gb->memory.rumble = rumble;
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->setCursorLocation = _GBCoreSetCursorLocation;
623	core->setCursorDown = _GBCoreSetCursorDown;
624	core->frameCounter = _GBCoreFrameCounter;
625	core->frameCycles = _GBCoreFrameCycles;
626	core->frequency = _GBCoreFrequency;
627	core->getGameTitle = _GBCoreGetGameTitle;
628	core->getGameCode = _GBCoreGetGameCode;
629	core->setRotation = _GBCoreSetRotation;
630	core->setRumble = _GBCoreSetRumble;
631	core->busRead8 = _GBCoreBusRead8;
632	core->busRead16 = _GBCoreBusRead16;
633	core->busRead32 = _GBCoreBusRead32;
634	core->busWrite8 = _GBCoreBusWrite8;
635	core->busWrite16 = _GBCoreBusWrite16;
636	core->busWrite32 = _GBCoreBusWrite32;
637	core->rawRead8 = _GBCoreRawRead8;
638	core->rawRead16 = _GBCoreRawRead16;
639	core->rawRead32 = _GBCoreRawRead32;
640	core->rawWrite8 = _GBCoreRawWrite8;
641	core->rawWrite16 = _GBCoreRawWrite16;
642	core->rawWrite32 = _GBCoreRawWrite32;
643#ifdef USE_DEBUGGERS
644	core->supportsDebuggerType = _GBCoreSupportsDebuggerType;
645	core->debuggerPlatform = _GBCoreDebuggerPlatform;
646	core->cliDebuggerSystem = _GBCoreCliDebuggerSystem;
647	core->attachDebugger = _GBCoreAttachDebugger;
648	core->detachDebugger = _GBCoreDetachDebugger;
649#endif
650	core->cheatDevice = _GBCoreCheatDevice;
651	core->savedataClone = _GBCoreSavedataClone;
652	core->savedataRestore = _GBCoreSavedataRestore;
653	return core;
654}