1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-27 00:29:31 +00:00

Added C128 extended memory driver for memory in bank #1

git-svn-id: svn://svn.cc65.org/cc65/trunk@1715 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-12-04 22:29:45 +00:00
parent 867b2ea2ed
commit 87531388f9
3 changed files with 279 additions and 2 deletions

View File

@ -45,7 +45,7 @@ OBJS = _scrsize.o \
TGIS =
EMDS = c128-georam.emd c128-reu.emd
EMDS = c128-georam.emd c128-ram.emd c128-reu.emd
#--------------------------------------------------------------------------
# Targets

273
libsrc/c128/c128-ram.s Normal file
View File

@ -0,0 +1,273 @@
;
; Extended memory driver for the C128 RAM in bank #1
;
; Ullrich von Bassewitz, 2002-12-04
;
.include "zeropage.inc"
.include "em-kernel.inc"
.include "em-error.inc"
.include "c128.inc"
.macpack generic
; ------------------------------------------------------------------------
; Header. Includes jump table
.segment "JUMPTABLE"
; Driver signature
.byte $65, $6d, $64 ; "emd"
.byte $00 ; EM API version number
; Jump table.
.word INSTALL
.word DEINSTALL
.word PAGECOUNT
.word MAP
.word COMMIT
.word COPYFROM
.word COPYTO
; ------------------------------------------------------------------------
; Constants
BASE = $400
TOPMEM = $FF00
PAGES = (TOPMEM - BASE) / 256
; ------------------------------------------------------------------------
; Data.
.data
curpage: .word $FFFF ; Current page number (invalid)
.bss
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:
lda #<EM_ERR_OK
ldx #>EM_ERR_OK
rts
; ------------------------------------------------------------------------
; DEINSTALL routine. Is called before the driver is removed from memory.
; Can do cleanup or whatever. Must not return anything.
;
DEINSTALL:
rts
; ------------------------------------------------------------------------
; PAGECOUNT: Return the total number of available pages in a/x.
;
PAGECOUNT:
lda #<PAGES
ldx #>PAGES
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
stx curpage+1 ; Remember the new page
clc
adc #>BASE
sta ptr1+1
ldy #$00
sty ptr1
lda #<ptr1
sta FETVEC
; Transfer one page
@L1: ldx #MMU_CFG_RAM1
jsr FETCH
sta window,y
iny
bne @L1
; Return the memory window
lda #<window
ldx #>window ; Return the window address
rts
; ------------------------------------------------------------------------
; COMMIT: Commit changes in the memory window to extended storage.
COMMIT: lda curpage ; Get the current page
ldx curpage+1
bmi done ; Jump if no page mapped
clc
adc #>BASE
sta ptr1+1
ldy #$00
sty ptr1
lda #<ptr1
sta STAVEC
; Transfer one page. Y must be zero on entry
@L1: lda window,y
ldx #MMU_CFG_RAM1
jsr STASH
iny
bne @L1
; Done
done: 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 ptr3
stx ptr3+1 ; Save the passed em_copy pointer
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
sta FETVEC
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
@L1: ldx #MMU_CFG_RAM1
jsr FETCH
sta (ptr2),y
iny
bne @L1
inc ptr1+1
inc ptr2+1
dec tmp1
bne @L1
; Copy the remainder of the page
@L2: ldy #EM_COPY_COUNT
lda (ptr3),y ; Get bytes in last page
beq @L4
sta tmp1
@L3: ldx #MMU_CFG_RAM1
jsr FETCH
sta (ptr2),y
iny
dec tmp1
bne @L3
; Done
@L4: 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 ptr3
stx ptr3+1 ; Save the passed em_copy pointer
ldy #EM_COPY_OFFS
lda (ptr3),y
sta ptr1
ldy #EM_COPY_PAGE
lda (ptr3),y
clc
adc #>BASE
sta ptr1+1 ; To
ldy #EM_COPY_BUF
lda (ptr3),y
sta ptr2
iny
lda (ptr3),y
sta ptr2+1 ; From
lda #<ptr1
sta STAVEC
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
@L1: lda (ptr2),y
ldx #MMU_CFG_RAM1
jsr STASH
iny
bne @L1
inc ptr1+1
inc ptr2+1
dec tmp1
bne @L1
; Copy the remainder of the page
@L2: ldy #EM_COPY_COUNT
lda (ptr3),y ; Get bytes in last page
beq @L4
sta tmp1
@L3: lda (ptr2),y
ldx #MMU_CFG_RAM1
jsr STASH
iny
dec tmp1
bne @L3
; Done
@L4: rts

View File

@ -24,6 +24,10 @@ CRAM_PTR = $E2 ; Pointer to current char in color RAM
CHARCOLOR = $F1
FKEY_COUNT = $D1 ; Characters for function key
FETCH = $2A2 ; Fetch subroutine in RAM
FETVEC = $2AA ; Vector patch location for FETCH
STASH = $2AF ; Stash routine in RAM
STAVEC = $2B9 ; Vector patch location for STASH
PALFLAG = $A03 ; $FF=PAL, $00=NTSC
INIT_STATUS = $A04 ; Flag: Reset/NMI Status
FKEY_LEN = $1000 ; Function key lengths
@ -179,7 +183,7 @@ CIA2_CRB = $DD0F
MMU_CR = $FF00
MMU_CFG_CC65 = %00001110 ; Bank 0 with kernal ROM
MMU_CFG_RAM0 = %00111111 ; Bank 0 full RAM
MMU_CFG_RAM1 = %01111111 ; Bank 1 full RAM
; ---------------------------------------------------------------------------
; Super CPU