From d799884153cfb32a3681ef494c6e0b0b93ef9ec9 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Sun, 2 Nov 2008 04:53:55 +0000 Subject: [PATCH] Improved EE/IOP synchronization and also reduced the frequency of EE branch text executions (speedup!) git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@269 a6443dda-0b58-4228-96e9-037be469359c --- pcsx2/R3000A.c | 4 ++-- pcsx2/R5900.c | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pcsx2/R3000A.c b/pcsx2/R3000A.c index 2090ad9c58..1ee8ff8eb8 100644 --- a/pcsx2/R3000A.c +++ b/pcsx2/R3000A.c @@ -165,11 +165,11 @@ static void _psxTestInterrupts() { // drawback. The IOP is almost always forced to perform branch tests at import- // ant intervals regardless of this value (such as counter or irq events, hsyncs, // etc.) -#define IOP_WAIT_CYCLE 256 +#define IOP_WAIT_CYCLE 1024 void psxBranchTest() { - g_psxNextBranchCycle = psxRegs.cycle; + g_psxNextBranchCycle = psxRegs.cycle + IOP_WAIT_CYCLE; if ((int)(psxRegs.cycle - psxNextsCounter) >= psxNextCounter) psxRcntUpdate(); diff --git a/pcsx2/R5900.c b/pcsx2/R5900.c index c2fa61444f..9286dd51b9 100644 --- a/pcsx2/R5900.c +++ b/pcsx2/R5900.c @@ -382,7 +382,7 @@ _inline static void _cpuTestTIMR() { } } -#define EE_WAIT_CYCLE 512 +#define EE_WAIT_CYCLE 2048 // if cpuRegs.cycle is greater than this cycle, should check cpuBranchTest for updates u32 g_nextBranchCycle = 0; @@ -435,9 +435,12 @@ void cpuBranchTest() //#endif _cpuTestTIMR(); + // ---- IOP ------------- + // Signal for an immediate branch test! This is important! The IOP must // be able to act on the state the EE has given it before executing any - // additional code. Everything just seems a lot happier this way! + // additional code. Dothing this actually fixes some games that used to crash + // when trying to boot them through the BIOS. psxBranchTest(); @@ -445,15 +448,31 @@ void cpuBranchTest() EEoCycle = cpuRegs.cycle; psxCpu->ExecuteBlock(); - + + // IOP Synchronization: + // If the IOP needs to branch soon then so should the EE. + // As the master of all, the EE should look out for its children and + // assure them the love they deserve: + { + u32 iopDelta = (g_psxNextBranchCycle-psxRegs.cycle)*8; + if( g_nextBranchCycle - cpuRegs.cycle > iopDelta ) + g_nextBranchCycle = cpuRegs.cycle + iopDelta; + } + + // ---- VU0 ------------- + if (VU0.VI[REG_VPU_STAT].UL & 0x1) { FreezeXMMRegs(1); Cpu->ExecuteVU0Block(); FreezeXMMRegs(0); } - if( (int)cpuRegs.cycle-(int)g_nextBranchCycle > 0 ) - g_nextBranchCycle = cpuRegs.cycle+1; + // [Air] dead code? There shouldn't be any reason to bother checking + // for g_nextBranchCycle being behind cpuRegs.cycle, since the branch code will + // just do the same check after the next block. + + //if( (int)cpuRegs.cycle-(int)g_nextBranchCycle > 0 ) + // g_nextBranchCycle = cpuRegs.cycle+1; #ifndef PCSX2_NORECBUILD assert( !g_globalXMMSaved X86_32CODE(&& !g_globalMMXSaved) );