2002-12-04 22:29:45 +00:00
|
|
|
;
|
2010-02-04 18:28:56 +00:00
|
|
|
; Extended memory driver for the C128 RAM in bank #1. Driver works without
|
2003-02-10 22:57:05 +00:00
|
|
|
; problems when statically linked.
|
2002-12-04 22:29:45 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2002-12-04
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "em-kernel.inc"
|
2002-12-04 22:29:45 +00:00
|
|
|
.include "em-error.inc"
|
|
|
|
.include "c128.inc"
|
|
|
|
|
|
|
|
.macpack generic
|
2014-06-04 21:50:18 +00:00
|
|
|
.macpack module
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Header. Includes jump table
|
|
|
|
|
2014-06-04 21:50:18 +00:00
|
|
|
module_header _c128_ram_emd
|
2002-12-04 22:29:45 +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-04 22:29:45 +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-04 22:29:45 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Constants
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
BASE = $400
|
2010-02-04 18:28:56 +00:00
|
|
|
TOPMEM = $FF00
|
2013-05-09 11:56:54 +00:00
|
|
|
PAGES = (TOPMEM - BASE) / 256
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data.
|
|
|
|
|
|
|
|
.bss
|
2015-11-30 07:04:23 +00:00
|
|
|
curpage: .res 2 ; Current page number
|
2003-02-10 22:57:05 +00:00
|
|
|
|
2002-12-04 22:29:45 +00:00
|
|
|
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:
|
2003-02-10 22:57:05 +00:00
|
|
|
ldx #$FF
|
|
|
|
stx curpage
|
2010-02-04 18:28:56 +00:00
|
|
|
stx curpage+1 ; Invalidate the current page
|
|
|
|
inx
|
|
|
|
txa ; A = X = EM_ERR_OK
|
2015-11-29 19:35:25 +00:00
|
|
|
; rts ; Run into UNINSTALL instead
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2003-02-10 22:57:05 +00:00
|
|
|
; UNINSTALL routine. Is called before the driver is removed from memory.
|
2002-12-04 22:29:45 +00:00
|
|
|
; Can do cleanup or whatever. Must not return anything.
|
|
|
|
;
|
|
|
|
|
2003-02-10 22:57:05 +00:00
|
|
|
UNINSTALL:
|
2002-12-04 22:29:45 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; PAGECOUNT: Return the total number of available pages in a/x.
|
|
|
|
;
|
|
|
|
|
|
|
|
PAGECOUNT:
|
2010-02-04 18:28:56 +00:00
|
|
|
lda #<PAGES
|
|
|
|
ldx #>PAGES
|
2002-12-04 22:29:45 +00:00
|
|
|
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.
|
|
|
|
;
|
|
|
|
|
2015-12-02 08:21:55 +00:00
|
|
|
MAP: sta curpage
|
2002-12-04 22:29:45 +00:00
|
|
|
stx curpage+1 ; Remember the new page
|
|
|
|
|
2010-02-01 17:56:37 +00:00
|
|
|
clc
|
2013-05-09 11:56:54 +00:00
|
|
|
adc #>BASE
|
|
|
|
sta ptr1+1
|
|
|
|
ldy #$00
|
|
|
|
sty ptr1
|
2010-02-04 18:28:56 +00:00
|
|
|
|
2002-12-04 22:29:45 +00:00
|
|
|
lda #<ptr1
|
|
|
|
sta FETVEC
|
2015-12-02 08:21:55 +00:00
|
|
|
sei
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
; Transfer one page
|
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
@L1: ldx #MMU_CFG_RAM1
|
2002-12-04 22:29:45 +00:00
|
|
|
jsr FETCH
|
|
|
|
sta window,y
|
|
|
|
iny
|
|
|
|
bne @L1
|
2015-12-02 08:21:55 +00:00
|
|
|
cli
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
; Return the memory window
|
|
|
|
|
|
|
|
lda #<window
|
|
|
|
ldx #>window ; Return the window address
|
|
|
|
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-04 22:29:45 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; COMMIT: Commit changes in the memory window to extended storage.
|
|
|
|
|
2015-12-02 08:21:55 +00:00
|
|
|
COMMIT: lda curpage ; Get the current page
|
2002-12-04 22:29:45 +00:00
|
|
|
ldx curpage+1
|
|
|
|
bmi done ; Jump if no page mapped
|
|
|
|
|
|
|
|
clc
|
2013-05-09 11:56:54 +00:00
|
|
|
adc #>BASE
|
|
|
|
sta ptr1+1
|
|
|
|
ldy #$00
|
|
|
|
sty ptr1
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
lda #<ptr1
|
|
|
|
sta STAVEC
|
2015-12-02 08:21:55 +00:00
|
|
|
sei
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
; Transfer one page. Y must be zero on entry
|
|
|
|
|
|
|
|
@L1: lda window,y
|
2010-02-04 18:28:56 +00:00
|
|
|
ldx #MMU_CFG_RAM1
|
2002-12-04 22:29:45 +00:00
|
|
|
jsr STASH
|
|
|
|
iny
|
|
|
|
bne @L1
|
2015-12-02 08:21:55 +00:00
|
|
|
cli
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
; Done
|
|
|
|
|
2015-12-02 08:21:55 +00:00
|
|
|
done: rts
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; 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:
|
2010-02-04 18:28:56 +00:00
|
|
|
sta ptr3
|
|
|
|
stx ptr3+1 ; Save the passed em_copy pointer
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
ldy #EM_COPY::OFFS
|
|
|
|
lda (ptr3),y
|
|
|
|
sta ptr1
|
|
|
|
ldy #EM_COPY::PAGE
|
|
|
|
lda (ptr3),y
|
|
|
|
clc
|
|
|
|
adc #>BASE
|
|
|
|
sta ptr1+1 ; From
|
|
|
|
|
|
|
|
ldy #EM_COPY::BUF
|
|
|
|
lda (ptr3),y
|
|
|
|
sta ptr2
|
|
|
|
iny
|
|
|
|
lda (ptr3),y
|
|
|
|
sta ptr2+1 ; To
|
|
|
|
|
|
|
|
lda #<ptr1
|
2002-12-04 22:29:45 +00:00
|
|
|
sta FETVEC
|
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
ldy #EM_COPY::COUNT+1
|
|
|
|
lda (ptr3),y ; Get number of pages
|
|
|
|
beq @L2 ; Skip if no full pages
|
|
|
|
sta tmp1
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
; Copy full pages
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
ldy #$00
|
2015-12-02 08:21:55 +00:00
|
|
|
sei
|
2010-02-04 18:28:56 +00:00
|
|
|
@L1: ldx #MMU_CFG_RAM1
|
|
|
|
jsr FETCH
|
|
|
|
sta (ptr2),y
|
|
|
|
iny
|
2010-02-01 17:56:37 +00:00
|
|
|
bne @L1
|
2010-02-04 18:28:56 +00:00
|
|
|
inc ptr1+1
|
|
|
|
inc ptr2+1
|
|
|
|
dec tmp1
|
2010-02-01 17:56:37 +00:00
|
|
|
bne @L1
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
; Copy the remainder of the page
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
@L2: ldy #EM_COPY::COUNT
|
|
|
|
lda (ptr3),y ; Get bytes in last page
|
|
|
|
beq @L4
|
|
|
|
sta tmp1
|
|
|
|
|
|
|
|
ldy #$00
|
|
|
|
@L3: ldx #MMU_CFG_RAM1
|
|
|
|
jsr FETCH
|
2013-05-09 11:56:54 +00:00
|
|
|
sta (ptr2),y
|
2010-02-04 18:28:56 +00:00
|
|
|
iny
|
|
|
|
dec tmp1
|
2010-02-01 17:56:37 +00:00
|
|
|
bne @L3
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
; Done
|
|
|
|
|
2015-11-30 07:04:23 +00:00
|
|
|
@L4: cli
|
|
|
|
rts
|
2002-12-04 22:29:45 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; 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.
|
|
|
|
;
|
|
|
|
|
2015-12-02 08:21:55 +00:00
|
|
|
COPYTO: sta ptr3
|
2010-02-04 18:28:56 +00:00
|
|
|
stx ptr3+1 ; Save the passed em_copy pointer
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
ldy #EM_COPY::OFFS
|
|
|
|
lda (ptr3),y
|
|
|
|
sta ptr1
|
|
|
|
ldy #EM_COPY::PAGE
|
|
|
|
lda (ptr3),y
|
2010-02-01 17:56:37 +00:00
|
|
|
clc
|
2010-02-04 18:28:56 +00:00
|
|
|
adc #>BASE
|
|
|
|
sta ptr1+1 ; To
|
2010-02-01 17:56:37 +00:00
|
|
|
|
|
|
|
ldy #EM_COPY::BUF
|
2010-02-04 18:28:56 +00:00
|
|
|
lda (ptr3),y
|
2010-02-01 17:56:37 +00:00
|
|
|
sta ptr2
|
2002-12-04 22:29:45 +00:00
|
|
|
iny
|
2010-02-04 18:28:56 +00:00
|
|
|
lda (ptr3),y
|
|
|
|
sta ptr2+1 ; From
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
lda #<ptr1
|
|
|
|
sta STAVEC
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
ldy #EM_COPY::COUNT+1
|
|
|
|
lda (ptr3),y ; Get number of pages
|
|
|
|
beq @L2 ; Skip if no full pages
|
|
|
|
sta tmp1
|
|
|
|
|
|
|
|
; Copy full pages
|
|
|
|
|
|
|
|
ldy #$00
|
2015-12-02 08:21:55 +00:00
|
|
|
sei
|
2010-02-04 18:28:56 +00:00
|
|
|
@L1: lda (ptr2),y
|
|
|
|
ldx #MMU_CFG_RAM1
|
|
|
|
jsr STASH
|
2010-02-01 17:56:37 +00:00
|
|
|
iny
|
2010-02-04 18:28:56 +00:00
|
|
|
bne @L1
|
|
|
|
inc ptr1+1
|
|
|
|
inc ptr2+1
|
|
|
|
dec tmp1
|
|
|
|
bne @L1
|
2002-12-04 22:29:45 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
; Copy the remainder of the page
|
2010-02-01 17:56:37 +00:00
|
|
|
|
2010-02-04 18:28:56 +00:00
|
|
|
@L2: ldy #EM_COPY::COUNT
|
|
|
|
lda (ptr3),y ; Get bytes in last page
|
|
|
|
beq @L4
|
|
|
|
sta tmp1
|
|
|
|
|
|
|
|
ldy #$00
|
|
|
|
@L3: lda (ptr2),y
|
|
|
|
ldx #MMU_CFG_RAM1
|
|
|
|
jsr STASH
|
|
|
|
iny
|
|
|
|
dec tmp1
|
|
|
|
bne @L3
|
2010-02-01 17:56:37 +00:00
|
|
|
|
|
|
|
; Done
|
|
|
|
|
2015-11-30 07:04:23 +00:00
|
|
|
@L4: cli
|
|
|
|
rts
|