]> git.sur5r.net Git - cc65/blob - libsrc/apple2/extra/iobuf-0800.s
Package additional linker configs for the apple2enh
[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         __RAM_START__
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     #>__RAM_START__
22         sec
23         sbc     #>$0800
24         lsr
25         lsr
26
27         ; Mark all remaining table entries as used
28         tax
29         lda     #$FF
30 :       sta     table,x
31         inx
32         cpx     #MAX_FDS
33         bcc     :-
34         rts
35
36 ; ------------------------------------------------------------------------
37
38         .code
39
40 iobuf_alloc:
41         ; Get and save "memptr"
42         jsr     incsp2
43         jsr     popax
44         sta     ptr1
45         stx     ptr1+1
46
47         ; Search table for free entry
48         ldx     #$00
49 :       lda     table,x
50         beq     :+
51         inx
52         cpx     #MAX_FDS
53         bcc     :-
54         lda     #ENOMEM
55         rts
56
57         ; Mark table entry as used
58 :       lda     #$FF
59         sta     table,x
60
61         ; Convert table index to address hibyte
62         txa
63         asl
64         asl
65         clc
66         adc     #>$0800
67
68         ; Store address in "memptr"
69         ldy     #$01
70         sta     (ptr1),y
71         dey
72         lda     #$00
73         sta     (ptr1),y
74         rts
75
76 iobuf_free:
77         ; Convert address hibyte to table index
78         txa
79         sec
80         sbc     #>$0800
81         lsr
82         lsr
83
84         ; Mark table entry as free
85         tax
86         lda     #$00
87         sta     table,x
88         rts
89
90 ; ------------------------------------------------------------------------
91
92         .bss
93
94 table:  .res    MAX_FDS