void EmuShutdown() { ClearAllCheats(); FreeCheatSearchResults(); FreeCheatSearchMem(); FreePPFCache(); psxShutdown(); }
void BuildPPFCache() { FILE *ppffile; char buffer[12]; char method, undo = 0, blockcheck = 0; int dizlen, dizyn; unsigned char ppfmem[512]; char szPPF[MAXPATHLEN]; int count, seekpos, pos; u32 anz; // use 32-bit to avoid stupid overflows s32 ladr, off, anx; FreePPFCache(); if (CdromId[0] == '\0') return; // Generate filename in the format of SLUS_123.45 buffer[0] = toupper(CdromId[0]); buffer[1] = toupper(CdromId[1]); buffer[2] = toupper(CdromId[2]); buffer[3] = toupper(CdromId[3]); buffer[4] = '_'; buffer[5] = CdromId[4]; buffer[6] = CdromId[5]; buffer[7] = CdromId[6]; buffer[8] = '.'; buffer[9] = CdromId[7]; buffer[10] = CdromId[8]; buffer[11] = '\0'; sprintf(szPPF, "%s%s", Config.PatchesDir, buffer); ppffile = fopen(szPPF, "rb"); if (ppffile == NULL) return; memset(buffer, 0, 5); fread(buffer, 3, 1, ppffile); if (strcmp(buffer, "PPF") != 0) { SysPrintf(_("Invalid PPF patch: %s.\n"), szPPF); fclose(ppffile); return; } fseek(ppffile, 5, SEEK_SET); method = fgetc(ppffile); switch (method) { case 0: // ppf1 fseek(ppffile, 0, SEEK_END); count = ftell(ppffile); count -= 56; seekpos = 56; break; case 1: // ppf2 fseek(ppffile, -8, SEEK_END); memset(buffer, 0, 5); fread(buffer, 4, 1, ppffile); if (strcmp(".DIZ", buffer) != 0) { dizyn = 0; } else { fread(&dizlen, 4, 1, ppffile); dizlen = SWAP32(dizlen); dizyn = 1; } fseek(ppffile, 0, SEEK_END); count = ftell(ppffile); if (dizyn == 0) { count -= 1084; seekpos = 1084; } else { count -= 1084; count -= 38; count -= dizlen; seekpos = 1084; } break; case 2: // ppf3 fseek(ppffile, 57, SEEK_SET); blockcheck = fgetc(ppffile); undo = fgetc(ppffile); fseek(ppffile, -6, SEEK_END); memset(buffer, 0, 5); fread(buffer, 4, 1, ppffile); dizlen = 0; if (strcmp(".DIZ", buffer) == 0) { fseek(ppffile, -2, SEEK_END); fread(&dizlen, 2, 1, ppffile); dizlen = SWAP32(dizlen); dizlen += 36; } fseek(ppffile, 0, SEEK_END); count = ftell(ppffile); count -= dizlen; if (blockcheck) { seekpos = 1084; count -= 1084; } else { seekpos = 60; count -= 60; } break; default: fclose(ppffile); SysPrintf(_("Unsupported PPF version (%d).\n"), method + 1); return; } // now do the data reading do { fseek(ppffile, seekpos, SEEK_SET); fread(&pos, 4, 1, ppffile); pos = SWAP32(pos); if (method == 2) fread(buffer, 4, 1, ppffile); // skip 4 bytes on ppf3 (no int64 support here) anz = fgetc(ppffile); fread(ppfmem, anz, 1, ppffile); ladr = pos / CD_FRAMESIZE_RAW; off = pos % CD_FRAMESIZE_RAW; if (off + anz > CD_FRAMESIZE_RAW) { anx = off + anz - CD_FRAMESIZE_RAW; anz -= (unsigned char)anx; AddToPPF(ladr + 1, 0, anx, &ppfmem[anz]); } AddToPPF(ladr, off, anz, ppfmem); // add to link list if (method == 2) { if (undo) anz += anz; anz += 4; } seekpos = seekpos + 5 + anz; count = count - 5 - anz; } while (count != 0); // loop til end fclose(ppffile); FillPPFCache(); // build address array SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, szPPF); }
int CheckCdrom() { struct iso_directory_record *dir; unsigned char time[4], *buf; unsigned char mdir[4096]; char exename[256]; int i, len, c; FreePPFCache(); time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); READTRACK(); memset(CdromLabel, 0, sizeof(CdromLabel)); memset(CdromId, 0, sizeof(CdromId)); memset(exename, 0, sizeof(exename)); strncpy(CdromLabel, buf + 52, 32); // skip head and sub, and go to the root directory record dir = (struct iso_directory_record *)&buf[12 + 156]; mmssdd(dir->extent, (char *)time); READDIR(mdir); if (GetCdromFile(mdir, time, "SYSTEM.CNF;1") != -1) { READTRACK(); sscanf((char *)buf + 12, "BOOT = cdrom:\\%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { sscanf((char *)buf + 12, "BOOT = cdrom:%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { char *ptr = strstr(buf + 12, "cdrom:"); // possibly the executable is in some subdir if (ptr != NULL) { ptr += 6; while (*ptr == '\\' || *ptr == '/') ptr++; strncpy(exename, ptr, 255); exename[255] = '\0'; ptr = exename; while (*ptr != '\0' && *ptr != '\r' && *ptr != '\n') ptr++; *ptr = '\0'; if (GetCdromFile(mdir, time, exename) == -1) return -1; // main executable not found } else return -1; } } } else if (GetCdromFile(mdir, time, "PSX.EXE;1") != -1) { strcpy(exename, "PSX.EXE;1"); strcpy(CdromId, "SLUS99999"); } else return -1; // SYSTEM.CNF and PSX.EXE not found if (CdromId[0] == '\0') { len = strlen(exename); c = 0; for (i = 0; i < len; ++i) { if (exename[i] == ';' || c >= sizeof(CdromId) - 1) break; if (isalnum(exename[i])) CdromId[c++] = exename[i]; } } if (Config.PsxAuto) { // autodetect system (pal or ntsc) if((CdromId[2] == 'e') || (CdromId[2] == 'E') || !strncmp(CdromId, "DTLS3035", 8) || !strncmp(CdromId, "PBPX95001", 9) || // according to redump.org, these PAL !strncmp(CdromId, "PBPX95007", 9) || // discs have a non-standard ID; !strncmp(CdromId, "PBPX95008", 9)) // add more serials if they are discovered. Config.PsxType = PSX_TYPE_PAL; // pal else Config.PsxType = PSX_TYPE_NTSC; // ntsc } if (Config.PsxStock == 0) { PsxClockSpeed = 33868800; // 33.8688 MHz (stock) } else { if (Config.PsxClock == 0) { PsxClockSpeed = 16934400; // 16.9344 MHz (0.5x) } if (Config.PsxClock == 1) { PsxClockSpeed = 25401600; // 25.4016 MHz (0.75x) } if (Config.PsxClock == 2) { PsxClockSpeed = 50803200; // 50.8032 MHz (1.5x) } if (Config.PsxClock == 3) { PsxClockSpeed = 67737600; // 67.7376 MHz (2x) } if (Config.PsxClock == 4) { PsxClockSpeed = 101606400; // 101.6064 MHz (3x) } if (Config.PsxClock == 5) { PsxClockSpeed = 135475200; // 135.4752 MHz (4x) } if (Config.PsxClock == 6) { PsxClockSpeed = 169344000; // 169.3440 MHz (5x) } } if (CdromLabel[0] == ' ') { strncpy(CdromLabel, CdromId, 9); } SysPrintf(_("CD-ROM Label: %.32s\n"), CdromLabel); SysPrintf(_("CD-ROM ID: %.9s\n"), CdromId); SysPrintf(_("CD-ROM EXE Name: %.255s\n"), exename); BuildPPFCache(); LoadSBI(NULL); return 0; }
int CheckCdrom() { struct iso_directory_record *dir; unsigned char time[4]; char *buf; unsigned char mdir[4096]; char exename[256]; int i, c; FreePPFCache(); time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); READTRACK(); CdromLabel[0] = '\0'; CdromId[0] = '\0'; strncpy(CdromLabel, buf + 52, 32); // skip head and sub, and go to the root directory record dir = (struct iso_directory_record *)&buf[12 + 156]; mmssdd(dir->extent, (char *)time); READDIR(mdir); if (GetCdromFile(mdir, time, "SYSTEM.CNF;1") != -1) { READTRACK(); sscanf(buf + 12, "BOOT = cdrom:\\%256s", exename); if (GetCdromFile(mdir, time, exename) == -1) { sscanf(buf + 12, "BOOT = cdrom:%256s", exename); if (GetCdromFile(mdir, time, exename) == -1) { char *ptr = strstr(buf + 12, "cdrom:"); // possibly the executable is in some subdir if (ptr != NULL) { ptr += 6; while (*ptr == '\\' || *ptr == '/') ptr++; strncpy(exename, ptr, 255); exename[255] = '\0'; ptr = exename; while (*ptr != '\0' && *ptr != '\r' && *ptr != '\n') ptr++; *ptr = '\0'; if (GetCdromFile(mdir, time, exename) == -1) return -1; // main executable not found } else return -1; } } } else if (GetCdromFile(mdir, time, "PSX.EXE;1") != -1) { strcpy(exename, "PSX.EXE;1"); strcpy(CdromId, "SLUS99999"); } else return -1; // SYSTEM.CNF and PSX.EXE not found if (CdromId[0] == '\0') { i = strlen(exename); if (i >= 2) { if (exename[i - 2] == ';') i-= 2; c = 8; i--; while (i >= 0 && c >= 0) { if (isalnum(exename[i])) CdromId[c--] = exename[i]; i--; } } } if (CdromId[0] == '\0') strcpy(CdromId, "SLUS99999"); if (Config.PsxAuto) { // autodetect system (pal or ntsc) if (CdromId[2] == 'e' || CdromId[2] == 'E') Config.PsxType = PSX_TYPE_PAL; // pal else Config.PsxType = PSX_TYPE_NTSC; // ntsc } if (CdromLabel[0] == ' ') { strncpy(CdromLabel, CdromId, 9); } SysPrintf(_("CD-ROM Label: %.32s\n"), CdromLabel); SysPrintf(_("CD-ROM ID: %.9s\n"), CdromId); BuildPPFCache(); return 0; }