summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/deckarn.cpp
blob: 67543ea4239bb8910bba4fa82d0b1e8ee8454a35 (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
// license:BSD-3-Clause
// copyright-holders:Bryan McPhail,David Haywood
/* Data East 'Karnov style' sprites */
/* Custom Chip ??? */

#include "emu.h"
#include "deckarn.h"

DEFINE_DEVICE_TYPE(DECO_KARNOVSPRITES, deco_karnovsprites_device, "deco_karnovsprites", "DECO Karnov Sprites")

deco_karnovsprites_device::deco_karnovsprites_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: device_t(mconfig, DECO_KARNOVSPRITES, tag, owner, clock)
	, m_colpri_cb(*this)
{
}

void deco_karnovsprites_device::device_start()
{
	m_flip_screen = false;
	m_colpri_cb.resolve();

	save_item(NAME(m_flip_screen));
}

void deco_karnovsprites_device::device_reset()
{
}

void deco_karnovsprites_device::draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element *gfx, u16* spriteram, int size)
{
	const bool priority = !m_colpri_cb.isnull();
	int start, end, inc;
	if (priority)             { start = size - 4; end =   -4; inc = -4; }
	else                      { start =        0; end = size; inc = +4; }

	for (int offs = start; offs != end; offs += inc)
	{
		int sprite2;
		u32 pri_mask = 0;

		const u16 data0 = spriteram[offs];
		if (!(data0 & 0x8000))
			continue;

		int y = data0 & 0x1ff;
		const u16 data3 = spriteram[offs + 3];
		u32 colour = data3 >> 12;
		if (priority)
			m_colpri_cb(colour, pri_mask);

		u32 sprite = data3 & 0xfff;
		int x = spriteram[offs + 2] & 0x1ff;

		const u16 data1 = spriteram[offs + 1];

		/* the 8-bit implementation had this.
		           illustrated by enemy projectile explosions in Shackled being left on screen. */
		if ((data1 & 0x1) == 0) continue;

		const bool extra = (data1 & 0x10) ? 1 : 0;
		int fy = data1 & 0x2;
		int fx = data1 & 0x4;

		if (extra)
		{
			y = y + 16;
			sprite &= 0xffe; // taken from 8-bit version
		}

		/* Convert the co-ords..*/
		x = (x + 16) % 0x200;
		y = (y + 16) % 0x200;
		x = 256 - x;
		y = 256 - y;
		if (m_flip_screen)
		{
			y = 240 - y;
			x = 240 - x;
			if (fx) fx = 0; else fx = 1;
			if (fy) fy = 0; else fy = 1;
			if (extra) y = y - 16;
		}

		/* Y Flip determines order of multi-sprite */
		if (extra && fy)
		{
			sprite2 = sprite;
			sprite++;
		}
		else
			sprite2 = sprite + 1;

		if (priority)
		{
			gfx->prio_transpen(bitmap,cliprect,
					sprite,
					colour,fx,fy,x,y,screen.priority(),pri_mask,0);

			/* 1 more sprite drawn underneath */
			if (extra)
				gfx->prio_transpen(bitmap,cliprect,
					sprite2,
					colour,fx,fy,x,y+16,screen.priority(),pri_mask,0);
		}
		else
		{
			gfx->transpen(bitmap,cliprect,
					sprite,
					colour,fx,fy,x,y,0);

			/* 1 more sprite drawn underneath */
			if (extra)
				gfx->transpen(bitmap,cliprect,
					sprite2,
					colour,fx,fy,x,y+16,0);
		}
	}
}