2 ; Extended memory driver for the C128 RAM in bank #1
4 ; Ullrich von Bassewitz, 2002-12-04
7 .include "zeropage.inc"
9 .include "em-kernel.inc"
10 .include "em-error.inc"
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
24 .byte $65, $6d, $64 ; "emd"
25 .byte $00 ; EM API version number
38 ; ------------------------------------------------------------------------
43 PAGES = (TOPMEM - BASE) / 256
45 ; ------------------------------------------------------------------------
49 curpage: .word $FFFF ; Current page number (invalid)
52 window: .res 256 ; Memory "window"
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
60 ; Must return an EM_ERR_xx code in a/x.
68 ; ------------------------------------------------------------------------
69 ; DEINSTALL routine. Is called before the driver is removed from memory.
70 ; Can do cleanup or whatever. Must not return anything.
77 ; ------------------------------------------------------------------------
78 ; PAGECOUNT: Return the total number of available pages in a/x.
86 ; ------------------------------------------------------------------------
87 ; MAP: Map the page in a/x into memory and return a pointer to the page in
88 ; a/x. The contents of the currently mapped page (if any) may be discarded
93 stx curpage+1 ; Remember the new page
106 @L1: ldx #MMU_CFG_RAM1
112 ; Return the memory window
115 ldx #>window ; Return the window address
118 ; ------------------------------------------------------------------------
119 ; USE: Tell the driver that the window is now associated with a given page.
122 stx curpage+1 ; Remember the page
124 ldx #>window ; Return the window
127 ; ------------------------------------------------------------------------
128 ; COMMIT: Commit changes in the memory window to extended storage.
130 COMMIT: lda curpage ; Get the current page
132 bmi done ; Jump if no page mapped
143 ; Transfer one page. Y must be zero on entry
155 ; ------------------------------------------------------------------------
156 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
157 ; describing the request is passed in a/x.
158 ; The function must not return anything.
163 stx ptr3+1 ; Save the passed em_copy pointer
185 lda (ptr3),y ; Get number of pages
186 beq @L2 ; Skip if no full pages
192 @L1: ldx #MMU_CFG_RAM1
202 ; Copy the remainder of the page
204 @L2: ldy #EM_COPY_COUNT
205 lda (ptr3),y ; Get bytes in last page
210 @L3: ldx #MMU_CFG_RAM1
221 ; ------------------------------------------------------------------------
222 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
223 ; describing the request is passed in a/x.
224 ; The function must not return anything.
228 stx ptr3+1 ; Save the passed em_copy pointer
250 lda (ptr3),y ; Get number of pages
251 beq @L2 ; Skip if no full pages
267 ; Copy the remainder of the page
269 @L2: ldy #EM_COPY_COUNT
270 lda (ptr3),y ; Get bytes in last page