1 // license:GPL-2.0+
2 // copyright-holders:Juergen Buchmueller, David Haywood
3 #ifndef MAME_INCLUDES_DECOCASS_H
4 #define MAME_INCLUDES_DECOCASS_H
5 
6 #pragma once
7 
8 #ifdef MAME_DEBUG
9 #define LOGLEVEL  5
10 #else
11 #define LOGLEVEL  0
12 #endif
13 #define LOG(n,x)  do { if (LOGLEVEL >= n) logerror x; } while (0)
14 
15 #include "machine/decocass_tape.h"
16 #include "machine/gen_latch.h"
17 #include "machine/timer.h"
18 #include "machine/watchdog.h"
19 #include "cpu/mcs48/mcs48.h"
20 #include "emupal.h"
21 #include "screen.h"
22 #include "tilemap.h"
23 
24 #define T1PROM 1
25 #define T1DIRECT 2
26 #define T1LATCH 4
27 #define T1LATCHINV 8
28 
29 class decocass_state : public driver_device
30 {
31 public:
decocass_state(const machine_config & mconfig,device_type type,const char * tag)32 	decocass_state(const machine_config &mconfig, device_type type, const char *tag)
33 		: driver_device(mconfig, type, tag)
34 		, m_maincpu(*this, "maincpu")
35 		, m_mcu(*this, "mcu")
36 		, m_dongle_r(*this)
37 		, m_dongle_w(*this)
38 		, m_audiocpu(*this, "audiocpu")
39 		, m_watchdog(*this, "watchdog")
40 		, m_cassette(*this, "cassette")
41 		, m_gfxdecode(*this, "gfxdecode")
42 		, m_screen(*this, "screen")
43 		, m_palette(*this, "palette")
44 		, m_soundlatch(*this, "soundlatch")
45 		, m_soundlatch2(*this, "soundlatch2")
46 		, m_rambase(*this, "rambase")
47 		, m_charram(*this, "charram")
48 		, m_fgvideoram(*this, "fgvideoram")
49 		, m_colorram(*this, "colorram")
50 		, m_tileram(*this, "tileram")
51 		, m_objectram(*this, "objectram")
52 		, m_paletteram(*this, "paletteram")
53 	{
54 	}
55 
56 	void decocass(machine_config &config);
57 
58 	void init_decocass();
59 	void init_decocrom();
60 	void init_cdsteljn();
61 
62 protected:
63 	/* devices */
64 	required_device<cpu_device> m_maincpu;
65 	required_device<upi41_cpu_device> m_mcu;
66 
67 	/* dongles-related */
68 	read8sm_delegate    m_dongle_r; // TODO: why isn't this a virtual method?
69 	write8sm_delegate   m_dongle_w; // TODO: why isn't this a virtual method?
70 
71 	virtual void machine_start() override;
72 	virtual void machine_reset() override;
73 
74 	int32_t     m_firsttime;
75 	uint8_t     m_latch1;
76 
77 private:
78 	/* devices */
79 	required_device<cpu_device> m_audiocpu;
80 	required_device<watchdog_timer_device> m_watchdog;
81 	required_device<decocass_tape_device> m_cassette;
82 	required_device<gfxdecode_device> m_gfxdecode;
83 	required_device<screen_device> m_screen;
84 	required_device<palette_device> m_palette;
85 	required_device<generic_latch_8_device> m_soundlatch;
86 	required_device<generic_latch_8_device> m_soundlatch2;
87 
88 	/* memory pointers */
89 	required_shared_ptr<uint8_t> m_rambase;
90 	required_shared_ptr<uint8_t> m_charram;
91 	required_shared_ptr<uint8_t> m_fgvideoram;
92 	required_shared_ptr<uint8_t> m_colorram;
93 	uint8_t *   m_bgvideoram; /* shares bits D0-3 with tileram! */
94 	required_shared_ptr<uint8_t> m_tileram;
95 	required_shared_ptr<uint8_t> m_objectram;
96 	required_shared_ptr<uint8_t> m_paletteram;
97 
98 	size_t    m_bgvideoram_size;
99 
100 	/* video-related */
101 	tilemap_t   *m_fg_tilemap;
102 	tilemap_t   *m_bg_tilemap_l;
103 	tilemap_t   *m_bg_tilemap_r;
104 	uint8_t     m_empty_tile[16*16];
105 	int32_t     m_watchdog_count;
106 	int32_t     m_watchdog_flip;
107 	int32_t     m_color_missiles;
108 	int32_t     m_color_center_bot;
109 	int32_t     m_mode_set;
110 	int32_t     m_back_h_shift;
111 	int32_t     m_back_vl_shift;
112 	int32_t     m_back_vr_shift;
113 	int32_t     m_part_h_shift;
114 	int32_t     m_part_v_shift;
115 	int32_t     m_center_h_shift_space;
116 	int32_t     m_center_v_shift;
117 	rectangle m_bg_tilemap_l_clip;
118 	rectangle m_bg_tilemap_r_clip;
119 
120 	/* sound-related */
121 	uint8_t     m_sound_ack;  /* sound latches, ACK status bits and NMI timer */
122 	uint8_t     m_audio_nmi_enabled;
123 	uint8_t     m_audio_nmi_state;
124 
125 	/* misc */
126 	uint8_t     m_decocass_reset;
127 	int32_t     m_de0091_enable;  /* DE-0091xx daughter board enable */
128 	uint8_t     m_quadrature_decoder[4];  /* four inputs from the quadrature decoder (H1, V1, H2, V2) */
129 	int       m_showmsg;        // for debugging purposes
130 
131 	/* i8041 */
132 	uint8_t     m_i8041_p1;
133 	uint8_t     m_i8041_p2;
134 	int       m_i8041_p1_write_latch;
135 	int       m_i8041_p1_read_latch;
136 	int       m_i8041_p2_write_latch;
137 	int       m_i8041_p2_read_latch;
138 
139 	/* DS Telejan */
140 	uint8_t     m_mux_data;
141 
142 	TILEMAP_MAPPER_MEMBER(fgvideoram_scan_cols);
143 	TILEMAP_MAPPER_MEMBER(bgvideoram_scan_cols);
144 	TILE_GET_INFO_MEMBER(get_bg_l_tile_info);
145 	TILE_GET_INFO_MEMBER(get_bg_r_tile_info);
146 	TILE_GET_INFO_MEMBER(get_fg_tile_info);
147 	virtual void video_start() override;
148 	void decocass_palette(palette_device &palette) const;
149 
150 	uint32_t screen_update_decocass(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
151 	void decocass_coin_counter_w(uint8_t data);
152 	void decocass_sound_command_w(uint8_t data);
153 	uint8_t decocass_sound_command_main_r();
154 	uint8_t decocass_sound_data_r();
155 	uint8_t decocass_sound_ack_r();
156 	void decocass_sound_data_w(uint8_t data);
157 	uint8_t decocass_sound_command_r();
158 	void decocass_sound_nmi_enable_w(uint8_t data);
159 	uint8_t decocass_sound_nmi_enable_r();
160 	uint8_t decocass_sound_data_ack_reset_r();
161 	void decocass_sound_data_ack_reset_w(uint8_t data);
162 	void decocass_nmi_reset_w(uint8_t data);
163 	void decocass_quadrature_decoder_reset_w(uint8_t data);
164 	void decocass_adc_w(uint8_t data);
165 	uint8_t decocass_input_r(offs_t offset);
166 
167 	void decocass_reset_w(offs_t offset, uint8_t data);
168 
169 	uint8_t decocass_e5xx_r(offs_t offset);
170 	void decocass_e5xx_w(offs_t offset, uint8_t data);
171 	void decocass_de0091_w(offs_t offset, uint8_t data);
172 	void decocass_e900_w(uint8_t data);
173 
174 
175 	void i8041_p1_w(uint8_t data);
176 	uint8_t i8041_p1_r();
177 	void i8041_p2_w(uint8_t data);
178 	uint8_t i8041_p2_r();
179 
180 	void decocass_machine_state_save_init();
181 
182 	void decocass_paletteram_w(offs_t offset, uint8_t data);
183 	void decocass_charram_w(offs_t offset, uint8_t data);
184 	void decocass_fgvideoram_w(offs_t offset, uint8_t data);
185 	void decocass_colorram_w(offs_t offset, uint8_t data);
186 	void decocass_bgvideoram_w(offs_t offset, uint8_t data);
187 	void decocass_tileram_w(offs_t offset, uint8_t data);
188 	void decocass_objectram_w(offs_t offset, uint8_t data);
189 
190 	void decocass_watchdog_count_w(uint8_t data);
191 	void decocass_watchdog_flip_w(uint8_t data);
192 	void decocass_color_missiles_w(uint8_t data);
193 	void decocass_mode_set_w(uint8_t data);
194 	void decocass_color_center_bot_w(uint8_t data);
195 	void decocass_back_h_shift_w(uint8_t data);
196 	void decocass_back_vl_shift_w(uint8_t data);
197 	void decocass_back_vr_shift_w(uint8_t data);
198 	void decocass_part_h_shift_w(uint8_t data);
199 	void decocass_part_v_shift_w(uint8_t data);
200 	void decocass_center_h_shift_space_w(uint8_t data);
201 	void decocass_center_v_shift_w(uint8_t data);
202 
203 	void decocass_video_state_save_init();
204 
205 	void mirrorvideoram_w(offs_t offset, uint8_t data);
206 	void mirrorcolorram_w(offs_t offset, uint8_t data);
207 	uint8_t mirrorvideoram_r(offs_t offset);
208 	uint8_t mirrorcolorram_r(offs_t offset);
209 	uint8_t cdsteljn_input_r(offs_t offset);
210 	void cdsteljn_mux_w(uint8_t data);
211 	TIMER_DEVICE_CALLBACK_MEMBER(decocass_audio_nmi_gen);
212 	void decocass_map(address_map &map);
213 	void decocass_sound_map(address_map &map);
214 
215 	void draw_edge(bitmap_ind16 &bitmap, const rectangle &cliprect, int which, bool opaque);
216 	void draw_special_priority(bitmap_ind16 &bitmap, bitmap_ind8 &priority, const rectangle &cliprect);
217 	void draw_center(bitmap_ind16 &bitmap, const rectangle &cliprect);
218 	void mark_bg_tile_dirty(offs_t offset);
219 	void draw_sprites(bitmap_ind16 &bitmap, bitmap_ind8 &priority, const rectangle &cliprect, int color,
220 					int sprite_y_adjust, int sprite_y_adjust_flip_screen,
221 					uint8_t *sprite_ram, int interleave);
222 
223 	void draw_missiles(bitmap_ind16 &bitmap, bitmap_ind8 &priority, const rectangle &cliprect,
224 					int missile_y_adjust, int missile_y_adjust_flip_screen,
225 					uint8_t *missile_ram, int interleave);
226 protected:
227 	void decocass_fno( offs_t offset, uint8_t data );
228 };
229 
230 class decocass_type1_state : public decocass_state
231 {
232 public:
decocass_type1_state(const machine_config & mconfig,device_type type,const char * tag)233 	decocass_type1_state(const machine_config &mconfig, device_type type, const char *tag)
234 		: decocass_state(mconfig, type, tag)
235 	{
236 		m_type1_map = nullptr;
237 	}
238 
239 	void cprogolfj(machine_config &config);
240 	void cfboy0a1(machine_config &config);
241 	void cdsteljn(machine_config &config);
242 	void csuperas(machine_config &config);
243 	void clocknch(machine_config &config);
244 	void cterrani(machine_config &config);
245 	void chwy(machine_config &config);
246 	void ctisland3(machine_config &config);
247 	void cocean1a(machine_config &config);
248 	void cluckypo(machine_config &config);
249 	void cexplore(machine_config &config);
250 	void cmanhat(machine_config &config);
251 	void clocknchj(machine_config &config);
252 	void cprogolf(machine_config &config);
253 	void ctsttape(machine_config &config);
254 	void castfant(machine_config &config);
255 	void ctisland(machine_config &config);
256 
257 private:
258 	DECLARE_MACHINE_RESET(ctsttape);
259 	DECLARE_MACHINE_RESET(chwy);
260 	DECLARE_MACHINE_RESET(cdsteljn);
261 	DECLARE_MACHINE_RESET(cterrani);
262 	DECLARE_MACHINE_RESET(castfant);
263 	DECLARE_MACHINE_RESET(csuperas);
264 	DECLARE_MACHINE_RESET(cmanhat);
265 	DECLARE_MACHINE_RESET(clocknch);
266 	DECLARE_MACHINE_RESET(cprogolf);
267 	DECLARE_MACHINE_RESET(cprogolfj);
268 	DECLARE_MACHINE_RESET(cluckypo);
269 	DECLARE_MACHINE_RESET(ctisland);
270 	DECLARE_MACHINE_RESET(ctisland3);
271 	DECLARE_MACHINE_RESET(cexplore);
272 	DECLARE_MACHINE_RESET(cocean1a); /* 10 */
273 	DECLARE_MACHINE_RESET(cfboy0a1); /* 12 */
274 	DECLARE_MACHINE_RESET(clocknchj); /* 11 */
275 
276 	virtual void machine_start() override;
277 	virtual void machine_reset() override;
278 
279 	uint8_t decocass_type1_r(offs_t offset);
280 
281 	/* dongle type #1 */
282 	uint32_t    m_type1_inmap;
283 	uint32_t    m_type1_outmap;
284 	uint8_t* m_type1_map;
285 };
286 
287 
288 class decocass_type2_state : public decocass_state
289 {
290 public:
decocass_type2_state(const machine_config & mconfig,device_type type,const char * tag)291 	decocass_type2_state(const machine_config &mconfig, device_type type, const char *tag)
292 		: decocass_state(mconfig, type, tag)
293 	{
294 	}
295 
296 private:
297 	virtual void machine_start() override;
298 	virtual void machine_reset() override;
299 
300 	uint8_t decocass_type2_r(offs_t offset);
301 	void decocass_type2_w(offs_t offset, uint8_t data);
302 
303 	/* dongle type #2: status of the latches */
304 	int32_t     m_type2_d2_latch; /* latched 8041-STATUS D2 value */
305 	int32_t     m_type2_xx_latch; /* latched value (D7-4 == 0xc0) ? 1 : 0 */
306 	int32_t     m_type2_promaddr; /* latched PROM address A0-A7 */
307 };
308 
309 
310 class decocass_type3_state : public decocass_state
311 {
312 public:
decocass_type3_state(const machine_config & mconfig,device_type type,const char * tag)313 	decocass_type3_state(const machine_config &mconfig, device_type type, const char *tag)
314 		: decocass_state(mconfig, type, tag)
315 	{
316 	}
317 
318 
319 	void csdtenis(machine_config &config);
320 	void cburnrub(machine_config &config);
321 	void cppicf(machine_config &config);
322 	void cgraplop2(machine_config &config);
323 	void cfghtice(machine_config &config);
324 	void cpsoccer(machine_config &config);
325 	void cnightst(machine_config &config);
326 	void cprobowl(machine_config &config);
327 	void cskater(machine_config &config);
328 	void cbtime(machine_config &config);
329 	void cgraplop(machine_config &config);
330 	void clapapa(machine_config &config);
331 	void cfishing(machine_config &config);
332 	void czeroize(machine_config &config);
333 
334 private:
335 	DECLARE_MACHINE_RESET(cfishing);
336 	DECLARE_MACHINE_RESET(cbtime);
337 	DECLARE_MACHINE_RESET(cburnrub);
338 	DECLARE_MACHINE_RESET(cgraplop);
339 	DECLARE_MACHINE_RESET(cgraplop2);
340 	DECLARE_MACHINE_RESET(clapapa);
341 	DECLARE_MACHINE_RESET(cskater);
342 	DECLARE_MACHINE_RESET(cprobowl);
343 	DECLARE_MACHINE_RESET(cnightst);
344 	DECLARE_MACHINE_RESET(cpsoccer);
345 	DECLARE_MACHINE_RESET(csdtenis);
346 	DECLARE_MACHINE_RESET(czeroize);
347 	DECLARE_MACHINE_RESET(cppicf);
348 	DECLARE_MACHINE_RESET(cfghtice);
349 
350 	virtual void machine_start() override;
351 	virtual void machine_reset() override;
352 
353 	uint8_t decocass_type3_r(offs_t offset);
354 	void decocass_type3_w(offs_t offset, uint8_t data);
355 
356 	/* dongle type #3: status and patches */
357 	int32_t     m_type3_ctrs;     /* 12 bit counter stage */
358 	int32_t     m_type3_d0_latch; /* latched 8041-D0 value */
359 	int32_t     m_type3_pal_19;       /* latched 1 for PAL input pin-19 */
360 	int32_t     m_type3_swap;
361 };
362 
363 
364 
365 class decocass_type4_state : public decocass_state
366 {
367 public:
decocass_type4_state(const machine_config & mconfig,device_type type,const char * tag)368 	decocass_type4_state(const machine_config &mconfig, device_type type, const char *tag)
369 		: decocass_state(mconfig, type, tag)
370 	{
371 	}
372 
373 private:
374 
375 	virtual void machine_start() override;
376 	virtual void machine_reset() override;
377 
378 	uint8_t decocass_type4_r(offs_t offset);
379 	void decocass_type4_w(offs_t offset, uint8_t data);
380 
381 	/* dongle type #4: status */
382 	int32_t     m_type4_ctrs;     /* latched PROM address (E5x0 LSB, E5x1 MSB) */
383 	int32_t     m_type4_latch;        /* latched enable PROM (1100xxxx written to E5x1) */
384 };
385 
386 
387 class decocass_type5_state : public decocass_state
388 {
389 public:
decocass_type5_state(const machine_config & mconfig,device_type type,const char * tag)390 	decocass_type5_state(const machine_config &mconfig, device_type type, const char *tag)
391 		: decocass_state(mconfig, type, tag)
392 	{
393 	}
394 
395 private:
396 
397 	virtual void machine_start() override;
398 	virtual void machine_reset() override;
399 
400 	uint8_t decocass_type5_r(offs_t offset);
401 	void decocass_type5_w(offs_t offset, uint8_t data);
402 
403 	/* dongle type #5: status */
404 	int32_t     m_type5_latch;        /* latched enable PROM (1100xxxx written to E5x1) */
405 };
406 
407 
408 class decocass_nodong_state : public decocass_state
409 {
410 public:
decocass_nodong_state(const machine_config & mconfig,device_type type,const char * tag)411 	decocass_nodong_state(const machine_config &mconfig, device_type type, const char *tag)
412 		: decocass_state(mconfig, type, tag)
413 	{
414 	}
415 
416 private:
417 
418 	//virtual void machine_start() override;
419 	virtual void machine_reset() override;
420 
421 	uint8_t decocass_nodong_r(offs_t offset);
422 };
423 
424 
425 class decocass_widel_state : public decocass_state
426 {
427 public:
decocass_widel_state(const machine_config & mconfig,device_type type,const char * tag)428 	decocass_widel_state(const machine_config &mconfig, device_type type, const char *tag)
429 		: decocass_state(mconfig, type, tag)
430 	{
431 	}
432 
433 private:
434 
435 	virtual void machine_start() override;
436 	virtual void machine_reset() override;
437 
438 	uint8_t decocass_widel_r(offs_t offset);
439 	void decocass_widel_w(offs_t offset, uint8_t data);
440 
441 	/* dongle type widel: status */
442 	int32_t     m_widel_ctrs;     /* latched PROM address (E5x0 LSB, E5x1 MSB) */
443 	int32_t     m_widel_latch;        /* latched enable PROM (1100xxxx written to E5x1) */
444 };
445 
446 #endif // MAME_INCLUDES_DECOCASS_H
447