Subversion Repositories pentevo

Rev

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

  1. /*
  2.    YM-2149F emulator for Unreal Speccy project
  3.    created under public domain license by SMT, jan.2006
  4. */
  5.  
  6.  
  7. #ifndef _SNDCHIP_H_INCLUDED
  8. #define _SNDCHIP_H_INCLUDED
  9.  
  10. #include "../sysdefs.h"
  11. #include "sndrender.h"
  12.  
  13. const unsigned SNDR_DEFAULT_AY_RATE = 1750000;
  14.                                                 //1774400; // original ZX-Spectrum soundchip clock fq
  15.  
  16. struct AYOUT;
  17. struct SNDCHIP_VOLTAB;
  18. struct SNDCHIP_PANTAB;
  19.  
  20. extern const char * const ay_chips[];
  21.  
  22. #ifdef __GNUC__
  23. #pragma pack(push,1)
  24. #else
  25. #pragma pack(push)
  26. #pragma pack(1) // envelope period (envT, R13-R14) has invalid word alignment
  27. #endif
  28. struct AYREGS
  29. {
  30.    unsigned short fA, fB, fC;
  31.    unsigned char noise, mix;
  32.    unsigned char vA, vB, vC;
  33.    unsigned short envT;
  34.    unsigned char env;
  35.    unsigned char portA, portB;
  36. };
  37. #pragma pack(pop)
  38.  
  39. class SNDCHIP : public SNDRENDER
  40. {
  41.  
  42.  public:
  43.  
  44.    YM2203 * Chip2203; //registers //Dexus
  45.    //FMSAMPLE FMbuf; //1 sample //Dexus
  46. #define FMBUFSIZE (1) //Alone Coder
  47.    FMSAMPLE FMbufs[FMBUFSIZE]; //Alone Coder
  48.    UINT16 FMbufN; //Alone Coder
  49.    int FMbufOUT; //1 sample for add to AY output //Alone Coder
  50.    UINT16 FMbufMUL; //conf.sound.ay/8192*0.7f //Alone Coder
  51.    float nextfmtickfloat,ayticks_per_fmtick; //Alone Coder
  52.    unsigned int nextfmtick; //Alone Coder
  53.  
  54.    enum CHIP_TYPE { CHIP_AY, CHIP_YM, CHIP_YM2203, CHIP_MAX }; //Dexus
  55.    static const char *get_chipname(CHIP_TYPE i) { return ay_chips[i]; }
  56.  
  57.    void set_chip(CHIP_TYPE type) { chiptype = type; }
  58.    void set_timings(unsigned system_clock_rate, unsigned chip_clock_rate, unsigned sample_rate);
  59.    void set_volumes(unsigned global_vol, const SNDCHIP_VOLTAB *voltab, const SNDCHIP_PANTAB *stereo);
  60.  
  61.    void reset(unsigned timestamp = 0); // call with default parameter, when context outside start_frame/end_frame block
  62.  
  63.    // 'render' is a function that converts array of register writes into PCM-buffer
  64. //[vv]   unsigned render(AYOUT *src, unsigned srclen, unsigned clk_ticks, bufptr_t dst);
  65.  
  66.    // set of functions that fills buffer in emulation progress
  67.    void start_frame(bufptr_t dst);
  68.    void select(unsigned char nreg);
  69.    void write(unsigned timestamp, unsigned char val);
  70.    unsigned char read();
  71.    unsigned end_frame(unsigned clk_ticks);
  72.  
  73.    SNDCHIP();
  74.  
  75.    // new start position as previous end position
  76.    // (continue to fill buffer)
  77.    void start_frame() { start_frame(dstpos); }
  78.  
  79.    // for monitoring, chip can't report this values
  80.    unsigned char get_activereg() { return activereg; }
  81.    unsigned char get_r13_reloaded() { return r13_reloaded; }
  82.    unsigned char get_reg(unsigned nreg) { return reg[nreg]; }
  83.    unsigned get_env() { return env; }
  84.  
  85.  private:
  86.  
  87.    unsigned t, ta, tb, tc, tn, te, env;
  88.    int denv;
  89.    unsigned bitA, bitB, bitC, bitN, ns;
  90.    unsigned bit0, bit1, bit2, bit3, bit4, bit5;
  91.    unsigned ea, eb, ec, va, vb, vc;
  92.    unsigned fa, fb, fc, fn, fe;
  93.    unsigned mult_const;
  94.  
  95.    unsigned char activereg, r13_reloaded;
  96.  
  97.    unsigned vols[6][32];
  98.    CHIP_TYPE chiptype;
  99.  
  100.    union {
  101.       unsigned char reg[16];
  102.       struct AYREGS r;
  103.    };
  104.  
  105.    unsigned chip_clock_rate, system_clock_rate;
  106.    uint64_t passed_chip_ticks, passed_clk_ticks;
  107.    void flush(unsigned chiptick);
  108.    void apply_regs(unsigned timestamp = 0);
  109. };
  110.  
  111. struct AYOUT
  112. {
  113.    unsigned timestamp; // in system ticks
  114.    unsigned char reg_num;
  115.    unsigned char reg_value;
  116.    unsigned char res1, res2; // padding
  117. };
  118.  
  119. // output volumes (#0000-#FFFF) for given envelope state or R8-R10 value
  120. // AY chip has only 16 different volume values, so v[0]=v[1], v[2]=v[3], ...
  121. struct SNDCHIP_VOLTAB
  122. {
  123.    unsigned v[32];
  124. };
  125.  
  126. // generator's channel panning, % (0-100)
  127. struct SNDCHIP_PANTAB
  128. {
  129.    unsigned raw[6];
  130.    // structured as 'struct { unsigned left, right; } chan[3]';
  131. };
  132.  
  133. extern const SNDCHIP_VOLTAB SNDR_VOL_AY_S;
  134. extern const SNDCHIP_VOLTAB SNDR_VOL_YM_S;
  135. extern const SNDCHIP_PANTAB SNDR_PAN_MONO_S;
  136. extern const SNDCHIP_PANTAB SNDR_PAN_ABC_S;
  137. extern const SNDCHIP_PANTAB SNDR_PAN_ACB_S;
  138. extern const SNDCHIP_PANTAB SNDR_PAN_BAC_S;
  139. extern const SNDCHIP_PANTAB SNDR_PAN_BCA_S;
  140. extern const SNDCHIP_PANTAB SNDR_PAN_CAB_S;
  141. extern const SNDCHIP_PANTAB SNDR_PAN_CBA_S;
  142.  
  143. // used as parameters to SNDCHIP::set_volumes(),
  144. // if application don't want to override defaults
  145. const SNDCHIP_VOLTAB * const SNDR_VOL_AY = &SNDR_VOL_AY_S;
  146. const SNDCHIP_VOLTAB * const SNDR_VOL_YM = &SNDR_VOL_YM_S;
  147. const SNDCHIP_PANTAB * const SNDR_PAN_MONO = &SNDR_PAN_MONO_S;
  148. const SNDCHIP_PANTAB * const SNDR_PAN_ABC = &SNDR_PAN_ABC_S;
  149. const SNDCHIP_PANTAB * const SNDR_PAN_ACB = &SNDR_PAN_ACB_S;
  150. const SNDCHIP_PANTAB * const SNDR_PAN_BAC = &SNDR_PAN_BAC_S;
  151. const SNDCHIP_PANTAB * const SNDR_PAN_BCA = &SNDR_PAN_BCA_S;
  152. const SNDCHIP_PANTAB * const SNDR_PAN_CAB = &SNDR_PAN_CAB_S;
  153. const SNDCHIP_PANTAB * const SNDR_PAN_CBA = &SNDR_PAN_CBA_S;
  154.  
  155. #endif // _SNDCHIP_H_INCLUDED
  156.