summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/gridlee.cpp
blob: 95efb8525b1d91b7c58df1901f4cdbc65d3f8121 (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
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************

    Videa Gridlee hardware

    driver by Aaron Giles

    Based on the Bally/Sente SAC system

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

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


/*************************************
 *
 *  Color PROM conversion
 *
 *************************************/

void gridlee_state::gridlee_palette(palette_device &palette) const
{
	const uint8_t *color_prom = memregion("proms")->base();

	for (int i = 0; i < palette.entries(); i++)
	{
		palette.set_pen_color(i, pal4bit(color_prom[0x0000]), pal4bit(color_prom[0x0800]), pal4bit(color_prom[0x1000]));
		color_prom++;
	}
}



/*************************************
 *
 *  Video system restart
 *
 *************************************/

void gridlee_state::expand_pixels()
{
	for (int offset = 0; offset < 0x77ff; offset++)
	{
		m_local_videoram[offset * 2 + 0] = m_videoram[offset] >> 4;
		m_local_videoram[offset * 2 + 1] = m_videoram[offset] & 15;
	}
}



/*************************************
 *
 *  Video system start
 *
 *************************************/

void gridlee_state::video_start()
{
	/* allocate a local copy of video RAM */
	m_local_videoram = make_unique_clear<uint8_t[]>(256 * 256);

	/* reset the palette */
	m_palettebank_vis = 0;

	save_pointer(NAME(m_local_videoram), 256 * 256);
	save_item(NAME(m_cocktail_flip));
	save_item(NAME(m_palettebank_vis));
	machine().save().register_postload(save_prepost_delegate(FUNC(gridlee_state::expand_pixels), this));
}



/*************************************
 *
 *  Cocktail flip
 *
 *************************************/

WRITE_LINE_MEMBER(gridlee_state::cocktail_flip_w)
{
	m_cocktail_flip = state;
}



/*************************************
 *
 *  Video RAM write
 *
 *************************************/

WRITE8_MEMBER(gridlee_state::gridlee_videoram_w)
{
	uint8_t *videoram = m_videoram;
	videoram[offset] = data;

	/* expand the two pixel values into two bytes */
	m_local_videoram[offset * 2 + 0] = data >> 4;
	m_local_videoram[offset * 2 + 1] = data & 15;
}



/*************************************
 *
 *  Palette banking
 *
 *************************************/

WRITE8_MEMBER(gridlee_state::gridlee_palette_select_w)
{
	/* update the scanline palette */
	m_screen->update_partial(m_screen->vpos() - 1 + GRIDLEE_VBEND);
	m_palettebank_vis = data & 0x3f;
}



/*************************************
 *
 *  Main screen refresh
 *
 *************************************/

/* all the GRIDLEE_VBEND adjustments are needed because the hardware has a separate counting chain
   to address the video memory instead of using the video chain directly */

uint32_t gridlee_state::screen_update_gridlee(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	const pen_t *pens = &m_palette->pen(m_palettebank_vis * 32);
	uint8_t *gfx;
	int x, y, i;

	/* draw scanlines from the VRAM directly */
	for (y = cliprect.min_y; y <= cliprect.max_y; y++)
	{
		/* non-flipped: draw directly from the bitmap */
		if (!m_cocktail_flip)
			draw_scanline8(bitmap, 0, y, 256, &m_local_videoram[(y - GRIDLEE_VBEND) * 256], pens + 16);

		/* flipped: x-flip the scanline into a temp buffer and draw that */
		else
		{
			int srcy = GRIDLEE_VBSTART - 1 - y;
			uint8_t temp[256];
			int xx;

			for (xx = 0; xx < 256; xx++)
				temp[xx] = m_local_videoram[srcy * 256 + 255 - xx];
			draw_scanline8(bitmap, 0, y, 256, temp, pens + 16);
		}
	}

	/* draw the sprite images */
	gfx = memregion("gfx1")->base();
	for (i = 0; i < 32; i++)
	{
		uint8_t *sprite = m_spriteram + i * 4;
		uint8_t *src;
		int image = sprite[0];
		int ypos = sprite[2] + 17 + GRIDLEE_VBEND;
		int xpos = sprite[3];

		/* get a pointer to the source image */
		src = &gfx[64 * image];

		/* loop over y */
		for (y = 0; y < 16; y++, ypos = (ypos + 1) & 255)
		{
			int currxor = 0;

			/* adjust for flip */
			if (m_cocktail_flip)
			{
				ypos = 271 - ypos;
				currxor = 0xff;
			}

			if (ypos >= (16 + GRIDLEE_VBEND) && ypos >= cliprect.min_y && ypos <= cliprect.max_y)
			{
				int currx = xpos;

				/* loop over x */
				for (x = 0; x < 4; x++)
				{
					int ipixel = *src++;
					int left = ipixel >> 4;
					int right = ipixel & 0x0f;

					/* left pixel */
					if (left && currx >= 0 && currx < 256)
						bitmap.pix16(ypos, currx ^ currxor) = pens[left];
					currx++;

					/* right pixel */
					if (right && currx >= 0 && currx < 256)
						bitmap.pix16(ypos, currx ^ currxor) = pens[right];
					currx++;
				}
			}
			else
				src += 4;

			/* de-adjust for flip */
			if (m_cocktail_flip)
				ypos = 271 - ypos;
		}
	}
	return 0;
}