}
// timer state - FIXME
-static u32 timer_cycles[2];
+static u32 timer_cycles[2]; // TODO save this in state!
static u32 timer_tick_cycles[2];
static u32 timer_tick_factor[2];
sh2s[i].state |= SH2_TIMER_RUN;
tmp = PREG8(sh2s[i].peri_regs, 0x80) & 7;
// Sclk cycles per timer tick
- cycles = 2;
- if (tmp)
- cycles <<= tmp + 4;
- if (tmp >= 6)
- cycles <<= 1;
+ if (tmp >= 6) tmp++;
+ if (tmp) tmp += 5;
+ else tmp = 1;
+ cycles = 1 << tmp;
timer_tick_cycles[i] = cycles;
- timer_tick_factor[i] = (1ULL << 32) / cycles;
+ timer_tick_factor[i] = tmp;
timer_cycles[i] = 0;
elprintf(EL_32XP, "WDT cycles[%d] = %d", i, cycles);
}
// WDT timer
timer_cycles[i] += cycles;
if (timer_cycles[i] > timer_tick_cycles[i]) {
- // cnt = timer_cycles[i] / timer_tick_cycles[i];
- cnt = (1ULL * timer_cycles[i] * timer_tick_factor[i]) >> 32;
+ cnt = (timer_cycles[i] >> timer_tick_factor[i]);
timer_cycles[i] -= timer_tick_cycles[i] * cnt;
cnt += PREG8(pregs, 0x81);