2 ; Extended memory driver for the ISEPIC cartridge.
3 ; Marco van den Heuvel, 2010-01-24
6 .include "zeropage.inc"
8 .include "em-kernel.inc"
9 .include "em-error.inc"
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
19 module_header _c64_isepic_emd
23 .byte $65, $6d, $64 ; "emd"
24 .byte EMD_API_VERSION ; EM API version number
41 ; ------------------------------------------------------------------------
44 IP_WINDOW = $DF00 ; Address of ISEPIC window
48 ; ------------------------------------------------------------------------
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.
79 lda #<EM_ERR_NO_DEVICE
80 ldx #>EM_ERR_NO_DEVICE
86 ; rts ; Run into UNINSTALL instead
88 ; ------------------------------------------------------------------------
89 ; UNINSTALL routine. Is called before the driver is removed from memory.
90 ; Can do cleanup or whatever. Must not return anything.
96 ; ------------------------------------------------------------------------
97 ; PAGECOUNT: Return the total number of available pages in a/x.
105 ; ------------------------------------------------------------------------
106 ; USE: Tell the driver that the window is now associated with a given page.
107 ; The Isepic cartridge does not copy but actually map the window, so USE is
112 ; ------------------------------------------------------------------------
113 ; MAP: Map the page in a/x into memory and return a pointer to the page in
114 ; a/x. The contents of the currently mapped page (if any) may be discarded
124 ; Use the RTS from COMMIT below to save a precious byte of storage
126 ; ------------------------------------------------------------------------
127 ; COMMIT: Commit changes in the memory window to extended storage.
132 ; ------------------------------------------------------------------------
133 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
134 ; describing the request is passed in a/x.
135 ; The function must not return anything.
143 ; - ptr1 contains the struct pointer
144 ; - ptr2 contains the linear memory buffer
145 ; - ptr3 contains -(count-1)
146 ; - tmp1 contains the low page register value
147 ; - X contains the page offset
162 ; Bump count and repeat
174 inc tmp1 ; Bump low page register
182 ; ------------------------------------------------------------------------
183 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
184 ; describing the request is passed in a/x.
185 ; The function must not return anything.
193 ; - ptr1 contains the struct pointer
194 ; - ptr2 contains the linear memory buffer
195 ; - ptr3 contains -(count-1)
196 ; - tmp1 contains the low page register value
197 ; - X contains the page offset
212 ; Bump count and repeat
224 inc tmp1 ; Bump page register
232 ; ------------------------------------------------------------------------
233 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
234 ; structure and prepare data for the copy
238 stx ptr1+1 ; Save passed pointer
240 ; Get the page number from the struct and remember it.
246 ; Get the buffer pointer into ptr2
255 ; Get the count, calculate -(count-1) and store it into ptr3
266 ; Get the page offset into X and clear Y