]> git.sur5r.net Git - cc65/blob - libsrc/apple2/settime.s
Don't pass mode argument to open() from _fopen().
[cc65] / libsrc / apple2 / settime.s
1 ;
2 ; Oliver Schmidt, 15.08.2018
3 ;
4 ; int 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         jsr     _localtime
33         sta     ptr1
34         stx     ptr1+1
35
36         ; Set date
37         ldy     #tm::tm_mon
38         lda     (ptr1),y
39         clc
40         adc     #$01            ; Move [0..11] to [1..12]
41         asl
42         asl
43         asl
44         asl
45         asl
46         php                     ; Save month msb
47         ldy     #tm::tm_mday
48         ora     (ptr1),y
49         sta     DATELO
50         ldy     #tm::tm_year
51         lda     (ptr1),y
52         cmp     #100            ; Year since 1900 < 100?
53         bcc     :+              ; Yes, leave alone
54         sbc     #100            ; Move 20xx to 19xx
55 :       plp                     ; Restore month msb
56         rol
57         sta     DATELO+1
58
59         ; Return success
60         jmp     return0
61
62         ; Load errno code
63 enosys: lda     #ENOSYS
64         bne     errno           ; Always
65
66         ; Load errno code
67 erange: lda     #ERANGE
68
69         ; Set __errno
70 errno:  jmp     __directerrno