summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/crgolf.c
blob: 16127f2acaf644bdee32b058b61281a3776ddaa3 (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
/***************************************************************************

    Kitco Crowns Golf hardware

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

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


#define NUM_PENS        (0x20)
#define VIDEORAM_SIZE   (0x2000 * 3)


/*************************************
 *
 *  Video RAM access
 *
 *************************************/

WRITE8_MEMBER(crgolf_state::crgolf_videoram_w)
{
	if (*m_screen_select & 1)
		m_videoram_b[offset] = data;
	else
		m_videoram_a[offset] = data;
}


READ8_MEMBER(crgolf_state::crgolf_videoram_r)
{
	UINT8 ret;

	if (*m_screen_select & 1)
		ret = m_videoram_b[offset];
	else
		ret = m_videoram_a[offset];

	return ret;
}



/*************************************
 *
 *  Palette handling
 *
 *************************************/

void crgolf_state::get_pens( pen_t *pens )
{
	offs_t offs;
	const UINT8 *prom = memregion("proms")->base();

	for (offs = 0; offs < NUM_PENS; offs++)
	{
		int bit0, bit1, bit2, r, g, b;

		UINT8 data = prom[offs];

		/* red component */
		bit0 = (data >> 0) & 0x01;
		bit1 = (data >> 1) & 0x01;
		bit2 = (data >> 2) & 0x01;
		r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		/* green component */
		bit0 = (data >> 3) & 0x01;
		bit1 = (data >> 4) & 0x01;
		bit2 = (data >> 5) & 0x01;
		g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		/* blue component */
		bit0 = (data >> 6) & 0x01;
		bit1 = (data >> 7) & 0x01;
		b = 0x4f * bit0 + 0xa8 * bit1;

		pens[offs] = rgb_t(r, g, b);
	}
}



/*************************************
 *
 *  Video startup
 *
 *************************************/

VIDEO_START_MEMBER(crgolf_state,crgolf)
{
	/* allocate memory for the two bitmaps */
	m_videoram_a = auto_alloc_array(machine(), UINT8, VIDEORAM_SIZE);
	m_videoram_b = auto_alloc_array(machine(), UINT8, VIDEORAM_SIZE);

	/* register for save states */
	save_pointer(NAME(m_videoram_a), VIDEORAM_SIZE);
	save_pointer(NAME(m_videoram_b), VIDEORAM_SIZE);
}



/*************************************
 *
 *  Video update
 *
 *************************************/

UINT32 crgolf_state::screen_update_crgolf(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	int flip = *m_screen_flip & 1;

	offs_t offs;
	pen_t pens[NUM_PENS];

	get_pens(pens);

	/* for each byte in the video RAM */
	for (offs = 0; offs < VIDEORAM_SIZE / 3; offs++)
	{
		int i;

		UINT8 y = (offs & 0x1fe0) >> 5;
		UINT8 x = (offs & 0x001f) << 3;

		UINT8 data_a0 = m_videoram_a[0x2000 | offs];
		UINT8 data_a1 = m_videoram_a[0x0000 | offs];
		UINT8 data_a2 = m_videoram_a[0x4000 | offs];
		UINT8 data_b0 = m_videoram_b[0x2000 | offs];
		UINT8 data_b1 = m_videoram_b[0x0000 | offs];
		UINT8 data_b2 = m_videoram_b[0x4000 | offs];

		if (flip)
		{
			y = ~y;
			x = ~x;
		}

		/* for each pixel in the byte */
		for (i = 0; i < 8; i++)
		{
			offs_t color;
			UINT8 data_b = 0;
			UINT8 data_a = 0;

			if (~*m_screena_enable & 1)
				data_a = ((data_a0 & 0x80) >> 7) | ((data_a1 & 0x80) >> 6) | ((data_a2 & 0x80) >> 5);

			if (~*m_screenb_enable & 1)
				data_b = ((data_b0 & 0x80) >> 7) | ((data_b1 & 0x80) >> 6) | ((data_b2 & 0x80) >> 5);

			/* screen A has priority over B */
			if (data_a)
				color = data_a;
			else
				color = data_b | 0x08;

			/* add HI bit if enabled */
			if (*m_color_select)
				color = color | 0x10;

			bitmap.pix32(y, x) = pens[color];

			/* next pixel */
			data_a0 = data_a0 << 1;
			data_a1 = data_a1 << 1;
			data_a2 = data_a2 << 1;
			data_b0 = data_b0 << 1;
			data_b1 = data_b1 << 1;
			data_b2 = data_b2 << 1;

			if (flip)
				x = x - 1;
			else
				x = x + 1;
		}
	}

	return 0;
}


/*************************************
 *
 *  Machine driver
 *
 *************************************/

MACHINE_CONFIG_FRAGMENT( crgolf_video )

	MCFG_VIDEO_START_OVERRIDE(crgolf_state,crgolf)
	MCFG_SCREEN_ADD("screen", RASTER)
	MCFG_SCREEN_SIZE(256, 256)
	MCFG_SCREEN_VISIBLE_AREA(0, 255, 8, 247)
	MCFG_SCREEN_REFRESH_RATE(60)
	MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */)
	MCFG_SCREEN_UPDATE_DRIVER(crgolf_state, screen_update_crgolf)
MACHINE_CONFIG_END