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 ; ------------------------------------------------------------------------
47 PAGES = 127 ; Do not touch MMU
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.
90 lda #<EM_ERR_NO_DEVICE
91 ldx #>EM_ERR_NO_DEVICE
97 stx curpage+1 ; Invalidate the current page
99 txa ; A = X = EM_ERR_OK
100 ; rts ; Run into UNINSTALL instead
102 ; ------------------------------------------------------------------------
103 ; UNINSTALL routine. Is called before the driver is removed from memory.
104 ; Can do cleanup or whatever. Must not return anything.
111 ; ------------------------------------------------------------------------
112 ; PAGECOUNT: Return the total number of available pages in a/x.
120 ; ------------------------------------------------------------------------
121 ; MAP: Map the page in a/x into memory and return a pointer to the page in
122 ; a/x. The contents of the currently mapped page (if any) may be discarded
127 stx curpage+1 ; Remember the new page
141 @L1: ldx #MMU_CFG_IFROM
147 ; Return the memory window
151 ldx #>window ; Return the window address
154 ; ------------------------------------------------------------------------
155 ; USE: Tell the driver that the window is now associated with a given page.
158 stx curpage+1 ; Remember the page
160 ldx #>window ; Return the window
163 ; ------------------------------------------------------------------------
164 ; COMMIT: Commit changes in the memory window to extended storage.
166 COMMIT: lda curpage ; Get the current page
168 bmi done ; Jump if no page mapped
180 ; Transfer one page. Y must be zero on entry
193 ; ------------------------------------------------------------------------
194 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
195 ; describing the request is passed in a/x.
196 ; The function must not return anything.
201 stx ptr3+1 ; Save the passed em_copy pointer
222 ldy #EM_COPY::COUNT+1
223 lda (ptr3),y ; Get number of pages
224 beq @L2 ; Skip if no full pages
231 @L1: ldx #MMU_CFG_IFROM
241 ; Copy the remainder of the page
243 @L2: ldy #EM_COPY::COUNT
244 lda (ptr3),y ; Get bytes in last page
249 @L3: ldx #MMU_CFG_IFROM
260 ; ------------------------------------------------------------------------
261 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
262 ; describing the request is passed in a/x.
263 ; The function must not return anything.
267 stx ptr3+1 ; Save the passed em_copy pointer
288 ldy #EM_COPY::COUNT+1
289 lda (ptr3),y ; Get number of pages
290 beq @L2 ; Skip if no full pages
307 ; Copy the remainder of the page
309 @L2: ldy #EM_COPY::COUNT
310 lda (ptr3),y ; Get bytes in last page