2 ; Christian Groessler, May-2000
4 ; int open(const char *name,int flags,...);
12 .import fddecusage,newfd
14 .import __do_oserror,__seterrno,incsp4
15 .import ldaxysp,addysp
25 cpy #4 ; correct # of arguments (bytes)?
26 beq parmok ; parameter count ok
27 tya ; parm count < 4 shouldn't be needed to be checked
28 sec ; (it generates a c compiler warning)
31 jsr addysp ; fix stack, throw away unused parameters
33 parmok: jsr findfreeiocb
34 beq iocbok ; we found one
36 lda #<EMFILE ; "too many open files"
38 seterr: jsr __seterrno
39 jsr incsp4 ; clean up stack
44 ; process the mode argument
45 ; @@@TODO: append not handled yet!
48 jsr clriocb ; init with zero
50 jsr ldaxysp ; get mode
67 ; process the filename argument
76 lda #<EINVAL ; file name is too long
81 .endif ; defined UCASE_FILENAME
85 ;AX - points to filename
86 ;Y - iocb to use, if open needed
87 jsr newfd ; maybe we don't need to open and can reuse an iocb
88 ; returns fd num to use in tmp2, all regs unchanged
89 bcs doopen ; C set: open needed
90 lda #0 ; clears N flag
109 .ifdef UCASE_FILENAME
111 jsr addysp ; free used space on the stack
112 .endif ; defined UCASE_FILENAME
114 jsr incsp4 ; clean up stack
123 jsr fddecusage ; decrement usage counter of fd as open failed
126 ok: lda tmp2 ; get fd