partial fix to CIA timer: avoid timer's desync in read count operation

This commit is contained in:
Roberto Zandona 2009-09-07 05:40:59 +00:00
parent 8fbe10c91f
commit 24745e0c58

View File

@ -361,6 +361,25 @@ static void cia_timer_update(cia_timer *timer, INT32 new_count)
} }
} }
/*-------------------------------------------------
cia_get_timer - get the count
for a given CIA timer
-------------------------------------------------*/
static UINT16 cia_get_timer(cia_timer *timer)
{
UINT16 count;
if (is_timer_active(timer->timer))
{
UINT16 current_count = attotime_to_double(attotime_mul(timer_timeelapsed(timer->timer), timer->cia->device->clock));
count = timer->count - MIN(timer->count, current_count);
}
else
count = timer->count;
return count;
}
/*------------------------------------------------- /*-------------------------------------------------
cia_timer_bump cia_timer_bump
@ -684,16 +703,14 @@ READ8_DEVICE_HANDLER( cia_r )
case CIA_TALO: case CIA_TALO:
case CIA_TBLO: case CIA_TBLO:
timer = &cia->timer[(offset >> 1) & 1]; timer = &cia->timer[(offset >> 1) & 1];
cia_timer_update(timer, -1); data = cia_get_timer(timer) >> 0;
data = timer->count >> 0;
break; break;
/* timer A/B high byte */ /* timer A/B high byte */
case CIA_TAHI: case CIA_TAHI:
case CIA_TBHI: case CIA_TBHI:
timer = &cia->timer[(offset >> 1) & 1]; timer = &cia->timer[(offset >> 1) & 1];
cia_timer_update(timer, -1); data = cia_get_timer(timer) >> 8;
data = timer->count >> 8;
break; break;
/* TOD counter */ /* TOD counter */
@ -745,6 +762,7 @@ READ8_DEVICE_HANDLER( cia_r )
data = timer->mode; data = timer->mode;
break; break;
} }
return data; return data;
} }