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
// Benesse Pocket Challenge W
//#define enable_PCW
#define enable_PCW
// Sega Master System
#define enable_SMS
@ -127,10 +127,10 @@ char ver[5] = "11.1";
#define enable_VBOY
// WonderSwan
//#define enable_WS
#define enable_WS
// Watara Supervision
//#define enable_WSV
#define enable_WSV
//******************************************
// 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
// delay. For shorter delays or non-multiple-of-3-cycle delays, add your own
// NOPs.
#define N64_DELAY_LOOP(cycle_count) do { \
#define N64_DELAY_LOOP(cycle_count) \
do { \
byte i; \
__asm__ __volatile__("\n" \
"\tldi %[i], %[loop_count]\n" \
@ -627,8 +628,7 @@ static uint8_t dataCRC(uint8_t* data) {
"\tbrne .delay_loop_%=\n" \
: [i] "=r"(i) \
: [loop_count] "i"(cycle_count / 3) \
: "cc" \
); \
: "cc"); \
} while (0)
/******************************************
@ -797,8 +797,7 @@ void sendJoyBus(const byte *buffer, char length) {
: [line_low] "r"(line_low),
[line_high] "r"(line_high),
[out_byte] "i"(&DDRH)
: "cc", "memory"
);
: "cc", "memory");
}
word recvJoyBus(byte* output, byte byte_count) {
@ -905,8 +904,7 @@ word recvJoyBus(byte *output, byte byte_count) {
[scratch] "=&a"(scratch)
: [in_byte] "i"(&PINH),
[in_bit] "i"(4)
: "cc", "memory"
);
: "cc", "memory");
return byte_count;
}

View File

@ -893,7 +893,7 @@ void readROM_SFM() {
//clear the screen
display_Clear();
println_Msg(F("Creating folder: "));
print_Msg(F("Creating folder "));
println_Msg(folder);
display_Update();
@ -927,7 +927,7 @@ void readROM_SFM() {
println_Msg(F("Dumping HiRom..."));
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 (int c = 0; c < 512; 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) {
display_Clear();
print_Msg(F("Writing Bank 0x"));
print_Msg(startBank, HEX);
print_Msg(F("..."));
println_Msg(startBank, HEX);
display_Update();
// Open file on sd card
@ -1026,8 +1025,13 @@ void writeFlash_SFM(int startBank, uint32_t pos) {
dataOut();
if (romType) {
//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = numBanks * 0x10000;
draw_progressbar(0, totalProgressBar);
// 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
for (unsigned long currByte = 0; currByte < 0x10000; currByte += 128) {
myFile.read(sdBuffer, 128);
@ -1049,8 +1053,16 @@ void writeFlash_SFM(int startBank, uint32_t pos) {
// Wait until write is finished
busyCheck_SFM(startBank);
}
// update progress bar
processedProgressBar += 0x10000;
draw_progressbar(processedProgressBar, totalProgressBar);
}
} else {
//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = numBanks * 0x8000;
draw_progressbar(0, totalProgressBar);
// Write lorom
for (byte currBank = 0; currBank < numBanks; currBank++) {
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
busyCheck_SFM(startBank);
}
// update progress bar
processedProgressBar += 0x8000;
draw_progressbar(processedProgressBar, totalProgressBar);
}
}
// Close the file:
@ -1155,7 +1170,7 @@ byte blankcheck_SFM(int startBank) {
byte blank = 1;
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++) {
if (readBank_SFM(currBank, currByte) != 0xFF) {
currBank = startBank + numBanks;
@ -1192,7 +1207,7 @@ unsigned long verifyFlash_SFM(int startBank, uint32_t pos) {
controlIn_SFM();
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) {
// Fill SDBuffer
myFile.read(sdBuffer, 512);
@ -1244,7 +1259,7 @@ void readFlash_SFM() {
print_FatalError(create_file_STR);
}
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 (int c = 0; c < 512; 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;
draw_progressbar(0, totalProgressBar);
for (byte currBank = start; currBank < total; currBank++) {
for (word currBank = start; currBank < total; currBank++) {
PORTL = currBank;
// Blink led
@ -653,7 +653,7 @@ void readHiRomBanks(unsigned int start, unsigned int total, FsFile* file) {
uint32_t totalProgressBar = (uint32_t)(total - start) * 1024;
draw_progressbar(0, totalProgressBar);
for (byte currBank = start; currBank < total; currBank++) {
for (word currBank = start; currBank < total; currBank++) {
PORTL = currBank;
// Blink led