From 7df35cac945232fc20043b989e1e31ffbcd6a7d4 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Mon, 30 Nov 2015 09:53:30 -0800 Subject: [PATCH 1/5] Started on making c128 function ram emd's. --- asminc/c128.inc | 14 +- libsrc/c128/emd/c128-ifnram.s | 297 ++++++++++++++++++++++++++++++++++ testcode/lib/em-test.c | 1 + 3 files changed, 306 insertions(+), 6 deletions(-) create mode 100755 libsrc/c128/emd/c128-ifnram.s diff --git a/asminc/c128.inc b/asminc/c128.inc index 6e3078297..baee2ac72 100644 --- a/asminc/c128.inc +++ b/asminc/c128.inc @@ -198,12 +198,14 @@ CIA2_CRB := $DD0F ; --------------------------------------------------------------------------- ; I/O: MMU -MMU_CR := $FF00 -MMU_CFG_CC65 := %00001110 ; Bank 0 with kernal ROM -MMU_CFG_RAM0 := %00111111 ; Bank 0 full RAM -MMU_CFG_RAM1 := %01111111 ; Bank 1 full RAM -MMU_CFG_RAM2 := %10111111 ; Bank 2 full RAM -MMU_CFG_RAM3 := %11111111 ; Bank 3 full RAM +MMU_CR := $FF00 +MMU_CFG_CC65 := %00001110 ; Bank 0 with kernal ROM +MMU_CFG_RAM0 := %00111111 ; Bank 0 full RAM +MMU_CFG_RAM1 := %01111111 ; Bank 1 full RAM +MMU_CFG_RAM2 := %10111111 ; Bank 2 full RAM +MMU_CFG_RAM3 := %11111111 ; Bank 3 full RAM +MMU_CFG_INT_FROM := %00010111 ; Bank 0 with Internal Function RAM/ROM +MMU_CFG_EXT_FROM := %00101011 ; Bank 0 with External Function RAM/ROM ; --------------------------------------------------------------------------- ; Super CPU diff --git a/libsrc/c128/emd/c128-ifnram.s b/libsrc/c128/emd/c128-ifnram.s new file mode 100755 index 000000000..774678f33 --- /dev/null +++ b/libsrc/c128/emd/c128-ifnram.s @@ -0,0 +1,297 @@ +; +; Extended memory driver for the C128 Internal 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_ifnram_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 = 128 + +; ------------------------------------------------------------------------ +; 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 #$FF + stx curpage + stx curpage+1 ; Invalidate the current page + inx + txa ; A = X = EM_ERR_OK + +; ------------------------------------------------------------------------ +; 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 + 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 + + clc + adc #>BASE + sta ptr1+1 + ldy #$00 + sty ptr1 + + lda #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 ; 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 + + 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 # Date: Mon, 30 Nov 2015 20:14:45 -0800 Subject: [PATCH 2/5] Finished adding c128 internal/external function ram emd's. --- asminc/c128.inc | 4 +- libsrc/c128/emd/c128-efnram.s | 326 ++++++++++++++++++++++++++++++++++ libsrc/c128/emd/c128-ifnram.s | 31 +++- testcode/lib/em-test.c | 1 + 4 files changed, 359 insertions(+), 3 deletions(-) create mode 100755 libsrc/c128/emd/c128-efnram.s diff --git a/asminc/c128.inc b/asminc/c128.inc index baee2ac72..124552647 100644 --- a/asminc/c128.inc +++ b/asminc/c128.inc @@ -204,8 +204,8 @@ MMU_CFG_RAM0 := %00111111 ; Bank 0 full RAM MMU_CFG_RAM1 := %01111111 ; Bank 1 full RAM MMU_CFG_RAM2 := %10111111 ; Bank 2 full RAM MMU_CFG_RAM3 := %11111111 ; Bank 3 full RAM -MMU_CFG_INT_FROM := %00010111 ; Bank 0 with Internal Function RAM/ROM -MMU_CFG_EXT_FROM := %00101011 ; Bank 0 with External Function RAM/ROM +MMU_CFG_INT_FROM := %01010111 ; Bank 1 with Internal Function RAM/ROM +MMU_CFG_EXT_FROM := %01101011 ; Bank 1 with External Function RAM/ROM ; --------------------------------------------------------------------------- ; Super CPU diff --git a/libsrc/c128/emd/c128-efnram.s b/libsrc/c128/emd/c128-efnram.s new file mode 100755 index 000000000..4d179da83 --- /dev/null +++ b/libsrc/c128/emd/c128-efnram.s @@ -0,0 +1,326 @@ +; +; 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: + sei + ldx #0 + stx ptr1 + ldx #$80 + stx ptr1+1 + ldx #EM_ERR_NO_DEVICE + cli + rts + +@ram_present: + ldx #$FF + stx curpage + stx curpage+1 ; Invalidate the current page + inx + txa ; A = X = EM_ERR_OK + cli +; 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 #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: sei + 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 + 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 ; 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 + + 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 #EM_ERR_NO_DEVICE + cli + rts + +@ram_present: ldx #$FF stx curpage stx curpage+1 ; Invalidate the current page inx txa ; A = X = EM_ERR_OK + cli +; rts ; Run into UNINSTALL instead ; ------------------------------------------------------------------------ ; UNINSTALL routine. Is called before the driver is removed from memory. diff --git a/testcode/lib/em-test.c b/testcode/lib/em-test.c index d6683f550..230e87f57 100644 --- a/testcode/lib/em-test.c +++ b/testcode/lib/em-test.c @@ -97,6 +97,7 @@ static emd_test_t drivers[] = { { '4', "REU", "c128-reu.emd" }, { '5', "VDC", "c128-vdc.emd" }, { '6', "Internal Function RAM", "c128-ifnram.emd" }, + { '7', "External Function RAM", "c128-efnram.emd" }, #endif #if defined(__CBM510__) From 83c63a65c3766daaafbcd6a48b7cfb472b2de21e Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Wed, 2 Dec 2015 00:14:56 -0800 Subject: [PATCH 3/5] optimized the sei/cli pairing a bit. --- libsrc/c128/emd/c128-efnram.s | 27 +++++++++++++-------------- libsrc/c128/emd/c128-ifnram.s | 31 +++++++++++++++---------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/libsrc/c128/emd/c128-efnram.s b/libsrc/c128/emd/c128-efnram.s index 4d179da83..78882fa6e 100755 --- a/libsrc/c128/emd/c128-efnram.s +++ b/libsrc/c128/emd/c128-efnram.s @@ -64,7 +64,6 @@ window: .res 256 ; Memory "window" ; INSTALL: - sei ldx #0 stx ptr1 ldx #$80 @@ -74,20 +73,22 @@ INSTALL: stx STAVEC ldy #0 ldx #MMU_CFG_EXT_FROM + sei jsr FETCH tax inx txa sta tmp1 ldx #MMU_CFG_EXT_FROM + sei jsr STASH ldx #MMU_CFG_EXT_FROM jsr FETCH + cli cmp tmp1 beq @ram_present lda #EM_ERR_NO_DEVICE - cli rts @ram_present: @@ -96,7 +97,6 @@ INSTALL: stx curpage+1 ; Invalidate the current page inx txa ; A = X = EM_ERR_OK - cli ; rts ; Run into UNINSTALL instead ; ------------------------------------------------------------------------ @@ -123,8 +123,7 @@ PAGECOUNT: ; by the driver. ; -MAP: sei - sta curpage +MAP: sta curpage stx curpage+1 ; Remember the new page clc @@ -135,6 +134,7 @@ MAP: sei lda #window ; Return the window address - cli rts ; ------------------------------------------------------------------------ @@ -163,8 +163,7 @@ USE: sta curpage ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. -COMMIT: sei - lda curpage ; Get the current page +COMMIT: lda curpage ; Get the current page ldx curpage+1 bmi done ; Jump if no page mapped @@ -176,6 +175,7 @@ COMMIT: sei lda #EM_ERR_NO_DEVICE - cli rts @ram_present: @@ -96,7 +97,6 @@ INSTALL: stx curpage+1 ; Invalidate the current page inx txa ; A = X = EM_ERR_OK - cli ; rts ; Run into UNINSTALL instead ; ------------------------------------------------------------------------ @@ -123,8 +123,7 @@ PAGECOUNT: ; by the driver. ; -MAP: sei - sta curpage +MAP: sta curpage stx curpage+1 ; Remember the new page clc @@ -135,6 +134,7 @@ MAP: sei lda #window ; Return the window address - cli rts ; ------------------------------------------------------------------------ @@ -163,8 +163,7 @@ USE: sta curpage ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. -COMMIT: sei - lda curpage ; Get the current page +COMMIT: lda curpage ; Get the current page ldx curpage+1 bmi done ; Jump if no page mapped @@ -176,6 +175,7 @@ COMMIT: sei lda # Date: Wed, 2 Dec 2015 00:17:29 -0800 Subject: [PATCH 4/5] optimized the sei/cli pairing a bit for internal function ram emd as well. --- libsrc/c128/emd/c128-ifnram.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/c128/emd/c128-ifnram.s b/libsrc/c128/emd/c128-ifnram.s index ad482e663..7cdbb8818 100755 --- a/libsrc/c128/emd/c128-ifnram.s +++ b/libsrc/c128/emd/c128-ifnram.s @@ -1,5 +1,5 @@ ; -; Extended memory driver for the C128 External Function RAM. Driver works +; Extended memory driver for the C128 Internal Function RAM. Driver works ; without problems when statically linked. ; ; Marco van den Heuvel, 2015-11-30 @@ -18,7 +18,7 @@ ; ------------------------------------------------------------------------ ; Header. Includes jump table - module_header _c128_efnram_emd + module_header _c128_ifnram_emd ; Driver signature From 433eeb1bc79e4292d63a75e268e9e15c1cc104ad Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Wed, 2 Dec 2015 00:30:30 -0800 Subject: [PATCH 5/5] Renamed MMU_CFG_INT_FROM -> MMU_CFG_IFROM and MMU_CFG_EXT_FROM -> MMU_CFG_EFROM --- asminc/c128.inc | 16 ++++++++-------- libsrc/c128/emd/c128-efnram.s | 18 +++++++++--------- libsrc/c128/emd/c128-ifnram.s | 18 +++++++++--------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/asminc/c128.inc b/asminc/c128.inc index 124552647..e6c89b07b 100644 --- a/asminc/c128.inc +++ b/asminc/c128.inc @@ -198,14 +198,14 @@ CIA2_CRB := $DD0F ; --------------------------------------------------------------------------- ; I/O: MMU -MMU_CR := $FF00 -MMU_CFG_CC65 := %00001110 ; Bank 0 with kernal ROM -MMU_CFG_RAM0 := %00111111 ; Bank 0 full RAM -MMU_CFG_RAM1 := %01111111 ; Bank 1 full RAM -MMU_CFG_RAM2 := %10111111 ; Bank 2 full RAM -MMU_CFG_RAM3 := %11111111 ; Bank 3 full RAM -MMU_CFG_INT_FROM := %01010111 ; Bank 1 with Internal Function RAM/ROM -MMU_CFG_EXT_FROM := %01101011 ; Bank 1 with External Function RAM/ROM +MMU_CR := $FF00 +MMU_CFG_CC65 := %00001110 ; Bank 0 with kernal ROM +MMU_CFG_RAM0 := %00111111 ; Bank 0 full RAM +MMU_CFG_RAM1 := %01111111 ; Bank 1 full RAM +MMU_CFG_RAM2 := %10111111 ; Bank 2 full RAM +MMU_CFG_RAM3 := %11111111 ; Bank 3 full RAM +MMU_CFG_IFROM := %01010111 ; Bank 1 with Internal Function RAM/ROM +MMU_CFG_EFROM := %01101011 ; Bank 1 with External Function RAM/ROM ; --------------------------------------------------------------------------- ; Super CPU diff --git a/libsrc/c128/emd/c128-efnram.s b/libsrc/c128/emd/c128-efnram.s index 78882fa6e..788c73e0f 100755 --- a/libsrc/c128/emd/c128-efnram.s +++ b/libsrc/c128/emd/c128-efnram.s @@ -72,17 +72,17 @@ INSTALL: stx FETVEC stx STAVEC ldy #0 - ldx #MMU_CFG_EXT_FROM + ldx #MMU_CFG_EFROM sei jsr FETCH tax inx txa sta tmp1 - ldx #MMU_CFG_EXT_FROM + ldx #MMU_CFG_EFROM sei jsr STASH - ldx #MMU_CFG_EXT_FROM + ldx #MMU_CFG_EFROM jsr FETCH cli cmp tmp1 @@ -138,7 +138,7 @@ MAP: sta curpage ; Transfer one page -@L1: ldx #MMU_CFG_EXT_FROM +@L1: ldx #MMU_CFG_EFROM jsr FETCH sta window,y iny @@ -180,7 +180,7 @@ COMMIT: lda curpage ; Get the current page ; Transfer one page. Y must be zero on entry @L1: lda window,y - ldx #MMU_CFG_EXT_FROM + ldx #MMU_CFG_EFROM jsr STASH iny bne @L1 @@ -228,7 +228,7 @@ COPYFROM: ldy #$00 sei -@L1: ldx #MMU_CFG_EXT_FROM +@L1: ldx #MMU_CFG_EFROM jsr FETCH sta (ptr2),y iny @@ -246,7 +246,7 @@ COPYFROM: sta tmp1 ldy #$00 -@L3: ldx #MMU_CFG_EXT_FROM +@L3: ldx #MMU_CFG_EFROM jsr FETCH sta (ptr2),y iny @@ -295,7 +295,7 @@ COPYTO: sta ptr3 sei ldy #$00 @L1: lda (ptr2),y - ldx #MMU_CFG_EXT_FROM + ldx #MMU_CFG_EFROM jsr STASH iny bne @L1 @@ -313,7 +313,7 @@ COPYTO: sta ptr3 ldy #$00 @L3: lda (ptr2),y - ldx #MMU_CFG_EXT_FROM + ldx #MMU_CFG_EFROM jsr STASH iny dec tmp1 diff --git a/libsrc/c128/emd/c128-ifnram.s b/libsrc/c128/emd/c128-ifnram.s index 7cdbb8818..01a4fdf8e 100755 --- a/libsrc/c128/emd/c128-ifnram.s +++ b/libsrc/c128/emd/c128-ifnram.s @@ -72,17 +72,17 @@ INSTALL: stx FETVEC stx STAVEC ldy #0 - ldx #MMU_CFG_INT_FROM + ldx #MMU_CFG_IFROM sei jsr FETCH tax inx txa sta tmp1 - ldx #MMU_CFG_INT_FROM + ldx #MMU_CFG_IFROM sei jsr STASH - ldx #MMU_CFG_INT_FROM + ldx #MMU_CFG_IFROM jsr FETCH cli cmp tmp1 @@ -138,7 +138,7 @@ MAP: sta curpage ; Transfer one page -@L1: ldx #MMU_CFG_INT_FROM +@L1: ldx #MMU_CFG_IFROM jsr FETCH sta window,y iny @@ -180,7 +180,7 @@ COMMIT: lda curpage ; Get the current page ; Transfer one page. Y must be zero on entry @L1: lda window,y - ldx #MMU_CFG_INT_FROM + ldx #MMU_CFG_IFROM jsr STASH iny bne @L1 @@ -228,7 +228,7 @@ COPYFROM: ldy #$00 sei -@L1: ldx #MMU_CFG_INT_FROM +@L1: ldx #MMU_CFG_IFROM jsr FETCH sta (ptr2),y iny @@ -246,7 +246,7 @@ COPYFROM: sta tmp1 ldy #$00 -@L3: ldx #MMU_CFG_INT_FROM +@L3: ldx #MMU_CFG_IFROM jsr FETCH sta (ptr2),y iny @@ -295,7 +295,7 @@ COPYTO: sta ptr3 sei ldy #$00 @L1: lda (ptr2),y - ldx #MMU_CFG_INT_FROM + ldx #MMU_CFG_IFROM jsr STASH iny bne @L1 @@ -313,7 +313,7 @@ COPYTO: sta ptr3 ldy #$00 @L3: lda (ptr2),y - ldx #MMU_CFG_INT_FROM + ldx #MMU_CFG_IFROM jsr STASH iny dec tmp1