2 ; Extended memory driver for the RamCart 64/128KB cartridge. Driver works
3 ; without problems when statically linked.
4 ; Code is based on GEORAM code by Ullrich von Bassewitz.
5 ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl>
10 .include "zeropage.inc"
12 .include "em-kernel.inc"
13 .include "em-error.inc"
20 ; ------------------------------------------------------------------------
21 ; Header. Includes jump table
23 module_header _c64_ramcart_emd
27 .byte $65, $6d, $64 ; "emd"
28 .byte EMD_API_VERSION ; EM API version number
45 ; ------------------------------------------------------------------------
48 RAMC_WINDOW = $DF00 ; Address of RamCart window
49 RAMC_PAGE_LO = $DE00 ; Page register low
50 RAMC_PAGE_HI = $DE01 ; Page register high (only for RC128)
52 ; ------------------------------------------------------------------------
57 pagecount: .res 2 ; Number of available pages
61 ; ------------------------------------------------------------------------
62 ; INSTALL routine. Is called after the driver is loaded into memory. If
63 ; possible, check if the hardware is present and determine the amount of
65 ; Must return an EM_ERR_xx code in a/x.
106 lda #<EM_ERR_NO_DEVICE
107 ldx #>EM_ERR_NO_DEVICE
108 ; rts ; Run into UNINSTALL instead
110 ; ------------------------------------------------------------------------
111 ; UNINSTALL routine. Is called before the driver is removed from memory.
112 ; Can do cleanup or whatever. Must not return anything.
119 ; ------------------------------------------------------------------------
120 ; PAGECOUNT: Return the total number of available pages in a/x.
128 ; ------------------------------------------------------------------------
129 ; USE: Tell the driver that the window is now associated with a given page.
130 ; The RamCart cartridge does not copy but actually map the window, so USE is
136 ; ------------------------------------------------------------------------
137 ; MAP: Map the page in a/x into memory and return a pointer to the page in
138 ; a/x. The contents of the currently mapped page (if any) may be discarded
142 MAP: sta RAMC_PAGE_LO
147 ; Use the RTS from COMMIT below to save a precious byte of storage
149 ; ------------------------------------------------------------------------
150 ; COMMIT: Commit changes in the memory window to extended storage.
154 ; ------------------------------------------------------------------------
155 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
156 ; describing the request is passed in a/x.
157 ; The function must not return anything.
165 ; - ptr1 contains the struct pointer
166 ; - ptr2 contains the linear memory buffer
167 ; - ptr3 contains -(count-1)
168 ; - tmp1 contains the low page register value
169 ; - tmp2 contains the high page register value
170 ; - X contains the page offset
175 @L1: lda RAMC_WINDOW,x
183 ; Bump count and repeat
202 ; ------------------------------------------------------------------------
203 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
204 ; describing the request is passed in a/x.
205 ; The function must not return anything.
213 ; - ptr1 contains the struct pointer
214 ; - ptr2 contains the linear memory buffer
215 ; - ptr3 contains -(count-1)
216 ; - tmp1 contains the low page register value
217 ; - tmp2 contains the high page register value
218 ; - X contains the page offset
231 ; Bump count and repeat
250 ; ------------------------------------------------------------------------
251 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
252 ; structure and prepare data for the copy
255 stx ptr1+1 ; Save passed pointer
257 ; Get the page number from the struct and adjust it so that it may be used
258 ; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
267 ; Get the buffer pointer into ptr2
276 ; Get the count, calculate -(count-1) and store it into ptr3
287 ; Get the page offset into X and clear Y