summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/angelkds.cpp
blob: afe1501c3a6872123109933a1b499c18f86e77af (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
// license:BSD-3-Clause
// copyright-holders:David Haywood
/* video/angelkds.c - see drivers/angelkds.c for more info */

/* graphical issues

enable / disable tilemap bits might be wrong

*/

#include "emu.h"
#include "includes/angelkds.h"
#include "screen.h"


/*** Text Layer Tilemap

*/

TILE_GET_INFO_MEMBER(angelkds_state::get_tx_tile_info)
{
	int tileno;

	tileno = m_txvideoram[tile_index] + (m_txbank * 0x100);
	SET_TILE_INFO_MEMBER(0, tileno, 0, 0);
}

WRITE8_MEMBER(angelkds_state::angelkds_txvideoram_w)
{
	m_txvideoram[offset] = data;
	m_tx_tilemap->mark_tile_dirty(offset);
}

WRITE8_MEMBER(angelkds_state::angelkds_txbank_write)
{
	if (m_txbank != data)
	{
		m_txbank = data;
		m_tx_tilemap->mark_all_dirty();
	}
}

/*** Top Half Background Tilemap

*/

TILE_GET_INFO_MEMBER(angelkds_state::get_bgtop_tile_info)
{
	int tileno;

	tileno = m_bgtopvideoram[tile_index];

	tileno += m_bgtopbank * 0x100 ;
	SET_TILE_INFO_MEMBER(1, tileno, 0, 0);
}

WRITE8_MEMBER(angelkds_state::angelkds_bgtopvideoram_w)
{
	m_bgtopvideoram[offset] = data;
	m_bgtop_tilemap->mark_tile_dirty(offset);
}

WRITE8_MEMBER(angelkds_state::angelkds_bgtopbank_write)
{
	if (m_bgtopbank != data)
	{
		m_bgtopbank = data;
		m_bgtop_tilemap->mark_all_dirty();
	}
}

WRITE8_MEMBER(angelkds_state::angelkds_bgtopscroll_write)
{
	m_bgtop_tilemap->set_scrollx(0, data);
}

/*** Bottom Half Background Tilemap

*/

TILE_GET_INFO_MEMBER(angelkds_state::get_bgbot_tile_info)
{
	int tileno;

	tileno = m_bgbotvideoram[tile_index];

	tileno += m_bgbotbank * 0x100 ;
	SET_TILE_INFO_MEMBER(2, tileno, 1, 0);
}

WRITE8_MEMBER(angelkds_state::angelkds_bgbotvideoram_w)
{
	m_bgbotvideoram[offset] = data;
	m_bgbot_tilemap->mark_tile_dirty(offset);
}


WRITE8_MEMBER(angelkds_state::angelkds_bgbotbank_write)
{
	if (m_bgbotbank != data)
	{
		m_bgbotbank = data;
		m_bgbot_tilemap->mark_all_dirty();
	}
}

WRITE8_MEMBER(angelkds_state::angelkds_bgbotscroll_write)
{
	m_bgbot_tilemap->set_scrollx(0, data);
}


WRITE8_MEMBER(angelkds_state::angelkds_layer_ctrl_write)
{
	m_layer_ctrl = data;
}

/*** Sprites

the sprites are similar to the tilemaps in the sense that there is
a split down the middle of the screen

*/

void angelkds_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, int enable_n)
{
	const uint8_t *source = m_spriteram + 0x100 - 4;
	const uint8_t *finish = m_spriteram;
	gfx_element *gfx = m_gfxdecode->gfx(3);

	while (source >= finish)
	{
	/*

	nnnn nnnn - EeFf B?cc - yyyy yyyy - xxxx xxxx

	n = sprite number
	E = Sprite Enabled in Top Half of Screen
	e = Sprite Enabled in Bottom Half of Screen
	F = Flip Y
	f = Flip X
	B = Tile Bank
	? = unknown, nothing / unused? recheck
	c = color
	y = Y position
	x = X position

	*/
		uint16_t tile_no = source[0];
		uint8_t attr = source[1];
		uint8_t ypos = source[2];
		uint8_t xpos = source[3];

		uint8_t enable = attr & 0xc0;
		uint8_t flipx = (attr & 0x10) >> 4;
		uint8_t flipy = (attr & 0x20) >> 5;
		uint8_t bank = attr & 0x08;
		uint8_t color = attr & 0x03;

		if (bank)
			tile_no += 0x100;

		ypos = 0xff - ypos;

		if (enable & enable_n)
		{
					gfx->transpen(
					bitmap,
					cliprect,
					tile_no,
					color*4,
					flipx,flipy,
					xpos,ypos,15
					);
			/* wraparound */
			if (xpos > 240)

						gfx->transpen(
						bitmap,
						cliprect,
						tile_no,
						color*4,
						flipx,flipy,
						xpos-256,ypos,15
						);
			/* wraparound */
			if (ypos > 240)
			{
						gfx->transpen(
						bitmap,
						cliprect,
						tile_no,
						color*4,
						flipx,flipy,
						xpos,ypos-256,15
						);
				/* wraparound */
				if (xpos > 240)

							gfx->transpen(
							bitmap,
							cliprect,
							tile_no,
							color*4,
							flipx,flipy,
							xpos-256,ypos-256,15
							);
			}
		}

		source -= 0x04;
	}

}


/*** Video Start & Update

*/

void angelkds_state::video_start()
{
	m_tx_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(angelkds_state::get_tx_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
	m_tx_tilemap->set_transparent_pen(0);

	m_bgbot_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(angelkds_state::get_bgbot_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
	m_bgbot_tilemap->set_transparent_pen(15);

	m_bgtop_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(angelkds_state::get_bgtop_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
	m_bgtop_tilemap->set_transparent_pen(15);
}

/* enable bits are uncertain */

uint32_t angelkds_state::screen_update_angelkds(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	const rectangle &visarea = screen.visible_area();
	rectangle clip;

	bitmap.fill(0x3f, cliprect); /* is there a register controlling the colour?, we currently use the last colour of the tx palette */

	/* draw top of screen */
	clip.set(8*0, 8*16-1, visarea.min_y, visarea.max_y);

	if ((m_layer_ctrl & 0x80) == 0x00)
		m_bgtop_tilemap->draw(screen, bitmap, clip, 0, 0);

	draw_sprites(bitmap, clip, 0x80);

	if ((m_layer_ctrl & 0x20) == 0x00)
		m_tx_tilemap->draw(screen, bitmap, clip, 0, 0);

	/* draw bottom of screen */
	clip.set(8*16, 8*32-1, visarea.min_y, visarea.max_y);

	if ((m_layer_ctrl & 0x40) == 0x00)
		m_bgbot_tilemap->draw(screen, bitmap, clip, 0, 0);

	draw_sprites(bitmap, clip, 0x40);

	if ((m_layer_ctrl & 0x20) == 0x00)
		m_tx_tilemap->draw(screen, bitmap, clip, 0, 0);

	return 0;
}