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"
14 .import fddecusage,newfd
16 .import __do_oserror,__seterrno,incsp4
17 .import ldaxysp,addysp,subysp
18 .import _strupr,__oserror
19 .importzp tmp4,tmp2,sp
26 cpy #4 ; correct # of arguments (bytes)?
27 beq parmok ; parameter count ok
28 tya ; parm count < 4 shouldn't be needed to be checked
29 sec ; (it generates a c compiler warning)
32 jsr addysp ; fix stack, throw away unused parameters
34 parmok: jsr findfreeiocb
35 beq iocbok ; we found one
37 lda #<EMFILE ; "too many open files"
39 seterr: jsr __seterrno
40 jsr incsp4 ; clean up stack
45 ; process the mode argument
46 ; @@@TODO: append not handled yet!
49 jsr clriocb ; init with zero
51 jsr ldaxysp ; get mode
68 ; process the filename argument
74 ; we make sure that the filename doesn't contain lowercase letters
75 ; we copy the filename we got onto the stack, uppercase it and use this
76 ; one to open the iocb
77 ; we're using tmp3, ptr4
79 ; save the original pointer
83 ; now we need the length of the name
87 cmp #ATEOL ; we also accept Atari EOF char as end of string
90 bne loop ; not longer than 255 chars (127 real limit)
91 toolong:lda #<EINVAL ; file name is too long
95 str_end:iny ; room for terminating zero
96 cpy #128 ; we only can handle lenght < 128
99 jsr subysp ; make room on the stack
101 ; copy filename to the temp. place on the stack
102 lda #0 ; end-of-string
103 sta (sp),y ; Y still contains length + 1
108 bpl loop2 ; bpl: this way we only support a max. length of 127
110 ; uppercase the temp. filename
115 ; leave X and Y pointing to the modified filename
119 .endif ; defined UCASE_FILENAME
123 ;AX - points to filename
124 ;Y - iocb to use, if open needed
125 jsr newfd ; maybe we don't need to open and can reuse an iocb
126 ; returns fd num to use in tmp2, all regs unchanged
127 bcs doopen ; C set: open needed
128 lda #0 ; clears N flag
147 .ifdef UCASE_FILENAME
149 jsr addysp ; free used space on the stack
150 .endif ; defined UCASE_FILENAME
152 jsr incsp4 ; clean up stack
161 jsr fddecusage ; decrement usage counter of fd as open failed
164 ok: lda tmp2 ; get fd