Fix reading/writing 4MB HiROM

HiROM starts at bank 192 and has 64 banks so byte variable currBank overflows.
This commit is contained in:
sanni 2022-10-31 15:41:29 +01:00
parent a3feb32e15
commit cc17c70e30
6 changed files with 258 additions and 245 deletions

View File

@ -109,7 +109,7 @@ char ver[5] = "11.1";
#define enable_PCE #define enable_PCE
// Benesse Pocket Challenge W // Benesse Pocket Challenge W
//#define enable_PCW #define enable_PCW
// Sega Master System // Sega Master System
#define enable_SMS #define enable_SMS
@ -127,10 +127,10 @@ char ver[5] = "11.1";
#define enable_VBOY #define enable_VBOY
// WonderSwan // WonderSwan
//#define enable_WS #define enable_WS
// Watara Supervision // Watara Supervision
//#define enable_WSV #define enable_WSV
//****************************************** //******************************************
// HW CONFIGS // HW CONFIGS

View File

@ -618,7 +618,8 @@ static uint8_t dataCRC(uint8_t* data) {
// (3 instructions) making it the same size as the equivalent 3-cycles NOP // (3 instructions) making it the same size as the equivalent 3-cycles NOP
// delay. For shorter delays or non-multiple-of-3-cycle delays, add your own // delay. For shorter delays or non-multiple-of-3-cycle delays, add your own
// NOPs. // NOPs.
#define N64_DELAY_LOOP(cycle_count) do { \ #define N64_DELAY_LOOP(cycle_count) \
do { \
byte i; \ byte i; \
__asm__ __volatile__("\n" \ __asm__ __volatile__("\n" \
"\tldi %[i], %[loop_count]\n" \ "\tldi %[i], %[loop_count]\n" \
@ -627,8 +628,7 @@ static uint8_t dataCRC(uint8_t* data) {
"\tbrne .delay_loop_%=\n" \ "\tbrne .delay_loop_%=\n" \
: [i] "=r"(i) \ : [i] "=r"(i) \
: [loop_count] "i"(cycle_count / 3) \ : [loop_count] "i"(cycle_count / 3) \
: "cc" \ : "cc"); \
); \
} while (0) } while (0)
/****************************************** /******************************************
@ -797,8 +797,7 @@ void sendJoyBus(const byte *buffer, char length) {
: [line_low] "r"(line_low), : [line_low] "r"(line_low),
[line_high] "r"(line_high), [line_high] "r"(line_high),
[out_byte] "i"(&DDRH) [out_byte] "i"(&DDRH)
: "cc", "memory" : "cc", "memory");
);
} }
word recvJoyBus(byte* output, byte byte_count) { word recvJoyBus(byte* output, byte byte_count) {
@ -905,8 +904,7 @@ word recvJoyBus(byte *output, byte byte_count) {
[scratch] "=&a"(scratch) [scratch] "=&a"(scratch)
: [in_byte] "i"(&PINH), : [in_byte] "i"(&PINH),
[in_bit] "i"(4) [in_bit] "i"(4)
: "cc", "memory" : "cc", "memory");
);
return byte_count; return byte_count;
} }

View File

@ -893,7 +893,7 @@ void readROM_SFM() {
//clear the screen //clear the screen
display_Clear(); display_Clear();
println_Msg(F("Creating folder: ")); print_Msg(F("Creating folder "));
println_Msg(folder); println_Msg(folder);
display_Update(); display_Update();
@ -927,7 +927,7 @@ void readROM_SFM() {
println_Msg(F("Dumping HiRom...")); println_Msg(F("Dumping HiRom..."));
display_Update(); display_Update();
for (byte currBank = 192; currBank < (numBanks + 192); currBank++) { for (word currBank = 192; currBank < (numBanks + 192); currBank++) {
for (long currByte = 0; currByte < 65536; currByte += 512) { for (long currByte = 0; currByte < 65536; currByte += 512) {
for (int c = 0; c < 512; c++) { for (int c = 0; c < 512; c++) {
sdBuffer[c] = readBank_SFM(currBank, currByte + c); sdBuffer[c] = readBank_SFM(currBank, currByte + c);
@ -1009,8 +1009,7 @@ void idFlash_SFM(int startBank) {
void writeFlash_SFM(int startBank, uint32_t pos) { void writeFlash_SFM(int startBank, uint32_t pos) {
display_Clear(); display_Clear();
print_Msg(F("Writing Bank 0x")); print_Msg(F("Writing Bank 0x"));
print_Msg(startBank, HEX); println_Msg(startBank, HEX);
print_Msg(F("..."));
display_Update(); display_Update();
// Open file on sd card // Open file on sd card
@ -1026,8 +1025,13 @@ void writeFlash_SFM(int startBank, uint32_t pos) {
dataOut(); dataOut();
if (romType) { if (romType) {
//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = numBanks * 0x10000;
draw_progressbar(0, totalProgressBar);
// Write hirom // Write hirom
for (byte currBank = startBank; currBank < startBank + numBanks; currBank++) { for (word currBank = startBank; currBank < startBank + numBanks; currBank++) {
// Fill SDBuffer with 1 page at a time then write it repeat until all bytes are written // Fill SDBuffer with 1 page at a time then write it repeat until all bytes are written
for (unsigned long currByte = 0; currByte < 0x10000; currByte += 128) { for (unsigned long currByte = 0; currByte < 0x10000; currByte += 128) {
myFile.read(sdBuffer, 128); myFile.read(sdBuffer, 128);
@ -1049,8 +1053,16 @@ void writeFlash_SFM(int startBank, uint32_t pos) {
// Wait until write is finished // Wait until write is finished
busyCheck_SFM(startBank); busyCheck_SFM(startBank);
} }
// update progress bar
processedProgressBar += 0x10000;
draw_progressbar(processedProgressBar, totalProgressBar);
} }
} else { } else {
//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = numBanks * 0x8000;
draw_progressbar(0, totalProgressBar);
// Write lorom // Write lorom
for (byte currBank = 0; currBank < numBanks; currBank++) { for (byte currBank = 0; currBank < numBanks; currBank++) {
for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte += 128) { for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte += 128) {
@ -1072,6 +1084,9 @@ void writeFlash_SFM(int startBank, uint32_t pos) {
// Wait until write is finished // Wait until write is finished
busyCheck_SFM(startBank); busyCheck_SFM(startBank);
} }
// update progress bar
processedProgressBar += 0x8000;
draw_progressbar(processedProgressBar, totalProgressBar);
} }
} }
// Close the file: // Close the file:
@ -1155,7 +1170,7 @@ byte blankcheck_SFM(int startBank) {
byte blank = 1; byte blank = 1;
if (romType) { if (romType) {
for (byte currBank = startBank; currBank < startBank + numBanks; currBank++) { for (word currBank = startBank; currBank < startBank + numBanks; currBank++) {
for (unsigned long currByte = 0; currByte < 0x10000; currByte++) { for (unsigned long currByte = 0; currByte < 0x10000; currByte++) {
if (readBank_SFM(currBank, currByte) != 0xFF) { if (readBank_SFM(currBank, currByte) != 0xFF) {
currBank = startBank + numBanks; currBank = startBank + numBanks;
@ -1192,7 +1207,7 @@ unsigned long verifyFlash_SFM(int startBank, uint32_t pos) {
controlIn_SFM(); controlIn_SFM();
if (romType) { if (romType) {
for (byte currBank = startBank; currBank < startBank + numBanks; currBank++) { for (word currBank = startBank; currBank < startBank + numBanks; currBank++) {
for (unsigned long currByte = 0; currByte < 0x10000; currByte += 512) { for (unsigned long currByte = 0; currByte < 0x10000; currByte += 512) {
// Fill SDBuffer // Fill SDBuffer
myFile.read(sdBuffer, 512); myFile.read(sdBuffer, 512);
@ -1244,7 +1259,7 @@ void readFlash_SFM() {
print_FatalError(create_file_STR); print_FatalError(create_file_STR);
} }
if (romType) { if (romType) {
for (byte currBank = 0xC0; currBank < 0xC0 + numBanks; currBank++) { for (word currBank = 0xC0; currBank < 0xC0 + numBanks; currBank++) {
for (unsigned long currByte = 0; currByte < 0x10000; currByte += 512) { for (unsigned long currByte = 0; currByte < 0x10000; currByte += 512) {
for (int c = 0; c < 512; c++) { for (int c = 0; c < 512; c++) {
sdBuffer[c] = readBank_SFM(currBank, currByte + c); sdBuffer[c] = readBank_SFM(currBank, currByte + c);

View File

@ -602,7 +602,7 @@ void readLoRomBanks(unsigned int start, unsigned int total, FsFile* file) {
uint32_t totalProgressBar = (uint32_t)(total - start) * 1024; uint32_t totalProgressBar = (uint32_t)(total - start) * 1024;
draw_progressbar(0, totalProgressBar); draw_progressbar(0, totalProgressBar);
for (byte currBank = start; currBank < total; currBank++) { for (word currBank = start; currBank < total; currBank++) {
PORTL = currBank; PORTL = currBank;
// Blink led // Blink led
@ -653,7 +653,7 @@ void readHiRomBanks(unsigned int start, unsigned int total, FsFile* file) {
uint32_t totalProgressBar = (uint32_t)(total - start) * 1024; uint32_t totalProgressBar = (uint32_t)(total - start) * 1024;
draw_progressbar(0, totalProgressBar); draw_progressbar(0, totalProgressBar);
for (byte currBank = start; currBank < total; currBank++) { for (word currBank = start; currBank < total; currBank++) {
PORTL = currBank; PORTL = currBank;
// Blink led // Blink led