core: move some more stuff to psxRegs
authornotaz <notasas@gmail.com>
Thu, 16 Jan 2025 00:01:21 +0000 (02:01 +0200)
committernotaz <notasas@gmail.com>
Thu, 16 Jan 2025 00:01:21 +0000 (02:01 +0200)
less literal pools

libpcsxcore/new_dynarec/emu_if.c
libpcsxcore/new_dynarec/patches/trace_intr
libpcsxcore/psxbios.c
libpcsxcore/psxcounters.c
libpcsxcore/psxcounters.h
libpcsxcore/psxevents.c
libpcsxcore/psxevents.h
libpcsxcore/r3000a.c
libpcsxcore/r3000a.h

index bed98e1..4c21b00 100644 (file)
@@ -674,12 +674,12 @@ void do_insn_trace(void)
        }
        // log event changes
        for (i = 0; i < PSXINT_COUNT; i++) {
-               if (event_cycles[i] != event_cycles_o[i]) {
+               if (psxRegs.event_cycles[i] != event_cycles_o[i]) {
                        byte = 0xf8;
                        fwrite(&byte, 1, 1, f);
                        fwrite(&i, 1, 1, f);
-                       fwrite(&event_cycles[i], 1, 4, f);
-                       event_cycles_o[i] = event_cycles[i];
+                       fwrite(&psxRegs.event_cycles[i], 1, 4, f);
+                       event_cycles_o[i] = psxRegs.event_cycles[i];
                }
        }
        #define SAVE_IF_CHANGED(code_, name_) { \
@@ -816,9 +816,9 @@ void do_insn_cmp(void)
 
        //if (psxRegs.cycle == 166172) breakme();
 
-       if (which_event >= 0 && event_cycles[which_event] != ev_cycles) {
+       if (which_event >= 0 && psxRegs.event_cycles[which_event] != ev_cycles) {
                printf("bad ev_cycles #%d: %u %u / %u\n", which_event,
-                       event_cycles[which_event], ev_cycles, psxRegs.cycle);
+                       psxRegs.event_cycles[which_event], ev_cycles, psxRegs.cycle);
                fatal = 1;
        }
 
index dcea980..f81a096 100644 (file)
@@ -339,6 +339,6 @@ index 0c29dba7..3af7e156 100644
  void psxBranchTest() {
 + extern u32 irq_test_cycle;
 + irq_test_cycle = psxRegs.cycle;
-       if ((psxRegs.cycle - psxNextsCounter) >= psxNextCounter)
+       if ((psxRegs.cycle - psxRegs.psxNextsCounter) >= psxRegs.psxNextCounter)
                psxRcntUpdate();
  
index 7682c92..0e80875 100644 (file)
@@ -1623,8 +1623,8 @@ static u8 cdrom_sync(int do_ack)
 {
        u8 r = 0;
        if (psxRegs.interrupt & (1u << PSXINT_CDR)) {
-               if ((s32)(psxRegs.cycle - event_cycles[PSXINT_CDR]) < 0)
-                       psxRegs.cycle = event_cycles[PSXINT_CDR] + 1;
+               if ((s32)(psxRegs.cycle - psxRegs.event_cycles[PSXINT_CDR]) < 0)
+                       psxRegs.cycle = psxRegs.event_cycles[PSXINT_CDR] + 1;
                irq_test(&psxRegs.CP0);
        }
        if (do_ack) {
index 9ff295e..064c06b 100644 (file)
@@ -75,8 +75,6 @@ unsigned int hSyncCount = 0;
 unsigned int frame_counter = 0;
 static u32 hsync_steps = 0;
 
-u32 psxNextCounter = 0, psxNextsCounter = 0;
-
 /******************************************************************************/
 
 #define FPS_FRACTIONAL_PAL  (53203425/314./3406) // ~49.75
@@ -241,26 +239,26 @@ void psxRcntSet()
     s32 countToUpdate;
     u32 i;
 
-    psxNextsCounter = psxRegs.cycle;
-    psxNextCounter  = 0x7fffffff;
+    psxRegs.psxNextsCounter = psxRegs.cycle;
+    psxRegs.psxNextCounter  = 0x7fffffff;
 
     for( i = 0; i < CounterQuantity; ++i )
     {
-        countToUpdate = rcnts[i].cycle - (psxNextsCounter - rcnts[i].cycleStart);
+        countToUpdate = rcnts[i].cycle - (psxRegs.psxNextsCounter - rcnts[i].cycleStart);
 
         if( countToUpdate < 0 )
         {
-            psxNextCounter = 0;
+            psxRegs.psxNextCounter = 0;
             break;
         }
 
-        if( countToUpdate < (s32)psxNextCounter )
+        if( countToUpdate < (s32)psxRegs.psxNextCounter )
         {
-            psxNextCounter = countToUpdate;
+            psxRegs.psxNextCounter = countToUpdate;
         }
     }
 
-    set_event(PSXINT_RCNT, psxNextCounter);
+    set_event(PSXINT_RCNT, psxRegs.psxNextCounter);
 }
 
 /******************************************************************************/
@@ -596,8 +594,8 @@ s32 psxRcntFreeze( void *f, s32 Mode )
     gzfreeze( &rcnts, sizeof(Rcnt) * CounterQuantity );
     gzfreeze( &hSyncCount, sizeof(hSyncCount) );
     gzfreeze( &spuSyncCount, sizeof(spuSyncCount) );
-    gzfreeze( &psxNextCounter, sizeof(psxNextCounter) );
-    gzfreeze( &psxNextsCounter, sizeof(psxNextsCounter) );
+    gzfreeze( &psxRegs.psxNextCounter, sizeof(psxRegs.psxNextCounter) );
+    gzfreeze( &psxRegs.psxNextsCounter, sizeof(psxRegs.psxNextsCounter) );
 
     if (Mode == 0)
     {
index 618d74d..ceaf8b8 100644 (file)
@@ -29,8 +29,6 @@ extern "C" {
 #include "psxmem.h"
 #include "plugins.h"
 
-extern u32 psxNextCounter, psxNextsCounter;
-
 extern unsigned int hSyncCount, frame_counter;
 
 typedef struct Rcnt
index 64fbbe3..1e2d01f 100644 (file)
@@ -9,8 +9,6 @@
 //#define evprintf printf
 #define evprintf(...)
 
-u32 event_cycles[PSXINT_COUNT];
-
 static psxRegisters *cp0TOpsxRegs(psxCP0Regs *cp0)
 {
 #ifndef LIGHTREC
@@ -31,7 +29,7 @@ u32 schedule_timeslice(psxRegisters *regs)
        for (i = 0; irqs != 0; i++, irqs >>= 1) {
                if (!(irqs & 1))
                        continue;
-               dif = event_cycles[i] - c;
+               dif = regs->event_cycles[i] - c;
                //evprintf("  ev %d\n", dif);
                if (0 < dif && dif < min)
                        min = dif;
@@ -72,7 +70,7 @@ void irq_test(psxCP0Regs *cp0)
        for (irq = 0, irq_bits = regs->interrupt; irq_bits != 0; irq++, irq_bits >>= 1) {
                if (!(irq_bits & 1))
                        continue;
-               if ((s32)(cycle - event_cycles[irq]) >= 0) {
+               if ((s32)(cycle - regs->event_cycles[irq]) >= 0) {
                        // note: irq_funcs() also modify regs->interrupt
                        regs->interrupt &= ~(1u << irq);
                        irq_funcs[irq]();
@@ -104,9 +102,9 @@ void events_restore(void)
 {
        int i;
        for (i = 0; i < PSXINT_COUNT; i++)
-               event_cycles[i] = psxRegs.intCycle[i].sCycle + psxRegs.intCycle[i].cycle;
+               psxRegs.event_cycles[i] = psxRegs.intCycle[i].sCycle + psxRegs.intCycle[i].cycle;
 
-       event_cycles[PSXINT_RCNT] = psxNextsCounter + psxNextCounter;
+       psxRegs.event_cycles[PSXINT_RCNT] = psxRegs.psxNextsCounter + psxRegs.psxNextCounter;
        psxRegs.interrupt |=  1 << PSXINT_RCNT;
        psxRegs.interrupt &= (1 << PSXINT_COUNT) - 1;
 }
index 1a72c33..543f8fc 100644 (file)
@@ -22,12 +22,10 @@ enum {
        PSXINT_COUNT
 };
 
-extern u32 event_cycles[PSXINT_COUNT];
-
 #define set_event_raw_abs(e, abs) { \
        u32 abs_ = abs; \
        s32 di_ = psxRegs.next_interupt - abs_; \
-       event_cycles[e] = abs_; \
+       psxRegs.event_cycles[e] = abs_; \
        if (di_ > 0) { \
                /*printf("%u: next_interupt %u -> %u\n", psxRegs.cycle, psxRegs.next_interupt, abs_);*/ \
                psxRegs.next_interupt = abs_; \
index b1b819e..c282422 100644 (file)
 #include "psxbios.h"
 #include "psxevents.h"
 #include "../include/compiler_features.h"
+#include <assert.h>
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+#endif
 
 R3000Acpu *psxCpu = NULL;
 #ifdef DRC_DISABLE
@@ -36,6 +41,9 @@ psxRegisters psxRegs;
 #endif
 
 int psxInit() {
+       assert(PSXINT_COUNT <= ARRAY_SIZE(psxRegs.intCycle));
+       assert(ARRAY_SIZE(psxRegs.intCycle) == ARRAY_SIZE(psxRegs.event_cycles));
+
 #ifndef DRC_DISABLE
        if (Config.Cpu == CPU_INTERPRETER) {
                psxCpu = &psxInt;
@@ -126,7 +134,7 @@ void psxException(u32 cause, enum R3000Abdt bdt, psxCP0Regs *cp0) {
 }
 
 void psxBranchTest() {
-       if ((psxRegs.cycle - psxNextsCounter) >= psxNextCounter)
+       if ((psxRegs.cycle - psxRegs.psxNextsCounter) >= psxRegs.psxNextCounter)
                psxRcntUpdate();
 
        irq_test(&psxRegs.CP0);
index 06c9826..2889885 100644 (file)
@@ -196,7 +196,10 @@ typedef struct psxRegisters {
        u32 code;                       /* The instruction */
        u32 cycle;
        u32 interrupt;
-       struct { u32 sCycle, cycle; } intCycle[31];
+       struct { u32 sCycle, cycle; } intCycle[20];
+       u32 event_cycles[20];
+       u32 psxNextCounter;
+       u32 psxNextsCounter;
        u32 next_interupt;  /* cycle */
        u32 unused;
        u32 gteBusyCycle;