DOSBox-X
|
00001 // license:BSD-3-Clause 00002 // copyright-holders:Juergen Buchmueller, Manuel Abadia 00003 /********************************************** 00004 Philips SAA1099 Sound driver 00005 **********************************************/ 00006 00007 #ifndef MAME_SOUND_SAA1099_H 00008 #define MAME_SOUND_SAA1099_H 00009 00010 #pragma once 00011 00012 //************************************************************************** 00013 // INTERFACE CONFIGURATION MACROS 00014 //************************************************************************** 00015 00016 #define MCFG_SAA1099_ADD(_tag, _clock) \ 00017 MCFG_DEVICE_ADD(_tag, SAA1099, _clock) 00018 #define MCFG_SAA1099_REPLACE(_tag, _clock) \ 00019 MCFG_DEVICE_REPLACE(_tag, SAA1099, _clock) 00020 00021 00022 //************************************************************************** 00023 // TYPE DEFINITIONS 00024 //************************************************************************** 00025 00026 //Container class for int that just initalizes to 0 00027 class NullInt { 00028 int value; 00029 public: 00030 operator int& () { 00031 return value; 00032 } 00033 00034 int& operator= ( int set ) { 00035 value = set; 00036 return value; 00037 } 00038 00039 NullInt( int set = 0 ) : value( set ) { 00040 } 00041 }; 00042 00043 // ======================> saa1099_device 00044 00045 class saa1099_device : public device_t, 00046 public device_sound_interface 00047 { 00048 public: 00049 saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); 00050 00051 DECLARE_WRITE8_MEMBER( control_w ); 00052 DECLARE_WRITE8_MEMBER( data_w ); 00053 00054 DECLARE_WRITE8_MEMBER( write ); 00055 00056 //protected: 00057 // device-level overrides 00058 virtual void device_start(); 00059 00060 // sound stream update overrides 00061 virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); 00062 00063 void SaveState( std::ostream& stream ); 00064 void LoadState( std::istream& stream ); 00065 00066 private: 00067 struct saa1099_channel 00068 { 00069 saa1099_channel() { 00070 //Quite hacky, but let's see how it goes 00071 memset( this, 0, sizeof( *this ) ); 00072 } 00073 00074 int frequency ; /* frequency (0x00..0xff) */ 00075 int freq_enable ; /* frequency enable */ 00076 int noise_enable ; /* noise enable */ 00077 int octave ; /* octave (0x00..0x07) */ 00078 int amplitude[2]; /* amplitude (0x00..0x0f) */ 00079 int envelope[2]; /* envelope (0x00..0x0f or 0x10 == off) */ 00080 00081 /* vars to simulate the square wave */ 00082 double counter ; 00083 double freq ; 00084 int level ; 00085 00086 }; 00087 00088 struct saa1099_noise 00089 { 00090 saa1099_noise() { 00091 counter = 0; 00092 freq = 0; 00093 level = 0xFFFFFFFF; 00094 } 00095 00096 /* vars to simulate the noise generator output */ 00097 double counter; 00098 double freq; 00099 uint32_t level; /* noise polynomial shifter */ 00100 }; 00101 00102 void envelope_w(int ch); 00103 00104 sound_stream *m_stream; /* our stream */ 00105 int m_noise_params[2]; /* noise generators parameters */ 00106 int m_env_enable[2]; /* envelope generators enable */ 00107 int m_env_reverse_right[2]; /* envelope reversed for right channel */ 00108 int m_env_mode[2]; /* envelope generators mode */ 00109 int m_env_bits[2]; /* non zero = 3 bits resolution */ 00110 int m_env_clock[2]; /* envelope clock mode (non-zero external) */ 00111 int m_env_step[2]; /* current envelope step */ 00112 int m_all_ch_enable; /* all channels enable */ 00113 int m_sync_state; /* sync all channels */ 00114 int m_selected_reg; /* selected register */ 00115 saa1099_channel m_channels[6]; /* channels */ 00116 saa1099_noise m_noise[2]; /* noise generators */ 00117 double m_sample_rate; 00118 int m_master_clock; 00119 }; 00120 00121 DECLARE_DEVICE_TYPE(SAA1099, saa1099_device) 00122 00123 #endif // MAME_SOUND_SAA1099_H