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 $00 ; 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
184 ; Restore the old memory configuration, allow interrupts
186 stx $01 ; Restore the old configuration
193 ; ------------------------------------------------------------------------
194 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
195 ; describing the request is passed in a/x.
196 ; The function must not return anything.
201 stx ptr3+1 ; Save the passed em_copy pointer
219 common: ldy #EM_COPY_COUNT+1
220 lda (ptr3),y ; Get number of pages
221 beq @L2 ; Skip if no full pages
224 ; Copy full pages allowing interrupts after each page copied
233 ; Copy the remainder of the page
235 @L2: ldy #EM_COPY_COUNT
236 lda (ptr3),y ; Get bytes in last page
240 lda $01 ; Remember c64 control port
242 and #$F8 ; Bank out ROMs, I/O
246 ; Transfer the bytes in the last page
255 ; Restore the old memory configuration, allow interrupts
258 sta $01 ; Restore the old configuration
265 ; ------------------------------------------------------------------------
266 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
267 ; describing the request is passed in a/x.
268 ; The function must not return anything.
272 stx ptr3+1 ; Save the passed em_copy pointer