1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-08 13:04:52 +00:00
cc65/libsrc/lynx/clock.s
Oliver Schmidt 419eb700b5 Renamed INITBSS to INIT and INIT to ONCE.
The way we want to use the INITBSS segment - and especially the fact that it won't have the type bss on all ROM based targets - means that the name INITBSS is misleading. After all INIT is the best name from my perspective as it serves several purposes and therefore needs a rather generic name.

Unfortunately this means that the current INIT segment needs to be renamed too. Looking for a short (ideally 4 letter) name I came up with ONCE as it contains all code (and data) accessed only once during initialization.
2016-03-06 21:27:19 +01:00

92 lines
2.3 KiB
ArmAsm

;
; 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.
;
.export _clock, __clk_tck, clock_count
.interruptor update_clock, 2 ; (low priority)
.constructor init_clock
.import sreg: zp
.include "lynx.inc"
.macpack generic
.proc _clock
php
sei ; Disable interrupts
; Read the clock counter.
lda clock_count
ldx clock_count+1
ldy clock_count+2
plp ; Re-enable interrupts
sty sreg
stz sreg+1 ; Promote 24 bits up to 32 bits
rts
.endproc
;-----------------------------------------------------------------------------
; Return the number of clock ticks in one second.
;
__clk_tck:
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
;-----------------------------------------------------------------------------
; This interrupt handler increments a 24-bit counter at every video
; vertical-blanking time.
;
.segment "LOWCODE"
update_clock:
lda INTSET
and #%00000100
beq @NotVBlank ; Not vertical-blank interrupt
inc clock_count
bne @L1
inc clock_count+1
bne @L1
inc clock_count+2
@L1: ;clc ; General interrupt was not reset
@NotVBlank:
rts
;-----------------------------------------------------------------------------
; Enable the interrupt that update_clock needs.
;
.segment "ONCE"
init_clock:
lda #%10000000
tsb VTIMCTLA
rts
;-----------------------------------------------------------------------------
;
.bss
clock_count:
.res 3