summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/ambush.c
blob: 60f6273b2a0b85a5771416785515e9e8f4ca695b (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
/***************************************************************************

  video.c

  Functions to emulate the video hardware of the machine.

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

#include "driver.h"


UINT8 *ambush_scrollram;
UINT8 *ambush_colorbank;


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

  Convert the color PROMs into a more useable format.

  I'm not sure about the resistor value, I'm using the Galaxian ones.

***************************************************************************/
PALETTE_INIT( ambush )
{
	int i;

	for (i = 0;i < machine->drv->total_colors; i++)
	{
		int bit0,bit1,bit2,r,g,b;

		/* red component */
		bit0 = (color_prom[i] >> 0) & 0x01;
		bit1 = (color_prom[i] >> 1) & 0x01;
		bit2 = (color_prom[i] >> 2) & 0x01;
		r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
		/* green component */
		bit0 = (color_prom[i] >> 3) & 0x01;
		bit1 = (color_prom[i] >> 4) & 0x01;
		bit2 = (color_prom[i] >> 5) & 0x01;
		g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
		/* blue component */
		bit0 = 0;
		bit1 = (color_prom[i] >> 6) & 0x01;
		bit2 = (color_prom[i] >> 7) & 0x01;
		b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		palette_set_color(machine,i,MAKE_RGB(r,g,b));
	}
}


static void draw_chars(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect, int priority)
{
	int offs, transparency;


	transparency = (priority == 0) ? TRANSPARENCY_NONE : TRANSPARENCY_PEN;

	for (offs = 0; offs < videoram_size; offs++)
	{
		int code,sx,sy,col;
		UINT8 scroll;


		sy = (offs / 32);
		sx = (offs % 32);

		col = colorram[((sy & 0x1c) << 3) + sx];

		if ((col & 0x10) != priority)  continue;

		scroll = ~ambush_scrollram[sx];

		code = videoram[offs] | ((col & 0x60) << 3);

		if (flip_screen)
		{
			sx = 31 - sx;
			sy = 31 - sy;
			scroll = ~scroll - 1;
		}

		drawgfx(bitmap,machine->gfx[0],
				code,
				(col & 0x0f) | ((*ambush_colorbank & 0x03) << 4),
				flip_screen,flip_screen,
				8*sx, (8*sy + scroll) & 0xff,
				cliprect,transparency,0);
	}
}


VIDEO_UPDATE( ambush )
{
	int offs;


	fillbitmap(bitmap,machine->pens[0],cliprect);


	/* Draw the background priority characters */
	draw_chars(machine, bitmap, cliprect, 0x00);


	/* Draw the sprites. */
	for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
	{
		int code,col,sx,sy,flipx,flipy,gfx;


		sy = spriteram[offs + 0];
		sx = spriteram[offs + 3];

		if ( (sy == 0) ||
			 (sy == 0xff) ||
			((sx <  0x40) && (  spriteram[offs + 2] & 0x10)) ||
			((sx >= 0xc0) && (!(spriteram[offs + 2] & 0x10))))  continue;  /* prevent wraparound */


		code = (spriteram[offs + 1] & 0x3f) | ((spriteram[offs + 2] & 0x60) << 1);

		if (spriteram[offs + 2] & 0x80)
		{
			/* 16x16 sprites */
			gfx = 1;

			if (!flip_screen)
			{
				sy = 240 - sy;
			}
			else
			{
				sx = 240 - sx;
			}
		}
		else
		{
			/* 8x8 sprites */
			gfx = 0;
			code <<= 2;

			if (!flip_screen)
			{
				sy = 248 - sy;
			}
			else
			{
				sx = 248 - sx;
			}
		}

		col   = spriteram[offs + 2] & 0x0f;
		flipx = spriteram[offs + 1] & 0x40;
		flipy = spriteram[offs + 1] & 0x80;

		if (flip_screen)
		{
			flipx = !flipx;
			flipy = !flipy;
		}

		drawgfx(bitmap,machine->gfx[gfx],
				code, col | ((*ambush_colorbank & 0x03) << 4),
				flipx, flipy,
				sx,sy,
				cliprect,TRANSPARENCY_PEN,0);
	}


	/* Draw the foreground priority characters */
	draw_chars(machine, bitmap, cliprect, 0x10);
	return 0;
}