Timer
-----
Sometimes it's useful to have a timer that interrupts at
regular intervals for routines that require periodic or
percise updates. The timer in the GameBoy has a selectable
frequency of 4096, 16384, 65536, or 262144 Hertz. This
frequency increments the Timer Counter (TIMA). When it
overflows, it generates an interrupt. It is then loaded
with the contents of Timer Modulo (TMA). The following
are examples:
;This interval timer interrupts 4096 times per second
ld a,-1
ld ($FF06),a ;Set TMA to divide clock by 1
ld a,4
ld ($FF07),a ;Set clock to 4096 Hertz
;This interval timer interrupts 65536 times per second
ld a,-4
ld ($FF06),a ;Set TMA to divide clock by 4
ld a,5
ld ($FF07),a ;Set clock to 262144 Hertz