1 // license:BSD-3-Clause
2 // copyright-holders:Quench, Yochizo, David Haywood
3 #ifndef MAME_INCLUDES_TOAPLAN2_H
4 #define MAME_INCLUDES_TOAPLAN2_H
5 
6 #pragma once
7 
8 #include "cpu/m68000/m68000.h"
9 #include "machine/bankdev.h"
10 #include "machine/eepromser.h"
11 #include "machine/gen_latch.h"
12 #include "machine/ticket.h"
13 #include "machine/upd4992.h"
14 #include "video/gp9001.h"
15 #include "sound/okim6295.h"
16 #include "emupal.h"
17 #include "screen.h"
18 #include "tilemap.h"
19 
20 /**************** Machine stuff ******************/
21 
22 class toaplan2_state : public driver_device
23 {
24 public:
toaplan2_state(const machine_config & mconfig,device_type type,const char * tag)25 	toaplan2_state(const machine_config &mconfig, device_type type, const char *tag)
26 		: driver_device(mconfig, type, tag)
27 		, m_shared_ram(*this, "shared_ram")
28 		, m_tx_videoram(*this, "tx_videoram")
29 		, m_tx_lineselect(*this, "tx_lineselect")
30 		, m_tx_linescroll(*this, "tx_linescroll")
31 		, m_tx_gfxram(*this, "tx_gfxram")
32 		, m_mainram(*this, "mainram")
33 		, m_maincpu(*this, "maincpu")
34 		, m_audiocpu(*this, "audiocpu")
35 		, m_vdp(*this, "gp9001_%u", 0U)
36 		, m_oki(*this, "oki%u", 1U)
37 		, m_eeprom(*this, "eeprom")
38 		, m_rtc(*this, "rtc")
39 		, m_gfxdecode(*this, "gfxdecode")
40 		, m_screen(*this, "screen")
41 		, m_palette(*this, "palette")
42 		, m_soundlatch(*this, "soundlatch")
43 		, m_soundlatch2(*this, "soundlatch2")
44 		, m_hopper(*this, "hopper")
45 		, m_dma_space(*this, "dma_space")
46 		, m_z80_rom(*this, "audiocpu")
47 		, m_oki_rom(*this, "oki%u", 1U)
48 		, m_audiobank(*this, "audiobank")
49 		, m_okibank(*this, "okibank")
50 		, m_raizing_okibank{{*this, "raizing_okibank0_%u", 0U},
51 							{*this, "raizing_okibank1_%u", 0U}}
52 		, m_io_pad(*this, "PAD%u", 1U)
53 		, m_eepromout(*this, "EEPROMOUT")
54 	{ }
55 
56 	void dogyuun(machine_config &config);
57 	void othldrby(machine_config &config);
58 	void snowbro2(machine_config &config);
59 	void bgareggabl(machine_config &config);
60 	void pwrkick(machine_config &config);
61 	void mahoudai(machine_config &config);
62 	void tekipaki(machine_config &config);
63 	void bbakraid(machine_config &config);
64 	void fixeightbl(machine_config &config);
65 	void fixeight(machine_config &config);
66 	void ghox(machine_config &config);
67 	void bgaregga(machine_config &config);
68 	void batrider(machine_config &config);
69 	void shippumd(machine_config &config);
70 	void kbash(machine_config &config);
71 	void pipibibs(machine_config &config);
72 	void pipibibsbl(machine_config &config);
73 	void batsugun(machine_config &config);
74 	void enmadaio(machine_config &config);
75 	void truxton2(machine_config &config);
76 	void vfive(machine_config &config);
77 	void kbash2(machine_config &config);
78 	void nprobowl(machine_config &config);
79 
80 	void init_bbakraid();
81 	void init_pipibibsbl();
82 	void init_dogyuun();
83 	void init_fixeight();
84 	void init_bgaregga();
85 	void init_fixeightbl();
86 	void init_vfive();
87 	void init_batrider();
88 	void init_enmadaio();
89 
90 	DECLARE_READ_LINE_MEMBER(c2map_r);
91 
92 protected:
93 	virtual void device_post_load() override;
94 
95 private:
96 	// We encode priority with colour in the tilemaps, so need a larger palette
97 	static constexpr unsigned T2PALETTE_LENGTH = 0x10000;
98 
99 	optional_shared_ptr<u8> m_shared_ram; // 8 bit RAM shared between 68K and sound CPU
100 	optional_shared_ptr<u16> m_tx_videoram;
101 	optional_shared_ptr<u16> m_tx_lineselect;
102 	optional_shared_ptr<u16> m_tx_linescroll;
103 	optional_shared_ptr<u16> m_tx_gfxram;
104 	optional_shared_ptr<u16> m_mainram;
105 
106 	required_device<m68000_base_device> m_maincpu;
107 	optional_device<cpu_device> m_audiocpu;
108 	optional_device_array<gp9001vdp_device, 2> m_vdp;
109 	optional_device_array<okim6295_device, 2> m_oki;
110 	optional_device<eeprom_serial_93cxx_device> m_eeprom;
111 	optional_device<upd4992_device> m_rtc;
112 	optional_device<gfxdecode_device> m_gfxdecode;
113 	required_device<screen_device> m_screen;
114 	required_device<palette_device> m_palette;
115 	optional_device<generic_latch_8_device> m_soundlatch; // tekipaki, batrider, bgaregga, batsugun
116 	optional_device<generic_latch_8_device> m_soundlatch2;
117 	optional_device<ticket_dispenser_device> m_hopper;
118 
119 	optional_device<address_map_bank_device> m_dma_space;
120 
121 	optional_region_ptr<u8> m_z80_rom;
122 	optional_region_ptr_array<u8, 2> m_oki_rom;
123 	optional_memory_bank m_audiobank;
124 	optional_memory_bank m_okibank;
125 	optional_memory_bank_array<8> m_raizing_okibank[2];
126 
127 	optional_ioport_array<2> m_io_pad;
128 	optional_ioport m_eepromout;
129 
130 	s8 m_old_p1_paddle_h; /* For Ghox */
131 	s8 m_old_p2_paddle_h;
132 	u8 m_sound_reset_bit; /* 0x20 for dogyuun/batsugun, 0x10 for vfive, 0x08 for fixeight */
133 	u8 m_sndirq_line;        /* IRQ4 for batrider, IRQ2 for bbakraid */
134 	u8 m_z80_busreq;
135 	u16 m_gfxrom_bank[8];       /* Batrider object bank */
136 
137 	bitmap_ind8 m_custom_priority_bitmap;
138 	bitmap_ind16 m_secondary_render_bitmap;
139 
140 	tilemap_t *m_tx_tilemap;    /* Tilemap for extra-text-layer */
141 	u16 video_count_r();
142 	void coin_w(u8 data);
143 	void coin_sound_reset_w(u8 data);
144 	void shippumd_coin_w(u8 data);
145 	u8 shared_ram_r(offs_t offset);
146 	void shared_ram_w(offs_t offset, u8 data);
147 	u16 ghox_p1_h_analog_r();
148 	u16 ghox_p2_h_analog_r();
149 	void sound_reset_w(u8 data);
150 	void fixeightbl_oki_bankswitch_w(u8 data);
151 	void raizing_z80_bankswitch_w(u8 data);
152 	void raizing_oki_bankswitch_w(offs_t offset, u8 data);
153 	u8 bgaregga_E01D_r();
154 	u16 batrider_z80_busack_r();
155 	void batrider_z80_busreq_w(u8 data);
156 	u16 batrider_z80rom_r(offs_t offset);
157 	void batrider_soundlatch_w(u8 data);
158 	void batrider_soundlatch2_w(u8 data);
159 	void batrider_unknown_sound_w(u16 data);
160 	void batrider_clear_sndirq_w(u16 data);
161 	void batrider_sndirq_w(u8 data);
162 	void batrider_clear_nmi_w(u8 data);
163 	u16 bbakraid_eeprom_r();
164 	void bbakraid_eeprom_w(u8 data);
165 	void tx_videoram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
166 	void tx_linescroll_w(offs_t offset, u16 data, u16 mem_mask = ~0);
167 	void tx_gfxram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
168 	void batrider_tx_gfxram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
169 	void batrider_textdata_dma_w(u16 data);
170 	void batrider_pal_text_dma_w(u16 data);
171 	void batrider_objectbank_w(offs_t offset, u8 data);
172 	void batrider_bank_cb(u8 layer, u32 &code);
173 
174 	template<int Chip> void oki_bankswitch_w(u8 data);
175 	void enmadaio_oki_bank_w(offs_t offset, u16 data, u16 mem_mask = ~0);
176 	void install_raizing_okibank(int chip);
177 
178 	TILE_GET_INFO_MEMBER(get_text_tile_info);
179 	virtual void machine_start() override;
180 	DECLARE_MACHINE_RESET(toaplan2);
181 	DECLARE_MACHINE_RESET(bgaregga);
182 	DECLARE_VIDEO_START(toaplan2);
183 	DECLARE_MACHINE_RESET(ghox);
184 	DECLARE_VIDEO_START(truxton2);
185 	DECLARE_VIDEO_START(fixeightbl);
186 	DECLARE_VIDEO_START(bgaregga);
187 	DECLARE_VIDEO_START(bgareggabl);
188 	DECLARE_VIDEO_START(batrider);
189 
190 	// Teki Paki sound
191 	u8 tekipaki_cmdavailable_r();
192 
193 	u32 screen_update_toaplan2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
194 	u32 screen_update_dogyuun(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
195 	u32 screen_update_batsugun(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
196 	u32 screen_update_truxton2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
197 	u32 screen_update_bootleg(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
198 	DECLARE_WRITE_LINE_MEMBER(screen_vblank);
199 	void cpu_space_fixeightbl_map(address_map &map);
200 	void cpu_space_pipibibsbl_map(address_map &map);
201 	INTERRUPT_GEN_MEMBER(bbakraid_snd_interrupt);
202 	void create_tx_tilemap(int dx = 0, int dx_flipped = 0);
203 
204 	void pwrkick_coin_w(u8 data);
205 	void pwrkick_coin_lockout_w(u8 data);
206 
207 	DECLARE_WRITE_LINE_MEMBER(toaplan2_reset);
208 
209 	void batrider_68k_mem(address_map &map);
210 	void batrider_dma_mem(address_map &map);
211 	void batrider_sound_z80_mem(address_map &map);
212 	void batrider_sound_z80_port(address_map &map);
213 	void batsugun_68k_mem(address_map &map);
214 	void bbakraid_68k_mem(address_map &map);
215 	void bbakraid_sound_z80_mem(address_map &map);
216 	void bbakraid_sound_z80_port(address_map &map);
217 	void bgaregga_68k_mem(address_map &map);
218 	void bgaregga_sound_z80_mem(address_map &map);
219 	void dogyuun_68k_mem(address_map &map);
220 	void enmadaio_68k_mem(address_map &map);
221 	void enmadaio_oki(address_map &map);
222 	void fixeight_68k_mem(address_map &map);
223 	void fixeight_v25_mem(address_map &map);
224 	void fixeightbl_68k_mem(address_map &map);
225 	void fixeightbl_oki(address_map &map);
226 	void ghox_68k_mem(address_map &map);
227 	void ghox_hd647180_mem_map(address_map &map);
228 	void hd647180_io_map(address_map &map);
229 	void kbash2_68k_mem(address_map &map);
230 	void kbash_68k_mem(address_map &map);
231 	void kbash_v25_mem(address_map &map);
232 	void mahoudai_68k_mem(address_map &map);
233 	void nprobowl_68k_mem(address_map &map);
234 	void othldrby_68k_mem(address_map &map);
235 	void pipibibi_bootleg_68k_mem(address_map &map);
236 	void pipibibs_68k_mem(address_map &map);
237 	void pipibibs_sound_z80_mem(address_map &map);
238 	void pwrkick_68k_mem(address_map &map);
239 	template<unsigned Chip> void raizing_oki(address_map &map);
240 	void raizing_sound_z80_mem(address_map &map);
241 	void shippumd_68k_mem(address_map &map);
242 	void snowbro2_68k_mem(address_map &map);
243 	void tekipaki_68k_mem(address_map &map);
244 	void truxton2_68k_mem(address_map &map);
245 	void v25_mem(address_map &map);
246 	void vfive_68k_mem(address_map &map);
247 	void vfive_v25_mem(address_map &map);
248 };
249 
250 #endif // MAME_INCLUDES_TOAPLAN2_H
251