Mercurial > hg > dmlib
diff tools/lib64gfx.h @ 2132:6528a1398e8e
Add char map helper functions and use them.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 28 May 2019 10:32:12 +0300 |
parents | 2129d4ac6f45 |
children | 84780a9d8d17 |
line wrap: on
line diff
--- a/tools/lib64gfx.h Tue May 28 07:25:20 2019 +0300 +++ b/tools/lib64gfx.h Tue May 28 10:32:12 2019 +0300 @@ -390,6 +390,13 @@ vshift = 6 - ((rasterX * 2) & 6); +#define DM_C64_GENERIC_CHAR_PIXEL(ximg) \ + const int \ + x = rasterX / 8, \ + y = rasterY / 8, \ + scroffs = y * (ximg)->fmt->chWidth + x; \ + + // // Inline helper functions for pixel format decoding // @@ -423,6 +430,95 @@ } +static inline int dmC64GetGenericCharSCPixel(Uint8 *col, + const DMC64Image *img, const int scroffs, const int rasterX, + const int chrbank, const size_t chroffs, const int chr, + const int cbank, const int bgcolor) +{ + if (chroffs >= img->charData[chrbank].size) + { + return dmError(DMERR_INVALID_DATA, + "Character map index #%d out of bounds for char ROM data.\n", + chr); + } + + const int vshift = 7 - (rasterX & 7); + if ((img->charData[chrbank].data[chroffs] >> vshift) & 1) + *col = img->color[cbank].data[scroffs]; + else + *col = bgcolor; + + return DMERR_OK; +} + + +static inline int dmC64GetGenericCharMCPixel(Uint8 *col, + const DMC64Image *img, const int scroffs, const int rasterX, + const int chrbank, const size_t chroffs, const int chr, + const int cbank, const int bgcolor, + const int bgd022, const int bgd023) +{ + if (chroffs >= img->charData[chrbank].size) + { + return dmError(DMERR_INVALID_DATA, + "Character map index #%d out of bounds for char ROM data.\n", + chr); + } + + const int ccol = img->color[cbank].data[scroffs]; + if (ccol & 8) + { + const int vshift = 6 - (rasterX & 6); + switch ((img->charData[chrbank].data[chroffs] >> vshift) & 3) + { + case 0: *col = bgcolor; break; + case 1: *col = bgd022; break; + case 2: *col = bgd023; break; + case 3: *col = ccol & 15; + } + } + else + { + const int vshift = 7 - (rasterX & 7); + if ((img->charData[chrbank].data[chroffs] >> vshift) & 1) + *col = ccol & 7; + else + *col = bgcolor; + } + + return DMERR_OK; +} + + +static inline int dmC64GetGenericCharECMPixel(Uint8 *col, + const DMC64Image *img, const int scroffs, const int rasterX, + const int chrbank, const size_t chroffs, const int chr, + const int cbank, const int bgcolor, + const int bgd022, const int bgd023, const int bgd024) +{ + if (chroffs >= img->charData[0].size) + { + return dmError(DMERR_INVALID_DATA, + "Character map index #%d out of bounds for char ROM data.\n", + chr); + } + + const int vshift = 7 - (rasterX & 7); + if ((img->charData[chrbank].data[chroffs] >> vshift) & 1) + *col = img->color[cbank].data[scroffs] & 15; + else + switch ((chr >> 6) & 3) + { + case 0: *col = bgcolor; break; + case 1: *col = bgd022; break; + case 2: *col = bgd023; break; + case 3: *col = bgd024; break; + } + + return DMERR_OK; +} + + static inline const DMC64EncDecOp * fmtGetEncDecOp(const DMC64ImageFormat *fmt, const int index) { return &fmt->format->encdecOps[index];