diff tools/lib64gfx.c @ 1780:5ea4713e9e0f

Change c64 format probing API to use DMGrowBuf.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 12 Jun 2018 20:37:53 +0300
parents 4e4d54135baf
children 1ce808599129
line wrap: on
line diff
--- a/tools/lib64gfx.c	Tue Jun 12 18:33:35 2018 +0300
+++ b/tools/lib64gfx.c	Tue Jun 12 20:37:53 2018 +0300
@@ -138,10 +138,12 @@
 }
 
 
-BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr)
+BOOL dmCompareAddr16(const DMGrowBuf *buf, const size_t offs, const Uint16 addr)
 {
-    return buf[offs    ] == DM_GET_ADDR_LO(addr) &&
-           buf[offs + 1] == DM_GET_ADDR_HI(addr);
+    return
+        offs + 1 < buf->len &&
+        buf->data[offs    ] == DM_GET_ADDR_LO(addr) &&
+        buf->data[offs + 1] == DM_GET_ADDR_HI(addr);
 }
 
 
@@ -1341,7 +1343,7 @@
             return DMERR_OUT_OF_DATA;
 
         dmGrowBufConstCopyOffs(&tmp, buf, probeOffs);
-        if (dmC64ProbeBMP(tmp.data, tmp.len, fmt) == DM_PROBE_SCORE_FALSE)
+        if (dmC64ProbeBMP(&tmp, fmt) == DM_PROBE_SCORE_FALSE)
             return DMERR_NOT_SUPPORTED;
     }
 
@@ -1441,7 +1443,7 @@
 // if it contains a supported "C64" image format. Returns the
 // "probe score", see libgfx.h for list of values. If a match
 // is found, pointer to format description is set to *pfmt.
-int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **pfmt)
+int dmC64ProbeBMP(const DMGrowBuf *buf, const DMC64ImageFormat **pfmt)
 {
     int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1;
 
@@ -1452,12 +1454,12 @@
         if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0)
         {
             // Generic probe just checks matching size and load address
-            if (len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr))
+            if (buf->len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr))
                 score = DM_PROBE_SCORE_GOOD;
         }
         else
         if (fmt->probe != NULL)
-            score = fmt->probe(buf, len, fmt);
+            score = fmt->probe(buf, fmt);
 
         if (score > scoreMax)
         {