Develop and Download Open Source Software

Browse CVS Repository

Contents of /mame32jp/mame32jp/src/drawgfx.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Tue May 7 00:17:30 2002 UTC (21 years, 11 months ago) by zero
Branch: MAIN
CVS Tags: ver_0_60_1, ver0_60_2, ver0_60_3, ver0_60_4, ver0_60_5, HEAD
Changes since 1.7: +212 -2 lines
File MIME type: text/x-csrc
*** empty log message ***

1 #ifndef DECLARE
2
3 #include "driver.h"
4
5
6 #ifdef LSB_FIRST
7 #define SHIFT0 0
8 #define SHIFT1 8
9 #define SHIFT2 16
10 #define SHIFT3 24
11 #else
12 #define SHIFT3 0
13 #define SHIFT2 8
14 #define SHIFT1 16
15 #define SHIFT0 24
16 #endif
17
18
19 typedef void (*plot_pixel_proc)(struct mame_bitmap *bitmap,int x,int y,pen_t pen);
20 typedef pen_t (*read_pixel_proc)(struct mame_bitmap *bitmap,int x,int y);
21 typedef void (*plot_box_proc)(struct mame_bitmap *bitmap,int x,int y,int width,int height,pen_t pen);
22 #ifdef MAME32JP
23 typedef void (*plot_box_ts_proc)(struct mame_bitmap *bitmap,int x,int y,int width,int height);
24 #endif
25
26 UINT8 gfx_drawmode_table[256];
27 mark_dirty_proc mark_dirty;
28
29 static UINT8 is_raw[TRANSPARENCY_MODES];
30
31
32 #ifdef ALIGN_INTS /* GSL 980108 read/write nonaligned dword routine for ARM processor etc */
33
34 INLINE UINT32 read_dword(void *address)
35 {
36 if ((long)address & 3)
37 {
38 return (*((UINT8 *)address ) << SHIFT0) +
39 (*((UINT8 *)address+1) << SHIFT1) +
40 (*((UINT8 *)address+2) << SHIFT2) +
41 (*((UINT8 *)address+3) << SHIFT3);
42 }
43 else
44 return *(UINT32 *)address;
45 }
46
47
48 INLINE void write_dword(void *address, UINT32 data)
49 {
50 if ((long)address & 3)
51 {
52 *((UINT8 *)address) = (data>>SHIFT0);
53 *((UINT8 *)address+1) = (data>>SHIFT1);
54 *((UINT8 *)address+2) = (data>>SHIFT2);
55 *((UINT8 *)address+3) = (data>>SHIFT3);
56 return;
57 }
58 else
59 *(UINT32 *)address = data;
60 }
61 #else
62 #define read_dword(address) *(int *)address
63 #define write_dword(address,data) *(int *)address=data
64 #endif
65
66
67
68 INLINE int readbit(const UINT8 *src,int bitnum)
69 {
70 return src[bitnum / 8] & (0x80 >> (bitnum % 8));
71 }
72
73 struct _alpha_cache alpha_cache;
74 int alpha_active;
75
76 void alpha_init(void)
77 {
78 int lev, byte;
79 for(lev=0; lev<257; lev++)
80 for(byte=0; byte<256; byte++)
81 alpha_cache.alpha[lev][byte] = (byte*lev) >> 8;
82 alpha_set_level(255);
83 }
84
85
86 static void calc_penusage(struct GfxElement *gfx,int num)
87 {
88 int x,y;
89 UINT8 *dp;
90
91 if (!gfx->pen_usage) return;
92
93 /* fill the pen_usage array with info on the used pens */
94 gfx->pen_usage[num] = 0;
95
96 dp = gfx->gfxdata + num * gfx->char_modulo;
97
98 if (gfx->flags & GFX_PACKED)
99 {
100 for (y = 0;y < gfx->height;y++)
101 {
102 for (x = 0;x < gfx->width/2;x++)
103 {
104 gfx->pen_usage[num] |= 1 << (dp[x] & 0x0f);
105 gfx->pen_usage[num] |= 1 << (dp[x] >> 4);
106 }
107 dp += gfx->line_modulo;
108 }
109 }
110 else
111 {
112 for (y = 0;y < gfx->height;y++)
113 {
114 for (x = 0;x < gfx->width;x++)
115 {
116 gfx->pen_usage[num] |= 1 << dp[x];
117 }
118 dp += gfx->line_modulo;
119 }
120 }
121 }
122
123 void decodechar(struct GfxElement *gfx,int num,const UINT8 *src,const struct GfxLayout *gl)
124 {
125 int plane,x,y;
126 UINT8 *dp;
127 int baseoffs;
128 const UINT32 *xoffset,*yoffset;
129
130
131 xoffset = gl->xoffset;
132 yoffset = gl->yoffset;
133 if (Machine->orientation & ORIENTATION_SWAP_XY)
134 {
135 const UINT32 *t = xoffset; xoffset = yoffset; yoffset = t;
136 }
137 if (gfx->flags & GFX_SWAPXY)
138 {
139 const UINT32 *t = xoffset; xoffset = yoffset; yoffset = t;
140 }
141
142 dp = gfx->gfxdata + num * gfx->char_modulo;
143 memset(dp,0,gfx->char_modulo);
144
145 baseoffs = num * gl->charincrement;
146
147 if (gfx->flags & GFX_PACKED)
148 {
149 for (plane = 0;plane < gl->planes;plane++)
150 {
151 int shiftedbit = 1 << (gl->planes-1-plane);
152 int offs = baseoffs + gl->planeoffset[plane];
153
154 dp = gfx->gfxdata + num * gfx->char_modulo + (gfx->height-1) * gfx->line_modulo;
155
156 y = gfx->height;
157 while (--y >= 0)
158 {
159 int offs2 = offs + yoffset[y];
160
161 x = gfx->width/2;
162 while (--x >= 0)
163 {
164 if (readbit(src,offs2 + xoffset[2*x+1]))
165 dp[x] |= shiftedbit << 4;
166 if (readbit(src,offs2 + xoffset[2*x]))
167 dp[x] |= shiftedbit;
168 }
169 dp -= gfx->line_modulo;
170 }
171 }
172 }
173 else
174 {
175 for (plane = 0;plane < gl->planes;plane++)
176 {
177 int shiftedbit = 1 << (gl->planes-1-plane);
178 int offs = baseoffs + gl->planeoffset[plane];
179
180 dp = gfx->gfxdata + num * gfx->char_modulo + (gfx->height-1) * gfx->line_modulo;
181
182 #ifdef PREROTATE_GFX
183 y = gfx->height;
184 while (--y >= 0)
185 {
186 int yoffs;
187
188 yoffs = y;
189 if (Machine->orientation & ORIENTATION_FLIP_Y)
190 yoffs = gfx->height-1 - yoffs;
191
192 x = gfx->width;
193 while (--x >= 0)
194 {
195 int xoffs;
196
197 xoffs = x;
198 if (Machine->orientation & ORIENTATION_FLIP_X)
199 xoffs = gfx->width-1 - xoffs;
200
201 if (readbit(src,offs + xoffset[xoffs] + yoffset[yoffs]))
202 dp[x] |= shiftedbit;
203 }
204 dp -= gfx->line_modulo;
205 }
206 #else
207 y = gfx->height;
208 while (--y >= 0)
209 {
210 int offs2 = offs + yoffset[y];
211
212 x = gfx->width;
213 while (--x >= 0)
214 {
215 if (readbit(src,offs2 + xoffset[x]))
216 dp[x] |= shiftedbit;
217 }
218 dp -= gfx->line_modulo;
219 }
220 #endif
221 }
222 }
223
224 calc_penusage(gfx,num);
225 }
226
227
228 struct GfxElement *decodegfx(const UINT8 *src,const struct GfxLayout *gl)
229 {
230 int c;
231 struct GfxElement *gfx;
232
233
234 if ((gfx = malloc(sizeof(struct GfxElement))) == 0)
235 return 0;
236 memset(gfx,0,sizeof(struct GfxElement));
237
238 if (Machine->orientation & ORIENTATION_SWAP_XY)
239 {
240 #ifndef NOPRESWAP
241 gfx->width = gl->height;
242 gfx->height = gl->width;
243 #else
244 gfx->width = gl->width;
245 gfx->height = gl->height;
246 gfx->flags |= GFX_SWAPXY;
247 #endif
248 }
249 else
250 {
251 gfx->width = gl->width;
252 gfx->height = gl->height;
253 }
254
255 gfx->total_elements = gl->total;
256 gfx->color_granularity = 1 << gl->planes;
257
258 gfx->pen_usage = 0; /* need to make sure this is NULL if the next test fails) */
259 if (gfx->color_granularity <= 32) /* can't handle more than 32 pens */
260 gfx->pen_usage = malloc(gfx->total_elements * sizeof(int));
261 /* no need to check for failure, the code can work without pen_usage */
262
263 if (gl->planeoffset[0] == GFX_RAW)
264 {
265 if (gl->planes <= 4) gfx->flags |= GFX_PACKED;
266 if (Machine->orientation & ORIENTATION_SWAP_XY) gfx->flags |= GFX_SWAPXY;
267
268 gfx->line_modulo = gl->yoffset[0] / 8;
269 gfx->char_modulo = gl->charincrement / 8;
270
271 gfx->gfxdata = (UINT8 *)src + gl->xoffset[0] / 8;
272 gfx->flags |= GFX_DONT_FREE_GFXDATA;
273
274 for (c = 0;c < gfx->total_elements;c++)
275 calc_penusage(gfx,c);
276 }
277 else
278 {
279 if (0 && gl->planes <= 4 && !(gfx->width & 1))
280 // if (gl->planes <= 4 && !(gfx->width & 1))
281 {
282 gfx->flags |= GFX_PACKED;
283 gfx->line_modulo = gfx->width/2;
284 }
285 else
286 gfx->line_modulo = gfx->width;
287 gfx->char_modulo = gfx->line_modulo * gfx->height;
288
289 if ((gfx->gfxdata = malloc(gfx->total_elements * gfx->char_modulo * sizeof(UINT8))) == 0)
290 {
291 free(gfx->pen_usage);
292 free(gfx);
293 return 0;
294 }
295
296 for (c = 0;c < gfx->total_elements;c++)
297 decodechar(gfx,c,src,gl);
298 }
299
300 return gfx;
301 }
302
303
304 void freegfx(struct GfxElement *gfx)
305 {
306 if (gfx)
307 {
308 free(gfx->pen_usage);
309 if (!(gfx->flags & GFX_DONT_FREE_GFXDATA))
310 free(gfx->gfxdata);
311 free(gfx);
312 }
313 }
314
315
316
317
318 INLINE void blockmove_NtoN_transpen_noremap8(
319 const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
320 UINT8 *dstdata,int dstmodulo,
321 int transpen)
322 {
323 UINT8 *end;
324 int trans4;
325 UINT32 *sd4;
326
327 srcmodulo -= srcwidth;
328 dstmodulo -= srcwidth;
329
330 trans4 = transpen * 0x01010101;
331
332 while (srcheight)
333 {
334 end = dstdata + srcwidth;
335 while (((long)srcdata & 3) && dstdata < end) /* longword align */
336 {
337 int col;
338
339 col = *(srcdata++);
340 if (col != transpen) *dstdata = col;
341 dstdata++;
342 }
343 sd4 = (UINT32 *)srcdata;
344 while (dstdata <= end - 4)
345 {
346 UINT32 col4;
347
348 if ((col4 = *(sd4++)) != trans4)
349 {
350 UINT32 xod4;
351
352 xod4 = col4 ^ trans4;
353 if( (xod4&0x000000ff) && (xod4&0x0000ff00) &&
354 (xod4&0x00ff0000) && (xod4&0xff000000) )
355 {
356 write_dword((UINT32 *)dstdata,col4);
357 }
358 else
359 {
360 if (xod4 & (0xff<<SHIFT0)) dstdata[0] = col4>>SHIFT0;
361 if (xod4 & (0xff<<SHIFT1)) dstdata[1] = col4>>SHIFT1;
362 if (xod4 & (0xff<<SHIFT2)) dstdata[2] = col4>>SHIFT2;
363 if (xod4 & (0xff<<SHIFT3)) dstdata[3] = col4>>SHIFT3;
364 }
365 }
366 dstdata += 4;
367 }
368 srcdata = (UINT8 *)sd4;
369 while (dstdata < end)
370 {
371 int col;
372
373 col = *(srcdata++);
374 if (col != transpen) *dstdata = col;
375 dstdata++;
376 }
377
378 srcdata += srcmodulo;
379 dstdata += dstmodulo;
380 srcheight--;
381 }
382 }
383
384 INLINE void blockmove_NtoN_transpen_noremap_flipx8(
385 const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
386 UINT8 *dstdata,int dstmodulo,
387 int transpen)
388 {
389 UINT8 *end;
390 int trans4;
391 UINT32 *sd4;
392
393 srcmodulo += srcwidth;
394 dstmodulo -= srcwidth;
395 //srcdata += srcwidth-1;
396 srcdata -= 3;
397
398 trans4 = transpen * 0x01010101;
399
400 while (srcheight)
401 {
402 end = dstdata + srcwidth;
403 while (((long)srcdata & 3) && dstdata < end) /* longword align */
404 {
405 int col;
406
407 col = srcdata[3];
408 srcdata--;
409 if (col != transpen) *dstdata = col;
410 dstdata++;
411 }
412 sd4 = (UINT32 *)srcdata;
413 while (dstdata <= end - 4)
414 {
415 UINT32 col4;
416
417 if ((col4 = *(sd4--)) != trans4)
418 {
419 UINT32 xod4;
420
421 xod4 = col4 ^ trans4;
422 if (xod4 & (0xff<<SHIFT0)) dstdata[3] = (col4>>SHIFT0);
423 if (xod4 & (0xff<<SHIFT1)) dstdata[2] = (col4>>SHIFT1);
424 if (xod4 & (0xff<<SHIFT2)) dstdata[1] = (col4>>SHIFT2);
425 if (xod4 & (0xff<<SHIFT3)) dstdata[0] = (col4>>SHIFT3);
426 }
427 dstdata += 4;
428 }
429 srcdata = (UINT8 *)sd4;
430 while (dstdata < end)
431 {
432 int col;
433
434 col = srcdata[3];
435 srcdata--;
436 if (col != transpen) *dstdata = col;
437 dstdata++;
438 }
439
440 srcdata += srcmodulo;
441 dstdata += dstmodulo;
442 srcheight--;
443 }
444 }
445
446
447 INLINE void blockmove_NtoN_transpen_noremap16(
448 const UINT16 *srcdata,int srcwidth,int srcheight,int srcmodulo,
449 UINT16 *dstdata,int dstmodulo,
450 int transpen)
451 {
452 UINT16 *end;
453
454 srcmodulo -= srcwidth;
455 dstmodulo -= srcwidth;
456
457 while (srcheight)
458 {
459 end = dstdata + srcwidth;
460 while (dstdata < end)
461 {
462 int col;
463
464 col = *(srcdata++);
465 if (col != transpen) *dstdata = col;
466 dstdata++;
467 }
468
469 srcdata += srcmodulo;
470 dstdata += dstmodulo;
471 srcheight--;
472 }
473 }
474
475 INLINE void blockmove_NtoN_transpen_noremap_flipx16(
476 const UINT16 *srcdata,int srcwidth,int srcheight,int srcmodulo,
477 UINT16 *dstdata,int dstmodulo,
478 int transpen)
479 {
480 UINT16 *end;
481
482 srcmodulo += srcwidth;
483 dstmodulo -= srcwidth;
484 //srcdata += srcwidth-1;
485
486 while (srcheight)
487 {
488 end = dstdata + srcwidth;
489 while (dstdata < end)
490 {
491 int col;
492
493 col = *(srcdata--);
494 if (col != transpen) *dstdata = col;
495 dstdata++;
496 }
497
498 srcdata += srcmodulo;
499 dstdata += dstmodulo;
500 srcheight--;
501 }
502 }
503
504 INLINE void blockmove_NtoN_transpen_noremap32(
505 const UINT32 *srcdata,int srcwidth,int srcheight,int srcmodulo,
506 UINT32 *dstdata,int dstmodulo,
507 int transpen)
508 {
509 UINT32 *end;
510
511 srcmodulo -= srcwidth;
512 dstmodulo -= srcwidth;
513
514 while (srcheight)
515 {
516 end = dstdata + srcwidth;
517 while (dstdata < end)
518 {
519 int col;
520
521 col = *(srcdata++);
522 if (col != transpen) *dstdata = col;
523 dstdata++;
524 }
525
526 srcdata += srcmodulo;
527 dstdata += dstmodulo;
528 srcheight--;
529 }
530 }
531
532 INLINE void blockmove_NtoN_transpen_noremap_flipx32(
533 const UINT32 *srcdata,int srcwidth,int srcheight,int srcmodulo,
534 UINT32 *dstdata,int dstmodulo,
535 int transpen)
536 {
537 UINT32 *end;
538
539 srcmodulo += srcwidth;
540 dstmodulo -= srcwidth;
541 //srcdata += srcwidth-1;
542
543 while (srcheight)
544 {
545 end = dstdata + srcwidth;
546 while (dstdata < end)
547 {
548 int col;
549
550 col = *(srcdata--);
551 if (col != transpen) *dstdata = col;
552 dstdata++;
553 }
554
555 srcdata += srcmodulo;
556 dstdata += dstmodulo;
557 srcheight--;
558 }
559 }
560
561
562 static int afterdrawmask = 31;
563 int pdrawgfx_shadow_lowpri = 0;
564
565
566 /* 8-bit version */
567 #define DATA_TYPE UINT8
568 #define DEPTH 8
569
570 #define DECLARE(function,args,body)
571 #define DECLAREG(function,args,body)
572
573 #define VMODULO 1
574 #define HMODULO dstmodulo
575 #define COMMON_ARGS \
576 const UINT8 *srcdata,int srcheight,int srcwidth,int srcmodulo, \
577 int topskip,int leftskip,int flipy,int flipx, \
578 DATA_TYPE *dstdata,int dstheight,int dstwidth,int dstmodulo
579
580
581 #define COLOR_ARG unsigned int colorbase,UINT8 *pridata,UINT32 pmask
582 #define INCREMENT_DST(n) {dstdata+=(n);pridata += (n);}
583 #define LOOKUP(n) (colorbase + (n))
584 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
585 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy_raw_pri8 args body
586 #include "drawgfx.c"
587 #undef DECLARE_SWAP_RAW_PRI
588 #undef COLOR_ARG
589 #undef LOOKUP
590 #undef SETPIXELCOLOR
591
592 #define COLOR_ARG const pen_t *paldata,UINT8 *pridata,UINT32 pmask
593 #define LOOKUP(n) (paldata[n])
594 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
595 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy_pri8 args body
596 #include "drawgfx.c"
597 #undef DECLARE_SWAP_RAW_PRI
598 #undef COLOR_ARG
599 #undef LOOKUP
600 #undef INCREMENT_DST
601 #undef SETPIXELCOLOR
602
603 #define COLOR_ARG unsigned int colorbase
604 #define INCREMENT_DST(n) {dstdata+=(n);}
605 #define LOOKUP(n) (colorbase + (n))
606 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
607 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy_raw8 args body
608 #include "drawgfx.c"
609 #undef DECLARE_SWAP_RAW_PRI
610 #undef COLOR_ARG
611 #undef LOOKUP
612 #undef SETPIXELCOLOR
613
614 #define COLOR_ARG const pen_t *paldata
615 #define LOOKUP(n) (paldata[n])
616 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
617 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy8 args body
618 #include "drawgfx.c"
619 #undef DECLARE_SWAP_RAW_PRI
620 #undef COLOR_ARG
621 #undef LOOKUP
622 #undef INCREMENT_DST
623 #undef SETPIXELCOLOR
624
625 #undef HMODULO
626 #undef VMODULO
627 #undef COMMON_ARGS
628
629 #define HMODULO 1
630 #define VMODULO dstmodulo
631 #define COMMON_ARGS \
632 const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo, \
633 int leftskip,int topskip,int flipx,int flipy, \
634 DATA_TYPE *dstdata,int dstwidth,int dstheight,int dstmodulo
635
636 #define COLOR_ARG unsigned int colorbase,UINT8 *pridata,UINT32 pmask
637 #define INCREMENT_DST(n) {dstdata+=(n);pridata += (n);}
638 #define LOOKUP(n) (colorbase + (n))
639 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
640 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_raw_pri8 args body
641 #include "drawgfx.c"
642 #undef DECLARE_SWAP_RAW_PRI
643 #undef COLOR_ARG
644 #undef LOOKUP
645 #undef SETPIXELCOLOR
646
647 #define COLOR_ARG const pen_t *paldata,UINT8 *pridata,UINT32 pmask
648 #define LOOKUP(n) (paldata[n])
649 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
650 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_pri8 args body
651 #include "drawgfx.c"
652 #undef DECLARE_SWAP_RAW_PRI
653 #undef COLOR_ARG
654 #undef LOOKUP
655 #undef INCREMENT_DST
656 #undef SETPIXELCOLOR
657
658 #define COLOR_ARG unsigned int colorbase
659 #define INCREMENT_DST(n) {dstdata+=(n);}
660 #define LOOKUP(n) (colorbase + (n))
661 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
662 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_raw8 args body
663 #include "drawgfx.c"
664 #undef DECLARE_SWAP_RAW_PRI
665 #undef COLOR_ARG
666 #undef LOOKUP
667 #undef SETPIXELCOLOR
668
669 #define COLOR_ARG const pen_t *paldata
670 #define LOOKUP(n) (paldata[n])
671 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
672 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##8 args body
673 #include "drawgfx.c"
674 #undef DECLARE_SWAP_RAW_PRI
675 #undef COLOR_ARG
676 #undef LOOKUP
677 #undef INCREMENT_DST
678 #undef SETPIXELCOLOR
679
680 #undef HMODULO
681 #undef VMODULO
682 #undef COMMON_ARGS
683 #undef DECLARE
684 #undef DECLAREG
685
686 #define DECLARE(function,args,body) void function##8 args body
687 #define DECLAREG(function,args,body) void function##8 args body
688 #define DECLARE_SWAP_RAW_PRI(function,args,body)
689 #define BLOCKMOVE(function,flipx,args) \
690 if (flipx) blockmove_##function##_flipx##8 args ; \
691 else blockmove_##function##8 args
692 #define BLOCKMOVELU(function,args) \
693 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##8 args ; \
694 else blockmove_##function##8 args
695 #define BLOCKMOVERAW(function,args) \
696 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##_raw##8 args ; \
697 else blockmove_##function##_raw##8 args
698 #define BLOCKMOVEPRI(function,args) \
699 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##_pri##8 args ; \
700 else blockmove_##function##_pri##8 args
701 #define BLOCKMOVERAWPRI(function,args) \
702 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##_raw_pri##8 args ; \
703 else blockmove_##function##_raw_pri##8 args
704 #include "drawgfx.c"
705 #undef DECLARE
706 #undef DECLARE_SWAP_RAW_PRI
707 #undef DECLAREG
708 #undef BLOCKMOVE
709 #undef BLOCKMOVELU
710 #undef BLOCKMOVERAW
711 #undef BLOCKMOVEPRI
712 #undef BLOCKMOVERAWPRI
713
714 #undef DEPTH
715 #undef DATA_TYPE
716
717 /* 16-bit version */
718 #define DATA_TYPE UINT16
719 #define DEPTH 16
720 #define alpha_blend alpha_blend16
721
722 #define DECLARE(function,args,body)
723 #define DECLAREG(function,args,body)
724
725 #define VMODULO 1
726 #define HMODULO dstmodulo
727 #define COMMON_ARGS \
728 const UINT8 *srcdata,int srcheight,int srcwidth,int srcmodulo, \
729 int topskip,int leftskip,int flipy,int flipx, \
730 DATA_TYPE *dstdata,int dstheight,int dstwidth,int dstmodulo
731
732 #define COLOR_ARG unsigned int colorbase,UINT8 *pridata,UINT32 pmask
733 #define INCREMENT_DST(n) {dstdata+=(n);pridata += (n);}
734 #define LOOKUP(n) (colorbase + (n))
735 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
736 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy_raw_pri16 args body
737 #include "drawgfx.c"
738 #undef DECLARE_SWAP_RAW_PRI
739 #undef COLOR_ARG
740 #undef LOOKUP
741 #undef SETPIXELCOLOR
742
743 #define COLOR_ARG const pen_t *paldata,UINT8 *pridata,UINT32 pmask
744 #define LOOKUP(n) (paldata[n])
745 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
746 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy_pri16 args body
747 #include "drawgfx.c"
748 #undef DECLARE_SWAP_RAW_PRI
749 #undef COLOR_ARG
750 #undef LOOKUP
751 #undef INCREMENT_DST
752 #undef SETPIXELCOLOR
753
754 #define COLOR_ARG unsigned int colorbase
755 #define INCREMENT_DST(n) {dstdata+=(n);}
756 #define LOOKUP(n) (colorbase + (n))
757 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
758 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy_raw16 args body
759 #include "drawgfx.c"
760 #undef DECLARE_SWAP_RAW_PRI
761 #undef COLOR_ARG
762 #undef LOOKUP
763 #undef SETPIXELCOLOR
764
765 #define COLOR_ARG const pen_t *paldata
766 #define LOOKUP(n) (paldata[n])
767 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
768 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy16 args body
769 #include "drawgfx.c"
770 #undef DECLARE_SWAP_RAW_PRI
771 #undef COLOR_ARG
772 #undef LOOKUP
773 #undef INCREMENT_DST
774 #undef SETPIXELCOLOR
775
776 #undef HMODULO
777 #undef VMODULO
778 #undef COMMON_ARGS
779
780 #define HMODULO 1
781 #define VMODULO dstmodulo
782 #define COMMON_ARGS \
783 const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo, \
784 int leftskip,int topskip,int flipx,int flipy, \
785 DATA_TYPE *dstdata,int dstwidth,int dstheight,int dstmodulo
786
787 #define COLOR_ARG unsigned int colorbase,UINT8 *pridata,UINT32 pmask
788 #define INCREMENT_DST(n) {dstdata+=(n);pridata += (n);}
789 #define LOOKUP(n) (colorbase + (n))
790 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
791 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_raw_pri16 args body
792 #include "drawgfx.c"
793 #undef DECLARE_SWAP_RAW_PRI
794 #undef COLOR_ARG
795 #undef LOOKUP
796 #undef SETPIXELCOLOR
797
798 #define COLOR_ARG const pen_t *paldata,UINT8 *pridata,UINT32 pmask
799 #define LOOKUP(n) (paldata[n])
800 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
801 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_pri16 args body
802 #include "drawgfx.c"
803 #undef DECLARE_SWAP_RAW_PRI
804 #undef COLOR_ARG
805 #undef LOOKUP
806 #undef INCREMENT_DST
807 #undef SETPIXELCOLOR
808
809 #define COLOR_ARG unsigned int colorbase
810 #define INCREMENT_DST(n) {dstdata+=(n);}
811 #define LOOKUP(n) (colorbase + (n))
812 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
813 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_raw16 args body
814 #include "drawgfx.c"
815 #undef DECLARE_SWAP_RAW_PRI
816 #undef COLOR_ARG
817 #undef LOOKUP
818 #undef SETPIXELCOLOR
819
820 #define COLOR_ARG const pen_t *paldata
821 #define LOOKUP(n) (paldata[n])
822 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
823 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##16 args body
824 #include "drawgfx.c"
825 #undef DECLARE_SWAP_RAW_PRI
826 #undef COLOR_ARG
827 #undef LOOKUP
828 #undef INCREMENT_DST
829 #undef SETPIXELCOLOR
830
831 #undef HMODULO
832 #undef VMODULO
833 #undef COMMON_ARGS
834 #undef DECLARE
835 #undef DECLAREG
836
837 #define DECLARE(function,args,body) void function##16 args body
838 #define DECLAREG(function,args,body) void function##16 args body
839 #define DECLARE_SWAP_RAW_PRI(function,args,body)
840 #define BLOCKMOVE(function,flipx,args) \
841 if (flipx) blockmove_##function##_flipx##16 args ; \
842 else blockmove_##function##16 args
843 #define BLOCKMOVELU(function,args) \
844 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##16 args ; \
845 else blockmove_##function##16 args
846 #define BLOCKMOVERAW(function,args) \
847 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##_raw##16 args ; \
848 else blockmove_##function##_raw##16 args
849 #define BLOCKMOVEPRI(function,args) \
850 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##_pri##16 args ; \
851 else blockmove_##function##_pri##16 args
852 #define BLOCKMOVERAWPRI(function,args) \
853 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##_raw_pri##16 args ; \
854 else blockmove_##function##_raw_pri##16 args
855 #include "drawgfx.c"
856 #undef DECLARE
857 #undef DECLARE_SWAP_RAW_PRI
858 #undef DECLAREG
859 #undef BLOCKMOVE
860 #undef BLOCKMOVELU
861 #undef BLOCKMOVERAW
862 #undef BLOCKMOVEPRI
863 #undef BLOCKMOVERAWPRI
864
865 #undef DEPTH
866 #undef DATA_TYPE
867 #undef alpha_blend
868
869 /* 32-bit version */
870 #define DATA_TYPE UINT32
871 #define DEPTH 32
872 #define alpha_blend alpha_blend32
873
874 #define DECLARE(function,args,body)
875 #define DECLAREG(function,args,body)
876
877 #define VMODULO 1
878 #define HMODULO dstmodulo
879 #define COMMON_ARGS \
880 const UINT8 *srcdata,int srcheight,int srcwidth,int srcmodulo, \
881 int topskip,int leftskip,int flipy,int flipx, \
882 DATA_TYPE *dstdata,int dstheight,int dstwidth,int dstmodulo
883
884 #define COLOR_ARG unsigned int colorbase,UINT8 *pridata,UINT32 pmask
885 #define INCREMENT_DST(n) {dstdata+=(n);pridata += (n);}
886 #define LOOKUP(n) (colorbase + (n))
887 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
888 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy_raw_pri32 args body
889 #include "drawgfx.c"
890 #undef DECLARE_SWAP_RAW_PRI
891 #undef COLOR_ARG
892 #undef LOOKUP
893 #undef SETPIXELCOLOR
894
895 #define COLOR_ARG const pen_t *paldata,UINT8 *pridata,UINT32 pmask
896 #define LOOKUP(n) (paldata[n])
897 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
898 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy_pri32 args body
899 #include "drawgfx.c"
900 #undef DECLARE_SWAP_RAW_PRI
901 #undef COLOR_ARG
902 #undef LOOKUP
903 #undef INCREMENT_DST
904 #undef SETPIXELCOLOR
905
906 #define COLOR_ARG unsigned int colorbase
907 #define INCREMENT_DST(n) {dstdata+=(n);}
908 #define LOOKUP(n) (colorbase + (n))
909 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
910 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy_raw32 args body
911 #include "drawgfx.c"
912 #undef DECLARE_SWAP_RAW_PRI
913 #undef COLOR_ARG
914 #undef LOOKUP
915 #undef SETPIXELCOLOR
916
917 #define COLOR_ARG const pen_t *paldata
918 #define LOOKUP(n) (paldata[n])
919 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
920 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_swapxy32 args body
921 #include "drawgfx.c"
922 #undef DECLARE_SWAP_RAW_PRI
923 #undef COLOR_ARG
924 #undef LOOKUP
925 #undef INCREMENT_DST
926 #undef SETPIXELCOLOR
927
928 #undef HMODULO
929 #undef VMODULO
930 #undef COMMON_ARGS
931
932 #define HMODULO 1
933 #define VMODULO dstmodulo
934 #define COMMON_ARGS \
935 const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo, \
936 int leftskip,int topskip,int flipx,int flipy, \
937 DATA_TYPE *dstdata,int dstwidth,int dstheight,int dstmodulo
938
939 #define COLOR_ARG unsigned int colorbase,UINT8 *pridata,UINT32 pmask
940 #define INCREMENT_DST(n) {dstdata+=(n);pridata += (n);}
941 #define LOOKUP(n) (colorbase + (n))
942 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
943 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_raw_pri32 args body
944 #include "drawgfx.c"
945 #undef DECLARE_SWAP_RAW_PRI
946 #undef COLOR_ARG
947 #undef LOOKUP
948 #undef SETPIXELCOLOR
949
950 #define COLOR_ARG const pen_t *paldata,UINT8 *pridata,UINT32 pmask
951 #define LOOKUP(n) (paldata[n])
952 #define SETPIXELCOLOR(dest,n) { if (((1 << (pridata[dest] & 0x1f)) & pmask) == 0) { if (pridata[dest] & 0x80) { dstdata[dest] = palette_shadow_table[n];} else { dstdata[dest] = (n);} } pridata[dest] = (pridata[dest] & 0x7f) | afterdrawmask; }
953 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_pri32 args body
954 #include "drawgfx.c"
955 #undef DECLARE_SWAP_RAW_PRI
956 #undef COLOR_ARG
957 #undef LOOKUP
958 #undef INCREMENT_DST
959 #undef SETPIXELCOLOR
960
961 #define COLOR_ARG unsigned int colorbase
962 #define INCREMENT_DST(n) {dstdata+=(n);}
963 #define LOOKUP(n) (colorbase + (n))
964 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
965 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##_raw32 args body
966 #include "drawgfx.c"
967 #undef DECLARE_SWAP_RAW_PRI
968 #undef COLOR_ARG
969 #undef LOOKUP
970 #undef SETPIXELCOLOR
971
972 #define COLOR_ARG const pen_t *paldata
973 #define LOOKUP(n) (paldata[n])
974 #define SETPIXELCOLOR(dest,n) {dstdata[dest] = (n);}
975 #define DECLARE_SWAP_RAW_PRI(function,args,body) void function##32 args body
976 #include "drawgfx.c"
977 #undef DECLARE_SWAP_RAW_PRI
978 #undef COLOR_ARG
979 #undef LOOKUP
980 #undef INCREMENT_DST
981 #undef SETPIXELCOLOR
982
983 #undef HMODULO
984 #undef VMODULO
985 #undef COMMON_ARGS
986 #undef DECLARE
987 #undef DECLAREG
988
989 #define DECLARE(function,args,body) void function##32 args body
990 #define DECLAREG(function,args,body) void function##32 args body
991 #define DECLARE_SWAP_RAW_PRI(function,args,body)
992 #define BLOCKMOVE(function,flipx,args) \
993 if (flipx) blockmove_##function##_flipx##32 args ; \
994 else blockmove_##function##32 args
995 #define BLOCKMOVELU(function,args) \
996 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##32 args ; \
997 else blockmove_##function##32 args
998 #define BLOCKMOVERAW(function,args) \
999 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##_raw##32 args ; \
1000 else blockmove_##function##_raw##32 args
1001 #define BLOCKMOVEPRI(function,args) \
1002 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##_pri##32 args ; \
1003 else blockmove_##function##_pri##32 args
1004 #define BLOCKMOVERAWPRI(function,args) \
1005 if (gfx->flags & GFX_SWAPXY) blockmove_##function##_swapxy##_raw_pri##32 args ; \
1006 else blockmove_##function##_raw_pri##32 args
1007 #include "drawgfx.c"
1008 #undef DECLARE
1009 #undef DECLARE_SWAP_RAW_PRI
1010 #undef DECLAREG
1011 #undef BLOCKMOVE
1012 #undef BLOCKMOVELU
1013 #undef BLOCKMOVERAW
1014 #undef BLOCKMOVEPRI
1015 #undef BLOCKMOVERAWPRI
1016
1017 #undef DEPTH
1018 #undef DATA_TYPE
1019 #undef alpha_blend
1020
1021
1022 /***************************************************************************
1023
1024 Draw graphic elements in the specified bitmap.
1025
1026 transparency == TRANSPARENCY_NONE - no transparency.
1027 transparency == TRANSPARENCY_PEN - bits whose _original_ value is == transparent_color
1028 are transparent. This is the most common kind of
1029 transparency.
1030 transparency == TRANSPARENCY_PENS - as above, but transparent_color is a mask of
1031 transparent pens.
1032 transparency == TRANSPARENCY_COLOR - bits whose _remapped_ palette index (taken from
1033 Machine->game_colortable) is == transparent_color
1034
1035 transparency == TRANSPARENCY_PEN_TABLE - the transparency condition is same as TRANSPARENCY_PEN
1036 A special drawing is done according to gfx_drawmode_table[source pixel].
1037 DRAWMODE_NONE transparent
1038 DRAWMODE_SOURCE normal, draw source pixel.
1039 DRAWMODE_SHADOW destination is changed through palette_shadow_table[]
1040
1041 ***************************************************************************/
1042
1043 INLINE void common_drawgfx(struct mame_bitmap *dest,const struct GfxElement *gfx,
1044 unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
1045 const struct rectangle *clip,int transparency,int transparent_color,
1046 struct mame_bitmap *pri_buffer,UINT32 pri_mask)
1047 {
1048 struct rectangle myclip;
1049
1050 if (!gfx)
1051 {
1052 usrintf_showmessage("drawgfx() gfx == 0");
1053 return;
1054 }
1055 if (!gfx->colortable && !is_raw[transparency])
1056 {
1057 usrintf_showmessage("drawgfx() gfx->colortable == 0");
1058 return;
1059 }
1060
1061 code %= gfx->total_elements;
1062 if (!is_raw[transparency])
1063 color %= gfx->total_colors;
1064
1065 if (!alpha_active && (transparency == TRANSPARENCY_ALPHAONE || transparency == TRANSPARENCY_ALPHA))
1066 {
1067 if (transparency == TRANSPARENCY_ALPHAONE && (cpu_getcurrentframe() & 1))
1068 {
1069 transparency = TRANSPARENCY_PENS;
1070 transparent_color = (1 << (transparent_color & 0xff))|(1 << (transparent_color >> 8));
1071 }
1072 else
1073 {
1074 transparency = TRANSPARENCY_PEN;
1075 transparent_color &= 0xff;
1076 }
1077 }
1078
1079 if (gfx->pen_usage && (transparency == TRANSPARENCY_PEN || transparency == TRANSPARENCY_PENS))
1080 {
1081 int transmask = 0;
1082
1083 if (transparency == TRANSPARENCY_PEN)
1084 {
1085 transmask = 1 << (transparent_color & 0xff);
1086 }
1087 else /* transparency == TRANSPARENCY_PENS */
1088 {
1089 transmask = transparent_color;
1090 }
1091
1092 if ((gfx->pen_usage[code] & ~transmask) == 0)
1093 /* character is totally transparent, no need to draw */
1094 return;
1095 else if ((gfx->pen_usage[code] & transmask) == 0)
1096 /* character is totally opaque, can disable transparency */
1097 transparency = TRANSPARENCY_NONE;
1098 }
1099
1100 if (Machine->orientation & ORIENTATION_SWAP_XY)
1101 {
1102 int temp;
1103
1104 temp = sx;
1105 sx = sy;
1106 sy = temp;
1107
1108 temp = flipx;
1109 flipx = flipy;
1110 flipy = temp;
1111
1112 if (clip)
1113 {
1114 /* clip and myclip might be the same, so we need a temporary storage */
1115 temp = clip->min_x;
1116 myclip.min_x = clip->min_y;
1117 myclip.min_y = temp;
1118 temp = clip->max_x;
1119 myclip.max_x = clip->max_y;
1120 myclip.max_y = temp;
1121 clip = &myclip;
1122 }
1123 }
1124 if (Machine->orientation & ORIENTATION_FLIP_X)
1125 {
1126 sx = dest->width - gfx->width - sx;
1127 if (clip)
1128 {
1129 int temp;
1130
1131
1132 /* clip and myclip might be the same, so we need a temporary storage */
1133 temp = clip->min_x;
1134 myclip.min_x = dest->width-1 - clip->max_x;
1135 myclip.max_x = dest->width-1 - temp;
1136 myclip.min_y = clip->min_y;
1137 myclip.max_y = clip->max_y;
1138 clip = &myclip;
1139 }
1140 #ifndef PREROTATE_GFX
1141 flipx = !flipx;
1142 #endif
1143 }
1144 if (Machine->orientation & ORIENTATION_FLIP_Y)
1145 {
1146 sy = dest->height - gfx->height - sy;
1147 if (clip)
1148 {
1149 int temp;
1150
1151
1152 myclip.min_x = clip->min_x;
1153 myclip.max_x = clip->max_x;
1154 /* clip and myclip might be the same, so we need a temporary storage */
1155 temp = clip->min_y;
1156 myclip.min_y = dest->height-1 - clip->max_y;
1157 myclip.max_y = dest->height-1 - temp;
1158 clip = &myclip;
1159 }
1160 #ifndef PREROTATE_GFX
1161 flipy = !flipy;
1162 #endif
1163 }
1164
1165 if (dest->depth == 8)
1166 drawgfx_core8(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,pri_buffer,pri_mask);
1167 else if(dest->depth == 15 || dest->depth == 16)
1168 drawgfx_core16(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,pri_buffer,pri_mask);
1169 else
1170 drawgfx_core32(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,pri_buffer,pri_mask);
1171 }
1172
1173 void drawgfx(struct mame_bitmap *dest,const struct GfxElement *gfx,
1174 unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
1175 const struct rectangle *clip,int transparency,int transparent_color)
1176 {
1177 profiler_mark(PROFILER_DRAWGFX);
1178 common_drawgfx(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,NULL,0);
1179 profiler_mark(PROFILER_END);
1180 }
1181
1182 void pdrawgfx(struct mame_bitmap *dest,const struct GfxElement *gfx,
1183 unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
1184 const struct rectangle *clip,int transparency,int transparent_color,UINT32 priority_mask)
1185 {
1186 profiler_mark(PROFILER_DRAWGFX);
1187 common_drawgfx(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,priority_bitmap,priority_mask | (1<<31));
1188 profiler_mark(PROFILER_END);
1189 }
1190
1191 void mdrawgfx(struct mame_bitmap *dest,const struct GfxElement *gfx,
1192 unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
1193 const struct rectangle *clip,int transparency,int transparent_color,UINT32 priority_mask)
1194 {
1195 profiler_mark(PROFILER_DRAWGFX);
1196 common_drawgfx(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,priority_bitmap,priority_mask);
1197 profiler_mark(PROFILER_END);
1198 }
1199
1200
1201 /***************************************************************************
1202
1203 Use drawgfx() to copy a bitmap onto another at the given position.
1204 This function will very likely change in the future.
1205
1206 ***************************************************************************/
1207 void copybitmap(struct mame_bitmap *dest,struct mame_bitmap *src,int flipx,int flipy,int sx,int sy,
1208 const struct rectangle *clip,int transparency,int transparent_color)
1209 {
1210 /* translate to proper transparency here */
1211 if (transparency == TRANSPARENCY_NONE)
1212 transparency = TRANSPARENCY_NONE_RAW;
1213 else if (transparency == TRANSPARENCY_PEN)
1214 transparency = TRANSPARENCY_PEN_RAW;
1215 else if (transparency == TRANSPARENCY_COLOR)
1216 {
1217 transparent_color = Machine->pens[transparent_color];
1218 transparency = TRANSPARENCY_PEN_RAW;
1219 }
1220
1221 copybitmap_remap(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
1222 }
1223
1224
1225 void copybitmap_remap(struct mame_bitmap *dest,struct mame_bitmap *src,int flipx,int flipy,int sx,int sy,
1226 const struct rectangle *clip,int transparency,int transparent_color)
1227 {
1228 struct rectangle myclip;
1229
1230
1231 profiler_mark(PROFILER_COPYBITMAP);
1232
1233 if (Machine->orientation & ORIENTATION_SWAP_XY)
1234 {
1235 int temp;
1236
1237 temp = sx;
1238 sx = sy;
1239 sy = temp;
1240
1241 temp = flipx;
1242 flipx = flipy;
1243 flipy = temp;
1244
1245 if (clip)
1246 {
1247 /* clip and myclip might be the same, so we need a temporary storage */
1248 temp = clip->min_x;
1249 myclip.min_x = clip->min_y;
1250 myclip.min_y = temp;
1251 temp = clip->max_x;
1252 myclip.max_x = clip->max_y;
1253 myclip.max_y = temp;
1254 clip = &myclip;
1255 }
1256 }
1257 if (Machine->orientation & ORIENTATION_FLIP_X)
1258 {
1259 sx = dest->width - src->width - sx;
1260 if (clip)
1261 {
1262 int temp;
1263
1264
1265 /* clip and myclip might be the same, so we need a temporary storage */
1266 temp = clip->min_x;
1267 myclip.min_x = dest->width-1 - clip->max_x;
1268 myclip.max_x = dest->width-1 - temp;
1269 myclip.min_y = clip->min_y;
1270 myclip.max_y = clip->max_y;
1271 clip = &myclip;
1272 }
1273 }
1274 if (Machine->orientation & ORIENTATION_FLIP_Y)
1275 {
1276 sy = dest->height - src->height - sy;
1277 if (clip)
1278 {
1279 int temp;
1280
1281
1282 myclip.min_x = clip->min_x;
1283 myclip.max_x = clip->max_x;
1284 /* clip and myclip might be the same, so we need a temporary storage */
1285 temp = clip->min_y;
1286 myclip.min_y = dest->height-1 - clip->max_y;
1287 myclip.max_y = dest->height-1 - temp;
1288 clip = &myclip;
1289 }
1290 }
1291
1292 if (dest->depth == 8)
1293 copybitmap_core8(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
1294 else if(dest->depth == 15 || dest->depth == 16)
1295 copybitmap_core16(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
1296 else
1297 copybitmap_core32(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
1298
1299 profiler_mark(PROFILER_END);
1300 }
1301
1302
1303
1304 /***************************************************************************
1305
1306 Copy a bitmap onto another with scroll and wraparound.
1307 This function supports multiple independently scrolling rows/columns.
1308 "rows" is the number of indepentently scrolling rows. "rowscroll" is an
1309 array of integers telling how much to scroll each row. Same thing for
1310 "cols" and "colscroll".
1311 If the bitmap cannot scroll in one direction, set rows or columns to 0.
1312 If the bitmap scrolls as a whole, set rows and/or cols to 1.
1313 Bidirectional scrolling is, of course, supported only if the bitmap
1314 scrolls as a whole in at least one direction.
1315
1316 ***************************************************************************/
1317 void copyscrollbitmap(struct mame_bitmap *dest,struct mame_bitmap *src,
1318 int rows,const int *rowscroll,int cols,const int *colscroll,
1319 const struct rectangle *clip,int transparency,int transparent_color)
1320 {
1321 /* translate to proper transparency here */
1322 if (transparency == TRANSPARENCY_NONE)
1323 transparency = TRANSPARENCY_NONE_RAW;
1324 else if (transparency == TRANSPARENCY_PEN)
1325 transparency = TRANSPARENCY_PEN_RAW;
1326 else if (transparency == TRANSPARENCY_COLOR)
1327 {
1328 transparent_color = Machine->pens[transparent_color];
1329 transparency = TRANSPARENCY_PEN_RAW;
1330 }
1331
1332 copyscrollbitmap_remap(dest,src,rows,rowscroll,cols,colscroll,clip,transparency,transparent_color);
1333 }
1334
1335 void copyscrollbitmap_remap(struct mame_bitmap *dest,struct mame_bitmap *src,
1336 int rows,const int *rowscroll,int cols,const int *colscroll,
1337 const struct rectangle *clip,int transparency,int transparent_color)
1338 {
1339 int srcwidth,srcheight,destwidth,destheight;
1340 struct rectangle orig_clip;
1341
1342
1343 if (clip)
1344 {
1345 orig_clip.min_x = clip->min_x;
1346 orig_clip.max_x = clip->max_x;
1347 orig_clip.min_y = clip->min_y;
1348 orig_clip.max_y = clip->max_y;
1349 }
1350 else
1351 {
1352 orig_clip.min_x = 0;
1353 orig_clip.max_x = dest->width-1;
1354 orig_clip.min_y = 0;
1355 orig_clip.max_y = dest->height-1;
1356 }
1357 clip = &orig_clip;
1358
1359 if (rows == 0 && cols == 0)
1360 {
1361 copybitmap(dest,src,0,0,0,0,clip,transparency,transparent_color);
1362 return;
1363 }
1364
1365 profiler_mark(PROFILER_COPYBITMAP);
1366
1367 if (Machine->orientation & ORIENTATION_SWAP_XY)
1368 {
1369 srcwidth = src->height;
1370 srcheight = src->width;
1371 destwidth = dest->height;
1372 destheight = dest->width;
1373 }
1374 else
1375 {
1376 srcwidth = src->width;
1377 srcheight = src->height;
1378 destwidth = dest->width;
1379 destheight = dest->height;
1380 }
1381
1382 if (rows == 0)
1383 {
1384 /* scrolling columns */
1385 int col,colwidth;
1386 struct rectangle myclip;
1387
1388
1389 colwidth = srcwidth / cols;
1390
1391 myclip.min_y = clip->min_y;
1392 myclip.max_y = clip->max_y;
1393
1394 col = 0;
1395 while (col < cols)
1396 {
1397 int cons,scroll;
1398
1399
1400 /* count consecutive columns scrolled by the same amount */
1401 scroll = colscroll[col];
1402 cons = 1;
1403 while (col + cons < cols && colscroll[col + cons] == scroll)
1404 cons++;
1405
1406 if (scroll < 0) scroll = srcheight - (-scroll) % srcheight;
1407 else scroll %= srcheight;
1408
1409 myclip.min_x = col * colwidth;
1410 if (myclip.min_x < clip->min_x) myclip.min_x = clip->min_x;
1411 myclip.max_x = (col + cons) * colwidth - 1;
1412 if (myclip.max_x > clip->max_x) myclip.max_x = clip->max_x;
1413
1414 copybitmap(dest,src,0,0,0,scroll,&myclip,transparency,transparent_color);
1415 copybitmap(dest,src,0,0,0,scroll - srcheight,&myclip,transparency,transparent_color);
1416
1417 col += cons;
1418 }
1419 }
1420 else if (cols == 0)
1421 {
1422 /* scrolling rows */
1423 int row,rowheight;
1424 struct rectangle myclip;
1425
1426
1427 rowheight = srcheight / rows;
1428
1429 myclip.min_x = clip->min_x;
1430 myclip.max_x = clip->max_x;
1431
1432 row = 0;
1433 while (row < rows)
1434 {
1435 int cons,scroll;
1436
1437
1438 /* count consecutive rows scrolled by the same amount */
1439 scroll = rowscroll[row];
1440 cons = 1;
1441 while (row + cons < rows && rowscroll[row + cons] == scroll)
1442 cons++;
1443
1444 if (scroll < 0) scroll = srcwidth - (-scroll) % srcwidth;
1445 else scroll %= srcwidth;
1446
1447 myclip.min_y = row * rowheight;
1448 if (myclip.min_y < clip->min_y) myclip.min_y = clip->min_y;
1449 myclip.max_y = (row + cons) * rowheight - 1;
1450 if (myclip.max_y > clip->max_y) myclip.max_y = clip->max_y;
1451
1452 copybitmap(dest,src,0,0,scroll,0,&myclip,transparency,transparent_color);
1453 copybitmap(dest,src,0,0,scroll - srcwidth,0,&myclip,transparency,transparent_color);
1454
1455 row += cons;
1456 }
1457 }
1458 else if (rows == 1 && cols == 1)
1459 {
1460 /* XY scrolling playfield */
1461 int scrollx,scrolly,sx,sy;
1462
1463
1464 if (rowscroll[0] < 0) scrollx = srcwidth - (-rowscroll[0]) % srcwidth;
1465 else scrollx = rowscroll[0] % srcwidth;
1466
1467 if (colscroll[0] < 0) scrolly = srcheight - (-colscroll[0]) % srcheight;
1468 else scrolly = colscroll[0] % srcheight;
1469
1470 for (sx = scrollx - srcwidth;sx < destwidth;sx += srcwidth)
1471 for (sy = scrolly - srcheight;sy < destheight;sy += srcheight)
1472 copybitmap(dest,src,0,0,sx,sy,clip,transparency,transparent_color);
1473 }
1474 else if (rows == 1)
1475 {
1476 /* scrolling columns + horizontal scroll */
1477 int col,colwidth;
1478 int scrollx;
1479 struct rectangle myclip;
1480
1481
1482 if (rowscroll[0] < 0) scrollx = srcwidth - (-rowscroll[0]) % srcwidth;
1483 else scrollx = rowscroll[0] % srcwidth;
1484
1485 colwidth = srcwidth / cols;
1486
1487 myclip.min_y = clip->min_y;
1488 myclip.max_y = clip->max_y;
1489
1490 col = 0;
1491 while (col < cols)
1492 {
1493 int cons,scroll;
1494
1495
1496 /* count consecutive columns scrolled by the same amount */
1497 scroll = colscroll[col];
1498 cons = 1;
1499 while (col + cons < cols && colscroll[col + cons] == scroll)
1500 cons++;
1501
1502 if (scroll < 0) scroll = srcheight - (-scroll) % srcheight;
1503 else scroll %= srcheight;
1504
1505 myclip.min_x = col * colwidth + scrollx;
1506 if (myclip.min_x < clip->min_x) myclip.min_x = clip->min_x;
1507 myclip.max_x = (col + cons) * colwidth - 1 + scrollx;
1508 if (myclip.max_x > clip->max_x) myclip.max_x = clip->max_x;
1509
1510 copybitmap(dest,src,0,0,scrollx,scroll,&myclip,transparency,transparent_color);
1511 copybitmap(dest,src,0,0,scrollx,scroll - srcheight,&myclip,transparency,transparent_color);
1512
1513 myclip.min_x = col * colwidth + scrollx - srcwidth;
1514 if (myclip.min_x < clip->min_x) myclip.min_x = clip->min_x;
1515 myclip.max_x = (col + cons) * colwidth - 1 + scrollx - srcwidth;
1516 if (myclip.max_x > clip->max_x) myclip.max_x = clip->max_x;
1517
1518 copybitmap(dest,src,0,0,scrollx - srcwidth,scroll,&myclip,transparency,transparent_color);
1519 copybitmap(dest,src,0,0,scrollx - srcwidth,scroll - srcheight,&myclip,transparency,transparent_color);
1520
1521 col += cons;
1522 }
1523 }
1524 else if (cols == 1)
1525 {
1526 /* scrolling rows + vertical scroll */
1527 int row,rowheight;
1528 int scrolly;
1529 struct rectangle myclip;
1530
1531
1532 if (colscroll[0] < 0) scrolly = srcheight - (-colscroll[0]) % srcheight;
1533 else scrolly = colscroll[0] % srcheight;
1534
1535 rowheight = srcheight / rows;
1536
1537 myclip.min_x = clip->min_x;
1538 myclip.max_x = clip->max_x;
1539
1540 row = 0;
1541 while (row < rows)
1542 {
1543 int cons,scroll;
1544
1545
1546 /* count consecutive rows scrolled by the same amount */
1547 scroll = rowscroll[row];
1548 cons = 1;
1549 while (row + cons < rows && rowscroll[row + cons] == scroll)
1550 cons++;
1551
1552 if (scroll < 0) scroll = srcwidth - (-scroll) % srcwidth;
1553 else scroll %= srcwidth;
1554
1555 myclip.min_y = row * rowheight + scrolly;
1556 if (myclip.min_y < clip->min_y) myclip.min_y = clip->min_y;
1557 myclip.max_y = (row + cons) * rowheight - 1 + scrolly;
1558 if (myclip.max_y > clip->max_y) myclip.max_y = clip->max_y;
1559
1560 copybitmap(dest,src,0,0,scroll,scrolly,&myclip,transparency,transparent_color);
1561 copybitmap(dest,src,0,0,scroll - srcwidth,scrolly,&myclip,transparency,transparent_color);
1562
1563 myclip.min_y = row * rowheight + scrolly - srcheight;
1564 if (myclip.min_y < clip->min_y) myclip.min_y = clip->min_y;
1565 myclip.max_y = (row + cons) * rowheight - 1 + scrolly - srcheight;
1566 if (myclip.max_y > clip->max_y) myclip.max_y = clip->max_y;
1567
1568 copybitmap(dest,src,0,0,scroll,scrolly - srcheight,&myclip,transparency,transparent_color);
1569 copybitmap(dest,src,0,0,scroll - srcwidth,scrolly - srcheight,&myclip,transparency,transparent_color);
1570
1571 row += cons;
1572 }
1573 }
1574
1575 profiler_mark(PROFILER_END);
1576 }
1577
1578
1579 /* notes:
1580 - startx and starty MUST be UINT32 for calculations to work correctly
1581 - srcbitmap->width and height are assumed to be a power of 2 to speed up wraparound
1582 */
1583 void copyrozbitmap(struct mame_bitmap *dest,struct mame_bitmap *src,
1584 UINT32 startx,UINT32 starty,int incxx,int incxy,int incyx,int incyy,int wraparound,
1585 const struct rectangle *clip,int transparency,int transparent_color,UINT32 priority)
1586 {
1587 profiler_mark(PROFILER_COPYBITMAP);
1588
1589 /* cheat, the core doesn't support TRANSPARENCY_NONE yet */
1590 if (transparency == TRANSPARENCY_NONE)
1591 {
1592 transparency = TRANSPARENCY_PEN;
1593 transparent_color = -1;
1594 }
1595
1596 /* if necessary, remap the transparent color */
1597 if (transparency == TRANSPARENCY_COLOR)
1598 {
1599 transparency = TRANSPARENCY_PEN;
1600 transparent_color = Machine->pens[transparent_color];
1601 }
1602
1603 if (transparency != TRANSPARENCY_PEN)
1604 {
1605 usrintf_showmessage("copyrozbitmap unsupported trans %02x",transparency);
1606 return;
1607 }
1608
1609 if (dest->depth == 8)
1610 copyrozbitmap_core8(dest,src,startx,starty,incxx,incxy,incyx,incyy,wraparound,clip,transparency,transparent_color,priority);
1611 else if(dest->depth == 15 || dest->depth == 16)
1612 copyrozbitmap_core16(dest,src,startx,starty,incxx,incxy,incyx,incyy,wraparound,clip,transparency,transparent_color,priority);
1613 else
1614 copyrozbitmap_core32(dest,src,startx,starty,incxx,incxy,incyx,incyy,wraparound,clip,transparency,transparent_color,priority);
1615
1616 profiler_mark(PROFILER_END);
1617 }
1618
1619
1620
1621 /* fill a bitmap using the specified pen */
1622 void fillbitmap(struct mame_bitmap *dest,pen_t pen,const struct rectangle *clip)
1623 {
1624 int sx,sy,ex,ey,y;
1625 struct rectangle myclip;
1626
1627 if (Machine->orientation & ORIENTATION_SWAP_XY)
1628 {
1629 if (clip)
1630 {
1631 myclip.min_x = clip->min_y;
1632 myclip.max_x = clip->max_y;
1633 myclip.min_y = clip->min_x;
1634 myclip.max_y = clip->max_x;
1635 clip = &myclip;
1636 }
1637 }
1638 if (Machine->orientation & ORIENTATION_FLIP_X)
1639 {
1640 if (clip)
1641 {
1642 int temp;
1643
1644
1645 temp = clip->min_x;
1646 myclip.min_x = dest->width-1 - clip->max_x;
1647 myclip.max_x = dest->width-1 - temp;
1648 myclip.min_y = clip->min_y;
1649 myclip.max_y = clip->max_y;
1650 clip = &myclip;
1651 }
1652 }
1653 if (Machine->orientation & ORIENTATION_FLIP_Y)
1654 {
1655 if (clip)
1656 {
1657 int temp;
1658
1659
1660 myclip.min_x = clip->min_x;
1661 myclip.max_x = clip->max_x;
1662 temp = clip->min_y;
1663 myclip.min_y = dest->height-1 - clip->max_y;
1664 myclip.max_y = dest->height-1 - temp;
1665 clip = &myclip;
1666 }
1667 }
1668
1669
1670 sx = 0;
1671 ex = dest->width - 1;
1672 sy = 0;
1673 ey = dest->height - 1;
1674
1675 if (clip && sx < clip->min_x) sx = clip->min_x;
1676 if (clip && ex > clip->max_x) ex = clip->max_x;
1677 if (sx > ex) return;
1678 if (clip && sy < clip->min_y) sy = clip->min_y;
1679 if (clip && ey > clip->max_y) ey = clip->max_y;
1680 if (sy > ey) return;
1681
1682 if (Machine->drv->video_attributes & VIDEO_SUPPORTS_DIRTY)
1683 osd_mark_dirty(sx,sy,ex,ey);
1684
1685 if (dest->depth == 32)
1686 {
1687 if (((pen >> 8) == (pen & 0xff)) && ((pen>>16) == (pen & 0xff)))
1688 {
1689 for (y = sy;y <= ey;y++)
1690 memset(((UINT32 *)dest->line[y]) + sx,pen&0xff,(ex-sx+1)*4);
1691 }
1692 else
1693 {
1694 UINT32 *sp = (UINT32 *)dest->line[sy];
1695 int x;
1696
1697 for (x = sx;x <= ex;x++)
1698 sp[x] = pen;
1699 sp+=sx;
1700 for (y = sy+1;y <= ey;y++)
1701 memcpy(((UINT32 *)dest->line[y]) + sx,sp,(ex-sx+1)*4);
1702 }
1703 }
1704 else if (dest->depth == 15 || dest->depth == 16)
1705 {
1706 if ((pen >> 8) == (pen & 0xff))
1707 {
1708 for (y = sy;y <= ey;y++)
1709 memset(((UINT16 *)dest->line[y]) + sx,pen&0xff,(ex-sx+1)*2);
1710 }
1711 else
1712 {
1713 UINT16 *sp = (UINT16 *)dest->line[sy];
1714 int x;
1715
1716 for (x = sx;x <= ex;x++)
1717 sp[x] = pen;
1718 sp+=sx;
1719 for (y = sy+1;y <= ey;y++)
1720 memcpy(((UINT16 *)dest->line[y]) + sx,sp,(ex-sx+1)*2);
1721 }
1722 }
1723 else
1724 {
1725 for (y = sy;y <= ey;y++)
1726 memset(((UINT8 *)dest->line[y]) + sx,pen,ex-sx+1);
1727 }
1728 }
1729
1730
1731 INLINE void common_drawgfxzoom( struct mame_bitmap *dest_bmp,const struct GfxElement *gfx,
1732 unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
1733 const struct rectangle *clip,int transparency,int transparent_color,
1734 int scalex, int scaley,struct mame_bitmap *pri_buffer,UINT32 pri_mask)
1735 {
1736 struct rectangle myclip;
1737 int alphapen = 0;
1738
1739 if (!scalex || !scaley) return;
1740
1741 if (scalex == 0x10000 && scaley == 0x10000)
1742 {
1743 common_drawgfx(dest_bmp,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,pri_buffer,pri_mask);
1744 return;
1745 }
1746
1747
1748 if (transparency != TRANSPARENCY_PEN && transparency != TRANSPARENCY_PEN_RAW
1749 && transparency != TRANSPARENCY_PENS && transparency != TRANSPARENCY_COLOR
1750 && transparency != TRANSPARENCY_PEN_TABLE && transparency != TRANSPARENCY_PEN_TABLE_RAW
1751 && transparency != TRANSPARENCY_BLEND_RAW && transparency != TRANSPARENCY_ALPHAONE
1752 && transparency != TRANSPARENCY_ALPHA && transparency != TRANSPARENCY_NONE)
1753 {
1754 usrintf_showmessage("drawgfxzoom unsupported trans %02x",transparency);
1755 return;
1756 }
1757
1758 if (!alpha_active && (transparency == TRANSPARENCY_ALPHAONE || transparency == TRANSPARENCY_ALPHA))
1759 {
1760 transparency = TRANSPARENCY_PEN;
1761 transparent_color &= 0xff;
1762 }
1763
1764 if (transparency == TRANSPARENCY_ALPHAONE)
1765 {
1766 alphapen = transparent_color >> 8;
1767 transparent_color &= 0xff;
1768 }
1769
1770 if (transparency == TRANSPARENCY_COLOR)
1771 transparent_color = Machine->pens[transparent_color];
1772
1773
1774 /*
1775 scalex and scaley are 16.16 fixed point numbers
1776 1<<15 : shrink to 50%
1777 1<<16 : uniform scale
1778 1<<17 : double to 200%
1779 */
1780
1781
1782 if (Machine->orientation & ORIENTATION_SWAP_XY)
1783 {
1784 int temp;
1785
1786 temp = sx;
1787 sx = sy;
1788 sy = temp;
1789
1790 temp = flipx;
1791 flipx = flipy;
1792 flipy = temp;
1793
1794 temp = scalex;
1795 scalex = scaley;
1796 scaley = temp;
1797
1798 if (clip)
1799 {
1800 /* clip and myclip might be the same, so we need a temporary storage */
1801 temp = clip->min_x;
1802 myclip.min_x = clip->min_y;
1803 myclip.min_y = temp;
1804 temp = clip->max_x;
1805 myclip.max_x = clip->max_y;
1806 myclip.max_y = temp;
1807 clip = &myclip;
1808 }
1809 }
1810 if (Machine->orientation & ORIENTATION_FLIP_X)
1811 {
1812 sx = dest_bmp->width - ((gfx->width * scalex + 0x7fff) >> 16) - sx;
1813 if (clip)
1814 {
1815 int temp;
1816
1817
1818 /* clip and myclip might be the same, so we need a temporary storage */
1819 temp = clip->min_x;
1820 myclip.min_x = dest_bmp->width-1 - clip->max_x;
1821 myclip.max_x = dest_bmp->width-1 - temp;
1822 myclip.min_y = clip->min_y;
1823 myclip.max_y = clip->max_y;
1824 clip = &myclip;
1825 }
1826 #ifndef PREROTATE_GFX
1827 flipx = !flipx;
1828 #endif
1829 }
1830 if (Machine->orientation & ORIENTATION_FLIP_Y)
1831 {
1832 sy = dest_bmp->height - ((gfx->height * scaley + 0x7fff) >> 16) - sy;
1833 if (clip)
1834 {
1835 int temp;
1836
1837
1838 myclip.min_x = clip->min_x;
1839 myclip.max_x = clip->max_x;
1840 /* clip and myclip might be the same, so we need a temporary storage */
1841 temp = clip->min_y;
1842 myclip.min_y = dest_bmp->height-1 - clip->max_y;
1843 myclip.max_y = dest_bmp->height-1 - temp;
1844 clip = &myclip;
1845 }
1846 #ifndef PREROTATE_GFX
1847 flipy = !flipy;
1848 #endif
1849 }
1850
1851 /* KW 991012 -- Added code to force clip to bitmap boundary */
1852 if(clip)
1853 {
1854 myclip.min_x = clip->min_x;
1855 myclip.max_x = clip->max_x;
1856 myclip.min_y = clip->min_y;
1857 myclip.max_y = clip->max_y;
1858
1859 if (myclip.min_x < 0) myclip.min_x = 0;
1860 if (myclip.max_x >= dest_bmp->width) myclip.max_x = dest_bmp->width-1;
1861 if (myclip.min_y < 0) myclip.min_y = 0;
1862 if (myclip.max_y >= dest_bmp->height) myclip.max_y = dest_bmp->height-1;
1863
1864 clip=&myclip;
1865 }
1866
1867
1868 /* ASG 980209 -- added 16-bit version */
1869 if (dest_bmp->depth == 8)
1870 {
1871 if( gfx && gfx->colortable )
1872 {
1873 const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
1874 int source_base = (code % gfx->total_elements) * gfx->height;
1875
1876 int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
1877 int sprite_screen_width = (scalex*gfx->width+0x8000)>>16;
1878
1879 if (sprite_screen_width && sprite_screen_height)
1880 {
1881 /* compute sprite increment per screen pixel */
1882 int dx = (gfx->width<<16)/sprite_screen_width;
1883 int dy = (gfx->height<<16)/sprite_screen_height;
1884
1885 int ex = sx+sprite_screen_width;
1886 int ey = sy+sprite_screen_height;
1887
1888 int x_index_base;
1889 int y_index;
1890
1891 if( flipx )
1892 {
1893 x_index_base = (sprite_screen_width-1)*dx;
1894 dx = -dx;
1895 }
1896 else
1897 {
1898 x_index_base = 0;
1899 }
1900
1901 if( flipy )
1902 {
1903 y_index = (sprite_screen_height-1)*dy;
1904 dy = -dy;
1905 }
1906 else
1907 {
1908 y_index = 0;
1909 }
1910
1911 if( clip )
1912 {
1913 if( sx < clip->min_x)
1914 { /* clip left */
1915 int pixels = clip->min_x-sx;
1916 sx += pixels;
1917 x_index_base += pixels*dx;
1918 }
1919 if( sy < clip->min_y )
1920 { /* clip top */
1921 int pixels = clip->min_y-sy;
1922 sy += pixels;
1923 y_index += pixels*dy;
1924 }
1925 /* NS 980211 - fixed incorrect clipping */
1926 if( ex > clip->max_x+1 )
1927 { /* clip right */
1928 int pixels = ex-clip->max_x-1;
1929 ex -= pixels;
1930 }
1931 if( ey > clip->max_y+1 )
1932 { /* clip bottom */
1933 int pixels = ey-clip->max_y-1;
1934 ey -= pixels;
1935 }
1936 }
1937
1938 if( ex>sx )
1939 { /* skip if inner loop doesn't draw anything */
1940 int y;
1941
1942 /* case 0: TRANSPARENCY_NONE */
1943 if (transparency == TRANSPARENCY_NONE)
1944 {
1945 if (pri_buffer)
1946 {
1947 if (gfx->flags & GFX_PACKED)
1948 {
1949 for( y=sy; y<ey; y++ )
1950 {
1951 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1952 UINT8 *dest = dest_bmp->line[y];
1953 UINT8 *pri = pri_buffer->line[y];
1954
1955 int x, x_index = x_index_base;
1956 for( x=sx; x<ex; x++ )
1957 {
1958 if (((1 << pri[x]) & pri_mask) == 0)
1959 dest[x] = pal[(source[x_index>>17] >> ((x_index & 0x10000) >> 14)) & 0x0f];
1960 pri[x] = 31;
1961 x_index += dx;
1962 }
1963
1964 y_index += dy;
1965 }
1966 }
1967 else
1968 {
1969 for( y=sy; y<ey; y++ )
1970 {
1971 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1972 UINT8 *dest = dest_bmp->line[y];
1973 UINT8 *pri = pri_buffer->line[y];
1974
1975 int x, x_index = x_index_base;
1976 for( x=sx; x<ex; x++ )
1977 {
1978 if (((1 << pri[x]) & pri_mask) == 0)
1979 dest[x] = pal[source[x_index>>16]];
1980 x_index += dx;
1981 }
1982
1983 y_index += dy;
1984 }
1985 }
1986 }
1987 else
1988 {
1989 if (gfx->flags & GFX_PACKED)
1990 {
1991 for( y=sy; y<ey; y++ )
1992 {
1993 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1994 UINT8 *dest = dest_bmp->line[y];
1995
1996 int x, x_index = x_index_base;
1997 for( x=sx; x<ex; x++ )
1998 {
1999 dest[x] = pal[(source[x_index>>17] >> ((x_index & 0x10000) >> 14)) & 0x0f];
2000 x_index += dx;
2001 }
2002
2003 y_index += dy;
2004 }
2005 }
2006 else
2007 {
2008 for( y=sy; y<ey; y++ )
2009 {
2010 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2011 UINT8 *dest = dest_bmp->line[y];
2012
2013 int x, x_index = x_index_base;
2014 for( x=sx; x<ex; x++ )
2015 {
2016 dest[x] = pal[source[x_index>>16]];
2017 x_index += dx;
2018 }
2019
2020 y_index += dy;
2021 }
2022 }
2023 }
2024 }
2025
2026 /* case 1: TRANSPARENCY_PEN */
2027 if (transparency == TRANSPARENCY_PEN)
2028 {
2029 if (pri_buffer)
2030 {
2031 if (gfx->flags & GFX_PACKED)
2032 {
2033 for( y=sy; y<ey; y++ )
2034 {
2035 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2036 UINT8 *dest = dest_bmp->line[y];
2037 UINT8 *pri = pri_buffer->line[y];
2038
2039 int x, x_index = x_index_base;
2040 for( x=sx; x<ex; x++ )
2041 {
2042 int c = (source[x_index>>17] >> ((x_index & 0x10000) >> 14)) & 0x0f;
2043 if( c != transparent_color )
2044 {
2045 if (((1 << pri[x]) & pri_mask) == 0)
2046 dest[x] = pal[c];
2047 pri[x] = 31;
2048 }
2049 x_index += dx;
2050 }
2051
2052 y_index += dy;
2053 }
2054 }
2055 else
2056 {
2057 for( y=sy; y<ey; y++ )
2058 {
2059 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2060 UINT8 *dest = dest_bmp->line[y];
2061 UINT8 *pri = pri_buffer->line[y];
2062
2063 int x, x_index = x_index_base;
2064 for( x=sx; x<ex; x++ )
2065 {
2066 int c = source[x_index>>16];
2067 if( c != transparent_color )
2068 {
2069 if (((1 << pri[x]) & pri_mask) == 0)
2070 dest[x] = pal[c];
2071 pri[x] = 31;
2072 }
2073 x_index += dx;
2074 }
2075
2076 y_index += dy;
2077 }
2078 }
2079 }
2080 else
2081 {
2082 if (gfx->flags & GFX_PACKED)
2083 {
2084 for( y=sy; y<ey; y++ )
2085 {
2086 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2087 UINT8 *dest = dest_bmp->line[y];
2088
2089 int x, x_index = x_index_base;
2090 for( x=sx; x<ex; x++ )
2091 {
2092 int c = (source[x_index>>17] >> ((x_index & 0x10000) >> 14)) & 0x0f;
2093 if( c != transparent_color ) dest[x] = pal[c];
2094 x_index += dx;
2095 }
2096
2097 y_index += dy;
2098 }
2099 }
2100 else
2101 {
2102 for( y=sy; y<ey; y++ )
2103 {
2104 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2105 UINT8 *dest = dest_bmp->line[y];
2106
2107 int x, x_index = x_index_base;
2108 for( x=sx; x<ex; x++ )
2109 {
2110 int c = source[x_index>>16];
2111 if( c != transparent_color ) dest[x] = pal[c];
2112 x_index += dx;
2113 }
2114
2115 y_index += dy;
2116 }
2117 }
2118 }
2119 }
2120
2121 /* case 1b: TRANSPARENCY_PEN_RAW */
2122 if (transparency == TRANSPARENCY_PEN_RAW)
2123 {
2124 if (pri_buffer)
2125 {
2126 for( y=sy; y<ey; y++ )
2127 {
2128 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2129 UINT8 *dest = dest_bmp->line[y];
2130 UINT8 *pri = pri_buffer->line[y];
2131
2132 int x, x_index = x_index_base;
2133 for( x=sx; x<ex; x++ )
2134 {
2135 int c = source[x_index>>16];
2136 if( c != transparent_color )
2137 {
2138 if (((1 << pri[x]) & pri_mask) == 0)
2139 dest[x] = color + c;
2140 pri[x] = 31;
2141 }
2142 x_index += dx;
2143 }
2144
2145 y_index += dy;
2146 }
2147 }
2148 else
2149 {
2150 for( y=sy; y<ey; y++ )
2151 {
2152 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2153 UINT8 *dest = dest_bmp->line[y];
2154
2155 int x, x_index = x_index_base;
2156 for( x=sx; x<ex; x++ )
2157 {
2158 int c = source[x_index>>16];
2159 if( c != transparent_color ) dest[x] = color + c;
2160 x_index += dx;
2161 }
2162
2163 y_index += dy;
2164 }
2165 }
2166 }
2167
2168 /* case 1c: TRANSPARENCY_BLEND_RAW */
2169 if (transparency == TRANSPARENCY_BLEND_RAW)
2170 {
2171 if (pri_buffer)
2172 {
2173 for( y=sy; y<ey; y++ )
2174 {
2175 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2176 UINT8 *dest = dest_bmp->line[y];
2177 UINT8 *pri = pri_buffer->line[y];
2178
2179 int x, x_index = x_index_base;
2180 for( x=sx; x<ex; x++ )
2181 {
2182 int c = source[x_index>>16];
2183 if( c != transparent_color )
2184 {
2185 if (((1 << pri[x]) & pri_mask) == 0)
2186 dest[x] |= (color + c);
2187 pri[x] = 31;
2188 }
2189 x_index += dx;
2190 }
2191
2192 y_index += dy;
2193 }
2194 }
2195 else
2196 {
2197 for( y=sy; y<ey; y++ )
2198 {
2199 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2200 UINT8 *dest = dest_bmp->line[y];
2201
2202 int x, x_index = x_index_base;
2203 for( x=sx; x<ex; x++ )
2204 {
2205 int c = source[x_index>>16];
2206 if( c != transparent_color ) dest[x] |= (color + c);
2207 x_index += dx;
2208 }
2209
2210 y_index += dy;
2211 }
2212 }
2213 }
2214
2215 /* case 2: TRANSPARENCY_PENS */
2216 if (transparency == TRANSPARENCY_PENS)
2217 {
2218 if (pri_buffer)
2219 {
2220 for( y=sy; y<ey; y++ )
2221 {
2222 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2223 UINT8 *dest = dest_bmp->line[y];
2224 UINT8 *pri = pri_buffer->line[y];
2225
2226 int x, x_index = x_index_base;
2227 for( x=sx; x<ex; x++ )
2228 {
2229 int c = source[x_index>>16];
2230 if (((1 << c) & transparent_color) == 0)
2231 {
2232 if (((1 << pri[x]) & pri_mask) == 0)
2233 dest[x] = pal[c];
2234 pri[x] = 31;
2235 }
2236 x_index += dx;
2237 }
2238
2239 y_index += dy;
2240 }
2241 }
2242 else
2243 {
2244 for( y=sy; y<ey; y++ )
2245 {
2246 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2247 UINT8 *dest = dest_bmp->line[y];
2248
2249 int x, x_index = x_index_base;
2250 for( x=sx; x<ex; x++ )
2251 {
2252 int c = source[x_index>>16];
2253 if (((1 << c) & transparent_color) == 0)
2254 dest[x] = pal[c];
2255 x_index += dx;
2256 }
2257
2258 y_index += dy;
2259 }
2260 }
2261 }
2262
2263 /* case 3: TRANSPARENCY_COLOR */
2264 else if (transparency == TRANSPARENCY_COLOR)
2265 {
2266 if (pri_buffer)
2267 {
2268 for( y=sy; y<ey; y++ )
2269 {
2270 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2271 UINT8 *dest = dest_bmp->line[y];
2272 UINT8 *pri = pri_buffer->line[y];
2273
2274 int x, x_index = x_index_base;
2275 for( x=sx; x<ex; x++ )
2276 {
2277 int c = pal[source[x_index>>16]];
2278 if( c != transparent_color )
2279 {
2280 if (((1 << pri[x]) & pri_mask) == 0)
2281 dest[x] = c;
2282 pri[x] = 31;
2283 }
2284 x_index += dx;
2285 }
2286
2287 y_index += dy;
2288 }
2289 }
2290 else
2291 {
2292 for( y=sy; y<ey; y++ )
2293 {
2294 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2295 UINT8 *dest = dest_bmp->line[y];
2296
2297 int x, x_index = x_index_base;
2298 for( x=sx; x<ex; x++ )
2299 {
2300 int c = pal[source[x_index>>16]];
2301 if( c != transparent_color ) dest[x] = c;
2302 x_index += dx;
2303 }
2304
2305 y_index += dy;
2306 }
2307 }
2308 }
2309
2310 /* case 4: TRANSPARENCY_PEN_TABLE */
2311 if (transparency == TRANSPARENCY_PEN_TABLE)
2312 {
2313 if (pri_buffer)
2314 {
2315 for( y=sy; y<ey; y++ )
2316 {
2317 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2318 UINT8 *dest = dest_bmp->line[y];
2319 UINT8 *pri = pri_buffer->line[y];
2320
2321 int x, x_index = x_index_base;
2322 for( x=sx; x<ex; x++ )
2323 {
2324 int c = source[x_index>>16];
2325 if( c != transparent_color )
2326 {
2327 switch(gfx_drawmode_table[c])
2328 {
2329 case DRAWMODE_SOURCE:
2330 if (((1 << (pri[x] & 0x1f)) & pri_mask) == 0)
2331 {
2332 if (pri[x] & 0x80)
2333 dest[x] = palette_shadow_table[pal[c]];
2334 else
2335 dest[x] = pal[c];
2336 }
2337 pri[x] = (pri[x] & 0x7f) | 31;
2338 break;
2339 case DRAWMODE_SHADOW:
2340 if (((1 << pri[x]) & pri_mask) == 0)
2341 dest[x] = palette_shadow_table[dest[x]];
2342 pri[x] |= pdrawgfx_shadow_lowpri ? 0 : 0x80;
2343 break;
2344 }
2345 }
2346 x_index += dx;
2347 }
2348
2349 y_index += dy;
2350 }
2351 }
2352 else
2353 {
2354 for( y=sy; y<ey; y++ )
2355 {
2356 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2357 UINT8 *dest = dest_bmp->line[y];
2358
2359 int x, x_index = x_index_base;
2360 for( x=sx; x<ex; x++ )
2361 {
2362 int c = source[x_index>>16];
2363 if( c != transparent_color )
2364 {
2365 switch(gfx_drawmode_table[c])
2366 {
2367 case DRAWMODE_SOURCE:
2368 dest[x] = pal[c];
2369 break;
2370 case DRAWMODE_SHADOW:
2371 dest[x] = palette_shadow_table[dest[x]];
2372 break;
2373 }
2374 }
2375 x_index += dx;
2376 }
2377
2378 y_index += dy;
2379 }
2380 }
2381 }
2382
2383 /* case 4b: TRANSPARENCY_PEN_TABLE_RAW */
2384 if (transparency == TRANSPARENCY_PEN_TABLE_RAW)
2385 {
2386 if (pri_buffer)
2387 {
2388 for( y=sy; y<ey; y++ )
2389 {
2390 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2391 UINT8 *dest = dest_bmp->line[y];
2392 UINT8 *pri = pri_buffer->line[y];
2393
2394 int x, x_index = x_index_base;
2395 for( x=sx; x<ex; x++ )
2396 {
2397 int c = source[x_index>>16];
2398 if( c != transparent_color )
2399 {
2400 switch(gfx_drawmode_table[c])
2401 {
2402 case DRAWMODE_SOURCE:
2403 if (((1 << (pri[x] & 0x1f)) & pri_mask) == 0)
2404 {
2405 if (pri[x] & 0x80)
2406 dest[x] = palette_shadow_table[color + c];
2407 else
2408 dest[x] = color + c;
2409 }
2410 pri[x] = (pri[x] & 0x7f) | 31;
2411 break;
2412 case DRAWMODE_SHADOW:
2413 if (((1 << pri[x]) & pri_mask) == 0)
2414 dest[x] = palette_shadow_table[dest[x]];
2415 pri[x] |= pdrawgfx_shadow_lowpri ? 0 : 0x80;
2416 break;
2417 }
2418 }
2419 x_index += dx;
2420 }
2421
2422 y_index += dy;
2423 }
2424 }
2425 else
2426 {
2427 for( y=sy; y<ey; y++ )
2428 {
2429 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2430 UINT8 *dest = dest_bmp->line[y];
2431
2432 int x, x_index = x_index_base;
2433 for( x=sx; x<ex; x++ )
2434 {
2435 int c = source[x_index>>16];
2436 if( c != transparent_color )
2437 {
2438 switch(gfx_drawmode_table[c])
2439 {
2440 case DRAWMODE_SOURCE:
2441 dest[x] = color + c;
2442 break;
2443 case DRAWMODE_SHADOW:
2444 dest[x] = palette_shadow_table[dest[x]];
2445 break;
2446 }
2447 }
2448 x_index += dx;
2449 }
2450
2451 y_index += dy;
2452 }
2453 }
2454 }
2455 }
2456 }
2457 }
2458 }
2459
2460 /* ASG 980209 -- new 16-bit part */
2461 else if (dest_bmp->depth == 15 || dest_bmp->depth == 16)
2462 {
2463 if( gfx && gfx->colortable )
2464 {
2465 const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
2466 int source_base = (code % gfx->total_elements) * gfx->height;
2467
2468 int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
2469 int sprite_screen_width = (scalex*gfx->width+0x8000)>>16;
2470
2471 if (sprite_screen_width && sprite_screen_height)
2472 {
2473 /* compute sprite increment per screen pixel */
2474 int dx = (gfx->width<<16)/sprite_screen_width;
2475 int dy = (gfx->height<<16)/sprite_screen_height;
2476
2477 int ex = sx+sprite_screen_width;
2478 int ey = sy+sprite_screen_height;
2479
2480 int x_index_base;
2481 int y_index;
2482
2483 if( flipx )
2484 {
2485 x_index_base = (sprite_screen_width-1)*dx;
2486 dx = -dx;
2487 }
2488 else
2489 {
2490 x_index_base = 0;
2491 }
2492
2493 if( flipy )
2494 {
2495 y_index = (sprite_screen_height-1)*dy;
2496 dy = -dy;
2497 }
2498 else
2499 {
2500 y_index = 0;
2501 }
2502
2503 if( clip )
2504 {
2505 if( sx < clip->min_x)
2506 { /* clip left */
2507 int pixels = clip->min_x-sx;
2508 sx += pixels;
2509 x_index_base += pixels*dx;
2510 }
2511 if( sy < clip->min_y )
2512 { /* clip top */
2513 int pixels = clip->min_y-sy;
2514 sy += pixels;
2515 y_index += pixels*dy;
2516 }
2517 /* NS 980211 - fixed incorrect clipping */
2518 if( ex > clip->max_x+1 )
2519 { /* clip right */
2520 int pixels = ex-clip->max_x-1;
2521 ex -= pixels;
2522 }
2523 if( ey > clip->max_y+1 )
2524 { /* clip bottom */
2525 int pixels = ey-clip->max_y-1;
2526 ey -= pixels;
2527 }
2528 }
2529
2530 if( ex>sx )
2531 { /* skip if inner loop doesn't draw anything */
2532 int y;
2533
2534 /* case 0: TRANSPARENCY_NONE */
2535 if (transparency == TRANSPARENCY_NONE)
2536 {
2537 if (pri_buffer)
2538 {
2539 if (gfx->flags & GFX_PACKED)
2540 {
2541 for( y=sy; y<ey; y++ )
2542 {
2543 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2544 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2545 UINT8 *pri = pri_buffer->line[y];
2546
2547 int x, x_index = x_index_base;
2548 for( x=sx; x<ex; x++ )
2549 {
2550 if (((1 << pri[x]) & pri_mask) == 0)
2551 dest[x] = pal[(source[x_index>>17] >> ((x_index & 0x10000) >> 14)) & 0x0f];
2552 pri[x] = 31;
2553 x_index += dx;
2554 }
2555
2556 y_index += dy;
2557 }
2558 }
2559 else
2560 {
2561 for( y=sy; y<ey; y++ )
2562 {
2563 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2564 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2565 UINT8 *pri = pri_buffer->line[y];
2566
2567 int x, x_index = x_index_base;
2568 for( x=sx; x<ex; x++ )
2569 {
2570 if (((1 << pri[x]) & pri_mask) == 0)
2571 dest[x] = pal[source[x_index>>16]];
2572 pri[x] = 31;
2573 x_index += dx;
2574 }
2575
2576 y_index += dy;
2577 }
2578 }
2579 }
2580 else
2581 {
2582 if (gfx->flags & GFX_PACKED)
2583 {
2584 for( y=sy; y<ey; y++ )
2585 {
2586 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2587 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2588
2589 int x, x_index = x_index_base;
2590 for( x=sx; x<ex; x++ )
2591 {
2592 dest[x] = pal[(source[x_index>>17] >> ((x_index & 0x10000) >> 14)) & 0x0f];
2593 x_index += dx;
2594 }
2595
2596 y_index += dy;
2597 }
2598 }
2599 else
2600 {
2601 for( y=sy; y<ey; y++ )
2602 {
2603 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2604 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2605
2606 int x, x_index = x_index_base;
2607 for( x=sx; x<ex; x++ )
2608 {
2609 dest[x] = pal[source[x_index>>16]];
2610 x_index += dx;
2611 }
2612
2613 y_index += dy;
2614 }
2615 }
2616 }
2617 }
2618
2619 /* case 1: TRANSPARENCY_PEN */
2620 if (transparency == TRANSPARENCY_PEN)
2621 {
2622 if (pri_buffer)
2623 {
2624 if (gfx->flags & GFX_PACKED)
2625 {
2626 for( y=sy; y<ey; y++ )
2627 {
2628 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2629 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2630 UINT8 *pri = pri_buffer->line[y];
2631
2632 int x, x_index = x_index_base;
2633 for( x=sx; x<ex; x++ )
2634 {
2635 int c = (source[x_index>>17] >> ((x_index & 0x10000) >> 14)) & 0x0f;
2636 if( c != transparent_color )
2637 {
2638 if (((1 << pri[x]) & pri_mask) == 0)
2639 dest[x] = pal[c];
2640 pri[x] = 31;
2641 }
2642 x_index += dx;
2643 }
2644
2645 y_index += dy;
2646 }
2647 }
2648 else
2649 {
2650 for( y=sy; y<ey; y++ )
2651 {
2652 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2653 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2654 UINT8 *pri = pri_buffer->line[y];
2655
2656 int x, x_index = x_index_base;
2657 for( x=sx; x<ex; x++ )
2658 {
2659 int c = source[x_index>>16];
2660 if( c != transparent_color )
2661 {
2662 if (((1 << pri[x]) & pri_mask) == 0)
2663 dest[x] = pal[c];
2664 pri[x] = 31;
2665 }
2666 x_index += dx;
2667 }
2668
2669 y_index += dy;
2670 }
2671 }
2672 }
2673 else
2674 {
2675 if (gfx->flags & GFX_PACKED)
2676 {
2677 for( y=sy; y<ey; y++ )
2678 {
2679 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2680 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2681
2682 int x, x_index = x_index_base;
2683 for( x=sx; x<ex; x++ )
2684 {
2685 int c = (source[x_index>>17] >> ((x_index & 0x10000) >> 14)) & 0x0f;
2686 if( c != transparent_color ) dest[x] = pal[c];
2687 x_index += dx;
2688 }
2689
2690 y_index += dy;
2691 }
2692 }
2693 else
2694 {
2695 for( y=sy; y<ey; y++ )
2696 {
2697 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2698 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2699
2700 int x, x_index = x_index_base;
2701 for( x=sx; x<ex; x++ )
2702 {
2703 int c = source[x_index>>16];
2704 if( c != transparent_color ) dest[x] = pal[c];
2705 x_index += dx;
2706 }
2707
2708 y_index += dy;
2709 }
2710 }
2711 }
2712 }
2713
2714 /* case 1b: TRANSPARENCY_PEN_RAW */
2715 if (transparency == TRANSPARENCY_PEN_RAW)
2716 {
2717 if (pri_buffer)
2718 {
2719 for( y=sy; y<ey; y++ )
2720 {
2721 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2722 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2723 UINT8 *pri = pri_buffer->line[y];
2724
2725 int x, x_index = x_index_base;
2726 for( x=sx; x<ex; x++ )
2727 {
2728 int c = source[x_index>>16];
2729 if( c != transparent_color )
2730 {
2731 if (((1 << pri[x]) & pri_mask) == 0)
2732 dest[x] = color + c;
2733 pri[x] = 31;
2734 }
2735 x_index += dx;
2736 }
2737
2738 y_index += dy;
2739 }
2740 }
2741 else
2742 {
2743 for( y=sy; y<ey; y++ )
2744 {
2745 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2746 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2747
2748 int x, x_index = x_index_base;
2749 for( x=sx; x<ex; x++ )
2750 {
2751 int c = source[x_index>>16];
2752 if( c != transparent_color ) dest[x] = color + c;
2753 x_index += dx;
2754 }
2755
2756 y_index += dy;
2757 }
2758 }
2759 }
2760
2761 /* case 1c: TRANSPARENCY_BLEND_RAW */
2762 if (transparency == TRANSPARENCY_BLEND_RAW)
2763 {
2764 if (pri_buffer)
2765 {
2766 for( y=sy; y<ey; y++ )
2767 {
2768 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2769 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2770 UINT8 *pri = pri_buffer->line[y];
2771
2772 int x, x_index = x_index_base;
2773 for( x=sx; x<ex; x++ )
2774 {
2775 int c = source[x_index>>16];
2776 if( c != transparent_color )
2777 {
2778 if (((1 << pri[x]) & pri_mask) == 0)
2779 dest[x] |= color + c;
2780 pri[x] = 31;
2781 }
2782 x_index += dx;
2783 }
2784
2785 y_index += dy;
2786 }
2787 }
2788 else
2789 {
2790 for( y=sy; y<ey; y++ )
2791 {
2792 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2793 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2794
2795 int x, x_index = x_index_base;
2796 for( x=sx; x<ex; x++ )
2797 {
2798 int c = source[x_index>>16];
2799 if( c != transparent_color ) dest[x] |= color + c;
2800 x_index += dx;
2801 }
2802
2803 y_index += dy;
2804 }
2805 }
2806 }
2807
2808 /* case 2: TRANSPARENCY_PENS */
2809 if (transparency == TRANSPARENCY_PENS)
2810 {
2811 if (pri_buffer)
2812 {
2813 for( y=sy; y<ey; y++ )
2814 {
2815 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2816 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2817 UINT8 *pri = pri_buffer->line[y];
2818
2819 int x, x_index = x_index_base;
2820 for( x=sx; x<ex; x++ )
2821 {
2822 int c = source[x_index>>16];
2823 if (((1 << c) & transparent_color) == 0)
2824 {
2825 if (((1 << pri[x]) & pri_mask) == 0)
2826 dest[x] = pal[c];
2827 pri[x] = 31;
2828 }
2829 x_index += dx;
2830 }
2831
2832 y_index += dy;
2833 }
2834 }
2835 else
2836 {
2837 for( y=sy; y<ey; y++ )
2838 {
2839 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2840 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2841
2842 int x, x_index = x_index_base;
2843 for( x=sx; x<ex; x++ )
2844 {
2845 int c = source[x_index>>16];
2846 if (((1 << c) & transparent_color) == 0)
2847 dest[x] = pal[c];
2848 x_index += dx;
2849 }
2850
2851 y_index += dy;
2852 }
2853 }
2854 }
2855
2856 /* case 3: TRANSPARENCY_COLOR */
2857 else if (transparency == TRANSPARENCY_COLOR)
2858 {
2859 if (pri_buffer)
2860 {
2861 for( y=sy; y<ey; y++ )
2862 {
2863 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2864 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2865 UINT8 *pri = pri_buffer->line[y];
2866
2867 int x, x_index = x_index_base;
2868 for( x=sx; x<ex; x++ )
2869 {
2870 int c = pal[source[x_index>>16]];
2871 if( c != transparent_color )
2872 {
2873 if (((1 << pri[x]) & pri_mask) == 0)
2874 dest[x] = c;
2875 pri[x] = 31;
2876 }
2877 x_index += dx;
2878 }
2879
2880 y_index += dy;
2881 }
2882 }
2883 else
2884 {
2885 for( y=sy; y<ey; y++ )
2886 {
2887 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2888 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2889
2890 int x, x_index = x_index_base;
2891 for( x=sx; x<ex; x++ )
2892 {
2893 int c = pal[source[x_index>>16]];
2894 if( c != transparent_color ) dest[x] = c;
2895 x_index += dx;
2896 }
2897
2898 y_index += dy;
2899 }
2900 }
2901 }
2902
2903 /* case 4: TRANSPARENCY_PEN_TABLE */
2904 if (transparency == TRANSPARENCY_PEN_TABLE)
2905 {
2906 if (pri_buffer)
2907 {
2908 for( y=sy; y<ey; y++ )
2909 {
2910 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2911 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2912 UINT8 *pri = pri_buffer->line[y];
2913
2914 int x, x_index = x_index_base;
2915 for( x=sx; x<ex; x++ )
2916 {
2917 int c = source[x_index>>16];
2918 if( c != transparent_color )
2919 {
2920 switch(gfx_drawmode_table[c])
2921 {
2922 case DRAWMODE_SOURCE:
2923 if (((1 << (pri[x] & 0x1f)) & pri_mask) == 0)
2924 {
2925 if (pri[x] & 0x80)
2926 dest[x] = palette_shadow_table[pal[c]];
2927 else
2928 dest[x] = pal[c];
2929 }
2930 pri[x] = (pri[x] & 0x7f) | 31;
2931 break;
2932 case DRAWMODE_SHADOW:
2933 if (((1 << pri[x]) & pri_mask) == 0)
2934 dest[x] = palette_shadow_table[dest[x]];
2935 pri[x] |= pdrawgfx_shadow_lowpri ? 0 : 0x80;
2936 break;
2937 }
2938 }
2939 x_index += dx;
2940 }
2941
2942 y_index += dy;
2943 }
2944 }
2945 else
2946 {
2947 for( y=sy; y<ey; y++ )
2948 {
2949 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2950 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2951
2952 int x, x_index = x_index_base;
2953 for( x=sx; x<ex; x++ )
2954 {
2955 int c = source[x_index>>16];
2956 if( c != transparent_color )
2957 {
2958 switch(gfx_drawmode_table[c])
2959 {
2960 case DRAWMODE_SOURCE:
2961 dest[x] = pal[c];
2962 break;
2963 case DRAWMODE_SHADOW:
2964 dest[x] = palette_shadow_table[dest[x]];
2965 break;
2966 }
2967 }
2968 x_index += dx;
2969 }
2970
2971 y_index += dy;
2972 }
2973 }
2974 }
2975
2976 /* case 4b: TRANSPARENCY_PEN_TABLE_RAW */
2977 if (transparency == TRANSPARENCY_PEN_TABLE_RAW)
2978 {
2979 if (pri_buffer)
2980 {
2981 for( y=sy; y<ey; y++ )
2982 {
2983 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
2984 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2985 UINT8 *pri = pri_buffer->line[y];
2986
2987 int x, x_index = x_index_base;
2988 for( x=sx; x<ex; x++ )
2989 {
2990 int c = source[x_index>>16];
2991 if( c != transparent_color )
2992 {
2993 switch(gfx_drawmode_table[c])
2994 {
2995 case DRAWMODE_SOURCE:
2996 if (((1 << (pri[x] & 0x1f)) & pri_mask) == 0)
2997 {
2998 if (pri[x] & 0x80)
2999 dest[x] = palette_shadow_table[color + c];
3000 else
3001 dest[x] = color + c;
3002 }
3003 pri[x] = (pri[x] & 0x7f) | 31;
3004 break;
3005 case DRAWMODE_SHADOW:
3006 if (((1 << pri[x]) & pri_mask) == 0)
3007 dest[x] = palette_shadow_table[dest[x]];
3008 pri[x] |= pdrawgfx_shadow_lowpri ? 0 : 0x80;
3009 break;
3010 }
3011 }
3012 x_index += dx;
3013 }
3014
3015 y_index += dy;
3016 }
3017 }
3018 else
3019 {
3020 for( y=sy; y<ey; y++ )
3021 {
3022 UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
3023 UINT16 *dest = (UINT16 *)dest_bmp->line[y];
3024
3025 int x, x_index = x_index_base;
3026 for( x=sx; x<ex; x++ )
3027 {
3028 int c = source[x_index>>16];
3029 if( c != transparent_color )
3030 {
3031 switch(gfx_drawmode_table[c])
3032 {
3033 case DRAWMODE_SOURCE:
3034 dest[x] = color + c;
3035 break;
3036 case DRAWMODE_SHADOW:
3037 dest[x] = palette_shadow_table[dest[x]];
3038 break;
3039 }
3040 }
3041 x_index += dx;
3042 }