Use a subroutine to set errno to save some space.

git-svn-id: svn://svn.cc65.org/cc65/trunk@3032 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2004-05-13 21:09:08 +00:00
parent 7a9cabe279
commit 8f7b91eea6
9 changed files with 36 additions and 27 deletions

View file

@ -67,6 +67,7 @@ S_OBJS = _cwd.o \
_heapmemavail.o \
_oserror.o \
_printf.o \
_seterrno.o \
_swap.o \
_sys.o \
abs.o \

View file

@ -69,10 +69,8 @@
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

22
libsrc/common/_seterrno.s Normal file
View file

@ -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

View file

@ -38,10 +38,8 @@
; 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

View file

@ -31,11 +31,9 @@
; 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.

View 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

View file

@ -38,10 +38,8 @@
; File not open
lda #EINVAL
sta __errno
lda #0
sta __errno+1
lda #EINVAL
jsr __seterrno
@L1: jsr incsp6
jmp return0

View file

@ -39,9 +39,7 @@
; File not open
lda #EINVAL
sta __errno
lda #0
sta __errno+1
jsr __seterrno
@L1: jsr incsp6
jmp return0

View file

@ -52,11 +52,9 @@
@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