From 9741a49b80031b1c8ad44cd4986434c81bda5c8a Mon Sep 17 00:00:00 2001 From: tudnai Date: Mon, 3 Aug 2020 22:16:11 -0700 Subject: [PATCH] Fixed some MMU issues --- A2Mac.xcodeproj/project.pbxproj | 4 +- .../xcdebugger/Expressions.xcexplist | 11 +++ src/cpu/6502.c | 4 +- .../instructions/6502_instr_shift_rotate.h | 2 +- src/dev/mem/mmio.h | 80 ++++++++++++++++--- 5 files changed, 84 insertions(+), 17 deletions(-) diff --git a/A2Mac.xcodeproj/project.pbxproj b/A2Mac.xcodeproj/project.pbxproj index 281dabc..1492abf 100644 --- a/A2Mac.xcodeproj/project.pbxproj +++ b/A2Mac.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 320B3FC424AD88B0005EA133 /* power.png in Copy Image Files */ = {isa = PBXBuildFile; fileRef = 320B3FC324AD88B0005EA133 /* power.png */; }; 320B4FC124B182DE00070038 /* Apple Disk II.png in Copy Image Files */ = {isa = PBXBuildFile; fileRef = 320B4FC024B182DD00070038 /* Apple Disk II.png */; }; 320F2A8824CFD74100671B35 /* Steve2Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 320F2A8724CFD74000671B35 /* Steve2Icon.icns */; }; - 320F2AAD24D53B4100671B35 /* 6502.c in Sources */ = {isa = PBXBuildFile; fileRef = 32439F7422ECD8AD0077AAE0 /* 6502.c */; }; 3213936624079C30007F5C4A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32BFFB6022EACC660003B53F /* Main.storyboard */; }; 323D042E248980600086A901 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 323D042D248980600086A901 /* Preferences.storyboard */; }; 323D043024898AB70086A901 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 323D042F24898AB70086A901 /* PreferencesViewController.swift */; }; @@ -111,6 +110,7 @@ 32F1D03824CE3AA30058AC75 /* RepeatingTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C45305232E3EEF0000EBA1 /* RepeatingTimer.swift */; }; 32F1D03924CE3AB10058AC75 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 323D042F24898AB70086A901 /* PreferencesViewController.swift */; }; 32F1D03A24CE3AB10058AC75 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 323D04312489BFD80086A901 /* PreferencesWindowController.swift */; }; + 32F8994924D9149800C85BE5 /* 6502.c in Sources */ = {isa = PBXBuildFile; fileRef = 32439F7422ECD8AD0077AAE0 /* 6502.c */; }; 32F8A87C24A3A84300EE6735 /* PrintChar21.ttf in Copy Font Files */ = {isa = PBXBuildFile; fileRef = 325EB67B23FBD43800C6B4A4 /* PrintChar21.ttf */; }; 32F8A87D24A3A84700EE6735 /* PRNumber3.ttf in Copy Font Files */ = {isa = PBXBuildFile; fileRef = 32089E4724556DBD0036E667 /* PRNumber3.ttf */; }; 32F8A87F24A3A8A000EE6735 /* apple.rom in Copy ROM Images */ = {isa = PBXBuildFile; fileRef = 32439F8422ECD8AD0077AAE0 /* apple.rom */; }; @@ -1208,11 +1208,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 320F2AAD24D53B4100671B35 /* 6502.c in Sources */, 32BFFB5B22EACC630003B53F /* AppDelegate.swift in Sources */, 32E3126D24AC033A00E61891 /* ToolBarController.swift in Sources */, 323D043024898AB70086A901 /* PreferencesViewController.swift in Sources */, 323D04332489BFD80086A901 /* PreferencesWindowController.swift in Sources */, + 32F8994924D9149800C85BE5 /* 6502.c in Sources */, 32E3126924A98B9300E61891 /* dsk2woz.c in Sources */, 325EB63623F8F78300C6B4A4 /* disk.c in Sources */, 325EB62F23F8856F00C6B4A4 /* woz.c in Sources */, diff --git a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist index 73d371a..d9c3450 100644 --- a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -95,6 +95,9 @@ + + @@ -103,6 +106,14 @@ + + + + + + diff --git a/src/cpu/6502.c b/src/cpu/6502.c index b56aee0..b01d1b9 100644 --- a/src/cpu/6502.c +++ b/src/cpu/6502.c @@ -749,9 +749,7 @@ void m6502_ColdReset( const char * bundlePath, const char * romFileName ) { // Disk ][ ROM in Slot 6 read_rom( bundlePath, "DISK_II_C600.ROM", Apple2_64K_RAM, 0xC600); memcpy(Apple2_64K_MEM + 0xC600, Apple2_64K_RAM + 0xC600, 0x100); - -// read_rom( "/Users/trudnai/Library/Containers/com.gamealloy.A2Mac/Data/", "DISK_II_C600.ROM", Apple2_64K_MEM, 0xC600); - + m6502.A = m6502.X = m6502.Y = 0xFF; // reset vector m6502.SP = 0xFF; //-3; diff --git a/src/cpu/instructions/6502_instr_shift_rotate.h b/src/cpu/instructions/6502_instr_shift_rotate.h index a0fcaed..c65c663 100644 --- a/src/cpu/instructions/6502_instr_shift_rotate.h +++ b/src/cpu/instructions/6502_instr_shift_rotate.h @@ -40,7 +40,7 @@ absolute,X ASL oper,X 1E 3 7 **/ INLINE void _ASL( uint16_t addr ) { - m6502.C = WRLOMEM[addr] & 0x80; + m6502.C = memread(addr) & 0x80; set_flags_NZ( WRLOMEM[addr] <<= 1 ); } INLINE void ASL( uint16_t addr ) { diff --git a/src/dev/mem/mmio.h b/src/dev/mem/mmio.h index e2db06d..1069b78 100644 --- a/src/dev/mem/mmio.h +++ b/src/dev/mem/mmio.h @@ -59,7 +59,8 @@ uint8_t * const RAM = Apple2_64K_RAM; // Pointer to the Main Memory so uint8_t * const MEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift uint8_t * const RDLOMEM = Apple2_64K_MEM; // for Read $0000 - $BFFF (shadow memory) -uint8_t * WRLOMEM = Apple2_64K_MEM; // for Write $0000 - $BFFF (shadow memory) +uint8_t * WRZEROPG= Apple2_64K_MEM; // for Write $0000 - $0200 (shadow memory) +uint8_t * WRLOMEM = Apple2_64K_MEM; // for Write $0200 - $BFFF (shadow memory) uint8_t * const RDHIMEM = Apple2_64K_MEM; // for Read / Write $0000 - $BFFF (shadow memory) uint8_t * WRD0MEM = Apple2_Dummy_RAM; // for writing $D000 - $DFFF uint8_t * WRHIMEM = Apple2_Dummy_RAM; // for writing $E000 - $FFFF @@ -246,6 +247,8 @@ enum mmio { io_VID_SET80VID = 0xC00D, // ECG W 80 Columns io_VID_CLRALTCHAR = 0xC00E, // ECG W Primary Character Set io_VID_SETALTCHAR = 0xC00F, // ECG W Alternate Character Set + io_VID_RDVBL = 0xC019, // E G R7 Vertical Blanking (E:1=drawing G:0=drawing) + // RSTVBL C R Reset Vertical Blanking Interrupt io_VID_RDTEXT = 0xC01A, // ECG R7 Status of Text/Graphics io_VID_RDMIXED = 0xC01B, // ECG R7 Status of Full Screen/Mixed Graphics io_VID_RDPAGE2 = 0xC01C, // ECG R7 Status of Page 1/Page 2 @@ -370,6 +373,11 @@ void resetMemory() { memset( Apple2_64K_RAM + 0xC000, 0, 0x1000 ); newMEMcfg = MEMcfg; + + WRZEROPG= Apple2_64K_MEM; // for Write $0000 - $0200 (shadow memory) + WRLOMEM = Apple2_64K_MEM; // for Write $0200 - $BFFF (shadow memory) + WRD0MEM = Apple2_Dummy_RAM; // for writing $D000 - $DFFF + WRHIMEM = Apple2_Dummy_RAM; // for writing $E000 - $FFFF } @@ -445,18 +453,62 @@ void auxMemorySelect( MEMcfg_t newMEMcfg ) { MEMcfg = newMEMcfg; } + +const uint8_t * const shadowZeropage = Apple2_64K_MEM; +const uint8_t * currentZeropage = Apple2_64K_RAM; + +void auxZeropageSelect( MEMcfg_t newMEMcfg ) { + + // save the content of Shadow Memory + memcpy( (void*) currentZeropage, shadowZeropage, 0x200); + + if ( newMEMcfg.is_80STORE ) { + if ( newMEMcfg.ALT_ZP ) { + currentZeropage = Apple2_64K_AUX; + } + else { + currentZeropage = Apple2_64K_RAM; + } + } + + WRZEROPG = (uint8_t*)shadowZeropage; + + // load new content to shadow memory + memcpy( (void*) shadowZeropage, currentZeropage, 0x200); + + MEMcfg = newMEMcfg; +} + + +void C3MemorySelect( MEMcfg_t newMEMcfg ) { + + if ( newMEMcfg.slot_C3_ROM ) { + // load internal ROM to memory + memcpy(Apple2_64K_MEM + 0xC300, Apple2_16K_ROM + 0x300, 0x100); + } + else { + // load peripheral ROM to memory + memcpy(Apple2_64K_MEM + 0xC300, Apple2_64K_RAM + 0xC300, 0x100); + } + + + MEMcfg = newMEMcfg; +} + + void CxMemorySelect( MEMcfg_t newMEMcfg ) { if ( newMEMcfg.int_Cx_ROM ) { // load internal ROM to memory - memcpy(Apple2_64K_MEM + 0xC100, Apple2_16K_ROM + 0x100, 16 * KB - 0x100); + memcpy(Apple2_64K_MEM + 0xC100, Apple2_16K_ROM + 0x100, 0xF00); } else { // load peripheral ROM to memory -// memcpy(Apple2_64K_MEM + 0xC100, Apple2_64K_RAM + 0xC100, 16 * KB - 0x100); +// memcpy(Apple2_64K_MEM + 0xC100, Apple2_64K_RAM + 0xC100, 0xF00); memcpy(Apple2_64K_MEM + 0xC600, Apple2_64K_RAM + 0xC600, 0x100); } + C3MemorySelect( newMEMcfg ); MEMcfg = newMEMcfg; } @@ -647,6 +699,9 @@ INLINE uint8_t ioRead( uint16_t addr ) { spkr_toggle(); return Apple2_64K_RAM[io_SPKR]; + case (uint8_t)io_VID_RDVBL: + return (clkfrm < 4550) ? 0x80 : 0; + case (uint8_t)io_VID_RDTEXT: return videoMode.text << 7; @@ -938,13 +993,13 @@ INLINE void ioWrite( uint16_t addr, uint8_t val ) { break; case (uint8_t)io_SETSTDZP: - MEMcfg.ALT_ZP = 0; - // TODO: set zero page table to RAM + newMEMcfg.ALT_ZP = 0; + auxZeropageSelect(newMEMcfg); break; case (uint8_t)io_SETALTZP: - MEMcfg.ALT_ZP = 1; - // TODO: set zero page table to AUX + newMEMcfg.ALT_ZP = 1; + auxZeropageSelect(newMEMcfg); break; case (uint8_t)io_SETSLOTCXROM: @@ -962,13 +1017,13 @@ INLINE void ioWrite( uint16_t addr, uint8_t val ) { case (uint8_t)io_SETSLOTC3ROM: // printf("io_SETSLOTC3ROM\n"); MEMcfg.slot_C3_ROM = 1; - // TODO: set C300 ROM area table to SLOT + C3MemorySelect(MEMcfg); break; case (uint8_t)io_SETINTC3ROM: // printf("io_SETINTC3ROM\n"); MEMcfg.slot_C3_ROM = 0; - // TODO: set C300 ROM area table to INT + C3MemorySelect(MEMcfg); break; case (uint8_t)io_VID_CLR80VID: @@ -1195,7 +1250,10 @@ INLINE uint8_t memread( uint16_t addr ) { **/ INLINE void memwrite8_low( uint16_t addr, uint8_t data ) { - WRLOMEM[addr] = data; + Apple2_64K_MEM[addr] = data; +} +INLINE void memwrite8_zero( uint16_t addr, uint8_t data ) { + WRZEROPG[addr] = data; } INLINE void memwrite8_bank2( uint16_t addr, uint8_t data ) { WRD0MEM[addr] = data; @@ -1225,7 +1283,7 @@ INLINE void memwrite( uint16_t addr, uint8_t data ) { // RAM memwrite8_low(addr, data); } - + } /**