Mercurial > hg > dmlib
diff tools/lib64fmts.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 | 20bf4140eaa1 |
children | 04e13949b314 |
line wrap: on
line diff
--- a/tools/lib64fmts.c Tue Jun 12 18:33:35 2018 +0300 +++ b/tools/lib64fmts.c Tue Jun 12 20:37:53 2018 +0300 @@ -10,12 +10,12 @@ -static int fmtProbeKoalaPaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeKoalaPaintPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { // Attempt to prevent misprobes of unpacked Koala and Run Paint - if (len > 30 && - len != 10006 && - len != 10003 && + if (buf->len > 30 && + buf->len != 10006 && + buf->len != 10003 && dmCompareAddr16(buf, 0, fmt->addr)) return DM_PROBE_SCORE_GOOD; @@ -70,10 +70,10 @@ } -static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeDrazPaint20Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { - const Uint8 *ident = buf + 2; - if (len > 22 && + const Uint8 *ident = buf->data + 2; + if (buf->len > 22 && dmCompareAddr16(buf, 0, fmt->addr) && memcmp(ident, "DRAZPAINT ", 10) == 0 && ident[11] == '.' && ( @@ -146,11 +146,11 @@ } -static int fmtProbeDrazLace10Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeDrazLace10Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { - if (len > 22 && + if (buf->len > 22 && dmCompareAddr16(buf, 0, fmt->addr) && - memcmp(buf + 2, "DRAZLACE! 1.0", 13) == 0) + memcmp(buf->data + 2, "DRAZLACE! 1.0", 13) == 0) return DM_PROBE_SCORE_MAX; return DM_PROBE_SCORE_FALSE; @@ -177,11 +177,11 @@ static const char *fmtBDP5MagicID = "BDP 5.00"; -static int fmtProbeBDP5Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeBDP5Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { - if (len > 20 && + if (buf->len > 20 && dmCompareAddr16(buf, 0, fmt->addr) && - memcmp(buf + 2, fmtBDP5MagicID, strlen(fmtBDP5MagicID)) == 0) + memcmp(buf->data + 2, fmtBDP5MagicID, strlen(fmtBDP5MagicID)) == 0) return DM_PROBE_SCORE_MAX; return DM_PROBE_SCORE_FALSE; @@ -255,11 +255,11 @@ #define fmtGunPaintMagicLen (14) #define fmtGunPaintMagicOffs (0x3e8) -static int fmtProbeGunPaint(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeGunPaint(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { - if (len > 0x400 && + if (buf->len > 0x400 && dmCompareAddr16(buf, 0, fmt->addr) && - memcmp(buf + fmtGunPaintMagicOffs + 2, fmtGunPaintMagicID, fmtGunPaintMagicLen) == 0) + memcmp(buf->data + fmtGunPaintMagicOffs + 2, fmtGunPaintMagicID, fmtGunPaintMagicLen) == 0) return DM_PROBE_SCORE_MAX; return DM_PROBE_SCORE_FALSE; @@ -277,20 +277,21 @@ } -static int fmtProbeAmicaPaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeAmicaPaintPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { size_t i, n; - if (len < 256 || !dmCompareAddr16(buf, 0, fmt->addr)) + if (buf->len < 256 || !dmCompareAddr16(buf, 0, fmt->addr)) return DM_PROBE_SCORE_FALSE; // Interpaint Hi-Res gives a false positive // as do some GunPaint images .. - if (len == 9002 || fmtProbeGunPaint(buf, len, fmt) > DM_PROBE_SCORE_GOOD) + if (buf->len == 9002 || + fmtProbeGunPaint(buf, fmt) > DM_PROBE_SCORE_GOOD) return DM_PROBE_SCORE_FALSE; - for (n = 0, i = 2; i < len; i++) - if (buf[i] == 0xC2) n++; + for (n = 0, i = 2; i < buf->len; i++) + if (buf->data[i] == 0xC2) n++; if (n > 50) return DM_PROBE_SCORE_GOOD; @@ -361,9 +362,9 @@ } -static int fmtProbeSaracenPaint(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeSaracenPaint(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { - if ((len == 10219 || len == 10220) && + if ((buf->len == 10219 || buf->len == 10220) && dmCompareAddr16(buf, 0, fmt->addr)) return DM_PROBE_SCORE_GOOD; @@ -371,9 +372,9 @@ } -static int fmtProbeFLIDesigner(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeFLIDesigner(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { - if (len == fmt->size && + if (buf->len == fmt->size && (dmCompareAddr16(buf, 0, 0x3c00) || dmCompareAddr16(buf, 0, 0x3ff0))) return DM_PROBE_SCORE_GOOD; @@ -402,7 +403,7 @@ } -static int fmtProbeTruePaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeTruePaintPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { // The beginning/un-changing part of the BASIC bootstrap and // relocation of decompression code @@ -414,8 +415,8 @@ 0xff, 0xc6, 0xfe }; - if (len >= 512 && dmCompareAddr16(buf, 0, fmt->addr) && - memcmp(buf + 2, magicID, sizeof(magicID)) == 0) + if (buf->len >= 512 && dmCompareAddr16(buf, 0, fmt->addr) && + memcmp(buf->data + 2, magicID, sizeof(magicID)) == 0) return DM_PROBE_SCORE_MAX; return DM_PROBE_SCORE_FALSE; @@ -538,9 +539,10 @@ #define XX2_BSIZE (XX2_SIZE * 8) -static int fmtProbeFormatXX2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeFormatXX2(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { - if (len >= XX2_MIN_SIZE && len <= XX2_MIN_SIZE + 8 && + if (buf->len >= XX2_MIN_SIZE && + buf->len <= XX2_MIN_SIZE + 8 && dmCompareAddr16(buf, 0, fmt->addr)) return DM_PROBE_SCORE_MAYBE; @@ -571,18 +573,18 @@ static const char *fmtFunPaint2MagicID = "FUNPAINT (MT) "; -static int fmtProbeFunPaint2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeFunPaint2(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { - if (len > 30 && + if (buf->len > 30 && dmCompareAddr16(buf, 0, fmt->addr) && - memcmp(buf + 2, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) == 0) + memcmp(buf->data + 2, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) == 0) { // Unpacked variant - if (fmt->size != 0 && buf[14 + 2] == 0) + if (fmt->size != 0 && buf->data[14 + 2] == 0) return DM_PROBE_SCORE_MAX; // Packed variant - if (fmt->size == 0 && buf[14 + 2] != 0) + if (fmt->size == 0 && buf->data[14 + 2] != 0) return DM_PROBE_SCORE_MAX; } @@ -811,20 +813,20 @@ } -static int fmtProbeECIPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +static int fmtProbeECIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { size_t i, n; // XXX TODO: Perhaps count statistics about used byte values // and compare to value in buf[2] which is the RLE marker - if (len < 128 || + if (buf->len < 128 || !dmCompareAddr16(buf, 0, fmt->addr) || // Try to avoid misprobe of Crest Hires FLI Designer and Cosmos Design format - len == 16386 || len == 16385) + buf->len == 16386 || buf->len == 16385) return DM_PROBE_SCORE_FALSE; - for (n = 0, i = 3; i < len; i++) - if (buf[i] == buf[2]) n++; + for (n = 0, i = 3; i < buf->len; i++) + if (buf->data[i] == buf->data[2]) n++; if (n > 50) return DM_PROBE_SCORE_GOOD;