summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/skyraid.c
blob: 4bcd8eab7641af006ae757ad81b94a5f00beca3f (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
/***************************************************************************

Atari Sky Raider video emulation

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

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


VIDEO_START( skyraid )
{
	skyraid_state *state = machine.driver_data<skyraid_state>();

	state->m_helper.allocate(128, 240);
}


static void draw_text(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	skyraid_state *state = machine.driver_data<skyraid_state>();
	const UINT8* p = state->m_alpha_num_ram;

	int i;

	for (i = 0; i < 4; i++)
	{
		int x;
		int y;

		y = 136 + 16 * (i ^ 1);

		for (x = 0; x < bitmap.width(); x += 16)
			drawgfx_transpen(bitmap, cliprect, machine.gfx[0], *p++, 0, 0, 0,	x, y, 0);
	}
}


static void draw_terrain(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	skyraid_state *state = machine.driver_data<skyraid_state>();
	const UINT8* p = machine.region("user1")->base();

	int x;
	int y;

	for (y = 0; y < bitmap.height(); y++)
	{
		int offset = (16 * state->m_scroll + 16 * ((y + 1) / 2)) & 0x7FF;

		x = 0;

		while (x < bitmap.width())
		{
			UINT8 val = p[offset++];

			int color = val / 32;
			int count = val % 32;

			rectangle r(x, x + 31 - count, y, y+ 1);

			bitmap.fill(color, r);

			x += 32 - count;
		}
	}
}


static void draw_sprites(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	skyraid_state *state = machine.driver_data<skyraid_state>();
	int i;

	for (i = 0; i < 4; i++)
	{
		int code = state->m_obj_ram[8 + 2 * i + 0] & 15;
		int flag = state->m_obj_ram[8 + 2 * i + 1] & 15;
		int vert = state->m_pos_ram[8 + 2 * i + 0];
		int horz = state->m_pos_ram[8 + 2 * i + 1];

		vert -= 31;

		if (flag & 1)
			drawgfx_transpen(bitmap, cliprect, machine.gfx[1],
				code ^ 15, code >> 3, 0, 0,
				horz / 2, vert, 2);
	}
}


static void draw_missiles(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	skyraid_state *state = machine.driver_data<skyraid_state>();
	int i;

	/* hardware is restricted to one sprite per scanline */

	for (i = 0; i < 4; i++)
	{
		int code = state->m_obj_ram[2 * i + 0] & 15;
		int vert = state->m_pos_ram[2 * i + 0];
		int horz = state->m_pos_ram[2 * i + 1];

		vert -= 15;
		horz -= 31;

		drawgfx_transpen(bitmap, cliprect, machine.gfx[2],
			code ^ 15, 0, 0, 0,
			horz / 2, vert, 0);
	}
}


static void draw_trapezoid(running_machine &machine, bitmap_ind16& dst, bitmap_ind16& src)
{
	const UINT8* p = machine.region("user2")->base();

	int x;
	int y;

	for (y = 0; y < dst.height(); y++)
	{
		UINT16* pSrc = &src.pix16(y);
		UINT16* pDst = &dst.pix16(y);

		int x1 = 0x000 + p[(y & ~1) + 0];
		int x2 = 0x100 + p[(y & ~1) + 1];

		for (x = x1; x < x2; x++)
			pDst[x] = pSrc[128 * (x - x1) / (x2 - x1)];
	}
}


SCREEN_UPDATE_IND16( skyraid )
{
	skyraid_state *state = screen.machine().driver_data<skyraid_state>();

	bitmap.fill(0, cliprect);

	rectangle helper_clip = cliprect;
	helper_clip &= state->m_helper.cliprect();

	draw_terrain(screen.machine(), state->m_helper, helper_clip);
	draw_sprites(screen.machine(), state->m_helper, helper_clip);
	draw_missiles(screen.machine(), state->m_helper, helper_clip);
	draw_trapezoid(screen.machine(), bitmap, state->m_helper);
	draw_text(screen.machine(), bitmap, cliprect);
	return 0;
}