all repos — mgba @ a5bcfc7c80db49fadd652677ed4a3b87c6f235e5

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