2002-11-16 23:45:15 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 16.11.2002
|
|
|
|
;
|
|
|
|
; int __fastcall__ close (int fd);
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _close
|
|
|
|
|
2002-11-17 22:45:55 +00:00
|
|
|
.import readdiskerror, closecmdchannel
|
|
|
|
.importzp tmp2
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
.include "errno.inc"
|
|
|
|
.include "cbm.inc"
|
|
|
|
.include "filedes.inc"
|
|
|
|
|
|
|
|
|
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
; _close
|
2018-07-03 19:47:42 +00:00
|
|
|
|
2002-11-16 23:45:15 +00:00
|
|
|
.proc _close
|
|
|
|
|
|
|
|
; Check if we have a valid handle
|
|
|
|
|
|
|
|
cpx #$00
|
|
|
|
bne invalidfd
|
|
|
|
cmp #MAX_FDS ; Is it valid?
|
|
|
|
bcs invalidfd ; Jump if no
|
2002-11-17 22:45:55 +00:00
|
|
|
sta tmp2 ; Save the handle
|
2002-11-16 23:45:15 +00:00
|
|
|
|
2002-11-17 22:45:55 +00:00
|
|
|
; Check if the file is actually open
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
tax
|
2002-11-17 22:45:55 +00:00
|
|
|
lda fdtab,x ; Get flags for this handle
|
|
|
|
and #LFN_OPEN
|
2010-06-04 10:50:58 +00:00
|
|
|
beq invalidfd
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
; Valid lfn, close it. The close call is always error free, at least as far
|
|
|
|
; as the kernal is involved
|
|
|
|
|
|
|
|
lda #LFN_CLOSED
|
2002-11-17 22:45:55 +00:00
|
|
|
sta fdtab,x
|
2018-02-26 20:07:13 +00:00
|
|
|
txa ; Get handle
|
2002-11-17 22:45:55 +00:00
|
|
|
clc
|
|
|
|
adc #LFN_OFFS ; Make LFN from handle
|
2002-11-16 23:45:15 +00:00
|
|
|
jsr CLOSE
|
|
|
|
|
2002-11-17 22:45:55 +00:00
|
|
|
; Read the drive error channel, then close it
|
2002-11-16 23:45:15 +00:00
|
|
|
|
2002-11-17 22:45:55 +00:00
|
|
|
ldy tmp2 ; Get the handle
|
2010-06-04 10:50:58 +00:00
|
|
|
ldx unittab,y ; Get the disk for this handle
|
2002-11-17 22:45:55 +00:00
|
|
|
jsr readdiskerror ; Read the disk error code
|
|
|
|
pha ; Save it on stack
|
|
|
|
ldy tmp2
|
|
|
|
ldx unittab,y
|
|
|
|
jsr closecmdchannel ; Close the disk command channel
|
|
|
|
pla ; Get the error code from the disk
|
2022-08-28 19:52:53 +00:00
|
|
|
jmp ___mappederrno ; Set __oserror and _errno, return 0/-1
|
2002-11-16 23:45:15 +00:00
|
|
|
|
2010-06-04 10:50:58 +00:00
|
|
|
; Error entry: The given file descriptor is not valid or not open
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
invalidfd:
|
2010-06-04 10:50:58 +00:00
|
|
|
lda #EBADF
|
2022-08-28 19:52:53 +00:00
|
|
|
jmp ___directerrno ; Set _errno, clear __oserror, return -1
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
.endproc
|