;
-; Stefan Haubenthal, 2009-07-27
-; Ullrich von Bassewitz, 2009-09-24
-; Oliver Schmidt, 2018-08-14
+; 2009-07-27, Stefan Haubenthal
+; 2009-09-24, Ullrich von Bassewitz
+; 2018-08-18, Oliver Schmidt
+; 2018-08-19, Greg King
;
-; int clock_gettime (clockid_t clk_id, struct timespec *tp);
+; int __fastcall__ clock_gettime (clockid_t clk_id, struct timespec *tp);
;
.include "time.inc"
.import pushax, pusheax, tosmul0ax, steaxspidx, incsp1
.import sys_bank, restore_bank
+ .import TM, load_tenth
.importzp sreg, tmp1, tmp2
.proc _clock_gettime
- jsr sys_bank
jsr pushax
jsr pushax
+ jsr sys_bank
ldy #CIA::TODHR
lda (cia),y
sed
lda (cia),y
jsr BCD2dec
sta TM + tm::tm_sec
+ ldy #CIA::TOD10
+ lda (cia),y
+ jsr restore_bank
+ pha
lda #<TM
ldx #>TM
jsr _mktime
ldy #timespec::tv_sec
jsr steaxspidx ; Pops address pushed by 2. pushax
- lda #<(100 * 1000 * 1000 / $10000)
- ldx #>(100 * 1000 * 1000 / $10000)
- sta sreg
- stx sreg+1
- lda #<(100 * 1000 * 1000)
- ldx #>(100 * 1000 * 1000)
+ jsr load_tenth
jsr pusheax
- ldy #CIA::TOD10
- lda (cia),y
+ pla
ldx #>$0000
jsr tosmul0ax
ldy #timespec::tv_nsec
jsr steaxspidx ; Pops address pushed by 1. pushax
- jsr incsp1
-
- lda #0
+ lda #$00
tax
- jmp restore_bank
+ jmp incsp1
.endproc
rts
.endproc
-
-;----------------------------------------------------------------------------
-; TM struct with date set to 1970-01-01
-.data
-
-TM: .word 0 ; tm_sec
- .word 0 ; tm_min
- .word 0 ; tm_hour
- .word 1 ; tm_mday
- .word 0 ; tm_mon
- .word 70 ; tm_year
- .word 0 ; tm_wday
- .word 0 ; tm_yday
- .word 0 ; tm_isdst
-