comparison 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
comparison
equal deleted inserted replaced
1779:20bf4140eaa1 1780:5ea4713e9e0f
136 136
137 return TRUE; 137 return TRUE;
138 } 138 }
139 139
140 140
141 BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr) 141 BOOL dmCompareAddr16(const DMGrowBuf *buf, const size_t offs, const Uint16 addr)
142 { 142 {
143 return buf[offs ] == DM_GET_ADDR_LO(addr) && 143 return
144 buf[offs + 1] == DM_GET_ADDR_HI(addr); 144 offs + 1 < buf->len &&
145 buf->data[offs ] == DM_GET_ADDR_LO(addr) &&
146 buf->data[offs + 1] == DM_GET_ADDR_HI(addr);
145 } 147 }
146 148
147 149
148 int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt) 150 int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt)
149 { 151 {
1339 // Nope, perform a generic probe 1341 // Nope, perform a generic probe
1340 if (probeOffs >= buf->len) 1342 if (probeOffs >= buf->len)
1341 return DMERR_OUT_OF_DATA; 1343 return DMERR_OUT_OF_DATA;
1342 1344
1343 dmGrowBufConstCopyOffs(&tmp, buf, probeOffs); 1345 dmGrowBufConstCopyOffs(&tmp, buf, probeOffs);
1344 if (dmC64ProbeBMP(tmp.data, tmp.len, fmt) == DM_PROBE_SCORE_FALSE) 1346 if (dmC64ProbeBMP(&tmp, fmt) == DM_PROBE_SCORE_FALSE)
1345 return DMERR_NOT_SUPPORTED; 1347 return DMERR_NOT_SUPPORTED;
1346 } 1348 }
1347 1349
1348 if (loadOffs >= buf->len) 1350 if (loadOffs >= buf->len)
1349 return DMERR_INVALID_ARGS; 1351 return DMERR_INVALID_ARGS;
1439 1441
1440 // Perform probing of the given data buffer, trying to determine 1442 // Perform probing of the given data buffer, trying to determine
1441 // if it contains a supported "C64" image format. Returns the 1443 // if it contains a supported "C64" image format. Returns the
1442 // "probe score", see libgfx.h for list of values. If a match 1444 // "probe score", see libgfx.h for list of values. If a match
1443 // is found, pointer to format description is set to *pfmt. 1445 // is found, pointer to format description is set to *pfmt.
1444 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **pfmt) 1446 int dmC64ProbeBMP(const DMGrowBuf *buf, const DMC64ImageFormat **pfmt)
1445 { 1447 {
1446 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; 1448 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1;
1447 1449
1448 for (int i = 0; i < ndmC64ImageFormats; i++) 1450 for (int i = 0; i < ndmC64ImageFormats; i++)
1449 { 1451 {
1450 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; 1452 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
1451 int score = DM_PROBE_SCORE_FALSE; 1453 int score = DM_PROBE_SCORE_FALSE;
1452 if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0) 1454 if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0)
1453 { 1455 {
1454 // Generic probe just checks matching size and load address 1456 // Generic probe just checks matching size and load address
1455 if (len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr)) 1457 if (buf->len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr))
1456 score = DM_PROBE_SCORE_GOOD; 1458 score = DM_PROBE_SCORE_GOOD;
1457 } 1459 }
1458 else 1460 else
1459 if (fmt->probe != NULL) 1461 if (fmt->probe != NULL)
1460 score = fmt->probe(buf, len, fmt); 1462 score = fmt->probe(buf, fmt);
1461 1463
1462 if (score > scoreMax) 1464 if (score > scoreMax)
1463 { 1465 {
1464 scoreMax = score; 1466 scoreMax = score;
1465 scoreIndex = i; 1467 scoreIndex = i;