2002-11-16 23:45:15 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 16.11.2002
|
|
|
|
;
|
|
|
|
; int __fastcall__ close (int fd);
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _close
|
|
|
|
|
2002-11-19 23:02:47 +00:00
|
|
|
.import CLOSE
|
2002-11-17 22:45:55 +00:00
|
|
|
.import readdiskerror, closecmdchannel
|
2002-11-20 18:14:35 +00:00
|
|
|
.import __oserror
|
2002-11-17 22:45:55 +00:00
|
|
|
.importzp tmp2
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
.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
|
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
|
2002-11-16 23:45:15 +00:00
|
|
|
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
|
2002-11-17 22:45:55 +00:00
|
|
|
sta fdtab,x
|
|
|
|
lda tmp2 ; Get the handle
|
|
|
|
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
|
|
|
|
ldx unittab,y ; Get teh disk for this handle
|
|
|
|
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
|
|
|
|
bne error ; Jump if error
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
; Successful
|
|
|
|
|
2002-11-17 22:45:55 +00:00
|
|
|
tax ; Return zero in a/x
|
2002-11-16 23:45:15 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|