2 ; Extended memory driver for the GEORAM cartridge
4 ; Ullrich von Bassewitz, 2002-11-29
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 ; ------------------------------------------------------------------------
40 GR_WINDOW = $DE00 ; Address of GEORAM window
41 GR_PAGE_LO = $DFFE ; Page register low
42 GR_PAGE_HI = $DFFF ; Page register high
44 ; ------------------------------------------------------------------------
49 pagecount: .word 2048 ; Currently fixed
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.
65 ; ------------------------------------------------------------------------
66 ; DEINSTALL routine. Is called before the driver is removed from memory.
67 ; Can do cleanup or whatever. Must not return anything.
74 ; ------------------------------------------------------------------------
75 ; PAGECOUNT: Return the total number of available pages in a/x.
83 ; ------------------------------------------------------------------------
84 ; USE: Tell the driver that the window is now associated with a given page.
85 ; The GeoRAM cartridge does not copy but actually map the window, so USE is
90 ; ------------------------------------------------------------------------
91 ; MAP: Map the page in a/x into memory and return a pointer to the page in
92 ; a/x. The contents of the currently mapped page (if any) may be discarded
112 ; Use the RTS from COMMIT below to save a precious byte of storage
114 ; ------------------------------------------------------------------------
115 ; COMMIT: Commit changes in the memory window to extended storage.
119 ; ------------------------------------------------------------------------
120 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
121 ; describing the request is passed in a/x.
122 ; The function must not return anything.
130 ; - ptr1 contains the struct pointer
131 ; - ptr2 contains the linear memory buffer
132 ; - ptr3 contains -(count-1)
133 ; - tmp1 contains the low page register value
134 ; - tmp2 contains the high page register value
135 ; - X contains the page offset
148 ; Bump count and repeat
158 @L4: inc tmp1 ; Bump low page register
159 bit tmp1 ; Check for overflow in bit 6
160 bvc @L6 ; Jump if no overflow
168 ; ------------------------------------------------------------------------
169 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
170 ; describing the request is passed in a/x.
171 ; The function must not return anything.
179 ; - ptr1 contains the struct pointer
180 ; - ptr2 contains the linear memory buffer
181 ; - ptr3 contains -(count-1)
182 ; - tmp1 contains the low page register value
183 ; - tmp2 contains the high page register value
184 ; - X contains the page offset
197 ; Bump count and repeat
207 @L4: inc tmp1 ; Bump low page register
208 bit tmp1 ; Check for overflow in bit 6
209 bvc @L6 ; Jump if no overflow
217 ; ------------------------------------------------------------------------
218 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
219 ; structure and prepare data for the copy
222 stx ptr1+1 ; Save passed pointer
224 ; Get the page number from the struct and adjust it so that it may be used
225 ; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
240 ; Get the buffer pointer into ptr2
249 ; Get the count, calculate -(count-1) and store it into ptr3
260 ; Get the page offset into X and clear Y