Skip to content

Commit

Permalink
Merge branch 'master' into libretro
Browse files Browse the repository at this point in the history
  • Loading branch information
notaz committed Jan 16, 2025
2 parents 9fec7ce + 92dc6b2 commit cf0cd7c
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 44 deletions.
2 changes: 1 addition & 1 deletion libpcsxcore/cdriso.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ static int cdread_compressed(FILE *f, unsigned int base, void *dest, int sector)

if (fread(is_compressed ? compr_img->buff_compressed : compr_img->buff_raw[0],
1, size, cdHandle) != size) {
SysPrintf("read error for block %d at %zx: ", block, start_byte);
SysPrintf("read error for block %d at %lx: ", block, (long)start_byte);
perror(NULL);
return -1;
}
Expand Down
10 changes: 8 additions & 2 deletions libpcsxcore/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ int Load(const char *ExePath) {
case 0: /* End of file */
break;
default:
SysPrintf(_("Unknown CPE opcode %02x at position %08zx.\n"), opcode, ftell(tmpFile) - 1);
SysPrintf(_("Unknown CPE opcode %02x at position %08lx.\n"), opcode, ftell(tmpFile) - 1);
retval = -1;
break;
}
Expand Down Expand Up @@ -751,10 +751,10 @@ int LoadState(const char *file) {
void *f;
GPUFreeze_t *gpufP = NULL;
SPUFreeze_t *spufP = NULL;
boolean hle, oldhle;
int Size;
char header[32];
u32 version;
boolean hle;
int result = -1;

f = SaveFuncs.open(file, "rb");
Expand All @@ -768,6 +768,7 @@ int LoadState(const char *file) {
SysPrintf("incompatible savestate version %x\n", version);
goto cleanup;
}
oldhle = Config.HLE;
Config.HLE = hle;

if (Config.HLE)
Expand Down Expand Up @@ -826,6 +827,11 @@ int LoadState(const char *file) {
if (Config.HLE)
psxBiosCheckExe(biosBranchCheckOld, 0x60, 1);

if (Config.HLE != oldhle) {
// at least ari64 drc compiles differently so hard reset
psxCpu->Shutdown();
psxCpu->Init();
}
psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL);

result = 0;
Expand Down
18 changes: 9 additions & 9 deletions libpcsxcore/new_dynarec/emu_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ static void ari64_execute_until(psxRegisters *regs)
void *drc_local = (char *)regs - LO_psxRegs;

assert(drc_local == dynarec_local);
evprintf("ari64_execute %08x, %u->%u (%d)\n", regs->pc,
regs->cycle, regs->next_interupt, regs->next_interupt - regs->cycle);
evprintf("+exec %08x, %u->%u (%d)\n", regs->pc, regs->cycle,
regs->next_interupt, regs->next_interupt - regs->cycle);

new_dyna_start(drc_local);

evprintf("ari64_execute end %08x, %u->%u (%d)\n", regs->pc,
regs->cycle, regs->next_interupt, regs->next_interupt - regs->cycle);
evprintf("-exec %08x, %u->%u (%d) stop %d \n", regs->pc, regs->cycle,
regs->next_interupt, regs->next_interupt - regs->cycle, regs->stop);
}

static void ari64_execute(struct psxRegisters *regs)
Expand Down 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
4 changes: 2 additions & 2 deletions libpcsxcore/new_dynarec/linkage_arm.S
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ FUNCTION(cc_interrupt):
ldr r10, [fp, #LO_cycle]
ldr r0, [fp, #LO_pcaddr]
ldr r1, [fp, #LO_next_interupt]
ldr r2, [fp, #LO_stop]
ldrb r2, [fp, #LO_stop]
str r1, [fp, #LO_last_count]
sub r10, r10, r1
tst r2, r2
Expand Down Expand Up @@ -307,7 +307,7 @@ call_psxException:
/* note: psxException might do recursive recompiler call from it's HLE code,
* so be ready for this */
FUNCTION(jump_to_new_pc):
ldr r2, [fp, #LO_stop]
ldrb r2, [fp, #LO_stop]
ldr r1, [fp, #LO_next_interupt]
ldr r10, [fp, #LO_cycle]
ldr r0, [fp, #LO_pcaddr]
Expand Down
4 changes: 2 additions & 2 deletions libpcsxcore/new_dynarec/linkage_arm64.S
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ FUNCTION(cc_interrupt):
ldr rCC, [rFP, #LO_cycle]
ldr w0, [rFP, #LO_pcaddr]
ldr w1, [rFP, #LO_next_interupt]
ldr w2, [rFP, #LO_stop]
ldrb w2, [rFP, #LO_stop]
str w1, [rFP, #LO_last_count]
sub rCC, rCC, w1
cbnz w2, new_dyna_leave
Expand Down Expand Up @@ -169,7 +169,7 @@ call_psxException:
/* note: psxException might do recursive recompiler call from it's HLE code,
* so be ready for this */
FUNCTION(jump_to_new_pc):
ldr w2, [rFP, #LO_stop]
ldrb w2, [rFP, #LO_stop]
ldr w1, [rFP, #LO_next_interupt]
ldr rCC, [rFP, #LO_cycle]
ldr w0, [rFP, #LO_pcaddr]
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
11 changes: 4 additions & 7 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 @@ -63,7 +61,6 @@ static irq_func * const irq_funcs[] = {
[PSXINT_RCNT] = psxRcntUpdate,
};

/* local dupe of psxBranchTest, using event_cycles */
void irq_test(psxCP0Regs *cp0)
{
psxRegisters *regs = cp0TOpsxRegs(cp0);
Expand All @@ -73,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 @@ -105,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 cf0cd7c

Please sign in to comment.