1 // license:BSD-3-Clause
2 // copyright-holders:smf, David Haywood
3 #ifndef MAME_INCLUDES_M62_H
4 #define MAME_INCLUDES_M62_H
5 
6 #pragma once
7 
8 #include "audio/irem.h"
9 #include "emupal.h"
10 #include "tilemap.h"
11 
12 class m62_state : public driver_device
13 {
14 public:
m62_state(const machine_config & mconfig,device_type type,const char * tag)15 	m62_state(const machine_config &mconfig, device_type type, const char *tag) :
16 		driver_device(mconfig, type, tag),
17 		m_spriteram(*this, "spriteram"),
18 		m_m62_tileram(*this, "m62_tileram"),
19 		m_m62_textram(*this, "m62_textram"),
20 		m_scrollram(*this, "scrollram"),
21 		m_sprite_height_prom(*this, "spr_height_prom"),
22 		m_sprite_color_proms(*this, "spr_color_proms"),
23 		m_chr_color_proms(*this, "chr_color_proms"),
24 		m_fg_color_proms(*this, "fg_color_proms"),
25 		m_maincpu(*this, "maincpu"),
26 		m_fg_decode(*this, "fg_decode"),
27 		m_spr_decode(*this, "spr_decode"),
28 		m_chr_decode(*this, "chr_decode"),
29 		m_fg_palette(*this, "fg_palette"),
30 		m_spr_palette(*this, "spr_palette"),
31 		m_chr_palette(*this, "chr_palette"),
32 		m_audio(*this, "irem_audio")
33 	{ }
34 
35 	void ldrun2(machine_config &config);
36 	void lotlot(machine_config &config);
37 	void ldrun3(machine_config &config);
38 	void battroad(machine_config &config);
39 	void horizon(machine_config &config);
40 	void ldrun4(machine_config &config);
41 	void spelunk2(machine_config &config);
42 	void youjyudn(machine_config &config);
43 	void kungfum(machine_config &config);
44 	void spelunkr(machine_config &config);
45 	void ldrun(machine_config &config);
46 	void kidniki(machine_config &config);
47 
48 	void init_youjyudn();
49 	void init_spelunkr();
50 	void init_ldrun2();
51 	void init_ldrun4();
52 	void init_spelunk2();
53 	void init_kidniki();
54 	void init_battroad();
55 
56 private:
57 	/* memory pointers */
58 	required_shared_ptr<uint8_t> m_spriteram;
59 
60 	required_shared_ptr<uint8_t> m_m62_tileram;
61 	optional_shared_ptr<uint8_t> m_m62_textram;
62 	optional_shared_ptr<uint8_t> m_scrollram;
63 
64 	/* video-related */
65 	tilemap_t*             m_bg_tilemap;
66 	tilemap_t*             m_fg_tilemap;
67 	int                  m_flipscreen;
68 	required_region_ptr<uint8_t> m_sprite_height_prom;
69 	required_region_ptr<uint8_t> m_sprite_color_proms;
70 	required_region_ptr<uint8_t> m_chr_color_proms;
71 	optional_region_ptr<uint8_t> m_fg_color_proms;
72 	int32_t                m_m62_background_hscroll;
73 	int32_t                m_m62_background_vscroll;
74 	uint8_t                m_kidniki_background_bank;
75 	int32_t                m_kidniki_text_vscroll;
76 	int                  m_ldrun3_topbottom_mask;
77 	int32_t                m_spelunkr_palbank;
78 
79 	/* misc */
80 	int                 m_ldrun2_bankswap;  //ldrun2
81 	int                 m_bankcontrol[2];   //ldrun2
82 	uint8_t ldrun2_bankswitch_r();
83 	void ldrun2_bankswitch_w(offs_t offset, uint8_t data);
84 	uint8_t ldrun3_prot_5_r();
85 	uint8_t ldrun3_prot_7_r();
86 	void ldrun4_bankswitch_w(uint8_t data);
87 	void kidniki_bankswitch_w(uint8_t data);
88 	void spelunkr_bankswitch_w(uint8_t data);
89 	void spelunk2_bankswitch_w(uint8_t data);
90 	void youjyudn_bankswitch_w(uint8_t data);
91 	void m62_flipscreen_w(uint8_t data);
92 	void m62_hscroll_low_w(uint8_t data);
93 	void m62_hscroll_high_w(uint8_t data);
94 	void m62_vscroll_low_w(uint8_t data);
95 	void m62_vscroll_high_w(uint8_t data);
96 	void m62_tileram_w(offs_t offset, uint8_t data);
97 	void m62_textram_w(offs_t offset, uint8_t data);
98 	void kungfum_tileram_w(offs_t offset, uint8_t data);
99 	void ldrun3_topbottom_mask_w(uint8_t data);
100 	void kidniki_text_vscroll_low_w(uint8_t data);
101 	void kidniki_text_vscroll_high_w(uint8_t data);
102 	void kidniki_background_bank_w(uint8_t data);
103 	void spelunkr_palbank_w(uint8_t data);
104 	void spelunk2_gfxport_w(uint8_t data);
105 	void horizon_scrollram_w(offs_t offset, uint8_t data);
106 	TILE_GET_INFO_MEMBER(get_kungfum_bg_tile_info);
107 	TILE_GET_INFO_MEMBER(get_ldrun_bg_tile_info);
108 	TILE_GET_INFO_MEMBER(get_ldrun2_bg_tile_info);
109 	TILE_GET_INFO_MEMBER(get_battroad_bg_tile_info);
110 	TILE_GET_INFO_MEMBER(get_battroad_fg_tile_info);
111 	TILE_GET_INFO_MEMBER(get_ldrun4_bg_tile_info);
112 	TILE_GET_INFO_MEMBER(get_lotlot_bg_tile_info);
113 	TILE_GET_INFO_MEMBER(get_lotlot_fg_tile_info);
114 	TILE_GET_INFO_MEMBER(get_kidniki_bg_tile_info);
115 	TILE_GET_INFO_MEMBER(get_kidniki_fg_tile_info);
116 	TILE_GET_INFO_MEMBER(get_spelunkr_bg_tile_info);
117 	TILE_GET_INFO_MEMBER(get_spelunkr_fg_tile_info);
118 	TILE_GET_INFO_MEMBER(get_spelunk2_bg_tile_info);
119 	TILE_GET_INFO_MEMBER(get_youjyudn_bg_tile_info);
120 	TILE_GET_INFO_MEMBER(get_youjyudn_fg_tile_info);
121 	TILE_GET_INFO_MEMBER(get_horizon_bg_tile_info);
122 	DECLARE_MACHINE_START(battroad);
123 	void machine_init_save();
124 	virtual void machine_start() override;
125 	virtual void machine_reset() override;
126 	virtual void video_start() override;
127 	void m62_spr(palette_device &palette) const;
128 	void m62_chr(palette_device &palette) const;
129 	void m62_lotlot_fg(palette_device &palette) const;
130 	void m62_battroad_fg(palette_device &palette) const;
131 	DECLARE_VIDEO_START(kungfum);
132 	DECLARE_VIDEO_START(battroad);
133 	DECLARE_VIDEO_START(ldrun2);
134 	DECLARE_VIDEO_START(ldrun4);
135 	DECLARE_VIDEO_START(lotlot);
136 	DECLARE_VIDEO_START(kidniki);
137 	DECLARE_VIDEO_START(spelunkr);
138 	DECLARE_VIDEO_START(spelunk2);
139 	void spelunk2_palette(palette_device &palette) const;
140 	DECLARE_VIDEO_START(youjyudn);
141 	DECLARE_VIDEO_START(horizon);
142 	uint32_t screen_update_ldrun(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
143 	uint32_t screen_update_kungfum(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
144 	uint32_t screen_update_battroad(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
145 	uint32_t screen_update_ldrun3(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
146 	uint32_t screen_update_ldrun4(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
147 	uint32_t screen_update_lotlot(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
148 	uint32_t screen_update_kidniki(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
149 	uint32_t screen_update_spelunkr(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
150 	uint32_t screen_update_spelunk2(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
151 	uint32_t screen_update_youjyudn(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
152 	uint32_t screen_update_horizon(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
153 	void m62_amplify_contrast(bool include_fg);
154 	void register_savestate();
155 	void draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, int colormask, int prioritymask, int priority);
156 	void m62_start(tilemap_get_info_delegate tile_get_info, int rows, int cols, int x1, int y1, int x2, int y2);
157 	void m62_textlayer(tilemap_get_info_delegate tile_get_info, int rows, int cols, int x1, int y1, int x2, int y2);
158 	required_device<cpu_device> m_maincpu;
159 	optional_device<gfxdecode_device> m_fg_decode;
160 	required_device<gfxdecode_device> m_spr_decode;
161 	required_device<gfxdecode_device> m_chr_decode;
162 	optional_device<palette_device> m_fg_palette;
163 	required_device<palette_device> m_spr_palette;
164 	required_device<palette_device> m_chr_palette;
165 	required_device<irem_audio_device> m_audio;
166 
167 	void battroad_io_map(address_map &map);
168 	void battroad_map(address_map &map);
169 	void horizon_map(address_map &map);
170 	void kidniki_io_map(address_map &map);
171 	void kidniki_map(address_map &map);
172 	void kungfum_io_map(address_map &map);
173 	void kungfum_map(address_map &map);
174 	void ldrun2_io_map(address_map &map);
175 	void ldrun2_map(address_map &map);
176 	void ldrun3_io_map(address_map &map);
177 	void ldrun3_map(address_map &map);
178 	void ldrun4_io_map(address_map &map);
179 	void ldrun4_map(address_map &map);
180 	void ldrun_map(address_map &map);
181 	void lotlot_map(address_map &map);
182 	void spelunk2_map(address_map &map);
183 	void spelunkr_map(address_map &map);
184 	void youjyudn_io_map(address_map &map);
185 	void youjyudn_map(address_map &map);
186 };
187 
188 #endif // MAME_INCLUDES_M62_H
189