1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 04:30:10 +00:00

Fixed sources to use the new __mappederrno and __directerrno functions, and

made handling of _oserror and errno consistent.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4731 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2010-06-26 11:28:44 +00:00
parent 672cffa1d2
commit ae98a6db40
4 changed files with 44 additions and 55 deletions

View File

@ -17,7 +17,7 @@
;--------------------------------------------------------------------------
; _close
.proc _close
; Check if we have a valid handle
@ -55,13 +55,13 @@
ldx unittab,y
jsr closecmdchannel ; Close the disk command channel
pla ; Get the error code from the disk
jmp __mappederrno ; Set _oserror and _errno, returns 0/-1
jmp __mappederrno ; Set _oserror and _errno, return 0/-1
; Error entry: The given file descriptor is not valid or not open
invalidfd:
lda #EBADF
jmp __directerrno ; Sets _errno, clears _oserror, returns -1
jmp __directerrno ; Set _errno, clear _oserror, return -1
.endproc

View File

@ -10,17 +10,17 @@
.import SETLFS, OPEN, CHKIN, BASIN, CLRCH, READST
.import rwcommon
.import popax
.import __oserror
.importzp ptr1, ptr2, ptr3, tmp1, tmp2, tmp3
.include "fcntl.inc"
.include "cbm.inc"
.include "errno.inc"
.include "fcntl.inc"
.include "filedes.inc"
;--------------------------------------------------------------------------
; initstdin: Open the stdin file descriptors for the keyboard
.segment "INIT"
.proc initstdin
@ -44,7 +44,7 @@
.proc _read
jsr rwcommon ; Pop params, check handle
bcs errout ; Invalid handle, errno already set
bcs invalidfd ; Invalid handle
; Check if the LFN is valid and the file is open for writing
@ -52,7 +52,7 @@
tax
lda fdtab-LFN_OFFS,x; Get flags for this handle
and #LFN_READ ; File open for writing?
beq notopen
beq invalidfd
; Check the EOF flag. If it is set, don't read anything
@ -62,11 +62,8 @@
; Valid lfn. Make it the input file
jsr CHKIN
bcs error
; Go looping...
bcc @L3 ; Branch always
bcc @L3 ; Branch if ok
jmp __mappederrno ; Store into __oserror, map to errno, return -1
; Read the next byte
@ -76,7 +73,7 @@
jsr READST ; Read the IEEE status
sta tmp3 ; Save it
and #%10111111 ; Check anything but the EOI bit
bne error5 ; Assume device not present
bne devnotpresent ; Assume device not present
; Store the byte just read
@ -118,25 +115,25 @@
done: jsr CLRCH
; Return the number of chars read
; Clear _oserror and return the number of chars read
eof: lda ptr3
eof: lda #0
sta __oserror
lda ptr3
ldx ptr3+1
rts
; Error entry, file is not open
; Error entry: Device not present
notopen:
lda #3 ; File not open
bne error
devnotpresent:
lda #ENODEV
jmp __directerrno ; Sets _errno, clears _oserror, returns -1
; Error entry, status not ok
; Error entry: The given file descriptor is not valid or not open
error5: lda #5 ; Device not present
error: sta __oserror
errout: lda #$FF
tax ; Return -1
rts
invalidfd:
lda #EBADF
jmp __directerrno ; Sets _errno, clears _oserror, returns -1
.endproc

View File

@ -37,18 +37,10 @@
jsr popax ; Get the handle
cpx #$01
bcs invhandle
cmp #MAX_FDS
bcs invhandle
bcs @L9
cmp #MAX_FDS ; Set carry if fd too large
sta tmp2
rts ; Return with carry clear
invhandle:
lda #EINVAL
sta __errno
lda #0
sta __errno+1
rts ; Return with carry set
@L9: rts ; Return with result in carry
.endproc

View File

@ -9,11 +9,11 @@
.import SETLFS, OPEN, CKOUT, BSOUT, CLRCH
.import rwcommon
.import __oserror
.importzp sp, ptr1, ptr2, ptr3
.include "fcntl.inc"
.include "cbm.inc"
.include "errno.inc"
.include "fcntl.inc"
.include "filedes.inc"
@ -42,13 +42,13 @@
;--------------------------------------------------------------------------
; _write
.code
.proc _write
jsr rwcommon ; Pop params, check handle
bcs errout ; Invalid handle, errno already set
bcs invalidfd ; Invalid handle
; Check if the LFN is valid and the file is open for writing
@ -56,13 +56,13 @@
tax
lda fdtab-LFN_OFFS,x; Get flags for this handle
and #LFN_WRITE ; File open for writing?
beq notopen
beq invalidfd
; Valid lfn. Make it the output file
jsr CKOUT
bcs error
bcc @L2
@error: jmp __mappederrno ; Store into __oserror, map to errno, return -1
; Output the next character from the buffer
@ -72,7 +72,7 @@
bne @L1
inc ptr2+1 ; A = *buf++;
@L1: jsr BSOUT
bcs error ; Bail out on errors
bcs @error ; Bail out on errors
; Count characters written
@ -91,25 +91,25 @@
jsr CLRCH
; Return the number of chars written
; Clear _oserror and return the number of chars written
lda #0
sta __oserror
lda ptr3
ldx ptr3+1
rts
; Error entry, file is not open
; Error entry: Device not present
notopen:
lda #3 ; File not open
bne error
devnotpresent:
lda #ENODEV
jmp __directerrno ; Sets _errno, clears _oserror, returns -1
; Error entry, status not ok
; Error entry: The given file descriptor is not valid or not open
error5: lda #5 ; Device not present
error: sta __oserror
errout: lda #$FF
tax ; Return -1
rts
invalidfd:
lda #EBADF
jmp __directerrno ; Sets _errno, clears _oserror, returns -1
.endproc