2012-02-06 20:17:54 +00:00
|
|
|
;
|
|
|
|
; 2003-04-13, Ullrich von Bassewitz
|
|
|
|
; 2012-02-06, Greg King
|
|
|
|
;
|
|
|
|
; #include <time.h>
|
|
|
|
;
|
|
|
|
; typedef unsigned long int clock_t;
|
|
|
|
; clock_t _clk_tck(void);
|
|
|
|
; #define CLOCKS_PER_SEC _clk_tck()
|
|
|
|
; clock_t clock(void);
|
|
|
|
;
|
|
|
|
; clk_tck()'s test-values are based on the numbers in "set_tv.s".
|
|
|
|
; If you change the numbers there, then change them here, too.
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _clock, __clk_tck, clock_count
|
|
|
|
.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.
|
|
|
|
;
|
|
|
|
__clk_tck:
|
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
|