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"
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
24 .byte $65, $6d, $64 ; "emd"
25 .byte EMD_API_VERSION ; EM API version number
42 ; ------------------------------------------------------------------------
48 ; ------------------------------------------------------------------------
52 curpage: .res 1 ; Current page number
54 window: .res 256 ; Memory "window"
55 pagecount: .res 1 ; Number of available pages
60 ; ------------------------------------------------------------------------
61 ; INSTALL routine. Is called after the driver is loaded into memory. If
62 ; possible, check if the hardware is present and determine the amount of
64 ; Must return an EM_ERR_xx code in a/x.
69 sta curpage ; Invalidate the current page
70 sta pagecount ; Assume all memory available
75 cmp #RAMBANK ; Top of memory in bank 2?
76 bne @L1 ; No: We can use all the memory
85 ; rts ; Run into UNINSTALL instead
87 ; ------------------------------------------------------------------------
88 ; UNINSTALL routine. Is called before the driver is removed from memory.
89 ; Can do cleanup or whatever. Must not return anything.
96 ; ------------------------------------------------------------------------
97 ; PAGECOUNT: Return the total number of available pages in a/x.
105 ; ------------------------------------------------------------------------
106 ; MAP: Map the page in a/x into memory and return a pointer to the page in
107 ; a/x. The contents of the currently mapped page (if any) may be discarded
111 MAP: sta curpage ; Remember the new page
133 ; Return the memory window
136 ldx #>window ; Return the window address
139 ; ------------------------------------------------------------------------
140 ; USE: Tell the driver that the window is now associated with a given page.
142 USE: sta curpage ; Remember the page
144 ldx #>window ; Return the window
147 ; ------------------------------------------------------------------------
148 ; COMMIT: Commit changes in the memory window to extended storage.
150 COMMIT: lda curpage ; Get the current page
152 beq done ; Jump if no page mapped
178 ; ------------------------------------------------------------------------
179 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
180 ; describing the request is passed in a/x.
181 ; The function must not return anything.
187 ; Setup the buffer address in this bank.
192 ; Check if we must copy full pages
206 ; Copy the remaining page
213 ; Restore the indirect segment
223 ; ------------------------------------------------------------------------
224 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
225 ; describing the request is passed in a/x.
226 ; The function must not return anything.
231 ; Setup the buffer address in this bank.
236 ; Check if we must copy full pages
250 ; Copy the remaining page
257 ; Restore the indirect segment
266 ; ------------------------------------------------------------------------
267 ; setup: Helper function for COPYFROM and COPYTO, will setup parameters.
271 stx ptr3+1 ; Save the passed em_copy pointer
287 sta ptr2+1 ; Get count into ptr2
293 lda (ptr3),y ; Get the buffer pointer into a/x
302 ; ------------------------------------------------------------------------
315 ; ------------------------------------------------------------------------