summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/playch10.c
blob: 5c2fd5e3b7dc2c04a52ef66dde1d406d488b2fd9 (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
#include "driver.h"
#include "deprecat.h"
#include "video/ppu2c0x.h"

/* from machine */
extern int pc10_sdcs;			/* ShareD Chip Select */
extern int pc10_dispmask;		/* Display Mask */
extern int pc10_gun_controller;	/* whether we need to draw a crosshair or not */
extern int pc10_int_detect;
extern int pc10_game_mode;
extern int pc10_dispmask_old;

static int pc10_bios;

static tilemap *bg_tilemap;

WRITE8_HANDLER( playch10_videoram_w )
{
	if (pc10_sdcs)
	{
		videoram[offset] = data;
		tilemap_mark_tile_dirty(bg_tilemap, offset / 2);
	}
}

PALETTE_INIT( playch10 )
{
	int i;

	for (i = 0; i < 256; i++)
	{
		int bit0, bit1, bit2, bit3, r, g, b;

		/* red component */

		bit0 = ~(color_prom[0] >> 0) & 0x01;
		bit1 = ~(color_prom[0] >> 1) & 0x01;
		bit2 = ~(color_prom[0] >> 2) & 0x01;
		bit3 = ~(color_prom[0] >> 3) & 0x01;

		r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;

		/* green component */
		bit0 = ~(color_prom[256] >> 0) & 0x01;
		bit1 = ~(color_prom[256] >> 1) & 0x01;
		bit2 = ~(color_prom[256] >> 2) & 0x01;
		bit3 = ~(color_prom[256] >> 3) & 0x01;

		g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;

		/* blue component */

		bit0 = ~(color_prom[2*256] >> 0) & 0x01;
		bit1 = ~(color_prom[2*256] >> 1) & 0x01;
		bit2 = ~(color_prom[2*256] >> 2) & 0x01;
		bit3 = ~(color_prom[2*256] >> 3) & 0x01;

		b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;

		palette_set_color(machine,i,MAKE_RGB(r,g,b));

		color_prom++;
	}

	ppu2c0x_init_palette(machine, 256 );
}

static void ppu_irq( int num, int *ppu_regs )
{
	cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE );
	pc10_int_detect = 1;
}

/* our ppu interface                                           */
/* things like mirroring and whether to use vrom or vram       */
/* can be set by calling 'ppu2c0x_override_hardware_options'   */

static const ppu2c0x_interface ppu_interface =
{
	PPU_2C03B,				/* type */
	1,						/* num */
	{ REGION_GFX2 },		/* vrom gfx region */
	{ 1 },					/* gfxlayout num */
	{ 256 },				/* color base */
	{ PPU_MIRROR_NONE },	/* mirroring */
	{ ppu_irq },			/* irq */
	{ 0 }					/* vram */
};

static const ppu2c0x_interface ppu_interface_hboard =
{
	PPU_2C03B,				/* type */
	1,						/* num */
	{ REGION_GFX2 },		/* vrom gfx region */
	{ 1 },					/* gfxlayout num */
	{ 256 },				/* color base */
	{ PPU_MIRROR_NONE },	/* mirroring */
	{ ppu_irq },			/* irq */
	{ 1 }					/* vram */
};

static TILE_GET_INFO( get_bg_tile_info )
{
	int offs = tile_index * 2;
	int code = videoram[offs] + ((videoram[offs + 1] & 0x07) << 8);
	int color = (videoram[offs + 1] >> 3) & 0x1f;

	SET_TILE_INFO(0, code, color, 0);
}

VIDEO_START( playch10 )
{
	const UINT8 *bios = memory_region(REGION_CPU1);
	pc10_bios = (bios[3] == 0x2a) ? 1 : 2;

	bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows,
		 8, 8, 32, 32);

	ppu2c0x_init(machine, &ppu_interface );
}

VIDEO_START( playch10_hboard )
{
	const UINT8 *bios = memory_region(REGION_CPU1);
	pc10_bios = (bios[3] == 0x2a) ? 1 : 2;

	bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows,
		 8, 8, 32, 32);

	ppu2c0x_init(machine, &ppu_interface_hboard );
}

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

  Display refresh

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

VIDEO_UPDATE( playch10 )
{
	/* Dual monitor version */
	if (pc10_bios == 1)
	{
		const device_config *top_screen = device_list_find_by_tag(screen->machine->config->devicelist, VIDEO_SCREEN, "top");

		/* On Playchoice 10 single monitor, this bit toggles    */
		/* between PPU and BIOS display.                        */
		/* We support the multi-monitor layout. In this case,   */
		/* if the bit is not set, then we should display        */
		/* the PPU portion.                                     */

		if (screen == top_screen)
		{
			if ( !pc10_dispmask )
				/* render the ppu */
				ppu2c0x_render( 0, bitmap, 0, 0, 0, 0 );
			else
				fillbitmap(bitmap, 0, cliprect);
		}
		else
		{
			/* When the bios is accessing vram, the video circuitry can't access it */

			if ( !pc10_sdcs )
				tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0);
			else
				fillbitmap(bitmap, 0, cliprect);
		}
	}
	else	/* Single Monitor version */
	{
		rectangle top_monitor = *video_screen_get_visible_area(screen);

		top_monitor.max_y = ( top_monitor.max_y - top_monitor.min_y ) / 2;

		if(pc10_dispmask_old != pc10_dispmask)
		{
			pc10_dispmask_old = pc10_dispmask;

			if(pc10_dispmask)
				pc10_game_mode ^= 1;
		}

		if ( pc10_game_mode )
			/* render the ppu */
			ppu2c0x_render( 0, bitmap, 0, 0, 0, 0 );
		else
		{
			/* When the bios is accessing vram, the video circuitry can't access it */
			if ( !pc10_sdcs )
				tilemap_draw(bitmap, &top_monitor, bg_tilemap, 0, 0);
		}
	}
	return 0;
}