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