* Miscellaneous functions, including savestates and CD-ROM loading.
*/
+#include <stddef.h>
#include "misc.h"
#include "cdrom.h"
#include "mdec.h"
#include "gpu.h"
#include "ppf.h"
+#include "database.h"
#include <zlib.h>
char CdromId[10] = "";
tmpHead.t_addr = SWAP32(tmpHead.t_addr);
psxCpu->Clear(tmpHead.t_addr, tmpHead.t_size / 4);
+ psxCpu->Reset();
// Read the rest of the main executable
while (tmpHead.t_size & ~2047) {
addr = head->t_addr;
psxCpu->Clear(addr, size / 4);
+ psxCpu->Reset();
while (size & ~2047) {
incTime();
strcpy(CdromId, "SLUS99999");
if (Config.PsxAuto) { // autodetect system (pal or ntsc)
- if (CdromId[2] == 'e' || CdromId[2] == 'E')
+ if (
+ /* Make sure Wild Arms SCUS-94608 is not detected as a PAL game. */
+ ((CdromId[0] == 's' || CdromId[0] == 'S') && (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 (CdromLabel[0] == ' ') {
- memcpy(CdromLabel, CdromId, 9);
+ 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);
+
+ Apply_Hacks_Cdrom();
BuildPPFCache();
current = ftell(f);
fseek(f, 0L, SEEK_SET);
- fread(mybuf, 2048, 1, f);
+ if (fread(&mybuf, sizeof(mybuf), 1, f) != sizeof(mybuf))
+ goto io_fail;
+
fseek(f, current, SEEK_SET);
exe_hdr = (EXE_HEADER *)mybuf;
return COFF_EXE;
return INVALID_EXE;
+
+io_fail:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ return INVALID_EXE;
}
// temporary pandora workaround..
type = PSXGetFileType(tmpFile);
switch (type) {
case PSX_EXE:
- fread(&tmpHead,sizeof(EXE_HEADER),1,tmpFile);
+ if (fread(&tmpHead, sizeof(EXE_HEADER), 1, tmpFile) != sizeof(EXE_HEADER))
+ goto fail_io;
section_address = SWAP32(tmpHead.t_addr);
section_size = SWAP32(tmpHead.t_size);
mem = PSXM(section_address);
fread_to_ram(mem, section_size, 1, tmpFile);
psxCpu->Clear(section_address, section_size / 4);
}
- fclose(tmpFile);
psxRegs.pc = SWAP32(tmpHead.pc0);
psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0);
psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr);
case CPE_EXE:
fseek(tmpFile, 6, SEEK_SET); /* Something tells me we should go to 4 and read the "08 00" here... */
do {
- fread(&opcode, 1, 1, tmpFile);
+ if (fread(&opcode, sizeof(opcode), 1, tmpFile) != sizeof(opcode))
+ goto fail_io;
switch (opcode) {
case 1: /* Section loading */
- fread(§ion_address, 4, 1, tmpFile);
- fread(§ion_size, 4, 1, tmpFile);
+ if (fread(§ion_address, sizeof(section_address), 1, tmpFile) != sizeof(section_address))
+ goto fail_io;
+ if (fread(§ion_size, sizeof(section_size), 1, tmpFile) != sizeof(section_size))
+ goto fail_io;
section_address = SWAPu32(section_address);
section_size = SWAPu32(section_size);
#ifdef EMU_LOG
break;
case 3: /* register loading (PC only?) */
fseek(tmpFile, 2, SEEK_CUR); /* unknown field */
- fread(&psxRegs.pc, 4, 1, tmpFile);
+ if (fread(&psxRegs.pc, sizeof(psxRegs.pc), 1, tmpFile) != sizeof(psxRegs.pc))
+ goto fail_io;
psxRegs.pc = SWAPu32(psxRegs.pc);
break;
case 0: /* End of file */
CdromLabel[0] = '\0';
}
+ fclose(tmpFile);
return retval;
+
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ fclose(tmpFile);
+ return -1;
}
// STATES
SaveFuncs.write(f, psxM, 0x00200000);
SaveFuncs.write(f, psxR, 0x00080000);
SaveFuncs.write(f, psxH, 0x00010000);
- SaveFuncs.write(f, (void *)&psxRegs, sizeof(psxRegs));
+ // only partial save of psxRegisters to maintain savestate compat
+ SaveFuncs.write(f, &psxRegs, offsetof(psxRegisters, gteBusyCycle));
// gpu
gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t));
SaveFuncs.read(f, psxM, 0x00200000);
SaveFuncs.read(f, psxR, 0x00080000);
SaveFuncs.read(f, psxH, 0x00010000);
- SaveFuncs.read(f, (void *)&psxRegs, sizeof(psxRegs));
+ SaveFuncs.read(f, &psxRegs, offsetof(psxRegisters, gteBusyCycle));
+ psxRegs.gteBusyCycle = psxRegs.cycle;
if (Config.HLE)
psxBiosFreeze(0);
NET_recvData(&Config.Cpu, sizeof(Config.Cpu), PSE_NET_BLOCKING);
if (tmp != Config.Cpu) {
psxCpu->Shutdown();
-#if defined(NEW_DYNAREC) || defined(LIGHTREC)
+#ifndef DRC_DISABLE
if (Config.Cpu == CPU_INTERPRETER) psxCpu = &psxInt;
else psxCpu = &psxRec;
#else