summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/vicdual.cpp
blob: b3c80d2d677da19f5407bd314a06f52419e9aa08 (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
// license:BSD-3-Clause
// copyright-holders:Zsolt Vasvari
/***************************************************************************

    VIC Dual Game board

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

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


static const pen_t pens_from_color_prom[] =
{
	rgb_t::black(),
	rgb_t(0x00, 0xff, 0x00),
	rgb_t(0x00, 0x00, 0xff),
	rgb_t(0x00, 0xff, 0xff),
	rgb_t(0xff, 0x00, 0x00),
	rgb_t(0xff, 0xff, 0x00),
	rgb_t(0xff, 0x00, 0xff),
	rgb_t::white()
};


WRITE8_MEMBER(vicdual_state::palette_bank_w)
{
	m_screen->update_partial(m_screen->vpos());
	m_palette_bank = data & 3;
}


uint32_t vicdual_state::screen_update_bw(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	uint8_t x = 0;
	uint8_t y = cliprect.min_y;
	uint8_t video_data = 0;

	while (1)
	{
		pen_t pen;

		if ((x & 0x07) == 0)
		{
			offs_t offs;
			uint8_t char_code;

			/* read the character code */
			offs = (y >> 3 << 5) | (x >> 3);
			char_code = m_videoram[offs];

			/* read the appropriate line of the character ram */
			offs = (char_code << 3) | (y & 0x07);
			video_data = m_characterram[offs];
		}

		/* plot the current pixel */
		pen = (video_data & 0x80) ? rgb_t::white() : rgb_t::black();
		bitmap.pix32(y, x) = pen;

		/* next pixel */
		video_data = video_data << 1;
		x = x + 1;

		/* end of line? */
		if (x == 0)
		{
			/* end of region to update? */
			if (y == cliprect.max_y)
			{
				break;
			}

			/* next row */
			y = y + 1;
		}
	}

	return 0;
}


uint32_t vicdual_state::screen_update_color(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	uint8_t *color_prom = (uint8_t *)m_proms->base();
	uint8_t x = 0;
	uint8_t y = cliprect.min_y;
	uint8_t video_data = 0;
	pen_t back_pen = 0;
	pen_t fore_pen = 0;

	while (1)
	{
		pen_t pen;

		if ((x & 0x07) == 0)
		{
			offs_t offs;
			uint8_t char_code;

			/* read the character code */
			offs = (y >> 3 << 5) | (x >> 3);
			char_code = m_videoram[offs];

			/* read the appropriate line of the character ram */
			offs = (char_code << 3) | (y & 0x07);
			video_data = m_characterram[offs];

			/* get the foreground and background colors from the PROM */
			offs = (char_code >> 5) | (m_palette_bank << 3);
			back_pen = pens_from_color_prom[(color_prom[offs] >> 1) & 0x07];
			fore_pen = pens_from_color_prom[(color_prom[offs] >> 5) & 0x07];
		}

		// this does nothing by default, but is used to enable overrides
		back_pen = choose_pen(x, y, back_pen);

		/* plot the current pixel */
		pen = (video_data & 0x80) ? fore_pen : back_pen;
		bitmap.pix32(y, x) = pen;

		/* next pixel */
		video_data = video_data << 1;
		x = x + 1;

		/* end of line? */
		if (x == 0)
		{
			/* end of region to update? */
			if (y == cliprect.max_y)
			{
				break;
			}

			/* next row */
			y = y + 1;
		}
	}

	return 0;
}


uint32_t vicdual_state::screen_update_bw_or_color(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	if (is_cabinet_color())
		screen_update_color(screen, bitmap, cliprect);
	else
		screen_update_bw(screen, bitmap, cliprect);

	return 0;
}


pen_t vicdual_state::choose_pen(uint8_t x, uint8_t y, pen_t back_pen)
{
	return back_pen;
}


pen_t nsub_state::choose_pen(uint8_t x, uint8_t y, pen_t back_pen)
{
	return m_s97269pb->choose_pen(x, y, back_pen);
}