2 ; Extended memory driver for the C128 RAM in bank #1. Driver works without
3 ; problems when statically linked.
5 ; Ullrich von Bassewitz, 2002-12-04
8 .include "zeropage.inc"
10 .include "em-kernel.inc"
11 .include "em-error.inc"
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
21 module_header _c128_ram_emd
25 .byte $65, $6d, $64 ; "emd"
26 .byte EMD_API_VERSION ; EM API version number
43 ; ------------------------------------------------------------------------
48 PAGES = (TOPMEM - BASE) / 256
50 ; ------------------------------------------------------------------------
54 curpage: .res 2 ; Current page number
56 window: .res 256 ; Memory "window"
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.
70 stx curpage+1 ; Invalidate the current page
72 txa ; A = X = EM_ERR_OK
73 ; rts ; Run into UNINSTALL instead
75 ; ------------------------------------------------------------------------
76 ; UNINSTALL routine. Is called before the driver is removed from memory.
77 ; Can do cleanup or whatever. Must not return anything.
84 ; ------------------------------------------------------------------------
85 ; PAGECOUNT: Return the total number of available pages in a/x.
93 ; ------------------------------------------------------------------------
94 ; MAP: Map the page in a/x into memory and return a pointer to the page in
95 ; a/x. The contents of the currently mapped page (if any) may be discarded
100 stx curpage+1 ; Remember the new page
114 @L1: ldx #MMU_CFG_RAM1
121 ; Return the memory window
124 ldx #>window ; Return the window address
127 ; ------------------------------------------------------------------------
128 ; USE: Tell the driver that the window is now associated with a given page.
131 stx curpage+1 ; Remember the page
133 ldx #>window ; Return the window
136 ; ------------------------------------------------------------------------
137 ; COMMIT: Commit changes in the memory window to extended storage.
139 COMMIT: lda curpage ; Get the current page
141 bmi done ; Jump if no page mapped
153 ; Transfer one page. Y must be zero on entry
166 ; ------------------------------------------------------------------------
167 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
168 ; describing the request is passed in a/x.
169 ; The function must not return anything.
174 stx ptr3+1 ; Save the passed em_copy pointer
195 ldy #EM_COPY::COUNT+1
196 lda (ptr3),y ; Get number of pages
197 beq @L2 ; Skip if no full pages
204 @L1: ldx #MMU_CFG_RAM1
214 ; Copy the remainder of the page
216 @L2: ldy #EM_COPY::COUNT
217 lda (ptr3),y ; Get bytes in last page
222 @L3: ldx #MMU_CFG_RAM1
234 ; ------------------------------------------------------------------------
235 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
236 ; describing the request is passed in a/x.
237 ; The function must not return anything.
241 stx ptr3+1 ; Save the passed em_copy pointer
262 ldy #EM_COPY::COUNT+1
263 lda (ptr3),y ; Get number of pages
264 beq @L2 ; Skip if no full pages
281 ; Copy the remainder of the page
283 @L2: ldy #EM_COPY::COUNT
284 lda (ptr3),y ; Get bytes in last page