summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/8080bw.c
blob: 54b7dc7805629b644e8e233a9db305f48a8c8707 (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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/***************************************************************************

  video.c

  Functions to emulate the video hardware of the machine.

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

#include "driver.h"
#include "8080bw.h"
#include "mw8080bw.h"


#define NUM_PENS	(8)


UINT8 *c8080bw_colorram;

static UINT8 c8080bw_flip_screen;
static UINT8 color_map;
static UINT8 screen_red;
static UINT8 schaser_background_disable;
static UINT8 schaser_background_select;



void c8080bw_flip_screen_w(int data)
{
	color_map = data;
	c8080bw_flip_screen = data && (readinputportbytag(CABINET_PORT_TAG) & 0x01);
}


void c8080bw_screen_red_w(int data)
{
	screen_red = data;
}


void schaser_background_control_w(int data)
{
	schaser_background_disable = (data >> 3) & 0x01;
	schaser_background_select = (data >> 4) & 0x01;
}


static void invadpt2_get_pens(pen_t *pens)
{
	offs_t i;

	for (i = 0; i < NUM_PENS; i++)
	{
		pens[i] = MAKE_RGB(pal1bit(i >> 0), pal1bit(i >> 2), pal1bit(i >> 1));
	}
}


static void sflush_get_pens(pen_t *pens)
{
	offs_t i;

	pens[0] = MAKE_RGB(0x80, 0x80, 0xff);

	for (i = 1; i < NUM_PENS; i++)
	{
		pens[i] = MAKE_RGB(pal1bit(i >> 0), pal1bit(i >> 2), pal1bit(i >> 1));
	}
}


static void cosmo_get_pens(pen_t *pens)
{
	offs_t i;

	for (i = 0; i < NUM_PENS; i++)
	{
		pens[i] = MAKE_RGB(pal1bit(i >> 0), pal1bit(i >> 1), pal1bit(i >> 2));
	}
}


INLINE void set_pixel(mame_bitmap *bitmap, UINT8 y, UINT8 x, pen_t *pens, UINT8 color)
{
	if (y >= MW8080BW_VCOUNTER_START_NO_VBLANK)
	{
		if (c8080bw_flip_screen)
			*BITMAP_ADDR32(bitmap, MW8080BW_VBSTART - 1 - (y - MW8080BW_VCOUNTER_START_NO_VBLANK), MW8080BW_HPIXCOUNT - 1 - x) = pens[color];
		else
			*BITMAP_ADDR32(bitmap, y - MW8080BW_VCOUNTER_START_NO_VBLANK, x) = pens[color];
	}
}


INLINE void set_8_pixels(mame_bitmap *bitmap, UINT8 y, UINT8 x, UINT8 data,
						  pen_t *pens, UINT8 fore_color, UINT8 back_color)
{
	int i;

	for (i = 0; i < 8; i++)
	{
		set_pixel(bitmap, y, x, pens, (data & 0x01) ? fore_color : back_color);

		x = x + 1;
		data = data >> 1;
	}
}


/* this is needed as this driver doesn't emulate the shift register like mw8080bw does */
static void clear_extra_columns(mame_bitmap *bitmap, pen_t *pens, UINT8 color)
{
	UINT8 x;

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

		for (y = MW8080BW_VCOUNTER_START_NO_VBLANK; y != 0; y++)
		{
			if (c8080bw_flip_screen)
				*BITMAP_ADDR32(bitmap, MW8080BW_VBSTART - 1 - (y - MW8080BW_VCOUNTER_START_NO_VBLANK), MW8080BW_HPIXCOUNT - 1 - (256 + x)) = pens[color];
			else
				*BITMAP_ADDR32(bitmap, y - MW8080BW_VCOUNTER_START_NO_VBLANK, 256 + x) = pens[color];
		}
	}
}


