1 // license:BSD-3-Clause
2 // copyright-holders:Bryan McPhail
3 #include "cpu/h6280/h6280.h"
4 #include "audio/decobsmt.h"
5 #include "video/bufsprite.h"
6 #include "video/decospr.h"
7 #include "video/deco16ic.h"
8 #include "video/deco_ace.h"
9 #include "machine/deco_irq.h"
10 #include "machine/eepromser.h"
11 #include "machine/gen_latch.h"
12 #include "sound/lc7535.h"
13 #include "sound/okim6295.h"
14 #include "sound/ym2151.h"
15 #include "machine/deco146.h"
16 #include "machine/deco104.h"
17 #include "video/deco_zoomspr.h"
18 #include "emupal.h"
19 #include "screen.h"
20 
21 class deco32_state : public driver_device
22 {
23 public:
deco32_state(const machine_config & mconfig,device_type type,const char * tag)24 	deco32_state(const machine_config &mconfig, device_type type, const char *tag)
25 		: driver_device(mconfig, type, tag)
26 		, m_audiocpu(*this, "audiocpu")
27 		, m_sprgen(*this, "spritegen%u", 1)
28 		, m_deco_tilegen(*this, "tilegen%u", 1)
29 		, m_gfxdecode(*this, "gfxdecode")
30 		, m_screen(*this, "screen")
31 		, m_palette(*this, "palette")
32 		, m_deco_irq(*this, "irq")
33 		, m_decobsmt(*this, "decobsmt")
34 		, m_eeprom(*this, "eeprom")
35 		, m_ioprot(*this, "ioprot")
36 		, m_ym2151(*this, "ymsnd")
37 		, m_oki(*this, "oki%u", 1)
38 		, m_soundlatch(*this, "soundlatch")
39 		, m_maincpu(*this, "maincpu")
40 		, m_pf_rowscroll32(*this, "pf%u_rowscroll32", 1)
41 		, m_paletteram(*this, "paletteram")
42 	{ }
43 
44 	void sound_bankswitch_w(u8 data);
45 
46 protected:
47 	void h6280_sound_custom_latch_map(address_map &map);
48 	void h6280_sound_map(address_map &map);
49 	void z80_sound_io(address_map &map);
50 	void z80_sound_map(address_map &map);
51 
52 	// common
53 	u16 ioprot_r(offs_t offset);
54 	void ioprot_w(offs_t offset, u16 data, u16 mem_mask = ~0);
55 	u8 eeprom_r();
56 	void eeprom_w(u8 data);
57 	void volume_w(u8 data);
58 	void vblank_ack_w(u32 data);
59 
60 	template<int Chip> void pf_rowscroll_w(offs_t offset, u32 data, u32 mem_mask = ~0);
61 
62 	// captaven, fghthist, nslasher and tattass
63 	template<int Chip> u32 spriteram_r(offs_t offset);
64 	template<int Chip> void spriteram_w(offs_t offset, u32 data, u32 mem_mask = ~0);
65 	template<int Chip> void buffer_spriteram_w(u32 data);
66 	void pri_w(u32 data);
67 
68 	// all but captaven
69 	void buffered_palette_w(offs_t offset, u32 data, u32 mem_mask = ~0);
70 	void palette_dma_w(u32 data);
71 
72 	optional_device<cpu_device> m_audiocpu;
73 	optional_device_array<decospr_device, 2> m_sprgen;
74 	required_device_array<deco16ic_device, 2> m_deco_tilegen;
75 	required_device<gfxdecode_device> m_gfxdecode;
76 	required_device<screen_device> m_screen;
77 	optional_device<palette_device> m_palette;
78 	optional_device<deco_irq_device> m_deco_irq;
79 	optional_device<decobsmt_device> m_decobsmt;
80 	optional_device<eeprom_serial_93cxx_device> m_eeprom;
81 	required_device<deco_146_base_device> m_ioprot;
82 	optional_device<ym2151_device> m_ym2151;
83 	optional_device_array<okim6295_device, 3> m_oki;
84 	optional_device<generic_latch_8_device> m_soundlatch;
85 	required_device<cpu_device> m_maincpu;
86 
87 	void allocate_spriteram(int chip);
88 	void allocate_buffered_palette();
89 	void allocate_rowscroll(int size1, int size2, int size3, int size4);
90 
91 	virtual void video_start() override;
92 
93 	std::unique_ptr<u8[]> m_dirty_palette; // all but captaven
94 	int m_pri; // all but dragngun
95 	std::unique_ptr<u16[]> m_spriteram16[2]; // all but dragngun
96 	std::unique_ptr<u16[]> m_spriteram16_buffered[2]; // all but dragngun
97 	std::unique_ptr<u16[]> m_pf_rowscroll[4]; // common
98 
99 private:
100 	// we use the pointers below to store a 32-bit copy..
101 	required_shared_ptr_array<u32, 4> m_pf_rowscroll32;
102 	optional_shared_ptr<u32> m_paletteram;
103 };
104 
105 class captaven_state : public deco32_state
106 {
107 public:
captaven_state(const machine_config & mconfig,device_type type,const char * tag)108 	captaven_state(const machine_config &mconfig, device_type type, const char *tag)
109 		: deco32_state(mconfig, type, tag)
110 		, m_io_dsw(*this, "DSW%u", 1U)
111 	{ }
112 
113 	void captaven(machine_config &config);
114 
115 	void init_captaven();
116 
117 private:
118 	required_ioport_array<3> m_io_dsw;
119 	u32 _71_r();
120 	u8 captaven_soundcpu_status_r();
121 
122 	virtual void video_start() override;
123 
124 	u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
125 
126 	void tile_callback(u32 &tile, u32 &colour, int layer, bool is_8x8);
127 	DECO16IC_BANK_CB_MEMBER(bank_callback);
128 	DECOSPR_PRIORITY_CB_MEMBER(captaven_pri_callback);
129 
130 	void captaven_map(address_map &map);
131 };
132 
133 class fghthist_state : public deco32_state
134 {
135 public:
fghthist_state(const machine_config & mconfig,device_type type,const char * tag)136 	fghthist_state(const machine_config &mconfig, device_type type, const char *tag)
137 		: deco32_state(mconfig, type, tag)
138 		, m_io_in(*this, "IN%u", 0U)
139 	{ }
140 
141 	void fghthist(machine_config &config);
142 	void fghthistu(machine_config &config);
143 	void fghthsta(machine_config &config);
144 
145 	void init_fghthist();
146 
147 private:
148 	required_ioport_array<2> m_io_in;
149 //  void sound_w(u32 data);
150 	u32 unk_status_r();
151 
152 	virtual void video_start() override;
153 
154 	u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
155 
156 	DECO16IC_BANK_CB_MEMBER(bank_callback);
157 	DECOSPR_PRIORITY_CB_MEMBER(fghthist_pri_callback);
158 
159 	void fghthist_map(address_map &map);
160 	void fghthsta_memmap(address_map &map);
161 private:
162 };
163 
164 // nslasher, tattass
165 class nslasher_state : public deco32_state
166 {
167 public:
nslasher_state(const machine_config & mconfig,device_type type,const char * tag)168 	nslasher_state(const machine_config &mconfig, device_type type, const char *tag)
169 		: deco32_state(mconfig, type, tag)
170 		, m_deco_ace(*this, "deco_ace")
171 	{ }
172 
173 	void nslasheru(machine_config &config);
174 	void tattass(machine_config &config);
175 	void nslasher(machine_config &config);
176 
177 	void init_tattass();
178 	void init_nslasher();
179 
180 private:
181 	required_device<deco_ace_device> m_deco_ace;
182 
183 	void tilemap_color_bank_w(u8 data);
184 	void sprite1_color_bank_w(u8 data);
185 	void sprite2_color_bank_w(u8 data);
186 	void tattass_control_w(offs_t offset, u32 data, u32 mem_mask = ~0);
187 	DECLARE_WRITE_LINE_MEMBER(tattass_sound_irq_w);
188 	u16 nslasher_debug_r();
189 
190 	virtual void video_start() override;
191 
192 	u32 screen_update_nslasher(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
193 	u32 screen_update_tattass(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
194 
195 	u16 port_b_tattass();
196 	DECO16IC_BANK_CB_MEMBER(bank_callback);
197 	u16 mix_callback(u16 p, u16 p2);
198 
199 	void nslasher_map(address_map &map);
200 	void tattass_map(address_map &map);
201 
202 	void mix_nslasher(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx0, gfx_element *gfx1, int mixAlphaTilemap);
203 	void mix_tattass(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx0, gfx_element *gfx1, int mixAlphaTilemap);
204 
205 	std::unique_ptr<bitmap_ind16> m_tilemap_alpha_bitmap;
206 
207 	int m_tattass_eprom_bit;
208 	int m_last_clock;
209 	u32 m_buffer;
210 	int m_buf_ptr;
211 	int m_pending_command;
212 	int m_read_bit_count;
213 	int m_byte_addr;
214 };
215 
216 class dragngun_state : public deco32_state
217 {
218 public:
dragngun_state(const machine_config & mconfig,device_type type,const char * tag)219 	dragngun_state(const machine_config &mconfig, device_type type, const char *tag)
220 		: deco32_state(mconfig, type, tag)
221 		, m_sprgenzoom(*this, "spritegen_zoom")
222 		, m_spriteram(*this, "spriteram")
223 		, m_sprite_layout_ram(*this, "lay%u", 0)
224 		, m_sprite_lookup_ram(*this, "look%u", 0)
225 		, m_vol_main(*this, "vol_main")
226 		, m_vol_gun(*this, "vol_gun")
227 		, m_io_inputs(*this, "INPUTS")
228 		, m_io_light_x(*this, "LIGHT%u_X", 0U)
229 		, m_io_light_y(*this, "LIGHT%u_Y", 0U)
230 		, m_gun_speaker_disabled(true)
231 	{ }
232 
233 	void dragngun(machine_config &config);
234 	void lockload(machine_config &config);
235 	void lockloadu(machine_config &config);
236 
237 	void init_dragngun();
238 	void init_dragngunj();
239 	void init_lockload();
240 
241 	DECLARE_INPUT_CHANGED_MEMBER(lockload_gun_trigger);
242 
243 private:
244 	required_device<deco_zoomspr_device> m_sprgenzoom;
245 	required_device<buffered_spriteram32_device> m_spriteram;
246 
247 	required_shared_ptr_array<u32, 2> m_sprite_layout_ram;
248 	required_shared_ptr_array<u32, 2> m_sprite_lookup_ram;
249 	required_device<lc7535_device> m_vol_main;
250 	optional_device<lc7535_device> m_vol_gun;
251 
252 	optional_ioport m_io_inputs;
253 	optional_ioport_array<2> m_io_light_x;
254 	optional_ioport_array<2> m_io_light_y;
255 
256 	u32 m_sprite_ctrl;
257 	int m_lightgun_port;
258 	int m_oki2_bank; // lockload
259 	bitmap_rgb32 m_temp_render_bitmap;
260 
261 	u32 lightgun_r();
262 	void lightgun_w(offs_t offset, u32 data = 0);
263 	void sprite_control_w(u32 data);
264 	void spriteram_dma_w(u32 data);
265 	void gun_irq_ack_w(u32 data);
266 	u32 unk_video_r();
267 	void eeprom_w(u8 data);
268 	u32 lockload_gun_mirror_r(offs_t offset);
269 
270 	void volume_w(u32 data);
271 	void speaker_switch_w(u32 data);
272 	LC7535_VOLUME_CHANGED(volume_main_changed);
273 	LC7535_VOLUME_CHANGED(volume_gun_changed);
274 
275 	void lockload_okibank_lo_w(u8 data);
276 	void lockload_okibank_hi_w(u8 data); // lockload
277 
278 	virtual void video_start() override;
279 	void dragngun_init_common();
280 
281 	u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
282 
283 	DECO16IC_BANK_CB_MEMBER(bank_1_callback);
284 	DECO16IC_BANK_CB_MEMBER(bank_2_callback);
285 
286 	void dragngun_map(address_map &map);
287 	void lockload_map(address_map &map);
288 	void lockloadu_map(address_map &map);
289 	void lockload_sound_map(address_map &map);
290 	void lockloadu_sound_map(address_map &map);
291 	bool m_gun_speaker_disabled;
292 };
293