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
38 ; ------------------------------------------------------------------------
42 PAGES = ($10000 - BASE) / 256
44 ; ------------------------------------------------------------------------
48 curpage: .res 1 ; Current page number
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.
62 stx curpage ; Invalidate the current page
64 txa ; A = X = EM_ERR_OK
65 ; rts ; Run into UNINSTALL instead
67 ; ------------------------------------------------------------------------
68 ; UNINSTALL 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
91 MAP: sta curpage ; Remember the new page
106 jsr transfer ; Transfer one page
108 ; Return the memory window
111 ldx #>window ; Return the window address
114 ; ------------------------------------------------------------------------
115 ; USE: Tell the driver that the window is now associated with a given page.
117 USE: sta curpage ; Remember the page
119 ldx #>window ; Return the window
122 ; ------------------------------------------------------------------------
123 ; COMMIT: Commit changes in the memory window to extended storage.
125 COMMIT: lda curpage ; Get the current page
126 bmi done ; Jump if no page mapped
139 ; Transfer one page. Y must be zero on entry
142 ldx $01 ; Remember c64 control port
144 and #$F8 ; Bank out ROMs, I/O
148 ; Unroll the following loop
158 ; Restore the old memory configuration, allow interrupts
160 stx $01 ; Restore the old configuration
167 ; ------------------------------------------------------------------------
168 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
169 ; describing the request is passed in a/x.
170 ; The function must not return anything.
175 stx ptr3+1 ; Save the passed em_copy pointer
193 common: ldy #EM_COPY::COUNT+1
194 lda (ptr3),y ; Get number of pages
195 beq @L2 ; Skip if no full pages
198 ; Copy full pages allowing interrupts after each page copied
207 ; Copy the remainder of the page
209 @L2: ldy #EM_COPY::COUNT
210 lda (ptr3),y ; Get bytes in last page
214 lda $01 ; Remember c64 control port
216 and #$F8 ; Bank out ROMs, I/O
220 ; Transfer the bytes in the last page
229 ; Restore the old memory configuration, allow interrupts
232 sta $01 ; Restore the old configuration
239 ; ------------------------------------------------------------------------
240 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
241 ; describing the request is passed in a/x.
242 ; The function must not return anything.
246 stx ptr3+1 ; Save the passed em_copy pointer