From ef6ae3ccc5f94cd4752a044e9322fb74190c841a Mon Sep 17 00:00:00 2001 From: tudnai Date: Fri, 1 May 2020 18:56:30 -0700 Subject: [PATCH] Shadow memory kinda works --- A2Mac/HiRes.swift | 6 +-- A2Mac/ViewController.swift | 4 +- src/cpu/6502.c | 3 +- src/cpu/instructions/6502_instr_load_store.h | 10 +---- src/dev/disk/disk.c | 2 +- src/dev/mem/mmio.h | 44 ++++++++++++++------ 6 files changed, 41 insertions(+), 28 deletions(-) diff --git a/A2Mac/HiRes.swift b/A2Mac/HiRes.swift index 83dcb66..c52cc4c 100644 --- a/A2Mac/HiRes.swift +++ b/A2Mac/HiRes.swift @@ -25,9 +25,9 @@ class HiRes: NSView { static let blockWidth = PixelWidth / blockCols static let blockHeight = PixelHeight / blockRows - let HiResBuffer1 = UnsafeRawBufferPointer(start: RAM + Page1Addr, count: PageSize * 2) - let HiResBuffer2 = UnsafeRawBufferPointer(start: RAM + Page2Addr, count: PageSize * 2) - var HiResBufferPointer = UnsafeRawBufferPointer(start: RAM + Page1Addr, count: PageSize * 2) + let HiResBuffer1 = UnsafeRawBufferPointer(start: MEM + Page1Addr, count: PageSize * 2) + let HiResBuffer2 = UnsafeRawBufferPointer(start: MEM + Page2Addr, count: PageSize * 2) + var HiResBufferPointer = UnsafeRawBufferPointer(start: MEM + Page1Addr, count: PageSize * 2) let HiResRawPointer = UnsafeRawPointer(RAM + Page1Addr) diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift index ecdd8cf..d22b5e3 100644 --- a/A2Mac/ViewController.swift +++ b/A2Mac/ViewController.swift @@ -382,9 +382,11 @@ class ViewController: NSViewController { var halted = true; func Update() { - clk_6502_per_frm_max = 0 +// clk_6502_per_frm_max = 0 clkCounter += Double(clkfrm) + // we start a new frame from here, so CPU is running even while rendering + clkfrm = 0 frameCounter += 1 diff --git a/src/cpu/6502.c b/src/cpu/6502.c index 6574ff0..1e0430f 100644 --- a/src/cpu/6502.c +++ b/src/cpu/6502.c @@ -713,7 +713,8 @@ void m6502_Run() { #ifdef SPEEDTEST for ( inst_cnt = 0; inst_cnt < iterations ; inst_cnt++ ) #elif defined( CLK_WAIT ) - for ( clkfrm = 0; clkfrm < clk_6502_per_frm_max ; clkfrm += clk ) + // we clear the clkfrm from ViewController Update() + for ( ; clkfrm < clk_6502_per_frm_max ; clkfrm += clk ) #else // for ( ; m6502.pc ; ) for ( ; ; ) diff --git a/src/cpu/instructions/6502_instr_load_store.h b/src/cpu/instructions/6502_instr_load_store.h index 9eb8a0c..aa4bff2 100644 --- a/src/cpu/instructions/6502_instr_load_store.h +++ b/src/cpu/instructions/6502_instr_load_store.h @@ -92,15 +92,7 @@ char * charConv = **/ INLINE void STR( uint16_t addr, uint8_t src ) { dbgPrintf("STR [%04X], %02X ", addr, src ); - - // I/O or ROM or RAM EXP - if ( ( addr >= 0xC000 ) && ( addr < 0xC100 ) ) { - return ioWrite( addr, src ); - } - - // DO NOT MAKE IT NICER! faster this way! - *(RAM_PG_WR_TBL[ addr >> 8 ] + (addr & 0xFF)) = src; -// RAM[addr] = src; + memwrite(addr, src); } /** diff --git a/src/dev/disk/disk.c b/src/dev/disk/disk.c index b6c3888..e1fad51 100644 --- a/src/dev/disk/disk.c +++ b/src/dev/disk/disk.c @@ -17,7 +17,7 @@ disk_t disk = { 0, // clk_since_last_read }; -const int diskAccelerator_frames = 5; +const int diskAccelerator_frames = 3; int diskAccelerator_count = 10; int diskAccelerator_speed = 25; // less than actual CPU speed means no acceleration //const unsigned long long clk_6502_per_frm_diskAccelerator = 25 * M / fps; // disk acceleration bumps up CPU clock to 25 MHz diff --git a/src/dev/mem/mmio.h b/src/dev/mem/mmio.h index 00ff13d..1b2bc28 100644 --- a/src/dev/mem/mmio.h +++ b/src/dev/mem/mmio.h @@ -28,7 +28,7 @@ videoMode_t videoMode = { 1 }; // 40 col text, page 1 uint8_t Apple2_Dummy_Page[ 1 * PG ]; // Dummy Page to discard data -uint8_t Apple2_Dummy_RAM[ 4 * KB ]; // Dummy RAM to discard data +uint8_t Apple2_Dummy_RAM[ 64 * KB ]; // Dummy RAM to discard data uint8_t Apple2_16K_ROM[ 16 * KB ] = {0}; // ROM C0, C8, D0, D8, E0, E8, F0, F8 @@ -44,7 +44,7 @@ uint8_t * const MEM = Apple2_64K_MEM; // Pointer to the Shadow Memory uint8_t * const RDLOMEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift uint8_t * const WRLOMEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift uint8_t * const RDHIMEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift -uint8_t * const WRHIMEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift +uint8_t * const WRHIMEM = Apple2_Dummy_RAM; // Pointer to the Shadow Memory Map so we can use this from Swift @@ -941,7 +941,7 @@ INLINE uint16_t memread16( uint16_t addr ) { INLINE uint8_t memread( uint16_t addr ) { if (addr >= 0xC000) { - if (addr <= 0xC0FF) { + if (addr < 0xC100) { return ioRead(addr); } @@ -974,20 +974,38 @@ INLINE uint8_t memread( uint16_t addr ) { /** Naive implementation of RAM write to address **/ -static void memwrite( uint16_t addr, uint8_t byte ) { -// if ( addr >= 0xD000 ) { -// // ROM -// return; -// } -// if ( addr >= 0xC000 ) { -// return mmioWrite(addr); + +INLINE void memwrite8_low( uint16_t addr, uint8_t data ) { + WRLOMEM[addr] = data; +} +INLINE void memwrite8_high( uint16_t addr, uint8_t data ) { + WRHIMEM[addr] = data; +} +INLINE void memwrite( uint16_t addr, uint8_t data ) { + if (addr >= 0xC000) { + if (addr < 0xC100) { + ioWrite(addr, data); + } + else { +// *(RAM_PG_WR_TBL[ addr >> 8 ] + (addr & 0xFF)) = data; + memwrite8_high(addr, data); + } + } + else { + memwrite8_low(addr, data); + } + +// // I/O or ROM or RAM EXP +// if ( ( addr >= 0xC000 ) && ( addr < 0xC100 ) ) { +// return ioWrite( addr, src ); // } // - - RAM[ addr ] = byte; +// // DO NOT MAKE IT NICER! faster this way! +// *(RAM_PG_WR_TBL[ addr >> 8 ] + (addr & 0xFF)) = src; +//// RAM[addr] = src; +// } - /** Fetching 1 byte from memory address pc (program counter) increase pc by one