Mercurial > hg > dmlib
diff tools/64vw.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 | 56d4dc81774b |
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);