@@ -108,8 +108,8 @@ void cdc_reset(void)
108
108
cdc .head [1 ][2 ] = 0x00 ;
109
109
cdc .head [1 ][3 ] = 0x00 ;
110
110
111
- /* reset CDC DMA cycle counter */
112
- cdc .cycles = 0 ;
111
+ /* reset CDC DMA & decoder cycle counters */
112
+ cdc .cycles [ 0 ] = cdc . cycles [ 1 ] = 0 ;
113
113
114
114
/* disable CDC DMA */
115
115
cdc .dma_w = cdc .halted_dma_w = 0 ;
@@ -176,7 +176,6 @@ int cdc_context_save(uint8 *state)
176
176
save_param (& cdc .head , sizeof (cdc .head ));
177
177
save_param (& cdc .stat , sizeof (cdc .stat ));
178
178
save_param (& cdc .cycles , sizeof (cdc .cycles ));
179
- save_param (& cdc .dma_w , sizeof (cdc .dma_w ));
180
179
save_param (& cdc .ram , sizeof (cdc .ram ));
181
180
save_param (& tmp8 , 1 );
182
181
@@ -198,7 +197,6 @@ int cdc_context_load(uint8 *state)
198
197
load_param (& cdc .head , sizeof (cdc .head ));
199
198
load_param (& cdc .stat , sizeof (cdc .stat ));
200
199
load_param (& cdc .cycles , sizeof (cdc .cycles ));
201
- load_param (& cdc .dma_w , sizeof (cdc .dma_w ));
202
200
load_param (& cdc .ram , sizeof (cdc .ram ));
203
201
204
202
load_param (& tmp8 , 1 );
@@ -290,6 +288,16 @@ void cdc_dma_init(void)
290
288
/* Data Transfer End interrupt enabled ? */
291
289
if (cdc .ifctrl & BIT_DTEIEN )
292
290
{
291
+ /* check end of CDC decoder active period */
292
+ if ((cdc .irq & BIT_DECI ) && (cdc .cycles [0 ] > cdc .cycles [1 ]))
293
+ {
294
+ /* clear pending decoder interrupt */
295
+ cdc .ifstat |= BIT_DECI ;
296
+
297
+ /* update CDC IRQ state */
298
+ cdc .irq &= ~BIT_DECI ;
299
+ }
300
+
293
301
/* level 5 interrupt triggered only on CDC /INT falling edge with interrupt enabled on gate-array side */
294
302
if (!cdc .irq && (scd .regs [0x32 >>1 ].byte .l & 0x20 ))
295
303
{
@@ -380,7 +388,7 @@ void cdc_dma_init(void)
380
388
void cdc_dma_update (unsigned int cycles )
381
389
{
382
390
/* max number of bytes that can be transfered */
383
- int dma_bytes = (cycles - cdc .cycles + DMA_CYCLES_PER_BYTE - 1 ) / DMA_CYCLES_PER_BYTE ;
391
+ int dma_bytes = (cycles - cdc .cycles [ 0 ] + DMA_CYCLES_PER_BYTE - 1 ) / DMA_CYCLES_PER_BYTE ;
384
392
385
393
/* always process blocks of 8 bytes */
386
394
dma_bytes = (dma_bytes / 8 ) * 8 ;
@@ -391,6 +399,9 @@ void cdc_dma_update(unsigned int cycles)
391
399
/* transfer remaining bytes using DMA */
392
400
cdc .dma_w (cdc .dbc .w + 1 );
393
401
402
+ /* update DMA cycle counter */
403
+ cdc .cycles [0 ] += (cdc .dbc .w + 1 ) * DMA_CYCLES_PER_BYTE ;
404
+
394
405
/* reset data byte counter (DBCH bits 4-7 should also be set to 1) */
395
406
cdc .dbc .w = 0xffff ;
396
407
@@ -403,6 +414,16 @@ void cdc_dma_update(unsigned int cycles)
403
414
/* Data Transfer End interrupt enabled ? */
404
415
if (cdc .ifctrl & BIT_DTEIEN )
405
416
{
417
+ /* check end of CDC decoder active period */
418
+ if ((cdc .irq & BIT_DECI ) && (cdc .cycles [0 ] > cdc .cycles [1 ]))
419
+ {
420
+ /* clear pending decoder interrupt */
421
+ cdc .ifstat |= BIT_DECI ;
422
+
423
+ /* update CDC IRQ state */
424
+ cdc .irq &= ~BIT_DECI ;
425
+ }
426
+
406
427
/* level 5 interrupt triggered only on CDC /INT falling edge with interrupt enabled on gate-array side*/
407
428
if (!cdc .irq && (scd .regs [0x32 >>1 ].byte .l & 0x20 ))
408
429
{
@@ -424,7 +445,7 @@ void cdc_dma_update(unsigned int cycles)
424
445
if (s68k .stopped & (1 <<0x04 ))
425
446
{
426
447
/* sync SUB-CPU with CDC DMA */
427
- s68k .cycles = cdc .cycles ;
448
+ s68k .cycles = cdc .cycles [ 0 ] ;
428
449
429
450
/* restart SUB-CPU */
430
451
s68k .stopped = 0 ;
@@ -445,7 +466,7 @@ void cdc_dma_update(unsigned int cycles)
445
466
cdc .dbc .w -= dma_bytes ;
446
467
447
468
/* update DMA cycle counter */
448
- cdc .cycles += dma_bytes * DMA_CYCLES_PER_BYTE ;
469
+ cdc .cycles [ 0 ] += dma_bytes * DMA_CYCLES_PER_BYTE ;
449
470
}
450
471
}
451
472
@@ -463,6 +484,9 @@ void cdc_decoder_update(uint32 header)
463
484
/* pending decoder interrupt */
464
485
cdc .ifstat &= ~BIT_DECI ;
465
486
487
+ /* update CDC decoder end cycle (value adjusted for MCD-verificator CDC FLAGS Tests #40 & #41) */
488
+ cdc .cycles [1 ] = s68k .cycles + 269000 ;
489
+
466
490
/* decoder interrupt enabled ? */
467
491
if (cdc .ifctrl & BIT_DECIEN )
468
492
{
@@ -555,6 +579,16 @@ void cdc_reg_w(unsigned char data)
555
579
{
556
580
/* previous CDC IRQ state */
557
581
uint8 prev_irq = cdc .irq ;
582
+
583
+ /* check end of CDC decoder active period */
584
+ if (s68k .cycles > cdc .cycles [1 ])
585
+ {
586
+ /* clear pending decoder interrupt */
587
+ cdc .ifstat |= BIT_DECI ;
588
+
589
+ /* update previous CDC IRQ state */
590
+ prev_irq &= ~BIT_DECI ;
591
+ }
558
592
559
593
/* update CDC IRQ state according to DTEIEN and DECIEN bits */
560
594
cdc .irq = ~cdc .ifstat & data & (BIT_DTEIEN | BIT_DECIEN );
@@ -614,7 +648,7 @@ void cdc_reg_w(unsigned char data)
614
648
cdc_dma_init ();
615
649
616
650
/* initialize DMA cycle counter */
617
- cdc .cycles = s68k .cycles ;
651
+ cdc .cycles [ 0 ] = s68k .cycles ;
618
652
}
619
653
620
654
break ;
@@ -708,6 +742,16 @@ unsigned char cdc_reg_r(void)
708
742
{
709
743
case 0x01 : /* IFSTAT */
710
744
{
745
+ /* check end of CDC decoder active period */
746
+ if (s68k .cycles > cdc .cycles [1 ])
747
+ {
748
+ /* clear pending decoder interrupt */
749
+ cdc .ifstat |= BIT_DECI ;
750
+
751
+ /* update CDC IRQ state */
752
+ cdc .irq &= ~BIT_DECI ;
753
+ }
754
+
711
755
data = cdc .ifstat ;
712
756
break ;
713
757
}
@@ -869,6 +913,16 @@ unsigned short cdc_host_r(uint8 cpu_access)
869
913
/* Data Transfer End interrupt enabled ? */
870
914
if (cdc .ifctrl & BIT_DTEIEN )
871
915
{
916
+ /* check end of CDC decoder active period */
917
+ if ((cdc .irq & BIT_DECI ) && (cdc .cycles [0 ] > cdc .cycles [1 ]))
918
+ {
919
+ /* clear pending decoder interrupt */
920
+ cdc .ifstat |= BIT_DECI ;
921
+
922
+ /* update CDC IRQ state */
923
+ cdc .irq &= ~BIT_DECI ;
924
+ }
925
+
872
926
/* level 5 interrupt triggered only on CDC /INT falling edge with interrupt enabled on gate-array side */
873
927
if (!cdc .irq && (scd .regs [0x32 >>1 ].byte .l & 0x20 ))
874
928
{
0 commit comments