summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/pc6001.cpp
blob: 8dcb5121ed02c6f7145d7bebc5b926a676c92bf0 (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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
// license:BSD-3-Clause
// copyright-holders:Angelo Salese
/*******************************************************************
 *
 * PC-6xxx video related functions
 *
 *
 *
 ******************************************************************/

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

/*****************************************
 *
 * Palette Inits
 *
 ****************************************/

static constexpr rgb_t defcolors[] =
{
	rgb_t(0x07, 0xff, 0x00), // GREEN
	rgb_t(0xff, 0xff, 0x00), // YELLOW
	rgb_t(0x3b, 0x08, 0xff), // BLUE
	rgb_t(0xcc, 0x00, 0x3b), // RED
	rgb_t(0xff, 0xff, 0xff), // BUFF
	rgb_t(0x07, 0xe3, 0x99), // CYAN
	rgb_t(0xff, 0x1c, 0xff), // MAGENTA
	rgb_t(0xff, 0x81, 0x00), // ORANGE

	// MC6847 specific
	rgb_t(0x00, 0x7c, 0x00), // ALPHANUMERIC DARK GREEN
	rgb_t(0x07, 0xff, 0x00), // ALPHANUMERIC BRIGHT GREEN
	rgb_t(0x91, 0x00, 0x00), // ALPHANUMERIC DARK ORANGE
	rgb_t(0xff, 0x81, 0x00)  // ALPHANUMERIC BRIGHT ORANGE
};

static constexpr rgb_t mk2_defcolors[] =
{
	rgb_t(0x00, 0x00, 0x00), // BLACK
	rgb_t(0xff, 0xaf, 0x00), // ORANGE
	rgb_t(0x00, 0xff, 0xaf), // tone of GREEN
	rgb_t(0xaf, 0xff, 0x00), // tone of GREEN
	rgb_t(0xaf, 0x00, 0xff), // VIOLET
	rgb_t(0xff, 0x00, 0xaf), // SCARLET
	rgb_t(0x00, 0xaf, 0xff), // LIGHT BLUE
	rgb_t(0xaf, 0xaf, 0xaf), // GRAY
	rgb_t(0x00, 0x00, 0x00), // BLACK
	rgb_t(0xff, 0x00, 0x00), // RED
	rgb_t(0x00, 0xff, 0x00), // GREEN
	rgb_t(0xff, 0xff, 0x00), // YELLOW
	rgb_t(0x00, 0x00, 0xff), // BLUE
	rgb_t(0xff, 0x00, 0xff), // PINK
	rgb_t(0x00, 0xff, 0xff), // CYAN
	rgb_t(0xff, 0xff, 0xff)  // WHITE
};

void pc6001_state::pc6001_palette(palette_device &palette) const
{
	for(int i=0;i<8+4;i++)
		palette.set_pen_color(i+8,defcolors[i]);
}

void pc6001mk2_state::pc6001mk2_palette(palette_device &palette) const
{
	for(int i=0;i<8;i++)
		palette.set_pen_color(i+8,defcolors[i]);

	for(int i=0x10;i<0x20;i++)
		palette.set_pen_color(i,mk2_defcolors[i-0x10]);
}

/*****************************************
 *
 * Video functions
 *
 ****************************************/

 // MC6847 old interfacing code
#ifdef UNUSED_FUNCTION
ATTR_CONST pc6001_state::uint8_t pc6001_get_attributes(uint8_t c,int scanline, int pos)
{
	uint8_t result = 0x00;
	uint8_t val = m_video_ram [(scanline / 12) * 0x20 + pos];

	if (val & 0x01) {
		result |= M6847_INV;
	}
	if (val & 0x40)
		result |= M6847_AG | M6847_GM1; //TODO

	result |= M6847_INTEXT; // always use external ROM
	return result;
}

const pc6001_state::uint8_t *pc6001_get_video_ram(int scanline)
{
	return m_video_ram +0x0200+ (scanline / 12) * 0x20;
}

uint8_t pc6001_state::pc6001_get_char_rom(uint8_t ch, int line)
{
	uint8_t *gfx = m_region_gfx1->base();
	return gfx[ch*16+line];
}
#endif

void pc6001_state::video_start()
{
	#if 0
	m6847_config cfg;

	memset(&cfg, 0, sizeof(cfg));
	cfg.type = M6847_VERSION_M6847T1_NTSC;
	cfg.get_attributes = pc6001_get_attributes;
	cfg.get_video_ram = pc6001_get_video_ram;
	cfg.get_char_rom = pc6001_get_char_rom;
	m6847_init(machine(), &cfg);
	#endif
	m_video_ram = auto_alloc_array_clear(machine(), uint8_t, 0x4000);
}

void pc6001mk2_state::video_start()
{
	// ...
}

void pc6001sr_state::video_start()
{
//  m_video_ram = auto_alloc_array_clear(machine(), uint8_t, 0x4000);
	m_gvram = auto_alloc_array_clear(machine(), uint8_t, 320*256*8); // TODO: size
	save_pointer(NAME(m_gvram), 320*256*8);
}

/* this is known as gfx mode 4 */
void pc6001_state::draw_gfx_mode4(bitmap_ind16 &bitmap,const rectangle &cliprect,int attr)
{
	int x,y,xi;
	int fgcol,color;
	int col_setting;
	static const uint8_t pen_gattr[4][4] = {
		{ 0, 1, 6, 2 }, //Red / Blue
		{ 0, 6, 1, 2 }, //Blue / Red
		{ 0, 5, 2, 2 }, //Pink / Green
		{ 0, 2, 5, 2 }, //Green / Pink
	};
	static const uint8_t pen_wattr[4][4] = {
		{ 0, 1, 6, 7 }, //Red / Blue
		{ 0, 6, 1, 7 }, //Blue / Red
		{ 0, 5, 2, 7 }, //Pink / Green
		{ 0, 2, 5, 7 }, //Green / Pink
	};
	col_setting = m_io_mode4_dsw->read() & 7;

	if((attr & 0x0c) != 0x0c)
		popmessage("Mode 4 vram attr != 0x0c, contact MESSdev");

	for(y=0;y<192;y++)
	{
		for(x=0;x<32;x++)
		{
			int tile = m_video_ram[(x+(y*32))+0x200];

			if(col_setting == 0x00) //monochrome
			{
				for(xi=0;xi<8;xi++)
				{
					fgcol = (attr & 2) ? 7 : 2;

					color = ((tile)>>(7-xi) & 1) ? fgcol : 0;

					bitmap.pix16((y+24), (x*8+xi)+32) = m_palette->pen(color);
				}
			}
			else
			{
				for(xi=0;xi<4;xi++)
				{
					fgcol = ((tile)>>(6-(xi*2)) & 3);

					color = (attr & 2) ? (pen_wattr[col_setting-1][fgcol]) : (pen_gattr[col_setting-1][fgcol]);

					bitmap.pix16((y+24), ((x*8+xi*2)+0)+32) = m_palette->pen(color);
					bitmap.pix16((y+24), ((x*8+xi*2)+1)+32) = m_palette->pen(color);
				}
			}
		}
	}
}

void pc6001_state::draw_bitmap_2bpp(bitmap_ind16 &bitmap,const rectangle &cliprect, int attr)
{
	int color,x,y,xi,yi;

	int shrink_x = 2*4;
	int shrink_y = (attr & 8) ? 1 : 2;
	int w = (shrink_x == 8) ? 32 : 16;
	int col_bank = ((attr & 2)<<1);

	if(attr & 4)
	{
		for(y=0;y<(192/shrink_y);y++)
		{
			for(x=0;x<w;x++)
			{
				int tile = m_video_ram[(x+(y*32))+0x200];

				for(yi=0;yi<shrink_y;yi++)
				{
					for(xi=0;xi<shrink_x;xi++)
					{
						int i;
						i = (shrink_x == 8) ? (xi & 0x06) : (xi & 0x0c)>>1;
						color = ((tile >> i) & 3)+8;
						color+= col_bank;

						bitmap.pix16(((y*shrink_y+yi)+24), (x*shrink_x+((shrink_x-1)-xi))+32) = m_palette->pen(color);
					}
				}
			}
		}
	}
	else /* TODO: clean this up */
	{
		for(y=0;y<(192/shrink_y);y+=3)
		{
			for(x=0;x<w;x++)
			{
				int tile = m_video_ram[(x+((y/3)*32))+0x200];

				for(yi=0;yi<shrink_y;yi++)
				{
					for(xi=0;xi<shrink_x;xi++)
					{
						int i;
						i = (shrink_x == 8) ? (xi & 0x06) : (xi & 0x0c)>>1;
						color = ((tile >> i) & 3)+8;
						color+= col_bank;

						bitmap.pix16((((y+0)*shrink_y+yi)+24), (x*shrink_x+((shrink_x-1)-xi))+32) = m_palette->pen(color);
						bitmap.pix16((((y+1)*shrink_y+yi)+24), (x*shrink_x+((shrink_x-1)-xi))+32) = m_palette->pen(color);
						bitmap.pix16((((y+2)*shrink_y+yi)+24), (x*shrink_x+((shrink_x-1)-xi))+32) = m_palette->pen(color);
					}
				}
			}
		}
	}
}

void pc6001_state::draw_tile_3bpp(bitmap_ind16 &bitmap,const rectangle &cliprect,int x,int y,int tile,int attr)
{
	int color,pen,xi,yi;

	if(attr & 0x10) //2x2 squares on a single cell
		pen = (tile & 0x70)>>4;
	else //2x3
		pen = (tile & 0xc0) >> 6 | (attr & 2)<<1;

	for(yi=0;yi<12;yi++)
	{
		for(xi=0;xi<8;xi++)
		{
			int i;
			i = (xi & 4)>>2; //x-axis
			if(attr & 0x10) //2x2
			{
				i+= (yi >= 6) ? 2 : 0; //y-axis
			}
			else //2x3
			{
				i+= (yi & 4)>>1; //y-axis 1
				i+= (yi & 8)>>1; //y-axis 2
			}

			color = ((tile >> i) & 1) ? pen+8 : 0;

			bitmap.pix16(((y*12+(11-yi))+24), (x*8+(7-xi))+32) = m_palette->pen(color);
		}
	}
}

void pc6001_state::draw_tile_text(bitmap_ind16 &bitmap,const rectangle &cliprect,int x,int y,int tile,int attr,int has_mc6847)
{
	int xi,yi,pen,fgcol,color;
	uint8_t *gfx_data = m_region_gfx1->base();

	for(yi=0;yi<12;yi++)
	{
		for(xi=0;xi<8;xi++)
		{
			pen = gfx_data[(tile*0x10)+yi]>>(7-xi) & 1;

			if(has_mc6847)
			{
				fgcol = (attr & 2) ? 0x12 : 0x10;

				if(attr & 1)
					color = pen ? (fgcol+0) : (fgcol+1);
				else
					color = pen ? (fgcol+1) : (fgcol+0);

			}
			else
			{
				fgcol = (attr & 2) ? 2 : 7;

				if(attr & 1)
					color = pen ? 0 : fgcol;
				else
					color = pen ? fgcol : 0;
			}

			bitmap.pix16(((y*12+yi)+24), (x*8+xi)+32) = m_palette->pen(color);
		}
	}
}

void pc6001_state::draw_border(bitmap_ind16 &bitmap,const rectangle &cliprect,int attr,int has_mc6847)
{
	int x,y,color;

	for(y=0;y<240;y++)
	{
		for(x=0;x<320;x++)
		{
			if(!has_mc6847) //mk2 border color is always black
				color = 0;
			else if((attr & 0x90) == 0x80) //2bpp
				color = ((attr & 2)<<1) + 8;
			else if((attr & 0x90) == 0x90) //1bpp
				color = (attr & 2) ? 7 : 2;
			else
				color = 0; //FIXME: other modes not yet checked

			bitmap.pix16(y, x) = m_palette->pen(color);
		}
	}
}

void pc6001_state::pc6001_screen_draw(bitmap_ind16 &bitmap,const rectangle &cliprect, int has_mc6847)
{
	int x,y;
	int tile,attr;

	attr = m_video_ram[0];

	draw_border(bitmap,cliprect,attr,has_mc6847);

	if(attr & 0x80) // gfx mode
	{
		if(attr & 0x10) // 256x192x1 mode (FIXME: might be a different trigger)
		{
			draw_gfx_mode4(bitmap,cliprect,attr);
		}
		else // 128x192x2 mode
		{
			draw_bitmap_2bpp(bitmap,cliprect,attr);
		}
	}
	else // text mode
	{
		for(y=0;y<16;y++)
		{
			for(x=0;x<32;x++)
			{
				tile = m_video_ram[(x+(y*32))+0x200];
				attr = m_video_ram[(x+(y*32)) & 0x1ff];

				if(attr & 0x40)
				{
					draw_tile_3bpp(bitmap,cliprect,x,y,tile,attr);
				}
				else
				{
					draw_tile_text(bitmap,cliprect,x,y,tile,attr,has_mc6847);
				}
			}
		}
	}
}

uint32_t pc6001_state::screen_update_pc6001(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	pc6001_screen_draw(bitmap,cliprect,1);

	return 0;
}

uint32_t pc6001mk2_state::screen_update_pc6001mk2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int x,y,tile,attr;

	/* note: bitmap mode have priority over everything else, check American Truck */
	if(m_exgfx_bitmap_mode)
	{
		int count,color,i;

		count = 0;

		for(y=0;y<200;y++)
		{
			for(x=0;x<160;x+=4)
			{
				for(i=0;i<4;i++)
				{
					int pen[2];
#if 0
					/* palette reference: */
					static const uint8_t pal_num[] = { 0x00, 0x04, 0x01, 0x05,
						0x02, 0x06, 0x03, 0x07,
						0x08, 0x0c, 0x09, 0x0d,
						0x0a, 0x0e, 0x0b, 0x0f };

					color |= pal_num[(pen[0] & 3) | ((pen[1] & 3) << 2)];
#endif

					pen[0] = m_video_ram[count+0x0000] >> (6-i*2) & 3;
					pen[1] = m_video_ram[count+0x2000] >> (6-i*2) & 3;

					color = 0x10;
					color |= ((pen[0] & 1) << 2);
					color |= ((pen[0] & 2) >> 1);
					color |= ((pen[1] & 1) << 1);
					color |= ((pen[1] & 2) << 2);

					if (cliprect.contains((x+i)*2+0, y))
						bitmap.pix16(y, (x+i)*2+0) = m_palette->pen(color);
					if (cliprect.contains((x+i)*2+1, y))
						bitmap.pix16(y, (x+i)*2+1) = m_palette->pen(color);
				}

				count++;
			}
		}
	}
	else if(m_exgfx_2bpp_mode)
	{
		int count,color,i;

		count = 0;

		for(y=0;y<200;y++)
		{
			for(x=0;x<320;x+=8)
			{
				for(i=0;i<8;i++)
				{
					int pen[2];
#if 0
					/* palette reference: */
					static const uint8_t pal_num[] = { 0x00, 0x04, 0x01, 0x05 };

					color |= pal_num[(pen[0] & 1) | ((pen[1] & 1) << 1)];
#endif

					pen[0] = m_video_ram[count+0x0000] >> (7-i) & 1;
					pen[1] = m_video_ram[count+0x2000] >> (7-i) & 1;

					if(m_bgcol_bank & 4) //PC-6001 emulation mode
					{
						color = 0x08;
						color |= (pen[0]) | (pen[1]<<1);
						color |= (m_bgcol_bank & 1) << 2;
					}
					else //Mk-2 mode
					{
						color = 0x10;
						color |= ((pen[0] & 1) << 2);
						color |= ((pen[1] & 1) >> 0);
						color |= ((m_bgcol_bank & 1) << 1);
						color |= ((m_bgcol_bank & 2) << 2);
					}

					if (cliprect.contains(x+i, y))
						bitmap.pix16(y, (x+i)) = m_palette->pen(color);
				}

				count++;
			}
		}

	}
	else if(m_exgfx_text_mode)
	{
		int xi,yi,pen,fgcol,bgcol,color;
		uint8_t *gfx_data = m_region_gfx1->base();

		for(y=0;y<20;y++)
		{
			for(x=0;x<40;x++)
			{
				/*
				exgfx attr format:
				x--- ---- rom bank select
				-xxx ---- bg color
				---- xxxx fg color
				Note that the exgfx banks a different gfx ROM
				*/
				tile = m_video_ram[(x+(y*40))+0x400] + 0x200;
				attr = m_video_ram[(x+(y*40)) & 0x3ff];
				tile+= ((attr & 0x80) << 1);

				for(yi=0;yi<12;yi++)
				{
					for(xi=0;xi<8;xi++)
					{
						pen = gfx_data[(tile*0x10)+yi]>>(7-xi) & 1;

						fgcol = (attr & 0x0f) + 0x10;
						bgcol = ((attr & 0x70) >> 4) + 0x10 + ((m_bgcol_bank & 2) << 2);

						color = pen ? fgcol : bgcol;

						if (cliprect.contains(x*8+xi, y*12+yi))
							bitmap.pix16(((y*12+yi)), (x*8+xi)) = m_palette->pen(color);
					}
				}
			}
		}
	}
	else
	{
		//attr = m_video_ram[0];
		pc6001_screen_draw(bitmap,cliprect,0);
	}

	return 0;
}

