File: gettime.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (114 lines) | stat: -rw-r--r-- 2,312 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
;
; Oliver Schmidt, 14.08.2018
; Christian Groessler, 25.09.2018
;
; int __fastcall__ clock_gettime (clockid_t clk_id, struct timespec *tp);
;

        .import         pushax, steaxspidx, incsp1, incsp3, return0
        .import         __dos_type
        .import         sdxtry

        .include        "time.inc"
        .include        "zeropage.inc"
        .include        "errno.inc"
        .include        "atari.inc"

_clock_gettime:
        jsr     pushax

; clear tp

        sta     ptr1
        stx     ptr1+1
        lda     #$00
        ldy     #.sizeof(timespec)-1
:       sta     (ptr1),y
        dey
        bpl     :-

; only supported on SpartaDOS-X >= 4.40

        lda     #SPARTADOS
        cmp     __dos_type
        bne     notsupp
        lda     SDX_VERSION
        cmp     #$44
        bcc     notsupp

; get date/time from system (SD-X call)
; see settime.s for reasons of using sdxtry

        lda     #0              ; init loop count (256)
        sta     sdxtry

try_get:lda     #SDX_CLK_DEV    ; CLK device
        sta     SDX_DEVICE
        ldy     #SDX_KD_GETTD   ; GETTD function
        jsr     SDX_KERNEL      ; do the call
        bcc     done

        dec     sdxtry
        bne     try_get

        lda     #EBUSY
        bne     errexit

; fill timespec

; date
done:   lda     SDX_DATE        ; mday
        sta     TM + tm::tm_mday
        ldx     SDX_DATE+1      ; month
        dex
        stx     TM + tm::tm_mon
        lda     SDX_DATE+2      ; year
        cmp     #79             ; 1979: the Atari 800 came out
        bcs     :+
        adc     #100            ; adjust century
:       sta     TM + tm::tm_year

; time
        lda     SDX_TIME
        sta     TM + tm::tm_hour
        lda     SDX_TIME+1
        sta     TM + tm::tm_min
        lda     SDX_TIME+2
        sta     TM + tm::tm_sec

; make time_t

        lda     #<TM
        ldx     #>TM
        jsr     _mktime

; store tv_sec into output tp struct

        ldy     #timespec::tv_sec
        jsr     steaxspidx

; cleanup stack

        jsr     incsp1

; return success

        jmp     return0

; load errno code

notsupp:lda     #ENOSYS

; cleanup stack

errexit:jsr     incsp3          ; Preserves A

; set __errno

        jmp     __directerrno

; -------

        .bss

TM:     .tag    tm