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:
parent
7a9cabe279
commit
8f7b91eea6
9 changed files with 36 additions and 27 deletions
|
@ -67,6 +67,7 @@ S_OBJS = _cwd.o \
|
||||||
_heapmemavail.o \
|
_heapmemavail.o \
|
||||||
_oserror.o \
|
_oserror.o \
|
||||||
_printf.o \
|
_printf.o \
|
||||||
|
_seterrno.o \
|
||||||
_swap.o \
|
_swap.o \
|
||||||
_sys.o \
|
_sys.o \
|
||||||
abs.o \
|
abs.o \
|
||||||
|
|
|
@ -69,10 +69,8 @@
|
||||||
|
|
||||||
invmode:
|
invmode:
|
||||||
lda #EINVAL
|
lda #EINVAL
|
||||||
sta __errno
|
jsr __seterrno ; Set __errno, returns zero in A
|
||||||
lda #0
|
tax ; a/x = 0
|
||||||
sta __errno+1
|
|
||||||
tax
|
|
||||||
jmp incsp4
|
jmp incsp4
|
||||||
|
|
||||||
; Mode string successfully parsed. Store the binary mode onto the stack in
|
; Mode string successfully parsed. Store the binary mode onto the stack in
|
||||||
|
|
22
libsrc/common/_seterrno.s
Normal file
22
libsrc/common/_seterrno.s
Normal 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
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,8 @@
|
||||||
; Error, no space left
|
; Error, no space left
|
||||||
|
|
||||||
@Error: lda #ENOSPC ; No space left
|
@Error: lda #ENOSPC ; No space left
|
||||||
sta __errno
|
jsr __seterrno
|
||||||
ldx #$00
|
ldx #$FF ; Return -1
|
||||||
stx __errno+1
|
|
||||||
dex ; Make return value -1
|
|
||||||
txa
|
txa
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,9 @@
|
||||||
; File is not open
|
; File is not open
|
||||||
|
|
||||||
lda #EINVAL
|
lda #EINVAL
|
||||||
sta __errno
|
jsr __seterrno
|
||||||
ldx #0
|
lda #$FF ; Return -1
|
||||||
stx __errno+1
|
tax
|
||||||
dex
|
|
||||||
txa
|
|
||||||
rts
|
rts
|
||||||
|
|
||||||
; File is open. Reset the flags and close the file.
|
; File is open. Reset the flags and close the file.
|
||||||
|
|
|
@ -36,9 +36,7 @@
|
||||||
; Failed to allocate a file stream
|
; Failed to allocate a file stream
|
||||||
|
|
||||||
lda #EMFILE
|
lda #EMFILE
|
||||||
sta __errno
|
jsr __seterrno ; Set __errno, will return 0 in A
|
||||||
lda #0
|
|
||||||
sta __errno+1
|
|
||||||
tax
|
tax
|
||||||
rts ; Return zero
|
rts ; Return zero
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,7 @@
|
||||||
; File not open
|
; File not open
|
||||||
|
|
||||||
lda #EINVAL
|
lda #EINVAL
|
||||||
sta __errno
|
jsr __seterrno
|
||||||
lda #0
|
|
||||||
sta __errno+1
|
|
||||||
@L1: jsr incsp6
|
@L1: jsr incsp6
|
||||||
jmp return0
|
jmp return0
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,7 @@
|
||||||
; File not open
|
; File not open
|
||||||
|
|
||||||
lda #EINVAL
|
lda #EINVAL
|
||||||
sta __errno
|
jsr __seterrno
|
||||||
lda #0
|
|
||||||
sta __errno+1
|
|
||||||
@L1: jsr incsp6
|
@L1: jsr incsp6
|
||||||
jmp return0
|
jmp return0
|
||||||
|
|
||||||
|
|
|
@ -53,10 +53,8 @@
|
||||||
@L1: ldy sreg+1
|
@L1: ldy sreg+1
|
||||||
bpl @L2
|
bpl @L2
|
||||||
|
|
||||||
lda #$00
|
|
||||||
sta __errno+1
|
|
||||||
lda #ENOSYS ; Function not implemented
|
lda #ENOSYS ; Function not implemented
|
||||||
sta __errno
|
jsr __seterrno ; Set __errno
|
||||||
|
|
||||||
; Reload the low byte of the result and return
|
; Reload the low byte of the result and return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue