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
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 1 ; 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
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
113 @L1: ldx #MMU_CFG_RAM1
119 ; Return the memory window
122 ldx #>window ; Return the window address
125 ; ------------------------------------------------------------------------
126 ; USE: Tell the driver that the window is now associated with a given page.
129 stx curpage+1 ; Remember the page
131 ldx #>window ; Return the window
134 ; ------------------------------------------------------------------------
135 ; COMMIT: Commit changes in the memory window to extended storage.
137 COMMIT: lda curpage ; Get the current page
139 bmi done ; Jump if no page mapped
150 ; Transfer one page. Y must be zero on entry
162 ; ------------------------------------------------------------------------
163 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
164 ; describing the request is passed in a/x.
165 ; The function must not return anything.
170 stx ptr3+1 ; Save the passed em_copy pointer
191 ldy #EM_COPY::COUNT+1
192 lda (ptr3),y ; Get number of pages
193 beq @L2 ; Skip if no full pages
199 @L1: ldx #MMU_CFG_RAM1
209 ; Copy the remainder of the page
211 @L2: ldy #EM_COPY::COUNT
212 lda (ptr3),y ; Get bytes in last page
217 @L3: ldx #MMU_CFG_RAM1
228 ; ------------------------------------------------------------------------
229 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
230 ; describing the request is passed in a/x.
231 ; The function must not return anything.
235 stx ptr3+1 ; Save the passed em_copy pointer
256 ldy #EM_COPY::COUNT+1
257 lda (ptr3),y ; Get number of pages
258 beq @L2 ; Skip if no full pages
274 ; Copy the remainder of the page
276 @L2: ldy #EM_COPY::COUNT
277 lda (ptr3),y ; Get bytes in last page