1 // license:BSD-3-Clause 2 // copyright-holders:Juergen Buchmueller, Manuel Abadia 3 /********************************************** 4 Philips SAA1099 Sound driver 5 **********************************************/ 6 7 #ifndef MAME_SOUND_SAA1099_H 8 #define MAME_SOUND_SAA1099_H 9 10 #pragma once 11 12 //************************************************************************** 13 // TYPE DEFINITIONS 14 //************************************************************************** 15 16 // ======================> saa1099_device 17 18 class saa1099_device : public device_t, 19 public device_sound_interface 20 { 21 public: 22 saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); 23 24 void control_w(u8 data); 25 void data_w(u8 data); 26 27 void write(offs_t offset, u8 data); 28 29 protected: 30 // device-level overrides 31 virtual void device_start() override; 32 virtual void device_clock_changed() override; 33 34 // sound stream update overrides 35 virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; 36 37 private: 38 struct saa1099_channel 39 { saa1099_channelsaa1099_channel40 saa1099_channel() : amplitude{ 0, 0 }, envelope{ 0, 0 } { } 41 42 u8 frequency = 0; // frequency (0x00..0xff) 43 bool freq_enable = false; // frequency enable 44 bool noise_enable = false; // noise enable 45 u8 octave = 0; // octave (0x00..0x07) 46 u16 amplitude[2]; // amplitude 47 u8 envelope[2]; // envelope (0x00..0x0f or 0x10 == off) 48 49 /* vars to simulate the square wave */ freqsaa1099_channel50 inline u32 freq() const { return (511 - frequency) << (8 - octave); } // clock / ((511 - frequency) * 2^(8 - octave)) 51 int counter = 0; 52 u8 level = 0; 53 }; 54 55 struct saa1099_noise 56 { saa1099_noisesaa1099_noise57 saa1099_noise() { } 58 59 /* vars to simulate the noise generator output */ 60 int counter = 0; 61 int freq = 0; 62 u32 level = 0xffffffffU; // noise polynomial shifter 63 }; 64 65 void envelope_w(int ch); 66 67 sound_stream *m_stream; // our stream 68 u8 m_noise_params[2]; // noise generators parameters 69 bool m_env_enable[2]; // envelope generators enable 70 bool m_env_reverse_right[2]; // envelope reversed for right channel 71 u8 m_env_mode[2]; // envelope generators mode 72 bool m_env_bits[2]; // true = 3 bits resolution 73 bool m_env_clock[2]; // envelope clock mode (true external) 74 u8 m_env_step[2]; // current envelope step 75 bool m_all_ch_enable; // all channels enable 76 bool m_sync_state; // sync all channels 77 u8 m_selected_reg; // selected register 78 saa1099_channel m_channels[6]; // channels 79 saa1099_noise m_noise[2]; // noise generators 80 }; 81 82 DECLARE_DEVICE_TYPE(SAA1099, saa1099_device) 83 84 #endif // MAME_SOUND_SAA1099_H 85