1 // license:BSD-3-Clause
2 // copyright-holders:Ernesto Corvi,Tim Lindquist,Carlos A. Lozano,Bryan McPhail,Jarek Parchanski,Nicola Salmoria,Tomasz Slanina,Phil Stroffolino,Acho A. Tang,Victor Trucco
3 // thanks-to:Marco Cassili
4 
5 /*************************************************************************
6 
7     various SNK triple Z80 games
8 
9 *************************************************************************/
10 #ifndef MAME_INCLUDES_SNK_H
11 #define MAME_INCLUDES_SNK_H
12 
13 #pragma once
14 
15 #include "machine/gen_latch.h"
16 #include "emupal.h"
17 #include "screen.h"
18 #include "tilemap.h"
19 
20 class snk_state : public driver_device
21 {
22 public:
snk_state(const machine_config & mconfig,device_type type,const char * tag)23 	snk_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_subcpu(*this, "sub"),
28 		m_gfxdecode(*this, "gfxdecode"),
29 		m_screen(*this, "screen"),
30 		m_palette(*this, "palette"),
31 		m_soundlatch(*this, "soundlatch"),
32 		m_spriteram(*this, "spriteram"),
33 		m_fg_videoram(*this, "fg_videoram"),
34 		m_bg_videoram(*this, "bg_videoram"),
35 		m_tx_videoram(*this, "tx_videoram"),
36 		m_rot_io(*this, "P%uROT", 1U),
37 		m_trackball_x_io(*this, "TRACKBALLX%u", 1U),
38 		m_trackball_y_io(*this, "TRACKBALLY%u", 1U),
39 		m_joymode_io(*this, "JOYSTICK_MODE"),
40 		m_bonus_io(*this, "BONUS")
41 	{ }
42 
43 	void gwar(machine_config &config);
44 	void psychos(machine_config &config);
45 	void fitegolf(machine_config &config);
46 	void countryc(machine_config &config);
47 	void tdfever2(machine_config &config);
48 	void aso(machine_config &config);
49 	void gwara(machine_config &config);
50 	void tdfever(machine_config &config);
51 	void fitegolf2(machine_config &config);
52 	void jcross(machine_config &config);
53 	void choppera(machine_config &config);
54 	void tnk3(machine_config &config);
55 	void victroad(machine_config &config);
56 	void chopper1(machine_config &config);
57 	void vangrd2(machine_config &config);
58 	void bermudat(machine_config &config);
59 	void hal21(machine_config &config);
60 	void marvins(machine_config &config);
61 	void athena(machine_config &config);
62 	void ikari(machine_config &config);
63 	void sgladiat(machine_config &config);
64 	void madcrush(machine_config &config);
65 
66 	DECLARE_READ_LINE_MEMBER(sound_busy_r);
67 	template <int Which> DECLARE_CUSTOM_INPUT_MEMBER(gwar_rotary);
68 	template <int Which> DECLARE_CUSTOM_INPUT_MEMBER(gwarb_rotary);
69 	DECLARE_CUSTOM_INPUT_MEMBER(countryc_trackball_x);
70 	DECLARE_CUSTOM_INPUT_MEMBER(countryc_trackball_y);
71 	template <int Mask> DECLARE_CUSTOM_INPUT_MEMBER(snk_bonus_r);
72 
73 private:
74 	required_device<cpu_device> m_maincpu;
75 	required_device<cpu_device> m_audiocpu;
76 	required_device<cpu_device> m_subcpu;
77 	required_device<gfxdecode_device> m_gfxdecode;
78 	required_device<screen_device> m_screen;
79 	required_device<palette_device> m_palette;
80 	optional_device<generic_latch_8_device> m_soundlatch;
81 
82 	required_shared_ptr<uint8_t> m_spriteram;
83 	optional_shared_ptr<uint8_t> m_fg_videoram;
84 	required_shared_ptr<uint8_t> m_bg_videoram;
85 	required_shared_ptr<uint8_t> m_tx_videoram;
86 
87 	optional_ioport_array<2> m_rot_io;
88 	optional_ioport_array<2> m_trackball_x_io;
89 	optional_ioport_array<2> m_trackball_y_io;
90 	optional_ioport m_joymode_io;
91 	optional_ioport m_bonus_io;
92 
93 	int m_countryc_trackball;
94 	int m_last_value[2];
95 	int m_cp_count[2];
96 
97 	// FIXME this should be initialised on machine reset
98 	int m_sound_status;
99 
100 	tilemap_t *m_tx_tilemap;
101 	tilemap_t *m_fg_tilemap;
102 	tilemap_t *m_bg_tilemap;
103 	int m_fg_scrollx;
104 	int m_fg_scrolly;
105 	int m_bg_scrollx;
106 	int m_bg_scrolly;
107 	int m_sp16_scrollx;
108 	int m_sp16_scrolly;
109 	int m_sp32_scrollx;
110 	int m_sp32_scrolly;
111 	uint8_t m_sprite_split_point;
112 	int m_num_sprites;
113 	int m_yscroll_mask;
114 	uint32_t m_bg_tile_offset;
115 	uint32_t m_tx_tile_offset;
116 	int m_is_psychos;
117 
118 	uint8_t m_drawmode_table[16];
119 	uint8_t m_empty_tile[16*16];
120 	int m_hf_posy;
121 	int m_hf_posx;
122 	int m_tc16_posy;
123 	int m_tc16_posx;
124 	int m_tc32_posy;
125 	int m_tc32_posx;
126 	uint8_t snk_cpuA_nmi_trigger_r();
127 	void snk_cpuA_nmi_ack_w(uint8_t data);
128 	uint8_t snk_cpuB_nmi_trigger_r();
129 	void snk_cpuB_nmi_ack_w(uint8_t data);
130 	uint8_t marvins_sound_nmi_ack_r();
131 	void sgladiat_soundlatch_w(uint8_t data);
132 	uint8_t sgladiat_soundlatch_r();
133 	uint8_t sgladiat_sound_nmi_ack_r();
134 	uint8_t sgladiat_sound_irq_ack_r();
135 	void snk_soundlatch_w(uint8_t data);
136 	uint8_t snk_sound_status_r();
137 	void snk_sound_status_w(uint8_t data);
138 	uint8_t tnk3_cmdirq_ack_r();
139 	uint8_t tnk3_ymirq_ack_r();
140 	uint8_t tnk3_busy_clear_r();
141 	void hardflags_scrollx_w(uint8_t data);
142 	void hardflags_scrolly_w(uint8_t data);
143 	void hardflags_scroll_msb_w(uint8_t data);
144 	uint8_t hardflags1_r();
145 	uint8_t hardflags2_r();
146 	uint8_t hardflags3_r();
147 	uint8_t hardflags4_r();
148 	uint8_t hardflags5_r();
149 	uint8_t hardflags6_r();
150 	uint8_t hardflags7_r();
151 	void turbocheck16_1_w(uint8_t data);
152 	void turbocheck16_2_w(uint8_t data);
153 	void turbocheck32_1_w(uint8_t data);
154 	void turbocheck32_2_w(uint8_t data);
155 	void turbocheck_msb_w(uint8_t data);
156 	uint8_t turbocheck16_1_r();
157 	uint8_t turbocheck16_2_r();
158 	uint8_t turbocheck16_3_r();
159 	uint8_t turbocheck16_4_r();
160 	uint8_t turbocheck16_5_r();
161 	uint8_t turbocheck16_6_r();
162 	uint8_t turbocheck16_7_r();
163 	uint8_t turbocheck16_8_r();
164 	uint8_t turbocheck32_1_r();
165 	uint8_t turbocheck32_2_r();
166 	uint8_t turbocheck32_3_r();
167 	uint8_t turbocheck32_4_r();
168 	void athena_coin_counter_w(uint8_t data);
169 	void ikari_coin_counter_w(uint8_t data);
170 	void tdfever_coin_counter_w(uint8_t data);
171 	void countryc_trackball_w(uint8_t data);
172 	void snk_tx_videoram_w(offs_t offset, uint8_t data);
173 	void marvins_fg_videoram_w(offs_t offset, uint8_t data);
174 	void marvins_bg_videoram_w(offs_t offset, uint8_t data);
175 	void snk_bg_videoram_w(offs_t offset, uint8_t data);
176 	void snk_fg_scrollx_w(uint8_t data);
177 	void snk_fg_scrolly_w(uint8_t data);
178 	void snk_bg_scrollx_w(uint8_t data);
179 	void snk_bg_scrolly_w(uint8_t data);
180 	void snk_sp16_scrollx_w(uint8_t data);
181 	void snk_sp16_scrolly_w(uint8_t data);
182 	void snk_sp32_scrollx_w(uint8_t data);
183 	void snk_sp32_scrolly_w(uint8_t data);
184 	void snk_sprite_split_point_w(uint8_t data);
185 	void marvins_palette_bank_w(uint8_t data);
186 	void marvins_flipscreen_w(uint8_t data);
187 	void sgladiat_flipscreen_w(uint8_t data);
188 	void hal21_flipscreen_w(uint8_t data);
189 	void marvins_scroll_msb_w(uint8_t data);
190 	void jcross_scroll_msb_w(uint8_t data);
191 	void sgladiat_scroll_msb_w(uint8_t data);
192 	void aso_videoattrs_w(uint8_t data);
193 	void tnk3_videoattrs_w(uint8_t data);
194 	void aso_bg_bank_w(uint8_t data);
195 	void ikari_bg_scroll_msb_w(uint8_t data);
196 	void ikari_sp_scroll_msb_w(uint8_t data);
197 	void ikari_unknown_video_w(uint8_t data);
198 	void gwar_tx_bank_w(uint8_t data);
199 	void gwar_videoattrs_w(uint8_t data);
200 	void gwara_videoattrs_w(uint8_t data);
201 	void gwara_sp_scroll_msb_w(uint8_t data);
202 	void tdfever_sp_scroll_msb_w(uint8_t data);
203 	void tdfever_spriteram_w(offs_t offset, uint8_t data);
204 
205 	TILEMAP_MAPPER_MEMBER(marvins_tx_scan_cols);
206 	TILE_GET_INFO_MEMBER(marvins_get_tx_tile_info);
207 	TILE_GET_INFO_MEMBER(ikari_get_tx_tile_info);
208 	TILE_GET_INFO_MEMBER(gwar_get_tx_tile_info);
209 	TILE_GET_INFO_MEMBER(marvins_get_fg_tile_info);
210 	TILE_GET_INFO_MEMBER(marvins_get_bg_tile_info);
211 	TILE_GET_INFO_MEMBER(aso_get_bg_tile_info);
212 	TILE_GET_INFO_MEMBER(tnk3_get_bg_tile_info);
213 	TILE_GET_INFO_MEMBER(ikari_get_bg_tile_info);
214 	TILE_GET_INFO_MEMBER(gwar_get_bg_tile_info);
215 	DECLARE_VIDEO_START(marvins);
216 	void tnk3_palette(palette_device &palette) const;
217 	DECLARE_VIDEO_START(jcross);
218 	DECLARE_VIDEO_START(tnk3);
219 	DECLARE_VIDEO_START(ikari);
220 	DECLARE_VIDEO_START(gwar);
221 	DECLARE_VIDEO_START(tdfever);
222 	DECLARE_VIDEO_START(sgladiat);
223 	DECLARE_VIDEO_START(hal21);
224 	DECLARE_VIDEO_START(aso);
225 	DECLARE_VIDEO_START(psychos);
226 	DECLARE_VIDEO_START(snk_3bpp_shadow);
227 	DECLARE_VIDEO_START(snk_4bpp_shadow);
228 	uint32_t screen_update_marvins(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
229 	uint32_t screen_update_tnk3(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
230 	uint32_t screen_update_ikari(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
231 	uint32_t screen_update_gwar(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
232 	uint32_t screen_update_tdfever(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
233 	uint32_t screen_update_fitegolf2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
234 	TIMER_CALLBACK_MEMBER(sgladiat_sndirq_update_callback);
235 	TIMER_CALLBACK_MEMBER(sndirq_update_callback);
236 	DECLARE_WRITE_LINE_MEMBER(ymirq_callback_2);
237 	void marvins_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, const int scrollx, const int scrolly, const int from, const int to);
238 	void tnk3_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, const int xscroll, const int yscroll);
239 	void ikari_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, const int start, const int xscroll, const int yscroll, const uint8_t *source, const int gfxnum );
240 	void tdfever_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect,  const int xscroll, const int yscroll, const uint8_t *source, const int gfxnum, const int hw_xflip, const int from, const int to);
241 	int hardflags_check(int num);
242 	int hardflags_check8(int num);
243 	int turbofront_check(int small, int num);
244 	int turbofront_check8(int small, int num);
245 	DECLARE_WRITE_LINE_MEMBER(ymirq_callback_1);
246 
247 	void Y8950_sound_map(address_map &map);
248 	void YM3526_Y8950_sound_map(address_map &map);
249 	void YM3526_YM3526_sound_map(address_map &map);
250 	void YM3812_Y8950_sound_map(address_map &map);
251 	void YM3812_sound_map(address_map &map);
252 	void aso_YM3526_sound_map(address_map &map);
253 	void aso_cpuA_map(address_map &map);
254 	void aso_cpuB_map(address_map &map);
255 	void bermudat_cpuA_map(address_map &map);
256 	void bermudat_cpuB_map(address_map &map);
257 	void countryc_cpuA_map(address_map &map);
258 	void gwar_cpuA_map(address_map &map);
259 	void gwar_cpuB_map(address_map &map);
260 	void gwara_cpuA_map(address_map &map);
261 	void gwara_cpuB_map(address_map &map);
262 	void hal21_cpuA_map(address_map &map);
263 	void hal21_cpuB_map(address_map &map);
264 	void hal21_sound_map(address_map &map);
265 	void hal21_sound_portmap(address_map &map);
266 	void ikari_cpuA_map(address_map &map);
267 	void ikari_cpuB_map(address_map &map);
268 	void jcross_cpuA_map(address_map &map);
269 	void jcross_cpuB_map(address_map &map);
270 	void jcross_sound_map(address_map &map);
271 	void jcross_sound_portmap(address_map &map);
272 	void madcrash_cpuA_map(address_map &map);
273 	void madcrash_cpuB_map(address_map &map);
274 	void madcrush_cpuA_map(address_map &map);
275 	void madcrush_cpuB_map(address_map &map);
276 	void marvins_cpuA_map(address_map &map);
277 	void marvins_cpuB_map(address_map &map);
278 	void marvins_sound_map(address_map &map);
279 	void marvins_sound_portmap(address_map &map);
280 	void sgladiat_cpuA_map(address_map &map);
281 	void sgladiat_cpuB_map(address_map &map);
282 	void tdfever_cpuA_map(address_map &map);
283 	void tdfever_cpuB_map(address_map &map);
284 	void tnk3_YM3526_sound_map(address_map &map);
285 	void tnk3_cpuA_map(address_map &map);
286 	void tnk3_cpuB_map(address_map &map);
287 };
288 
289 #endif // MAME_INCLUDES_SNK_H
290