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"
15 ; ------------------------------------------------------------------------
16 ; Header. Includes jump table
22 .byte $65, $6d, $64 ; "emd"
23 .byte EMD_API_VERSION ; EM API version number
40 ; ------------------------------------------------------------------------
43 IP_WINDOW = $DF00 ; Address of ISEPIC window
47 ; ------------------------------------------------------------------------
52 ; ------------------------------------------------------------------------
53 ; INSTALL routine. Is called after the driver is loaded into memory. If
54 ; possible, check if the hardware is present and determine the amount of
56 ; Must return an EM_ERR_xx code in a/x.
78 lda #<EM_ERR_NO_DEVICE
79 ldx #>EM_ERR_NO_DEVICE
85 ; rts ; Run into UNINSTALL instead
87 ; ------------------------------------------------------------------------
88 ; UNINSTALL routine. Is called before the driver is removed from memory.
89 ; Can do cleanup or whatever. Must not return anything.
95 ; ------------------------------------------------------------------------
96 ; PAGECOUNT: Return the total number of available pages in a/x.
104 ; ------------------------------------------------------------------------
105 ; USE: Tell the driver that the window is now associated with a given page.
106 ; The Isepic cartridge does not copy but actually map the window, so USE is
111 ; ------------------------------------------------------------------------
112 ; MAP: Map the page in a/x into memory and return a pointer to the page in
113 ; a/x. The contents of the currently mapped page (if any) may be discarded
123 ; Use the RTS from COMMIT below to save a precious byte of storage
125 ; ------------------------------------------------------------------------
126 ; COMMIT: Commit changes in the memory window to extended storage.
131 ; ------------------------------------------------------------------------
132 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
133 ; describing the request is passed in a/x.
134 ; The function must not return anything.
142 ; - ptr1 contains the struct pointer
143 ; - ptr2 contains the linear memory buffer
144 ; - ptr3 contains -(count-1)
145 ; - tmp1 contains the low page register value
146 ; - X contains the page offset
161 ; Bump count and repeat
173 inc tmp1 ; Bump low page register
181 ; ------------------------------------------------------------------------
182 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
183 ; describing the request is passed in a/x.
184 ; The function must not return anything.
192 ; - ptr1 contains the struct pointer
193 ; - ptr2 contains the linear memory buffer
194 ; - ptr3 contains -(count-1)
195 ; - tmp1 contains the low page register value
196 ; - X contains the page offset
211 ; Bump count and repeat
223 inc tmp1 ; Bump page register
231 ; ------------------------------------------------------------------------
232 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
233 ; structure and prepare data for the copy
237 stx ptr1+1 ; Save passed pointer
239 ; Get the page number from the struct and remember it.
245 ; Get the buffer pointer into ptr2
254 ; Get the count, calculate -(count-1) and store it into ptr3
265 ; Get the page offset into X and clear Y