mirror of
https://github.com/cc65/cc65.git
synced 2024-07-05 21:29:03 +00:00
87 lines
1.7 KiB
ArmAsm
87 lines
1.7 KiB
ArmAsm
|
;
|
||
|
; Ullrich von Bassewitz, 16.11.2002
|
||
|
;
|
||
|
; int __fastcall__ close (int fd);
|
||
|
;
|
||
|
|
||
|
.export _close
|
||
|
|
||
|
.import getdiskerror
|
||
|
.import __errno, __oserror
|
||
|
|
||
|
.include "errno.inc"
|
||
|
.include "cbm.inc"
|
||
|
.include "filedes.inc"
|
||
|
|
||
|
|
||
|
;--------------------------------------------------------------------------
|
||
|
; _close
|
||
|
|
||
|
.proc _close
|
||
|
|
||
|
; Check if we have a valid handle
|
||
|
|
||
|
cpx #$00
|
||
|
bne invalidfd
|
||
|
cmp #MAX_FDS ; Is it valid?
|
||
|
bcs invalidfd ; Jump if no
|
||
|
|
||
|
; Check if the LFN is valid and the file is open for writing
|
||
|
|
||
|
adc #LFN_OFFS ; Carry is already clear
|
||
|
tax
|
||
|
lda fdtab-LFN_OFFS,x; Get flags for this handle
|
||
|
beq notopen
|
||
|
|
||
|
; Valid lfn, close it. The close call is always error free, at least as far
|
||
|
; as the kernal is involved
|
||
|
|
||
|
lda #LFN_CLOSED
|
||
|
sta fdtab-LFN_OFFS,x
|
||
|
lda unittab,x
|
||
|
pha ; Push unit for this file
|
||
|
txa
|
||
|
jsr CLOSE
|
||
|
pla
|
||
|
|
||
|
; Read the drive error channel
|
||
|
|
||
|
lda unittab,x
|
||
|
tax
|
||
|
jsr getdiskerror
|
||
|
cmp #$00
|
||
|
bne error
|
||
|
|
||
|
; Successful
|
||
|
|
||
|
tax
|
||
|
rts
|
||
|
|
||
|
; Error entry, file descriptor is invalid
|
||
|
|
||
|
invalidfd:
|
||
|
lda #EINVAL
|
||
|
sta __errno
|
||
|
lda #0
|
||
|
sta __errno+1
|
||
|
beq errout
|
||
|
|
||
|
; Error entry, file is not open
|
||
|
|
||
|
notopen:
|
||
|
lda #3 ; File not open
|
||
|
bne error
|
||
|
|
||
|
; Error entry, status not ok
|
||
|
|
||
|
error: sta __oserror
|
||
|
errout: lda #$FF
|
||
|
tax ; Return -1
|
||
|
rts
|
||
|
|
||
|
.endproc
|
||
|
|
||
|
|
||
|
|
||
|
|