2006-08-17 19:50:23 +00:00
|
|
|
;
|
|
|
|
; Extended memory driver for the Apple II auxiliary memory
|
|
|
|
;
|
|
|
|
; Stefan Haubenthal, 2003-12-12
|
|
|
|
; Ullrich von Bassewitz, 2002-12-02
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
2006-08-17 19:50:23 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "em-kernel.inc"
|
|
|
|
.include "em-error.inc"
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Header. Includes jump table
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "JUMPTABLE"
|
2006-08-17 19:50:23 +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
|
2006-08-17 19:50:23 +00:00
|
|
|
|
2013-05-31 22:11:31 +00:00
|
|
|
; Library reference
|
2006-08-17 19:50:23 +00:00
|
|
|
|
2013-05-31 22:11:31 +00:00
|
|
|
.addr $0000
|
|
|
|
|
|
|
|
; Jump table
|
|
|
|
|
|
|
|
.addr INSTALL
|
|
|
|
.addr UNINSTALL
|
|
|
|
.addr PAGECOUNT
|
|
|
|
.addr MAP
|
|
|
|
.addr USE
|
|
|
|
.addr COMMIT
|
|
|
|
.addr COPYFROM
|
|
|
|
.addr COPYTO
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Constants
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
BASE = $0200
|
|
|
|
AUXCARD = $C30C ; Card signature
|
|
|
|
AUXMOVE = $C311 ; Auxiliary move routine
|
|
|
|
PAGES = ($C000 - BASE) / 256
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data.
|
|
|
|
|
|
|
|
.data
|
2013-05-09 11:56:54 +00:00
|
|
|
curpage: .byte $FF ; Current page number (invalid)
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
.bss
|
2013-05-09 11:56:54 +00:00
|
|
|
window: .res 256 ; Memory "window"
|
2006-08-17 19:50:23 +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 #0
|
|
|
|
lda AUXCARD
|
|
|
|
and #$f0
|
|
|
|
cmp #$80
|
|
|
|
bne @L1
|
|
|
|
lda #EM_ERR_OK
|
|
|
|
rts
|
|
|
|
@L1: lda #EM_ERR_NO_DEVICE
|
|
|
|
; rts
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2013-05-31 22:11:31 +00:00
|
|
|
; UNINSTALL routine. Is called before the driver is removed from memory.
|
2006-08-17 19:50:23 +00:00
|
|
|
; Can do cleanup or whatever. Must not return anything.
|
|
|
|
;
|
|
|
|
|
2013-05-31 22:11:31 +00:00
|
|
|
UNINSTALL:
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; PAGECOUNT: Return the total number of available pages in a/x.
|
|
|
|
;
|
|
|
|
|
|
|
|
PAGECOUNT:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<PAGES
|
|
|
|
ldx #>PAGES
|
|
|
|
rts
|
2006-08-17 19:50:23 +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.
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
MAP: sta curpage ; Remember the new page
|
2006-08-17 19:50:23 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
clc
|
|
|
|
adc #>BASE
|
|
|
|
sta ptr1+1
|
|
|
|
ldy #$00
|
|
|
|
sty ptr1
|
2006-08-17 19:50:23 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<window
|
|
|
|
sta ptr2
|
|
|
|
lda #>window
|
|
|
|
sta ptr2+1
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; Transfer one page
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
clc ; Direction flag
|
|
|
|
jsr transfer ; Transfer one page
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; Return the memory window
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<window
|
|
|
|
ldx #>window ; Return the window address
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; Done
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
done: rts
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; USE: Tell the driver that the window is now associated with a given page.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
USE: sta curpage ; Remember the page
|
|
|
|
lda #<window
|
|
|
|
ldx #>window ; Return the window
|
|
|
|
rts
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; COMMIT: Commit changes in the memory window to extended storage.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
COMMIT: lda curpage ; Get the current page
|
|
|
|
cmp #$FF
|
|
|
|
beq done ; Jump if no page mapped
|
|
|
|
|
|
|
|
clc
|
|
|
|
adc #>BASE
|
|
|
|
sta ptr2+1
|
|
|
|
ldy #$00
|
|
|
|
sty ptr2
|
|
|
|
|
|
|
|
lda #<window
|
|
|
|
sta ptr1
|
|
|
|
lda #>window
|
|
|
|
sta ptr1+1
|
|
|
|
lda #<$FF
|
|
|
|
sta ptr4
|
|
|
|
lda #>$FF
|
|
|
|
sta ptr4+1
|
|
|
|
sec ; Direction flag
|
2006-08-17 19:50:23 +00:00
|
|
|
|
|
|
|
; Transfer one page/all bytes
|
|
|
|
|
|
|
|
transfer:
|
2013-05-09 11:56:54 +00:00
|
|
|
php
|
|
|
|
clc
|
|
|
|
lda ptr1
|
|
|
|
sta $3C
|
|
|
|
adc ptr4
|
|
|
|
sta $3E
|
|
|
|
lda ptr1+1
|
|
|
|
sta $3D
|
|
|
|
adc ptr4+1
|
|
|
|
sta $3F
|
|
|
|
lda ptr2
|
|
|
|
sta $42
|
|
|
|
lda ptr2+1
|
|
|
|
sta $43
|
|
|
|
plp
|
|
|
|
jmp AUXMOVE
|
2006-08-17 19:50:23 +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:
|
2013-05-09 11:56:54 +00:00
|
|
|
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
|
|
|
|
clc ; Direction flag
|
|
|
|
|
|
|
|
common: ldy #EM_COPY::COUNT
|
|
|
|
lda (ptr3),y ; Get bytes in last page
|
|
|
|
sta ptr4
|
|
|
|
iny
|
|
|
|
lda (ptr3),y ; Get number of pages
|
|
|
|
sta ptr4+1
|
|
|
|
|
|
|
|
jmp transfer
|
2006-08-17 19:50:23 +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.
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
COPYTO: sta ptr3
|
|
|
|
stx ptr3+1 ; Save the passed em_copy pointer
|
|
|
|
|
|
|
|
ldy #EM_COPY::OFFS
|
|
|
|
lda (ptr3),y
|
|
|
|
sta ptr2
|
|
|
|
ldy #EM_COPY::PAGE
|
|
|
|
lda (ptr3),y
|
|
|
|
clc
|
|
|
|
adc #>BASE
|
|
|
|
sta ptr2+1 ; To
|
|
|
|
|
|
|
|
ldy #EM_COPY::BUF
|
|
|
|
lda (ptr3),y
|
|
|
|
sta ptr1
|
|
|
|
iny
|
|
|
|
lda (ptr3),y
|
|
|
|
sta ptr1+1 ; From
|
|
|
|
|
|
|
|
sec ; Direction flag
|
|
|
|
jmp common
|