]> git.sur5r.net Git - cc65/blob - libsrc/common/_fdesc.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / common / _fdesc.s
1 ;
2 ; Ullrich von Bassewitz, 17.06.1998
3 ;
4 ; int _fdesc (void);
5 ; /* Find a free descriptor slot */
6
7
8         .export         __fdesc
9         .import         return0
10
11         .include        "stdio.inc"
12         .include        "_file.inc"
13
14 .proc   __fdesc
15
16         ldy     #0
17         lda     #_FOPEN
18 Loop:   and     __filetab + _FILE::f_flags,y    ; load flags
19         beq     Found                           ; jump if closed
20 .repeat .sizeof(_FILE)
21         iny
22 .endrepeat
23         cpy     #(FOPEN_MAX * .sizeof(_FILE))   ; Done?
24         bne     Loop
25
26 ; File table is full
27
28         jmp     return0
29
30 ; Free slot found, get address
31
32 Found:  tya                     ; Offset
33         clc
34         adc     #<__filetab
35         ldx     #>__filetab     ; High byte
36         bcc     @L1             ; Jump if no overflow
37         inx                     ; Bump high byte
38 @L1:    rts
39
40 .endproc
41
42
43