1 // license:BSD-3-Clause
2 // copyright-holders:Darren Olafson, Quench
3 /***************************************************************************
4                 ToaPlan game hardware from 1988-1991
5                 ------------------------------------
6 ****************************************************************************/
7 #ifndef MAME_INCLUDES_TOAPLAN1_H
8 #define MAME_INCLUDES_TOAPLAN1_H
9 
10 #pragma once
11 
12 #include "cpu/m68000/m68000.h"
13 #include "cpu/tms32010/tms32010.h"
14 #include "sound/3812intf.h"
15 #include "video/toaplan_scu.h"
16 #include "emupal.h"
17 #include "screen.h"
18 #include "tilemap.h"
19 
20 class toaplan1_state : public driver_device
21 {
22 public:
toaplan1_state(const machine_config & mconfig,device_type type,const char * tag)23 	toaplan1_state(const machine_config &mconfig, device_type type, const char *tag) :
24 		driver_device(mconfig, type, tag),
25 		m_bgpaletteram(*this, "bgpalette"),
26 		m_fgpaletteram(*this, "fgpalette"),
27 		m_sharedram(*this, "sharedram"),
28 		m_dswb_io(*this, "DSWB"),
29 		m_tjump_io(*this, "TJUMP"),
30 		m_spriteram(*this, "spriteram"),
31 		m_maincpu(*this, "maincpu"),
32 		m_audiocpu(*this, "audiocpu"),
33 		m_ymsnd(*this, "ymsnd"),
34 		m_gfxdecode(*this, "gfxdecode"),
35 		m_screen(*this, "screen"),
36 		m_palette(*this, "palette")
37 	{ }
38 
39 	void truxton(machine_config &config);
40 	void outzone(machine_config &config);
41 	void vimana(machine_config &config);
42 	void outzonecv(machine_config &config);
43 	void hellfire(machine_config &config);
44 	void zerowing(machine_config &config);
45 
46 protected:
47 	virtual void machine_start() override;
48 	virtual void machine_reset() override;
49 	virtual void video_start() override;
50 
51 	required_shared_ptr<u16> m_bgpaletteram;
52 	required_shared_ptr<u16> m_fgpaletteram;
53 
54 	optional_shared_ptr<u8> m_sharedram;
55 
56 	optional_ioport m_dswb_io;
57 	optional_ioport m_tjump_io;
58 
59 	int m_intenable;
60 
61 	std::unique_ptr<u16[]> m_tilevram[4];
62 	/*
63 	std::unique_ptr<u16[]> m_tilevram[3];   //  ||  Drawn in this order
64 	std::unique_ptr<u16[]> m_tilevram[2];   //  ||
65 	std::unique_ptr<u16[]> m_tilevram[1];   // \||/
66 	std::unique_ptr<u16[]> m_tilevram[0];   //  \/
67 	*/
68 
69 	optional_shared_ptr<u16> m_spriteram;
70 	std::unique_ptr<u16[]> m_buffered_spriteram;
71 	std::unique_ptr<u16[]> m_spritesizeram;
72 	std::unique_ptr<u16[]> m_buffered_spritesizeram;
73 
74 	s32 m_bcu_flipscreen;     /* Tile   controller flip flag */
75 	s32 m_fcu_flipscreen;     /* Sprite controller flip flag */
76 
77 	s32 m_pf_voffs;
78 	s32 m_spriteram_offs;
79 
80 	s32 m_scrollx[4];
81 	s32 m_scrolly[4];
82 
83 #ifdef MAME_DEBUG
84 	int m_display_pf[4];
85 	int m_displog;
86 #endif
87 
88 	s32 m_tiles_offsetx;
89 	s32 m_tiles_offsety;
90 
91 	tilemap_t *m_tilemap[4];
92 
93 	void intenable_w(u8 data);
94 	u8 shared_r(offs_t offset);
95 	void shared_w(offs_t offset, u8 data);
96 	void reset_sound_w(u8 data);
97 	void coin_w(u8 data);
98 
99 	u16 frame_done_r();
100 	void tile_offsets_w(offs_t offset, u16 data, u16 mem_mask = ~0);
101 	void bcu_flipscreen_w(u8 data);
102 	void fcu_flipscreen_w(u8 data);
103 	u16 spriteram_offs_r();
104 	void spriteram_offs_w(offs_t offset, u16 data, u16 mem_mask = ~0);
105 	void bgpalette_w(offs_t offset, u16 data, u16 mem_mask = ~0);
106 	void fgpalette_w(offs_t offset, u16 data, u16 mem_mask = ~0);
107 	u16 spriteram_r();
108 	void spriteram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
109 	u16 spritesizeram_r();
110 	void spritesizeram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
111 	void bcu_control_w(offs_t offset, u16 data);
112 	u16 tileram_offs_r();
113 	void tileram_offs_w(offs_t offset, u16 data, u16 mem_mask = ~0);
114 	u16 tileram_r(offs_t offset);
115 	void tileram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
116 	u16 scroll_regs_r(offs_t offset);
117 	void scroll_regs_w(offs_t offset, u16 data, u16 mem_mask = ~0);
118 
119 	u8 vimana_dswb_invert_r();
120 	u8 vimana_tjump_invert_r();
121 
122 	template<unsigned Layer> TILE_GET_INFO_MEMBER(get_tile_info);
123 
124 	DECLARE_MACHINE_RESET(zerowing);
125 	u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
126 
127 	DECLARE_WRITE_LINE_MEMBER(screen_vblank);
128 	void interrupt();
129 
130 	void create_tilemaps();
131 	void vram_alloc();
132 	void spritevram_alloc();
133 	void set_scrolls();
134 	void register_common();
135 	void log_vram();
136 	void draw_sprites(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect );
137 	void draw_sprite_custom(screen_device &screen, bitmap_rgb32 &dest_bmp, const rectangle &clip, gfx_element *gfx,
138 		u32 code, u32 color, int flipx, int flipy, int sx, int sy,
139 		int priority);
140 	void reset_sound();
141 	DECLARE_WRITE_LINE_MEMBER(reset_callback);
142 	required_device<m68000_device> m_maincpu;
143 	required_device<cpu_device> m_audiocpu;
144 	required_device<ym3812_device> m_ymsnd;
145 	required_device<gfxdecode_device> m_gfxdecode;
146 	required_device<screen_device> m_screen;
147 	required_device<palette_device> m_palette;
148 
149 	void hellfire_main_map(address_map &map);
150 	void hellfire_sound_io_map(address_map &map);
151 	void outzone_main_map(address_map &map);
152 	void outzone_sound_io_map(address_map &map);
153 	void outzonecv_main_map(address_map &map);
154 	void sound_map(address_map &map);
155 	void truxton_main_map(address_map &map);
156 	void truxton_sound_io_map(address_map &map);
157 	void vimana_hd647180_io_map(address_map &map);
158 	void vimana_hd647180_mem_map(address_map &map);
159 	void vimana_main_map(address_map &map);
160 	void zerowing_main_map(address_map &map);
161 	void zerowing_sound_io_map(address_map &map);
162 };
163 
164 class toaplan1_rallybik_state : public toaplan1_state
165 {
166 public:
toaplan1_rallybik_state(const machine_config & mconfig,device_type type,const char * tag)167 	toaplan1_rallybik_state(const machine_config &mconfig, device_type type, const char *tag) :
168 		toaplan1_state(mconfig, type, tag),
169 		m_spritegen(*this, "scu")
170 	{
171 	}
172 
173 	void rallybik(machine_config &config);
174 
175 protected:
176 	virtual void video_start() override;
177 
178 private:
179 	DECLARE_WRITE_LINE_MEMBER(coin_counter_1_w);
180 	DECLARE_WRITE_LINE_MEMBER(coin_counter_2_w);
181 	DECLARE_WRITE_LINE_MEMBER(coin_lockout_1_w);
182 	DECLARE_WRITE_LINE_MEMBER(coin_lockout_2_w);
183 	u16 tileram_r(offs_t offset);
184 	u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
185 	DECLARE_WRITE_LINE_MEMBER(screen_vblank);
186 
187 	required_device<toaplan_scu_device> m_spritegen;
188 	void rallybik_main_map(address_map &map);
189 	void rallybik_sound_io_map(address_map &map);
190 };
191 
192 class toaplan1_demonwld_state : public toaplan1_state
193 {
194 public:
toaplan1_demonwld_state(const machine_config & mconfig,device_type type,const char * tag)195 	toaplan1_demonwld_state(const machine_config &mconfig, device_type type, const char *tag) :
196 		toaplan1_state(mconfig, type, tag),
197 		m_dsp(*this, "dsp")
198 	{
199 	}
200 
201 	void demonwld(machine_config &config);
202 
203 protected:
204 	virtual void device_post_load() override;
205 	virtual void machine_start() override;
206 	virtual void machine_reset() override;
207 
208 private:
209 	/* Demon world */
210 	int m_dsp_on;
211 	int m_dsp_bio;
212 	int m_dsp_execute;
213 	u32 m_dsp_addr_w;
214 	u32 m_main_ram_seg;
215 
216 	void dsp_addrsel_w(u16 data);
217 	u16 dsp_r();
218 	void dsp_w(u16 data);
219 	void dsp_bio_w(u16 data);
220 	DECLARE_READ_LINE_MEMBER(bio_r);
221 	void dsp_ctrl_w(u8 data);
222 	void dsp_int_w(int enable);
223 
224 	required_device<tms32010_device> m_dsp;
225 	void dsp_io_map(address_map &map);
226 	void dsp_program_map(address_map &map);
227 	void main_map(address_map &map);
228 	void sound_io_map(address_map &map);
229 };
230 
231 class toaplan1_samesame_state : public toaplan1_state
232 {
233 public:
toaplan1_samesame_state(const machine_config & mconfig,device_type type,const char * tag)234 	toaplan1_samesame_state(const machine_config &mconfig, device_type type, const char *tag) :
235 		toaplan1_state(mconfig, type, tag)
236 	{
237 	}
238 
239 	void samesame(machine_config &config);
240 
241 protected:
242 	virtual void machine_start() override;
243 
244 private:
245 	// Fire Shark sound
246 	u8 m_to_mcu;
247 	u8 m_cmdavailable;
248 
249 	void mcu_w(u8 data);
250 	u8 soundlatch_r();
251 	void sound_done_w(u8 data);
252 	u8 cmdavailable_r();
253 	u8 port_6_word_r();
254 
255 	DECLARE_WRITE_LINE_MEMBER(screen_vblank);
256 
257 	void hd647180_io_map(address_map &map);
258 	void main_map(address_map &map);
259 };
260 
261 #endif // MAME_INCLUDES_TOAPLAN1_H
262