changeset 1389:979f550ead77

Implement GunPaint support. Possibly not working correctly.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 24 Sep 2017 22:00:51 +0300
parents 4f81528aa4f6
children e3794fb2df83
files tools/lib64gfx.c
diffstat 1 files changed, 58 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64gfx.c	Sun Sep 24 21:45:35 2017 +0300
+++ b/tools/lib64gfx.c	Sun Sep 24 22:00:51 2017 +0300
@@ -336,6 +336,17 @@
 }
 
 
+static int fmtProbeGunPaint(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
+{
+    if (len > 0x400 &&
+        dmCompareAddr16(buf, 0, fmt->addr) &&
+        strncmp((const char *) (buf + 0x3ea), "GUNPAINT (JZ) ", 14) == 0)
+        return DM_PROBE_SCORE_MAX;
+
+    return DM_PROBE_SCORE_FALSE;
+}
+
+
 #define AMICA_DM_PROBE_SIZE 2048
 static int fmtProbeAmicaPaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
 {
@@ -344,7 +355,8 @@
         return DM_PROBE_SCORE_FALSE;
 
     // Interpaint Hi-Res gives a false positive
-    if (len == 9002)
+    // as do some GunPaint images ..
+    if (len == 9002 || fmtProbeGunPaint(buf, len, fmt) > DM_PROBE_SCORE_GOOD)
         return DM_PROBE_SCORE_FALSE;
 
     for (n = 0, i = 2; i < len; i++)
@@ -509,6 +521,33 @@
 }
 
 
+static Uint8 fmtGetPixelGunPaint(
+    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 < 177)
+    {
+        vb = 0;
+        vr = raster;
+    }
+    else
+    {
+        vb = 0;
+        vr = raster - 177;
+    }
+
+    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)
@@ -844,6 +883,24 @@
         }
     },
 
+    {
+        D64_FMT_MC | D64_FMT_FLI | D64_FMT_ILACE, "gun", "GunPaint (unpacked)", 0x4000, 0,
+        C64_SCR_WIDTH, C64_SCR_HEIGHT,
+        C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT,
+        fmtProbeGunPaint, NULL,
+        NULL, NULL, NULL, fmtGetPixelGunPaint,
+        {
+            DEF_SCREEN_RAMS_8(0x0000, 0)
+            { DT_BITMAP,       0x2000, 0,  0, NULL, NULL },
+            { DT_EXTRA_DATA,   0x3f4f, 0,  177, NULL, NULL },
+            { DT_COLOR_RAM,    0x4000, 0,  0, NULL, NULL },
+            DEF_SCREEN_RAMS_8(0x4400, 8)
+            { DT_BITMAP,       0x6400, 1,  0, NULL, NULL },
+            { DT_EXTRA_DATA,   0x47e8, 1,  20, NULL, NULL },
+            { DT_LAST,         0,      0,  0, NULL, NULL },
+        }
+    },
+
 };
 
 const int ndmC64ImageFormats = sizeof(dmC64ImageFormats) / sizeof(dmC64ImageFormats[0]);