Mercurial > hg > dmlib
diff tools/lib64gfx.c @ 1846:88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
combine and separate data from multiple sources/destinations into one data block.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 Jun 2018 22:31:52 +0300 |
parents | 19d4f76e003d |
children | cfc7046fb176 |
line wrap: on
line diff
--- a/tools/lib64gfx.c Fri Jun 22 21:47:31 2018 +0300 +++ b/tools/lib64gfx.c Fri Jun 22 22:31:52 2018 +0300 @@ -174,6 +174,17 @@ } +int dmC64MemBlockReAlloc(DMC64MemBlock *blk, const size_t size) +{ + if ((blk->data = dmRealloc(blk->data, size)) == NULL) + return DMERR_MALLOC; + + dmMemset(blk->data + blk->size, 0, size - blk->size); + blk->size = size; + return DMERR_OK; +} + + int dmC64MemBlockCopy(DMC64MemBlock *dst, const DMC64MemBlock *src) { if (src->data != NULL && src->size > 0) @@ -882,7 +893,7 @@ case DS_EXTRA_DATA: // XXX BZZZT .. a nasty cast here --v dmC64GetOpMemBlockAndName(img, op->subject, op->bank, (const DMC64MemBlock **) &blk, &blkname); - if ((dmC64MemBlockAlloc(blk, size)) != DMERR_OK) + if ((dmC64MemBlockReAlloc(blk, op->offs2 + size)) != DMERR_OK) { return dmError(DMERR_MALLOC, "Could not allocate '%s' block! " @@ -892,15 +903,15 @@ switch (op->type) { case DO_COPY: - memcpy(blk->data, src, size); + memcpy(blk->data + op->offs2, src, size); break; case DO_SET_MEM: - dmMemset(blk->data, *src, size); + dmMemset(blk->data + op->offs2, *src, size); break; case DO_SET_OP: - dmMemset(blk->data, op->offs, size); + dmMemset(blk->data + op->offs2, op->offs, size); break; default: @@ -1094,15 +1105,15 @@ blkname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); goto err; } - if (size > blk->size) + if (op->offs2 + size > blk->size) { res = dmError(DMERR_INTERNAL, "'%s' size mismatch %d <> %d in " - "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", - blkname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); + "op #%d, offs=%d ($%04x), bank=%d, offs2=%d ($%02x), size=%d ($%04x)\n", + blkname, op->offs2 + size, blk->size, i, op->offs, op->offs, op->bank, op->offs2, op->offs2, size, size); goto err; } - memcpy(dst, blk->data, size); + memcpy(dst, blk->data + op->offs2, size); break; case DO_SET_MEM: