some movies fixed
[fceu.git] / mappers / fmopl.h
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 1999,2000 Tatsuyuki Satoh
5  *  Copyright (C) 2001,2002 Ben Parnell
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
20  */
21 /* This file has been heavily modified from the original(mostly unused
22    code was removed).  If you want to use it for anything other than
23    VRC7 sound emulation, you should get the original from the AdPlug
24    source distribution or the MAME(version 0.37b16) source distribution
25    (but be careful about the different licenses).
26         - Xodnizel
27 */
28
29 #ifndef __FMOPL_H_
30 #define __FMOPL_H_
31
32 /* --- system optimize --- */
33 /* select bit size of output : 8 or 16 */
34 #define OPL_OUTPUT_BIT 16
35
36 /* compiler dependence */
37 #ifndef OSD_CPU_H
38 #define OSD_CPU_H
39
40 typedef unsigned char   UINT8;   /* unsigned  8bit */
41 typedef unsigned short  UINT16;  /* unsigned 16bit */
42 typedef unsigned long   UINT32;  /* unsigned 32bit */
43 typedef signed char             INT8;    /* signed  8bit   */
44 typedef signed short    INT16;   /* signed 16bit   */
45 typedef signed long             INT32;   /* signed 32bit   */
46 #endif
47
48 #if (OPL_OUTPUT_BIT==16)
49 typedef INT16 OPLSAMPLE;
50 #endif
51 #if (OPL_OUTPUT_BIT==8)
52 typedef unsigned char  OPLSAMPLE;
53 #endif
54
55
56 /* !!!!! here is private section , do not access there member direct !!!!! */
57
58 #define OPL_TYPE_WAVESEL   0x01  /* waveform select    */
59
60 /* Saving is necessary for member of the 'R' mark for suspend/resume */
61 /* ---------- OPL one of slot  ---------- */
62 typedef struct fm_opl_slot {
63         INT32 TL;               /* total level     :TL << 8            */
64         INT32 TLL;              /* adjusted now TL                     */
65         UINT8  KSR;             /* key scale rate  :(shift down bit)   */
66         INT32 *AR;              /* attack rate     :&AR_TABLE[AR<<2]   */
67         INT32 *DR;              /* decay rate      :&DR_TALBE[DR<<2]   */
68         INT32 SL;               /* sustin level    :SL_TALBE[SL]       */
69         INT32 *RR;              /* release rate    :&DR_TABLE[RR<<2]   */
70         UINT8 ksl;              /* keyscale level  :(shift down bits)  */
71         UINT8 ksr;              /* key scale rate  :kcode>>KSR         */
72         UINT32 mul;             /* multiple        :ML_TABLE[ML]       */
73         UINT32 Cnt;             /* frequency count :                   */
74         UINT32 Incr;    /* frequency step  :                   */
75         /* envelope generator state */
76         UINT8 eg_typ;   /* envelope type flag                  */
77         UINT8 evm;              /* envelope phase                      */
78         INT32 evc;              /* envelope counter                    */
79         INT32 eve;              /* envelope counter end point          */
80         INT32 evs;              /* envelope counter step               */
81         INT32 evsa;     /* envelope step for AR :AR[ksr]           */
82         INT32 evsd;     /* envelope step for DR :DR[ksr]           */
83         INT32 evsr;     /* envelope step for RR :RR[ksr]           */
84         /* LFO */
85         UINT8 ams;              /* ams flag                            */
86         UINT8 vib;              /* vibrate flag                        */
87         /* wave selector */
88         INT32 **wavetable;
89 }OPL_SLOT;
90
91 /* ---------- OPL one of channel  ---------- */
92 typedef struct fm_opl_channel {
93         OPL_SLOT SLOT[2];
94         UINT8 CON;                      /* connection type                     */
95         UINT8 FB;                       /* feed back       :(shift down bit)   */
96         INT32 *connect1;        /* slot1 output pointer                */
97         INT32 *connect2;        /* slot2 output pointer                */
98         INT32 op1_out[2];       /* slot1 output for selfeedback        */
99         /* phase generator state */
100         UINT32  block_fnum;     /* block+fnum      :                   */
101         UINT8 kcode;            /* key code        : KeyScaleCode      */
102         UINT32  fc;                     /* Freq. Increment base                */
103         UINT32  ksl_base;       /* KeyScaleLevel Base step             */
104         UINT8 keyon;            /* key on/off flag                     */
105 } OPL_CH;
106
107 /* OPL state */
108 typedef struct fm_opl_f {
109         UINT8 type;                     /* chip type                         */
110         int clock;                      /* master clock  (Hz)                */
111         int rate;                       /* sampling rate (Hz)                */
112         double freqbase;        /* frequency base                    */
113         double TimerBase;       /* Timer base time (==sampling time) */
114         UINT8 address;          /* address register                  */
115         UINT32 mode;            /* Reg.08 : CSM , notesel,etc.       */
116
117         /* FM channel slots */
118         OPL_CH *P_CH;           /* pointer of CH                     */
119         int     max_ch;                 /* maximum channel                   */
120
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
135 } FM_OPL;
136
137 /* ---------- Generic interface section ---------- */
138 #define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
139
140 FM_OPL *OPLCreate(int type, int clock, int rate);
141 void OPLDestroy(FM_OPL *OPL);
142
143 void OPLResetChip(FM_OPL *OPL);
144 void OPLWrite(FM_OPL *OPL,UINT8 a,UINT8 v);
145
146 /* YM3626/YM3812 local section */
147 void YM3812UpdateOne(FM_OPL *OPL, UINT32 *buffer, int length);
148
149 #endif