fmopl.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #ifndef __FMOPL_H_
  2. #define __FMOPL_H_
  3. #ifdef _MSC_VER
  4. #pragma warning (disable:4018)
  5. #pragma warning (disable:4244)
  6. #pragma warning (disable:4996)
  7. #endif
  8. /* --- select emulation chips --- */
  9. #define BUILD_YM3812 (HAS_YM3812)
  10. //#define BUILD_YM3526 (HAS_YM3526)
  11. //#define BUILD_Y8950 (HAS_Y8950)
  12. /* --- system optimize --- */
  13. /* select bit size of output : 8 or 16 */
  14. #define OPL_OUTPUT_BIT 16
  15. /* compiler dependence */
  16. #ifndef OSD_CPU_H
  17. #define OSD_CPU_H
  18. typedef unsigned char UINT8; /* unsigned 8bit */
  19. typedef unsigned short UINT16; /* unsigned 16bit */
  20. typedef unsigned int UINT32; /* unsigned 32bit */
  21. typedef signed char INT8; /* signed 8bit */
  22. typedef signed short INT16; /* signed 16bit */
  23. typedef signed int INT32; /* signed 32bit */
  24. #endif
  25. #if (OPL_OUTPUT_BIT==16)
  26. typedef INT16 OPLSAMPLE;
  27. #endif
  28. #if (OPL_OUTPUT_BIT==8)
  29. typedef unsigned char OPLSAMPLE;
  30. #endif
  31. #if BUILD_Y8950
  32. #include "ymdeltat.h"
  33. #endif
  34. typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
  35. typedef void (*OPL_IRQHANDLER)(int param,int irq);
  36. typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
  37. typedef void (*OPL_PORTHANDLER_W)(int param,unsigned char data);
  38. typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
  39. /* !!!!! here is private section , do not access there member direct !!!!! */
  40. #define OPL_TYPE_WAVESEL 0x01 /* waveform select */
  41. #define OPL_TYPE_ADPCM 0x02 /* DELTA-T ADPCM unit */
  42. #define OPL_TYPE_KEYBOARD 0x04 /* keyboard interface */
  43. #define OPL_TYPE_IO 0x08 /* I/O port */
  44. /* Saving is necessary for member of the 'R' mark for suspend/resume */
  45. /* ---------- OPL one of slot ---------- */
  46. typedef struct fm_opl_slot {
  47. INT32 TL; /* total level :TL << 8 */
  48. INT32 TLL; /* adjusted now TL */
  49. UINT8 KSR; /* key scale rate :(shift down bit) */
  50. INT32 *AR; /* attack rate :&AR_TABLE[AR<<2] */
  51. INT32 *DR; /* decay rate :&DR_TALBE[DR<<2] */
  52. INT32 SL; /* sustin level :SL_TALBE[SL] */
  53. INT32 *RR; /* release rate :&DR_TABLE[RR<<2] */
  54. UINT8 ksl; /* keyscale level :(shift down bits) */
  55. UINT8 ksr; /* key scale rate :kcode>>KSR */
  56. UINT32 mul; /* multiple :ML_TABLE[ML] */
  57. UINT32 Cnt; /* frequency count : */
  58. UINT32 Incr; /* frequency step : */
  59. /* envelope generator state */
  60. UINT8 eg_typ; /* envelope type flag */
  61. UINT8 evm; /* envelope phase */
  62. INT32 evc; /* envelope counter */
  63. INT32 eve; /* envelope counter end point */
  64. INT32 evs; /* envelope counter step */
  65. INT32 evsa; /* envelope step for AR :AR[ksr] */
  66. INT32 evsd; /* envelope step for DR :DR[ksr] */
  67. INT32 evsr; /* envelope step for RR :RR[ksr] */
  68. /* LFO */
  69. UINT8 ams; /* ams flag */
  70. UINT8 vib; /* vibrate flag */
  71. /* wave selector */
  72. INT32 **wavetable;
  73. }OPL_SLOT;
  74. /* ---------- OPL one of channel ---------- */
  75. typedef struct fm_opl_channel {
  76. OPL_SLOT SLOT[2];
  77. UINT8 CON; /* connection type */
  78. UINT8 FB; /* feed back :(shift down bit) */
  79. INT32 *connect1; /* slot1 output pointer */
  80. INT32 *connect2; /* slot2 output pointer */
  81. INT32 op1_out[2]; /* slot1 output for selfeedback */
  82. /* phase generator state */
  83. UINT32 block_fnum; /* block+fnum : */
  84. UINT8 kcode; /* key code : KeyScaleCode */
  85. UINT32 fc; /* Freq. Increment base */
  86. UINT32 ksl_base; /* KeyScaleLevel Base step */
  87. UINT8 keyon; /* key on/off flag */
  88. } OPL_CH;
  89. /* OPL state */
  90. typedef struct fm_opl_f {
  91. UINT8 type; /* chip type */
  92. int clock; /* master clock (Hz) */
  93. int rate; /* sampling rate (Hz) */
  94. double freqbase; /* frequency base */
  95. double TimerBase; /* Timer base time (==sampling time) */
  96. UINT8 address; /* address register */
  97. UINT8 status; /* status flag */
  98. UINT8 statusmask; /* status mask */
  99. UINT32 mode; /* Reg.08 : CSM , notesel,etc. */
  100. /* Timer */
  101. int T[2]; /* timer counter */
  102. UINT8 st[2]; /* timer enable */
  103. /* FM channel slots */
  104. OPL_CH *P_CH; /* pointer of CH */
  105. int max_ch; /* maximum channel */
  106. /* Rythm sention */
  107. UINT8 rythm; /* Rythm mode , key flag */
  108. #if BUILD_Y8950
  109. /* Delta-T ADPCM unit (Y8950) */
  110. YM_DELTAT *deltat; /* DELTA-T ADPCM */
  111. #endif
  112. /* Keyboard / I/O interface unit (Y8950) */
  113. UINT8 portDirection;
  114. UINT8 portLatch;
  115. OPL_PORTHANDLER_R porthandler_r;
  116. OPL_PORTHANDLER_W porthandler_w;
  117. int port_param;
  118. OPL_PORTHANDLER_R keyboardhandler_r;
  119. OPL_PORTHANDLER_W keyboardhandler_w;
  120. int keyboard_param;
  121. /* time tables */
  122. INT32 AR_TABLE[75]; /* atttack rate tables */
  123. INT32 DR_TABLE[75]; /* decay rate tables */
  124. UINT32 FN_TABLE[1024]; /* fnumber -> increment counter */
  125. /* LFO */
  126. INT32 *ams_table;
  127. INT32 *vib_table;
  128. INT32 amsCnt;
  129. INT32 amsIncr;
  130. INT32 vibCnt;
  131. INT32 vibIncr;
  132. /* wave selector enable flag */
  133. UINT8 wavesel;
  134. /* external event callback handler */
  135. OPL_TIMERHANDLER TimerHandler; /* TIMER handler */
  136. int TimerParam; /* TIMER parameter */
  137. OPL_IRQHANDLER IRQHandler; /* IRQ handler */
  138. int IRQParam; /* IRQ parameter */
  139. OPL_UPDATEHANDLER UpdateHandler; /* stream update handler */
  140. int UpdateParam; /* stream update parameter */
  141. } FM_OPL;
  142. /* ---------- Generic interface section ---------- */
  143. #define OPL_TYPE_YM3526 (0)
  144. #define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
  145. #define OPL_TYPE_Y8950 (OPL_TYPE_ADPCM|OPL_TYPE_KEYBOARD|OPL_TYPE_IO)
  146. FM_OPL *OPLCreate(int type, int clock, int rate);
  147. void OPLDestroy(FM_OPL *OPL);
  148. void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset);
  149. void OPLSetIRQHandler(FM_OPL *OPL,OPL_IRQHANDLER IRQHandler,int param);
  150. void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int param);
  151. /* Y8950 port handlers */
  152. void OPLSetPortHandler(FM_OPL *OPL,OPL_PORTHANDLER_W PortHandler_w,OPL_PORTHANDLER_R PortHandler_r,int param);
  153. void OPLSetKeyboardHandler(FM_OPL *OPL,OPL_PORTHANDLER_W KeyboardHandler_w,OPL_PORTHANDLER_R KeyboardHandler_r,int param);
  154. void OPLResetChip(FM_OPL *OPL);
  155. int OPLWrite(FM_OPL *OPL,int a,int v);
  156. unsigned char OPLRead(FM_OPL *OPL,int a);
  157. int OPLTimerOver(FM_OPL *OPL,int c);
  158. /* YM3626/YM3812 local section */
  159. void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length);
  160. void Y8950UpdateOne(FM_OPL *OPL, INT16 *buffer, int length);
  161. #endif