2002-12-02 06:14:46 +00:00
|
|
|
;
|
2003-02-10 22:57:05 +00:00
|
|
|
; Extended memory driver for the GEORAM cartridge. Driver works without
|
|
|
|
; problems when statically linked.
|
2002-12-02 06:14:46 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2002-11-29
|
2010-02-01 07:20:06 +00:00
|
|
|
;
|
|
|
|
; GEORAM page size checking routine by
|
|
|
|
; Marco van den Heuvel, 2010-01-21
|
2002-12-02 06:14:46 +00:00
|
|
|
;
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
.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_georam_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
|
|
|
|
|
|
|
|
GR_WINDOW = $DE00 ; Address of GEORAM window
|
|
|
|
GR_PAGE_LO = $DFFE ; Page register low
|
|
|
|
GR_PAGE_HI = $DFFF ; Page register high
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data.
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
2010-02-01 07:20:06 +00:00
|
|
|
pagecount: .res 2 ; Number of available pages
|
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:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx GR_WINDOW
|
2010-02-01 07:20:06 +00:00
|
|
|
cpx GR_WINDOW
|
|
|
|
bne @notpresent
|
|
|
|
inc GR_WINDOW
|
2013-05-09 11:56:54 +00:00
|
|
|
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
|
2010-02-01 07:20:06 +00:00
|
|
|
bne @setok
|
|
|
|
|
|
|
|
@has64k:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #>256
|
|
|
|
bne @setok
|
2010-02-01 07:20:06 +00:00
|
|
|
@has128k:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #>512
|
|
|
|
bne @setok
|
2010-02-01 07:20:06 +00:00
|
|
|
@has256k:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #>1024
|
|
|
|
bne @setok
|
2010-02-01 07:20:06 +00:00
|
|
|
@has512k:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #>2048
|
|
|
|
bne @setok
|
2010-02-01 07:20:06 +00:00
|
|
|
@has1024k:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #>4096
|
|
|
|
bne @setok
|
2010-02-01 07:20:06 +00:00
|
|
|
@has2048k:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #>8192
|
|
|
|
bne @setok
|
2010-02-01 07:20:06 +00:00
|
|
|
|
|
|
|
@notpresent:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<EM_ERR_NO_DEVICE
|
|
|
|
ldx #>EM_ERR_NO_DEVICE
|
|
|
|
rts
|
2010-02-01 07:20:06 +00:00
|
|
|
|
|
|
|
@setok:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #0
|
|
|
|
sta pagecount
|
|
|
|
stx pagecount+1
|
|
|
|
lda #<EM_ERR_OK
|
|
|
|
ldx #>EM_ERR_OK
|
|
|
|
rts
|
2010-02-01 07:20:06 +00:00
|
|
|
|
|
|
|
check:
|
2013-05-09 11:56:54 +00:00
|
|
|
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
|
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
|
|
|
|
|
2002-12-05 18:57:53 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; 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
|
|
|
|
|
2002-12-02 06:14:46 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; 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.
|
|
|
|
|
2003-12-16 21:08:13 +00:00
|
|
|
ldy #EM_COPY::PAGE+1
|
2002-12-02 06:14:46 +00:00
|
|
|
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
|
|
|
|
|
2003-12-16 21:08:13 +00:00
|
|
|
ldy #EM_COPY::BUF
|
2002-12-02 06:14:46 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
sta ptr2
|
|
|
|
iny
|
|
|
|
lda (ptr1),y
|
2003-12-16 21:08:13 +00:00
|
|
|
sta ptr2+1
|
2002-12-02 06:14:46 +00:00
|
|
|
|
|
|
|
; Get the count, calculate -(count-1) and store it into ptr3
|
|
|
|
|
2003-12-16 21:08:13 +00:00
|
|
|
ldy #EM_COPY::COUNT
|
2002-12-02 06:14:46 +00:00
|
|
|
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
|
|
|
|
|
2003-12-16 21:08:13 +00:00
|
|
|
ldy #EM_COPY::OFFS
|
2002-12-02 06:14:46 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
tax
|
|
|
|
ldy #$00
|
|
|
|
|
|
|
|
; Done
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|