From 7ffeffdb92f9de2caa4126a52bbee23504829f66 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sat, 19 Sep 2020 11:15:42 +0200 Subject: [PATCH] Working on MAP test. Added fragment. --- .../vwum1=vwuc1_minus_vbuxx.asm | 8 ++ src/test/kc/examples/mega65/memorymap-test.c | 82 +++++++++++++++++-- src/test/kc/examples/mega65/raster65.c | 7 +- 3 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 src/main/fragment/mos6502-common/vwum1=vwuc1_minus_vbuxx.asm diff --git a/src/main/fragment/mos6502-common/vwum1=vwuc1_minus_vbuxx.asm b/src/main/fragment/mos6502-common/vwum1=vwuc1_minus_vbuxx.asm new file mode 100644 index 000000000..82128c617 --- /dev/null +++ b/src/main/fragment/mos6502-common/vwum1=vwuc1_minus_vbuxx.asm @@ -0,0 +1,8 @@ +stx $ff +lda #<{c1} +sec +sbc $ff +sta {m1} +lda #>{c1} +sbc #00 +sta {m1}+1 \ No newline at end of file diff --git a/src/test/kc/examples/mega65/memorymap-test.c b/src/test/kc/examples/mega65/memorymap-test.c index 6ffd772dc..a25815aab 100644 --- a/src/test/kc/examples/mega65/memorymap-test.c +++ b/src/test/kc/examples/mega65/memorymap-test.c @@ -4,32 +4,96 @@ #include void main() { + /* // Remap block at $4000 to point to $10000 // offset = $10000-$4000 = $c000 asm { lda #$c0 // lower blocks offset page - ldx #$40 // lower blocks to map + lower blocks offset page + ldx #$40 // lower blocks to map + lower blocks offset ldy #0 ldz #0 map eom } - // Put data into $4000 asm { lda #$55 sta $4000 } - -} + */ + + + char * block1 = 0x4000; + char * block2 = 0x8000; + memoryBlockRemap((unsigned char)>block1, 0x100); + memoryBlockRemap((unsigned char)>block2, 0x120); + + // TODO: The mapper can only map the lower 32K to one memory address and the upper 32K to another + // TODO: The mapper always remaps both - so it cannot be separated into two different calls (without some memory)! + + block1[0] = 0x55; + block1[1] = 0xaa; + block2[0] = 0x55; + block2[1] = 0xaa; + //block2[1] = 0xaa; + //block2[2] = block1[1]; -// Remap one of the 8 8K memory blocks of the MEGA65 to point to somewhere else in the 256MB memory space. -// After the remapping the CPU will be actualy be accessing the remapped memory whenever it uses instructions accessing the remapped block. -// blockAddress: The address of the 8K memory block to remap. The block addresses are: $0000, $2000, $4000, ... -// newAddress: The address in 256MB memory that the block should point to. The address must be 256b page aligned: $00000000, $00000100, $00000200, ... -void memoryBlockRemap(unsigned int blockAddress, unsigned long newAddress) { } + +// Remap one of the eight 8K memory blocks in the 64K address space of the 6502 to point somewhere else in the first 1MB memory space of the MEGA65. +// After the remapping the CPU will access the mapped memory whenever it uses instructions that access the mapped block. +// blockPage: Page address of the 8K memory block to remap (ie. the block that is remapped is $100 * the passed page address.) +// Legal block page addresses are: $00: block $0000-$1fff, $20: block $2000-$3fff, ..., $e0: block $e000-$ffff +// memoryPage: Page address of the memory that the block should point to in the 1MB memory space of the MEGA65. +// Ie. the memory that will be pointed to is $100 * the passed page address. Only the lower 12bits of the passed value is used. +void memoryBlockRemap(unsigned char blockPage, unsigned int memoryPage) { + // Which block is being remapped? (0-7) + char block = blockPage / $20; + // Find the page offset (the number of pages to offset the block) + unsigned int pageOffset = memoryPage-blockPage; + if(block&4) { + // High block (4-7) + char * yVal = 0xfe; + char * zVal = 0xff; + *yVal = pageOffset & 0xf); + asm { + lda #0 // lower blocks offset page low + ldx #0 // lower blocks to map + lower blocks offset page high nibble + ldy yVal // upper blocks offset page + ldz zVal // upper blocks to map + upper blocks offset page high nibble + map + eom + } + } else { + // Low block (0-3) + char * aVal = 0xfe; + char * xVal = 0xff; + *aVal = pageOffset & 0xf); + asm { + lda aVal // lower blocks offset page low + ldx xVal // lower blocks to map + lower blocks offset high nibble + ldy #0 // upper blocks offset page + ldz #0 // upper blocks to map + upper blocks offset page high nibble + map + eom + } + + } + +} + +// Test corner case behaviors +// - Mapping two blocks to the same memory : [$4000-$5fff] >> [$10000-$12000], [$6000-$7fff] >> [$10000-$12000] +// - Mapping two blocks to overlapping memory : [$4000-$5fff] >> [$10000-$12000], [$6000-$7f00] >> [$11000-$12ff] +// - Mapping a block to the 1MB border : [$4000-$5fff] >> [$ff000-$100fff] or [$ff000-$00fff] ? +// - Mapping a block over zeropage : [$0000-$1fff] >> [$10000-$12000]. Does zp-addressing-mode access the mapped memory? + + +// Add memory block remapping to the full 256MB memory + diff --git a/src/test/kc/examples/mega65/raster65.c b/src/test/kc/examples/mega65/raster65.c index 901732582..0fa5a5831 100644 --- a/src/test/kc/examples/mega65/raster65.c +++ b/src/test/kc/examples/mega65/raster65.c @@ -1,8 +1,7 @@ -// Raster65 Demo Implementation in C -// Based on RASTER65 assembler demo made by DEFT in 2015 +// Raster65 Demo re-implementation in C by Jesper Gravgaard +// Based on RASTER65 assembler demo made in 2015 and updated in 2020 by DEFT // https://mega.scryptos.com/sharefolder/MEGA/MEGA65+filehost // https://www.forum64.de/index.php?thread/104591-xemu-vic-iv-implementation-update/&postID=1560511#post1560511 - #pragma target(mega65_c64) #pragma emulator("/Users/jespergravgaard/c64/mega65/xemu-hernandp/build/bin/xmega65.native -prg") #include @@ -203,7 +202,7 @@ interrupt(hardware_stack) void irq() { (SCREEN + SCROLL_ROW*40)[i] = (SCREEN + SCROLL_ROW*40 + 1)[i]; // Show next char char nxt = *(scroll_ptr++); - if(nxt==0) { + if(nxt == 0) { scroll_ptr = SCROLL_TEXT; nxt = *scroll_ptr; }