Skip to content

Commit

Permalink
#define ENABLE_FLASH now enables/disables all repro flash code
Browse files Browse the repository at this point in the history
This cuts down memory usage from 90%/66% to 68%/63%. Useful for people that don't flash repros and would like to enable more systems instead.
  • Loading branch information
sanni committed Aug 16, 2024
1 parent 9400330 commit 34e2ef2
Show file tree
Hide file tree
Showing 12 changed files with 633 additions and 571 deletions.
21 changes: 19 additions & 2 deletions Cart_Reader/Cart_Reader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
This project represents a community-driven effort to provide
an easy to build and easy to modify cartridge dumper.
Date: 2024-08-11
Version: 14.2
Date: 2024-08-16
Version: 14.3
SD lib: https://github.com/greiman/SdFat
LCD lib: https://github.com/olikraus/u8g2
Expand Down Expand Up @@ -2332,6 +2332,21 @@ void setup() {
if (!myLog.open("OSCR_LOG.txt", O_RDWR | O_CREAT | O_APPEND)) {
print_FatalError(sd_error_STR);
}

// Start new log if file is too big
if (myLog.fileSize() > 262144) {
EEPROM_readAnything(0, foldern);
sprintf(folder, "%s%d%s", "OSCR_LOG_", foldern, ".txt");
foldern = foldern + 1;
EEPROM_writeAnything(0, foldern);
myLog.rename(folder);
// Close the file:
myLog.close();
if (!myLog.open("OSCR_LOG.txt", O_RDWR | O_CREAT | O_APPEND)) {
print_FatalError(sd_error_STR);
}
}

println_Msg(FS(FSTRING_EMPTY));
#if defined(HW1)
print_Msg(F("OSCR HW1"));
Expand Down Expand Up @@ -3686,10 +3701,12 @@ void loop() {
case CORE_GB: return gbMenu();
case CORE_GBA: return gbaMenu();
case CORE_GBM: return gbmMenu();
#if defined(ENABLE_FLASH)
case CORE_GB_GBSMART: return gbSmartMenu();
case CORE_GB_GBSMART_FLASH: return gbSmartFlashMenu();
case CORE_GB_GBSMART_GAME: return gbSmartGameOptions();
#endif
#endif
#ifdef ENABLE_FLASH
case CORE_FLASH8: return flashromMenu8();
#ifdef ENABLE_FLASH16
Expand Down
2 changes: 1 addition & 1 deletion Cart_Reader/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
/* [ Flashrom Programmer for repro carts -------------------------- ]
*/

#define ENABLE_FLASH
//#define ENABLE_FLASH
//#define ENABLE_FLASH16

/****/
Expand Down
11 changes: 11 additions & 0 deletions Cart_Reader/GB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static const char* const menuOptionsGBx[] PROGMEM = { gbxMenuItem1, gbxMenuItem2
// GB menu items
static const char* const menuOptionsGB[] PROGMEM = { FSTRING_READ_ROM, FSTRING_READ_SAVE, FSTRING_WRITE_SAVE, FSTRING_RESET };

#if defined(ENABLE_FLASH)
// GB Flash items
static const char GBFlashItem1[] PROGMEM = "GB 29F Repro";
static const char GBFlashItem2[] PROGMEM = "GB CFI Repro";
Expand All @@ -42,6 +43,7 @@ static const char GBFlash29Item2[] PROGMEM = "DIY MBC5 (WR)";
static const char GBFlash29Item3[] PROGMEM = "HDR MBC30 (Audio)";
static const char GBFlash29Item4[] PROGMEM = "HDR GameBoy Cam";
static const char* const menuOptionsGBFlash29[] PROGMEM = { GBFlash29Item1, GBFlash29Item2, GBFlash29Item3, GBFlash29Item4, FSTRING_RESET };
#endif

// Pelican Codebreaker, Brainboy, and Monster Brain Operation Menu
static const char PelicanRead[] PROGMEM = "Read Device";
Expand All @@ -55,6 +57,7 @@ static const char GameSharkRead[] PROGMEM = "Read GBC GameShark";
static const char GameSharkWrite[] PROGMEM = "Write GBC GameShark";
static const char* const menuOptionsGBDatel[] PROGMEM = { MegaMemRead, MegaMemWrite, GameSharkRead, GameSharkWrite };

#if defined(ENABLE_FLASH)
bool gbxFlashCFI() {
// Flash CFI
display_Clear();
Expand All @@ -80,6 +83,7 @@ bool gbxFlashCFI() {
}
return true;
}
#endif

void feedbackPressAndReset() {
// Prints string out of the common strings array either with or without newline
Expand Down Expand Up @@ -113,6 +117,7 @@ void gbxMenu() {
mode = CORE_GBA;
break;

#if defined(ENABLE_FLASH)
case 2:
// create submenu with title and 7 options to choose from
unsigned char gbFlash;
Expand Down Expand Up @@ -314,6 +319,7 @@ void gbxMenu() {
break;
}
break;
#endif

case 3:
// Flash GB Memory
Expand Down Expand Up @@ -430,6 +436,9 @@ void gbxMenu() {
case 6:
resetArduino();
break;

default:
print_MissingModule(); // does not return
}
}

Expand Down Expand Up @@ -1806,6 +1815,7 @@ void sendMBC7EEPROM_Inst_GB(uint8_t op, uint8_t addr, uint16_t data) {
}
}

#if defined(ENABLE_FLASH)
/******************************************
29F016/29F032/29F033 flashrom functions
*****************************************/
Expand Down Expand Up @@ -2452,6 +2462,7 @@ bool writeCFI_GB() {
}
return true;
}
#endif

/**************************************************
Pelican Gameboy Device Read Function
Expand Down
10 changes: 8 additions & 2 deletions Cart_Reader/GBA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
static const char GBAMenuItem4[] PROGMEM = "Force Savetype";
static const char* const menuOptionsGBA[] PROGMEM = { FSTRING_READ_ROM, FSTRING_READ_SAVE, FSTRING_WRITE_SAVE, GBAMenuItem4, FSTRING_RESET };

#if defined(ENABLE_FLASH)
// 369-in-1 menu items
static const char Menu369Item1[] PROGMEM = "Read 256MB";
static const char Menu369Item2[] PROGMEM = "Write 256MB";
static const char Menu369Item3[] PROGMEM = "Read Offset";
static const char Menu369Item4[] PROGMEM = "Write Offset";
static const char* const Options369GBA[] PROGMEM = { Menu369Item1, Menu369Item2, Menu369Item3, Menu369Item4, FSTRING_RESET };
#endif

// Rom menu
static const char GBARomItem1[] PROGMEM = "1 MB";
Expand Down Expand Up @@ -233,6 +235,7 @@ void gbaMenu() {
}
}

#if defined(ENABLE_FLASH)
// Flash GBA Repro
void GBAReproMenu() {
setup_GBA_Repro();
Expand Down Expand Up @@ -302,6 +305,7 @@ void repro369in1Menu() {
wait();
resetArduino();
}
#endif

/******************************************
Setup
Expand Down Expand Up @@ -367,12 +371,14 @@ void setup_GBA() {
wait();
}

#if defined(ENABLE_FLASH)
void setup_GBA_Repro() {
// Request 3.3V
setVoltage(VOLTS_SET_3V3);
setROM_GBA();
display_Clear();
}
#endif

/******************************************
Low level functions
Expand Down Expand Up @@ -2002,6 +2008,7 @@ unsigned long verifyEEP_GBA(word eepSize) {
return wrError;
}

#if defined(ENABLE_FLASH)
/******************************************
GBA REPRO Functions (32MB Intel 4000L0YBQ0 and 16MB MX29GL128E)
*****************************************/
Expand Down Expand Up @@ -2920,9 +2927,8 @@ void flashRepro_GBA(boolean option) {
print_FatalError(F("Check voltage"));
}
}

#endif

#endif
//******************************************
// End of File
//******************************************
10 changes: 9 additions & 1 deletion Cart_Reader/GBM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ void gbmMenu() {

// wait for user choice to come back from the question box menu
switch (mainMenu) {
#if defined(ENABLE_FLASH)
// Read Flash ID
case 0:
// Clear screen
display_Clear();
readFlashID_GBM();
break;
#endif

// Read Flash
case 1:
Expand Down Expand Up @@ -62,6 +64,7 @@ void gbmMenu() {
readROM_GBM(64);
break;

#if defined(ENABLE_FLASH)
// Erase Flash
case 2:
// Clear screen
Expand Down Expand Up @@ -172,6 +175,10 @@ void gbmMenu() {
// Write mapping
writeMapping_GBM();
break;
#endif

default:
print_MissingModule(); // does not return
}
println_Msg(FS(FSTRING_EMPTY));
// Prints string out of the common strings array either with or without newline
Expand Down Expand Up @@ -447,6 +454,7 @@ void send_GBM(byte myCommand) {
}
}

#if defined(ENABLE_FLASH)
void send_GBM(byte myCommand, word myAddress, byte myData) {
byte myAddrLow = myAddress & 0xFF;
byte myAddrHigh = (myAddress >> 8) & 0xFF;
Expand Down Expand Up @@ -905,7 +913,7 @@ void writeMapping_GBM() {
print_Error(open_file_STR);
}
}

#endif
#endif

//******************************************
Expand Down
2 changes: 2 additions & 0 deletions Cart_Reader/GBS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Supports 32M cart with LH28F016SUT flash
//******************************************
#ifdef ENABLE_GBX
#if defined(ENABLE_FLASH)
#define GB_SMART_GAMES_PER_PAGE 6

/******************************************
Expand Down Expand Up @@ -728,6 +729,7 @@ uint8_t gbSmartGetResizeParam(uint8_t rom_size, uint8_t sram_size) {
return (sram_size | rom_size);
}

#endif
#endif
//******************************************
// End of File
Expand Down
11 changes: 7 additions & 4 deletions Cart_Reader/MD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ void mdMenu() {
case 3:
resetArduino();
break;

default:
print_MissingModule(); // does not return
}
}

Expand Down Expand Up @@ -2120,7 +2123,6 @@ void verifyFlash_MD() {
display_Update();
}
}
#endif

// Delay between write operations based on status register
void busyCheck_MD() {
Expand All @@ -2137,6 +2139,7 @@ void busyCheck_MD() {
// Set data pins to output
dataOut_MD();
}
#endif

//******************************************
// EEPROM Functions
Expand Down Expand Up @@ -2899,9 +2902,9 @@ void printRomSize_MD(int index) {
void force_cartSize_MD() {
cartSize = navigateMenu(0, 9, &printRomSize_MD);
cartSize = pgm_read_byte(&(MDSize[cartSize])) * 131072;
#if (defined(ENABLE_OLED) || defined(ENABLE_LCD))
#if (defined(ENABLE_OLED) || defined(ENABLE_LCD))
display.setCursor(0, 56); // Display selection at bottom
#endif
#endif
print_Msg(FS(FSTRING_ROM_SIZE));
print_Msg(cartSize / 131072);
println_Msg(F(" Mbit"));
Expand All @@ -2913,4 +2916,4 @@ void force_cartSize_MD() {

//******************************************
// End of File
//******************************************
//******************************************
17 changes: 10 additions & 7 deletions Cart_Reader/N64.ino
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ static const char* const menuOptionsN64Controller[] PROGMEM = { N64ContMenuItem1
static const char N64CartMenuItem4[] PROGMEM = "Force Savetype";
static const char* const menuOptionsN64Cart[] PROGMEM = { FSTRING_READ_ROM, FSTRING_READ_SAVE, FSTRING_WRITE_SAVE, N64CartMenuItem4, FSTRING_RESET };

// N64 CRC32 error menu items
static const char N64CRCMenuItem1[] PROGMEM = "No";
static const char N64CRCMenuItem2[] PROGMEM = "Yes and keep old";
static const char N64CRCMenuItem3[] PROGMEM = "Yes and delete old";
static const char* const menuOptionsN64CRC[] PROGMEM = { N64CRCMenuItem1, N64CRCMenuItem2, N64CRCMenuItem3, FSTRING_RESET };

// Rom menu
static const char N64RomItem1[] PROGMEM = "4 MB";
static const char N64RomItem2[] PROGMEM = "8 MB";
Expand All @@ -93,6 +87,7 @@ static const char N64SaveItem4[] PROGMEM = "SRAM";
static const char N64SaveItem5[] PROGMEM = "FLASH";
static const char* const saveOptionsN64[] PROGMEM = { N64SaveItem1, N64SaveItem2, N64SaveItem3, N64SaveItem4, N64SaveItem5 };

#if defined(ENABLE_FLASH)
// Repro write buffer menu
static const char N64BufferItem1[] PROGMEM = "No buffer";
static const char N64BufferItem2[] PROGMEM = "32 Byte";
Expand All @@ -106,6 +101,7 @@ static const char N64SectorItem2[] PROGMEM = "32 KB";
static const char N64SectorItem3[] PROGMEM = "64 KB";
static const char N64SectorItem4[] PROGMEM = "128 KB";
static const char* const sectorOptionsN64[] PROGMEM = { N64SectorItem1, N64SectorItem2, N64SectorItem3, N64SectorItem4 };
#endif

// N64 start menu
void n64Menu() {
Expand All @@ -132,6 +128,7 @@ void n64Menu() {
mode = CORE_N64_CONTROLLER;
break;

#if defined(ENABLE_FLASH)
case 2:
display_Clear();
display_Update();
Expand All @@ -140,6 +137,7 @@ void n64Menu() {
printCartInfo_N64();
mode = CORE_N64_CART;
break;
#endif

case 3:
display_Clear();
Expand All @@ -165,6 +163,9 @@ void n64Menu() {
case 5:
resetArduino();
break;

default:
print_MissingModule(); // does not return
}
}

Expand Down Expand Up @@ -3039,6 +3040,7 @@ void savesummary_N64(boolean checkfound, char crcStr[9], unsigned long timeElaps
}
#endif

#if defined(ENABLE_FLASH)
/******************************************
N64 Repro Flashrom Functions
*****************************************/
Expand Down Expand Up @@ -3997,6 +3999,7 @@ unsigned long verifyFlashrom_N64() {
return 9999;
}
}
#endif

/******************************************
N64 Gameshark Flash Functions
Expand Down Expand Up @@ -4687,4 +4690,4 @@ unsigned long verifyXplorer_N64() {

//******************************************
// End of File
//******************************************
//******************************************
Loading

0 comments on commit 34e2ef2

Please sign in to comment.