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

    Atari Food Fight hardware

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

#include "emu.h"
#include "includes/foodf.h"
#include "video/resnet.h"


/*************************************
 *
 *  Tilemap callbacks
 *
 *************************************/

TILE_GET_INFO_MEMBER(foodf_state::get_playfield_tile_info)
{
	uint16_t data = m_playfield_tilemap->basemem_read(tile_index);
	int code = (data & 0xff) | ((data >> 7) & 0x100);
	int color = (data >> 8) & 0x3f;
	SET_TILE_INFO_MEMBER(0, code, color, m_playfield_flip ? (TILE_FLIPX | TILE_FLIPY) : 0);
}



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

void foodf_state::video_start()
{
	static const int resistances[3] = { 1000, 470, 220 };

	/* adjust the playfield for the 8 pixel offset */
	m_playfield_tilemap->set_scrollx(0, -8);
	save_item(NAME(m_playfield_flip));

	/* compute the color output resistor weights */
	compute_resistor_weights(0, 255, -1.0,
			3,  &resistances[0], m_rweights, 0, 0,
			3,  &resistances[0], m_gweights, 0, 0,
			2,  &resistances[1], m_bweights, 0, 0);
}



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

void foodf_state::foodf_set_flip(int flip)
{
	if (flip != m_playfield_flip)
	{
		m_playfield_flip = flip;
		m_playfield_tilemap->mark_all_dirty();
	}
}



/*************************************
 *
 *  Palette RAM write
 *
 *************************************/

WRITE16_MEMBER(foodf_state::foodf_paletteram_w)
{
	int newword, r, g, b, bit0, bit1, bit2;

	COMBINE_DATA(&m_paletteram[offset]);
	newword = m_paletteram[offset];

	/* only the bottom 8 bits are used */
	/* red component */
	bit0 = (newword >> 0) & 0x01;
	bit1 = (newword >> 1) & 0x01;
	bit2 = (newword >> 2) & 0x01;
	r = combine_weights(m_rweights, bit0, bit1, bit2);

	/* green component */
	bit0 = (newword >> 3) & 0x01;
	bit1 = (newword >> 4) & 0x01;
	bit2 = (newword >> 5) & 0x01;
	g = combine_weights(m_gweights, bit0, bit1, bit2);

	/* blue component */
	bit0 = (newword >> 6) & 0x01;
	bit1 = (newword >> 7) & 0x01;
	b = combine_weights(m_bweights, bit0, bit1);

	m_palette->set_pen_color(offset, rgb_t(r, g, b));
}



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

uint32_t foodf_state::screen_update_foodf(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int offs;
	gfx_element *gfx = m_gfxdecode->gfx(1);
	bitmap_ind8 &priority_bitmap = screen.priority();
	uint16_t *spriteram16 = m_spriteram;

	/* first draw the playfield opaquely */
	m_playfield_tilemap->draw(screen, bitmap, cliprect, TILEMAP_DRAW_OPAQUE, 0);

	/* then draw the non-transparent parts with a priority of 1 */
	priority_bitmap.fill(0);
	m_playfield_tilemap->draw(screen, bitmap, cliprect, 0, 1);

	/* draw the motion objects front-to-back */
	for (offs = 0x80-2; offs >= 0x20; offs -= 2)
	{
		int data1 = spriteram16[offs];
		int data2 = spriteram16[offs+1];

		int pict = data1 & 0xff;
		int color = (data1 >> 8) & 0x1f;
		int xpos = (data2 >> 8) & 0xff;
		int ypos = (0xff - data2 - 16) & 0xff;
		int hflip = (data1 >> 15) & 1;
		int vflip = (data1 >> 14) & 1;
		int pri = (data1 >> 13) & 1;

		gfx->prio_transpen(bitmap,cliprect, pict, color, hflip, vflip,
				xpos, ypos, priority_bitmap, pri * 2, 0);

		/* draw again with wraparound (needed to get the end of level animation right) */
		gfx->prio_transpen(bitmap,cliprect, pict, color, hflip, vflip,
				xpos - 256, ypos, priority_bitmap, pri * 2, 0);
	}

	return 0;
}