1 // license:BSD-3-Clause
2 // copyright-holders:Luca Elia
3 #ifndef MAME_INCLUDES_SSV_H
4 #define MAME_INCLUDES_SSV_H
5 
6 #pragma once
7 
8 #include "cpu/upd7725/upd7725.h"
9 #include "video/st0020.h"
10 #include "machine/adc0808.h"
11 #include "machine/eepromser.h"
12 #include "machine/timer.h"
13 #include "machine/upd4701.h"
14 #include "machine/upd7001.h"
15 #include "sound/es5506.h"
16 #include "emupal.h"
17 #include "screen.h"
18 #include "tilemap.h"
19 
20 class ssv_state : public driver_device
21 {
22 public:
ssv_state(const machine_config & mconfig,device_type type,const char * tag)23 	ssv_state(const machine_config &mconfig, device_type type, const char *tag) :
24 		driver_device(mconfig, type, tag),
25 		m_maincpu(*this, "maincpu"),
26 		m_ensoniq(*this, "ensoniq"),
27 		m_dsp(*this, "dsp"),
28 		m_mainram(*this, "mainram"),
29 		m_spriteram(*this, "spriteram"),
30 		m_scroll(*this, "scroll"),
31 		m_irq_vectors(*this, "irq_vectors"),
32 		m_input_sel(*this, "input_sel"),
33 		m_srmp7_esbank(*this, "esbank_%u", 2U),
34 		m_raster_interrupt_enabled(false),
35 		m_io_key(*this, "KEY%u", 0U),
36 		m_gfxdecode(*this, "gfxdecode"),
37 		m_screen(*this, "screen"),
38 		m_palette(*this, "palette")
39 	{ }
40 
41 	void ssv(machine_config &config);
42 	void dynagear(machine_config &config);
43 	void hypreac2(machine_config &config);
44 	void meosism(machine_config &config);
45 	void drifto94(machine_config &config);
46 	void stmblade(machine_config &config);
47 	void srmp4(machine_config &config);
48 	void srmp7(machine_config &config);
49 	void twineag2(machine_config &config);
50 	void ryorioh(machine_config &config);
51 	void janjans1(machine_config &config);
52 	void survarts(machine_config &config);
53 	void ultrax(machine_config &config);
54 	void vasara(machine_config &config);
55 	void mslider(machine_config &config);
56 	void jsk(machine_config &config);
57 	void hypreact(machine_config &config);
58 	void keithlcy(machine_config &config);
59 	void pastelis(machine_config &config);
60 	void cairblad(machine_config &config);
61 
62 	void init_ssv();
63 	void init_ssv_tilescram();
64 	void init_ssv_irq1();
65 	void init_srmp7();
66 	void init_jsk();
67 	void init_pastelis();
68 
69 protected:
70 	required_device<cpu_device> m_maincpu;
71 	required_device<es5506_device> m_ensoniq;
72 	optional_device<upd96050_device> m_dsp;
73 
74 	required_shared_ptr<uint16_t> m_mainram;
75 	required_shared_ptr<uint16_t> m_spriteram;
76 	required_shared_ptr<uint16_t> m_scroll;
77 	required_shared_ptr<uint16_t> m_irq_vectors;
78 	optional_shared_ptr<uint16_t> m_input_sel;
79 	optional_memory_bank_array<2> m_srmp7_esbank;
80 
81 	int m_tile_code[16];
82 	int m_enable_video;
83 	int m_shadow_pen_mask;
84 	int m_shadow_pen_shift;
85 	uint8_t m_requested_int;
86 	uint16_t m_irq_enable;
87 	int m_interrupt_ultrax;
88 	bool m_raster_interrupt_enabled;
89 	uint32_t m_latches[8];
90 
91 	void irq_ack_w(offs_t offset, uint16_t data);
92 	void irq_enable_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
93 	void lockout_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
94 	void lockout_inv_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
95 	uint16_t dsp_dr_r();
96 	void dsp_dr_w(uint16_t data);
97 	uint16_t dsp_r(offs_t offset);
98 	void dsp_w(offs_t offset, uint16_t data);
99 	uint16_t drifto94_unknown_r();
100 	uint16_t hypreact_input_r();
101 	uint16_t mainram_r(offs_t offset);
102 	void mainram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
103 	uint16_t srmp4_input_r();
104 	uint16_t srmp7_irqv_r();
105 	void srmp7_sound_bank_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
106 	uint16_t srmp7_input_r();
107 	uint32_t latch32_r(offs_t offset);
108 	void latch32_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
109 	uint16_t latch16_r(offs_t offset);
110 	void latch16_w(offs_t offset, uint16_t data);
111 	uint16_t vblank_r();
112 	void scroll_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
113 
114 	virtual void machine_reset() override;
115 	virtual void video_start() override;
116 
117 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
118 
119 	TIMER_DEVICE_CALLBACK_MEMBER(interrupt);
120 	void update_irq_state();
121 	IRQ_CALLBACK_MEMBER(irq_callback);
122 
123 	void drawgfx_line(bitmap_ind16 &bitmap, const rectangle &cliprect, int gfx, uint32_t code, uint32_t color, int flipx, int flipy, int base_sx, int base_sy, int shadow, int realline, int line);
124 	void drawgfx(bitmap_ind16 &bitmap, const rectangle &cliprect, int gfx,uint32_t code, uint32_t color, int flipx, int flipy, int base_sx, int base_sy,int shadow);
125 
126 	void draw_16x16_tile_line(bitmap_ind16 &bitmap, const rectangle &cliprect, int flipx, int flipy, int mode, int code, int color, int sx, int sy, int realline, int line);
127 	void get_tile(int x, int y, int size, int page, int& code, int& attr, int& flipx, int& flipy);
128 	void draw_row_64pixhigh(bitmap_ind16 &bitmap, const rectangle &cliprect, int in_sy, int scroll);
129 	void draw_layer(bitmap_ind16 &bitmap, const rectangle &cliprect, int  nr);
130 
131 	void draw_sprites_tiles(bitmap_ind16 &bitmap, const rectangle &cliprect, int code, int flipx, int flipy, int gfx, int shadow, int color, int sx, int sy, int xnum, int ynum);
132 	void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
133 	void enable_video(int enable);
134 
135 	void cairblad_map(address_map &map);
136 	void drifto94_map(address_map &map);
137 	void dsp_data_map(address_map &map);
138 	void dsp_prg_map(address_map &map);
139 	void hypreac2_map(address_map &map);
140 	void hypreact_map(address_map &map);
141 	void janjans1_map(address_map &map);
142 	void jsk_map(address_map &map);
143 	void jsk_v810_mem(address_map &map);
144 	void keithlcy_map(address_map &map);
145 	void meosism_map(address_map &map);
146 	void mslider_map(address_map &map);
147 	void ryorioh_map(address_map &map);
148 	void srmp4_map(address_map &map);
149 	void srmp7_map(address_map &map);
150 	void srmp7_es5506_bank2_map(address_map &map);
151 	void srmp7_es5506_bank3_map(address_map &map);
152 	void survarts_map(address_map &map);
153 	void twineag2_map(address_map &map);
154 	void ultrax_map(address_map &map);
155 
156 	optional_ioport_array<4> m_io_key;
157 	required_device<gfxdecode_device> m_gfxdecode;
158 	required_device<screen_device> m_screen;
159 	required_device<palette_device> m_palette;
160 
161 	void ssv_map(address_map &map, u32 rom);
162 };
163 
164 class gdfs_state : public ssv_state
165 {
166 public:
gdfs_state(const machine_config & mconfig,device_type type,const char * tag)167 	gdfs_state(const machine_config &mconfig, device_type type, const char *tag) :
168 		ssv_state(mconfig, type, tag),
169 		m_adc(*this, "adc"),
170 		m_eeprom(*this, "eeprom"),
171 		m_st0020(*this, "st0020_spr"),
172 		m_tmapram(*this, "gdfs_tmapram"),
173 		m_tmapscroll(*this, "gdfs_tmapscroll")
174 	{ }
175 
176 	void gdfs(machine_config &config);
177 
178 protected:
179 	virtual void video_start() override;
180 
181 private:
182 	DECLARE_WRITE_LINE_MEMBER(adc_int_w);
183 
184 	uint16_t eeprom_r();
185 	void eeprom_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
186 
187 	void gdfs_map(address_map &map);
188 
189 	TILE_GET_INFO_MEMBER(get_tile_info_0);
190 	void tmapram_w(offs_t offset, uint16_t data, uint16_t mem_mask);
191 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
192 
193 	required_device<adc0808_device> m_adc;
194 	required_device<eeprom_serial_93cxx_device> m_eeprom;
195 	required_device<st0020_device> m_st0020;
196 	required_shared_ptr<uint16_t> m_tmapram;
197 	required_shared_ptr<uint16_t> m_tmapscroll;
198 
199 	tilemap_t *m_tmap;
200 };
201 
202 class eaglshot_state : public ssv_state
203 {
204 public:
eaglshot_state(const machine_config & mconfig,device_type type,const char * tag)205 	eaglshot_state(const machine_config &mconfig, device_type type, const char *tag) :
206 		ssv_state(mconfig, type, tag),
207 		m_upd4701(*this, "upd4701")
208 	{ }
209 
210 	void eaglshot(machine_config &config);
211 
212 	void init_eaglshot();
213 
214 protected:
215 	virtual void video_start() override;
216 
217 private:
218 	void gfxrom_bank_w(uint8_t data);
219 	void trackball_w(uint8_t data);
220 	uint16_t gfxram_r(offs_t offset, uint16_t mem_mask);
221 	void gfxram_w(offs_t offset, uint16_t data, uint16_t mem_mask);
222 
223 	void eaglshot_map(address_map &map);
224 
225 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
226 
227 	required_device<upd4701_device> m_upd4701;
228 
229 	std::unique_ptr<uint16_t[]> m_gfxram;
230 };
231 
232 class sxyreact_state : public ssv_state
233 {
234 public:
sxyreact_state(const machine_config & mconfig,device_type type,const char * tag)235 	sxyreact_state(const machine_config &mconfig, device_type type, const char *tag) :
236 		ssv_state(mconfig, type, tag),
237 		m_sxyreact_adc(*this, "adc"),
238 		m_io_service(*this, "SERVICE")
239 	{ }
240 
241 	void sxyreact(machine_config &config);
242 	void sxyreac2(machine_config &config);
243 
244 	void init_sexy();
245 
246 private:
247 	uint16_t ballswitch_r();
248 	uint8_t dial_r();
249 	void dial_w(uint8_t data);
250 	void motor_w(uint16_t data);
251 
252 	void sxyreact_map(address_map &map);
253 
254 	required_device<upd7001_device> m_sxyreact_adc;
255 	required_ioport m_io_service;
256 };
257 
258 #endif // MAME_INCLUDES_SSV_H
259