Timers Module
This module controls the hardware timing devices, used for driving the speaker and interrupt line.
Download:
; /////////////////////////////////////////////////////////////
; // Timer Module
; // (c) 1999 Geoff Knagge, Andrew Carr, Mark Lynn
; // last modified : 22/10/1999
; //
; // Setsound adjusts timer 2C to a frequency determined by A
; // Nosound switches off timer 2C be setting it as a strobe
; // initTimers sets up the timers, and turns off the sound.
; //
; /////////////////////////////////////////////////////////////
;// system clock out runs at 4.915MHz
;// 1 ms = 1Khz = 4915 counts
;// 2 KHz = 2457 counts
;// 4 KHZ = 1228 counts
; 500Hz, 1KHz, 2KHz, 4KHz, 3KHz
soundbank: .word 2666, 1333, 999, 4CC, 666;
initTimers:
push af
mvi A,36H ;Timer 2A, 1ms - timing interrupt
out 63
mvi A,33H
out 60
mvi A,13H
out 60
mvi A,76H ;Timer 2B, 10ms - LCD interrupt
out 63
mvi A,0FEH
out 61
mvi A,0BFH
out 61
mvi A,10110110#
out 53
mvi a,0
out 52
mvi a,1
out 52
call noSound ; initialise Timer 2C
pop af
ret
noSound: ; sets timer 2C as a strobe
push af
mvi A,0B8 ; mode 4 - strobe
out 63
mvi a,5 ; low order of count
out 62
mvi a,0 ; high order of count
out 62
pop af
ret
setSound: ; uses Timer 2C to generate a square
; wave. The period is determined by A,
; which indexes the SoundBank array.
push af
push bc
push hl
mov c,a
mvi b,0 ;BC = sound number
lxi hl,soundbank;point HL to delay list
dad bc ;advance HL by BC
mvi A,0B6 ;set the timer to square wave
out 63
mov a,m ;send low byte of appropriate delay
out 62
inx hl
mov a,m ;send high byte of delay
out 62
pop hl
pop bc
pop af
ret
|