2002-12-02 06:14:46 +00:00
|
|
|
;
|
2003-02-10 22:57:05 +00:00
|
|
|
; Extended memory driver for the Commodore REU. Driver works without
|
|
|
|
; problems when statically linked.
|
2002-12-02 06:14:46 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2002-11-29
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
2002-12-02 06:14:46 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "em-kernel.inc"
|
2002-12-02 06:14:46 +00:00
|
|
|
.include "em-error.inc"
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "c128.inc"
|
2002-12-02 06:14:46 +00:00
|
|
|
|
|
|
|
.macpack generic
|
2014-06-04 21:50:18 +00:00
|
|
|
.macpack module
|
2002-12-02 06:14:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Header. Includes jump table
|
|
|
|
|
2014-06-04 21:50:18 +00:00
|
|
|
module_header _c128_reu_emd
|
2002-12-02 06:14:46 +00:00
|
|
|
|
|
|
|
; Driver signature
|
|
|
|
|
|
|
|
.byte $65, $6d, $64 ; "emd"
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte EMD_API_VERSION ; EM API version number
|
2002-12-02 06:14:46 +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
|
2002-12-02 06:14:46 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Constants
|
|
|
|
|
|
|
|
REU_STATUS = $DF00 ; Status register
|
|
|
|
REU_COMMAND = $DF01 ; Command register
|
|
|
|
REU_C64ADDR = $DF02 ; C64 base address register
|
|
|
|
REU_REUADDR = $DF04 ; REU base address register
|
|
|
|
REU_COUNT = $DF07 ; Transfer count register
|
|
|
|
REU_IRQMASK = $DF09 ; IRQ mask register
|
|
|
|
REU_CONTROL = $DF0A ; Control register
|
|
|
|
REU_TRIGGER = $FF00 ; REU command trigger
|
|
|
|
|
|
|
|
OP_COPYFROM = $ED
|
|
|
|
OP_COPYTO = $EC
|
|
|
|
|
2018-03-06 01:46:51 +00:00
|
|
|
OP_COPYFROM_ALOAD = $B1
|
|
|
|
OP_COPYTO_ALOAD = $B0
|
2002-12-02 06:14:46 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data.
|
|
|
|
|
2003-02-10 22:57:05 +00:00
|
|
|
.bss
|
2002-12-02 06:14:46 +00:00
|
|
|
pagecount: .res 2 ; Number of pages available
|
2003-02-10 22:57:05 +00:00
|
|
|
curpage: .res 2 ; Current page number
|
2002-12-02 06:14:46 +00:00
|
|
|
|
|
|
|
window: .res 256 ; Memory "window"
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
reu_params: .word $0000 ; Host address, lo, hi
|
|
|
|
.word $0000 ; Exp address, lo, hi
|
|
|
|
.byte $00 ; Expansion bank no.
|
|
|
|
.word $0000 ; # bytes to move, lo, hi
|
|
|
|
.byte $00 ; Interrupt mask reg.
|
2022-02-21 20:44:31 +00:00
|
|
|
.byte $00 ; Address control reg.
|
2002-12-02 06:14:46 +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:
|
2003-12-13 15:16:11 +00:00
|
|
|
ldx #$00 ; High byte of return code
|
2002-12-02 06:14:46 +00:00
|
|
|
lda #$55
|
|
|
|
sta REU_REUADDR
|
|
|
|
cmp REU_REUADDR ; Check for presence of REU
|
|
|
|
bne nodevice
|
2003-12-13 15:16:11 +00:00
|
|
|
asl a ; A = $AA
|
2002-12-02 06:14:46 +00:00
|
|
|
sta REU_REUADDR
|
|
|
|
cmp REU_REUADDR ; Check for presence of REU
|
|
|
|
bne nodevice
|
|
|
|
|
2018-03-05 23:01:55 +00:00
|
|
|
; determine the size
|
|
|
|
php
|
|
|
|
sei
|
2003-12-13 15:16:11 +00:00
|
|
|
ldy #$FF
|
2018-03-05 23:01:55 +00:00
|
|
|
loop:
|
|
|
|
sty window
|
|
|
|
jsr reu_size_check_common
|
2018-03-06 01:46:51 +00:00
|
|
|
ldx #OP_COPYTO_ALOAD
|
2018-03-05 23:01:55 +00:00
|
|
|
stx REU_COMMAND
|
|
|
|
dey
|
|
|
|
cpy #$FF
|
|
|
|
bne loop
|
|
|
|
iny
|
|
|
|
size_loop:
|
|
|
|
jsr reu_size_check_common
|
2018-03-06 01:46:51 +00:00
|
|
|
ldx #OP_COPYFROM_ALOAD
|
2018-03-05 23:01:55 +00:00
|
|
|
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
|
2002-12-02 06:14:46 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; No REU found
|
|
|
|
|
|
|
|
nodevice:
|
2003-12-13 15:16:11 +00:00
|
|
|
lda #EM_ERR_NO_DEVICE
|
|
|
|
; rts ; Run into UNINSTALL instead
|
2002-12-02 06:14:46 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2003-02-10 22:57:05 +00:00
|
|
|
; UNINSTALL routine. Is called before the driver is removed from memory.
|
2002-12-02 06:14:46 +00:00
|
|
|
; Can do cleanup or whatever. Must not return anything.
|
|
|
|
;
|
|
|
|
|
2003-02-10 22:57:05 +00:00
|
|
|
UNINSTALL:
|
2002-12-02 06:14:46 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; PAGECOUNT: Return the total number of available pages in a/x.
|
|
|
|
;
|
|
|
|
|
|
|
|
PAGECOUNT:
|
|
|
|
lda pagecount
|
|
|
|
ldx pagecount+1
|
|
|
|
rts
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; MAP: Map the page in a/x into memory and return a pointer to the page in
|
2002-12-02 21:27:06 +00:00
|
|
|
; a/x. The contents of the currently mapped page (if any) may be discarded
|
|
|
|
; by the driver.
|
2002-12-02 06:14:46 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
MAP: sta curpage
|
|
|
|
stx curpage+1 ; Remember the new page
|
|
|
|
|
|
|
|
ldy #OP_COPYFROM
|
|
|
|
jsr common ; Copy the window
|
|
|
|
|
|
|
|
lda #<window
|
|
|
|
ldx #>window ; Return the window address
|
|
|
|
done: rts
|
|
|
|
|
2002-12-05 18:57:53 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; 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
|
|
|
|
|
2002-12-02 06:14:46 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; COMMIT: Commit changes in the memory window to extended storage.
|
|
|
|
|
|
|
|
COMMIT: lda curpage
|
|
|
|
ldx curpage+1 ; Do we have a page mapped?
|
|
|
|
bmi done ; Jump if no page mapped
|
|
|
|
|
|
|
|
ldy #OP_COPYTO
|
|
|
|
common: sty tmp1
|
|
|
|
|
|
|
|
ldy #<window
|
|
|
|
sty REU_C64ADDR
|
|
|
|
ldy #>window
|
|
|
|
sty REU_C64ADDR+1
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
sty REU_REUADDR+0
|
|
|
|
sta REU_REUADDR+1
|
|
|
|
stx REU_REUADDR+2
|
|
|
|
|
|
|
|
sty REU_COUNT+0
|
|
|
|
ldy #1
|
|
|
|
sty REU_COUNT+1 ; Move 256 bytes
|
|
|
|
bne transfer1 ; Transfer 256 bytes into REU
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; 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:
|
|
|
|
ldy #OP_COPYFROM
|
|
|
|
.byte $2C
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; 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:
|
|
|
|
ldy #OP_COPYTO
|
|
|
|
sty tmp1
|
|
|
|
|
|
|
|
; Remember the passed pointer
|
|
|
|
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1 ; Save the pointer
|
|
|
|
|
|
|
|
; The structure passed to the functions has the same layout as the registers
|
|
|
|
; of the Commodore REU, so register programming is easy.
|
|
|
|
|
|
|
|
ldy #7-1
|
|
|
|
@L1: lda (ptr1),y
|
|
|
|
sta REU_C64ADDR,y
|
|
|
|
dey
|
|
|
|
bpl @L1
|
|
|
|
|
|
|
|
; Invalidate the page in the memory window
|
|
|
|
|
|
|
|
sty curpage+1 ; Y = $FF
|
|
|
|
|
|
|
|
; Reload the REU command and start the transfer
|
|
|
|
|
|
|
|
transfer1:
|
|
|
|
ldy tmp1
|
|
|
|
|
|
|
|
; Transfer subroutine for the REU. Expects command in Y.
|
|
|
|
|
|
|
|
transfer:
|
2013-05-09 11:56:54 +00:00
|
|
|
sty REU_COMMAND ; Issue command
|
2002-12-02 06:14:46 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy MMU_CR ; Save the current MMU settings
|
|
|
|
lda #MMU_CFG_RAM0 ;
|
|
|
|
sei ;
|
|
|
|
sta MMU_CR ; Enable RAM in bank #0
|
2002-12-02 06:14:46 +00:00
|
|
|
lda REU_TRIGGER ; Don't change $FF00
|
2013-05-09 11:56:54 +00:00
|
|
|
sta REU_TRIGGER ; Start the transfer...
|
2002-12-02 06:14:46 +00:00
|
|
|
|
2002-12-02 14:12:34 +00:00
|
|
|
sty MMU_CR ; Restore the old configuration
|
2002-12-02 06:14:46 +00:00
|
|
|
cli
|
|
|
|
rts
|
|
|
|
|