2010-02-02 18:32:34 +00:00
|
|
|
;
|
|
|
|
; Extended memory driver for the ISEPIC cartridge.
|
|
|
|
; Marco van den Heuvel, 2010-01-24
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
2010-02-02 18:32:34 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "em-kernel.inc"
|
|
|
|
.include "em-error.inc"
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.macpack generic
|
2014-06-04 21:50:18 +00:00
|
|
|
.macpack module
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Header. Includes jump table
|
|
|
|
|
2014-06-04 21:50:18 +00:00
|
|
|
module_header _c64_isepic_emd
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Driver signature
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte $65, $6d, $64 ; "emd"
|
|
|
|
.byte EMD_API_VERSION ; EM API version number
|
2010-02-02 18:32:34 +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
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Constants
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
IP_WINDOW = $DF00 ; Address of ISEPIC window
|
2010-02-02 18:32:34 +00:00
|
|
|
IP_CTRL_BASE = $DE00
|
|
|
|
PAGES = 8
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Code.
|
|
|
|
|
|
|
|
.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
|
|
|
lda #0
|
|
|
|
sta IP_CTRL_BASE
|
|
|
|
ldx IP_WINDOW
|
|
|
|
cpx IP_WINDOW
|
|
|
|
bne @notpresent
|
|
|
|
inc IP_WINDOW
|
|
|
|
cpx IP_WINDOW
|
|
|
|
beq @notpresent
|
|
|
|
ldx IP_WINDOW
|
|
|
|
sta IP_CTRL_BASE+1
|
2010-02-02 18:32:34 +00:00
|
|
|
inx
|
2013-05-09 11:56:54 +00:00
|
|
|
stx IP_WINDOW
|
2010-02-02 18:32:34 +00:00
|
|
|
dex
|
2013-05-09 11:56:54 +00:00
|
|
|
sta IP_CTRL_BASE
|
|
|
|
cpx IP_WINDOW
|
|
|
|
beq @setok
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
@notpresent:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<EM_ERR_NO_DEVICE
|
|
|
|
ldx #>EM_ERR_NO_DEVICE
|
2010-02-02 18:32:34 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
@setok:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<EM_ERR_OK
|
|
|
|
ldx #>EM_ERR_OK
|
|
|
|
; rts ; Run into UNINSTALL instead
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; 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:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<PAGES
|
|
|
|
ldx #>PAGES
|
2010-02-02 18:32:34 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; USE: Tell the driver that the window is now associated with a given page.
|
|
|
|
; The Isepic 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:
|
|
|
|
tax
|
2013-05-09 11:56:54 +00:00
|
|
|
sta IP_CTRL_BASE,x
|
|
|
|
lda #<IP_WINDOW
|
|
|
|
ldx #>IP_WINDOW
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; 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:
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr setup
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Setup is:
|
|
|
|
;
|
|
|
|
; - ptr1 contains the struct pointer
|
|
|
|
; - ptr2 contains the linear memory buffer
|
|
|
|
; - ptr3 contains -(count-1)
|
|
|
|
; - tmp1 contains the low page register value
|
|
|
|
; - X contains the page offset
|
|
|
|
; - Y contains zero
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jmp @L5
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
@L1:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda IP_WINDOW,x
|
|
|
|
sta (ptr2),y
|
2010-02-02 18:32:34 +00:00
|
|
|
iny
|
2013-05-09 11:56:54 +00:00
|
|
|
bne @L2
|
|
|
|
inc ptr2+1
|
2010-02-02 18:32:34 +00:00
|
|
|
@L2:
|
|
|
|
inx
|
2013-05-09 11:56:54 +00:00
|
|
|
beq @L4
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Bump count and repeat
|
|
|
|
|
|
|
|
@L3:
|
2013-05-09 11:56:54 +00:00
|
|
|
inc ptr3
|
|
|
|
bne @L1
|
|
|
|
inc ptr3+1
|
|
|
|
bne @L1
|
2010-02-02 18:32:34 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; Bump page register
|
|
|
|
|
|
|
|
@L4:
|
2013-05-09 11:56:54 +00:00
|
|
|
inc tmp1 ; Bump low page register
|
2010-02-02 18:32:34 +00:00
|
|
|
@L5:
|
2013-05-09 11:56:54 +00:00
|
|
|
stx tmp2
|
|
|
|
ldx tmp1
|
|
|
|
sta IP_CTRL_BASE,x
|
|
|
|
ldx tmp2
|
|
|
|
jmp @L3
|
2010-02-02 18:32:34 +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.
|
|
|
|
;
|
|
|
|
|
|
|
|
COPYTO:
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr setup
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Setup is:
|
|
|
|
;
|
|
|
|
; - ptr1 contains the struct pointer
|
|
|
|
; - ptr2 contains the linear memory buffer
|
|
|
|
; - ptr3 contains -(count-1)
|
|
|
|
; - tmp1 contains the low page register value
|
|
|
|
; - X contains the page offset
|
|
|
|
; - Y contains zero
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jmp @L5
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
@L1:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr2),y
|
|
|
|
sta IP_WINDOW,x
|
2010-02-02 18:32:34 +00:00
|
|
|
iny
|
2013-05-09 11:56:54 +00:00
|
|
|
bne @L2
|
|
|
|
inc ptr2+1
|
2010-02-02 18:32:34 +00:00
|
|
|
@L2:
|
|
|
|
inx
|
2013-05-09 11:56:54 +00:00
|
|
|
beq @L4
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Bump count and repeat
|
|
|
|
|
|
|
|
@L3:
|
2013-05-09 11:56:54 +00:00
|
|
|
inc ptr3
|
|
|
|
bne @L1
|
|
|
|
inc ptr3+1
|
|
|
|
bne @L1
|
2010-02-02 18:32:34 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; Bump page register
|
|
|
|
|
|
|
|
@L4:
|
2013-05-09 11:56:54 +00:00
|
|
|
inc tmp1 ; Bump page register
|
2010-02-02 18:32:34 +00:00
|
|
|
@L5:
|
2013-05-09 11:56:54 +00:00
|
|
|
stx tmp2
|
|
|
|
ldx tmp1
|
|
|
|
sta IP_CTRL_BASE,x
|
|
|
|
ldx tmp2
|
|
|
|
jmp @L3
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Helper function for COPYFROM and COPYTO: Store the pointer to the request
|
|
|
|
; structure and prepare data for the copy
|
|
|
|
|
|
|
|
setup:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1 ; Save passed pointer
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Get the page number from the struct and remember it.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #EM_COPY::PAGE
|
|
|
|
lda (ptr1),y
|
|
|
|
sta tmp1
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Get the buffer pointer into ptr2
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #EM_COPY::BUF
|
|
|
|
lda (ptr1),y
|
|
|
|
sta ptr2
|
2010-02-02 18:32:34 +00:00
|
|
|
iny
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
sta ptr2+1
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Get the count, calculate -(count-1) and store it into ptr3
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #EM_COPY::COUNT
|
|
|
|
lda (ptr1),y
|
|
|
|
eor #$FF
|
|
|
|
sta ptr3
|
2010-02-02 18:32:34 +00:00
|
|
|
iny
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
eor #$FF
|
|
|
|
sta ptr3+1
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Get the page offset into X and clear Y
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #EM_COPY::OFFS
|
|
|
|
lda (ptr1),y
|
2010-02-02 18:32:34 +00:00
|
|
|
tax
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #0
|
2010-02-02 18:32:34 +00:00
|
|
|
|
|
|
|
; Done
|
|
|
|
|
|
|
|
rts
|