2 ; Extended memory driver for the Commodore REU
4 ; Ullrich von Bassewitz, 2002-11-29
7 .include "zeropage.inc"
9 .include "em-kernel.inc"
10 .include "em-error.inc"
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
23 .byte $65, $6d, $64 ; "emd"
24 .byte $00 ; EM API version number
36 ; ------------------------------------------------------------------------
39 REU_STATUS = $DF00 ; Status register
40 REU_COMMAND = $DF01 ; Command register
41 REU_C64ADDR = $DF02 ; C64 base address register
42 REU_REUADDR = $DF04 ; REU base address register
43 REU_COUNT = $DF07 ; Transfer count register
44 REU_IRQMASK = $DF09 ; IRQ mask register
45 REU_CONTROL = $DF0A ; Control register
46 REU_TRIGGER = $FF00 ; REU command trigger
52 ; ------------------------------------------------------------------------
56 pagecount: .res 2 ; Number of pages available
57 curpage: .word $FFFF ; Current page number (invalid)
60 window: .res 256 ; Memory "window"
62 reu_params: .word $0000 ; Host address, lo, hi
63 .word $0000 ; Exp address, lo, hi
64 .byte $00 ; Expansion bank no.
65 .word $0000 ; # bytes to move, lo, hi
66 .byte $00 ; Interrupt mask reg.
67 .byte $00 ; Adress control reg.
71 ; ------------------------------------------------------------------------
72 ; INSTALL routine. Is called after the driver is loaded into memory. If
73 ; possible, check if the hardware is present and determine the amount of
75 ; Must return an EM_ERR_xx code in a/x.
81 cmp REU_REUADDR ; Check for presence of REU
85 cmp REU_REUADDR ; Check for presence of REU
88 ldx #>(128*4) ; Assume 128KB
90 and #$10 ; Check size bit
92 ldx #>(256*4) ; 256KB when size bit is set
102 lda #<EM_ERR_NO_DEVICE
103 ldx #>EM_ERR_NO_DEVICE
106 ; ------------------------------------------------------------------------
107 ; DEINSTALL routine. Is called before the driver is removed from memory.
108 ; Can do cleanup or whatever. Must not return anything.
115 ; ------------------------------------------------------------------------
116 ; PAGECOUNT: Return the total number of available pages in a/x.
124 ; ------------------------------------------------------------------------
125 ; MAP: Map the page in a/x into memory and return a pointer to the page in
126 ; a/x. The contents of the currently mapped page (if any) are assumed to be
127 ; dirty and must be saved into secondary storage if this is necessary.
131 stx curpage+1 ; Remember the new page
134 jsr common ; Copy the window
137 ldx #>window ; Return the window address
140 ; ------------------------------------------------------------------------
141 ; COMMIT: Commit changes in the memory window to extended storage.
144 ldx curpage+1 ; Do we have a page mapped?
145 bmi done ; Jump if no page mapped
162 sty REU_COUNT+1 ; Move 256 bytes
163 bne transfer1 ; Transfer 256 bytes into REU
165 ; ------------------------------------------------------------------------
166 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
167 ; describing the request is passed in a/x.
168 ; The function must not return anything.
175 ; ------------------------------------------------------------------------
176 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
177 ; describing the request is passed in a/x.
178 ; The function must not return anything.
185 ; Remember the passed pointer
188 stx ptr1+1 ; Save the pointer
190 ; The structure passed to the functions has the same layout as the registers
191 ; of the Commodore REU, so register programming is easy.
199 ; Invalidate the page in the memory window
201 sty curpage+1 ; Y = $FF
203 ; Reload the REU command and start the transfer
208 ; Transfer subroutine for the REU. Expects command in Y.
211 sty REU_COMMAND ; Issue command
213 ldy $01 ; Save the value of the c64 control port...
215 ora #$03 ; Turn on lower 3 bits to bank out ROMs, I/O.
218 lda REU_TRIGGER ; Don't change $FF00
219 sta REU_TRIGGER ; Start the transfer...
221 sty $01 ; Restore the old configuration