summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/thepit.cpp
blob: f139859f2d576a4a2391c054e444df0d9213dc8f (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
// license:BSD-3-Clause
// copyright-holders:Zsolt Vasvari
/***************************************************************************

  thepit.c

  Functions to emulate the video hardware of the machine.

  I have a feeling sprite area masking should be done based on tile
  attributes, not a custom cliprect.

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

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


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

  Convert the color PROMs into a more useable format.

  bit 7 -- 220 ohm resistor  -- BLUE
        -- 470 ohm resistor  -- BLUE
        -- 220 ohm resistor  -- GREEN
        -- 470 ohm resistor  -- GREEN
        -- 1  kohm resistor  -- GREEN
        -- 220 ohm resistor  -- RED
        -- 470 ohm resistor  -- RED
  bit 0 -- 1  kohm resistor  -- RED


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

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

	for (int i = 0; i < 32; i++)
	{
		int bit0, bit1, bit2;

		bit0 = BIT(color_prom[i], 0);
		bit1 = BIT(color_prom[i], 1);
		bit2 = BIT(color_prom[i], 2);
		int const r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		bit0 = BIT(color_prom[i], 3);
		bit1 = BIT(color_prom[i], 4);
		bit2 = BIT(color_prom[i], 5);
		int const g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		bit0 = 0;
		bit1 = BIT(color_prom[i], 6);
		bit2 = BIT(color_prom[i], 7);
		int const b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		palette.set_pen_color(i, rgb_t(r, g, b));
	}

	// allocate primary colors for the background and foreground
	// this is wrong, but I don't know where to pick the colors from
	for (int i = 0; i < 8; i++)
		palette.set_pen_color(i + 32, pal1bit(i >> 2), pal1bit(i >> 1), pal1bit(i >> 0));
}


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

 Super Mouse has 5 bits per gun (maybe 6 for green), exact weights are
 unknown.

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

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

	for (int i = 0; i < 32; i++)
	{
		uint8_t const b = bitswap<8>(color_prom[i + 0x00], 0, 1, 2, 3, 4, 5, 6, 7);
		uint8_t const g = bitswap<8>(color_prom[i + 0x20], 0, 1, 2, 3, 4, 5, 6, 7);
		uint8_t const r = (b>>5&7)<<2 | (g>>6&3);

		palette.set_pen_color(i, pal5bit(r), pal5bit(g), pal4bit(b));
	}

	// allocate primary colors for the background and foreground
	// this is wrong, but I don't know where to pick the colors from
	for (int i = 0; i < 8; i++)
		palette.set_pen_color(i + 32, pal1bit(i >> 2), pal1bit(i >> 1), pal1bit(i >> 0));
}



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

  Callbacks for the TileMap code

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

TILE_GET_INFO_MEMBER(thepit_state::solid_get_tile_info)
{
	uint8_t back_color = (m_colorram[tile_index] & 0x70) >> 4;
	int priority = (back_color != 0) && ((m_colorram[tile_index] & 0x80) == 0);
	tileinfo.pen_data = m_dummy_tile.get();
	tileinfo.palette_base = back_color + 32;
	tileinfo.category = priority;
}


TILE_GET_INFO_MEMBER(thepit_state::get_tile_info)
{
	uint8_t fore_color = m_colorram[tile_index] % m_gfxdecode->gfx(0)->colors();
	uint8_t code = m_videoram[tile_index];
	SET_TILE_INFO_MEMBER(2 * m_graphics_bank, code, fore_color, 0);
}



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

void thepit_state::video_start()
{
	m_solid_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(thepit_state::solid_get_tile_info)), TILEMAP_SCAN_ROWS, 8,8, 32,32);

	m_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(thepit_state::get_tile_info)), TILEMAP_SCAN_ROWS, 8,8, 32,32);
	m_tilemap->set_transparent_pen(0);

	m_solid_tilemap->set_scroll_cols(32);
	m_tilemap->set_scroll_cols(32);

	m_dummy_tile = make_unique_clear<uint8_t[]>(8*8);

	m_graphics_bank = 0;    /* only used in intrepid */

	save_item(NAME(m_graphics_bank));
	save_item(NAME(m_flip_x));
	save_item(NAME(m_flip_y));
}



/*************************************
 *
 *  Memory handlers
 *
 *************************************/

WRITE8_MEMBER(thepit_state::videoram_w)
{
	m_videoram[offset] = data;
	m_tilemap->mark_tile_dirty(offset);
}


WRITE8_MEMBER(thepit_state::colorram_w)
{
	m_colorram[offset] = data;
	m_tilemap->mark_tile_dirty(offset);
	m_solid_tilemap->mark_tile_dirty(offset);
}


WRITE_LINE_MEMBER(thepit_state::flip_screen_x_w)
{
	m_flip_x = state;

	int flip = m_flip_x ? TILEMAP_FLIPX : 0;
	if (m_flip_y)
		flip |= TILEMAP_FLIPY ;

	m_tilemap->set_flip(flip);
	m_solid_tilemap->set_flip(flip);

}


