2 ; Extended memory driver for the CBM510 additional RAM banks. Driver works
3 ; without problems when linked statically.
5 ; Ullrich von Bassewitz, 2002-12-09, 2003-12-27
8 .include "zeropage.inc"
10 .include "em-kernel.inc"
11 .include "em-error.inc"
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
21 module_header _cbm510_ram_emd
25 .byte $65, $6d, $64 ; "emd"
26 .byte EMD_API_VERSION ; EM API version number
43 ; ------------------------------------------------------------------------
49 ; ------------------------------------------------------------------------
53 curpage: .res 1 ; Current page number
55 window: .res 256 ; Memory "window"
56 pagecount: .res 1 ; Number of available pages
61 ; ------------------------------------------------------------------------
62 ; INSTALL routine. Is called after the driver is loaded into memory. If
63 ; possible, check if the hardware is present and determine the amount of
65 ; Must return an EM_ERR_xx code in a/x.
70 sta curpage ; Invalidate the current page
71 sta pagecount ; Assume all memory available
76 cmp #RAMBANK ; Top of memory in bank 2?
77 bne @L1 ; No: We can use all the memory
86 ; rts ; Run into UNINSTALL instead
88 ; ------------------------------------------------------------------------
89 ; UNINSTALL routine. Is called before the driver is removed from memory.
90 ; Can do cleanup or whatever. Must not return anything.
97 ; ------------------------------------------------------------------------
98 ; PAGECOUNT: Return the total number of available pages in a/x.
106 ; ------------------------------------------------------------------------
107 ; MAP: Map the page in a/x into memory and return a pointer to the page in
108 ; a/x. The contents of the currently mapped page (if any) may be discarded
112 MAP: sta curpage ; Remember the new page
134 ; Return the memory window
137 ldx #>window ; Return the window address
140 ; ------------------------------------------------------------------------
141 ; USE: Tell the driver that the window is now associated with a given page.
143 USE: sta curpage ; Remember the page
145 ldx #>window ; Return the window
148 ; ------------------------------------------------------------------------
149 ; COMMIT: Commit changes in the memory window to extended storage.
151 COMMIT: lda curpage ; Get the current page
153 beq done ; Jump if no page mapped
179 ; ------------------------------------------------------------------------
180 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
181 ; describing the request is passed in a/x.
182 ; The function must not return anything.
188 ; Setup the buffer address in this bank.
193 ; Check if we must copy full pages
207 ; Copy the remaining page
214 ; Restore the indirect segment
224 ; ------------------------------------------------------------------------
225 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
226 ; describing the request is passed in a/x.
227 ; The function must not return anything.
232 ; Setup the buffer address in this bank.
237 ; Check if we must copy full pages
251 ; Copy the remaining page
258 ; Restore the indirect segment
267 ; ------------------------------------------------------------------------
268 ; setup: Helper function for COPYFROM and COPYTO, will setup parameters.
272 stx ptr3+1 ; Save the passed em_copy pointer
288 sta ptr2+1 ; Get count into ptr2
294 lda (ptr3),y ; Get the buffer pointer into a/x
303 ; ------------------------------------------------------------------------
316 ; ------------------------------------------------------------------------