VIDEO_UPDATE( invadpt2 )
{
	pen_t pens[NUM_PENS];
	offs_t offs;
	UINT8 *color_map_base;

	invadpt2_get_pens(pens);

	color_map_base = color_map ? &memory_region(REGION_PROMS)[0x0400] : memory_region(REGION_PROMS);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		offs_t color_address = (offs >> 8 << 5) | (offs & 0x1f);

		UINT8 data = mw8080bw_ram[offs];
		UINT8 fore_color = screen_red ? 1 : color_map_base[color_address] & 0x07;

		set_8_pixels(bitmap, y, x, data, pens, fore_color, 0);
	}

	clear_extra_columns(bitmap, pens, 0);

	return 0;
}


VIDEO_UPDATE( ballbomb )
{
	pen_t pens[NUM_PENS];
	offs_t offs;
	UINT8 *color_map_base;

	invadpt2_get_pens(pens);

	color_map_base = color_map ? &memory_region(REGION_PROMS)[0x0400] : memory_region(REGION_PROMS);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		offs_t color_address = (offs >> 8 << 5) | (offs & 0x1f);

		UINT8 data = mw8080bw_ram[offs];
		UINT8 fore_color = screen_red ? 1 : color_map_base[color_address] & 0x07;

		/* blue background */
		set_8_pixels(bitmap, y, x, data, pens, fore_color, 2);
	}

	clear_extra_columns(bitmap, pens, 2);

	return 0;
}


VIDEO_UPDATE( schaser )
{
	pen_t pens[NUM_PENS];
	offs_t offs;
	UINT8 *background_map_base;

	invadpt2_get_pens(pens);

	background_map_base = memory_region(REGION_PROMS);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 back_color = 0;

		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		UINT8 data = mw8080bw_ram[offs];
		UINT8 fore_color = c8080bw_colorram[offs & 0x1f1f] & 0x07;

		if (!schaser_background_disable)
		{
			offs_t back_address = (offs >> 8 << 5) | (offs & 0x1f);

			UINT8 back_data = background_map_base[back_address];

			/* the equations derived from the schematics don't appear to produce
               the right colors, but this one does, at least for this PROM */
			back_color = (((back_data & 0x0c) == 0x0c) && schaser_background_select) ? 4 : 2;
		}

		set_8_pixels(bitmap, y, x, data, pens, fore_color, back_color);
	}

	clear_extra_columns(bitmap, pens, schaser_background_disable ? 0 : 2);

	return 0;
}


VIDEO_UPDATE( schasrcv )
{
	pen_t pens[NUM_PENS];
	offs_t offs;

	invadpt2_get_pens(pens);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		UINT8 data = mw8080bw_ram[offs];
		UINT8 fore_color = c8080bw_colorram[offs & 0x1f1f] & 0x07;

		/* blue background */
		set_8_pixels(bitmap, y, x, data, pens, fore_color, 2);
	}

	clear_extra_columns(bitmap, pens, 2);

	return 0;
}


VIDEO_UPDATE( rollingc )
{
	pen_t pens[NUM_PENS];
	offs_t offs;

	invadpt2_get_pens(pens);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		UINT8 data = mw8080bw_ram[offs];
		UINT8 fore_color = c8080bw_colorram[offs & 0x1f1f] & 0x07;

		set_8_pixels(bitmap, y, x, data, pens, fore_color, 0);
	}

	clear_extra_columns(bitmap, pens, 0);

	return 0;
}


