2 ; Extended memory driver for the C64 D2TV (the second or PAL version).
3 ; Driver works without problems when statically linked.
5 ; Ullrich von Bassewitz, 2005-11-27
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 OP_COPYFROM = %00001101
44 PAGES = (2048 - 128) * 4
47 ; ------------------------------------------------------------------------
51 window: .res 256 ; Memory "window"
55 ; The MAP and COMMIT entries will actually call COPYFROM/COPYTO with
56 ; a pointer to the following data structure:
58 dma_params: .word window ; Host address
59 .byte 0 ; Offset in page
60 curpage: .word $0000 ; Page
61 .word .sizeof (window); # bytes to move, lo, hi
65 ; ------------------------------------------------------------------------
66 ; INSTALL routine. Is called after the driver is loaded into memory. If
67 ; possible, check if the hardware is present and determine the amount of
69 ; Must return an EM_ERR_xx code in a/x.
74 stx curpage+1 ; Invalidate curpage
79 ; ------------------------------------------------------------------------
80 ; UNINSTALL routine. Is called before the driver is removed from memory.
81 ; Can do cleanup or whatever. Must not return anything.
88 ; ------------------------------------------------------------------------
89 ; PAGECOUNT: Return the total number of available pages in a/x.
97 ; ------------------------------------------------------------------------
98 ; MAP: Map the page in a/x into memory and return a pointer to the page in
99 ; a/x. The contents of the currently mapped page (if any) may be discarded
104 stx curpage+1 ; Remember the new page
108 jsr COPYFROM ; Copy data into the window
111 ldx #>window ; Return the window address
114 ; ------------------------------------------------------------------------
115 ; USE: Tell the driver that the window is now associated with a given page.
118 stx curpage+1 ; Remember the page
120 ldx #>window ; Return the window
123 ; ------------------------------------------------------------------------
124 ; COMMIT: Commit changes in the memory window to extended storage.
126 COMMIT: lda curpage+1 ; Do we have a page mapped?
127 bmi done ; Jump if no page mapped
134 ; ------------------------------------------------------------------------
135 ; COPYTO: Copy from linear into extended memory. A pointer to a structure
136 ; describing the request is passed in a/x.
137 ; The function must not return anything.
141 stx ptr1+1 ; Save the pointer
143 ldx #OP_COPYTO ; Load the command
146 ; ------------------------------------------------------------------------
147 ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
148 ; describing the request is passed in a/x.
149 ; The function must not return anything.
154 stx ptr1+1 ; Save the pointer
158 ; DTV DMA transfer routine. Expects the command in X.
161 lda #$01 ; Enable extended features
164 ; Wait until the current DMA operation is finished
168 ; Setup the source address. Carry is clear.
178 adc #$42 ; Always RAM, start at $20000
181 ; Setup the target address
189 lda #$40 ; Always RAM, start at $00000
192 ; Source and target steps
218 ; Wait until DMA finished
222 ; Disable access to the extended registers
230 ; ------------------------------------------------------------------------
231 ; Wait until DMA has finished