Subversion Repositories pentevo

Rev

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