1 // license:BSD-3-Clause
2 // copyright-holders:Manuel Abadia
3 #include "cpu/m68000/m68000.h"
4 #include "video/bufsprite.h"
5 #include "machine/74259.h"
6 #include "machine/eepromser.h"
7 #include "machine/timer.h"
8 #include "emupal.h"
9 #include "tilemap.h"
10 
11 class gaelco2_state : public driver_device
12 {
13 public:
gaelco2_state(const machine_config & mconfig,device_type type,const char * tag)14 	gaelco2_state(const machine_config &mconfig, device_type type, const char *tag) :
15 		driver_device(mconfig, type, tag),
16 		m_maincpu(*this, "maincpu"),
17 		m_mainlatch(*this, "mainlatch"),
18 		m_spriteram(*this, "spriteram"),
19 		m_eeprom(*this, "eeprom"),
20 		m_gfxdecode(*this, "gfxdecode"),
21 		m_palette(*this, "palette"),
22 		m_global_spritexoff(0),
23 		m_vregs(*this, "vregs"),
24 		m_snowboar_protection(*this, "snowboar_prot"),
25 		m_paletteram(*this, "paletteram"),
26 		m_shareram(*this, "shareram")
27 	{ }
28 
29 	void maniacsq_d5002fp(machine_config &config);
30 	void play2000(machine_config &config);
31 	void srollnd(machine_config &config);
32 	void alighunt(machine_config &config);
33 	void touchgo(machine_config &config);
34 	void alighunt_d5002fp(machine_config &config);
35 	void snowboar(machine_config &config);
36 	void maniacsq(machine_config &config);
37 	void maniacsqs(machine_config &config);
38 	void touchgo_d5002fp(machine_config &config);
39 	void saltcrdi(machine_config &config);
40 
41 	void init_touchgo();
42 	void init_snowboar();
43 	void init_snowboara();
44 	void init_alighunt();
45 	void init_wrally2();
46 	void init_play2000();
47 
48 	DECLARE_WRITE_LINE_MEMBER(coin1_counter_w);
49 	DECLARE_WRITE_LINE_MEMBER(coin2_counter_w);
50 
51 	DECLARE_VIDEO_START(gaelco2);
52 	DECLARE_VIDEO_START(gaelco2_dual);
53 
54 	u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
55 	u32 screen_update_left(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
56 	u32 screen_update_right(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
57 
58 protected:
59 	required_device<m68000_device> m_maincpu;
60 	optional_device<ls259_device> m_mainlatch;
61 	required_device<buffered_spriteram16_device> m_spriteram;
62 	optional_device<eeprom_serial_93cxx_device> m_eeprom;
63 	required_device<gfxdecode_device> m_gfxdecode;
64 	required_device<palette_device> m_palette;
65 
66 	void vram_w(offs_t offset, u16 data, u16 mem_mask = ~0);
67 	void vregs_w(offs_t offset, u16 data, u16 mem_mask = ~0);
68 	void palette_w(offs_t offset, u16 data, u16 mem_mask = ~0);
69 
70 	void wrally2_latch_w(offs_t offset, u16 data);
71 
72 	void mcu_hostmem_map(address_map &map);
73 
74 private:
75 	void shareram_w(offs_t offset, u8 data);
76 	u8 shareram_r(offs_t offset);
77 	void alighunt_coin_w(u16 data);
78 	DECLARE_WRITE_LINE_MEMBER(coin3_counter_w);
79 	DECLARE_WRITE_LINE_MEMBER(coin4_counter_w);
80 	u16 snowboar_protection_r();
81 	void snowboar_protection_w(offs_t offset, u16 data, u16 mem_mask = ~0);
82 	template<unsigned Layer> TILE_GET_INFO_MEMBER(get_tile_info);
83 	template<unsigned Layer> TILE_GET_INFO_MEMBER(get_tile_info_dual);
84 	void draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int mask);
85 	u32 dual_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int index);
86 	void ROM16_split_gfx(const char *src_reg, const char *dst_reg, int start, int length, int dest1, int dest2);
87 
88 	void alighunt_map(address_map &map);
89 	void maniacsq_map(address_map &map);
90 	void play2000_map(address_map &map);
91 	void snowboar_map(address_map &map);
92 	void touchgo_map(address_map &map);
93 	void saltcrdi_map(address_map &map);
94 	void srollnd_map(address_map &map);
95 
96 	// simulation
97 	u16 srollnd_share_sim_r(offs_t offset, u16 mem_mask = ~0);
98 	void srollnd_share_sim_w(offs_t offset, u16 data, u16 mem_mask = ~0);
99 
100 	u32 m_snowboard_latch;
101 
102 	u16 *m_videoram;
103 	tilemap_t *m_pant[2];
104 	int m_dual_monitor;
105 	int m_global_spritexoff;
106 
107 	required_shared_ptr<u16> m_vregs;
108 	optional_shared_ptr<u16> m_snowboar_protection;
109 	required_shared_ptr<u16> m_paletteram;
110 	optional_shared_ptr<u16> m_shareram;
111 };
112 
113 
114 class bang_state : public gaelco2_state
115 {
116 public:
bang_state(const machine_config & mconfig,device_type type,const char * tag)117 	bang_state(const machine_config &mconfig, device_type type, const char *tag)
118 		: gaelco2_state(mconfig, type, tag)
119 		, m_light0_x(*this, "LIGHT0_X")
120 		, m_light0_y(*this, "LIGHT0_Y")
121 		, m_light1_x(*this, "LIGHT1_X")
122 		, m_light1_y(*this, "LIGHT1_Y")
123 	{}
124 
125 	void bang(machine_config &config);
126 
127 	void init_bang();
128 
129 private:
130 	required_ioport m_light0_x;
131 	required_ioport m_light0_y;
132 	required_ioport m_light1_x;
133 	required_ioport m_light1_y;
134 
135 	int m_clr_gun_int;
136 
137 	u16 p1_gun_x();
138 	u16 p1_gun_y();
139 	u16 p2_gun_x();
140 	u16 p2_gun_y();
141 	void bang_clr_gun_int_w(u16 data);
142 	TIMER_DEVICE_CALLBACK_MEMBER(bang_irq);
143 	void bang_map(address_map &map);
144 };
145 
146 
147 class wrally2_state : public gaelco2_state
148 {
149 public:
wrally2_state(const machine_config & mconfig,device_type type,const char * tag)150 	wrally2_state(const machine_config &mconfig, device_type type, const char *tag)
151 		: gaelco2_state(mconfig, type, tag)
152 		, m_analog0(*this, "ANALOG0")
153 		, m_analog1(*this, "ANALOG1")
154 	{}
155 
156 	void wrally2(machine_config &config);
157 
158 	template <int N> DECLARE_READ_LINE_MEMBER(wrally2_analog_bit_r);
159 
160 private:
161 	required_ioport m_analog0;
162 	required_ioport m_analog1;
163 
164 	uint8_t m_analog_ports[2];
165 
166 	DECLARE_WRITE_LINE_MEMBER(wrally2_adc_clk);
167 	DECLARE_WRITE_LINE_MEMBER(wrally2_adc_cs);
168 	void wrally2_map(address_map &map);
169 };
170