1 /***************************************************************************
\r
2 externals.h - description
\r
4 begin : Wed May 15 2002
\r
5 copyright : (C) 2002 by Pete Bernert
\r
6 email : BlackDove@addcom.de
\r
7 ***************************************************************************/
\r
8 /***************************************************************************
\r
10 * This program is free software; you can redistribute it and/or modify *
\r
11 * it under the terms of the GNU General Public License as published by *
\r
12 * the Free Software Foundation; either version 2 of the License, or *
\r
13 * (at your option) any later version. See also the license.txt file for *
\r
14 * additional informations. *
\r
16 ***************************************************************************/
\r
20 /////////////////////////////////////////////////////////
\r
22 /////////////////////////////////////////////////////////
\r
25 #define noinline __attribute__((noinline))
\r
26 #define unlikely(x) __builtin_expect((x), 0)
\r
29 #define unlikely(x) x
\r
32 #define PSE_LT_SPU 4
\r
33 #define PSE_SPU_ERR_SUCCESS 0
\r
34 #define PSE_SPU_ERR -60
\r
35 #define PSE_SPU_ERR_NOTCONFIGURED PSE_SPU_ERR - 1
\r
36 #define PSE_SPU_ERR_INIT PSE_SPU_ERR - 2
\r
38 #define max(a,b) (((a) > (b)) ? (a) : (b))
\r
39 #define min(a,b) (((a) < (b)) ? (a) : (b))
\r
42 ////////////////////////////////////////////////////////////////////////
\r
44 ////////////////////////////////////////////////////////////////////////
\r
49 // note: must be even due to the way reverb works now
\r
50 #define NSSIZE ((44100 / 50 + 16) & ~1)
\r
52 ///////////////////////////////////////////////////////////
\r
54 ///////////////////////////////////////////////////////////
\r
63 // ADSR INFOS PER CHANNEL
\r
66 unsigned char State:2; // ADSR_State
\r
67 unsigned char AttackModeExp:1;
\r
68 unsigned char SustainModeExp:1;
\r
69 unsigned char SustainIncrease:1;
\r
70 unsigned char ReleaseModeExp:1;
\r
71 unsigned char AttackRate;
\r
72 unsigned char DecayRate;
\r
73 unsigned char SustainLevel;
\r
74 unsigned char SustainRate;
\r
75 unsigned char ReleaseRate;
\r
79 ///////////////////////////////////////////////////////////
\r
83 // used for debug channel muting
\r
86 // used for simple interpolation
\r
87 #define FLAG_IPOL0 2
\r
88 #define FLAG_IPOL1 4
\r
90 ///////////////////////////////////////////////////////////
\r
92 // MAIN CHANNEL STRUCT
\r
95 int iSBPos; // mixing stuff
\r
100 unsigned char * pCurr; // current pos in sound mem
\r
101 unsigned char * pLoop; // loop ptr in sound mem
\r
103 unsigned int bReverb:1; // can we do reverb on this channel? must have ctrl register bit, to get active
\r
104 unsigned int bRVBActive:1; // reverb active flag
\r
105 unsigned int bNoise:1; // noise active flag
\r
106 unsigned int bFMod:2; // freq mod (0=off, 1=sound channel, 2=freq channel)
\r
107 unsigned int prevflags:3; // flags from previous block
\r
109 int iLeftVolume; // left volume
\r
110 int iRightVolume; // right volume
\r
112 int iRawPitch; // raw pitch (0...3fff)
\r
115 ///////////////////////////////////////////////////////////
\r
119 int StartAddr; // reverb area start addr in samples
\r
120 int CurrAddr; // reverb area curr addr in samples
\r
127 int FB_SRC_A; // (offset)
\r
128 int FB_SRC_B; // (offset)
\r
129 int IIR_ALPHA; // (coef.)
\r
130 int ACC_COEF_A; // (coef.)
\r
131 int ACC_COEF_B; // (coef.)
\r
132 int ACC_COEF_C; // (coef.)
\r
133 int ACC_COEF_D; // (coef.)
\r
134 int IIR_COEF; // (coef.)
\r
135 int FB_ALPHA; // (coef.)
\r
136 int FB_X; // (coef.)
\r
137 int IIR_DEST_A0; // (offset)
\r
138 int IIR_DEST_A1; // (offset)
\r
139 int ACC_SRC_A0; // (offset)
\r
140 int ACC_SRC_A1; // (offset)
\r
141 int ACC_SRC_B0; // (offset)
\r
142 int ACC_SRC_B1; // (offset)
\r
143 int IIR_SRC_A0; // (offset)
\r
144 int IIR_SRC_A1; // (offset)
\r
145 int IIR_DEST_B0; // (offset)
\r
146 int IIR_DEST_B1; // (offset)
\r
147 int ACC_SRC_C0; // (offset)
\r
148 int ACC_SRC_C1; // (offset)
\r
149 int ACC_SRC_D0; // (offset)
\r
150 int ACC_SRC_D1; // (offset)
\r
151 int IIR_SRC_B1; // (offset)
\r
152 int IIR_SRC_B0; // (offset)
\r
153 int MIX_DEST_A0; // (offset)
\r
154 int MIX_DEST_A1; // (offset)
\r
155 int MIX_DEST_B0; // (offset)
\r
156 int MIX_DEST_B1; // (offset)
\r
157 int IN_COEF_L; // (coef.)
\r
158 int IN_COEF_R; // (coef.)
\r
160 int dirty; // registers changed
\r
162 // normalized offsets
\r
163 int nIIR_DEST_A0, nIIR_DEST_A1, nIIR_DEST_B0, nIIR_DEST_B1,
\r
164 nACC_SRC_A0, nACC_SRC_A1, nACC_SRC_B0, nACC_SRC_B1,
\r
165 nIIR_SRC_A0, nIIR_SRC_A1, nIIR_SRC_B0, nIIR_SRC_B1,
\r
166 nACC_SRC_C0, nACC_SRC_C1, nACC_SRC_D0, nACC_SRC_D1,
\r
167 nMIX_DEST_A0, nMIX_DEST_A1, nMIX_DEST_B0, nMIX_DEST_B1;
\r
168 // MIX_DEST_xx - FB_SRC_x
\r
169 int nFB_SRC_A0, nFB_SRC_A1, nFB_SRC_B0, nFB_SRC_B1;
\r
172 ///////////////////////////////////////////////////////////
\r
174 // psx buffers / addresses
\r
176 #define SB_SIZE (32 + 4)
\r
180 unsigned short spuCtrl;
\r
181 unsigned short spuStat;
\r
183 unsigned int spuAddr;
\r
185 unsigned char *spuMemC;
\r
186 unsigned short *spuMem;
\r
188 unsigned char * pSpuIrq;
\r
190 unsigned int cycles_played;
\r
192 int decode_dirty_ch;
\r
193 unsigned int bSpuInit:1;
\r
194 unsigned int bSPUIsOpen:1;
\r
196 unsigned int dwNoiseVal; // global noise generator
\r
197 unsigned int dwNoiseCount;
\r
198 unsigned int dwNewChannel; // flags for faster testing, if new channel starts
\r
199 unsigned int dwChannelOn; // not silent channels
\r
200 unsigned int dwChannelDead; // silent+not useful channels
\r
202 unsigned char * pSpuBuffer;
\r
205 void (CALLBACK *irqCallback)(void); // func of main emu, called on spu irq
\r
206 void (CALLBACK *cddavCallback)(unsigned short,unsigned short);
\r
207 void (CALLBACK *scheduleCallback)(unsigned int);
\r
209 xa_decode_t * xapGlobal;
\r
210 unsigned int * XAFeed;
\r
211 unsigned int * XAPlay;
\r
212 unsigned int * XAStart;
\r
213 unsigned int * XAEnd;
\r
215 unsigned int * CDDAFeed;
\r
216 unsigned int * CDDAPlay;
\r
217 unsigned int * CDDAStart;
\r
218 unsigned int * CDDAEnd;
\r
220 unsigned int XARepeat;
\r
221 unsigned int XALastVal;
\r
233 unsigned short regArea[0x400];
\r
236 ///////////////////////////////////////////////////////////
\r
238 ///////////////////////////////////////////////////////////
\r
242 extern SPUInfo spu;
\r
243 extern REVERBInfo rvb;
\r
245 void do_samples(unsigned int cycles_to, int do_sync);
\r
246 void schedule_next_irq(void);
\r
248 #define regAreaGet(ch,offset) \
\r
249 spu.regArea[((ch<<4)|(offset))>>1]
\r
251 #define do_samples_if_needed(c, sync) \
\r
253 if (sync || (int)((c) - spu.cycles_played) >= 16 * 768) \
\r
254 do_samples(c, sync); \
\r