2 ; Extended memory driver for the C128 Internal Function RAM. Driver works
3 ; without problems when statically linked.
5 ; Marco van den Heuvel, 2015-11-30
8 .include "zeropage.inc"
10 .include "em-kernel.inc"
11 .include "em-error.inc"
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
21 module_header _c128_ifnram_emd
25 .byte $65, $6d, $64 ; "emd"
26 .byte EMD_API_VERSION ; EM API version number
43 ; ------------------------------------------------------------------------
49 ; ------------------------------------------------------------------------
53 curpage: .res 2 ; Current page number
55 window: .res 256 ; Memory "window"
59 ; ------------------------------------------------------------------------
60 ; INSTALL routine. Is called after the driver is loaded into memory. If
61 ; possible, check if the hardware is present and determine the amount of
63 ; Must return an EM_ERR_xx code in a/x.
69 stx curpage+1 ; Invalidate the current page
71 txa ; A = X = EM_ERR_OK
73 ; ------------------------------------------------------------------------
74 ; UNINSTALL routine. Is called before the driver is removed from memory.
75 ; Can do cleanup or whatever. Must not return anything.
82 ; ------------------------------------------------------------------------
83 ; PAGECOUNT: Return the total number of available pages in a/x.
91 ; ------------------------------------------------------------------------
92 ; MAP: Map the page in a/x into memory and return a pointer to the page in
93 ; a/x. The contents of the currently mapped page (if any) may be discarded
99 stx curpage+1 ; Remember the new page
112 @L1: ldx #MMU_CFG_INT_FROM
118 ; Return the memory window
121 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.
138 lda curpage ; Get the current page
140 bmi done ; Jump if no page mapped
151 ; Transfer one page. Y must be zero on entry
154 ldx #MMU_CFG_INT_FROM
164 ; ------------------------------------------------------------------------
165 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
166 ; describing the request is passed in a/x.
167 ; The function must not return anything.
173 stx ptr3+1 ; Save the passed em_copy pointer
194 ldy #EM_COPY::COUNT+1
195 lda (ptr3),y ; Get number of pages
196 beq @L2 ; Skip if no full pages
202 @L1: ldx #MMU_CFG_INT_FROM
212 ; Copy the remainder of the page
214 @L2: ldy #EM_COPY::COUNT
215 lda (ptr3),y ; Get bytes in last page
220 @L3: ldx #MMU_CFG_INT_FROM
232 ; ------------------------------------------------------------------------
233 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
234 ; describing the request is passed in a/x.
235 ; The function must not return anything.
240 stx ptr3+1 ; Save the passed em_copy pointer
261 ldy #EM_COPY::COUNT+1
262 lda (ptr3),y ; Get number of pages
263 beq @L2 ; Skip if no full pages
270 ldx #MMU_CFG_INT_FROM
279 ; Copy the remainder of the page
281 @L2: ldy #EM_COPY::COUNT
282 lda (ptr3),y ; Get bytes in last page
288 ldx #MMU_CFG_INT_FROM