2 ; Extended memory driver for the GEORAM cartridge. Driver works without
3 ; problems when statically linked.
5 ; Ullrich von Bassewitz, 2002-11-29
7 ; GEORAM page size checking routine by
8 ; Marco van den Heuvel, 2010-01-21
11 .include "zeropage.inc"
13 .include "em-kernel.inc"
14 .include "em-error.inc"
20 ; ------------------------------------------------------------------------
21 ; Header. Includes jump table
27 .byte $65, $6d, $64 ; "emd"
28 .byte EMD_API_VERSION ; EM API version number
41 ; ------------------------------------------------------------------------
44 GR_WINDOW = $DE00 ; Address of GEORAM window
45 GR_PAGE_LO = $DFFE ; Page register low
46 GR_PAGE_HI = $DFFF ; Page register high
48 ; ------------------------------------------------------------------------
53 pagecount: .res 2 ; Number of available pages
57 ; ------------------------------------------------------------------------
58 ; INSTALL routine. Is called after the driver is loaded into memory. If
59 ; possible, check if the hardware is present and determine the amount of
61 ; Must return an EM_ERR_xx code in a/x.
119 lda #<EM_ERR_NO_DEVICE
120 ldx #>EM_ERR_NO_DEVICE
141 ; rts ; Run into UNINSTALL instead
143 ; ------------------------------------------------------------------------
144 ; UNINSTALL routine. Is called before the driver is removed from memory.
145 ; Can do cleanup or whatever. Must not return anything.
152 ; ------------------------------------------------------------------------
153 ; PAGECOUNT: Return the total number of available pages in a/x.
161 ; ------------------------------------------------------------------------
162 ; USE: Tell the driver that the window is now associated with a given page.
163 ; The GeoRAM cartridge does not copy but actually map the window, so USE is
168 ; ------------------------------------------------------------------------
169 ; MAP: Map the page in a/x into memory and return a pointer to the page in
170 ; a/x. The contents of the currently mapped page (if any) may be discarded
190 ; Use the RTS from COMMIT below to save a precious byte of storage
192 ; ------------------------------------------------------------------------
193 ; COMMIT: Commit changes in the memory window to extended storage.
197 ; ------------------------------------------------------------------------
198 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
199 ; describing the request is passed in a/x.
200 ; The function must not return anything.
208 ; - ptr1 contains the struct pointer
209 ; - ptr2 contains the linear memory buffer
210 ; - ptr3 contains -(count-1)
211 ; - tmp1 contains the low page register value
212 ; - tmp2 contains the high page register value
213 ; - X contains the page offset
226 ; Bump count and repeat
236 @L4: inc tmp1 ; Bump low page register
237 bit tmp1 ; Check for overflow in bit 6
238 bvc @L6 ; Jump if no overflow
246 ; ------------------------------------------------------------------------
247 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
248 ; describing the request is passed in a/x.
249 ; The function must not return anything.
257 ; - ptr1 contains the struct pointer
258 ; - ptr2 contains the linear memory buffer
259 ; - ptr3 contains -(count-1)
260 ; - tmp1 contains the low page register value
261 ; - tmp2 contains the high page register value
262 ; - X contains the page offset
275 ; Bump count and repeat
285 @L4: inc tmp1 ; Bump low page register
286 bit tmp1 ; Check for overflow in bit 6
287 bvc @L6 ; Jump if no overflow
295 ; ------------------------------------------------------------------------
296 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
297 ; structure and prepare data for the copy
300 stx ptr1+1 ; Save passed pointer
302 ; Get the page number from the struct and adjust it so that it may be used
303 ; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
318 ; Get the buffer pointer into ptr2
327 ; Get the count, calculate -(count-1) and store it into ptr3
338 ; Get the page offset into X and clear Y