File: settime.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 (99 lines) | stat: -rw-r--r-- 2,518 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
;
; Oliver Schmidt, 15.08.2018
; Christian Groessler, 25.09.2018
;
; int __fastcall__ clock_settime (clockid_t clk_id, const struct timespec *tp);
;

        .import         __dos_type
        .import         incsp1, return0
        .import         sdxtry

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

_clock_settime:

; cleanup stack

        jsr     incsp1          ; preserves AX

; only supported on SpartaDOS-X >= 4.40

        ldy     #SPARTADOS
        cpy     __dos_type
        bne     enosys
        ldy     SDX_VERSION
        cpy     #$44
        bcc     enosys

; create tm from tp (tv_sec) input parameter

        .assert timespec::tv_sec = 0, error
        jsr     _localtime
        sta     ptr1
        stx     ptr1+1

; set date

        ldy     #tm::tm_mday
        lda     (ptr1),y        ; get day of month
        sta     SDX_DATE        ; set day of month

        ldy     #tm::tm_mon
        lda     (ptr1),y        ; get month (0-based)
        tax
        inx                     ; move [0..11] to [1..12]
        stx     SDX_DATE+1

        ldy     #tm::tm_year
        lda     (ptr1),y        ; get year (0 = year 1900)
        cmp     #100
        bcc     :+
        sbc     #100
:       sta     SDX_DATE+2

        ldy     #tm::tm_hour
        lda     (ptr1),y        ; get hour
        sta     SDX_TIME

        ldy     #tm::tm_min
        lda     (ptr1),y        ; get minutes
        sta     SDX_TIME+1

        ldy     #tm::tm_sec
        lda     (ptr1),y        ; get seconds
        sta     SDX_TIME+2

; set new time/date (SD-X call)
; SpartaDOS-X User's Guide (4.48) states at page 145:
; "In the I_GETTD and I_SETTD procedures a set Carry-Flag means that the clock driver is
; busy at the moment. You should call the routine again."
; It goes on to mention that one should provide an upper limit on the number of calls,
; in order not to "hang". We are doing this here...

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

try_set:lda     #SDX_CLK_DEV    ; CLK device
        sta     SDX_DEVICE
        ldy     #SDX_KD_SETTD   ; SETTD function
        jsr     SDX_KERNEL      ; do the call
        bcc     done

        dec     sdxtry
        bne     try_set

        lda     #EBUSY
        bne     drcter          ; jump always

; return success

done:   jmp     return0

; load errno code

enosys: lda     #ENOSYS
drcter: jmp     __directerrno