1 // license:BSD-3-Clause
2 // copyright-holders:Bryan McPhail
3 #ifndef MAME_INCLUDES_DEC0_H
4 #define MAME_INCLUDES_DEC0_H
5 
6 #pragma once
7 
8 #include "cpu/h6280/h6280.h"
9 #include "cpu/mcs51/mcs51.h"
10 #include "machine/74157.h"
11 #include "machine/bankdev.h"
12 #include "machine/gen_latch.h"
13 #include "sound/msm5205.h"
14 #include "video/bufsprite.h"
15 #include "video/decbac06.h"
16 #include "video/decmxc06.h"
17 #include "emupal.h"
18 #include "screen.h"
19 
20 class dec0_state : public driver_device
21 {
22 public:
dec0_state(const machine_config & mconfig,device_type type,const char * tag)23 	dec0_state(const machine_config &mconfig, device_type type, const char *tag) :
24 		driver_device(mconfig, type, tag),
25 		m_maincpu(*this, "maincpu"),
26 		m_audiocpu(*this, "audiocpu"),
27 		m_soundlatch(*this, "soundlatch"),
28 		m_screen(*this, "screen"),
29 		m_gfxdecode(*this, "gfxdecode"),
30 		m_tilegen(*this, "tilegen%u", 1U),
31 		m_spritegen(*this, "spritegen"),
32 		m_spriteram(*this, "spriteram"),
33 		m_palette(*this, "palette"),
34 		m_paletteram(*this, "palette"),
35 		m_subcpu(*this, "sub"),
36 		m_mcu(*this, "mcu"),
37 		m_pfprotect(*this, "pfprotect"),
38 		m_sndprotect(*this, "sndprotect"),
39 		m_ram(*this, "ram"),
40 		m_robocop_shared_ram(*this, "robocop_shared"),
41 		m_hippodrm_shared_ram(*this, "hippodrm_shared")
42 	{ }
43 
44 	void dec0_base(machine_config &config);
45 	void dec0(machine_config &config);
46 	void dec1(machine_config &config);
47 	void midres(machine_config &config);
48 	void birdtry(machine_config &config);
49 	void baddudes(machine_config &config);
50 	void midresbj(machine_config &config);
51 	void slyspy(machine_config &config);
52 	void hbarrel(machine_config &config);
53 	void bandit(machine_config &config);
54 	void midresb(machine_config &config);
55 	void ffantasybl(machine_config &config);
56 	void drgninjab(machine_config &config);
57 	void robocop(machine_config &config);
58 	void robocopb(machine_config &config);
59 	void hippodrm(machine_config &config);
60 
61 	void init_hippodrm();
62 	void init_hbarrel();
63 	void init_slyspy();
64 	void init_drgninja();
65 	void init_midresb();
66 	void init_ffantasybl();
67 
68 protected:
69 	required_device<cpu_device> m_maincpu;
70 	required_device<cpu_device> m_audiocpu;
71 	required_device<generic_latch_8_device> m_soundlatch;
72 	required_device<screen_device> m_screen;
73 	required_device<gfxdecode_device> m_gfxdecode;
74 	optional_device_array<deco_bac06_device, 3> m_tilegen;
75 	optional_device<deco_mxc06_device> m_spritegen;
76 	required_device<buffered_spriteram16_device> m_spriteram;
77 	required_device<palette_device> m_palette;
78 	required_shared_ptr<uint16_t> m_paletteram;
79 
80 	uint16_t *m_buffered_spriteram;
81 	uint16_t m_pri;
82 
83 	uint16_t dec0_controls_r(offs_t offset);
84 	uint16_t slyspy_controls_r(offs_t offset);
85 	void priority_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
86 
87 	DECLARE_VIDEO_START(dec0_nodma);
88 	DECLARE_VIDEO_START(slyspy);
89 
90 	void robocop_colpri_cb(u32 &colour, u32 &pri_mask);
91 	void baddudes_tile_cb(tile_data &tileinfo, u32 &tile, u32 &colour, u32 &flags);
92 
93 	void set_screen_raw_params_data_east(machine_config &config);
94 
95 private:
96 	enum class mcu_type {
97 		EMULATED,
98 		BADDUDES_SIM
99 	};
100 
101 	optional_device<h6280_device> m_subcpu;
102 	optional_device<cpu_device> m_mcu;
103 	optional_device<address_map_bank_device> m_pfprotect;
104 	optional_device<address_map_bank_device> m_sndprotect;
105 	required_shared_ptr<uint16_t> m_ram;
106 	optional_shared_ptr<uint8_t> m_robocop_shared_ram;
107 	optional_shared_ptr<uint8_t> m_hippodrm_shared_ram;
108 
109 	mcu_type m_game;
110 	uint16_t m_i8751_return;
111 	uint16_t m_i8751_command;
112 	int m_slyspy_state;
113 	int m_slyspy_sound_state;
114 	int m_hippodrm_msb;
115 	int m_hippodrm_lsb;
116 	uint8_t m_i8751_ports[4];
117 
118 	void dec0_control_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
119 	void midres_sound_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
120 	uint16_t slyspy_protection_r(offs_t offset);
121 	void slyspy_state_w(uint16_t data);
122 	uint16_t slyspy_state_r();
123 	uint16_t midres_controls_r(offs_t offset);
124 	uint8_t hippodrm_prot_r(offs_t offset);
125 	void hippodrm_prot_w(offs_t offset, uint8_t data);
126 	uint8_t dec0_mcu_port0_r();
127 	void dec0_mcu_port0_w(uint8_t data);
128 	void dec0_mcu_port1_w(uint8_t data);
129 	void dec0_mcu_port2_w(uint8_t data);
130 	void dec0_mcu_port3_w(uint8_t data);
131 	uint16_t hippodrm_68000_share_r(offs_t offset);
132 	void hippodrm_68000_share_w(offs_t offset, uint16_t data);
133 	void sprite_mirror_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
134 	uint16_t robocop_68000_share_r(offs_t offset);
135 	void robocop_68000_share_w(offs_t offset, uint16_t data);
136 	uint16_t ffantasybl_242024_r();
137 
138 	uint8_t slyspy_sound_state_r();
139 	uint8_t slyspy_sound_state_reset_r();
140 
141 	virtual void machine_start() override;
142 	DECLARE_MACHINE_RESET(slyspy);
143 	DECLARE_VIDEO_START(dec0);
144 	DECLARE_VIDEO_START(baddudes);
145 
146 	uint32_t screen_update_hbarrel(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
147 	uint32_t screen_update_baddudes(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
148 	uint32_t screen_update_birdtry(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
149 	uint32_t screen_update_robocop(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
150 	uint32_t screen_update_slyspy(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
151 
152 	void hbarrel_colpri_cb(u32 &colour, u32 &pri_mask);
153 	void bandit_colpri_cb(u32 &colour, u32 &pri_mask);
154 	void midres_colpri_cb(u32 &colour, u32 &pri_mask);
155 
156 	void baddudes_i8751_write(int data);
157 	void dec0_i8751_write(int data);
158 	void dec0_i8751_reset();
159 	void h6280_decrypt(const char *cputag);
160 	void dec0_map(address_map &map);
161 	void dec0_tb_map(address_map &map);
162 	void dec0_s_map(address_map &map);
163 	void hippodrm_map(address_map &map);
164 	void hippodrm_sub_map(address_map &map);
165 	void midres_map(address_map &map);
166 	void midres_s_map(address_map &map);
167 	void midresb_map(address_map &map);
168 	void robocop_map(address_map &map);
169 	void robocop_sub_map(address_map &map);
170 	void slyspy_map(address_map &map);
171 	void slyspy_protection_map(address_map &map);
172 	void slyspy_s_map(address_map &map);
173 	void slyspy_sound_protection_map(address_map &map);
174 };
175 
176 
177 class dec0_automat_state : public dec0_state
178 {
179 public:
dec0_automat_state(const machine_config & mconfig,device_type type,const char * tag)180 	dec0_automat_state(const machine_config &mconfig, device_type type, const char *tag) :
181 		dec0_state(mconfig, type, tag),
182 		m_msm(*this, "msm%u", 1U),
183 		m_adpcm_select(*this, "adpcm_select%u", 1U),
184 		m_soundbank(*this, "soundbank")
185 	{
186 	}
187 
188 	void secretab(machine_config &config);
189 	void automat(machine_config &config);
190 
191 private:
192 	required_device_array<msm5205_device, 2> m_msm;
193 	required_device_array<ls157_device, 2> m_adpcm_select;
194 	required_memory_bank m_soundbank;
195 
196 	bool m_adpcm_toggle[2];
197 	uint16_t m_automat_scroll_regs[4];
198 
199 	void automat_control_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
200 	uint16_t automat_palette_r(offs_t offset);
201 	void automat_palette_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
202 	void automat_scroll_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0)
203 	{
204 		COMBINE_DATA(&m_automat_scroll_regs[offset]);
205 	}
206 	void sound_bankswitch_w(uint8_t data);
207 	DECLARE_WRITE_LINE_MEMBER(msm1_vclk_cb);
208 	DECLARE_WRITE_LINE_MEMBER(msm2_vclk_cb);
209 
210 	virtual void machine_start() override;
211 
212 	uint32_t screen_update_automat(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
213 	uint32_t screen_update_secretab(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
214 	void automat_map(address_map &map);
215 	void automat_s_map(address_map &map);
216 	void secretab_map(address_map &map);
217 	void secretab_s_map(address_map &map);
218 };
219 
220 #endif // MAME_INCLUDES_DEC0_H
221