Skip to content

Commit 1351a8f

Browse files
committed
adjust irq10 and rcnt for pal
#723
1 parent 1e93efc commit 1351a8f

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

libpcsxcore/psxcounters.c

+33-17
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ enum
6161
static const u32 CountToOverflow = 0;
6262
static const u32 CountToTarget = 1;
6363

64-
static const u32 FrameRate[] = { 60, 50 };
65-
static const u32 HSyncTotal[] = { 263, 314 }; // actually one more on odd lines for PAL
66-
#define VBlankStart 240
64+
static const u32 HSyncTotal[] = { 263, 314 };
65+
#define VBlankStart 240 // todo: depend on the actual GPU setting
6766

6867
#define VERBOSE_LEVEL 0
6968

@@ -79,6 +78,15 @@ u32 psxNextCounter = 0, psxNextsCounter = 0;
7978

8079
/******************************************************************************/
8180

81+
static inline
82+
u32 lineCycles(void)
83+
{
84+
if (Config.PsxType)
85+
return PSXCLK / 50 / HSyncTotal[1];
86+
else
87+
return PSXCLK / 60 / HSyncTotal[0];
88+
}
89+
8290
static inline
8391
void setIrq( u32 irq )
8492
{
@@ -170,7 +178,7 @@ void _psxRcntWmode( u32 index, u32 value )
170178
case 1:
171179
if( value & Rc1HSyncClock )
172180
{
173-
rcnts[index].rate = (PSXCLK / (FrameRate[Config.PsxType] * HSyncTotal[Config.PsxType]));
181+
rcnts[index].rate = lineCycles();
174182
}
175183
else
176184
{
@@ -327,10 +335,10 @@ void psxRcntUpdate()
327335
{
328336
if (((rcnts[0].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset) ||
329337
(rcnts[0].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset2))
330-
&& cycles_passed > PSXCLK / 60 / 263)
338+
&& cycles_passed > lineCycles())
331339
{
332-
u32 q = cycles_passed / (PSXCLK / 60 / 263 + 1u);
333-
rcnts[0].cycleStart += q * (PSXCLK / 60) / 263u;
340+
u32 q = cycles_passed / (lineCycles() + 1u);
341+
rcnts[0].cycleStart += q * lineCycles();
334342
break;
335343
}
336344
else
@@ -375,7 +383,7 @@ void psxRcntUpdate()
375383
// Update lace.
376384
if( hSyncCount >= HSyncTotal[Config.PsxType] )
377385
{
378-
u32 status, field = 0, i;
386+
u32 status, field = 0;
379387
rcnts[3].cycleStart += Config.PsxType ? PSXCLK / 50 : PSXCLK / 60;
380388
hSyncCount = 0;
381389
frame_counter++;
@@ -390,13 +398,21 @@ void psxRcntUpdate()
390398
HW_GPU_STATUS = SWAP32(status);
391399
GPU_vBlank(0, field);
392400

393-
for (i = 0; i < 2; i++)
401+
if ((rcnts[0].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset) ||
402+
(rcnts[0].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset2))
403+
{
404+
rcnts[0].cycleStart = rcnts[3].cycleStart;
405+
}
406+
407+
if ((rcnts[1].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset) ||
408+
(rcnts[1].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset2))
409+
{
410+
rcnts[1].cycleStart = rcnts[3].cycleStart;
411+
}
412+
else if (rcnts[1].mode & Rc1HSyncClock)
394413
{
395-
if ((rcnts[i].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset) ||
396-
(rcnts[i].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset2))
397-
{
398-
rcnts[i].cycleStart = rcnts[3].cycleStart;
399-
}
414+
// adjust to remove the rounding error
415+
_psxRcntWcount(1, (psxRegs.cycle - rcnts[1].cycleStart) / rcnts[1].rate);
400416
}
401417
}
402418

@@ -452,7 +468,8 @@ u32 psxRcntRcount0()
452468
(rcnts[0].mode & 7) == (RcSyncModeEnable | Rc01UnblankReset2))
453469
{
454470
count = psxRegs.cycle - rcnts[index].cycleStart;
455-
count = ((16u * count) % (16u * PSXCLK / 60 / 263)) / 16u;
471+
//count = ((16u * count) % (16u * PSXCLK / 60 / 263)) / 16u;
472+
count = count % lineCycles();
456473
rcnts[index].cycleStart = psxRegs.cycle - count;
457474
}
458475
else
@@ -526,8 +543,6 @@ void psxRcntInit()
526543

527544
// rcnt base.
528545
rcnts[3].rate = 1;
529-
rcnts[3].mode = RcCountToTarget;
530-
rcnts[3].target = (PSXCLK / (FrameRate[Config.PsxType] * HSyncTotal[Config.PsxType]));
531546

532547
for( i = 0; i < CounterQuantity; ++i )
533548
{
@@ -537,6 +552,7 @@ void psxRcntInit()
537552
hSyncCount = 0;
538553
hsync_steps = 1;
539554

555+
scheduleRcntBase();
540556
psxRcntSet();
541557
}
542558

libpcsxcore/r3000a.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,11 @@ void irq10Interrupt() {
280280
irq10count, psxRegs.cycle - prevc,
281281
(psxRegs.CP0.n.SR & 0x401) != 0x401, !(psxHu32(0x1074) & 0x400));
282282
#endif
283-
if (--irq10count > 0)
284-
psxScheduleIrq10One(prevc + PSXCLK / 60 / 263);
283+
if (--irq10count > 0) {
284+
u32 cycles_per_line = Config.PsxType
285+
? PSXCLK / 50 / 314 : PSXCLK / 60 / 263;
286+
psxScheduleIrq10One(prevc + cycles_per_line);
287+
}
285288
}
286289

287290
void psxScheduleIrq10(int irq_count, int x_cycles, int y) {

0 commit comments

Comments
 (0)