2 ; Ullrich von Bassewitz, 16.11.2002
4 ; int __fastcall__ close (int fd);
10 .import readdiskerror, closecmdchannel
16 .include "filedes.inc"
19 ;--------------------------------------------------------------------------
24 ; Check if we have a valid handle
28 cmp #MAX_FDS ; Is it valid?
29 bcs invalidfd ; Jump if no
30 sta tmp2 ; Save the handle
32 ; Check if the file is actually open
35 lda fdtab,x ; Get flags for this handle
39 ; Valid lfn, close it. The close call is always error free, at least as far
40 ; as the kernal is involved
44 lda tmp2 ; Get the handle
46 adc #LFN_OFFS ; Make LFN from handle
49 ; Read the drive error channel, then close it
51 ldy tmp2 ; Get the handle
52 ldx unittab,y ; Get teh disk for this handle
53 jsr readdiskerror ; Read the disk error code
54 pha ; Save it on stack
57 jsr closecmdchannel ; Close the disk command channel
58 pla ; Get the error code from the disk
59 bne error ; Jump if error
63 tax ; Return zero in a/x
66 ; Error entry, file descriptor is invalid
75 ; Error entry, file is not open
78 lda #3 ; File not open
81 ; Error entry, status not ok