X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fmisc.c;h=022ad6d9afec738dae00e27cc19a03583290965a;hb=f5f5f5dddc4ab9b4d613fda8e450685689cbc8c7;hp=85402fc2b8a21b5fc9a113ea2b0e1fe87e3ca531;hpb=adb7d7ac1b92eac9ebc408e35d2be60c6339f89b;p=pcsx_rearmed.git diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 85402fc2..022ad6d9 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -22,6 +22,7 @@ */ #include +#include #include "misc.h" #include "cdrom.h" #include "mdec.h" @@ -55,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 __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - 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 @@ -96,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]); @@ -160,7 +155,7 @@ static const unsigned int gpu_data_def[] = { 0x02000000, 0x00000000, 0x01ff03ff, }; -static void fake_bios_gpu_setup(void) +void BiosLikeGPUSetup() { int i; @@ -171,6 +166,26 @@ static void fake_bios_gpu_setup(void) GPU_writeData(gpu_data_def[i]); } +static void SetBootRegs(u32 pc, u32 gp, u32 sp) +{ + //printf("%s %08x %08x %08x\n", __func__, pc, gp, sp); + psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); + + psxRegs.pc = pc; + psxRegs.GPR.n.gp = gp; + psxRegs.GPR.n.sp = sp ? sp : 0x801fff00; + + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); +} + +void BiosBootBypass() { + assert(psxRegs.pc == 0x80030000); + + // skip BIOS logos and region check + psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); + psxRegs.pc = psxRegs.GPR.n.ra; +} + int LoadCdrom() { EXE_HEADER tmpHead; struct iso_directory_record *dir; @@ -178,14 +193,10 @@ int LoadCdrom() { u8 mdir[4096]; char exename[256]; - // not the best place to do it, but since BIOS boot logo killer - // is just below, do it here - fake_bios_gpu_setup(); - - if (!Config.HLE && !Config.SlowBoot) { - // skip BIOS logos - psxRegs.pc = psxRegs.GPR.n.ra; - return 0; + if (!Config.HLE) { + if (!BiosBooted) return 0; // custom BIOS + if (psxRegs.pc != 0x80030000) return 0; // BiosBootBypass'ed + if (Config.SlowBoot) return 0; } time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); @@ -203,6 +214,7 @@ int LoadCdrom() { if (GetCdromFile(mdir, time, "SYSTEM.CNF;1") == -1) { // if SYSTEM.CNF is missing, start an existing PSX.EXE if (GetCdromFile(mdir, time, "PSX.EXE;1") == -1) return -1; + strcpy(exename, "PSX.EXE;1"); READTRACK(); } @@ -236,10 +248,8 @@ int LoadCdrom() { memcpy(&tmpHead, buf + 12, sizeof(EXE_HEADER)); - psxRegs.pc = SWAP32(tmpHead.pc0); - psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0); - psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr); - if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00; + SysPrintf("manual booting '%s'\n", exename); + SetBootRegs(SWAP32(tmpHead.pc0), SWAP32(tmpHead.gp0), SWAP32(tmpHead.s_addr)); tmpHead.t_size = SWAP32(tmpHead.t_size); tmpHead.t_addr = SWAP32(tmpHead.t_addr); @@ -423,7 +433,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); @@ -484,7 +494,7 @@ 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); @@ -494,23 +504,20 @@ int Load(const char *ExePath) { fread_to_ram(mem, section_size, 1, tmpFile); psxCpu->Clear(section_address, section_size / 4); } - psxRegs.pc = SWAP32(tmpHead.pc0); - psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0); - psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr); - if (psxRegs.GPR.n.sp == 0) - psxRegs.GPR.n.sp = 0x801fff00; + SetBootRegs(SWAP32(tmpHead.pc0), SWAP32(tmpHead.gp0), + SWAP32(tmpHead.s_addr)); retval = 0; break; 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); @@ -525,7 +532,7 @@ int Load(const char *ExePath) { 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; @@ -555,7 +562,8 @@ int Load(const char *ExePath) { CdromLabel[0] = '\0'; } - fclose(tmpFile); + if (tmpFile) + fclose(tmpFile); return retval; fail_io: @@ -603,18 +611,10 @@ static const char PcsxHeader[32] = "STv4 PCSX v" PCSX_VERSION; // If you make changes to the savestate version, please increment the value below. static const u32 SaveVersion = 0x8b410006; -static int drc_is_lightrec(void) -{ -#if defined(LIGHTREC) - return 1; -#else - return 0; -#endif -} - int SaveState(const char *file) { void *f; GPUFreeze_t *gpufP; + SPUFreezeHdr_t *spufH; SPUFreeze_t *spufP; int Size; unsigned char *pMem; @@ -622,10 +622,7 @@ int SaveState(const char *file) { f = SaveFuncs.open(file, "wb"); if (f == NULL) return -1; - new_dyna_before_save(); - - if (drc_is_lightrec() && Config.Cpu != CPU_INTERPRETER) - lightrec_plugin_prepare_save_state(); + psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); SaveFuncs.write(f, (void *)PcsxHeader, 32); SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32)); @@ -654,10 +651,10 @@ int SaveState(const char *file) { free(gpufP); // spu - spufP = (SPUFreeze_t *) malloc(16); - SPU_freeze(2, spufP, psxRegs.cycle); - Size = spufP->Size; SaveFuncs.write(f, &Size, 4); - free(spufP); + spufH = malloc(sizeof(*spufH)); + SPU_freeze(2, (SPUFreeze_t *)spufH, psxRegs.cycle); + Size = spufH->Size; SaveFuncs.write(f, &Size, 4); + free(spufH); spufP = (SPUFreeze_t *) malloc(Size); SPU_freeze(1, spufP, psxRegs.cycle); SaveFuncs.write(f, spufP, Size); @@ -672,8 +669,6 @@ int SaveState(const char *file) { SaveFuncs.close(f); - new_dyna_after_save(); - return 0; } @@ -702,18 +697,14 @@ int LoadState(const char *file) { if (Config.HLE) psxBiosInit(); - 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, &psxRegs, offsetof(psxRegisters, gteBusyCycle)); psxRegs.gteBusyCycle = psxRegs.cycle; - if (drc_is_lightrec() && Config.Cpu != CPU_INTERPRETER) - lightrec_plugin_prepare_load_state(); + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); if (Config.HLE) psxBiosFreeze(0); @@ -772,10 +763,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); @@ -788,10 +782,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(); @@ -810,6 +807,7 @@ int RecvPcsxInfo() { SysClose(); return -1; } psxCpu->Reset(); + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); } return 0;