1 // license:BSD-3-Clause
2 // copyright-holders:Zsolt Vasvari
3 /*************************************************************************
4 
5     VIC Dual Game board
6 
7 *************************************************************************/
8 
9 #include "cpu/mcs48/mcs48.h"
10 #include "machine/pit8253.h"
11 #include "machine/timer.h"
12 #include "sound/ay8910.h"
13 #include "sound/dac.h"
14 #include "sound/discrete.h"
15 #include "sound/samples.h"
16 #include "screen.h"
17 #include "audio/vicdual.h"
18 #include "audio/vicdual-97271p.h"
19 #include "video/vicdual-97269pb.h"
20 
21 class vicdual_state : public driver_device
22 {
23 public:
vicdual_state(const machine_config & mconfig,device_type type,const char * tag)24 	vicdual_state(const machine_config &mconfig, device_type type, const char *tag) :
25 		driver_device(mconfig, type, tag),
26 		m_maincpu(*this,"maincpu"),
27 		m_samples(*this, "samples"),
28 		m_discrete(*this, "discrete"),
29 		m_coinstate_timer(*this, "coinstate"),
30 		m_nsub_coinage_timer(*this, "nsub_coin"),
31 		m_screen(*this, "screen"),
32 		m_vicdual_sound(*this, "vicdual_sound"),
33 		m_proms(*this, "proms"),
34 		m_videoram(*this, "videoram"),
35 		m_characterram(*this, "characterram"),
36 		m_in0(*this, "IN0"),
37 		m_in1(*this, "IN1"),
38 		m_in2(*this, "IN2"),
39 		m_coinage(*this, "COINAGE"),
40 		m_color_bw(*this, "COLOR_BW"),
41 		m_fake_lives(*this, "FAKE_LIVES.%u", 0)
42 	{ }
43 
44 	void vicdual_root(machine_config &config);
45 	void vicdual_dualgame_root(machine_config &config);
46 	void heiankyo(machine_config &config);
47 	void headon(machine_config &config);
48 	void headon_audio(machine_config &config);
49 	void sspacaho(machine_config &config);
50 	void headonn(machine_config &config);
51 	void invho2(machine_config &config);
52 	void frogs(machine_config &config);
53 	void headons(machine_config &config);
54 	void invinco(machine_config &config);
55 	void invinco_audio(machine_config &config);
56 	void invds(machine_config &config);
57 	void headon2(machine_config &config);
58 	void pulsar(machine_config &config);
59 	void pulsar_audio(machine_config &config);
60 	void spacetrk(machine_config &config);
61 	void headon2bw(machine_config &config);
62 	void safari(machine_config &config);
63 	void brdrline(machine_config &config);
64 	void samurai(machine_config &config);
65 	void sspaceat(machine_config &config);
66 	void digger(machine_config &config);
67 	void depthch(machine_config &config);
68 	void depthch_audio(machine_config &config);
69 	void carhntds(machine_config &config);
70 	void alphaho(machine_config &config);
71 
72 	DECLARE_READ_LINE_MEMBER(coin_status_r);
73 	DECLARE_READ_LINE_MEMBER(get_64v);
74 	DECLARE_READ_LINE_MEMBER(vblank_comp_r);
75 	DECLARE_READ_LINE_MEMBER(cblank_comp_r);
76 	DECLARE_READ_LINE_MEMBER(timer_value_r);
77 	template <int Param> DECLARE_READ_LINE_MEMBER(fake_lives_r);
78 	template <int N> DECLARE_READ_LINE_MEMBER(samurai_protection_r);
79 	DECLARE_INPUT_CHANGED_MEMBER(coin_changed);
80 
81 protected:
82 	required_device<cpu_device> m_maincpu;
83 	optional_device<samples_device> m_samples;
84 	optional_device<discrete_sound_device> m_discrete;
85 	required_device<timer_device> m_coinstate_timer;
86 	optional_device<timer_device> m_nsub_coinage_timer;
87 	required_device<screen_device> m_screen;
88 	optional_device<vicdual_audio_device_base> m_vicdual_sound;
89 	optional_memory_region m_proms;
90 
91 	required_shared_ptr<uint8_t> m_videoram;
92 	required_shared_ptr<uint8_t> m_characterram;
93 
94 	required_ioport m_in0;
95 	required_ioport m_in1;
96 	optional_ioport m_in2;
97 	optional_ioport m_coinage;
98 	optional_ioport m_color_bw;
99 	optional_ioport_array<2> m_fake_lives;
100 
101 	uint8_t m_coin_status;
102 	uint8_t m_palette_bank;
103 	uint8_t m_samurai_protection_data;
104 	int m_port1State;
105 	int m_port2State;
106 	emu_timer *m_frogs_croak_timer;
107 
108 	void coin_in();
109 	void assert_coin_status();
110 
111 	// common
112 	void videoram_w(offs_t offset, uint8_t data);
113 	void characterram_w(offs_t offset, uint8_t data);
114 	void palette_bank_w(uint8_t data);
115 
116 	// game specific
117 	uint8_t depthch_io_r(offs_t offset);
118 	void depthch_io_w(offs_t offset, uint8_t data);
119 	uint8_t safari_io_r(offs_t offset);
120 	void safari_io_w(offs_t offset, uint8_t data);
121 	uint8_t frogs_io_r(offs_t offset);
122 	void frogs_io_w(offs_t offset, uint8_t data);
123 	uint8_t headon_io_r(offs_t offset);
124 	uint8_t sspaceat_io_r(offs_t offset);
125 	void headon_io_w(offs_t offset, uint8_t data);
126 	DECLARE_MACHINE_RESET(headon2);
127 	uint8_t headon2_io_r(offs_t offset);
128 	void headon2_io_w(offs_t offset, uint8_t data);
129 	void digger_io_w(offs_t offset, uint8_t data);
130 	void invho2_io_w(offs_t offset, uint8_t data);
131 	void invds_io_w(offs_t offset, uint8_t data);
132 	void carhntds_io_w(offs_t offset, uint8_t data);
133 	void sspacaho_io_w(offs_t offset, uint8_t data);
134 	void headonn_io_w(offs_t offset, uint8_t data);
135 	void spacetrk_io_w(offs_t offset, uint8_t data);
136 	void brdrline_io_w(offs_t offset, uint8_t data);
137 	void pulsar_io_w(offs_t offset, uint8_t data);
138 	void heiankyo_io_w(offs_t offset, uint8_t data);
139 	void alphaho_io_w(offs_t offset, uint8_t data);
140 	void samurai_protection_w(uint8_t data);
141 	void samurai_io_w(offs_t offset, uint8_t data);
142 	uint8_t invinco_io_r(offs_t offset);
143 	void invinco_io_w(offs_t offset, uint8_t data);
144 
145 	/*----------- defined in audio/vicdual.cpp -----------*/
146 	void headon_audio_w(uint8_t data);
147 	void invho2_audio_w(uint8_t data);
148 
149 	/*----------- defined in audio/depthch.cpp -----------*/
150 	void depthch_audio_w(uint8_t data);
151 
152 	/*----------- defined in audio/invinco.cpp -----------*/
153 	void invinco_audio_w(uint8_t data);
154 
155 	/*----------- defined in audio/pulsar.cpp -----------*/
156 	void pulsar_audio_1_w(uint8_t data);
157 	void pulsar_audio_2_w(uint8_t data);
158 
159 	TIMER_DEVICE_CALLBACK_MEMBER(clear_coin_status);
160 
161 	DECLARE_MACHINE_START(samurai);
162 
163 	virtual void machine_start() override;
164 
165 	uint32_t screen_update_bw(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
166 	uint32_t screen_update_bw_or_color(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
167 	uint32_t screen_update_color(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
168 	int get_vcounter();
169 	int is_cabinet_color();
170 	virtual pen_t choose_pen(uint8_t x, uint8_t y, pen_t back_pen);
171 
172 	void alphaho_io_map(address_map &map);
173 	void brdrline_io_map(address_map &map);
174 	void carhntds_dualgame_map(address_map &map);
175 	void carhntds_io_map(address_map &map);
176 	void depthch_io_map(address_map &map);
177 	void depthch_map(address_map &map);
178 	void digger_io_map(address_map &map);
179 	void frogs_io_map(address_map &map);
180 	void frogs_map(address_map &map);
181 	void headon2_io_map(address_map &map);
182 	void headon2_map(address_map &map);
183 	void headon_io_map(address_map &map);
184 	void headon_map(address_map &map);
185 	void headonn_io_map(address_map &map);
186 	void heiankyo_io_map(address_map &map);
187 	void invds_io_map(address_map &map);
188 	void invho2_io_map(address_map &map);
189 	void invinco_io_map(address_map &map);
190 	void invinco_map(address_map &map);
191 	void pulsar_io_map(address_map &map);
192 	void safari_io_map(address_map &map);
193 	void safari_map(address_map &map);
194 	void samurai_io_map(address_map &map);
195 	void samurai_map(address_map &map);
196 	void spacetrk_io_map(address_map &map);
197 	void sspacaho_io_map(address_map &map);
198 	void sspaceat_io_map(address_map &map);
199 	void vicdual_dualgame_map(address_map &map);
200 };
201 
202 class tranqgun_state : public vicdual_state
203 {
204 public:
tranqgun_state(const machine_config & mconfig,device_type type,const char * tag)205 	tranqgun_state(const machine_config &mconfig, device_type type, const char *tag) :
206 		vicdual_state(mconfig, type, tag)
207 	{ }
208 
209 	void tranqgun(machine_config &config);
210 
211 protected:
212 	virtual void machine_start() override;
213 
214 private:
215 	void tranqgun_io_map(address_map &map);
216 	void tranqgun_io_w(offs_t offset, uint8_t data);
217 
218 	uint8_t tranqgun_prot_r(offs_t offset);
219 	void tranqgun_prot_w(offs_t offset, uint8_t data);
220 
221 	void tranqgun_dualgame_map(address_map &map);
222 
223 	uint8_t m_tranqgun_prot_return;
224 };
225 
226 
227 class nsub_state : public vicdual_state
228 {
229 public:
nsub_state(const machine_config & mconfig,device_type type,const char * tag)230 	nsub_state(const machine_config &mconfig, device_type type, const char *tag) :
231 		vicdual_state(mconfig, type, tag),
232 		m_s97269pb(*this,"s97269pb"),
233 		m_s97271p(*this,"s97271p")
234 	{ }
235 
236 	void nsub(machine_config &config);
237 
238 	DECLARE_INPUT_CHANGED_MEMBER(nsub_coin_in);
239 
240 private:
241 	required_device<s97269pb_device> m_s97269pb;
242 	required_device<s97271p_device> m_s97271p;
243 
244 	int m_nsub_coin_counter;
245 	int m_nsub_play_counter;
246 
247 	uint8_t nsub_io_r(offs_t offset);
248 	void nsub_io_w(offs_t offset, uint8_t data);
249 
250 	TIMER_DEVICE_CALLBACK_MEMBER(nsub_coin_pulse);
251 
252 	DECLARE_MACHINE_START(nsub);
253 	DECLARE_MACHINE_RESET(nsub);
254 
255 	virtual pen_t choose_pen(uint8_t x, uint8_t y, pen_t back_pen) override;
256 	void nsub_io_map(address_map &map);
257 	void nsub_map(address_map &map);
258 };
259 
260 class carnival_state : public vicdual_state
261 {
262 public:
carnival_state(const machine_config & mconfig,device_type type,const char * tag)263 	carnival_state(const machine_config &mconfig, device_type type, const char *tag) :
264 		vicdual_state(mconfig, type, tag),
265 		m_audiocpu(*this, "audiocpu"),
266 		m_psg(*this, "psg"),
267 		m_pit(*this, "pit"),
268 		m_dac(*this, "dac%u", 0)
269 	{ }
270 
271 	void carnival(machine_config &config);
272 	void carnivalb(machine_config &config);
273 	void carnivalh(machine_config &config);
274 
275 	void carnivala_audio(machine_config &config);
276 	void carnivalb_audio(machine_config &config);
277 
278 protected:
279 	virtual void machine_start() override;
280 
281 	required_device<i8035_device> m_audiocpu;
282 	optional_device<ay8910_device> m_psg;
283 	optional_device<pit8253_device> m_pit;
284 	optional_device_array<dac_bit_interface, 3> m_dac;
285 
286 	void carnival_io_map(address_map &map);
287 	void mboard_map(address_map &map);
288 
289 	int m_musicData;
290 	int m_musicBus;
291 
292 	void carnival_io_w(offs_t offset, uint8_t data);
293 
294 	/*----------- defined in audio/carnival.cpp -----------*/
295 	void carnival_audio_1_w(uint8_t data);
296 	void carnival_audio_2_w(uint8_t data);
297 	DECLARE_READ_LINE_MEMBER( carnival_music_port_t1_r );
298 	void carnivala_music_port_1_w(uint8_t data);
299 	void carnivala_music_port_2_w(uint8_t data);
300 	void carnival_psg_latch();
301 	void carnivalb_music_port_1_w(uint8_t data);
302 	void carnivalb_music_port_2_w(uint8_t data);
303 };
304 
305 class headonsa_state : public vicdual_state
306 {
307 public:
headonsa_state(const machine_config & mconfig,device_type type,const char * tag)308 	headonsa_state(const machine_config &mconfig, device_type type, const char *tag) :
309 		vicdual_state(mconfig, type, tag)
310 	{ }
311 
312 	DECLARE_INPUT_CHANGED_MEMBER(headonsa_coin_inserted);
313 };
314