summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/includes/decocass.h
blob: 63e1f073a33b348bdbcd8bdbef7419c74e33a021 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
// license:GPL-2.0+
// copyright-holders:Juergen Buchmueller, David Haywood
#ifndef MAME_INCLUDES_DECOCASS_H
#define MAME_INCLUDES_DECOCASS_H

#pragma once

#ifdef MAME_DEBUG
#define LOGLEVEL  5
#else
#define LOGLEVEL  0
#endif
#define LOG(n,x)  do { if (LOGLEVEL >= n) logerror x; } while (0)

#include "machine/decocass_tape.h"
#include "machine/gen_latch.h"
#include "machine/timer.h"
#include "machine/watchdog.h"
#include "cpu/mcs48/mcs48.h"
#include "emupal.h"
#include "screen.h"
#include "tilemap.h"

#define T1PROM 1
#define T1DIRECT 2
#define T1LATCH 4
#define T1LATCHINV 8

class decocass_state : public driver_device
{
public:
	decocass_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag)
		, m_maincpu(*this, "maincpu")
		, m_mcu(*this, "mcu")
		, m_dongle_r(*this)
		, m_dongle_w(*this)
		, m_audiocpu(*this, "audiocpu")
		, m_watchdog(*this, "watchdog")
		, m_cassette(*this, "cassette")
		, m_gfxdecode(*this, "gfxdecode")
		, m_screen(*this, "screen")
		, m_palette(*this, "palette")
		, m_soundlatch(*this, "soundlatch")
		, m_soundlatch2(*this, "soundlatch2")
		, m_rambase(*this, "rambase")
		, m_charram(*this, "charram")
		, m_fgvideoram(*this, "fgvideoram")
		, m_colorram(*this, "colorram")
		, m_tileram(*this, "tileram")
		, m_objectram(*this, "objectram")
		, m_paletteram(*this, "paletteram")
	{
	}

	void decocass(machine_config &config);

	void init_decocass();
	void init_decocrom();
	void init_cdsteljn();

protected:
	/* devices */
	required_device<cpu_device> m_maincpu;
	required_device<upi41_cpu_device> m_mcu;

	/* dongles-related */
	read8_delegate    m_dongle_r; // TODO: why isn't this a virtual method?
	write8_delegate   m_dongle_w; // TODO: why isn't this a virtual method?

	virtual void machine_start() override;
	virtual void machine_reset() override;

	int32_t     m_firsttime;
	uint8_t     m_latch1;

