2 ; Christian Groessler, May-2000
4 ; int open(const char *name,int flags,...);
7 UCASE_FILENAME = 1 ; comment it out if filename shouldn't be uppercased
10 .include "../common/fmode.inc"
11 .include "../common/errno.inc"
13 .import fddecusage,newfd
14 .import __do_oserror,__seterrno,incsp4
15 .import ldaxysp,addysp,subysp
16 .import _strupr,__oserror
17 .importzp tmp4,tmp2,sp
24 cpy #4 ; correct # of arguments (bytes)?
25 beq parmok ; parameter count ok
26 tya ; parm count < 4 shouldn't be needed to be checked
27 sec ; (it generates a c compiler warning)
30 jsr addysp ; fix stack, throw away unused parameters
32 parmok: jsr findfreeiocb
33 beq iocbok ; we found one
35 lda #<EMFILE ; "too many open files"
37 seterr: jsr __seterrno
38 jsr incsp4 ; clean up stack
43 ; process the mode argument
44 ; @@@TODO: append not handled yet!
47 jsr clriocb ; init with zero
49 jsr ldaxysp ; get mode
66 ; process the filename argument
72 ; we make sure that the filename doesn't contain lowercase letters
73 ; we copy the filename we got onto the stack, uppercase it and use this
74 ; one to open the iocb
75 ; we're using tmp3, ptr4
77 ; save the original pointer
81 ; now we need the length of the name
85 cmp #ATEOL ; we also accept Atari EOF char as end of string
88 bne loop ; not longer than 255 chars (127 real limit)
89 toolong:lda #<EINVAL ; file name is too long
93 str_end:iny ; room for terminating zero
94 cpy #128 ; we only can handle lenght < 128
97 jsr subysp ; make room on the stack
99 ; copy filename to the temp. place on the stack
100 lda #0 ; end-of-string
101 sta (sp),y ; Y still contains length + 1
106 bpl loop2 ; bpl: this way we only support a max. length of 127
108 ; uppercase the temp. filename
113 ; leave X and Y pointing to the modified filename
117 .endif ; defined UCASE_FILENAME
121 ;AX - points to filename
122 ;Y - iocb to use, if open needed
123 jsr newfd ; maybe we don't need to open and can reuse an iocb
124 ; returns fd num to use in tmp2, all regs unchanged
125 bcs doopen ; C set: open needed
126 lda #0 ; clears N flag
145 .ifdef UCASE_FILENAME
147 jsr addysp ; free used space on the stack
148 .endif ; defined UCASE_FILENAME
150 jsr incsp4 ; clean up stack
159 jsr fddecusage ; decrement usage counter of fd as open failed
162 ok: lda tmp2 ; get fd
171 ; no entry parameters
172 ; return ZF = 0/1 for not found/found
173 ; index in X if found
174 ; all registers destroyed
189 inx ; return ZF cleared
195 ; clear iocb except for ICHID field
196 ; expects X to be index to IOCB (0,$10,$20,etc.)
197 ; all registers destroyed
201 inx ; don't clear ICHID