2 ; 2003-04-13, Ullrich von Bassewitz
3 ; 2012-02-06, Greg King
7 ; typedef unsigned long int clock_t;
8 ; clock_t _clk_tck(void);
9 ; #define CLOCKS_PER_SEC _clk_tck()
10 ; clock_t clock(void);
12 ; clk_tck()'s test-values are based on the numbers in "set_tv.s".
13 ; If you change the numbers there, then change them here, too.
16 .export _clock, __clk_tck, clock_count
17 .interruptor update_clock, 2 ; (low priority)
18 .constructor init_clock
28 sei ; Disable interrupts
30 ; Read the clock counter.
36 plp ; Re-enable interrupts
38 stz sreg+1 ; Promote 24 bits up to 32 bits
42 ;-----------------------------------------------------------------------------
43 ; Return the number of clock ticks in one second.
46 ldx #$00 ; >50, >60, >75
55 @ok: stz sreg ; return 32 bits
59 ;-----------------------------------------------------------------------------
60 ; This interrupt handler increments a 24-bit counter at every video
61 ; vertical-blanking time.
67 beq @NotVBlank ; Not vertical-blank interrupt
74 @L1: ;clc ; General interrupt was not reset
78 ;-----------------------------------------------------------------------------
79 ; Enable the interrupt that update_clock needs.
87 ;-----------------------------------------------------------------------------