{
struct CIA *c = &cia[num];
c->tod_event_state = 3; // done
- if (!c->todon)
+ if (!c->todon) {
return;
+ }
c->tod++;
c->tod &= 0xFFFFFF;
cia_checkalarm(true, irq, num);
static void CIA_tod_inc_event(uae_u32 num)
{
struct CIA *c = &cia[num];
- if (c->tod_event_state != 2)
+ if (c->tod_event_state != 2) {
return;
+ }
CIA_tod_inc(true, num);
}
event2_newevent_xx(-1, -hpos * CYCLE_UNIT, num, CIA_tod_inc_event);
}
-static void CIA_tod_handler(int hoffset, int num)
+static void CIA_tod_handler(int hoffset, int num, bool delayedevent)
{
struct CIA *c = &cia[num];
c->tod_event_state = 0;
c->tod_offset = tod_inc_delay(hoffset);
if (c->tod_offset >= maxhpos) {
+ if (!delayedevent) {
+ return;
+ }
+ // crossed scanline, increase in next line
+ c->tod_offset -= maxhpos;
+ c->tod_event_state = 4;
return;
}
c->tod_event_state = 1; // TOD inc needed
return;
}
#endif
- CIA_tod_handler(hoffset, 0);
+ CIA_tod_handler(hoffset, 0, true);
}
void CIAB_tod_handler(int hoffset)
{
- CIA_tod_handler(hoffset, 1);
+ CIA_tod_handler(hoffset, 1, false);
}
void keyboard_connected(bool connect)
static void cia_delayed_tod(int num)
{
struct CIA *c = &cia[num];
- if (c->tod_event_state == 1)
+ if (c->tod_event_state == 1) {
CIA_tod_inc(false, num);
+ }
c->tod_event_state = 0;
c->tod_offset = -1;
}
if (!ciahsync) {
// Increase CIA-A TOD if delayed from previous line
+ struct CIA *c = &cia[0];
+ if (c->tod_event_state == 4) {
+ c->tod_event_state = 1;
+ }
cia_delayed_tod(0);
if (currprefs.tod_hack && cia[0].todon) {
do_tod_hack();