]> git.sur5r.net Git - cc65/blob - libsrc/common/time.s
Saved 2 bytes and fixed error in case of negative result.
[cc65] / libsrc / common / time.s
1 ;
2 ; Ullrich von Bassewitz, 12.11.2002
3 ;
4 ; time_t __fastcall__ time (time_t* timep);
5 ;
6
7         .export         _time
8
9         .import         decsp1, ldeaxi
10         .importzp       ptr1, sreg, tmp1, tmp2
11
12         .include        "time.inc"
13
14
15 .code
16
17 .proc   _time
18
19         pha
20         txa
21         pha                     ; Save timep
22
23 ; Get the time (machine dependent)
24
25         jsr     decsp1
26         lda     #<time
27         ldx     #>time
28         jsr     _clock_gettime
29         sta     tmp2
30         lda     #<time
31         ldx     #>time
32         .assert timespec::tv_sec = 0, error
33         jsr     ldeaxi
34         sta     tmp1            ; Save low byte of result
35
36 ; Restore timep and check if it is NULL
37
38         pla
39         sta     ptr1+1
40         pla
41         sta     ptr1            ; Restore timep
42         ora     ptr1+1          ; timep == 0?
43         beq     @L1
44
45 ; timep is not NULL, store the result there
46
47         ldy     #3
48         lda     sreg+1
49         sta     (ptr1),y
50         dey
51         lda     sreg
52         sta     (ptr1),y
53         dey
54         txa
55         sta     (ptr1),y
56         dey
57         lda     tmp1
58         sta     (ptr1),y
59
60 ; If the result is != 0, return -1
61
62 @L1:    lda     tmp2
63         beq     @L2
64
65         tax
66         sta     sreg
67         sta     sreg+1
68         rts
69
70 ; Reload the low byte of the result and return
71
72 @L2:    lda     tmp1
73         rts
74
75 .endproc
76
77 ; ------------------------------------------------------------------------
78 ; Data
79
80 .bss
81 time:   .tag    timespec