Use already existing sdBuffer array

This commit is contained in:
sanni 2022-02-15 12:59:25 +01:00
parent 7b92953e0b
commit 5a59ed155b
2 changed files with 12 additions and 14 deletions

View File

@ -472,7 +472,7 @@ byte readByte_GB(word myAddress) {
return tempByte; return tempByte;
} }
void writeByte_GB(int myAddress, uint8_t myData) { void writeByte_GB(int myAddress, byte myData) {
PORTF = myAddress & 0xFF; PORTF = myAddress & 0xFF;
PORTK = (myAddress >> 8) & 0xFF; PORTK = (myAddress >> 8) & 0xFF;
PORTC = myData; PORTC = myData;
@ -520,7 +520,7 @@ byte readByteSRAM_GB(word myAddress) {
return tempByte; return tempByte;
} }
void writeByteSRAM_GB(int myAddress, uint8_t myData) { void writeByteSRAM_GB(int myAddress, byte myData) {
PORTF = myAddress & 0xFF; PORTF = myAddress & 0xFF;
PORTK = (myAddress >> 8) & 0xFF; PORTK = (myAddress >> 8) & 0xFF;
PORTC = myData; PORTC = myData;
@ -809,14 +809,14 @@ void readSRAM_GB() {
writeByte_GB(0x0000, 0x0A); writeByte_GB(0x0000, 0x0A);
// Switch SRAM banks // Switch SRAM banks
for (uint8_t bank = 0; bank < sramBanks; bank++) { for (byte currBank = 0; currBank < sramBanks; currBank++) {
dataOut(); dataOut();
writeByte_GB(0x4000, bank); writeByte_GB(0x4000, currBank);
// Read SRAM // Read SRAM
dataIn_GB(); dataIn_GB();
for (word sramAddress = 0xA000; sramAddress <= lastByte; sramAddress += 64) { for (word sramAddress = 0xA000; sramAddress <= lastByte; sramAddress += 64) {
for (uint8_t i = 0; i < 64; i++) { for (byte i = 0; i < 64; i++) {
sdBuffer[i] = readByteSRAM_GB(sramAddress + i); sdBuffer[i] = readByteSRAM_GB(sramAddress + i);
} }
myFile.write(sdBuffer, 64); myFile.write(sdBuffer, 64);
@ -923,9 +923,9 @@ unsigned long verifySRAM_GB() {
writeByte_GB(0x0000, 0x0A); writeByte_GB(0x0000, 0x0A);
// Switch SRAM banks // Switch SRAM banks
for (uint8_t bank = 0; bank < sramBanks; bank++) { for (byte currBank = 0; currBank < sramBanks; currBank++) {
dataOut(); dataOut();
writeByte_GB(0x4000, bank); writeByte_GB(0x4000, currBank);
// Read SRAM // Read SRAM
dataIn_GB(); dataIn_GB();
@ -1095,12 +1095,11 @@ void writeFlash29F_GB(byte MBC) {
dataIn(); dataIn();
for (unsigned int currAddr = 0x4000; currAddr < 0x7FFF; currAddr += 512) { for (unsigned int currAddr = 0x4000; currAddr < 0x7FFF; currAddr += 512) {
uint8_t readData[512];
for (int currByte = 0; currByte < 512; currByte++) { for (int currByte = 0; currByte < 512; currByte++) {
readData[currByte] = readByte_GB(currAddr + currByte); sdBuffer[currByte] = readByte_GB(currAddr + currByte);
} }
for (int j = 0; j < 512; j++) { for (int j = 0; j < 512; j++) {
if (readData[j] != 0xFF) { if (sdBuffer[j] != 0xFF) {
println_Msg(F("Not empty")); println_Msg(F("Not empty"));
print_Error(F("Erase failed"), true); print_Error(F("Erase failed"), true);
} }
@ -1496,12 +1495,11 @@ bool writeCFI_GB() {
dataIn(); dataIn();
for (unsigned int currAddr = 0x4000; currAddr < 0x7FFF; currAddr += 512) { for (unsigned int currAddr = 0x4000; currAddr < 0x7FFF; currAddr += 512) {
uint8_t readData[512];
for (int currByte = 0; currByte < 512; currByte++) { for (int currByte = 0; currByte < 512; currByte++) {
readData[currByte] = readByte_GB(currAddr + currByte); sdBuffer[currByte] = readByte_GB(currAddr + currByte);
} }
for (int j = 0; j < 512; j++) { for (int j = 0; j < 512; j++) {
if (readData[j] != 0xFF) { if (sdBuffer[j] != 0xFF) {
println_Msg(F("Not empty")); println_Msg(F("Not empty"));
print_Error(F("Erase failed"), true); print_Error(F("Erase failed"), true);
} }

View File

@ -2,7 +2,7 @@
// !!! CHOOSE HARDWARE VERSION !!! // !!! CHOOSE HARDWARE VERSION !!!
//****************************************** //******************************************
// Remove // in front of the line with your hardware version // Remove // in front of the line with your hardware version
//#define HW4 #define HW4
//#define HW3 //#define HW3
//#define HW2 //#define HW2
//#define HW1 //#define HW1