]> git.sur5r.net Git - cc65/blob - libsrc/apple2/settime.s
Adjusted comments to match actual prototypes.
[cc65] / libsrc / apple2 / settime.s
1 ;
2 ; Oliver Schmidt, 15.08.2018
3 ;
4 ; int __fastcall__ clock_settime (clockid_t clk_id, const struct timespec *tp);
5 ;
6
7         .import         __dos_type
8         .import         incsp1, return0
9
10         .include        "time.inc"
11         .include        "zeropage.inc"
12         .include        "errno.inc"
13         .include        "mli.inc"
14
15 _clock_settime:
16
17         ; Cleanup stack
18         jsr     incsp1          ; Preserves A
19
20         ; Check for ProDOS 8
21         ldy     __dos_type
22         beq     enosys
23
24         ; Check for existing minutes or hours
25         tay                     ; Save A
26         lda     TIMELO
27         ora     TIMELO+1
28         bne     erange
29         tya                     ; Restore A
30
31         ; Get tm
32         .assert timespec::tv_sec = 0, error
33         jsr     _localtime
34         sta     ptr1
35         stx     ptr1+1
36
37         ; Set date
38         ldy     #tm::tm_mon
39         lda     (ptr1),y
40         clc
41         adc     #$01            ; Move [0..11] to [1..12]
42         asl
43         asl
44         asl
45         asl
46         asl
47         php                     ; Save month msb
48         ldy     #tm::tm_mday
49         ora     (ptr1),y
50         sta     DATELO
51         ldy     #tm::tm_year
52         lda     (ptr1),y
53         cmp     #100            ; Year since 1900 < 100?
54         bcc     :+              ; Yes, leave alone
55         sbc     #100            ; Move 20xx to 19xx
56 :       plp                     ; Restore month msb
57         rol
58         sta     DATELO+1
59
60         ; Return success
61         jmp     return0
62
63         ; Load errno code
64 enosys: lda     #ENOSYS
65         bne     errno           ; Always
66
67         ; Load errno code
68 erange: lda     #ERANGE
69
70         ; Set __errno
71 errno:  jmp     __directerrno