struct mCore* mCoreFind(const char* path) { struct VDir* archive = VDirOpenArchive(path); struct mCore* core = NULL; if (archive) { struct VDirEntry* dirent = archive->listNext(archive); while (dirent) { struct VFile* vf = archive->openFile(archive, dirent->name(dirent), O_RDONLY); if (!vf) { dirent = archive->listNext(archive); continue; } core = mCoreFindVF(vf); vf->close(vf); if (core) { break; } dirent = archive->listNext(archive); } archive->close(archive); } else { struct VFile* vf = VFileOpen(path, O_RDONLY); if (!vf) { return NULL; } core = mCoreFindVF(vf); vf->close(vf); } if (core) { return core; } return NULL; }
void _mLibraryAddEntry(struct mLibrary* library, const char* filename, const char* base, struct VFile* vf) { struct mCore* core; if (!vf) { return; } core = mCoreFindVF(vf); if (core) { struct mLibraryEntry entry; memset(&entry, 0, sizeof(entry)); core->init(core); core->loadROM(core, vf); core->getGameTitle(core, entry.internalTitle); core->getGameCode(core, entry.internalCode); core->checksum(core, &entry.crc32, CHECKSUM_CRC32); entry.platform = core->platform(core); entry.title = NULL; entry.base = base; entry.filename = filename; entry.filesize = vf->size(vf); _mLibraryInsertEntry(library, &entry); // Note: this destroys the VFile core->deinit(core); } else { vf->close(vf); } }
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 = mCoreFindVF(rom); if (!core) { rom->close(rom); mappedMemoryFree(data, game->size); return false; } mCoreInitConfig(core, NULL); core->init(core); core->setAVStream(core, &stream); size_t size = 256 * 224 * BYTES_PER_PIXEL; outputBuffer = malloc(size); memset(outputBuffer, 0xFF, size); 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->setPeripheral(core, mPERIPH_RUMBLE, &rumble); savedata = anonymousMemoryMap(SIZE_CART_FLASH1M); struct VFile* save = VFileFromMemory(savedata, SIZE_CART_FLASH1M); _reloadSettings(); core->loadROM(core, rom); core->loadSave(core, save); const char* sysDir = 0; const char* biosName = 0; char biosPath[PATH_MAX]; environCallback(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &sysDir); #ifdef M_CORE_GBA if (core->platform(core) == PLATFORM_GBA) { core->setPeripheral(core, mPERIPH_GBA_LUMINANCE, &lux); biosName = "gba_bios.bin"; } #endif #ifdef M_CORE_GB if (core->platform(core) == PLATFORM_GB) { memset(&cam, 0, sizeof(cam)); cam.height = GBCAM_HEIGHT; cam.width = GBCAM_WIDTH; cam.caps = 1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER; cam.frame_raw_framebuffer = _updateCamera; core->setPeripheral(core, mPERIPH_IMAGE_SOURCE, &imageSource); environCallback(RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE, &cam); const char* modelName = mCoreConfigGetValue(&core->config, "gb.model"); struct GB* gb = core->board; if (modelName) { gb->model = GBNameToModel(modelName); } else { GBDetectModel(gb); } switch (gb->model) { case GB_MODEL_AGB: case GB_MODEL_CGB: biosName = "gbc_bios.bin"; break; case GB_MODEL_SGB: biosName = "sgb_bios.bin"; break; case GB_MODEL_DMG: default: biosName = "gb_bios.bin"; break; } } #endif if (core->opts.useBios && sysDir && biosName) { snprintf(biosPath, sizeof(biosPath), "%s%s%s", sysDir, PATH_SEP, biosName); struct VFile* bios = VFileOpen(biosPath, O_RDONLY); if (bios) { core->loadBIOS(core, bios, 0); } } core->reset(core); _setupMaps(core); return true; }