summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/decmxc06.c
blob: c5ab3bdcfe49c9574fda5150abee2776c2c95446 (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
/*
 Deco MXC06 sprite generator:

 used by:
 madmotor.c

Notes (dec0.c)

   Sprite data:  The unknown bits seem to be unused.

    Byte 0:
        Bit 0 : Y co-ord hi bit
        Bit 1,2 : Sprite width (1x, 2x, 4x, 8x)
        Bit 3,4 : Sprite height (1x, 2x, 4x, 8x)
        Bit 5  - X flip
        Bit 6  - Y flip
        Bit 7  - Only display Sprite if set
    Byte 1: Y-coords
    Byte 2:
        Bit 0,1,2,3: Hi bits of sprite number
        Bit 4,5,6,7: (Probably unused MSB's of sprite)
    Byte 3: Low bits of sprite number
    Byte 4:
        Bit 0 : X co-ords hi bit
        Bit 1,2: ??
        Bit 3: Sprite flash (sprite is displayed every other frame)
        Bit 4,5,6,7:  - Colour
    Byte 5: X-coords


todo:
    Implement sprite/tilemap orthogonality (not strictly needed as no
    games make deliberate use of it). (pdrawgfx, or rendering to bitmap for manual mixing)

*/


#include "emu.h"
#include "decmxc06.h"

void deco_mxc06_device::set_gfx_region(device_t &device, int region)
{
	deco_mxc06_device &dev = downcast<deco_mxc06_device &>(device);
	dev.m_gfxregion = region;
}


const device_type DECO_MXC06 = &device_creator<deco_mxc06_device>;

deco_mxc06_device::deco_mxc06_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, DECO_MXC06, "decmxc06_device", tag, owner, clock, "deco_mxc06", __FILE__),
		m_gfxregion(0),
		m_gfxdecode(*this),
		m_palette(*this)
{
}

//-------------------------------------------------
//  static_set_gfxdecode_tag: Set the tag of the
//  gfx decoder
//-------------------------------------------------

void deco_mxc06_device::static_set_gfxdecode_tag(device_t &device, const char *tag)
{
	downcast<deco_mxc06_device &>(device).m_gfxdecode.set_tag(tag);
}


/* this implementation was originally from Mad Motor */
void deco_mxc06_device::draw_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, UINT16* spriteram, int pri_mask, int pri_val, int col_mask )
{
	int offs;

	offs = 0;
	while (offs < 0x800 / 2)
	{
		int sx, sy, code, color, w, h, flipx, flipy, incy, flash, mult, x, y;

		sy = spriteram[offs];
		sx = spriteram[offs + 2];
		color = sx >> 12;

		flash = sx & 0x800;

		flipx = sy & 0x2000;
		flipy = sy & 0x4000;
		h = (1 << ((sy & 0x1800) >> 11));   /* 1x, 2x, 4x, 8x height */
		w = (1 << ((sy & 0x0600) >>  9));   /* 1x, 2x, 4x, 8x width */
		/* multi width used only on the title screen? */



		sx = sx & 0x01ff;
		sy = sy & 0x01ff;
		if (sx >= 256) sx -= 512;
		if (sy >= 256) sy -= 512;
		sx = 240 - sx;
		sy = 240 - sy;
		
		if (machine.driver_data()->flip_screen())
		{
			sy = 240 - sy;
			sx = 240 - sx;
			if (flipx) flipx = 0; else flipx = 1;
			if (flipy) flipy = 0; else flipy = 1;
			mult = 16;
		}
		else
			mult = -16;

		for (x = 0; x < w; x++)
		{
			// maybe, birdie try appears to specify the base code for each part..
			code = spriteram[offs + 1] & 0x1fff;

			code &= ~(h-1);

			if (flipy)
				incy = -1;
			else
			{
				code += h-1;
				incy = 1;
			}
			
			for (y = 0; y < h; y++)
			{
				if (spriteram[offs] & 0x8000)
				{
					int draw = 0;
					if (!flash || (machine.first_screen()->frame_number() & 1))
					{
						if (m_priority_type==0) // most cases
						{
							if ((color & pri_mask) == pri_val)
							{
								draw = 1;
							}
						}
						else if (m_priority_type==1) // vaportra
						{
							if (pri_mask && (color >= pri_val))
								continue;

							if (!pri_mask && !(color >= pri_val))
								continue;

							draw = 1;
						}
					}

					if (draw)
					{
						m_gfxdecode->gfx(m_gfxregion)->transpen(m_palette,bitmap,cliprect,
							code - y * incy,
							color & col_mask,
							flipx,flipy,
							sx + (mult * x),sy + (mult * y),0);
					}
				}
			}

			offs += 4;
			if (offs >= 0x800 / 2)
					return;
		}
	}
}

/* this is used by the automat bootleg, it seems to have greatly simplified sprites compared to the real chip */
/* spriteram is twice the size tho! */
void deco_mxc06_device::draw_sprites_bootleg( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, UINT16* spriteram, int pri_mask, int pri_val, int col_mask )
{
	int offs;

	offs = 0;
	while (offs < 0x800 / 2)
	{
		int sx, sy, code, color, flipx, flipy;

		code =  spriteram[offs];
		sy = 240-spriteram[offs + 1]; // 241- will align robocop with the ground but causes other issues too
		sx = spriteram[offs + 2];
		code |= (spriteram[offs + 3] &0x0f)<<8;
		flipx = !(spriteram[offs + 3] &0x20);
		flipy = (spriteram[offs + 3] &0x40);
		color = (spriteram[offs + 0x400]&0xf0)>>4;
		sx |= (spriteram[offs + 0x400]&0x01)<<8;
		sx -= 16;
		sx &=0x1ff;

		sx -= 0x100;

		m_gfxdecode->gfx(m_gfxregion)->transpen(m_palette,bitmap,cliprect,
			code,
			color & col_mask,
			flipx,flipy,
			sx,sy,0);

		offs += 4;
	}
}

void deco_mxc06_device::device_start()
{
	m_priority_type = 0;
}

void deco_mxc06_device::device_reset()
{
}

//-------------------------------------------------
//  static_set_palette_tag: Set the tag of the
//  palette device
//-------------------------------------------------

void deco_mxc06_device::static_set_palette_tag(device_t &device, const char *tag)
{
	downcast<deco_mxc06_device &>(device).m_palette.set_tag(tag);
}