summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/exidy.h
blob: 86ed7b145cd81f93dcc2c4656b4c4cf9956a83d6 (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
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
#ifndef MAME_AUDIO_EXIDY_H
#define MAME_AUDIO_EXIDY_H

#pragma once

#include "machine/6532riot.h"
#include "machine/6821pia.h"
#include "sound/hc55516.h"
#include "sound/tms5220.h"


class exidy_sound_device : public device_t,
									public device_sound_interface
{
	/* 6840 variables */
	struct sh6840_timer_channel
	{
		uint8_t   cr;
		uint8_t   state;
		uint8_t   leftovers;
		uint16_t  timer;
		uint32_t  clocks;
		union
		{
#ifdef LSB_FIRST
			struct { uint8_t l, h; } b;
#else
			struct { uint8_t h, l; } b;
#endif
			uint16_t w;
		} counter;
	};

public:
	exidy_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
	~exidy_sound_device() {}

	uint8_t sh6840_r(offs_t offset);
	void sh6840_w(offs_t offset, uint8_t data);
	void sfxctrl_w(offs_t offset, uint8_t data);

protected:
	exidy_sound_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;

	void common_sh_start();
	void common_sh_reset();

	void sh6840_register_state_globals();

	// sound stream update overrides
	virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override;
	virtual stream_sample_t generate_music_sample();

	static inline void sh6840_apply_clock(sh6840_timer_channel *t, int clocks);

	/* sound streaming variables */
	sound_stream *m_stream;
	double m_freq_to_step;

private:
	// internal state
	sh6840_timer_channel m_sh6840_timer[3];
	int16_t m_sh6840_volume[3];
	uint8_t m_sh6840_MSB_latch;
	uint8_t m_sh6840_LSB_latch;
	uint8_t m_sh6840_LFSR_oldxor;
	uint32_t m_sh6840_LFSR_0;
	uint32_t m_sh6840_LFSR_1;
	uint32_t m_sh6840_LFSR_2;
	uint32_t m_sh6840_LFSR_3;
	uint32_t m_sh6840_clocks_per_sample;
	uint32_t m_sh6840_clock_count;

	uint8_t m_sfxctrl;

	inline int sh6840_update_noise(int clocks);
};

DECLARE_DEVICE_TYPE(EXIDY, exidy_sound_device)

class exidy_sh8253_sound_device : public exidy_sound_device
{
	struct sh8253_timer_channel
	{
		uint8_t   clstate;
		uint8_t   enable;
		uint16_t  count;
		uint32_t  step;
		uint32_t  fraction;
	};

protected:
	exidy_sh8253_sound_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;

	virtual stream_sample_t generate_music_sample() override;

	void r6532_porta_w(uint8_t data);
	uint8_t r6532_porta_r();
	void r6532_portb_w(uint8_t data);
	uint8_t r6532_portb_r();

	void sh8253_w(offs_t offset, uint8_t data);

	void sh8253_register_state_globals();

	/* 8253 variables */
	sh8253_timer_channel m_sh8253_timer[3];

	/* 6532 variables */
	required_device<riot6532_device> m_riot;

	/* 5220/CVSD variables */
	optional_device<hc55516_device> m_cvsd;
	optional_device<cpu_device> m_cvsdcpu;
	optional_device<tms5220_device> m_tms;
	required_device<pia6821_device> m_pia;
};

class venture_sound_device : public exidy_sh8253_sound_device
{
public:
	venture_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	// configuration access
	auto pa_callback() { return m_pa_callback.bind(); }
	auto pb_callback() { return m_pb_callback.bind(); }
	auto ca2_callback() { return m_ca2_callback.bind(); }
	auto cb2_callback() { return m_cb2_callback.bind(); }

	// external access
	void pa_w(uint8_t data);
	void pb_w(uint8_t data);
	DECLARE_WRITE_LINE_MEMBER(ca_w);
	DECLARE_WRITE_LINE_MEMBER(cb_w);

protected:
	venture_sound_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	// device-level overrides
	virtual void device_resolve_objects() override;
	virtual void device_add_mconfig(machine_config &config) override;

	void venture_audio_map(address_map &map);

private:
	void filter_w(uint8_t data);

	void pia_pa_w(uint8_t data);
	void pia_pb_w(uint8_t data);
	DECLARE_WRITE_LINE_MEMBER(pia_ca2_w);
	DECLARE_WRITE_LINE_MEMBER(pia_cb2_w);

	void venture_audio(machine_config &config);

	devcb_write8 m_pa_callback;
	devcb_write8 m_pb_callback;
	devcb_write_line m_ca2_callback;
	devcb_write_line m_cb2_callback;
};

DECLARE_DEVICE_TYPE(EXIDY_VENTURE, venture_sound_device)

class mtrap_sound_device : public venture_sound_device
{
public:
	mtrap_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

protected:
	// device-level overrides
	virtual void device_add_mconfig(machine_config &config) override;

private:
	void voiceio_w(offs_t offset, uint8_t data);
	uint8_t voiceio_r(offs_t offset);

	void cvsd_map(address_map &map);
	void cvsd_iomap(address_map &map);
};

DECLARE_DEVICE_TYPE(EXIDY_MTRAP, mtrap_sound_device)

class victory_sound_device : public exidy_sh8253_sound_device
{
public:
	victory_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	// external access
	uint8_t response_r();
	uint8_t status_r();
	void command_w(uint8_t data);

protected:
	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_add_mconfig(machine_config &config) override;

private:
	DECLARE_WRITE_LINE_MEMBER(irq_clear_w);
	DECLARE_WRITE_LINE_MEMBER(main_ack_w);

	void victory_audio_map(address_map &map);

	// internal state
	uint8_t m_victory_sound_response_ack_clk; /* 7474 @ F4 */

	TIMER_CALLBACK_MEMBER( delayed_command_w );

	int m_pia_ca1;
	int m_pia_cb1;
};

DECLARE_DEVICE_TYPE(EXIDY_VICTORY, victory_sound_device)

#endif // MAME_AUDIO_EXIDY_H