changeset 2165:3d3094ba21c5

Add read-only support for Crest Super Hires FLI Editor v1.0 (unpacked) format.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Jun 2019 05:11:31 +0300
parents ed079e869d64
children 4c3fdc9c0056
files tools/lib64fmts.c
diffstat 1 files changed, 88 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Tue Jun 11 02:27:38 2019 +0300
+++ b/tools/lib64fmts.c	Tue Jun 11 05:11:31 2019 +0300
@@ -1244,6 +1244,71 @@
 }
 
 
+static int fmtGetSpritePixelCrestSHFLI(Uint8 *col,
+    const DMC64Image *img, const int sindex, const int cindex,
+    const int spr_xd, const int spr_yd, const int mask)
+{
+    const size_t offs = sindex * D64_SPR_SIZE + (D64_SPR_WIDTH_UT * spr_yd) + spr_xd;
+
+    if (offs >= img->extraData[14].size)
+        return DMERR_BOUNDS;
+
+    if (img->extraData[14].data[offs] & mask)
+    {
+        *col = img->extraData[15].data[cindex];
+        return DMERR_OK;
+    }
+
+    return -1;
+}
+
+
+static int fmtGetPixelCrestSHFLI(Uint8 *col,
+    const DMC64Image *img, const int rasterX, const int rasterY)
+{
+    DM_C64_GENERIC_SC_PIXEL_DEFS(img)
+    const int sprOffsetX = 112, sprOffsetY = 1;
+    const int nbank = rasterY & 7;
+    int res;
+
+    if (rasterY / 8 >= img->fmt->chHeight)
+    {
+        *col = img->bgcolor;
+        return DMERR_OK;
+    }
+
+    if (rasterY >= sprOffsetY &&
+        rasterX >= sprOffsetX &&
+        rasterX < sprOffsetX + 4 * D64_SPR_WIDTH_PX)
+    {
+        const int localX = rasterX - sprOffsetX,
+                  localY = rasterY - sprOffsetY;
+        const int sbank = localY & 7;
+        const int spr_yd = localY % D64_SPR_HEIGHT_PX;
+        const int spr_x = localX / D64_SPR_WIDTH_PX;
+        const int spr_xd = (localX % D64_SPR_WIDTH_PX) / 8;
+        const int mask = 1 << (7 - (localX & 7));
+
+        const int spr_offs = spr_x & 3;
+        const int spr_index1 = img->extraData[sbank].data[spr_offs];
+        const int spr_index2 = img->extraData[sbank].data[spr_offs + 4];
+
+        if ((res = fmtGetSpritePixelCrestSHFLI(col, img, spr_index1, 0, spr_xd, spr_yd, mask)) == DMERR_OK ||
+            res != -1)
+            return res;
+
+        if ((res = fmtGetSpritePixelCrestSHFLI(col, img, spr_index2, 1, spr_xd, spr_yd, mask)) == DMERR_OK ||
+            res != -1)
+            return res;
+    }
+
+    if ((res = dmC64GetGenericSCPixel(col, img, bmoffs, scroffs, vshift, nbank, 0)) != DMERR_OK)
+        return res;
+
+    return DMERR_OK;
+}
+
+
 static int fmtGetPixelHCB(Uint8 *col,
     const DMC64Image *img, const int rasterX, const int rasterY)
 {
@@ -2273,6 +2338,29 @@
     },
 
     {
+        "cshf", "Crest Super Hires FLI Editor v1.0 (unpacked)", 0x4000, 15874, DM_FMT_RD,
+        NULL,
+        NULL, NULL,
+        {
+            D64_FMT_HIRES | D64_FMT_FLI,
+            D64_SCR_WIDTH, D64_SCR_HEIGHT,
+            D64_SCR_CH_WIDTH, 21,
+            1, 1,
+            NULL, NULL,
+            fmtGetPixelCrestSHFLI,
+            {
+                DEF_REPEAT_BLOCK_8(DS_SCREEN_RAM,  0x0000, 0, 0x400, 0),
+                DEF_REPEAT_BLOCK_8(DS_EXTRA_DATA,  0x03f8, 0, 0x400, 8), // Sprite pointers for each bank
+                { DO_COPY       , DS_EXTRA_DATA  , 0x03e8, 15, 2     ,   0, NULL, NULL },  // 2 sprite colors
+                { DO_COPY       , DS_EXTRA_DATA  , 0x0000, 14, 0x3e00,   0, NULL, NULL },  // Lazily copy whole data for sprite data
+                { DO_COPY       , DS_BITMAP_RAM  , 0x2000, 0,  0,   0, NULL, NULL },
+                { DO_LAST       , 0              , 0     , 0,  0,   0, NULL, NULL },
+            }
+        },
+        NULL
+    },
+
+    {
         "cdhm", "Cosmos Designs Hires Manager (unpacked)", 0x4000, 16385, DM_FMT_RDWR,
         fmtProbeCosmosDesignsHiresManager,
         NULL, NULL,