]> git.sur5r.net Git - cc65/blob - libsrc/apple2/getres.s
Atari: implement clock_getres()
[cc65] / libsrc / apple2 / getres.s
1 ;
2 ; Oliver Schmidt, 15.08.2018
3 ;
4 ; int __fastcall__ clock_getres (clockid_t clk_id, struct timespec *res);
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_getres:
16         sta     ptr1
17         stx     ptr1+1
18
19         ; Cleanup stack
20         jsr     incsp1
21
22         ; Check for ProDOS 8
23         lda     __dos_type
24         beq     enosys
25
26         ; Presume day resolution
27         ldx     #<day_res
28         ldy     #>day_res
29
30         ; Check for existing minutes or hours
31         lda     TIMELO
32         ora     TIMELO+1
33         beq     :+
34
35         ; Switch to minute resolution
36         ldx     #<min_res
37         ldy     #>min_res
38
39         ; Copy timespec
40 :       stx     ptr2
41         sty     ptr2+1
42         ldy     #.sizeof(timespec)-1
43 :       lda     (ptr2),y
44         sta     (ptr1),y
45         dey
46         bpl     :-
47
48         ; Return success
49         jmp     return0
50
51         ; Load errno code
52 enosys: lda     #ENOSYS
53
54         ; Set __errno
55         jmp     __directerrno
56
57         .rodata
58
59 min_res:.dword  60
60         .dword  0
61
62 day_res:.dword  60 * 60 * 24
63         .dword  0