]> git.sur5r.net Git - cc65/blob - libsrc/apple2/extra/iobuf-0800.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / apple2 / extra / iobuf-0800.s
1 ;
2 ; Oliver Schmidt, 15.09.2009
3 ;
4 ; ProDOS 8 I/O buffer management for memory between
5 ; location $0800 and the cc65 program start address
6 ;
7
8         .constructor    initiobuf
9         .export         iobuf_alloc, iobuf_free
10         .import         __STARTUP_RUN__
11         .import         incsp2, popax
12
13         .include        "zeropage.inc"
14         .include        "errno.inc"
15         .include        "../filedes.inc"
16
17         .segment        "INIT"
18
19 initiobuf:
20         ; Convert end address highbyte to table index
21         lda     #>__STARTUP_RUN__
22         sec
23         sbc     #>$0800
24         lsr
25         lsr
26
27         ; Mark all remaining table entries as used
28         tax
29         lda     #$FF
30 :       cpx     #MAX_FDS
31         bcc     :+
32         rts
33 :       sta     table,x
34         inx
35         bne     :--             ; Branch always
36
37 ; ------------------------------------------------------------------------
38
39         .code
40
41 iobuf_alloc:
42         ; Get and save "memptr"
43         jsr     incsp2
44         jsr     popax
45         sta     ptr1
46         stx     ptr1+1
47
48         ; Search table for free entry
49         ldx     #$00
50 :       lda     table,x
51         beq     :+
52         inx
53         cpx     #MAX_FDS
54         bcc     :-
55         lda     #ENOMEM
56         rts
57
58         ; Mark table entry as used
59 :       lda     #$FF
60         sta     table,x
61
62         ; Convert table index to address hibyte
63         txa
64         asl
65         asl
66         clc
67         adc     #>$0800
68
69         ; Store address in "memptr"
70         ldy     #$01
71         sta     (ptr1),y
72         dey
73         tya
74         sta     (ptr1),y
75         rts
76
77 iobuf_free:
78         ; Convert address hibyte to table index
79         txa
80         sec
81         sbc     #>$0800
82         lsr
83         lsr
84
85         ; Mark table entry as free
86         tax
87         lda     #$00
88         sta     table,x
89         rts
90
91 ; ------------------------------------------------------------------------
92
93         .bss
94
95 table:  .res    MAX_FDS