aboutsummaryrefslogtreecommitdiffhomepage
path: root/Cart_Reader/SMS.ino
diff options
context:
space:
mode:
authorsmesgr9000 <smesgr9000>2024-05-26 22:20:47 +0200
committersmesgr9000 <smesgr9000>2024-05-26 22:20:47 +0200
commit363d18b5429c2f418250af4496a81d5522aed6d6 (patch)
tree41ce7be00b881091f5f30e27691ed8f96c62edb0 /Cart_Reader/SMS.ino
parent78bf1462d00df5cfbc9447b25577e9ec3d128b66 (diff)
downloadcartreader-363d18b5429c2f418250af4496a81d5522aed6d6.tar.gz
cartreader-363d18b5429c2f418250af4496a81d5522aed6d6.zip
add common function to open create folder, print message and open file. Remove duplicate code
Diffstat (limited to 'Cart_Reader/SMS.ino')
-rw-r--r--Cart_Reader/SMS.ino45
1 files changed, 19 insertions, 26 deletions
diff --git a/Cart_Reader/SMS.ino b/Cart_Reader/SMS.ino
index bc30f0c..721a316 100644
--- a/Cart_Reader/SMS.ino
+++ b/Cart_Reader/SMS.ino
@@ -647,37 +647,30 @@ void readSRAM_SMS() {
} else {
system = "SMS";
}
- createFolder(system, "SAVE", romName, "sav");
+ createFolderAndOpenFile(system, "SAVE", romName, "sav");
- printAndIncrementFolder(true);
+ // Write the whole 32KB
+ // When there is only 8KB of SRAM, the contents should be duplicated
+ word bankSize = 16 * 1024UL;
+ for (byte currBank = 0x0; currBank < 2; currBank++) {
+ writeByte_SMS(0xFFFC, 0x08 | (currBank << 2));
- // Create file on sd card
- if (myFile.open(fileName, O_RDWR | O_CREAT)) {
- // Write the whole 32KB
- // When there is only 8KB of SRAM, the contents should be duplicated
- word bankSize = 16 * 1024UL;
- for (byte currBank = 0x0; currBank < 2; currBank++) {
- writeByte_SMS(0xFFFC, 0x08 | (currBank << 2));
-
- // Blink led
- blinkLED();
-
- // Read 16KB from slot 2 which starts at 0x8000
- for (word currBuffer = 0; currBuffer < bankSize; currBuffer += 512) {
- // Fill SD buffer
- for (int currByte = 0; currByte < 512; currByte++) {
- sdBuffer[currByte] = readByte_SMS(0x8000 + currBuffer + currByte);
- }
- myFile.write(sdBuffer, 512);
+ // Blink led
+ blinkLED();
+
+ // Read 16KB from slot 2 which starts at 0x8000
+ for (word currBuffer = 0; currBuffer < bankSize; currBuffer += 512) {
+ // Fill SD buffer
+ for (int currByte = 0; currByte < 512; currByte++) {
+ sdBuffer[currByte] = readByte_SMS(0x8000 + currBuffer + currByte);
}
+ myFile.write(sdBuffer, 512);
}
- // Close file
- myFile.close();
- print_STR(press_button_STR, 1);
- display_Update();
- } else {
- print_FatalError(sd_error_STR);
}
+ // Close file
+ myFile.close();
+ print_STR(press_button_STR, 1);
+ display_Update();
}
//**********************************************