1 // license:BSD-3-Clause
2 // copyright-holders:Angelo Salese
3 /***************************************************************************
4 
5     Flower custom sound chip
6 
7 ***************************************************************************/
8 
9 #ifndef MAME_AUDIO_FLOWER_H
10 #define MAME_AUDIO_FLOWER_H
11 
12 #pragma once
13 
14 //**************************************************************************
15 //  TYPE DEFINITIONS
16 //**************************************************************************
17 
18 // ======================> flower_sound_device
19 
20 class flower_sound_device : public device_t,
21 							public device_sound_interface,
22 							public device_memory_interface
23 {
24 public:
25 	// construction/destruction
26 	flower_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
27 
28 	// I/O operations
29 	void lower_write(offs_t offset, uint8_t data);
30 	void upper_write(offs_t offset, uint8_t data);
31 //  virtual void lower_map(address_map &map);
32 //  virtual void upper_map(address_map &map);
33 
34 	void regs_map(address_map &map);
35 protected:
36 	// device-level overrides
37 	//virtual void device_validity_check(validity_checker &valid) const override;
38 	//virtual void device_add_mconfig(machine_config &config) override;
39 	virtual void device_start() override;
40 	virtual void device_reset() override;
41 	virtual space_config_vector memory_space_config() const override;
42 	virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
43 
44 	address_space *m_iospace;
45 private:
46 
47 	const address_space_config m_io_space_config;
48 	sound_stream *m_stream;
49 
50 	static constexpr unsigned MAX_VOICES = 8;
51 	static constexpr int defgain = 48;
52 
53 	std::vector<int16_t> m_mixer_table;
54 	int16_t *m_mixer_lookup;
55 	std::vector<short> m_mixer_buffer;
56 
57 	struct fl_sound_channel
58 	{
59 		uint8_t start_nibbles[6];
60 		uint8_t raw_frequency[4];
61 		uint32_t start_address;
62 		uint32_t position;
63 		uint16_t frequency;
64 		uint8_t volume;
65 		uint8_t volume_bank;
66 		uint8_t effect;
67 		bool enable;
68 		bool repeat;
69 		int channel_number;
70 	};
71 
72 	/* data about the sound system */
73 	fl_sound_channel m_channel_list[MAX_VOICES];
74 	fl_sound_channel *m_last_channel;
75 
76 	void make_mixer_table(int voices, int gain);
77 
78 	const uint8_t *m_sample_rom;
79 	const uint8_t *m_volume_rom;
80 
81 	void frequency_w(offs_t offset, uint8_t data);
82 	void repeat_w(offs_t offset, uint8_t data);
83 	void unk_w(offs_t offset, uint8_t data);
84 	void volume_w(offs_t offset, uint8_t data);
85 	void start_address_w(offs_t offset, uint8_t data);
86 	void sample_trigger_w(offs_t offset, uint8_t data);
87 };
88 
89 
90 // device type definition
91 DECLARE_DEVICE_TYPE(FLOWER_CUSTOM, flower_sound_device)
92 
93 
94 #endif // MAME_AUDIO_FLOWER_H
95