replace hardcoded bank maps with power of 2

This commit is contained in:
smesgr9000 2024-05-12 08:15:03 +02:00
parent 7ba32d24fc
commit c09e772299
4 changed files with 25 additions and 112 deletions

View File

@ -652,6 +652,22 @@ boolean compareCRC(const char* database, uint32_t crc32sum, boolean renamerom, i
return 0;
}
//******************************************
// Math Functions
//******************************************
#if (defined(ENABLE_NES) || defined(ENABLE_MSX) || defined(ENABLE_GBX))
int int_pow(int base, int exp) { // Power for int
int result = 1;
while (exp) {
if (exp & 1)
result *= base;
exp /= 2;
base *= base;
}
return result;
}
#endif
// move file pointer to first game line with matching letter. If no match is found the last database entry is selected
void seek_first_letter_in_database(FsFile& database, byte myLetter) {
char gamename_str[3];

View File

@ -1008,36 +1008,9 @@ void getCartInfo_GB() {
sprintf(checksumStr, "%02X%02X", eepbit[6], eepbit[7]);
// ROM banks
switch (romSize) {
case 0x00:
romBanks = 2;
break;
case 0x01:
romBanks = 4;
break;
case 0x02:
romBanks = 8;
break;
case 0x03:
romBanks = 16;
break;
case 0x04:
romBanks = 32;
break;
case 0x05:
romBanks = 64;
break;
case 0x06:
romBanks = 128;
break;
case 0x07:
romBanks = 256;
break;
case 0x08:
romBanks = 512;
break;
default:
romBanks = 2;
romBanks = 2;
if(romSize >= 0x01 && romSize <= 0x08) {
romBanks = int_pow(2, romSize + 1);
}
// SRAM banks
@ -1971,33 +1944,9 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) {
myFile.seekSet(0);
// ROM banks
switch (romSize) {
case 0x00:
romBanks = 2;
break;
case 0x01:
romBanks = 4;
break;
case 0x02:
romBanks = 8;
break;
case 0x03:
romBanks = 16;
break;
case 0x04:
romBanks = 32;
break;
case 0x05:
romBanks = 64;
break;
case 0x06:
romBanks = 128;
break;
case 0x07:
romBanks = 256;
break;
default:
romBanks = 2;
romBanks = 2;
if(romSize >= 0x01 && romSize <= 0x07) {
romBanks = int_pow(2, romSize + 1);
}
// Set ROM bank hi 0
@ -2417,33 +2366,9 @@ bool writeCFI_GB() {
myFile.seekSet(0);
// ROM banks
switch (romSize) {
case 0x00:
romBanks = 2;
break;
case 0x01:
romBanks = 4;
break;
case 0x02:
romBanks = 8;
break;
case 0x03:
romBanks = 16;
break;
case 0x04:
romBanks = 32;
break;
case 0x05:
romBanks = 64;
break;
case 0x06:
romBanks = 128;
break;
case 0x07:
romBanks = 256;
break;
default:
romBanks = 2;
romBanks = 2;
if(romSize >= 0x01 && romSize <= 0x07) {
romBanks = int_pow(2, romSize + 1);
}
if (romBanks <= flashBanks) {

View File

@ -290,23 +290,6 @@ void writeData_MSX(uint16_t addr, uint8_t data) {
DDRC = 0x00; // Reset to Input
}
//******************************************
// POWER
//******************************************
#ifndef ENABLE_NES
int int_pow(int base, int exp) // Power for int
{
int result = 1;
while (exp) {
if (exp & 1)
result *= base;
exp /= 2;
base *= base;
}
return result;
}
#endif
//******************************************
// CS CODE
//******************************************

View File

@ -947,17 +947,6 @@ static void write_wram_byte(unsigned int address, uint8_t data) { // Mapper 5 (
PHI2_HI;
}
int int_pow(int base, int exp) { // Power for int
int result = 1;
while (exp) {
if (exp & 1)
result *= base;
exp /= 2;
base *= base;
}
return result;
}
/******************************************
File Functions
*****************************************/