Timers: Difference between revisions
(Created page with "The WonderSwan features two timers: * Horizontal Blank Timer - counts down every horizontal blank (256 CPU cycles), * Vertical Blank Timer - counts down every frame. The timers also feature an auto-reload functionality: that is, they can be configured to fire one time or repeat periodically. == Interrupts == Each timer has its own interrupt; it is triggered when the counter would be about to count down to zero, that is when the counter's value is 1 and the timer cond...") |
No edit summary |
||
Line 2: | Line 2: | ||
* Horizontal Blank Timer - counts down every horizontal blank (256 CPU cycles), | * Horizontal Blank Timer - counts down every horizontal blank (256 CPU cycles), | ||
* Vertical Blank Timer - counts down every | * Vertical Blank Timer - counts down every vertical blank (beginning of line 144). | ||
The timers also feature an auto-reload functionality: that is, they can be configured to fire one time or repeat periodically. | The timers also feature an auto-reload functionality: that is, they can be configured to fire one time or repeat periodically. |
Revision as of 06:22, 22 August 2023
The WonderSwan features two timers:
- Horizontal Blank Timer - counts down every horizontal blank (256 CPU cycles),
- Vertical Blank Timer - counts down every vertical blank (beginning of line 144).
The timers also feature an auto-reload functionality: that is, they can be configured to fire one time or repeat periodically.
Interrupts
Each timer has its own interrupt; it is triggered when the counter would be about to count down to zero, that is when the counter's value is 1 and the timer condition occurs.
This leads to a quirk: the timer interrupt will be triggered if the reload value is set to one even if the timer countdown is disabled, so long as the interrupt is enabled.
I/O Ports
Timer Control
7 bit 0 ---- ---- .... VvHh |||+- Horizontal blank timer: Enable countdown. ||+-- Horizontal blank timer: 0: One-shot, 1: Repeat/auto-reload. |+--- Vertical blank timer: Enable countdown. +---- Vertical blank timer: 0: One-shot, 1: Repeat/auto-reload.
Timer Reload
Read/write; contains the initial counter value. The Timer Counter port is immediately initialized with this value upon writing. If auto-reload is enabled, the interrupt trigger will re-initialize the Timer Counter port with this value.
Timer Counter
Read-only; contains the current value of the counter.
Note that if auto-reload is enabled, this will never contain the value zero.