Statistics
| Branch: | Revision:

root / hw / fmopl.h @ ff753bb9

History | View | Annotate | Download (6.5 kB)

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