1 // license:BSD-3-Clause
2 // copyright-holders:Nicola Salmoria
3 #ifndef MAME_INCLUDES_TMNT_H
4 #define MAME_INCLUDES_TMNT_H
5 
6 #pragma once
7 
8 #include "sound/samples.h"
9 #include "sound/upd7759.h"
10 #include "sound/k007232.h"
11 #include "sound/k053260.h"
12 #include "sound/k054539.h"
13 #include "video/k053244_k053245.h"
14 #include "video/k052109.h"
15 #include "video/k051960.h"
16 #include "video/k053251.h"
17 #include "video/k053936.h"
18 #include "video/k054000.h"
19 #include "video/konami_helper.h"
20 #include "emupal.h"
21 #include "tilemap.h"
22 
23 class tmnt_state : public driver_device
24 {
25 public:
tmnt_state(const machine_config & mconfig,device_type type,const char * tag)26 	tmnt_state(const machine_config &mconfig, device_type type, const char *tag) :
27 		driver_device(mconfig, type, tag),
28 		m_spriteram(*this, "spriteram"),
29 		m_tmnt2_rom(*this, "tmnt2_rom"),
30 		m_sunset_104000(*this, "sunset_104000"),
31 		m_tmnt2_1c0800(*this, "tmnt2_1c0800"),
32 		m_maincpu(*this, "maincpu"),
33 		m_audiocpu(*this, "audiocpu"),
34 		m_k007232(*this, "k007232"),
35 		m_k053260(*this, "k053260"),
36 		m_k054539(*this, "k054539"),
37 		m_k052109(*this, "k052109"),
38 		m_k051960(*this, "k051960"),
39 		m_k053245(*this, "k053245"),
40 		m_k053251(*this, "k053251"),
41 		m_k053936(*this, "k053936"),
42 		m_k054000(*this, "k054000"),
43 		m_upd7759(*this, "upd"),
44 		m_samples(*this, "samples"),
45 		m_gfxdecode(*this, "gfxdecode"),
46 		m_palette(*this, "palette")
47 	{ }
48 
49 	void cuebrick(machine_config &config);
50 	void blswhstl(machine_config &config);
51 	void ssriders(machine_config &config);
52 	void tmnt2(machine_config &config);
53 	void lgtnfght(machine_config &config);
54 	void thndrx2(machine_config &config);
55 	void sunsetbl(machine_config &config);
56 	void tmnt(machine_config &config);
57 	void mia(machine_config &config);
58 	void punkshot(machine_config &config);
59 
60 	void init_mia();
61 	void init_tmnt();
62 	void init_cuebrick();
63 
64 protected:
65 	virtual void machine_start() override;
66 
67 	enum
68 	{
69 		TIMER_NMI
70 	};
71 
72 	/* memory pointers */
73 	optional_shared_ptr<uint16_t> m_spriteram;
74 	optional_shared_ptr<uint16_t> m_tmnt2_rom;
75 	optional_shared_ptr<uint16_t> m_sunset_104000;
76 	optional_shared_ptr<uint16_t> m_tmnt2_1c0800;
77 
78 	/* video-related */
79 	int        m_layer_colorbase[3];
80 	int        m_sprite_colorbase;
81 	int        m_layerpri[3];
82 	int        m_sorted_layer[3];   // this might not be necessary, but tmnt2 uses it in a strange way...
83 
84 	tilemap_t  *m_roz_tilemap;
85 	int        m_glfgreat_pixel;
86 	int        m_blswhstl_rombank;
87 	int        m_tmnt_priorityflag;
88 	int        m_lastdim;
89 	int        m_lasten;
90 	int        m_dim_c;
91 	int        m_dim_v; /* lgtnfght, ssriders, tmnt2 only */
92 
93 	/* misc */
94 	int        m_tmnt_soundlatch;
95 	int        m_toggle;
96 	int        m_last;
97 	uint16_t     m_cuebrick_nvram[0x400 * 0x20 / 2];  // 32k paged in a 1k window
98 
99 	/* devices */
100 	required_device<cpu_device> m_maincpu;
101 	optional_device<cpu_device> m_audiocpu;
102 	optional_device<k007232_device> m_k007232;
103 	optional_device<k053260_device> m_k053260;
104 	optional_device<k054539_device> m_k054539;
105 	required_device<k052109_device> m_k052109;
106 	optional_device<k051960_device> m_k051960;
107 	optional_device<k05324x_device> m_k053245;
108 	optional_device<k053251_device> m_k053251;
109 	optional_device<k053936_device> m_k053936;
110 	optional_device<k054000_device> m_k054000;
111 	optional_device<upd7759_device> m_upd7759;
112 	optional_device<samples_device> m_samples;
113 	optional_device<gfxdecode_device> m_gfxdecode;
114 	required_device<palette_device> m_palette;
115 
116 	/* memory buffers */
117 	int16_t      m_sampledata[0x40000];
118 
119 	uint8_t      m_irq5_mask;
120 	uint16_t k052109_word_noA12_r(offs_t offset);
121 	void k052109_word_noA12_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
122 	void punkshot_k052109_word_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
123 	void punkshot_k052109_word_noA12_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
124 	uint16_t k053245_scattered_word_r(offs_t offset);
125 	void k053245_scattered_word_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
126 	uint16_t k053244_word_noA1_r(offs_t offset);
127 	void k053244_word_noA1_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
128 	uint8_t tmnt_sres_r();
129 	void tmnt_sres_w(uint8_t data);
130 	void sound_arm_nmi_w(uint8_t data);
131 	uint16_t punkshot_kludge_r();
132 	uint16_t ssriders_protection_r(address_space &space);
133 	void ssriders_protection_w(address_space &space, offs_t offset, uint16_t data);
134 	uint16_t blswhstl_coin_r();
135 	uint16_t ssriders_eeprom_r();
136 	uint16_t sunsetbl_eeprom_r();
137 	void blswhstl_eeprom_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
138 	uint16_t thndrx2_eeprom_r();
139 	void thndrx2_eeprom_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
140 	void cuebrick_nvbank_w(uint8_t data);
141 	void ssriders_soundkludge_w(uint16_t data);
142 	void tmnt2_1c0800_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
143 	void tmnt_0a0000_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
144 	void punkshot_0a0020_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
145 	void lgtnfght_0a0018_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
146 	void blswhstl_700300_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
147 	void ssriders_eeprom_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
148 	void ssriders_1c0300_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
149 	void tmnt_priority_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
150 	void tmnt_upd_start_w(uint8_t data);
151 	uint8_t tmnt_upd_busy_r();
152 
153 	DECLARE_MACHINE_RESET(common);
154 	DECLARE_VIDEO_START(cuebrick);
155 	DECLARE_VIDEO_START(mia);
156 	DECLARE_MACHINE_RESET(tmnt);
157 	DECLARE_VIDEO_START(tmnt);
158 	DECLARE_VIDEO_START(lgtnfght);
159 	DECLARE_VIDEO_START(blswhstl);
160 	uint32_t screen_update_mia(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
161 	uint32_t screen_update_tmnt(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
162 	uint32_t screen_update_punkshot(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
163 	uint32_t screen_update_lgtnfght(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
164 	uint32_t screen_update_glfgreat(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
165 	uint32_t screen_update_tmnt2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
166 	uint32_t screen_update_thndrx2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
167 	DECLARE_WRITE_LINE_MEMBER(screen_vblank_blswhstl);
168 	INTERRUPT_GEN_MEMBER(tmnt_interrupt);
169 	INTERRUPT_GEN_MEMBER(punkshot_interrupt);
170 	INTERRUPT_GEN_MEMBER(lgtnfght_interrupt);
171 	inline uint32_t tmnt2_get_word( uint32_t addr );
172 	void tmnt2_put_word( uint32_t addr, uint16_t data );
173 	void volume_callback(uint8_t data);
174 	K051960_CB_MEMBER(mia_sprite_callback);
175 	K051960_CB_MEMBER(tmnt_sprite_callback);
176 	K051960_CB_MEMBER(punkshot_sprite_callback);
177 	K051960_CB_MEMBER(thndrx2_sprite_callback);
178 	K05324X_CB_MEMBER(lgtnfght_sprite_callback);
179 	K05324X_CB_MEMBER(blswhstl_sprite_callback);
180 	K052109_CB_MEMBER(mia_tile_callback);
181 	K052109_CB_MEMBER(cuebrick_tile_callback);
182 	K052109_CB_MEMBER(tmnt_tile_callback);
183 	K052109_CB_MEMBER(ssbl_tile_callback);
184 	K052109_CB_MEMBER(blswhstl_tile_callback);
185 	SAMPLES_START_CB_MEMBER(tmnt_decode_sample);
186 
187 	void blswhstl_main_map(address_map &map);
188 	void cuebrick_main_map(address_map &map);
189 	void lgtnfght_audio_map(address_map &map);
190 	void lgtnfght_main_map(address_map &map);
191 	void mia_audio_map(address_map &map);
192 	void mia_main_map(address_map &map);
193 	void punkshot_audio_map(address_map &map);
194 	void punkshot_main_map(address_map &map);
195 	void ssriders_audio_map(address_map &map);
196 	void ssriders_main_map(address_map &map);
197 	void sunsetbl_main_map(address_map &map);
198 	void thndrx2_audio_map(address_map &map);
199 	void thndrx2_main_map(address_map &map);
200 	void tmnt2_main_map(address_map &map);
201 	void tmnt_audio_map(address_map &map);
202 	void tmnt_main_map(address_map &map);
203 
204 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
205 };
206 
207 class glfgreat_state : public tmnt_state
208 {
209 public:
glfgreat_state(const machine_config & mconfig,device_type type,const char * tag)210 	glfgreat_state(const machine_config &mconfig, device_type type, const char *tag) :
211 		tmnt_state(mconfig, type, tag),
212 		m_analog_controller(*this, "CONTROL%c", 'A')
213 	{ }
214 
215 	void glfgreat(machine_config &config);
216 
217 private:
218 	void k053251_glfgreat_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
219 	uint8_t controller_r();
220 	uint16_t glfgreat_rom_r(offs_t offset);
221 	void glfgreat_122000_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
222 	uint16_t glfgreat_ball_r();
223 	void glfgreat_sound_w(offs_t offset, uint8_t data);
224 
225 	TILE_GET_INFO_MEMBER(glfgreat_get_roz_tile_info);
226 	DECLARE_VIDEO_START(glfgreat);
227 
228 	void glfgreat_audio_map(address_map &map);
229 	void glfgreat_main_map(address_map &map);
230 
231 	required_ioport_array<4> m_analog_controller;
232 
233 	uint8_t    m_controller_select;
234 	int        m_roz_rom_bank;
235 	int        m_roz_char_bank;
236 	int        m_roz_rom_mode;
237 };
238 
239 class prmrsocr_state : public tmnt_state
240 {
241 public:
prmrsocr_state(const machine_config & mconfig,device_type type,const char * tag)242 	prmrsocr_state(const machine_config &mconfig, device_type type, const char *tag) :
243 		tmnt_state(mconfig, type, tag)
244 	{ }
245 
246 	void prmrsocr(machine_config &config);
247 
248 protected:
249 	virtual void machine_start() override;
250 
251 private:
252 	void prmrsocr_sound_irq_w(uint16_t data);
253 	void prmrsocr_audio_bankswitch_w(uint8_t data);
254 	void prmrsocr_eeprom_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
255 	void prmrsocr_122000_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
256 	uint16_t prmrsocr_rom_r(offs_t offset);
257 
258 	TILE_GET_INFO_MEMBER(prmrsocr_get_roz_tile_info);
259 	DECLARE_VIDEO_START(prmrsocr);
260 	K05324X_CB_MEMBER(prmrsocr_sprite_callback);
261 
262 	void prmrsocr_audio_map(address_map &map);
263 	void prmrsocr_main_map(address_map &map);
264 
265 	int        m_sprite_bank;
266 	int        m_roz_char_bank;
267 };
268 
269 #endif // MAME_INCLUDES_TMNT_H
270