cdrom: change pause timing again
[pcsx_rearmed.git] / libpcsxcore / new_dynarec / patches / trace_drc_chk
index e09af7a..da86169 100644 (file)
-diff --git a/libpcsxcore/new_dynarec/linkage_arm.S b/libpcsxcore/new_dynarec/linkage_arm.S
-index bbc52c3..83c5b08 100644
---- a/libpcsxcore/new_dynarec/linkage_arm.S
-+++ b/libpcsxcore/new_dynarec/linkage_arm.S
-@@ -437,7 +437,7 @@ FUNCTION(cc_interrupt):
-       str     r1, [fp, #LO_pending_exception]
-       and     r2, r2, r10, lsr #17
-       add     r3, fp, #LO_restore_candidate
--      str     r10, [fp, #LO_cycle]            /* PCSX cycles */
-+@@@   str     r10, [fp, #LO_cycle]            /* PCSX cycles */
- @@    str     r10, [fp, #LO_reg_cop0+36]      /* Count */
-       ldr     r4, [r2, r3]
-       mov     r10, lr
-@@ -527,7 +527,7 @@ FUNCTION(new_dyna_leave):
-       ldr     r0, [fp, #LO_last_count]
-       add     r12, fp, #28
-       add     r10, r0, r10
--      str     r10, [fp, #LO_cycle]
-+@@@   str     r10, [fp, #LO_cycle]
-       ldmfd   sp!, {r4, r5, r6, r7, r8, r9, sl, fp, ip, pc}
-       .size   new_dyna_leave, .-new_dyna_leave
-@@ -644,7 +644,7 @@ FUNCTION(new_dyna_start):
-       \readop r0, [r1, r3, lsl #\tab_shift]
- .endif
-       movcc   pc, lr
--      str     r2, [fp, #LO_cycle]
-+@@@   str     r2, [fp, #LO_cycle]
-       bx      r1
- .endm
-@@ -679,7 +679,7 @@ FUNCTION(jump_handler_read32):
-       mov     r0, r1
-       add     r2, r2, r12
-       push    {r2, lr}
--      str     r2, [fp, #LO_cycle]
-+@@@   str     r2, [fp, #LO_cycle]
-       blx     r3
-       ldr     r0, [fp, #LO_next_interupt]
-@@ -707,7 +707,7 @@ FUNCTION(jump_handler_write_h):
-       add     r2, r2, r12
-       mov     r0, r1
-       push    {r2, lr}
--      str     r2, [fp, #LO_cycle]
-+@@@   str     r2, [fp, #LO_cycle]
-       blx     r3
-       ldr     r0, [fp, #LO_next_interupt]
-diff --git a/libpcsxcore/new_dynarec/linkage_arm64.S b/libpcsxcore/new_dynarec/linkage_arm64.S
-index 698bd78..798abea 100644
---- a/libpcsxcore/new_dynarec/linkage_arm64.S
-+++ b/libpcsxcore/new_dynarec/linkage_arm64.S
-@@ -119,7 +119,7 @@ FUNCTION(cc_interrupt):
-       str     wzr, [rFP, #LO_pending_exception]
-       and     w2, w2, rCC, lsr #17
-       add     x3, rFP, #LO_restore_candidate
--      str     rCC, [rFP, #LO_cycle]           /* PCSX cycles */
-+##    str     rCC, [rFP, #LO_cycle]           /* PCSX cycles */
- #     str     rCC, [rFP, #LO_reg_cop0+36]     /* Count */
-       ldr     w19, [x3, w2, uxtw]
-       mov     x21, lr
-@@ -227,7 +227,7 @@ FUNCTION(new_dyna_start):
- FUNCTION(new_dyna_leave):
-       ldr     w0,  [rFP, #LO_last_count]
-       add     rCC, rCC, w0
--      str     rCC, [rFP, #LO_cycle]
-+##    str     rCC, [rFP, #LO_cycle]
-       ldp     x19, x20, [sp, #16*1]
-       ldp     x21, x22, [sp, #16*2]
-       ldp     x23, x24, [sp, #16*3]
-@@ -245,7 +245,7 @@ FUNCTION(new_dyna_leave):
-       /* w0 = adddr/data, x1 = rhandler, w2 = cycles, x3 = whandler */
-       ldr     w4, [rFP, #LO_last_count]
-       add     w4, w4, w2
--      str     w4, [rFP, #LO_cycle]
-+##    str     w4, [rFP, #LO_cycle]
- .endm
- .macro memhandler_post
 diff --git a/libpcsxcore/new_dynarec/new_dynarec.c b/libpcsxcore/new_dynarec/new_dynarec.c
-index 1452db3..8200e44 100644
+index 74f32ee3..4eec8a83 100644
 --- a/libpcsxcore/new_dynarec/new_dynarec.c
 +++ b/libpcsxcore/new_dynarec/new_dynarec.c
-@@ -44,10 +44,10 @@ static int sceBlock;
- #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
- #endif
+@@ -325,7 +325,7 @@ static struct compile_info
+   int new_dynarec_hacks_old;
+   int new_dynarec_did_compile;
+-  #define HACK_ENABLED(x) ((new_dynarec_hacks | new_dynarec_hacks_pergame) & (x))
++  #define HACK_ENABLED(x) ((NDHACK_NO_STALLS) & (x))
  
--//#define DISASM
--//#define assem_debug printf
-+#define DISASM
-+#define assem_debug printf
- //#define inv_debug printf
--#define assem_debug(...)
-+//#define assem_debug(...)
- #define inv_debug(...)
+   extern int cycle_count; // ... until end of the timeslice, counts -N -> 0 (CCREG)
+   extern int last_count;  // last absolute target, often = next_interupt
+@@ -603,6 +603,7 @@ static int cycle_multiplier_active;
  
- #ifdef __i386__
-@@ -423,6 +423,9 @@ static int doesnt_expire_soon(void *tcaddr)
+ static int CLOCK_ADJUST(int x)
+ {
++  return x * 2;
+   int m = cycle_multiplier_active;
+   int s = (x >> 31) | 1;
+   return (x * m + s * 50) / 100;
+@@ -808,6 +809,9 @@ static noinline u_int generate_exception(u_int pc)
  // This is called from the recompiled JR/JALR instructions
void noinline *get_addr(u_int vaddr)
static void noinline *get_addr(u_int vaddr, int can_compile)
  {
 +#ifdef DRC_DBG
 +printf("get_addr %08x, pc=%08x\n", vaddr, psxRegs.pc);
 +#endif
-   u_int page=get_page(vaddr);
-   u_int vpage=get_vpage(vaddr);
-   struct ll_entry *head;
-@@ -4393,13 +4396,15 @@ void do_cc(int i,signed char i_regmap[],int *adj,int addr,int taken,int invert)
-     }
-     emit_addimm_and_set_flags(cycles,HOST_CCREG);
-     jaddr=out;
--    emit_jns(0);
-+    //emit_jns(0);
-+   emit_jmp(0);
-   }
-   else
-   {
-     emit_cmpimm(HOST_CCREG,-CLOCK_ADJUST(count+2));
-     jaddr=out;
--    emit_jns(0);
-+    //emit_jns(0);
-+   emit_jmp(0);
-   }
-   add_stub(CC_STUB,jaddr,idle?idle:out,(*adj==0||invert||idle)?0:(count+2),i,addr,taken,0);
- }
-@@ -4807,7 +4812,8 @@ static void rjump_assemble(int i,struct regstat *i_regs)
-     // special case for RFE
-     emit_jmp(0);
-   else
--    emit_jns(0);
-+    //emit_jns(0);
-+   emit_jmp(0);
-   //load_regs_bt(branch_regs[i].regmap,branch_regs[i].dirty,-1);
-   #ifdef USE_MINI_HT
-   if(rs1[i]==31) {
-@@ -4912,7 +4918,8 @@ static void cjump_assemble(int i,struct regstat *i_regs)
-     else if(nop) {
-       emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),cc);
-       void *jaddr=out;
--      emit_jns(0);
-+      //emit_jns(0);
-+     emit_jmp(0);
-       add_stub(CC_STUB,jaddr,out,0,i,start+i*4+8,NOTTAKEN,0);
-     }
-     else {
-@@ -5099,7 +5106,8 @@ static void cjump_assemble(int i,struct regstat *i_regs)
-         emit_loadreg(CCREG,HOST_CCREG);
-         emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),HOST_CCREG);
-         void *jaddr=out;
--        emit_jns(0);
-+        //emit_jns(0);
-+       emit_jmp(0);
-         add_stub(CC_STUB,jaddr,out,0,i,start+i*4+8,NOTTAKEN,0);
-         emit_storereg(CCREG,HOST_CCREG);
-       }
-@@ -5108,7 +5116,8 @@ static void cjump_assemble(int i,struct regstat *i_regs)
-         assert(cc==HOST_CCREG);
-         emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),cc);
-         void *jaddr=out;
--        emit_jns(0);
-+        //emit_jns(0);
-+       emit_jmp(0);
-         add_stub(CC_STUB,jaddr,out,0,i,start+i*4+8,likely[i]?NULLDS:NOTTAKEN,0);
-       }
-     }
-@@ -5210,7 +5219,8 @@ static void sjump_assemble(int i,struct regstat *i_regs)
-     else if(nevertaken) {
-       emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),cc);
-       void *jaddr=out;
--      emit_jns(0);
-+      //emit_jns(0);
-+     emit_jmp(0);
-       add_stub(CC_STUB,jaddr,out,0,i,start+i*4+8,NOTTAKEN,0);
-     }
-     else {
-@@ -5366,7 +5376,8 @@ static void sjump_assemble(int i,struct regstat *i_regs)
-         emit_loadreg(CCREG,HOST_CCREG);
-         emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),HOST_CCREG);
-         void *jaddr=out;
--        emit_jns(0);
-+        //emit_jns(0);
-+       emit_jmp(0);
-         add_stub(CC_STUB,jaddr,out,0,i,start+i*4+8,NOTTAKEN,0);
-         emit_storereg(CCREG,HOST_CCREG);
-       }
-@@ -5375,7 +5386,8 @@ static void sjump_assemble(int i,struct regstat *i_regs)
-         assert(cc==HOST_CCREG);
-         emit_addimm_and_set_flags(CLOCK_ADJUST(ccadj[i]+2),cc);
-         void *jaddr=out;
--        emit_jns(0);
-+        //emit_jns(0);
-+       emit_jmp(0);
-         add_stub(CC_STUB,jaddr,out,0,i,start+i*4+8,likely[i]?NULLDS:NOTTAKEN,0);
-       }
-     }
-@@ -5863,7 +5875,7 @@ void unneeded_registers(int istart,int iend,int r)
+   u_int start_page = get_page_prev(vaddr);
+   u_int i, page, end_page = get_page(vaddr);
+   void *found_clean = NULL;
+@@ -7213,7 +7217,7 @@ static noinline void pass2_unneeded_regs(int istart,int iend,int r)
      // R0 is always unneeded
      u|=1;
      // Save it
@@ -203,51 +38,105 @@ index 1452db3..8200e44 100644
      gte_unneeded[i]=gte_u;
      /*
      printf("ur (%d,%d) %x: ",istart,iend,start+i*4);
-@@ -8387,6 +8399,7 @@ int new_recompile_block(int addr)
-   // This allocates registers (if possible) one instruction prior
-   // to use, which can avoid a load-use penalty on certain CPUs.
-+#if 0
+@@ -8355,6 +8359,7 @@ static noinline void pass5a_preallocate1(void)
+ static noinline void pass5b_preallocate2(void)
+ {
+   int i, hr;
++ return;
    for(i=0;i<slen-1;i++)
    {
-     if(!i||(itype[i-1]!=UJUMP&&itype[i-1]!=CJUMP&&itype[i-1]!=SJUMP&&itype[i-1]!=RJUMP))
-@@ -8543,6 +8556,7 @@ int new_recompile_block(int addr)
-       }
-     }
-   }
-+#endif
+     if (!i || !dops[i-1].is_jump)
+@@ -9380,6 +9385,10 @@ static int new_recompile_block(u_int addr)
  
-   /* Pass 6 - Optimize clean/dirty state */
-   clean_registers(0,slen-1,1);
-@@ -8842,6 +8856,11 @@ int new_recompile_block(int addr)
-         case SPAN:
-           pagespan_assemble(i,&regs[i]);break;
-       }
-+
-+#ifdef DRC_DBG
-+      if(itype[i]!=UJUMP&&itype[i]!=CJUMP&&itype[i]!=SJUMP&&itype[i]!=RJUMP)
-+        wb_dirtys(regs[i].regmap,regs[i].dirty);
+ #ifdef ASSEM_PRINT
+   fflush(stdout);
 +#endif
-       if(itype[i]==UJUMP||itype[i]==RJUMP||(source[i]>>16)==0x1000)
-         literal_pool(1024);
-       else
-@@ -8950,7 +8969,7 @@ int new_recompile_block(int addr)
-     }
-   }
-   // External Branch Targets (jump_in)
--  if(copy+slen*4>(void *)shadow+sizeof(shadow)) copy=shadow;
-+  if(copy+slen*4>(void *)shadow+sizeof(shadow)) {copy=shadow;printf("shadow overflow\n");}
-   for(i=0;i<slen;i++)
-   {
-     if(bt[i]||i==0)
-@@ -9065,6 +9084,10 @@ int new_recompile_block(int addr)
-     }
-     expirep=(expirep+1)&65535;
-   }
 +#ifdef DRC_DBG
 +printf("new_recompile_block done\n");
 +fflush(stdout);
-+#endif
+ #endif
+   stat_inc(stat_bc_direct);
    return 0;
+diff --git a/libpcsxcore/new_dynarec/pcsxmem.c b/libpcsxcore/new_dynarec/pcsxmem.c
+index f4b1d90e..d3975ceb 100644
+--- a/libpcsxcore/new_dynarec/pcsxmem.c
++++ b/libpcsxcore/new_dynarec/pcsxmem.c
+@@ -258,6 +258,8 @@ static void write_biu(u32 value)
+               return;
+       }
++extern u32 handler_cycle;
++handler_cycle = psxRegs.cycle;
+       memprintf("write_biu %08x @%08x %u\n", value, psxRegs.pc, psxRegs.cycle);
+       psxRegs.biuReg = value;
+ }
+diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c
+index d0d45ec5..4ed03c40 100644
+--- a/libpcsxcore/psxcounters.c
++++ b/libpcsxcore/psxcounters.c
+@@ -428,9 +428,12 @@ void psxRcntUpdate()
+ /******************************************************************************/
++extern u32 handler_cycle;
++
+ void psxRcntWcount( u32 index, u32 value )
+ {
+     verboseLog( 2, "[RCNT %i] wcount: %x\n", index, value );
++handler_cycle = psxRegs.cycle;
+     _psxRcntWcount( index, value );
+     psxRcntSet();
+@@ -439,6 +442,7 @@ void psxRcntWcount( u32 index, u32 value )
+ void psxRcntWmode( u32 index, u32 value )
+ {
+     verboseLog( 1, "[RCNT %i] wmode: %x\n", index, value );
++handler_cycle = psxRegs.cycle;
+     _psxRcntWmode( index, value );
+     _psxRcntWcount( index, 0 );
+@@ -450,6 +454,7 @@ void psxRcntWmode( u32 index, u32 value )
+ void psxRcntWtarget( u32 index, u32 value )
+ {
+     verboseLog( 1, "[RCNT %i] wtarget: %x\n", index, value );
++handler_cycle = psxRegs.cycle;
+     rcnts[index].target = value;
+@@ -463,6 +468,7 @@ u32 psxRcntRcount0()
+ {
+     u32 index = 0;
+     u32 count;
++handler_cycle = psxRegs.cycle;
+     if ((rcnts[0].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset) ||
+         (rcnts[0].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset2))
+diff --git a/libpcsxcore/psxinterpreter.c b/libpcsxcore/psxinterpreter.c
+index f6ff2e8b..2f7147c3 100644
+--- a/libpcsxcore/psxinterpreter.c
++++ b/libpcsxcore/psxinterpreter.c
+@@ -245,7 +245,7 @@ static inline void addCycle(psxRegisters *regs)
+ {
+       assert(regs->subCycleStep >= 0x10000);
+       regs->subCycle += regs->subCycleStep;
+-      regs->cycle += regs->subCycle >> 16;
++      regs->cycle += 2; //regs->subCycle >> 16;
+       regs->subCycle &= 0xffff;
+ }
+@@ -1348,8 +1348,15 @@ static void intShutdown() {
+ // single step (may do several ops in case of a branch or load delay)
+ // called by asm/dynarec
+ void execI(psxRegisters *regs) {
++ extern int last_count;
++ extern u32 next_interupt;
++ void do_insn_cmp(void);
++ printf("execI %08x c %u, ni %u\n", regs->pc, regs->cycle, next_interupt);
++ last_count = 0;
+       do {
+               execIbp(psxMemRLUT, regs);
++              if (regs->dloadReg[0] || regs->dloadReg[1])
++                      do_insn_cmp();
+       } while (regs->dloadReg[0] || regs->dloadReg[1]);
  }