]> git.sur5r.net Git - cc65/blobdiff - libsrc/common/time.s
The spans do now contain the size of a span, no longer the end offset.
[cc65] / libsrc / common / time.s
index 2ee3c04d281fc690d07dc4258799445aed411810..00171a82a2e624915046b6add0cf2db79736fa37 100644 (file)
@@ -1,13 +1,13 @@
 ;
 ; Ullrich von Bassewitz, 12.11.2002
 ;
-; time_t __fastcall__ time (time_t* t);
+; time_t __fastcall__ time (time_t* timep);
 ;
 
        .export         _time
 
-        .import         __errno
-        .importzp       ptr1, sreg
+        .import         __systime
+        .importzp       ptr1, sreg, tmp1
 
         .include        "errno.inc"
 
 
 .proc   _time
 
-        sta     ptr1
-        stx     ptr1+1          ; t
+        pha
+        txa
+        pha                     ; Save timep
+
+        jsr     __systime       ; Get the time (machine dependent)
 
-        ldx     #$FF
-        stx     sreg
-        stx     sreg+1
+        sta     tmp1            ; Save low byte of result
 
-        ora     ptr1+1          ; t == 0?
+; Restore timep and check if it is NULL
+
+        pla
+        sta     ptr1
+        pla
+        sta     ptr1+1          ; Restore timep
+        ora     ptr1            ; timep == 0?
         beq     @L1
 
-        ldy     #$03
+; timep is not NULL, store the result there
+
+        ldy     #3
+        lda     sreg+1
+        sta     (ptr1),y
+        dey
+        lda     sreg
+        sta     (ptr1),y
+        dey
         txa
-@L0:    sta     (ptr1),y        ; *t = -1
+        sta     (ptr1),y
         dey
-        bpl     @L0
-        lda     #$00
+        lda     tmp1
+        sta     (ptr1),y
 
-@L1:    sta     __errno+1
+; If the result is less than zero, set ERRNO
+
+@L1:    ldy     sreg+1
+        bpl     @L2
+                  
         lda     #ENOSYS         ; Function not implemented
-        sta     __errno
+        jsr     __seterrno      ; Set __errno
+
+; Reload the low byte of the result and return
 
-        txa                     ; A = $FF
+@L2:    lda     tmp1
         rts
 
 .endproc