summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/video/pcw16.c
blob: 40324af4e7e94f0d608ad17ef4f2177ff9fcdf1a (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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// license:GPL-2.0+
// copyright-holders:Kevin Thacker
#include "emu.h"
#include "includes/pcw16.h"
#include "machine/ram.h"


#if 0
/* 16 colours, + 1 for border */
static const unsigned short pcw16_colour_table[PCW16_NUM_COLOURS] =
{
	0, 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
};
#endif

static const rgb_t pcw16_palette[PCW16_NUM_COLOURS] =
{
	rgb_t(0x080, 0x080, 0x080),  /* light grey */
	rgb_t(0x080, 0x080, 0x080),  /* light grey */
	rgb_t(0x000, 0x080, 0x080),  /* magenta */
	rgb_t(0x000, 0x080, 0x080),  /* magenta */
	rgb_t(0x080, 0x080, 0x080),  /* light grey */
	rgb_t(0x080, 0x080, 0x080),  /* light grey */
	rgb_t(0x0ff, 0x080, 0x080),  /* pastel green */
	rgb_t(0x0ff, 0x080, 0x080),  /* pastel green */
	rgb_t(0x000, 0x000, 0x080),  /* blue */
	rgb_t(0x000, 0x000, 0x000),  /* black */
	rgb_t(0x000, 0x080, 0x0ff),  /* mauve */
	rgb_t(0x000, 0x000, 0x0ff),  /* bright blue */
	rgb_t(0x000, 0x080, 0x000),  /* red */
	rgb_t(0x000, 0x0ff, 0x000),  /* bright red */
	rgb_t(0x000, 0x0ff, 0x080),  /* purple */
	rgb_t(0x000, 0x0ff, 0x0ff),  /* bright magenta */
	rgb_t(0x0ff, 0x000, 0x080),  /* sea green */
	rgb_t(0x0ff, 0x000, 0x0ff),  /* bright green */
	rgb_t(0x0ff, 0x080, 0x0ff),  /* pastel cyan */
	rgb_t(0x0ff, 0x000, 0x0ff),  /* bright cyan */
	rgb_t(0x0ff, 0x080, 0x000),  /* lime green */
	rgb_t(0x0ff, 0x0ff, 0x000),  /* bright yellow */
	rgb_t(0x0ff, 0x0ff, 0x080),  /* pastel yellow */
	rgb_t(0x0ff, 0x0ff, 0x0ff),  /* bright white */
	rgb_t(0x080, 0x000, 0x080),  /* cyan */
	rgb_t(0x080, 0x000, 0x000),  /* green */
	rgb_t(0x080, 0x080, 0x0ff),  /* pastel blue */
	rgb_t(0x080, 0x000, 0x0ff),  /* sky blue */
	rgb_t(0x080, 0x080, 0x000),  /* yellow */
	rgb_t(0x080, 0x0ff, 0x000),  /* orange */
	rgb_t(0x080, 0x0ff, 0x080),  /* pink */
	rgb_t(0x080, 0x0ff, 0x0ff),  /* pastel magenta */
};


inline void pcw16_state::pcw16_plot_pixel(bitmap_ind16 &bitmap, int x, int y, UINT32 color)
{
	bitmap.pix16(y, x) = (UINT16)color;
}

/* Initialise the palette */
PALETTE_INIT_MEMBER(pcw16_state, pcw16)
{
	palette.set_pen_colors(0, pcw16_palette, ARRAY_LENGTH(pcw16_palette));
}

void pcw16_state::video_start()
{
}

/* 640, 1 bit per pixel */
void pcw16_state::pcw16_vh_decode_mode0(bitmap_ind16 &bitmap, int x, int y, unsigned char byte)
{
	int b;
	int local_byte;
	int cols[2];
	int px;

	local_byte = byte;

	cols[0] = m_colour_palette[0];
	cols[1] = m_colour_palette[1];

	px = x;
	for (b=0; b<8; b++)
	{
		pcw16_plot_pixel(bitmap, px, y, cols[(local_byte>>7) & 0x01]);
		px++;

		local_byte = local_byte<<1;
	}
}

/* 320, 2 bits per pixel */
void pcw16_state::pcw16_vh_decode_mode1(bitmap_ind16 &bitmap, int x, int y, unsigned char byte)
{
	int b;
	int px;
	int local_byte;
	int cols[4];

	for (b=0; b<3; b++)
	{
		cols[b] = m_colour_palette[b];
	}

	local_byte = byte;

	px = x;
	for (b=0; b<4; b++)
	{
		int col;

		col = cols[((local_byte>>6) & 0x03)];

		pcw16_plot_pixel(bitmap, px, y, col);
		px++;
		pcw16_plot_pixel(bitmap, px, y, col);
		px++;

		local_byte = local_byte<<2;
	}
}

/* 160, 4 bits per pixel */
void pcw16_state::pcw16_vh_decode_mode2(bitmap_ind16 &bitmap, int x, int y, unsigned char byte)
{
	int px;
	int b;
	int local_byte;
	int cols[2];

	cols[0] = m_colour_palette[0];
	cols[1] = m_colour_palette[1];
	local_byte = byte;

	px = x;
	for (b=0; b<2; b++)
	{
		int col;

		col = cols[((local_byte>>4)&0x0f)];

		pcw16_plot_pixel(bitmap, px, y, col);
		px++;
		pcw16_plot_pixel(bitmap, px, y, col);
		px++;
		pcw16_plot_pixel(bitmap, px, y, col);
		px++;
		pcw16_plot_pixel(bitmap, px, y, col);
		px++;

		local_byte = local_byte<<4;
	}
}

/***************************************************************************
  Draw the game screen in the given bitmap_ind16.
  Do NOT call osd_update_display() from this function,
  it will be called by the main emulation engine.
***************************************************************************/
UINT32 pcw16_state::screen_update_pcw16(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	UINT8 *ram = m_ram->pointer();
	unsigned char *pScanLine = (unsigned char *)ram + 0x0fc00;  //0x03c00;  //0x020FC00;

	int y;
	int x;

	int border_colour;

	border_colour = m_video_control & 31;

	/* reverse video? */
	if (m_video_control & (1<<7))
	{
		/* colour 0 and colour 1 need to be inverted? - what happens in mode 1 and 2 - ignored? or is bit 1 toggled,
		or is whole lot toggled? */

		/* force border to be colour 1 */
		border_colour = m_colour_palette[1];
	}

	if ((m_video_control & (1<<6))==0)
	{
		/* blank */
		rectangle rect(0, PCW16_SCREEN_WIDTH, 0, PCW16_SCREEN_HEIGHT);
		bitmap.fill(border_colour, rect);
	}
	else
	{
		/* no blank */


		/* render top border */
		rectangle rect(0, PCW16_SCREEN_WIDTH, 0, PCW16_BORDER_HEIGHT);
		bitmap.fill(border_colour, rect);

		/* render bottom border */
		rect.set(0, PCW16_SCREEN_WIDTH, PCW16_BORDER_HEIGHT + PCW16_DISPLAY_HEIGHT, PCW16_BORDER_HEIGHT + PCW16_DISPLAY_HEIGHT + PCW16_BORDER_HEIGHT);
		bitmap.fill(border_colour, rect);

		/* render border on either side of display */
		bitmap.plot_box(0,                                          PCW16_BORDER_HEIGHT, 8, PCW16_DISPLAY_HEIGHT, border_colour);
		bitmap.plot_box(PCW16_DISPLAY_WIDTH + PCW16_BORDER_WIDTH,   PCW16_BORDER_HEIGHT, 8, PCW16_DISPLAY_HEIGHT, border_colour);

		/* render display */
		for (y=0; y<PCW16_DISPLAY_HEIGHT; y++)
		{
			int b;
			int ScanLineAddr;
			int Addr;
			int AddrUpper;
			int mode;

			/* get line address */
			ScanLineAddr = (pScanLine[0] & 0x0ff) | ((pScanLine[1] & 0x0ff)<<8);

			/* generate address */
			Addr = (ScanLineAddr & 0x03fff)<<4;

			/* get upper bits of addr */
			AddrUpper = Addr & (~0x0ffff);

			/* get mode */
			mode = ((ScanLineAddr>>14) & 0x03);

			/* set initial x position */
			x = PCW16_BORDER_WIDTH;

			for (b=0; b<80; b++)
			{
				int byte;

				byte = ram[Addr];

				switch (mode)
				{
					case 0:
					{
						pcw16_vh_decode_mode0(bitmap, x, y+PCW16_BORDER_HEIGHT, byte);
					}
					break;

					case 1:
					{
						pcw16_vh_decode_mode1(bitmap, x, y+PCW16_BORDER_HEIGHT, byte);
					}
					break;

					case 3:
					case 2:
					{
						pcw16_vh_decode_mode2(bitmap, x, y+PCW16_BORDER_HEIGHT, byte);
					}
					break;
				}

				/* only lowest 16 bits are incremented between fetches */
				Addr = ((Addr+1) & 0x0ffff) | AddrUpper;

				x=x+8;
			}

			pScanLine+=2;
		}
	}
	return 0;
}