1 // license:BSD-3-Clause
2 // copyright-holders:Phil Stroffolino
3 
4 /***************************************************************************
5 
6     Ninja Gaiden
7 
8 ***************************************************************************/
9 #ifndef MAME_INCLUDES_GAIDEN_H
10 #define MAME_INCLUDES_GAIDEN_H
11 
12 #pragma once
13 
14 #include "machine/gen_latch.h"
15 #include "machine/74157.h"
16 #include "sound/msm5205.h"
17 #include "video/bufsprite.h"
18 #include "video/tecmo_spr.h"
19 #include "video/tecmo_mix.h"
20 #include "emupal.h"
21 #include "screen.h"
22 #include "tilemap.h"
23 
24 class gaiden_state : public driver_device
25 {
26 public:
gaiden_state(const machine_config & mconfig,device_type type,const char * tag)27 	gaiden_state(const machine_config &mconfig, device_type type, const char *tag) :
28 		driver_device(mconfig, type, tag),
29 		m_videoram(*this, "videoram%u", 1),
30 		m_spriteram(*this, "spriteram"),
31 		m_adpcm_bank(*this, "adpcm_bank"),
32 		m_maincpu(*this, "maincpu"),
33 		m_audiocpu(*this, "audiocpu"),
34 		m_gfxdecode(*this, "gfxdecode"),
35 		m_screen(*this, "screen"),
36 		m_palette(*this, "palette"),
37 		m_sprgen(*this, "spritegen"),
38 		m_mixer(*this, "mixer"),
39 		m_msm(*this, "msm%u", 1),
40 		m_adpcm_select(*this, "adpcm_select%u", 1)
41 	{ }
42 
43 	void raiga(machine_config &config);
44 	void drgnbowl(machine_config &config);
45 	void mastninj(machine_config &config);
46 	void shadoww(machine_config &config);
47 	void wildfang(machine_config &config);
48 
49 	void init_raiga();
50 	void init_drgnbowl();
51 	void init_drgnbowla();
52 	void init_mastninj();
53 	void init_shadoww();
54 	void init_wildfang();
55 
56 protected:
57 	virtual void machine_start() override;
58 	virtual void machine_reset() override;
59 
60 private:
61 	/* memory pointers */
62 	required_shared_ptr_array<uint16_t, 3> m_videoram;
63 	required_device<buffered_spriteram16_device> m_spriteram;
64 	optional_memory_bank m_adpcm_bank;
65 
66 	/* video-related */
67 	tilemap_t   *m_text_layer;
68 	tilemap_t   *m_foreground;
69 	tilemap_t   *m_background;
70 	bitmap_ind16 m_sprite_bitmap;
71 	bitmap_ind16 m_tile_bitmap_bg;
72 	bitmap_ind16 m_tile_bitmap_fg;
73 	bitmap_ind16 m_tile_bitmap_tx;
74 	uint16_t      m_tx_scroll_x;
75 	uint16_t      m_tx_scroll_y;
76 	uint16_t      m_bg_scroll_x;
77 	uint16_t      m_bg_scroll_y;
78 	uint16_t      m_fg_scroll_x;
79 	uint16_t      m_fg_scroll_y;
80 	int8_t        m_tx_offset_y;
81 	int8_t        m_bg_offset_y;
82 	int8_t        m_fg_offset_y;
83 	int8_t        m_spr_offset_y;
84 
85 	/* misc */
86 	int         m_sprite_sizey;
87 	int         m_prot;
88 	int         m_jumpcode;
89 	const int   *m_jumppoints; // raiga, wildfang
90 	bool        m_adpcm_toggle;
91 
92 	/* devices */
93 	required_device<cpu_device> m_maincpu;
94 	required_device<cpu_device> m_audiocpu;
95 	required_device<gfxdecode_device> m_gfxdecode;
96 	required_device<screen_device> m_screen;
97 	required_device<palette_device> m_palette;
98 	optional_device<tecmo_spr_device> m_sprgen;
99 	optional_device<tecmo_mix_device> m_mixer;
100 	optional_device_array<msm5205_device, 2> m_msm;
101 	optional_device_array<ls157_device, 2> m_adpcm_select;
102 
103 	// mastninja ADPCM control
104 	DECLARE_WRITE_LINE_MEMBER(vck_flipflop_w);
105 	void adpcm_bankswitch_w(uint8_t data);
106 
107 	void irq_ack_w(uint16_t data);
108 	void drgnbowl_irq_ack_w(uint8_t data);
109 	void gaiden_sound_command_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
110 	void wildfang_protection_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
111 	uint16_t wildfang_protection_r();
112 	void raiga_protection_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
113 	uint16_t raiga_protection_r();
114 	void gaiden_flip_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
115 	void gaiden_txscrollx_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
116 	void gaiden_txscrolly_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
117 	void gaiden_fgscrollx_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
118 	void gaiden_fgscrolly_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
119 	void gaiden_bgscrollx_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
120 	void gaiden_bgscrolly_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
121 	void gaiden_txoffsety_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
122 	void gaiden_fgoffsety_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
123 	void gaiden_bgoffsety_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
124 	void gaiden_sproffsety_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
125 	void bg_videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
126 	void fg_videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
127 	void tx_videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
128 	TILE_GET_INFO_MEMBER(get_bg_tile_info);
129 	TILE_GET_INFO_MEMBER(get_fg_tile_info);
130 	TILE_GET_INFO_MEMBER(get_fg_tile_info_raiga);
131 	TILE_GET_INFO_MEMBER(get_tx_tile_info);
132 	DECLARE_MACHINE_START(mastninj);
133 	DECLARE_MACHINE_RESET(raiga);
134 	DECLARE_VIDEO_START(gaiden);
135 	DECLARE_VIDEO_START(drgnbowl);
136 	DECLARE_VIDEO_START(raiga);
137 	DECLARE_WRITE_LINE_MEMBER(screen_vblank_raiga);
138 	uint32_t screen_update_gaiden(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
139 	uint32_t screen_update_raiga(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
140 	uint32_t screen_update_drgnbowl(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
141 	void drgnbowl_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
142 	void descramble_drgnbowl(int descramble_cpu);
143 	void descramble_mastninj_gfx(uint8_t* src);
144 
145 	void drgnbowl_map(address_map &map);
146 	void drgnbowl_sound_map(address_map &map);
147 	void drgnbowl_sound_port_map(address_map &map);
148 	void gaiden_map(address_map &map);
149 	void wildfang_map(address_map &map);
150 	void raiga_map(address_map &map);
151 	void mastninj_map(address_map &map);
152 	void mastninj_sound_map(address_map &map);
153 	void sound_map(address_map &map);
154 };
155 
156 #endif // MAME_INCLUDES_GAIDEN_H
157