2012-02-06 20:17:54 +00:00
|
|
|
;
|
|
|
|
; 2003-04-13, Ullrich von Bassewitz
|
|
|
|
; 2012-02-06, Greg King
|
|
|
|
;
|
2020-10-25 13:06:44 +00:00
|
|
|
; clock_t clock (void);
|
|
|
|
; clock_t _clocks_per_sec (void);
|
2012-02-06 20:17:54 +00:00
|
|
|
;
|
2020-10-25 13:06:44 +00:00
|
|
|
; clocks_per_sec()'s test-values are based on the numbers in "set_tv.s".
|
2012-02-06 20:17:54 +00:00
|
|
|
; If you change the numbers there, then change them here, too.
|
|
|
|
;
|
|
|
|
|
2020-10-25 13:06:44 +00:00
|
|
|
.export _clock, __clocks_per_sec, clock_count
|
2013-05-09 11:56:54 +00:00
|
|
|
.interruptor update_clock, 2 ; (low priority)
|
|
|
|
.constructor init_clock
|
2012-02-06 20:17:54 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.import sreg: zp
|
|
|
|
.include "lynx.inc"
|
2012-02-06 20:17:54 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.macpack generic
|
2012-02-06 20:17:54 +00:00
|
|
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc _clock
|
|
|
|
php
|
|
|
|
sei ; Disable interrupts
|
2012-02-06 20:17:54 +00:00
|
|
|
|
|
|
|
; Read the clock counter.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda clock_count
|
|
|
|
ldx clock_count+1
|
|
|
|
ldy clock_count+2
|
2012-02-06 20:17:54 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
plp ; Re-enable interrupts
|
|
|
|
sty sreg
|
|
|
|
stz sreg+1 ; Promote 24 bits up to 32 bits
|
|
|
|
rts
|
|
|
|
.endproc
|
2012-02-06 20:17:54 +00:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
; Return the number of clock ticks in one second.
|
|
|
|
;
|
2020-10-25 13:06:44 +00:00
|
|
|
__clocks_per_sec:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #$00 ; >50, >60, >75
|
|
|
|
ldy PBKUP
|
|
|
|
lda #<75
|
|
|
|
cpy #$20 + 1
|
|
|
|
blt @ok
|
|
|
|
lda #<60
|
|
|
|
cpy #$29 + 1
|
|
|
|
blt @ok
|
|
|
|
lda #<50
|
|
|
|
@ok: stz sreg ; return 32 bits
|
|
|
|
stz sreg+1
|
|
|
|
rts
|
2012-02-06 20:17:54 +00:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
; This interrupt handler increments a 24-bit counter at every video
|
|
|
|
; vertical-blanking time.
|
|
|
|
;
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "LOWCODE"
|
2012-02-06 20:17:54 +00:00
|
|
|
update_clock:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda INTSET
|
|
|
|
and #%00000100
|
|
|
|
beq @NotVBlank ; Not vertical-blank interrupt
|
2012-02-06 20:17:54 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
inc clock_count
|
|
|
|
bne @L1
|
|
|
|
inc clock_count+1
|
|
|
|
bne @L1
|
|
|
|
inc clock_count+2
|
|
|
|
@L1: ;clc ; General interrupt was not reset
|
2012-02-06 20:17:54 +00:00
|
|
|
@NotVBlank:
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2012-02-06 20:17:54 +00:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
; Enable the interrupt that update_clock needs.
|
|
|
|
;
|
2016-03-06 20:26:22 +00:00
|
|
|
.segment "ONCE"
|
2012-02-06 20:17:54 +00:00
|
|
|
init_clock:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #%10000000
|
|
|
|
tsb VTIMCTLA
|
|
|
|
rts
|
2012-02-06 20:17:54 +00:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
;
|
2013-05-09 11:56:54 +00:00
|
|
|
.bss
|
2012-02-06 20:17:54 +00:00
|
|
|
clock_count:
|
2013-05-09 11:56:54 +00:00
|
|
|
.res 3
|