2 ; Christian Groessler, Jan-2003
4 ; int open(const char *name,int flags,...);
11 .include "zeropage.inc"
14 .destructor closeallfiles, 5
18 .import fddecusage,newfd
21 .import ldaxysp,addysp
29 dey ; parm count < 4 shouldn't be needed to be checked
30 dey ; (it generates a c compiler warning)
33 beq parmok ; parameter count ok
34 jsr addysp ; fix stack, throw away unused parameters
36 parmok: jsr findfreeiocb
37 beq iocbok ; we found one
39 lda #<EMFILE ; "too many open files"
40 seterr: jsr __directerrno
41 jsr incsp4 ; clean up stack
46 ; process the mode argument
49 jsr clriocb ; init with zero
51 jsr ldaxysp ; get mode
58 cmp #O_RDONLY ; DOS supports append with write-only only
65 .ifndef UCASE_FILENAME
66 invret: lda #<EINVAL ; file name is too long
87 ; process the filename argument
98 sty tmp2 ; set flag for ucase_fn
101 invret: lda #<EINVAL ; file name is too long
105 .endif ; defined UCASE_FILENAME
109 ;AX - points to filename
110 ;Y - iocb to use, if open needed
111 jsr newfd ; maybe we don't need to open and can reuse an iocb
112 ; returns fd num to use in tmp2, all regs unchanged
113 bcs doopen ; C set: open needed
114 lda #0 ; clears N flag
133 .ifdef UCASE_FILENAME
135 jsr addysp ; free used space on the stack
136 .endif ; defined UCASE_FILENAME
138 jsr incsp4 ; clean up stack
147 sty tmp3 ; remember error code
150 jsr CIOV ; close IOCB again since open failed
151 jsr fddecusage ; and decrement usage counter of fd
152 lda tmp3 ; put error code into A
155 ok: lda tmp2 ; get fd
163 ; closeallfiles: Close all files opened by the program.