2013-12-13 21:24:03 +00:00
|
|
|
; timer routines
|
|
|
|
;
|
|
|
|
; the timer should be a 16-bit counter that's incremented by about
|
|
|
|
; 1000 units per second. it doesn't have to be particularly accurate.
|
|
|
|
; this VIC20 implementation requires the routine timer_vbl_handler be called 60 times per second
|
|
|
|
|
2018-02-23 15:36:05 +00:00
|
|
|
.include "../inc/common.inc"
|
2013-12-27 13:57:56 +00:00
|
|
|
|
|
|
|
.export timer_init
|
|
|
|
.export timer_read
|
|
|
|
.export timer_seconds
|
|
|
|
|
|
|
|
IRQ_VECTOR = $314
|
|
|
|
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
current_time_value: .res 2
|
|
|
|
current_seconds: .res 1
|
|
|
|
current_jiffies: .res 1
|
|
|
|
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
jmp_old_handler:
|
|
|
|
.byte $4c ; JMP
|
|
|
|
old_handler:
|
|
|
|
.word $00
|
|
|
|
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
; reset timer to 0
|
|
|
|
; inputs: none
|
|
|
|
; outputs: none
|
2013-12-13 21:24:03 +00:00
|
|
|
timer_init:
|
2015-08-28 12:42:29 +00:00
|
|
|
lda old_handler+1
|
2013-12-13 21:24:03 +00:00
|
|
|
bne @handler_installed
|
2013-12-27 13:57:56 +00:00
|
|
|
ldax IRQ_VECTOR
|
|
|
|
stax old_handler
|
2013-12-13 21:24:03 +00:00
|
|
|
ldax #timer_vbl_handler
|
2013-12-27 13:57:56 +00:00
|
|
|
stax IRQ_VECTOR
|
|
|
|
@handler_installed:
|
|
|
|
lda #0
|
2013-12-13 21:24:03 +00:00
|
|
|
sta current_time_value
|
|
|
|
sta current_time_value+1
|
|
|
|
sta current_seconds
|
|
|
|
sta current_jiffies
|
2013-12-27 13:57:56 +00:00
|
|
|
rts
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; read the current timer value
|
2013-12-13 21:24:03 +00:00
|
|
|
; inputs: none
|
|
|
|
; outputs: AX = current timer value (roughly equal to number of milliseconds since the last call to 'timer_init')
|
|
|
|
timer_read:
|
2013-12-27 13:57:56 +00:00
|
|
|
ldax current_time_value
|
2013-12-13 21:24:03 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; tick over the current timer value - should be called 60 times per second
|
|
|
|
; inputs: none
|
2015-08-28 12:42:29 +00:00
|
|
|
; outputs: none (all registers preserved, but carry flag can be modified)
|
2013-12-13 21:24:03 +00:00
|
|
|
timer_vbl_handler:
|
|
|
|
pha
|
2015-08-28 12:42:29 +00:00
|
|
|
lda #17 ; 60 HZ =~ 17 ms per 'tick'
|
|
|
|
clc
|
2013-12-13 21:24:03 +00:00
|
|
|
adc current_time_value
|
|
|
|
sta current_time_value
|
|
|
|
bcc :+
|
|
|
|
inc current_time_value+1
|
2013-12-27 13:57:56 +00:00
|
|
|
: inc current_jiffies
|
2013-12-13 21:24:03 +00:00
|
|
|
lda current_jiffies
|
2017-09-24 00:26:40 +00:00
|
|
|
cmp #60 ; full second?
|
|
|
|
bne @done ; no, we're done
|
|
|
|
lda #0 ; yes, increment "seconds" counter
|
2013-12-13 21:24:03 +00:00
|
|
|
sta current_jiffies
|
2017-09-24 00:26:40 +00:00
|
|
|
sed
|
|
|
|
clc
|
|
|
|
lda #$01
|
|
|
|
adc current_seconds
|
|
|
|
cld
|
|
|
|
cmp #$60
|
2013-12-13 21:24:03 +00:00
|
|
|
bne :+
|
|
|
|
lda #$00
|
2015-08-28 12:42:29 +00:00
|
|
|
: sta current_seconds
|
2013-12-27 13:57:56 +00:00
|
|
|
@done:
|
2013-12-13 21:24:03 +00:00
|
|
|
pla
|
|
|
|
jmp jmp_old_handler
|
|
|
|
|
|
|
|
timer_seconds:
|
|
|
|
lda current_seconds
|
|
|
|
rts
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
; -- LICENSE FOR c64timer_nb65.s --
|
2013-12-13 21:24:03 +00:00
|
|
|
; The contents of this file are subject to the Mozilla Public License
|
|
|
|
; Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
; compliance with the License. You may obtain a copy of the License at
|
|
|
|
; http://www.mozilla.org/MPL/
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; Software distributed under the License is distributed on an "AS IS"
|
|
|
|
; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
; License for the specific language governing rights and limitations
|
|
|
|
; under the License.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Original Code is ip65.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Initial Developer of the Original Code is Jonno Downes,
|
|
|
|
; jonno@jamtronix.com.
|
|
|
|
; Portions created by the Initial Developer are Copyright (C) 2009
|
2013-12-27 13:57:56 +00:00
|
|
|
; Jonno Downes. All Rights Reserved.
|
2013-12-13 21:24:03 +00:00
|
|
|
; -- LICENSE END --
|