aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorsmesgr9000 <smesgr9000>2024-05-28 20:20:29 +0200
committersmesgr9000 <smesgr9000>2024-05-28 20:20:29 +0200
commit0d9596eb70b3eb0494d0b66292d5d915df0b2aac (patch)
tree62e47509e953925864307075d38766d35c7f674c
parentcb111077f893d75069f5ba88719fd411f8f3c369 (diff)
downloadcartreader-0d9596eb70b3eb0494d0b66292d5d915df0b2aac.tar.gz
cartreader-0d9596eb70b3eb0494d0b66292d5d915df0b2aac.zip
replace custom FLASH saving code with common function
-rw-r--r--Cart_Reader/Cart_Reader.ino6
-rw-r--r--Cart_Reader/FLASH.ino66
2 files changed, 8 insertions, 64 deletions
diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino
index 2fee71c..6b162fa 100644
--- a/Cart_Reader/Cart_Reader.ino
+++ b/Cart_Reader/Cart_Reader.ino
@@ -674,7 +674,11 @@ void createFolder(const char* system, const char* subfolder, const char* gameNam
// create a new folder for the rom file
EEPROM_readAnything(0, foldern);
- sprintf(folder, "%s/%s/%s/%d", system, subfolder, gameName, foldern);
+ if(subfolder == NULL) {
+ sprintf(folder, "%s/%s/%d", system, gameName, foldern);
+ } else {
+ sprintf(folder, "%s/%s/%s/%d", system, subfolder, gameName, foldern);
+ }
sd.mkdir(folder, true);
sd.chdir(folder);
}
diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino
index 424901b..82359b2 100644
--- a/Cart_Reader/FLASH.ino
+++ b/Cart_Reader/FLASH.ino
@@ -1741,26 +1741,8 @@ void readFlash() {
// Reset to root directory
sd.chdir("/");
- // Get name, add extension and convert to char array for sd lib
- EEPROM_readAnything(0, foldern);
- sd.mkdir("FLASH", true);
- sd.chdir("FLASH");
- sprintf(fileName, "FL%d", foldern);
- strcat(fileName, ".bin");
- // write new folder number back to eeprom
- foldern = foldern + 1;
- EEPROM_writeAnything(0, foldern);
+ createFolderAndOpenFile("FLASH", NULL, "FL", "bin");
- display_Clear();
- print_STR(saving_to_STR, 0);
- print_Msg(fileName);
- println_Msg(F("..."));
- display_Update();
-
- // Open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- print_FatalError(create_file_STR);
- }
for (unsigned long currByte = 0; currByte < flashSize; currByte += 512) {
for (int c = 0; c < 512; c++) {
sdBuffer[c] = readByte_Flash(currByte + c);
@@ -2001,29 +1983,8 @@ void readFlash16() {
// Reset to root directory
sd.chdir("/");
- // Get name, add extension and convert to char array for sd lib
- EEPROM_readAnything(0, foldern);
- sd.mkdir("FLASH", true);
- sd.chdir("FLASH");
- sprintf(fileName, "FL%d", foldern);
- strcat(fileName, ".bin");
- // write new folder number back to eeprom
- foldern = foldern + 1;
- EEPROM_writeAnything(0, foldern);
+ createFolderAndOpenFile("FLASH", NULL, "FL", "bin");
- display_Clear();
- print_STR(saving_to_STR, 0);
- print_Msg(fileName);
- println_Msg(F("..."));
- display_Update();
-
- // Open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- println_Msg(F("Can't create file on SD."));
- display_Update();
- while (1)
- ;
- }
word d = 0;
for (unsigned long currByte = 0; currByte < flashSize / 2; currByte += 256) {
for (word c = 0; c < 256; c++) {
@@ -2277,29 +2238,8 @@ void read_Eprom() {
// Reset to root directory
sd.chdir("/");
- // Get name, add extension and convert to char array for sd lib
- EEPROM_readAnything(0, foldern);
- sd.mkdir("FLASH", true);
- sd.chdir("FLASH");
- sprintf(fileName, "FL%d", foldern);
- strcat(fileName, ".bin");
- // write new folder number back to eeprom
- foldern = foldern + 1;
- EEPROM_writeAnything(0, foldern);
+ createFolderAndOpenFile("FLASH", NULL, "FL", "bin");
- display_Clear();
- print_STR(saving_to_STR, 0);
- print_Msg(fileName);
- println_Msg(F("..."));
- display_Update();
-
- // Open file on sd card
- if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
- println_Msg(F("Can't create file on SD."));
- display_Update();
- while (1)
- ;
- }
word d = 0;
for (unsigned long currWord = 0; currWord < flashSize / 2; currWord += 256) {
for (word c = 0; c < 256; c++) {