1 // license:BSD-3-Clause
2 // copyright-holders:Luca Elia, Mirko Buffoni, Takahiro Nogi
3 #ifndef MAME_INCLUDES_TNZS_H
4 #define MAME_INCLUDES_TNZS_H
5 
6 #pragma once
7 
8 
9 #include "cpu/mcs48/mcs48.h"
10 #include "machine/bankdev.h"
11 #include "machine/gen_latch.h"
12 #include "machine/upd4701.h"
13 #include "sound/dac.h"
14 #include "sound/samples.h"
15 #include "video/seta001.h"
16 #include "emupal.h"
17 #include "screen.h"
18 
19 class tnzs_base_state : public driver_device
20 {
21 public:
tnzs_base_state(const machine_config & mconfig,device_type type,const char * tag)22 	tnzs_base_state(const machine_config &mconfig, device_type type, const char *tag)
23 		: driver_device(mconfig, type, tag)
24 		, m_maincpu(*this, "maincpu")
25 		, m_subcpu(*this, "sub")
26 		, m_seta001(*this, "spritegen")
27 		, m_palette(*this, "palette")
28 		, m_gfxdecode(*this, "gfxdecode")
29 		, m_screen(*this, "screen")
30 		, m_mainbank(*this, "mainbank")
31 		, m_subbank(*this, "subbank")
32 	{ }
33 
34 	void tnzs_base(machine_config &config);
35 	void tnzs_mainbank(machine_config &config);
36 
37 protected:
38 	virtual void machine_start() override;
39 
40 	virtual void bankswitch1_w(uint8_t data);
41 
42 	void ramrom_bankswitch_w(uint8_t data);
43 
44 	void prompalette(palette_device &palette) const;
45 	uint32_t screen_update_tnzs(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
46 	DECLARE_WRITE_LINE_MEMBER(screen_vblank_tnzs);
47 
48 	void base_sub_map(address_map &map);
49 	void main_map(address_map &map);
50 	void mainbank_map(address_map &map);
51 
52 	/* devices */
53 	required_device<cpu_device> m_maincpu;
54 	optional_device<cpu_device> m_subcpu;
55 	optional_device<seta001_device> m_seta001;
56 	required_device<palette_device> m_palette;
57 	required_device<gfxdecode_device> m_gfxdecode;
58 	required_device<screen_device> m_screen;
59 	optional_device<address_map_bank_device> m_mainbank; /* FIXME: optional because of reuse from cchance.cpp */
60 	optional_memory_bank m_subbank; /* FIXME: optional because of reuse from cchance.cpp */
61 
62 	/* misc / mcu */
63 	int      m_bank2;
64 };
65 
66 class tnzs_mcu_state : public tnzs_base_state
67 {
68 public:
tnzs_mcu_state(const machine_config & mconfig,device_type type,const char * tag,bool lockout_level)69 	tnzs_mcu_state(const machine_config &mconfig, device_type type, const char *tag, bool lockout_level)
70 		: tnzs_base_state(mconfig, type, tag)
71 		, m_mcu(*this, "mcu")
72 		, m_upd4701(*this, "upd4701")
73 		, m_in0(*this, "IN0")
74 		, m_in1(*this, "IN1")
75 		, m_in2(*this, "IN2")
76 		, m_input_select(0)
77 		, m_lockout_level(lockout_level)
78 	{ }
79 
80 	void tnzs(machine_config &config);
81 
82 protected:
83 	virtual void bankswitch1_w(uint8_t data) override;
84 
85 	uint8_t mcu_port1_r();
86 	void mcu_port2_w(uint8_t data);
87 	uint8_t mcu_r(offs_t offset);
88 	void mcu_w(offs_t offset, uint8_t data);
89 
90 	uint8_t analog_r(offs_t offset);
91 
92 	void tnzs_sub_map(address_map &map);
93 
94 	required_device<upi41_cpu_device> m_mcu;
95 	optional_device<upd4701_device> m_upd4701;
96 
97 	required_ioport m_in0;
98 	required_ioport m_in1;
99 	required_ioport m_in2;
100 
101 	int      m_input_select;
102 	bool     m_lockout_level;
103 };
104 
105 class tnzs_state : public tnzs_mcu_state
106 {
107 public:
tnzs_state(const machine_config & mconfig,device_type type,const char * tag)108 	tnzs_state(const machine_config &mconfig, device_type type, const char *tag)
109 		: tnzs_mcu_state(mconfig, type, tag, true)
110 	{ }
111 };
112 
113 class extrmatn_state : public tnzs_mcu_state
114 {
115 public:
extrmatn_state(const machine_config & mconfig,device_type type,const char * tag)116 	extrmatn_state(const machine_config &mconfig, device_type type, const char *tag)
117 		: tnzs_mcu_state(mconfig, type, tag, false)
118 	{ }
119 	void extrmatn(machine_config &config);
120 	void plumppop(machine_config &config);
121 
122 protected:
123 	void prompal_main_map(address_map &map);
124 };
125 
126 class arknoid2_state : public extrmatn_state
127 {
128 public:
arknoid2_state(const machine_config & mconfig,device_type type,const char * tag)129 	arknoid2_state(const machine_config &mconfig, device_type type, const char *tag)
130 		: extrmatn_state(mconfig, type, tag)
131 		, m_coin1(*this, "COIN1")
132 		, m_coin2(*this, "COIN2")
133 		, m_in0(*this, "IN0")
134 		, m_in1(*this, "IN1")
135 		, m_in2(*this, "IN2")
136 	{ }
137 
138 	void arknoid2(machine_config &config);
139 
140 private:
141 	virtual void machine_start() override;
142 	virtual void machine_reset() override;
143 
144 	virtual void bankswitch1_w(uint8_t data) override;
145 
146 	uint8_t mcu_r(offs_t offset);
147 	void mcu_w(offs_t offset, uint8_t data);
148 	INTERRUPT_GEN_MEMBER(mcu_interrupt);
149 
150 	void arknoid2_sub_map(address_map &map);
151 
152 	required_ioport m_coin1;
153 	required_ioport m_coin2;
154 	required_ioport m_in0;
155 	required_ioport m_in1;
156 	required_ioport m_in2;
157 
158 	void mcu_reset();
159 
160 	int      m_mcu_initializing;
161 	int      m_mcu_coinage_init;
162 	int      m_mcu_command;
163 	int      m_mcu_readcredits;
164 	int      m_mcu_reportcoin;
165 	int      m_insertcoin;
166 	uint8_t    m_mcu_coinage[4];
167 	uint8_t    m_mcu_coins_a;
168 	uint8_t    m_mcu_coins_b;
169 	uint8_t    m_mcu_credits;
170 
171 	void mcu_handle_coins(int coin);
172 };
173 
174 class kageki_state : public tnzs_base_state
175 {
176 public:
kageki_state(const machine_config & mconfig,device_type type,const char * tag)177 	kageki_state(const machine_config &mconfig, device_type type, const char *tag)
178 		: tnzs_base_state(mconfig, type, tag)
179 		, m_samples(*this, "samples")
180 		, m_dswa(*this, "DSWA")
181 		, m_dswb(*this, "DSWB")
182 		, m_csport_sel(0)
183 	{ }
184 
185 	void kageki(machine_config &config);
186 
187 	void init_kageki();
188 
189 protected:
190 	virtual void machine_start() override;
191 	virtual void machine_reset() override;
192 
193 private:
194 	static constexpr unsigned MAX_SAMPLES = 0x2f;
195 
196 	virtual void bankswitch1_w(uint8_t data) override;
197 
198 	uint8_t csport_r();
199 	void csport_w(uint8_t data);
200 
201 	DECLARE_MACHINE_RESET(kageki);
202 
203 	SAMPLES_START_CB_MEMBER(init_samples);
204 
205 	void kageki_sub_map(address_map &map);
206 
207 	required_device<samples_device> m_samples;
208 
209 	required_ioport m_dswa;
210 	required_ioport m_dswb;
211 
212 	/* sound-related */
213 	std::unique_ptr<int16_t[]>    m_sampledata[MAX_SAMPLES];
214 	int      m_samplesize[MAX_SAMPLES];
215 
216 	int      m_csport_sel;
217 };
218 
219 class jpopnics_state : public tnzs_base_state
220 {
221 public:
jpopnics_state(const machine_config & mconfig,device_type type,const char * tag)222 	jpopnics_state(const machine_config &mconfig, device_type type, const char *tag)
223 		: tnzs_base_state(mconfig, type, tag)
224 		, m_upd4701(*this, "upd4701")
225 	{ }
226 
227 	void jpopnics(machine_config &config);
228 
229 protected:
230 	virtual void machine_reset() override;
231 
232 private:
233 	void subbankswitch_w(uint8_t data);
234 
235 	void jpopnics_main_map(address_map &map);
236 	void jpopnics_sub_map(address_map &map);
237 	required_device<upd4701_device> m_upd4701;
238 };
239 
240 class insectx_state : public tnzs_base_state
241 {
242 public:
insectx_state(const machine_config & mconfig,device_type type,const char * tag)243 	insectx_state(const machine_config &mconfig, device_type type, const char *tag)
244 		: tnzs_base_state(mconfig, type, tag)
245 	{ }
246 
247 	void insectx(machine_config &config);
248 
249 private:
250 	virtual void bankswitch1_w(uint8_t data) override;
251 	void insectx_sub_map(address_map &map);
252 };
253 
254 class tnzsb_state : public tnzs_base_state
255 {
256 public:
tnzsb_state(const machine_config & mconfig,device_type type,const char * tag)257 	tnzsb_state(const machine_config &mconfig, device_type type, const char *tag)
258 		: tnzs_base_state(mconfig, type, tag)
259 		, m_audiocpu(*this, "audiocpu")
260 		, m_soundlatch(*this, "soundlatch")
261 	{ }
262 
263 	void tnzsb(machine_config &config);
264 
265 protected:
266 	DECLARE_WRITE_LINE_MEMBER(ym2203_irqhandler);
267 
268 	void sound_command_w(uint8_t data);
269 
270 	virtual void bankswitch1_w(uint8_t data) override;
271 
272 	void tnzsb_base_sub_map(address_map &map);
273 	void tnzsb_cpu2_map(address_map &map);
274 	void tnzsb_io_map(address_map &map);
275 	void tnzsb_main_map(address_map &map);
276 	void tnzsb_sub_map(address_map &map);
277 
278 	required_device<cpu_device> m_audiocpu;
279 	required_device<generic_latch_8_device> m_soundlatch;
280 };
281 
282 class kabukiz_state : public tnzsb_state
283 {
284 public:
kabukiz_state(const machine_config & mconfig,device_type type,const char * tag)285 	kabukiz_state(const machine_config &mconfig, device_type type, const char *tag)
286 		: tnzsb_state(mconfig, type, tag)
287 		, m_audiobank(*this, "audiobank")
288 	{ }
289 
290 	void kabukiz(machine_config &config);
291 
292 protected:
293 	virtual void machine_start() override;
294 
295 private:
296 	void sound_bank_w(uint8_t data);
297 
298 	void kabukiz_cpu2_map(address_map &map);
299 	void kabukiz_sub_map(address_map &map);
300 
301 	required_memory_bank m_audiobank;
302 };
303 
304 #endif // MAME_INCLUDES_TNZS_H
305