]> git.sur5r.net Git - cc65/blob - libsrc/atari/getfd.s
Fixed _textcolor definition.
[cc65] / libsrc / atari / getfd.s
1 ;
2 ; Christian Groessler, Oct-2000
3 ;
4 ; allocates a new fd in the indirection table
5 ;
6
7         .include "atari.inc"
8         .include "fd.inc"
9         .include "_file.inc"
10         .importzp tmp1
11         .import fd_table, fd_index
12
13         .export fdt_to_fdi,getfd
14
15         .code
16
17 ; fdt_to_fdi
18 ; returns a fd_index entry pointing to the given ft_table entry
19 ; get fd_table entry in A
20 ; return C = 0/1 for OK/error
21 ; return fd_index entry in A if OK
22 ; registers destroyed
23 .proc   fdt_to_fdi
24
25         tay
26         lda     #$ff
27         tax
28         inx
29 loop:   cmp     fd_index,x
30         beq     found
31         inx
32         cpx     #MAX_FD_INDEX
33         bcc     loop
34         rts
35
36 found:  tya
37         sta     fd_index,x
38         txa
39         clc
40         rts
41
42 .endproc
43
44 ; getfd
45 ; get a new fd pointing to a ft_table entry
46 ; usage counter of ft_table entry incremented
47 ; A - fd_table entry
48 ; return C = 0/1 for OK/error
49 ; returns fd in A if OK
50 ; registers destroyed, tmp1 destroyed
51 .proc   getfd
52
53         sta     tmp1            ; save fd_table entry
54         jsr     fdt_to_fdi
55         bcs     error
56
57         pha
58         lda     tmp1
59         asl     a
60         asl     a                       ; also clears C
61         tax
62         inc     fd_table+ft_usa,x       ; increment usage counter
63         pla
64 error:  rts
65
66 .endproc