Always disable SRAM when flashing any hirom repros

This commit is contained in:
sanni 2024-06-30 11:04:40 +02:00
parent 27b84d2f7e
commit f798336aaa
3 changed files with 107 additions and 92 deletions

View File

@ -442,46 +442,46 @@
*/
#if defined(ENABLE_CONFIG)
# define CONFIG_FILE "config.txt"
#define CONFIG_FILE "config.txt"
// Define the max length of the key=value pairs
// Do your best not to have to increase these.
# define CONFIG_KEY_MAX 32
# define CONFIG_VALUE_MAX 32
#define CONFIG_KEY_MAX 32
#define CONFIG_VALUE_MAX 32
#endif
#if (defined(HW4) || defined(HW5))
# define ENABLE_LCD
# define ENABLE_NEOPIXEL
# define ENABLE_ROTARY
#define ENABLE_LCD
#define ENABLE_NEOPIXEL
#define ENABLE_ROTARY
//# define rotate_counter_clockwise
# define ENABLE_CLOCKGEN
# define OPTION_N64_FASTCRC
# define OPTION_WS_ADAPTER_V2
#define ENABLE_CLOCKGEN
#define OPTION_N64_FASTCRC
#define OPTION_WS_ADAPTER_V2
#endif
#if (defined(HW2) || defined(HW3))
# define ENABLE_OLED
# define ENABLE_BUTTON2
# define ENABLE_CLOCKGEN
# define ENABLE_CA_LED
# define OPTION_N64_FASTCRC
#define ENABLE_OLED
#define ENABLE_BUTTON2
#define ENABLE_CLOCKGEN
#define ENABLE_CA_LED
#define OPTION_N64_FASTCRC
#endif
#if defined(HW1)
# define ENABLE_OLED
#define ENABLE_OLED
//#define ENABLE_CLOCKGEN
//#define OPTION_N64_FASTCRC
#endif
#if defined(SERIAL_MONITOR)
# define ENABLE_SERIAL
#define ENABLE_SERIAL
//#define ENABLE_CLOCKGEN
//#define OPTION_N64_FASTCRC
#endif
/* Firmware updater only works with HW3 and HW5 */
#if !(defined(HW5) || defined(HW3))
# undef ENABLE_UPDATER
#undef ENABLE_UPDATER
#endif
/* End of settings */

View File

