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"
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
24 .byte $65, $6d, $64 ; "emd"
25 .byte EMD_API_VERSION ; EM API version number
42 ; ------------------------------------------------------------------------
46 PAGES = ($10000 - BASE) / 256
48 ; ------------------------------------------------------------------------
52 curpage: .res 1 ; Current page number
53 window: .res 256 ; Memory "window"
57 ; ------------------------------------------------------------------------
58 ; INSTALL routine. Is called after the driver is loaded into memory. If
59 ; possible, check if the hardware is present and determine the amount of
61 ; Must return an EM_ERR_xx code in a/x.
66 stx curpage ; Invalidate the current page
68 txa ; A = X = EM_ERR_OK
69 ; rts ; Run into UNINSTALL instead
71 ; ------------------------------------------------------------------------
72 ; UNINSTALL routine. Is called before the driver is removed from memory.
73 ; Can do cleanup or whatever. Must not return anything.
80 ; ------------------------------------------------------------------------
81 ; PAGECOUNT: Return the total number of available pages in a/x.
89 ; ------------------------------------------------------------------------
90 ; MAP: Map the page in a/x into memory and return a pointer to the page in
91 ; a/x. The contents of the currently mapped page (if any) may be discarded
95 MAP: sta curpage ; Remember the new page
110 jsr transfer ; Transfer one page
112 ; Return the memory window
115 ldx #>window ; Return the window address
118 ; ------------------------------------------------------------------------
119 ; USE: Tell the driver that the window is now associated with a given page.
121 USE: sta curpage ; Remember the page
123 ldx #>window ; Return the window
126 ; ------------------------------------------------------------------------
127 ; COMMIT: Commit changes in the memory window to extended storage.
129 COMMIT: lda curpage ; Get the current page
130 bmi done ; Jump if no page mapped
143 ; Transfer one page. Y must be zero on entry
146 ldx $01 ; Remember c64 control port
148 and #$F8 ; Bank out ROMs, I/O
152 ; Unroll the following loop
162 ; Restore the old memory configuration, allow interrupts
164 stx $01 ; Restore the old configuration
171 ; ------------------------------------------------------------------------
172 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
173 ; describing the request is passed in a/x.
174 ; The function must not return anything.
179 stx ptr3+1 ; Save the passed em_copy pointer
197 common: ldy #EM_COPY::COUNT+1
198 lda (ptr3),y ; Get number of pages
199 beq @L2 ; Skip if no full pages
202 ; Copy full pages allowing interrupts after each page copied
211 ; Copy the remainder of the page
213 @L2: ldy #EM_COPY::COUNT
214 lda (ptr3),y ; Get bytes in last page
218 lda $01 ; Remember c64 control port
220 and #$F8 ; Bank out ROMs, I/O
224 ; Transfer the bytes in the last page
233 ; Restore the old memory configuration, allow interrupts
236 sta $01 ; Restore the old configuration
243 ; ------------------------------------------------------------------------
244 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
245 ; describing the request is passed in a/x.
246 ; The function must not return anything.
250 stx ptr3+1 ; Save the passed em_copy pointer