2009-01-22 01:27:03 +00:00
|
|
|
; timer routines
|
|
|
|
;
|
|
|
|
; the timer should be a 16-bit counter that's incremented by about
|
2009-03-28 02:06:49 +00:00
|
|
|
; 1000 units per second. it doesn't have to be particularly accurate.
|
|
|
|
; this C64 implementation requires the routine timer_vbl_handler be called 60 times per second
|
2009-01-22 01:27:03 +00:00
|
|
|
|
|
|
|
.include "../inc/common.i"
|
|
|
|
|
|
|
|
|
|
|
|
.export timer_init
|
|
|
|
.export timer_read
|
2009-03-28 02:06:49 +00:00
|
|
|
.export timer_vbl_handler
|
|
|
|
|
|
|
|
.code
|
|
|
|
.bss
|
|
|
|
current_time_value: .res 2
|
|
|
|
|
2009-01-22 01:27:03 +00:00
|
|
|
.code
|
|
|
|
|
2009-03-28 02:06:49 +00:00
|
|
|
;reset timer to 0
|
2009-03-21 06:40:53 +00:00
|
|
|
;inputs: none
|
|
|
|
;outputs: none
|
2009-01-22 01:27:03 +00:00
|
|
|
timer_init:
|
2009-03-28 02:06:49 +00:00
|
|
|
ldax #0
|
|
|
|
stax current_time_value
|
2009-01-22 01:27:03 +00:00
|
|
|
rts
|
|
|
|
|
2009-03-28 02:06:49 +00:00
|
|
|
;read the current timer value
|
|
|
|
; inputs: none
|
|
|
|
; outputs: AX = current timer value (roughly equal to number of milliseconds since the last call to 'timer_init')
|
2009-01-22 01:27:03 +00:00
|
|
|
timer_read:
|
2009-03-28 02:06:49 +00:00
|
|
|
ldax current_time_value
|
|
|
|
rts
|
|
|
|
|
|
|
|
; tick over the current timer value - should be called 60 times per second
|
|
|
|
; inputs: none
|
|
|
|
; outputs: none (all registers preserved, by carry flag can be modified)
|
|
|
|
timer_vbl_handler:
|
|
|
|
pha
|
|
|
|
lda #$11
|
|
|
|
adc current_time_value
|
|
|
|
sta current_time_value
|
|
|
|
bcc :+
|
|
|
|
inc current_time_value+1
|
|
|
|
:
|
|
|
|
pla
|
|
|
|
rts
|