Mercurial > hg > dmlib
diff tools/lib64gfx.h @ 1588:ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 14 May 2018 04:27:53 +0300 |
parents | 3c9e5962eca6 |
children | 3cc7b2aadda3 |
line wrap: on
line diff
--- a/tools/lib64gfx.h Mon May 14 04:11:45 2018 +0300 +++ b/tools/lib64gfx.h Mon May 14 04:27:53 2018 +0300 @@ -98,6 +98,13 @@ }; +typedef struct +{ + Uint8 *data; + size_t size; +} DMC64MemBlock; + + typedef struct _DMC64Image { int type, // Image type (D64_FMT_*) @@ -107,20 +114,20 @@ int width, height; // Width and height in pixels int chWidth, chHeight; // Width and height in charblocks - size_t - screenSize, - bitmapSize, - charmemSize; + // Bitmaps, color RAM, screen, etc. blocks * nbanks + // Not all of them may be allocated + DMC64MemBlock + *color, + *bitmap, + *screen, + *charData; - Uint8 - **color, - **bitmap, - **screen, - **charmem, - *extraData[C64_MAX_EXTRA_DATA], - d020, bgcolor, d022, d023, d024; + // Other standard colours + Uint8 d020, bgcolor, d022, d023, d024; - size_t extraDataSizes[C64_MAX_EXTRA_DATA]; + // Extra data areas used by some formats, + // for example raster colours might be stored + DMC64MemBlock extraData[C64_MAX_EXTRA_DATA]; DMC64Sprite sprites[C64_MAX_SPRITES]; } DMC64Image; @@ -217,14 +224,20 @@ // Miscellaneous functions // void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt); +char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); + void dmSetDefaultC64Palette(DMImage *img); -char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); +int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt); int dmC64ConvertCSDataToImage(DMImage *img, int xoffs, int yoffs, const Uint8 *inBuf, int width, int height, BOOL multicolor, int *colors); -int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt); BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr); + int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img); BOOL dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt, size_t *size); +int dmC64MemBlockAlloc(DMC64MemBlock *blk, const size_t size); +int dmC64MemBlockCopy(DMC64MemBlock *dst, const DMC64MemBlock *src); +void dmC64MemBlockFree(DMC64MemBlock *blk); + // C64 bitmap image allocation/freeing DMC64Image *dmC64ImageAlloc(const DMC64ImageFormat *fmt); @@ -263,10 +276,10 @@ const int vshift, const int vbank, const int vbitmap, const int cbank) { (void) cbank; - if ((img->bitmap[vbitmap][bmoffs] >> vshift) & 1) - return img->screen[vbank][scroffs] >> 4; + if ((img->bitmap[vbitmap].data[bmoffs] >> vshift) & 1) + return img->screen[vbank].data[scroffs] >> 4; else - return img->screen[vbank][scroffs] & 15; + return img->screen[vbank].data[scroffs] & 15; } @@ -275,12 +288,12 @@ const int vshift, const int vbank, const int vbitmap, const int cbank, const int bgcolor) { - switch ((img->bitmap[vbitmap][bmoffs] >> vshift) & 3) + switch ((img->bitmap[vbitmap].data[bmoffs] >> vshift) & 3) { case 0: return bgcolor; - case 1: return img->screen[vbank][scroffs] >> 4; - case 2: return img->screen[vbank][scroffs] & 15; - default: return img->color[cbank][scroffs] & 15; + case 1: return img->screen[vbank].data[scroffs] >> 4; + case 2: return img->screen[vbank].data[scroffs] & 15; + default: return img->color[cbank].data[scroffs] & 15; } }