Merge pull request #4852 from FernetMenta/aefixes
[vuplus_xbmc] / lib / snesapu / Types.h
1 //**************************************************************************************************
2 // Type Redefinitions
3 #ifndef SPC_TYPES_H
4 #define SPC_TYPES_H
5
6 /*
7  *      Copyright (C) 2005-2013 Team XBMC
8  *      http://xbmc.org
9  *
10  *  This Program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2, or (at your option)
13  *  any later version.
14  *
15  *  This Program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with XBMC; see the file COPYING.  If not, see
22  *  <http://www.gnu.org/licenses/>.
23  *
24  */
25
26 typedef void v0;
27
28 #ifdef  __cplusplus
29 #if defined __BORLANDC__
30 typedef bool b8;
31 #else
32 typedef unsigned char b8;
33 #endif
34 #else
35 typedef char b8;
36 #endif
37
38 typedef unsigned char u8;
39 typedef unsigned short u16;
40 typedef unsigned int u32;
41 #if defined _MSC_VER || defined __BORLANDC__
42 typedef unsigned __int64 u64;
43 #else
44 typedef unsigned long long int u64;
45 #endif
46
47 typedef char s8;
48 typedef short s16;
49 typedef int s32;
50 #if defined _MSC_VER || defined __BORLANDC__
51 typedef __int64 s64;
52 #else
53 typedef long long int s64;
54 #endif
55
56 typedef float f32;
57 typedef double f64;
58 typedef long double f80;
59
60 typedef struct DSPVoice
61 {
62         s8      volL;                                                                   //Volume Left
63         s8      volR;                                                                   //Volume Right
64         u16     pitch;                                                                  //Pitch (rate/32000) (3.11)
65         u8      srcn;                                                                   //Sound source being played back
66         u8      adsr[2];                                                                //Envelope rates for attack, decay, and sustain
67         u8      gain;                                                                   //Envelope gain (if not using ADSR)
68         s8      envx;                                                                   //Current envelope height (.7)
69         s8      outx;                                                                   //Current sample being output (-.7)
70         s8      __r[6];
71 } DSPVoice;
72
73 typedef struct SPCState
74 {
75         void    *pRAM;                                                          //[0.0] -> APU's RAM (64k)
76         u32             _r1;                                                            //[0.4] reserved
77         u16             pc;                                                                     //[0.8] Registers
78         u8              a,y,x;
79         u8              psw;
80         u16             sp;
81
82         u32             t8kHz,t64kHz;                                           //[1.0] # of cycles left until timer increase
83         u32             t64Cnt;                                                         //[1.8] # of 64kHz ticks since emulation began
84         u32             _r2;                                                            //[1.C] reserved
85         u8              upCnt[3];                                                       //[2.0] Up counters for counter increase
86         u8              portMod;                                                        //[2.3] Flags for in ports that have been modified
87         u8              outp[4];                                                        //[2.4] Out ports
88         u32             _r3[2];                                                         //[2.8] reserved
89 } SPCState;
90
91 typedef struct DSPFIR
92 {
93         s8      __r[15];
94         s8      c;                                                                              //Filter coefficient
95 } DSPFIR;
96
97 typedef union DSPReg
98 {
99         DSPVoice        voice[8];                                               //Voice registers
100
101         struct                                                                          //Global registers
102         {
103                 s8      __r00[12];
104                 s8      mvolL;                                                          //Main Volume Left (-.7)
105                 s8      efb;                                                            //Echo Feedback (-.7)
106                 s8      __r0E;
107                 s8      c0;                                                                     //FIR filter coefficent (-.7)
108
109                 s8      __r10[12];
110                 s8      mvolR;                                                          //Main Volume Right (-.7)
111                 s8      __r1D;
112                 s8      __r1E;
113                 s8      c1;
114
115                 s8      __r20[12];
116                 s8      evolL;                                                          //Echo Volume Left (-.7)
117                 u8      pmon;                                                           //Pitch Modulation on/off for each voice
118                 s8      __r2E;
119                 s8      c2;
120
121                 s8      __r30[12];
122                 s8      evolR;                                                          //Echo Volume Right (-.7)
123                 u8      non;                                                            //Noise output on/off for each voice
124                 s8      __r3E;
125                 s8      c3;
126
127                 s8      __r40[12];
128                 u8      kon;                                                            //Key On for each voice
129                 u8      eon;                                                            //Echo on/off for each voice
130                 s8      __r4E;
131                 s8      c4;
132
133                 s8      __r50[12];
134                 u8      kof;                                                            //Key Off for each voice (instantiates release mode)
135                 u8      dir;                                                            //Page containing source directory (wave table offsets)
136                 s8      __r5E;
137                 s8      c5;
138
139                 s8      __r60[12];
140                 u8      flg;                                                            //DSP flags and noise frequency
141                 u8      esa;                                                            //Starting page used to store echo waveform
142                 s8      __r6E;
143                 s8      c6;
144
145                 s8      __r70[12];
146                 u8      endx;                                                           //Waveform has ended
147                 u8      edl;                                                            //Echo Delay in ms >> 4
148                 s8      __r7E;
149                 s8      c7;
150         } u;
151
152         DSPFIR  fir[8];                                                         //FIR filter
153
154         u8              reg[128];
155 } DSPReg;
156
157 typedef struct Voice
158 {
159         //Voice -----------08
160         DSPVoice        *pVoice;                                                //-> voice registers in DSP
161         u32             _r;
162         //Waveform --------06
163         void    *bCur;                                                          //-> current block
164         u8              bHdr;                                                           //Block Header for current block
165         u8              mFlg;                                                           //Mixing flags (see MixF)
166         //Envelope --------22
167         u8              eMode;                                                          //[3-0] Current mode (see EnvM)
168                                                                                                 //[6-4] ADSR mode to switch into from Gain
169                                                                                                 //[7]   Envelope is idle
170         u8              eRIdx;                                                          //Index in RateTab (0-31)
171         u32             eRate;                                                          //Rate of envelope adjustment (16.16)
172         u32             eCnt;                                                           //Sample counter (16.16)
173         u32             eVal;                                                           //Current envelope value
174         s32             eAdj;                                                           //Amount to adjust envelope height
175         u32             eDest;                                                          //Envelope Destination
176         //Visualization ---08
177         s32             vMaxL;                                                          //Maximum absolute sample output
178         s32             vMaxR;
179         //Samples ---------52
180         s32             sP1;                                                            //Last sample decompressed (prev1)
181         s32             sP2;                                                            //Second to last sample (prev2)
182         s16             *sIdx;                                                          //-> current sample in sBuf
183         s16             sBufP[4];                                                       //Last 4 samples from previous block (needed for inter.)
184         s16             sBuf[16];                                                       //32 bytes for decompressed sample blocks
185         //Mixing ----------32
186         float mTgtL;                                                            //Target volume (floating-point routine only)
187         float           mTgtR;                                                          // "  "
188         s32             mChnL;                                                          //Channel Volume (-24.7)
189         s32             mChnR;                                                          // "  "
190         u32             mRate;                                                          //Pitch Rate after modulation (16.16)
191         u32             mDec;                                                           //Pitch Decimal (.16) (used as delta for interpolation)
192         u32             mOrgP;                                                          //Original pitch rate converted from the DSP (16.16)
193         s32             mOut;                                                           //Last sample output before chn vol (used for pitch mod)
194 } Voice;
195
196 typedef struct DSPState
197 {
198         DSPReg  *pDSP;                                                          //[0.0] -> DSP registers (128 bytes)
199         Voice   *pVoice;                                                        //[0.4] -> Internal mixing settings (1k)
200         void    *pEcho;                                                         //[0.8] -> echo buffer (bytes = sample rate * 1.92)
201         u32             _r1;                                                            //[0.C] reserved
202
203         u32             vMMaxL,vMMaxR;                                          //[1.0] Maximum output so far
204         u32             mAmp;                                                           //[1.8] Amplification
205         u8              vActive;                                                        //[1.C] Flags for each active voice
206         u8              _r2[3];                                                         //[1.D] reserved
207 } DSPState;
208
209 typedef enum
210 {
211   SPC_EMULATOR_UNKNOWN = 0,
212   SPC_EMULATOR_ZSNES,
213   SPC_EMULATOR_SNES9X
214 } SPC_EmulatorType;
215
216 typedef struct SPC_ID666
217 {
218   char songname[33];
219   char gametitle[33];
220   char dumper[17];
221   char comments[33];
222   char author[33];
223   int playtime;
224   int fadetime;
225   SPC_EmulatorType emulator;
226 } SPC_ID666;
227
228 //Interpolation routines -------------------
229         enum DSPInter
230         {
231                 INT_INVALID = -1,
232                 INT_NONE,                                                               //None
233                 INT_LINEAR,                                                             //Linear
234                 INT_CUBIC,                                                              //Cubic
235                 INT_GAUSS,                                                              //4-point Gaussian
236                 INT_SINC,                                                               //8-point Sinc
237                 INT_TOTAL
238         };
239
240         //DSP options ------------------------------
241         enum DSPOpts
242         {
243                 OPT_ANALOG,                                                             //Simulate anomalies of the analog hardware
244                 OPT_OLDSMP,                                                             //Old sample decompression routine
245                 OPT_SURND,                                                              //"Surround" sound
246                 OPT_REVERSE,                                                    //Reverse stereo samples
247                 OPT_NOECHO,                                                             //Disable echo
248                 OPT_FILTER                                                              //Pass each voice through an anti-aliasing filter
249         };
250
251         //Mixing routines (see DSP.Asm for details of each routine)
252         enum Mixing
253         {
254                 MIX_INVALID =   -1,
255                 MIX_NONE =              0,                                              //No mixing
256                 MIX_INT =               1,                                              //Use integer math
257                 MIX_FLOAT =             3                                               //Use floating-point math
258         };
259
260 #endif
261