From: notaz Date: Thu, 16 Jan 2025 00:01:21 +0000 (+0200) Subject: core: move some more stuff to psxRegs X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92dc6b2f0eeea09c63be6ce6f78aa69227b9a200;p=pcsx_rearmed.git core: move some more stuff to psxRegs less literal pools --- diff --git a/libpcsxcore/new_dynarec/emu_if.c b/libpcsxcore/new_dynarec/emu_if.c index bed98e12..4c21b002 100644 --- a/libpcsxcore/new_dynarec/emu_if.c +++ b/libpcsxcore/new_dynarec/emu_if.c @@ -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; } diff --git a/libpcsxcore/new_dynarec/patches/trace_intr b/libpcsxcore/new_dynarec/patches/trace_intr index dcea9800..f81a0965 100644 --- a/libpcsxcore/new_dynarec/patches/trace_intr +++ b/libpcsxcore/new_dynarec/patches/trace_intr @@ -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(); diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 7682c92f..0e808754 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -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) { diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c index 9ff295e0..064c06b6 100644 --- a/libpcsxcore/psxcounters.c +++ b/libpcsxcore/psxcounters.c @@ -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) { diff --git a/libpcsxcore/psxcounters.h b/libpcsxcore/psxcounters.h index 618d74de..ceaf8b83 100644 --- a/libpcsxcore/psxcounters.h +++ b/libpcsxcore/psxcounters.h @@ -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 diff --git a/libpcsxcore/psxevents.c b/libpcsxcore/psxevents.c index 64fbbe3f..1e2d01f6 100644 --- a/libpcsxcore/psxevents.c +++ b/libpcsxcore/psxevents.c @@ -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; } diff --git a/libpcsxcore/psxevents.h b/libpcsxcore/psxevents.h index 1a72c330..543f8fc4 100644 --- a/libpcsxcore/psxevents.h +++ b/libpcsxcore/psxevents.h @@ -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_; \ diff --git a/libpcsxcore/r3000a.c b/libpcsxcore/r3000a.c index b1b819e4..c282422d 100644 --- a/libpcsxcore/r3000a.c +++ b/libpcsxcore/r3000a.c @@ -29,6 +29,11 @@ #include "psxbios.h" #include "psxevents.h" #include "../include/compiler_features.h" +#include + +#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); diff --git a/libpcsxcore/r3000a.h b/libpcsxcore/r3000a.h index 06c9826a..2889885f 100644 --- a/libpcsxcore/r3000a.h +++ b/libpcsxcore/r3000a.h @@ -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;