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"
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
26 .byte $65, $6d, $64 ; "emd"
27 .byte EMD_API_VERSION ; EM API version number
40 ; ------------------------------------------------------------------------
43 RAMC_WINDOW = $DF00 ; Address of RamCart window
44 RAMC_PAGE_LO = $DE00 ; Page register low
45 RAMC_PAGE_HI = $DE01 ; Page register high (only for RC128)
47 ; ------------------------------------------------------------------------
52 pagecount: .res 2 ; Number of available pages
56 ; ------------------------------------------------------------------------
57 ; INSTALL routine. Is called after the driver is loaded into memory. If
58 ; possible, check if the hardware is present and determine the amount of
60 ; Must return an EM_ERR_xx code in a/x.
101 lda #<EM_ERR_NO_DEVICE
102 ldx #>EM_ERR_NO_DEVICE
103 ; rts ; Run into UNINSTALL instead
105 ; ------------------------------------------------------------------------
106 ; UNINSTALL routine. Is called before the driver is removed from memory.
107 ; Can do cleanup or whatever. Must not return anything.
114 ; ------------------------------------------------------------------------
115 ; PAGECOUNT: Return the total number of available pages in a/x.
123 ; ------------------------------------------------------------------------
124 ; USE: Tell the driver that the window is now associated with a given page.
125 ; The RamCart cartridge does not copy but actually map the window, so USE is
131 ; ------------------------------------------------------------------------
132 ; MAP: Map the page in a/x into memory and return a pointer to the page in
133 ; a/x. The contents of the currently mapped page (if any) may be discarded
137 MAP: sta RAMC_PAGE_LO
142 ; Use the RTS from COMMIT below to save a precious byte of storage
144 ; ------------------------------------------------------------------------
145 ; COMMIT: Commit changes in the memory window to extended storage.
149 ; ------------------------------------------------------------------------
150 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
151 ; describing the request is passed in a/x.
152 ; The function must not return anything.
160 ; - ptr1 contains the struct pointer
161 ; - ptr2 contains the linear memory buffer
162 ; - ptr3 contains -(count-1)
163 ; - tmp1 contains the low page register value
164 ; - tmp2 contains the high page register value
165 ; - X contains the page offset
170 @L1: lda RAMC_WINDOW,x
178 ; Bump count and repeat
197 ; ------------------------------------------------------------------------
198 ; COPYTO: Copy from linear into extended 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
245 ; ------------------------------------------------------------------------
246 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
247 ; structure and prepare data for the copy
250 stx ptr1+1 ; Save passed pointer
252 ; Get the page number from the struct and adjust it so that it may be used
253 ; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
262 ; Get the buffer pointer into ptr2
271 ; Get the count, calculate -(count-1) and store it into ptr3
282 ; Get the page offset into X and clear Y