1 // license:BSD-3-Clause
2 // copyright-holders:Philip Bennett,Carlos A. Lozano, Rob Rosenbrock, Phil Stroffolino, Ernesto Corvi, David Haywood, R. Belmont
3 /*************************************************************************
4 
5     Double Dragon & Double Dragon II (but also China Gate)
6 
7 *************************************************************************/
8 #ifndef MAME_INCLUDES_DDRAGON_H
9 #define MAME_INCLUDES_DDRAGON_H
10 
11 #pragma once
12 
13 #include "cpu/m6805/m68705.h"
14 #include "machine/bankdev.h"
15 #include "machine/gen_latch.h"
16 #include "machine/timer.h"
17 #include "sound/msm5205.h"
18 #include "emupal.h"
19 #include "screen.h"
20 #include "tilemap.h"
21 
22 
23 class ddragon_state : public driver_device
24 {
25 public:
ddragon_state(const machine_config & mconfig,device_type type,const char * tag)26 	ddragon_state(const machine_config &mconfig, device_type type, const char *tag)
27 		: driver_device(mconfig, type, tag)
28 		, m_maincpu(*this, "maincpu")
29 		, m_soundcpu(*this, "soundcpu")
30 		, m_subcpu(*this, "sub")
31 		, m_screen(*this, "screen")
32 		, m_palette(*this, "palette")
33 		, m_gfxdecode(*this, "gfxdecode")
34 		, m_soundlatch(*this, "soundlatch")
35 		, m_mainbank(*this, "mainbank")
36 		, m_rambase(*this, "rambase")
37 		, m_bgvideoram(*this, "bgvideoram")
38 		, m_fgvideoram(*this, "fgvideoram")
39 		, m_comram(*this, "comram")
40 		, m_spriteram(*this, "spriteram")
41 		, m_scrollx_lo(*this, "scrollx_lo")
42 		, m_scrolly_lo(*this, "scrolly_lo")
43 		, m_adpcm(*this, "adpcm%u", 1U)
44 		, m_adpcm_rom(*this, "adpcm%u", 1U)
45 	{
46 	}
47 
48 	void ddragon(machine_config &config);
49 	void ddragon6809(machine_config &config);
50 	void ddragonb(machine_config &config);
51 	void ddragonba(machine_config &config);
52 	void ddragon2(machine_config &config);
53 
54 	void init_ddragon2();
55 	void init_ddragon();
56 	void init_ddragon6809();
57 
58 	DECLARE_READ_LINE_MEMBER(subcpu_bus_free_r);
59 
60 protected:
61 	required_device<cpu_device> m_maincpu;
62 	required_device<cpu_device> m_soundcpu;
63 	optional_device<cpu_device> m_subcpu;
64 	required_device<screen_device> m_screen;
65 	required_device<palette_device> m_palette;
66 	required_device<gfxdecode_device> m_gfxdecode;
67 	required_device<generic_latch_8_device> m_soundlatch;
68 
69 	optional_memory_bank m_mainbank;
70 	optional_shared_ptr<uint8_t> m_rambase;
71 
72 	/* video-related */
73 	tilemap_t      *m_fg_tilemap;
74 	tilemap_t      *m_bg_tilemap;
75 	uint8_t        m_technos_video_hw;
76 	uint8_t        m_scrollx_hi;
77 	uint8_t        m_scrolly_hi;
78 
79 	/* misc */
80 	uint8_t        m_ddragon_sub_port;
81 	uint8_t        m_sprite_irq;
82 	uint8_t        m_adpcm_sound_irq;
83 	uint32_t       m_adpcm_pos[2];
84 	uint32_t       m_adpcm_end[2];
85 	bool           m_adpcm_idle[2];
86 	int            m_adpcm_data[2];
87 
88 	/* for Sai Yu Gou Ma Roku */
89 	int            m_adpcm_addr;
90 	int            m_i8748_P1;
91 	int            m_i8748_P2;
92 	int            m_pcm_shift;
93 	int            m_pcm_nibble;
94 	int            m_mcu_command;
95 #if 0
96 	int            m_m5205_clk;
97 #endif
98 
99 	void ddragon_bgvideoram_w(offs_t offset, uint8_t data);
100 	void ddragon_fgvideoram_w(offs_t offset, uint8_t data);
101 
102 	TILEMAP_MAPPER_MEMBER(background_scan);
103 
104 	TILE_GET_INFO_MEMBER(get_bg_tile_info);
105 	TILE_GET_INFO_MEMBER(get_fg_16color_tile_info);
106 
107 	int scanline_to_vcount(int scanline);
108 
109 	uint32_t screen_update_ddragon(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
110 
111 	void ddragon_base_map(address_map &map);
112 
113 private:
114 	/* memory pointers */
115 	required_shared_ptr<uint8_t> m_bgvideoram;
116 	required_shared_ptr<uint8_t> m_fgvideoram;
117 	optional_shared_ptr<uint8_t> m_comram;
118 	required_shared_ptr<uint8_t> m_spriteram;
119 	required_shared_ptr<uint8_t> m_scrollx_lo;
120 	required_shared_ptr<uint8_t> m_scrolly_lo;
121 
122 	/* devices */
123 	optional_device_array<msm5205_device, 2> m_adpcm;
124 
125 	optional_region_ptr_array<uint8_t, 2> m_adpcm_rom;
126 
127 	void ddragon_interrupt_ack(offs_t offset, uint8_t data);
128 	void dd_adpcm_int(int chip);
129 
130 	/* video/ddragon.c */
131 	TILE_GET_INFO_MEMBER(get_fg_tile_info);
132 	void draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect);
133 
134 	DECLARE_MACHINE_START(ddragon);
135 	DECLARE_MACHINE_RESET(ddragon);
136 	DECLARE_VIDEO_START(ddragon);
137 
138 	TIMER_DEVICE_CALLBACK_MEMBER(ddragon_scanline);
139 
140 	void ddragon_bankswitch_w(uint8_t data);
141 	uint8_t ddragon_interrupt_r(offs_t offset);
142 	void ddragon_interrupt_w(offs_t offset, uint8_t data);
143 	void ddragon2_sub_irq_ack_w(uint8_t data);
144 	void ddragon2_sub_irq_w(uint8_t data);
145 	void sub_port6_w(uint8_t data);
146 	uint8_t ddragon_comram_r(offs_t offset);
147 	void ddragon_comram_w(offs_t offset, uint8_t data);
148 	void dd_adpcm_w(offs_t offset, uint8_t data);
149 	uint8_t dd_adpcm_status_r();
150 	void ddragonba_port_w(uint8_t data);
151 	DECLARE_WRITE_LINE_MEMBER(dd_adpcm_int_1);
152 	DECLARE_WRITE_LINE_MEMBER(dd_adpcm_int_2);
153 
154 	void dd2_map(address_map &map);
155 	void dd2_sound_map(address_map &map);
156 	void dd2_sub_map(address_map &map);
157 	void ddragon_map(address_map &map);
158 	void ddragonba_sub_map(address_map &map);
159 	void sound_map(address_map &map);
160 	void ddragon6809_sound_map(address_map &map);
161 	void sub_map(address_map &map);
162 	void sub_6309_map(address_map &map);
163 	void sub_6809_map(address_map &map);
164 };
165 
166 
167 class darktowr_state : public ddragon_state
168 {
169 public:
darktowr_state(const machine_config & mconfig,device_type type,const char * tag)170 	darktowr_state(const machine_config &mconfig, device_type type, const char *tag)
171 		: ddragon_state(mconfig, type, tag)
172 		, m_mcu(*this, "mcu")
173 		, m_darktowr_bank(*this, "darktowr_bank")
174 		, m_mcu_port_a_out(0xff)
175 	{
176 	}
177 
178 	void darktowr(machine_config &config);
179 
180 	void init_darktowr();
181 
182 private:
183 	uint8_t darktowr_mcu_bank_r(offs_t offset);
184 	void darktowr_mcu_bank_w(offs_t offset, uint8_t data);
185 	void darktowr_bankswitch_w(uint8_t data);
186 	void mcu_port_a_w(offs_t offset, uint8_t data);
187 
188 	void darktowr_map(address_map &map);
189 	void darktowr_banked_map(address_map &map);
190 
191 	required_device<m68705p_device> m_mcu;
192 	optional_device<address_map_bank_device> m_darktowr_bank;
193 
194 	uint8_t m_mcu_port_a_out;
195 };
196 
197 
198 class toffy_state : public ddragon_state
199 {
200 public:
toffy_state(const machine_config & mconfig,device_type type,const char * tag)201 	toffy_state(const machine_config &mconfig, device_type type, const char *tag)
202 		: ddragon_state(mconfig, type, tag)
203 	{
204 	}
205 
206 	void toffy(machine_config &config);
207 
208 	void init_toffy();
209 
210 private:
211 	void toffy_bankswitch_w(uint8_t data);
212 
213 	void toffy_map(address_map &map);
214 };
215 
216 #endif // MAME_INCLUDES_DDRAGON_H
217