bool retro_load_game(const struct retro_game_info* game) { struct VFile* rom; if (game->data) { data = anonymousMemoryMap(game->size); dataSize = game->size; memcpy(data, game->data, game->size); rom = VFileFromMemory(data, game->size); } else { data = 0; rom = VFileOpen(game->path, O_RDONLY); } if (!rom) { return false; } core = NULL; #ifdef M_CORE_GBA if (!core && GBAIsROM(rom)) { core = GBACoreCreate(); } #endif #ifdef M_CORE_GB if (!core && GBIsROM(rom)) { core = GBCoreCreate(); } #endif if (!core) { rom->close(rom); mappedMemoryFree(data, game->size); return false; } mCoreInitConfig(core, NULL); core->init(core); core->setAVStream(core, &stream); outputBuffer = malloc(256 * VIDEO_VERTICAL_PIXELS * BYTES_PER_PIXEL); core->setVideoBuffer(core, outputBuffer, 256); core->setAudioBufferSize(core, SAMPLES); blip_set_rates(core->getAudioChannel(core, 0), core->frequency(core), 32768); blip_set_rates(core->getAudioChannel(core, 1), core->frequency(core), 32768); core->setRumble(core, &rumble); #ifdef M_CORE_GBA if (core->platform(core) == PLATFORM_GBA) { struct GBA* gba = core->board; gba->luminanceSource = &lux; const char* sysDir = 0; if (environCallback(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &sysDir)) { char biosPath[PATH_MAX]; snprintf(biosPath, sizeof(biosPath), "%s%s%s", sysDir, PATH_SEP, "gba_bios.bin"); struct VFile* bios = VFileOpen(biosPath, O_RDONLY); if (bios) { core->loadBIOS(core, bios, 0); } } GBACheatDeviceCreate(&cheats); GBACheatAttachDevice(gba, &cheats); GBACheatSetInit(&cheatSet, "libretro"); GBACheatAddSet(&cheats, &cheatSet); } #endif savedata = anonymousMemoryMap(SIZE_CART_FLASH1M); struct VFile* save = VFileFromMemory(savedata, SIZE_CART_FLASH1M); _reloadSettings(); core->loadROM(core, rom); core->loadSave(core, save); core->reset(core); return true; }
void retro_cheat_reset(void) { GBACheatSetDeinit(&cheatSet); GBACheatSetInit(&cheatSet, "libretro"); }
bool GBACheatParseFile(struct GBACheatDevice* device, struct VFile* vf) { char cheat[MAX_LINE_LENGTH]; struct GBACheatSet* set = 0; struct GBACheatSet* newSet; int gsaVersion = 0; bool nextDisabled = false; bool reset = false; while (true) { size_t i = 0; ssize_t bytesRead = vf->readline(vf, cheat, sizeof(cheat)); if (bytesRead == 0) { break; } if (bytesRead < 0) { return false; } while (isspace((int) cheat[i])) { ++i; } switch (cheat[i]) { case '#': do { ++i; } while (isspace((int) cheat[i])); newSet = malloc(sizeof(*set)); GBACheatSetInit(newSet, &cheat[i]); newSet->enabled = !nextDisabled; nextDisabled = false; if (set) { GBACheatAddSet(device, set); } if (set && !reset) { GBACheatSetCopyProperties(newSet, set); } else { GBACheatSetGameSharkVersion(newSet, gsaVersion); } reset = false; set = newSet; break; case '!': do { ++i; } while (isspace((int) cheat[i])); if (strncasecmp(&cheat[i], "GSAv", 4) == 0 || strncasecmp(&cheat[i], "PARv", 4) == 0) { i += 4; gsaVersion = atoi(&cheat[i]); break; } if (strcasecmp(&cheat[i], "disabled") == 0) { nextDisabled = true; break; } if (strcasecmp(&cheat[i], "reset") == 0) { reset = true; break; } break; default: if (!set) { set = malloc(sizeof(*set)); GBACheatSetInit(set, 0); set->enabled = !nextDisabled; nextDisabled = false; GBACheatSetGameSharkVersion(set, gsaVersion); } GBACheatAddLine(set, cheat); break; } } if (set) { GBACheatAddSet(device, set); } return true; }