changeset 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 59bde9a7220d
children a17b37872d8e
files tools/64vw.c tools/gfxconv.c
diffstat 2 files changed, 61 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tools/64vw.c	Mon May 27 05:59:57 2019 +0300
+++ b/tools/64vw.c	Mon May 27 06:01:32 2019 +0300
@@ -23,6 +23,9 @@
         optListOnly  = FALSE;
 size_t  noptFilenames1 = 0, noptFilenames2 = 0;
 char    **optFilenames = NULL;
+char    *optCharROMFilename = NULL;
+
+DMC64MemBlock setCharROM;
 
 
 static const DMOptArg optList[] =
@@ -36,6 +39,7 @@
     { 6, 'i', "info",       "Print information only (no display)", OPT_NONE },
     { 7, 'l', "list",       "Output list of files that were recognized (implies -i)", OPT_NONE },
     { 8, 'p', "probe",      "Probe only (do not attempt to decode the image)", OPT_NONE },
+    { 9, 'G', "char-rom",   "Set character ROM file to be used.", OPT_ARGREQ },
 };
 
 const int optListN = sizeof(optList) / sizeof(optList[0]);
@@ -155,6 +159,10 @@
             optProbeOnly = TRUE;
             break;
 
+        case 9:
+            optCharROMFilename = optArg;
+            break;
+
         default:
             dmErrorMsg("Unknown option '%s'.\n", currArg);
             return FALSE;
@@ -208,7 +216,7 @@
 }
 
 
-int dmDecodeC64Image(const DMC64Image *cimage, const DMC64ImageFormat *fmt,
+int dmDecodeC64Image(DMC64Image *cimage, const DMC64ImageFormat *fmt,
     SDL_Surface *surf, const DMC64ImageConvSpec *spec)
 {
     DMImage bmap;
@@ -224,11 +232,17 @@
     if ((ret = dmSetDefaultC64Palette(&bmap)) != DMERR_OK)
         return ret;
 
+    if (cimage->charData->data == NULL)
+        cimage->charData = &setCharROM;
+
     if (fmt->format->convertFrom != NULL)
         ret = fmt->format->convertFrom(&bmap, cimage, fmt, spec);
     else
         ret = dmC64ConvertGenericBMP2Image(&bmap, cimage, fmt, spec);
 
+    if (cimage->charData == &setCharROM)
+        cimage->charData = NULL;
+
     SDL_SetPaletteColors(surf->format->palette, (SDL_Color *) bmap.pal->colors, 0, bmap.pal->ncolors);
 
     dmPaletteFree(bmap.pal);
@@ -252,6 +266,7 @@
     dmC64InitializeFormats();
     dmSetScaleFactor(2.0);
     memset(&spec, 0, sizeof(spec));
+    memset(&setCharROM, 0, sizeof(setCharROM));
 
     dmInitProg("64vw", "Display some C64 bitmap graphics formats", "0.4", NULL, NULL);
 
@@ -321,6 +336,20 @@
         goto exit;
     }
 
+    // Check character ROM filename
+    if (optCharROMFilename == NULL)
+        optCharROMFilename = DM_DEF_CHARGEN;
+
+    // Attempt to read character ROM
+    dmMsg(1, "Using character ROM file '%s'.\n",
+        optCharROMFilename);
+
+    if ((ret = dmReadDataFile(NULL, optCharROMFilename, &setCharROM.data, &setCharROM.size)) != DMERR_OK)
+    {
+        dmErrorMsg("Could not read character ROM from '%s'.\n",
+            optCharROMFilename);
+    }
+
     // Initialize libSDL
     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
     {
@@ -546,6 +575,7 @@
 exit:
     // Cleanup
     dmFree(optFilenames);
+    dmC64MemBlockFree(&setCharROM);
 
     if (texture != NULL)
         SDL_DestroyTexture(texture);
--- 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)