private:
	/* devices */
	required_device<cpu_device> m_audiocpu;
	required_device<watchdog_timer_device> m_watchdog;
	required_device<decocass_tape_device> m_cassette;
	required_device<gfxdecode_device> m_gfxdecode;
	required_device<screen_device> m_screen;
	required_device<palette_device> m_palette;
	required_device<generic_latch_8_device> m_soundlatch;
	required_device<generic_latch_8_device> m_soundlatch2;

	/* memory pointers */
	required_shared_ptr<uint8_t> m_rambase;
	required_shared_ptr<uint8_t> m_charram;
	required_shared_ptr<uint8_t> m_fgvideoram;
	required_shared_ptr<uint8_t> m_colorram;
	uint8_t *   m_bgvideoram; /* shares bits D0-3 with tileram! */
	required_shared_ptr<uint8_t> m_tileram;
	required_shared_ptr<uint8_t> m_objectram;
	required_shared_ptr<uint8_t> m_paletteram;

	size_t    m_bgvideoram_size;

	/* video-related */
	tilemap_t   *m_fg_tilemap;
	tilemap_t   *m_bg_tilemap_l;
	tilemap_t   *m_bg_tilemap_r;
	uint8_t     m_empty_tile[16*16];
	int32_t     m_watchdog_count;
	int32_t     m_watchdog_flip;
	int32_t     m_color_missiles;
	int32_t     m_color_center_bot;
	int32_t     m_mode_set;
	int32_t     m_back_h_shift;
	int32_t     m_back_vl_shift;
	int32_t     m_back_vr_shift;
	int32_t     m_part_h_shift;
	int32_t     m_part_v_shift;
	int32_t     m_center_h_shift_space;
	int32_t     m_center_v_shift;
	rectangle m_bg_tilemap_l_clip;
	rectangle m_bg_tilemap_r_clip;

	/* sound-related */
	uint8_t     m_sound_ack;  /* sound latches, ACK status bits and NMI timer */
	uint8_t     m_audio_nmi_enabled;
	uint8_t     m_audio_nmi_state;

	/* misc */
	uint8_t     m_decocass_reset;
	int32_t     m_de0091_enable;  /* DE-0091xx daughter board enable */
	uint8_t     m_quadrature_decoder[4];  /* four inputs from the quadrature decoder (H1, V1, H2, V2) */
	int       m_showmsg;        // for debugging purposes

	/* i8041 */
	uint8_t     m_i8041_p1;
	uint8_t     m_i8041_p2;
	int       m_i8041_p1_write_latch;
	int       m_i8041_p1_read_latch;
	int       m_i8041_p2_write_latch;
	int       m_i8041_p2_read_latch;

	/* DS Telejan */
	uint8_t     m_mux_data;

	TILEMAP_MAPPER_MEMBER(fgvideoram_scan_cols);
	TILEMAP_MAPPER_MEMBER(bgvideoram_scan_cols);
	TILE_GET_INFO_MEMBER(get_bg_l_tile_info);
	TILE_GET_INFO_MEMBER(get_bg_r_tile_info);
	TILE_GET_INFO_MEMBER(get_fg_tile_info);
	virtual void video_start() override;
	void decocass_palette(palette_device &palette) const;

	uint32_t screen_update_decocass(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	DECLARE_WRITE8_MEMBER(decocass_coin_counter_w);
	DECLARE_WRITE8_MEMBER(decocass_sound_command_w);
	DECLARE_READ8_MEMBER(decocass_sound_command_main_r);
	DECLARE_READ8_MEMBER(decocass_sound_data_r);
	DECLARE_READ8_MEMBER(decocass_sound_ack_r);
	DECLARE_WRITE8_MEMBER(decocass_sound_data_w);
	DECLARE_READ8_MEMBER(decocass_sound_command_r);
	DECLARE_WRITE8_MEMBER(decocass_sound_nmi_enable_w);
	DECLARE_READ8_MEMBER(decocass_sound_nmi_enable_r);
	DECLARE_READ8_MEMBER(decocass_sound_data_ack_reset_r);
	DECLARE_WRITE8_MEMBER(decocass_sound_data_ack_reset_w);
	DECLARE_WRITE8_MEMBER(decocass_nmi_reset_w);
	DECLARE_WRITE8_MEMBER(decocass_quadrature_decoder_reset_w);
	DECLARE_WRITE8_MEMBER(decocass_adc_w);
	DECLARE_READ8_MEMBER(decocass_input_r);

	DECLARE_WRITE8_MEMBER(decocass_reset_w);

	DECLARE_READ8_MEMBER(decocass_e5xx_r);
	DECLARE_WRITE8_MEMBER(decocass_e5xx_w);
	DECLARE_WRITE8_MEMBER(decocass_de0091_w);
	DECLARE_WRITE8_MEMBER(decocass_e900_w);


	DECLARE_WRITE8_MEMBER(i8041_p1_w);
	DECLARE_READ8_MEMBER(i8041_p1_r);
	DECLARE_WRITE8_MEMBER(i8041_p2_w);
	DECLARE_READ8_MEMBER(i8041_p2_r);

	void decocass_machine_state_save_init();

	DECLARE_WRITE8_MEMBER(decocass_paletteram_w);
	DECLARE_WRITE8_MEMBER(decocass_charram_w);
	DECLARE_WRITE8_MEMBER(decocass_fgvideoram_w);
	DECLARE_WRITE8_MEMBER(decocass_colorram_w);
	DECLARE_WRITE8_MEMBER(decocass_bgvideoram_w);
	DECLARE_WRITE8_MEMBER(decocass_tileram_w);
	DECLARE_WRITE8_MEMBER(decocass_objectram_w);

	DECLARE_WRITE8_MEMBER(decocass_watchdog_count_w);
	DECLARE_WRITE8_MEMBER(decocass_watchdog_flip_w);
	DECLARE_WRITE8_MEMBER(decocass_color_missiles_w);
	DECLARE_WRITE8_MEMBER(decocass_mode_set_w);
	DECLARE_WRITE8_MEMBER(decocass_color_center_bot_w);
	DECLARE_WRITE8_MEMBER(decocass_back_h_shift_w);
	DECLARE_WRITE8_MEMBER(decocass_back_vl_shift_w);
	DECLARE_WRITE8_MEMBER(decocass_back_vr_shift_w);
	DECLARE_WRITE8_MEMBER(decocass_part_h_shift_w);
	DECLARE_WRITE8_MEMBER(decocass_part_v_shift_w);
	DECLARE_WRITE8_MEMBER(decocass_center_h_shift_space_w);
	DECLARE_WRITE8_MEMBER(decocass_center_v_shift_w);

	void decocass_video_state_save_init();

	DECLARE_WRITE8_MEMBER(mirrorvideoram_w);
	DECLARE_WRITE8_MEMBER(mirrorcolorram_w);
	DECLARE_READ8_MEMBER(mirrorvideoram_r);
	DECLARE_READ8_MEMBER(mirrorcolorram_r);
	DECLARE_READ8_MEMBER(cdsteljn_input_r);
	DECLARE_WRITE8_MEMBER(cdsteljn_mux_w);
	TIMER_DEVICE_CALLBACK_MEMBER(decocass_audio_nmi_gen);
	void decocass_map(address_map &map);
	void decocass_sound_map(address_map &map);

	void draw_edge(bitmap_ind16 &bitmap, const rectangle &cliprect, int which, bool opaque);
	void draw_special_priority(bitmap_ind16 &bitmap, bitmap_ind8 &priority, const rectangle &cliprect);
	void draw_center(bitmap_ind16 &bitmap, const rectangle &cliprect);
	void mark_bg_tile_dirty(offs_t offset);
	void draw_sprites(bitmap_ind16 &bitmap, bitmap_ind8 &priority, const rectangle &cliprect, int color,
					int sprite_y_adjust, int sprite_y_adjust_flip_screen,
					uint8_t *sprite_ram, int interleave);

	void draw_missiles(bitmap_ind16 &bitmap, bitmap_ind8 &priority, const rectangle &cliprect,
					int missile_y_adjust, int missile_y_adjust_flip_screen,
					uint8_t *missile_ram, int interleave);
protected:
	void decocass_fno( offs_t offset, uint8_t data );
};

