Trim some old file read related code

This commit is contained in:
Garhoogin 2025-05-29 13:12:43 -05:00 committed by GitHub
parent c8077dfe59
commit 13351c005e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 40 additions and 55 deletions

View File

@ -200,7 +200,7 @@ void ChrInit(NCGR *ncgr, int format) {
void ChrReadChars(NCGR *ncgr, const unsigned char *buffer) {
int nChars = ncgr->nTiles;
unsigned char **tiles = (unsigned char **) calloc(nChars, sizeof(BYTE **));
unsigned char **tiles = (unsigned char **) calloc(nChars, sizeof(unsigned char **));
for (int i = 0; i < nChars; i++) {
tiles[i] = (unsigned char *) calloc(64, 1);
unsigned char *tile = tiles[i];
@ -214,7 +214,7 @@ void ChrReadChars(NCGR *ncgr, const unsigned char *buffer) {
//4-bit graphics: unpack
for (int j = 0; j < 32; j++) {
BYTE b = *buffer;
unsigned char b = *buffer;
tile[j * 2] = b & 0xF;
tile[j * 2 + 1] = b >> 4;
buffer++;
@ -270,11 +270,8 @@ void ChrReadGraphics(NCGR *ncgr, const unsigned char *buffer) {
}
}
int ChrReadHudson(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
if (size < 8) return 1; //file too small
if (*buffer == 0x10) return 1; //TODO: LZ77 decompress
static int ChrReadHudson(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
int type = ChrIsValidHudson(buffer, size);
if (type == NCGR_TYPE_INVALID) return 1;
int nCharacters = 0;
if (type == NCGR_TYPE_HUDSON) {
@ -318,10 +315,10 @@ int ChrReadHudson(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
ncgr->tilesX = tilesX;
ncgr->tilesY = tilesY;
ChrReadGraphics(ncgr, buffer);
return 0;
return OBJ_STATUS_SUCCESS;
}
int ChriIsCommonRead(NCGR *ncgr, const unsigned char *buffer, unsigned int size, int type) {
static int ChriIsCommonRead(NCGR *ncgr, const unsigned char *buffer, unsigned int size, int type) {
int footerOffset = ChriIsCommonScanFooter(buffer, size, type);
int width = 0, height = 0, depth = 4;
@ -383,18 +380,18 @@ int ChriIsCommonRead(NCGR *ncgr, const unsigned char *buffer, unsigned int size,
for (int i = 0; i < width * height; i++) {
ncgr->attr[i] = attr[i] & 0xF;
}
return 0;
return OBJ_STATUS_SUCCESS;
}
int ChrReadAcg(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
static int ChrReadAcg(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
return ChriIsCommonRead(ncgr, buffer, size, NCGR_TYPE_AC);
}
int ChrReadIcg(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
static int ChrReadIcg(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
return ChriIsCommonRead(ncgr, buffer, size, NCGR_TYPE_IC);
}
int ChrReadBin(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
static int ChrReadBin(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
ChrInit(ncgr, NCGR_TYPE_BIN);
ncgr->nTiles = size / 0x20;
ncgr->nBits = 4;
@ -404,10 +401,10 @@ int ChrReadBin(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
ncgr->tilesY = ncgr->nTiles / ncgr->tilesX;
ChrReadGraphics(ncgr, buffer);
return 0;
return OBJ_STATUS_SUCCESS;
}
int ChrReadGhostTrick(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
static int ChrReadGhostTrick(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
ChrInit(ncgr, NCGR_TYPE_GHOSTTRICK);
ncgr->nBits = 4;
ncgr->mappingMode = GX_OBJVRAMMODE_CHAR_1D_128K;
@ -452,10 +449,10 @@ int ChrReadGhostTrick(NCGR *ncgr, const unsigned char *buffer, unsigned int size
ncgr->nSlices = nSlices;
ChrReadGraphics(ncgr, uncomp);
free(uncomp);
return 0;
return OBJ_STATUS_SUCCESS;
}
int ChrReadNcg(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
static int ChrReadNcg(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
ChrInit(ncgr, NCGR_TYPE_NC);
unsigned int charSize = 0, attrSize = 0, linkSize = 0, cmntSize = 0;
@ -495,10 +492,10 @@ int ChrReadNcg(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
}
}
return 0;
return OBJ_STATUS_SUCCESS;
}
int ChrReadNcgr(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
static int ChrReadNcgr(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
unsigned int charSize = 0;
const unsigned char *sChar = NnsG2dFindBlockBySignature(buffer, size, "CHAR", NNS_SIG_LE, &charSize);
@ -530,7 +527,7 @@ int ChrReadNcgr(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
ncgr->bitmap = (type == 1);
ChrReadGraphics(ncgr, sChar + gfxOffset);
return 0;
return OBJ_STATUS_SUCCESS;
}
int ChrRead(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
@ -551,7 +548,7 @@ int ChrRead(NCGR *ncgr, const unsigned char *buffer, unsigned int size) {
case NCGR_TYPE_BIN:
return ChrReadBin(ncgr, buffer, size);
}
return 1;
return OBJ_STATUS_INVALID;
}
int ChrReadFile(NCGR *ncgr, LPCWSTR path) {
@ -645,11 +642,11 @@ void ChrSetWidth(NCGR *ncgr, int width) {
}
//use a temporary buffer to unswizzle and reswizzle
BYTE *bmp = (BYTE *) calloc(ncgr->tilesX * ncgr->tilesY * 64, 1);
unsigned char *bmp = (unsigned char *) calloc(ncgr->tilesX * ncgr->tilesY * 64, 1);
int bmpWidth = ncgr->tilesX * 8, bmpHeight = ncgr->tilesY * 8;
for (int y = 0; y < ncgr->tilesY; y++) {
for (int x = 0; x < ncgr->tilesX; x++) {
BYTE *tile = ncgr->tiles[y * ncgr->tilesX + x];
unsigned char *tile = ncgr->tiles[y * ncgr->tilesX + x];
int bmpX = x * 8;
int bmpY = y * 8;
@ -665,7 +662,7 @@ void ChrSetWidth(NCGR *ncgr, int width) {
bmpWidth = ncgr->tilesX * 8, bmpHeight = ncgr->tilesY * 8;
for (int y = 0; y < ncgr->tilesY; y++) {
for (int x = 0; x < ncgr->tilesX; x++) {
BYTE *tile = ncgr->tiles[y * ncgr->tilesX + x];
unsigned char *tile = ncgr->tiles[y * ncgr->tilesX + x];
int bmpX = x * 8;
int bmpY = y * 8;

View File

@ -127,8 +127,6 @@ int PalIdentify(const unsigned char *lpFile, unsigned int size) {
}
int PalReadHudson(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
if (size < 4) return 1;
int dataLength = *(uint16_t *) buffer;
int nColors = *(uint16_t *) (buffer + 2);
@ -137,7 +135,7 @@ int PalReadHudson(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
nclr->nBits = 4;
nclr->colors = (COLOR *) calloc(nColors, 2);
memcpy(nclr->colors, buffer + 4, nColors * 2);
return 0;
return OBJ_STATUS_SUCCESS;
}
int PalReadBin(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
@ -150,12 +148,10 @@ int PalReadBin(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
nclr->nBits = 4;
nclr->colors = (COLOR *) calloc(nColors, 2);
memcpy(nclr->colors, buffer, nColors * 2);
return 0;
return OBJ_STATUS_SUCCESS;
}
int PalReadNcl(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
if (!PalIsValidNcl(buffer, size)) return 1;
PalInit(nclr, NCLR_TYPE_NC);
unsigned int paltSize = 0, cmntSize = 0;
@ -173,10 +169,10 @@ int PalReadNcl(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
memcpy(nclr->header.comment, cmnt, cmntSize);
}
return 0;
return OBJ_STATUS_SUCCESS;
}
void PaliReadIStudio(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
static void PaliReadIStudio(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
unsigned int paltSize = 0;
const unsigned char *palt = NnsG2dFindBlockBySignature(buffer, size, "PALT", NNS_SIG_BE, &paltSize);
@ -188,26 +184,21 @@ void PaliReadIStudio(NCLR *nclr, const unsigned char *buffer, unsigned int size)
}
int PalReadIStudio(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
if (!PalIsValidIStudio(buffer, size)) return 1;
PalInit(nclr, NCLR_TYPE_ISTUDIO);
PaliReadIStudio(nclr, buffer, size);
return 0;
return OBJ_STATUS_SUCCESS;
}
int PalReadIStudioCompressed(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
if (!PalIsValidIStudioCompressed(buffer, size)) return 1;
PalInit(nclr, NCLR_TYPE_ISTUDIOC);
PaliReadIStudio(nclr, buffer, size);
return 0;
return OBJ_STATUS_SUCCESS;
}
int PalReadNclr(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
unsigned int plttSize = 0, pcmpSize = 0;
const unsigned char *pltt = NnsG2dFindBlockBySignature(buffer, size, "PLTT", NNS_SIG_LE, &plttSize);
const unsigned char *pcmp = NnsG2dFindBlockBySignature(buffer, size, "PCMP", NNS_SIG_LE, &pcmpSize);
if (pltt == NULL) return 1;
int bits = *(uint32_t *) (pltt + 0x0);
bits = 1 << (bits - 1);
@ -250,7 +241,7 @@ int PalReadNclr(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
nclr->compressedPalette = 1;
}
return 0;
return OBJ_STATUS_SUCCESS;
}
int PalRead(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
@ -271,7 +262,7 @@ int PalRead(NCLR *nclr, const unsigned char *buffer, unsigned int size) {
case NCLR_TYPE_NTFP:
return PalReadBin(nclr, buffer, size);
}
return 1;
return OBJ_STATUS_INVALID;
}
int PalReadFile(NCLR *nclr, LPCWSTR path) {

View File

@ -310,10 +310,7 @@ void ScrInit(NSCR *nscr, int format) {
nscr->header.combo = NULL;
}
int ScrReadHudson(NSCR *nscr, const unsigned char *file, unsigned int dwFileSize) {
if (*file == 0x10) return 1; //TODO: implement LZ77 decompression
if (dwFileSize < 8) return 1; //file too small
//if (file[4] != 0) return 1; //not a screen file
static int ScrReadHudson(NSCR *nscr, const unsigned char *file, unsigned int dwFileSize) {
int type = ScrIsValidHudson(file, dwFileSize);
int tilesX = 0, tilesY = 0;
@ -337,10 +334,10 @@ int ScrReadHudson(NSCR *nscr, const unsigned char *file, unsigned int dwFileSize
nscr->tilesY = tilesY;
ScriReadScreenData(nscr, srcData, tilesX * tilesY * 2);
ScrComputeHighestCharacter(nscr);
return 0;
return OBJ_STATUS_SUCCESS;
}
int ScrReadBin(NSCR *nscr, const unsigned char *file, unsigned int dwFileSize) {
static int ScrReadBin(NSCR *nscr, const unsigned char *file, unsigned int dwFileSize) {
ScrInit(nscr, NSCR_TYPE_BIN);
nscr->fmt = SCREENFORMAT_TEXT;
nscr->colorMode = SCREENCOLORMODE_16x16;
@ -379,10 +376,10 @@ int ScrReadBin(NSCR *nscr, const unsigned char *file, unsigned int dwFileSize) {
nscr->dataSize = nscr->tilesX * nscr->tilesY * 2;
ScriReadScreenData(nscr, file, dwFileSize);
ScrComputeHighestCharacter(nscr);
return 0;
return OBJ_STATUS_SUCCESS;
}
int ScrReadNsc(NSCR *nscr, const unsigned char *file, unsigned int size) {
static int ScrReadNsc(NSCR *nscr, const unsigned char *file, unsigned int size) {
ScrInit(nscr, NSCR_TYPE_NC);
unsigned int scrnSize = 0, escrSize = 0, clrfSize = 0, clrcSize = 0, gridSize = 0, linkSize = 0, cmntSize = 0;
@ -423,7 +420,7 @@ int ScrReadNsc(NSCR *nscr, const unsigned char *file, unsigned int size) {
//calculate highest index
ScrComputeHighestCharacter(nscr);
return 0;
return OBJ_STATUS_SUCCESS;
}
static int ScriIsCommonRead(NSCR *nscr, const unsigned char *file, unsigned int size, int type) {
@ -487,18 +484,18 @@ static int ScriIsCommonRead(NSCR *nscr, const unsigned char *file, unsigned int
ScrComputeHighestCharacter(nscr);
return 0;
return OBJ_STATUS_SUCCESS;
}
int ScrReadAsc(NSCR *nscr, const unsigned char *file, unsigned int size) {
static int ScrReadAsc(NSCR *nscr, const unsigned char *file, unsigned int size) {
return ScriIsCommonRead(nscr, file, size, NSCR_TYPE_AC);
}
int ScrReadIsc(NSCR *nscr, const unsigned char *file, unsigned int size) {
static int ScrReadIsc(NSCR *nscr, const unsigned char *file, unsigned int size) {
return ScriIsCommonRead(nscr, file, size, NSCR_TYPE_IC);
}
int ScrReadNscr(NSCR *nscr, const unsigned char *file, unsigned int size) {
static int ScrReadNscr(NSCR *nscr, const unsigned char *file, unsigned int size) {
ScrInit(nscr, NSCR_TYPE_NSCR);
unsigned int scrnSize = 0;
@ -518,7 +515,7 @@ int ScrReadNscr(NSCR *nscr, const unsigned char *file, unsigned int size) {
ScriReadScreenData(nscr, scrn + 0xC, dwDataSize);
ScrComputeHighestCharacter(nscr);
return 0;
return OBJ_STATUS_SUCCESS;
}
int ScrRead(NSCR *nscr, const unsigned char *file, unsigned int dwFileSize) {
@ -537,7 +534,7 @@ int ScrRead(NSCR *nscr, const unsigned char *file, unsigned int dwFileSize) {
case NSCR_TYPE_BIN:
return ScrReadBin(nscr, file, dwFileSize);
}
return 1;
return OBJ_STATUS_INVALID;
}
int ScrReadFile(NSCR *nscr, LPCWSTR path) {