m = ((m / 10) << 4) | m % 10;
s = ((s / 10) << 4) | s % 10;
- d = ((d / 10) << 4) | d % 10;
+ d = ((d / 10) << 4) | d % 10;
p[0] = m;
p[1] = s;
READTRACK();
// skip head and sub, and go to the root directory record
- dir = (struct iso_directory_record*) &buf[12+156];
+ dir = (struct iso_directory_record*) &buf[12+156];
mmssdd(dir->extent, (char*)time);
psxRegs.pc = SWAP32(tmpHead.pc0);
psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0);
- psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr);
+ psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr);
if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00;
tmpHead.t_size = SWAP32(tmpHead.t_size);
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) {
READTRACK();
// skip head and sub, and go to the root directory record
- dir = (struct iso_directory_record *)&buf[12 + 156];
+ dir = (struct iso_directory_record *)&buf[12 + 156];
mmssdd(dir->extent, (char*)time);
addr = head->t_addr;
psxCpu->Clear(addr, size / 4);
+ psxCpu->Reset();
while (size & ~2047) {
incTime();
strncpy(CdromLabel, buf + 52, 32);
// skip head and sub, and go to the root directory record
- dir = (struct iso_directory_record *)&buf[12 + 156];
+ dir = (struct iso_directory_record *)&buf[12 + 156];
mmssdd(dir->extent, (char *)time);
return -1;
}
}
+ /* Workaround for Wild Arms EU/US which has non-standard string causing incorrect region detection */
+ if (exename[0] == 'E' && exename[1] == 'X' && exename[2] == 'E' && exename[3] == '\\') {
+ size_t offset = 4;
+ size_t i, len = strlen(exename) - offset;
+ for (i = 0; i < len; i++)
+ exename[i] = exename[i + offset];
+ exename[i] = '\0';
+ }
} else if (GetCdromFile(mdir, time, "PSX.EXE;1") != -1) {
strcpy(exename, "PSX.EXE;1");
strcpy(CdromId, "SLUS99999");
}
if (CdromLabel[0] == ' ') {
- strncpy(CdromLabel, CdromId, 9);
+ memcpy(CdromLabel, CdromId, 9);
}
SysPrintf(_("CD-ROM Label: %.32s\n"), CdromLabel);
SysPrintf(_("CD-ROM ID: %.9s\n"), CdromId);
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..
{
void *tmp;
size_t ret = 0;
-
+
tmp = malloc(size * nmemb);
if (tmp) {
ret = fread(tmp, size, nmemb, stream);
u32 section_address, section_size;
void *mem;
- strncpy(CdromId, "SLUS99999", 9);
- strncpy(CdromLabel, "SLUS_999.99", 11);
+ strcpy(CdromId, "SLUS99999");
+ strcpy(CdromLabel, "SLUS_999.99");
tmpFile = fopen(ExePath, "rb");
if (tmpFile == NULL) {
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);
if (mem != NULL) {
- fseek(tmpFile, 0x800, SEEK_SET);
+ fseek(tmpFile, 0x800, SEEK_SET);
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);
+ psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr);
if (psxRegs.GPR.n.sp == 0)
psxRegs.GPR.n.sp = 0x801fff00;
retval = 0;
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
zlib_open, zlib_read, zlib_write, zlib_seek, zlib_close
};
-static const char PcsxHeader[32] = "STv4 PCSX v" PACKAGE_VERSION;
+static const char PcsxHeader[32] = "STv4 PCSX v" PCSX_VERSION;
// Savestate Versioning!
// If you make changes to the savestate version, please increment the value below.
if (Config.HLE)
psxBiosInit();
+#if defined(LIGHTREC)
+ if (Config.Cpu != CPU_INTERPRETER)
+ psxCpu->Clear(0, UINT32_MAX); //clear all
+ else
+#endif
psxCpu->Reset();
SaveFuncs.seek(f, 128 * 96 * 3, SEEK_CUR);
NET_recvData(&Config.Cpu, sizeof(Config.Cpu), PSE_NET_BLOCKING);
if (tmp != Config.Cpu) {
psxCpu->Shutdown();
-#ifdef PSXREC
+#if defined(NEW_DYNAREC) || defined(LIGHTREC)
if (Config.Cpu == CPU_INTERPRETER) psxCpu = &psxInt;
else psxCpu = &psxRec;
#else