summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/splash.cpp
blob: b65f24a5e066c8a6a6b425c2cfb827f5ccc83799 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// license:BSD-3-Clause
// copyright-holders:Manuel Abadia, David Haywood
/***************************************************************************

  splash.c

  Functions to emulate the video hardware of the machine.

***************************************************************************/

#include "emu.h"
#include "includes/splash.h"

/***************************************************************************

    Callbacks for the TileMap code

***************************************************************************/

/*
    Tile format
    -----------

    Tilemap 0: (64*32, 8x8 tiles)

    Word | Bit(s)            | Description
    -----+-FEDCBA98-76543210-+--------------------------
      0  | -------- xxxxxxxx | sprite code (low 8 bits)
      0  | ----xxxx -------- | sprite code (high 4 bits)
      0  | xxxx---- -------- | color

    Tilemap 1: (32*32, 16x16 tiles)

    Word | Bit(s)            | Description
    -----+-FEDCBA98-76543210-+--------------------------
      0  | -------- -------x | flip y
      0  | -------- ------x- | flip x
      0  | -------- xxxxxx-- | sprite code (low 6 bits)
      0  | ----xxxx -------- | sprite code (high 4 bits)
      0  | xxxx---- -------- | color
*/

TILE_GET_INFO_MEMBER(splash_state::get_tile_info_tilemap0)
{
	int data = m_videoram[tile_index];
	int attr = data >> 8;
	int code = data & 0xff;

	tileinfo.set(0,
			code + ((0x20 + (attr & 0x0f)) << 8),
			(attr & 0xf0) >> 4,
			0);
}

TILE_GET_INFO_MEMBER(splash_state::get_tile_info_tilemap1)
{
	int data = m_videoram[(0x1000/2) + tile_index];
	int attr = data >> 8;
	int code = data & 0xff;

	tileinfo.set(1,
			(code >> 2) + ((0x30 + (attr & 0x0f)) << 6),
			(attr & 0xf0) >> 4,
			TILE_FLIPXY(code & 0x03));
}

/***************************************************************************

    Memory Handlers

***************************************************************************/

WRITE16_MEMBER(splash_state::vram_w)
{
	COMBINE_DATA(&m_videoram[offset]);
	m_bg_tilemap[offset >> 11]->mark_tile_dirty(((offset << 1) & 0x0fff) >> 1);
}

void splash_state::draw_bitmap(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int colxor = 0; /* splash and some bitmap modes in roldfrog */
	int swaps = 0;

	if (m_bitmap_type == 1) /* roldfrog */
	{
		if (m_bitmap_mode[0] == 0x0000)
		{
			colxor = 0x7f;
		}
		else if (m_bitmap_mode[0] == 0x0100)
		{
			swaps = 1;
		}
		else if (m_bitmap_mode[0] == 0x0200)
		{
			colxor = 0x55;
		}
		else if (m_bitmap_mode[0] == 0x0300)
		{
			swaps = 2;
			colxor = 0x7f;
		}
		else if (m_bitmap_mode[0] == 0x0400)
		{
			swaps = 3;
		}
		else if (m_bitmap_mode[0] == 0x0500)
		{
			swaps = 4;
		}
		else if (m_bitmap_mode[0] == 0x0600)
		{
			swaps = 5;
			colxor = 0x7f;
		}
		else if (m_bitmap_mode[0] == 0x0700)
		{
			swaps = 6;
			colxor = 0x55;
		}
	}

	int count = 0;
	for (int sy=0;sy<256;sy++)
	{
		for (int sx=0;sx<512;sx++)
		{
			int color = m_pixelram[count]&0xff;
			count++;

			switch (swaps)
			{
			case 1:
				color = bitswap<8>(color,7,0,1,2,3,4,5,6);
				break;
			case 2:
				color = bitswap<8>(color,7,4,6,5,1,0,3,2);
				break;
			case 3:
				color = bitswap<8>(color,7,3,2,1,0,6,5,4);
				break;
			case 4:
				color = bitswap<8>(color,7,6,4,2,0,5,3,1);
				break;
			case 5:
				color = bitswap<8>(color,7,0,6,5,4,3,2,1);
				break;
			case 6:
				color = bitswap<8>(color,7,4,3,2,1,0,6,5);
				break;
			}

			if (sy >= cliprect.min_y && sy <= cliprect.max_y && sx-9 >= cliprect.min_x && sx-9 <= cliprect.max_x)
				bitmap.pix16(sy, sx-9) = 0x300+(color^colxor);
		}
	}

}
/***************************************************************************

    Start the video hardware emulation.

***************************************************************************/

