Mercurial > hg > dmlib
comparison 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 |
comparison
equal
deleted
inserted
replaced
1587:e6a228b50bd6 | 1588:ca087c0cc9c4 |
---|---|
96 DC_D023, | 96 DC_D023, |
97 DC_D024, | 97 DC_D024, |
98 }; | 98 }; |
99 | 99 |
100 | 100 |
101 typedef struct | |
102 { | |
103 Uint8 *data; | |
104 size_t size; | |
105 } DMC64MemBlock; | |
106 | |
107 | |
101 typedef struct _DMC64Image | 108 typedef struct _DMC64Image |
102 { | 109 { |
103 int type, // Image type (D64_FMT_*) | 110 int type, // Image type (D64_FMT_*) |
104 laceType, // Interlace type (D64_ILACE_*) | 111 laceType, // Interlace type (D64_ILACE_*) |
105 nbanks; | 112 nbanks; |
106 | 113 |
107 int width, height; // Width and height in pixels | 114 int width, height; // Width and height in pixels |
108 int chWidth, chHeight; // Width and height in charblocks | 115 int chWidth, chHeight; // Width and height in charblocks |
109 | 116 |
110 size_t | 117 // Bitmaps, color RAM, screen, etc. blocks * nbanks |
111 screenSize, | 118 // Not all of them may be allocated |
112 bitmapSize, | 119 DMC64MemBlock |
113 charmemSize; | 120 *color, |
114 | 121 *bitmap, |
115 Uint8 | 122 *screen, |
116 **color, | 123 *charData; |
117 **bitmap, | 124 |
118 **screen, | 125 // Other standard colours |
119 **charmem, | 126 Uint8 d020, bgcolor, d022, d023, d024; |
120 *extraData[C64_MAX_EXTRA_DATA], | 127 |
121 d020, bgcolor, d022, d023, d024; | 128 // Extra data areas used by some formats, |
122 | 129 // for example raster colours might be stored |
123 size_t extraDataSizes[C64_MAX_EXTRA_DATA]; | 130 DMC64MemBlock extraData[C64_MAX_EXTRA_DATA]; |
124 | 131 |
125 DMC64Sprite sprites[C64_MAX_SPRITES]; | 132 DMC64Sprite sprites[C64_MAX_SPRITES]; |
126 } DMC64Image; | 133 } DMC64Image; |
127 | 134 |
128 | 135 |
215 | 222 |
216 // | 223 // |
217 // Miscellaneous functions | 224 // Miscellaneous functions |
218 // | 225 // |
219 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt); | 226 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt); |
227 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); | |
228 | |
220 void dmSetDefaultC64Palette(DMImage *img); | 229 void dmSetDefaultC64Palette(DMImage *img); |
221 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); | 230 int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt); |
222 int dmC64ConvertCSDataToImage(DMImage *img, int xoffs, int yoffs, const Uint8 *inBuf, int width, int height, BOOL multicolor, int *colors); | 231 int dmC64ConvertCSDataToImage(DMImage *img, int xoffs, int yoffs, const Uint8 *inBuf, int width, int height, BOOL multicolor, int *colors); |
223 int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt); | |
224 BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr); | 232 BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr); |
233 | |
225 int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img); | 234 int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img); |
226 BOOL dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt, size_t *size); | 235 BOOL dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt, size_t *size); |
236 | |
237 int dmC64MemBlockAlloc(DMC64MemBlock *blk, const size_t size); | |
238 int dmC64MemBlockCopy(DMC64MemBlock *dst, const DMC64MemBlock *src); | |
239 void dmC64MemBlockFree(DMC64MemBlock *blk); | |
227 | 240 |
228 | 241 |
229 // C64 bitmap image allocation/freeing | 242 // C64 bitmap image allocation/freeing |
230 DMC64Image *dmC64ImageAlloc(const DMC64ImageFormat *fmt); | 243 DMC64Image *dmC64ImageAlloc(const DMC64ImageFormat *fmt); |
231 void dmC64ImageFree(DMC64Image *img); | 244 void dmC64ImageFree(DMC64Image *img); |
261 static inline Uint8 dmC64GetGenericSCPixel( | 274 static inline Uint8 dmC64GetGenericSCPixel( |
262 const DMC64Image *img, const int bmoffs, const int scroffs, | 275 const DMC64Image *img, const int bmoffs, const int scroffs, |
263 const int vshift, const int vbank, const int vbitmap, const int cbank) | 276 const int vshift, const int vbank, const int vbitmap, const int cbank) |
264 { | 277 { |
265 (void) cbank; | 278 (void) cbank; |
266 if ((img->bitmap[vbitmap][bmoffs] >> vshift) & 1) | 279 if ((img->bitmap[vbitmap].data[bmoffs] >> vshift) & 1) |
267 return img->screen[vbank][scroffs] >> 4; | 280 return img->screen[vbank].data[scroffs] >> 4; |
268 else | 281 else |
269 return img->screen[vbank][scroffs] & 15; | 282 return img->screen[vbank].data[scroffs] & 15; |
270 } | 283 } |
271 | 284 |
272 | 285 |
273 static inline Uint8 dmC64GetGenericMCPixel( | 286 static inline Uint8 dmC64GetGenericMCPixel( |
274 const DMC64Image *img, const int bmoffs, const int scroffs, | 287 const DMC64Image *img, const int bmoffs, const int scroffs, |
275 const int vshift, const int vbank, const int vbitmap, const int cbank, | 288 const int vshift, const int vbank, const int vbitmap, const int cbank, |
276 const int bgcolor) | 289 const int bgcolor) |
277 { | 290 { |
278 switch ((img->bitmap[vbitmap][bmoffs] >> vshift) & 3) | 291 switch ((img->bitmap[vbitmap].data[bmoffs] >> vshift) & 3) |
279 { | 292 { |
280 case 0: return bgcolor; | 293 case 0: return bgcolor; |
281 case 1: return img->screen[vbank][scroffs] >> 4; | 294 case 1: return img->screen[vbank].data[scroffs] >> 4; |
282 case 2: return img->screen[vbank][scroffs] & 15; | 295 case 2: return img->screen[vbank].data[scroffs] & 15; |
283 default: return img->color[cbank][scroffs] & 15; | 296 default: return img->color[cbank].data[scroffs] & 15; |
284 } | 297 } |
285 } | 298 } |
286 | 299 |
287 | 300 |
288 static inline Uint8 fmtGetGenericSCPixel( | 301 static inline Uint8 fmtGetGenericSCPixel( |