WRITE_LINE_MEMBER(thepit_state::flip_screen_y_w)
{
	m_flip_y = state;

	int flip = m_flip_x ? TILEMAP_FLIPX : 0;
	if (m_flip_y)
		flip |= TILEMAP_FLIPY ;

	m_tilemap->set_flip(flip);
	m_solid_tilemap->set_flip(flip);

}


WRITE_LINE_MEMBER(thepit_state::intrepid_graphics_bank_w)
{
	m_graphics_bank = state;

	m_tilemap->mark_all_dirty();
}


READ8_MEMBER(thepit_state::input_port_0_r)
{
	/* Read either the real or the fake input ports depending on the
	   horizontal flip switch. (This is how the real PCB does it) */
	if (m_flip_x)
	{
		return ioport("IN2")->read();
	}
	else
	{
		return ioport("IN0")->read();
	}
}



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

void thepit_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, int priority_to_draw)
{
	for (int offs = m_spriteram.bytes() - 4; offs >= 0; offs -= 4)
	{
		if (((m_spriteram[offs + 2] & 0x08) >> 3) == priority_to_draw)
		{
			uint8_t y, x, flipx, flipy;

			if ((m_spriteram[offs + 0] == 0) || (m_spriteram[offs + 3] == 0))
			{
				continue;
			}

			y = 240 - m_spriteram[offs];
			x = m_spriteram[offs + 3] + 1;

			flipx = m_spriteram[offs + 1] & 0x40;
			flipy = m_spriteram[offs + 1] & 0x80;

			if (m_flip_y)
			{
				y = 240 - y;
				flipy = !flipy;
			}

			if (m_flip_x)
			{
				x = 242 - x;
				flipx = !flipx;
			}

			/* sprites 0-3 are drawn one pixel down */
			if (offs < 16) y++;


					m_gfxdecode->gfx(2 * m_graphics_bank + 1)->transpen(bitmap,cliprect,
					m_spriteram[offs + 1] & 0x3f,
					m_spriteram[offs + 2],
					flipx, flipy, x, y, 0);


					m_gfxdecode->gfx(2 * m_graphics_bank + 1)->transpen(bitmap,cliprect,
					m_spriteram[offs + 1] & 0x3f,
					m_spriteram[offs + 2],
					flipx, flipy, x-256, y, 0);

		}
	}
}


uint32_t thepit_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	const rectangle spritevisiblearea(2*8+1, 32*8-1, 2*8, 30*8-1);
	const rectangle spritevisibleareaflipx(0*8, 30*8-2, 2*8, 30*8-1);

	offs_t offs;

	for (offs = 0; offs < 32; offs++)
	{
		int xshift = m_flip_x ? 128 : 0;
		int yshift = m_flip_y ? -8 : 0;

		m_tilemap->set_scrollx(offs, xshift);
		m_solid_tilemap->set_scrollx(offs, xshift);

		m_tilemap->set_scrolly(offs, yshift + m_attributesram[offs << 1]);
		m_solid_tilemap->set_scrolly(offs, yshift + m_attributesram[offs << 1]);
	}

	/* low priority tiles */
	m_solid_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	m_tilemap->draw(screen, bitmap, cliprect, 0, 0);

	/* low priority sprites */
	draw_sprites(bitmap, m_flip_x ? spritevisibleareaflipx : spritevisiblearea, 0);

	/* high priority tiles */
	m_solid_tilemap->draw(screen, bitmap, cliprect, 1, 1);

	/* high priority sprites */
	draw_sprites(bitmap, m_flip_x ? spritevisibleareaflipx : spritevisiblearea, 1);

	return 0;
}

uint32_t thepit_state::screen_update_desertdan(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	offs_t offs;
	const rectangle spritevisiblearea(0*8+1, 24*8-1, 2*8, 30*8-1);
	const rectangle spritevisibleareaflipx(8*8, 32*8-2, 2*8, 30*8-1);

	for (offs = 0; offs < 32; offs++)
	{
		int xshift = m_flip_x ? 128 : 0;
		int yshift = m_flip_y ? -8 : 0;

		m_tilemap->set_scrollx(offs, xshift);
		m_solid_tilemap->set_scrollx(offs, xshift);

		m_tilemap->set_scrolly(offs, yshift + m_attributesram[offs << 1]);
		m_solid_tilemap->set_scrolly(offs, yshift + m_attributesram[offs << 1]);
	}

	/* low priority tiles */
	m_graphics_bank = 0;
	m_solid_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	m_tilemap->draw(screen, bitmap, cliprect, 0, 0);

	/* low priority sprites */
	m_graphics_bank = 1;
	draw_sprites(bitmap, m_flip_y ? spritevisibleareaflipx : spritevisiblearea, 0);

	/* high priority tiles */ // not sure about this, draws a white block over the title logo sprite, looks like it should be behind?
	m_graphics_bank = 0;
	m_solid_tilemap->draw(screen, bitmap, cliprect, 1, 1);

	/* high priority sprites */
	m_graphics_bank = 1;
	draw_sprites(bitmap, m_flip_y ? spritevisibleareaflipx : spritevisiblearea, 1);

	return 0;
}