@ -15,7 +15,7 @@ unsigned long time;
unsigned long blank;
unsigned long sectorSize;
uint16_t bufferSize;
byte mapping = 1;
byte mapping = 0;
/******************************************
Menu
@ -57,6 +57,10 @@ static const char epromMenuItem4[] PROGMEM = "Verify";
static const char* const menuOptionsEprom[] PROGMEM = { flashMenuItemBlankcheck, flashMenuItemRead, flashMenuItemWrite, epromMenuItem4, flashMenuItemPrint, FSTRING_RESET };
void flashMenu() {
display_Clear();
display_Update();
mapping = 0;
// create menu with title and 5 options to choose from
unsigned char flashSlot;
// Copy menuOptions out of progmem
@ -77,9 +81,6 @@ void flashMenu() {
break;
case 1:
display_Clear();
display_Update();
mapping = 1;
setup_Flash8();
id_Flash8();
wait();
@ -87,15 +88,11 @@ void flashMenu() {
break;
case 2:
display_Clear();
display_Update();
setup_Eprom();
mode = CORE_EPROM;
break;
case 3:
display_Clear();
display_Update();
setup_Flash16();
id_Flash16();
wait();
@ -114,7 +111,7 @@ void flashMenu() {
void flashMenu() {
display_Clear();
display_Update();
mapping = 1;
mapping = 0;
// create menu with title and 3 options to choose from
unsigned char flashMode;
@ -856,15 +853,15 @@ void writeByte_Flash(unsigned long myAddress, byte myData) {
// A0-A7
PORTF = myAddress & 0xFF;
// standard for flash adapter and SNES HiRom
if (mapping == 1) {
// flash adapter (without SRAM save chip)
if (mapping == 0) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A23
PORTL = (myAddress >> 16) & 0xFF;
}
// for SNES LoRom
else if (mapping == 0) {
// SNES LoRom
else if (mapping == 1) {
// A8-A14
PORTK = (myAddress >> 8) & 0x7F;
// Set SNES A15(PK7) HIGH to disable SRAM
@ -872,8 +869,39 @@ void writeByte_Flash(unsigned long myAddress, byte myData) {
// A15-A22
PORTL = (myAddress >> 15) & 0xFF;
}
// for SNES ExLoRom repro with 2x 4MB
// SNES HiRom
else if (mapping == 2) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A23
PORTL = (myAddress >> 16) & 0xFF;
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
}
// for SNES LoRom repro with 2x 2MB
else if (mapping == 11) {
// A8-A14
PORTK = (myAddress >> 8) & 0x7F;
// Set SNES A15(PK7) HIGH to disable SRAM
PORTK |= (1 << 7);
// A15-A22
PORTL = (myAddress >> 15) & 0xFF;
// Flip BA6(PL6) to address second rom chip
PORTL ^= (1 << 6);
}
// for SNES HiRom repro with 2x 2MB
else if (mapping == 22) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A23
PORTL = (myAddress >> 16) & 0xFF;
// Flip BA5(PL5) to address second rom chip
PORTL ^= (1 << 5);
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
}
// for SNES ExLoRom repro with 2x 4MB
else if (mapping == 111) {
// A8-A14
PORTK = (myAddress >> 8) & 0x7F;
// Set SNES A15(PK7) HIGH to disable SRAM
@ -884,7 +912,7 @@ void writeByte_Flash(unsigned long myAddress, byte myData) {
PORTL ^= (1 << 7);
}
// for SNES ExHiRom repro
else if (mapping == 3) {
else if (mapping == 222) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A22
@ -900,28 +928,6 @@ void writeByte_Flash(unsigned long myAddress, byte myData) {
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
}
// for SNES LoRom repro with 2x 2MB
else if (mapping == 4) {
// A8-A14
PORTK = (myAddress >> 8) & 0x7F;
// Set SNES A15(PK7) HIGH to disable SRAM
PORTK |= (1 << 7);
// A15-A22
PORTL = (myAddress >> 15) & 0xFF;
// Flip BA6(PL6) to address second rom chip
PORTL ^= (1 << 6);
}
// for SNES HiRom repro with 2x 2MB
else if (mapping == 5) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A23
PORTL = (myAddress >> 16) & 0xFF;
// Flip BA5(PL5) to address second rom chip
PORTL ^= (1 << 5);
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
}
// Data
PORTC = myData;
@ -962,15 +968,15 @@ byte readByte_Flash(unsigned long myAddress) {
// A0-A7
PORTF = myAddress & 0xFF;
// standard for flash adapter and SNES HiRom
if (mapping == 1) {
// flash adapter (without SRAM save chip)
if (mapping == 0) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A23
PORTL = (myAddress >> 16) & 0xFF;
}
// for SNES LoRom
else if (mapping == 0) {
// SNES LoRom
else if (mapping == 1) {
// A8-A14
PORTK = (myAddress >> 8) & 0x7F;
// Set SNES A15(PK7) HIGH to disable SRAM
@ -978,8 +984,39 @@ byte readByte_Flash(unsigned long myAddress) {
// A15-A22
PORTL = (myAddress >> 15) & 0xFF;
}
// for SNES ExLoRom repro
// SNES HiRom
else if (mapping == 2) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A23
PORTL = (myAddress >> 16) & 0xFF;
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
}
// for SNES LoRom repro with 2x 2MB
else if (mapping == 11) {
// A8-A14
PORTK = (myAddress >> 8) & 0x7F;
// Set SNES A15(PK7) HIGH to disable SRAM
PORTK |= (1 << 7);
// A15-A22
PORTL = (myAddress >> 15) & 0xFF;
// Flip BA6(PL6) to address second rom chip
PORTL ^= (1 << 6);
}
// for SNES HiRom repro with 2x 2MB
else if (mapping == 22) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A23
PORTL = (myAddress >> 16) & 0xFF;
// Flip BA5(PL5) to address second rom chip
PORTL ^= (1 << 5);
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
}
// for SNES ExLoRom repro
else if (mapping == 111) {
// A8-A14
PORTK = (myAddress >> 8) & 0x7F;
// Set SNES A15(PK7) HIGH to disable SRAM
@ -990,7 +1027,7 @@ byte readByte_Flash(unsigned long myAddress) {
PORTL ^= (1 << 7);
}
// for SNES ExHiRom repro
else if (mapping == 3) {
else if (mapping == 222) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A22
@ -1006,28 +1043,6 @@ byte readByte_Flash(unsigned long myAddress) {
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
}
// for SNES LoRom repro with 2x 2MB
else if (mapping == 4) {
// A8-A14
PORTK = (myAddress >> 8) & 0x7F;
// Set SNES A15(PK7) HIGH to disable SRAM
PORTK |= (1 << 7);
// A15-A22
PORTL = (myAddress >> 15) & 0xFF;
// Flip BA6(PL6) to address second rom chip
PORTL ^= (1 << 6);
}
// for SNES HiRom repro with 2x 2MB
else if (mapping == 5) {
// A8-A15
PORTK = (myAddress >> 8) & 0xFF;
// A16-A23
PORTL = (myAddress >> 16) & 0xFF;
// Flip BA5(PL5) to address second rom chip
PORTL ^= (1 << 5);
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
}
// Arduino running at 16Mhz -> one nop = 62.5ns
__asm__("nop\n\t"

View File

@ -112,11 +112,11 @@ void reproCFIMenu() {
// Switch to second ROM chip, see flash.ino low level functions line 811
// LoROM
if (mapping == 0)
mapping = 4;
if (mapping == 1)
mapping = 11;
// HiROM
else if (mapping == 1)
mapping = 5;
else if (mapping == 2)
mapping = 22;
// Write second rom chip
display_Clear();
@ -159,13 +159,13 @@ void reproMenu() {
#ifdef ENABLE_FLASH
case 0:
// CFI LoROM
mapping = 0;
mapping = 1;
reproCFIMenu();
break;
case 1:
// CFI HiROM
mapping = 1;
mapping = 2;
reproCFIMenu();
break;
@ -173,7 +173,7 @@ void reproMenu() {
// LoRom
display_Clear();
display_Update();
mapping = 0;
mapping = 1;
setup_Flash8();
id_Flash8();
wait();
@ -184,7 +184,7 @@ void reproMenu() {
// HiRom
display_Clear();
display_Update();
mapping = 1;
mapping = 2;
setup_Flash8();
id_Flash8();
wait();
@ -195,7 +195,7 @@ void reproMenu() {
// ExLoRom
display_Clear();
display_Update();
mapping = 2;
mapping = 111;
setup_Flash8();
id_Flash8();
wait();
@ -206,7 +206,7 @@ void reproMenu() {
// ExHiRom
display_Clear();
display_Update();
mapping = 3;
mapping = 222;
setup_Flash8();
id_Flash8();
wait();