some cleanup

This commit is contained in:
mrdudz
2022-07-21 03:43:54 +02:00
parent a55807f682
commit 86091ac6bf

View File

@@ -3,34 +3,48 @@
;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"
.include "em-error.inc"
.macpack generic
.macpack module
; ------------------------------------------------------------------------
c64_ram = ptr1 ; use some more expressive identifiers...
rr_ram = ptr2 rr_ram = ptr2
len = ptr3 len = ptr3
aux = ptr4 aux = ptr4
temp = tmp1 temp = tmp1
Lo_Mem = $0100 ;location of Lo_Code (must be below $1000 or above $e000) Lo_Mem = $0100 ; location of Lo_Code (must be below $1000 or above $e000)
.segment "JUMPTABLE" ; ------------------------------------------------------------------------
; Header. Includes jump table
.byte $65,$6d,$64 ;Driver signature module_header _c64_rrr_emd
.byte EMD_API_VERSION
.addr INSTALL ;Jump Table ; 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 UNINSTALL
.addr PAGECOUNT .addr PAGECOUNT
.addr MAP .addr MAP
@@ -39,13 +53,17 @@ Lo_Mem = $0100 ;location of Lo_Code (must be below $1000 or above
.addr COPYFROM .addr COPYFROM
.addr COPYTO .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,10 +142,11 @@ 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
@@ -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);
@@ -281,5 +301,6 @@ get_struct_data:
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