2 ; Extended memory driver for the C64 hidden RAM. Driver works without
3 ; problems when statically linked.
5 ; Ullrich von Bassewitz, 2002-12-02
8 .include "zeropage.inc"
10 .include "em-kernel.inc"
11 .include "em-error.inc"
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
21 module_header _c64_ram_emd
25 .byte $65, $6d, $64 ; "emd"
26 .byte EMD_API_VERSION ; EM API version number
43 ; ------------------------------------------------------------------------
47 PAGES = ($FF00 - BASE) / 256
49 ; ------------------------------------------------------------------------
53 curpage: .res 1 ; Current page number
54 window: .res 256 ; Memory "window"
58 ; ------------------------------------------------------------------------
59 ; INSTALL routine. Is called after the driver is loaded into memory. If
60 ; possible, check if the hardware is present and determine the amount of
62 ; Must return an EM_ERR_xx code in a/x.
67 stx curpage ; Invalidate the current page
69 txa ; A = X = EM_ERR_OK
70 ; rts ; Run into UNINSTALL instead
72 ; ------------------------------------------------------------------------
73 ; UNINSTALL routine. Is called before the driver is removed from memory.
74 ; Can do cleanup or whatever. Must not return anything.
81 ; ------------------------------------------------------------------------
82 ; PAGECOUNT: Return the total number of available pages in a/x.
90 ; ------------------------------------------------------------------------
91 ; MAP: Map the page in a/x into memory and return a pointer to the page in
92 ; a/x. The contents of the currently mapped page (if any) may be discarded
96 MAP: sta curpage ; Remember the new page
111 jsr transfer ; Transfer one page
113 ; Return the memory window
116 ldx #>window ; Return the window address
119 ; ------------------------------------------------------------------------
120 ; USE: Tell the driver that the window is now associated with a given page.
122 USE: sta curpage ; Remember the page
124 ldx #>window ; Return the window
127 ; ------------------------------------------------------------------------
128 ; COMMIT: Commit changes in the memory window to extended storage.
130 COMMIT: lda curpage ; Get the current page
131 bmi done ; Jump if no page mapped
144 ; Transfer one page. Y must be zero on entry
147 ldx $01 ; Remember c64 control port
149 and #$F8 ; Bank out ROMs, I/O
153 ; Unroll the following loop
163 ; Restore the old memory configuration, allow interrupts
165 stx $01 ; Restore the old configuration
172 ; ------------------------------------------------------------------------
173 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
174 ; describing the request is passed in a/x.
175 ; The function must not return anything.
180 stx ptr3+1 ; Save the passed em_copy pointer
198 common: ldy #EM_COPY::COUNT+1
199 lda (ptr3),y ; Get number of pages
200 beq @L2 ; Skip if no full pages
203 ; Copy full pages allowing interrupts after each page copied
212 ; Copy the remainder of the page
214 @L2: ldy #EM_COPY::COUNT
215 lda (ptr3),y ; Get bytes in last page
219 lda $01 ; Remember c64 control port
221 and #$F8 ; Bank out ROMs, I/O
225 ; Transfer the bytes in the last page
234 ; Restore the old memory configuration, allow interrupts
237 sta $01 ; Restore the old configuration
244 ; ------------------------------------------------------------------------
245 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
246 ; describing the request is passed in a/x.
247 ; The function must not return anything.
251 stx ptr3+1 ; Save the passed em_copy pointer