summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/vastar.c
blob: 50aedba1f36952b45d393159032924ce960385b1 (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
/***************************************************************************

  video.c

  Functions to emulate the video hardware of the machine.

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

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


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

  Callbacks for the TileMap code

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

TILE_GET_INFO_MEMBER(vastar_state::get_fg_tile_info)
{
	UINT8 *videoram = m_fgvideoram;
	int code, color, fxy;

	code = videoram[tile_index + 0x800] | (videoram[tile_index + 0x400] << 8);
	color = videoram[tile_index];
	fxy = (code & 0xc00) >> 10; // maybe, based on the other layers
	SET_TILE_INFO_MEMBER(
			0,
			code,
			color & 0x3f,
			TILE_FLIPXY(fxy));
}

TILE_GET_INFO_MEMBER(vastar_state::get_bg1_tile_info)
{
	UINT8 *videoram = m_bg1videoram;
	int code, color, fxy;

	code = videoram[tile_index + 0x800] | (videoram[tile_index] << 8);
	color = videoram[tile_index + 0xc00];
	fxy = (code & 0xc00) >> 10;
	SET_TILE_INFO_MEMBER(
			4,
			code,
			color & 0x3f,
			TILE_FLIPXY(fxy));
}

TILE_GET_INFO_MEMBER(vastar_state::get_bg2_tile_info)
{
	UINT8 *videoram = m_bg2videoram;
	int code, color, fxy;

	code = videoram[tile_index + 0x800] | (videoram[tile_index] << 8);
	color = videoram[tile_index + 0xc00];
	fxy = (code & 0xc00) >> 10;
	SET_TILE_INFO_MEMBER(
			3,
			code,
			color & 0x3f,
			TILE_FLIPXY(fxy));
}


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

  Start the video hardware emulation.

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

void vastar_state::video_start()
{
	m_fg_tilemap  = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(vastar_state::get_fg_tile_info),this), TILEMAP_SCAN_ROWS,8,8,32,32);
	m_bg1_tilemap = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(vastar_state::get_bg1_tile_info),this),TILEMAP_SCAN_ROWS,8,8,32,32);
	m_bg2_tilemap = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(vastar_state::get_bg2_tile_info),this),TILEMAP_SCAN_ROWS,8,8,32,32);

	m_fg_tilemap->set_transparent_pen(0);
	m_bg1_tilemap->set_transparent_pen(0);
	m_bg2_tilemap->set_transparent_pen(0);

	m_bg1_tilemap->set_scroll_cols(32);
	m_bg2_tilemap->set_scroll_cols(32);
}


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

  Memory handlers

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

WRITE8_MEMBER(vastar_state::vastar_fgvideoram_w)
{
	m_fgvideoram[offset] = data;
	m_fg_tilemap->mark_tile_dirty(offset & 0x3ff);
}

WRITE8_MEMBER(vastar_state::vastar_bg1videoram_w)
{
	m_bg1videoram[offset] = data;
	m_bg1_tilemap->mark_tile_dirty(offset & 0x3ff);
}

WRITE8_MEMBER(vastar_state::vastar_bg2videoram_w)
{
	m_bg2videoram[offset] = data;
	m_bg2_tilemap->mark_tile_dirty(offset & 0x3ff);
}




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

  Display refresh

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

// I wouldn't rule out the possibility of there being 2 sprite chips due to
// "offs & 0x20" being used to select the tile bank.
//
// for Planet Probe more cases appear correct if we draw the list in reverse
// order, but it's also possible we should be drawing 2 swapped lists in
// forward order instead
static void draw_sprites(running_machine &machine, bitmap_ind16 &bitmap,const rectangle &cliprect)
{
	vastar_state *state = machine.driver_data<vastar_state>();
	UINT8 *spriteram = state->m_spriteram1;
	UINT8 *spriteram_2 = state->m_spriteram2;
	UINT8 *spriteram_3 = state->m_spriteram3;
	int offs;

//	for (offs = 0; offs < 0x40; offs += 2)
	for (offs = 0x40-2; offs >=0; offs -= 2)
	{
		int code, sx, sy, color, flipx, flipy;


		code = ((spriteram_3[offs] & 0xfc) >> 2) + ((spriteram_2[offs] & 0x01) << 6)
				+ ((offs & 0x20) << 2);

		sx = spriteram_3[offs + 1];
		sy = spriteram[offs];
		color = spriteram[offs + 1] & 0x3f;
		flipx = spriteram_3[offs] & 0x02;
		flipy = spriteram_3[offs] & 0x01;

		if (state->flip_screen())
		{
			flipx = !flipx;
			flipy = !flipy;
		}

		if (spriteram_2[offs] & 0x08)	/* double width */
		{
			if (!state->flip_screen())
				sy = 224 - sy;

			drawgfx_transpen(bitmap,cliprect,machine.gfx[2],
					code/2,
					color,
					flipx,flipy,
					sx,sy,0);
			/* redraw with wraparound */
			drawgfx_transpen(bitmap,cliprect,machine.gfx[2],
					code/2,
					color,
					flipx,flipy,
					sx,sy+256,0);
		}
		else
		{
			if (!state->flip_screen())
				sy = 240 - sy;

			drawgfx_transpen(bitmap,cliprect,machine.gfx[1],
					code,
					color,
					flipx,flipy,
					sx,sy,0);
		}
	}
}

UINT32 vastar_state::screen_update_vastar(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int i;

	for (i = 0;i < 32;i++)
	{
		m_bg1_tilemap->set_scrolly(i,m_bg1_scroll[i]);
		m_bg2_tilemap->set_scrolly(i,m_bg2_scroll[i]);
	}

	switch (*m_sprite_priority)
	{
	case 0:
		m_bg1_tilemap->draw(bitmap, cliprect, TILEMAP_DRAW_OPAQUE,0);
		draw_sprites(machine(), bitmap,cliprect);
		m_bg2_tilemap->draw(bitmap, cliprect, 0,0);
		m_fg_tilemap->draw(bitmap, cliprect, 0,0);
		break;

	case 1: // ?? planet probe
		m_bg1_tilemap->draw(bitmap, cliprect, TILEMAP_DRAW_OPAQUE,0);
		m_bg2_tilemap->draw(bitmap, cliprect, 0,0);
		draw_sprites(machine(), bitmap,cliprect);
		m_fg_tilemap->draw(bitmap, cliprect, 0,0);
		break;

	case 2:
		m_bg1_tilemap->draw(bitmap, cliprect, TILEMAP_DRAW_OPAQUE,0);
		draw_sprites(machine(), bitmap,cliprect);
		m_bg1_tilemap->draw(bitmap, cliprect, 0,0);
		m_bg2_tilemap->draw(bitmap, cliprect, 0,0);
		m_fg_tilemap->draw(bitmap, cliprect, 0,0);
		break;

	case 3:
		m_bg1_tilemap->draw(bitmap, cliprect, TILEMAP_DRAW_OPAQUE,0);
		m_bg2_tilemap->draw(bitmap, cliprect, 0,0);
		m_fg_tilemap->draw(bitmap, cliprect, 0,0);
		draw_sprites(machine(), bitmap,cliprect);
		break;

	default:
		logerror("Unimplemented priority %X\n", *m_sprite_priority);
		break;
	}
	return 0;
}