summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/route16.c
blob: 0bb486dd033295eb75091b90f64c81a8117a35d1 (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
/***************************************************************************

  video.c

  Functions to emulate the video hardware of the machine.

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

#include "emu.h"
#include "sound/sn76477.h"
#include "includes/route16.h"


/*************************************
 *
 *  Memory handlers
 *
 *************************************/

WRITE8_HANDLER( route16_out0_w )
{
	route16_state *state = space->machine().driver_data<route16_state>();
	state->m_palette_1 = data & 0x1f;

	coin_counter_w(space->machine(), 0, (data >> 5) & 0x01);
}


WRITE8_HANDLER( route16_out1_w )
{
	route16_state *state = space->machine().driver_data<route16_state>();
	state->m_palette_2 = data & 0x1f;

	state->m_flipscreen = (data >> 5) & 0x01;
}



/*************************************
 *
 *  Video update
 *
 *************************************/

static pen_t route16_make_pen(UINT8 color)
{
	return MAKE_RGB(pal1bit((color >> 0) & 0x01),
					pal1bit((color >> 1) & 0x01),
					pal1bit((color >> 2) & 0x01));

}


static pen_t ttmajng_make_pen(UINT8 color)
{
	return MAKE_RGB(pal1bit((color >> 2) & 0x01),
					pal1bit((color >> 1) & 0x01),
					pal1bit((color >> 0) & 0x01));

}


/*
 *  Game observation shows that Route 16 can blank each
 *  bitmap by setting bit 1 of the palette register.
 *  Since the schematics are missing the relevant pages, I
 *  cannot confirm how this works, but I am 99% sure the bit 1
 *  would be connected to A7 of the color PROM.  Since the
 *  color PROMs contain 0 in the upper half, this would produce
 *  a black output.
 */

SCREEN_UPDATE( route16 )
{
	route16_state *state = screen->machine().driver_data<route16_state>();
	offs_t offs;

	UINT8 *color_prom1 = &screen->machine().region("proms")->base()[0x000];
	UINT8 *color_prom2 = &screen->machine().region("proms")->base()[0x100];

	for (offs = 0; offs < state->m_videoram_size; offs++)
	{
		int i;

		UINT8 y = offs >> 6;
		UINT8 x = offs << 2;

		UINT8 data1 = state->m_videoram1[offs];
		UINT8 data2 = state->m_videoram2[offs];

		for (i = 0; i < 4; i++)
		{
			UINT8 color1 = color_prom1[((state->m_palette_1 << 6) & 0x80) |
									    (state->m_palette_1 << 2) |
										((data1 >> 3) & 0x02) |
										((data1 >> 0) & 0x01)];

			/* bit 7 of the 2nd color is the OR of the 1st color bits 0 and 1 - this is a guess */
			UINT8 color2 = color_prom2[((state->m_palette_2 << 6) & 0x80) | (((color1 << 6) & 0x80) | ((color1 << 7) & 0x80)) |
										(state->m_palette_2 << 2) |
										((data2 >> 3) & 0x02) |
										((data2 >> 0) & 0x01)];

			/* the final color is the OR of the two colors (verified) */
			UINT8 final_color = color1 | color2;

			pen_t pen = route16_make_pen(final_color);

			if (state->m_flipscreen)
				*BITMAP_ADDR32(bitmap, 255 - y, 255 - x) = pen;
			else
				*BITMAP_ADDR32(bitmap, y, x) = pen;

			x = x + 1;
			data1 = data1 >> 1;
			data2 = data2 >> 1;
		}
	}

	return 0;
}


/*
 *  The Stratovox video connections have been verified from the schematics
 */

static int video_update_stratvox_ttmahjng(running_machine &machine, bitmap_t *bitmap,
										  const rectangle *cliprect,
										  pen_t (*make_pen)(UINT8))
{
	route16_state *state = machine.driver_data<route16_state>();
	offs_t offs;

	UINT8 *color_prom1 = &machine.region("proms")->base()[0x000];
	UINT8 *color_prom2 = &machine.region("proms")->base()[0x100];

	for (offs = 0; offs < state->m_videoram_size; offs++)
	{
		int i;

		UINT8 y = offs >> 6;
		UINT8 x = offs << 2;

		UINT8 data1 = state->m_videoram1[offs];
		UINT8 data2 = state->m_videoram2[offs];

		for (i = 0; i < 4; i++)
		{
			UINT8 color1 = color_prom1[(state->m_palette_1 << 2) |
									   ((data1 >> 3) & 0x02) |
									   ((data1 >> 0) & 0x01)];

			/* bit 7 of the 2nd color is the OR of the 1st color bits 0 and 1 (verified) */
			UINT8 color2 = color_prom2[(((data1 << 3) & 0x80) | ((data1 << 7) & 0x80)) |
									   (state->m_palette_2 << 2) |
									   ((data2 >> 3) & 0x02) |
									   ((data2 >> 0) & 0x01)];

			/* the final color is the OR of the two colors */
			UINT8 final_color = color1 | color2;

			pen_t pen = make_pen(final_color);

			if (state->m_flipscreen)
				*BITMAP_ADDR32(bitmap, 255 - y, 255 - x) = pen;
			else
				*BITMAP_ADDR32(bitmap, y, x) = pen;

			x = x + 1;
			data1 = data1 >> 1;
			data2 = data2 >> 1;
		}
	}

	return 0;
}


SCREEN_UPDATE( stratvox )
{
	return video_update_stratvox_ttmahjng(screen->machine(), bitmap, cliprect, route16_make_pen);
}


SCREEN_UPDATE( ttmahjng )
{
	return video_update_stratvox_ttmahjng(screen->machine(), bitmap, cliprect, ttmajng_make_pen);
}