summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/nitrogfx/gfx.c94
-rw-r--r--tools/nitrogfx/gfx.h1
-rw-r--r--tools/nitrogfx/json.c49
-rw-r--r--tools/nitrogfx/json.h2
-rw-r--r--tools/nitrogfx/main.c39
-rw-r--r--tools/nitrogfx/options.h7
6 files changed, 166 insertions, 26 deletions
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c
index d158069c..be01a456 100644
--- a/tools/nitrogfx/gfx.c
+++ b/tools/nitrogfx/gfx.c
@@ -858,43 +858,85 @@ void WriteNtrCell(char *path, struct JsonToCellOptions *options)
free(KBECContents);
- unsigned int lablSize = 8 + options->cellCount * 4;
- for (i = 0; i < options->cellCount; i++)
- {
- lablSize += strlen(options->cells[i]->label) + 1;
- }
+ if (options->label)
+ {
+ unsigned int lablSize = 8 + options->cellCount * 4;
+ for (i = 0; i < options->cellCount; i++)
+ {
+ lablSize += strlen(options->cells[i]->label) + 1;
+ }
- unsigned char *labl = malloc(lablSize);
+ unsigned char *labl = malloc(lablSize);
- memset(labl, 0, lablSize);
+ memset(labl, 0, lablSize);
- strcpy((char *)labl, "LBAL");
- labl[4] = lablSize & 0xff;
- labl[5] = lablSize >> 8;
+ strcpy((char *) labl, "LBAL");
+ labl[4] = lablSize & 0xff;
+ labl[5] = lablSize >> 8;
- unsigned int position = 0;
+ unsigned int position = 0;
- for (i = 0; i < options->cellCount * 4; i += 4)
- {
- labl[i + 8] = position & 0xff;
- labl[i + 9] = position >> 8;
+ for (i = 0; i < options->cellCount * 4; i += 4)
+ {
+ labl[i + 8] = position & 0xff;
+ labl[i + 9] = position >> 8;
- position += strlen(options->cells[i / 4]->label) + 1;
- }
+ position += strlen(options->cells[i / 4]->label) + 1;
+ }
- for (int j = 0; j < options->cellCount; j++)
- {
- strcpy((char *)(labl + (i + 8)), options->cells[j]->label);
- i += strlen(options->cells[j]->label) + 1;
- }
+ for (int j = 0; j < options->cellCount; j++)
+ {
+ strcpy((char *) (labl + (i + 8)), options->cells[j]->label);
+ i += strlen(options->cells[j]->label) + 1;
+ }
- fwrite(labl, 1, lablSize, fp);
+ fwrite(labl, 1, lablSize, fp);
- free(labl);
+ free(labl);
- unsigned char texu[0xc] = { 0x54, 0x58, 0x45, 0x55, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ unsigned char texu[0xc] = {0x54, 0x58, 0x45, 0x55, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- fwrite(texu, 1, 0xc, fp);
+ fwrite(texu, 1, 0xc, fp);
+ }
fclose(fp);
}
+
+void WriteNtrScreen(char *outputPath, struct JsonToScreenOptions *options)
+{
+ FILE *fp = fopen(outputPath, "wb");
+
+ if (fp == NULL)
+ FATAL_ERROR("Failed to open \"%s\" for writing.\n", outputPath);
+
+ int totalSize = options->width * options->height * 2 + 0x14;
+
+ WriteGenericNtrHeader(fp, "RCSN", totalSize, true, false, 1);
+
+ unsigned char NSCRHeader[0x14] = { 0x4E, 0x52, 0x43, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00 };
+
+ NSCRHeader[0x4] = totalSize & 0xff;
+ NSCRHeader[0x5] = (totalSize >> 8) & 0xff;
+ NSCRHeader[0x6] = (totalSize >> 16) & 0xff;
+ NSCRHeader[0x7] = totalSize >> 24;
+
+ NSCRHeader[0x8] = (options->width * 8) & 0xff;
+ NSCRHeader[0x9] = (options->width * 8) >> 8;
+
+ NSCRHeader[0xA] = (options->height * 8) & 0xff;
+ NSCRHeader[0xB] = (options->height * 8) >> 8;
+
+ NSCRHeader[0xC] = options->bitdepth == 4 ? 0 : 1;
+
+ NSCRHeader[0x10] = (totalSize - 0x14) & 0xff;
+ NSCRHeader[0x11] = ((totalSize - 0x14) >> 8) & 0xff;
+ NSCRHeader[0x12] = ((totalSize - 0x14) >> 16) & 0xff;
+ NSCRHeader[0x13] = (totalSize - 0x14) >> 24;
+
+ fwrite(NSCRHeader, 1, 0x14, fp);
+
+ fwrite(options->data, 1, totalSize - 0x14, fp);
+
+ fclose(fp);
+}
diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h
index 728e8839..d0e6521a 100644
--- a/tools/nitrogfx/gfx.h
+++ b/tools/nitrogfx/gfx.h
@@ -39,5 +39,6 @@ void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth, int palIn
void WriteGbaPalette(char *path, struct Palette *palette);
void WriteNtrPalette(char *path, struct Palette *palette, bool ncpr, bool ir, int bitdepth, bool pad, int compNum);
void WriteNtrCell(char *path, struct JsonToCellOptions *options);
+void WriteNtrScreen(char *outputPath, struct JsonToScreenOptions *options);
#endif // GFX_H
diff --git a/tools/nitrogfx/json.c b/tools/nitrogfx/json.c
index ff52def9..fa9f9e5e 100644
--- a/tools/nitrogfx/json.c
+++ b/tools/nitrogfx/json.c
@@ -149,6 +149,48 @@ struct JsonToCellOptions *ParseNCERJson(char *path)
return options;
}
+struct JsonToScreenOptions *ParseNSCRJson(char *path)
+{
+ int fileLength;
+ unsigned char *jsonString = ReadWholeFile(path, &fileLength);
+
+ cJSON *json = cJSON_Parse((const char *)jsonString);
+
+ struct JsonToScreenOptions *options = malloc(sizeof(struct JsonToScreenOptions));
+
+ if (json == NULL)
+ {
+ const char *errorPtr = cJSON_GetErrorPtr();
+ FATAL_ERROR("Error in line \"%s\"\n", errorPtr);
+ }
+
+ cJSON *Height = cJSON_GetObjectItemCaseSensitive(json, "height");
+ cJSON *Width = cJSON_GetObjectItemCaseSensitive(json, "width");
+
+ options->height = GetInt(Height);
+ options->width = GetInt(Width);
+
+ options->data = malloc(sizeof(unsigned short) * options->height * options->width);
+
+ cJSON *layer = NULL;
+ cJSON *layers = cJSON_GetObjectItemCaseSensitive(json, "layers");
+ cJSON_ArrayForEach(layer, layers)
+ {
+ cJSON *tile = NULL;
+ cJSON *data = cJSON_GetObjectItemCaseSensitive(layer, "data");
+ int i = 0;
+ cJSON_ArrayForEach(tile, data)
+ {
+ options->data[i] = (short)(GetInt(tile) - 1); //TODO horizontal and vertical flips
+ i++;
+ }
+ }
+
+ cJSON_Delete(json);
+ free(jsonString);
+ return options;
+}
+
void FreeNCERCell(struct JsonToCellOptions *options)
{
for (int i = 0; i < options->cellCount; i++)
@@ -161,3 +203,10 @@ void FreeNCERCell(struct JsonToCellOptions *options)
}
free(options);
}
+
+void FreeNSCRScreen(struct JsonToScreenOptions *options)
+{
+ free(options->data);
+ free(options);
+}
+
diff --git a/tools/nitrogfx/json.h b/tools/nitrogfx/json.h
index b7cabf93..f297cf08 100644
--- a/tools/nitrogfx/json.h
+++ b/tools/nitrogfx/json.h
@@ -6,6 +6,8 @@
#include "options.h"
struct JsonToCellOptions *ParseNCERJson(char *path);
+struct JsonToScreenOptions *ParseNSCRJson(char *path);
void FreeNCERCell(struct JsonToCellOptions *options);
+void FreeNSCRScreen(struct JsonToScreenOptions *options);
#endif //JSON_H
diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c
index a2ddce6f..171cb5f3 100644
--- a/tools/nitrogfx/main.c
+++ b/tools/nitrogfx/main.c
@@ -686,6 +686,44 @@ void HandleJsonToNtrCellCommand(char *inputPath, char *outputPath, int argc UNUS
FreeNCERCell(options);
}
+void HandleJsonToNtrScreenCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
+{
+ struct JsonToScreenOptions *options;
+
+ options = ParseNSCRJson(inputPath);
+
+ int bitdepth = 4;
+
+ for (int i = 3; i < argc; i++)
+ {
+ char *option = argv[i];
+
+ if (strcmp(option, "-bitdepth") == 0)
+ {
+ if (i + 1 >= argc)
+ FATAL_ERROR("No bitdepth following \"-bitdepth\".\n");
+
+ i++;
+
+ if (!ParseNumber(argv[i], NULL, 10, &bitdepth))
+ FATAL_ERROR("Failed to parse bitdepth.\n");
+
+ if (bitdepth != 4 && bitdepth != 8)
+ FATAL_ERROR("Bitdepth must be 4 or 8.\n");
+ }
+ else
+ {
+ FATAL_ERROR("Unrecognized option \"%s\".\n", option);
+ }
+ }
+
+ options->bitdepth = bitdepth;
+
+ WriteNtrScreen(outputPath, options);
+
+ FreeNSCRScreen(options);
+}
+
void HandleLatinFontToPngCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
{
struct Image image;
@@ -945,6 +983,7 @@ int main(int argc, char **argv)
{ "fwjpnfont", "png", HandleFullwidthJapaneseFontToPngCommand },
{ "png", "fwjpnfont", HandlePngToFullwidthJapaneseFontCommand },
{ "json", "NCER", HandleJsonToNtrCellCommand },
+ { "json", "NSCR", HandleJsonToNtrScreenCommand },
{ NULL, "huff", HandleHuffCompressCommand },
{ NULL, "lz", HandleLZCompressCommand },
{ "huff", NULL, HandleHuffDecompressCommand },
diff --git a/tools/nitrogfx/options.h b/tools/nitrogfx/options.h
index 9b97529c..f4626df9 100644
--- a/tools/nitrogfx/options.h
+++ b/tools/nitrogfx/options.h
@@ -81,4 +81,11 @@ struct JsonToCellOptions {
struct Cell **cells;
};
+struct JsonToScreenOptions {
+ int height;
+ int width;
+ unsigned short *data;
+ int bitdepth;
+};
+
#endif // OPTIONS_H