X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fpsxbios.c;h=3671af5a0f0406841282658570b11524677920fd;hb=f8896d181bd26ef6fd18af17f01c77b73ae17a68;hp=0cb1b87026eb05c2fa49418c07a961c62fa75eea;hpb=3b988ef27435350b7b944016f6387cb189051c45;p=pcsx_rearmed.git diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 0cb1b870..3671af5a 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -36,6 +36,7 @@ #include "sio.h" #include "psxhle.h" #include "psxinterpreter.h" +#include "psxevents.h" #include #ifndef PSXBIOS_LOG @@ -397,14 +398,17 @@ static inline void softCall(u32 pc) { ra = 0x80001000; psxRegs.CP0.n.SR &= ~0x404; // disable interrupts + assert(psxRegs.cpuInRecursion <= 1); + psxRegs.cpuInRecursion++; psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, PTR_1); - while (pc0 != 0x80001000 && ++lim < 1000000) + while (pc0 != 0x80001000 && ++lim < 0x100000) psxCpu->ExecuteBlock(EXEC_CALLER_HLE); psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, PTR_1); + psxRegs.cpuInRecursion--; - if (lim == 1000000) + if (lim == 0x100000) PSXBIOS_LOG("softCall @%x hit lim\n", pc); ra = sra; psxRegs.CP0.n.SR |= ssr & 0x404; @@ -420,14 +424,16 @@ static inline void softCallInException(u32 pc) { return; ra = 0x80001000; + psxRegs.cpuInRecursion++; psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, PTR_1); - while (!returned_from_exception() && pc0 != 0x80001000 && ++lim < 1000000) + while (!returned_from_exception() && pc0 != 0x80001000 && ++lim < 0x100000) psxCpu->ExecuteBlock(EXEC_CALLER_HLE); psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, PTR_1); + psxRegs.cpuInRecursion--; - if (lim == 1000000) + if (lim == 0x100000) PSXBIOS_LOG("softCallInException @%x hit lim\n", pc); if (pc0 == 0x80001000) ra = sra; @@ -1473,13 +1479,15 @@ void psxBios_printf() { // 0x3f } static void psxBios_cd() { // 0x40 - const char *p, *dir = castRam8ptr(a0); + const char *p, *dir = Ra0; PSXBIOS_LOG("psxBios_%s %x(%s)\n", biosB0n[0x40], a0, dir); - if ((p = strchr(dir, ':'))) - dir = ++p; - if (*dir == '\\') - dir++; - snprintf(cdir, sizeof(cdir), "%s", dir); + if (dir != INVALID_PTR) { + if ((p = strchr(dir, ':'))) + dir = ++p; + if (*dir == '\\') + dir++; + snprintf(cdir, sizeof(cdir), "%s", dir); + } mips_return_c(1, 100); } @@ -2560,7 +2568,7 @@ void psxBios_puts() { // 3e/3f } static void bufile(const u8 *mcd_data, u32 dir_) { - struct DIRENTRY *dir = (struct DIRENTRY *)castRam8ptr(dir_); + struct DIRENTRY *dir = (struct DIRENTRY *)PSXM(dir_); const char *pfile = ffile + 5; const u8 *data = mcd_data; int i = 0, match = 0; @@ -2568,6 +2576,9 @@ static void bufile(const u8 *mcd_data, u32 dir_) { u32 head = 0; v0 = 0; + if (dir == INVALID_PTR) + return; + for (; nfile <= 15 && !match; nfile++) { const char *name; @@ -2621,11 +2632,12 @@ static void bufile(const u8 *mcd_data, u32 dir_) { */ static void psxBios_firstfile() { // 42 - char *pa0 = castRam8ptr(a0); + char *pa0 = Ra0; PSXBIOS_LOG("psxBios_%s %s %x\n", biosB0n[0x42], pa0, a1); v0 = 0; + if (pa0 != INVALID_PTR) { snprintf(ffile, sizeof(ffile), "%s", pa0); if (ffile[5] == 0) @@ -3310,7 +3322,6 @@ void psxBiosSetupBootState(void) GPU_writeStatus(gpu_ctl_def[i]); 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); // spu for (i = 0x1f801d80; i < sizeof(spu_config) / sizeof(spu_config[0]); i++) @@ -3330,6 +3341,8 @@ void psxBiosInit() { int i; uLongf len; + psxRegs.biosBranchCheck = ~0; + memset(psxM, 0, 0x10000); for(i = 0; i < 256; i++) { biosA0[i] = NULL; @@ -3341,7 +3354,15 @@ void psxBiosInit() { biosA0[0x3e] = biosB0[0x3f] = psxBios_puts_psxout; biosA0[0x3f] = psxBios_printf_psxout; - if (!Config.HLE) return; + if (!Config.HLE) { + char verstr[0x24+1]; + rom32 = (u32 *)psxR; + memcpy(verstr, psxR + 0x12c, 0x24); + verstr[0x24] = 0; + SysPrintf("BIOS: %08x, '%s', '%c'\n", SWAP32(rom32[0x100/4]), + verstr, psxR[0x7ff52]); + return; + } for(i = 0; i < 256; i++) { if (biosA0[i] == NULL) biosA0[i] = psxBios_dummy; @@ -4024,6 +4045,7 @@ void psxBiosException() { sp = fp = loadRam32(A_EXC_SP); gp = A_EXC_GP; use_cycles(46); + assert(!psxRegs.cpuInRecursion); // do the chains (always 4) for (c = lim = 0; c < 4; c++) { @@ -4164,6 +4186,75 @@ void (* const psxHLEt[24])() = { hleExcPadCard1, hleExcPadCard2, }; +void psxBiosCheckExe(u32 t_addr, u32 t_size, int loading_state) +{ + // lw $v0, 0x10($sp) + // nop + // addiu $v0, -1 + // sw $v0, 0x10($sp) + // lw $v0, 0x10($sp) + // nop + // bne $v0, $v1, not_timeout + // nop + // lui $a0, ... + static const u8 pattern[] = { + 0x10, 0x00, 0xA2, 0x8F, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x42, 0x24, 0x10, 0x00, 0xA2, 0xAF, + 0x10, 0x00, 0xA2, 0x8F, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x00, 0x43, 0x14, 0x00, 0x00, 0x00, 0x00, + }; + u32 start = t_addr & 0x1ffffc; + u32 end = (start + t_size) & 0x1ffffc; + u32 buf[sizeof(pattern) / sizeof(u32)]; + const u32 *r32 = (u32 *)(psxM + start); + u32 i, j; + + if (end <= start) + return; + if (!Config.HLE) + return; + + memcpy(buf, pattern, sizeof(buf)); + for (i = 0; i < t_size / 4; i += j + 1) { + for (j = 0; j < sizeof(buf) / sizeof(buf[0]); j++) + if (r32[i + j] != buf[j]) + break; + if (j != sizeof(buf) / sizeof(buf[0])) + continue; + + if ((SWAP32(r32[i + j]) >> 16) != 0x3c04) // lui + continue; + if (!loading_state) + SysPrintf("HLE vsync @%08x\n", start + i * 4); + psxRegs.biosBranchCheck = (t_addr & 0xa01ffffc) + i * 4; + } +} + +void psxBiosCheckBranch(void) +{ +#if 1 + // vsync HLE hack + static u32 cycles_prev, v0_prev; + u32 cycles_passed, waste_cycles; + u32 loops, v0_expect = v0_prev - 1; + if (v0 != 1) + return; + execI(&psxRegs); + cycles_passed = psxRegs.cycle - cycles_prev; + cycles_prev = psxRegs.cycle; + v0_prev = v0; + if (cycles_passed < 10 || cycles_passed > 50 || v0 != v0_expect) + return; + + waste_cycles = schedule_timeslice() - psxRegs.cycle; + loops = waste_cycles / cycles_passed; + if (loops > v0) + loops = v0; + v0 -= loops; + psxRegs.cycle += loops * cycles_passed; + //printf("c %4u %d\n", loops, cycles_passed); +#endif +} #define bfreeze(ptr, size) { \ if (Mode == 1) memcpy(&psxR[base], ptr, size); \