2 ; Christian Groessler, May-2000
4 ; fd indirection table & helper functions
28 MAX_FD_VAL = (* - fd_table) / 4
30 ft_usa = 0 ; usage counter
31 ft_iocb = 1 ; iocb index (0,$10,$20,etc.), $ff for empty entry
32 ft_dev = 2 ; device of open iocb
37 ; gets fd in ax, decrements usage counter
38 ; return iocb index in X
39 ; return N bit set for invalid fd
40 ; return Z bit set if last user
41 ; all registers destroyed
48 asl a ; create index into fd table
52 cmp fd_table+ft_iocb,x ; entry in use?
53 beq inval ; no, return error
54 lda fd_table+ft_usa,x ; get usage counter
57 sbc #1 ; decr usage counter
62 lda fd_table+ft_iocb,x ; get iocb
68 sta fd_table+ft_iocb,y ; clear table entry
78 inval: ldx #$ff ; sets N
83 ; return iocb index in X
84 ; return N bit set for invalid fd
85 ; all registers destroyed
92 asl a ; create index into fd table
96 cmp fd_table+ft_iocb,x ; entry in use?
97 beq inval ; no, return error
98 lda fd_table+ft_usa,x ; get usage counter
99 beq inval ; 0? should not happen
100 lda fd_table+ft_iocb,x ; get iocb