string Utility::selectCartridge() { audio.clear(); QString filename = QFileDialog::getOpenFileName(0, "Load Cartridge", utf8() << (config.path.rom != "" ? config.path.rom : config.path.current), "SNES images (*.smc *.sfc *.swc *.fig *.bs *.st" #if defined(GZIP_SUPPORT) " *.zip *.gz" #endif #if defined(JMA_SUPPORT) " *.jma" #endif ");;" "All files (*)" ); string name = filename.toUtf8().constData(); if(strlen(name) > 0) config.path.current = basepath(name); return name; } string Utility::selectFolder(const char *title) { audio.clear(); QString pathname = QFileDialog::getExistingDirectory(0, title, utf8() << config.path.current, QFileDialog::ShowDirsOnly); string path = pathname.toUtf8().constData(); strtr(path, "\\", "/"); if(strend(path, "/") == false) path << "/"; return path; } void Utility::loadCartridge(const char *filename) { SNES::MappedRAM memory; if(loadCartridge(filename, memory) == false) return; SNES::Cartridge::Type type = SNES::cartridge.detect_image_type(memory.data(), memory.size()); memory.reset(); switch(type) { case SNES::Cartridge::TypeNormal: loadCartridgeNormal(filename); break; case SNES::Cartridge::TypeBsxSlotted: winLoader->loadBsxSlottedCartridge(filename, ""); break; case SNES::Cartridge::TypeBsxBios: winLoader->loadBsxCartridge(filename, ""); break; case SNES::Cartridge::TypeBsx: winLoader->loadBsxCartridge(config.path.bsx, filename); break; case SNES::Cartridge::TypeSufamiTurboBios: winLoader->loadSufamiTurboCartridge(filename, "", ""); break; case SNES::Cartridge::TypeSufamiTurbo: winLoader->loadSufamiTurboCartridge(config.path.st, filename, ""); break; case SNES::Cartridge::TypeSuperGameBoyBios: winLoader->loadSuperGameBoyCartridge(filename, ""); break; case SNES::Cartridge::TypeGameBoy: winLoader->loadSuperGameBoyCartridge(config.path.sgb, filename); break; } } bool Utility::loadCartridgeNormal(const char *base) { unloadCartridge(); if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false; SNES::cartridge.load(SNES::Cartridge::ModeNormal); loadMemory(cartridge.baseName, ".srm", SNES::memory::cartram); loadMemory(cartridge.baseName, ".rtc", SNES::memory::cartrtc); cartridge.name = basename(base); modifySystemState(LoadCartridge); return true; } bool Utility::loadCartridgeBsxSlotted(const char *base, const char *slot) { unloadCartridge(); if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false; loadCartridge(cartridge.slotAName = slot, SNES::memory::bsxflash); SNES::cartridge.load(SNES::Cartridge::ModeBsxSlotted); loadMemory(cartridge.baseName, ".srm", SNES::memory::cartram); loadMemory(cartridge.baseName, ".rtc", SNES::memory::cartrtc); cartridge.name = basename(base); if(*slot) cartridge.name << " + " << basename(slot); modifySystemState(LoadCartridge); return true; } bool Utility::loadCartridgeBsx(const char *base, const char *slot) { unloadCartridge(); if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false; loadCartridge(cartridge.slotAName = slot, SNES::memory::bsxflash); SNES::cartridge.load(SNES::Cartridge::ModeBsx); loadMemory(cartridge.baseName, ".srm", SNES::memory::bsxram ); loadMemory(cartridge.baseName, ".psr", SNES::memory::bsxpram); cartridge.name = (*slot ? basename(slot) : basename(base)); modifySystemState(LoadCartridge); return true; } bool Utility::loadCartridgeSufamiTurbo(const char *base, const char *slotA, const char *slotB) { unloadCartridge(); if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false; loadCartridge(cartridge.slotAName = slotA, SNES::memory::stArom); loadCartridge(cartridge.slotBName = slotB, SNES::memory::stBrom); SNES::cartridge.load(SNES::Cartridge::ModeSufamiTurbo); loadMemory(cartridge.slotAName, ".srm", SNES::memory::stAram); loadMemory(cartridge.slotBName, ".srm", SNES::memory::stBram); if(!*slotA && !*slotB) cartridge.name = basename(base); else if(!*slotB) cartridge.name = basename(slotA); else if(!*slotA) cartridge.name = basename(slotB); else cartridge.name = string() << basename(slotA) << " + " << basename(slotB); modifySystemState(LoadCartridge); return true; } bool Utility::loadCartridgeSuperGameBoy(const char *base, const char *slot) { unloadCartridge(); if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false; loadCartridge(cartridge.slotAName = slot, SNES::memory::gbrom); SNES::cartridge.load(SNES::Cartridge::ModeSuperGameBoy); loadMemory(cartridge.slotAName, ".sav", SNES::memory::gbram); cartridge.name = (*slot ? basename(slot) : basename(base)); modifySystemState(LoadCartridge); return true; } void Utility::saveMemory() { if(SNES::cartridge.loaded() == false) return; switch(SNES::cartridge.mode()) { case SNES::Cartridge::ModeNormal: case SNES::Cartridge::ModeBsxSlotted: { saveMemory(cartridge.baseName, ".srm", SNES::memory::cartram); saveMemory(cartridge.baseName, ".rtc", SNES::memory::cartrtc); } break; case SNES::Cartridge::ModeBsx: { saveMemory(cartridge.baseName, ".srm", SNES::memory::bsxram ); saveMemory(cartridge.baseName, ".psr", SNES::memory::bsxpram); } break; case SNES::Cartridge::ModeSufamiTurbo: { saveMemory(cartridge.slotAName, ".srm", SNES::memory::stAram); saveMemory(cartridge.slotBName, ".srm", SNES::memory::stBram); } break; case SNES::Cartridge::ModeSuperGameBoy: { saveMemory(cartridge.slotAName, ".sav", SNES::memory::gbram); } break; } } void Utility::unloadCartridge() { if(SNES::cartridge.loaded() == false) return; saveMemory(); modifySystemState(UnloadCartridge); } void Utility::modifySystemState(system_state_t state) { video.clear(); audio.clear(); switch(state) { case LoadCartridge: { //must call cartridge.load_cart_...() before calling modifySystemState(LoadCartridge) if(SNES::cartridge.loaded() == false) break; loadCheats(); application.power = true; application.pause = false; SNES::system.power(); //warn if unsupported hardware detected string chip; if(SNES::cartridge.has_superfx()) chip = "SuperFX"; else if(SNES::cartridge.has_st011()) chip = "ST011"; else if(SNES::cartridge.has_st018()) chip = "ST018"; else if(SNES::cartridge.has_dsp3()) chip = "DSP-3"; //unplayable; only partially supported if(chip != "") { QMessageBox::warning(winMain->window, "Warning", utf8() << "
Warning:
Unsupported " << chip << " chip detected. "
<< "It is unlikely that this title will work properly.