diff tools/gfxconv.c @ 2123:47ddbedf5b56

Add initial support to 64vw and gfxconv for viewing and converting character map / mode (PETSCII and custom charset stuff etc. basically.)
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 May 2019 06:01:32 +0300
parents 88d37ec1b4d6
children a17b37872d8e
line wrap: on
line diff
--- a/tools/gfxconv.c	Mon May 27 05:59:57 2019 +0300
+++ b/tools/gfxconv.c	Mon May 27 06:01:32 2019 +0300
@@ -134,6 +134,8 @@
         optScaleMode = SCALE_AUTO;
 DMMapValue optRemapTable[DM_MAX_COLORS];
 int     optColorMap[C64_NCOLORS];
+char    *optCharROMFilename = NULL;
+
 
 DMImageConvSpec optSpec =
 {
@@ -166,6 +168,7 @@
     { 14, 'I', "interleave",    "Interleaved/planar output (some output formats)", OPT_NONE },
     { 20, 'C', "compress",      "Use compression -C <0-9>, 0 = disable, default is 9", OPT_ARGREQ },
     { 16, 'R', "remap",         "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>][+remove] | -R @map.txt[+remove])", OPT_ARGREQ },
+    { 21, 'G', "char-rom",      "Set character ROM file to be used.", OPT_ARGREQ },
 };
 
 static const int optListN = sizeof(optList) / sizeof(optList[0]);
@@ -950,6 +953,10 @@
             optSpec.compression = tmpUInt;
             break;
 
+        case 21:
+            optCharROMFilename = optArg;
+            break;
+
         default:
             dmErrorMsg("Unknown option '%s'.\n", currArg);
             return FALSE;
@@ -1926,6 +1933,10 @@
         argHandleOpt, argHandleFile, OPTH_BAILOUT))
         exit(1);
 
+    // Check character ROM filename
+    if (optCharROMFilename == NULL)
+        optCharROMFilename = DM_DEF_CHARGEN;
+
     // Determine input format, if not specified
     if (optInType == FFMT_AUTO && optInFilename != NULL)
     {
@@ -2127,6 +2138,25 @@
                 case FFMT_IMAGE:
                 case FFMT_CHAR:
                 case FFMT_SPRITE:
+                    // Set character data if required
+                    if ((inC64Fmt->format->type & D64_FMT_CHAR) &&
+                        inC64Image->charData->data == NULL)
+                    {
+                        // Attempt to read character ROM
+                        dmMsg(1, "Using character ROM file '%s'.\n",
+                            optCharROMFilename);
+
+                        if ((res = dmReadDataFile(NULL, optCharROMFilename,
+                            &inC64Image->charData->data,
+                            &inC64Image->charData->size)) != DMERR_OK)
+                        {
+                            dmErrorMsg("Could not read character ROM from '%s'.\n",
+                                optCharROMFilename);
+                            goto error;
+                        }
+                    }
+
+                    // Convert the image
                     res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt, &imageSpecC64);
 
                     if (res != DMERR_OK || outImage == NULL)