Replaced whole bunch for Makefiles with a single generic Makefile.
- No complex shell logic. - "Source file shadowing" for all targets via vpath. - Dependency handling. - True incremental build. - Don't write into source directories. - Easy cleanup by just removing 'wrk'.
This commit is contained in:
349
libsrc/c128/emd/c128-georam.s
Normal file
349
libsrc/c128/emd/c128-georam.s
Normal file
@@ -0,0 +1,349 @@
|
||||
;
|
||||
; Extended memory driver for the GEORAM cartridge. Driver works without
|
||||
; problems when statically linked.
|
||||
;
|
||||
; Ullrich von Bassewitz, 2002-11-29
|
||||
;
|
||||
; GEORAM page size checking routine by
|
||||
; Marco van den Heuvel, 2010-01-21
|
||||
;
|
||||
|
||||
.include "zeropage.inc"
|
||||
|
||||
.include "em-kernel.inc"
|
||||
.include "em-error.inc"
|
||||
|
||||
|
||||
.macpack generic
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Header. Includes jump table
|
||||
|
||||
.segment "JUMPTABLE"
|
||||
|
||||
; Driver signature
|
||||
|
||||
.byte $65, $6d, $64 ; "emd"
|
||||
.byte EMD_API_VERSION ; EM API version number
|
||||
|
||||
; Jump table.
|
||||
|
||||
.word INSTALL
|
||||
.word UNINSTALL
|
||||
.word PAGECOUNT
|
||||
.word MAP
|
||||
.word USE
|
||||
.word COMMIT
|
||||
.word COPYFROM
|
||||
.word COPYTO
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Constants
|
||||
|
||||
GR_WINDOW = $DE00 ; Address of GEORAM window
|
||||
GR_PAGE_LO = $DFFE ; Page register low
|
||||
GR_PAGE_HI = $DFFF ; Page register high
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
|
||||
.data
|
||||
|
||||
pagecount: .res 2 ; Number of available pages
|
||||
|
||||
.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:
|
||||
ldx GR_WINDOW
|
||||
cpx GR_WINDOW
|
||||
bne @notpresent
|
||||
inc GR_WINDOW
|
||||
cpx GR_WINDOW
|
||||
beq @notpresent
|
||||
|
||||
lda #4
|
||||
jsr check
|
||||
cpy GR_WINDOW
|
||||
beq @has64k
|
||||
lda #8
|
||||
jsr check
|
||||
cpy GR_WINDOW
|
||||
beq @has128k
|
||||
lda #16
|
||||
jsr check
|
||||
cpy GR_WINDOW
|
||||
beq @has256k
|
||||
lda #32
|
||||
jsr check
|
||||
cpy GR_WINDOW
|
||||
beq @has512k
|
||||
lda #64
|
||||
jsr check
|
||||
cpy GR_WINDOW
|
||||
beq @has1024k
|
||||
lda #128
|
||||
jsr check
|
||||
cpy GR_WINDOW
|
||||
beq @has2048k
|
||||
ldx #>16384
|
||||
bne @setok
|
||||
|
||||
@has64k:
|
||||
ldx #>256
|
||||
bne @setok
|
||||
@has128k:
|
||||
ldx #>512
|
||||
bne @setok
|
||||
@has256k:
|
||||
ldx #>1024
|
||||
bne @setok
|
||||
@has512k:
|
||||
ldx #>2048
|
||||
bne @setok
|
||||
@has1024k:
|
||||
ldx #>4096
|
||||
bne @setok
|
||||
@has2048k:
|
||||
ldx #>8192
|
||||
bne @setok
|
||||
|
||||
@notpresent:
|
||||
lda #<EM_ERR_NO_DEVICE
|
||||
ldx #>EM_ERR_NO_DEVICE
|
||||
rts
|
||||
|
||||
@setok:
|
||||
lda #0
|
||||
sta pagecount
|
||||
stx pagecount+1
|
||||
lda #<EM_ERR_OK
|
||||
ldx #>EM_ERR_OK
|
||||
rts
|
||||
|
||||
check:
|
||||
ldx #0
|
||||
stx GR_PAGE_LO
|
||||
stx GR_PAGE_HI
|
||||
ldy GR_WINDOW
|
||||
iny
|
||||
sta GR_PAGE_HI
|
||||
sty GR_WINDOW
|
||||
ldx #0
|
||||
stx GR_PAGE_HI
|
||||
; 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 pagecount
|
||||
ldx pagecount+1
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; USE: Tell the driver that the window is now associated with a given page.
|
||||
; The GeoRAM 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 tmp1
|
||||
txa
|
||||
asl tmp1
|
||||
rol a
|
||||
asl tmp1
|
||||
rol a
|
||||
|
||||
sta GR_PAGE_HI
|
||||
lda tmp1
|
||||
lsr a
|
||||
lsr a
|
||||
sta GR_PAGE_LO
|
||||
|
||||
lda #<GR_WINDOW
|
||||
ldx #>GR_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
|
||||
|
||||
jmp @L5
|
||||
|
||||
@L1: lda GR_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 ; Bump low page register
|
||||
bit tmp1 ; Check for overflow in bit 6
|
||||
bvc @L6 ; Jump if no overflow
|
||||
inc tmp2
|
||||
@L5: lda tmp2
|
||||
sta GR_PAGE_HI
|
||||
@L6: lda tmp1
|
||||
sta GR_PAGE_LO
|
||||
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
|
||||
|
||||
jmp @L5
|
||||
|
||||
@L1: lda (ptr2),y
|
||||
sta GR_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 ; Bump low page register
|
||||
bit tmp1 ; Check for overflow in bit 6
|
||||
bvc @L6 ; Jump if no overflow
|
||||
inc tmp2
|
||||
@L5: lda tmp2
|
||||
sta GR_PAGE_HI
|
||||
@L6: lda tmp1
|
||||
sta GR_PAGE_LO
|
||||
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
|
||||
asl a
|
||||
rol tmp2
|
||||
asl a
|
||||
rol tmp2
|
||||
lsr a
|
||||
lsr a
|
||||
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
|
||||
|
||||
|
||||
288
libsrc/c128/emd/c128-ram.s
Normal file
288
libsrc/c128/emd/c128-ram.s
Normal file
@@ -0,0 +1,288 @@
|
||||
;
|
||||
; Extended memory driver for the C128 RAM in bank #1. Driver works without
|
||||
; problems when statically linked.
|
||||
;
|
||||
; 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 EMD_API_VERSION ; EM API version number
|
||||
|
||||
; Jump table.
|
||||
|
||||
.word INSTALL
|
||||
.word UNINSTALL
|
||||
.word PAGECOUNT
|
||||
.word MAP
|
||||
.word USE
|
||||
.word COMMIT
|
||||
.word COPYFROM
|
||||
.word COPYTO
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Constants
|
||||
|
||||
BASE = $400
|
||||
TOPMEM = $FF00
|
||||
PAGES = (TOPMEM - BASE) / 256
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
|
||||
.bss
|
||||
curpage: .res 1 ; Current page number
|
||||
|
||||
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:
|
||||
ldx #$FF
|
||||
stx curpage
|
||||
stx curpage+1 ; Invalidate the current page
|
||||
inx
|
||||
txa ; A = X = EM_ERR_OK
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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 #<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
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
ldy #$00
|
||||
@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
|
||||
|
||||
ldy #$00
|
||||
@L3: lda (ptr2),y
|
||||
ldx #MMU_CFG_RAM1
|
||||
jsr STASH
|
||||
iny
|
||||
dec tmp1
|
||||
bne @L3
|
||||
|
||||
; Done
|
||||
|
||||
@L4: rts
|
||||
|
||||
426
libsrc/c128/emd/c128-ram2.s
Normal file
426
libsrc/c128/emd/c128-ram2.s
Normal file
@@ -0,0 +1,426 @@
|
||||
;
|
||||
; Extended memory driver for the C128 RAM in banks #1, #2 and #3. Driver works without
|
||||
; problems when statically linked.
|
||||
;
|
||||
; Ullrich von Bassewitz, 2002-12-04
|
||||
;
|
||||
; Updated to use banks 2 and 3 as well by
|
||||
; Marco van den Heuvel, 2010-01-21
|
||||
;
|
||||
|
||||
.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 EMD_API_VERSION ; EM API version number
|
||||
|
||||
; Jump table.
|
||||
|
||||
.word INSTALL
|
||||
.word UNINSTALL
|
||||
.word PAGECOUNT
|
||||
.word MAP
|
||||
.word USE
|
||||
.word COMMIT
|
||||
.word COPYFROM
|
||||
.word COPYTO
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Constants
|
||||
|
||||
BASE = $400
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
|
||||
.bss
|
||||
curpage: .res 2 ; Current page number
|
||||
curbank: .res 1 ; Current bank number
|
||||
copybank: .res 2 ; temp bank number
|
||||
|
||||
window: .res 256 ; Memory "window"
|
||||
|
||||
pagecount: .res 2 ; Number of available pages
|
||||
|
||||
.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:
|
||||
ldx #0
|
||||
stx ptr1
|
||||
ldx #4
|
||||
stx ptr1+1
|
||||
ldx #<ptr1
|
||||
stx FETVEC
|
||||
stx STAVEC
|
||||
ldy #0
|
||||
ldx #MMU_CFG_RAM1
|
||||
jsr FETCH
|
||||
sta tmp1
|
||||
ldx #MMU_CFG_RAM3
|
||||
jsr FETCH
|
||||
cmp tmp1
|
||||
bne @has_4_banks
|
||||
tax
|
||||
inx
|
||||
txa
|
||||
ldx #MMU_CFG_RAM1
|
||||
jsr STASH
|
||||
ldx #MMU_CFG_RAM3
|
||||
jsr FETCH
|
||||
cmp tmp1
|
||||
beq @has_4_banks
|
||||
ldx #0
|
||||
lda #251
|
||||
bne @setok
|
||||
|
||||
@has_4_banks:
|
||||
ldx #2
|
||||
lda #241
|
||||
@setok:
|
||||
sta pagecount
|
||||
stx pagecount+1
|
||||
ldx #$FF
|
||||
stx curpage
|
||||
stx curpage+1 ; Invalidate the current page
|
||||
inx
|
||||
txa ; A = X = EM_ERR_OK
|
||||
; 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 pagecount
|
||||
ldx pagecount+1
|
||||
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: sei
|
||||
sta curpage
|
||||
stx curpage+1 ; Remember the new page
|
||||
|
||||
jsr calculate_bank_and_correct_page
|
||||
stx curbank
|
||||
|
||||
clc
|
||||
adc #>BASE
|
||||
sta ptr1+1
|
||||
ldy #$00
|
||||
sty ptr1
|
||||
lda #<ptr1
|
||||
sta FETVEC
|
||||
|
||||
; Transfer one page
|
||||
|
||||
@L1: ldx curbank
|
||||
jsr getcurbankmmu
|
||||
jsr FETCH
|
||||
sta window,y
|
||||
iny
|
||||
bne @L1
|
||||
|
||||
; Return the memory window
|
||||
|
||||
lda #<window
|
||||
ldx #>window ; Return the window address
|
||||
cli
|
||||
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
|
||||
ldx #>window ; Return the window
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; COMMIT: Commit changes in the memory window to extended storage.
|
||||
|
||||
COMMIT: sei
|
||||
lda curpage ; Get the current page
|
||||
ldx curpage+1
|
||||
bmi done ; Jump if no page mapped
|
||||
|
||||
jsr calculate_bank_and_correct_page
|
||||
stx curbank
|
||||
|
||||
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 curbank
|
||||
jsr getcurbankmmu
|
||||
jsr STASH
|
||||
iny
|
||||
bne @L1
|
||||
cli
|
||||
|
||||
; 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:
|
||||
sei
|
||||
jsr setup
|
||||
|
||||
; Setup is:
|
||||
;
|
||||
; - ptr1 contains the struct pointer
|
||||
; - ptr2 contains the linear memory buffer
|
||||
; - ptr3 contains -(count-1)
|
||||
; - ptr4 contains the page buffer and offset
|
||||
; - tmp1 contains the bank
|
||||
; - tmp2 contains zero (used for linear memory buffer offset)
|
||||
|
||||
lda #<ptr4
|
||||
sta FETVEC
|
||||
jmp @L3
|
||||
|
||||
@L1: ldx tmp1
|
||||
jsr getcurbankmmu
|
||||
ldy #0
|
||||
jsr FETCH
|
||||
ldy tmp2
|
||||
sta (ptr2),y
|
||||
inc tmp2
|
||||
bne @L2
|
||||
inc ptr2+1
|
||||
@L2: inc ptr4
|
||||
beq @L4
|
||||
|
||||
; Bump count and repeat
|
||||
|
||||
@L3: inc ptr3
|
||||
bne @L1
|
||||
inc ptr3+1
|
||||
bne @L1
|
||||
cli
|
||||
rts
|
||||
|
||||
; Bump page register
|
||||
|
||||
@L4: inc ptr4+1
|
||||
lda ptr4+1
|
||||
cmp #$ff
|
||||
bne @L3
|
||||
lda #4
|
||||
sta ptr4+1
|
||||
inc tmp1
|
||||
@L5:
|
||||
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:
|
||||
sei
|
||||
jsr setup
|
||||
|
||||
; Setup is:
|
||||
;
|
||||
; - ptr1 contains the struct pointer
|
||||
; - ptr2 contains the linear memory buffer
|
||||
; - ptr3 contains -(count-1)
|
||||
; - ptr4 contains the page buffer and offset
|
||||
; - tmp1 contains the bank
|
||||
; - tmp2 contains zero (used for linear memory buffer offset)
|
||||
|
||||
lda #<ptr4
|
||||
sta STAVEC
|
||||
jmp @L3
|
||||
|
||||
@L1:
|
||||
ldy tmp2
|
||||
lda (ptr2),y
|
||||
ldx tmp1
|
||||
jsr getcurbankmmu
|
||||
ldy #0
|
||||
jsr STASH
|
||||
inc tmp2
|
||||
bne @L2
|
||||
inc ptr2+1
|
||||
@L2: inc ptr4
|
||||
beq @L4
|
||||
|
||||
; Bump count and repeat
|
||||
|
||||
@L3: inc ptr3
|
||||
bne @L1
|
||||
inc ptr3+1
|
||||
bne @L1
|
||||
cli
|
||||
rts
|
||||
|
||||
; Bump page register
|
||||
|
||||
@L4: inc ptr4+1
|
||||
lda ptr4+1
|
||||
cmp #$ff
|
||||
bne @L3
|
||||
inc tmp1
|
||||
lda #4
|
||||
sta ptr4+1
|
||||
@L5:
|
||||
jmp @L3
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Helper function to calculate the correct bank and page
|
||||
; when addressing bank 2 or 3
|
||||
|
||||
calculate_bank_and_correct_page:
|
||||
cpx #2
|
||||
beq @calculate_bank_3_with_2
|
||||
cpx #1
|
||||
beq @calculate_bank_2_or_3_with_1
|
||||
sec
|
||||
sbc #251
|
||||
bcs @calculate_bank_2_with_0
|
||||
ldx #1
|
||||
lda curpage
|
||||
rts
|
||||
|
||||
@calculate_bank_3_with_2:
|
||||
lda curpage
|
||||
clc
|
||||
adc #10
|
||||
@calculate_bank_3_with_1:
|
||||
ldx #3
|
||||
rts
|
||||
|
||||
@calculate_bank_2_or_3_with_1:
|
||||
sec
|
||||
sbc #246
|
||||
bcs @calculate_bank_3_with_1
|
||||
lda curpage
|
||||
clc
|
||||
adc #5
|
||||
@calculate_bank_2_with_0:
|
||||
ldx #2
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Helper function to get the correct mmu value in x
|
||||
|
||||
getcurbankmmu:
|
||||
cpx #1
|
||||
beq @bank1
|
||||
cpx #2
|
||||
beq @bank2
|
||||
ldx #MMU_CFG_RAM3
|
||||
rts
|
||||
@bank2:
|
||||
ldx #MMU_CFG_RAM2
|
||||
rts
|
||||
@bank1:
|
||||
ldx #MMU_CFG_RAM1
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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: page pointer in ptr4 and bank in tmp1
|
||||
|
||||
ldy #EM_COPY::PAGE+1
|
||||
lda (ptr1),y
|
||||
tax
|
||||
dey
|
||||
lda (ptr1),y
|
||||
sta curpage
|
||||
jsr calculate_bank_and_correct_page
|
||||
clc
|
||||
adc #4
|
||||
sta ptr4+1
|
||||
stx 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 the low byte of ptr4 clear tmp2
|
||||
|
||||
ldy #EM_COPY::OFFS
|
||||
lda (ptr1),y
|
||||
sta ptr4
|
||||
lda #0
|
||||
sta tmp2
|
||||
|
||||
; Done
|
||||
|
||||
rts
|
||||
292
libsrc/c128/emd/c128-ramcart.s
Normal file
292
libsrc/c128/emd/c128-ramcart.s
Normal file
@@ -0,0 +1,292 @@
|
||||
;
|
||||
; Extended memory driver for the RamCart 64/128KB cartridge. Driver works
|
||||
; without problems when statically linked.
|
||||
; Code is based on GEORAM code by Ullrich von Bassewitz.
|
||||
; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl>
|
||||
; 06,22.12.2002
|
||||
;
|
||||
|
||||
|
||||
.include "zeropage.inc"
|
||||
|
||||
.include "em-kernel.inc"
|
||||
.include "em-error.inc"
|
||||
|
||||
|
||||
.macpack generic
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Header. Includes jump table
|
||||
|
||||
.segment "JUMPTABLE"
|
||||
|
||||
; Driver signature
|
||||
|
||||
.byte $65, $6d, $64 ; "emd"
|
||||
.byte EMD_API_VERSION ; EM API version number
|
||||
|
||||
; Jump table.
|
||||
|
||||
.word INSTALL
|
||||
.word UNINSTALL
|
||||
.word PAGECOUNT
|
||||
.word MAP
|
||||
.word USE
|
||||
.word COMMIT
|
||||
.word COPYFROM
|
||||
.word COPYTO
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Constants
|
||||
|
||||
RAMC_WINDOW = $DF00 ; Address of RamCart window
|
||||
RAMC_PAGE_LO = $DE00 ; Page register low
|
||||
RAMC_PAGE_HI = $DE01 ; Page register high (only for RC128)
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
|
||||
.bss
|
||||
|
||||
pagecount: .res 2 ; Number of pages available
|
||||
|
||||
.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:
|
||||
ldx RAMC_WINDOW
|
||||
cpx RAMC_WINDOW
|
||||
bne @notpresent
|
||||
|
||||
lda #0
|
||||
sta RAMC_PAGE_LO
|
||||
sta RAMC_PAGE_HI
|
||||
ldx RAMC_WINDOW
|
||||
cpx RAMC_WINDOW
|
||||
bne @notpresent
|
||||
lda #2
|
||||
sta RAMC_WINDOW
|
||||
cmp RAMC_WINDOW
|
||||
beq @cont
|
||||
cpx RAMC_WINDOW
|
||||
beq @readonly
|
||||
@cont: ldy #1
|
||||
sty RAMC_PAGE_HI
|
||||
sty RAMC_WINDOW
|
||||
dey
|
||||
sty RAMC_PAGE_HI
|
||||
iny
|
||||
cpy RAMC_WINDOW
|
||||
beq @rc64
|
||||
; we're on rc128
|
||||
ldx #>512
|
||||
bne @setsize
|
||||
@rc64: ldx #>256
|
||||
@setsize:
|
||||
lda #0
|
||||
sta pagecount
|
||||
stx pagecount+1
|
||||
lda #<EM_ERR_OK
|
||||
ldx #>EM_ERR_OK
|
||||
rts
|
||||
@notpresent:
|
||||
@readonly:
|
||||
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 pagecount
|
||||
ldx pagecount+1
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; USE: Tell the driver that the window is now associated with a given page.
|
||||
; The RamCart 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
|
||||
stx 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
|
||||
|
||||
jmp @L5
|
||||
|
||||
@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
|
||||
|
||||
jmp @L5
|
||||
|
||||
@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
|
||||
|
||||
236
libsrc/c128/emd/c128-reu.s
Normal file
236
libsrc/c128/emd/c128-reu.s
Normal file
@@ -0,0 +1,236 @@
|
||||
;
|
||||
; Extended memory driver for the Commodore REU. Driver works without
|
||||
; problems when statically linked.
|
||||
;
|
||||
; Ullrich von Bassewitz, 2002-11-29
|
||||
;
|
||||
|
||||
.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 EMD_API_VERSION ; EM API version number
|
||||
|
||||
; Jump table.
|
||||
|
||||
.word INSTALL
|
||||
.word UNINSTALL
|
||||
.word PAGECOUNT
|
||||
.word MAP
|
||||
.word USE
|
||||
.word COMMIT
|
||||
.word COPYFROM
|
||||
.word COPYTO
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
|
||||
.bss
|
||||
pagecount: .res 2 ; Number of pages available
|
||||
curpage: .res 2 ; Current page number
|
||||
|
||||
window: .res 256 ; Memory "window"
|
||||
|
||||
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.
|
||||
.byte $00 ; Adress control reg.
|
||||
|
||||
.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:
|
||||
ldx #$00 ; High byte of return code
|
||||
lda #$55
|
||||
sta REU_REUADDR
|
||||
cmp REU_REUADDR ; Check for presence of REU
|
||||
bne nodevice
|
||||
asl a ; A = $AA
|
||||
sta REU_REUADDR
|
||||
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
|
||||
|
||||
ldy #$FF
|
||||
sty curpage
|
||||
sty curpage+1 ; Invalidate the current page
|
||||
txa ; X = A = EM_ERR_OK
|
||||
rts
|
||||
|
||||
; No REU found
|
||||
|
||||
nodevice:
|
||||
lda #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 pagecount
|
||||
ldx pagecount+1
|
||||
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
|
||||
|
||||
ldy #OP_COPYFROM
|
||||
jsr common ; Copy the window
|
||||
|
||||
lda #<window
|
||||
ldx #>window ; Return the window address
|
||||
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
|
||||
ldx #>window ; Return the window
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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:
|
||||
sty REU_COMMAND ; Issue command
|
||||
|
||||
ldy MMU_CR ; Save the current MMU settings
|
||||
lda #MMU_CFG_RAM0 ;
|
||||
sei ;
|
||||
sta MMU_CR ; Enable RAM in bank #0
|
||||
lda REU_TRIGGER ; Don't change $FF00
|
||||
sta REU_TRIGGER ; Start the transfer...
|
||||
|
||||
sty MMU_CR ; Restore the old configuration
|
||||
cli
|
||||
rts
|
||||
|
||||
381
libsrc/c128/emd/c128-vdc.s
Normal file
381
libsrc/c128/emd/c128-vdc.s
Normal file
@@ -0,0 +1,381 @@
|
||||
;
|
||||
; Extended memory driver for the VDC RAM available on all C128 machines
|
||||
; (based on code by Ullrich von Bassewitz)
|
||||
; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl>
|
||||
; 06,20.12.2002
|
||||
|
||||
.include "zeropage.inc"
|
||||
|
||||
.include "em-kernel.inc"
|
||||
.include "em-error.inc"
|
||||
|
||||
|
||||
.macpack generic
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Header. Includes jump table
|
||||
|
||||
.segment "JUMPTABLE"
|
||||
|
||||
; Driver signature
|
||||
|
||||
.byte $65, $6d, $64 ; "emd"
|
||||
.byte EMD_API_VERSION ; EM API version number
|
||||
|
||||
; Jump table.
|
||||
|
||||
.word INSTALL
|
||||
.word DEINSTALL
|
||||
.word PAGECOUNT
|
||||
.word MAP
|
||||
.word USE
|
||||
.word COMMIT
|
||||
.word COPYFROM
|
||||
.word COPYTO
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Constants
|
||||
|
||||
VDC_ADDR_REG = $D600 ; VDC address
|
||||
VDC_DATA_REG = $D601 ; VDC data
|
||||
|
||||
VDC_DATA_HI = 18 ; used registers
|
||||
VDC_DATA_LO = 19
|
||||
VDC_CSET = 28
|
||||
VDC_DATA = 31
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
|
||||
.data
|
||||
|
||||
pagecount: .word 64 ; $0000-$3fff as 16k default
|
||||
curpage: .word $ffff ; currently mapped-in page (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:
|
||||
; do test for VDC presence here???
|
||||
|
||||
ldx #VDC_CSET ; determine size of RAM...
|
||||
jsr vdcgetreg
|
||||
sta tmp1
|
||||
ora #%00010000
|
||||
jsr vdcputreg ; turn on 64k
|
||||
|
||||
jsr settestadr1 ; save original value of test byte
|
||||
jsr vdcgetbyte
|
||||
sta tmp2
|
||||
|
||||
lda #$55 ; write $55 here
|
||||
ldy #ptr1
|
||||
jsr test64k ; read it here and there
|
||||
lda #$aa ; write $aa here
|
||||
ldy #ptr2
|
||||
jsr test64k ; read it here and there
|
||||
|
||||
jsr settestadr1
|
||||
lda tmp2
|
||||
jsr vdcputbyte ; restore original value of test byte
|
||||
|
||||
lda ptr1 ; do bytes match?
|
||||
cmp ptr1+1
|
||||
bne @have64k
|
||||
lda ptr2
|
||||
cmp ptr2+1
|
||||
bne @have64k
|
||||
|
||||
ldx #VDC_CSET
|
||||
lda tmp1
|
||||
jsr vdcputreg ; restore 16/64k flag
|
||||
jmp @endok ; and leave default values for 16k
|
||||
|
||||
@have64k:
|
||||
lda #<256
|
||||
ldx #>256
|
||||
sta pagecount
|
||||
stx pagecount+1
|
||||
@endok:
|
||||
lda #<EM_ERR_OK
|
||||
ldx #>EM_ERR_OK
|
||||
rts
|
||||
|
||||
test64k:
|
||||
sta tmp1
|
||||
sty ptr3
|
||||
lda #0
|
||||
sta ptr3+1
|
||||
jsr settestadr1
|
||||
lda tmp1
|
||||
jsr vdcputbyte ; write $55
|
||||
jsr settestadr1
|
||||
jsr vdcgetbyte ; read here
|
||||
pha
|
||||
jsr settestadr2
|
||||
jsr vdcgetbyte ; and there
|
||||
ldy #1
|
||||
sta (ptr3),y
|
||||
pla
|
||||
dey
|
||||
sta (ptr3),y
|
||||
rts
|
||||
|
||||
settestadr1:
|
||||
ldy #$02 ; test page 2 (here)
|
||||
.byte $2c
|
||||
settestadr2:
|
||||
ldy #$42 ; or page 64+2 (there)
|
||||
lda #0
|
||||
jmp vdcsetsrcaddr
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; DEINSTALL routine. Is called before the driver is removed from memory.
|
||||
; Can do cleanup or whatever. Must not return anything.
|
||||
;
|
||||
|
||||
DEINSTALL:
|
||||
;on C128 restore font and clear the screen?
|
||||
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
|
||||
; a/x. The contents of the currently mapped page (if any) may be discarded
|
||||
; by the driver.
|
||||
;
|
||||
|
||||
MAP: sta curpage
|
||||
stx curpage+1
|
||||
sta ptr1+1
|
||||
ldy #0
|
||||
sty ptr1
|
||||
|
||||
lda #<window
|
||||
sta ptr2
|
||||
lda #>window
|
||||
sta ptr2+1
|
||||
|
||||
jsr transferin
|
||||
|
||||
lda #<window
|
||||
ldx #>window
|
||||
rts
|
||||
|
||||
; copy a single page from (ptr1):VDCRAM to (ptr2):RAM
|
||||
|
||||
transferin:
|
||||
lda ptr1
|
||||
ldy ptr1+1
|
||||
jsr vdcsetsrcaddr ; set source address in VDC
|
||||
ldy #0
|
||||
ldx #VDC_DATA
|
||||
stx VDC_ADDR_REG
|
||||
@L0: bit VDC_ADDR_REG
|
||||
bpl @L0
|
||||
lda VDC_DATA_REG ; get 2 bytes at a time to speed-up
|
||||
sta (ptr2),y ; (in fact up to 8 bytes could be fetched with special VDC config)
|
||||
iny
|
||||
lda VDC_DATA_REG
|
||||
sta (ptr2),y
|
||||
iny
|
||||
bne @L0
|
||||
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
|
||||
ldx #>window ; Return the window
|
||||
done: rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; COMMIT: Commit changes in the memory window to extended storage.
|
||||
|
||||
COMMIT:
|
||||
lda curpage ; jump if no page mapped
|
||||
ldx curpage+1
|
||||
bmi done
|
||||
sta ptr1+1
|
||||
ldy #0
|
||||
sty ptr1
|
||||
|
||||
lda #<window
|
||||
sta ptr2
|
||||
lda #>window
|
||||
sta ptr2+1
|
||||
|
||||
; fall through to transferout
|
||||
|
||||
; copy a single page from (ptr2):RAM to (ptr1):VDCRAM
|
||||
|
||||
transferout:
|
||||
lda ptr1
|
||||
ldy ptr1+1
|
||||
jsr vdcsetsrcaddr ; set source address in VDC
|
||||
ldy #0
|
||||
ldx #VDC_DATA
|
||||
stx VDC_ADDR_REG
|
||||
@L0: bit VDC_ADDR_REG
|
||||
bpl @L0
|
||||
lda (ptr2),y ; speedup does not work for writing
|
||||
sta VDC_DATA_REG
|
||||
iny
|
||||
bne @L0
|
||||
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
|
||||
beq @L2 ; Skip if no full pages
|
||||
|
||||
; Copy full pages
|
||||
|
||||
@L1: jsr transferin
|
||||
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
|
||||
|
||||
; Transfer the bytes in the last page
|
||||
|
||||
ldy #0
|
||||
@L3: jsr vdcgetbyte
|
||||
sta (ptr2),y
|
||||
iny
|
||||
dec tmp1
|
||||
lda tmp1
|
||||
bne @L3
|
||||
@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:
|
||||
jsr setup
|
||||
beq @L2 ; Skip if no full pages
|
||||
|
||||
; Copy full pages
|
||||
|
||||
@L1: jsr transferout
|
||||
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
|
||||
|
||||
; Transfer the bytes in the last page
|
||||
|
||||
ldy #0
|
||||
@L3: lda (ptr2),y
|
||||
jsr vdcputbyte
|
||||
iny
|
||||
dec tmp1
|
||||
lda tmp1
|
||||
bne @L3
|
||||
@L4: rts
|
||||
|
||||
;-------------------------------------------------------------------------
|
||||
; Helper functions to handle VDC ram
|
||||
;
|
||||
|
||||
vdcsetsrcaddr:
|
||||
ldx #VDC_DATA_LO
|
||||
stx VDC_ADDR_REG
|
||||
@L0: bit VDC_ADDR_REG
|
||||
bpl @L0
|
||||
sta VDC_DATA_REG
|
||||
dex
|
||||
tya
|
||||
stx VDC_ADDR_REG
|
||||
sta VDC_DATA_REG
|
||||
rts
|
||||
|
||||
vdcgetbyte:
|
||||
ldx #VDC_DATA
|
||||
vdcgetreg:
|
||||
stx VDC_ADDR_REG
|
||||
@L0: bit VDC_ADDR_REG
|
||||
bpl @L0
|
||||
lda VDC_DATA_REG
|
||||
rts
|
||||
|
||||
vdcputbyte:
|
||||
ldx #VDC_DATA
|
||||
vdcputreg:
|
||||
stx VDC_ADDR_REG
|
||||
@L0: bit VDC_ADDR_REG
|
||||
bpl @L0
|
||||
sta VDC_DATA_REG
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Helper function for COPYFROM and COPYTO: Store the pointer to the request
|
||||
; structure and prepare data for the copy
|
||||
;
|
||||
|
||||
setup:
|
||||
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
|
||||
sta ptr1+1 ; From
|
||||
|
||||
ldy #EM_COPY::BUF
|
||||
lda (ptr3),y
|
||||
sta ptr2
|
||||
iny
|
||||
lda (ptr3),y
|
||||
sta ptr2+1 ; To
|
||||
|
||||
ldy #EM_COPY::COUNT+1
|
||||
lda (ptr3),y ; Get number of pages
|
||||
sta tmp1
|
||||
rts
|
||||
|
||||
Reference in New Issue
Block a user