2 ; Christian Groessler, Jan-2003
4 ; int open(const char *name,int flags,...);
13 .destructor closeallfiles, 5
17 .import fddecusage,newfd
20 .import ldaxysp,addysp
30 dey ; parm count < 4 shouldn't be needed to be checked
31 dey ; (it generates a c compiler warning)
34 beq parmok ; parameter count ok
35 jsr addysp ; fix stack, throw away unused parameters
37 parmok: jsr findfreeiocb
38 beq iocbok ; we found one
40 lda #<EMFILE ; "too many open files"
41 seterr: jsr __directerrno
42 jsr incsp4 ; clean up stack
47 ; process the mode argument
50 jsr clriocb ; init with zero
52 jsr ldaxysp ; get mode
59 cmp #O_RDONLY ; DOS supports append with write-only only
66 .ifndef UCASE_FILENAME
67 invret: lda #<EINVAL ; file name is too long
88 ; process the filename argument
99 sty tmp2 ; set flag for ucase_fn
102 invret: lda #<EINVAL ; file name is too long
106 .endif ; defined UCASE_FILENAME
110 ;AX - points to filename
111 ;Y - iocb to use, if open needed
112 jsr newfd ; maybe we don't need to open and can reuse an iocb
113 ; returns fd num to use in tmp2, all regs unchanged
114 bcs doopen ; C set: open needed
115 lda #0 ; clears N flag
134 .ifdef UCASE_FILENAME
136 jsr addysp ; free used space on the stack
137 .endif ; defined UCASE_FILENAME
139 jsr incsp4 ; clean up stack
148 sty tmp3 ; remember error code
151 jsr CIOV ; close IOCB again since open failed
152 jsr fddecusage ; and decrement usage counter of fd
153 lda tmp3 ; put error code into A
156 ok: lda tmp2 ; get fd
164 ; closeallfiles: Close all files opened by the program.