# HG changeset patch # User Matti Hamalainen # Date 1506276646 -10800 # Node ID ef20200d71d74d83d6a58c7b04d0901cb92d7e36 # Parent 3bcf02e5a3754f4fda41e3b4283418c2fdef9406 Implement (buggy) support for packed and unpacked FunPaint II images in lib64gfx. diff -r 3bcf02e5a375 -r ef20200d71d7 tools/lib64gfx.c --- a/tools/lib64gfx.c Sun Sep 24 21:10:02 2017 +0300 +++ b/tools/lib64gfx.c Sun Sep 24 21:10:46 2017 +0300 @@ -428,6 +428,87 @@ } + +#define FUNPAINT2_HEADER_SIZE (0x10) + +static BOOL fmtProbeFunPaint2Header(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +{ + return + len > 30 && + dmCompareAddr16(buf, 0, fmt->addr) && + strncmp((const char *) (buf + 2), "FUNPAINT (MT) ", 14) == 0; +} + + +static int fmtProbeFunPaint2Unpacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +{ + if (fmtProbeFunPaint2Header(buf, len, fmt) && + buf[2 + 14] == 0) + return DM_PROBE_SCORE_MAX; + else + return DM_PROBE_SCORE_FALSE; +} + + +static int fmtProbeFunPaint2Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +{ + if (fmtProbeFunPaint2Header(buf, len, fmt) && + buf[2 + 14] != 0) + return DM_PROBE_SCORE_MAX; + else + return DM_PROBE_SCORE_FALSE; +} + + +static int fmtDecodeFunPaint2Unpacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +{ + return dmC64DecodeGenericBMP(img, buf + FUNPAINT2_HEADER_SIZE, len - FUNPAINT2_HEADER_SIZE, fmt); +} + + +static int fmtDecodeFunPaint2Packed(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +{ + int res; + Uint8 *mem = NULL, *end; + + if ((res = dmDecodeGenericRLE(&mem, &end, buf + FUNPAINT2_HEADER_SIZE, buf + len, *(buf + 15))) != DMERR_OK) + goto out; + + res = dmC64DecodeGenericBMP(img, mem, end - mem + 1, fmt); + +out: + dmFree(mem); + return res; +} + + +static Uint8 fmtGetPixelFunPaint2( + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbitmap, const int raster) +{ + const int vbank = (raster & 7);// + (vbitmap * 8); + int vr, vb; + if (raster < 100) + { + vb = 0; + vr = raster; + } + else + { + vb = 0; + vr = raster - 100; + } + + switch ((img->bitmap[vbitmap][bmoffs] >> vshift) & 3) + { + case 0: return img->extraData[vb][vr] & 15; break; + case 1: return img->screen[vbank][scroffs] >> 4; break; + case 2: return img->screen[vbank][scroffs] & 15; break; + default: return img->color[0][scroffs] & 15; break; + } +} + + static Uint8 fmtGetPixelBMFLI( const DMC64Image *img, const int bmoffs, const int scroffs, const int vshift, const int vbitmap, const int raster) @@ -732,6 +813,89 @@ { DT_LAST, 0, 0, 0, NULL, NULL }, } }, + +#define FP2_SCREEN_RAM(oindex, bindex) { DT_SCREEN_RAM, FP2_SCREEN_RAM_START + (0x400 * (oindex)), (bindex), 0, NULL, NULL } + + { + D64_FMT_MC | D64_FMT_FLI | D64_FMT_ILACE, "fp2", "FunPaint II (unpacked)", 0x3ff0, 33694, + C64_SCR_WIDTH, C64_SCR_HEIGHT, + C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT, + fmtProbeFunPaint2Unpacked, fmtDecodeFunPaint2Unpacked, + NULL, NULL, NULL, fmtGetPixelFunPaint2, + { +#define FP2_SCREEN_RAM_START 0 + FP2_SCREEN_RAM(0, 0), + FP2_SCREEN_RAM(1, 1), + FP2_SCREEN_RAM(2, 2), + FP2_SCREEN_RAM(3, 3), + FP2_SCREEN_RAM(4, 4), + FP2_SCREEN_RAM(5, 5), + FP2_SCREEN_RAM(6, 6), + FP2_SCREEN_RAM(7, 7), + + { DT_BITMAP, 0x2000, 0, 0, NULL, NULL }, + { DT_EXTRA_DATA, 0x3f40, 0, 100, NULL, NULL }, + { DT_COLOR_RAM, 0x4000, 0, 0, NULL, NULL }, + +#undef FP2_SCREEN_RAM_START +#define FP2_SCREEN_RAM_START 0x4000 + + FP2_SCREEN_RAM(0, 8), + FP2_SCREEN_RAM(1, 9), + FP2_SCREEN_RAM(2, 10), + FP2_SCREEN_RAM(3, 11), + FP2_SCREEN_RAM(4, 12), + FP2_SCREEN_RAM(5, 13), + FP2_SCREEN_RAM(6, 14), + FP2_SCREEN_RAM(7, 15), + + { DT_BITMAP, 0x63e8, 1, 0, NULL, NULL }, + { DT_EXTRA_DATA, 0x8328, 1, 100, NULL, NULL }, + + { DT_LAST, 0, 0, 0, NULL, NULL }, + } + }, + + { + D64_FMT_MC | D64_FMT_FLI | D64_FMT_ILACE, "fp2", "FunPaint II (packed)", 0x3ff0, 0, + C64_SCR_WIDTH, C64_SCR_HEIGHT, + C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT, + fmtProbeFunPaint2Packed, fmtDecodeFunPaint2Packed, + NULL, NULL, NULL, fmtGetPixelFunPaint2, + { +#define FP2_SCREEN_RAM_START 0 + FP2_SCREEN_RAM(0, 0), + FP2_SCREEN_RAM(1, 1), + FP2_SCREEN_RAM(2, 2), + FP2_SCREEN_RAM(3, 3), + FP2_SCREEN_RAM(4, 4), + FP2_SCREEN_RAM(5, 5), + FP2_SCREEN_RAM(6, 6), + FP2_SCREEN_RAM(7, 7), + + { DT_BITMAP, 0x2000, 0, 0, NULL, NULL }, + { DT_EXTRA_DATA, 0x3f40, 0, 100, NULL, NULL }, + { DT_COLOR_RAM, 0x4000, 0, 0, NULL, NULL }, + +#undef FP2_SCREEN_RAM_START +#define FP2_SCREEN_RAM_START 0x4000 + + FP2_SCREEN_RAM(0, 8), + FP2_SCREEN_RAM(1, 9), + FP2_SCREEN_RAM(2, 10), + FP2_SCREEN_RAM(3, 11), + FP2_SCREEN_RAM(4, 12), + FP2_SCREEN_RAM(5, 13), + FP2_SCREEN_RAM(6, 14), + FP2_SCREEN_RAM(7, 15), + + { DT_BITMAP, 0x63e8, 1, 0, NULL, NULL }, + { DT_EXTRA_DATA, 0x8328, 1, 100, NULL, NULL }, + + { DT_LAST, 0, 0, 0, NULL, NULL }, + } + }, + }; const int ndmC64ImageFormats = sizeof(dmC64ImageFormats) / sizeof(dmC64ImageFormats[0]);