; ; Extended memory driver for the C128 External Function RAM. Driver works ; without problems when statically linked. ; ; Marco van den Heuvel, 2015-11-30 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .include "c128.inc" .macpack generic .macpack module ; ------------------------------------------------------------------------ ; Header. Includes jump table module_header _c128_efnram_emd ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Library reference .addr $0000 ; Jump table .addr INSTALL .addr UNINSTALL .addr PAGECOUNT .addr MAP .addr USE .addr COMMIT .addr COPYFROM .addr COPYTO ; ------------------------------------------------------------------------ ; Constants BASE = $8000 PAGES = 127 ; Do not touch MMU ; ------------------------------------------------------------------------ ; Data. .bss curpage: .res 2 ; 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 #0 stx ptr1 ldx #$80 stx ptr1+1 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 #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 ; 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 #BASE sta ptr1+1 ; From ldy #EM_COPY::BUF lda (ptr3),y sta ptr2 iny lda (ptr3),y sta ptr2+1 ; To lda #BASE sta ptr1+1 ; To ldy #EM_COPY::BUF lda (ptr3),y sta ptr2 iny lda (ptr3),y sta ptr2+1 ; From lda #