uint32_t pc6001sr_state::screen_update_pc6001sr(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int x,y,tile,attr;
	int xi,yi,pen,fgcol,bgcol,color;
	uint8_t *gfx_data = m_region_gfx1->base();

	bitmap.fill(0,cliprect);

	if(m_sr_text_mode == true) // text mode
	{
		for(y=0;y<m_sr_text_rows;y++)
		{
			for(x=0;x<40;x++)
			{
				tile = m_video_ram[(x+(y*40))*2+0];
				attr = m_video_ram[(x+(y*40))*2+1];
				tile+= ((attr & 0x80) << 1);

				for(yi=0;yi<12;yi++)
				{
					for(xi=0;xi<8;xi++)
					{
						pen = gfx_data[(tile*0x10)+yi]>>(7-xi) & 1;

						fgcol = (attr & 0x0f) + 0x10;
						bgcol = ((attr & 0x70) >> 4) + 0x10 + ((m_bgcol_bank & 2) << 2);

						color = pen ? fgcol : bgcol;

						if (cliprect.contains(x*8+xi, y*12+yi))
							bitmap.pix16(((y*12+yi)), (x*8+xi)) = m_palette->pen(color);
					}
				}
			}
		}
	}
	else //4bpp bitmap mode (TODO)
	{
		for(y=0;y<200;y++)
		{
			for(x=0;x<320;x+=2)
			{
				uint32_t vram_addr;

				if(x >= 256)
					vram_addr = 0x1a00 + (x-256)+y*64;
				else
					vram_addr = x+y*256;

				color = (m_gvram[vram_addr] & 0xf0) >> 4;

				if (cliprect.contains(x, y+0))
					bitmap.pix16((y+0), (x+0)) = m_palette->pen(color+0x10);

				color = (m_gvram[vram_addr] & 0x0f);

				if (cliprect.contains(x+1, y+0))
					bitmap.pix16((y+0), (x+1)) = m_palette->pen(color+0x10);
			}
		}
	}

	return 0;
}