class decocass_type1_state : public decocass_state
{
public:
	decocass_type1_state(const machine_config &mconfig, device_type type, const char *tag)
		: decocass_state(mconfig, type, tag)
	{
		m_type1_map = nullptr;
	}

	void cprogolfj(machine_config &config);
	void cfboy0a1(machine_config &config);
	void cdsteljn(machine_config &config);
	void csuperas(machine_config &config);
	void clocknch(machine_config &config);
	void cterrani(machine_config &config);
	void chwy(machine_config &config);
	void ctisland3(machine_config &config);
	void cocean1a(machine_config &config);
	void cluckypo(machine_config &config);
	void cexplore(machine_config &config);
	void cmanhat(machine_config &config);
	void clocknchj(machine_config &config);
	void cprogolf(machine_config &config);
	void ctsttape(machine_config &config);
	void castfant(machine_config &config);
	void ctisland(machine_config &config);

private:
	DECLARE_MACHINE_RESET(ctsttape);
	DECLARE_MACHINE_RESET(chwy);
	DECLARE_MACHINE_RESET(cdsteljn);
	DECLARE_MACHINE_RESET(cterrani);
	DECLARE_MACHINE_RESET(castfant);
	DECLARE_MACHINE_RESET(csuperas);
	DECLARE_MACHINE_RESET(cmanhat);
	DECLARE_MACHINE_RESET(clocknch);
	DECLARE_MACHINE_RESET(cprogolf);
	DECLARE_MACHINE_RESET(cprogolfj);
	DECLARE_MACHINE_RESET(cluckypo);
	DECLARE_MACHINE_RESET(ctisland);
	DECLARE_MACHINE_RESET(ctisland3);
	DECLARE_MACHINE_RESET(cexplore);
	DECLARE_MACHINE_RESET(cocean1a); /* 10 */
	DECLARE_MACHINE_RESET(cfboy0a1); /* 12 */
	DECLARE_MACHINE_RESET(clocknchj); /* 11 */

	virtual void machine_start() override;
	virtual void machine_reset() override;

	DECLARE_READ8_MEMBER(decocass_type1_r);

	/* dongle type #1 */
	uint32_t    m_type1_inmap;
	uint32_t    m_type1_outmap;
	uint8_t* m_type1_map;
};


class decocass_type2_state : public decocass_state
{
public:
	decocass_type2_state(const machine_config &mconfig, device_type type, const char *tag)
		: decocass_state(mconfig, type, tag)
	{
	}

private:
	virtual void machine_start() override;
	virtual void machine_reset() override;

	DECLARE_READ8_MEMBER(decocass_type2_r);
	DECLARE_WRITE8_MEMBER(decocass_type2_w);

	/* dongle type #2: status of the latches */
	int32_t     m_type2_d2_latch; /* latched 8041-STATUS D2 value */
	int32_t     m_type2_xx_latch; /* latched value (D7-4 == 0xc0) ? 1 : 0 */
	int32_t     m_type2_promaddr; /* latched PROM address A0-A7 */
};


