2 ; Extended memory driver for the C16 hidden RAM. Driver works without
3 ; problems when statically linked.
5 ; Ullrich von Bassewitz, 2003-12-15
8 .include "zeropage.inc"
10 .include "em-kernel.inc"
11 .include "em-error.inc"
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
24 .byte $65, $6d, $64 ; "emd"
25 .byte EMD_API_VERSION ; EM API version number
42 ; ------------------------------------------------------------------------
47 ; ------------------------------------------------------------------------
51 pages: .res 1 ; Number of pages
52 curpage: .res 1 ; Current page number
53 window: .res 256 ; Memory "window"
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.
66 ; Determine how much memory is available. We will use all memory above
70 jsr $FF99 ; MEMTOP: Get top memory into Y/X
72 sub #>BASE ; Low 32 K are used
74 beq nomem ; Offering zero pages is a bad idea
78 stx curpage ; Invalidate the current page
80 txa ; A = X = EM_ERR_OK
83 nomem: ldx #>EM_ERR_NO_DEVICE
84 lda #<EM_ERR_NO_DEVICE
85 ; rts ; Run into UNINSTALL instead
87 ; ------------------------------------------------------------------------
88 ; UNINSTALL routine. Is called before the driver is removed from memory.
89 ; Can do cleanup or whatever. Must not return anything.
96 ; ------------------------------------------------------------------------
97 ; PAGECOUNT: Return the total number of available pages in a/x.
102 ldx #$00 ; 128 pages max
105 ; ------------------------------------------------------------------------
106 ; MAP: Map the page in a/x into memory and return a pointer to the page in
107 ; a/x. The contents of the currently mapped page (if any) may be discarded
111 MAP: sta curpage ; Remember the new page
125 jsr transfer ; Transfer one page
127 ; Return the memory window
130 ldx #>window ; Return the window address
133 ; ------------------------------------------------------------------------
134 ; USE: Tell the driver that the window is now associated with a given page.
136 USE: sta curpage ; Remember the page
138 ldx #>window ; Return the window
141 ; ------------------------------------------------------------------------
142 ; COMMIT: Commit changes in the memory window to extended storage.
144 COMMIT: lda curpage ; Get the current page
145 bmi done ; Jump if no page mapped
157 ; Transfer one page. Y must be zero on entry. Because we bank out the
158 ; kernal, we will run the routine with interrupts disabled but leave
159 ; short breath times. Unroll the following loop to make it somewhat faster.
180 ; ------------------------------------------------------------------------
181 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
182 ; describing the request is passed in a/x.
183 ; The function must not return anything.
188 stx ptr3+1 ; Save the passed em_copy pointer
205 common: ldy #EM_COPY::COUNT+1
206 lda (ptr3),y ; Get number of pages
207 beq @L2 ; Skip if no full pages
210 ; Copy full pages allowing interrupts after each page copied
219 ; Copy the remainder of the page
221 @L2: ldy #EM_COPY::COUNT
222 lda (ptr3),y ; Get bytes in last page
227 sta ENABLE_RAM ; Bank out the ROM
229 ; Transfer the bytes in the last page
238 ; Restore the old memory configuration, allow interrupts
247 ; ------------------------------------------------------------------------
248 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
249 ; describing the request is passed in a/x.
250 ; The function must not return anything.
254 stx ptr3+1 ; Save the passed em_copy pointer