From WSdev Wiki
Jump to navigationJump to search

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.


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 ($A2, $A3)

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.

Horizontal Blank Timer Reload ($A4, $A5)

Vertical Blank Timer Reload ($A6, $A7)

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.

Horizontal Blank Timer Counter ($A8, $A9 read)

Vertical Blank Timer Counter ($AA, $AB read)

Contains the current value of the counter.

Note that if auto-reload is enabled, this will never contain the value zero.