1 /***************************************************************************
2 
3   vidhrdw.c
4 
5   Functions to emulate the video hardware of the machine.
6 
7 ***************************************************************************/
8 
9 #include "driver.h"
10 #include "tilemap.h"
11 #include "vidhrdw/generic.h"
12 
13 data16_t *splash_vregs;
14 data16_t *splash_videoram;
15 data16_t *splash_spriteram;
16 data16_t *splash_pixelram;
17 
18 static struct tilemap *screen[2];
19 static struct mame_bitmap *screen2;
20 
21 
22 /***************************************************************************
23 
24 	Callbacks for the TileMap code
25 
26 ***************************************************************************/
27 
28 /*
29 	Tile format
30 	-----------
31 
32 	Screen 0: (64*32, 8x8 tiles)
33 
34 	Word | Bit(s)			 | Description
35 	-----+-FEDCBA98-76543210-+--------------------------
36 	  0  | -------- xxxxxxxx | sprite code (low 8 bits)
37 	  0  | ----xxxx -------- | sprite code (high 4 bits)
38 	  0  | xxxx---- -------- | color
39 
40 	Screen 1: (32*32, 16x16 tiles)
41 
42 	Word | Bit(s)			 | Description
43 	-----+-FEDCBA98-76543210-+--------------------------
44 	  0  | -------- -------x | flip y
45 	  0  | -------- ------x- | flip x
46 	  0  | -------- xxxxxx-- | sprite code (low 6 bits)
47 	  0  | ----xxxx -------- | sprite code (high 4 bits)
48 	  0  | xxxx---- -------- | color
49 */
50 
get_tile_info_splash_screen0(int tile_index)51 static void get_tile_info_splash_screen0(int tile_index)
52 {
53 	int data = splash_videoram[tile_index];
54 	int attr = data >> 8;
55 	int code = data & 0xff;
56 
57 	SET_TILE_INFO(
58 			0,
59 			code + ((0x20 + (attr & 0x0f)) << 8),
60 			(attr & 0xf0) >> 4,
61 			0)
62 }
63 
get_tile_info_splash_screen1(int tile_index)64 static void get_tile_info_splash_screen1(int tile_index)
65 {
66 	int data = splash_videoram[(0x1000/2) + tile_index];
67 	int attr = data >> 8;
68 	int code = data & 0xff;
69 
70 	SET_TILE_INFO(
71 			1,
72 			(code >> 2) + ((0x30 + (attr & 0x0f)) << 6),
73 			(attr & 0xf0) >> 4,
74 			TILE_FLIPXY(code & 0x03))
75 }
76 
77 /***************************************************************************
78 
79 	Memory Handlers
80 
81 ***************************************************************************/
82 
READ16_HANDLER(splash_vram_r)83 READ16_HANDLER( splash_vram_r )
84 {
85 	return splash_videoram[offset];
86 }
87 
WRITE16_HANDLER(splash_vram_w)88 WRITE16_HANDLER( splash_vram_w )
89 {
90 	int oldword = splash_videoram[offset];
91 	COMBINE_DATA(&splash_videoram[offset]);
92 
93 	if (oldword != splash_videoram[offset])
94 		tilemap_mark_tile_dirty(screen[offset >> 11],((offset << 1) & 0x0fff) >> 1);
95 }
96 
READ16_HANDLER(splash_pixelram_r)97 READ16_HANDLER( splash_pixelram_r )
98 {
99 	return splash_pixelram[offset];
100 }
101 
WRITE16_HANDLER(splash_pixelram_w)102 WRITE16_HANDLER( splash_pixelram_w )
103 {
104 	int sx,sy,color;
105 
106 	COMBINE_DATA(&splash_pixelram[offset]);
107 
108 	sx = offset & 0x1ff;
109 	sy = (offset >> 9);
110 
111 	color = splash_pixelram[offset];
112 
113 	plot_pixel(screen2, sx-9, sy, Machine->pens[0x300 + (color & 0xff)]);
114 }
115 
116 
117 /***************************************************************************
118 
119 	Start the video hardware emulation.
120 
121 ***************************************************************************/
122 
VIDEO_START(splash)123 VIDEO_START( splash )
124 {
125 	screen[0] = tilemap_create(get_tile_info_splash_screen0,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,64,32);
126 	screen[1] = tilemap_create(get_tile_info_splash_screen1,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
127 	screen2 = auto_bitmap_alloc (512, 256);
128 
129 	if (!screen[0] || !screen[1] || !screen2)
130 		return 1;
131 
132 	tilemap_set_transparent_pen(screen[0],0);
133 	tilemap_set_transparent_pen(screen[1],0);
134 
135 	tilemap_set_scrollx(screen[0], 0, 4);
136 
137 	return 0;
138 }
139 
140 /***************************************************************************
141 
142 	Sprites
143 
144 ***************************************************************************/
145 
146 /*
147 	Sprite Format
148 	-------------
149 
150   	Word | Bit(s)			 | Description
151 	-----+-FEDCBA98-76543210-+--------------------------
152 	  0  | -------- xxxxxxxx | sprite number (low 8 bits)
153 	  0  | xxxxxxxx -------- | unused
154 	  1  | -------- xxxxxxxx | y position
155 	  1  | xxxxxxxx -------- | unused
156 	  2  | -------- xxxxxxxx | x position (low 8 bits)
157 	  2  | xxxxxxxx -------- | unused
158 	  3  | -------- ----xxxx | sprite number (high 4 bits)
159 	  3  | -------- --xx---- | unknown
160 	  3  | -------- -x------ | flip x
161 	  3  | -------- x------- | flip y
162 	  3  | xxxxxxxx -------- | unused
163   	  400| -------- ----xxxx | sprite color
164 	  400| -------- -xxx---- | unknown
165 	  400| -------- x------- | x position (high bit)
166 	  400| xxxxxxxx -------- | unused
167 */
168 
splash_draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)169 static void splash_draw_sprites(struct mame_bitmap *bitmap,const struct rectangle *cliprect)
170 {
171 	int i;
172 	const struct GfxElement *gfx = Machine->gfx[1];
173 
174 	for (i = 0; i < 0x400; i += 4){
175 		int sx = splash_spriteram[i+2] & 0xff;
176 		int sy = (240 - (splash_spriteram[i+1] & 0xff)) & 0xff;
177 		int attr = splash_spriteram[i+3] & 0xff;
178 		int attr2 = splash_spriteram[i+0x400] >> 8;
179 		int number = (splash_spriteram[i] & 0xff) + (attr & 0xf)*256;
180 
181 		if (attr2 & 0x80) sx += 256;
182 
183 		drawgfx(bitmap,gfx,number,
184 			0x10 + (attr2 & 0x0f),attr & 0x40,attr & 0x80,
185 			sx-8,sy,
186 			cliprect,TRANSPARENCY_PEN,0);
187 	}
188 }
189 
190 /***************************************************************************
191 
192 	Display Refresh
193 
194 ***************************************************************************/
195 
VIDEO_UPDATE(splash)196 VIDEO_UPDATE( splash )
197 {
198 	/* set scroll registers */
199 	tilemap_set_scrolly(screen[0], 0, splash_vregs[0]);
200 	tilemap_set_scrolly(screen[1], 0, splash_vregs[1]);
201 
202 	copybitmap(bitmap,screen2,0,0,0,0,cliprect,TRANSPARENCY_NONE,0);
203 
204 	tilemap_draw(bitmap,cliprect,screen[1],0,0);
205 	splash_draw_sprites(bitmap,cliprect);
206 	tilemap_draw(bitmap,cliprect,screen[0],0,0);
207 }
208