Merge branch 'master' into rremd
This commit is contained in:
@@ -1,376 +1,376 @@
|
||||
;
|
||||
; Extended memory driver for 65816 based extra RAM. Driver works without
|
||||
; problems when statically linked.
|
||||
;
|
||||
; Marco van den Heuvel, 2015-12-01
|
||||
;
|
||||
|
||||
.include "zeropage.inc"
|
||||
|
||||
.include "em-kernel.inc"
|
||||
.include "em-error.inc"
|
||||
|
||||
|
||||
.macpack generic
|
||||
.macpack module
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Header. Includes jump table
|
||||
|
||||
module_header _c64_65816_emd
|
||||
|
||||
; 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
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
|
||||
.bss
|
||||
isnotscpu: .res 1 ; SuperCPU not present
|
||||
curpage: .res 1 ; Current page number
|
||||
curbank: .res 1 ; Current bank number (+1)
|
||||
bankcount: .res 1 ; Number of available banks (pages = banks * 256)
|
||||
window: .res 256 ; Memory "window"
|
||||
|
||||
.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:
|
||||
sei
|
||||
clc
|
||||
sed
|
||||
lda #$99
|
||||
adc #$01 ; on 65C02, 65SC02, 65CE02, 65802 and 65816 sets the zero flag correctly
|
||||
cld
|
||||
bne @not_present
|
||||
clc
|
||||
.P816
|
||||
sep #$01 ; nop #$01 on 65C02/65SC02 and lda ($01,s),y on 65CE02
|
||||
.P02
|
||||
bcc @not_present
|
||||
lda $d0bc
|
||||
and #$80
|
||||
sta isnotscpu
|
||||
lda $07e8
|
||||
pha ; save value incase it was used somewhere else
|
||||
ldx #$ff
|
||||
@fillloop: ; fill from top (bank 255) to bottom
|
||||
txa
|
||||
pha
|
||||
.P816
|
||||
plb ; pull dbr
|
||||
.P02
|
||||
stx $07e8
|
||||
dex
|
||||
cpx #$ff
|
||||
bne @fillloop
|
||||
inx
|
||||
@compareloop: ; check from bottom to top
|
||||
txa
|
||||
pha
|
||||
.P816
|
||||
plb
|
||||
.P02
|
||||
cmp $07e8
|
||||
bne @found_pages
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
sta $07e8
|
||||
cmp $07e8
|
||||
bne @found_pages
|
||||
inx
|
||||
bne @compareloop
|
||||
@found_pages:
|
||||
dex
|
||||
lda #$00
|
||||
pha
|
||||
.P816
|
||||
plb
|
||||
.P02
|
||||
pla
|
||||
sta $07e8
|
||||
cli
|
||||
lda isnotscpu
|
||||
bne @noextradex
|
||||
dex
|
||||
@noextradex:
|
||||
stx bankcount
|
||||
lda #<EM_ERR_OK
|
||||
ldx #>EM_ERR_OK
|
||||
rts
|
||||
@not_present:
|
||||
cli
|
||||
lda #<EM_ERR_NO_DEVICE
|
||||
ldx #>EM_ERR_NO_DEVICE
|
||||
; rts ; Run into UNINSTALL instead
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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 #$00 ; a whole bank is either usable or not
|
||||
ldx bankcount
|
||||
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 ; Remember the new page
|
||||
stx curbank ; Remember the new bank
|
||||
|
||||
sta ptr2+1 ; src address low
|
||||
lda #$00
|
||||
sta ptr2 ; src address high
|
||||
inx
|
||||
ldy isnotscpu ; check if not scpu
|
||||
bne @notscpu
|
||||
inx
|
||||
@notscpu:
|
||||
stx tmp2 ; src bank
|
||||
|
||||
sta tmp1 ; dst bank
|
||||
|
||||
sta ptr3+1 ; length high
|
||||
lda #$ff
|
||||
sta ptr3 ; length low
|
||||
|
||||
lda #<window
|
||||
sta ptr1 ; dst address low
|
||||
ldx #>window
|
||||
stx ptr1+1 ; dst address high
|
||||
|
||||
jsr transfer
|
||||
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; USE: Tell the driver that the window is now associated with a given page.
|
||||
|
||||
USE: sta curpage ; Remember the page
|
||||
stx curbank ; Remember the bank
|
||||
lda #<window
|
||||
ldx #>window ; Return the window
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; COMMIT: Commit changes in the memory window to extended storage.
|
||||
|
||||
COMMIT: lda curpage ; Get the current page
|
||||
sta ptr1+1 ; dst high
|
||||
ldx #$00
|
||||
stx ptr1 ; dst low
|
||||
|
||||
lda #<window
|
||||
sta ptr2 ; src low
|
||||
lda #>window
|
||||
sta ptr2+1 ; src high
|
||||
|
||||
stx ptr3+1 ; length high
|
||||
lda #$ff
|
||||
sta ptr3 ; length low
|
||||
|
||||
stx tmp2 ; src bank
|
||||
ldy curbank ; Get the current bank
|
||||
iny
|
||||
ldx isnotscpu
|
||||
bne @notascpu
|
||||
iny
|
||||
@notascpu:
|
||||
sty tmp1 ; dst bank
|
||||
|
||||
jsr transfer
|
||||
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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 ptr4
|
||||
stx ptr4+1 ; Save the passed em_copy pointer
|
||||
|
||||
ldy #EM_COPY::COUNT+1 ; start at the end of the struct
|
||||
lda (ptr4),y ; get high byte of count
|
||||
tax
|
||||
dey
|
||||
lda (ptr4),y ; get low byte of count
|
||||
bne @nodex
|
||||
dex
|
||||
@nodex:
|
||||
.P816
|
||||
dec
|
||||
.P02
|
||||
sta ptr3 ; length low
|
||||
stx ptr3+1 ; length high
|
||||
dey
|
||||
lda (ptr4),y ; get bank
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
ldx isnotscpu
|
||||
bne @notscpu64
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
@notscpu64:
|
||||
sta tmp2 ; src bank
|
||||
dey
|
||||
lda (ptr4),y ; get page
|
||||
sta ptr2+1 ; src high
|
||||
dey
|
||||
lda (ptr4),y ; get offset in page
|
||||
sta ptr2 ; src low
|
||||
dey
|
||||
lda (ptr4),y ; get memory buffer high
|
||||
sta ptr1+1 ; dst high
|
||||
dey
|
||||
lda (ptr4),y ; get memory buffer low
|
||||
sta ptr1 ; dst low
|
||||
lda #$00
|
||||
sta tmp1 ; dst bank
|
||||
|
||||
jsr transfer
|
||||
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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 ptr4
|
||||
stx ptr4+1 ; Save the passed em_copy pointer
|
||||
|
||||
ldy #EM_COPY::COUNT+1 ; start at the end of the struct
|
||||
lda (ptr4),y ; get high byte of count
|
||||
tax
|
||||
dey
|
||||
lda (ptr4),y ; get low byte of count
|
||||
bne @nodex2
|
||||
dex
|
||||
@nodex2:
|
||||
.P816
|
||||
dec
|
||||
.P02
|
||||
sta ptr3 ; length low
|
||||
txa
|
||||
sta ptr3+1 ; length high
|
||||
dey
|
||||
lda (ptr4),y ; get bank
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
ldx isnotscpu
|
||||
bne @notascpu64
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
@notascpu64:
|
||||
sta tmp1 ; dst bank
|
||||
dey
|
||||
lda (ptr4),y ; get page
|
||||
sta ptr1+1 ; dst high
|
||||
dey
|
||||
lda (ptr4),y ; get page offset
|
||||
sta ptr1 ; dst low
|
||||
dey
|
||||
lda (ptr4),y ; get memory buffer high
|
||||
sta ptr2+1 ; src low
|
||||
dey
|
||||
lda (ptr4),y ; get memory buffer low
|
||||
sta ptr2 ; src high
|
||||
lda #$00
|
||||
sta tmp2 ; src bank
|
||||
|
||||
jsr transfer
|
||||
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Helper function for moving a block, the following is used:
|
||||
; ptr1: dst
|
||||
; ptr2: src
|
||||
; ptr3: length
|
||||
; tmp1: dst bank
|
||||
; tmp2: src bank
|
||||
|
||||
transfer:
|
||||
.P816
|
||||
.A8
|
||||
.I8
|
||||
sei
|
||||
pha
|
||||
phx
|
||||
phy
|
||||
ldx tmp1 ; load srcbank
|
||||
stx @move+1 ; store srcbank in move + 1
|
||||
ldy tmp2 ; load dstbank
|
||||
sty @move+2 ; store dstbank in move + 2
|
||||
clc ; switch to native mode
|
||||
xce
|
||||
php ; save status bits
|
||||
rep #%00110000 ; set A and index to 16bit
|
||||
.A16
|
||||
.I16
|
||||
ldy ptr1
|
||||
ldx ptr2
|
||||
lda ptr3
|
||||
@move:
|
||||
mvn 0,0
|
||||
plp ; restore status bits
|
||||
.A8
|
||||
.I8
|
||||
lda #$00
|
||||
pha
|
||||
plb ; restore dbr
|
||||
sec
|
||||
xce ; switch to emul mode
|
||||
ply
|
||||
plx
|
||||
pla
|
||||
cli
|
||||
rts
|
||||
.P02
|
||||
;
|
||||
; Extended memory driver for 65816 based extra RAM. Driver works without
|
||||
; problems when statically linked.
|
||||
;
|
||||
; Marco van den Heuvel, 2015-12-01
|
||||
;
|
||||
|
||||
.include "zeropage.inc"
|
||||
|
||||
.include "em-kernel.inc"
|
||||
.include "em-error.inc"
|
||||
|
||||
|
||||
.macpack generic
|
||||
.macpack module
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Header. Includes jump table
|
||||
|
||||
module_header _c64_65816_emd
|
||||
|
||||
; 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
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
|
||||
.bss
|
||||
isnotscpu: .res 1 ; SuperCPU not present
|
||||
curpage: .res 1 ; Current page number
|
||||
curbank: .res 1 ; Current bank number (+1)
|
||||
bankcount: .res 1 ; Number of available banks (pages = banks * 256)
|
||||
window: .res 256 ; Memory "window"
|
||||
|
||||
.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:
|
||||
sei
|
||||
clc
|
||||
sed
|
||||
lda #$99
|
||||
adc #$01 ; on 65C02, 65SC02, 65CE02, 65802 and 65816 sets the zero flag correctly
|
||||
cld
|
||||
bne @not_present
|
||||
clc
|
||||
.P816
|
||||
sep #$01 ; nop #$01 on 65C02/65SC02 and lda ($01,s),y on 65CE02
|
||||
.P02
|
||||
bcc @not_present
|
||||
lda $d0bc
|
||||
and #$80
|
||||
sta isnotscpu
|
||||
lda $07e8
|
||||
pha ; save value incase it was used somewhere else
|
||||
ldx #$ff
|
||||
@fillloop: ; fill from top (bank 255) to bottom
|
||||
txa
|
||||
pha
|
||||
.P816
|
||||
plb ; pull dbr
|
||||
.P02
|
||||
stx $07e8
|
||||
dex
|
||||
cpx #$ff
|
||||
bne @fillloop
|
||||
inx
|
||||
@compareloop: ; check from bottom to top
|
||||
txa
|
||||
pha
|
||||
.P816
|
||||
plb
|
||||
.P02
|
||||
cmp $07e8
|
||||
bne @found_pages
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
sta $07e8
|
||||
cmp $07e8
|
||||
bne @found_pages
|
||||
inx
|
||||
bne @compareloop
|
||||
@found_pages:
|
||||
dex
|
||||
lda #$00
|
||||
pha
|
||||
.P816
|
||||
plb
|
||||
.P02
|
||||
pla
|
||||
sta $07e8
|
||||
cli
|
||||
lda isnotscpu
|
||||
bne @noextradex
|
||||
dex
|
||||
@noextradex:
|
||||
stx bankcount
|
||||
lda #<EM_ERR_OK
|
||||
ldx #>EM_ERR_OK
|
||||
rts
|
||||
@not_present:
|
||||
cli
|
||||
lda #<EM_ERR_NO_DEVICE
|
||||
ldx #>EM_ERR_NO_DEVICE
|
||||
; rts ; Run into UNINSTALL instead
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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 #$00 ; a whole bank is either usable or not
|
||||
ldx bankcount
|
||||
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 ; Remember the new page
|
||||
stx curbank ; Remember the new bank
|
||||
|
||||
sta ptr2+1 ; src address low
|
||||
lda #$00
|
||||
sta ptr2 ; src address high
|
||||
inx
|
||||
ldy isnotscpu ; check if not scpu
|
||||
bne @notscpu
|
||||
inx
|
||||
@notscpu:
|
||||
stx tmp2 ; src bank
|
||||
|
||||
sta tmp1 ; dst bank
|
||||
|
||||
sta ptr3+1 ; length high
|
||||
lda #$ff
|
||||
sta ptr3 ; length low
|
||||
|
||||
lda #<window
|
||||
sta ptr1 ; dst address low
|
||||
ldx #>window
|
||||
stx ptr1+1 ; dst address high
|
||||
|
||||
jsr transfer
|
||||
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; USE: Tell the driver that the window is now associated with a given page.
|
||||
|
||||
USE: sta curpage ; Remember the page
|
||||
stx curbank ; Remember the bank
|
||||
lda #<window
|
||||
ldx #>window ; Return the window
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; COMMIT: Commit changes in the memory window to extended storage.
|
||||
|
||||
COMMIT: lda curpage ; Get the current page
|
||||
sta ptr1+1 ; dst high
|
||||
ldx #$00
|
||||
stx ptr1 ; dst low
|
||||
|
||||
lda #<window
|
||||
sta ptr2 ; src low
|
||||
lda #>window
|
||||
sta ptr2+1 ; src high
|
||||
|
||||
stx ptr3+1 ; length high
|
||||
lda #$ff
|
||||
sta ptr3 ; length low
|
||||
|
||||
stx tmp2 ; src bank
|
||||
ldy curbank ; Get the current bank
|
||||
iny
|
||||
ldx isnotscpu
|
||||
bne @notascpu
|
||||
iny
|
||||
@notascpu:
|
||||
sty tmp1 ; dst bank
|
||||
|
||||
jsr transfer
|
||||
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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 ptr4
|
||||
stx ptr4+1 ; Save the passed em_copy pointer
|
||||
|
||||
ldy #EM_COPY::COUNT+1 ; start at the end of the struct
|
||||
lda (ptr4),y ; get high byte of count
|
||||
tax
|
||||
dey
|
||||
lda (ptr4),y ; get low byte of count
|
||||
bne @nodex
|
||||
dex
|
||||
@nodex:
|
||||
.P816
|
||||
dec
|
||||
.P02
|
||||
sta ptr3 ; length low
|
||||
stx ptr3+1 ; length high
|
||||
dey
|
||||
lda (ptr4),y ; get bank
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
ldx isnotscpu
|
||||
bne @notscpu64
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
@notscpu64:
|
||||
sta tmp2 ; src bank
|
||||
dey
|
||||
lda (ptr4),y ; get page
|
||||
sta ptr2+1 ; src high
|
||||
dey
|
||||
lda (ptr4),y ; get offset in page
|
||||
sta ptr2 ; src low
|
||||
dey
|
||||
lda (ptr4),y ; get memory buffer high
|
||||
sta ptr1+1 ; dst high
|
||||
dey
|
||||
lda (ptr4),y ; get memory buffer low
|
||||
sta ptr1 ; dst low
|
||||
lda #$00
|
||||
sta tmp1 ; dst bank
|
||||
|
||||
jsr transfer
|
||||
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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 ptr4
|
||||
stx ptr4+1 ; Save the passed em_copy pointer
|
||||
|
||||
ldy #EM_COPY::COUNT+1 ; start at the end of the struct
|
||||
lda (ptr4),y ; get high byte of count
|
||||
tax
|
||||
dey
|
||||
lda (ptr4),y ; get low byte of count
|
||||
bne @nodex2
|
||||
dex
|
||||
@nodex2:
|
||||
.P816
|
||||
dec
|
||||
.P02
|
||||
sta ptr3 ; length low
|
||||
txa
|
||||
sta ptr3+1 ; length high
|
||||
dey
|
||||
lda (ptr4),y ; get bank
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
ldx isnotscpu
|
||||
bne @notascpu64
|
||||
.P816
|
||||
inc
|
||||
.P02
|
||||
@notascpu64:
|
||||
sta tmp1 ; dst bank
|
||||
dey
|
||||
lda (ptr4),y ; get page
|
||||
sta ptr1+1 ; dst high
|
||||
dey
|
||||
lda (ptr4),y ; get page offset
|
||||
sta ptr1 ; dst low
|
||||
dey
|
||||
lda (ptr4),y ; get memory buffer high
|
||||
sta ptr2+1 ; src low
|
||||
dey
|
||||
lda (ptr4),y ; get memory buffer low
|
||||
sta ptr2 ; src high
|
||||
lda #$00
|
||||
sta tmp2 ; src bank
|
||||
|
||||
jsr transfer
|
||||
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Helper function for moving a block, the following is used:
|
||||
; ptr1: dst
|
||||
; ptr2: src
|
||||
; ptr3: length
|
||||
; tmp1: dst bank
|
||||
; tmp2: src bank
|
||||
|
||||
transfer:
|
||||
.P816
|
||||
.A8
|
||||
.I8
|
||||
sei
|
||||
pha
|
||||
phx
|
||||
phy
|
||||
ldx tmp1 ; load srcbank
|
||||
stx @move+1 ; store srcbank in move + 1
|
||||
ldy tmp2 ; load dstbank
|
||||
sty @move+2 ; store dstbank in move + 2
|
||||
clc ; switch to native mode
|
||||
xce
|
||||
php ; save status bits
|
||||
rep #%00110000 ; set A and index to 16bit
|
||||
.A16
|
||||
.I16
|
||||
ldy ptr1
|
||||
ldx ptr2
|
||||
lda ptr3
|
||||
@move:
|
||||
mvn 0,0
|
||||
plp ; restore status bits
|
||||
.A8
|
||||
.I8
|
||||
lda #$00
|
||||
pha
|
||||
plb ; restore dbr
|
||||
sec
|
||||
xce ; switch to emul mode
|
||||
ply
|
||||
plx
|
||||
pla
|
||||
cli
|
||||
rts
|
||||
.P02
|
||||
|
||||
280
libsrc/c64/emd/c64-kerberos.s
Normal file
280
libsrc/c64/emd/c64-kerberos.s
Normal file
@@ -0,0 +1,280 @@
|
||||
; Extended Memory Driver for the Kerberos MIDI interface.
|
||||
; http://www.frank-buss.de/kerberos/
|
||||
; based on the code for RamCart 64/128KB cartridge.
|
||||
; 2020-06-16 Dirk Jagdmann <doj@cubic.org>
|
||||
|
||||
.include "zeropage.inc"
|
||||
.include "em-kernel.inc"
|
||||
.include "em-error.inc"
|
||||
|
||||
.macpack generic
|
||||
.macpack module
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Header. Includes jump table
|
||||
|
||||
module_header _c64_kerberos_emd
|
||||
|
||||
; 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
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Constants
|
||||
|
||||
RAMC_WINDOW = $DF00 ; Address of Kerberos SRAM
|
||||
RAMC_PAGE_LO = $DE3E ; Page register low
|
||||
RAMC_PAGE_HI = $DE3F ; Page register high
|
||||
|
||||
.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:
|
||||
;; write $55 into first page
|
||||
lda #0
|
||||
sta RAMC_PAGE_LO
|
||||
sta RAMC_PAGE_HI
|
||||
lda #$55
|
||||
sta RAMC_WINDOW
|
||||
|
||||
;; write $AA into second page
|
||||
lda #1
|
||||
sta RAMC_PAGE_LO
|
||||
sta RAMC_PAGE_HI
|
||||
lda #$AA
|
||||
sta RAMC_WINDOW
|
||||
|
||||
;; check $55 in first page
|
||||
lda #0
|
||||
sta RAMC_PAGE_LO
|
||||
sta RAMC_PAGE_HI
|
||||
lda RAMC_WINDOW
|
||||
cmp #$55
|
||||
bne @notpresent
|
||||
|
||||
;; check $AA in first page
|
||||
lda #1
|
||||
sta RAMC_PAGE_LO
|
||||
sta RAMC_PAGE_HI
|
||||
lda RAMC_WINDOW
|
||||
cmp #$AA
|
||||
bne @notpresent
|
||||
|
||||
lda #<EM_ERR_OK
|
||||
ldx #>EM_ERR_OK
|
||||
rts
|
||||
|
||||
@notpresent:
|
||||
lda #<EM_ERR_NO_DEVICE
|
||||
ldx #>EM_ERR_NO_DEVICE
|
||||
; use rts from UNINSTALL below
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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 #<(128 * 1024 / 256)
|
||||
ldx #>(128 * 1024 / 256)
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; USE: Tell the driver that the window is now associated with a given page.
|
||||
; The Kerberos cartridge does not copy but actually map the window, so USE is
|
||||
; identical to MAP.
|
||||
|
||||
USE = MAP
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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 RAMC_PAGE_LO
|
||||
txa
|
||||
and #1
|
||||
sta RAMC_PAGE_HI
|
||||
lda #<RAMC_WINDOW
|
||||
ldx #>RAMC_WINDOW
|
||||
|
||||
; Use the RTS from COMMIT below to save a precious byte of storage
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; COMMIT: Commit changes in the memory window to extended storage.
|
||||
|
||||
COMMIT: rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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:
|
||||
jsr setup
|
||||
|
||||
; Setup is:
|
||||
;
|
||||
; - ptr1 contains the struct pointer
|
||||
; - ptr2 contains the linear memory buffer
|
||||
; - ptr3 contains -(count-1)
|
||||
; - tmp1 contains the low page register value
|
||||
; - tmp2 contains the high page register value
|
||||
; - X contains the page offset
|
||||
; - Y contains zero
|
||||
|
||||
beq @L5 ; will always branch, because setup ends with ldy #0
|
||||
|
||||
@L1: lda RAMC_WINDOW,x
|
||||
sta (ptr2),y
|
||||
iny
|
||||
bne @L2
|
||||
inc ptr2+1
|
||||
@L2: inx
|
||||
beq @L4
|
||||
|
||||
; Bump count and repeat
|
||||
|
||||
@L3: inc ptr3
|
||||
bne @L1
|
||||
inc ptr3+1
|
||||
bne @L1
|
||||
rts
|
||||
|
||||
; Bump page register
|
||||
|
||||
@L4: inc tmp1
|
||||
bne @L5
|
||||
inc tmp2
|
||||
@L5: lda tmp1
|
||||
sta RAMC_PAGE_LO
|
||||
lda tmp2
|
||||
sta RAMC_PAGE_HI
|
||||
jmp @L3
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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:
|
||||
jsr setup
|
||||
|
||||
; Setup is:
|
||||
;
|
||||
; - ptr1 contains the struct pointer
|
||||
; - ptr2 contains the linear memory buffer
|
||||
; - ptr3 contains -(count-1)
|
||||
; - tmp1 contains the low page register value
|
||||
; - tmp2 contains the high page register value
|
||||
; - X contains the page offset
|
||||
; - Y contains zero
|
||||
|
||||
beq @L5 ; will always branch, because setup ends with ldy #0
|
||||
|
||||
@L1: lda (ptr2),y
|
||||
sta RAMC_WINDOW,x
|
||||
iny
|
||||
bne @L2
|
||||
inc ptr2+1
|
||||
@L2: inx
|
||||
beq @L4
|
||||
|
||||
; Bump count and repeat
|
||||
|
||||
@L3: inc ptr3
|
||||
bne @L1
|
||||
inc ptr3+1
|
||||
bne @L1
|
||||
rts
|
||||
|
||||
; Bump page register
|
||||
|
||||
@L4: inc tmp1
|
||||
bne @L5
|
||||
inc tmp2
|
||||
@L5: lda tmp1
|
||||
sta RAMC_PAGE_LO
|
||||
lda tmp2
|
||||
sta RAMC_PAGE_HI
|
||||
jmp @L3
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Helper function for COPYFROM and COPYTO: Store the pointer to the request
|
||||
; structure and prepare data for the copy
|
||||
|
||||
setup: sta ptr1
|
||||
stx ptr1+1 ; Save passed pointer
|
||||
|
||||
; Get the page number from the struct and adjust it so that it may be used
|
||||
; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
|
||||
|
||||
ldy #EM_COPY::PAGE+1
|
||||
lda (ptr1),y
|
||||
sta tmp2
|
||||
dey
|
||||
lda (ptr1),y
|
||||
sta tmp1
|
||||
|
||||
; Get the buffer pointer into ptr2
|
||||
|
||||
ldy #EM_COPY::BUF
|
||||
lda (ptr1),y
|
||||
sta ptr2
|
||||
iny
|
||||
lda (ptr1),y
|
||||
sta ptr2+1
|
||||
|
||||
; Get the count, calculate -(count-1) and store it into ptr3
|
||||
|
||||
ldy #EM_COPY::COUNT
|
||||
lda (ptr1),y
|
||||
eor #$FF
|
||||
sta ptr3
|
||||
iny
|
||||
lda (ptr1),y
|
||||
eor #$FF
|
||||
sta ptr3+1
|
||||
|
||||
; Get the page offset into X and clear Y
|
||||
|
||||
ldy #EM_COPY::OFFS
|
||||
lda (ptr1),y
|
||||
tax
|
||||
ldy #$00
|
||||
|
||||
; Done
|
||||
|
||||
rts
|
||||
@@ -44,7 +44,7 @@
|
||||
; Constants
|
||||
|
||||
BASE = $D000
|
||||
PAGES = ($10000 - BASE) / 256
|
||||
PAGES = ($FF00 - BASE) / 256
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
@@ -167,7 +167,7 @@ loop: .repeat 8
|
||||
|
||||
; Done
|
||||
|
||||
done: rts
|
||||
done: rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; COPYFROM: Copy from extended into linear memory. A pointer to a structure
|
||||
@@ -178,7 +178,7 @@ done: rts
|
||||
COPYFROM:
|
||||
sta ptr3
|
||||
stx ptr3+1 ; Save the passed em_copy pointer
|
||||
|
||||
|
||||
ldy #EM_COPY::OFFS
|
||||
lda (ptr3),y
|
||||
sta ptr1
|
||||
@@ -267,5 +267,3 @@ COPYTO: sta ptr3
|
||||
sta ptr1+1 ; From
|
||||
|
||||
jmp common
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,9 @@ REU_TRIGGER = $FF00 ; REU command trigger
|
||||
OP_COPYFROM = $ED
|
||||
OP_COPYTO = $EC
|
||||
|
||||
OP_COPYFROM_ALOAD = $B1
|
||||
OP_COPYTO_ALOAD = $B0
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
@@ -92,19 +95,59 @@ INSTALL:
|
||||
cmp REU_REUADDR ; Check for presence of REU
|
||||
bne nodevice
|
||||
|
||||
ldy #>(128*4) ; Assume 128KB
|
||||
lda REU_STATUS
|
||||
and #$10 ; Check size bit
|
||||
beq @L1
|
||||
ldy #>(256*4) ; 256KB when size bit is set
|
||||
@L1: sty pagecount+1
|
||||
|
||||
; determine the size
|
||||
php
|
||||
sei
|
||||
ldy #$FF
|
||||
sty curpage
|
||||
sty curpage+1 ; Invalidate the current page
|
||||
txa ; X = A = EM_ERR_OK
|
||||
loop:
|
||||
sty window
|
||||
jsr reu_size_check_common
|
||||
ldx #OP_COPYTO_ALOAD
|
||||
stx REU_COMMAND
|
||||
dey
|
||||
cpy #$FF
|
||||
bne loop
|
||||
iny
|
||||
size_loop:
|
||||
jsr reu_size_check_common
|
||||
ldx #OP_COPYFROM_ALOAD
|
||||
stx REU_COMMAND
|
||||
cpy window
|
||||
bne size_found
|
||||
iny
|
||||
bne size_loop
|
||||
size_found:
|
||||
plp
|
||||
ldx #$00
|
||||
cpy #$00 ; too many pages, shave off 2
|
||||
bne pagecount_ok
|
||||
dex
|
||||
dex
|
||||
dey
|
||||
pagecount_ok:
|
||||
stx pagecount
|
||||
sty pagecount+1
|
||||
lda #<EM_ERR_OK
|
||||
ldx #>EM_ERR_OK
|
||||
rts
|
||||
|
||||
; common REU setup for size check
|
||||
reu_size_check_common:
|
||||
sty REU_REUADDR+2
|
||||
ldx #<window
|
||||
stx REU_C64ADDR
|
||||
ldx #>window
|
||||
stx REU_C64ADDR+1
|
||||
ldx #$00
|
||||
stx REU_REUADDR
|
||||
stx REU_REUADDR+1
|
||||
stx REU_COUNT+1
|
||||
stx REU_CONTROL
|
||||
inx
|
||||
stx REU_COUNT
|
||||
rts
|
||||
|
||||
|
||||
; No REU found
|
||||
|
||||
nodevice:
|
||||
@@ -147,7 +190,7 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user