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"
12 .include "../plus4/plus4.inc"
17 ; ------------------------------------------------------------------------
18 ; Header. Includes jump table
24 .byte $65, $6d, $64 ; "emd"
25 .byte $00 ; EM API version number
38 ; ------------------------------------------------------------------------
43 ; ------------------------------------------------------------------------
47 pages: .res 1 ; Number of pages
48 curpage: .res 1 ; Current page number
49 window: .res 256 ; Memory "window"
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.
62 ; Determine how much memory is available. We will use all memory above
66 jsr $FF99 ; MEMTOP: Get top memory into Y/X
68 sub #>BASE ; Low 32 K are used
70 beq nomem ; Offering zero pages is a bad idea
74 stx curpage ; Invalidate the current page
76 txa ; A = X = EM_ERR_OK
79 nomem: ldx #>EM_ERR_NO_DEVICE
80 lda #<EM_ERR_NO_DEVICE
81 ; rts ; Run into UNINSTALL instead
83 ; ------------------------------------------------------------------------
84 ; UNINSTALL routine. Is called before the driver is removed from memory.
85 ; Can do cleanup or whatever. Must not return anything.
92 ; ------------------------------------------------------------------------
93 ; PAGECOUNT: Return the total number of available pages in a/x.
98 ldx #$00 ; 128 pages max
101 ; ------------------------------------------------------------------------
102 ; MAP: Map the page in a/x into memory and return a pointer to the page in
103 ; a/x. The contents of the currently mapped page (if any) may be discarded
107 MAP: sta curpage ; Remember the new page
121 jsr transfer ; Transfer one page
123 ; Return the memory window
126 ldx #>window ; Return the window address
129 ; ------------------------------------------------------------------------
130 ; USE: Tell the driver that the window is now associated with a given page.
132 USE: sta curpage ; Remember the page
134 ldx #>window ; Return the window
137 ; ------------------------------------------------------------------------
138 ; COMMIT: Commit changes in the memory window to extended storage.
140 COMMIT: lda curpage ; Get the current page
141 bmi done ; Jump if no page mapped
153 ; Transfer one page. Y must be zero on entry. Because we bank out the
154 ; kernal, we will run the routine with interrupts disabled but leave
155 ; short breath times. Unroll the following loop to make it somewhat faster.
176 ; ------------------------------------------------------------------------
177 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
178 ; describing the request is passed in a/x.
179 ; The function must not return anything.
184 stx ptr3+1 ; Save the passed em_copy pointer
201 common: ldy #EM_COPY_COUNT+1
202 lda (ptr3),y ; Get number of pages
203 beq @L2 ; Skip if no full pages
206 ; Copy full pages allowing interrupts after each page copied
215 ; Copy the remainder of the page
217 @L2: ldy #EM_COPY_COUNT
218 lda (ptr3),y ; Get bytes in last page
223 sta ENABLE_RAM ; Bank out the ROM
225 ; Transfer the bytes in the last page
234 ; Restore the old memory configuration, allow interrupts
243 ; ------------------------------------------------------------------------
244 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
245 ; describing the request is passed in a/x.
246 ; The function must not return anything.
250 stx ptr3+1 ; Save the passed em_copy pointer