; Christian Groessler, May-2000
;
; int open(const char *name,int flags,...);
-; returns fd
;
UCASE_FILENAME = 1 ; comment it out if filename shouldn't be uppercased
.include "../common/fmode.inc"
.include "../common/errno.inc"
.export _open
+ .import fddecusage,newfd
.import __do_oserror,__seterrno,incsp4
.import ldaxysp,addysp,subysp
.import _strupr,__oserror
- .importzp tmp4,sp
+ .importzp tmp4,tmp2,sp
.ifdef UCASE_FILENAME
.importzp tmp3,ptr4
.endif
ldy tmp4
+ ;AX - points to filename
+ ;Y - iocb to use, if open needed
jsr newfd ; maybe we don't need to open and can reuse an iocb
- bcc noopen
+ ; returns fd num to use in tmp2, all regs unchanged
+ bcs doopen ; C set: open needed
+ lda #0 ; clears N flag
+ beq finish
- sta ICBAL,y
+doopen: sta ICBAL,y
txa
sta ICBAH,y
ldx tmp4
; clean up the stack
- php
+finish: php
txa
pha
tya
plp
bpl ok
+ jsr fddecusage ; decrement usage counter of fd as open failed
jmp __do_oserror
-ok: txa
- lsr a
- lsr a
- lsr a
- lsr a
+ok: lda tmp2 ; get fd
ldx #0
stx __oserror
rts