mirror of
https://github.com/bobbimanners/emailler.git
synced 2024-07-30 16:29:13 +00:00
timer now uses 60hz IRQ handler, rather than CIA
git-svn-id: http://svn.code.sf.net/p/netboot65/code@65 93682198-c243-4bdb-bd91-e943c89aac3b
This commit is contained in:
parent
336117a834
commit
13f277ef44
@ -1,50 +1,47 @@
|
|||||||
; timer routines
|
; timer routines
|
||||||
;
|
;
|
||||||
; the timer should be a 16-bit counter that's incremented by about
|
; 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,
|
; 1000 units per second. it doesn't have to be particularly accurate.
|
||||||
; if you're working with e.g. a 60 Hz VBLANK IRQ, adding 17 to the
|
; this C64 implementation requires the routine timer_vbl_handler be called 60 times per second
|
||||||
; counter every frame would be just fine.
|
|
||||||
|
|
||||||
|
|
||||||
.include "../inc/common.i"
|
.include "../inc/common.i"
|
||||||
|
|
||||||
|
|
||||||
.export timer_init
|
.export timer_init
|
||||||
.export timer_read
|
.export timer_read
|
||||||
|
.export timer_vbl_handler
|
||||||
|
|
||||||
|
.code
|
||||||
|
.bss
|
||||||
|
current_time_value: .res 2
|
||||||
|
|
||||||
.code
|
.code
|
||||||
|
|
||||||
;initialize timers
|
;reset timer to 0
|
||||||
;inputs: none
|
;inputs: none
|
||||||
;outputs: none
|
;outputs: none
|
||||||
timer_init:
|
timer_init:
|
||||||
lda #$80 ; stop timers
|
ldax #0
|
||||||
sta $dd0e
|
stax current_time_value
|
||||||
sta $dd0f
|
|
||||||
|
|
||||||
ldax #999 ; timer A to 1000 cycles
|
|
||||||
stax $dd04
|
|
||||||
|
|
||||||
ldax #$ffff ; timer B to max cycles
|
|
||||||
stax $dd06
|
|
||||||
|
|
||||||
lda #$81 ; timer A in continuous mode
|
|
||||||
sta $dd0e
|
|
||||||
|
|
||||||
lda #$c1 ; timer B to count timer A underflows
|
|
||||||
sta $dd0f
|
|
||||||
|
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
;read the current timer value
|
||||||
;initialize timers
|
; inputs: none
|
||||||
;inputs: none
|
; outputs: AX = current timer value (roughly equal to number of milliseconds since the last call to 'timer_init')
|
||||||
;outputs: AX = count in milliseconds sent last call to timer_init
|
|
||||||
timer_read:
|
timer_read:
|
||||||
lda $dd07 ; cia counts backwards, return inverted value
|
ldax current_time_value
|
||||||
eor #$ff
|
|
||||||
tax
|
|
||||||
lda $dd06
|
|
||||||
eor #$ff
|
|
||||||
rts
|
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
|
Loading…
Reference in New Issue
Block a user