61
61
static const u32 CountToOverflow = 0 ;
62
62
static const u32 CountToTarget = 1 ;
63
63
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
67
66
68
67
#define VERBOSE_LEVEL 0
69
68
@@ -79,6 +78,15 @@ u32 psxNextCounter = 0, psxNextsCounter = 0;
79
78
80
79
/******************************************************************************/
81
80
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
+
82
90
static inline
83
91
void setIrq ( u32 irq )
84
92
{
@@ -170,7 +178,7 @@ void _psxRcntWmode( u32 index, u32 value )
170
178
case 1 :
171
179
if ( value & Rc1HSyncClock )
172
180
{
173
- rcnts [index ].rate = ( PSXCLK / ( FrameRate [ Config . PsxType ] * HSyncTotal [ Config . PsxType ]) );
181
+ rcnts [index ].rate = lineCycles ( );
174
182
}
175
183
else
176
184
{
@@ -327,10 +335,10 @@ void psxRcntUpdate()
327
335
{
328
336
if (((rcnts [0 ].mode & 7 ) == (RcSyncModeEnable | Rc01UnblankReset ) ||
329
337
(rcnts [0 ].mode & 7 ) == (RcSyncModeEnable | Rc01UnblankReset2 ))
330
- && cycles_passed > PSXCLK / 60 / 263 )
338
+ && cycles_passed > lineCycles () )
331
339
{
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 () ;
334
342
break ;
335
343
}
336
344
else
@@ -375,7 +383,7 @@ void psxRcntUpdate()
375
383
// Update lace.
376
384
if ( hSyncCount >= HSyncTotal [Config .PsxType ] )
377
385
{
378
- u32 status , field = 0 , i ;
386
+ u32 status , field = 0 ;
379
387
rcnts [3 ].cycleStart += Config .PsxType ? PSXCLK / 50 : PSXCLK / 60 ;
380
388
hSyncCount = 0 ;
381
389
frame_counter ++ ;
@@ -390,13 +398,21 @@ void psxRcntUpdate()
390
398
HW_GPU_STATUS = SWAP32 (status );
391
399
GPU_vBlank (0 , field );
392
400
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 )
394
413
{
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 );
400
416
}
401
417
}
402
418
@@ -452,7 +468,8 @@ u32 psxRcntRcount0()
452
468
(rcnts [0 ].mode & 7 ) == (RcSyncModeEnable | Rc01UnblankReset2 ))
453
469
{
454
470
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 ();
456
473
rcnts [index ].cycleStart = psxRegs .cycle - count ;
457
474
}
458
475
else
@@ -526,8 +543,6 @@ void psxRcntInit()
526
543
527
544
// rcnt base.
528
545
rcnts [3 ].rate = 1 ;
529
- rcnts [3 ].mode = RcCountToTarget ;
530
- rcnts [3 ].target = (PSXCLK / (FrameRate [Config .PsxType ] * HSyncTotal [Config .PsxType ]));
531
546
532
547
for ( i = 0 ; i < CounterQuantity ; ++ i )
533
548
{
@@ -537,6 +552,7 @@ void psxRcntInit()
537
552
hSyncCount = 0 ;
538
553
hsync_steps = 1 ;
539
554
555
+ scheduleRcntBase ();
540
556
psxRcntSet ();
541
557
}
542
558
0 commit comments