# HG changeset patch # User Matti Hamalainen # Date 1589502239 -10800 # Node ID 27271f2afa7cc5a08cbab9d8ad278cc72b7ee087 # Parent b19535da15e9a514b225fa92506fdb7bf93f36d6 Clean up the SupeRes decoder a bit. diff -r b19535da15e9 -r 27271f2afa7c tools/lib64fmts.c --- a/tools/lib64fmts.c Fri May 15 03:06:48 2020 +0300 +++ b/tools/lib64fmts.c Fri May 15 03:23:59 2020 +0300 @@ -109,6 +109,30 @@ } +static int fmtDecodeSupeRes24_25(DMSupeResCtx *ctx, Uint8 tmp) +{ + if (tmp == 0x24) + { + ctx->dbyte = 0xff; + } + else + { + if (tmp == 0x25) + { + int res; + if ((res = fmtSupeResGetByte(ctx, &tmp, 9)) != DMERR_OK) + return res; + + tmp = (0x26 + tmp) & 0xff; + } + + ctx->dbyte = tmp - 0x26; + } + + return DMERR_OK; +} + + static int fmtDecodeSupeResByte(DMSupeResCtx *ctx) { Uint8 tmp; @@ -123,13 +147,7 @@ { // ???? ctx->offs = 0xffff; - return DMERR_OK; - } - else - if (tmp == 0x24) - { - ctx->dbyte = 0xff; - return DMERR_OK; + goto out; } else if (tmp == 0x20) @@ -139,26 +157,10 @@ ctx->repcount = tmp - 0x26; - if ((res = fmtSupeResGetByte(ctx, &tmp, 3)) != DMERR_OK) + if ((res = fmtSupeResGetByte(ctx, &tmp, 3)) != DMERR_OK || + (res = fmtDecodeSupeRes24_25(ctx, tmp)) != DMERR_OK) goto out; - if (tmp == 0x24) - { - ctx->dbyte = 0xff; - } - else - { - if (tmp == 0x25) - { - if ((res = fmtSupeResGetByte(ctx, &tmp, 4)) != DMERR_OK) - goto out; - - tmp = (0x26 + tmp) & 0xff; - } - - ctx->dbyte = tmp - 0x26; - } - for (int cnt = 0; cnt < ctx->repcount; cnt++) { ctx->dstBuf[ctx->offs++] = ctx->dbyte; @@ -175,17 +177,8 @@ } else { - if (tmp == 0x25) - { - if ((res = fmtSupeResGetByte(ctx, &tmp, 9)) != DMERR_OK) - goto out; - - tmp = (0x26 + tmp) & 0xff; - } - - ctx->dbyte = tmp - 0x26; - - return DMERR_OK; + res = fmtDecodeSupeRes24_25(ctx, tmp); + goto out; } goto lcont; @@ -224,7 +217,7 @@ int res; memset(&ctx, 0, sizeof(ctx)); - ctx.dstSize = 0x4000; + ctx.dstSize = 0x3000; // As we need to modify the offs, etc. but not the data, // we will just make a shallow copy of the DMGrowBuf struct