diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index c3acaf2..a441156 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -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]; diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index 8ca130c..b0db5c3 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -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) { diff --git a/Cart_Reader/MSX.ino b/Cart_Reader/MSX.ino index e39eb54..b9647f4 100644 --- a/Cart_Reader/MSX.ino +++ b/Cart_Reader/MSX.ino @@ -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 //****************************************** diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index 4f27227..e88c460 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -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 *****************************************/