2 ; Extended memory driver for the Apple II language card
4 ; Stefan Haubenthal, 2003-12-13
5 ; Ullrich von Bassewitz, 2002-12-02,2003-12-21
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
38 ; ------------------------------------------------------------------------
41 BASE = $D000 ; $Cxxx -> $Dxxx bank 1
43 PAGES = ($10000 - BASE) / 256
48 ; ------------------------------------------------------------------------
52 curpage: .res 1 ; Current page number
55 window: .res 256 ; Memory "window"
59 ; ------------------------------------------------------------------------
60 ; INSTALL routine. Is called after the driver is loaded into memory. If
61 ; possible, check if the hardware is present and determine the amount of
63 ; Must return an EM_ERR_xx code in a/x.
68 sta curpage ; Invalidate the current page
71 ; rts ; Run into UNINSTALL instead
73 ; ------------------------------------------------------------------------
74 ; UNINSTALL routine. Is called before the driver is removed from memory.
75 ; Can do cleanup or whatever. Must not return anything.
82 ; ------------------------------------------------------------------------
83 ; PAGECOUNT: Return the total number of available pages in a/x.
91 ; ------------------------------------------------------------------------
92 ; MAP: Map the page in a/x into memory and return a pointer to the page in
93 ; a/x. The contents of the currently mapped page (if any) may be discarded
97 MAP: sta curpage ; Remember the new page
111 jsr transfer ; Transfer one page
113 ; Return the memory window
116 ldx #>window ; Return the window address
119 ; ------------------------------------------------------------------------
120 ; USE: Tell the driver that the window is now associated with a given page.
122 USE: sta curpage ; Remember the page
124 ldx #>window ; Return the window
127 ; ------------------------------------------------------------------------
128 ; COMMIT: Commit changes in the memory window to extended storage.
130 COMMIT: lda curpage ; Get the current page
131 bmi done ; Jump if no page mapped
143 ; Transfer one page. Y must be zero on entry
164 lda LC2RW,x ; Bank out ROMs
167 ; Unroll the following loop
177 ; Restore the old memory configuration, allow interrupts
179 lda ROMONLY2 ; Bank in ROMs
186 ; ------------------------------------------------------------------------
187 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
188 ; describing the request is passed in a/x.
189 ; The function must not return anything.
194 stx ptr3+1 ; Save the passed em_copy pointer
211 common: ldy #EM_COPY::COUNT+1
212 lda (ptr3),y ; Get number of pages
213 beq @L2 ; Skip if no full pages
216 ; Copy full pages allowing interrupts after each page copied
225 ; Copy the remainder of the page
227 @L2: ldy #EM_COPY::COUNT
228 lda (ptr3),y ; Get bytes in last page
233 lda LC2RW,x ; Bank out ROMs
238 ; Transfer the bytes in the last page
247 ; Restore the old memory configuration, allow interrupts
249 lda ROMONLY2 ; Bank in ROMs
256 ; ------------------------------------------------------------------------
257 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
258 ; describing the request is passed in a/x.
259 ; The function must not return anything.
263 stx ptr3+1 ; Save the passed em_copy pointer