]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/cbm510-ram.s
Use changed EM decls
[cc65] / libsrc / cbm510 / cbm510-ram.s
1 ;
2 ; Extended memory driver for the CBM510 additional RAM banks. Driver works
3 ; without problems when linked statically.
4 ;
5 ; Ullrich von Bassewitz, 2002-12-09        !!! UNTESTED !!!
6 ;
7
8         .include        "zeropage.inc"
9
10         .include        "em-kernel.inc"
11         .include        "em-error.inc"
12         .include        "cbm510.inc"
13
14         .macpack        generic
15
16
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
19
20 .segment        "JUMPTABLE"
21
22 ; Driver signature
23
24         .byte   $65, $6d, $64           ; "emd"
25         .byte   EMD_API_VERSION         ; EM API version number
26
27 ; Jump table.
28
29         .word   INSTALL
30         .word   UNINSTALL
31         .word   PAGECOUNT
32         .word   MAP
33         .word   USE
34         .word   COMMIT
35         .word   COPYFROM
36         .word   COPYTO
37
38 ; ------------------------------------------------------------------------
39 ; Constants
40
41 RAMBANK = 2
42 OFFS    = 2
43
44 ; ------------------------------------------------------------------------
45 ; Data.
46
47 .bss
48 curpage:        .res    1               ; Current page number
49
50 window:         .res    256             ; Memory "window"
51 pagecount:      .res    1               ; Number of available pages
52
53
54 .code
55
56 ; ------------------------------------------------------------------------
57 ; INSTALL routine. Is called after the driver is loaded into memory. If
58 ; possible, check if the hardware is present and determine the amount of
59 ; memory available.
60 ; Must return an EM_ERR_xx code in a/x.
61 ;
62
63 INSTALL:
64         lda     #$FF
65         sta     curpage                 ; Invalidate the current page
66
67         ldx     UsrMemTop+2
68         cpx     #RAMBANK                ; Top of memory in bank 2?
69         bne     @L1                     ; No: We can use all the memory
70         clc
71         adc     UsrMemTop+1
72 @L1:    sta     pagecount
73
74         lda     #<EM_ERR_OK
75         ldx     #>EM_ERR_OK
76 ;       rts                             ; Run into UNINSTALL instead
77
78 ; ------------------------------------------------------------------------
79 ; UNINSTALL routine. Is called before the driver is removed from memory.
80 ; Can do cleanup or whatever. Must not return anything.
81 ;
82
83 UNINSTALL:
84         rts
85
86
87 ; ------------------------------------------------------------------------
88 ; PAGECOUNT: Return the total number of available pages in a/x.
89 ;
90
91 PAGECOUNT:
92         lda     pagecount
93         ldx     #0
94         rts
95
96 ; ------------------------------------------------------------------------
97 ; MAP: Map the page in a/x into memory and return a pointer to the page in
98 ; a/x. The contents of the currently mapped page (if any) may be discarded
99 ; by the driver.
100 ;
101
102 MAP:    sta     curpage                 ; Remember the new page
103
104         sta     ptr1+1
105         lda     #OFFS
106         sta     ptr1
107
108 ; Transfer one page
109
110         ldx     IndReg
111         lda     #RAMBANK
112         sta     IndReg
113
114         ldy     #$00
115 @L1:    lda     (ptr1),y
116         sta     window,y
117         iny
118         lda     (ptr1),y
119         sta     window,y
120         iny
121         bne     @L1
122
123         stx     IndReg
124
125 ; Return the memory window
126
127         lda     #<window
128         ldx     #>window                ; Return the window address
129         rts
130
131 ; ------------------------------------------------------------------------
132 ; USE: Tell the driver that the window is now associated with a given page.
133
134 USE:    sta     curpage                 ; Remember the page
135         lda     #<window
136         ldx     #>window                ; Return the window
137         rts
138
139 ; ------------------------------------------------------------------------
140 ; COMMIT: Commit changes in the memory window to extended storage.
141
142 COMMIT: lda     curpage                 ; Get the current page
143         cmp     #$FF
144         beq     done                    ; Jump if no page mapped
145
146         sta     ptr1+1
147         lda     #OFFS
148         sta     ptr1
149
150 ; Transfer one page
151
152         ldx     IndReg
153         lda     #RAMBANK
154         sta     IndReg
155
156         ldy     #$00
157 @L1:    lda     window,y
158         sta     (ptr1),y
159         iny
160         lda     window,y
161         sta     (ptr1),y
162         iny
163         bne     @L1
164
165         stx     IndReg
166
167 ; Done
168
169 done:   rts
170
171 ; ------------------------------------------------------------------------
172 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
173 ; describing the request is passed in a/x.
174 ; The function must not return anything.
175 ;
176
177 COPYFROM:
178         jsr     setup
179
180 ; Setup the buffer address in this bank.
181
182         sta     copyfrom_buf
183         stx     copyfrom_buf+1
184
185 ; Check if we must copy full pages
186
187         ldx     ptr2+1
188         beq     @L2
189
190 ; Copy full pages
191
192         ldx     #$00
193 @L1:    jsr     copyfrom
194         inc     ptr1+1
195         inc     copyfrom_buf+1
196 @L2:    dec     ptr2+1
197         bne     @L1
198
199 ; Copy the remaining page
200
201         ldx     ptr2
202         beq     @L3
203
204         jsr     copyfrom
205
206 ; Restore the indirect segment
207
208 @L3:    lda     ExecReg
209         sta     IndReg
210
211 ; Done
212
213         rts
214
215
216 ; ------------------------------------------------------------------------
217 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
218 ; describing the request is passed in a/x.
219 ; The function must not return anything.
220 ;
221
222 COPYTO: jsr     setup
223
224 ; Setup the buffer address in this bank.
225
226         sta     copyto_buf
227         stx     copyto_buf+1
228
229 ; Check if we must copy full pages
230
231         ldx     ptr2+1
232         beq     @L2
233
234 ; Copy full pages
235
236         ldx     #$00
237 @L1:    jsr     copyto
238         inc     ptr1+1
239         inc     copyto_buf+1
240 @L2:    dec     ptr2+1
241         bne     @L1
242
243 ; Copy the remaining page
244
245         ldx     ptr2
246         beq     @L3
247
248         jsr     copyto
249
250 ; Restore the indirect segment
251
252 @L3:    lda     ExecReg
253         sta     IndReg
254
255 ; Done
256
257         rts
258
259 ; ------------------------------------------------------------------------
260 ; setup: Helper function for COPYFROM and COPYTO, will setup parameters.
261 ;
262
263 setup:  sta     ptr3
264         stx     ptr3+1                  ; Save the passed em_copy pointer
265
266         ldy     #EM_COPY::OFFS
267         lda     (ptr3),y
268         add     #OFFS
269         sta     ptr1
270         ldy     #EM_COPY::PAGE
271         lda     (ptr3),y
272         adc     #$00
273         sta     ptr1+1
274
275         ldy     #EM_COPY::COUNT
276         lda     (ptr3),y
277         sta     ptr2
278         iny
279         lda     (ptr3),y
280         sta     ptr2+1                  ; Get count into ptr2
281
282         ldy     #EM_COPY::BUF+1
283         lda     (ptr1),y
284         tax
285         dey
286         lda     (ptr1),y                ; Get the buffer pointer into a/x
287
288         ldy     #RAMBANK
289         sty     IndReg
290
291         ldy     #$00
292
293         rts
294
295 ; ------------------------------------------------------------------------
296 ; copyfrom
297
298 .data
299 copyfrom:
300         lda     (ptr1),y
301 copyfrom_buf = * + 1
302         sta     $0000,y
303         iny
304         dex
305         bne     copyfrom
306         rts
307
308 ; ------------------------------------------------------------------------
309 ; copyto
310
311 .data
312 copyto:
313 copyto_buf = * + 1
314         lda     $0000,y
315         sta     (ptr1),y
316         iny
317         dex
318         bne     copyto
319         rts
320