Skip to content

Commit

Permalink
core: move some more stuff to psxRegs
Browse files Browse the repository at this point in the history
less literal pools
  • Loading branch information
notaz committed Jan 16, 2025
1 parent bb17f8f commit 92dc6b2
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 32 deletions.
10 changes: 5 additions & 5 deletions libpcsxcore/new_dynarec/emu_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_) { \
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion libpcsxcore/new_dynarec/patches/trace_intr
Original file line number Diff line number Diff line change
Expand Up @@ -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();

4 changes: 2 additions & 2 deletions libpcsxcore/psxbios.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 9 additions & 11 deletions libpcsxcore/psxcounters.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/******************************************************************************/
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 0 additions & 2 deletions libpcsxcore/psxcounters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions libpcsxcore/psxevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
//#define evprintf printf
#define evprintf(...)

u32 event_cycles[PSXINT_COUNT];

static psxRegisters *cp0TOpsxRegs(psxCP0Regs *cp0)
{
#ifndef LIGHTREC
Expand All @@ -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;
Expand Down Expand Up @@ -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]();
Expand Down Expand Up @@ -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;
}
4 changes: 1 addition & 3 deletions libpcsxcore/psxevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; \
Expand Down
10 changes: 9 additions & 1 deletion libpcsxcore/r3000a.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@
#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
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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion libpcsxcore/r3000a.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 92dc6b2

Please sign in to comment.