Added real-time clock functions to the cx16 library.
This commit is contained in:
36
libsrc/cx16/getres.s
Normal file
36
libsrc/cx16/getres.s
Normal file
@@ -0,0 +1,36 @@
|
||||
;
|
||||
; 2019-12-26, Greg King
|
||||
;
|
||||
; int __fastcall__ clock_getres (clockid_t clk_id, struct timespec *res);
|
||||
;
|
||||
|
||||
.include "time.inc"
|
||||
|
||||
.importzp ptr1
|
||||
.import incsp1, return0
|
||||
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
|
||||
.proc _clock_getres
|
||||
|
||||
sta ptr1
|
||||
stx ptr1+1
|
||||
|
||||
ldy #.sizeof(timespec) - 1
|
||||
@L1: lda time,y
|
||||
sta (ptr1),y
|
||||
dey
|
||||
bpl @L1
|
||||
|
||||
jsr incsp1
|
||||
jmp return0
|
||||
|
||||
.endproc
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
; timespec struct with tv_nsec set to approximately 1/60 of a second
|
||||
.rodata
|
||||
|
||||
time: .dword 0
|
||||
.dword 17 * 1000 * 1000
|
||||
56
libsrc/cx16/gettime.s
Normal file
56
libsrc/cx16/gettime.s
Normal file
@@ -0,0 +1,56 @@
|
||||
;
|
||||
; 2019-12-27, Greg King
|
||||
;
|
||||
; int __fastcall__ clock_gettime (clockid_t clk_id, struct timespec *tp);
|
||||
;
|
||||
|
||||
.include "time.inc"
|
||||
.include "cx16.inc"
|
||||
|
||||
.import pushax, pusheax, tosmul0ax, steaxspidx, incsp1, return0
|
||||
.import TM, load_jiffy
|
||||
.import CLOCK_GET_DATE_TIME
|
||||
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
|
||||
.proc _clock_gettime
|
||||
|
||||
jsr pushax
|
||||
jsr pushax
|
||||
|
||||
jsr CLOCK_GET_DATE_TIME
|
||||
|
||||
lda gREG::r0L
|
||||
sta TM + tm::tm_year
|
||||
lda gREG::r0H
|
||||
dec a
|
||||
sta TM + tm::tm_mon
|
||||
lda gREG::r1L
|
||||
sta TM + tm::tm_mday
|
||||
|
||||
lda gREG::r1H
|
||||
sta TM + tm::tm_hour
|
||||
lda gREG::r2L
|
||||
sta TM + tm::tm_min
|
||||
lda gREG::r2H
|
||||
sta TM + tm::tm_sec
|
||||
|
||||
lda #<TM
|
||||
ldx #>TM
|
||||
jsr _mktime
|
||||
ldy #timespec::tv_sec
|
||||
jsr steaxspidx ; Pops address pushed by 2. pushax
|
||||
|
||||
jsr load_jiffy
|
||||
jsr pusheax
|
||||
lda gREG::r3L
|
||||
ldx #>$0000
|
||||
jsr tosmul0ax
|
||||
ldy #timespec::tv_nsec
|
||||
jsr steaxspidx ; Pops address pushed by 1. pushax
|
||||
|
||||
jsr incsp1
|
||||
jmp return0
|
||||
|
||||
.endproc
|
||||
55
libsrc/cx16/settime.s
Normal file
55
libsrc/cx16/settime.s
Normal file
@@ -0,0 +1,55 @@
|
||||
;
|
||||
; 2019-12-27, Greg King
|
||||
;
|
||||
; int __fastcall__ clock_settime (clockid_t clk_id, const struct timespec *tp);
|
||||
;
|
||||
|
||||
.include "time.inc"
|
||||
.include "cx16.inc"
|
||||
|
||||
.importzp ptr1
|
||||
.import pushax, pusheax, ldax0sp, ldeaxidx
|
||||
.import tosdiveax, incsp3, return0
|
||||
.import load_jiffy
|
||||
.import CLOCK_SET_DATE_TIME
|
||||
|
||||
|
||||
.macro COPY reg, offset
|
||||
ldy #offset
|
||||
lda (ptr1),y
|
||||
sta gREG::reg
|
||||
.endmac
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
|
||||
.proc _clock_settime
|
||||
|
||||
jsr pushax
|
||||
|
||||
.assert timespec::tv_sec = 0, error
|
||||
jsr _localtime
|
||||
sta ptr1
|
||||
stx ptr1+1
|
||||
|
||||
COPY r0L, tm::tm_year
|
||||
COPY r0H, tm::tm_mon
|
||||
inc gREG::r0H
|
||||
COPY r1L, tm::tm_mday
|
||||
COPY r1H, tm::tm_hour
|
||||
COPY r2L, tm::tm_min
|
||||
COPY r2H, tm::tm_sec
|
||||
|
||||
jsr ldax0sp ; Get tp
|
||||
ldy #timespec::tv_nsec+3
|
||||
jsr ldeaxidx ; Get nanoseconds
|
||||
jsr pusheax
|
||||
jsr load_jiffy
|
||||
jsr tosdiveax
|
||||
sta gREG::r3L ; Put number of jiffies
|
||||
|
||||
jsr CLOCK_SET_DATE_TIME
|
||||
|
||||
jsr incsp3
|
||||
jmp return0
|
||||
|
||||
.endproc
|
||||
@@ -1,16 +0,0 @@
|
||||
;
|
||||
; 2019-11-05, Greg King
|
||||
;
|
||||
|
||||
.export ST: zp
|
||||
|
||||
.segment "EXTZP": zp
|
||||
|
||||
; This is a temporary hack.
|
||||
|
||||
; A zero-page copy of the IEC status byte.
|
||||
; This is needed because the Commander X16's Kernal's status
|
||||
; variable was moved out of the zero page. But, the common
|
||||
; CBM file function modules import this as a zero-page variable.
|
||||
|
||||
ST: .res 1
|
||||
40
libsrc/cx16/tmcommon.s
Normal file
40
libsrc/cx16/tmcommon.s
Normal file
@@ -0,0 +1,40 @@
|
||||
;
|
||||
; 2019-12-27, Greg King
|
||||
;
|
||||
; Common stuff for the clock routines
|
||||
;
|
||||
|
||||
.export TM, load_jiffy
|
||||
|
||||
.importzp sreg
|
||||
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
; Load .EAX with the approximate number of nanoseconds
|
||||
; in one jiffy (1/60th of a second).
|
||||
|
||||
.proc load_jiffy
|
||||
|
||||
lda #<(17 * 1000 * 1000 / $10000)
|
||||
ldx #>(17 * 1000 * 1000 / $10000)
|
||||
sta sreg
|
||||
stx sreg+1
|
||||
lda #<(17 * 1000 * 1000)
|
||||
ldx #>(17 * 1000 * 1000)
|
||||
rts
|
||||
|
||||
.endproc
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
; TM struct with "is daylight-saving time" set to "unknown"
|
||||
.data
|
||||
|
||||
TM: .word 0 ; tm_sec
|
||||
.word 0 ; tm_min
|
||||
.word 0 ; tm_hour
|
||||
.word 0 ; tm_mday
|
||||
.word 0 ; tm_mon
|
||||
.word 0 ; tm_year
|
||||
.word 0 ; tm_wday
|
||||
.word 0 ; tm_yday
|
||||
.word .loword(-1) ; tm_isdst
|
||||
Reference in New Issue
Block a user