1 /* tilemap.h */
2 
3 #ifndef TILEMAP_H
4 #define TILEMAP_H
5 
6 #define ALL_TILEMAPS	0
7 /* ALL_TILEMAPS may be used with:
8 	tilemap_update, tilemap_render, tilemap_set_flip, tilemap_mark_all_pixels_dirty
9 */
10 
11 #define TILEMAP_OPAQUE				0x00
12 #define TILEMAP_TRANSPARENT			0x01
13 #define TILEMAP_SPLIT				0x02
14 #define TILEMAP_BITMASK				0x04
15 #define TILEMAP_TRANSPARENT_COLOR	0x08
16 /*
17 	TILEMAP_SPLIT should be used if the pixels from a single tile
18 	can appear in more than one plane.
19 
20 	TILEMAP_BITMASK is needed for Namco SystemI
21 */
22 
23 #define TILEMAP_IGNORE_TRANSPARENCY		0x10
24 #define TILEMAP_BACK					0x20
25 #define TILEMAP_FRONT					0x40
26 /*
27 	when rendering a split layer, pass TILEMAP_FRONT or TILEMAP_BACK or'd with the
28 	tile_priority value to specify the part to draw.
29 */
30 
31 #define TILEMAP_BITMASK_TRANSPARENT (0)
32 #define TILEMAP_BITMASK_OPAQUE ((UINT8 *)~0)
33 
34 struct cached_tile_info {
35 	const UINT8 *pen_data;
36 	const UINT16 *pal_data;
37 	UINT32 pen_usage;
38 	UINT32 flags;
39 };
40 
41 extern struct tile_info {
42 	/*
43 		you must set tile_info.pen_data, tile_info.pal_data and tile_info.pen_usage
44 		in the callback.  You can use the SET_TILE_INFO() macro below to do this.
45 		tile_info.flags and tile_info.priority will be automatically preset to 0,
46 		games that don't need them don't need to explicitly set them to 0
47 	*/
48 	const UINT8 *pen_data;
49 	const UINT16 *pal_data;
50 	UINT32 pen_usage;
51 	UINT32 flags;
52 
53 	UINT32 priority;
54 	UINT8 *mask_data;
55 } tile_info;
56 
57 #define SET_TILE_INFO(GFX,CODE,COLOR) { \
58 	const struct GfxElement *gfx = Machine->gfx[(GFX)]; \
59 	int _code = (CODE) % gfx->total_elements; \
60 	tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; \
61 	tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (COLOR)]; \
62 	tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; \
63 }
64 
65 /* tile flags, set by get_tile_info callback */
66 #define TILE_FLIPX					0x01
67 #define TILE_FLIPY					0x02
68 #define TILE_SPLIT(T)				((T)<<2)
69 /* TILE_SPLIT is for use with TILEMAP_SPLIT layers.  It selects transparency type. */
70 #define TILE_IGNORE_TRANSPARENCY	0x10
71 /* TILE_IGNORE_TRANSPARENCY is used if you need an opaque tile in a transparent layer */
72 
73 #define TILE_FLIPYX(YX)				(YX)
74 #define TILE_FLIPXY(XY)				((((XY)>>1)|((XY)<<1))&3)
75 /*
76 	TILE_FLIPYX is a shortcut that can be used by approx 80% of games,
77 	since yflip frequently occurs one bit higher than xflip within a
78 	tile attributes byte.
79 */
80 
81 #define TILE_LINE_DISABLED 0x80000000
82 
83 #ifndef OSD_CPU_H
84 #include "osd_cpu.h"
85 #endif
86 
87 extern struct osd_bitmap *priority_bitmap;
88 
89 struct tilemap_mask {
90 	struct osd_bitmap *bitmask;
91 	int line_offset;
92 	UINT8 *data;
93 	UINT8 **data_row;
94 };
95 
96 #ifdef _MSC_VER
97 __declspec(align(32))
98 #endif
99 struct tilemap {
100 	UINT32 (*get_memory_offset)( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows );
101 	int *memory_offset_to_cached_index;
102 	UINT32 *cached_index_to_memory_offset;
103 	int logical_flip_to_cached_flip[4];
104 
105 	/* callback to interpret video VRAM for the tilemap */
106 	void (*tile_get_info)( int memory_offset );
107 
108 	UINT32 max_memory_offset;
109 	int num_tiles;
110 	int num_logical_rows, num_logical_cols;
111 	int num_cached_rows, num_cached_cols;
112 	int cached_tile_width, cached_tile_height, cached_width, cached_height;
113 
114 	struct cached_tile_info *cached_tile_info;
115 
116 	int dx, dx_if_flipped;
117 	int dy, dy_if_flipped;
118 	int scrollx_delta, scrolly_delta;
119 
120 	int enable;
121 	int attributes;
122 
123 	int type;
124 	int transparent_pen;
125 	unsigned int transmask[4];
126 
127 	void (*draw)( int, int );
128 	void (*draw_opaque)( int, int );
129 
130 	UINT8 *priority,	/* priority for each tile */
131 		**priority_row;
132 
133 	UINT8 *visible; /* boolean flag for each tile */
134 
135 	UINT8 *dirty_vram; /* boolean flag for each tile */
136 
137 	UINT8 *dirty_pixels;
138 
139 	int scroll_rows, scroll_cols;
140 	int *rowscroll, *colscroll;
141 
142 	int orientation;
143 	int clip_left,clip_right,clip_top,clip_bottom;
144 
145 	/* cached color data */
146 	struct osd_bitmap *pixmap;
147 	int pixmap_line_offset;
148 
149 	struct tilemap_mask *foreground;
150 	/* for transparent layers, or the front half of a split layer */
151 
152 	struct tilemap_mask *background;
153 	/* for the back half of a split layer */
154 
155 	struct tilemap *next; /* resource tracking */
156 }
157 #ifndef _MSC_VER
158 __attribute__ ((__aligned__ (32)))
159 #endif
160    ;
161 
162 /* don't call these from drivers - they are called from mame.c */
163 int tilemap_init( void );
164 void tilemap_close( void );
165 
166 struct tilemap *tilemap_create(
167 	void (*tile_get_info)( int memory_offset ),
168 	UINT32 (*get_memory_offset)( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows ),
169 	int type,
170 	int tile_width, int tile_height, /* in pixels */
171 	int num_cols, int num_rows /* in tiles */
172 );
173 
174 void tilemap_dispose( struct tilemap *tilemap );
175 /*	you shouldn't call this in vh_close; all tilemaps will be automatically
176 	disposed.  tilemap_dispose is supplied for games that need to change
177 	tile size or cols/rows dynamically.
178 */
179 
180 void tilemap_set_transparent_pen( struct tilemap *tilemap, int pen );
181 void tilemap_set_scroll_cols( struct tilemap *tilemap, int scroll_cols );
182 void tilemap_set_scroll_rows( struct tilemap *tilemap, int scroll_rows );
183 /* scroll_rows and scroll_cols default to 1 for XY scrolling */
184 
185 void tilemap_mark_tile_dirty( struct tilemap *tilemap, int memory_offset );
186 void tilemap_mark_all_tiles_dirty( struct tilemap *tilemap );
187 void tilemap_mark_all_pixels_dirty( struct tilemap *tilemap );
188 
189 void tilemap_set_scrollx( struct tilemap *tilemap, int row, int value );
190 void tilemap_set_scrolly( struct tilemap *tilemap, int col, int value );
191 
192 void tilemap_set_scrolldx( struct tilemap *tilemap, int dx, int dx_if_flipped );
193 void tilemap_set_scrolldy( struct tilemap *tilemap, int dy, int dy_if_flipped );
194 
195 #define TILEMAP_FLIPX 0x1
196 #define TILEMAP_FLIPY 0x2
197 void tilemap_set_flip( struct tilemap *tilemap, int attributes );
198 void tilemap_set_clip( struct tilemap *tilemap, const struct rectangle *clip );
199 void tilemap_set_enable( struct tilemap *tilemap, int enable );
200 
201 void tilemap_update( struct tilemap *tilemap );
202 void tilemap_render( struct tilemap *tilemap );
203 void tilemap_draw( struct osd_bitmap *dest, struct tilemap *tilemap, UINT32 priority );
204 
205 /*********************************************************************/
206 
207 UINT32 tilemap_scan_cols( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows );
208 UINT32 tilemap_scan_rows( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows );
209 
210 #endif
211