summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/subs.c
blob: 16c67b2bb03eae2da48f455e1c4249b35d484065 (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
/***************************************************************************

    Atari Subs hardware

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

#include "emu.h"
#include "includes/subs.h"
#include "sound/discrete.h"

WRITE8_HANDLER( subs_invert1_w )
{
	if ((offset & 0x01) == 1)
	{
		palette_set_color(space->machine(), 0, MAKE_RGB(0x00, 0x00, 0x00));
		palette_set_color(space->machine(), 1, MAKE_RGB(0xFF, 0xFF, 0xFF));
	}
	else
	{
		palette_set_color(space->machine(), 1, MAKE_RGB(0x00, 0x00, 0x00));
		palette_set_color(space->machine(), 0, MAKE_RGB(0xFF, 0xFF, 0xFF));
	}
}

WRITE8_HANDLER( subs_invert2_w )
{
	if ((offset & 0x01) == 1)
	{
		palette_set_color(space->machine(), 2, MAKE_RGB(0x00, 0x00, 0x00));
		palette_set_color(space->machine(), 3, MAKE_RGB(0xFF, 0xFF, 0xFF));
	}
	else
	{
		palette_set_color(space->machine(), 3, MAKE_RGB(0x00, 0x00, 0x00));
		palette_set_color(space->machine(), 2, MAKE_RGB(0xFF, 0xFF, 0xFF));
	}
}


SCREEN_UPDATE( subs_left )
{
	subs_state *state = screen.machine().driver_data<subs_state>();
	UINT8 *videoram = state->m_videoram;
	UINT8 *spriteram = state->m_spriteram;
	int offs;

	device_t *discrete = screen.machine().device("discrete");

	/* for every character in the Video RAM, check if it has been modified */
	/* since last time and update it accordingly. */
	for (offs = 0x400 - 1; offs >= 0; offs--)
	{
		int charcode;
		int sx,sy;
		int left_enable; //,right_enable;
		int left_sonar_window,right_sonar_window;

		left_sonar_window = 0;
		right_sonar_window = 0;

		charcode = videoram[offs];

		/* Which monitor is this for? */
//      right_enable = charcode & 0x40;
		left_enable = charcode & 0x80;

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

		/* Special hardware logic for sonar windows */
		if ((sy >= (128+64)) && (sx < 32))
			left_sonar_window = 1;
		else if ((sy >= (128+64)) && (sx >= (128+64+32)))
			right_sonar_window = 1;
		else
			charcode = charcode & 0x3F;

		/* draw the left screen */
		if ((left_enable || left_sonar_window) && (!right_sonar_window))
			drawgfx_opaque(bitmap,cliprect,screen.machine().gfx[0],
					charcode, 1,
					0,0,sx,sy);
		else
			drawgfx_opaque(bitmap,cliprect,screen.machine().gfx[0],
					0, 1,
					0,0,sx,sy);
	}

	/* draw the motion objects */
	for (offs = 0; offs < 4; offs++)
	{
		int sx,sy;
		int charcode;
		int prom_set;
		int sub_enable;

		sx = spriteram[0x00 + (offs * 2)] - 16;
		sy = spriteram[0x08 + (offs * 2)] - 16;
		charcode = spriteram[0x09 + (offs * 2)];
		if (offs < 2)
			sub_enable = spriteram[0x01 + (offs * 2)] & 0x80;
		else
			sub_enable = 1;

		prom_set = charcode & 0x01;
		charcode = (charcode >> 3) & 0x1F;

		/* left screen - special check for drawing right screen's sub */
		if ((offs!=0) || (sub_enable))
			drawgfx_transpen(bitmap,cliprect,screen.machine().gfx[1],
					charcode + 32 * prom_set,
					0,
					0,0,sx,sy,0);
	}

	/* Update sound */
	discrete_sound_w(discrete, SUBS_LAUNCH_DATA, spriteram[5] & 0x0f);	// Launch data
	discrete_sound_w(discrete, SUBS_CRASH_DATA, spriteram[5] >> 4);		// Crash/explode data
	return 0;
}

SCREEN_UPDATE( subs_right )
{
	subs_state *state = screen.machine().driver_data<subs_state>();
	UINT8 *videoram = state->m_videoram;
	UINT8 *spriteram = state->m_spriteram;
	int offs;

	/* for every character in the Video RAM, check if it has been modified */
	/* since last time and update it accordingly. */
	for (offs = 0x400 - 1; offs >= 0; offs--)
	{
		int charcode;
		int sx,sy;
		int right_enable; //, left_enable;
		int left_sonar_window,right_sonar_window;

		left_sonar_window = 0;
		right_sonar_window = 0;

		charcode = videoram[offs];

		/* Which monitor is this for? */
		right_enable = charcode & 0x40;
		//left_enable = charcode & 0x80;

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

		/* Special hardware logic for sonar windows */
		if ((sy >= (128+64)) && (sx < 32))
			left_sonar_window = 1;
		else if ((sy >= (128+64)) && (sx >= (128+64+32)))
			right_sonar_window = 1;
		else
			charcode = charcode & 0x3F;

		/* draw the right screen */
		if ((right_enable || right_sonar_window) && (!left_sonar_window))
			drawgfx_opaque(bitmap,cliprect,screen.machine().gfx[0],
					charcode, 0,
					0,0,sx,sy);
		else
			drawgfx_opaque(bitmap,cliprect,screen.machine().gfx[0],
					0, 0,
					0,0,sx,sy);
	}

	/* draw the motion objects */
	for (offs = 0; offs < 4; offs++)
	{
		int sx,sy;
		int charcode;
		int prom_set;
		int sub_enable;

		sx = spriteram[0x00 + (offs * 2)] - 16;
		sy = spriteram[0x08 + (offs * 2)] - 16;
		charcode = spriteram[0x09 + (offs * 2)];
		if (offs < 2)
			sub_enable = spriteram[0x01 + (offs * 2)] & 0x80;
		else
			sub_enable = 1;

		prom_set = charcode & 0x01;
		charcode = (charcode >> 3) & 0x1F;

		if ((offs!=1) || (sub_enable))
			drawgfx_transpen(bitmap,cliprect,screen.machine().gfx[1],
					charcode + 32 * prom_set,
					0,
					0,0,sx,sy,0);
	}

	return 0;
}