1 // license:BSD-3-Clause
2 // copyright-holders:Luca Elia, David Haywood
3 #ifndef MAME_VIDEO_KANEKO_SPR_H
4 #define MAME_VIDEO_KANEKO_SPR_H
5
6 #pragma once
7
8 /* Kaneko Sprites */
9
10
11 struct priority_t
12 {
13 int sprite[4];
14 };
15
16 struct tempsprite_t
17 {
18 u32 code,color;
19 int x,y;
20 int xoffs,yoffs;
21 bool flipx,flipy;
22 int priority;
23 };
24
25
26
27 class kaneko16_sprite_device : public device_t, public device_gfx_interface, public device_video_interface
28 {
29 public:
30 // configuration
set_color_base(u16 base)31 void set_color_base(u16 base) { m_colbase = base; }
set_fliptype(int fliptype)32 void set_fliptype(int fliptype) { m_sprite_fliptype = fliptype; }
set_offsets(int xoffs,int yoffs)33 void set_offsets(int xoffs, int yoffs)
34 {
35 m_sprite_xoffs = xoffs;
36 m_sprite_yoffs = yoffs;
37 }
set_priorities(int pri0,int pri1,int pri2,int pri3)38 void set_priorities(int pri0, int pri1, int pri2, int pri3)
39 {
40 m_priority.sprite[0] = pri0;
41 m_priority.sprite[1] = pri1;
42 m_priority.sprite[2] = pri2;
43 m_priority.sprite[3] = pri3;
44 }
45
46 // (legacy) used in the bitmap clear functions
47 virtual int get_sprite_type(void) =0;
48
49 void render_sprites(const rectangle &cliprect, u16* spriteram16, int spriteram16_bytes);
50
51 void copybitmap(bitmap_ind16 &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap);
52 void copybitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap);
53
54 template<class BitmapClass>
55 void copybitmap_common(BitmapClass &bitmap, const rectangle &cliprect, bitmap_ind8 &priority_bitmap);
56
57 void bootleg_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, u16* spriteram16, int spriteram16_bytes);
58
59 u16 regs_r(offs_t offset);
60 void regs_w(offs_t offset, u16 data, u16 mem_mask);
61
62 protected:
63 kaneko16_sprite_device(
64 const machine_config &mconfig,
65 device_type type,
66 const char *tag,
67 device_t *owner,
68 u32 clock);
69
70 virtual void device_start() override;
71 virtual void device_reset() override;
72
73
74 // flip latching (set when declaring device in MCFG ) probably needs figuring out properly, only brapboys wants it?
75 int m_sprite_fliptype;
76
77 // offsets (set when declaring device in MCFG )
78 u16 m_sprite_xoffs;
79 u16 m_sprite_yoffs;
80
81 // priority for mixing (set when declaring device in MCFG )
82 priority_t m_priority;
83
84 // pure virtual function for getting the attributes on sprites, the two different chip types have
85 // them in a different order
86 virtual void get_sprite_attributes(struct tempsprite_t *s, u16 attr) =0;
87
88 required_memory_region m_gfx_region;
89 u16 m_colbase;
90
91 private:
92 // registers
93 u16 m_sprite_flipx;
94 u16 m_sprite_flipy;
95 std::unique_ptr<u16[]> m_sprites_regs;
96
97 std::unique_ptr<struct tempsprite_t[]> m_first_sprite;
98 int m_keep_sprites;
99 bitmap_ind16 m_sprites_bitmap;
100 bitmap_ind8 m_sprites_maskmap;
101
102
103 void draw_sprites(const rectangle &cliprect, u16* spriteram16, int spriteram16_bytes);
104
105
106 void draw_sprites_custom(const rectangle &clip,gfx_element *gfx,
107 u32 code,u32 color,bool flipx,bool flipy,int sx,int sy,
108 int priority);
109
110 int parse_sprite_type012(int i, struct tempsprite_t *s, u16* spriteram16, int spriteram16_bytes);
111 };
112
113 //extern const device_type KANEKO16_SPRITE;
114
115
116 /* berlwall, blazeon etc. */
117 class kaneko_vu002_sprite_device : public kaneko16_sprite_device
118 {
119 public:
kaneko_vu002_sprite_device(const machine_config & mconfig,const char * tag,device_t * owner)120 kaneko_vu002_sprite_device(const machine_config &mconfig, const char *tag, device_t *owner)
121 : kaneko_vu002_sprite_device(mconfig, tag, owner, (u32)0)
122 {
123 }
124
125 kaneko_vu002_sprite_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
126 void get_sprite_attributes(struct tempsprite_t *s, u16 attr) override;
get_sprite_type(void)127 int get_sprite_type(void) override{ return 0; };
128
129 protected:
130 virtual void device_start() override;
131 };
132
DECLARE_DEVICE_TYPE(KANEKO_VU002_SPRITE,kaneko_vu002_sprite_device)133 DECLARE_DEVICE_TYPE(KANEKO_VU002_SPRITE, kaneko_vu002_sprite_device)
134
135 /* gtmr, gtmr2, bloodwar etc. */
136 class kaneko_kc002_sprite_device : public kaneko16_sprite_device
137 {
138 public:
139 kaneko_kc002_sprite_device(const machine_config &mconfig, const char *tag, device_t *owner)
140 : kaneko_kc002_sprite_device(mconfig, tag, owner, (u32)0)
141 {
142 }
143
144 kaneko_kc002_sprite_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
145 void get_sprite_attributes(struct tempsprite_t *s, u16 attr) override;
146 int get_sprite_type(void) override{ return 1; };
147
148 protected:
149 virtual void device_start() override;
150 };
151
152 DECLARE_DEVICE_TYPE(KANEKO_KC002_SPRITE, kaneko_kc002_sprite_device)
153
154 #endif // MAME_VIDEO_KANEKO_SPR_H
155