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
39 ; ------------------------------------------------------------------------
44 PAGES = (TOPMEM - BASE) / 256
46 ; ------------------------------------------------------------------------
50 curpage: .res 1 ; Current page number
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.
66 stx curpage+1 ; Invalidate the current page
68 txa ; A = X = EM_ERR_OK
71 ; ------------------------------------------------------------------------
72 ; UNINSTALL routine. Is called before the driver is removed from memory.
73 ; Can do cleanup or whatever. Must not return anything.
80 ; ------------------------------------------------------------------------
81 ; PAGECOUNT: Return the total number of available pages in a/x.
89 ; ------------------------------------------------------------------------
90 ; MAP: Map the page in a/x into memory and return a pointer to the page in
91 ; a/x. The contents of the currently mapped page (if any) may be discarded
96 stx curpage+1 ; Remember the new page
109 @L1: ldx #MMU_CFG_RAM1
115 ; Return the memory window
118 ldx #>window ; Return the window address
121 ; ------------------------------------------------------------------------
122 ; USE: Tell the driver that the window is now associated with a given page.
125 stx curpage+1 ; Remember the page
127 ldx #>window ; Return the window
130 ; ------------------------------------------------------------------------
131 ; COMMIT: Commit changes in the memory window to extended storage.
133 COMMIT: lda curpage ; Get the current page
135 bmi done ; Jump if no page mapped
146 ; Transfer one page. Y must be zero on entry
158 ; ------------------------------------------------------------------------
159 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
160 ; describing the request is passed in a/x.
161 ; The function must not return anything.
166 stx ptr3+1 ; Save the passed em_copy pointer
187 ldy #EM_COPY::COUNT+1
188 lda (ptr3),y ; Get number of pages
189 beq @L2 ; Skip if no full pages
195 @L1: ldx #MMU_CFG_RAM1
205 ; Copy the remainder of the page
207 @L2: ldy #EM_COPY::COUNT
208 lda (ptr3),y ; Get bytes in last page
213 @L3: ldx #MMU_CFG_RAM1
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.
231 stx ptr3+1 ; Save the passed em_copy pointer
252 ldy #EM_COPY::COUNT+1
253 lda (ptr3),y ; Get number of pages
254 beq @L2 ; Skip if no full pages
270 ; Copy the remainder of the page
272 @L2: ldy #EM_COPY::COUNT
273 lda (ptr3),y ; Get bytes in last page