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
37 ; ------------------------------------------------------------------------
41 PAGES = ($10000 - BASE) / 256
43 ; ------------------------------------------------------------------------
47 curpage: .byte $FF ; Current page number (invalid)
50 window: .res 256 ; Memory "window"
54 ; ------------------------------------------------------------------------
55 ; INSTALL routine. Is called after the driver is loaded into memory. If
56 ; possible, check if the hardware is present and determine the amount of
58 ; Must return an EM_ERR_xx code in a/x.
66 ; ------------------------------------------------------------------------
67 ; DEINSTALL routine. Is called before the driver is removed from memory.
68 ; Can do cleanup or whatever. Must not return anything.
75 ; ------------------------------------------------------------------------
76 ; PAGECOUNT: Return the total number of available pages in a/x.
84 ; ------------------------------------------------------------------------
85 ; MAP: Map the page in a/x into memory and return a pointer to the page in
86 ; a/x. The contents of the currently mapped page (if any) may be discarded
90 MAP: sta curpage ; Remember the new page
105 jsr transfer ; Transfer one page
107 ; Return the memory window
110 ldx #>window ; Return the window address
113 ; ------------------------------------------------------------------------
114 ; USE: Tell the driver that the window is now associated with a given page.
116 USE: sta curpage ; Remember the page
118 ldx #>window ; Return the window
121 ; ------------------------------------------------------------------------
122 ; COMMIT: Commit changes in the memory window to extended storage.
124 COMMIT: lda curpage ; Get the current page
125 bmi done ; Jump if no page mapped
138 ; Transfer one page. Y must be zero on entry
141 ldx $01 ; Remember c64 control port
143 and #$F8 ; Bank out ROMs, I/O
147 ; Unroll the following loop
183 ; Restore the old memory configuration, allow interrupts
185 stx $01 ; Restore the old configuration
192 ; ------------------------------------------------------------------------
193 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
194 ; describing the request is passed in a/x.
195 ; The function must not return anything.
200 stx ptr3+1 ; Save the passed em_copy pointer
218 common: ldy #EM_COPY_COUNT+1
219 lda (ptr3),y ; Get number of pages
220 beq @L2 ; Skip if no full pages
223 ; Copy full pages allowing interrupts after each page copied
232 ; Copy the remainder of the page
234 @L2: ldy #EM_COPY_COUNT
235 lda (ptr3),y ; Get bytes in last page
239 lda $01 ; Remember c64 control port
241 and #$F8 ; Bank out ROMs, I/O
245 ; Transfer the bytes in the last page
254 ; Restore the old memory configuration, allow interrupts
257 sta $01 ; Restore the old configuration
264 ; ------------------------------------------------------------------------
265 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
266 ; describing the request is passed in a/x.
267 ; The function must not return anything.
271 stx ptr3+1 ; Save the passed em_copy pointer