1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /*************************************************************************
4 
5     Midway MCR-3 system
6 
7 **************************************************************************/
8 #ifndef MAME_INCLUDES_MCR3_H
9 #define MAME_INCLUDES_MCR3_H
10 
11 #pragma once
12 
13 #include "includes/mcr.h"
14 
15 #include "machine/74259.h"
16 #include "machine/adc0844.h"
17 #include "screen.h"
18 #include "tilemap.h"
19 
20 class mcr3_state : public mcr_state
21 {
22 public:
mcr3_state(const machine_config & mconfig,device_type type,const char * tag)23 	mcr3_state(const machine_config &mconfig, device_type type, const char *tag)
24 		: mcr_state(mconfig, type, tag)
25 		, m_spyhunt_alpharam(*this, "spyhunt_alpha")
26 		, m_screen(*this, "screen")
27 		, m_lamps(*this, "lamp%u", 0U)
28 	{ }
29 
30 	void mcrmono(machine_config &config);
31 	void mono_tcs(machine_config &config);
32 	void mcrscroll(machine_config &config);
33 	void mono_sg(machine_config &config);
34 
35 	void init_crater();
36 	void init_demoderm();
37 	void init_powerdrv();
38 	void init_stargrds();
39 	void init_rampage();
40 	void init_sarge();
41 
42 protected:
43 	void mcr3_videoram_w(offs_t offset, uint8_t data);
44 	void spyhunt_videoram_w(offs_t offset, uint8_t data);
45 	void spyhunt_alpharam_w(offs_t offset, uint8_t data);
46 	void spyhunt_scroll_value_w(offs_t offset, uint8_t data);
47 	void mcrmono_control_port_w(uint8_t data);
48 	uint8_t demoderm_ip1_r();
49 	uint8_t demoderm_ip2_r();
50 	void demoderm_op6_w(uint8_t data);
51 	uint8_t rampage_ip4_r();
52 	void rampage_op6_w(uint8_t data);
53 	uint8_t powerdrv_ip2_r();
54 	void powerdrv_op5_w(uint8_t data);
55 	void powerdrv_op6_w(uint8_t data);
56 	uint8_t stargrds_ip0_r();
57 	void stargrds_op5_w(uint8_t data);
58 	void stargrds_op6_w(uint8_t data);
59 
60 	DECLARE_VIDEO_START(spyhunt);
61 	void spyhunt_palette(palette_device &palette) const;
62 
63 	uint32_t screen_update_mcr3(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
64 	uint32_t screen_update_spyhunt(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
65 
66 	void mcrmono_map(address_map &map);
67 	void mcrmono_portmap(address_map &map);
68 	void spyhunt_map(address_map &map);
69 	void spyhunt_portmap(address_map &map);
70 
machine_start()71 	virtual void machine_start() override { m_lamps.resolve(); }
72 	virtual void video_start() override;
73 
74 	optional_shared_ptr<uint8_t> m_spyhunt_alpharam;
75 	required_device<screen_device> m_screen;
76 	output_finder<3> m_lamps;
77 
78 	uint8_t m_latched_input;
79 	uint8_t m_spyhunt_sprite_color_mask;
80 	int16_t m_spyhunt_scroll_offset;
81 	int16_t m_spyhunt_scrollx;
82 	int16_t m_spyhunt_scrolly;
83 	tilemap_t *m_alpha_tilemap;
84 
85 	TILE_GET_INFO_MEMBER(mcrmono_get_bg_tile_info);
86 	TILEMAP_MAPPER_MEMBER(spyhunt_bg_scan);
87 	TILE_GET_INFO_MEMBER(spyhunt_get_bg_tile_info);
88 	TILE_GET_INFO_MEMBER(spyhunt_get_alpha_tile_info);
89 	void mcr3_update_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int color_mask, int code_xor, int dx, int dy, int interlaced);
90 	void mcr_common_init();
91 };
92 
93 class maxrpm_state : public mcr3_state
94 {
95 public:
maxrpm_state(const machine_config & mconfig,device_type type,const char * tag)96 	maxrpm_state(const machine_config &mconfig, device_type type, const char *tag)
97 		: mcr3_state(mconfig, type, tag)
98 		, m_maxrpm_adc(*this, "adc")
99 	{ }
100 
101 	void maxrpm(machine_config &config);
102 
103 	void init_maxrpm();
104 
105 private:
106 	uint8_t maxrpm_ip1_r();
107 	uint8_t maxrpm_ip2_r();
108 	void maxrpm_op5_w(uint8_t data);
109 	void maxrpm_op6_w(uint8_t data);
110 
111 	required_device<adc0844_device> m_maxrpm_adc;
112 
113 	uint8_t m_maxrpm_adc_control;
114 	uint8_t m_maxrpm_last_shift;
115 	int8_t m_maxrpm_p1_shift;
116 	int8_t m_maxrpm_p2_shift;
117 };
118 
119 class mcrsc_csd_state : public mcr3_state
120 {
121 public:
mcrsc_csd_state(const machine_config & mconfig,device_type type,const char * tag)122 	mcrsc_csd_state(const machine_config &mconfig, device_type type, const char *tag)
123 		: mcr3_state(mconfig, type, tag)
124 		, m_lamplatch(*this, "lamplatch")
125 	{ }
126 
127 	void mcrsc_csd(machine_config &config);
128 
129 	void init_spyhunt();
130 	void init_turbotag();
131 
132 private:
133 	uint8_t spyhunt_ip1_r();
134 	uint8_t spyhunt_ip2_r();
135 	void spyhunt_op4_w(uint8_t data);
136 	uint8_t turbotag_ip2_r();
137 	uint8_t turbotag_kludge_r();
138 
139 	optional_device<cd4099_device> m_lamplatch;
140 };
141 
142 #endif // MAME_INCLUDES_MCR3_H
143