X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fmisc.c;h=252e1c8c7e77460766d94a897597603d396968e0;hb=4ee246ed0e02c61f0b33251d86ea74a4a0380a47;hp=8010d7a5baf9f8452f6aa76b617fa84b6a2b3c8d;hpb=7a8d521fba9c86ae7b51369ce061bf63112b745f;p=pcsx_rearmed.git diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 8010d7a5..252e1c8c 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -22,6 +22,7 @@ */ #include +#include #include "misc.h" #include "cdrom.h" #include "mdec.h" @@ -154,7 +155,7 @@ static const unsigned int gpu_data_def[] = { 0x02000000, 0x00000000, 0x01ff03ff, }; -static void fake_bios_gpu_setup(void) +void BiosLikeGPUSetup() { int i; @@ -163,6 +164,37 @@ static void fake_bios_gpu_setup(void) for (i = 0; i < sizeof(gpu_data_def) / sizeof(gpu_data_def[0]); i++) GPU_writeData(gpu_data_def[i]); + + HW_GPU_STATUS |= SWAP32(PSXGPU_nBUSY); +} + +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; +} + +static void getFromCnf(char *buf, const char *key, u32 *val) +{ + buf = strstr(buf, key); + if (buf) + buf = strchr(buf, '='); + if (buf) + *val = strtol(buf + 1, NULL, 16); } int LoadCdrom() { @@ -171,15 +203,17 @@ int LoadCdrom() { u8 time[4], *buf; 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; + u32 cnf_tcb = 4; + u32 cnf_event = 16; + u32 cnf_stack = 0; + u32 sp = 0; + int ret; + + if (!Config.HLE) { + if (psxRegs.pc != 0x80030000) // BiosBootBypass'ed or custom BIOS? + return 0; + if (Config.SlowBoot) + return 0; } time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); @@ -197,17 +231,19 @@ 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(); } else { // read the SYSTEM.CNF READTRACK(); + buf[1023] = 0; - 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) { + ret = sscanf((char *)buf + 12, "BOOT = cdrom:\\%255s", exename); + if (ret < 1 || GetCdromFile(mdir, time, exename) == -1) { + ret = sscanf((char *)buf + 12, "BOOT = cdrom:%255s", exename); + if (ret < 1 || GetCdromFile(mdir, time, exename) == -1) { char *ptr = strstr((char *)buf + 12, "cdrom:"); if (ptr != NULL) { ptr += 6; @@ -223,6 +259,11 @@ int LoadCdrom() { return -1; } } + getFromCnf((char *)buf + 12, "TCB", &cnf_tcb); + getFromCnf((char *)buf + 12, "EVENT", &cnf_event); + getFromCnf((char *)buf + 12, "STACK", &cnf_stack); + if (Config.HLE) + psxBiosCnfLoaded(cnf_tcb, cnf_event); // Read the EXE-Header READTRACK(); @@ -230,10 +271,11 @@ 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); + sp = SWAP32(tmpHead.s_addr); + if (cnf_stack) + sp = cnf_stack; + SetBootRegs(SWAP32(tmpHead.pc0), SWAP32(tmpHead.gp0), sp); tmpHead.t_size = SWAP32(tmpHead.t_size); tmpHead.t_addr = SWAP32(tmpHead.t_addr); @@ -488,11 +530,8 @@ 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: @@ -601,6 +640,7 @@ static const u32 SaveVersion = 0x8b410006; int SaveState(const char *file) { void *f; GPUFreeze_t *gpufP; + SPUFreezeHdr_t *spufH; SPUFreeze_t *spufP; int Size; unsigned char *pMem; @@ -608,7 +648,7 @@ int SaveState(const char *file) { f = SaveFuncs.open(file, "wb"); if (f == NULL) return -1; - new_dyna_before_save(); + psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); SaveFuncs.write(f, (void *)PcsxHeader, 32); SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32)); @@ -637,10 +677,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); @@ -655,8 +695,6 @@ int SaveState(const char *file) { SaveFuncs.close(f); - new_dyna_after_save(); - return 0; } @@ -685,15 +723,15 @@ int LoadState(const char *file) { if (Config.HLE) psxBiosInit(); - 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; + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); + if (Config.HLE) psxBiosFreeze(0); @@ -779,8 +817,6 @@ int RecvPcsxInfo() { NET_recvData(&RCntFix_old, sizeof(RCntFix_old), PSE_NET_BLOCKING); NET_recvData(&Config.PsxType, sizeof(Config.PsxType), PSE_NET_BLOCKING); - SysUpdate(); - tmp = Config.Cpu; NET_recvData(&Config.Cpu, sizeof(Config.Cpu), PSE_NET_BLOCKING); if (tmp != Config.Cpu) { @@ -795,6 +831,7 @@ int RecvPcsxInfo() { SysClose(); return -1; } psxCpu->Reset(); + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); } return 0;