fix verifySram_MD and writeSram_MD

This commit is contained in:
jiyunomegami 2020-07-13 19:23:51 +09:00
parent 6ece8b0fcd
commit 80c19a0bc4

View File

@ -1071,14 +1071,14 @@ void writeSram_MD() {
// skip high byte // skip high byte
myFile.read(); myFile.read();
} }
byte data = (myFile.read() & 0xFF); word data = myFile.read() & 0xFF;
writeWord_MD(currByte, data); writeWord_MD(currByte, data);
} }
} }
// Write to the upper byte // Write to the upper byte
else if (saveType == 2) { else if (saveType == 2) {
for (unsigned long currByte = sramBase; currByte < sramBase + sramSize; currByte++) { for (unsigned long currByte = sramBase; currByte < sramBase + sramSize; currByte++) {
byte data = ((myFile.read() << 8 ) & 0xFF); word data = (myFile.read() << 8) & 0xFF00;
writeWord_MD(currByte, data); writeWord_MD(currByte, data);
if (segaSram16bit > 0) { if (segaSram16bit > 0) {
// skip low byte // skip low byte
@ -1086,6 +1086,14 @@ void writeSram_MD() {
} }
} }
} }
// Write to both bytes
else if (saveType == 3) {
for (unsigned long currByte = sramBase; currByte < sramBase + sramSize; currByte++) {
word data = (myFile.read() << 8) & 0xFF00;
data |= (myFile.read() & 0xFF);
writeWord_MD(currByte, data);
}
}
else else
print_Error(F("Unknown save type"), false); print_Error(F("Unknown save type"), false);
@ -1186,31 +1194,30 @@ unsigned long verifySram_MD() {
if (saveType == 2) { if (saveType == 2) {
// Only use the upper byte // Only use the upper byte
if (segaSram16bit > 0) { sdBuffer[currWord * 2] = (( myWord >> 8 ) & 0xFF);
sdBuffer[(currWord * 2) + 0] = (( myWord >> 8 ) & 0xFF);
sdBuffer[(currWord * 2) + 1] = (( myWord >> 8 ) & 0xFF);
} else {
sdBuffer[currWord] = (( myWord >> 8 ) & 0xFF);
}
} }
else if (saveType == 1) { else if (saveType == 1) {
// Only use the lower byte // Only use the lower byte
if (segaSram16bit > 0) { sdBuffer[currWord * 2] = (myWord & 0xFF);
sdBuffer[(currWord * 2) + 0] = (myWord & 0xFF);
sdBuffer[(currWord * 2) + 1] = (myWord & 0xFF);
} else {
sdBuffer[currWord] = (myWord & 0xFF);
}
} }
else if (saveType == 3) { // BOTH else if (saveType == 3) { // BOTH
sdBuffer[currWord * 2] = (( myWord >> 8 ) & 0xFF); sdBuffer[(currWord * 2) + 0] = (( myWord >> 8 ) & 0xFF);
sdBuffer[(currWord * 2) + 1] = (myWord & 0xFF); sdBuffer[(currWord * 2) + 1] = (myWord & 0xFF);
} }
} }
int size = (saveType == 3 || segaSram16bit > 0) ? 512 : 256; int step = saveType == 3 ? 1 : 2;
// Check sdBuffer content against file on sd card // Check sdBuffer content against file on sd card
for (int i = 0; i < size; i++) { for (int i = 0; i < 512; i += step) {
if (myFile.read() != sdBuffer[i]) { if (saveType == 1 && segaSram16bit > 0) {
// skip high byte
myFile.read();
}
byte b = myFile.read();
if (saveType == 2 && segaSram16bit > 0) {
// skip low byte
myFile.read();
}
if (b != sdBuffer[i]) {
writeErrors++; writeErrors++;
} }
} }