1 // license:GPL-2.0+
2 // copyright-holders:Peter Trauner
3 /*****************************************************************************
4  *
5  *  svis_snd.h
6  *
7  ****************************************************************************/
8 
9 #ifndef MAME_AUDIO_SVIS_SND_H
10 #define MAME_AUDIO_SVIS_SND_H
11 
12 #pragma once
13 
14 
15 // ======================> svision_sound_device
16 
17 class svision_sound_device : public device_t, public device_sound_interface
18 {
19 public:
20 	template <typename T, typename U>
svision_sound_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock,T && cpu_tag,U && region_tag)21 	svision_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&cpu_tag, U &&region_tag)
22 		: svision_sound_device(mconfig, tag, owner, clock)
23 	{
24 		m_maincpu.set_tag(std::forward<T>(cpu_tag));
25 		m_cartrom.set_tag(std::forward<U>(region_tag));
26 	}
27 
28 	svision_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
29 
30 	// configuration
irq_cb()31 	auto irq_cb() { return m_irq_cb.bind(); }
32 
33 	void sounddma_w(offs_t offset, uint8_t data);
34 	void noise_w(offs_t offset, uint8_t data);
35 
36 	void sound_decrement();
37 	void soundport_w(int which, int offset, int data);
38 
39 protected:
40 	// device-level overrides
41 	virtual void device_start() override;
42 
43 	// sound stream update overrides
44 	virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
45 
46 private:
47 	struct NOISE
48 	{
49 		enum class Type
50 		{
51 			Type7Bit = 0,
52 			Type14Bit = 1
53 		};
54 
NOISENOISE55 		NOISE() : reg{ 0, 0, 0 } { }
56 
57 		uint8_t reg[3];
58 		int on = 0, right = 0, left = 0, play = 0;
59 		Type type = Type::Type7Bit;
60 		int state = 0;
61 		int volume = 0;
62 		int count = 0;
63 		double step = 0, pos = 0;
64 		int value = 0; // currently simple random function
65 	};
66 
67 	struct DMA
68 	{
DMADMA69 		DMA() : reg{ 0, 0, 0, 0, 0 } { }
70 
71 		uint8_t reg[5];
72 		int on = 0, right = 0, left = 0;
73 		int ca14to16 = 0;
74 		int start = 0, size = 0;
75 		double pos = 0, step = 0;
76 		int finished = 0;
77 	};
78 
79 	struct CHANNEL
80 	{
CHANNELCHANNEL81 		CHANNEL() : reg{ 0, 0, 0, 0 } { }
82 
83 		uint8_t reg[4];
84 		int on = 0;
85 		int waveform = 0, volume = 0;
86 		int pos = 0;
87 		int size = 0;
88 		int count = 0;
89 	};
90 
91 	devcb_write_line m_irq_cb;
92 
93 	required_device<cpu_device> m_maincpu;
94 	required_memory_bank m_cartrom;
95 
96 	sound_stream *m_mixer_channel;
97 	DMA m_dma;
98 	NOISE m_noise;
99 	CHANNEL m_channel[2];
100 };
101 
102 DECLARE_DEVICE_TYPE(SVISION_SND, svision_sound_device)
103 
104 #endif // MAME_AUDIO_SVIS_SND_H
105