From 7762fa4d5454be7be0e89b09986f31bbdff79a83 Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 10 Jul 2020 17:25:12 +0100 Subject: bit of work on graphics, mostly setup --- tools/nitrogfx/gfx.c | 6 +++--- tools/nitrogfx/gfx.h | 2 +- tools/nitrogfx/main.c | 7 ++++++- tools/nitrogfx/options.h | 1 + tools/nitrogfx/util.c | 7 ++++++- tools/nitrogfx/util.h | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 3315e00e..a80d341b 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -359,7 +359,7 @@ void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int m free(buffer); } -void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder) +void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101) { FILE *fp = fopen(path, "wb"); @@ -407,7 +407,7 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in break; } - WriteGenericNtrHeader(fp, "RGCN", bufferSize + 0x20, byteOrder); + WriteGenericNtrHeader(fp, "RGCN", bufferSize + 0x20, byteOrder, version101); unsigned char charHeader[0x20] = { 0x52, 0x41, 0x48, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00 }; @@ -545,7 +545,7 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr) uint32_t extSize = size + (ncpr ? 0x10 : 0x18); //NCLR header - WriteGenericNtrHeader(fp, (ncpr ? "RPCN" : "RLCN"), extSize, !ncpr); + WriteGenericNtrHeader(fp, (ncpr ? "RPCN" : "RLCN"), extSize, !ncpr, false); unsigned char palHeader[0x18] = { diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index da56c5c5..1b097336 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -31,7 +31,7 @@ struct Image { void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); -void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder); +void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101); void FreeImage(struct Image *image); void ReadGbaPalette(char *path, struct Palette *palette); void ReadNtrPalette(char *path, struct Palette *palette); diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 2f5b2735..076e7076 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -88,7 +88,7 @@ void ConvertPngToNtr(char *inputPath, char *outputPath, struct PngToNtrOptions * ReadPng(inputPath, &image); - WriteNtrImage(outputPath, options->numTiles, options->bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder); + WriteNtrImage(outputPath, options->numTiles, options->bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101); FreeImage(&image); } @@ -320,6 +320,7 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a options.metatileHeight = 1; options.clobberSize = false; options.byteOrder = true; + options.version101 = false; for (int i = 3; i < argc; i++) { @@ -385,6 +386,10 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a { options.byteOrder = false; } + else if (strcmp(option, "-version101") == 0) + { + options.version101 = true; + } else { FATAL_ERROR("Unrecognized option \"%s\".\n", option); diff --git a/tools/nitrogfx/options.h b/tools/nitrogfx/options.h index 8376348f..77006f21 100644 --- a/tools/nitrogfx/options.h +++ b/tools/nitrogfx/options.h @@ -28,6 +28,7 @@ struct PngToNtrOptions { int metatileHeight; bool clobberSize; bool byteOrder; + bool version101; }; diff --git a/tools/nitrogfx/util.c b/tools/nitrogfx/util.c index 73a128a1..304a2319 100644 --- a/tools/nitrogfx/util.c +++ b/tools/nitrogfx/util.c @@ -124,13 +124,18 @@ void WriteWholeFile(char *path, void *buffer, int bufferSize) fclose(fp); } -void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder) +void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder, bool version101) { unsigned char header[0x10] = { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00 }; //magic number memcpy(header, magicNumber, 4); + if (version101) + { + header[6] = 0x01; + } + //byte order if (!byteorder) { diff --git a/tools/nitrogfx/util.h b/tools/nitrogfx/util.h index f181b66e..bb1cd4ad 100644 --- a/tools/nitrogfx/util.h +++ b/tools/nitrogfx/util.h @@ -11,6 +11,6 @@ char *GetFileExtension(char *path); unsigned char *ReadWholeFile(char *path, int *size); unsigned char *ReadWholeFileZeroPadded(char *path, int *size, int padAmount); void WriteWholeFile(char *path, void *buffer, int bufferSize); -void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder); +void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder, bool version101); #endif // UTIL_H -- cgit v1.2.3 From 6b746c4bff86737b9ca6a3a14dcb543a1216d194 Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 10 Jul 2020 21:57:37 +0100 Subject: IR handling for palettes, potion and antidote/brn heal/frz heal --- tools/nitrogfx/gfx.c | 8 +++++++- tools/nitrogfx/gfx.h | 2 +- tools/nitrogfx/main.c | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index a80d341b..0acb4133 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -534,7 +534,7 @@ void WriteGbaPalette(char *path, struct Palette *palette) fclose(fp); } -void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr) +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir) { FILE *fp = fopen(path, "wb"); @@ -594,6 +594,12 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr) } } + if (ir) + { + colours[510] = 'I'; + colours[511] = 'R'; + } + fwrite(colours, 1, 256 * 2, fp); fclose(fp); diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index 1b097336..ef7926d1 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -36,6 +36,6 @@ void FreeImage(struct Image *image); void ReadGbaPalette(char *path, struct Palette *palette); void ReadNtrPalette(char *path, struct Palette *palette); void WriteGbaPalette(char *path, struct Palette *palette); -void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr); +void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir); #endif // GFX_H diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 076e7076..b922e4b2 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -411,6 +411,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c { struct Palette palette; bool ncpr = false; + bool ir = false; for (int i = 3; i < argc; i++) { @@ -420,6 +421,10 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c { ncpr = true; } + else if (strcmp(option, "-ir") == 0) + { + ir = true; + } else { FATAL_ERROR("Unrecognized option \"%s\".\n", option); @@ -427,7 +432,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c } ReadPngPalette(inputPath, &palette); - WriteNtrPalette(outputPath, &palette, ncpr); + WriteNtrPalette(outputPath, &palette, ncpr, ir); } void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) @@ -487,6 +492,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, { int numColors = 0; bool ncpr = false; + bool ir = false; for (int i = 3; i < argc; i++) { @@ -509,6 +515,10 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, { ncpr = true; } + else if (strcmp(option, "-ir") == 0) + { + ir = true; + } else { FATAL_ERROR("Unrecognized option \"%s\".\n", option); @@ -522,7 +532,7 @@ void HandleJascToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, if (numColors != 0) palette.numColors = numColors; - WriteNtrPalette(outputPath, &palette, ncpr); + WriteNtrPalette(outputPath, &palette, ncpr, ir); } void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) -- cgit v1.2.3 From d038e60ba5baee009a0b76466cf362ae7747d48f Mon Sep 17 00:00:00 2001 From: red031000 Date: Sat, 11 Jul 2020 16:13:04 +0100 Subject: add sopc support to ncgr --- tools/nitrogfx/gfx.c | 15 ++++++++++++--- tools/nitrogfx/gfx.h | 2 +- tools/nitrogfx/main.c | 7 ++++++- tools/nitrogfx/options.h | 1 + tools/nitrogfx/util.c | 6 +++++- tools/nitrogfx/util.h | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 0acb4133..7bbc7ddf 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -359,7 +359,7 @@ void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int m free(buffer); } -void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101) +void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101, bool sopc) { FILE *fp = fopen(path, "wb"); @@ -407,7 +407,7 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in break; } - WriteGenericNtrHeader(fp, "RGCN", bufferSize + 0x20, byteOrder, version101); + WriteGenericNtrHeader(fp, "RGCN", bufferSize + (sopc ? 0x30 : 0x20), byteOrder, version101, sopc ? 2 : 1); unsigned char charHeader[0x20] = { 0x52, 0x41, 0x48, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00 }; @@ -446,6 +446,15 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in fwrite(pixelBuffer, 1, bufferSize, fp); + if (sopc) + { + unsigned char sopcBuffer[0x10] = { 0x53, 0x4F, 0x50, 0x43, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00 }; + sopcBuffer[14] = numTiles & 0xFF; + sopcBuffer[15] = (numTiles >> 8) & 0xFF; + + fwrite(sopcBuffer, 1, 0x10, fp); + } + free(pixelBuffer); fclose(fp); } @@ -545,7 +554,7 @@ void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir) uint32_t extSize = size + (ncpr ? 0x10 : 0x18); //NCLR header - WriteGenericNtrHeader(fp, (ncpr ? "RPCN" : "RLCN"), extSize, !ncpr, false); + WriteGenericNtrHeader(fp, (ncpr ? "RPCN" : "RLCN"), extSize, !ncpr, false, 1); unsigned char palHeader[0x18] = { diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h index ef7926d1..54e6fb16 100644 --- a/tools/nitrogfx/gfx.h +++ b/tools/nitrogfx/gfx.h @@ -31,7 +31,7 @@ struct Image { void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); -void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101); +void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101, bool sopc); void FreeImage(struct Image *image); void ReadGbaPalette(char *path, struct Palette *palette); void ReadNtrPalette(char *path, struct Palette *palette); diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index b922e4b2..13eeb749 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -88,7 +88,7 @@ void ConvertPngToNtr(char *inputPath, char *outputPath, struct PngToNtrOptions * ReadPng(inputPath, &image); - WriteNtrImage(outputPath, options->numTiles, options->bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101); + WriteNtrImage(outputPath, options->numTiles, options->bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc); FreeImage(&image); } @@ -321,6 +321,7 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a options.clobberSize = false; options.byteOrder = true; options.version101 = false; + options.sopc = false; for (int i = 3; i < argc; i++) { @@ -390,6 +391,10 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a { options.version101 = true; } + else if (strcmp(option, "-sopc") == 0) + { + options.sopc = true; + } else { FATAL_ERROR("Unrecognized option \"%s\".\n", option); diff --git a/tools/nitrogfx/options.h b/tools/nitrogfx/options.h index 77006f21..dc90a2a2 100644 --- a/tools/nitrogfx/options.h +++ b/tools/nitrogfx/options.h @@ -29,6 +29,7 @@ struct PngToNtrOptions { bool clobberSize; bool byteOrder; bool version101; + bool sopc; }; diff --git a/tools/nitrogfx/util.c b/tools/nitrogfx/util.c index 304a2319..7dc4ca89 100644 --- a/tools/nitrogfx/util.c +++ b/tools/nitrogfx/util.c @@ -124,7 +124,7 @@ void WriteWholeFile(char *path, void *buffer, int bufferSize) fclose(fp); } -void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder, bool version101) +void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder, bool version101, uint16_t sectionCount) { unsigned char header[0x10] = { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00 }; @@ -149,5 +149,9 @@ void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, boo header[10] = (size >> 16) & 0xFF; header[11] = (size >> 24) & 0xFF; + //section count + header[14] = sectionCount & 0xFF; + header[15] = (sectionCount >> 8) & 0xFF; + fwrite(header, 1, 0x10, fp); } diff --git a/tools/nitrogfx/util.h b/tools/nitrogfx/util.h index bb1cd4ad..b757aa4d 100644 --- a/tools/nitrogfx/util.h +++ b/tools/nitrogfx/util.h @@ -11,6 +11,6 @@ char *GetFileExtension(char *path); unsigned char *ReadWholeFile(char *path, int *size); unsigned char *ReadWholeFileZeroPadded(char *path, int *size, int padAmount); void WriteWholeFile(char *path, void *buffer, int bufferSize); -void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder, bool version101); +void WriteGenericNtrHeader(FILE* fp, const char* magicNumber, uint32_t size, bool byteorder, bool version101, uint16_t sectionCount); #endif // UTIL_H -- cgit v1.2.3 From f76e211631b6b86ce7000c16acc5368d78b14f42 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sat, 11 Jul 2020 21:50:56 +0100 Subject: bit of title work, maths is still wrong --- tools/nitrogfx/gfx.c | 17 ++++++++++------- tools/nitrogfx/main.c | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c index 7bbc7ddf..c62a25f8 100644 --- a/tools/nitrogfx/gfx.c +++ b/tools/nitrogfx/gfx.c @@ -419,11 +419,14 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in if (!clobberSize) { - charHeader[8] = numTiles & 0xFF; - charHeader[9] = (numTiles >> 8) & 0xFF; - - charHeader[10] = tileSize & 0xFF; - charHeader[11] = (tileSize >> 8) & 0xFF; + //charHeader[8] = numTiles & 0xFF; + //charHeader[9] = (numTiles >> 8) & 0xFF; + charHeader[8] = (bufferSize / (256 * bitDepth)) & 0xFF; + charHeader[9] = ((bufferSize / (256 * bitDepth)) >> 8) & 0xFF; + + //charHeader[10] = tileSize & 0xFF; + //charHeader[11] = (tileSize >> 8) & 0xFF; + charHeader[10] = 0x20; //todo figure out if this changes } else { @@ -449,8 +452,8 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in if (sopc) { unsigned char sopcBuffer[0x10] = { 0x53, 0x4F, 0x50, 0x43, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00 }; - sopcBuffer[14] = numTiles & 0xFF; - sopcBuffer[15] = (numTiles >> 8) & 0xFF; + sopcBuffer[14] = (bufferSize / (256 * bitDepth)) & 0xFF; + sopcBuffer[15] = ((bufferSize / (256 * bitDepth)) >> 8) & 0xFF; fwrite(sopcBuffer, 1, 0x10, fp); } diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c index 13eeb749..0aaad201 100644 --- a/tools/nitrogfx/main.c +++ b/tools/nitrogfx/main.c @@ -88,7 +88,7 @@ void ConvertPngToNtr(char *inputPath, char *outputPath, struct PngToNtrOptions * ReadPng(inputPath, &image); - WriteNtrImage(outputPath, options->numTiles, options->bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc); + WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc); FreeImage(&image); } -- cgit v1.2.3