some cleanup
This commit is contained in:
@@ -3,49 +3,67 @@
|
|||||||
;should work for ActionReplay as well...
|
;should work for ActionReplay as well...
|
||||||
;
|
;
|
||||||
;
|
;
|
||||||
;Version 1.0
|
; original Version 1.0 by Johannes Braun 2006-08-22 <hannenz@freenet.de>
|
||||||
;
|
|
||||||
;Johannes Braun 2006-08-22
|
|
||||||
;hannenz@freenet.de
|
|
||||||
;
|
;
|
||||||
;use the functions described in "usr/lib/cc65/include/em.h" to make use of this driver.
|
;use the functions described in "usr/lib/cc65/include/em.h" to make use of this driver.
|
||||||
;-------------------------------------------------------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
;NOTE: If called from ROM the Lo_Code routines must exit with LDA #$00 / STA $DE00!!! just change and recompile!
|
;NOTE: If called from ROM the Lo_Code routines must exit with LDA #$00 / STA $DE00!!! just change and recompile!
|
||||||
|
|
||||||
.include "em-kernel.inc"
|
.include "zeropage.inc"
|
||||||
.importzp ptr1,ptr2,ptr3,ptr4,tmp1
|
|
||||||
.macpack generic
|
|
||||||
|
|
||||||
c64_ram = ptr1 ;use some more expressive identifiers...
|
.include "em-kernel.inc"
|
||||||
rr_ram = ptr2
|
.include "em-error.inc"
|
||||||
len = ptr3
|
|
||||||
aux = ptr4
|
|
||||||
temp = tmp1
|
|
||||||
|
|
||||||
Lo_Mem = $0100 ;location of Lo_Code (must be below $1000 or above $e000)
|
.macpack generic
|
||||||
|
.macpack module
|
||||||
|
|
||||||
.segment "JUMPTABLE"
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
.byte $65,$6d,$64 ;Driver signature
|
c64_ram = ptr1 ; use some more expressive identifiers...
|
||||||
.byte EMD_API_VERSION
|
rr_ram = ptr2
|
||||||
|
len = ptr3
|
||||||
|
aux = ptr4
|
||||||
|
temp = tmp1
|
||||||
|
|
||||||
.addr INSTALL ;Jump Table
|
Lo_Mem = $0100 ; location of Lo_Code (must be below $1000 or above $e000)
|
||||||
.addr UNINSTALL
|
|
||||||
.addr PAGECOUNT
|
; ------------------------------------------------------------------------
|
||||||
.addr MAP
|
; Header. Includes jump table
|
||||||
.addr USE
|
|
||||||
.addr COMMIT
|
module_header _c64_rrr_emd
|
||||||
.addr COPYFROM
|
|
||||||
.addr COPYTO
|
; Driver signature
|
||||||
|
|
||||||
|
.byte $65, $6d, $64 ; "emd"
|
||||||
|
.byte EMD_API_VERSION ; EM API version number
|
||||||
|
|
||||||
|
; Library reference
|
||||||
|
|
||||||
|
.addr $0000
|
||||||
|
|
||||||
|
; Jump table
|
||||||
|
|
||||||
|
.addr INSTALL
|
||||||
|
.addr UNINSTALL
|
||||||
|
.addr PAGECOUNT
|
||||||
|
.addr MAP
|
||||||
|
.addr USE
|
||||||
|
.addr COMMIT
|
||||||
|
.addr COPYFROM
|
||||||
|
.addr COPYTO
|
||||||
|
|
||||||
|
; ------------------------------------------------------------------------
|
||||||
|
|
||||||
.bss
|
.bss
|
||||||
window: .res 256 ;the memory window (256 bytes)
|
window: .res 256 ; the memory window (256 bytes)
|
||||||
|
|
||||||
.rodata
|
.rodata
|
||||||
dummy: .word window ;a "pseudo"-em_copy_struct, used by em_map/ em_commit
|
dummy:
|
||||||
.byte 0 ;to pass over to COPYTO/COPYFROM
|
.word window ; a "pseudo"-em_copy_struct, used by em_map/ em_commit
|
||||||
curpage: .byte $ff ;just this byte is changed according to the desired page
|
.byte 0 ; to pass over to COPYTO/COPYFROM
|
||||||
|
curpage:
|
||||||
|
.byte $ff ; just this byte is changed according to the desired page
|
||||||
.byte 0
|
.byte 0
|
||||||
.word 256
|
.word 256
|
||||||
|
|
||||||
@@ -61,37 +79,37 @@ INSTALL:
|
|||||||
sta Lo_Mem,x
|
sta Lo_Mem,x
|
||||||
dex
|
dex
|
||||||
bpl :-
|
bpl :-
|
||||||
stx curpage ;invalidate current page ($ff)
|
stx curpage ; invalidate current page ($ff)
|
||||||
|
|
||||||
ldx #$23 ;$de00 value for rr-ram
|
ldx #$23 ; $de00 value for rr-ram
|
||||||
ldy #$02 ;$de00 value for c64-ram, CHANGE TO LDA #$00 if driver is called from ROM!
|
ldy #$02 ; $de00 value for c64-ram, CHANGE TO LDA #$00 if driver is called from ROM!
|
||||||
bne COMMON
|
bne COMMON
|
||||||
|
|
||||||
c1: stx $de00 ;try accessing rr-ram
|
c1: stx $de00 ; try accessing rr-ram
|
||||||
lda $8888
|
lda $8888
|
||||||
pha
|
pha
|
||||||
lda $9999 ;remember old content of $8888 and $9999
|
lda $9999 ; remember old content of $8888 and $9999
|
||||||
pha
|
pha
|
||||||
|
|
||||||
lda #$55
|
lda #$55
|
||||||
sta $8888 ;write test values
|
sta $8888 ; write test values
|
||||||
asl
|
asl
|
||||||
sta $9999
|
sta $9999
|
||||||
|
|
||||||
sty $de00 ;switch to c64 ram
|
sty $de00 ; switch to c64 ram
|
||||||
stx $8888
|
stx $8888
|
||||||
stx $9999
|
stx $9999
|
||||||
|
|
||||||
stx $de00 ;switch to rr-ram again (if present)
|
stx $de00 ; switch to rr-ram again (if present)
|
||||||
ldx $8888 ;read the values
|
ldx $8888 ; read the values
|
||||||
ldy $9999
|
ldy $9999
|
||||||
pla
|
pla
|
||||||
sta $9999 ;and write the old values back
|
sta $9999 ; and write the old values back
|
||||||
pla
|
pla
|
||||||
sta $8888
|
sta $8888
|
||||||
|
|
||||||
lda #2
|
lda #2
|
||||||
sta $de00 ;c64 ram again
|
sta $de00 ; c64 ram again
|
||||||
|
|
||||||
cli
|
cli
|
||||||
cpx #$55
|
cpx #$55
|
||||||
@@ -100,7 +118,7 @@ c1: stx $de00 ;try accessing rr-ram
|
|||||||
bne no
|
bne no
|
||||||
lda #0
|
lda #0
|
||||||
rts
|
rts
|
||||||
no: asl ;.A still has #2, so return #4: error code for "device not present"
|
no: asl ; A still has #2, so return #4: error code for "device not present"
|
||||||
rts
|
rts
|
||||||
c2:
|
c2:
|
||||||
;----------------------------------------------------------------------------------------
|
;----------------------------------------------------------------------------------------
|
||||||
@@ -108,7 +126,8 @@ c2:
|
|||||||
;----------------------------------------------------------------------------------------
|
;----------------------------------------------------------------------------------------
|
||||||
UNINSTALL:
|
UNINSTALL:
|
||||||
return_null:
|
return_null:
|
||||||
lda #$00 ;always return 32kb (128 pages)
|
lda #$00 ; always return 32kb (128 pages)
|
||||||
|
; fall through, skip the LDA
|
||||||
.byte $2c
|
.byte $2c
|
||||||
|
|
||||||
;----------------------------------------------------------------------------------------
|
;----------------------------------------------------------------------------------------
|
||||||
@@ -123,12 +142,13 @@ PAGECOUNT:
|
|||||||
;void* __fastcall__ em_use(unsigned page);
|
;void* __fastcall__ em_use(unsigned page);
|
||||||
;----------------------------------------------------------------------------------------
|
;----------------------------------------------------------------------------------------
|
||||||
USE:
|
USE:
|
||||||
cmp #$80 ;valid page?
|
cmp #$80 ; valid page?
|
||||||
bcs return_null ;no, return NULL pointer
|
bcs return_null ; no, return NULL pointer
|
||||||
sta curpage ;set to current page
|
sta curpage ; set to current page
|
||||||
return_win: lda #<window ;return pointer to window
|
return_win:
|
||||||
|
lda #<window ; return pointer to window
|
||||||
ldx #>window
|
ldx #>window
|
||||||
return: rts
|
return: rts
|
||||||
|
|
||||||
;----------------------------------------------------------------------------------------
|
;----------------------------------------------------------------------------------------
|
||||||
;void* __fastcall__ em_map(unsigned page);
|
;void* __fastcall__ em_map(unsigned page);
|
||||||
@@ -137,10 +157,10 @@ MAP:
|
|||||||
cmp #$80
|
cmp #$80
|
||||||
bcs return_null
|
bcs return_null
|
||||||
sta curpage
|
sta curpage
|
||||||
lda #<dummy ;load .A/.X with adress of data for COPYFROM-call (which expects the
|
lda #<dummy ; load .A/.X with adress of data for COPYFROM-call (which expects the
|
||||||
ldx #>dummy ;adress in .A/.X)
|
ldx #>dummy ; adress in .A/.X)
|
||||||
jsr COPYFROM
|
jsr COPYFROM
|
||||||
bcs return_win ;function returns pointer to window (returns always with carry set!)
|
bcs return_win ; function returns pointer to window (returns always with carry set!)
|
||||||
|
|
||||||
;----------------------------------------------------------------------------------------
|
;----------------------------------------------------------------------------------------
|
||||||
;void __fastcall__ em_commit(void);
|
;void __fastcall__ em_commit(void);
|
||||||
@@ -149,8 +169,8 @@ COMMIT:
|
|||||||
lda curpage
|
lda curpage
|
||||||
cmp #$80
|
cmp #$80
|
||||||
bcs return
|
bcs return
|
||||||
lda #<dummy ;load .A/.X with adress of data for COPYTO-call (which expects the
|
lda #<dummy ; load .A/.X with adress of data for COPYTO-call (which expects the
|
||||||
ldx #>dummy ;adress in .A/.X)
|
ldx #>dummy ; adress in .A/.X)
|
||||||
|
|
||||||
;----------------------------------------------------------------------------------------
|
;----------------------------------------------------------------------------------------
|
||||||
;void __fastcall__ em_copyto (struct em_copy *copy_data);
|
;void __fastcall__ em_copyto (struct em_copy *copy_data);
|
||||||
@@ -161,7 +181,7 @@ COPYTO:
|
|||||||
;copy the main copyto routine into Lo_Mem
|
;copy the main copyto routine into Lo_Mem
|
||||||
|
|
||||||
ldy #Lo_Code1_End - Lo_Code1
|
ldy #Lo_Code1_End - Lo_Code1
|
||||||
: lda Lo_Code1-1,y
|
: lda Lo_Code1-1,y
|
||||||
sta Lo_Mem-1,y
|
sta Lo_Mem-1,y
|
||||||
dey
|
dey
|
||||||
bne :-
|
bne :-
|
||||||
@@ -172,11 +192,11 @@ COMMON:
|
|||||||
;this part will be executed in Lo_Mem (!) by COPYFROM
|
;this part will be executed in Lo_Mem (!) by COPYFROM
|
||||||
|
|
||||||
Lo_Code2:
|
Lo_Code2:
|
||||||
stx $de00 ;map in rr-ram
|
stx $de00 ;map in rr-ram
|
||||||
lda (rr_ram),y ;get byte from rr-ram
|
lda (rr_ram),y ;get byte from rr-ram
|
||||||
sty $de00 ;RR-ROM will be mapped to $8000-$a000 but write access will go to c64-ram anyway!!
|
sty $de00 ;RR-ROM will be mapped to $8000-$a000 but write access will go to c64-ram anyway!!
|
||||||
sta (c64_ram),y ;and write to c64-ram
|
sta (c64_ram),y ;and write to c64-ram
|
||||||
nop ;pad to same size as Lo_Code1
|
nop ;pad to same size as Lo_Code1
|
||||||
nop
|
nop
|
||||||
Lo_Code2_End:
|
Lo_Code2_End:
|
||||||
|
|
||||||
@@ -184,41 +204,41 @@ Lo_Code2_End:
|
|||||||
;this part will be executed in Lo_Mem (!) by COPYTO
|
;this part will be executed in Lo_Mem (!) by COPYTO
|
||||||
|
|
||||||
Lo_Code1:
|
Lo_Code1:
|
||||||
lda (c64_ram),y ;read 1 byte from c64-ram
|
lda (c64_ram),y ;read 1 byte from c64-ram
|
||||||
stx $de00 ;map in rr-ram
|
stx $de00 ;map in rr-ram
|
||||||
sta (rr_ram),y ;write byte to rr-ram
|
sta (rr_ram),y ;write byte to rr-ram
|
||||||
lda #$02 ;map in c64-ram again
|
lda #$02 ;map in c64-ram again
|
||||||
sta $de00
|
sta $de00
|
||||||
;12 bytes
|
;12 bytes
|
||||||
|
|
||||||
;this part is common for both COPYFROM/COPYTO and executed in Lo_Mem, too
|
;this part is common for both COPYFROM/COPYTO and executed in Lo_Mem, too
|
||||||
|
|
||||||
Lo_Code_Common:
|
Lo_Code_Common:
|
||||||
inc c64_ram ;increase pointers
|
inc c64_ram ;increase pointers
|
||||||
bne :+
|
bne :+
|
||||||
inc c64_ram+1
|
inc c64_ram+1
|
||||||
: inc rr_ram
|
: inc rr_ram
|
||||||
bne @skip
|
bne @skip
|
||||||
inc rr_ram+1
|
inc rr_ram+1
|
||||||
lda rr_ram+1
|
lda rr_ram+1
|
||||||
cmp #$a0 ;wrap around 16k boundary in rr-ram window ($8000-$a000)
|
cmp #$a0 ;wrap around 16k boundary in rr-ram window ($8000-$a000)
|
||||||
bne @skip
|
bne @skip
|
||||||
|
|
||||||
lda #$80 ;reset pointer to $8000
|
lda #$80 ;reset pointer to $8000
|
||||||
sta rr_ram+1
|
sta rr_ram+1
|
||||||
txa ;adjust value in .X to map in next 16k-bank in rr-ram
|
txa ;adjust value in .X to map in next 16k-bank in rr-ram
|
||||||
adc #7 ;carry is set because of former CMP, so it adds 8
|
adc #7 ;carry is set because of former CMP, so it adds 8
|
||||||
tax
|
tax
|
||||||
;27 bytes
|
;27 bytes
|
||||||
@skip: lda c64_ram
|
@skip: lda c64_ram
|
||||||
cmp len
|
cmp len
|
||||||
lda c64_ram+1
|
lda c64_ram+1
|
||||||
sbc len+1
|
sbc len+1
|
||||||
bcc Lo_Code1
|
bcc Lo_Code1
|
||||||
lda #2 ;CHANGE to LDA #0 if driver is called from ROM
|
lda #2 ;CHANGE to LDA #0 if driver is called from ROM
|
||||||
sta $de00
|
sta $de00
|
||||||
cli
|
cli
|
||||||
rts ;17 bytes = 56 bytes Lo_Code ($38)
|
rts ;17 bytes = 56 bytes Lo_Code ($38)
|
||||||
Lo_Code1_End:
|
Lo_Code1_End:
|
||||||
;----------------------------------------------------------------------------------------
|
;----------------------------------------------------------------------------------------
|
||||||
;void __fastcall__ em_copyfrom(struct em_copy *copy_data);
|
;void __fastcall__ em_copyfrom(struct em_copy *copy_data);
|
||||||
@@ -228,16 +248,16 @@ COPYFROM:
|
|||||||
jsr get_struct_data
|
jsr get_struct_data
|
||||||
|
|
||||||
ldy #Lo_Code2_End - Lo_Code2 ;copy routine into Lo_Mem
|
ldy #Lo_Code2_End - Lo_Code2 ;copy routine into Lo_Mem
|
||||||
: lda Lo_Code2-1,y
|
: lda Lo_Code2-1,y
|
||||||
sta Lo_Mem-1,y
|
sta Lo_Mem-1,y
|
||||||
dey
|
dey
|
||||||
bne :-
|
bne :-
|
||||||
ldy #Lo_Code1_End-Lo_Code_Common
|
ldy #Lo_Code1_End-Lo_Code_Common
|
||||||
: lda Lo_Code_Common-1,y
|
: lda Lo_Code_Common-1,y
|
||||||
sta Lo_Mem+11,y
|
sta Lo_Mem+11,y
|
||||||
dey
|
dey
|
||||||
bne :-
|
bne :-
|
||||||
beq COMMON ;and execute...
|
beq COMMON ;and execute...
|
||||||
;----------------------------------------------------------------------------------------
|
;----------------------------------------------------------------------------------------
|
||||||
;read the struct data located at (.A/.X)
|
;read the struct data located at (.A/.X)
|
||||||
;and setup parameters for stash/ fetch operation
|
;and setup parameters for stash/ fetch operation
|
||||||
@@ -247,39 +267,40 @@ get_struct_data:
|
|||||||
;read and process the values from the em_copy struct passed to as parameters rameter to the
|
;read and process the values from the em_copy struct passed to as parameters rameter to the
|
||||||
;functions em_copyto and em_copyfrom
|
;functions em_copyto and em_copyfrom
|
||||||
|
|
||||||
sta aux ;store adress of struct (passed in .A/.X) into a zp pointer
|
sta aux ;store adress of struct (passed in .A/.X) into a zp pointer
|
||||||
stx aux+1
|
stx aux+1
|
||||||
ldy #0 ;index 0
|
ldy #0 ;index 0
|
||||||
|
|
||||||
lda (aux),y ;read c64-adress lo
|
lda (aux),y ;read c64-adress lo
|
||||||
sta c64_ram
|
sta c64_ram
|
||||||
iny
|
iny
|
||||||
lda (aux),y ;read c64-adress hi
|
lda (aux),y ;read c64-adress hi
|
||||||
sta c64_ram+1 ;(c64_ram) --> points to c64-adress space
|
sta c64_ram+1 ;(c64_ram) --> points to c64-adress space
|
||||||
iny
|
iny
|
||||||
lda (aux),y ;read rr-adress lo
|
lda (aux),y ;read rr-adress lo
|
||||||
sta rr_ram
|
sta rr_ram
|
||||||
iny
|
iny
|
||||||
lda (aux),y ;rr-adress hi
|
lda (aux),y ;rr-adress hi
|
||||||
pha ;remember
|
pha ;remember
|
||||||
and #$1f
|
and #$1f
|
||||||
ora #$80 ;adjust into 16k-window ($8000-$a000)
|
ora #$80 ;adjust into 16k-window ($8000-$a000)
|
||||||
sta rr_ram+1
|
sta rr_ram+1
|
||||||
pla ;re-get hi byte of rr-adress
|
pla ;re-get hi byte of rr-adress
|
||||||
and #$60 ;isolate bits 5 and 6
|
and #$60 ;isolate bits 5 and 6
|
||||||
lsr
|
lsr
|
||||||
lsr ;shift into bits 3 and 4
|
lsr ;shift into bits 3 and 4
|
||||||
ora #$23 ;set bit 5 (select ram) and 1+2 (game/exrom setting for ULTIMAX-mode)
|
ora #$23 ;set bit 5 (select ram) and 1+2 (game/exrom setting for ULTIMAX-mode)
|
||||||
tax ;.X has now the value to write into $de00 to acess rr-ram at desired 16k-bank
|
tax ;.X has now the value to write into $de00 to acess rr-ram at desired 16k-bank
|
||||||
iny
|
iny
|
||||||
iny ;skip unused byte
|
iny ;skip unused byte
|
||||||
lda (aux),y ;read length lo-byte
|
lda (aux),y ;read length lo-byte
|
||||||
clc
|
clc
|
||||||
adc c64_ram ;add to c64-addres
|
adc c64_ram ;add to c64-addres
|
||||||
sta len
|
sta len
|
||||||
iny
|
iny
|
||||||
lda (aux),y ;length hi-byte
|
lda (aux),y ;length hi-byte
|
||||||
adc c64_ram+1
|
adc c64_ram+1
|
||||||
sta len+1 ;tmp2: length, tmp3 contains end adress of transfer in c64-ram.
|
sta len+1 ;tmp2: length, tmp3 contains end adress of transfer in c64-ram.
|
||||||
rts ;55 bytes
|
rts
|
||||||
|
;55 bytes
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user