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
37 ; ------------------------------------------------------------------------
42 PAGES = (TOPMEM - BASE) / 256
44 ; ------------------------------------------------------------------------
48 curpage: .word $FFFF ; Current page number (invalid)
51 window: .res 256 ; Memory "window"
55 ; ------------------------------------------------------------------------
56 ; INSTALL routine. Is called after the driver is loaded into memory. If
57 ; possible, check if the hardware is present and determine the amount of
59 ; Must return an EM_ERR_xx code in a/x.
67 ; ------------------------------------------------------------------------
68 ; DEINSTALL routine. Is called before the driver is removed from memory.
69 ; Can do cleanup or whatever. Must not return anything.
76 ; ------------------------------------------------------------------------
77 ; PAGECOUNT: Return the total number of available pages in a/x.
85 ; ------------------------------------------------------------------------
86 ; MAP: Map the page in a/x into memory and return a pointer to the page in
87 ; a/x. The contents of the currently mapped page (if any) may be discarded
92 stx curpage+1 ; Remember the new page
105 @L1: ldx #MMU_CFG_RAM1
111 ; Return the memory window
114 ldx #>window ; Return the window address
117 ; ------------------------------------------------------------------------
118 ; COMMIT: Commit changes in the memory window to extended storage.
120 COMMIT: lda curpage ; Get the current page
122 bmi done ; Jump if no page mapped
133 ; Transfer one page. Y must be zero on entry
145 ; ------------------------------------------------------------------------
146 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
147 ; describing the request is passed in a/x.
148 ; The function must not return anything.
153 stx ptr3+1 ; Save the passed em_copy pointer
175 lda (ptr3),y ; Get number of pages
176 beq @L2 ; Skip if no full pages
182 @L1: ldx #MMU_CFG_RAM1
192 ; Copy the remainder of the page
194 @L2: ldy #EM_COPY_COUNT
195 lda (ptr3),y ; Get bytes in last page
199 @L3: ldx #MMU_CFG_RAM1
210 ; ------------------------------------------------------------------------
211 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
212 ; describing the request is passed in a/x.
213 ; The function must not return anything.
217 stx ptr3+1 ; Save the passed em_copy pointer
239 lda (ptr3),y ; Get number of pages
240 beq @L2 ; Skip if no full pages
256 ; Copy the remainder of the page
258 @L2: ldy #EM_COPY_COUNT
259 lda (ptr3),y ; Get bytes in last page