# HG changeset patch # User Matti Hamalainen # Date 1560452524 -10800 # Node ID 868b68c188e546d1e1b52aeaf04492f8ca5f8c08 # Parent 71880ce885dd16c7acff8972ec58fcf8cea38990 Cleanup Crest SHFLI decoding and use specific constants better. diff -r 71880ce885dd -r 868b68c188e5 tools/lib64fmts.c --- a/tools/lib64fmts.c Thu Jun 13 21:21:43 2019 +0300 +++ b/tools/lib64fmts.c Thu Jun 13 22:02:04 2019 +0300 @@ -1221,8 +1221,17 @@ } -#define DM_CREST_SHFLI_BANKS 8 -#define DM_CREST_SHFLI_PTRS 8 +// Horizontal character X-offset and scanline Y-offset +#define DM_CREST_SHFLI_IMG_XOFFS 14 +#define DM_CREST_SHFLI_IMG_YOFFS 1 + +// True image width and height in character blocks +#define DM_CREST_SHFLI_IMG_WIDTH (4 * D64_SPR_WIDTH_UT) +#define DM_CREST_SHFLI_IMG_HEIGHT 21 + +#define DM_CREST_SHFLI_BANKS 8 +#define DM_CREST_SHFLI_PTRS 8 + static const Uint8 fmtCrestSHFLI_Sprite_pointers[DM_CREST_SHFLI_BANKS][DM_CREST_SHFLI_PTRS] = { { 0x80, 0x84, 0x85, 0x89, 0x8A, 0x8E, 0x8F, 0x93 }, @@ -1287,8 +1296,6 @@ { const size_t fmtUncompSize = 0x1ff0; const size_t dstSize = 16 * 1024; - const int imgXOffs = 14; - const int imgWidth = 4 * D64_SPR_WIDTH_UT; Uint8 *dstBuf, *sptr, *dptr; // Check uncompressed size? @@ -1338,7 +1345,7 @@ } // Now we copy and transform the bitmap and screen RAM data. - for (int yc = 0; yc < fmt->format->chHeight * 8; yc++) + for (int yc = 0; yc < DM_CREST_SHFLI_IMG_HEIGHT * 8; yc++) { const int syy = yc / 8; const int syd = yc & 7; @@ -1346,17 +1353,17 @@ // In the image the first visible scanline is unused, but in // the compressed version data starts right away, so we offset // the destination Y coordinate by one. - const int dyc = yc + 1; + const int dyc = yc + DM_CREST_SHFLI_IMG_YOFFS; const int dyy = dyc / 8; const int dyd = dyc & 7; // Format of the bitmap data is one horizontal pixel row (12 bytes) // times 21*8 rows, e.g. the data is "linear" rows of bytes and not // arranged in usual c64 bitmap "char" order. Thus we reorder it. - sptr = mem.data + 0x1000 + imgWidth * (syd + 8 * syy); - dptr = dstBuf + 0x2000 + imgXOffs * 8 + (fmt->format->chWidth * dyy * 8) + dyd; - - for (int xc = 0; xc < imgWidth; xc++) + sptr = mem.data + 0x1000 + DM_CREST_SHFLI_IMG_WIDTH * (syd + 8 * syy); + dptr = dstBuf + 0x2000 + DM_CREST_SHFLI_IMG_XOFFS * 8 + (fmt->format->chWidth * dyy * 8) + dyd; + + for (int xc = 0; xc < DM_CREST_SHFLI_IMG_WIDTH; xc++) { dptr[xc * 8] = sptr[xc]; sptr[xc] = 0xaa; @@ -1365,10 +1372,10 @@ // A bit similar arrangement is used for the screen RAM data. // Each row of 12 bytes of data is for a bank. Next row is for // next bank, etc. - sptr = mem.data + 0x1800 + imgWidth * syd + imgWidth * 8 * syy; - dptr = dstBuf + imgXOffs + 0x0400 * dyd + fmt->format->chWidth * dyy; - - for (int xc = 0; xc < imgWidth; xc++) + sptr = mem.data + 0x1800 + DM_CREST_SHFLI_IMG_WIDTH * syd + DM_CREST_SHFLI_IMG_WIDTH * 8 * syy; + dptr = dstBuf + DM_CREST_SHFLI_IMG_XOFFS + 0x0400 * dyd + fmt->format->chWidth * dyy; + + for (int xc = 0; xc < DM_CREST_SHFLI_IMG_WIDTH; xc++) { dptr[xc] = sptr[xc]; sptr[xc] = 0xaa; @@ -1378,17 +1385,17 @@ // The sprite data is also transformed similarly, data is // in same scanline format as the bitmap. Thus we need to // place it where it belongs based on the sprite pointers. - for (int yc = 0; yc < fmt->format->chHeight * 8; yc++) + for (int yc = 0; yc < DM_CREST_SHFLI_IMG_HEIGHT * 8; yc++) { - const int yd = yc % 21; + const int yd = yc % D64_SPR_HEIGHT_PX; const Uint8 *sprPtrs = fmtCrestSHFLI_Sprite_pointers[yc % 8]; Uint8 *sp1, *sp2, *dp; - dptr = dstBuf + 3 * yd; - sp1 = mem.data + imgWidth * yc; + dptr = dstBuf + D64_SPR_WIDTH_UT * yd; + sp1 = mem.data + DM_CREST_SHFLI_IMG_WIDTH * yc; sp2 = sp1 + 0x0800; - for (int xc = 0; xc < 4; xc++) + for (int xc = 0; xc < DM_CREST_SHFLI_IMG_WIDTH / D64_SPR_WIDTH_UT; xc++) { dp = dptr + D64_SPR_SIZE * sprPtrs[xc]; for (int xd = 0; xd < D64_SPR_WIDTH_UT; xd++) @@ -1434,11 +1441,12 @@ const DMC64Image *img, const int rasterX, const int rasterY) { DM_C64_GENERIC_SC_PIXEL_DEFS(img) - const int sprOffsetX = 112, sprOffsetY = 1; + const int sprOffsetX = DM_CREST_SHFLI_IMG_XOFFS * 8, + sprOffsetY = DM_CREST_SHFLI_IMG_YOFFS; const int nbank = rasterY & 7; int res; - if (rasterY / 8 >= img->fmt->chHeight) + if (rasterY / 8 >= DM_CREST_SHFLI_IMG_HEIGHT) { *col = 0x0f; return DMERR_OK; @@ -1840,7 +1848,7 @@ { // #11: Crest Super Hires FLI Editor 1.0 (SHF) D64_FMT_HIRES | D64_FMT_FLI, D64_SCR_WIDTH, D64_SCR_HEIGHT, - D64_SCR_CH_WIDTH, 21, + D64_SCR_CH_WIDTH, 24, 1, 1, NULL, NULL, fmtGetPixelCrestSHFLI,