summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/snk6502.h
blob: 244e6218b1970e977b40ee0b0001f3384ab91948 (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
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria, Dan Boris
/*************************************************************************

    rokola hardware

*************************************************************************/
#ifndef MAME_AUDIO_SNK6502_H
#define MAME_AUDIO_SNK6502_H

#pragma once

#include "sound/discrete.h"
#include "sound/samples.h"
#include "sound/sn76477.h"

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

	DECLARE_READ_LINE_MEMBER(music0_playing);

	void set_music_freq(int freq);
	void set_music_clock(double clock_time);
	void set_channel_base(int channel, int base, int mask = 0xff);
	void mute_channel(int channel);
	void unmute_channel(int channel);
	void set_sound0_stop_on_rollover(int value) { m_sound0_stop_on_rollover = value; }
	void reset_offset(int channel) { m_tone_channels[channel].offset = 0; }

	void speech_w(uint8_t data, const uint16_t *table, int start);

	void build_waveform(int channel, int mask);
	void sasuke_build_waveform(int mask);
	void satansat_build_waveform(int mask);

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

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

private:
	static constexpr unsigned NUM_CHANNELS = 3;

	struct tone_t
	{
		int mute;
		int offset;
		int base;
		int mask;
		int32_t   sample_rate;
		int32_t   sample_step;
		int32_t   sample_cur;
		int16_t   form[16];
	};

	// internal state
	tone_t m_tone_channels[NUM_CHANNELS];
	int32_t m_tone_clock_expire;
	int32_t m_tone_clock;
	sound_stream * m_tone_stream;

	optional_device<samples_device> m_samples;
	required_memory_region m_rom;
	int m_sound0_stop_on_rollover;

	int m_hd38880_cmd;
	uint32_t m_hd38880_addr;
	int m_hd38880_data_bytes;
	double m_hd38880_speed;

	void validate_tone_channel(int channel);
};


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

	DECLARE_WRITE8_MEMBER( sound_w );
	DECLARE_WRITE8_MEMBER( speech_w );

protected:
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_start() override;
	virtual void device_reset() override;

private:
	required_device<snk6502_sound_device> m_custom;
	required_device<sn76477_device> m_sn76477_2;
	required_device<samples_device> m_samples;

	uint8_t m_last_port1;
};


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

	DECLARE_WRITE8_MEMBER( sound_w );
	DECLARE_WRITE8_MEMBER( speech_w );

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

	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_start() override;
	virtual void device_reset() override;

	required_device<snk6502_sound_device> m_custom;

private:
	required_device<discrete_sound_device> m_discrete;

	uint8_t m_last_port1;
};


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

protected:
	virtual void device_add_mconfig(machine_config &config) override;
};


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

protected:
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_reset() override;
};


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

	DECLARE_WRITE8_MEMBER(sound_w);

protected:
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_start() override;
	virtual void device_reset() override;

private:
	required_device<snk6502_sound_device> m_custom;
	required_device<samples_device> m_samples;

	uint8_t m_last_port1;
};


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

	DECLARE_WRITE8_MEMBER(sound_w);

protected:
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_start() override;
	virtual void device_reset() override;

private:
	required_device<snk6502_sound_device> m_custom;
	required_device<samples_device> m_samples;

	uint8_t m_last_port1;
};


DECLARE_DEVICE_TYPE(SNK6502_SOUND,  snk6502_sound_device)

DECLARE_DEVICE_TYPE(VANGUARD_SOUND, vanguard_sound_device)
DECLARE_DEVICE_TYPE(FANTASY_SOUND,  fantasy_sound_device)
DECLARE_DEVICE_TYPE(NIBBLER_SOUND,  nibbler_sound_device)
DECLARE_DEVICE_TYPE(PBALLOON_SOUND, pballoon_sound_device)
DECLARE_DEVICE_TYPE(SASUKE_SOUND,   sasuke_sound_device)
DECLARE_DEVICE_TYPE(SATANSAT_SOUND, satansat_sound_device)

#endif // MAME_AUDIO_SNK6502_H