1 diff --git a/libpcsxcore/new_dynarec/emu_if.c b/libpcsxcore/new_dynarec/emu_if.c
2 index cefadd21..63a5c1b1 100644
3 --- a/libpcsxcore/new_dynarec/emu_if.c
4 +++ b/libpcsxcore/new_dynarec/emu_if.c
6 * See the COPYING file in the top-level directory.
13 @@ -631,13 +632,18 @@ static void ari64_shutdown()
14 ari64_thread_shutdown();
15 new_dynarec_cleanup();
16 new_dyna_pcsx_mem_shutdown();
17 + (void)ari64_execute;
18 + (void)ari64_execute_block;
21 +extern void intExecuteT(psxRegisters *regs);
22 +extern void intExecuteBlockT(psxRegisters *regs, enum blockExecCaller caller);
28 - ari64_execute_block,
34 @@ -699,7 +705,7 @@ static u32 memcheck_read(u32 a)
35 return *(u32 *)(psxM + (a & 0x1ffffc));
40 void do_insn_trace(void)
42 static psxRegisters oldregs;
43 diff --git a/libpcsxcore/new_dynarec/pcsxmem.c b/libpcsxcore/new_dynarec/pcsxmem.c
44 index 98e2c6be..edba031e 100644
45 --- a/libpcsxcore/new_dynarec/pcsxmem.c
46 +++ b/libpcsxcore/new_dynarec/pcsxmem.c
47 @@ -238,6 +238,8 @@ static void write_biu(u32 value)
51 +extern u32 handler_cycle;
52 +handler_cycle = psxRegs.cycle;
53 memprintf("write_biu %08x @%08x %u\n", value, psxRegs.pc, psxRegs.cycle);
54 psxRegs.biuReg = value;
56 diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c
57 index 064c06b6..07e2afb5 100644
58 --- a/libpcsxcore/psxcounters.c
59 +++ b/libpcsxcore/psxcounters.c
60 @@ -455,9 +455,12 @@ void psxRcntUpdate()
62 /******************************************************************************/
64 +extern u32 handler_cycle;
66 void psxRcntWcount( u32 index, u32 value )
68 verboseLog( 2, "[RCNT %i] wcount: %x\n", index, value );
69 +handler_cycle = psxRegs.cycle;
71 _psxRcntWcount( index, value );
73 @@ -466,6 +469,7 @@ void psxRcntWcount( u32 index, u32 value )
74 void psxRcntWmode( u32 index, u32 value )
76 verboseLog( 1, "[RCNT %i] wmode: %x\n", index, value );
77 +handler_cycle = psxRegs.cycle;
79 _psxRcntWmode( index, value );
80 _psxRcntWcount( index, 0 );
81 @@ -477,6 +481,7 @@ void psxRcntWmode( u32 index, u32 value )
82 void psxRcntWtarget( u32 index, u32 value )
84 verboseLog( 1, "[RCNT %i] wtarget: %x\n", index, value );
85 +handler_cycle = psxRegs.cycle;
87 rcnts[index].target = value;
89 @@ -490,6 +495,7 @@ u32 psxRcntRcount0()
93 +handler_cycle = psxRegs.cycle;
95 if ((rcnts[0].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset) ||
96 (rcnts[0].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset2))
97 diff --git a/libpcsxcore/psxevents.c b/libpcsxcore/psxevents.c
98 index 1e2d01f6..0ee15974 100644
99 --- a/libpcsxcore/psxevents.c
100 +++ b/libpcsxcore/psxevents.c
101 @@ -77,11 +77,13 @@ void irq_test(psxCP0Regs *cp0)
105 - cp0->n.Cause &= ~0x400;
106 + u32 c2 = cp0->n.Cause & ~0x400;
107 if (psxHu32(0x1070) & psxHu32(0x1074))
108 - cp0->n.Cause |= 0x400;
109 - if (((cp0->n.Cause | 1) & cp0->n.SR & 0x401) == 0x401)
111 + if (((c2 | 1) & cp0->n.SR & 0x401) == 0x401) {
113 psxException(0, 0, cp0);
117 void gen_interupt(psxCP0Regs *cp0)
118 diff --git a/libpcsxcore/psxhw.c b/libpcsxcore/psxhw.c
119 index c487b02d..171c447f 100644
120 --- a/libpcsxcore/psxhw.c
121 +++ b/libpcsxcore/psxhw.c
122 @@ -323,6 +323,7 @@ void psxHwWrite8(u32 add, u32 value) {
123 log_unhandled("unhandled w8 %08x %08x @%08x\n",
124 add, value, psxRegs.pc);
126 + if (add < 0x1f802000)
130 @@ -396,6 +397,7 @@ void psxHwWrite16(u32 add, u32 value) {
131 log_unhandled("unhandled w16 %08x %08x @%08x\n",
132 add, value, psxRegs.pc);
134 + if (add < 0x1f802000)
135 psxHu16ref(add) = SWAPu16(value);
138 @@ -452,6 +454,7 @@ void psxHwWrite32(u32 add, u32 value) {
142 + if (add < 0x1f802000)
143 psxHu32ref(add) = SWAPu32(value);
146 diff --git a/libpcsxcore/psxinterpreter.c b/libpcsxcore/psxinterpreter.c
147 index 68d79321..2e3d14ab 100644
148 --- a/libpcsxcore/psxinterpreter.c
149 +++ b/libpcsxcore/psxinterpreter.c
150 @@ -243,7 +243,7 @@ static inline void addCycle(psxRegisters *regs)
152 assert(regs->subCycleStep >= 0x10000);
153 regs->subCycle += regs->subCycleStep;
154 - regs->cycle += regs->subCycle >> 16;
155 + regs->cycle += 2; //regs->subCycle >> 16;
156 regs->subCycle &= 0xffff;
159 @@ -440,7 +440,9 @@ static void doBranch(psxRegisters *regs, u32 tar, enum R3000Abdt taken) {
160 regs->CP0.n.Target = pc_final;
163 + psxRegs.cycle += 2;
165 + psxRegs.cycle -= 2;
168 static void doBranchReg(psxRegisters *regs, u32 tar) {
169 @@ -973,7 +975,7 @@ void MTC0(psxRegisters *regs_, int reg, u32 val) {
173 -OP(psxMTC0) { MTC0(regs_, _Rd_, _u32(_rRt_)); }
174 +OP(psxMTC0) { MTC0(regs_, _Rd_, _u32(_rRt_)); psxBranchTest(); }
177 static inline void psxNULLne(psxRegisters *regs) {
178 @@ -1182,18 +1184,20 @@ static void intReset() {
179 static inline void execI_(u8 **memRLUT, psxRegisters *regs) {
187 regs->code = fetch(regs, memRLUT, pc);
188 psxBSC[regs->code >> 26](regs, regs->code);
189 + psxRegs.cycle += 2;
190 + fetchNoCache(regs, memRLUT, regs->pc); // bus err check
193 static inline void execIbp(u8 **memRLUT, psxRegisters *regs) {
200 if (execBreakCheck(regs, pc))
201 @@ -1202,6 +1206,8 @@ static inline void execIbp(u8 **memRLUT, psxRegisters *regs) {
203 regs->code = fetch(regs, memRLUT, pc);
204 psxBSC[regs->code >> 26](regs, regs->code);
205 + psxRegs.cycle += 2;
206 + fetchNoCache(regs, memRLUT, regs->pc); // bus err check
209 static void intExecute(psxRegisters *regs) {
210 @@ -1234,6 +1240,27 @@ static void intExecuteBlockBp(psxRegisters *regs, enum blockExecCaller caller) {
211 execIbp(memRLUT, regs);
214 +extern void do_insn_trace(void);
216 +void intExecuteT(psxRegisters *regs) {
217 + u8 **memRLUT = psxMemRLUT;
219 + while (!regs->stop) {
221 + execIbp(memRLUT, regs);
225 +void intExecuteBlockT(psxRegisters *regs, enum blockExecCaller caller) {
226 + u8 **memRLUT = psxMemRLUT;
228 + regs->branchSeen = 0;
229 + while (!regs->branchSeen) {
231 + execIbp(memRLUT, regs);
235 static void intClear(u32 Addr, u32 Size) {
238 @@ -1263,7 +1290,7 @@ static void setupCop(u32 sr)
240 psxBSC[17] = psxCOPd;
242 - psxBSC[18] = Config.DisableStalls ? psxCOP2 : psxCOP2_stall;
243 + psxBSC[18] = psxCOP2;
245 psxBSC[18] = psxCOPd;
247 @@ -1282,7 +1309,7 @@ void intApplyConfig() {
248 assert(psxSPC[26] == psxDIV || psxSPC[26] == psxDIV_stall);
249 assert(psxSPC[27] == psxDIVU || psxSPC[27] == psxDIVU_stall);
251 - if (Config.DisableStalls) {
253 psxBSC[18] = psxCOP2;
254 psxBSC[50] = gteLWC2;
255 psxBSC[58] = gteSWC2;
256 diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c
257 index 13301992..2ccdea74 100644
258 --- a/libpcsxcore/psxmem.c
259 +++ b/libpcsxcore/psxmem.c
260 @@ -316,10 +316,13 @@ void psxMemOnIsolate(int enable)
261 : R3000ACPU_NOTIFY_CACHE_UNISOLATED, NULL);
264 +extern u32 last_io_addr;
266 u8 psxMemRead8(u32 mem) {
270 + last_io_addr = mem;
272 if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) {
273 if ((mem & 0xffff) < 0x400)
274 @@ -345,6 +348,7 @@ u16 psxMemRead16(u32 mem) {
278 + last_io_addr = mem;
280 if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) {
281 if ((mem & 0xffff) < 0x400)
282 @@ -370,6 +374,7 @@ u32 psxMemRead32(u32 mem) {
286 + last_io_addr = mem;
288 if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) {
289 if ((mem & 0xffff) < 0x400)
290 @@ -397,6 +402,7 @@ void psxMemWrite8(u32 mem, u32 value) {
294 + last_io_addr = mem;
296 if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) {
297 if ((mem & 0xffff) < 0x400)
298 @@ -424,6 +430,7 @@ void psxMemWrite16(u32 mem, u32 value) {
302 + last_io_addr = mem;
304 if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) {
305 if ((mem & 0xffff) < 0x400)
306 @@ -451,6 +458,7 @@ void psxMemWrite32(u32 mem, u32 value) {
310 + last_io_addr = mem;
311 // if ((mem&0x1fffff) == 0x71E18 || value == 0x48088800) SysPrintf("t2fix!!\n");
313 if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) {
314 @@ -469,6 +477,8 @@ void psxMemWrite32(u32 mem, u32 value) {
317 if (mem == 0xfffe0130) {
318 +extern u32 handler_cycle;
319 +handler_cycle = psxRegs.cycle;
320 psxRegs.biuReg = value;
323 diff --git a/libpcsxcore/r3000a.c b/libpcsxcore/r3000a.c
324 index cfd1ab09..724167e0 100644
325 --- a/libpcsxcore/r3000a.c
326 +++ b/libpcsxcore/r3000a.c
327 @@ -141,6 +141,8 @@ void psxException(u32 cause, enum R3000Abdt bdt, psxCP0Regs *cp0) {
330 void psxBranchTest() {
331 + extern u32 irq_test_cycle;
332 + irq_test_cycle = psxRegs.cycle;
333 if ((psxRegs.cycle - psxRegs.psxNextsCounter) >= psxRegs.psxNextCounter)