File: getfd.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (66 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;
; Christian Groessler, Oct-2000
;
; allocates a new fd in the indirection table
;

        .include "atari.inc"
        .include "fd.inc"
        .include "_file.inc"
        .importzp tmp1
        .import fd_table, fd_index

        .export fdt_to_fdi,getfd

        .code

; fdt_to_fdi
; returns a fd_index entry pointing to the given ft_table entry
; get fd_table entry in A
; return C = 0/1 for OK/error
; return fd_index entry in A if OK
; registers destroyed
.proc   fdt_to_fdi

        tay
        lda     #$ff
        tax
        inx
loop:   cmp     fd_index,x
        beq     found
        inx
        cpx     #MAX_FD_INDEX
        bcc     loop
        rts

found:  tya
        sta     fd_index,x
        txa
        clc
        rts

.endproc

; getfd
; get a new fd pointing to a ft_table entry
; usage counter of ft_table entry incremented
; A - fd_table entry
; return C = 0/1 for OK/error
; returns fd in A if OK
; registers destroyed, tmp1 destroyed
.proc   getfd

        sta     tmp1            ; save fd_table entry
        jsr     fdt_to_fdi
        bcs     error

        pha
        lda     tmp1
        asl     a
        asl     a                       ; also clears C
        tax
        inc     fd_table+ft_usa,x       ; increment usage counter
        pla
error:  rts

.endproc