VIDEO_UPDATE( polaris )
{
	pen_t pens[NUM_PENS];
	offs_t offs;
	UINT8 *color_map_base;
	UINT8 *cloud_gfx;

	invadpt2_get_pens(pens);

	color_map_base = memory_region(REGION_PROMS);
	cloud_gfx = memory_region(REGION_USER1);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		UINT8 data = mw8080bw_ram[offs];

		offs_t color_address = (offs >> 8 << 5) | (offs & 0x1f);

		/* for the background color, bit 0 of the map PROM is connected to green gun.
           red is 0 and blue is 1, giving cyan and blue for the background.  This
           is different from what the schematics shows, but it's supported
           by screenshots.  Bit 3 is connected to cloud enable, while
           bits 1 and 2 are marked 'not use' (sic) */

		UINT8 back_color = (color_map_base[color_address] & 0x01) ? 6 : 2;
		UINT8 fore_color = ~c8080bw_colorram[offs & 0x1f1f] & 0x07;

		UINT8 cloud_y = y - polaris_get_cloud_pos();

		if ((color_map_base[color_address] & 0x08) || (cloud_y >= 64))
		{
			set_8_pixels(bitmap, y, x, data, pens, fore_color, back_color);
		}
		else
		{
			/* cloud appears in this part of the screen */
			int i;

			for (i = 0; i < 8; i++)
			{
				UINT8 color;

				if (data & 0x01)
				{
					color = fore_color;
				}
				else
				{
					int bit = 1 << (~x & 0x03);
					offs_t cloud_gfx_offs = ((x >> 2) & 0x03) | ((~cloud_y & 0x3f) << 2);

					color = (cloud_gfx[cloud_gfx_offs] & bit) ? 7 : back_color;
				}

				set_pixel(bitmap, y, x, pens, color);

				x = x + 1;
				data = data >> 1;
			}
		}
	}

	clear_extra_columns(bitmap, pens, 6);

	return 0;
}


VIDEO_UPDATE( lupin3 )
{
	pen_t pens[NUM_PENS];
	offs_t offs;

	invadpt2_get_pens(pens);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		UINT8 data = mw8080bw_ram[offs];
		UINT8 fore_color = ~c8080bw_colorram[offs & 0x1f1f] & 0x07;

		set_8_pixels(bitmap, y, x, data, pens, fore_color, 0);
	}

	clear_extra_columns(bitmap, pens, 0);

	return 0;
}


VIDEO_UPDATE( cosmo )
{
	pen_t pens[NUM_PENS];
	offs_t offs;

	cosmo_get_pens(pens);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		offs_t color_address = (offs >> 8 << 5) | (offs & 0x1f);

		UINT8 data = mw8080bw_ram[offs];
		UINT8 fore_color = c8080bw_colorram[color_address] & 0x07;

		set_8_pixels(bitmap, y, x, data, pens, fore_color, 0);
	}

	clear_extra_columns(bitmap, pens, 0);

	return 0;
}


VIDEO_UPDATE( indianbt )
{
	pen_t pens[NUM_PENS];
	offs_t offs;
	UINT8 *color_map_base;

	cosmo_get_pens(pens);

	color_map_base = color_map ? &memory_region(REGION_PROMS)[0x0400] : memory_region(REGION_PROMS);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		offs_t color_address = (offs >> 8 << 5) | (offs & 0x1f);

		UINT8 data = mw8080bw_ram[offs];
		UINT8 fore_color = color_map_base[color_address] & 0x07;

		set_8_pixels(bitmap, y, x, data, pens, fore_color, 0);
	}

	clear_extra_columns(bitmap, pens, 0);

	return 0;
}


VIDEO_UPDATE( shuttlei )
{
	pen_t pens[2] = { RGB_BLACK, RGB_WHITE };
	offs_t offs;

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		int i;

		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		UINT8 data = mw8080bw_ram[offs];

		for (i = 0; i < 8; i++)
		{
			pen_t pen = (data & 0x80) ? RGB_WHITE : RGB_BLACK;
			*BITMAP_ADDR32(bitmap, y, x) = pen;

			x = x + 1;
			data = data << 1;
		}
	}

	clear_extra_columns(bitmap, pens, 0);

	return 0;
}


VIDEO_UPDATE( sflush )
{
	pen_t pens[NUM_PENS];
	offs_t offs;

	sflush_get_pens(pens);

	for (offs = 0; offs < mw8080bw_ram_size; offs++)
	{
		UINT8 y = offs >> 5;
		UINT8 x = offs << 3;

		UINT8 data = mw8080bw_ram[offs];
		UINT8 fore_color = c8080bw_colorram[offs & 0x1f1f] & 0x07;

		set_8_pixels(bitmap, y, x, data, pens, fore_color, 0);
	}

	clear_extra_columns(bitmap, pens, 0);

	return 0;
}