-.endif ; defined UCASE_FILENAME
-
- 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
- ; returns fd num to use in tmp2, all regs unchanged
- bcs doopen ; C set: open needed
- lda #0 ; clears N flag
- beq finish
-
-doopen: sta ICBAL,y
- txa
- sta ICBAH,y
- ldx tmp4
- lda #OPEN
- sta ICCOM,x
- jsr CIOV
-
- ; clean up the stack
-
-finish: php
- txa
- pha
- tya
- pha
-
-.ifdef UCASE_FILENAME
- ldy tmp3 ; get size
- jsr addysp ; free used space on the stack
-.endif ; defined UCASE_FILENAME
-
- jsr incsp4 ; clean up stack
-
- pla
- tay
- pla
- tax
- plp
-
- bpl ok
- jsr fddecusage ; decrement usage counter of fd as open failed
- jmp __do_oserror
-
-ok: lda tmp2 ; get fd
- ldx #0
- stx __oserror
- rts
+.endif ; defined UCASE_FILENAME
+
+ 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
+ ; returns fd num to use in tmp2, all regs unchanged
+ bcs doopen ; C set: open needed
+ lda #0 ; clears N flag
+ beq finish
+
+doopen: sta ICBAL,y
+ txa
+ sta ICBAH,y
+ ldx tmp4
+ lda #OPEN
+ sta ICCOM,x
+ jsr CIOV
+
+ ; clean up the stack
+
+finish: php
+ txa
+ pha
+ tya
+ pha
+
+.ifdef UCASE_FILENAME
+ ldy tmp3 ; get size
+ jsr addysp ; free used space on the stack
+.endif ; defined UCASE_FILENAME
+
+ jsr incsp4 ; clean up stack
+
+ pla
+ tay
+ pla
+ tax
+ plp
+
+ bpl ok
+ sty tmp3 ; remember error code
+ lda #CLOSE
+ sta ICCOM,x
+ jsr CIOV ; close IOCB again since open failed
+ jsr fddecusage ; and decrement usage counter of fd
+ lda tmp3 ; put error code into A
+ jmp __mappederrno
+
+ok: lda tmp2 ; get fd
+ ldx #0
+ stx __oserror
+ rts