# HG changeset patch # User Matti Hamalainen # Date 1560471864 -10800 # Node ID cbac4912992c03d54553c6d6500964f18393a375 # Parent b259312ddb59e7572f47c14c655c110dda57ec6d Add new module "lib64util", and move some functions there from lib64gfx that do not strictly belong. diff -r b259312ddb59 -r cbac4912992c Makefile.gen --- a/Makefile.gen Fri Jun 14 01:58:05 2019 +0300 +++ b/Makefile.gen Fri Jun 14 03:24:24 2019 +0300 @@ -378,13 +378,16 @@ $(OBJPATH)lib64gfx.o: $(DMLIB)tools/lib64gfx.c $(DMLIB)tools/lib64gfx.h $(OBJPATH)libgfx.o $(COMPILE_OBJ) +$(OBJPATH)lib64util.o: $(DMLIB)tools/lib64util.c $(DMLIB)tools/lib64util.h $(OBJPATH)lib64gfx.o + $(COMPILE_OBJ) + $(OBJPATH)lib64fmts.o: $(DMLIB)tools/lib64fmts.c $(OBJPATH)lib64gfx.o $(COMPILE_OBJ) -$(OBJPATH)64vw.o: $(DMLIB)tools/64vw.c $(OBJPATH)lib64gfx.o +$(OBJPATH)64vw.o: $(DMLIB)tools/64vw.c $(OBJPATH)lib64util.o $(COMPILE_OBJ) -$(OBJPATH)gfxconv.o: $(DMLIB)tools/gfxconv.c $(OBJPATH)lib64gfx.o +$(OBJPATH)gfxconv.o: $(DMLIB)tools/gfxconv.c $(OBJPATH)lib64util.o $(COMPILE_OBJ) $(OBJPATH)ppl.o: $(TOOL_SRC)ppl.c $(DMLIB_SRC)setupfont.h \ @@ -465,10 +468,12 @@ $(TOOL_BINPATH)fanalyze$(EXEEXT): $(OBJPATH)fanalyze.o $(DMLIB_A) $(LINK_BIN) $(DM_LDFLAGS) $(TOOL_LDFLAGS) -$(TOOL_BINPATH)gfxconv$(EXEEXT): $(OBJPATH)gfxconv.o $(OBJPATH)lib64gfx.o $(OBJPATH)lib64fmts.o $(OBJPATH)libgfx.o $(DMLIB_A) +$(TOOL_BINPATH)gfxconv$(EXEEXT): $(OBJPATH)gfxconv.o $(OBJPATH)lib64gfx.o \ + $(OBJPATH)lib64fmts.o $(OBJPATH)lib64util.o $(OBJPATH)libgfx.o $(DMLIB_A) $(LINK_BIN) $(DM_LDFLAGS) $(TOOL_LDFLAGS) $(LIBPNG_LDFLAGS) $(ZLIB_LDFLAGS) -$(TOOL_BINPATH)64vw$(EXEEXT): $(OBJPATH)64vw.o $(OBJPATH)lib64gfx.o $(OBJPATH)lib64fmts.o $(OBJPATH)libgfx.o $(DMLIB_A) +$(TOOL_BINPATH)64vw$(EXEEXT): $(OBJPATH)64vw.o $(OBJPATH)lib64gfx.o \ + $(OBJPATH)lib64fmts.o $(OBJPATH)lib64util.o $(OBJPATH)libgfx.o $(DMLIB_A) $(LINK_BIN) $(DM_LDFLAGS) $(LIBPNG_LDFLAGS) $(ZLIB_LDFLAGS) $(SDL_LDFLAGS) $(TOOL_BINPATH)gentab$(EXEEXT): $(OBJPATH)gentab.o $(DMLIB_A) diff -r b259312ddb59 -r cbac4912992c tools/64vw.c --- a/tools/64vw.c Fri Jun 14 01:58:05 2019 +0300 +++ b/tools/64vw.c Fri Jun 14 03:24:24 2019 +0300 @@ -9,6 +9,7 @@ #include "dmargs.h" #include "dmfile.h" #include "lib64gfx.h" +#include "lib64util.h" #include diff -r b259312ddb59 -r cbac4912992c tools/gfxconv.c --- a/tools/gfxconv.c Fri Jun 14 01:58:05 2019 +0300 +++ b/tools/gfxconv.c Fri Jun 14 03:24:24 2019 +0300 @@ -11,6 +11,7 @@ #include "dmfile.h" #include "libgfx.h" #include "lib64gfx.h" +#include "lib64util.h" #include "dmmutex.h" diff -r b259312ddb59 -r cbac4912992c tools/lib64gfx.c --- a/tools/lib64gfx.c Fri Jun 14 01:58:05 2019 +0300 +++ b/tools/lib64gfx.c Fri Jun 14 03:24:24 2019 +0300 @@ -88,90 +88,6 @@ const int ndmC64DefaultPalettes = sizeof(dmC64DefaultPalettes) / sizeof(dmC64DefaultPalettes[0]); -char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng) -{ - static const char *fmtModesShort[] = { "*", "HiR", "MC", "ECM" }; - static const char *fmtModesLong[] = { "*", "HiRes", "MultiColor", "Extended Color Mode" }; - const char *fmtStr; - size_t nfmt = type & D64_FMT_MODE_MASK; - - if (nfmt < sizeof(fmtModesShort) / sizeof(fmtModesShort[0])) - fmtStr = lng ? fmtModesLong[nfmt] : fmtModesShort[nfmt]; - else - fmtStr = lng ? "ERROR" : "ERR"; - - snprintf(buf, len, - "%s %s%s%s", - fmtStr, - (type & D64_FMT_ILACE) ? (lng ? "Interlaced " : "ILace ") : "", - (type & D64_FMT_FLI) ? "FLI " : "", - (type & D64_FMT_CHAR) ? "CHAR" : "" - ); - - return buf; -} - - -void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent) -{ - char typeStr[64]; - - if (fmt != NULL) - { - fprintf(fh, - "%sFormat : %s [%s]\n", - indent, fmt->name, fmt->fext); - } - - if (img != NULL) - { - dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->fmt->type, TRUE); - - fprintf(fh, - "%sType : %s\n" - "%sInternal blocks : %d\n", - indent, typeStr, - indent, img->nblocks); - - if (img->fmt->type & D64_FMT_ILACE) - { - char *tmps; - switch (img->laceType) - { - case D64_ILACE_COLOR: tmps = "color"; break; - case D64_ILACE_RES: tmps = "resolution"; break; - default: tmps = "ERROR"; break; - } - fprintf(fh, - "%sInterlace type : %s\n", - indent, tmps); - } - - fprintf(fh, - "%sWidth x Height : %d x %d\n" - "%sCHwidth x CHheight : %d x %d\n" - "%sd020 / border : %d ($%02x)\n" - "%sd021 / background : %d ($%02x)\n", - indent, img->fmt->width, img->fmt->height, - indent, img->fmt->chWidth, img->fmt->chHeight, - indent, img->d020, img->d020, - indent, img->bgcolor, img->bgcolor); - } - else - if (fmt != NULL) - { - dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE); - fprintf(fh, - "%sType : %s\n" - "%sWidth x Height : %d x %d\n" - "%sCHwidth x CHheight : %d x %d\n", - indent, typeStr, - indent, fmt->format->width, fmt->format->height, - indent, fmt->format->chWidth, fmt->format->chHeight); - } -} - - int dmC64SetImagePalette(DMImage *img, const DMC64Palette *ppal, const BOOL mixed) { const DMC64Palette *cpal = ppal; diff -r b259312ddb59 -r cbac4912992c tools/lib64gfx.h --- a/tools/lib64gfx.h Fri Jun 14 01:58:05 2019 +0300 +++ b/tools/lib64gfx.h Fri Jun 14 03:24:24 2019 +0300 @@ -17,12 +17,6 @@ #endif -// Define default character ROM path -#ifndef DM_DEF_CHARGEN -#define DM_DEF_CHARGEN "/usr/local/lib64/vice/C64/chargen" -#endif - - // Bitmap constants #define D64_SCR_WIDTH 320 #define D64_SCR_HEIGHT 200 @@ -358,9 +352,6 @@ // int dmC64ProbeBMP(const DMGrowBuf *buf, const DMC64ImageFormat **fmt); -char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); -void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent); - int dmC64SetImagePalette(DMImage *img, const DMC64Palette *cpal, const BOOL mixed); BOOL dmCompareAddr16(const DMGrowBuf *buf, const size_t offs, const Uint16 addr); diff -r b259312ddb59 -r cbac4912992c tools/lib64util.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/lib64util.c Fri Jun 14 03:24:24 2019 +0300 @@ -0,0 +1,106 @@ +/* + * Common utility functions for gfxconv and 64vw + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2019 Tecnic Software productions (TNSP) + * + * Please read file 'COPYING' for information on license and distribution. + */ +#include "lib64util.h" + + +char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng) +{ + static const char *fmtModesShort[] = { "*", "HiR", "MC", "ECM" }; + static const char *fmtModesLong[] = { "*", "HiRes", "MultiColor", "Extended Color Mode" }; + const char *fmtStr; + size_t nfmt = type & D64_FMT_MODE_MASK; + + if (nfmt < sizeof(fmtModesShort) / sizeof(fmtModesShort[0])) + fmtStr = lng ? fmtModesLong[nfmt] : fmtModesShort[nfmt]; + else + fmtStr = lng ? "ERROR" : "ERR"; + + snprintf(buf, len, + "%s %s%s%s", + fmtStr, + (type & D64_FMT_ILACE) ? (lng ? "Interlaced " : "ILace ") : "", + (type & D64_FMT_FLI) ? "FLI " : "", + (type & D64_FMT_CHAR) ? "CHAR" : "" + ); + + return buf; +} + + +void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent) +{ + char typeStr[64]; + + if (fmt != NULL) + { + fprintf(fh, + "%sFormat : %s [%s]\n", + indent, fmt->name, fmt->fext); + } + + if (img != NULL) + { + dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->fmt->type, TRUE); + + fprintf(fh, + "%sType : %s\n" + "%sInternal blocks : %d\n", + indent, typeStr, + indent, img->nblocks); + + if (img->fmt->type & D64_FMT_ILACE) + { + char *tmps; + switch (img->laceType) + { + case D64_ILACE_COLOR: tmps = "color"; break; + case D64_ILACE_RES: tmps = "resolution"; break; + default: tmps = "ERROR"; break; + } + fprintf(fh, + "%sInterlace type : %s\n", + indent, tmps); + } + + fprintf(fh, + "%sWidth x Height : %d x %d\n" + "%sCHwidth x CHheight : %d x %d\n" + "%sd020 / border : %d ($%02x)\n" + "%sd021 / background : %d ($%02x)\n", + indent, img->fmt->width, img->fmt->height, + indent, img->fmt->chWidth, img->fmt->chHeight, + indent, img->d020, img->d020, + indent, img->bgcolor, img->bgcolor); + } + else + if (fmt != NULL) + { + dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE); + fprintf(fh, + "%sType : %s\n" + "%sWidth x Height : %d x %d\n" + "%sCHwidth x CHheight : %d x %d\n", + indent, typeStr, + indent, fmt->format->width, fmt->format->height, + indent, fmt->format->chWidth, fmt->format->chHeight); + } +} + + +void argShowC64PaletteHelp() +{ + fprintf(stdout, "\nAvailable C64 palettes:\n"); + for (int n = 0; n < ndmC64DefaultPalettes; n++) + { + DMC64Palette *pal = &dmC64DefaultPalettes[n]; + fprintf(stdout, + "%-10s | %s\n", + pal->name, pal->desc); + } + fprintf(stdout, "\n"); +} diff -r b259312ddb59 -r cbac4912992c tools/lib64util.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/lib64util.h Fri Jun 14 03:24:24 2019 +0300 @@ -0,0 +1,34 @@ +/* + * Common utility functions for gfxconv and 64vw + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2019 Tecnic Software productions (TNSP) + * + * Please read file 'COPYING' for information on license and distribution. + */ +#ifndef LIB64UTIL_H +#define LIB64UTIL_H 1 + +#include "lib64gfx.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +// Define default character ROM path +#ifndef DM_DEF_CHARGEN +#define DM_DEF_CHARGEN "/usr/local/lib64/vice/C64/chargen" +#endif + + + + +char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); +void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent); + + +#ifdef __cplusplus +} +#endif + +#endif // LIB64UTIL_H