mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2025-04-10 19:15:14 +00:00
Fixed warnings and whitespace
This commit is contained in:
parent
78609688c5
commit
4c7186b1f1
|
@ -81,7 +81,6 @@ static GameInfo * LoadCROMDirect(const struct ROMMap *Map, const char *file)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
const struct ROMMap *CROM = 0;
|
|
||||||
while (Map->region && strcmp(Map->region, "CROM"))
|
while (Map->region && strcmp(Map->region, "CROM"))
|
||||||
++Map;
|
++Map;
|
||||||
if (!Map->region)
|
if (!Map->region)
|
||||||
|
@ -131,9 +130,7 @@ void CopyRegion(UINT8 *dest, unsigned destOffset, unsigned destSize, UINT8 *src,
|
||||||
// Search for a ROM within a single game based on its CRC
|
// Search for a ROM within a single game based on its CRC
|
||||||
static bool FindROMByCRCInGame(const struct GameInfo **gamePtr, int *romIdxPtr, const struct GameInfo *Game, UINT32 crc)
|
static bool FindROMByCRCInGame(const struct GameInfo **gamePtr, int *romIdxPtr, const struct GameInfo *Game, UINT32 crc)
|
||||||
{
|
{
|
||||||
unsigned j;
|
for (int j = 0; Game->ROM[j].region != NULL; j++)
|
||||||
|
|
||||||
for (j = 0; Game->ROM[j].region != NULL; j++)
|
|
||||||
{
|
{
|
||||||
if (crc == Game->ROM[j].crc) // found it!
|
if (crc == Game->ROM[j].crc) // found it!
|
||||||
{
|
{
|
||||||
|
@ -149,15 +146,13 @@ static bool FindROMByCRCInGame(const struct GameInfo **gamePtr, int *romIdxPtr,
|
||||||
// Search for a ROM in the complete game list based on CRC32 and return its GameInfo and ROMInfo entries
|
// Search for a ROM in the complete game list based on CRC32 and return its GameInfo and ROMInfo entries
|
||||||
static bool FindROMByCRC(const struct GameInfo **gamePtr, int *romIdxPtr, const struct GameInfo *GameList, const struct GameInfo *TryGame, UINT32 crc)
|
static bool FindROMByCRC(const struct GameInfo **gamePtr, int *romIdxPtr, const struct GameInfo *GameList, const struct GameInfo *TryGame, UINT32 crc)
|
||||||
{
|
{
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
if (TryGame != NULL)
|
if (TryGame != NULL)
|
||||||
{
|
{
|
||||||
if (FindROMByCRCInGame(gamePtr, romIdxPtr, TryGame, crc) == OKAY)
|
if (FindROMByCRCInGame(gamePtr, romIdxPtr, TryGame, crc) == OKAY)
|
||||||
return OKAY;
|
return OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; GameList[i].title != NULL; i++)
|
for (int i = 0; GameList[i].title != NULL; i++)
|
||||||
{
|
{
|
||||||
if (FindROMByCRCInGame(gamePtr, romIdxPtr, &(GameList[i]), crc) == OKAY)
|
if (FindROMByCRCInGame(gamePtr, romIdxPtr, &(GameList[i]), crc) == OKAY)
|
||||||
return OKAY;
|
return OKAY;
|
||||||
|
@ -185,12 +180,9 @@ static bool ROMIsUnique(const struct GameInfo *GameList, UINT32 crc)
|
||||||
|
|
||||||
static void ByteSwap(UINT8 *buf, unsigned size)
|
static void ByteSwap(UINT8 *buf, unsigned size)
|
||||||
{
|
{
|
||||||
unsigned i;
|
for (size_t i = 0; i < size; i += 2)
|
||||||
UINT8 x;
|
|
||||||
|
|
||||||
for (i = 0; i < size; i += 2)
|
|
||||||
{
|
{
|
||||||
x = buf[i+0];
|
UINT8 x = buf[i+0];
|
||||||
buf[i+0] = buf[i+1];
|
buf[i+0] = buf[i+1];
|
||||||
buf[i+1] = x;
|
buf[i+1] = x;
|
||||||
}
|
}
|
||||||
|
@ -200,12 +192,10 @@ static void ByteSwap(UINT8 *buf, unsigned size)
|
||||||
static bool LoadROM(UINT8 *buf, unsigned bufSize, const struct ROMMap *Map, const struct ROMInfo *ROM, unzFile zf, const char *zipFile, bool loadAll)
|
static bool LoadROM(UINT8 *buf, unsigned bufSize, const struct ROMMap *Map, const struct ROMInfo *ROM, unzFile zf, const char *zipFile, bool loadAll)
|
||||||
{
|
{
|
||||||
char file[2048+1];
|
char file[2048+1];
|
||||||
int err, bytes;
|
|
||||||
unz_file_info fileInfo;
|
unz_file_info fileInfo;
|
||||||
unsigned i, j, destIdx, srcIdx;
|
|
||||||
|
|
||||||
// Read the file into the buffer
|
// Read the file into the buffer
|
||||||
err = unzGetCurrentFileInfo(zf, &fileInfo, file, 2048, NULL, 0, NULL, 0);
|
int err = unzGetCurrentFileInfo(zf, &fileInfo, file, 2048, NULL, 0, NULL, 0);
|
||||||
if (err != UNZ_OK)
|
if (err != UNZ_OK)
|
||||||
return ErrorLog("Unable to extract a file name from '%s'.", zipFile);
|
return ErrorLog("Unable to extract a file name from '%s'.", zipFile);
|
||||||
if (fileInfo.uncompressed_size != ROM->fileSize)
|
if (fileInfo.uncompressed_size != ROM->fileSize)
|
||||||
|
@ -213,7 +203,7 @@ static bool LoadROM(UINT8 *buf, unsigned bufSize, const struct ROMMap *Map, cons
|
||||||
err = unzOpenCurrentFile(zf);
|
err = unzOpenCurrentFile(zf);
|
||||||
if (UNZ_OK != err)
|
if (UNZ_OK != err)
|
||||||
return ErrorLog("Unable to read '%s' from '%s'.", file, zipFile);
|
return ErrorLog("Unable to read '%s' from '%s'.", file, zipFile);
|
||||||
bytes = unzReadCurrentFile(zf, buf, bufSize);
|
size_t bytes = unzReadCurrentFile(zf, buf, bufSize);
|
||||||
if (bytes != ROM->fileSize)
|
if (bytes != ROM->fileSize)
|
||||||
{
|
{
|
||||||
unzCloseCurrentFile(zf);
|
unzCloseCurrentFile(zf);
|
||||||
|
@ -228,19 +218,17 @@ static bool LoadROM(UINT8 *buf, unsigned bufSize, const struct ROMMap *Map, cons
|
||||||
ByteSwap(buf, ROM->fileSize);
|
ByteSwap(buf, ROM->fileSize);
|
||||||
|
|
||||||
// Find out how to map the ROM and do it
|
// Find out how to map the ROM and do it
|
||||||
for (i = 0; Map[i].region != NULL; i++)
|
for (size_t i = 0; Map[i].region != NULL; i++)
|
||||||
{
|
{
|
||||||
if (!strcmp(Map[i].region, ROM->region))
|
if (!strcmp(Map[i].region, ROM->region))
|
||||||
{
|
{
|
||||||
destIdx = ROM->offset;
|
size_t destIdx = ROM->offset;
|
||||||
for (srcIdx = 0; srcIdx < ROM->fileSize; )
|
for (size_t srcIdx = 0; srcIdx < ROM->fileSize; )
|
||||||
{
|
{
|
||||||
for (j = 0; j < ROM->groupSize; j++)
|
for (size_t j = 0; j < ROM->groupSize; j++)
|
||||||
Map[i].ptr[destIdx+j] = buf[srcIdx++];
|
Map[i].ptr[destIdx+j] = buf[srcIdx++];
|
||||||
|
|
||||||
destIdx += ROM->stride;
|
destIdx += ROM->stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OKAY;
|
return OKAY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,20 +264,16 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
|
||||||
if (!strcmp(zipFile, "crom.bin"))
|
if (!strcmp(zipFile, "crom.bin"))
|
||||||
return LoadCROMDirect(Map, zipFile);
|
return LoadCROMDirect(Map, zipFile);
|
||||||
|
|
||||||
unzFile zf, zfp = NULL;
|
|
||||||
unz_file_info fileInfo;
|
|
||||||
const struct GameInfo *Game = NULL;
|
const struct GameInfo *Game = NULL;
|
||||||
const struct GameInfo *CurGame; // this is the game to which the last ROM found is thought to belong
|
const struct GameInfo *CurGame; // this is the game to which the last ROM found is thought to belong
|
||||||
|
unz_file_info fileInfo;
|
||||||
string zipFileParent, zfpErr = "";
|
string zipFileParent, zfpErr = "";
|
||||||
int romIdx; // index within Game->ROM
|
int romIdx = 0; // index within Game->ROM
|
||||||
unsigned romsFound[sizeof(Game->ROM)/sizeof(struct ROMInfo)], numROMs;
|
unsigned romsFound[sizeof(Game->ROM)/sizeof(struct ROMInfo)];
|
||||||
int err;
|
|
||||||
unsigned i, maxSize;
|
|
||||||
bool multipleGameError = false;
|
bool multipleGameError = false;
|
||||||
UINT8 *buf;
|
|
||||||
|
|
||||||
// Try to open file
|
// Try to open file
|
||||||
zf = unzOpen(zipFile);
|
unzFile zf = unzOpen(zipFile);
|
||||||
if (NULL == zf)
|
if (NULL == zf)
|
||||||
{
|
{
|
||||||
ErrorLog("Could not open '%s'.", zipFile);
|
ErrorLog("Could not open '%s'.", zipFile);
|
||||||
|
@ -297,7 +281,7 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
|
||||||
}
|
}
|
||||||
|
|
||||||
// First pass: scan every file and determine the game
|
// First pass: scan every file and determine the game
|
||||||
err = unzGoToFirstFile(zf);
|
int err = unzGoToFirstFile(zf);
|
||||||
if (UNZ_OK != err)
|
if (UNZ_OK != err)
|
||||||
{
|
{
|
||||||
ErrorLog("Unable to read the contents of '%s' (code %X)", zipFile, err);
|
ErrorLog("Unable to read the contents of '%s' (code %X)", zipFile, err);
|
||||||
|
@ -343,6 +327,7 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unzFile zfp = 0;
|
||||||
if (CurGame->parent)
|
if (CurGame->parent)
|
||||||
{
|
{
|
||||||
// Create parent zip file name
|
// Create parent zip file name
|
||||||
|
@ -421,12 +406,13 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute how many ROM files this game has
|
// Compute how many ROM files this game has
|
||||||
for (numROMs = 0; Game->ROM[numROMs].region != NULL; numROMs++)
|
size_t numROMs = 0;
|
||||||
|
for (; Game->ROM[numROMs].region != NULL; numROMs++)
|
||||||
;
|
;
|
||||||
|
|
||||||
// If not all ROMs were present, tell the user
|
// If not all ROMs were present, tell the user
|
||||||
err = OKAY;
|
err = OKAY;
|
||||||
for (i = 0; i < numROMs; i++)
|
for (size_t i = 0; i < numROMs; i++)
|
||||||
{
|
{
|
||||||
if ((0 == romsFound[i]) && !Game->ROM[i].optional) // if not found and also not optional
|
if ((0 == romsFound[i]) && !Game->ROM[i].optional) // if not found and also not optional
|
||||||
err |= (int) ErrorLog("'%s' (CRC=%08X) is missing from '%s'%s.", Game->ROM[i].fileName, Game->ROM[i].crc, zipFile, zfp ? zfpErr.c_str() : "");
|
err |= (int) ErrorLog("'%s' (CRC=%08X) is missing from '%s'%s.", Game->ROM[i].fileName, Game->ROM[i].crc, zipFile, zfp ? zfpErr.c_str() : "");
|
||||||
|
@ -439,13 +425,13 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a scratch buffer big enough to hold the biggest ROM
|
// Allocate a scratch buffer big enough to hold the biggest ROM
|
||||||
maxSize = 0;
|
size_t maxSize = 0;
|
||||||
for (i = 0; i < numROMs; i++)
|
for (size_t i = 0; i < numROMs; i++)
|
||||||
{
|
{
|
||||||
if (Game->ROM[i].fileSize > maxSize)
|
if (Game->ROM[i].fileSize > maxSize)
|
||||||
maxSize = Game->ROM[i].fileSize;
|
maxSize = Game->ROM[i].fileSize;
|
||||||
}
|
}
|
||||||
buf = new(std::nothrow) UINT8[maxSize];
|
UINT8 *buf = new(std::nothrow) UINT8[maxSize];
|
||||||
if (NULL == buf)
|
if (NULL == buf)
|
||||||
{
|
{
|
||||||
unzClose(zf);
|
unzClose(zf);
|
||||||
|
@ -507,7 +493,7 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
|
||||||
{
|
{
|
||||||
// See if any ROMs (that are not optional) could not be found
|
// See if any ROMs (that are not optional) could not be found
|
||||||
err = OKAY;
|
err = OKAY;
|
||||||
for (i = 0; i < numROMs; i++)
|
for (size_t i = 0; i < numROMs; i++)
|
||||||
{
|
{
|
||||||
if (!(romsFound[i] || Game->ROM[i].optional)) // if ROM not found and also not optional
|
if (!(romsFound[i] || Game->ROM[i].optional)) // if ROM not found and also not optional
|
||||||
err = ErrorLog("Could not load '%s' (CRC=%08X) from '%s'%s.", Game->ROM[i].fileName, Game->ROM[i].crc, zipFile, zfp ? zfpErr.c_str() : "");
|
err = ErrorLog("Could not load '%s' (CRC=%08X) from '%s'%s.", Game->ROM[i].fileName, Game->ROM[i].crc, zipFile, zfp ? zfpErr.c_str() : "");
|
||||||
|
|
Loading…
Reference in a new issue