From f21e26d1953693805a1ed2a537534f20ceb26dcd Mon Sep 17 00:00:00 2001 From: Janne Johansson Date: Fri, 12 Nov 2021 15:07:44 +0100 Subject: [PATCH 1/4] Add dynamic mode change by writing to $d030 --- MCL64/SourceCode/MCL64.ino | 48 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/MCL64/SourceCode/MCL64.ino b/MCL64/SourceCode/MCL64.ino index 7d6a5a6..2e46e18 100644 --- a/MCL64/SourceCode/MCL64.ino +++ b/MCL64/SourceCode/MCL64.ino @@ -136,6 +136,7 @@ uint8_t direct_nmi=0; uint8_t assert_sync=0; uint8_t global_temp=0; uint8_t last_access_internal_RAM=0; +uint8_t mode=1; uint16_t register_pc=0; uint16_t current_address=0; @@ -162,8 +163,8 @@ uint8_t CART_LOW_ROM[0x2000]; // When set to 1 it will remove the unnecessary 6502 bus fetches, reads, and writes // Set to 0 for cycle-accurate mode // -#define SPEEDUP 1 - +// #define SPEEDUP 1 - changed to dynamic value + // ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------ @@ -242,15 +243,15 @@ void setup() { // ---------------------------------------------------------- inline uint8_t internal_address_check(uint16_t local_address) { - if ( (local_address > 0x0001 ) && (local_address <= 0x03FF) ) return 0x1; // Zero-Page up to video + if ( (local_address > 0x0001 ) && (local_address <= 0x03FF) ) return mode; // Zero-Page up to video if ( (local_address >= 0x0400) && (local_address <= 0x07FF) ) return 0x1; // C64 Video Memory - if ( (local_address >= 0x0800) && (local_address <= 0x9FFF) ) return 0x1; // C64 RAM - if ( (local_address >= 0xA000) && (local_address <= 0xBFFF) ) return 0x1; // C64 BASIC ROM - if ( (local_address >= 0xC000) && (local_address <= 0xCFFF) ) return 0x1; // C64 RAM + if ( (local_address >= 0x0800) && (local_address <= 0x9FFF) ) return mode; // C64 RAM + if ( (local_address >= 0xA000) && (local_address <= 0xBFFF) ) return mode; // C64 BASIC ROM + if ( (local_address >= 0xC000) && (local_address <= 0xCFFF) ) return mode; // C64 RAM //if ( (local_address >= 0xD000) && (local_address <= 0xDFFF) ) return 0x1; // C64 I/O - if ( (local_address >= 0xE000) && (local_address <= 0xE4FF) ) return 0x1; // C64 KERNAL ROM - if ( (local_address >= 0xE500) && (local_address <= 0xFF7F) ) return 0x1; // C64 KERNAL ROM - if ( (local_address >= 0xFF80) && (local_address <= 0xFFFF) ) return 0x1; // C64 KERNAL ROM + if ( (local_address >= 0xE000) && (local_address <= 0xE4FF) ) return mode; // C64 KERNAL ROM + if ( (local_address >= 0xE500) && (local_address <= 0xFF7F) ) return mode; // C64 KERNAL ROM + if ( (local_address >= 0xFF80) && (local_address <= 0xFFFF) ) return mode; // C64 KERNAL ROM return 0x0; } @@ -476,6 +477,9 @@ inline void write_byte(uint16_t local_address , uint8_t local_write_data) { wait_for_CLK_rising_edge(); digitalWriteFast(PIN_DATAOUT_OE_n, 0x1 ); + } + if ( internal_address_check(local_address) == 0xd030) { + mode = ( local_write_data & 0x03 ); } return; } @@ -547,7 +551,7 @@ uint8_t Fetch_ZeroPage() { uint8_t Fetch_ZeroPage_X() { uint16_t bal; bal = Fetch_Immediate(); - if (SPEEDUP==0) read_byte(register_pc+1); + if (mode==0) read_byte(register_pc+1); effective_address = (0x00FF & (bal + register_x)); return read_byte(effective_address); } @@ -555,7 +559,7 @@ uint8_t Fetch_ZeroPage_X() { uint8_t Fetch_ZeroPage_Y() { uint16_t bal; bal = Fetch_Immediate(); - if (SPEEDUP==0) read_byte(register_pc+1); + if (mode==0) read_byte(register_pc+1); effective_address = (0x00FF & (bal + register_y)); return read_byte(effective_address); } @@ -587,7 +591,7 @@ uint8_t Fetch_Absolute_X(uint8_t page_cross_check) { effective_address = bah + bal + register_x; local_data = read_byte(effective_address ); - if ( (SPEEDUP==0) && page_cross_check==1 && ( (0xFF00&effective_address) != (0xFF00&bah) ) ) { + if ( (mode==0) && page_cross_check==1 && ( (0xFF00&effective_address) != (0xFF00&bah) ) ) { local_data = read_byte(effective_address ); } return local_data; @@ -602,7 +606,7 @@ uint8_t Fetch_Absolute_Y(uint8_t page_cross_check) { effective_address = bah + bal + register_y; local_data = read_byte(effective_address ); - if ( (SPEEDUP==0) && page_cross_check==1 && ( (0xFF00&effective_address) != (0xFF00&bah) ) ) { + if ( (mode==0) && page_cross_check==1 && ( (0xFF00&effective_address) != (0xFF00&bah) ) ) { local_data = read_byte(effective_address ); } return local_data; @@ -633,7 +637,7 @@ uint8_t Fetch_Indexed_Indirect_Y(uint8_t page_cross_check) { effective_address = bah + bal + register_y; local_data = read_byte(effective_address); - if ( (SPEEDUP==0) && page_cross_check==1 && ((0xFF00&effective_address) != (0xFF00&bah)) ) { + if ( (mode==0) && page_cross_check==1 && ((0xFF00&effective_address) != (0xFF00&bah)) ) { local_data = read_byte(effective_address); } return local_data; @@ -655,14 +659,14 @@ void Write_Absolute(uint8_t local_data) { void Write_ZeroPage_X(uint8_t local_data) { effective_address = Fetch_Immediate(); - if (SPEEDUP==0) read_byte(effective_address); + if (mode==0) read_byte(effective_address); write_byte( (0x00FF&(effective_address + register_x)) , local_data ); return; } void Write_ZeroPage_Y(uint8_t local_data) { effective_address = Fetch_Immediate(); - if (SPEEDUP==0) read_byte(effective_address); + if (mode==0) read_byte(effective_address); write_byte( (0x00FF&(effective_address + register_y)) , local_data ); return; } @@ -673,7 +677,7 @@ void Write_Absolute_X(uint8_t local_data) { bal = Fetch_Immediate(); bah = Fetch_Immediate()<<8; effective_address = bal + bah + register_x; - if (SPEEDUP==0) read_byte(effective_address); + if (mode==0) read_byte(effective_address); write_byte(effective_address , local_data ); return; } @@ -686,7 +690,7 @@ void Write_Absolute_Y(uint8_t local_data) { effective_address = bal + bah + register_y; read_byte(effective_address); - if (SPEEDUP==0) { + if (mode==0) { if ( (0xFF00&effective_address) != (0xFF00&bah) ) { read_byte(effective_address); } @@ -716,14 +720,14 @@ void Write_Indexed_Indirect_Y(uint8_t local_data) { bal = read_byte(ial); bah = read_byte(ial+1)<<8; effective_address = bah + bal + register_y; - if (SPEEDUP==0) read_byte(effective_address); + if (mode==0) read_byte(effective_address); write_byte(effective_address , local_data ); return; } void Double_WriteBack(uint8_t local_data) { write_byte(effective_address , local_data); - if (SPEEDUP==0) write_byte(effective_address , local_data); + if (mode==0) write_byte(effective_address , local_data); return; } @@ -1401,7 +1405,7 @@ void Branch_Taken() { effective_address = Sign_Extend16(Fetch_Immediate()); effective_address = (register_pc+1) + effective_address; - if (SPEEDUP==0) { + if (mode==0) { if ( (0xFF00®ister_pc) == (0xFF00&effective_address) ) { Fetch_Immediate(); } // Page boundary not crossed else { Fetch_Immediate(); Fetch_Immediate(); } // Page boundary crossed } @@ -1490,7 +1494,7 @@ void opcode_0x60() { pcl = pop(); pch = pop()<<8; register_pc = pch+pcl+1; - if (SPEEDUP==0) read_byte(register_pc); + if (mode==0) read_byte(register_pc); assert_sync=1; start_read(register_pc); return ; From 0a8475077e6ad54d0439a5c00bf38f3f2bd0bf86 Mon Sep 17 00:00:00 2001 From: Janne Johansson Date: Sun, 14 Nov 2021 12:29:26 +0100 Subject: [PATCH 2/4] This would prevent writes to byte 0x02 --- MCL64/SourceCode/MCL64.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCL64/SourceCode/MCL64.ino b/MCL64/SourceCode/MCL64.ino index 2e46e18..669b34e 100644 --- a/MCL64/SourceCode/MCL64.ino +++ b/MCL64/SourceCode/MCL64.ino @@ -435,7 +435,7 @@ inline void write_byte(uint16_t local_address , uint8_t local_write_data) { // Internal RAM // - if (internal_address_check(local_address)>0x2) { + if (internal_address_check(local_address)>0x1) { last_access_internal_RAM=1; internal_RAM[local_address] = local_write_data; //if ( (Page_128_159==0x1) && ( (EXROM==1 && GAME==0) || ( EXROM==0 && ((bank_mode&0x3)==0x3) ) )) { } else internal_RAM[local_address] = local_write_data; From 24f4dffe7b1fb91c9c9aa9d3b858be450154315c Mon Sep 17 00:00:00 2001 From: Janne Johansson Date: Sun, 14 Nov 2021 12:51:24 +0100 Subject: [PATCH 3/4] Use current_p to test for which ROM and IO mode currently is in effect and test those modes before effecuating mode change at d030 --- MCL64/SourceCode/MCL64.ino | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/MCL64/SourceCode/MCL64.ino b/MCL64/SourceCode/MCL64.ino index 669b34e..9a2dd06 100644 --- a/MCL64/SourceCode/MCL64.ino +++ b/MCL64/SourceCode/MCL64.ino @@ -155,6 +155,10 @@ uint8_t KERNAL_ROM[0x2000]={ 0x85,0x56,0x20,0xf,0xbc,0xa5,0x61,0xc9,0x88,0x90, #define EXROM 1 #define GAME 1 +#define VIC_IO 0x04; +#define KERNAL_ROM_ENABLED 0x02; +#define BASIC_ROM_ENABLED 0x01; + // First few bytes of Copyrighted ROMs uint8_t CART_HIGH_ROM[0x4000]={ 0x78,0xa2,0xff,0x9a,0xd8,0xa9,0xe7,0x85,0x1,0xa9,0x37,0x85,0x0,0x4c,0x83,0xe1,0xa9 } ; uint8_t CART_LOW_ROM[0x2000]; @@ -478,9 +482,12 @@ inline void write_byte(uint16_t local_address , uint8_t local_write_data) { wait_for_CLK_rising_edge(); digitalWriteFast(PIN_DATAOUT_OE_n, 0x1 ); } - if ( internal_address_check(local_address) == 0xd030) { - mode = ( local_write_data & 0x03 ); - } + if ((current_p & VIC_IO) && // IO enabled and + (current_p & (KERNAL_ROM_ENABLED | BASIC_ROM_ENABLED) != 0 )) && // BASIC and KERNAL not both unmapped + (internal_address_check(local_address) == 0xd030) ) // and addr = d030 + { + mode = ( local_write_data & 0x03 ); + } return; } From 43075bc58c298ebc5de5ac4cff1ce1dacefb7bc9 Mon Sep 17 00:00:00 2001 From: Janne Johansson Date: Sun, 14 Nov 2021 12:58:05 +0100 Subject: [PATCH 4/4] Bah, did not compile test, fixed defines and if() logic --- MCL64/SourceCode/MCL64.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MCL64/SourceCode/MCL64.ino b/MCL64/SourceCode/MCL64.ino index 9a2dd06..582d53f 100644 --- a/MCL64/SourceCode/MCL64.ino +++ b/MCL64/SourceCode/MCL64.ino @@ -155,9 +155,9 @@ uint8_t KERNAL_ROM[0x2000]={ 0x85,0x56,0x20,0xf,0xbc,0xa5,0x61,0xc9,0x88,0x90, #define EXROM 1 #define GAME 1 -#define VIC_IO 0x04; -#define KERNAL_ROM_ENABLED 0x02; -#define BASIC_ROM_ENABLED 0x01; +#define VIC_IO 0x04 +#define KERNAL_ROM_ENABLED 0x02 +#define BASIC_ROM_ENABLED 0x01 // First few bytes of Copyrighted ROMs uint8_t CART_HIGH_ROM[0x4000]={ 0x78,0xa2,0xff,0x9a,0xd8,0xa9,0xe7,0x85,0x1,0xa9,0x37,0x85,0x0,0x4c,0x83,0xe1,0xa9 } ; @@ -483,7 +483,7 @@ inline void write_byte(uint16_t local_address , uint8_t local_write_data) { digitalWriteFast(PIN_DATAOUT_OE_n, 0x1 ); } if ((current_p & VIC_IO) && // IO enabled and - (current_p & (KERNAL_ROM_ENABLED | BASIC_ROM_ENABLED) != 0 )) && // BASIC and KERNAL not both unmapped + ((current_p & (KERNAL_ROM_ENABLED | BASIC_ROM_ENABLED)) != 0) && // BASIC and KERNAL not both unmapped (internal_address_check(local_address) == 0xd030) ) // and addr = d030 { mode = ( local_write_data & 0x03 );