1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-04 13:29:35 +00:00

Optimized the code and allowed access to the ROM by using page numbers

higher than what em_pagecount() returns.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3676 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2005-11-29 17:21:52 +00:00
parent d3ac084997
commit 60bb97e433

View File

@ -41,6 +41,7 @@
OP_COPYFROM = %00001101 OP_COPYFROM = %00001101
OP_COPYTO = %00001111 OP_COPYTO = %00001111
START_BANK = 2 ; Start at $20000
PAGES = (2048 - 128) * 4 PAGES = (2048 - 128) * 4
@ -70,11 +71,14 @@ curpage: .word $0000 ; Page
; ;
INSTALL: INSTALL:
lda #$01
sta $d03f ; Enable extended register access
ldx #$FF ldx #$FF
stx curpage+1 ; Invalidate curpage stx curpage+1 ; Invalidate curpage
inx ; X = 0 inx ; X = 0
txa ; A/X = EM_ERR_OK txa ; A/X = EM_ERR_OK
rts
; rts ; Run into UNINSTALL instead
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory. ; UNINSTALL routine. Is called before the driver is removed from memory.
@ -84,7 +88,6 @@ INSTALL:
UNINSTALL: UNINSTALL:
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; PAGECOUNT: Return the total number of available pages in a/x. ; PAGECOUNT: Return the total number of available pages in a/x.
; ;
@ -156,55 +159,53 @@ COPYFROM:
ldx #OP_COPYFROM ldx #OP_COPYFROM
; DTV DMA transfer routine. Expects the command in X. ; DTV DMA transfer routine. Expects the command in X.
; NOTE: We're using knowledge about field order in the EM_COPY struct here!
transfer: transfer:
lda #$01 ; Enable extended features jsr WAIT ; Wait until DMA is finished
sta $d03f
; Wait until the current DMA operation is finished ; Modulo disable
jsr WAIT ldy #$00
sty $d31e
; Setup the source address. Carry is clear. ; Setup the target address and the source and target steps. Y contains zero,
; which is EM_COPY::BUF.
ldy #EM_COPY::OFFS sty $d307 ; Source step high = 0
sty $d309 ; Dest step high = 0
lda (ptr1),y
sta $d303 ; Dest address low
iny ; Y = 1
sty $d306 ; Source step low = 1
sty $d308 ; Dest step low = 1
lda (ptr1),y
sta $d304
lda #$40 ; Dest is always RAM, start at $00000
sta $d305
; 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.
iny ; EM_COPY::OFFS
lda (ptr1),y lda (ptr1),y
sta $d300 sta $d300
ldy #EM_COPY::PAGE iny ; EM_COPY::PAGE
lda (ptr1),y lda (ptr1),y
sta $d301 sta $d301
iny iny
lda (ptr1),y lda (ptr1),y
adc #$42 ; Always RAM, start at $20000 adc #START_BANK ; Carry clear here from WAIT
sta $d302 and #$3f
cmp #>PAGES+START_BANK ; Valid range?
; Setup the target address bcs @L1 ; Jump if no
ora #$40 ; Address RAM
ldy #EM_COPY::BUF @L1: sta $d302
lda (ptr1),y
sta $d303
iny
lda (ptr1),y
sta $d304
lda #$40 ; Always RAM, start at $00000
sta $d305
; Source and target steps
lda #$01
ldy #$00
sta $d306
sty $d307
sta $d308
sty $d309
; Modulo disable
sty $d31e
; Length ; Length
ldy #EM_COPY::COUNT iny ; EM_COPY::COUNT
lda (ptr1),y lda (ptr1),y
sta $d30a sta $d30a
iny iny
@ -215,22 +216,10 @@ transfer:
stx $d31f stx $d31f
; Wait until DMA finished ; Wait until DMA is done
jsr WAIT
; Disable access to the extended registers
lda #$00
sta $d03f
rts
; ------------------------------------------------------------------------
; Wait until DMA has finished
WAIT: lda $d31f WAIT: lda $d31f
lsr a lsr a
bcs WAIT bcs WAIT
rts rts