void splash_state::video_start()
{
	m_bg_tilemap[0] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(splash_state::get_tile_info_tilemap0)), TILEMAP_SCAN_ROWS,  8,  8, 64, 32);
	m_bg_tilemap[1] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(splash_state::get_tile_info_tilemap1)), TILEMAP_SCAN_ROWS, 16, 16, 32, 32);

	m_bg_tilemap[0]->set_transparent_pen(0);
	m_bg_tilemap[1]->set_transparent_pen(0);

	m_bg_tilemap[0]->set_scrollx(0, 4);
}

/***************************************************************************

    Sprites

***************************************************************************/

/*
    Sprite Format
    -------------

    Word | Bit(s)            | Description
    -----+-FEDCBA98-76543210-+--------------------------
      0  | -------- xxxxxxxx | sprite number (low 8 bits)
      0  | xxxxxxxx -------- | unused
      1  | -------- xxxxxxxx | y position
      1  | xxxxxxxx -------- | unused
      2  | -------- xxxxxxxx | x position (low 8 bits)
      2  | xxxxxxxx -------- | unused
      3  | -------- ----xxxx | sprite number (high 4 bits)
      3  | -------- --xx---- | unknown
      3  | -------- -x------ | flip x
      3  | -------- x------- | flip y
      3  | xxxxxxxx -------- | unused
      400| -------- ----xxxx | sprite color
      400| -------- -xxx---- | unknown
      400| -------- x------- | x position (high bit)
      400| xxxxxxxx -------- | unused
*/

void splash_state::draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect)
{
	int i;
	gfx_element *gfx = m_gfxdecode->gfx(1);

	for (i = 0x400-4; i >= 0; i -= 4)
	{
		int sx = m_spriteram[i+2] & 0xff;
		int sy = (240 - (m_spriteram[i+1] & 0xff)) & 0xff;
		int attr = m_spriteram[i+3] & 0xff;
		int attr2 = m_spriteram[i+0x400] >> m_sprite_attr2_shift;
		int number = (m_spriteram[i] & 0xff) + (attr & 0xf)*256;

		if (attr2 & 0x80) sx += 256;

		gfx->transpen(bitmap,cliprect,number,
			0x10 + (attr2 & 0x0f),attr & 0x40,attr & 0x80,
			sx-8,sy,0);
	}
}

void funystrp_state::funystrp_draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect)
{
	int i;
	gfx_element *gfx = m_gfxdecode->gfx(1);

	for (i = 0x400-4; i >= 0; i -= 4)
	{
		int sx = m_spriteram[i+2] & 0xff;
		int sy = (240 - (m_spriteram[i+1] & 0xff)) & 0xff;
		int attr = m_spriteram[i+3] & 0xff;
		int attr2 = m_spriteram[i+0x400] >> m_sprite_attr2_shift;
		int number = (m_spriteram[i] & 0xff) + (attr & 0xf)*256;

		if (attr2 & 0x80) sx += 256;

		gfx->transpen(bitmap,cliprect,number,
			(attr2 & 0x7f),attr & 0x40,attr & 0x80,
			sx-8,sy,0);
	}
}

/***************************************************************************

    Display Refresh

***************************************************************************/

uint32_t splash_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	/* set scroll registers */
	m_bg_tilemap[0]->set_scrolly(0, m_vregs[0]);
	m_bg_tilemap[1]->set_scrolly(0, m_vregs[1]);

	draw_bitmap(bitmap, cliprect);

	m_bg_tilemap[1]->draw(screen, bitmap, cliprect, 0, 0);
	draw_sprites(bitmap, cliprect);
	m_bg_tilemap[0]->draw(screen, bitmap, cliprect, 0, 0);
	return 0;
}

uint32_t funystrp_state::screen_update_funystrp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	/* set scroll registers */
	m_bg_tilemap[0]->set_scrolly(0, m_vregs[0]);
	m_bg_tilemap[1]->set_scrolly(0, m_vregs[1]);

	draw_bitmap(bitmap, cliprect);

	m_bg_tilemap[1]->draw(screen, bitmap, cliprect, 0, 0);
	/*Sprite chip is similar but not the same*/
	funystrp_draw_sprites(bitmap, cliprect);
	m_bg_tilemap[0]->draw(screen, bitmap, cliprect, 0, 0);
	return 0;
}