- sec
- sbc #ft_iocb ; normalize
- tax
- lsr a
- lsr a
- sta tmp2 ; return fd
- lda #2
- bit tmp1 ; remember device?
- beq l1 ; yes
- lda #0 ; no, put 0 in field
- beq l2
-
-l1: ldy #0
- lda (sp),y ; get device
-l2: sta fd_table+ft_dev,x ; set device
- lda #1
- sta fd_table+ft_usa,x ; set usage counter
- lda loc_Y
- sta fd_table+ft_iocb,x ; set iocb index
- lda loc_devnum
- and #7 ; only 3 bits
- sta fd_table+ft_flag,x
- lda tmp2
- jsr fdt_to_fdi ; get new index
- bcs noslot ; no one available
- ;cmp #$ff ; no one available
- ;beq noslot ;@@@ cleanup needed
- sta tmp2 ; return index
- jmp finish
+ sec
+ sbc #ft_iocb ; normalize
+ tax
+ lsr a
+ lsr a
+ sta tmp2 ; return fd
+ lda #2
+ bit tmp1 ; remember device?
+ beq l1 ; yes
+ lda #0 ; no, put 0 in field
+ beq l2
+
+l1: ldy #0
+ lda (sp),y ; get device
+l2: sta fd_table+ft_dev,x ; set device
+ lda #1
+ sta fd_table+ft_usa,x ; set usage counter
+ lda loc_Y
+ sta fd_table+ft_iocb,x ; set iocb index
+ lda loc_devnum
+ and #7 ; device number is 3 bits
+ ora #16 ; indicated a fd actively opened by the app
+ sta fd_table+ft_flag,x
+ lda tmp2
+ jsr fdt_to_fdi ; get new index
+noslot1:bcs noslot ; no one available (noslot1: helper label for branch out of range)
+ ;cmp #$ff ; no one available
+ ;beq noslot ;@@@ cleanup needed
+ sta tmp2 ; return index
+ jmp finish