From 1524b0c13f4672a8f29ef7f4cc78f14064c96844 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 1 Feb 2010 17:56:37 +0000 Subject: [PATCH] Added code to the driver to use also banks 2 and 3 if present. Contributed by Marco van den Heuvel. git-svn-id: svn://svn.cc65.org/cc65/trunk@4569 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/c128/c128-ram.s | 362 ++++++++++++++++++++++++++++------------- 1 file changed, 250 insertions(+), 112 deletions(-) diff --git a/libsrc/c128/c128-ram.s b/libsrc/c128/c128-ram.s index 1211c444d..6b384392c 100644 --- a/libsrc/c128/c128-ram.s +++ b/libsrc/c128/c128-ram.s @@ -1,8 +1,11 @@ ; -; Extended memory driver for the C128 RAM in bank #1. Driver works without +; Extended memory driver for the C128 RAM in banks #1, #2 and #3. Driver works without ; problems when statically linked. ; ; Ullrich von Bassewitz, 2002-12-04 +; +; Updated to use banks 2 and 3 as well by +; Marco van den Heuvel, 2010-01-21 ; .include "zeropage.inc" @@ -40,17 +43,19 @@ ; Constants BASE = $400 -TOPMEM = $FF00 -PAGES = (TOPMEM - BASE) / 256 ; ------------------------------------------------------------------------ ; Data. .bss -curpage: .res 1 ; Current page number +curpage: .res 2 ; Current page number +curbank: .res 1 ; Current bank number +copybank: .res 2 ; temp bank number window: .res 256 ; Memory "window" +pagecount: .res 2 ; Number of available pages + .code ; ------------------------------------------------------------------------ @@ -61,12 +66,46 @@ window: .res 256 ; Memory "window" ; INSTALL: + ldx #0 + stx ptr1 + ldx #4 + stx ptr1+1 + ldx #PAGES + lda pagecount + ldx pagecount+1 rts ; ------------------------------------------------------------------------ @@ -92,21 +131,25 @@ PAGECOUNT: ; by the driver. ; -MAP: sta curpage +MAP: sei + sta curpage stx curpage+1 ; Remember the new page - clc - adc #>BASE - sta ptr1+1 - ldy #$00 - sty ptr1 + jsr calculate_bank_and_correct_page + stx curbank + clc + adc #>BASE + sta ptr1+1 + ldy #$00 + sty ptr1 lda #window ; Return the window address + cli rts ; ------------------------------------------------------------------------ @@ -130,15 +174,19 @@ USE: sta curpage ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. -COMMIT: lda curpage ; Get the current page +COMMIT: sei + lda curpage ; Get the current page ldx curpage+1 bmi done ; Jump if no page mapped + jsr calculate_bank_and_correct_page + stx curbank + clc adc #>BASE sta ptr1+1 ldy #$00 - sty ptr1 + sty ptr1 lda #BASE - sta ptr1+1 ; From +; Setup is: +; +; - ptr1 contains the struct pointer +; - ptr2 contains the linear memory buffer +; - ptr3 contains -(count-1) +; - ptr4 contains the page buffer and offset +; - tmp1 contains the bank +; - tmp2 contains zero (used for linear memory buffer offset) - ldy #EM_COPY::BUF - lda (ptr3),y - sta ptr2 - iny - lda (ptr3),y - sta ptr2+1 ; To - - lda #BASE - sta ptr1+1 ; To + adc #10 +@calculate_bank_3_with_1: + ldx #3 + rts + +@calculate_bank_2_or_3_with_1: + sec + sbc #246 + bcs @calculate_bank_3_with_1 + lda curpage + clc + adc #5 +@calculate_bank_2_with_0: + ldx #2 + rts + +; ------------------------------------------------------------------------ +; Helper function to get the correct mmu value in x + +getcurbankmmu: + cpx #1 + beq @bank1 + cpx #2 + beq @bank2 + ldx #MMU_CFG_RAM3 + rts +@bank2: + ldx #MMU_CFG_RAM2 + rts +@bank1: + ldx #MMU_CFG_RAM1 + rts + +; ------------------------------------------------------------------------ +; 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: page pointer in ptr4 and bank in tmp1 + + ldy #EM_COPY::PAGE+1 + lda (ptr1),y + tax + dey + lda (ptr1),y + sta curpage + jsr calculate_bank_and_correct_page + clc + adc #4 + sta ptr4+1 + stx tmp1 + +; Get the buffer pointer into ptr2 ldy #EM_COPY::BUF - lda (ptr3),y + lda (ptr1),y sta ptr2 iny - lda (ptr3),y - sta ptr2+1 ; From + lda (ptr1),y + sta ptr2+1 - lda #