2005-11-27 22:58:44 +00:00
|
|
|
;
|
|
|
|
; Extended memory driver for the C64 D2TV (the second or PAL version).
|
|
|
|
; Driver works without problems when statically linked.
|
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2005-11-27
|
|
|
|
;
|
|
|
|
|
2010-02-04 20:27:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
2005-11-27 22:58:44 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "em-kernel.inc"
|
2005-11-27 22:58:44 +00:00
|
|
|
.include "em-error.inc"
|
2013-05-09 11:56:54 +00:00
|
|
|
.import _get_ostype
|
2005-11-27 22:58:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
.macpack generic
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Header. Includes jump table
|
|
|
|
|
|
|
|
.segment "JUMPTABLE"
|
|
|
|
|
|
|
|
; Driver signature
|
|
|
|
|
|
|
|
.byte $65, $6d, $64 ; "emd"
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte EMD_API_VERSION ; EM API version number
|
2005-11-27 22:58:44 +00:00
|
|
|
|
2013-05-31 22:11:31 +00:00
|
|
|
; Library reference
|
|
|
|
|
|
|
|
.addr $0000
|
|
|
|
|
|
|
|
; Jump table
|
|
|
|
|
|
|
|
.addr INSTALL
|
|
|
|
.addr UNINSTALL
|
|
|
|
.addr PAGECOUNT
|
|
|
|
.addr MAP
|
|
|
|
.addr USE
|
|
|
|
.addr COMMIT
|
|
|
|
.addr COPYFROM
|
|
|
|
.addr COPYTO
|
2005-11-27 22:58:44 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Constants
|
|
|
|
|
|
|
|
OP_COPYFROM = %00001101
|
|
|
|
OP_COPYTO = %00001111
|
|
|
|
|
2005-11-29 17:21:52 +00:00
|
|
|
START_BANK = 2 ; Start at $20000
|
2005-11-27 22:58:44 +00:00
|
|
|
PAGES = (2048 - 128) * 4
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data.
|
|
|
|
|
|
|
|
.bss
|
|
|
|
window: .res 256 ; Memory "window"
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
; The MAP and COMMIT entries will actually call COPYFROM/COPYTO with
|
|
|
|
; a pointer to the following data structure:
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
dma_params: .word window ; Host address
|
2005-11-27 22:58:44 +00:00
|
|
|
.byte 0 ; Offset in page
|
2013-05-09 11:56:54 +00:00
|
|
|
curpage: .word $0000 ; Page
|
|
|
|
.word .sizeof (window); # bytes to move, lo, hi
|
2005-11-27 22:58:44 +00:00
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; INSTALL routine. Is called after the driver is loaded into memory. If
|
|
|
|
; possible, check if the hardware is present and determine the amount of
|
|
|
|
; memory available.
|
|
|
|
; Must return an EM_ERR_xx code in a/x.
|
|
|
|
;
|
|
|
|
|
|
|
|
INSTALL:
|
2010-02-04 20:27:48 +00:00
|
|
|
|
|
|
|
; Check for a DTV
|
|
|
|
|
|
|
|
ldx #1
|
|
|
|
stx $d03f
|
|
|
|
ldx $d040
|
|
|
|
cpx $d000
|
|
|
|
bne @present
|
|
|
|
inc $d000
|
|
|
|
cpx $d040
|
|
|
|
beq @present
|
|
|
|
dec $d000
|
|
|
|
|
|
|
|
; DTV not found
|
|
|
|
|
|
|
|
lda #<EM_ERR_NO_DEVICE
|
|
|
|
ldx #>EM_ERR_NO_DEVICE
|
|
|
|
rts
|
|
|
|
|
|
|
|
@present:
|
2005-11-27 22:58:44 +00:00
|
|
|
ldx #$FF
|
|
|
|
stx curpage+1 ; Invalidate curpage
|
|
|
|
inx ; X = 0
|
|
|
|
txa ; A/X = EM_ERR_OK
|
2005-11-29 17:21:52 +00:00
|
|
|
|
|
|
|
; rts ; Run into UNINSTALL instead
|
2005-11-27 22:58:44 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; UNINSTALL routine. Is called before the driver is removed from memory.
|
|
|
|
; Can do cleanup or whatever. Must not return anything.
|
|
|
|
;
|
|
|
|
|
|
|
|
UNINSTALL:
|
|
|
|
rts
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; PAGECOUNT: Return the total number of available pages in a/x.
|
|
|
|
;
|
|
|
|
|
|
|
|
PAGECOUNT:
|
|
|
|
lda #<PAGES
|
|
|
|
ldx #>PAGES
|
|
|
|
rts
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; MAP: Map the page in a/x into memory and return a pointer to the page in
|
|
|
|
; a/x. The contents of the currently mapped page (if any) may be discarded
|
|
|
|
; by the driver.
|
|
|
|
;
|
|
|
|
|
|
|
|
MAP: sta curpage
|
|
|
|
stx curpage+1 ; Remember the new page
|
|
|
|
|
|
|
|
lda #<dma_params
|
|
|
|
ldx #>dma_params
|
|
|
|
jsr COPYFROM ; Copy data into the window
|
|
|
|
|
|
|
|
lda #<window
|
|
|
|
ldx #>window ; Return the window address
|
|
|
|
done: rts
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; USE: Tell the driver that the window is now associated with a given page.
|
|
|
|
|
|
|
|
USE: sta curpage
|
|
|
|
stx curpage+1 ; Remember the page
|
|
|
|
lda #<window
|
|
|
|
ldx #>window ; Return the window
|
|
|
|
rts
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; COMMIT: Commit changes in the memory window to extended storage.
|
|
|
|
|
|
|
|
COMMIT: lda curpage+1 ; Do we have a page mapped?
|
|
|
|
bmi done ; Jump if no page mapped
|
|
|
|
|
|
|
|
lda #<dma_params
|
|
|
|
ldx #>dma_params
|
|
|
|
|
|
|
|
; Run into COPYTO
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; COPYTO: Copy from linear into extended memory. A pointer to a structure
|
|
|
|
; describing the request is passed in a/x.
|
|
|
|
; The function must not return anything.
|
|
|
|
;
|
|
|
|
|
|
|
|
COPYTO: sta ptr1
|
|
|
|
stx ptr1+1 ; Save the pointer
|
|
|
|
|
|
|
|
ldx #OP_COPYTO ; Load the command
|
|
|
|
bne transfer
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; COPYFROM: Copy from extended into linear memory. A pointer to a structure
|
|
|
|
; describing the request is passed in a/x.
|
|
|
|
; The function must not return anything.
|
|
|
|
;
|
|
|
|
|
|
|
|
COPYFROM:
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1 ; Save the pointer
|
|
|
|
|
|
|
|
ldx #OP_COPYFROM
|
|
|
|
|
|
|
|
; DTV DMA transfer routine. Expects the command in X.
|
2005-11-29 17:21:52 +00:00
|
|
|
; NOTE: We're using knowledge about field order in the EM_COPY struct here!
|
2005-11-27 22:58:44 +00:00
|
|
|
|
|
|
|
transfer:
|
2005-11-29 17:21:52 +00:00
|
|
|
jsr WAIT ; Wait until DMA is finished
|
2005-11-27 22:58:44 +00:00
|
|
|
|
2005-11-29 17:21:52 +00:00
|
|
|
; Modulo disable
|
2005-11-27 22:58:44 +00:00
|
|
|
|
2005-11-29 17:21:52 +00:00
|
|
|
ldy #$00
|
|
|
|
sty $d31e
|
2005-11-27 22:58:44 +00:00
|
|
|
|
2005-11-29 17:21:52 +00:00
|
|
|
; Setup the target address and the source and target steps. Y contains zero,
|
|
|
|
; which is EM_COPY::BUF.
|
2005-11-27 22:58:44 +00:00
|
|
|
|
2005-11-29 17:21:52 +00:00
|
|
|
sty $d307 ; Source step high = 0
|
|
|
|
sty $d309 ; Dest step high = 0
|
2005-11-27 22:58:44 +00:00
|
|
|
lda (ptr1),y
|
2005-11-29 17:21:52 +00:00
|
|
|
sta $d303 ; Dest address low
|
|
|
|
iny ; Y = 1
|
|
|
|
sty $d306 ; Source step low = 1
|
|
|
|
sty $d308 ; Dest step low = 1
|
2005-11-27 22:58:44 +00:00
|
|
|
lda (ptr1),y
|
2005-11-29 17:21:52 +00:00
|
|
|
sta $d304
|
|
|
|
lda #$40 ; Dest is always RAM, start at $00000
|
|
|
|
sta $d305
|
2005-11-27 22:58:44 +00:00
|
|
|
|
2005-11-29 17:21:52 +00:00
|
|
|
; Setup the source address. Incrementing Y will make it point to EM_COPY::OFFS.
|
|
|
|
; We will allow page numbers higher than PAGES and map them to ROM. This will
|
|
|
|
; allow reading the ROM by specifying a page starting with PAGES.
|
2005-11-27 22:58:44 +00:00
|
|
|
|
2005-11-29 17:21:52 +00:00
|
|
|
iny ; EM_COPY::OFFS
|
2005-11-27 22:58:44 +00:00
|
|
|
lda (ptr1),y
|
2005-11-29 17:21:52 +00:00
|
|
|
sta $d300
|
|
|
|
iny ; EM_COPY::PAGE
|
|
|
|
lda (ptr1),y
|
|
|
|
sta $d301
|
2005-11-27 22:58:44 +00:00
|
|
|
iny
|
|
|
|
lda (ptr1),y
|
2005-11-29 17:21:52 +00:00
|
|
|
adc #START_BANK ; Carry clear here from WAIT
|
|
|
|
and #$3f
|
|
|
|
cmp #>PAGES+START_BANK ; Valid range?
|
|
|
|
bcs @L1 ; Jump if no
|
|
|
|
ora #$40 ; Address RAM
|
|
|
|
@L1: sta $d302
|
2005-11-27 22:58:44 +00:00
|
|
|
|
|
|
|
; Length
|
|
|
|
|
2005-11-29 17:21:52 +00:00
|
|
|
iny ; EM_COPY::COUNT
|
2005-11-27 22:58:44 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
sta $d30a
|
|
|
|
iny
|
|
|
|
lda (ptr1),y
|
|
|
|
sta $d30b
|
|
|
|
|
|
|
|
; Start DMA
|
|
|
|
|
|
|
|
stx $d31f
|
|
|
|
|
2005-11-29 17:21:52 +00:00
|
|
|
; Wait until DMA is done
|
2005-11-27 22:58:44 +00:00
|
|
|
|
|
|
|
WAIT: lda $d31f
|
|
|
|
lsr a
|
|
|
|
bcs WAIT
|
|
|
|
rts
|
2005-11-29 17:21:52 +00:00
|
|
|
|