1 /*********************************************************************
2 
3   drawgfx.h
4 
5   Generic graphic functions.
6 
7 *********************************************************************/
8 
9 #ifndef DRAWGFX_H
10 #define DRAWGFX_H
11 
12 #define MAX_GFX_PLANES 8
13 #define MAX_GFX_SIZE 64
14 
15 #define RGN_FRAC(num,den) (0x80000000 | (((num) & 0x0f) << 27) | (((den) & 0x0f) << 23))
16 #define IS_FRAC(offset) ((offset) & 0x80000000)
17 #define FRAC_NUM(offset) (((offset) >> 27) & 0x0f)
18 #define FRAC_DEN(offset) (((offset) >> 23) & 0x0f)
19 #define FRAC_OFFSET(offset) ((offset) & 0x007fffff)
20 
21 #define STEP4(START,STEP)  (START),(START)+1*(STEP),(START)+2*(STEP),(START)+3*(STEP)
22 #define STEP8(START,STEP)  STEP4(START,STEP),STEP4((START)+4*(STEP),STEP)
23 #define STEP16(START,STEP) STEP8(START,STEP),STEP8((START)+8*(STEP),STEP)
24 
25 
26 struct GfxLayout
27 {
28 	UINT16 width,height; /* width and height (in pixels) of chars/sprites */
29 	UINT32 total; /* total numer of chars/sprites in the rom */
30 	UINT16 planes; /* number of bitplanes */
31 	UINT32 planeoffset[MAX_GFX_PLANES]; /* start of every bitplane (in bits) */
32 	UINT32 xoffset[MAX_GFX_SIZE]; /* position of the bit corresponding to the pixel */
33 	UINT32 yoffset[MAX_GFX_SIZE]; /* of the given coordinates */
34 	UINT16 charincrement; /* distance between two consecutive characters/sprites (in bits) */
35 };
36 
37 #ifdef _MSC_VER
38 __declspec(align(32))
39 #endif
40 struct GfxElement
41 {
42 	int width,height;
43 
44 	unsigned int total_elements;	/* total number of characters/sprites */
45 	int color_granularity;	/* number of colors for each color code */
46 							/* (for example, 4 for 2 bitplanes gfx) */
47 	unsigned short *colortable;	/* map color codes to screen pens */
48 	int total_colors;
49 	unsigned int *pen_usage;	/* an array of total_elements ints. */
50 								/* It is a table of the pens each character uses */
51 								/* (bit 0 = pen 0, and so on). This is used by */
52 								/* drawgfgx() to do optimizations like skipping */
53 								/* drawing of a totally transparent characters */
54 	unsigned char *gfxdata;	/* pixel data */
55 	int line_modulo;	/* amount to add to get to the next line (usually = width) */
56 	int char_modulo;	/* = line_modulo * height */
57 }
58 #ifndef _MSC_VER
59 __attribute__ ((__aligned__ (32)))
60 #endif
61    ;
62 
63 struct GfxDecodeInfo
64 {
65 	int memory_region;	/* memory region where the data resides (usually 1) */
66 						/* -1 marks the end of the array */
67 	int start;	/* beginning of data to decode */
68 	struct GfxLayout *gfxlayout;
69 	int color_codes_start;	/* offset in the color lookup table where color codes start */
70 	int total_color_codes;	/* total number of color codes */
71 };
72 
73 
74 struct rectangle
75 {
76 	int min_x,max_x;
77 	int min_y,max_y;
78 };
79 
80 
81 enum
82 {
83 	TRANSPARENCY_NONE,			/* opaque with remapping */
84 	TRANSPARENCY_NONE_RAW,		/* opaque with no remapping */
85 	TRANSPARENCY_PEN,			/* single pen transparency with remapping */
86 	TRANSPARENCY_PEN_RAW,		/* single pen transparency with no remapping */
87 	TRANSPARENCY_PENS,			/* multiple pen transparency with remapping */
88 	TRANSPARENCY_PENS_RAW,		/* multiple pen transparency with no remapping */
89 	TRANSPARENCY_COLOR,			/* single remapped pen transparency with remapping */
90 	TRANSPARENCY_THROUGH,		/* destination pixel overdraw with remapping */
91 	TRANSPARENCY_THROUGH_RAW,	/* destination pixel overdraw with no remapping */
92 	TRANSPARENCY_PEN_TABLE,		/* special pen remapping modes (see DRAWMODE_xxx below) with remapping */
93 	TRANSPARENCY_PEN_TABLE_RAW,	/* special pen remapping modes (see DRAWMODE_xxx below) with no remapping */
94 	TRANSPARENCY_BLEND,			/* blend two bitmaps, shifting the source and ORing to the dest with remapping */
95 	TRANSPARENCY_BLEND_RAW,		/* blend two bitmaps, shifting the source and ORing to the dest with no remapping */
96 
97 	TRANSPARENCY_MODES			/* total number of modes; must be last */
98 };
99 
100 /* drawing mode case TRANSPARENCY_PEN_TABLE */
101 extern UINT8 gfx_drawmode_table[256];
102 enum
103 {
104 	DRAWMODE_NONE,
105 	DRAWMODE_SOURCE,
106 	DRAWMODE_SHADOW
107 };
108 
109 
110 typedef void (*plot_pixel_proc)(struct osd_bitmap *bitmap,int x,int y,int pen);
111 typedef int  (*read_pixel_proc)(struct osd_bitmap *bitmap,int x,int y);
112 typedef void (*plot_box_proc)(struct osd_bitmap *bitmap,int x,int y,int width,int height,int pen);
113 
114 /* pointers to pixel functions.  They're set based on orientation, depthness and weather
115    dirty rectangle handling is enabled */
116 extern plot_pixel_proc plot_pixel;
117 extern read_pixel_proc read_pixel;
118 extern plot_box_proc plot_box;
119 
120 
121 void decodechar(struct GfxElement *gfx,int num,const unsigned char *src,const struct GfxLayout *gl);
122 struct GfxElement *decodegfx(const unsigned char *src,const struct GfxLayout *gl);
123 void set_pixel_functions(void);
124 void freegfx(struct GfxElement *gfx);
125 void drawgfx(struct osd_bitmap *dest,const struct GfxElement *gfx,
126 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
127 		const struct rectangle *clip,int transparency,int transparent_color);
128 void pdrawgfx(struct osd_bitmap *dest,const struct GfxElement *gfx,
129 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
130 		const struct rectangle *clip,int transparency,int transparent_color,
131 		UINT32 priority_mask);
132 void copybitmap(struct osd_bitmap *dest,struct osd_bitmap *src,int flipx,int flipy,int sx,int sy,
133 		const struct rectangle *clip,int transparency,int transparent_color);
134 void copybitmap_remap(struct osd_bitmap *dest,struct osd_bitmap *src,int flipx,int flipy,int sx,int sy,
135 		const struct rectangle *clip,int transparency,int transparent_color);
136 void copyscrollbitmap(struct osd_bitmap *dest,struct osd_bitmap *src,
137 		int rows,const int *rowscroll,int cols,const int *colscroll,
138 		const struct rectangle *clip,int transparency,int transparent_color);
139 void copyscrollbitmap_remap(struct osd_bitmap *dest,struct osd_bitmap *src,
140 		int rows,const int *rowscroll,int cols,const int *colscroll,
141 		const struct rectangle *clip,int transparency,int transparent_color);
142 
143 /*
144   Copy a bitmap applying rotation, zooming, and arbitrary distortion.
145   This function works in a way that mimics some real hardware like the Konami
146   051316, so it requires little or no further processing on the caller side.
147 
148   Two 16.16 fixed point counters are used to keep track of the position on
149   the source bitmap. startx and starty are the initial values of those counters,
150   indicating the source pixel that will be drawn at coordinates (0,0) in the
151   destination bitmap. The destination bitmap is scanned left to right, top to
152   bottom; every time the cursor moves one pixel to the right, incxx is added
153   to startx and incxy is added to starty. Every time the curso moves to the
154   next line, incyx is added to startx and incyy is added to startyy.
155 
156   What this means is that if incxy and incyx are both 0, the bitmap will be
157   copied with only zoom and no rotation. If e.g. incxx and incyy are both 0x8000,
158   the source bitmap will be doubled.
159 
160   Rotation is performed this way:
161   incxx = 0x10000 * cos(theta)
162   incxy = 0x10000 * -sin(theta)
163   incyx = 0x10000 * sin(theta)
164   incyy = 0x10000 * cos(theta)
165   this will perform a rotation around (0,0), you'll have to adjust startx and
166   starty to move the center of rotation elsewhere.
167 
168   Optionally the bitmap can be tiled across the screen instead of doing a single
169   copy. This is obtained by setting the wraparound parameter to true.
170  */
171 void copyrozbitmap(struct osd_bitmap *dest,struct osd_bitmap *src,
172 		UINT32 startx,UINT32 starty,int incxx,int incxy,int incyx,int incyy,int wraparound,
173 		const struct rectangle *clip,int transparency,int transparent_color,UINT32 priority);
174 
175 void fillbitmap(struct osd_bitmap *dest,int pen,const struct rectangle *clip);
176 void plot_pixel2(struct osd_bitmap *bitmap1,struct osd_bitmap *bitmap2,int x,int y,int pen);
177 void drawgfxzoom( struct osd_bitmap *dest_bmp,const struct GfxElement *gfx,
178 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
179 		const struct rectangle *clip,int transparency,int transparent_color,int scalex,int scaley);
180 void pdrawgfxzoom( struct osd_bitmap *dest_bmp,const struct GfxElement *gfx,
181 		unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
182 		const struct rectangle *clip,int transparency,int transparent_color,int scalex,int scaley,
183 		UINT32 priority_mask);
184 
185 #endif
186