summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/angelkds.c
blob: e81b0edaa03eb0942a3ef316da5c96ff79724216 (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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* video/angelkds.c - see drivers/angelkds.c for more info */

/* graphical issues

enable / disable tilemap bits might be wrong

*/

#include "driver.h"
#include "angelkds.h"


/*** Text Layer Tilemap

*/

static TILE_GET_INFO( get_tx_tile_info )
{
	angelkds_state *state = (angelkds_state *)machine->driver_data;
	int tileno;

	tileno = state->txvideoram[tile_index] + (state->txbank * 0x100);
	SET_TILE_INFO(0, tileno, 0, 0);
}

WRITE8_HANDLER( angelkds_txvideoram_w )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;

	state->txvideoram[offset] = data;
	tilemap_mark_tile_dirty(state->tx_tilemap, offset);
}

WRITE8_HANDLER( angelkds_txbank_write )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;

	if (state->txbank != data)
	{
		state->txbank = data;
		tilemap_mark_all_tiles_dirty(state->tx_tilemap);
	}
}

/*** Top Half Background Tilemap

*/

static TILE_GET_INFO( get_bgtop_tile_info )
{
	angelkds_state *state = (angelkds_state *)machine->driver_data;
	int tileno;

	tileno = state->bgtopvideoram[tile_index];

	tileno += state->bgtopbank * 0x100 ;
	SET_TILE_INFO(1, tileno, 0, 0);
}

WRITE8_HANDLER( angelkds_bgtopvideoram_w )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;

	state->bgtopvideoram[offset] = data;
	tilemap_mark_tile_dirty(state->bgtop_tilemap, offset);
}

WRITE8_HANDLER( angelkds_bgtopbank_write )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;

	if (state->bgtopbank != data)
	{
		state->bgtopbank = data;
		tilemap_mark_all_tiles_dirty(state->bgtop_tilemap);
	}
}

WRITE8_HANDLER( angelkds_bgtopscroll_write )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;

	tilemap_set_scrollx(state->bgtop_tilemap, 0, data);
}

/*** Bottom Half Background Tilemap

*/

static TILE_GET_INFO( get_bgbot_tile_info )
{
	angelkds_state *state = (angelkds_state *)machine->driver_data;
	int tileno;

	tileno = state->bgbotvideoram[tile_index];

	tileno += state->bgbotbank * 0x100 ;
	SET_TILE_INFO(2, tileno, 1, 0);
}

WRITE8_HANDLER( angelkds_bgbotvideoram_w )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;

	state->bgbotvideoram[offset] = data;
	tilemap_mark_tile_dirty(state->bgbot_tilemap, offset);
}


WRITE8_HANDLER( angelkds_bgbotbank_write )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;

	if (state->bgbotbank != data)
	{
		state->bgbotbank = data;
		tilemap_mark_all_tiles_dirty(state->bgbot_tilemap);
	}
}

WRITE8_HANDLER( angelkds_bgbotscroll_write )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;

	tilemap_set_scrollx(state->bgbot_tilemap, 0, data);
}


WRITE8_HANDLER( angelkds_layer_ctrl_write )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;

	state->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

*/

static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int enable_n)
{
	angelkds_state *state = (angelkds_state *)machine->driver_data;
	const UINT8 *source = state->spriteram + 0x100 - 4;
	const UINT8 *finish = state->spriteram;
	const gfx_element *gfx = machine->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 tile_no = source[0];
		UINT8 attr = source[1];
		UINT8 ypos = source[2];
		UINT8 xpos = source[3];

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

		if (bank) 
			tile_no += 0x100;

		ypos = 0xff - ypos;

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

		source -= 0x04;
	}

}


/*** Palette Handling

 4 bits of Red, 4 bits of Green, 4 bits of Blue

*/

WRITE8_HANDLER( angelkds_paletteram_w )
{
	angelkds_state *state = (angelkds_state *)space->machine->driver_data;
	int no;

	state->paletteram[offset] = data;

	no = offset & 0xff;
	palette_set_color_rgb(space->machine, no, pal4bit(state->paletteram[no]), pal4bit(state->paletteram[no]>>4), pal4bit(state->paletteram[no + 0x100]));
}

/*** Video Start & Update

*/

VIDEO_START( angelkds )
{
	angelkds_state *state = (angelkds_state *)machine->driver_data;

	state->tx_tilemap = tilemap_create(machine, get_tx_tile_info, tilemap_scan_rows, 8, 8, 32, 32);
	tilemap_set_transparent_pen(state->tx_tilemap, 0);

	state->bgbot_tilemap = tilemap_create(machine, get_bgbot_tile_info, tilemap_scan_rows, 8, 8, 32, 32);
	tilemap_set_transparent_pen(state->bgbot_tilemap, 15);

	state->bgtop_tilemap = tilemap_create(machine, get_bgtop_tile_info, tilemap_scan_rows, 8, 8, 32, 32);
	tilemap_set_transparent_pen(state->bgtop_tilemap, 15);
}

/* enable bits are uncertain */

VIDEO_UPDATE( angelkds )
{
	angelkds_state *state = (angelkds_state *)screen->machine->driver_data;
	const rectangle *visarea = video_screen_get_visible_area(screen);
	rectangle clip;

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

	/* draw top of screen */
	clip.min_x = 8*0;
	clip.max_x = 8*16-1;
	clip.min_y = visarea->min_y;
	clip.max_y = visarea->max_y;

	if ((state->layer_ctrl & 0x80) == 0x00) 
		tilemap_draw(bitmap, &clip, state->bgtop_tilemap, 0, 0);

	draw_sprites(screen->machine, bitmap, &clip, 0x80);

	if ((state->layer_ctrl & 0x20) == 0x00) 
		tilemap_draw(bitmap, &clip, state->tx_tilemap, 0, 0);

	/* draw bottom of screen */
	clip.min_x = 8*16;
	clip.max_x = 8*32-1;
	clip.min_y = visarea->min_y;
	clip.max_y = visarea->max_y;

	if ((state->layer_ctrl & 0x40) == 0x00) 
		tilemap_draw(bitmap, &clip, state->bgbot_tilemap, 0, 0);

	draw_sprites(screen->machine, bitmap, &clip, 0x40);

	if ((state->layer_ctrl & 0x20) == 0x00) 
		tilemap_draw(bitmap, &clip, state->tx_tilemap, 0, 0);

	return 0;
}