2 ; Extended memory driver for the GEORAM cartridge through the masC=erade
3 ; c64 cartridge adapter. Driver works without problems when statically
6 ; Marco van den Heuvel, 2018-03-18
9 .include "zeropage.inc"
11 .include "em-kernel.inc"
12 .include "em-error.inc"
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
22 module_header _vic20_georam_emd
26 .byte $65, $6d, $64 ; "emd"
27 .byte EMD_API_VERSION ; EM API version number
44 ; ------------------------------------------------------------------------
47 GR_WINDOW = $9800 ; Address of GEORAM window
48 GR_PAGE_LO = $9CFE ; Page register low
49 GR_PAGE_HI = $9CFF ; Page register high
51 ; ------------------------------------------------------------------------
56 pagecount: .res 2 ; Number of available pages
60 ; ------------------------------------------------------------------------
61 ; INSTALL routine. Is called after the driver is loaded into memory. If
62 ; possible, check if the hardware is present and determine the amount of
64 ; Must return an EM_ERR_xx code in a/x.
122 lda #<EM_ERR_NO_DEVICE
123 ldx #>EM_ERR_NO_DEVICE
144 ; rts ; Run into UNINSTALL instead
146 ; ------------------------------------------------------------------------
147 ; UNINSTALL routine. Is called before the driver is removed from memory.
148 ; Can do cleanup or whatever. Must not return anything.
155 ; ------------------------------------------------------------------------
156 ; PAGECOUNT: Return the total number of available pages in a/x.
164 ; ------------------------------------------------------------------------
165 ; USE: Tell the driver that the window is now associated with a given page.
166 ; The GeoRAM cartridge does not copy but actually map the window, so USE is
171 ; ------------------------------------------------------------------------
172 ; MAP: Map the page in a/x into memory and return a pointer to the page in
173 ; a/x. The contents of the currently mapped page (if any) may be discarded
193 ; Use the RTS from COMMIT below to save a precious byte of storage
195 ; ------------------------------------------------------------------------
196 ; COMMIT: Commit changes in the memory window to extended storage.
200 ; ------------------------------------------------------------------------
201 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
202 ; describing the request is passed in a/x.
203 ; The function must not return anything.
211 ; - ptr1 contains the struct pointer
212 ; - ptr2 contains the linear memory buffer
213 ; - ptr3 contains -(count-1)
214 ; - tmp1 contains the low page register value
215 ; - tmp2 contains the high page register value
216 ; - X contains the page offset
229 ; Bump count and repeat
239 @L4: inc tmp1 ; Bump low page register
240 bit tmp1 ; Check for overflow in bit 6
241 bvc @L6 ; Jump if no overflow
249 ; ------------------------------------------------------------------------
250 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
251 ; describing the request is passed in a/x.
252 ; The function must not return anything.
260 ; - ptr1 contains the struct pointer
261 ; - ptr2 contains the linear memory buffer
262 ; - ptr3 contains -(count-1)
263 ; - tmp1 contains the low page register value
264 ; - tmp2 contains the high page register value
265 ; - X contains the page offset
278 ; Bump count and repeat
288 @L4: inc tmp1 ; Bump low page register
289 bit tmp1 ; Check for overflow in bit 6
290 bvc @L6 ; Jump if no overflow
298 ; ------------------------------------------------------------------------
299 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
300 ; structure and prepare data for the copy
303 stx ptr1+1 ; Save passed pointer
305 ; Get the page number from the struct and adjust it so that it may be used
306 ; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
321 ; Get the buffer pointer into ptr2
330 ; Get the count, calculate -(count-1) and store it into ptr3
341 ; Get the page offset into X and clear Y