all repos — mgba @ 91c0f95e5f373bc084a050ae55b9fe93c32509cc

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			if (configPath) {
279				bios = VFileOpen(configPath, O_RDONLY);
280			}
281			if (bios && GBIsBIOS(bios)) {
282				found = true;
283			} else if (bios) {
284				bios->close(bios);
285				bios = NULL;
286			}
287		}
288		if (!found) {
289			char path[PATH_MAX];
290			mCoreConfigDirectory(path, PATH_MAX);
291			switch (gb->model) {
292			case GB_MODEL_DMG:
293			case GB_MODEL_SGB: // TODO
294				strncat(path, PATH_SEP "gb_bios.bin", PATH_MAX - strlen(path));
295				break;
296			case GB_MODEL_CGB:
297			case GB_MODEL_AGB:
298				strncat(path, PATH_SEP "gbc_bios.bin", PATH_MAX - strlen(path));
299				break;
300			default:
301				break;
302			};
303			bios = VFileOpen(path, O_RDONLY);
304			if (bios && GBIsBIOS(bios)) {
305				found = true;
306			} else if (bios) {
307				bios->close(bios);
308				bios = NULL;
309			}
310		}
311		if (bios) {
312			GBLoadBIOS(gb, bios);
313		}
314	}
315#endif
316
317	LR35902Reset(core->cpu);
318}
319
320static void _GBCoreRunFrame(struct mCore* core) {
321	struct GB* gb = core->board;
322	int32_t frameCounter = gb->video.frameCounter;
323	while (gb->video.frameCounter == frameCounter) {
324		LR35902Run(core->cpu);
325	}
326}
327
328static void _GBCoreRunLoop(struct mCore* core) {
329	LR35902Run(core->cpu);
330}
331
332static void _GBCoreStep(struct mCore* core) {
333	struct LR35902Core* cpu = core->cpu;
334	do {
335		LR35902Tick(cpu);
336	} while (cpu->executionState != LR35902_CORE_FETCH);
337}
338
339static size_t _GBCoreStateSize(struct mCore* core) {
340	UNUSED(core);
341	return sizeof(struct GBSerializedState);
342}
343
344static bool _GBCoreLoadState(struct mCore* core, const void* state) {
345	return GBDeserialize(core->board, state);
346}
347
348static bool _GBCoreSaveState(struct mCore* core, void* state) {
349	struct LR35902Core* cpu = core->cpu;
350	while (cpu->executionState != LR35902_CORE_FETCH) {
351		LR35902Tick(cpu);
352	}
353	GBSerialize(core->board, state);
354	return true;
355}
356
357static void _GBCoreSetKeys(struct mCore* core, uint32_t keys) {
358	struct GBCore* gbcore = (struct GBCore*) core;
359	gbcore->keys = keys;
360}
361
362static void _GBCoreAddKeys(struct mCore* core, uint32_t keys) {
363	struct GBCore* gbcore = (struct GBCore*) core;
364	gbcore->keys |= keys;
365}
366
367static void _GBCoreClearKeys(struct mCore* core, uint32_t keys) {
368	struct GBCore* gbcore = (struct GBCore*) core;
369	gbcore->keys &= ~keys;
370}
371
372static int32_t _GBCoreFrameCounter(const struct mCore* core) {
373	const struct GB* gb = core->board;
374	return gb->video.frameCounter;
375}
376
377static int32_t _GBCoreFrameCycles(const  struct mCore* core) {
378	UNUSED(core);
379	return GB_VIDEO_TOTAL_LENGTH;
380}
381
382static int32_t _GBCoreFrequency(const struct mCore* core) {
383	UNUSED(core);
384	// TODO: GB differences
385	return DMG_LR35902_FREQUENCY;
386}
387
388static void _GBCoreGetGameTitle(const struct mCore* core, char* title) {
389	GBGetGameTitle(core->board, title);
390}
391
392static void _GBCoreGetGameCode(const struct mCore* core, char* title) {
393	GBGetGameCode(core->board, title);
394}
395
396static void _GBCoreSetRotation(struct mCore* core, struct mRotationSource* rotation) {
397	struct GB* gb = core->board;
398	gb->memory.rotation = rotation;
399}
400
401static void _GBCoreSetRumble(struct mCore* core, struct mRumble* rumble) {
402	struct GB* gb = core->board;
403	gb->memory.rumble = rumble;
404}
405
406static uint32_t _GBCoreBusRead8(struct mCore* core, uint32_t address) {
407	struct LR35902Core* cpu = core->cpu;
408	return cpu->memory.load8(cpu, address);
409}
410
411static uint32_t _GBCoreBusRead16(struct mCore* core, uint32_t address) {
412	struct LR35902Core* cpu = core->cpu;
413	return cpu->memory.load8(cpu, address) | (cpu->memory.load8(cpu, address + 1) << 8);
414}
415
416static uint32_t _GBCoreBusRead32(struct mCore* core, uint32_t address) {
417	struct LR35902Core* cpu = core->cpu;
418	return cpu->memory.load8(cpu, address) | (cpu->memory.load8(cpu, address + 1) << 8) |
419	       (cpu->memory.load8(cpu, address + 2) << 16) | (cpu->memory.load8(cpu, address + 3) << 24);
420}
421
422static void _GBCoreBusWrite8(struct mCore* core, uint32_t address, uint8_t value) {
423	struct LR35902Core* cpu = core->cpu;
424	cpu->memory.store8(cpu, address, value);
425}
426
427static void _GBCoreBusWrite16(struct mCore* core, uint32_t address, uint16_t value) {
428	struct LR35902Core* cpu = core->cpu;
429	cpu->memory.store8(cpu, address, value);
430	cpu->memory.store8(cpu, address + 1, value >> 8);
431}
432
433static void _GBCoreBusWrite32(struct mCore* core, uint32_t address, uint32_t value) {
434	struct LR35902Core* cpu = core->cpu;
435	cpu->memory.store8(cpu, address, value);
436	cpu->memory.store8(cpu, address + 1, value >> 8);
437	cpu->memory.store8(cpu, address + 2, value >> 16);
438	cpu->memory.store8(cpu, address + 3, value >> 24);
439}
440
441static uint32_t _GBCoreRawRead8(struct mCore* core, uint32_t address, int segment) {
442	struct LR35902Core* cpu = core->cpu;
443	return GBView8(cpu, address, segment);
444}
445
446static uint32_t _GBCoreRawRead16(struct mCore* core, uint32_t address, int segment) {
447	struct LR35902Core* cpu = core->cpu;
448	return GBView8(cpu, address, segment) | (GBView8(cpu, address + 1, segment) << 8);
449}
450
451static uint32_t _GBCoreRawRead32(struct mCore* core, uint32_t address, int segment) {
452	struct LR35902Core* cpu = core->cpu;
453	return GBView8(cpu, address, segment) | (GBView8(cpu, address + 1, segment) << 8) |
454	       (GBView8(cpu, address + 2, segment) << 16) | (GBView8(cpu, address + 3, segment) << 24);
455}
456
457static void _GBCoreRawWrite8(struct mCore* core, uint32_t address, int segment, uint8_t value) {
458	struct LR35902Core* cpu = core->cpu;
459	GBPatch8(cpu, address, value, NULL, segment);
460}
461
462static void _GBCoreRawWrite16(struct mCore* core, uint32_t address, int segment, uint16_t value) {
463	struct LR35902Core* cpu = core->cpu;
464	GBPatch8(cpu, address, value, NULL, segment);
465	GBPatch8(cpu, address + 1, value >> 8, NULL, segment);
466}
467
468static void _GBCoreRawWrite32(struct mCore* core, uint32_t address, int segment, uint32_t value) {
469	struct LR35902Core* cpu = core->cpu;
470	GBPatch8(cpu, address, value, NULL, segment);
471	GBPatch8(cpu, address + 1, value >> 8, NULL, segment);
472	GBPatch8(cpu, address + 2, value >> 16, NULL, segment);
473	GBPatch8(cpu, address + 3, value >> 24, NULL, segment);
474}
475
476#ifdef USE_DEBUGGERS
477static bool _GBCoreSupportsDebuggerType(struct mCore* core, enum mDebuggerType type) {
478	UNUSED(core);
479	switch (type) {
480	case DEBUGGER_CLI:
481		return true;
482	default:
483		return false;
484	}
485}
486
487static struct mDebuggerPlatform* _GBCoreDebuggerPlatform(struct mCore* core) {
488	struct GBCore* gbcore = (struct GBCore*) core;
489	if (!gbcore->debuggerPlatform) {
490		gbcore->debuggerPlatform = LR35902DebuggerPlatformCreate();
491	}
492	return gbcore->debuggerPlatform;
493}
494
495static struct CLIDebuggerSystem* _GBCoreCliDebuggerSystem(struct mCore* core) {
496	return GBCLIDebuggerCreate(core);
497}
498
499static void _GBCoreAttachDebugger(struct mCore* core, struct mDebugger* debugger) {
500	struct LR35902Core* cpu = core->cpu;
501	if (core->debugger) {
502		LR35902HotplugDetach(cpu, CPU_COMPONENT_DEBUGGER);
503	}
504	cpu->components[CPU_COMPONENT_DEBUGGER] = &debugger->d;
505	LR35902HotplugAttach(cpu, CPU_COMPONENT_DEBUGGER);
506	core->debugger = debugger;
507}
508
509static void _GBCoreDetachDebugger(struct mCore* core) {
510	struct LR35902Core* cpu = core->cpu;
511	if (core->debugger) {
512		LR35902HotplugDetach(cpu, CPU_COMPONENT_DEBUGGER);
513	}
514	cpu->components[CPU_COMPONENT_DEBUGGER] = NULL;
515	core->debugger = NULL;
516}
517#endif
518
519static struct mCheatDevice* _GBCoreCheatDevice(struct mCore* core) {
520	struct GBCore* gbcore = (struct GBCore*) core;
521	if (!gbcore->cheatDevice) {
522		gbcore->cheatDevice = GBCheatDeviceCreate();
523		((struct LR35902Core*) core->cpu)->components[CPU_COMPONENT_CHEAT_DEVICE] = &gbcore->cheatDevice->d;
524		LR35902HotplugAttach(core->cpu, CPU_COMPONENT_CHEAT_DEVICE);
525		gbcore->cheatDevice->p = core;
526	}
527	return gbcore->cheatDevice;
528}
529
530static size_t _GBCoreSavedataClone(struct mCore* core, void** sram) {
531	struct GB* gb = core->board;
532	struct VFile* vf = gb->sramVf;
533	if (vf) {
534		*sram = malloc(vf->size(vf));
535		vf->seek(vf, 0, SEEK_SET);
536		return vf->read(vf, *sram, vf->size(vf));
537	}
538	*sram = malloc(gb->sramSize);
539	memcpy(*sram, gb->memory.sram, gb->sramSize);
540	return gb->sramSize;
541}
542
543static bool _GBCoreSavedataRestore(struct mCore* core, const void* sram, size_t size, bool writeback) {
544	struct GB* gb = core->board;
545	if (!writeback) {
546		struct VFile* vf = VFileMemChunk(sram, size);
547		GBSavedataMask(gb, vf, true);
548		return true;
549	}
550	struct VFile* vf = gb->sramVf;
551	if (vf) {
552		vf->seek(vf, 0, SEEK_SET);
553		return vf->write(vf, sram, size) > 0;
554	}
555	if (size > 0x20000) {
556		size = 0x20000;
557	}
558	GBResizeSram(gb, size);
559	memcpy(gb->memory.sram, sram, size);
560	return true;
561}
562
563struct mCore* GBCoreCreate(void) {
564	struct GBCore* gbcore = malloc(sizeof(*gbcore));
565	struct mCore* core = &gbcore->d;
566	memset(&core->opts, 0, sizeof(core->opts));
567	core->cpu = NULL;
568	core->board = NULL;
569	core->debugger = NULL;
570	core->init = _GBCoreInit;
571	core->deinit = _GBCoreDeinit;
572	core->platform = _GBCorePlatform;
573	core->setSync = _GBCoreSetSync;
574	core->loadConfig = _GBCoreLoadConfig;
575	core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions;
576	core->setVideoBuffer = _GBCoreSetVideoBuffer;
577	core->getPixels = _GBCoreGetPixels;
578	core->putPixels = _GBCorePutPixels;
579	core->getAudioChannel = _GBCoreGetAudioChannel;
580	core->setAudioBufferSize = _GBCoreSetAudioBufferSize;
581	core->getAudioBufferSize = _GBCoreGetAudioBufferSize;
582	core->setAVStream = _GBCoreSetAVStream;
583	core->addCoreCallbacks = _GBCoreAddCoreCallbacks;
584	core->clearCoreCallbacks = _GBCoreClearCoreCallbacks;
585	core->isROM = GBIsROM;
586	core->loadROM = _GBCoreLoadROM;
587	core->loadBIOS = _GBCoreLoadBIOS;
588	core->loadSave = _GBCoreLoadSave;
589	core->loadTemporarySave = _GBCoreLoadTemporarySave;
590	core->loadPatch = _GBCoreLoadPatch;
591	core->unloadROM = _GBCoreUnloadROM;
592	core->checksum = _GBCoreChecksum;
593	core->reset = _GBCoreReset;
594	core->runFrame = _GBCoreRunFrame;
595	core->runLoop = _GBCoreRunLoop;
596	core->step = _GBCoreStep;
597	core->stateSize = _GBCoreStateSize;
598	core->loadState = _GBCoreLoadState;
599	core->saveState = _GBCoreSaveState;
600	core->setKeys = _GBCoreSetKeys;
601	core->addKeys = _GBCoreAddKeys;
602	core->clearKeys = _GBCoreClearKeys;
603	core->frameCounter = _GBCoreFrameCounter;
604	core->frameCycles = _GBCoreFrameCycles;
605	core->frequency = _GBCoreFrequency;
606	core->getGameTitle = _GBCoreGetGameTitle;
607	core->getGameCode = _GBCoreGetGameCode;
608	core->setRotation = _GBCoreSetRotation;
609	core->setRumble = _GBCoreSetRumble;
610	core->busRead8 = _GBCoreBusRead8;
611	core->busRead16 = _GBCoreBusRead16;
612	core->busRead32 = _GBCoreBusRead32;
613	core->busWrite8 = _GBCoreBusWrite8;
614	core->busWrite16 = _GBCoreBusWrite16;
615	core->busWrite32 = _GBCoreBusWrite32;
616	core->rawRead8 = _GBCoreRawRead8;
617	core->rawRead16 = _GBCoreRawRead16;
618	core->rawRead32 = _GBCoreRawRead32;
619	core->rawWrite8 = _GBCoreRawWrite8;
620	core->rawWrite16 = _GBCoreRawWrite16;
621	core->rawWrite32 = _GBCoreRawWrite32;
622#ifdef USE_DEBUGGERS
623	core->supportsDebuggerType = _GBCoreSupportsDebuggerType;
624	core->debuggerPlatform = _GBCoreDebuggerPlatform;
625	core->cliDebuggerSystem = _GBCoreCliDebuggerSystem;
626	core->attachDebugger = _GBCoreAttachDebugger;
627	core->detachDebugger = _GBCoreDetachDebugger;
628#endif
629	core->cheatDevice = _GBCoreCheatDevice;
630	core->savedataClone = _GBCoreSavedataClone;
631	core->savedataRestore = _GBCoreSavedataRestore;
632	return core;
633}