all repos — mgba @ ba65740b159a2ce3bceecf1088f859f326d69b34

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 _GBCoreSetRotation(struct mCore* core, struct mRotationSource* rotation) {
412	struct GB* gb = core->board;
413	gb->memory.rotation = rotation;
414}
415
416static void _GBCoreSetRumble(struct mCore* core, struct mRumble* rumble) {
417	struct GB* gb = core->board;
418	gb->memory.rumble = rumble;
419}
420
421static uint32_t _GBCoreBusRead8(struct mCore* core, uint32_t address) {
422	struct LR35902Core* cpu = core->cpu;
423	return cpu->memory.load8(cpu, address);
424}
425
426static uint32_t _GBCoreBusRead16(struct mCore* core, uint32_t address) {
427	struct LR35902Core* cpu = core->cpu;
428	return cpu->memory.load8(cpu, address) | (cpu->memory.load8(cpu, address + 1) << 8);
429}
430
431static uint32_t _GBCoreBusRead32(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	       (cpu->memory.load8(cpu, address + 2) << 16) | (cpu->memory.load8(cpu, address + 3) << 24);
435}
436
437static void _GBCoreBusWrite8(struct mCore* core, uint32_t address, uint8_t value) {
438	struct LR35902Core* cpu = core->cpu;
439	cpu->memory.store8(cpu, address, value);
440}
441
442static void _GBCoreBusWrite16(struct mCore* core, uint32_t address, uint16_t value) {
443	struct LR35902Core* cpu = core->cpu;
444	cpu->memory.store8(cpu, address, value);
445	cpu->memory.store8(cpu, address + 1, value >> 8);
446}
447
448static void _GBCoreBusWrite32(struct mCore* core, uint32_t address, uint32_t value) {
449	struct LR35902Core* cpu = core->cpu;
450	cpu->memory.store8(cpu, address, value);
451	cpu->memory.store8(cpu, address + 1, value >> 8);
452	cpu->memory.store8(cpu, address + 2, value >> 16);
453	cpu->memory.store8(cpu, address + 3, value >> 24);
454}
455
456static uint32_t _GBCoreRawRead8(struct mCore* core, uint32_t address, int segment) {
457	struct LR35902Core* cpu = core->cpu;
458	return GBView8(cpu, address, segment);
459}
460
461static uint32_t _GBCoreRawRead16(struct mCore* core, uint32_t address, int segment) {
462	struct LR35902Core* cpu = core->cpu;
463	return GBView8(cpu, address, segment) | (GBView8(cpu, address + 1, segment) << 8);
464}
465
466static uint32_t _GBCoreRawRead32(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	       (GBView8(cpu, address + 2, segment) << 16) | (GBView8(cpu, address + 3, segment) << 24);
470}
471
472static void _GBCoreRawWrite8(struct mCore* core, uint32_t address, int segment, uint8_t value) {
473	struct LR35902Core* cpu = core->cpu;
474	GBPatch8(cpu, address, value, NULL, segment);
475}
476
477static void _GBCoreRawWrite16(struct mCore* core, uint32_t address, int segment, uint16_t value) {
478	struct LR35902Core* cpu = core->cpu;
479	GBPatch8(cpu, address, value, NULL, segment);
480	GBPatch8(cpu, address + 1, value >> 8, NULL, segment);
481}
482
483static void _GBCoreRawWrite32(struct mCore* core, uint32_t address, int segment, uint32_t value) {
484	struct LR35902Core* cpu = core->cpu;
485	GBPatch8(cpu, address, value, NULL, segment);
486	GBPatch8(cpu, address + 1, value >> 8, NULL, segment);
487	GBPatch8(cpu, address + 2, value >> 16, NULL, segment);
488	GBPatch8(cpu, address + 3, value >> 24, NULL, segment);
489}
490
491#ifdef USE_DEBUGGERS
492static bool _GBCoreSupportsDebuggerType(struct mCore* core, enum mDebuggerType type) {
493	UNUSED(core);
494	switch (type) {
495	case DEBUGGER_CLI:
496		return true;
497	default:
498		return false;
499	}
500}
501
502static struct mDebuggerPlatform* _GBCoreDebuggerPlatform(struct mCore* core) {
503	struct GBCore* gbcore = (struct GBCore*) core;
504	if (!gbcore->debuggerPlatform) {
505		gbcore->debuggerPlatform = LR35902DebuggerPlatformCreate();
506	}
507	return gbcore->debuggerPlatform;
508}
509
510static struct CLIDebuggerSystem* _GBCoreCliDebuggerSystem(struct mCore* core) {
511	return GBCLIDebuggerCreate(core);
512}
513
514static void _GBCoreAttachDebugger(struct mCore* core, struct mDebugger* debugger) {
515	struct LR35902Core* cpu = core->cpu;
516	if (core->debugger) {
517		LR35902HotplugDetach(cpu, CPU_COMPONENT_DEBUGGER);
518	}
519	cpu->components[CPU_COMPONENT_DEBUGGER] = &debugger->d;
520	LR35902HotplugAttach(cpu, CPU_COMPONENT_DEBUGGER);
521	core->debugger = debugger;
522}
523
524static void _GBCoreDetachDebugger(struct mCore* core) {
525	struct LR35902Core* cpu = core->cpu;
526	if (core->debugger) {
527		LR35902HotplugDetach(cpu, CPU_COMPONENT_DEBUGGER);
528	}
529	cpu->components[CPU_COMPONENT_DEBUGGER] = NULL;
530	core->debugger = NULL;
531}
532#endif
533
534static struct mCheatDevice* _GBCoreCheatDevice(struct mCore* core) {
535	struct GBCore* gbcore = (struct GBCore*) core;
536	if (!gbcore->cheatDevice) {
537		gbcore->cheatDevice = GBCheatDeviceCreate();
538		((struct LR35902Core*) core->cpu)->components[CPU_COMPONENT_CHEAT_DEVICE] = &gbcore->cheatDevice->d;
539		LR35902HotplugAttach(core->cpu, CPU_COMPONENT_CHEAT_DEVICE);
540		gbcore->cheatDevice->p = core;
541	}
542	return gbcore->cheatDevice;
543}
544
545static size_t _GBCoreSavedataClone(struct mCore* core, void** sram) {
546	struct GB* gb = core->board;
547	struct VFile* vf = gb->sramVf;
548	if (vf) {
549		*sram = malloc(vf->size(vf));
550		vf->seek(vf, 0, SEEK_SET);
551		return vf->read(vf, *sram, vf->size(vf));
552	}
553	*sram = malloc(gb->sramSize);
554	memcpy(*sram, gb->memory.sram, gb->sramSize);
555	return gb->sramSize;
556}
557
558static bool _GBCoreSavedataRestore(struct mCore* core, const void* sram, size_t size, bool writeback) {
559	struct GB* gb = core->board;
560	if (!writeback) {
561		struct VFile* vf = VFileMemChunk(sram, size);
562		GBSavedataMask(gb, vf, true);
563		return true;
564	}
565	struct VFile* vf = gb->sramVf;
566	if (vf) {
567		vf->seek(vf, 0, SEEK_SET);
568		return vf->write(vf, sram, size) > 0;
569	}
570	if (size > 0x20000) {
571		size = 0x20000;
572	}
573	GBResizeSram(gb, size);
574	memcpy(gb->memory.sram, sram, size);
575	return true;
576}
577
578struct mCore* GBCoreCreate(void) {
579	struct GBCore* gbcore = malloc(sizeof(*gbcore));
580	struct mCore* core = &gbcore->d;
581	memset(&core->opts, 0, sizeof(core->opts));
582	core->cpu = NULL;
583	core->board = NULL;
584	core->debugger = NULL;
585	core->init = _GBCoreInit;
586	core->deinit = _GBCoreDeinit;
587	core->platform = _GBCorePlatform;
588	core->setSync = _GBCoreSetSync;
589	core->loadConfig = _GBCoreLoadConfig;
590	core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions;
591	core->setVideoBuffer = _GBCoreSetVideoBuffer;
592	core->getPixels = _GBCoreGetPixels;
593	core->putPixels = _GBCorePutPixels;
594	core->getAudioChannel = _GBCoreGetAudioChannel;
595	core->setAudioBufferSize = _GBCoreSetAudioBufferSize;
596	core->getAudioBufferSize = _GBCoreGetAudioBufferSize;
597	core->setAVStream = _GBCoreSetAVStream;
598	core->addCoreCallbacks = _GBCoreAddCoreCallbacks;
599	core->clearCoreCallbacks = _GBCoreClearCoreCallbacks;
600	core->isROM = GBIsROM;
601	core->loadROM = _GBCoreLoadROM;
602	core->loadBIOS = _GBCoreLoadBIOS;
603	core->loadSave = _GBCoreLoadSave;
604	core->loadTemporarySave = _GBCoreLoadTemporarySave;
605	core->loadPatch = _GBCoreLoadPatch;
606	core->unloadROM = _GBCoreUnloadROM;
607	core->checksum = _GBCoreChecksum;
608	core->reset = _GBCoreReset;
609	core->runFrame = _GBCoreRunFrame;
610	core->runLoop = _GBCoreRunLoop;
611	core->step = _GBCoreStep;
612	core->stateSize = _GBCoreStateSize;
613	core->loadState = _GBCoreLoadState;
614	core->saveState = _GBCoreSaveState;
615	core->setKeys = _GBCoreSetKeys;
616	core->addKeys = _GBCoreAddKeys;
617	core->clearKeys = _GBCoreClearKeys;
618	core->frameCounter = _GBCoreFrameCounter;
619	core->frameCycles = _GBCoreFrameCycles;
620	core->frequency = _GBCoreFrequency;
621	core->getGameTitle = _GBCoreGetGameTitle;
622	core->getGameCode = _GBCoreGetGameCode;
623	core->setRotation = _GBCoreSetRotation;
624	core->setRumble = _GBCoreSetRumble;
625	core->busRead8 = _GBCoreBusRead8;
626	core->busRead16 = _GBCoreBusRead16;
627	core->busRead32 = _GBCoreBusRead32;
628	core->busWrite8 = _GBCoreBusWrite8;
629	core->busWrite16 = _GBCoreBusWrite16;
630	core->busWrite32 = _GBCoreBusWrite32;
631	core->rawRead8 = _GBCoreRawRead8;
632	core->rawRead16 = _GBCoreRawRead16;
633	core->rawRead32 = _GBCoreRawRead32;
634	core->rawWrite8 = _GBCoreRawWrite8;
635	core->rawWrite16 = _GBCoreRawWrite16;
636	core->rawWrite32 = _GBCoreRawWrite32;
637#ifdef USE_DEBUGGERS
638	core->supportsDebuggerType = _GBCoreSupportsDebuggerType;
639	core->debuggerPlatform = _GBCoreDebuggerPlatform;
640	core->cliDebuggerSystem = _GBCoreCliDebuggerSystem;
641	core->attachDebugger = _GBCoreAttachDebugger;
642	core->detachDebugger = _GBCoreDetachDebugger;
643#endif
644	core->cheatDevice = _GBCoreCheatDevice;
645	core->savedataClone = _GBCoreSavedataClone;
646	core->savedataRestore = _GBCoreSavedataRestore;
647	return core;
648}