]> git.sur5r.net Git - cc65/blob - libsrc/common/time.s
Merge pull request #389 from IrgendwerA8/stringimprovements
[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         __systime
10         .importzp       ptr1, sreg, tmp1
11
12         .include        "errno.inc"
13
14
15 .code
16
17 .proc   _time
18
19         pha
20         txa
21         pha                     ; Save timep
22
23         jsr     __systime       ; Get the time (machine dependent)
24
25         sta     tmp1            ; Save low byte of result
26
27 ; Restore timep and check if it is NULL
28
29         pla
30         sta     ptr1+1
31         pla
32         sta     ptr1            ; Restore timep
33         ora     ptr1+1          ; timep == 0?
34         beq     @L1
35
36 ; timep is not NULL, store the result there
37
38         ldy     #3
39         lda     sreg+1
40         sta     (ptr1),y
41         dey
42         lda     sreg
43         sta     (ptr1),y
44         dey
45         txa
46         sta     (ptr1),y
47         dey
48         lda     tmp1
49         sta     (ptr1),y
50
51 ; If the result is less than zero, set ERRNO
52
53 @L1:    ldy     sreg+1
54         bpl     @L2
55                   
56         lda     #ENOSYS         ; Function not implemented
57         jsr     __seterrno      ; Set __errno
58
59 ; Reload the low byte of the result and return
60
61 @L2:    lda     tmp1
62         rts
63
64 .endproc
65
66