2 ; Extended memory driver for the VDC RAM available on all C128 machines
3 ; version for GEOS enters safe I/O config on C64 (transparent on C128)
5 ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl>
8 .include "zeropage.inc"
9 .include "em-kernel.inc"
10 .include "em-error.inc"
14 ; ------------------------------------------------------------------------
15 ; Header. Includes jump table
21 .byte $65, $6d, $64 ; "emd"
22 .byte EMD_API_VERSION ; EM API version number
35 ; ------------------------------------------------------------------------
38 VDC_ADDR_REG = $D600 ; VDC address
39 VDC_DATA_REG = $D601 ; VDC data
41 VDC_DATA_HI = 18 ; used registers
46 ; ------------------------------------------------------------------------
52 .word 64 ; $0000-$3fff as 16k default
54 .word $ffff ; currently mapped-in page (invalid)
58 window: .res 256 ; memory window
62 ; ------------------------------------------------------------------------
63 ; INSTALL routine. Is called after the driver is loaded into memory. If
64 ; possible, check if the hardware is present and determine the amount of
66 ; Must return an EM_ERR_xx code in a/x.
70 ; do test for VDC presence here???
79 ldx #VDC_CSET ; determine size of RAM...
83 jsr vdcputreg ; turn on 64k
85 jsr settestadr1 ; save original value of test byte
89 lda #$55 ; write $55 here
91 jsr test64k ; read it here and there
92 lda #$aa ; write $aa here
94 jsr test64k ; read it here and there
98 jsr vdcputbyte ; restore original value of test byte
100 lda ptr1 ; do bytes match?
109 jsr vdcputreg ; restore 16/64k flag
110 jmp @endok ; and leave default values for 16k
132 jsr vdcputbyte ; write $55
134 jsr vdcgetbyte ; read here
137 jsr vdcgetbyte ; and there
146 ldy #$02 ; test page 2 (here)
149 ldy #$42 ; or page 64+2 (there)
153 ; ------------------------------------------------------------------------
154 ; UNINSTALL routine. Is called before the driver is removed from memory.
155 ; Can do cleanup or whatever. Must not return anything.
159 ;on C128 restore font and clear the screen?
162 ; ------------------------------------------------------------------------
163 ; PAGECOUNT: Return the total number of available pages in a/x.
171 ; ------------------------------------------------------------------------
172 ; MAP: Map the page in a/x into memory and return a pointer to the page in
173 ; a/x. The contents of the currently mapped page (if any) may be discarded
194 ; copy a single page from (ptr1):VDCRAM to (ptr2):RAM
205 jsr vdcsetsrcaddr ; set source address in VDC
209 @L0: bit VDC_ADDR_REG
211 lda VDC_DATA_REG ; get 2 bytes at a time to speed-up
212 sta (ptr2),y ; (in fact up to 8 bytes could be fetched with special VDC config)
223 ; ------------------------------------------------------------------------
224 ; USE: Tell the driver that the window is now associated with a given page.
227 stx curpage+1 ; Remember the page
229 ldx #>window ; Return the window
232 ; ------------------------------------------------------------------------
233 ; COMMIT: Commit changes in the memory window to extended storage.
236 lda curpage ; jump if no page mapped
248 ; fall through to transferout
250 ; copy a single page from (ptr2):RAM to (ptr1):VDCRAM
261 jsr vdcsetsrcaddr ; set source address in VDC
265 @L0: bit VDC_ADDR_REG
267 lda (ptr2),y ; speedup does not work for writing
276 ; ------------------------------------------------------------------------
277 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
278 ; describing the request is passed in a/x.
279 ; The function must not return anything.
284 beq @L2 ; Skip if no full pages
294 ; Copy the remainder of the page
296 @L2: ldy #EM_COPY::COUNT
297 lda (ptr3),y ; Get bytes in last page
301 ; Transfer the bytes in the last page
320 ; ------------------------------------------------------------------------
321 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
322 ; describing the request is passed in a/x.
323 ; The function must not return anything.
328 beq @L2 ; Skip if no full pages
338 ; Copy the remainder of the page
340 @L2: ldy #EM_COPY::COUNT
341 lda (ptr3),y ; Get bytes in last page
345 ; Transfer the bytes in the last page
364 ;-------------------------------------------------------------------------
365 ; Helper functions to handle VDC ram
371 @L0: bit VDC_ADDR_REG
384 @L0: bit VDC_ADDR_REG
393 @L0: bit VDC_ADDR_REG
398 ; ------------------------------------------------------------------------
399 ; Helper function for COPYFROM and COPYTO: Store the pointer to the request
400 ; structure and prepare data for the copy
405 stx ptr3+1 ; Save the passed em_copy pointer
421 ldy #EM_COPY::COUNT+1
422 lda (ptr3),y ; Get number of pages