2 ; Extended memory driver for the C64 hidden RAM
4 ; Ullrich von Bassewitz, 2002-12-02
7 .include "zeropage.inc"
9 .include "em-kernel.inc"
10 .include "em-error.inc"
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
23 .byte $65, $6d, $64 ; "emd"
24 .byte $00 ; EM API version number
36 ; ------------------------------------------------------------------------
40 PAGES = ($10000 - BASE) / 256
42 ; ------------------------------------------------------------------------
46 curpage: .byte $FF ; Current page number (invalid)
49 window: .res 256 ; Memory "window"
53 ; ------------------------------------------------------------------------
54 ; INSTALL routine. Is called after the driver is loaded into memory. If
55 ; possible, check if the hardware is present and determine the amount of
57 ; Must return an EM_ERR_xx code in a/x.
65 ; ------------------------------------------------------------------------
66 ; DEINSTALL routine. Is called before the driver is removed from memory.
67 ; Can do cleanup or whatever. Must not return anything.
74 ; ------------------------------------------------------------------------
75 ; PAGECOUNT: Return the total number of available pages in a/x.
83 ; ------------------------------------------------------------------------
84 ; MAP: Map the page in a/x into memory and return a pointer to the page in
85 ; a/x. The contents of the currently mapped page (if any) may be discarded
89 MAP: sta curpage ; Remember the new page
104 jsr transfer ; Transfer one page
106 ; Return the memory window
109 ldx #>window ; Return the window address
112 ; ------------------------------------------------------------------------
113 ; COMMIT: Commit changes in the memory window to extended storage.
115 COMMIT: lda curpage ; Get the current page
116 bmi done ; Jump if no page mapped
129 ; Transfer one page. Y must be zero on entry
132 ldx $01 ; Remember c64 control port
134 and #$F8 ; Bank out ROMs, I/O
138 ; Unroll the following loop
174 ; Restore the old memory configuration, allow interrupts
176 stx $01 ; Restore the old configuration
183 ; ------------------------------------------------------------------------
184 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
185 ; describing the request is passed in a/x.
186 ; The function must not return anything.
191 stx ptr3+1 ; Save the passed em_copy pointer
209 common: ldy #EM_COPY_COUNT+1
210 lda (ptr3),y ; Get number of pages
211 beq @L2 ; Skip if no full pages
214 ; Copy full pages allowing interrupts after each page copied
223 ; Copy the remainder of the page
225 @L2: ldy #EM_COPY_COUNT
226 lda (ptr3),y ; Get bytes in last page
230 lda $01 ; Remember c64 control port
232 and #$F8 ; Bank out ROMs, I/O
236 ; Transfer the bytes in the last page
244 ; Restore the old memory configuration, allow interrupts
247 sta $01 ; Restore the old configuration
254 ; ------------------------------------------------------------------------
255 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
256 ; describing the request is passed in a/x.
257 ; The function must not return anything.
261 stx ptr3+1 ; Save the passed em_copy pointer