Timers: Difference between revisions

From WSdev Wiki
Jump to navigationJump to search
m (Register formatting.)
(adjust port category name formatting)
 
Line 14: Line 14:
== I/O Ports ==
== I/O Ports ==


=== Timer Control ===
=== Timer Control ($A2, $A3) ===


<pre>
<pre>
Line 27: Line 27:
</pre>
</pre>


=== Timer Reload ===
{{Anchor|Timer Reload}}
=== Horizontal Blank Timer Reload ($A4, $A5) ===


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.
=== Vertical Blank Timer Reload ($A6, $A7) ===


=== Timer Counter ===
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.


Read-only; contains the current value of the counter.
{{Anchor|Timer Counter}}
=== 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.
Note that if auto-reload is enabled, this will never contain the value zero.

Latest revision as of 11:51, 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 ($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.