]> git.sur5r.net Git - cc65/commitdiff
Use a subroutine to set errno to save some space.
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 13 May 2004 21:09:08 +0000 (21:09 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 13 May 2004 21:09:08 +0000 (21:09 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3032 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/common/Makefile
libsrc/common/_fopen.s
libsrc/common/_seterrno.s [new file with mode: 0644]
libsrc/common/atexit.s
libsrc/common/fclose.s
libsrc/common/fopen.s
libsrc/common/fread.s
libsrc/common/fwrite.s
libsrc/common/time.s

index 21ed8aa29b0ef69b10a7315f81a135ac37dc8d38..6d4b5a06d8000c801405842864c7eccbc960a734 100644 (file)
@@ -67,6 +67,7 @@ S_OBJS =      _cwd.o          \
                 _heapmemavail.o \
                _oserror.o      \
                _printf.o       \
+                _seterrno.o     \
                _swap.o         \
                _sys.o          \
                abs.o           \
index a7a9eb4b5e1fc5a6df5f89f438fd6322106e0909..29f1c4cd92165ff1de2d1d4f03a522793a3c514c 100644 (file)
 
 invmode:
         lda     #EINVAL
-        sta     __errno
-        lda     #0
-        sta     __errno+1
-        tax
+        jsr     __seterrno      ; Set __errno, returns zero in A
+        tax                     ; a/x = 0
         jmp     incsp4
 
 ; Mode string successfully parsed. Store the binary mode onto the stack in
diff --git a/libsrc/common/_seterrno.s b/libsrc/common/_seterrno.s
new file mode 100644 (file)
index 0000000..4321252
--- /dev/null
@@ -0,0 +1,22 @@
+;
+; Ullrich von Bassewitz, 2004-05-13
+;
+; __seterrno: Will set __errno to the value in A and return zero in A. Other
+;             registers aren't changed. The function is C callable, but 
+;             currently only called from asm code.
+;
+
+       .include        "errno.inc"
+
+.code
+
+.proc   __seterrno
+
+        sta     __errno
+        lda     #0
+        sta     __errno+1
+        rts
+
+.endproc
+
+
index 9827f7123848aa7910a745872bf7f928620505b3..b66cce8e8d312d262d88886021b9bbb621ba96c8 100644 (file)
 ; Error, no space left
 
 @Error:        lda     #ENOSPC         ; No space left
-       sta     __errno
-       ldx     #$00
-       stx     __errno+1
-       dex                     ; Make return value -1
+        jsr     __seterrno
+               ldx     #$FF            ; Return -1
        txa
        rts
 
index 0d43aa47e9ffae97c18f17471b72718b49cb3e35..5365d70daf2e07db0d23d670416d95bf3271c79e 100644 (file)
 ; File is not open
 
         lda     #EINVAL
-        sta     __errno
-        ldx     #0
-        stx     __errno+1
-        dex
-        txa
+        jsr     __seterrno
+        lda     #$FF            ; Return -1
+        tax
         rts
 
 ; File is open. Reset the flags and close the file.
index 791dfcff59b58bbfaad1a4f399295689aa023389..d4d94acee18d96780a08649e3bdf5bfec91b76ea 100644 (file)
@@ -36,9 +36,7 @@
 ; Failed to allocate a file stream
 
         lda     #EMFILE
-        sta     __errno
-        lda     #0
-        sta     __errno+1
+        jsr     __seterrno      ; Set __errno, will return 0 in A
         tax
         rts                     ; Return zero
 
index c4941513d5e12558f604d34badc410abd4cefc3e..e65f33bea14053d507701d3be63a7b7daa4795e3 100644 (file)
 
 ; File not open
 
-       lda     #EINVAL
-       sta     __errno
-       lda     #0
-       sta     __errno+1
+       lda     #EINVAL
+        jsr     __seterrno
 @L1:    jsr     incsp6
         jmp     return0
 
index ef9c08d9e419daa05d387d0314aa5c09a5ae7440..586960d507ac33ecabd7205798738b34c0de0471 100644 (file)
@@ -39,9 +39,7 @@
 ; File not open
 
        lda     #EINVAL
-       sta     __errno
-       lda     #0
-       sta     __errno+1
+        jsr     __seterrno
 @L1:    jsr     incsp6
         jmp     return0
 
index 9220b7f19edca000cf50112fed888f41c9e26c12..00171a82a2e624915046b6add0cf2db79736fa37 100644 (file)
 
 @L1:    ldy     sreg+1
         bpl     @L2
-
-        lda     #$00
-        sta     __errno+1
+                  
         lda     #ENOSYS         ; Function not implemented
-        sta     __errno
+        jsr     __seterrno      ; Set __errno
 
 ; Reload the low byte of the result and return