}
// 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_) { \
//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;
}
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();
{
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) {
unsigned int frame_counter = 0;
static u32 hsync_steps = 0;
-u32 psxNextCounter = 0, psxNextsCounter = 0;
-
/******************************************************************************/
#define FPS_FRACTIONAL_PAL (53203425/314./3406) // ~49.75
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);
}
/******************************************************************************/
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)
{
#include "psxmem.h"
#include "plugins.h"
-extern u32 psxNextCounter, psxNextsCounter;
-
extern unsigned int hSyncCount, frame_counter;
typedef struct Rcnt
//#define evprintf printf
#define evprintf(...)
-u32 event_cycles[PSXINT_COUNT];
-
static psxRegisters *cp0TOpsxRegs(psxCP0Regs *cp0)
{
#ifndef LIGHTREC
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;
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]();
{
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;
}
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_; \
#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
#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;
}
void psxBranchTest() {
- if ((psxRegs.cycle - psxNextsCounter) >= psxNextCounter)
+ if ((psxRegs.cycle - psxRegs.psxNextsCounter) >= psxRegs.psxNextCounter)
psxRcntUpdate();
irq_test(&psxRegs.CP0);
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;