void emu_updateMovie(void) { int offs = Pico.m.frame_count*3 + 0x40; if (offs+3 > movie_size) { free(movie_data); movie_data = 0; strcpy(noticeMsg, "END OF MOVIE."); lprintf("END OF MOVIE.\n"); emu_noticeMsgUpdated(); } else { // MXYZ SACB RLDU PicoPad[0] = ~movie_data[offs] & 0x8f; // ! SCBA RLDU if(!(movie_data[offs] & 0x10)) PicoPad[0] |= 0x40; // A if(!(movie_data[offs] & 0x20)) PicoPad[0] |= 0x10; // B if(!(movie_data[offs] & 0x40)) PicoPad[0] |= 0x20; // A PicoPad[1] = ~movie_data[offs+1] & 0x8f; // ! SCBA RLDU if(!(movie_data[offs+1] & 0x10)) PicoPad[1] |= 0x40; // A if(!(movie_data[offs+1] & 0x20)) PicoPad[1] |= 0x10; // B if(!(movie_data[offs+1] & 0x40)) PicoPad[1] |= 0x20; // A PicoPad[0] |= (~movie_data[offs+2] & 0x0A) << 8; // ! MZYX if(!(movie_data[offs+2] & 0x01)) PicoPad[0] |= 0x0400; // X if(!(movie_data[offs+2] & 0x04)) PicoPad[0] |= 0x0100; // Z PicoPad[1] |= (~movie_data[offs+2] & 0xA0) << 4; // ! MZYX if(!(movie_data[offs+2] & 0x10)) PicoPad[1] |= 0x0400; // X if(!(movie_data[offs+2] & 0x40)) PicoPad[1] |= 0x0100; // Z } }
int emu_ReloadRom(void) { unsigned int rom_size = 0; char *used_rom_name = romFileName; char ext[5]; pm_file *rom; int ret, cd_state, cd_region, cfg_loaded = 0; lprintf("emu_ReloadRom(%s)\n", romFileName); get_ext(romFileName, ext); // detect wrong extensions if(!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz sprintf(menuErrorMsg, "Not a ROM selected."); return 0; } PicoPatchUnload(); // check for movie file if(movie_data) { free(movie_data); movie_data = 0; } #if 0 if(!strcmp(ext, ".gmv")) { // check for both gmv and rom int dummy; FILE *movie_file = fopen(romFileName, "rb"); if(!movie_file) { sprintf(menuErrorMsg, "Failed to open movie."); return 0; } fseek(movie_file, 0, SEEK_END); movie_size = ftell(movie_file); fseek(movie_file, 0, SEEK_SET); if(movie_size < 64+3) { sprintf(menuErrorMsg, "Invalid GMV file."); fclose(movie_file); return 0; } movie_data = malloc(movie_size); if(movie_data == NULL) { sprintf(menuErrorMsg, "low memory."); fclose(movie_file); return 0; } fread(movie_data, 1, movie_size, movie_file); fclose(movie_file); if (strncmp((char *)movie_data, "Gens Movie TEST", 15) != 0) { sprintf(menuErrorMsg, "Invalid GMV file."); return 0; } dummy = try_rfn_cut() || try_rfn_cut(); if (!dummy) { sprintf(menuErrorMsg, "Could't find a ROM for movie."); return 0; } get_ext(romFileName, ext); } else if (!strcmp(ext, ".pat")) { int dummy; PicoPatchLoad(romFileName); dummy = try_rfn_cut() || try_rfn_cut(); if (!dummy) { sprintf(menuErrorMsg, "Could't find a ROM to patch."); return 0; } get_ext(romFileName, ext); } #else // load GG patches list char ggFname[512]; romfname_ext(ggFname, NULL, ".cht"); PicoPatchLoad(ggFname); #endif if ((PicoMCD & 1) && Pico_mcd != NULL) Stop_CD(); // check for MegaCD image cd_state = emu_cdCheck(&cd_region); if (cd_state > 0) { // valid CD image, check for BIOS.. #if 0 // we need to have config loaded at this point ret = emu_ReadConfig(READ_CONFIG_FOR_GAME, READ_CONFIG_SKIP_DEF); if (!ret) emu_ReadConfig(READ_CONFIG_GLOBAL, READ_CONFIG_SKIP_DEF); #endif cfg_loaded = 1; if (PicoRegionOverride) { cd_region = PicoRegionOverride; lprintf("overrided region to %s\n", cd_region != 4 ? (cd_region == 8 ? "EU" : "JAP") : "USA"); } if (!emu_findBios(cd_region, &used_rom_name)) { // bios_help() ? return 0; } PicoMCD |= 1; get_ext(used_rom_name, ext); } else { if (PicoMCD & 1) Stop_CD(); PicoMCD &= ~1; } ips_define(ipsFileName); rom = pm_open(used_rom_name); if(!rom) { sprintf(menuErrorMsg, "Failed to open rom."); return 0; } menu_romload_prepare(used_rom_name); // also CD load if(rom_data) { free(rom_data); rom_data = 0; rom_size = 0; } if( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) { sprintf(menuErrorMsg, "PicoCartLoad() failed."); lprintf("%s\n", menuErrorMsg); pm_close(rom); menu_romload_end(); return 0; } pm_close(rom); // detect wrong files (Pico crashes on very small files), also see if ROM EP is good if(rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 || ((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) { if (rom_data) free(rom_data); rom_data = 0; sprintf(menuErrorMsg, "Not a ROM selected."); menu_romload_end(); return 0; } #if 0 // load config for this ROM (do this before insert to get correct region) if (!cfg_loaded) { ret = emu_ReadConfig(READ_CONFIG_FOR_GAME, READ_CONFIG_SKIP_DEF); if (!ret) emu_ReadConfig(READ_CONFIG_GLOBAL, READ_CONFIG_SKIP_DEF); } #endif lprintf("PicoCartInsert(%p, %d);\n", rom_data, rom_size); if(PicoCartInsert(rom_data, rom_size)) { sprintf(menuErrorMsg, "Failed to load ROM."); menu_romload_end(); return 0; } Pico.m.frame_count = 0; // insert CD if it was detected if (cd_state > 0) { ret = Insert_CD(romFileName, cd_state == 2); if (ret != 0) { sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?"); lprintf("%s\n", menuErrorMsg); menu_romload_end(); return 0; } } menu_romload_end(); #if 0 if (!emu_isBios(romFileName)) { // emu_ReadConfig() might have messed currentConfig.lastRomFile strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1); currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0; } #endif if (PicoPatches) { PicoPatchPrepare(); PicoPatchApply(); } // additional movie stuff if (movie_data) { if(movie_data[0x14] == '6') PicoOpt |= PicoOpt_6button_gamepad; // 6 button pad else PicoOpt &= ~PicoOpt_6button_gamepad; PicoOpt |= (PicoOpt_accurate_timing | PicoOpt_disable_vdp_fifo); // accurate timing, no VDP fifo timing if(movie_data[0xF] >= 'A') { if(movie_data[0x16] & 0x80) { PicoRegionOverride = 8; } else { PicoRegionOverride = 4; } PicoReset(0); // TODO: bits 6 & 5 } movie_data[0x18+30] = 0; sprintf(noticeMsg, "MOVIE: %s", (char *) &movie_data[0x18]); } else { PicoOpt &= ~PicoOpt_disable_vdp_fifo; if(Pico.m.pal) { strcpy(noticeMsg, "PAL SYSTEM / 50 FPS"); } else { strcpy(noticeMsg, "NTSC SYSTEM / 60 FPS"); } } emu_noticeMsgUpdated(); // load SRAM for this ROM emu_SaveLoadSRAM(1); return 1; }
int emu_SaveLoadGame(int load, int sram) { int ret = 0; char *saveFname; // make save filename saveFname = emu_GetSaveFName(load, sram, state_slot); if (saveFname == NULL) { if (!sram) { strcpy(noticeMsg, load ? "LOAD FAILED (missing file)" : "SAVE FAILED "); emu_noticeMsgUpdated(); } return -1; } lprintf("saveLoad (%i, %i): %s\n", load, sram, saveFname); if (sram) { FILE *sramFile; int sram_size; unsigned char *sram_data; int truncate = 1; if (PicoMCD&1) { if (PicoOpt&0x8000) { // MCD RAM cart? sram_size = 0x12000; sram_data = SRam.data; if (sram_data) memcpy32((int *)sram_data, (int *)Pico_mcd->bram, 0x2000/4); } else { sram_size = 0x2000; sram_data = Pico_mcd->bram; truncate = 0; // the .brm may contain RAM cart data after normal brm } } else { sram_size = SRam.end-SRam.start+1; if(Pico.m.sram_reg & 4) sram_size=0x2000; sram_data = SRam.data; } if (!sram_data) return 0; // SRam forcefully disabled for this game if (load) { sramFile = fopen(saveFname, "rb"); if(!sramFile) return -1; fread(sram_data, 1, sram_size, sramFile); fclose(sramFile); if ((PicoMCD&1) && (PicoOpt&0x8000)) memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4); } else { // sram save needs some special processing // see if we have anything to save for (; sram_size > 0; sram_size--) if (sram_data[sram_size-1]) break; if (sram_size) { sramFile = fopen(saveFname, truncate ? "wb" : "r+b"); if (!sramFile) sramFile = fopen(saveFname, "wb"); // retry if (!sramFile) return -1; ret = fwrite(sram_data, 1, sram_size, sramFile); ret = (ret != sram_size) ? -1 : 0; fclose(sramFile); #ifndef NO_SYNC sync(); #endif } } return ret; } else { void *PmovFile = NULL; if (strcmp(saveFname + strlen(saveFname) - 3, ".gz") == 0) { if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) { emu_setSaveStateCbs(1); if (!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY); } } else { if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) { emu_setSaveStateCbs(0); } } if(PmovFile) { ret = PmovState(load ? 6 : 5, PmovFile); areaClose(PmovFile); PmovFile = 0; if (load) Pico.m.dirtyPal=1; #ifndef NO_SYNC else sync(); #endif } else ret = -1; if (!ret) strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED "); else { strcpy(noticeMsg, load ? "LOAD FAILED " : "SAVE FAILED "); ret = -1; } emu_noticeMsgUpdated(); return ret; } }