class decocass_type3_state : public decocass_state
{
public:
	decocass_type3_state(const machine_config &mconfig, device_type type, const char *tag)
		: decocass_state(mconfig, type, tag)
	{
	}


	void csdtenis(machine_config &config);
	void cburnrub(machine_config &config);
	void cppicf(machine_config &config);
	void cgraplop2(machine_config &config);
	void cfghtice(machine_config &config);
	void cpsoccer(machine_config &config);
	void cnightst(machine_config &config);
	void cprobowl(machine_config &config);
	void cskater(machine_config &config);
	void cbtime(machine_config &config);
	void cgraplop(machine_config &config);
	void clapapa(machine_config &config);
	void cfishing(machine_config &config);
	void czeroize(machine_config &config);

private:
	DECLARE_MACHINE_RESET(cfishing);
	DECLARE_MACHINE_RESET(cbtime);
	DECLARE_MACHINE_RESET(cburnrub);
	DECLARE_MACHINE_RESET(cgraplop);
	DECLARE_MACHINE_RESET(cgraplop2);
	DECLARE_MACHINE_RESET(clapapa);
	DECLARE_MACHINE_RESET(cskater);
	DECLARE_MACHINE_RESET(cprobowl);
	DECLARE_MACHINE_RESET(cnightst);
	DECLARE_MACHINE_RESET(cpsoccer);
	DECLARE_MACHINE_RESET(csdtenis);
	DECLARE_MACHINE_RESET(czeroize);
	DECLARE_MACHINE_RESET(cppicf);
	DECLARE_MACHINE_RESET(cfghtice);

	virtual void machine_start() override;
	virtual void machine_reset() override;

	DECLARE_READ8_MEMBER(decocass_type3_r);
	DECLARE_WRITE8_MEMBER(decocass_type3_w);

	/* dongle type #3: status and patches */
	int32_t     m_type3_ctrs;     /* 12 bit counter stage */
	int32_t     m_type3_d0_latch; /* latched 8041-D0 value */
	int32_t     m_type3_pal_19;       /* latched 1 for PAL input pin-19 */
	int32_t     m_type3_swap;
};



class decocass_type4_state : public decocass_state
{
public:
	decocass_type4_state(const machine_config &mconfig, device_type type, const char *tag)
		: decocass_state(mconfig, type, tag)
	{
	}

private:

	virtual void machine_start() override;
	virtual void machine_reset() override;

	DECLARE_READ8_MEMBER(decocass_type4_r);
	DECLARE_WRITE8_MEMBER(decocass_type4_w);

	/* dongle type #4: status */
	int32_t     m_type4_ctrs;     /* latched PROM address (E5x0 LSB, E5x1 MSB) */
	int32_t     m_type4_latch;        /* latched enable PROM (1100xxxx written to E5x1) */
};


class decocass_type5_state : public decocass_state
{
public:
	decocass_type5_state(const machine_config &mconfig, device_type type, const char *tag)
		: decocass_state(mconfig, type, tag)
	{
	}

private:

	virtual void machine_start() override;
	virtual void machine_reset() override;

	DECLARE_READ8_MEMBER(decocass_type5_r);
	DECLARE_WRITE8_MEMBER(decocass_type5_w);

	/* dongle type #5: status */
	int32_t     m_type5_latch;        /* latched enable PROM (1100xxxx written to E5x1) */
};


class decocass_nodong_state : public decocass_state
{
public:
	decocass_nodong_state(const machine_config &mconfig, device_type type, const char *tag)
		: decocass_state(mconfig, type, tag)
	{
	}

private:

	//virtual void machine_start() override;
	virtual void machine_reset() override;

	DECLARE_READ8_MEMBER(decocass_nodong_r);
};


class decocass_widel_state : public decocass_state
{
public:
	decocass_widel_state(const machine_config &mconfig, device_type type, const char *tag)
		: decocass_state(mconfig, type, tag)
	{
	}

private:

	virtual void machine_start() override;
	virtual void machine_reset() override;

	DECLARE_READ8_MEMBER(decocass_widel_r);
	DECLARE_WRITE8_MEMBER(decocass_widel_w);

	/* dongle type widel: status */
	int32_t     m_widel_ctrs;     /* latched PROM address (E5x0 LSB, E5x1 MSB) */
	int32_t     m_widel_latch;        /* latched enable PROM (1100xxxx written to E5x1) */
};

#endif // MAME_INCLUDES_DECOCASS_H