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
37 ; ------------------------------------------------------------------------
40 REU_STATUS = $DF00 ; Status register
41 REU_COMMAND = $DF01 ; Command register
42 REU_C64ADDR = $DF02 ; C64 base address register
43 REU_REUADDR = $DF04 ; REU base address register
44 REU_COUNT = $DF07 ; Transfer count register
45 REU_IRQMASK = $DF09 ; IRQ mask register
46 REU_CONTROL = $DF0A ; Control register
47 REU_TRIGGER = $FF00 ; REU command trigger
53 ; ------------------------------------------------------------------------
57 pagecount: .res 2 ; Number of pages available
58 curpage: .word $FFFF ; Current page number (invalid)
61 window: .res 256 ; Memory "window"
63 reu_params: .word $0000 ; Host address, lo, hi
64 .word $0000 ; Exp address, lo, hi
65 .byte $00 ; Expansion bank no.
66 .word $0000 ; # bytes to move, lo, hi
67 .byte $00 ; Interrupt mask reg.
68 .byte $00 ; Adress control reg.
72 ; ------------------------------------------------------------------------
73 ; INSTALL routine. Is called after the driver is loaded into memory. If
74 ; possible, check if the hardware is present and determine the amount of
76 ; Must return an EM_ERR_xx code in a/x.
82 cmp REU_REUADDR ; Check for presence of REU
86 cmp REU_REUADDR ; Check for presence of REU
89 ldx #>(128*4) ; Assume 128KB
91 and #$10 ; Check size bit
93 ldx #>(256*4) ; 256KB when size bit is set
103 lda #<EM_ERR_NO_DEVICE
104 ldx #>EM_ERR_NO_DEVICE
107 ; ------------------------------------------------------------------------
108 ; DEINSTALL routine. Is called before the driver is removed from memory.
109 ; Can do cleanup or whatever. Must not return anything.
116 ; ------------------------------------------------------------------------
117 ; PAGECOUNT: Return the total number of available pages in a/x.
125 ; ------------------------------------------------------------------------
126 ; MAP: Map the page in a/x into memory and return a pointer to the page in
127 ; a/x. The contents of the currently mapped page (if any) may be discarded
132 stx curpage+1 ; Remember the new page
135 jsr common ; Copy the window
138 ldx #>window ; Return the window address
141 ; ------------------------------------------------------------------------
142 ; USE: Tell the driver that the window is now associated with a given page.
145 stx curpage+1 ; Remember the page
147 ldx #>window ; Return the window
150 ; ------------------------------------------------------------------------
151 ; COMMIT: Commit changes in the memory window to extended storage.
154 ldx curpage+1 ; Do we have a page mapped?
155 bmi done ; Jump if no page mapped
172 sty REU_COUNT+1 ; Move 256 bytes
173 bne transfer1 ; Transfer 256 bytes into REU
175 ; ------------------------------------------------------------------------
176 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
177 ; describing the request is passed in a/x.
178 ; The function must not return anything.
185 ; ------------------------------------------------------------------------
186 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
187 ; describing the request is passed in a/x.
188 ; The function must not return anything.
195 ; Remember the passed pointer
198 stx ptr1+1 ; Save the pointer
200 ; The structure passed to the functions has the same layout as the registers
201 ; of the Commodore REU, so register programming is easy.
209 ; Invalidate the page in the memory window
211 sty curpage+1 ; Y = $FF
213 ; Reload the REU command and start the transfer
218 ; Transfer subroutine for the REU. Expects command in Y.
221 sty REU_COMMAND ; Issue command
223 ldy $01 ; Save the value of the c64 control port...
225 and #$F8 ; Disable ROMs and I/O.
228 lda REU_TRIGGER ; Don't change $FF00
229 sta REU_TRIGGER ; Start the transfer...
231 sty $01 ; Restore the old configuration