1 #ifndef DECLARE
2 
3 #include "driver.h"
4 
5 /* LBO */
6 #ifdef MSB_FIRST
7 #define BL0 3
8 #define BL1 2
9 #define BL2 1
10 #define BL3 0
11 #define WL0 1
12 #define WL1 0
13 #else
14 #define BL0 0
15 #define BL1 1
16 #define BL2 2
17 #define BL3 3
18 #define WL0 0
19 #define WL1 1
20 #endif
21 
22 
23 UINT8 gfx_drawmode_table[256];
24 plot_pixel_proc plot_pixel;
25 read_pixel_proc read_pixel;
26 plot_box_proc plot_box;
27 
28 static UINT8 is_raw[TRANSPARENCY_MODES];
29 
30 #ifdef ALIGN_INTS /* GSL 980108 read/write nonaligned dword routine for ARM processor etc */
31 	#define write_dword_aligned(address,data) *(UINT32 *)address = data
32 	#ifdef MSB_FIRST
33 		#define write_dword_unaligned(address,data) \
34 			*(address+3) =  data; \
35 			*(address+2) = (data >> 8); \
36 			*(address+1) = (data >> 16); \
37 			*(address)   = (data >> 24)
38 	#else
39 		#define write_dword_unaligned(address,data) \
40 			*(address) =    data; \
41 			*(address+1) = (data >> 8); \
42 			*(address+2) = (data >> 16); \
43 			*(address+3) = (data >> 24)
44 	#endif
45 #else
46 #define write_dword(address,data) *address=data
47 #endif
48 
49 
50 
readbit(const UINT8 * src,int bitnum)51 static INLINE int readbit(const UINT8 *src,int bitnum)
52 {
53 	return (src[bitnum / 8] >> (7 - bitnum % 8)) & 1;
54 }
55 
56 
decodechar(struct GfxElement * gfx,int num,const UINT8 * src,const struct GfxLayout * gl)57 void decodechar(struct GfxElement *gfx,int num,const UINT8 *src,const struct GfxLayout *gl)
58 {
59 	int plane,x,y;
60 	UINT8 *dp;
61 	int offs;
62 
63 
64 	offs = num * gl->charincrement;
65 	dp = gfx->gfxdata + num * gfx->char_modulo;
66 	for (y = 0;y < gfx->height;y++)
67 	{
68 		int yoffs;
69 
70 		yoffs = y;
71 #ifdef PREROTATE_GFX
72 		if (Machine->orientation & ORIENTATION_FLIP_Y)
73 			yoffs = gfx->height-1 - yoffs;
74 #endif
75 
76 		for (x = 0;x < gfx->width;x++)
77 		{
78 			int xoffs;
79 
80 			xoffs = x;
81 #ifdef PREROTATE_GFX
82 			if (Machine->orientation & ORIENTATION_FLIP_X)
83 				xoffs = gfx->width-1 - xoffs;
84 #endif
85 
86 			dp[x] = 0;
87 			if (Machine->orientation & ORIENTATION_SWAP_XY)
88 			{
89 				for (plane = 0;plane < gl->planes;plane++)
90 				{
91 					if (readbit(src,offs + gl->planeoffset[plane] + gl->yoffset[xoffs] + gl->xoffset[yoffs]))
92 						dp[x] |= (1 << (gl->planes-1-plane));
93 				}
94 			}
95 			else
96 			{
97 				for (plane = 0;plane < gl->planes;plane++)
98 				{
99 					if (readbit(src,offs + gl->planeoffset[plane] + gl->yoffset[yoffs] + gl->xoffset[xoffs]))
100 						dp[x] |= (1 << (gl->planes-1-plane));
101 				}
102 			}
103 		}
104 		dp += gfx->line_modulo;
105 	}
106 
107 
108 	if (gfx->pen_usage)
109 	{
110 		/* fill the pen_usage array with info on the used pens */
111 		gfx->pen_usage[num] = 0;
112 
113 		dp = gfx->gfxdata + num * gfx->char_modulo;
114 		for (y = 0;y < gfx->height;y++)
115 		{
116 			for (x = 0;x < gfx->width;x++)
117 			{
118 				gfx->pen_usage[num] |= 1 << dp[x];
119 			}
120 			dp += gfx->line_modulo;
121 		}
122 	}
123 }
124 
125 
decodegfx(const UINT8 * src,const struct GfxLayout * gl)126 struct GfxElement *decodegfx(const UINT8 *src,const struct GfxLayout *gl)
127 {
128 	int c;
129 	struct GfxElement *gfx;
130 
131 
132 	if ((gfx = malloc(sizeof(struct GfxElement))) == 0)
133 		return 0;
134 	memset(gfx,0,sizeof(struct GfxElement));
135 
136 	if (Machine->orientation & ORIENTATION_SWAP_XY)
137 	{
138 		gfx->width = gl->height;
139 		gfx->height = gl->width;
140 	}
141 	else
142 	{
143 		gfx->width = gl->width;
144 		gfx->height = gl->height;
145 	}
146 
147 	gfx->line_modulo = gfx->width;
148 	gfx->char_modulo = gfx->line_modulo * gfx->height;
149 	if ((gfx->gfxdata = (unsigned char *) malloc(gl->total * gfx->char_modulo * sizeof(UINT8))) == 0)
150 	{
151 		free(gfx);
152 		return 0;
153 	}
154 
155 	gfx->total_elements = gl->total;
156 	gfx->color_granularity = 1 << gl->planes;
157 
158 	gfx->pen_usage = 0; /* need to make sure this is NULL if the next test fails) */
159 	if (gfx->color_granularity <= 32)	/* can't handle more than 32 pens */
160 		gfx->pen_usage = (unsigned int *) malloc(gfx->total_elements * sizeof(int));
161 		/* no need to check for failure, the code can work without pen_usage */
162 
163 	for (c = 0;c < gl->total;c++)
164 		decodechar(gfx,c,src,gl);
165 
166 	return gfx;
167 }
168 
169 
freegfx(struct GfxElement * gfx)170 void freegfx(struct GfxElement *gfx)
171 {
172 	if (gfx)
173 	{
174 		free(gfx->pen_usage);
175 		free(gfx->gfxdata);
176 		free(gfx);
177 	}
178 }
179 
180 
181 
182 
blockmove_NtoN_transpen_noremap8(const UINT8 * srcdata,int srcwidth,int srcheight,int srcmodulo,UINT8 * dstdata,int dstmodulo,int transpen)183 static INLINE void blockmove_NtoN_transpen_noremap8(
184 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
185 		UINT8 *dstdata,int dstmodulo,
186 		int transpen)
187 {
188 	UINT8 *end;
189 	int trans4;
190 	UINT32 *sd4;
191 
192 	srcmodulo -= srcwidth;
193 	dstmodulo -= srcwidth;
194 
195 	trans4 = transpen * 0x01010101;
196 
197 	while (srcheight)
198 	{
199 		end = dstdata + srcwidth;
200 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
201 		{
202 			int col;
203 
204 			col = *(srcdata++);
205 			if (col != transpen) *dstdata = col;
206 			dstdata++;
207 		}
208 		sd4 = (UINT32 *)srcdata;
209 
210 #ifdef ALIGN_INTS /* GSL 980108 read/write nonaligned dword routine for ARM processor etc */
211 
212 		if ((long)dstdata & 3)
213 		{
214 			while (dstdata <= end - 4)
215 			{
216 				UINT32 col4;
217 
218 				if ((col4 = *(sd4++)) != trans4)
219 				{
220 					UINT32 xod4;
221 
222 					xod4 = col4 ^ trans4;
223 					if( (xod4&0x000000ff) && (xod4&0x0000ff00) &&
224 						(xod4&0x00ff0000) && (xod4&0xff000000) )
225 					{
226 						write_dword_unaligned(dstdata,col4);
227 					}
228 					else
229 					{
230 						if (xod4 & 0xff000000) dstdata[BL3] = col4 >> 24;
231 						if (xod4 & 0x00ff0000) dstdata[BL2] = col4 >> 16;
232 						if (xod4 & 0x0000ff00) dstdata[BL1] = col4 >>  8;
233 						if (xod4 & 0x000000ff) dstdata[BL0] = col4;
234 					}
235 				}
236 				dstdata += 4;
237 			}
238 		}
239 		else
240 		{
241 			while (dstdata <= end - 4)
242 			{
243 				UINT32 col4;
244 
245 				if ((col4 = *(sd4++)) != trans4)
246 				{
247 					UINT32 xod4;
248 
249 					xod4 = col4 ^ trans4;
250 					if( (xod4&0x000000ff) && (xod4&0x0000ff00) &&
251 						(xod4&0x00ff0000) && (xod4&0xff000000) )
252 					{
253 						write_dword_aligned((UINT32 *)dstdata,col4);
254 					}
255 					else
256 					{
257 						if (xod4 & 0xff000000) dstdata[BL3] = col4 >> 24;
258 						if (xod4 & 0x00ff0000) dstdata[BL2] = col4 >> 16;
259 						if (xod4 & 0x0000ff00) dstdata[BL1] = col4 >>  8;
260 						if (xod4 & 0x000000ff) dstdata[BL0] = col4;
261 					}
262 				}
263 				dstdata += 4;
264 			}
265 		}
266 #else
267 		while (dstdata <= end - 4)
268 		{
269 			UINT32 col4;
270 
271 			if ((col4 = *(sd4++)) != trans4)
272 			{
273 				UINT32 xod4;
274 
275 				xod4 = col4 ^ trans4;
276 				if( (xod4&0x000000ff) && (xod4&0x0000ff00) &&
277 					(xod4&0x00ff0000) && (xod4&0xff000000) )
278 				{
279 					write_dword((UINT32 *)dstdata,col4);
280 				}
281 				else
282 				{
283 					if (xod4 & 0xff000000) dstdata[BL3] = col4 >> 24;
284 					if (xod4 & 0x00ff0000) dstdata[BL2] = col4 >> 16;
285 					if (xod4 & 0x0000ff00) dstdata[BL1] = col4 >>  8;
286 					if (xod4 & 0x000000ff) dstdata[BL0] = col4;
287 				}
288 			}
289 			dstdata += 4;
290 		}
291 #endif
292 		srcdata = (UINT8 *)sd4;
293 		while (dstdata < end)
294 		{
295 			int col;
296 
297 			col = *(srcdata++);
298 			if (col != transpen) *dstdata = col;
299 			dstdata++;
300 		}
301 
302 		srcdata += srcmodulo;
303 		dstdata += dstmodulo;
304 		srcheight--;
305 	}
306 }
307 
blockmove_NtoN_transpen_noremap_flipx8(const UINT8 * srcdata,int srcwidth,int srcheight,int srcmodulo,UINT8 * dstdata,int dstmodulo,int transpen)308 static INLINE void blockmove_NtoN_transpen_noremap_flipx8(
309 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
310 		UINT8 *dstdata,int dstmodulo,
311 		int transpen)
312 {
313 	UINT8 *end;
314 	int trans4;
315 	UINT32 *sd4;
316 
317 	srcmodulo += srcwidth;
318 	dstmodulo -= srcwidth;
319 	//srcdata += srcwidth-1;
320 	srcdata -= 3;
321 
322 	trans4 = transpen * 0x01010101;
323 
324 	while (srcheight)
325 	{
326 		end = dstdata + srcwidth;
327 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
328 		{
329 			int col;
330 
331 			col = srcdata[3];
332 			srcdata--;
333 			if (col != transpen) *dstdata = col;
334 			dstdata++;
335 		}
336 		sd4 = (UINT32 *)srcdata;
337 		while (dstdata <= end - 4)
338 		{
339 			UINT32 col4;
340 
341 			if ((col4 = *(sd4--)) != trans4)
342 			{
343 				UINT32 xod4;
344 
345 				xod4 = col4 ^ trans4;
346 				if (xod4 & 0x000000ff) dstdata[BL3] = col4;
347 				if (xod4 & 0x0000ff00) dstdata[BL2] = col4 >>  8;
348 				if (xod4 & 0x00ff0000) dstdata[BL1] = col4 >> 16;
349 				if (xod4 & 0xff000000) dstdata[BL0] = col4 >> 24;
350 			}
351 			dstdata += 4;
352 		}
353 		srcdata = (UINT8 *)sd4;
354 		while (dstdata < end)
355 		{
356 			int col;
357 
358 			col = srcdata[3];
359 			srcdata--;
360 			if (col != transpen) *dstdata = col;
361 			dstdata++;
362 		}
363 
364 		srcdata += srcmodulo;
365 		dstdata += dstmodulo;
366 		srcheight--;
367 	}
368 }
369 
370 
blockmove_NtoN_transpen_noremap16(const UINT16 * srcdata,int srcwidth,int srcheight,int srcmodulo,UINT16 * dstdata,int dstmodulo,int transpen)371 static INLINE void blockmove_NtoN_transpen_noremap16(
372 		const UINT16 *srcdata,int srcwidth,int srcheight,int srcmodulo,
373 		UINT16 *dstdata,int dstmodulo,
374 		int transpen)
375 {
376 	UINT16 *end;
377 
378 	srcmodulo -= srcwidth;
379 	dstmodulo -= srcwidth;
380 
381 	while (srcheight)
382 	{
383 		end = dstdata + srcwidth;
384 		while (dstdata < end)
385 		{
386 			int col;
387 
388 			col = *(srcdata++);
389 			if (col != transpen) *dstdata = col;
390 			dstdata++;
391 		}
392 
393 		srcdata += srcmodulo;
394 		dstdata += dstmodulo;
395 		srcheight--;
396 	}
397 }
398 
blockmove_NtoN_transpen_noremap_flipx16(const UINT16 * srcdata,int srcwidth,int srcheight,int srcmodulo,UINT16 * dstdata,int dstmodulo,int transpen)399 static INLINE void blockmove_NtoN_transpen_noremap_flipx16(
400 		const UINT16 *srcdata,int srcwidth,int srcheight,int srcmodulo,
401 		UINT16 *dstdata,int dstmodulo,
402 		int transpen)
403 {
404 	UINT16 *end;
405 
406 	srcmodulo += srcwidth;
407 	dstmodulo -= srcwidth;
408 	//srcdata += srcwidth-1;
409 
410 	while (srcheight)
411 	{
412 		end = dstdata + srcwidth;
413 		while (dstdata < end)
414 		{
415 			int col;
416 
417 			col = *(srcdata--);
418 			if (col != transpen) *dstdata = col;
419 			dstdata++;
420 		}
421 
422 		srcdata += srcmodulo;
423 		dstdata += dstmodulo;
424 		srcheight--;
425 	}
426 }
427 
428 
429 #define DATA_TYPE UINT8
430 #define DECLARE(function,args,body) static INLINE void function##8 args body
431 #define BLOCKMOVE(function,flipx,args) \
432 	if (flipx) blockmove_##function##_flipx##8 args ; \
433 	else blockmove_##function##8 args
434 #include "drawgfx.c"
435 #undef DATA_TYPE
436 #undef DECLARE
437 #undef BLOCKMOVE
438 
439 #define DATA_TYPE UINT16
440 #define DECLARE(function,args,body) static INLINE void function##16 args body
441 #define BLOCKMOVE(function,flipx,args) \
442 	if (flipx) blockmove_##function##_flipx##16 args ; \
443 	else blockmove_##function##16 args
444 #include "drawgfx.c"
445 #undef DATA_TYPE
446 #undef DECLARE
447 #undef BLOCKMOVE
448 
449 
450 /***************************************************************************
451 
452   Draw graphic elements in the specified bitmap.
453 
454   transparency == TRANSPARENCY_NONE - no transparency.
455   transparency == TRANSPARENCY_PEN - bits whose _original_ value is == transparent_color
456                                      are transparent. This is the most common kind of
457 									 transparency.
458   transparency == TRANSPARENCY_PENS - as above, but transparent_color is a mask of
459   									 transparent pens.
460   transparency == TRANSPARENCY_COLOR - bits whose _remapped_ palette index (taken from
461                                      Machine->game_colortable) is == transparent_color
462   transparency == TRANSPARENCY_THROUGH - if the _destination_ pixel is == transparent_color,
463                                      the source pixel is drawn over it. This is used by
464 									 e.g. Jr. Pac Man to draw the sprites when the background
465 									 has priority over them.
466 
467   transparency == TRANSPARENCY_PEN_TABLE - the transparency condition is same as TRANSPARENCY_PEN
468 					A special drawing is done according to gfx_drawmode_table[source pixel].
469 					DRAWMODE_NONE      transparent
470 					DRAWMODE_SOURCE    normal, draw source pixel.
471 					DRAWMODE_SHADOW    destination is changed through palette_shadow_table[]
472 
473 ***************************************************************************/
474 
common_drawgfx(struct osd_bitmap * dest,const struct GfxElement * gfx,unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,int transparency,int transparent_color,struct osd_bitmap * pri_buffer,UINT32 pri_mask)475 static INLINE void common_drawgfx(struct osd_bitmap *dest,const struct GfxElement *gfx,
476 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
477 		const struct rectangle *clip,int transparency,int transparent_color,
478 		struct osd_bitmap *pri_buffer,UINT32 pri_mask)
479 {
480 	struct rectangle myclip;
481 
482 	if (!gfx)
483 	{
484 		usrintf_showmessage("drawgfx() gfx == 0");
485 		return;
486 	}
487 	if (!gfx->colortable && !is_raw[transparency])
488 	{
489 		usrintf_showmessage("drawgfx() gfx->colortable == 0");
490 		return;
491 	}
492 
493 	code %= gfx->total_elements;
494 	if (!is_raw[transparency])
495 		color %= gfx->total_colors;
496 
497 	if (gfx->pen_usage && (transparency == TRANSPARENCY_PEN || transparency == TRANSPARENCY_PENS))
498 	{
499 		int transmask = 0;
500 
501 		if (transparency == TRANSPARENCY_PEN)
502 		{
503 			transmask = 1 << transparent_color;
504 		}
505 		else	/* transparency == TRANSPARENCY_PENS */
506 		{
507 			transmask = transparent_color;
508 		}
509 
510 		if ((gfx->pen_usage[code] & ~transmask) == 0)
511 			/* character is totally transparent, no need to draw */
512 			return;
513 		else if ((gfx->pen_usage[code] & transmask) == 0)
514 			/* character is totally opaque, can disable transparency */
515 			transparency = TRANSPARENCY_NONE;
516 	}
517 
518 	if (Machine->orientation & ORIENTATION_SWAP_XY)
519 	{
520 		int temp;
521 
522 		temp = sx;
523 		sx = sy;
524 		sy = temp;
525 
526 		temp = flipx;
527 		flipx = flipy;
528 		flipy = temp;
529 
530 		if (clip)
531 		{
532 			/* clip and myclip might be the same, so we need a temporary storage */
533 			temp = clip->min_x;
534 			myclip.min_x = clip->min_y;
535 			myclip.min_y = temp;
536 			temp = clip->max_x;
537 			myclip.max_x = clip->max_y;
538 			myclip.max_y = temp;
539 			clip = &myclip;
540 		}
541 	}
542 	if (Machine->orientation & ORIENTATION_FLIP_X)
543 	{
544 		sx = dest->width - gfx->width - sx;
545 		if (clip)
546 		{
547 			int temp;
548 
549 
550 			/* clip and myclip might be the same, so we need a temporary storage */
551 			temp = clip->min_x;
552 			myclip.min_x = dest->width-1 - clip->max_x;
553 			myclip.max_x = dest->width-1 - temp;
554 			myclip.min_y = clip->min_y;
555 			myclip.max_y = clip->max_y;
556 			clip = &myclip;
557 		}
558 #ifndef PREROTATE_GFX
559 		flipx = !flipx;
560 #endif
561 	}
562 	if (Machine->orientation & ORIENTATION_FLIP_Y)
563 	{
564 		sy = dest->height - gfx->height - sy;
565 		if (clip)
566 		{
567 			int temp;
568 
569 
570 			myclip.min_x = clip->min_x;
571 			myclip.max_x = clip->max_x;
572 			/* clip and myclip might be the same, so we need a temporary storage */
573 			temp = clip->min_y;
574 			myclip.min_y = dest->height-1 - clip->max_y;
575 			myclip.max_y = dest->height-1 - temp;
576 			clip = &myclip;
577 		}
578 #ifndef PREROTATE_GFX
579 		flipy = !flipy;
580 #endif
581 	}
582 
583 	if (dest->depth != 16)
584 		drawgfx_core8(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,pri_buffer,pri_mask);
585 	else
586 		drawgfx_core16(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,pri_buffer,pri_mask);
587 }
588 
drawgfx(struct osd_bitmap * dest,const struct GfxElement * gfx,unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,int transparency,int transparent_color)589 void drawgfx(struct osd_bitmap *dest,const struct GfxElement *gfx,
590 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
591 		const struct rectangle *clip,int transparency,int transparent_color)
592 {
593 	profiler_mark(PROFILER_DRAWGFX);
594 	common_drawgfx(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,NULL,0);
595 	profiler_mark(PROFILER_END);
596 }
597 
pdrawgfx(struct osd_bitmap * dest,const struct GfxElement * gfx,unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,int transparency,int transparent_color,UINT32 priority_mask)598 void pdrawgfx(struct osd_bitmap *dest,const struct GfxElement *gfx,
599 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
600 		const struct rectangle *clip,int transparency,int transparent_color,UINT32 priority_mask)
601 {
602 	profiler_mark(PROFILER_DRAWGFX);
603 	common_drawgfx(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,priority_bitmap,priority_mask);
604 	profiler_mark(PROFILER_END);
605 }
606 
607 
608 /***************************************************************************
609 
610   Use drawgfx() to copy a bitmap onto another at the given position.
611   This function will very likely change in the future.
612 
613 ***************************************************************************/
copybitmap(struct osd_bitmap * dest,struct osd_bitmap * src,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,int transparency,int transparent_color)614 void copybitmap(struct osd_bitmap *dest,struct osd_bitmap *src,int flipx,int flipy,int sx,int sy,
615 		const struct rectangle *clip,int transparency,int transparent_color)
616 {
617 	/* translate to proper transparency here */
618 	if (transparency == TRANSPARENCY_NONE)
619 		transparency = TRANSPARENCY_NONE_RAW;
620 	else if (transparency == TRANSPARENCY_PEN)
621 		transparency = TRANSPARENCY_PEN_RAW;
622 	else if (transparency == TRANSPARENCY_COLOR)
623 	{
624 		transparent_color = Machine->pens[transparent_color];
625 		transparency = TRANSPARENCY_PEN_RAW;
626 	}
627 	else if (transparency == TRANSPARENCY_THROUGH)
628 		transparency = TRANSPARENCY_THROUGH_RAW;
629 
630 	copybitmap_remap(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
631 }
632 
633 
copybitmap_remap(struct osd_bitmap * dest,struct osd_bitmap * src,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,int transparency,int transparent_color)634 void copybitmap_remap(struct osd_bitmap *dest,struct osd_bitmap *src,int flipx,int flipy,int sx,int sy,
635 		const struct rectangle *clip,int transparency,int transparent_color)
636 {
637 	struct rectangle myclip;
638 
639 
640 	profiler_mark(PROFILER_COPYBITMAP);
641 
642 	if (Machine->orientation & ORIENTATION_SWAP_XY)
643 	{
644 		int temp;
645 
646 		temp = sx;
647 		sx = sy;
648 		sy = temp;
649 
650 		temp = flipx;
651 		flipx = flipy;
652 		flipy = temp;
653 
654 		if (clip)
655 		{
656 			/* clip and myclip might be the same, so we need a temporary storage */
657 			temp = clip->min_x;
658 			myclip.min_x = clip->min_y;
659 			myclip.min_y = temp;
660 			temp = clip->max_x;
661 			myclip.max_x = clip->max_y;
662 			myclip.max_y = temp;
663 			clip = &myclip;
664 		}
665 	}
666 	if (Machine->orientation & ORIENTATION_FLIP_X)
667 	{
668 		sx = dest->width - src->width - sx;
669 		if (clip)
670 		{
671 			int temp;
672 
673 
674 			/* clip and myclip might be the same, so we need a temporary storage */
675 			temp = clip->min_x;
676 			myclip.min_x = dest->width-1 - clip->max_x;
677 			myclip.max_x = dest->width-1 - temp;
678 			myclip.min_y = clip->min_y;
679 			myclip.max_y = clip->max_y;
680 			clip = &myclip;
681 		}
682 	}
683 	if (Machine->orientation & ORIENTATION_FLIP_Y)
684 	{
685 		sy = dest->height - src->height - sy;
686 		if (clip)
687 		{
688 			int temp;
689 
690 
691 			myclip.min_x = clip->min_x;
692 			myclip.max_x = clip->max_x;
693 			/* clip and myclip might be the same, so we need a temporary storage */
694 			temp = clip->min_y;
695 			myclip.min_y = dest->height-1 - clip->max_y;
696 			myclip.max_y = dest->height-1 - temp;
697 			clip = &myclip;
698 		}
699 	}
700 
701 	if (dest->depth != 16)
702 		copybitmap_core8(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
703 	else
704 		copybitmap_core16(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
705 
706 	profiler_mark(PROFILER_END);
707 }
708 
709 
710 
711 /***************************************************************************
712 
713   Copy a bitmap onto another with scroll and wraparound.
714   This function supports multiple independently scrolling rows/columns.
715   "rows" is the number of indepentently scrolling rows. "rowscroll" is an
716   array of integers telling how much to scroll each row. Same thing for
717   "cols" and "colscroll".
718   If the bitmap cannot scroll in one direction, set rows or columns to 0.
719   If the bitmap scrolls as a whole, set rows and/or cols to 1.
720   Bidirectional scrolling is, of course, supported only if the bitmap
721   scrolls as a whole in at least one direction.
722 
723 ***************************************************************************/
copyscrollbitmap(struct osd_bitmap * dest,struct osd_bitmap * src,int rows,const int * rowscroll,int cols,const int * colscroll,const struct rectangle * clip,int transparency,int transparent_color)724 void copyscrollbitmap(struct osd_bitmap *dest,struct osd_bitmap *src,
725 		int rows,const int *rowscroll,int cols,const int *colscroll,
726 		const struct rectangle *clip,int transparency,int transparent_color)
727 {
728 	/* translate to proper transparency here */
729 	if (transparency == TRANSPARENCY_NONE)
730 		transparency = TRANSPARENCY_NONE_RAW;
731 	else if (transparency == TRANSPARENCY_PEN)
732 		transparency = TRANSPARENCY_PEN_RAW;
733 	else if (transparency == TRANSPARENCY_COLOR)
734 	{
735 		transparent_color = Machine->pens[transparent_color];
736 		transparency = TRANSPARENCY_PEN_RAW;
737 	}
738 	else if (transparency == TRANSPARENCY_THROUGH)
739 		transparency = TRANSPARENCY_THROUGH_RAW;
740 
741 	copyscrollbitmap_remap(dest,src,rows,rowscroll,cols,colscroll,clip,transparency,transparent_color);
742 }
743 
copyscrollbitmap_remap(struct osd_bitmap * dest,struct osd_bitmap * src,int rows,const int * rowscroll,int cols,const int * colscroll,const struct rectangle * clip,int transparency,int transparent_color)744 void copyscrollbitmap_remap(struct osd_bitmap *dest,struct osd_bitmap *src,
745 		int rows,const int *rowscroll,int cols,const int *colscroll,
746 		const struct rectangle *clip,int transparency,int transparent_color)
747 {
748 	int srcwidth,srcheight,destwidth,destheight;
749 
750 
751 	if (rows == 0 && cols == 0)
752 	{
753 		copybitmap(dest,src,0,0,0,0,clip,transparency,transparent_color);
754 		return;
755 	}
756 
757 	profiler_mark(PROFILER_COPYBITMAP);
758 
759 	if (Machine->orientation & ORIENTATION_SWAP_XY)
760 	{
761 		srcwidth = src->height;
762 		srcheight = src->width;
763 		destwidth = dest->height;
764 		destheight = dest->width;
765 	}
766 	else
767 	{
768 		srcwidth = src->width;
769 		srcheight = src->height;
770 		destwidth = dest->width;
771 		destheight = dest->height;
772 	}
773 
774 	if (rows == 0)
775 	{
776 		/* scrolling columns */
777 		int col,colwidth;
778 		struct rectangle myclip;
779 
780 
781 		colwidth = srcwidth / cols;
782 
783 		myclip.min_y = clip->min_y;
784 		myclip.max_y = clip->max_y;
785 
786 		col = 0;
787 		while (col < cols)
788 		{
789 			int cons,scroll;
790 
791 
792 			/* count consecutive columns scrolled by the same amount */
793 			scroll = colscroll[col];
794 			cons = 1;
795 			while (col + cons < cols &&	colscroll[col + cons] == scroll)
796 				cons++;
797 
798 			if (scroll < 0) scroll = srcheight - (-scroll) % srcheight;
799 			else scroll %= srcheight;
800 
801 			myclip.min_x = col * colwidth;
802 			if (myclip.min_x < clip->min_x) myclip.min_x = clip->min_x;
803 			myclip.max_x = (col + cons) * colwidth - 1;
804 			if (myclip.max_x > clip->max_x) myclip.max_x = clip->max_x;
805 
806 			copybitmap(dest,src,0,0,0,scroll,&myclip,transparency,transparent_color);
807 			copybitmap(dest,src,0,0,0,scroll - srcheight,&myclip,transparency,transparent_color);
808 
809 			col += cons;
810 		}
811 	}
812 	else if (cols == 0)
813 	{
814 		/* scrolling rows */
815 		int row,rowheight;
816 		struct rectangle myclip;
817 
818 
819 		rowheight = srcheight / rows;
820 
821 		myclip.min_x = clip->min_x;
822 		myclip.max_x = clip->max_x;
823 
824 		row = 0;
825 		while (row < rows)
826 		{
827 			int cons,scroll;
828 
829 
830 			/* count consecutive rows scrolled by the same amount */
831 			scroll = rowscroll[row];
832 			cons = 1;
833 			while (row + cons < rows &&	rowscroll[row + cons] == scroll)
834 				cons++;
835 
836 			if (scroll < 0) scroll = srcwidth - (-scroll) % srcwidth;
837 			else scroll %= srcwidth;
838 
839 			myclip.min_y = row * rowheight;
840 			if (myclip.min_y < clip->min_y) myclip.min_y = clip->min_y;
841 			myclip.max_y = (row + cons) * rowheight - 1;
842 			if (myclip.max_y > clip->max_y) myclip.max_y = clip->max_y;
843 
844 			copybitmap(dest,src,0,0,scroll,0,&myclip,transparency,transparent_color);
845 			copybitmap(dest,src,0,0,scroll - srcwidth,0,&myclip,transparency,transparent_color);
846 
847 			row += cons;
848 		}
849 	}
850 	else if (rows == 1 && cols == 1)
851 	{
852 		/* XY scrolling playfield */
853 		int scrollx,scrolly,sx,sy;
854 
855 
856 		if (rowscroll[0] < 0) scrollx = srcwidth - (-rowscroll[0]) % srcwidth;
857 		else scrollx = rowscroll[0] % srcwidth;
858 
859 		if (colscroll[0] < 0) scrolly = srcheight - (-colscroll[0]) % srcheight;
860 		else scrolly = colscroll[0] % srcheight;
861 
862 		for (sx = scrollx - srcwidth;sx < destwidth;sx += srcwidth)
863 			for (sy = scrolly - srcheight;sy < destheight;sy += srcheight)
864 				copybitmap(dest,src,0,0,sx,sy,clip,transparency,transparent_color);
865 	}
866 	else if (rows == 1)
867 	{
868 		/* scrolling columns + horizontal scroll */
869 		int col,colwidth;
870 		int scrollx;
871 		struct rectangle myclip;
872 
873 
874 		if (rowscroll[0] < 0) scrollx = srcwidth - (-rowscroll[0]) % srcwidth;
875 		else scrollx = rowscroll[0] % srcwidth;
876 
877 		colwidth = srcwidth / cols;
878 
879 		myclip.min_y = clip->min_y;
880 		myclip.max_y = clip->max_y;
881 
882 		col = 0;
883 		while (col < cols)
884 		{
885 			int cons,scroll;
886 
887 
888 			/* count consecutive columns scrolled by the same amount */
889 			scroll = colscroll[col];
890 			cons = 1;
891 			while (col + cons < cols &&	colscroll[col + cons] == scroll)
892 				cons++;
893 
894 			if (scroll < 0) scroll = srcheight - (-scroll) % srcheight;
895 			else scroll %= srcheight;
896 
897 			myclip.min_x = col * colwidth + scrollx;
898 			if (myclip.min_x < clip->min_x) myclip.min_x = clip->min_x;
899 			myclip.max_x = (col + cons) * colwidth - 1 + scrollx;
900 			if (myclip.max_x > clip->max_x) myclip.max_x = clip->max_x;
901 
902 			copybitmap(dest,src,0,0,scrollx,scroll,&myclip,transparency,transparent_color);
903 			copybitmap(dest,src,0,0,scrollx,scroll - srcheight,&myclip,transparency,transparent_color);
904 
905 			myclip.min_x = col * colwidth + scrollx - srcwidth;
906 			if (myclip.min_x < clip->min_x) myclip.min_x = clip->min_x;
907 			myclip.max_x = (col + cons) * colwidth - 1 + scrollx - srcwidth;
908 			if (myclip.max_x > clip->max_x) myclip.max_x = clip->max_x;
909 
910 			copybitmap(dest,src,0,0,scrollx - srcwidth,scroll,&myclip,transparency,transparent_color);
911 			copybitmap(dest,src,0,0,scrollx - srcwidth,scroll - srcheight,&myclip,transparency,transparent_color);
912 
913 			col += cons;
914 		}
915 	}
916 	else if (cols == 1)
917 	{
918 		/* scrolling rows + vertical scroll */
919 		int row,rowheight;
920 		int scrolly;
921 		struct rectangle myclip;
922 
923 
924 		if (colscroll[0] < 0) scrolly = srcheight - (-colscroll[0]) % srcheight;
925 		else scrolly = colscroll[0] % srcheight;
926 
927 		rowheight = srcheight / rows;
928 
929 		myclip.min_x = clip->min_x;
930 		myclip.max_x = clip->max_x;
931 
932 		row = 0;
933 		while (row < rows)
934 		{
935 			int cons,scroll;
936 
937 
938 			/* count consecutive rows scrolled by the same amount */
939 			scroll = rowscroll[row];
940 			cons = 1;
941 			while (row + cons < rows &&	rowscroll[row + cons] == scroll)
942 				cons++;
943 
944 			if (scroll < 0) scroll = srcwidth - (-scroll) % srcwidth;
945 			else scroll %= srcwidth;
946 
947 			myclip.min_y = row * rowheight + scrolly;
948 			if (myclip.min_y < clip->min_y) myclip.min_y = clip->min_y;
949 			myclip.max_y = (row + cons) * rowheight - 1 + scrolly;
950 			if (myclip.max_y > clip->max_y) myclip.max_y = clip->max_y;
951 
952 			copybitmap(dest,src,0,0,scroll,scrolly,&myclip,transparency,transparent_color);
953 			copybitmap(dest,src,0,0,scroll - srcwidth,scrolly,&myclip,transparency,transparent_color);
954 
955 			myclip.min_y = row * rowheight + scrolly - srcheight;
956 			if (myclip.min_y < clip->min_y) myclip.min_y = clip->min_y;
957 			myclip.max_y = (row + cons) * rowheight - 1 + scrolly - srcheight;
958 			if (myclip.max_y > clip->max_y) myclip.max_y = clip->max_y;
959 
960 			copybitmap(dest,src,0,0,scroll,scrolly - srcheight,&myclip,transparency,transparent_color);
961 			copybitmap(dest,src,0,0,scroll - srcwidth,scrolly - srcheight,&myclip,transparency,transparent_color);
962 
963 			row += cons;
964 		}
965 	}
966 
967 	profiler_mark(PROFILER_END);
968 }
969 
970 
971 /* notes:
972    - startx and starty MUST be UINT32 for calculations to work correctly
973    - srcbitmap->width and height are assumed to be a power of 2 to speed up wraparound
974    */
copyrozbitmap(struct osd_bitmap * dest,struct osd_bitmap * src,UINT32 startx,UINT32 starty,int incxx,int incxy,int incyx,int incyy,int wraparound,const struct rectangle * clip,int transparency,int transparent_color,UINT32 priority)975 void copyrozbitmap(struct osd_bitmap *dest,struct osd_bitmap *src,
976 		UINT32 startx,UINT32 starty,int incxx,int incxy,int incyx,int incyy,int wraparound,
977 		const struct rectangle *clip,int transparency,int transparent_color,UINT32 priority)
978 {
979 	profiler_mark(PROFILER_COPYBITMAP);
980 
981 	/* cheat, the core doesn't support TRANSPARENCY_NONE yet */
982 	if (transparency == TRANSPARENCY_NONE)
983 	{
984 		transparency = TRANSPARENCY_PEN;
985 		transparent_color = -1;
986 	}
987 
988 	/* if necessary, remap the transparent color */
989 	if (transparency == TRANSPARENCY_COLOR)
990 	{
991 		transparency = TRANSPARENCY_PEN;
992 		transparent_color = Machine->pens[transparent_color];
993 	}
994 
995 	if (transparency != TRANSPARENCY_PEN)
996 	{
997 		usrintf_showmessage("copyrozbitmap unsupported trans %02x",transparency);
998 		return;
999 	}
1000 
1001 	if (dest->depth != 16)
1002 		copyrozbitmap_core8(dest,src,startx,starty,incxx,incxy,incyx,incyy,wraparound,clip,transparency,transparent_color,priority);
1003 	else
1004 		copyrozbitmap_core16(dest,src,startx,starty,incxx,incxy,incyx,incyy,wraparound,clip,transparency,transparent_color,priority);
1005 
1006 	profiler_mark(PROFILER_END);
1007 }
1008 
1009 
1010 
1011 /* fill a bitmap using the specified pen */
fillbitmap(struct osd_bitmap * dest,int pen,const struct rectangle * clip)1012 void fillbitmap(struct osd_bitmap *dest,int pen,const struct rectangle *clip)
1013 {
1014 	int sx,sy,ex,ey,y;
1015 	struct rectangle myclip;
1016 
1017 
1018 	if (Machine->orientation & ORIENTATION_SWAP_XY)
1019 	{
1020 		if (clip)
1021 		{
1022 			myclip.min_x = clip->min_y;
1023 			myclip.max_x = clip->max_y;
1024 			myclip.min_y = clip->min_x;
1025 			myclip.max_y = clip->max_x;
1026 			clip = &myclip;
1027 		}
1028 	}
1029 	if (Machine->orientation & ORIENTATION_FLIP_X)
1030 	{
1031 		if (clip)
1032 		{
1033 			int temp;
1034 
1035 
1036 			temp = clip->min_x;
1037 			myclip.min_x = dest->width-1 - clip->max_x;
1038 			myclip.max_x = dest->width-1 - temp;
1039 			myclip.min_y = clip->min_y;
1040 			myclip.max_y = clip->max_y;
1041 			clip = &myclip;
1042 		}
1043 	}
1044 	if (Machine->orientation & ORIENTATION_FLIP_Y)
1045 	{
1046 		if (clip)
1047 		{
1048 			int temp;
1049 
1050 
1051 			myclip.min_x = clip->min_x;
1052 			myclip.max_x = clip->max_x;
1053 			temp = clip->min_y;
1054 			myclip.min_y = dest->height-1 - clip->max_y;
1055 			myclip.max_y = dest->height-1 - temp;
1056 			clip = &myclip;
1057 		}
1058 	}
1059 
1060 
1061 	sx = 0;
1062 	ex = dest->width - 1;
1063 	sy = 0;
1064 	ey = dest->height - 1;
1065 
1066 	if (clip && sx < clip->min_x) sx = clip->min_x;
1067 	if (clip && ex > clip->max_x) ex = clip->max_x;
1068 	if (sx > ex) return;
1069 	if (clip && sy < clip->min_y) sy = clip->min_y;
1070 	if (clip && ey > clip->max_y) ey = clip->max_y;
1071 	if (sy > ey) return;
1072 
1073 	osd_mark_dirty (sx,sy,ex,ey,0);	/* ASG 971011 */
1074 
1075 	/* ASG 980211 */
1076 	if (dest->depth == 16)
1077 	{
1078 		if ((pen >> 8) == (pen & 0xff))
1079 		{
1080 			for (y = sy;y <= ey;y++)
1081 				memset(&dest->line[y][sx*2],pen&0xff,(ex-sx+1)*2);
1082 		}
1083 		else
1084 		{
1085 			UINT16 *sp = (UINT16 *)dest->line[sy];
1086 			int x;
1087 
1088 			for (x = sx;x <= ex;x++)
1089 				sp[x] = pen;
1090 			sp+=sx;
1091 			for (y = sy+1;y <= ey;y++)
1092 				memcpy(&dest->line[y][sx*2],sp,(ex-sx+1)*2);
1093 		}
1094 	}
1095 	else
1096 	{
1097 		for (y = sy;y <= ey;y++)
1098 			memset(&dest->line[y][sx],pen,ex-sx+1);
1099 	}
1100 }
1101 
1102 
common_drawgfxzoom(struct osd_bitmap * dest_bmp,const struct GfxElement * gfx,unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,int transparency,int transparent_color,int scalex,int scaley,struct osd_bitmap * pri_buffer,UINT32 pri_mask)1103 static INLINE void common_drawgfxzoom( struct osd_bitmap *dest_bmp,const struct GfxElement *gfx,
1104 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
1105 		const struct rectangle *clip,int transparency,int transparent_color,
1106 		int scalex, int scaley,struct osd_bitmap *pri_buffer,UINT32 pri_mask)
1107 {
1108 	struct rectangle myclip;
1109 
1110 
1111 	if (!scalex || !scaley) return;
1112 
1113 	if (scalex == 0x10000 && scaley == 0x10000)
1114 	{
1115 		common_drawgfx(dest_bmp,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,pri_buffer,pri_mask);
1116 		return;
1117 	}
1118 
1119 
1120 	pri_mask |= (1<<31);
1121 
1122 	if (transparency != TRANSPARENCY_PEN && transparency != TRANSPARENCY_PEN_RAW
1123 			&& transparency != TRANSPARENCY_PENS && transparency != TRANSPARENCY_COLOR
1124 			&& transparency != TRANSPARENCY_PEN_TABLE && transparency != TRANSPARENCY_PEN_TABLE_RAW)
1125 	{
1126 		usrintf_showmessage("drawgfxzoom unsupported trans %02x",transparency);
1127 		return;
1128 	}
1129 
1130 	if (transparency == TRANSPARENCY_COLOR)
1131 		transparent_color = Machine->pens[transparent_color];
1132 
1133 
1134 	/*
1135 	scalex and scaley are 16.16 fixed point numbers
1136 	1<<15 : shrink to 50%
1137 	1<<16 : uniform scale
1138 	1<<17 : double to 200%
1139 	*/
1140 
1141 
1142 	if (Machine->orientation & ORIENTATION_SWAP_XY)
1143 	{
1144 		int temp;
1145 
1146 		temp = sx;
1147 		sx = sy;
1148 		sy = temp;
1149 
1150 		temp = flipx;
1151 		flipx = flipy;
1152 		flipy = temp;
1153 
1154 		temp = scalex;
1155 		scalex = scaley;
1156 		scaley = temp;
1157 
1158 		if (clip)
1159 		{
1160 			/* clip and myclip might be the same, so we need a temporary storage */
1161 			temp = clip->min_x;
1162 			myclip.min_x = clip->min_y;
1163 			myclip.min_y = temp;
1164 			temp = clip->max_x;
1165 			myclip.max_x = clip->max_y;
1166 			myclip.max_y = temp;
1167 			clip = &myclip;
1168 		}
1169 	}
1170 	if (Machine->orientation & ORIENTATION_FLIP_X)
1171 	{
1172 		sx = dest_bmp->width - ((gfx->width * scalex + 0x7fff) >> 16) - sx;
1173 		if (clip)
1174 		{
1175 			int temp;
1176 
1177 
1178 			/* clip and myclip might be the same, so we need a temporary storage */
1179 			temp = clip->min_x;
1180 			myclip.min_x = dest_bmp->width-1 - clip->max_x;
1181 			myclip.max_x = dest_bmp->width-1 - temp;
1182 			myclip.min_y = clip->min_y;
1183 			myclip.max_y = clip->max_y;
1184 			clip = &myclip;
1185 		}
1186 #ifndef PREROTATE_GFX
1187 		flipx = !flipx;
1188 #endif
1189 	}
1190 	if (Machine->orientation & ORIENTATION_FLIP_Y)
1191 	{
1192 		sy = dest_bmp->height - ((gfx->height * scaley + 0x7fff) >> 16) - sy;
1193 		if (clip)
1194 		{
1195 			int temp;
1196 
1197 
1198 			myclip.min_x = clip->min_x;
1199 			myclip.max_x = clip->max_x;
1200 			/* clip and myclip might be the same, so we need a temporary storage */
1201 			temp = clip->min_y;
1202 			myclip.min_y = dest_bmp->height-1 - clip->max_y;
1203 			myclip.max_y = dest_bmp->height-1 - temp;
1204 			clip = &myclip;
1205 		}
1206 #ifndef PREROTATE_GFX
1207 		flipy = !flipy;
1208 #endif
1209 	}
1210 
1211 	/* KW 991012 -- Added code to force clip to bitmap boundary */
1212 	if(clip)
1213 	{
1214 		myclip.min_x = clip->min_x;
1215 		myclip.max_x = clip->max_x;
1216 		myclip.min_y = clip->min_y;
1217 		myclip.max_y = clip->max_y;
1218 
1219 		if (myclip.min_x < 0) myclip.min_x = 0;
1220 		if (myclip.max_x >= dest_bmp->width) myclip.max_x = dest_bmp->width-1;
1221 		if (myclip.min_y < 0) myclip.min_y = 0;
1222 		if (myclip.max_y >= dest_bmp->height) myclip.max_y = dest_bmp->height-1;
1223 
1224 		clip=&myclip;
1225 	}
1226 
1227 
1228 	/* ASG 980209 -- added 16-bit version */
1229 	if (dest_bmp->depth != 16)
1230 	{
1231 		if( gfx && gfx->colortable )
1232 		{
1233 			const UINT16 *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
1234 			int source_base = (code % gfx->total_elements) * gfx->height;
1235 
1236 			int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
1237 			int sprite_screen_width = (scalex*gfx->width+0x8000)>>16;
1238 
1239 			/* compute sprite increment per screen pixel */
1240 			int dx = (gfx->width<<16)/sprite_screen_width;
1241 			int dy = (gfx->height<<16)/sprite_screen_height;
1242 
1243 			int ex = sx+sprite_screen_width;
1244 			int ey = sy+sprite_screen_height;
1245 
1246 			int x_index_base;
1247 			int y_index;
1248 
1249 			if( flipx )
1250 			{
1251 				x_index_base = (sprite_screen_width-1)*dx;
1252 				dx = -dx;
1253 			}
1254 			else
1255 			{
1256 				x_index_base = 0;
1257 			}
1258 
1259 			if( flipy )
1260 			{
1261 				y_index = (sprite_screen_height-1)*dy;
1262 				dy = -dy;
1263 			}
1264 			else
1265 			{
1266 				y_index = 0;
1267 			}
1268 
1269 			if( clip )
1270 			{
1271 				if( sx < clip->min_x)
1272 				{ /* clip left */
1273 					int pixels = clip->min_x-sx;
1274 					sx += pixels;
1275 					x_index_base += pixels*dx;
1276 				}
1277 				if( sy < clip->min_y )
1278 				{ /* clip top */
1279 					int pixels = clip->min_y-sy;
1280 					sy += pixels;
1281 					y_index += pixels*dy;
1282 				}
1283 				/* NS 980211 - fixed incorrect clipping */
1284 				if( ex > clip->max_x+1 )
1285 				{ /* clip right */
1286 					int pixels = ex-clip->max_x-1;
1287 					ex -= pixels;
1288 				}
1289 				if( ey > clip->max_y+1 )
1290 				{ /* clip bottom */
1291 					int pixels = ey-clip->max_y-1;
1292 					ey -= pixels;
1293 				}
1294 			}
1295 
1296 			if( ex>sx )
1297 			{ /* skip if inner loop doesn't draw anything */
1298 				int y;
1299 
1300 				/* case 1: TRANSPARENCY_PEN */
1301 				if (transparency == TRANSPARENCY_PEN)
1302 				{
1303 					if (pri_buffer)
1304 					{
1305 						for( y=sy; y<ey; y++ )
1306 						{
1307 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1308 							UINT8 *dest = dest_bmp->line[y];
1309 							UINT8 *pri = pri_buffer->line[y];
1310 
1311 							int x, x_index = x_index_base;
1312 							for( x=sx; x<ex; x++ )
1313 							{
1314 								int c = source[x_index>>16];
1315 								if( c != transparent_color )
1316 								{
1317 									if (((1 << pri[x]) & pri_mask) == 0)
1318 										dest[x] = pal[c];
1319 									pri[x] = 31;
1320 								}
1321 								x_index += dx;
1322 							}
1323 
1324 							y_index += dy;
1325 						}
1326 					}
1327 					else
1328 					{
1329 						for( y=sy; y<ey; y++ )
1330 						{
1331 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1332 							UINT8 *dest = dest_bmp->line[y];
1333 
1334 							int x, x_index = x_index_base;
1335 							for( x=sx; x<ex; x++ )
1336 							{
1337 								int c = source[x_index>>16];
1338 								if( c != transparent_color ) dest[x] = pal[c];
1339 								x_index += dx;
1340 							}
1341 
1342 							y_index += dy;
1343 						}
1344 					}
1345 				}
1346 
1347 				/* case 1b: TRANSPARENCY_PEN_RAW */
1348 				if (transparency == TRANSPARENCY_PEN_RAW)
1349 				{
1350 					if (pri_buffer)
1351 					{
1352 						for( y=sy; y<ey; y++ )
1353 						{
1354 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1355 							UINT8 *dest = dest_bmp->line[y];
1356 							UINT8 *pri = pri_buffer->line[y];
1357 
1358 							int x, x_index = x_index_base;
1359 							for( x=sx; x<ex; x++ )
1360 							{
1361 								int c = source[x_index>>16];
1362 								if( c != transparent_color )
1363 								{
1364 									if (((1 << pri[x]) & pri_mask) == 0)
1365 										dest[x] = color + c;
1366 									pri[x] = 31;
1367 								}
1368 								x_index += dx;
1369 							}
1370 
1371 							y_index += dy;
1372 						}
1373 					}
1374 					else
1375 					{
1376 						for( y=sy; y<ey; y++ )
1377 						{
1378 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1379 							UINT8 *dest = dest_bmp->line[y];
1380 
1381 							int x, x_index = x_index_base;
1382 							for( x=sx; x<ex; x++ )
1383 							{
1384 								int c = source[x_index>>16];
1385 								if( c != transparent_color ) dest[x] = color + c;
1386 								x_index += dx;
1387 							}
1388 
1389 							y_index += dy;
1390 						}
1391 					}
1392 				}
1393 
1394 				/* case 2: TRANSPARENCY_PENS */
1395 				if (transparency == TRANSPARENCY_PENS)
1396 				{
1397 					if (pri_buffer)
1398 					{
1399 						for( y=sy; y<ey; y++ )
1400 						{
1401 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1402 							UINT8 *dest = dest_bmp->line[y];
1403 							UINT8 *pri = pri_buffer->line[y];
1404 
1405 							int x, x_index = x_index_base;
1406 							for( x=sx; x<ex; x++ )
1407 							{
1408 								int c = source[x_index>>16];
1409 								if (((1 << c) & transparent_color) == 0)
1410 								{
1411 									if (((1 << pri[x]) & pri_mask) == 0)
1412 										dest[x] = pal[c];
1413 									pri[x] = 31;
1414 								}
1415 								x_index += dx;
1416 							}
1417 
1418 							y_index += dy;
1419 						}
1420 					}
1421 					else
1422 					{
1423 						for( y=sy; y<ey; y++ )
1424 						{
1425 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1426 							UINT8 *dest = dest_bmp->line[y];
1427 
1428 							int x, x_index = x_index_base;
1429 							for( x=sx; x<ex; x++ )
1430 							{
1431 								int c = source[x_index>>16];
1432 								if (((1 << c) & transparent_color) == 0)
1433 									dest[x] = pal[c];
1434 								x_index += dx;
1435 							}
1436 
1437 							y_index += dy;
1438 						}
1439 					}
1440 				}
1441 
1442 				/* case 3: TRANSPARENCY_COLOR */
1443 				else if (transparency == TRANSPARENCY_COLOR)
1444 				{
1445 					if (pri_buffer)
1446 					{
1447 						for( y=sy; y<ey; y++ )
1448 						{
1449 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1450 							UINT8 *dest = dest_bmp->line[y];
1451 							UINT8 *pri = pri_buffer->line[y];
1452 
1453 							int x, x_index = x_index_base;
1454 							for( x=sx; x<ex; x++ )
1455 							{
1456 								int c = pal[source[x_index>>16]];
1457 								if( c != transparent_color )
1458 								{
1459 									if (((1 << pri[x]) & pri_mask) == 0)
1460 										dest[x] = c;
1461 									pri[x] = 31;
1462 								}
1463 								x_index += dx;
1464 							}
1465 
1466 							y_index += dy;
1467 						}
1468 					}
1469 					else
1470 					{
1471 						for( y=sy; y<ey; y++ )
1472 						{
1473 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1474 							UINT8 *dest = dest_bmp->line[y];
1475 
1476 							int x, x_index = x_index_base;
1477 							for( x=sx; x<ex; x++ )
1478 							{
1479 								int c = pal[source[x_index>>16]];
1480 								if( c != transparent_color ) dest[x] = c;
1481 								x_index += dx;
1482 							}
1483 
1484 							y_index += dy;
1485 						}
1486 					}
1487 				}
1488 
1489 				/* case 4: TRANSPARENCY_PEN_TABLE */
1490 				if (transparency == TRANSPARENCY_PEN_TABLE)
1491 				{
1492 					if (pri_buffer)
1493 					{
1494 						for( y=sy; y<ey; y++ )
1495 						{
1496 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1497 							UINT8 *dest = dest_bmp->line[y];
1498 							UINT8 *pri = pri_buffer->line[y];
1499 
1500 							int x, x_index = x_index_base;
1501 							for( x=sx; x<ex; x++ )
1502 							{
1503 								int c = source[x_index>>16];
1504 								if( c != transparent_color )
1505 								{
1506 									if (((1 << pri[x]) & pri_mask) == 0)
1507 									{
1508 										switch(gfx_drawmode_table[c])
1509 										{
1510 										case DRAWMODE_SOURCE:
1511 											dest[x] = pal[c];
1512 											break;
1513 										case DRAWMODE_SHADOW:
1514 											dest[x] = palette_shadow_table[dest[x]];
1515 											break;
1516 										}
1517 									}
1518 									pri[x] = 31;
1519 								}
1520 								x_index += dx;
1521 							}
1522 
1523 							y_index += dy;
1524 						}
1525 					}
1526 					else
1527 					{
1528 						for( y=sy; y<ey; y++ )
1529 						{
1530 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1531 							UINT8 *dest = dest_bmp->line[y];
1532 
1533 							int x, x_index = x_index_base;
1534 							for( x=sx; x<ex; x++ )
1535 							{
1536 								int c = source[x_index>>16];
1537 								if( c != transparent_color )
1538 								{
1539 									switch(gfx_drawmode_table[c])
1540 									{
1541 									case DRAWMODE_SOURCE:
1542 										dest[x] = pal[c];
1543 										break;
1544 									case DRAWMODE_SHADOW:
1545 										dest[x] = palette_shadow_table[dest[x]];
1546 										break;
1547 									}
1548 								}
1549 								x_index += dx;
1550 							}
1551 
1552 							y_index += dy;
1553 						}
1554 					}
1555 				}
1556 
1557 				/* case 4b: TRANSPARENCY_PEN_TABLE_RAW */
1558 				if (transparency == TRANSPARENCY_PEN_TABLE_RAW)
1559 				{
1560 					if (pri_buffer)
1561 					{
1562 						for( y=sy; y<ey; y++ )
1563 						{
1564 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1565 							UINT8 *dest = dest_bmp->line[y];
1566 							UINT8 *pri = pri_buffer->line[y];
1567 
1568 							int x, x_index = x_index_base;
1569 							for( x=sx; x<ex; x++ )
1570 							{
1571 								int c = source[x_index>>16];
1572 								if( c != transparent_color )
1573 								{
1574 									if (((1 << pri[x]) & pri_mask) == 0)
1575 									{
1576 										switch(gfx_drawmode_table[c])
1577 										{
1578 										case DRAWMODE_SOURCE:
1579 											dest[x] = color + c;
1580 											break;
1581 										case DRAWMODE_SHADOW:
1582 											dest[x] = palette_shadow_table[dest[x]];
1583 											break;
1584 										}
1585 									}
1586 									pri[x] = 31;
1587 								}
1588 								x_index += dx;
1589 							}
1590 
1591 							y_index += dy;
1592 						}
1593 					}
1594 					else
1595 					{
1596 						for( y=sy; y<ey; y++ )
1597 						{
1598 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1599 							UINT8 *dest = dest_bmp->line[y];
1600 
1601 							int x, x_index = x_index_base;
1602 							for( x=sx; x<ex; x++ )
1603 							{
1604 								int c = source[x_index>>16];
1605 								if( c != transparent_color )
1606 								{
1607 									switch(gfx_drawmode_table[c])
1608 									{
1609 									case DRAWMODE_SOURCE:
1610 										dest[x] = color + c;
1611 										break;
1612 									case DRAWMODE_SHADOW:
1613 										dest[x] = palette_shadow_table[dest[x]];
1614 										break;
1615 									}
1616 								}
1617 								x_index += dx;
1618 							}
1619 
1620 							y_index += dy;
1621 						}
1622 					}
1623 				}
1624 			}
1625 		}
1626 	}
1627 
1628 	/* ASG 980209 -- new 16-bit part */
1629 	else
1630 	{
1631 		if( gfx && gfx->colortable )
1632 		{
1633 			const UINT16 *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
1634 			int source_base = (code % gfx->total_elements) * gfx->height;
1635 
1636 			int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
1637 			int sprite_screen_width = (scalex*gfx->width+0x8000)>>16;
1638 
1639 			/* compute sprite increment per screen pixel */
1640 			int dx = (gfx->width<<16)/sprite_screen_width;
1641 			int dy = (gfx->height<<16)/sprite_screen_height;
1642 
1643 			int ex = sx+sprite_screen_width;
1644 			int ey = sy+sprite_screen_height;
1645 
1646 			int x_index_base;
1647 			int y_index;
1648 
1649 			if( flipx )
1650 			{
1651 				x_index_base = (sprite_screen_width-1)*dx;
1652 				dx = -dx;
1653 			}
1654 			else
1655 			{
1656 				x_index_base = 0;
1657 			}
1658 
1659 			if( flipy )
1660 			{
1661 				y_index = (sprite_screen_height-1)*dy;
1662 				dy = -dy;
1663 			}
1664 			else
1665 			{
1666 				y_index = 0;
1667 			}
1668 
1669 			if( clip )
1670 			{
1671 				if( sx < clip->min_x)
1672 				{ /* clip left */
1673 					int pixels = clip->min_x-sx;
1674 					sx += pixels;
1675 					x_index_base += pixels*dx;
1676 				}
1677 				if( sy < clip->min_y )
1678 				{ /* clip top */
1679 					int pixels = clip->min_y-sy;
1680 					sy += pixels;
1681 					y_index += pixels*dy;
1682 				}
1683 				/* NS 980211 - fixed incorrect clipping */
1684 				if( ex > clip->max_x+1 )
1685 				{ /* clip right */
1686 					int pixels = ex-clip->max_x-1;
1687 					ex -= pixels;
1688 				}
1689 				if( ey > clip->max_y+1 )
1690 				{ /* clip bottom */
1691 					int pixels = ey-clip->max_y-1;
1692 					ey -= pixels;
1693 				}
1694 			}
1695 
1696 			if( ex>sx )
1697 			{ /* skip if inner loop doesn't draw anything */
1698 				int y;
1699 
1700 				/* case 1: TRANSPARENCY_PEN */
1701 				if (transparency == TRANSPARENCY_PEN)
1702 				{
1703 					if (pri_buffer)
1704 					{
1705 						for( y=sy; y<ey; y++ )
1706 						{
1707 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1708 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1709 							UINT8 *pri = pri_buffer->line[y];
1710 
1711 							int x, x_index = x_index_base;
1712 							for( x=sx; x<ex; x++ )
1713 							{
1714 								int c = source[x_index>>16];
1715 								if( c != transparent_color )
1716 								{
1717 									if (((1 << pri[x]) & pri_mask) == 0)
1718 										dest[x] = pal[c];
1719 									pri[x] = 31;
1720 								}
1721 								x_index += dx;
1722 							}
1723 
1724 							y_index += dy;
1725 						}
1726 					}
1727 					else
1728 					{
1729 						for( y=sy; y<ey; y++ )
1730 						{
1731 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1732 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1733 
1734 							int x, x_index = x_index_base;
1735 							for( x=sx; x<ex; x++ )
1736 							{
1737 								int c = source[x_index>>16];
1738 								if( c != transparent_color ) dest[x] = pal[c];
1739 								x_index += dx;
1740 							}
1741 
1742 							y_index += dy;
1743 						}
1744 					}
1745 				}
1746 
1747 				/* case 1b: TRANSPARENCY_PEN_RAW */
1748 				if (transparency == TRANSPARENCY_PEN_RAW)
1749 				{
1750 					if (pri_buffer)
1751 					{
1752 						for( y=sy; y<ey; y++ )
1753 						{
1754 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1755 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1756 							UINT8 *pri = pri_buffer->line[y];
1757 
1758 							int x, x_index = x_index_base;
1759 							for( x=sx; x<ex; x++ )
1760 							{
1761 								int c = source[x_index>>16];
1762 								if( c != transparent_color )
1763 								{
1764 									if (((1 << pri[x]) & pri_mask) == 0)
1765 										dest[x] = color + c;
1766 									pri[x] = 31;
1767 								}
1768 								x_index += dx;
1769 							}
1770 
1771 							y_index += dy;
1772 						}
1773 					}
1774 					else
1775 					{
1776 						for( y=sy; y<ey; y++ )
1777 						{
1778 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1779 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1780 
1781 							int x, x_index = x_index_base;
1782 							for( x=sx; x<ex; x++ )
1783 							{
1784 								int c = source[x_index>>16];
1785 								if( c != transparent_color ) dest[x] = color + c;
1786 								x_index += dx;
1787 							}
1788 
1789 							y_index += dy;
1790 						}
1791 					}
1792 				}
1793 
1794 				/* case 2: TRANSPARENCY_PENS */
1795 				if (transparency == TRANSPARENCY_PENS)
1796 				{
1797 					if (pri_buffer)
1798 					{
1799 						for( y=sy; y<ey; y++ )
1800 						{
1801 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1802 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1803 							UINT8 *pri = pri_buffer->line[y];
1804 
1805 							int x, x_index = x_index_base;
1806 							for( x=sx; x<ex; x++ )
1807 							{
1808 								int c = source[x_index>>16];
1809 								if (((1 << c) & transparent_color) == 0)
1810 								{
1811 									if (((1 << pri[x]) & pri_mask) == 0)
1812 										dest[x] = pal[c];
1813 									pri[x] = 31;
1814 								}
1815 								x_index += dx;
1816 							}
1817 
1818 							y_index += dy;
1819 						}
1820 					}
1821 					else
1822 					{
1823 						for( y=sy; y<ey; y++ )
1824 						{
1825 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1826 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1827 
1828 							int x, x_index = x_index_base;
1829 							for( x=sx; x<ex; x++ )
1830 							{
1831 								int c = source[x_index>>16];
1832 								if (((1 << c) & transparent_color) == 0)
1833 									dest[x] = pal[c];
1834 								x_index += dx;
1835 							}
1836 
1837 							y_index += dy;
1838 						}
1839 					}
1840 				}
1841 
1842 				/* case 3: TRANSPARENCY_COLOR */
1843 				else if (transparency == TRANSPARENCY_COLOR)
1844 				{
1845 					if (pri_buffer)
1846 					{
1847 						for( y=sy; y<ey; y++ )
1848 						{
1849 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1850 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1851 							UINT8 *pri = pri_buffer->line[y];
1852 
1853 							int x, x_index = x_index_base;
1854 							for( x=sx; x<ex; x++ )
1855 							{
1856 								int c = pal[source[x_index>>16]];
1857 								if( c != transparent_color )
1858 								{
1859 									if (((1 << pri[x]) & pri_mask) == 0)
1860 										dest[x] = c;
1861 									pri[x] = 31;
1862 								}
1863 								x_index += dx;
1864 							}
1865 
1866 							y_index += dy;
1867 						}
1868 					}
1869 					else
1870 					{
1871 						for( y=sy; y<ey; y++ )
1872 						{
1873 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1874 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1875 
1876 							int x, x_index = x_index_base;
1877 							for( x=sx; x<ex; x++ )
1878 							{
1879 								int c = pal[source[x_index>>16]];
1880 								if( c != transparent_color ) dest[x] = c;
1881 								x_index += dx;
1882 							}
1883 
1884 							y_index += dy;
1885 						}
1886 					}
1887 				}
1888 
1889 				/* case 4: TRANSPARENCY_PEN_TABLE */
1890 				if (transparency == TRANSPARENCY_PEN_TABLE)
1891 				{
1892 					if (pri_buffer)
1893 					{
1894 						for( y=sy; y<ey; y++ )
1895 						{
1896 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1897 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1898 							UINT8 *pri = pri_buffer->line[y];
1899 
1900 							int x, x_index = x_index_base;
1901 							for( x=sx; x<ex; x++ )
1902 							{
1903 								int c = source[x_index>>16];
1904 								if( c != transparent_color )
1905 								{
1906 									if (((1 << pri[x]) & pri_mask) == 0)
1907 									{
1908 										switch(gfx_drawmode_table[c])
1909 										{
1910 										case DRAWMODE_SOURCE:
1911 											dest[x] = pal[c];
1912 											break;
1913 										case DRAWMODE_SHADOW:
1914 											dest[x] = palette_shadow_table[dest[x]];
1915 											break;
1916 										}
1917 									}
1918 									pri[x] = 31;
1919 								}
1920 								x_index += dx;
1921 							}
1922 
1923 							y_index += dy;
1924 						}
1925 					}
1926 					else
1927 					{
1928 						for( y=sy; y<ey; y++ )
1929 						{
1930 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1931 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1932 
1933 							int x, x_index = x_index_base;
1934 							for( x=sx; x<ex; x++ )
1935 							{
1936 								int c = source[x_index>>16];
1937 								if( c != transparent_color )
1938 								{
1939 									switch(gfx_drawmode_table[c])
1940 									{
1941 									case DRAWMODE_SOURCE:
1942 										dest[x] = pal[c];
1943 										break;
1944 									case DRAWMODE_SHADOW:
1945 										dest[x] = palette_shadow_table[dest[x]];
1946 										break;
1947 									}
1948 								}
1949 								x_index += dx;
1950 							}
1951 
1952 							y_index += dy;
1953 						}
1954 					}
1955 				}
1956 
1957 				/* case 4b: TRANSPARENCY_PEN_TABLE_RAW */
1958 				if (transparency == TRANSPARENCY_PEN_TABLE_RAW)
1959 				{
1960 					if (pri_buffer)
1961 					{
1962 						for( y=sy; y<ey; y++ )
1963 						{
1964 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1965 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
1966 							UINT8 *pri = pri_buffer->line[y];
1967 
1968 							int x, x_index = x_index_base;
1969 							for( x=sx; x<ex; x++ )
1970 							{
1971 								int c = source[x_index>>16];
1972 								if( c != transparent_color )
1973 								{
1974 									if (((1 << pri[x]) & pri_mask) == 0)
1975 									{
1976 										switch(gfx_drawmode_table[c])
1977 										{
1978 										case DRAWMODE_SOURCE:
1979 											dest[x] = color + c;
1980 											break;
1981 										case DRAWMODE_SHADOW:
1982 											dest[x] = palette_shadow_table[dest[x]];
1983 											break;
1984 										}
1985 									}
1986 									pri[x] = 31;
1987 								}
1988 								x_index += dx;
1989 							}
1990 
1991 							y_index += dy;
1992 						}
1993 					}
1994 					else
1995 					{
1996 						for( y=sy; y<ey; y++ )
1997 						{
1998 							UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
1999 							UINT16 *dest = (UINT16 *)dest_bmp->line[y];
2000 
2001 							int x, x_index = x_index_base;
2002 							for( x=sx; x<ex; x++ )
2003 							{
2004 								int c = source[x_index>>16];
2005 								if( c != transparent_color )
2006 								{
2007 									switch(gfx_drawmode_table[c])
2008 									{
2009 									case DRAWMODE_SOURCE:
2010 										dest[x] = color + c;
2011 										break;
2012 									case DRAWMODE_SHADOW:
2013 										dest[x] = palette_shadow_table[dest[x]];
2014 										break;
2015 									}
2016 								}
2017 								x_index += dx;
2018 							}
2019 
2020 							y_index += dy;
2021 						}
2022 					}
2023 				}
2024 			}
2025 		}
2026 	}
2027 }
2028 
drawgfxzoom(struct osd_bitmap * dest_bmp,const struct GfxElement * gfx,unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,int transparency,int transparent_color,int scalex,int scaley)2029 void drawgfxzoom( struct osd_bitmap *dest_bmp,const struct GfxElement *gfx,
2030 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
2031 		const struct rectangle *clip,int transparency,int transparent_color,int scalex, int scaley)
2032 {
2033 	profiler_mark(PROFILER_DRAWGFX);
2034 	common_drawgfxzoom(dest_bmp,gfx,code,color,flipx,flipy,sx,sy,
2035 			clip,transparency,transparent_color,scalex,scaley,NULL,0);
2036 	profiler_mark(PROFILER_END);
2037 }
2038 
pdrawgfxzoom(struct osd_bitmap * dest_bmp,const struct GfxElement * gfx,unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,const struct rectangle * clip,int transparency,int transparent_color,int scalex,int scaley,UINT32 priority_mask)2039 void pdrawgfxzoom( struct osd_bitmap *dest_bmp,const struct GfxElement *gfx,
2040 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
2041 		const struct rectangle *clip,int transparency,int transparent_color,int scalex, int scaley,
2042 		UINT32 priority_mask)
2043 {
2044 	profiler_mark(PROFILER_DRAWGFX);
2045 	common_drawgfxzoom(dest_bmp,gfx,code,color,flipx,flipy,sx,sy,
2046 			clip,transparency,transparent_color,scalex,scaley,priority_bitmap,priority_mask);
2047 	profiler_mark(PROFILER_END);
2048 }
2049 
2050 
plot_pixel2(struct osd_bitmap * bitmap1,struct osd_bitmap * bitmap2,int x,int y,int pen)2051 void plot_pixel2(struct osd_bitmap *bitmap1,struct osd_bitmap *bitmap2,int x,int y,int pen)
2052 {
2053 	plot_pixel(bitmap1, x, y, pen);
2054 	plot_pixel(bitmap2, x, y, pen);
2055 }
2056 
pp_8_nd(struct osd_bitmap * b,int x,int y,int p)2057 static void pp_8_nd(struct osd_bitmap *b,int x,int y,int p)  { b->line[y][x] = p; }
pp_8_nd_fx(struct osd_bitmap * b,int x,int y,int p)2058 static void pp_8_nd_fx(struct osd_bitmap *b,int x,int y,int p)  { b->line[y][b->width-1-x] = p; }
pp_8_nd_fy(struct osd_bitmap * b,int x,int y,int p)2059 static void pp_8_nd_fy(struct osd_bitmap *b,int x,int y,int p)  { b->line[b->height-1-y][x] = p; }
pp_8_nd_fxy(struct osd_bitmap * b,int x,int y,int p)2060 static void pp_8_nd_fxy(struct osd_bitmap *b,int x,int y,int p)  { b->line[b->height-1-y][b->width-1-x] = p; }
pp_8_nd_s(struct osd_bitmap * b,int x,int y,int p)2061 static void pp_8_nd_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[x][y] = p; }
pp_8_nd_fx_s(struct osd_bitmap * b,int x,int y,int p)2062 static void pp_8_nd_fx_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[x][b->width-1-y] = p; }
pp_8_nd_fy_s(struct osd_bitmap * b,int x,int y,int p)2063 static void pp_8_nd_fy_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[b->height-1-x][y] = p; }
pp_8_nd_fxy_s(struct osd_bitmap * b,int x,int y,int p)2064 static void pp_8_nd_fxy_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[b->height-1-x][b->width-1-y] = p; }
2065 
pp_8_d(struct osd_bitmap * b,int x,int y,int p)2066 static void pp_8_d(struct osd_bitmap *b,int x,int y,int p)  { b->line[y][x] = p; osd_mark_dirty (x,y,x,y,0); }
pp_8_d_fx(struct osd_bitmap * b,int x,int y,int p)2067 static void pp_8_d_fx(struct osd_bitmap *b,int x,int y,int p)  { x = b->width-1-x;  b->line[y][x] = p; osd_mark_dirty (x,y,x,y,0); }
pp_8_d_fy(struct osd_bitmap * b,int x,int y,int p)2068 static void pp_8_d_fy(struct osd_bitmap *b,int x,int y,int p)  { y = b->height-1-y; b->line[y][x] = p; osd_mark_dirty (x,y,x,y,0); }
pp_8_d_fxy(struct osd_bitmap * b,int x,int y,int p)2069 static void pp_8_d_fxy(struct osd_bitmap *b,int x,int y,int p)  { x = b->width-1-x; y = b->height-1-y; b->line[y][x] = p; osd_mark_dirty (x,y,x,y,0); }
pp_8_d_s(struct osd_bitmap * b,int x,int y,int p)2070 static void pp_8_d_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[x][y] = p; osd_mark_dirty (y,x,y,x,0); }
pp_8_d_fx_s(struct osd_bitmap * b,int x,int y,int p)2071 static void pp_8_d_fx_s(struct osd_bitmap *b,int x,int y,int p)  { y = b->width-1-y; b->line[x][y] = p; osd_mark_dirty (y,x,y,x,0); }
pp_8_d_fy_s(struct osd_bitmap * b,int x,int y,int p)2072 static void pp_8_d_fy_s(struct osd_bitmap *b,int x,int y,int p)  { x = b->height-1-x; b->line[x][y] = p; osd_mark_dirty (y,x,y,x,0); }
pp_8_d_fxy_s(struct osd_bitmap * b,int x,int y,int p)2073 static void pp_8_d_fxy_s(struct osd_bitmap *b,int x,int y,int p)  { x = b->height-1-x; y = b->width-1-y; b->line[x][y] = p; osd_mark_dirty (y,x,y,x,0); }
2074 
pp_16_nd(struct osd_bitmap * b,int x,int y,int p)2075 static void pp_16_nd(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[y])[x] = p; }
pp_16_nd_fx(struct osd_bitmap * b,int x,int y,int p)2076 static void pp_16_nd_fx(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[y])[b->width-1-x] = p; }
pp_16_nd_fy(struct osd_bitmap * b,int x,int y,int p)2077 static void pp_16_nd_fy(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[b->height-1-y])[x] = p; }
pp_16_nd_fxy(struct osd_bitmap * b,int x,int y,int p)2078 static void pp_16_nd_fxy(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[b->height-1-y])[b->width-1-x] = p; }
pp_16_nd_s(struct osd_bitmap * b,int x,int y,int p)2079 static void pp_16_nd_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[x])[y] = p; }
pp_16_nd_fx_s(struct osd_bitmap * b,int x,int y,int p)2080 static void pp_16_nd_fx_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[x])[b->width-1-y] = p; }
pp_16_nd_fy_s(struct osd_bitmap * b,int x,int y,int p)2081 static void pp_16_nd_fy_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[b->height-1-x])[y] = p; }
pp_16_nd_fxy_s(struct osd_bitmap * b,int x,int y,int p)2082 static void pp_16_nd_fxy_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[b->height-1-x])[b->width-1-y] = p; }
2083 
pp_16_d(struct osd_bitmap * b,int x,int y,int p)2084 static void pp_16_d(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[y])[x] = p; osd_mark_dirty (x,y,x,y,0); }
pp_16_d_fx(struct osd_bitmap * b,int x,int y,int p)2085 static void pp_16_d_fx(struct osd_bitmap *b,int x,int y,int p)  { x = b->width-1-x;  ((UINT16 *)b->line[y])[x] = p; osd_mark_dirty (x,y,x,y,0); }
pp_16_d_fy(struct osd_bitmap * b,int x,int y,int p)2086 static void pp_16_d_fy(struct osd_bitmap *b,int x,int y,int p)  { y = b->height-1-y; ((UINT16 *)b->line[y])[x] = p; osd_mark_dirty (x,y,x,y,0); }
pp_16_d_fxy(struct osd_bitmap * b,int x,int y,int p)2087 static void pp_16_d_fxy(struct osd_bitmap *b,int x,int y,int p)  { x = b->width-1-x; y = b->height-1-y; ((UINT16 *)b->line[y])[x] = p; osd_mark_dirty (x,y,x,y,0); }
pp_16_d_s(struct osd_bitmap * b,int x,int y,int p)2088 static void pp_16_d_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[x])[y] = p; osd_mark_dirty (y,x,y,x,0); }
pp_16_d_fx_s(struct osd_bitmap * b,int x,int y,int p)2089 static void pp_16_d_fx_s(struct osd_bitmap *b,int x,int y,int p)  { y = b->width-1-y; ((UINT16 *)b->line[x])[y] = p; osd_mark_dirty (y,x,y,x,0); }
pp_16_d_fy_s(struct osd_bitmap * b,int x,int y,int p)2090 static void pp_16_d_fy_s(struct osd_bitmap *b,int x,int y,int p)  { x = b->height-1-x; ((UINT16 *)b->line[x])[y] = p; osd_mark_dirty (y,x,y,x,0); }
pp_16_d_fxy_s(struct osd_bitmap * b,int x,int y,int p)2091 static void pp_16_d_fxy_s(struct osd_bitmap *b,int x,int y,int p)  { x = b->height-1-x; y = b->width-1-y; ((UINT16 *)b->line[x])[y] = p; osd_mark_dirty (y,x,y,x,0); }
2092 
2093 
rp_8(struct osd_bitmap * b,int x,int y)2094 static int rp_8(struct osd_bitmap *b,int x,int y)  { return b->line[y][x]; }
rp_8_fx(struct osd_bitmap * b,int x,int y)2095 static int rp_8_fx(struct osd_bitmap *b,int x,int y)  { return b->line[y][b->width-1-x]; }
rp_8_fy(struct osd_bitmap * b,int x,int y)2096 static int rp_8_fy(struct osd_bitmap *b,int x,int y)  { return b->line[b->height-1-y][x]; }
rp_8_fxy(struct osd_bitmap * b,int x,int y)2097 static int rp_8_fxy(struct osd_bitmap *b,int x,int y)  { return b->line[b->height-1-y][b->width-1-x]; }
rp_8_s(struct osd_bitmap * b,int x,int y)2098 static int rp_8_s(struct osd_bitmap *b,int x,int y)  { return b->line[x][y]; }
rp_8_fx_s(struct osd_bitmap * b,int x,int y)2099 static int rp_8_fx_s(struct osd_bitmap *b,int x,int y)  { return b->line[x][b->width-1-y]; }
rp_8_fy_s(struct osd_bitmap * b,int x,int y)2100 static int rp_8_fy_s(struct osd_bitmap *b,int x,int y)  { return b->line[b->height-1-x][y]; }
rp_8_fxy_s(struct osd_bitmap * b,int x,int y)2101 static int rp_8_fxy_s(struct osd_bitmap *b,int x,int y)  { return b->line[b->height-1-x][b->width-1-y]; }
2102 
rp_16(struct osd_bitmap * b,int x,int y)2103 static int rp_16(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[y])[x]; }
rp_16_fx(struct osd_bitmap * b,int x,int y)2104 static int rp_16_fx(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[y])[b->width-1-x]; }
rp_16_fy(struct osd_bitmap * b,int x,int y)2105 static int rp_16_fy(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[b->height-1-y])[x]; }
rp_16_fxy(struct osd_bitmap * b,int x,int y)2106 static int rp_16_fxy(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[b->height-1-y])[b->width-1-x]; }
rp_16_s(struct osd_bitmap * b,int x,int y)2107 static int rp_16_s(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[x])[y]; }
rp_16_fx_s(struct osd_bitmap * b,int x,int y)2108 static int rp_16_fx_s(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[x])[b->width-1-y]; }
rp_16_fy_s(struct osd_bitmap * b,int x,int y)2109 static int rp_16_fy_s(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[b->height-1-x])[y]; }
rp_16_fxy_s(struct osd_bitmap * b,int x,int y)2110 static int rp_16_fxy_s(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[b->height-1-x])[b->width-1-y]; }
2111 
2112 
pb_8_nd(struct osd_bitmap * b,int x,int y,int w,int h,int p)2113 static void pb_8_nd(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; while(h-->0){ int c=w; x=t; while(c-->0){ b->line[y][x] = p; x++; } y++; } }
pb_8_nd_fx(struct osd_bitmap * b,int x,int y,int w,int h,int p)2114 static void pb_8_nd_fx(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->width-1-x; while(h-->0){ int c=w; x=t; while(c-->0){ b->line[y][x] = p; x--; } y++; } }
pb_8_nd_fy(struct osd_bitmap * b,int x,int y,int w,int h,int p)2115 static void pb_8_nd_fy(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; y = b->height-1-y; while(h-->0){ int c=w; x=t; while(c-->0){ b->line[y][x] = p; x++; } y--; } }
pb_8_nd_fxy(struct osd_bitmap * b,int x,int y,int w,int h,int p)2116 static void pb_8_nd_fxy(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->width-1-x; y = b->height-1-y; while(h-->0){ int c=w; x=t; while(c-->0){ b->line[y][x] = p; x--; } y--; } }
pb_8_nd_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2117 static void pb_8_nd_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; while(h-->0){ int c=w; x=t; while(c-->0){ b->line[x][y] = p; x++; } y++; } }
pb_8_nd_fx_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2118 static void pb_8_nd_fx_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; y = b->width-1-y; while(h-->0){ int c=w; x=t; while(c-->0){ b->line[x][y] = p; x++; } y--; } }
pb_8_nd_fy_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2119 static void pb_8_nd_fy_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->height-1-x; while(h-->0){ int c=w; x=t; while(c-->0){ b->line[x][y] = p; x--; } y++; } }
pb_8_nd_fxy_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2120 static void pb_8_nd_fxy_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->height-1-x; y = b->width-1-y; while(h-->0){ int c=w; x=t; while(c-->0){ b->line[x][y] = p; x--; } y--; } }
2121 
pb_8_d(struct osd_bitmap * b,int x,int y,int w,int h,int p)2122 static void pb_8_d(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; osd_mark_dirty (t,y,t+w-1,y+h-1,0); while(h-->0){ int c=w; x=t; while(c-->0){ b->line[y][x] = p; x++; } y++; } }
pb_8_d_fx(struct osd_bitmap * b,int x,int y,int w,int h,int p)2123 static void pb_8_d_fx(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->width-1-x;  osd_mark_dirty (t-w+1,y,t,y+h-1,0); while(h-->0){ int c=w; x=t; while(c-->0){ b->line[y][x] = p; x--; } y++; } }
pb_8_d_fy(struct osd_bitmap * b,int x,int y,int w,int h,int p)2124 static void pb_8_d_fy(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; y = b->height-1-y; osd_mark_dirty (t,y-h+1,t+w-1,y,0); while(h-->0){ int c=w; x=t; while(c-->0){ b->line[y][x] = p; x++; } y--; } }
pb_8_d_fxy(struct osd_bitmap * b,int x,int y,int w,int h,int p)2125 static void pb_8_d_fxy(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->width-1-x; y = b->height-1-y; osd_mark_dirty (t-w+1,y-h+1,t,y,0); while(h-->0){ int c=w; x=t; while(c-->0){ b->line[y][x] = p; x--; } y--; } }
pb_8_d_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2126 static void pb_8_d_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; osd_mark_dirty (y,t,y+h-1,t+w-1,0); while(h-->0){ int c=w; x=t; while(c-->0){ b->line[x][y] = p; x++; } y++; } }
pb_8_d_fx_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2127 static void pb_8_d_fx_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; y = b->width-1-y;  osd_mark_dirty (y-h+1,t,y,t+w-1,0); while(h-->0){ int c=w; x=t; while(c-->0){ b->line[x][y] = p; x++; } y--; } }
pb_8_d_fy_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2128 static void pb_8_d_fy_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->height-1-x; osd_mark_dirty (y,t-w+1,y+h-1,t,0); while(h-->0){ int c=w; x=t; while(c-->0){ b->line[x][y] = p; x--; } y++; } }
pb_8_d_fxy_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2129 static void pb_8_d_fxy_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->height-1-x; y = b->width-1-y; osd_mark_dirty (y-h+1,t-w+1,y,t,0); while(h-->0){ int c=w; x=t; while(c-->0){ b->line[x][y] = p; x--; } y--; } }
2130 
pb_16_nd(struct osd_bitmap * b,int x,int y,int w,int h,int p)2131 static void pb_16_nd(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[y])[x] = p; x++; } y++; } }
pb_16_nd_fx(struct osd_bitmap * b,int x,int y,int w,int h,int p)2132 static void pb_16_nd_fx(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->width-1-x; while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[y])[x] = p; x--; } y++; } }
pb_16_nd_fy(struct osd_bitmap * b,int x,int y,int w,int h,int p)2133 static void pb_16_nd_fy(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; y = b->height-1-y; while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[y])[x] = p; x++; } y--; } }
pb_16_nd_fxy(struct osd_bitmap * b,int x,int y,int w,int h,int p)2134 static void pb_16_nd_fxy(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->width-1-x; y = b->height-1-y; while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[y])[x] = p; x--; } y--; } }
pb_16_nd_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2135 static void pb_16_nd_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[x])[y] = p; x++; } y++; } }
pb_16_nd_fx_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2136 static void pb_16_nd_fx_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; y = b->width-1-y; while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[x])[y] = p; x++; } y--; } }
pb_16_nd_fy_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2137 static void pb_16_nd_fy_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->height-1-x; while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[x])[y] = p; x--; } y++; } }
pb_16_nd_fxy_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2138 static void pb_16_nd_fxy_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->height-1-x; y = b->width-1-y; while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[x])[y] = p; x--; } y--; } }
2139 
pb_16_d(struct osd_bitmap * b,int x,int y,int w,int h,int p)2140 static void pb_16_d(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; osd_mark_dirty (t,y,t+w-1,y+h-1,0); while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[y])[x] = p; x++; } y++; } }
pb_16_d_fx(struct osd_bitmap * b,int x,int y,int w,int h,int p)2141 static void pb_16_d_fx(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->width-1-x;  osd_mark_dirty (t-w+1,y,t,y+h-1,0); while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[y])[x] = p; x--; } y++; } }
pb_16_d_fy(struct osd_bitmap * b,int x,int y,int w,int h,int p)2142 static void pb_16_d_fy(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; y = b->height-1-y; osd_mark_dirty (t,y-h+1,t+w-1,y,0); while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[y])[x] = p; x++; } y--; } }
pb_16_d_fxy(struct osd_bitmap * b,int x,int y,int w,int h,int p)2143 static void pb_16_d_fxy(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->width-1-x; y = b->height-1-y; osd_mark_dirty (t-w+1,y-h+1,t,y,0); while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[y])[x] = p; x--; } y--; } }
pb_16_d_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2144 static void pb_16_d_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; osd_mark_dirty (y,t,y+h-1,t+w-1,0); while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[x])[y] = p; x++; } y++; } }
pb_16_d_fx_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2145 static void pb_16_d_fx_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=x; y = b->width-1-y; osd_mark_dirty (y-h+1,t,y,t+w-1,0); while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[x])[y] = p; x++; } y--; } }
pb_16_d_fy_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2146 static void pb_16_d_fy_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->height-1-x; osd_mark_dirty (y,t-w+1,y+h-1,t,0); while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[x])[y] = p; x--; } y++; } }
pb_16_d_fxy_s(struct osd_bitmap * b,int x,int y,int w,int h,int p)2147 static void pb_16_d_fxy_s(struct osd_bitmap *b,int x,int y,int w,int h,int p)  { int t=b->height-1-x; y = b->width-1-y; osd_mark_dirty (y-h+1,t-w+1,y,t,0); while(h-->0){ int c=w; x=t; while(c-->0){ ((UINT16 *)b->line[x])[y] = p; x--; } y--; } }
2148 
2149 
2150 static plot_pixel_proc pps_8_nd[] =
2151 		{ pp_8_nd, 	 pp_8_nd_fx,   pp_8_nd_fy, 	 pp_8_nd_fxy,
2152 		  pp_8_nd_s, pp_8_nd_fx_s, pp_8_nd_fy_s, pp_8_nd_fxy_s };
2153 
2154 static plot_pixel_proc pps_8_d[] =
2155 		{ pp_8_d, 	pp_8_d_fx,   pp_8_d_fy,	  pp_8_d_fxy,
2156 		  pp_8_d_s, pp_8_d_fx_s, pp_8_d_fy_s, pp_8_d_fxy_s };
2157 
2158 static plot_pixel_proc pps_16_nd[] =
2159 		{ pp_16_nd,   pp_16_nd_fx,   pp_16_nd_fy, 	pp_16_nd_fxy,
2160 		  pp_16_nd_s, pp_16_nd_fx_s, pp_16_nd_fy_s, pp_16_nd_fxy_s };
2161 
2162 static plot_pixel_proc pps_16_d[] =
2163 		{ pp_16_d,   pp_16_d_fx,   pp_16_d_fy, 	 pp_16_d_fxy,
2164 		  pp_16_d_s, pp_16_d_fx_s, pp_16_d_fy_s, pp_16_d_fxy_s };
2165 
2166 
2167 static read_pixel_proc rps_8[] =
2168 		{ rp_8,	  rp_8_fx,   rp_8_fy,	rp_8_fxy,
2169 		  rp_8_s, rp_8_fx_s, rp_8_fy_s, rp_8_fxy_s };
2170 
2171 static read_pixel_proc rps_16[] =
2172 		{ rp_16,   rp_16_fx,   rp_16_fy,   rp_16_fxy,
2173 		  rp_16_s, rp_16_fx_s, rp_16_fy_s, rp_16_fxy_s };
2174 
2175 
2176 static plot_box_proc pbs_8_nd[] =
2177 		{ pb_8_nd, 	 pb_8_nd_fx,   pb_8_nd_fy, 	 pb_8_nd_fxy,
2178 		  pb_8_nd_s, pb_8_nd_fx_s, pb_8_nd_fy_s, pb_8_nd_fxy_s };
2179 
2180 static plot_box_proc pbs_8_d[] =
2181 		{ pb_8_d, 	pb_8_d_fx,   pb_8_d_fy,	  pb_8_d_fxy,
2182 		  pb_8_d_s, pb_8_d_fx_s, pb_8_d_fy_s, pb_8_d_fxy_s };
2183 
2184 static plot_box_proc pbs_16_nd[] =
2185 		{ pb_16_nd,   pb_16_nd_fx,   pb_16_nd_fy, 	pb_16_nd_fxy,
2186 		  pb_16_nd_s, pb_16_nd_fx_s, pb_16_nd_fy_s, pb_16_nd_fxy_s };
2187 
2188 static plot_box_proc pbs_16_d[] =
2189 		{ pb_16_d,   pb_16_d_fx,   pb_16_d_fy, 	 pb_16_d_fxy,
2190 		  pb_16_d_s, pb_16_d_fx_s, pb_16_d_fy_s, pb_16_d_fxy_s };
2191 
2192 
set_pixel_functions(void)2193 void set_pixel_functions(void)
2194 {
2195 	if (Machine->color_depth == 8)
2196 	{
2197 		read_pixel = rps_8[Machine->orientation];
2198 
2199 		if (Machine->drv->video_attributes & VIDEO_SUPPORTS_DIRTY)
2200 		{
2201 			plot_pixel = pps_8_d[Machine->orientation];
2202 			plot_box = pbs_8_d[Machine->orientation];
2203 		}
2204 		else
2205 		{
2206 			plot_pixel = pps_8_nd[Machine->orientation];
2207 			plot_box = pbs_8_nd[Machine->orientation];
2208 		}
2209 	}
2210 	else
2211 	{
2212 		read_pixel = rps_16[Machine->orientation];
2213 
2214 		if (Machine->drv->video_attributes & VIDEO_SUPPORTS_DIRTY)
2215 		{
2216 			plot_pixel = pps_16_d[Machine->orientation];
2217 			plot_box = pbs_16_d[Machine->orientation];
2218 		}
2219 		else
2220 		{
2221 			plot_pixel = pps_16_nd[Machine->orientation];
2222 			plot_box = pbs_16_nd[Machine->orientation];
2223 		}
2224 	}
2225 
2226 	/* while we're here, fill in the raw drawing mode table as well */
2227 	is_raw[TRANSPARENCY_NONE_RAW]      = 1;
2228 	is_raw[TRANSPARENCY_PEN_RAW]       = 1;
2229 	is_raw[TRANSPARENCY_PENS_RAW]      = 1;
2230 	is_raw[TRANSPARENCY_THROUGH_RAW]   = 1;
2231 	is_raw[TRANSPARENCY_PEN_TABLE_RAW] = 1;
2232 	is_raw[TRANSPARENCY_BLEND_RAW]     = 1;
2233 }
2234 
2235 #else /* DECLARE */
2236 
2237 /* -------------------- included inline section --------------------- */
2238 
2239 /* don't put this file in the makefile, it is #included by common.c to */
2240 /* generate 8-bit and 16-bit versions                                  */
2241 
2242 DECLARE(blockmove_8toN_opaque,(
2243 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2244 		DATA_TYPE *dstdata,int dstmodulo,
2245 		const UINT16 *paldata),
2246 {
2247 	DATA_TYPE *end;
2248 
2249 	srcmodulo -= srcwidth;
2250 	dstmodulo -= srcwidth;
2251 
2252 	while (srcheight)
2253 	{
2254 		end = dstdata + srcwidth;
2255 		while (dstdata <= end - 8)
2256 		{
2257 			dstdata[0] = paldata[srcdata[0]];
2258 			dstdata[1] = paldata[srcdata[1]];
2259 			dstdata[2] = paldata[srcdata[2]];
2260 			dstdata[3] = paldata[srcdata[3]];
2261 			dstdata[4] = paldata[srcdata[4]];
2262 			dstdata[5] = paldata[srcdata[5]];
2263 			dstdata[6] = paldata[srcdata[6]];
2264 			dstdata[7] = paldata[srcdata[7]];
2265 			dstdata += 8;
2266 			srcdata += 8;
2267 		}
2268 		while (dstdata < end)
2269 			*(dstdata++) = paldata[*(srcdata++)];
2270 
2271 		srcdata += srcmodulo;
2272 		dstdata += dstmodulo;
2273 		srcheight--;
2274 	}
2275 })
2276 
2277 DECLARE(blockmove_8toN_opaque_flipx,(
2278 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2279 		DATA_TYPE *dstdata,int dstmodulo,
2280 		const UINT16 *paldata),
2281 {
2282 	DATA_TYPE *end;
2283 
2284 	srcmodulo += srcwidth;
2285 	dstmodulo -= srcwidth;
2286 	//srcdata += srcwidth-1;
2287 
2288 	while (srcheight)
2289 	{
2290 		end = dstdata + srcwidth;
2291 		while (dstdata <= end - 8)
2292 		{
2293 			srcdata -= 8;
2294 			dstdata[0] = paldata[srcdata[8]];
2295 			dstdata[1] = paldata[srcdata[7]];
2296 			dstdata[2] = paldata[srcdata[6]];
2297 			dstdata[3] = paldata[srcdata[5]];
2298 			dstdata[4] = paldata[srcdata[4]];
2299 			dstdata[5] = paldata[srcdata[3]];
2300 			dstdata[6] = paldata[srcdata[2]];
2301 			dstdata[7] = paldata[srcdata[1]];
2302 			dstdata += 8;
2303 		}
2304 		while (dstdata < end)
2305 			*(dstdata++) = paldata[*(srcdata--)];
2306 
2307 		srcdata += srcmodulo;
2308 		dstdata += dstmodulo;
2309 		srcheight--;
2310 	}
2311 })
2312 
2313 DECLARE(blockmove_8toN_opaque_pri,(
2314 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2315 		DATA_TYPE *dstdata,int dstmodulo,
2316 		const UINT16 *paldata,UINT8 *pridata,UINT32 pmask),
2317 {
2318 	DATA_TYPE *end;
2319 
2320 	pmask |= (1<<31);
2321 
2322 	srcmodulo -= srcwidth;
2323 	dstmodulo -= srcwidth;
2324 
2325 	while (srcheight)
2326 	{
2327 		end = dstdata + srcwidth;
2328 		while (dstdata <= end - 8)
2329 		{
2330 			if (((1 << pridata[0]) & pmask) == 0) dstdata[0] = paldata[srcdata[0]];
2331 			if (((1 << pridata[1]) & pmask) == 0) dstdata[1] = paldata[srcdata[1]];
2332 			if (((1 << pridata[2]) & pmask) == 0) dstdata[2] = paldata[srcdata[2]];
2333 			if (((1 << pridata[3]) & pmask) == 0) dstdata[3] = paldata[srcdata[3]];
2334 			if (((1 << pridata[4]) & pmask) == 0) dstdata[4] = paldata[srcdata[4]];
2335 			if (((1 << pridata[5]) & pmask) == 0) dstdata[5] = paldata[srcdata[5]];
2336 			if (((1 << pridata[6]) & pmask) == 0) dstdata[6] = paldata[srcdata[6]];
2337 			if (((1 << pridata[7]) & pmask) == 0) dstdata[7] = paldata[srcdata[7]];
2338 			memset(pridata,31,8);
2339 			srcdata += 8;
2340 			dstdata += 8;
2341 			pridata += 8;
2342 		}
2343 		while (dstdata < end)
2344 		{
2345 			if (((1 << *pridata) & pmask) == 0)
2346 				*dstdata = paldata[*srcdata];
2347 			*pridata = 31;
2348 			srcdata++;
2349 			dstdata++;
2350 			pridata++;
2351 		}
2352 
2353 		srcdata += srcmodulo;
2354 		dstdata += dstmodulo;
2355 		pridata += dstmodulo;
2356 		srcheight--;
2357 	}
2358 })
2359 
2360 DECLARE(blockmove_8toN_opaque_pri_flipx,(
2361 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2362 		DATA_TYPE *dstdata,int dstmodulo,
2363 		const UINT16 *paldata,UINT8 *pridata,UINT32 pmask),
2364 {
2365 	DATA_TYPE *end;
2366 
2367 	pmask |= (1<<31);
2368 
2369 	srcmodulo += srcwidth;
2370 	dstmodulo -= srcwidth;
2371 	//srcdata += srcwidth-1;
2372 
2373 	while (srcheight)
2374 	{
2375 		end = dstdata + srcwidth;
2376 		while (dstdata <= end - 8)
2377 		{
2378 			srcdata -= 8;
2379 			if (((1 << pridata[0]) & pmask) == 0) dstdata[0] = paldata[srcdata[8]];
2380 			if (((1 << pridata[1]) & pmask) == 0) dstdata[1] = paldata[srcdata[7]];
2381 			if (((1 << pridata[2]) & pmask) == 0) dstdata[2] = paldata[srcdata[6]];
2382 			if (((1 << pridata[3]) & pmask) == 0) dstdata[3] = paldata[srcdata[5]];
2383 			if (((1 << pridata[4]) & pmask) == 0) dstdata[4] = paldata[srcdata[4]];
2384 			if (((1 << pridata[5]) & pmask) == 0) dstdata[5] = paldata[srcdata[3]];
2385 			if (((1 << pridata[6]) & pmask) == 0) dstdata[6] = paldata[srcdata[2]];
2386 			if (((1 << pridata[7]) & pmask) == 0) dstdata[7] = paldata[srcdata[1]];
2387 			memset(pridata,31,8);
2388 			dstdata += 8;
2389 			pridata += 8;
2390 		}
2391 		while (dstdata < end)
2392 		{
2393 			if (((1 << *pridata) & pmask) == 0)
2394 				*dstdata = paldata[*srcdata];
2395 			*pridata = 31;
2396 			srcdata--;
2397 			dstdata++;
2398 			pridata++;
2399 		}
2400 
2401 		srcdata += srcmodulo;
2402 		dstdata += dstmodulo;
2403 		pridata += dstmodulo;
2404 		srcheight--;
2405 	}
2406 })
2407 
2408 
2409 DECLARE(blockmove_8toN_opaque_raw,(
2410 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2411 		DATA_TYPE *dstdata,int dstmodulo,
2412 		unsigned int colorbase),
2413 {
2414 	DATA_TYPE *end;
2415 
2416 	srcmodulo -= srcwidth;
2417 	dstmodulo -= srcwidth;
2418 
2419 	while (srcheight)
2420 	{
2421 		end = dstdata + srcwidth;
2422 		while (dstdata <= end - 8)
2423 		{
2424 			dstdata[0] = colorbase + srcdata[0];
2425 			dstdata[1] = colorbase + srcdata[1];
2426 			dstdata[2] = colorbase + srcdata[2];
2427 			dstdata[3] = colorbase + srcdata[3];
2428 			dstdata[4] = colorbase + srcdata[4];
2429 			dstdata[5] = colorbase + srcdata[5];
2430 			dstdata[6] = colorbase + srcdata[6];
2431 			dstdata[7] = colorbase + srcdata[7];
2432 			dstdata += 8;
2433 			srcdata += 8;
2434 		}
2435 		while (dstdata < end)
2436 			*(dstdata++) = colorbase + *(srcdata++);
2437 
2438 		srcdata += srcmodulo;
2439 		dstdata += dstmodulo;
2440 		srcheight--;
2441 	}
2442 })
2443 
2444 DECLARE(blockmove_8toN_opaque_raw_flipx,(
2445 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2446 		DATA_TYPE *dstdata,int dstmodulo,
2447 		unsigned int colorbase),
2448 {
2449 	DATA_TYPE *end;
2450 
2451 	srcmodulo += srcwidth;
2452 	dstmodulo -= srcwidth;
2453 	//srcdata += srcwidth-1;
2454 
2455 	while (srcheight)
2456 	{
2457 		end = dstdata + srcwidth;
2458 		while (dstdata <= end - 8)
2459 		{
2460 			srcdata -= 8;
2461 			dstdata[0] = colorbase + srcdata[8];
2462 			dstdata[1] = colorbase + srcdata[7];
2463 			dstdata[2] = colorbase + srcdata[6];
2464 			dstdata[3] = colorbase + srcdata[5];
2465 			dstdata[4] = colorbase + srcdata[4];
2466 			dstdata[5] = colorbase + srcdata[3];
2467 			dstdata[6] = colorbase + srcdata[2];
2468 			dstdata[7] = colorbase + srcdata[1];
2469 			dstdata += 8;
2470 		}
2471 		while (dstdata < end)
2472 			*(dstdata++) = colorbase + *(srcdata--);
2473 
2474 		srcdata += srcmodulo;
2475 		dstdata += dstmodulo;
2476 		srcheight--;
2477 	}
2478 })
2479 
2480 DECLARE(blockmove_8toN_transpen,(
2481 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2482 		DATA_TYPE *dstdata,int dstmodulo,
2483 		const UINT16 *paldata,int transpen),
2484 {
2485 	DATA_TYPE *end;
2486 	int trans4;
2487 	UINT32 *sd4;
2488 
2489 	srcmodulo -= srcwidth;
2490 	dstmodulo -= srcwidth;
2491 
2492 	trans4 = transpen * 0x01010101;
2493 
2494 	while (srcheight)
2495 	{
2496 		end = dstdata + srcwidth;
2497 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
2498 		{
2499 			int col;
2500 
2501 			col = *(srcdata++);
2502 			if (col != transpen) *dstdata = paldata[col];
2503 			dstdata++;
2504 		}
2505 		sd4 = (UINT32 *)srcdata;
2506 		while (dstdata <= end - 4)
2507 		{
2508 			UINT32 col4;
2509 
2510 			if ((col4 = *(sd4++)) != trans4)
2511 			{
2512 				UINT32 xod4;
2513 
2514 				xod4 = col4 ^ trans4;
2515 				if (xod4 & 0x000000ff) dstdata[BL0] = paldata[(col4) & 0xff];
2516 				if (xod4 & 0x0000ff00) dstdata[BL1] = paldata[(col4 >>  8) & 0xff];
2517 				if (xod4 & 0x00ff0000) dstdata[BL2] = paldata[(col4 >> 16) & 0xff];
2518 				if (xod4 & 0xff000000) dstdata[BL3] = paldata[col4 >> 24];
2519 			}
2520 			dstdata += 4;
2521 		}
2522 		srcdata = (UINT8 *)sd4;
2523 		while (dstdata < end)
2524 		{
2525 			int col;
2526 
2527 			col = *(srcdata++);
2528 			if (col != transpen) *dstdata = paldata[col];
2529 			dstdata++;
2530 		}
2531 
2532 		srcdata += srcmodulo;
2533 		dstdata += dstmodulo;
2534 		srcheight--;
2535 	}
2536 })
2537 
2538 DECLARE(blockmove_8toN_transpen_flipx,(
2539 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2540 		DATA_TYPE *dstdata,int dstmodulo,
2541 		const UINT16 *paldata,int transpen),
2542 {
2543 	DATA_TYPE *end;
2544 	int trans4;
2545 	UINT32 *sd4;
2546 
2547 	srcmodulo += srcwidth;
2548 	dstmodulo -= srcwidth;
2549 	//srcdata += srcwidth-1;
2550 	srcdata -= 3;
2551 
2552 	trans4 = transpen * 0x01010101;
2553 
2554 	while (srcheight)
2555 	{
2556 		end = dstdata + srcwidth;
2557 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
2558 		{
2559 			int col;
2560 
2561 			col = srcdata[3];
2562 			srcdata--;
2563 			if (col != transpen) *dstdata = paldata[col];
2564 			dstdata++;
2565 		}
2566 		sd4 = (UINT32 *)srcdata;
2567 		while (dstdata <= end - 4)
2568 		{
2569 			UINT32 col4;
2570 
2571 			if ((col4 = *(sd4--)) != trans4)
2572 			{
2573 				UINT32 xod4;
2574 
2575 				xod4 = col4 ^ trans4;
2576 				if (xod4 & 0xff000000) dstdata[BL0] = paldata[col4 >> 24];
2577 				if (xod4 & 0x00ff0000) dstdata[BL1] = paldata[(col4 >> 16) & 0xff];
2578 				if (xod4 & 0x0000ff00) dstdata[BL2] = paldata[(col4 >>  8) & 0xff];
2579 				if (xod4 & 0x000000ff) dstdata[BL3] = paldata[col4 & 0xff];
2580 			}
2581 			dstdata += 4;
2582 		}
2583 		srcdata = (UINT8 *)sd4;
2584 		while (dstdata < end)
2585 		{
2586 			int col;
2587 
2588 			col = srcdata[3];
2589 			srcdata--;
2590 			if (col != transpen) *dstdata = paldata[col];
2591 			dstdata++;
2592 		}
2593 
2594 		srcdata += srcmodulo;
2595 		dstdata += dstmodulo;
2596 		srcheight--;
2597 	}
2598 })
2599 
2600 DECLARE(blockmove_8toN_transpen_pri,(
2601 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2602 		DATA_TYPE *dstdata,int dstmodulo,
2603 		const UINT16 *paldata,int transpen,UINT8 *pridata,UINT32 pmask),
2604 {
2605 	DATA_TYPE *end;
2606 	int trans4;
2607 	UINT32 *sd4;
2608 
2609 	pmask |= (1<<31);
2610 
2611 	srcmodulo -= srcwidth;
2612 	dstmodulo -= srcwidth;
2613 
2614 	trans4 = transpen * 0x01010101;
2615 
2616 	while (srcheight)
2617 	{
2618 		end = dstdata + srcwidth;
2619 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
2620 		{
2621 			int col;
2622 
2623 			col = *(srcdata++);
2624 			if (col != transpen)
2625 			{
2626 				if (((1 << *pridata) & pmask) == 0)
2627 					*dstdata = paldata[col];
2628 				*pridata = 31;
2629 			}
2630 			dstdata++;
2631 			pridata++;
2632 		}
2633 		sd4 = (UINT32 *)srcdata;
2634 		while (dstdata <= end - 4)
2635 		{
2636 			UINT32 col4;
2637 
2638 			if ((col4 = *(sd4++)) != trans4)
2639 			{
2640 				UINT32 xod4;
2641 
2642 				xod4 = col4 ^ trans4;
2643 				if (xod4 & 0x000000ff)
2644 				{
2645 					if (((1 << pridata[BL0]) & pmask) == 0)
2646 						dstdata[BL0] = paldata[(col4) & 0xff];
2647 					pridata[BL0] = 31;
2648 				}
2649 				if (xod4 & 0x0000ff00)
2650 				{
2651 					if (((1 << pridata[BL1]) & pmask) == 0)
2652 						dstdata[BL1] = paldata[(col4 >>  8) & 0xff];
2653 					pridata[BL1] = 31;
2654 				}
2655 				if (xod4 & 0x00ff0000)
2656 				{
2657 					if (((1 << pridata[BL2]) & pmask) == 0)
2658 						dstdata[BL2] = paldata[(col4 >> 16) & 0xff];
2659 					pridata[BL2] = 31;
2660 				}
2661 				if (xod4 & 0xff000000)
2662 				{
2663 					if (((1 << pridata[BL3]) & pmask) == 0)
2664 						dstdata[BL3] = paldata[col4 >> 24];
2665 					pridata[BL3] = 31;
2666 				}
2667 			}
2668 			dstdata += 4;
2669 			pridata += 4;
2670 		}
2671 		srcdata = (UINT8 *)sd4;
2672 		while (dstdata < end)
2673 		{
2674 			int col;
2675 
2676 			col = *(srcdata++);
2677 			if (col != transpen)
2678 			{
2679 				if (((1 << *pridata) & pmask) == 0)
2680 					*dstdata = paldata[col];
2681 				*pridata = 31;
2682 			}
2683 			dstdata++;
2684 			pridata++;
2685 		}
2686 
2687 		srcdata += srcmodulo;
2688 		dstdata += dstmodulo;
2689 		pridata += dstmodulo;
2690 		srcheight--;
2691 	}
2692 })
2693 
2694 DECLARE(blockmove_8toN_transpen_pri_flipx,(
2695 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2696 		DATA_TYPE *dstdata,int dstmodulo,
2697 		const UINT16 *paldata,int transpen,UINT8 *pridata,UINT32 pmask),
2698 {
2699 	DATA_TYPE *end;
2700 	int trans4;
2701 	UINT32 *sd4;
2702 
2703 	pmask |= (1<<31);
2704 
2705 	srcmodulo += srcwidth;
2706 	dstmodulo -= srcwidth;
2707 	//srcdata += srcwidth-1;
2708 	srcdata -= 3;
2709 
2710 	trans4 = transpen * 0x01010101;
2711 
2712 	while (srcheight)
2713 	{
2714 		end = dstdata + srcwidth;
2715 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
2716 		{
2717 			int col;
2718 
2719 			col = srcdata[3];
2720 			srcdata--;
2721 			if (col != transpen)
2722 			{
2723 				if (((1 << *pridata) & pmask) == 0)
2724 					*dstdata = paldata[col];
2725 				*pridata = 31;
2726 			}
2727 			dstdata++;
2728 			pridata++;
2729 		}
2730 		sd4 = (UINT32 *)srcdata;
2731 		while (dstdata <= end - 4)
2732 		{
2733 			UINT32 col4;
2734 
2735 			if ((col4 = *(sd4--)) != trans4)
2736 			{
2737 				UINT32 xod4;
2738 
2739 				xod4 = col4 ^ trans4;
2740 				if (xod4 & 0xff000000)
2741 				{
2742 					if (((1 << pridata[BL0]) & pmask) == 0)
2743 						dstdata[BL0] = paldata[col4 >> 24];
2744 					pridata[BL0] = 31;
2745 				}
2746 				if (xod4 & 0x00ff0000)
2747 				{
2748 					if (((1 << pridata[BL1]) & pmask) == 0)
2749 						dstdata[BL1] = paldata[(col4 >> 16) & 0xff];
2750 					pridata[BL1] = 31;
2751 				}
2752 				if (xod4 & 0x0000ff00)
2753 				{
2754 					if (((1 << pridata[BL2]) & pmask) == 0)
2755 						dstdata[BL2] = paldata[(col4 >>  8) & 0xff];
2756 					pridata[BL2] = 31;
2757 				}
2758 				if (xod4 & 0x000000ff)
2759 				{
2760 					if (((1 << pridata[BL3]) & pmask) == 0)
2761 						dstdata[BL3] = paldata[col4 & 0xff];
2762 					pridata[BL3] = 31;
2763 				}
2764 			}
2765 			dstdata += 4;
2766 			pridata += 4;
2767 		}
2768 		srcdata = (UINT8 *)sd4;
2769 		while (dstdata < end)
2770 		{
2771 			int col;
2772 
2773 			col = srcdata[3];
2774 			srcdata--;
2775 			if (col != transpen)
2776 			{
2777 				if (((1 << *pridata) & pmask) == 0)
2778 					*dstdata = paldata[col];
2779 				*pridata = 31;
2780 			}
2781 			dstdata++;
2782 			pridata++;
2783 		}
2784 
2785 		srcdata += srcmodulo;
2786 		dstdata += dstmodulo;
2787 		pridata += dstmodulo;
2788 		srcheight--;
2789 	}
2790 })
2791 
2792 DECLARE(blockmove_8toN_transpen_raw,(
2793 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2794 		DATA_TYPE *dstdata,int dstmodulo,
2795 		unsigned int colorbase,int transpen),
2796 {
2797 	DATA_TYPE *end;
2798 	int trans4;
2799 	UINT32 *sd4;
2800 
2801 	srcmodulo -= srcwidth;
2802 	dstmodulo -= srcwidth;
2803 
2804 	trans4 = transpen * 0x01010101;
2805 
2806 	while (srcheight)
2807 	{
2808 		end = dstdata + srcwidth;
2809 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
2810 		{
2811 			int col;
2812 
2813 			col = *(srcdata++);
2814 			if (col != transpen) *dstdata = colorbase + col;
2815 			dstdata++;
2816 		}
2817 		sd4 = (UINT32 *)srcdata;
2818 		while (dstdata <= end - 4)
2819 		{
2820 			UINT32 col4;
2821 
2822 			if ((col4 = *(sd4++)) != trans4)
2823 			{
2824 				UINT32 xod4;
2825 
2826 				xod4 = col4 ^ trans4;
2827 				if (xod4 & 0x000000ff) dstdata[BL0] = colorbase + ((col4) & 0xff);
2828 				if (xod4 & 0x0000ff00) dstdata[BL1] = colorbase + ((col4 >>  8) & 0xff);
2829 				if (xod4 & 0x00ff0000) dstdata[BL2] = colorbase + ((col4 >> 16) & 0xff);
2830 				if (xod4 & 0xff000000) dstdata[BL3] = colorbase + (col4 >> 24);
2831 			}
2832 			dstdata += 4;
2833 		}
2834 		srcdata = (UINT8 *)sd4;
2835 		while (dstdata < end)
2836 		{
2837 			int col;
2838 
2839 			col = *(srcdata++);
2840 			if (col != transpen) *dstdata = colorbase + col;
2841 			dstdata++;
2842 		}
2843 
2844 		srcdata += srcmodulo;
2845 		dstdata += dstmodulo;
2846 		srcheight--;
2847 	}
2848 })
2849 
2850 DECLARE(blockmove_8toN_transpen_raw_flipx,(
2851 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2852 		DATA_TYPE *dstdata,int dstmodulo,
2853 		unsigned int colorbase, int transpen),
2854 {
2855 	DATA_TYPE *end;
2856 	int trans4;
2857 	UINT32 *sd4;
2858 
2859 	srcmodulo += srcwidth;
2860 	dstmodulo -= srcwidth;
2861 	//srcdata += srcwidth-1;
2862 	srcdata -= 3;
2863 
2864 	trans4 = transpen * 0x01010101;
2865 
2866 	while (srcheight)
2867 	{
2868 		end = dstdata + srcwidth;
2869 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
2870 		{
2871 			int col;
2872 
2873 			col = srcdata[3];
2874 			srcdata--;
2875 			if (col != transpen) *dstdata = colorbase + col;
2876 			dstdata++;
2877 		}
2878 		sd4 = (UINT32 *)srcdata;
2879 		while (dstdata <= end - 4)
2880 		{
2881 			UINT32 col4;
2882 
2883 			if ((col4 = *(sd4--)) != trans4)
2884 			{
2885 				UINT32 xod4;
2886 
2887 				xod4 = col4 ^ trans4;
2888 				if (xod4 & 0xff000000) dstdata[BL0] = colorbase + (col4 >> 24);
2889 				if (xod4 & 0x00ff0000) dstdata[BL1] = colorbase + ((col4 >> 16) & 0xff);
2890 				if (xod4 & 0x0000ff00) dstdata[BL2] = colorbase + ((col4 >>  8) & 0xff);
2891 				if (xod4 & 0x000000ff) dstdata[BL3] = colorbase + (col4 & 0xff);
2892 			}
2893 			dstdata += 4;
2894 		}
2895 		srcdata = (UINT8 *)sd4;
2896 		while (dstdata < end)
2897 		{
2898 			int col;
2899 
2900 			col = srcdata[3];
2901 			srcdata--;
2902 			if (col != transpen) *dstdata = colorbase + col;
2903 			dstdata++;
2904 		}
2905 
2906 		srcdata += srcmodulo;
2907 		dstdata += dstmodulo;
2908 		srcheight--;
2909 	}
2910 })
2911 
2912 #define PEN_IS_OPAQUE ((1<<col)&transmask) == 0
2913 
2914 DECLARE(blockmove_8toN_transmask,(
2915 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2916 		DATA_TYPE *dstdata,int dstmodulo,
2917 		const UINT16 *paldata,int transmask),
2918 {
2919 	DATA_TYPE *end;
2920 	UINT32 *sd4;
2921 
2922 	srcmodulo -= srcwidth;
2923 	dstmodulo -= srcwidth;
2924 
2925 	while (srcheight)
2926 	{
2927 		end = dstdata + srcwidth;
2928 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
2929 		{
2930 			int col;
2931 
2932 			col = *(srcdata++);
2933 			if (PEN_IS_OPAQUE) *dstdata = paldata[col];
2934 			dstdata++;
2935 		}
2936 		sd4 = (UINT32 *)srcdata;
2937 		while (dstdata <= end - 4)
2938 		{
2939 			int col;
2940 			UINT32 col4;
2941 
2942 			col4 = *(sd4++);
2943 			col = (col4 >>  0) & 0xff;
2944 			if (PEN_IS_OPAQUE) dstdata[BL0] = paldata[col];
2945 			col = (col4 >>  8) & 0xff;
2946 			if (PEN_IS_OPAQUE) dstdata[BL1] = paldata[col];
2947 			col = (col4 >> 16) & 0xff;
2948 			if (PEN_IS_OPAQUE) dstdata[BL2] = paldata[col];
2949 			col = (col4 >> 24) & 0xff;
2950 			if (PEN_IS_OPAQUE) dstdata[BL3] = paldata[col];
2951 			dstdata += 4;
2952 		}
2953 		srcdata = (UINT8 *)sd4;
2954 		while (dstdata < end)
2955 		{
2956 			int col;
2957 
2958 			col = *(srcdata++);
2959 			if (PEN_IS_OPAQUE) *dstdata = paldata[col];
2960 			dstdata++;
2961 		}
2962 
2963 		srcdata += srcmodulo;
2964 		dstdata += dstmodulo;
2965 		srcheight--;
2966 	}
2967 })
2968 
2969 DECLARE(blockmove_8toN_transmask_flipx,(
2970 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
2971 		DATA_TYPE *dstdata,int dstmodulo,
2972 		const UINT16 *paldata,int transmask),
2973 {
2974 	DATA_TYPE *end;
2975 	UINT32 *sd4;
2976 
2977 	srcmodulo += srcwidth;
2978 	dstmodulo -= srcwidth;
2979 	//srcdata += srcwidth-1;
2980 	srcdata -= 3;
2981 
2982 	while (srcheight)
2983 	{
2984 		end = dstdata + srcwidth;
2985 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
2986 		{
2987 			int col;
2988 
2989 			col = srcdata[3];
2990 			srcdata--;
2991 			if (PEN_IS_OPAQUE) *dstdata = paldata[col];
2992 			dstdata++;
2993 		}
2994 		sd4 = (UINT32 *)srcdata;
2995 		while (dstdata <= end - 4)
2996 		{
2997 			int col;
2998 			UINT32 col4;
2999 
3000 			col4 = *(sd4--);
3001 			col = (col4 >> 24) & 0xff;
3002 			if (PEN_IS_OPAQUE) dstdata[BL0] = paldata[col];
3003 			col = (col4 >> 16) & 0xff;
3004 			if (PEN_IS_OPAQUE) dstdata[BL1] = paldata[col];
3005 			col = (col4 >>  8) & 0xff;
3006 			if (PEN_IS_OPAQUE) dstdata[BL2] = paldata[col];
3007 			col = (col4 >>  0) & 0xff;
3008 			if (PEN_IS_OPAQUE) dstdata[BL3] = paldata[col];
3009 			dstdata += 4;
3010 		}
3011 		srcdata = (UINT8 *)sd4;
3012 		while (dstdata < end)
3013 		{
3014 			int col;
3015 
3016 			col = srcdata[3];
3017 			srcdata--;
3018 			if (PEN_IS_OPAQUE) *dstdata = paldata[col];
3019 			dstdata++;
3020 		}
3021 
3022 		srcdata += srcmodulo;
3023 		dstdata += dstmodulo;
3024 		srcheight--;
3025 	}
3026 })
3027 
3028 DECLARE(blockmove_8toN_transmask_pri,(
3029 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3030 		DATA_TYPE *dstdata,int dstmodulo,
3031 		const UINT16 *paldata,int transmask,UINT8 *pridata,UINT32 pmask),
3032 {
3033 	DATA_TYPE *end;
3034 	UINT32 *sd4;
3035 
3036 	pmask |= (1<<31);
3037 
3038 	srcmodulo -= srcwidth;
3039 	dstmodulo -= srcwidth;
3040 
3041 	while (srcheight)
3042 	{
3043 		end = dstdata + srcwidth;
3044 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
3045 		{
3046 			int col;
3047 
3048 			col = *(srcdata++);
3049 			if (PEN_IS_OPAQUE)
3050 			{
3051 				if (((1 << *pridata) & pmask) == 0)
3052 					*dstdata = paldata[col];
3053 				*pridata = 31;
3054 			}
3055 			dstdata++;
3056 			pridata++;
3057 		}
3058 		sd4 = (UINT32 *)srcdata;
3059 		while (dstdata <= end - 4)
3060 		{
3061 			int col;
3062 			UINT32 col4;
3063 
3064 			col4 = *(sd4++);
3065 			col = (col4 >>  0) & 0xff;
3066 			if (PEN_IS_OPAQUE)
3067 			{
3068 				if (((1 << pridata[BL0]) & pmask) == 0)
3069 					dstdata[BL0] = paldata[col];
3070 				pridata[BL0] = 31;
3071 			}
3072 			col = (col4 >>  8) & 0xff;
3073 			if (PEN_IS_OPAQUE)
3074 			{
3075 				if (((1 << pridata[BL1]) & pmask) == 0)
3076 					dstdata[BL1] = paldata[col];
3077 				pridata[BL1] = 31;
3078 			}
3079 			col = (col4 >> 16) & 0xff;
3080 			if (PEN_IS_OPAQUE)
3081 			{
3082 				if (((1 << pridata[BL2]) & pmask) == 0)
3083 					dstdata[BL2] = paldata[col];
3084 				pridata[BL2] = 31;
3085 			}
3086 			col = (col4 >> 24) & 0xff;
3087 			if (PEN_IS_OPAQUE)
3088 			{
3089 				if (((1 << pridata[BL3]) & pmask) == 0)
3090 					dstdata[BL3] = paldata[col];
3091 				pridata[BL3] = 31;
3092 			}
3093 			dstdata += 4;
3094 			pridata += 4;
3095 		}
3096 		srcdata = (UINT8 *)sd4;
3097 		while (dstdata < end)
3098 		{
3099 			int col;
3100 
3101 			col = *(srcdata++);
3102 			if (PEN_IS_OPAQUE)
3103 			{
3104 				if (((1 << *pridata) & pmask) == 0)
3105 					*dstdata = paldata[col];
3106 				*pridata = 31;
3107 			}
3108 			dstdata++;
3109 			pridata++;
3110 		}
3111 
3112 		srcdata += srcmodulo;
3113 		dstdata += dstmodulo;
3114 		pridata += dstmodulo;
3115 		srcheight--;
3116 	}
3117 })
3118 
3119 DECLARE(blockmove_8toN_transmask_pri_flipx,(
3120 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3121 		DATA_TYPE *dstdata,int dstmodulo,
3122 		const UINT16 *paldata,int transmask,UINT8 *pridata,UINT32 pmask),
3123 {
3124 	DATA_TYPE *end;
3125 	UINT32 *sd4;
3126 
3127 	pmask |= (1<<31);
3128 
3129 	srcmodulo += srcwidth;
3130 	dstmodulo -= srcwidth;
3131 	//srcdata += srcwidth-1;
3132 	srcdata -= 3;
3133 
3134 	while (srcheight)
3135 	{
3136 		end = dstdata + srcwidth;
3137 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
3138 		{
3139 			int col;
3140 
3141 			col = srcdata[3];
3142 			srcdata--;
3143 			if (PEN_IS_OPAQUE)
3144 			{
3145 				if (((1 << *pridata) & pmask) == 0)
3146 					*dstdata = paldata[col];
3147 				*pridata = 31;
3148 			}
3149 			dstdata++;
3150 			pridata++;
3151 		}
3152 		sd4 = (UINT32 *)srcdata;
3153 		while (dstdata <= end - 4)
3154 		{
3155 			int col;
3156 			UINT32 col4;
3157 
3158 			col4 = *(sd4--);
3159 			col = (col4 >> 24) & 0xff;
3160 			if (PEN_IS_OPAQUE)
3161 			{
3162 				if (((1 << pridata[BL0]) & pmask) == 0)
3163 					dstdata[BL0] = paldata[col];
3164 				pridata[BL0] = 31;
3165 			}
3166 			col = (col4 >> 16) & 0xff;
3167 			if (PEN_IS_OPAQUE)
3168 			{
3169 				if (((1 << pridata[BL1]) & pmask) == 0)
3170 					dstdata[BL1] = paldata[col];
3171 				pridata[BL1] = 31;
3172 			}
3173 			col = (col4 >>  8) & 0xff;
3174 			if (PEN_IS_OPAQUE)
3175 			{
3176 				if (((1 << pridata[BL2]) & pmask) == 0)
3177 					dstdata[BL2] = paldata[col];
3178 				pridata[BL2] = 31;
3179 			}
3180 			col = (col4 >>  0) & 0xff;
3181 			if (PEN_IS_OPAQUE)
3182 			{
3183 				if (((1 << pridata[BL3]) & pmask) == 0)
3184 					dstdata[BL3] = paldata[col];
3185 				pridata[BL3] = 31;
3186 			}
3187 			dstdata += 4;
3188 			pridata += 4;
3189 		}
3190 		srcdata = (UINT8 *)sd4;
3191 		while (dstdata < end)
3192 		{
3193 			int col;
3194 
3195 			col = srcdata[3];
3196 			srcdata--;
3197 			if (PEN_IS_OPAQUE)
3198 			{
3199 				if (((1 << *pridata) & pmask) == 0)
3200 					*dstdata = paldata[col];
3201 				*pridata = 31;
3202 			}
3203 			dstdata++;
3204 			pridata++;
3205 		}
3206 
3207 		srcdata += srcmodulo;
3208 		dstdata += dstmodulo;
3209 		pridata += dstmodulo;
3210 		srcheight--;
3211 	}
3212 })
3213 
3214 DECLARE(blockmove_8toN_transmask_raw,(
3215 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3216 		DATA_TYPE *dstdata,int dstmodulo,
3217 		unsigned int colorbase,int transmask),
3218 {
3219 	DATA_TYPE *end;
3220 	UINT32 *sd4;
3221 
3222 	srcmodulo -= srcwidth;
3223 	dstmodulo -= srcwidth;
3224 
3225 	while (srcheight)
3226 	{
3227 		end = dstdata + srcwidth;
3228 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
3229 		{
3230 			int col;
3231 
3232 			col = *(srcdata++);
3233 			if (PEN_IS_OPAQUE) *dstdata = colorbase + col;
3234 			dstdata++;
3235 		}
3236 		sd4 = (UINT32 *)srcdata;
3237 		while (dstdata <= end - 4)
3238 		{
3239 			int col;
3240 			UINT32 col4;
3241 
3242 			col4 = *(sd4++);
3243 			col = (col4 >>  0) & 0xff;
3244 			if (PEN_IS_OPAQUE) dstdata[BL0] = colorbase + col;
3245 			col = (col4 >>  8) & 0xff;
3246 			if (PEN_IS_OPAQUE) dstdata[BL1] = colorbase + col;
3247 			col = (col4 >> 16) & 0xff;
3248 			if (PEN_IS_OPAQUE) dstdata[BL2] = colorbase + col;
3249 			col = (col4 >> 24) & 0xff;
3250 			if (PEN_IS_OPAQUE) dstdata[BL3] = colorbase + col;
3251 			dstdata += 4;
3252 		}
3253 		srcdata = (UINT8 *)sd4;
3254 		while (dstdata < end)
3255 		{
3256 			int col;
3257 
3258 			col = *(srcdata++);
3259 			if (PEN_IS_OPAQUE) *dstdata = colorbase + col;
3260 			dstdata++;
3261 		}
3262 
3263 		srcdata += srcmodulo;
3264 		dstdata += dstmodulo;
3265 		srcheight--;
3266 	}
3267 })
3268 
3269 DECLARE(blockmove_8toN_transmask_raw_flipx,(
3270 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3271 		DATA_TYPE *dstdata,int dstmodulo,
3272 		unsigned int colorbase,int transmask),
3273 {
3274 	DATA_TYPE *end;
3275 	UINT32 *sd4;
3276 
3277 	srcmodulo += srcwidth;
3278 	dstmodulo -= srcwidth;
3279 	//srcdata += srcwidth-1;
3280 	srcdata -= 3;
3281 
3282 	while (srcheight)
3283 	{
3284 		end = dstdata + srcwidth;
3285 		while (((long)srcdata & 3) && dstdata < end)	/* longword align */
3286 		{
3287 			int col;
3288 
3289 			col = srcdata[3];
3290 			srcdata--;
3291 			if (PEN_IS_OPAQUE) *dstdata = colorbase + col;
3292 			dstdata++;
3293 		}
3294 		sd4 = (UINT32 *)srcdata;
3295 		while (dstdata <= end - 4)
3296 		{
3297 			int col;
3298 			UINT32 col4;
3299 
3300 			col4 = *(sd4--);
3301 			col = (col4 >> 24) & 0xff;
3302 			if (PEN_IS_OPAQUE) dstdata[BL0] = colorbase + col;
3303 			col = (col4 >> 16) & 0xff;
3304 			if (PEN_IS_OPAQUE) dstdata[BL1] = colorbase + col;
3305 			col = (col4 >>  8) & 0xff;
3306 			if (PEN_IS_OPAQUE) dstdata[BL2] = colorbase + col;
3307 			col = (col4 >>  0) & 0xff;
3308 			if (PEN_IS_OPAQUE) dstdata[BL3] = colorbase + col;
3309 			dstdata += 4;
3310 		}
3311 		srcdata = (UINT8 *)sd4;
3312 		while (dstdata < end)
3313 		{
3314 			int col;
3315 
3316 			col = srcdata[3];
3317 			srcdata--;
3318 			if (PEN_IS_OPAQUE) *dstdata = colorbase + col;
3319 			dstdata++;
3320 		}
3321 
3322 		srcdata += srcmodulo;
3323 		dstdata += dstmodulo;
3324 		srcheight--;
3325 	}
3326 })
3327 
3328 
3329 DECLARE(blockmove_8toN_transcolor,(
3330 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3331 		DATA_TYPE *dstdata,int dstmodulo,
3332 		const UINT16 *paldata,int transcolor),
3333 {
3334 	DATA_TYPE *end;
3335 	const UINT16 *lookupdata = Machine->game_colortable + (paldata - Machine->remapped_colortable);
3336 
3337 	srcmodulo -= srcwidth;
3338 	dstmodulo -= srcwidth;
3339 
3340 	while (srcheight)
3341 	{
3342 		end = dstdata + srcwidth;
3343 		while (dstdata < end)
3344 		{
3345 			if (lookupdata[*srcdata] != transcolor) *dstdata = paldata[*srcdata];
3346 			srcdata++;
3347 			dstdata++;
3348 		}
3349 
3350 		srcdata += srcmodulo;
3351 		dstdata += dstmodulo;
3352 		srcheight--;
3353 	}
3354 })
3355 
3356 DECLARE(blockmove_8toN_transcolor_flipx,(
3357 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3358 		DATA_TYPE *dstdata,int dstmodulo,
3359 		const UINT16 *paldata,int transcolor),
3360 {
3361 	DATA_TYPE *end;
3362 	const UINT16 *lookupdata = Machine->game_colortable + (paldata - Machine->remapped_colortable);
3363 
3364 	srcmodulo += srcwidth;
3365 	dstmodulo -= srcwidth;
3366 	//srcdata += srcwidth-1;
3367 
3368 	while (srcheight)
3369 	{
3370 		end = dstdata + srcwidth;
3371 		while (dstdata < end)
3372 		{
3373 			if (lookupdata[*srcdata] != transcolor) *dstdata = paldata[*srcdata];
3374 			srcdata--;
3375 			dstdata++;
3376 		}
3377 
3378 		srcdata += srcmodulo;
3379 		dstdata += dstmodulo;
3380 		srcheight--;
3381 	}
3382 })
3383 
3384 DECLARE(blockmove_8toN_transcolor_pri,(
3385 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3386 		DATA_TYPE *dstdata,int dstmodulo,
3387 		const UINT16 *paldata,int transcolor,UINT8 *pridata,UINT32 pmask),
3388 {
3389 	DATA_TYPE *end;
3390 	const UINT16 *lookupdata = Machine->game_colortable + (paldata - Machine->remapped_colortable);
3391 
3392 	pmask |= (1<<31);
3393 
3394 	srcmodulo -= srcwidth;
3395 	dstmodulo -= srcwidth;
3396 
3397 	while (srcheight)
3398 	{
3399 		end = dstdata + srcwidth;
3400 		while (dstdata < end)
3401 		{
3402 			if (lookupdata[*srcdata] != transcolor)
3403 			{
3404 				if (((1 << *pridata) & pmask) == 0)
3405 					*dstdata = paldata[*srcdata];
3406 				*pridata = 31;
3407 			}
3408 			srcdata++;
3409 			dstdata++;
3410 			pridata++;
3411 		}
3412 
3413 		srcdata += srcmodulo;
3414 		dstdata += dstmodulo;
3415 		pridata += dstmodulo;
3416 		srcheight--;
3417 	}
3418 })
3419 
3420 DECLARE(blockmove_8toN_transcolor_pri_flipx,(
3421 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3422 		DATA_TYPE *dstdata,int dstmodulo,
3423 		const UINT16 *paldata,int transcolor,UINT8 *pridata,UINT32 pmask),
3424 {
3425 	DATA_TYPE *end;
3426 	const UINT16 *lookupdata = Machine->game_colortable + (paldata - Machine->remapped_colortable);
3427 
3428 	pmask |= (1<<31);
3429 
3430 	srcmodulo += srcwidth;
3431 	dstmodulo -= srcwidth;
3432 	//srcdata += srcwidth-1;
3433 
3434 	while (srcheight)
3435 	{
3436 		end = dstdata + srcwidth;
3437 		while (dstdata < end)
3438 		{
3439 			if (lookupdata[*srcdata] != transcolor)
3440 			{
3441 				if (((1 << *pridata) & pmask) == 0)
3442 					*dstdata = paldata[*srcdata];
3443 				*pridata = 31;
3444 			}
3445 			srcdata--;
3446 			dstdata++;
3447 			pridata++;
3448 		}
3449 
3450 		srcdata += srcmodulo;
3451 		dstdata += dstmodulo;
3452 		pridata += dstmodulo;
3453 		srcheight--;
3454 	}
3455 })
3456 
3457 
3458 DECLARE(blockmove_8toN_transthrough,(
3459 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3460 		DATA_TYPE *dstdata,int dstmodulo,
3461 		const UINT16 *paldata,int transcolor),
3462 {
3463 	DATA_TYPE *end;
3464 
3465 	srcmodulo -= srcwidth;
3466 	dstmodulo -= srcwidth;
3467 
3468 	while (srcheight)
3469 	{
3470 		end = dstdata + srcwidth;
3471 		while (dstdata < end)
3472 		{
3473 			if (*dstdata == transcolor) *dstdata = paldata[*srcdata];
3474 			srcdata++;
3475 			dstdata++;
3476 		}
3477 
3478 		srcdata += srcmodulo;
3479 		dstdata += dstmodulo;
3480 		srcheight--;
3481 	}
3482 })
3483 
3484 DECLARE(blockmove_8toN_transthrough_flipx,(
3485 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3486 		DATA_TYPE *dstdata,int dstmodulo,
3487 		const UINT16 *paldata,int transcolor),
3488 {
3489 	DATA_TYPE *end;
3490 
3491 	srcmodulo += srcwidth;
3492 	dstmodulo -= srcwidth;
3493 	//srcdata += srcwidth-1;
3494 
3495 	while (srcheight)
3496 	{
3497 		end = dstdata + srcwidth;
3498 		while (dstdata < end)
3499 		{
3500 			if (*dstdata == transcolor) *dstdata = paldata[*srcdata];
3501 			srcdata--;
3502 			dstdata++;
3503 		}
3504 
3505 		srcdata += srcmodulo;
3506 		dstdata += dstmodulo;
3507 		srcheight--;
3508 	}
3509 })
3510 
3511 DECLARE(blockmove_8toN_transthrough_raw,(
3512 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3513 		DATA_TYPE *dstdata,int dstmodulo,
3514 		unsigned int colorbase,int transcolor),
3515 {
3516 	DATA_TYPE *end;
3517 
3518 	srcmodulo -= srcwidth;
3519 	dstmodulo -= srcwidth;
3520 
3521 	while (srcheight)
3522 	{
3523 		end = dstdata + srcwidth;
3524 		while (dstdata < end)
3525 		{
3526 			if (*dstdata == transcolor) *dstdata = colorbase + *srcdata;
3527 			srcdata++;
3528 			dstdata++;
3529 		}
3530 
3531 		srcdata += srcmodulo;
3532 		dstdata += dstmodulo;
3533 		srcheight--;
3534 	}
3535 })
3536 
3537 DECLARE(blockmove_8toN_transthrough_raw_flipx,(
3538 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3539 		DATA_TYPE *dstdata,int dstmodulo,
3540 		unsigned int colorbase,int transcolor),
3541 {
3542 	DATA_TYPE *end;
3543 
3544 	srcmodulo += srcwidth;
3545 	dstmodulo -= srcwidth;
3546 	//srcdata += srcwidth-1;
3547 
3548 	while (srcheight)
3549 	{
3550 		end = dstdata + srcwidth;
3551 		while (dstdata < end)
3552 		{
3553 			if (*dstdata == transcolor) *dstdata = colorbase + *srcdata;
3554 			srcdata--;
3555 			dstdata++;
3556 		}
3557 
3558 		srcdata += srcmodulo;
3559 		dstdata += dstmodulo;
3560 		srcheight--;
3561 	}
3562 })
3563 
3564 DECLARE(blockmove_8toN_pen_table,(
3565 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3566 		DATA_TYPE *dstdata,int dstmodulo,
3567 		const UINT16 *paldata,int transcolor),
3568 {
3569 	DATA_TYPE *end;
3570 
3571 	srcmodulo -= srcwidth;
3572 	dstmodulo -= srcwidth;
3573 
3574 	while (srcheight)
3575 	{
3576 		end = dstdata + srcwidth;
3577 		while (dstdata < end)
3578 		{
3579 			int col;
3580 
3581 			col = *(srcdata++);
3582 			if (col != transcolor)
3583 			{
3584 				switch(gfx_drawmode_table[col])
3585 				{
3586 				case DRAWMODE_SOURCE:
3587 					*dstdata = paldata[col];
3588 					break;
3589 				case DRAWMODE_SHADOW:
3590 					*dstdata = palette_shadow_table[*dstdata];
3591 					break;
3592 				}
3593 			}
3594 			dstdata++;
3595 		}
3596 
3597 		srcdata += srcmodulo;
3598 		dstdata += dstmodulo;
3599 		srcheight--;
3600 	}
3601 })
3602 
3603 DECLARE(blockmove_8toN_pen_table_flipx,(
3604 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3605 		DATA_TYPE *dstdata,int dstmodulo,
3606 		const UINT16 *paldata,int transcolor),
3607 {
3608 	DATA_TYPE *end;
3609 
3610 	srcmodulo += srcwidth;
3611 	dstmodulo -= srcwidth;
3612 	//srcdata += srcwidth-1;
3613 
3614 	while (srcheight)
3615 	{
3616 		end = dstdata + srcwidth;
3617 		while (dstdata < end)
3618 		{
3619 			int col;
3620 
3621 			col = *(srcdata--);
3622 			if (col != transcolor)
3623 			{
3624 				switch(gfx_drawmode_table[col])
3625 				{
3626 				case DRAWMODE_SOURCE:
3627 					*dstdata = paldata[col];
3628 					break;
3629 				case DRAWMODE_SHADOW:
3630 					*dstdata = palette_shadow_table[*dstdata];
3631 					break;
3632 				}
3633 			}
3634 			dstdata++;
3635 		}
3636 
3637 		srcdata += srcmodulo;
3638 		dstdata += dstmodulo;
3639 		srcheight--;
3640 	}
3641 })
3642 
3643 DECLARE(blockmove_8toN_pen_table_raw,(
3644 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3645 		DATA_TYPE *dstdata,int dstmodulo,
3646 		unsigned int colorbase,int transcolor),
3647 {
3648 	DATA_TYPE *end;
3649 
3650 	srcmodulo -= srcwidth;
3651 	dstmodulo -= srcwidth;
3652 
3653 	while (srcheight)
3654 	{
3655 		end = dstdata + srcwidth;
3656 		while (dstdata < end)
3657 		{
3658 			int col;
3659 
3660 			col = *(srcdata++);
3661 			if (col != transcolor)
3662 			{
3663 				switch(gfx_drawmode_table[col])
3664 				{
3665 				case DRAWMODE_SOURCE:
3666 					*dstdata = colorbase + col;
3667 					break;
3668 				case DRAWMODE_SHADOW:
3669 					*dstdata = palette_shadow_table[*dstdata];
3670 					break;
3671 				}
3672 			}
3673 			dstdata++;
3674 		}
3675 
3676 		srcdata += srcmodulo;
3677 		dstdata += dstmodulo;
3678 		srcheight--;
3679 	}
3680 })
3681 
3682 DECLARE(blockmove_8toN_pen_table_raw_flipx,(
3683 		const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
3684 		DATA_TYPE *dstdata,int dstmodulo,
3685 		unsigned int colorbase,int transcolor),
3686 {
3687 	DATA_TYPE *end;
3688 
3689 	srcmodulo += srcwidth;
3690 	dstmodulo -= srcwidth;
3691 	//srcdata += srcwidth-1;
3692 
3693 	while (srcheight)
3694 	{
3695 		end = dstdata + srcwidth;
3696 		while (dstdata < end)
3697 		{
3698 			int col;
3699 
3700 			col = *(srcdata--);
3701 			if (col != transcolor)
3702 			{
3703 				switch(gfx_drawmode_table[col])
3704 				{
3705 				case DRAWMODE_SOURCE:
3706 					*dstdata = colorbase + col;
3707 					break;
3708 				case DRAWMODE_SHADOW:
3709 					*dstdata = palette_shadow_table[*dstdata];
3710 					break;
3711 				}
3712 			}
3713 			dstdata++;
3714 		}
3715 
3716 		srcdata += srcmodulo;
3717 		dstdata += dstmodulo;
3718 		srcheight--;
3719 	}
3720 })
3721 
3722 DECLARE(blockmove_NtoN_opaque_noremap,(
3723 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
3724 		DATA_TYPE *dstdata,int dstmodulo),
3725 {
3726 	while (srcheight)
3727 	{
3728 		memcpy(dstdata,srcdata,srcwidth * sizeof(DATA_TYPE));
3729 		srcdata += srcmodulo;
3730 		dstdata += dstmodulo;
3731 		srcheight--;
3732 	}
3733 })
3734 
3735 DECLARE(blockmove_NtoN_opaque_noremap_flipx,(
3736 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
3737 		DATA_TYPE *dstdata,int dstmodulo),
3738 {
3739 	DATA_TYPE *end;
3740 
3741 	srcmodulo += srcwidth;
3742 	dstmodulo -= srcwidth;
3743 	//srcdata += srcwidth-1;
3744 
3745 	while (srcheight)
3746 	{
3747 		end = dstdata + srcwidth;
3748 		while (dstdata <= end - 8)
3749 		{
3750 			srcdata -= 8;
3751 			dstdata[0] = srcdata[8];
3752 			dstdata[1] = srcdata[7];
3753 			dstdata[2] = srcdata[6];
3754 			dstdata[3] = srcdata[5];
3755 			dstdata[4] = srcdata[4];
3756 			dstdata[5] = srcdata[3];
3757 			dstdata[6] = srcdata[2];
3758 			dstdata[7] = srcdata[1];
3759 			dstdata += 8;
3760 		}
3761 		while (dstdata < end)
3762 			*(dstdata++) = *(srcdata--);
3763 
3764 		srcdata += srcmodulo;
3765 		dstdata += dstmodulo;
3766 		srcheight--;
3767 	}
3768 })
3769 
3770 DECLARE(blockmove_NtoN_opaque_remap,(
3771 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
3772 		DATA_TYPE *dstdata,int dstmodulo,
3773 		const UINT16 *paldata),
3774 {
3775 	DATA_TYPE *end;
3776 
3777 	srcmodulo -= srcwidth;
3778 	dstmodulo -= srcwidth;
3779 
3780 	while (srcheight)
3781 	{
3782 		end = dstdata + srcwidth;
3783 		while (dstdata <= end - 8)
3784 		{
3785 			dstdata[0] = paldata[srcdata[0]];
3786 			dstdata[1] = paldata[srcdata[1]];
3787 			dstdata[2] = paldata[srcdata[2]];
3788 			dstdata[3] = paldata[srcdata[3]];
3789 			dstdata[4] = paldata[srcdata[4]];
3790 			dstdata[5] = paldata[srcdata[5]];
3791 			dstdata[6] = paldata[srcdata[6]];
3792 			dstdata[7] = paldata[srcdata[7]];
3793 			dstdata += 8;
3794 			srcdata += 8;
3795 		}
3796 		while (dstdata < end)
3797 			*(dstdata++) = paldata[*(srcdata++)];
3798 
3799 		srcdata += srcmodulo;
3800 		dstdata += dstmodulo;
3801 		srcheight--;
3802 	}
3803 })
3804 
3805 DECLARE(blockmove_NtoN_opaque_remap_flipx,(
3806 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
3807 		DATA_TYPE *dstdata,int dstmodulo,
3808 		const UINT16 *paldata),
3809 {
3810 	DATA_TYPE *end;
3811 
3812 	srcmodulo += srcwidth;
3813 	dstmodulo -= srcwidth;
3814 	//srcdata += srcwidth-1;
3815 
3816 	while (srcheight)
3817 	{
3818 		end = dstdata + srcwidth;
3819 		while (dstdata <= end - 8)
3820 		{
3821 			srcdata -= 8;
3822 			dstdata[0] = paldata[srcdata[8]];
3823 			dstdata[1] = paldata[srcdata[7]];
3824 			dstdata[2] = paldata[srcdata[6]];
3825 			dstdata[3] = paldata[srcdata[5]];
3826 			dstdata[4] = paldata[srcdata[4]];
3827 			dstdata[5] = paldata[srcdata[3]];
3828 			dstdata[6] = paldata[srcdata[2]];
3829 			dstdata[7] = paldata[srcdata[1]];
3830 			dstdata += 8;
3831 		}
3832 		while (dstdata < end)
3833 			*(dstdata++) = paldata[*(srcdata--)];
3834 
3835 		srcdata += srcmodulo;
3836 		dstdata += dstmodulo;
3837 		srcheight--;
3838 	}
3839 })
3840 
3841 
3842 DECLARE(blockmove_NtoN_transthrough_noremap,(
3843 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
3844 		DATA_TYPE *dstdata,int dstmodulo,
3845 		int transcolor),
3846 {
3847 	DATA_TYPE *end;
3848 
3849 	srcmodulo -= srcwidth;
3850 	dstmodulo -= srcwidth;
3851 
3852 	while (srcheight)
3853 	{
3854 		end = dstdata + srcwidth;
3855 		while (dstdata < end)
3856 		{
3857 			if (*dstdata == transcolor) *dstdata = *srcdata;
3858 			srcdata++;
3859 			dstdata++;
3860 		}
3861 
3862 		srcdata += srcmodulo;
3863 		dstdata += dstmodulo;
3864 		srcheight--;
3865 	}
3866 })
3867 
3868 DECLARE(blockmove_NtoN_transthrough_noremap_flipx,(
3869 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
3870 		DATA_TYPE *dstdata,int dstmodulo,
3871 		int transcolor),
3872 {
3873 	DATA_TYPE *end;
3874 
3875 	srcmodulo += srcwidth;
3876 	dstmodulo -= srcwidth;
3877 	//srcdata += srcwidth-1;
3878 
3879 	while (srcheight)
3880 	{
3881 		end = dstdata + srcwidth;
3882 		while (dstdata < end)
3883 		{
3884 			if (*dstdata == transcolor) *dstdata = *srcdata;
3885 			srcdata--;
3886 			dstdata++;
3887 		}
3888 
3889 		srcdata += srcmodulo;
3890 		dstdata += dstmodulo;
3891 		srcheight--;
3892 	}
3893 })
3894 
3895 DECLARE(blockmove_NtoN_blend_noremap,(
3896 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
3897 		DATA_TYPE *dstdata,int dstmodulo,
3898 		int srcshift),
3899 {
3900 	DATA_TYPE *end;
3901 
3902 	srcmodulo -= srcwidth;
3903 	dstmodulo -= srcwidth;
3904 
3905 	while (srcheight)
3906 	{
3907 		end = dstdata + srcwidth;
3908 		while (dstdata <= end - 8)
3909 		{
3910 			dstdata[0] |= srcdata[0] << srcshift;
3911 			dstdata[1] |= srcdata[1] << srcshift;
3912 			dstdata[2] |= srcdata[2] << srcshift;
3913 			dstdata[3] |= srcdata[3] << srcshift;
3914 			dstdata[4] |= srcdata[4] << srcshift;
3915 			dstdata[5] |= srcdata[5] << srcshift;
3916 			dstdata[6] |= srcdata[6] << srcshift;
3917 			dstdata[7] |= srcdata[7] << srcshift;
3918 			dstdata += 8;
3919 			srcdata += 8;
3920 		}
3921 		while (dstdata < end)
3922 			*(dstdata++) |= *(srcdata++) << srcshift;
3923 
3924 		srcdata += srcmodulo;
3925 		dstdata += dstmodulo;
3926 		srcheight--;
3927 	}
3928 })
3929 
3930 DECLARE(blockmove_NtoN_blend_noremap_flipx,(
3931 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
3932 		DATA_TYPE *dstdata,int dstmodulo,
3933 		int srcshift),
3934 {
3935 	DATA_TYPE *end;
3936 
3937 	srcmodulo += srcwidth;
3938 	dstmodulo -= srcwidth;
3939 	//srcdata += srcwidth-1;
3940 
3941 	while (srcheight)
3942 	{
3943 		end = dstdata + srcwidth;
3944 		while (dstdata <= end - 8)
3945 		{
3946 			srcdata -= 8;
3947 			dstdata[0] |= srcdata[8] << srcshift;
3948 			dstdata[1] |= srcdata[7] << srcshift;
3949 			dstdata[2] |= srcdata[6] << srcshift;
3950 			dstdata[3] |= srcdata[5] << srcshift;
3951 			dstdata[4] |= srcdata[4] << srcshift;
3952 			dstdata[5] |= srcdata[3] << srcshift;
3953 			dstdata[6] |= srcdata[2] << srcshift;
3954 			dstdata[7] |= srcdata[1] << srcshift;
3955 			dstdata += 8;
3956 		}
3957 		while (dstdata < end)
3958 			*(dstdata++) |= *(srcdata--) << srcshift;
3959 
3960 		srcdata += srcmodulo;
3961 		dstdata += dstmodulo;
3962 		srcheight--;
3963 	}
3964 })
3965 
3966 DECLARE(blockmove_NtoN_blend_remap,(
3967 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
3968 		DATA_TYPE *dstdata,int dstmodulo,
3969 		const UINT16 *paldata,int srcshift),
3970 {
3971 	DATA_TYPE *end;
3972 
3973 	srcmodulo -= srcwidth;
3974 	dstmodulo -= srcwidth;
3975 
3976 	while (srcheight)
3977 	{
3978 		end = dstdata + srcwidth;
3979 		while (dstdata <= end - 8)
3980 		{
3981 			dstdata[0] = paldata[dstdata[0] | (srcdata[0] << srcshift)];
3982 			dstdata[1] = paldata[dstdata[1] | (srcdata[1] << srcshift)];
3983 			dstdata[2] = paldata[dstdata[2] | (srcdata[2] << srcshift)];
3984 			dstdata[3] = paldata[dstdata[3] | (srcdata[3] << srcshift)];
3985 			dstdata[4] = paldata[dstdata[4] | (srcdata[4] << srcshift)];
3986 			dstdata[5] = paldata[dstdata[5] | (srcdata[5] << srcshift)];
3987 			dstdata[6] = paldata[dstdata[6] | (srcdata[6] << srcshift)];
3988 			dstdata[7] = paldata[dstdata[7] | (srcdata[7] << srcshift)];
3989 			dstdata += 8;
3990 			srcdata += 8;
3991 		}
3992 		while (dstdata < end)
3993 		{
3994 			*dstdata = paldata[*dstdata | (*(srcdata++) << srcshift)];
3995 			dstdata++;
3996 		}
3997 
3998 		srcdata += srcmodulo;
3999 		dstdata += dstmodulo;
4000 		srcheight--;
4001 	}
4002 })
4003 
4004 DECLARE(blockmove_NtoN_blend_remap_flipx,(
4005 		const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
4006 		DATA_TYPE *dstdata,int dstmodulo,
4007 		const UINT16 *paldata,int srcshift),
4008 {
4009 	DATA_TYPE *end;
4010 
4011 	srcmodulo += srcwidth;
4012 	dstmodulo -= srcwidth;
4013 	//srcdata += srcwidth-1;
4014 
4015 	while (srcheight)
4016 	{
4017 		end = dstdata + srcwidth;
4018 		while (dstdata <= end - 8)
4019 		{
4020 			srcdata -= 8;
4021 			dstdata[0] = paldata[dstdata[0] | (srcdata[8] << srcshift)];
4022 			dstdata[1] = paldata[dstdata[1] | (srcdata[7] << srcshift)];
4023 			dstdata[2] = paldata[dstdata[2] | (srcdata[6] << srcshift)];
4024 			dstdata[3] = paldata[dstdata[3] | (srcdata[5] << srcshift)];
4025 			dstdata[4] = paldata[dstdata[4] | (srcdata[4] << srcshift)];
4026 			dstdata[5] = paldata[dstdata[5] | (srcdata[3] << srcshift)];
4027 			dstdata[6] = paldata[dstdata[6] | (srcdata[2] << srcshift)];
4028 			dstdata[7] = paldata[dstdata[7] | (srcdata[1] << srcshift)];
4029 			dstdata += 8;
4030 		}
4031 		while (dstdata < end)
4032 		{
4033 			*dstdata = paldata[*dstdata | (*(srcdata--) << srcshift)];
4034 			dstdata++;
4035 		}
4036 
4037 		srcdata += srcmodulo;
4038 		dstdata += dstmodulo;
4039 		srcheight--;
4040 	}
4041 })
4042 
4043 
4044 DECLARE(drawgfx_core,(
4045 		struct osd_bitmap *dest,const struct GfxElement *gfx,
4046 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
4047 		const struct rectangle *clip,int transparency,int transparent_color,
4048 		struct osd_bitmap *pri_buffer,UINT32 pri_mask),
4049 {
4050 	int ox;
4051 	int oy;
4052 	int ex;
4053 	int ey;
4054 
4055 
4056 	/* check bounds */
4057 	ox = sx;
4058 	oy = sy;
4059 
4060 	ex = sx + gfx->width-1;
4061 	if (sx < 0) sx = 0;
4062 	if (clip && sx < clip->min_x) sx = clip->min_x;
4063 	if (ex >= dest->width) ex = dest->width-1;
4064 	if (clip && ex > clip->max_x) ex = clip->max_x;
4065 	if (sx > ex) return;
4066 
4067 	ey = sy + gfx->height-1;
4068 	if (sy < 0) sy = 0;
4069 	if (clip && sy < clip->min_y) sy = clip->min_y;
4070 	if (ey >= dest->height) ey = dest->height-1;
4071 	if (clip && ey > clip->max_y) ey = clip->max_y;
4072 	if (sy > ey) return;
4073 
4074 	osd_mark_dirty (sx,sy,ex,ey,0);	/* ASG 971011 */
4075 
4076 	{
4077 		UINT8 *sd = gfx->gfxdata + code * gfx->char_modulo;		/* source data */
4078 		int sw = ex-sx+1;										/* source width */
4079 		int sh = ey-sy+1;										/* source height */
4080 		int sm = gfx->line_modulo;								/* source modulo */
4081 		DATA_TYPE *dd = ((DATA_TYPE *)dest->line[sy]) + sx;		/* dest data */
4082 		int dm = ((DATA_TYPE *)dest->line[1])-((DATA_TYPE *)dest->line[0]);	/* dest modulo */
4083 		const UINT16 *paldata = &gfx->colortable[gfx->color_granularity * color];
4084 		UINT8 *pribuf = (pri_buffer) ? pri_buffer->line[sy] + sx : NULL;
4085 
4086 		if (flipx)
4087 		{
4088 			//if ((sx-ox) == 0) sd += gfx->width - sw;
4089 			sd += gfx->width -1 -(sx-ox);
4090 		}
4091 		else
4092 			sd += (sx-ox);
4093 
4094 		if (flipy)
4095 		{
4096 			//if ((sy-oy) == 0) sd += sm * (gfx->height - sh);
4097 			//dd += dm * (sh - 1);
4098 			//dm = -dm;
4099 			sd += sm * (gfx->height -1 -(sy-oy));
4100 			sm = -sm;
4101 		}
4102 		else
4103 			sd += sm * (sy-oy);
4104 
4105 		switch (transparency)
4106 		{
4107 			case TRANSPARENCY_NONE:
4108 				if (pribuf)
4109 					BLOCKMOVE(8toN_opaque_pri,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
4110 				else
4111 					BLOCKMOVE(8toN_opaque,flipx,(sd,sw,sh,sm,dd,dm,paldata));
4112 				break;
4113 
4114 			case TRANSPARENCY_PEN:
4115 				if (pribuf)
4116 					BLOCKMOVE(8toN_transpen_pri,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color,pribuf,pri_mask));
4117 				else
4118 					BLOCKMOVE(8toN_transpen,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
4119 				break;
4120 
4121 			case TRANSPARENCY_PENS:
4122 				if (pribuf)
4123 					BLOCKMOVE(8toN_transmask_pri,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color,pribuf,pri_mask));
4124 				else
4125 					BLOCKMOVE(8toN_transmask,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
4126 				break;
4127 
4128 			case TRANSPARENCY_COLOR:
4129 				if (pribuf)
4130 					BLOCKMOVE(8toN_transcolor_pri,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color,pribuf,pri_mask));
4131 				else
4132 					BLOCKMOVE(8toN_transcolor,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
4133 				break;
4134 
4135 			case TRANSPARENCY_THROUGH:
4136 				if (pribuf)
4137 usrintf_showmessage("pdrawgfx TRANS_THROUGH not supported");
4138 //					BLOCKMOVE(8toN_transthrough,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
4139 				else
4140 					BLOCKMOVE(8toN_transthrough,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
4141 				break;
4142 
4143 			case TRANSPARENCY_PEN_TABLE:
4144 				if (pribuf)
4145 usrintf_showmessage("pdrawgfx TRANS_PEN_TABLE not supported");
4146 //					BLOCKMOVE(8toN_pen_table_pri,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
4147 				else
4148 					BLOCKMOVE(8toN_pen_table,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
4149 				break;
4150 
4151 			case TRANSPARENCY_PEN_TABLE_RAW:
4152 				if (pribuf)
4153 usrintf_showmessage("pdrawgfx TRANS_PEN_TABLE_RAW not supported");
4154 //					BLOCKMOVE(8toN_pen_table_pri_raw,flipx,(sd,sw,sh,sm,dd,dm,color,transparent_color));
4155 				else
4156 					BLOCKMOVE(8toN_pen_table_raw,flipx,(sd,sw,sh,sm,dd,dm,color,transparent_color));
4157 				break;
4158 
4159 			case TRANSPARENCY_NONE_RAW:
4160 				if (pribuf)
4161 usrintf_showmessage("pdrawgfx TRANS_NONE_RAW not supported");
4162 //					BLOCKMOVE(8toN_opaque_pri_raw,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
4163 				else
4164 					BLOCKMOVE(8toN_opaque_raw,flipx,(sd,sw,sh,sm,dd,dm,color));
4165 				break;
4166 
4167 			case TRANSPARENCY_PEN_RAW:
4168 				if (pribuf)
4169 usrintf_showmessage("pdrawgfx TRANS_PEN_RAW not supported");
4170 //					BLOCKMOVE(8toN_transpen_pri_raw,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
4171 				else
4172 					BLOCKMOVE(8toN_transpen_raw,flipx,(sd,sw,sh,sm,dd,dm,color,transparent_color));
4173 				break;
4174 
4175 			case TRANSPARENCY_PENS_RAW:
4176 				if (pribuf)
4177 usrintf_showmessage("pdrawgfx TRANS_PENS_RAW not supported");
4178 //					BLOCKMOVE(8toN_transmask_pri_raw,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
4179 				else
4180 					BLOCKMOVE(8toN_transmask_raw,flipx,(sd,sw,sh,sm,dd,dm,color,transparent_color));
4181 				break;
4182 
4183 			case TRANSPARENCY_THROUGH_RAW:
4184 				if (pribuf)
4185 usrintf_showmessage("pdrawgfx TRANS_PEN_RAW not supported");
4186 //					BLOCKMOVE(8toN_transpen_pri_raw,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
4187 				else
4188 					BLOCKMOVE(8toN_transthrough_raw,flipx,(sd,sw,sh,sm,dd,dm,color,transparent_color));
4189 				break;
4190 
4191 			default:
4192 				if (pribuf)
4193 					usrintf_showmessage("pdrawgfx pen mode not supported");
4194 				else
4195 					usrintf_showmessage("drawgfx pen mode not supported");
4196 				break;
4197 		}
4198 	}
4199 })
4200 
4201 DECLARE(copybitmap_core,(
4202 		struct osd_bitmap *dest,struct osd_bitmap *src,
4203 		int flipx,int flipy,int sx,int sy,
4204 		const struct rectangle *clip,int transparency,int transparent_color),
4205 {
4206 	int ox;
4207 	int oy;
4208 	int ex;
4209 	int ey;
4210 
4211 
4212 	/* check bounds */
4213 	ox = sx;
4214 	oy = sy;
4215 
4216 	ex = sx + src->width-1;
4217 	if (sx < 0) sx = 0;
4218 	if (clip && sx < clip->min_x) sx = clip->min_x;
4219 	if (ex >= dest->width) ex = dest->width-1;
4220 	if (clip && ex > clip->max_x) ex = clip->max_x;
4221 	if (sx > ex) return;
4222 
4223 	ey = sy + src->height-1;
4224 	if (sy < 0) sy = 0;
4225 	if (clip && sy < clip->min_y) sy = clip->min_y;
4226 	if (ey >= dest->height) ey = dest->height-1;
4227 	if (clip && ey > clip->max_y) ey = clip->max_y;
4228 	if (sy > ey) return;
4229 
4230 	{
4231 		DATA_TYPE *sd = ((DATA_TYPE *)src->line[0]);							/* source data */
4232 		int sw = ex-sx+1;														/* source width */
4233 		int sh = ey-sy+1;														/* source height */
4234 		int sm = ((DATA_TYPE *)src->line[1])-((DATA_TYPE *)src->line[0]);		/* source modulo */
4235 		DATA_TYPE *dd = ((DATA_TYPE *)dest->line[sy]) + sx;						/* dest data */
4236 		int dm = ((DATA_TYPE *)dest->line[1])-((DATA_TYPE *)dest->line[0]);		/* dest modulo */
4237 
4238 		if (flipx)
4239 		{
4240 			//if ((sx-ox) == 0) sd += gfx->width - sw;
4241 			sd += src->width -1 -(sx-ox);
4242 		}
4243 		else
4244 			sd += (sx-ox);
4245 
4246 		if (flipy)
4247 		{
4248 			//if ((sy-oy) == 0) sd += sm * (gfx->height - sh);
4249 			//dd += dm * (sh - 1);
4250 			//dm = -dm;
4251 			sd += sm * (src->height -1 -(sy-oy));
4252 			sm = -sm;
4253 		}
4254 		else
4255 			sd += sm * (sy-oy);
4256 
4257 		switch (transparency)
4258 		{
4259 			case TRANSPARENCY_NONE:
4260 				BLOCKMOVE(NtoN_opaque_remap,flipx,(sd,sw,sh,sm,dd,dm,Machine->pens));
4261 				break;
4262 
4263 			case TRANSPARENCY_NONE_RAW:
4264 				BLOCKMOVE(NtoN_opaque_noremap,flipx,(sd,sw,sh,sm,dd,dm));
4265 				break;
4266 
4267 			case TRANSPARENCY_PEN_RAW:
4268 				BLOCKMOVE(NtoN_transpen_noremap,flipx,(sd,sw,sh,sm,dd,dm,transparent_color));
4269 				break;
4270 
4271 			case TRANSPARENCY_THROUGH_RAW:
4272 				BLOCKMOVE(NtoN_transthrough_noremap,flipx,(sd,sw,sh,sm,dd,dm,transparent_color));
4273 				break;
4274 
4275 			case TRANSPARENCY_BLEND:
4276 				BLOCKMOVE(NtoN_blend_remap,flipx,(sd,sw,sh,sm,dd,dm,Machine->pens,transparent_color));
4277 				break;
4278 
4279 			case TRANSPARENCY_BLEND_RAW:
4280 				BLOCKMOVE(NtoN_blend_noremap,flipx,(sd,sw,sh,sm,dd,dm,transparent_color));
4281 				break;
4282 
4283 			default:
4284 				usrintf_showmessage("copybitmap pen mode not supported");
4285 				break;
4286 		}
4287 	}
4288 })
4289 
4290 DECLARE(copyrozbitmap_core,(struct osd_bitmap *bitmap,struct osd_bitmap *srcbitmap,
4291 		UINT32 startx,UINT32 starty,int incxx,int incxy,int incyx,int incyy,int wraparound,
4292 		const struct rectangle *clip,int transparency,int transparent_color,UINT32 priority),
4293 {
4294 	UINT32 cx;
4295 	UINT32 cy;
4296 	int x;
4297 	int sx;
4298 	int sy;
4299 	int ex;
4300 	int ey;
4301 	const int xmask = srcbitmap->width-1;
4302 	const int ymask = srcbitmap->height-1;
4303 	const int widthshifted = srcbitmap->width << 16;
4304 	const int heightshifted = srcbitmap->height << 16;
4305 	DATA_TYPE *dest;
4306 
4307 
4308 	if (clip)
4309 	{
4310 		startx += clip->min_x * incxx + clip->min_y * incyx;
4311 		starty += clip->min_x * incxy + clip->min_y * incyy;
4312 
4313 		sx = clip->min_x;
4314 		sy = clip->min_y;
4315 		ex = clip->max_x;
4316 		ey = clip->max_y;
4317 	}
4318 	else
4319 	{
4320 		sx = 0;
4321 		sy = 0;
4322 		ex = bitmap->width-1;
4323 		ey = bitmap->height-1;
4324 	}
4325 
4326 
4327 	if (Machine->orientation & ORIENTATION_SWAP_XY)
4328 	{
4329 		int t;
4330 
4331 		t = startx; startx = starty; starty = t;
4332 		t = sx; sx = sy; sy = t;
4333 		t = ex; ex = ey; ey = t;
4334 		t = incxx; incxx = incyy; incyy = t;
4335 		t = incxy; incxy = incyx; incyx = t;
4336 	}
4337 
4338 	if (Machine->orientation & ORIENTATION_FLIP_X)
4339 	{
4340 		int w = ex - sx;
4341 
4342 		incxy = -incxy;
4343 		incyx = -incyx;
4344 		startx = widthshifted - startx - 1;
4345 		startx -= incxx * w;
4346 		starty -= incxy * w;
4347 
4348 		w = sx;
4349 		sx = bitmap->width-1 - ex;
4350 		ex = bitmap->width-1 - w;
4351 	}
4352 
4353 	if (Machine->orientation & ORIENTATION_FLIP_Y)
4354 	{
4355 		int h = ey - sy;
4356 
4357 		incxy = -incxy;
4358 		incyx = -incyx;
4359 		starty = heightshifted - starty - 1;
4360 		startx -= incyx * h;
4361 		starty -= incyy * h;
4362 
4363 		h = sy;
4364 		sy = bitmap->height-1 - ey;
4365 		ey = bitmap->height-1 - h;
4366 	}
4367 
4368 	if (incxy == 0 && incyx == 0 && !wraparound)
4369 	{
4370 		/* optimized loop for the not rotated case */
4371 
4372 		if (incxx == 0x10000)
4373 		{
4374 			/* optimized loop for the not zoomed case */
4375 
4376 			/* startx is unsigned */
4377 			startx = ((INT32)startx) >> 16;
4378 
4379 			if (startx >= srcbitmap->width)
4380 			{
4381 				sx += -startx;
4382 				startx = 0;
4383 			}
4384 
4385 			if (sx <= ex)
4386 			{
4387 				while (sy <= ey)
4388 				{
4389 					if (starty < heightshifted)
4390 					{
4391 						x = sx;
4392 						cx = startx;
4393 						cy = starty >> 16;
4394 						dest = ((DATA_TYPE *)bitmap->line[sy]) + sx;
4395 						if (priority)
4396 						{
4397 							UINT8 *pri = &priority_bitmap->line[sy][sx];
4398 							DATA_TYPE *src = (DATA_TYPE *)srcbitmap->line[cy];
4399 
4400 							while (x <= ex && cx < srcbitmap->width)
4401 							{
4402 								int c = src[cx];
4403 
4404 								if (c != transparent_color)
4405 								{
4406 									*dest = c;
4407 									*pri |= priority;
4408 								}
4409 
4410 								cx++;
4411 								x++;
4412 								dest++;
4413 								pri++;
4414 							}
4415 						}
4416 						else
4417 						{
4418 							DATA_TYPE *src = (DATA_TYPE *)srcbitmap->line[cy];
4419 
4420 							while (x <= ex && cx < srcbitmap->width)
4421 							{
4422 								int c = src[cx];
4423 
4424 								if (c != transparent_color)
4425 									*dest = c;
4426 
4427 								cx++;
4428 								x++;
4429 								dest++;
4430 							}
4431 						}
4432 					}
4433 					starty += incyy;
4434 					sy++;
4435 				}
4436 			}
4437 		}
4438 		else
4439 		{
4440 			while (startx >= widthshifted && sx <= ex)
4441 			{
4442 				startx += incxx;
4443 				sx++;
4444 			}
4445 
4446 			if (sx <= ex)
4447 			{
4448 				while (sy <= ey)
4449 				{
4450 					if (starty < heightshifted)
4451 					{
4452 						x = sx;
4453 						cx = startx;
4454 						cy = starty >> 16;
4455 						dest = ((DATA_TYPE *)bitmap->line[sy]) + sx;
4456 						if (priority)
4457 						{
4458 							UINT8 *pri = &priority_bitmap->line[sy][sx];
4459 							DATA_TYPE *src = (DATA_TYPE *)srcbitmap->line[cy];
4460 
4461 							while (x <= ex && cx < widthshifted)
4462 							{
4463 								int c = src[cx >> 16];
4464 
4465 								if (c != transparent_color)
4466 								{
4467 									*dest = c;
4468 									*pri |= priority;
4469 								}
4470 
4471 								cx += incxx;
4472 								x++;
4473 								dest++;
4474 								pri++;
4475 							}
4476 						}
4477 						else
4478 						{
4479 							DATA_TYPE *src = (DATA_TYPE *)srcbitmap->line[cy];
4480 
4481 							while (x <= ex && cx < widthshifted)
4482 							{
4483 								int c = src[cx >> 16];
4484 
4485 								if (c != transparent_color)
4486 									*dest = c;
4487 
4488 								cx += incxx;
4489 								x++;
4490 								dest++;
4491 							}
4492 						}
4493 					}
4494 					starty += incyy;
4495 					sy++;
4496 				}
4497 			}
4498 		}
4499 	}
4500 	else
4501 	{
4502 		if (wraparound)
4503 		{
4504 			/* plot with wraparound */
4505 			while (sy <= ey)
4506 			{
4507 				x = sx;
4508 				cx = startx;
4509 				cy = starty;
4510 				dest = ((DATA_TYPE *)bitmap->line[sy]) + sx;
4511 				if (priority)
4512 				{
4513 					UINT8 *pri = &priority_bitmap->line[sy][sx];
4514 
4515 					while (x <= ex)
4516 					{
4517 						int c = ((DATA_TYPE *)srcbitmap->line[(cy >> 16) & xmask])[(cx >> 16) & ymask];
4518 
4519 						if (c != transparent_color)
4520 						{
4521 							*dest = c;
4522 							*pri |= priority;
4523 						}
4524 
4525 						cx += incxx;
4526 						cy += incxy;
4527 						x++;
4528 						dest++;
4529 						pri++;
4530 					}
4531 				}
4532 				else
4533 				{
4534 					while (x <= ex)
4535 					{
4536 						int c = ((DATA_TYPE *)srcbitmap->line[(cy >> 16) & xmask])[(cx >> 16) & ymask];
4537 
4538 						if (c != transparent_color)
4539 							*dest = c;
4540 
4541 						cx += incxx;
4542 						cy += incxy;
4543 						x++;
4544 						dest++;
4545 					}
4546 				}
4547 				startx += incyx;
4548 				starty += incyy;
4549 				sy++;
4550 			}
4551 		}
4552 		else
4553 		{
4554 			while (sy <= ey)
4555 			{
4556 				x = sx;
4557 				cx = startx;
4558 				cy = starty;
4559 				dest = ((DATA_TYPE *)bitmap->line[sy]) + sx;
4560 				if (priority)
4561 				{
4562 					UINT8 *pri = &priority_bitmap->line[sy][sx];
4563 
4564 					while (x <= ex)
4565 					{
4566 						if (cx < widthshifted && cy < heightshifted)
4567 						{
4568 							int c = ((DATA_TYPE *)srcbitmap->line[cy >> 16])[cx >> 16];
4569 
4570 							if (c != transparent_color)
4571 							{
4572 								*dest = c;
4573 								*pri |= priority;
4574 							}
4575 						}
4576 
4577 						cx += incxx;
4578 						cy += incxy;
4579 						x++;
4580 						dest++;
4581 						pri++;
4582 					}
4583 				}
4584 				else
4585 				{
4586 					while (x <= ex)
4587 					{
4588 						if (cx < widthshifted && cy < heightshifted)
4589 						{
4590 							int c = ((DATA_TYPE *)srcbitmap->line[cy >> 16])[cx >> 16];
4591 
4592 							if (c != transparent_color)
4593 								*dest = c;
4594 						}
4595 
4596 						cx += incxx;
4597 						cy += incxy;
4598 						x++;
4599 						dest++;
4600 					}
4601 				}
4602 				startx += incyx;
4603 				starty += incyy;
4604 				sy++;
4605 			}
4606 		}
4607 	}
4608 })
4609 
4610 #endif /* DECLARE */
4611