]> git.sur5r.net Git - cc65/blob - libsrc/apple2/emd/a2.auxmem.s
ld65: implement '--allow-multiple-definition' command line parameter
[cc65] / libsrc / apple2 / emd / a2.auxmem.s
1 ;
2 ; Extended memory driver for the Apple II auxiliary memory
3 ;
4 ; Stefan Haubenthal, 2003-12-12
5 ; Ullrich von Bassewitz, 2002-12-02
6 ;
7
8         .include        "zeropage.inc"
9
10         .include        "em-kernel.inc"
11         .include        "em-error.inc"
12
13         .macpack        module
14
15 ; ------------------------------------------------------------------------
16 ; Header. Includes jump table
17
18         .ifdef  __APPLE2ENH__
19         module_header   _a2e_auxmem_emd
20         .else
21         module_header   _a2_auxmem_emd
22         .endif
23
24 ; Driver signature
25
26         .byte   $65, $6d, $64           ; "emd"
27         .byte   EMD_API_VERSION         ; EM API version number
28
29 ; Library reference
30
31         .addr   $0000
32
33 ; Jump table
34
35         .addr   INSTALL
36         .addr   UNINSTALL
37         .addr   PAGECOUNT
38         .addr   MAP
39         .addr   USE
40         .addr   COMMIT
41         .addr   COPYFROM
42         .addr   COPYTO
43
44 ; ------------------------------------------------------------------------
45 ; Constants
46
47 BASE    = $0200
48 AUXCARD = $C30C                         ; Card signature
49 AUXMOVE = $C311                         ; Auxiliary move routine
50 PAGES   = ($C000 - BASE) / 256
51
52 ; ------------------------------------------------------------------------
53 ; Data.
54
55 .data
56 curpage:        .byte   $FF             ; Current page number (invalid)
57
58 .bss
59 window:         .res    256             ; Memory "window"
60
61 .code
62
63 ; ------------------------------------------------------------------------
64 ; INSTALL routine. Is called after the driver is loaded into memory. If
65 ; possible, check if the hardware is present and determine the amount of
66 ; memory available.
67 ; Must return an EM_ERR_xx code in a/x.
68 ;
69
70 INSTALL:
71         ldx     #0
72         lda     AUXCARD
73         and     #$f0
74         cmp     #$80
75         bne     @L1
76         lda     #EM_ERR_OK
77         rts
78 @L1:    lda     #EM_ERR_NO_DEVICE
79 ;       rts
80
81 ; ------------------------------------------------------------------------
82 ; UNINSTALL routine. Is called before the driver is removed from memory.
83 ; Can do cleanup or whatever. Must not return anything.
84 ;
85
86 UNINSTALL:
87         rts
88
89
90 ; ------------------------------------------------------------------------
91 ; PAGECOUNT: Return the total number of available pages in a/x.
92 ;
93
94 PAGECOUNT:
95         lda     #<PAGES
96         ldx     #>PAGES
97         rts
98
99 ; ------------------------------------------------------------------------
100 ; MAP: Map the page in a/x into memory and return a pointer to the page in
101 ; a/x. The contents of the currently mapped page (if any) may be discarded
102 ; by the driver.
103 ;
104
105 MAP:    sta     curpage                 ; Remember the new page
106
107         clc
108         adc     #>BASE
109         sta     ptr1+1
110         ldy     #$00
111         sty     ptr1
112
113         lda     #<window
114         sta     ptr2
115         lda     #>window
116         sta     ptr2+1
117
118 ; Transfer one page
119
120         clc                             ; Direction flag
121         jsr     transfer                ; Transfer one page
122
123 ; Return the memory window
124
125         lda     #<window
126         ldx     #>window                ; Return the window address
127
128 ; Done
129
130 done:   rts
131
132 ; ------------------------------------------------------------------------
133 ; USE: Tell the driver that the window is now associated with a given page.
134
135 USE:    sta     curpage                 ; Remember the page
136         lda     #<window
137         ldx     #>window                ; Return the window
138         rts
139
140 ; ------------------------------------------------------------------------
141 ; COMMIT: Commit changes in the memory window to extended storage.
142
143 COMMIT: lda     curpage                 ; Get the current page
144         cmp     #$FF
145         beq     done                    ; Jump if no page mapped
146
147         clc
148         adc     #>BASE
149         sta     ptr2+1
150         ldy     #$00
151         sty     ptr2
152
153         lda     #<window
154         sta     ptr1
155         lda     #>window
156         sta     ptr1+1
157         lda     #<$FF
158         sta     ptr4
159         lda     #>$FF
160         sta     ptr4+1
161         sec                             ; Direction flag
162
163 ; Transfer one page/all bytes
164
165 transfer:
166         php
167         clc
168         lda     ptr1
169         sta     $3C
170         adc     ptr4
171         sta     $3E
172         lda     ptr1+1
173         sta     $3D
174         adc     ptr4+1
175         sta     $3F
176         lda     ptr2
177         sta     $42
178         lda     ptr2+1
179         sta     $43
180         plp
181         jmp     AUXMOVE
182
183 ; ------------------------------------------------------------------------
184 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
185 ; describing the request is passed in a/x.
186 ; The function must not return anything.
187 ;
188
189 COPYFROM:
190         sta     ptr3
191         stx     ptr3+1                  ; Save the passed em_copy pointer
192
193         ldy     #EM_COPY::OFFS
194         lda     (ptr3),y
195         sta     ptr1
196         ldy     #EM_COPY::PAGE
197         lda     (ptr3),y
198         clc
199         adc     #>BASE
200         sta     ptr1+1                  ; From
201
202         ldy     #EM_COPY::BUF
203         lda     (ptr3),y
204         sta     ptr2
205         iny
206         lda     (ptr3),y
207         sta     ptr2+1                  ; To
208         clc                             ; Direction flag
209
210 common: ldy     #EM_COPY::COUNT
211         lda     (ptr3),y                ; Get bytes in last page
212         sta     ptr4
213         iny
214         lda     (ptr3),y                ; Get number of pages
215         sta     ptr4+1
216
217         jmp     transfer
218
219 ; ------------------------------------------------------------------------
220 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
221 ; describing the request is passed in a/x.
222 ; The function must not return anything.
223 ;
224
225 COPYTO: sta     ptr3
226         stx     ptr3+1                  ; Save the passed em_copy pointer
227
228         ldy     #EM_COPY::OFFS
229         lda     (ptr3),y
230         sta     ptr2
231         ldy     #EM_COPY::PAGE
232         lda     (ptr3),y
233         clc
234         adc     #>BASE
235         sta     ptr2+1                  ; To
236
237         ldy     #EM_COPY::BUF
238         lda     (ptr3),y
239         sta     ptr1
240         iny
241         lda     (ptr3),y
242         sta     ptr1+1                  ; From
243
244         sec                             ; Direction flag
245         jmp     common