2 ; Extended memory driver for the Commodore REU. Driver works without
3 ; problems when statically linked.
5 ; Ullrich von Bassewitz, 2002-11-29
8 .include "zeropage.inc"
10 .include "em-kernel.inc"
11 .include "em-error.inc"
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
21 module_header _c64_reu_emd
25 .byte $65, $6d, $64 ; "emd"
26 .byte EMD_API_VERSION ; EM API version number
43 ; ------------------------------------------------------------------------
46 REU_STATUS = $DF00 ; Status register
47 REU_COMMAND = $DF01 ; Command register
48 REU_C64ADDR = $DF02 ; C64 base address register
49 REU_REUADDR = $DF04 ; REU base address register
50 REU_COUNT = $DF07 ; Transfer count register
51 REU_IRQMASK = $DF09 ; IRQ mask register
52 REU_CONTROL = $DF0A ; Control register
53 REU_TRIGGER = $FF00 ; REU command trigger
58 OP_COPYFROM_ALOAD = $B1
62 ; ------------------------------------------------------------------------
66 pagecount: .res 2 ; Number of pages available
67 curpage: .res 2 ; Current page number
69 window: .res 256 ; Memory "window"
71 reu_params: .word $0000 ; Host address, lo, hi
72 .word $0000 ; Exp address, lo, hi
73 .byte $00 ; Expansion bank no.
74 .word $0000 ; # bytes to move, lo, hi
75 .byte $00 ; Interrupt mask reg.
76 .byte $00 ; Adress control reg.
80 ; ------------------------------------------------------------------------
81 ; INSTALL routine. Is called after the driver is loaded into memory. If
82 ; possible, check if the hardware is present and determine the amount of
84 ; Must return an EM_ERR_xx code in a/x.
88 ldx #$00 ; High byte of return code
91 cmp REU_REUADDR ; Check for presence of REU
95 cmp REU_REUADDR ; Check for presence of REU
104 jsr reu_size_check_common
112 jsr reu_size_check_common
113 ldx #OP_COPYFROM_ALOAD
122 cpy #$00 ; too many pages, shave off 2
134 ; common REU setup for size check
135 reu_size_check_common:
154 lda #EM_ERR_NO_DEVICE
155 ; rts ; Run into UNINSTALL instead
157 ; ------------------------------------------------------------------------
158 ; UNINSTALL routine. Is called before the driver is removed from memory.
159 ; Can do cleanup or whatever. Must not return anything.
166 ; ------------------------------------------------------------------------
167 ; PAGECOUNT: Return the total number of available pages in a/x.
175 ; ------------------------------------------------------------------------
176 ; MAP: Map the page in a/x into memory and return a pointer to the page in
177 ; a/x. The contents of the currently mapped page (if any) may be discarded
182 stx curpage+1 ; Remember the new page
185 jsr common ; Copy the window
188 ldx #>window ; Return the window address
191 ; ------------------------------------------------------------------------
192 ; USE: Tell the driver that the window is now associated with a given page.
195 stx curpage+1 ; Remember the page
197 ldx #>window ; Return the window
200 ; ------------------------------------------------------------------------
201 ; COMMIT: Commit changes in the memory window to extended storage.
204 ldx curpage+1 ; Do we have a page mapped?
205 bmi done ; Jump if no page mapped
222 sty REU_COUNT+1 ; Move 256 bytes
223 bne transfer1 ; Transfer 256 bytes into REU
225 ; ------------------------------------------------------------------------
226 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
227 ; describing the request is passed in a/x.
228 ; The function must not return anything.
235 ; ------------------------------------------------------------------------
236 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
237 ; describing the request is passed in a/x.
238 ; The function must not return anything.
245 ; Remember the passed pointer
248 stx ptr1+1 ; Save the pointer
250 ; The structure passed to the functions has the same layout as the registers
251 ; of the Commodore REU, so register programming is easy.
259 ; Invalidate the page in the memory window
261 sty curpage+1 ; Y = $FF
263 ; Reload the REU command and start the transfer
268 ; Transfer subroutine for the REU. Expects command in Y.
271 sty REU_COMMAND ; Issue command
273 ldy $01 ; Save the value of the c64 control port...
275 and #$F8 ; Disable ROMs and I/O.
278 lda REU_TRIGGER ; Don't change $FF00
279 sta REU_TRIGGER ; Start the transfer...
281 sty $01 ; Restore the old configuration