agon-mos icon indicating copy to clipboard operation
agon-mos copied to clipboard

Fix centisecond timer to count 100 times per second instead of 120.

Open lennart-benschop opened this issue 2 years ago • 2 comments

The centisecond timer is incremented by 2 for every VBLANK interrupt. At least in most modes (hint, hint, you could use QVGA_320x240_60Hz instead of VGA_320x200_75Hz) this interrupt occurs 60 times per second, meaning that the counter is incremented by 120 every second, instead of 100.

Suggestion: keep a modulo-3 counter to track the number of VBLANK IRQs and increment the timer only by 1 for every third VBLANK interrupt, by 2 for the other two. Each second the counter would be incremented by 40 times by 2 and by 20 times by 1. Together this is 2x40+20 = 100 times.

lennart-benschop avatar May 25 '23 19:05 lennart-benschop

An alternative approach would be to use an eZ80 timer, but that would decouple it from the VBLANK interrupt.

breakintoprogram avatar Jul 08 '23 18:07 breakintoprogram

Reading this, it feels to me that we should just have two different timers.

One should be a genuine centisecond timer, de-coupled from the VBLANK interrupt. This should probably use the existing sysvar_time value. This would fix that value, so it would then represent the value it is documented to represent.

The other should be a genuine VBLANK timer, incremented by one every time a VBLANK interrupt happens.

It feels that the suggestion @lennart-benschop has made could fix things, to get it to work properly the code would need to work out what the VBLANK interval actually is, especially given the existence of 75hz modes as well as 60hz modes. I suspect this would be more complex than just having separate timers.

stevesims avatar Aug 11 '23 18:08 stevesims