diff tools/lib64fmts.c @ 1788:04e13949b314

Implement support for packed variant of Black Mail FLI format.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 13 Jun 2018 01:57:07 +0300
parents 5ea4713e9e0f
children 9f5c5ab0e85e
line wrap: on
line diff
--- a/tools/lib64fmts.c	Wed Jun 13 01:46:18 2018 +0300
+++ b/tools/lib64fmts.c	Wed Jun 13 01:57:07 2018 +0300
@@ -382,6 +382,59 @@
 }
 
 
+static int fmtProbeBlackMailFLIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
+{
+    if (buf->len > 16 &&
+        dmCompareAddr16(buf, 0, fmt->addr) &&
+        dmCompareAddr16(buf, 2 + 1, fmt->addr + buf->len - 3) &&
+        dmCompareAddr16(buf, 2 + 3, 0x7f3f))
+        return DM_PROBE_SCORE_MAX;
+
+    return DM_PROBE_SCORE_FALSE;
+}
+
+
+static int fmtDecodeBlackMailFLIPacked(DMC64Image *img, const DMGrowBuf *psrc, const DMC64ImageFormat *fmt)
+{
+    int res;
+    DMGrowBuf dst, src;
+    DMCompParams cfg;
+
+    cfg.func         = fmt->name;
+    cfg.type         = DM_COMP_RLE_MARKER;
+    cfg.flags        = DM_RLE_BYTE_RUNS | DM_RLE_ORDER_1 | DM_RLE_ZERO_COUNT_MAX |
+                       DM_RLE_BACKWARDS_INPUT | DM_RLE_BACKWARDS_OUTPUT | DM_OUT_CROP_END;
+    cfg.rleMarkerB   = psrc->data[0];
+    cfg.cropOutLen   = 0x4442 - 2; // Crop to unpacked size - load address
+
+    // Skip the RLE marker byte, packed data end address and unpacked data end address
+    dmGrowBufConstCopyOffs(&src, psrc, 1 + 2 + 2);
+
+    if ((res = dmDecodeGenericRLEAlloc(&dst, &src, &cfg)) != DMERR_OK)
+        goto out;
+
+    res = dmC64DecodeGenericBMP(img, &dst, fmt);
+
+out:
+    dmGrowBufFree(&dst);
+    return res;
+}
+
+
+static Uint8 fmtGetPixelBlackMailFLI(
+    const DMC64Image *img, const int bmoffs, const int scroffs,
+    const int shift, const int bitmap, const int rasterX, const int rasterY)
+{
+    const int vbank = rasterY & 7;
+    (void) rasterX;
+
+    return dmC64GetGenericMCPixel(
+        img, bmoffs, scroffs, shift,
+        vbank, bitmap, 0,
+        img->extraData[0].data[rasterY] & 15);
+}
+
+
 static BOOL fmtTruePaintGetLaceType(DMC64Image *img, const DMC64EncDecOp *op,
     const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
 {
@@ -746,20 +799,6 @@
 }
 
 
-static Uint8 fmtGetPixelBlackMailFLI(
-    const DMC64Image *img, const int bmoffs, const int scroffs,
-    const int shift, const int bitmap, const int rasterX, const int rasterY)
-{
-    const int vbank = rasterY & 7;
-    (void) rasterX;
-
-    return dmC64GetGenericMCPixel(
-        img, bmoffs, scroffs, shift,
-        vbank, bitmap, 0,
-        img->extraData[0].data[rasterY] & 15);
-}
-
-
 static Uint8 fmtGetPixelFLIDesigner(
     const DMC64Image *img, const int bmoffs, const int scroffs,
     const int shift, const int bitmap, const int rasterX, const int rasterY)
@@ -899,7 +938,19 @@
         }
     },
 
-    { // #1: UNUSED
+    { // #1: Black Mail FLI Graph
+        D64_FMT_MC | D64_FMT_FLI,
+        C64_SCR_WIDTH / 2, C64_SCR_HEIGHT,
+        C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT,
+        NULL, NULL,
+        fmtGetPixelBlackMailFLI,
+        {
+            { DO_COPY     , DS_EXTRA_DATA  , 0x0000, 0,  200, NULL, NULL },
+            { DO_COPY     , DS_COLOR_RAM   , 0x0100, 0,  0, NULL, NULL },
+            DEF_SCREEN_RAMS_8(0x0500, 0, 0x400),
+            { DO_COPY     , DS_BITMAP_RAM  , 0x2500, 0,  0, NULL, NULL },
+            { DO_LAST     , 0              , 0     , 0,  0, NULL, NULL },
+        }
     },
 
     { // #2: Art Studio etc. Hires
@@ -1436,24 +1487,17 @@
     },
 
     {
-        "bml", "Blackmail FLI (unpacked)", 0x3b00, 17474, DM_FMT_RDWR,
+        "bml", "Black Mail FLI (unpacked)", 0x3b00, 17474, DM_FMT_RDWR,
         NULL,
         NULL, NULL,
-        {
-            D64_FMT_MC | D64_FMT_FLI,
-            C64_SCR_WIDTH / 2, C64_SCR_HEIGHT,
-            C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT,
-            NULL, NULL,
-            fmtGetPixelBlackMailFLI,
-            {
-                { DO_COPY     , DS_EXTRA_DATA  , 0x0000, 0,  200, NULL, NULL },
-                { DO_COPY     , DS_COLOR_RAM   , 0x0100, 0,  0, NULL, NULL },
-                DEF_SCREEN_RAMS_8(0x0500, 0, 0x400),
-                { DO_COPY     , DS_BITMAP_RAM  , 0x2500, 0,  0, NULL, NULL },
-                { DO_LAST     , 0              , 0     , 0,  0, NULL, NULL },
-            }
-        },
-        NULL
+        { }, &dmC64CommonFormats[1]
+    },
+
+    {
+        "bmlp", "Black Mail FLI (packed)", 0x38f0, 0, DM_FMT_RD,
+        fmtProbeBlackMailFLIPacked,
+        fmtDecodeBlackMailFLIPacked, NULL,
+        { }, &dmC64CommonFormats[1]
     },
 
     {