Auto format

This commit is contained in:
sanni 2022-10-28 15:02:51 +02:00
parent 30d880bfa7
commit a8a981e137
10 changed files with 128 additions and 124 deletions

View File

@ -76,25 +76,60 @@ char ver[5] = "11.0";
//******************************************
// ENABLE MODULES
//******************************************
// remove // before #define to enable a module
#define enable_SNES
#define enable_SFM
#define enable_SV
#define enable_MD
#define enable_SMS
#define enable_N64
#define enable_GBX
#define enable_NES
// add/remove // before #define to disable/enable modules you
// don't need/need to save programm storage space and dynamic memory
// ColecoVision
#define enable_COLV
// Flashrom Programmer for SNES repros
#define enable_FLASH
#define enable_FLASH16
// #define enable_PCE
// #define enable_WS
// #define enable_NGP
// #define enable_INTV
// #define enable_COLV
// #define enable_VBOY
// #define enable_WSV
// #define enable_PCW
//#define enable_FLASH16
// Game Boy (Color) and Advance
#define enable_GBX
// Intellivision
#define enable_INTV
// Sega Mega Drive/Genesis
#define enable_MD
// Nintendo 64
#define enable_N64
// Nintendo Entertainment System/Family Computer
#define enable_NES
// Neo Geo Pocket
#define enable_NGP
// PC Engine/TurboGrafx 16
#define enable_PCE
// Benesse Pocket Challenge W
//#define enable_PCW
// Sega Master System
#define enable_SMS
// Super Nintendo
#define enable_SNES
// Super Famicom SF Memory Cassette
#define enable_SFM
// Super Famicom Satellaview
#define enable_SV
// Virtual Boy
#define enable_VBOY
// WonderSwan
//#define enable_WS
// Watara Supervision
//#define enable_WSV
//******************************************
// HW CONFIGS
@ -533,30 +568,31 @@ static const uint32_t crc_32_tab[] PROGMEM = { /* CRC polynomial 0xedb88320 */
// Defined as a macros, as compiler disregards inlining requests and these are
// performance-critical functions.
#define UPDATE_CRC(crc, ch) do { \
#define UPDATE_CRC(crc, ch) \
do { \
uint8_t idx = ((crc) ^ (ch)) & 0xff; \
uint32_t tab_value = pgm_read_dword(crc_32_tab + idx); \
(crc) = tab_value ^ ((crc) >> 8); \
} while (0)
} while (0)
uint32_t updateCRC(const byte *buffer, size_t length, uint32_t crc) {
uint32_t updateCRC(const byte* buffer, size_t length, uint32_t crc) {
for (size_t c = 0; c < length; c++) {
UPDATE_CRC(crc, buffer[c]);
}
return crc;
}
uint32_t calculateCRC(const byte *buffer, size_t length) {
uint32_t calculateCRC(const byte* buffer, size_t length) {
uint32_t crc = 0xFFFFFFFF;
crc = updateCRC(buffer, length, crc);
return ~crc;
}
uint32_t calculateCRC(FsFile &infile) {
uint32_t calculateCRC(FsFile& infile) {
uint32_t byte_count;
uint32_t crc = 0xFFFFFFFF;
while((byte_count = infile.read(sdBuffer, sizeof(sdBuffer))) != 0) {
while ((byte_count = infile.read(sdBuffer, sizeof(sdBuffer))) != 0) {
crc = updateCRC(sdBuffer, byte_count, crc);
}
return ~crc;
@ -632,7 +668,7 @@ void get_line(char* str_buf, FsFile* readfile, uint8_t maxi) {
}
}
void rewind_line(FsFile &readfile, byte count=1) {
void rewind_line(FsFile& readfile, byte count = 1) {
uint32_t position = readfile.curPosition();
count++;
for (byte count_newline = 0; count_newline < count; count_newline++) {
@ -1886,7 +1922,7 @@ void setColor_RGB(byte r, byte g, byte b) {
// Extract ASCII printable characters from input, collapsing underscores and spaces.
// Use when extracting titles from cartridges, to build a rom title.
byte buildRomName(char *output, const byte *input, byte length) {
byte buildRomName(char* output, const byte* input, byte length) {
byte input_char;
byte output_len = 0;
for (unsigned int i = 0; i < length; i++) {
@ -1900,10 +1936,7 @@ byte buildRomName(char *output, const byte *input, byte length) {
}
}
while (
output_len && (
output[output_len - 1] == '_' || output[output_len - 1] == ' '
)
) {
output_len && (output[output_len - 1] == '_' || output[output_len - 1] == ' ')) {
output_len--;
}
output[output_len] = 0;
@ -2384,7 +2417,7 @@ void statusLED(boolean on) {
*/
}
#else
void statusLED(boolean on __attribute__ ((unused))) {
void statusLED(boolean on __attribute__((unused))) {
}
#endif

View File

@ -903,9 +903,7 @@ void getCartInfo_GB() {
// Strip trailing white space
while (
myLength &&
(romName[myLength - 1] == '_' || romName[myLength - 1] == ' ')
) {
myLength && (romName[myLength - 1] == '_' || romName[myLength - 1] == ' ')) {
myLength--;
}
romName[myLength] = 0;
@ -918,34 +916,16 @@ void getCartInfo_GB() {
// MMM01 (Mani 4 in 1)
if (
(
strncmp(romName, "BOUKENJIMA2 SET", 15) == 0 && sdBuffer[0x14D] == 0
) || (
strncmp(romName, "BUBBLEBOBBLE SET", 16) == 0 && sdBuffer[0x14D] == 0xC6
) || (
strncmp(romName, "GANBARUGA SET", 13) == 0 && sdBuffer[0x14D] == 0x90
) || (
strncmp(romName, "RTYPE 2 SET", 11) == 0 && sdBuffer[0x14D] == 0x32
)
) {
strncmp(romName, "BOUKENJIMA2 SET", 15) == 0 && sdBuffer[0x14D] == 0)
|| (strncmp(romName, "BUBBLEBOBBLE SET", 16) == 0 && sdBuffer[0x14D] == 0xC6) || (strncmp(romName, "GANBARUGA SET", 13) == 0 && sdBuffer[0x14D] == 0x90) || (strncmp(romName, "RTYPE 2 SET", 11) == 0 && sdBuffer[0x14D] == 0x32)) {
romType = 0x0B;
}
// MBC1M
if (
(
strncmp(romName, "MOMOCOL", 7) == 0 && sdBuffer[0x14D] == 0x28
) || (
strncmp(romName, "BOMCOL", 6) == 0 && sdBuffer[0x14D] == 0x86
) || (
strncmp(romName, "GENCOL", 6) == 0 && sdBuffer[0x14D] == 0x8A
) || (
strncmp(romName, "SUPERCHINESE 123", 16) == 0 && sdBuffer[0x14D] == 0xE4
) || (
strncmp(romName, "MORTALKOMBATI&II", 16) == 0 && sdBuffer[0x14D] == 0xB9
) || (
strncmp(romName, "MORTALKOMBAT DUO", 16) == 0 && sdBuffer[0x14D] == 0xA7
)
) {
strncmp(romName, "MOMOCOL", 7) == 0 && sdBuffer[0x14D] == 0x28)
|| (strncmp(romName, "BOMCOL", 6) == 0 && sdBuffer[0x14D] == 0x86) || (strncmp(romName, "GENCOL", 6) == 0 && sdBuffer[0x14D] == 0x8A) || (strncmp(romName, "SUPERCHINESE 123", 16) == 0 && sdBuffer[0x14D] == 0xE4) || (strncmp(romName, "MORTALKOMBATI&II", 16) == 0 && sdBuffer[0x14D] == 0xB9) || (strncmp(romName, "MORTALKOMBAT DUO", 16) == 0 && sdBuffer[0x14D] == 0xA7)) {
romType += 0x100;
}

View File

@ -51,7 +51,7 @@ void gbaMenu() {
case 0:
// Read rom
if (cartSize == 0) {
const byte romOptionsGBASize[] = {1, 2, 4, 8, 16, 32};
const byte romOptionsGBASize[] = { 1, 2, 4, 8, 16, 32 };
// create submenu with title and 4 options to choose from
unsigned char GBARomMenu;
// Copy menuOptions out of progmem
@ -313,7 +313,7 @@ void setup_GBA() {
*****************************************/
static byte getSaveType() {
if (saveType == 0) {
const byte saveOptionsGBAType[] = {1, 2, 3, 6, 4, 5};
const byte saveOptionsGBAType[] = { 1, 2, 3, 6, 4, 5 };
// create submenu with title and 6 options to choose from
unsigned char GBASaveMenu;
// Copy menuOptions out of progmem

View File

@ -12,22 +12,21 @@
static const char gbSmartMenuItem1[] PROGMEM = "Game Menu";
static const char gbSmartMenuItem2[] PROGMEM = "Flash Menu";
//static const char gbSmartMenuItem3[] PROGMEM = "Reset"; (stored in common strings array)
static const char* const menuOptionsGBSmart[] PROGMEM = { gbSmartMenuItem1, gbSmartMenuItem2, string_reset2 };
static const char *const menuOptionsGBSmart[] PROGMEM = { gbSmartMenuItem1, gbSmartMenuItem2, string_reset2 };
static const char gbSmartFlashMenuItem1[] PROGMEM = "Read Flash";
static const char gbSmartFlashMenuItem2[] PROGMEM = "Write Flash";
static const char gbSmartFlashMenuItem3[] PROGMEM = "Back";
static const char* const menuOptionsGBSmartFlash[] PROGMEM = { gbSmartFlashMenuItem1, gbSmartFlashMenuItem2, gbSmartFlashMenuItem3 };
static const char *const menuOptionsGBSmartFlash[] PROGMEM = { gbSmartFlashMenuItem1, gbSmartFlashMenuItem2, gbSmartFlashMenuItem3 };
static const char gbSmartGameMenuItem1[] PROGMEM = "Read Game";
static const char gbSmartGameMenuItem2[] PROGMEM = "Read SRAM";
static const char gbSmartGameMenuItem3[] PROGMEM = "Write SRAM";
static const char gbSmartGameMenuItem4[] PROGMEM = "Switch Game";
//static const char gbSmartGameMenuItem5[] PROGMEM = "Reset"; (stored in common strings array)
static const char* const menuOptionsGBSmartGame[] PROGMEM = { gbSmartGameMenuItem1, gbSmartGameMenuItem2, gbSmartGameMenuItem3, gbSmartGameMenuItem4, string_reset2 };
static const char *const menuOptionsGBSmartGame[] PROGMEM = { gbSmartGameMenuItem1, gbSmartGameMenuItem2, gbSmartGameMenuItem3, gbSmartGameMenuItem4, string_reset2 };
struct GBSmartGameInfo
{
struct GBSmartGameInfo {
uint8_t start_bank;
uint8_t rom_type;
uint8_t rom_size;

View File

@ -858,7 +858,7 @@ void setCart_INTV() {
myFile.seekCur(1);
// Read SRAM size
byte sramSize __attribute__ ((unused)) = myFile.read() - 48;
byte sramSize __attribute__((unused)) = myFile.read() - 48;
// Skip rest of line
myFile.seekCur(2);

View File

@ -667,16 +667,14 @@ void dataIn_MD() {
/******************************************
MEGA DRIVE functions
*****************************************/
byte copyToRomName_MD(char *output, const byte *input, byte length) {
byte copyToRomName_MD(char* output, const byte* input, byte length) {
byte myLength = 0;
for (byte i = 0; i < 48; i++) {
if (
(
(input[i] >= '0' && input[i] <= '9') ||
(input[i] >= 'A' && input[i] <= 'z')
) && myLength < length
) {
(input[i] >= '0' && input[i] <= '9') || (input[i] >= 'A' && input[i] <= 'z'))
&& myLength < length) {
output[myLength++] = input[i];
}
}

View File

@ -1726,7 +1726,7 @@ void verifyCRC() {
}
// Calculates the checksum of the header
boolean checkHeader(byte *buf) {
boolean checkHeader(byte* buf) {
word sum = 0;
word buf_sum = (buf[28] << 8) + buf[29];

View File

@ -460,9 +460,9 @@ struct database_entry {
char filename[128];
char crc_str[8 + 1 + 8 + 1 + 32 + 1];
uint32_t crc;
char *crc512_str;
char* crc512_str;
uint32_t crc512;
char *iNES_str;
char* iNES_str;
};
void printPRG(unsigned long myOffset) {
@ -495,7 +495,7 @@ void setDefaultRomName() {
romName[4] = '\0';
}
void setRomnameFromString(const char *input) {
void setRomnameFromString(const char* input) {
byte myLength = 0;
for (byte i = 0; i < 20 && myLength < 15; i++) {
// Stop at first "(" to remove "(Country)"
@ -503,10 +503,7 @@ void setRomnameFromString(const char *input) {
break;
}
if (
(input[i] >= '0' && input[i] <= '9') ||
(input[i] >= 'A' && input[i] <= 'Z') ||
(input[i] >= 'a' && input[i] <= 'z')
) {
(input[i] >= '0' && input[i] <= '9') || (input[i] >= 'A' && input[i] <= 'Z') || (input[i] >= 'a' && input[i] <= 'z')) {
romName[myLength++] = input[i];
}
}
@ -568,10 +565,7 @@ void getMapping() {
readDatabaseEntry(database, &entry);
//if checksum search was successful set mapper and end search, also filter out 0xFF checksum
if (
entry.crc512 != 0xBD7BC39F && (
entry.crc512 == oldcrc32 || entry.crc512 == oldcrc32MMC3
)
) {
entry.crc512 != 0xBD7BC39F && (entry.crc512 == oldcrc32 || entry.crc512 == oldcrc32MMC3)) {
// Rewind to start of entry
rewind_line(database, 3);
break;
@ -597,8 +591,8 @@ void getMapping() {
// Display database
while (database.available()) {
byte iNES[16];
byte *output;
char *input;
byte* output;
char* input;
struct database_entry entry;
@ -709,7 +703,7 @@ void getMapping() {
database.close();
}
static void readDatabaseEntry(FsFile &database, struct database_entry *entry) {
static void readDatabaseEntry(FsFile& database, struct database_entry* entry) {
get_line(entry->filename, &database, sizeof(entry->filename));
get_line(entry->crc_str, &database, sizeof(entry->crc_str));
skip_line(&database);
@ -724,7 +718,7 @@ static void readDatabaseEntry(FsFile &database, struct database_entry *entry) {
entry->crc512 = strtoul(entry->crc512_str, NULL, 16);
}
static void selectMapping(FsFile &database) {
static void selectMapping(FsFile& database) {
// Select starting letter
byte myLetter = starting_letter();
@ -2514,7 +2508,7 @@ void readPRG(boolean readrom) {
case 87: // 16K/32K
case 184: // 32K
case 185: // 16K/32K
for (word address = 0; address < (((word) prgsize) * 0x4000) + 0x4000; address += 512) { // 16K or 32K
for (word address = 0; address < (((word)prgsize) * 0x4000) + 0x4000; address += 512) { // 16K or 32K
dumpPRG(base, address);
}
break;
@ -2542,7 +2536,7 @@ void readPRG(boolean readrom) {
case 2: // 128K/256K
for (int i = 0; i < 8; i++) { // 128K/256K
write_prg_byte(0x8000, i);
for (word address = 0x0; address < (((word) prgsize - 3) * 0x4000) + 0x4000; address += 512) {
for (word address = 0x0; address < (((word)prgsize - 3) * 0x4000) + 0x4000; address += 512) {
dumpPRG(base, address);
}
}
@ -2764,9 +2758,9 @@ void readPRG(boolean readrom) {
case 36:
banks = int_pow(2, prgsize) / 2;
for (int i = 0; i < banks; i++) {
write_prg_byte(0xFFA0+i, (i<<4));
write_prg_byte(0xFFA0 + i, (i << 4));
write_prg_byte(0x4101, 0);
write_prg_byte(0x4102, (i<<4));
write_prg_byte(0x4102, (i << 4));
write_prg_byte(0x4103, 0);
write_prg_byte(0x4100, 0);
write_prg_byte(0x4103, 0xFF);
@ -3017,7 +3011,7 @@ void readPRG(boolean readrom) {
case 91:
banks = int_pow(2, prgsize);
for (int i = 0; i < (banks-2); i += 2) {
for (int i = 0; i < (banks - 2); i += 2) {
write_prg_byte(0x7000, (i | 0));
write_prg_byte(0x7001, (i | 1));
for (word address = 0x0; address < 0x4000; address += 512) {
@ -3854,10 +3848,10 @@ void readCHR(boolean readrom) {
case 91:
banks = int_pow(2, chrsize) / 2;
for (int i = 0; i < banks; i += 8) {
write_prg_byte(0x6000, (i/2) | 0);
write_prg_byte(0x6001, (i/2) | 1);
write_prg_byte(0x6002, (i/2) | 2);
write_prg_byte(0x6003, (i/2) | 3);
write_prg_byte(0x6000, (i / 2) | 0);
write_prg_byte(0x6001, (i / 2) | 1);
write_prg_byte(0x6002, (i / 2) | 2);
write_prg_byte(0x6003, (i / 2) | 3);
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}

View File

@ -440,7 +440,7 @@ uint32_t calculate_crc32(int n, unsigned char c[], uint32_t r) {
return r;
}
void crc_search(char *file_p, char *folder_p, uint32_t rom_size __attribute__ ((unused)), uint32_t crc) {
void crc_search(char *file_p, char *folder_p, uint32_t rom_size __attribute__((unused)), uint32_t crc) {
FsFile rom, script;
char gamename[100];
char crc_file[9], crc_search[9];

View File

@ -433,7 +433,7 @@ void sfmFlashMenu() {
#endif
// Read the games from the menu area
void getGames(char gameCode[8][20], boolean *hasMenu, byte *numGames) {
void getGames(char gameCode[8][20], boolean* hasMenu, byte* numGames) {
// Set data pins to input
dataIn();
// Set control pins to input