mirror of
https://github.com/cc65/cc65.git
synced 2024-06-30 16:29:58 +00:00
Added an implementation of clock() for the Lynx console. By Greg King.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5477 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
b32b663b2c
commit
c03a5caf19
|
@ -6,7 +6,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2005 Ullrich von Bassewitz */
|
/* (C) 1998-2012 Ullrich von Bassewitz */
|
||||||
/* Römerstrasse 52 */
|
/* Römerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
|
@ -99,6 +99,12 @@ unsigned _clocks_per_sec (void);
|
||||||
#elif defined(__GEOS__)
|
#elif defined(__GEOS__)
|
||||||
# define CLK_TCK 1 /* POSIX */
|
# define CLK_TCK 1 /* POSIX */
|
||||||
# define CLOCKS_PER_SEC 1 /* ANSI */
|
# define CLOCKS_PER_SEC 1 /* ANSI */
|
||||||
|
#elif defined(__LYNX__)
|
||||||
|
/* The clock-rate depends on the video scan-rate;
|
||||||
|
** so, read it at run-time. */
|
||||||
|
extern clock_t _clk_tck (void);
|
||||||
|
# define CLK_TCK _clk_tck()
|
||||||
|
# define CLOCKS_PER_SEC _clk_tck()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
|
||||||
OBJS = bllhdr.o \
|
OBJS = bllhdr.o \
|
||||||
bootldr.o \
|
bootldr.o \
|
||||||
cgetc.o \
|
cgetc.o \
|
||||||
|
clock.o \
|
||||||
crt0.o \
|
crt0.o \
|
||||||
ctype.o \
|
ctype.o \
|
||||||
defdir.o \
|
defdir.o \
|
||||||
|
|
91
libsrc/lynx/clock.s
Normal file
91
libsrc/lynx/clock.s
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
;
|
||||||
|
; 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 "INIT"
|
||||||
|
init_clock:
|
||||||
|
lda #%10000000
|
||||||
|
tsb VTIMCTLA
|
||||||
|
rts
|
||||||
|
|
||||||
|
;-----------------------------------------------------------------------------
|
||||||
|
;
|
||||||
|
.bss
|
||||||
|
clock_count:
|
||||||
|
.res 3
|
Loading…
Reference in New Issue
Block a user