summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/kaneko_spr.h
blob: f5533cc11ec9e0615cdb7d046b67b73ed9ffcc69 (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
// license:BSD-3-Clause
// copyright-holders:Luca Elia, David Haywood
#ifndef MAME_VIDEO_KANEKO_SPR_H
#define MAME_VIDEO_KANEKO_SPR_H

#pragma once

/* Kaneko Sprites */

/* berlwall, blazeon etc. */
#define MCFG_DEVICE_ADD_VU002_SPRITES \
	MCFG_DEVICE_ADD("kan_spr", KANEKO_VU002_SPRITE, 0)
/* gtmr, gtmr2, bloodwar etc. */
#define MCFG_DEVICE_ADD_KC002_SPRITES \
	MCFG_DEVICE_ADD("kan_spr", KANEKO_KC002_SPRITE, 0)


struct kaneko16_priority_t
{
	int sprite[4];
};

struct kan_tempsprite
{
	int code,color;
	int x,y;
	int xoffs,yoffs;
	int flipx,flipy;
	int priority;
};



class kaneko16_sprite_device : public device_t, public device_video_interface
{
public:
	// configuration
	void set_gfxdecode_tag(const char *tag) { m_gfxdecode.set_tag(tag); }
	void set_fliptype(int fliptype) { m_sprite_fliptype = fliptype; }
	void set_offsets(int xoffs, int yoffs)
	{
		m_sprite_xoffs = xoffs;
		m_sprite_yoffs = yoffs;
	}
	void set_priorities(int pri0, int pri1, int pri2, int pri3)
	{
		m_priority.sprite[0] = pri0;
		m_priority.sprite[1] = pri1;
		m_priority.sprite[2] = pri2;
		m_priority.sprite[3] = pri3;
	}

	// (legacy) used in the bitmap clear functions
	virtual int get_sprite_type(void) =0;

	void kaneko16_render_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap, uint16_t* spriteram16, int spriteram16_bytes);
	void kaneko16_render_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap, uint16_t* spriteram16, int spriteram16_bytes);


	template<class _BitmapClass>
	void kaneko16_render_sprites_common(_BitmapClass &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap, uint16_t* spriteram16, int spriteram16_bytes);

	void bootleg_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, uint16_t* spriteram16, int spriteram16_bytes);


	DECLARE_READ16_MEMBER(kaneko16_sprites_regs_r);
	DECLARE_WRITE16_MEMBER(kaneko16_sprites_regs_w);

protected:
	kaneko16_sprite_device(
			const machine_config &mconfig,
			device_type type,
			const char *tag,
			device_t *owner,
			uint32_t clock);

	virtual void device_start() override;
	virtual void device_reset() override;


	// flip latching (set when declaring device in MCFG )  probably needs figuring out properly, only brapboys wants it?
	int m_sprite_fliptype;

	// offsets (set when declaring device in MCFG )
	uint16_t m_sprite_xoffs;
	uint16_t m_sprite_yoffs;

	// priority for mixing (set when declaring device in MCFG )
	kaneko16_priority_t m_priority;

	// pure virtual function for getting the attributes on sprites, the two different chip types have
	// them in a different order
	virtual void get_sprite_attributes(struct kan_tempsprite *s, uint16_t attr) =0;


private:
	// registers
	uint16_t m_sprite_flipx;
	uint16_t m_sprite_flipy;
	std::unique_ptr<uint16_t[]> m_sprites_regs;

	std::unique_ptr<struct kan_tempsprite[]> m_first_sprite;
	int m_keep_sprites;
	bitmap_ind16 m_sprites_bitmap;


	template<class _BitmapClass>
	void kaneko16_draw_sprites(_BitmapClass &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap, uint16_t* spriteram16, int spriteram16_bytes);


	template<class _BitmapClass>
	void kaneko16_draw_sprites_custom(_BitmapClass &dest_bmp,const rectangle &clip,gfx_element *gfx,
			uint32_t code,uint32_t color,int flipx,int flipy,int sx,int sy,
			bitmap_ind8 &priority_bitmap, int priority);

	int kaneko16_parse_sprite_type012(int i, struct kan_tempsprite *s, uint16_t* spriteram16, int spriteram16_bytes);

	void kaneko16_copybitmap(bitmap_ind16 &bitmap, const rectangle &cliprect);
	void kaneko16_copybitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect);

	required_device<gfxdecode_device> m_gfxdecode;

};

//extern const device_type KANEKO16_SPRITE;

#define MCFG_KANEKO16_SPRITE_GFXDECODE(_gfxtag) \
	downcast<kaneko16_sprite_device &>(*device).set_gfxdecode_tag(_gfxtag);
#define MCFG_KANEKO16_SPRITE_PRIORITIES(_pri0, _pri1, _pri2, _pri3) \
	downcast<kaneko16_sprite_device &>(*device).set_priorities(_pri0, _pri1, _pri2, _pri3);
#define MCFG_KANEKO16_SPRITE_OFFSETS(_xoffs, _yoffs) \
	downcast<kaneko16_sprite_device &>(*device).set_offsets(_xoffs, _yoffs);
#define MCFG_KANEKO16_SPRITE_FLIPTYPE(_fliptype) \
	downcast<kaneko16_sprite_device &>(*device).set_fliptype(_fliptype);


class kaneko_vu002_sprite_device : public kaneko16_sprite_device
{
public:
	kaneko_vu002_sprite_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
	void get_sprite_attributes(struct kan_tempsprite *s, uint16_t attr) override;
	int get_sprite_type(void) override{ return 0; };
};

DECLARE_DEVICE_TYPE(KANEKO_VU002_SPRITE, kaneko_vu002_sprite_device)

class kaneko_kc002_sprite_device : public kaneko16_sprite_device
{
public:
	kaneko_kc002_sprite_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
	void get_sprite_attributes(struct kan_tempsprite *s, uint16_t attr) override;
	int get_sprite_type(void) override{ return 1; };
};

DECLARE_DEVICE_TYPE(KANEKO_KC002_SPRITE, kaneko_kc002_sprite_device)

#endif // MAME_VIDEO_KANEKO_SPR_H