Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. #pragma once
  2.  
  3. #ifndef __SAA1099_H__
  4. #define __SAA1099_H__
  5.  
  6. #include "../sysdefs.h"
  7. #include "sndrender.h"
  8.  
  9. /**********************************************
  10.     Philips SAA1099 Sound driver
  11. **********************************************/
  12. /* this structure defines a channel */
  13. struct saa1099_channel
  14. {
  15.     int frequency;          /* frequency (0x00..0xff) */
  16.     int freq_enable;        /* frequency enable */
  17.     int noise_enable;       /* noise enable */
  18.     int octave;             /* octave (0x00..0x07) */
  19.     int amplitude[2];       /* value from amplitude lookup table */
  20.     int amp[2];             /* amplitude (0x00..0x0f) */
  21.     int envelope[2];        /* envelope (0x00..0x0f or 0x10 == off) */
  22.  
  23.     /* vars to simulate the square wave */
  24.     double counter;
  25.     double freq;
  26.     int level;
  27. };
  28.  
  29. /* this structure defines a noise channel */
  30. struct saa1099_noise
  31. {
  32.     /* vars to simulate the noise generator output */
  33.     double counter;
  34.     double freq;
  35.     int level;                      /* noise polynomal shifter */
  36. };
  37.  
  38. /* this structure defines a SAA1099 chip */
  39. struct saa1099_state
  40. {
  41. //    running_device *device;
  42. //    sound_stream * stream;          /* our stream */
  43.     int noise_params[2];            /* noise generators parameters */
  44.     int env_enable[2];              /* envelope generators enable */
  45.     int env_reverse_right[2];       /* envelope reversed for right channel */
  46.     int env_reverse_right_buf[2];   /* envelope reversed for right channel buffered value */
  47.     int env_mode[2];                /* envelope generators mode */
  48.     int env_mode_buf[2];            /* envelope generators mode buffered value */
  49.     int env_bits[2];                /* non zero = 3 bits resolution */
  50.     int env_clock[2];               /* envelope clock mode (non-zero external) */
  51.     int env_clock_buf[2];           /* envelope clock mode (non-zero external) buffered value */
  52.     int env_step[2];                /* current envelope step */
  53.     bool env_upd[2];                // true if buffered data present
  54.     int all_ch_enable;              /* all channels enable */
  55.     int sync_state;                 /* sync all channels */
  56.     int selected_reg;               /* selected register */
  57.     saa1099_channel channels[6];    /* channels */
  58.     saa1099_noise noise[2]; /* noise generators */
  59.     double sample_rate;
  60. };
  61.  
  62. // 8MHz in sam coupe
  63. class TSaa1099 : public saa1099_state,  public SNDRENDER
  64. {
  65. private:
  66.    unsigned chip_clock_rate;
  67.    unsigned system_clock_rate;
  68.    uint64_t passed_chip_ticks;
  69.    uint64_t passed_clk_ticks;
  70.  
  71.    unsigned t;
  72. public:
  73.    TSaa1099();
  74.  
  75.    void set_timings(unsigned system_clock_rate, unsigned chip_clock_rate, unsigned sample_rate);
  76.    void reset(unsigned TimeStamp = 0);
  77.  
  78.    // set of functions that fills buffer in emulation progress
  79.    void start_frame() { SNDRENDER::start_frame(); }
  80.    void start_frame(bufptr_t dst);
  81.    unsigned end_frame(unsigned clk_ticks);
  82.    void WrCtl(u8 Val);
  83.    void WrData(unsigned TimeStamp, u8 Val);
  84. private:
  85.    void update(unsigned TimeStamp);
  86.    void flush(unsigned chiptick);
  87. };
  88.  
  89. extern TSaa1099 Saa1099;
  90.  
  91. //void saa1099_control_w(ATTR_UNUSED device_t *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT8 data);
  92. //void saa1099_data_w(ATTR_UNUSED device_t *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT8 data);
  93.  
  94. #endif /* __SAA1099_H__ */
  95.