X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fmisc.c;h=7929dc76fc6b8aa64c4349c6d82beb1cf1a7280b;hb=5b5680983b7b3dde95acfe42f58e748d9f7fe1cb;hp=553b90da1bc055f87c5d3bfb876f46be3d93b8c5;hpb=9361a5aa4fef73e06bc78b7c462eb28a7d12e3d0;p=pcsx_rearmed.git diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 553b90da..7929dc76 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -21,11 +21,14 @@ * Miscellaneous functions, including savestates and CD-ROM loading. */ +#include #include "misc.h" #include "cdrom.h" #include "mdec.h" #include "gpu.h" #include "ppf.h" +#include "database.h" +#include "lightrec/plugin.h" #include char CdromId[10] = ""; @@ -53,17 +56,11 @@ struct iso_directory_record { char name [1]; }; -void mmssdd( char *b, char *p ) +static void mmssdd( char *b, char *p ) { int m, s, d; -#if defined(__arm__) - unsigned char *u = (void *)b; - int block = (u[3] << 24) | (u[2] << 16) | (u[1] << 8) | u[0]; -#elif defined(__BIGENDIAN__) - int block = (b[0] & 0xff) | ((b[1] & 0xff) << 8) | ((b[2] & 0xff) << 16) | (b[3] << 24); -#else - int block = *((int*)b); -#endif + unsigned char *ub = (void *)b; + int block = (ub[3] << 24) | (ub[2] << 16) | (ub[1] << 8) | ub[0]; block += 150; m = block / 4500; // minutes @@ -94,7 +91,7 @@ void mmssdd( char *b, char *p ) time[0] = itob(time[0]); time[1] = itob(time[1]); time[2] = itob(time[2]); #define READTRACK() \ - if (CDR_readTrack(time) == -1) return -1; \ + if (!CDR_readTrack(time)) return -1; \ buf = (void *)CDR_getBuffer(); \ if (buf == NULL) return -1; \ else CheckPPFCache((u8 *)buf, time[0], time[1], time[2]); @@ -243,6 +240,7 @@ int LoadCdrom() { 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) { @@ -251,7 +249,7 @@ int LoadCdrom() { incTime(); READTRACK(); - if (ptr != NULL) memcpy(ptr, buf+12, 2048); + if (ptr != INVALID_PTR) memcpy(ptr, buf+12, 2048); tmpHead.t_size -= 2048; tmpHead.t_addr += 2048; @@ -290,13 +288,14 @@ int LoadCdromFile(const char *filename, EXE_HEADER *head) { addr = head->t_addr; psxCpu->Clear(addr, size / 4); + psxCpu->Reset(); while (size & ~2047) { incTime(); READTRACK(); mem = PSXM(addr); - if (mem) + if (mem != INVALID_PTR) memcpy(mem, buf + 12, 2048); size -= 2048; @@ -386,17 +385,25 @@ int CheckCdrom() { 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(); @@ -411,7 +418,7 @@ static int PSXGetFileType(FILE *f) { current = ftell(f); fseek(f, 0L, SEEK_SET); - if (fread(&mybuf, sizeof(mybuf), 1, f) != sizeof(mybuf)) + if (fread(&mybuf, 1, sizeof(mybuf), f) != sizeof(mybuf)) goto io_fail; fseek(f, current, SEEK_SET); @@ -472,12 +479,12 @@ int Load(const char *ExePath) { type = PSXGetFileType(tmpFile); switch (type) { case PSX_EXE: - if (fread(&tmpHead, sizeof(EXE_HEADER), 1, tmpFile) != sizeof(EXE_HEADER)) + if (fread(&tmpHead, 1, sizeof(EXE_HEADER), 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) { + if (mem != INVALID_PTR) { fseek(tmpFile, 0x800, SEEK_SET); fread_to_ram(mem, section_size, 1, tmpFile); psxCpu->Clear(section_address, section_size / 4); @@ -492,13 +499,13 @@ int Load(const char *ExePath) { case CPE_EXE: fseek(tmpFile, 6, SEEK_SET); /* Something tells me we should go to 4 and read the "08 00" here... */ do { - if (fread(&opcode, sizeof(opcode), 1, tmpFile) != sizeof(opcode)) + if (fread(&opcode, 1, sizeof(opcode), tmpFile) != sizeof(opcode)) goto fail_io; switch (opcode) { case 1: /* Section loading */ - if (fread(§ion_address, sizeof(section_address), 1, tmpFile) != sizeof(section_address)) + if (fread(§ion_address, 1, sizeof(section_address), tmpFile) != sizeof(section_address)) goto fail_io; - if (fread(§ion_size, sizeof(section_size), 1, tmpFile) != sizeof(section_size)) + if (fread(§ion_size, 1, sizeof(section_size), tmpFile) != sizeof(section_size)) goto fail_io; section_address = SWAPu32(section_address); section_size = SWAPu32(section_size); @@ -506,14 +513,14 @@ int Load(const char *ExePath) { EMU_LOG("Loading %08X bytes from %08X to %08X\n", section_size, ftell(tmpFile), section_address); #endif mem = PSXM(section_address); - if (mem != NULL) { + if (mem != INVALID_PTR) { fread_to_ram(mem, section_size, 1, tmpFile); psxCpu->Clear(section_address, section_size / 4); } break; case 3: /* register loading (PC only?) */ fseek(tmpFile, 2, SEEK_CUR); /* unknown field */ - if (fread(&psxRegs.pc, sizeof(psxRegs.pc), 1, tmpFile) != sizeof(psxRegs.pc)) + if (fread(&psxRegs.pc, 1, sizeof(psxRegs.pc), tmpFile) != sizeof(psxRegs.pc)) goto fail_io; psxRegs.pc = SWAPu32(psxRegs.pc); break; @@ -543,7 +550,8 @@ int Load(const char *ExePath) { CdromLabel[0] = '\0'; } - fclose(tmpFile); + if (tmpFile) + fclose(tmpFile); return retval; fail_io: @@ -603,6 +611,9 @@ int SaveState(const char *file) { new_dyna_before_save(); + if (drc_is_lightrec() && Config.Cpu != CPU_INTERPRETER) + lightrec_plugin_sync_regs_to_pcsx(); + SaveFuncs.write(f, (void *)PcsxHeader, 32); SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32)); SaveFuncs.write(f, (void *)&Config.HLE, sizeof(boolean)); @@ -619,7 +630,8 @@ int SaveState(const char *file) { 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)); @@ -677,18 +689,18 @@ int LoadState(const char *file) { if (Config.HLE) psxBiosInit(); -#if defined(LIGHTREC) - if (Config.Cpu != CPU_INTERPRETER) - psxCpu->Clear(0, UINT32_MAX); //clear all - else -#endif - psxCpu->Reset(); + if (!drc_is_lightrec() || Config.Cpu == CPU_INTERPRETER) + psxCpu->Reset(); SaveFuncs.seek(f, 128 * 96 * 3, SEEK_CUR); 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 (drc_is_lightrec() && Config.Cpu != CPU_INTERPRETER) + lightrec_plugin_sync_regs_from_pcsx(); if (Config.HLE) psxBiosFreeze(0); @@ -699,7 +711,7 @@ int LoadState(const char *file) { GPU_freeze(0, gpufP); free(gpufP); if (HW_GPU_STATUS == 0) - HW_GPU_STATUS = GPU_readStatus(); + HW_GPU_STATUS = SWAP32(GPU_readStatus()); // spu SaveFuncs.read(f, &Size, 4); @@ -747,10 +759,13 @@ int SendPcsxInfo() { if (NET_recvData == NULL || NET_sendData == NULL) return 0; + boolean Sio_old = 0; + boolean SpuIrq_old = 0; + boolean RCntFix_old = 0; NET_sendData(&Config.Xa, sizeof(Config.Xa), PSE_NET_BLOCKING); - NET_sendData(&Config.Sio, sizeof(Config.Sio), PSE_NET_BLOCKING); - NET_sendData(&Config.SpuIrq, sizeof(Config.SpuIrq), PSE_NET_BLOCKING); - NET_sendData(&Config.RCntFix, sizeof(Config.RCntFix), PSE_NET_BLOCKING); + NET_sendData(&Sio_old, sizeof(Sio_old), PSE_NET_BLOCKING); + NET_sendData(&SpuIrq_old, sizeof(SpuIrq_old), PSE_NET_BLOCKING); + NET_sendData(&RCntFix_old, sizeof(RCntFix_old), PSE_NET_BLOCKING); NET_sendData(&Config.PsxType, sizeof(Config.PsxType), PSE_NET_BLOCKING); NET_sendData(&Config.Cpu, sizeof(Config.Cpu), PSE_NET_BLOCKING); @@ -763,10 +778,13 @@ int RecvPcsxInfo() { if (NET_recvData == NULL || NET_sendData == NULL) return 0; + boolean Sio_old = 0; + boolean SpuIrq_old = 0; + boolean RCntFix_old = 0; NET_recvData(&Config.Xa, sizeof(Config.Xa), PSE_NET_BLOCKING); - NET_recvData(&Config.Sio, sizeof(Config.Sio), PSE_NET_BLOCKING); - NET_recvData(&Config.SpuIrq, sizeof(Config.SpuIrq), PSE_NET_BLOCKING); - NET_recvData(&Config.RCntFix, sizeof(Config.RCntFix), PSE_NET_BLOCKING); + NET_recvData(&Sio_old, sizeof(Sio_old), PSE_NET_BLOCKING); + NET_recvData(&SpuIrq_old, sizeof(SpuIrq_old), PSE_NET_BLOCKING); + NET_recvData(&RCntFix_old, sizeof(RCntFix_old), PSE_NET_BLOCKING); NET_recvData(&Config.PsxType, sizeof(Config.PsxType), PSE_NET_BLOCKING); SysUpdate(); @@ -775,7 +793,7 @@ int RecvPcsxInfo() { 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