Commit | Line | Data |
---|---|---|
ef79bbde P |
1 | /***************************************************************************\r |
2 | registers.c - description\r | |
3 | -------------------\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 | |
9 | * *\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 | |
15 | * *\r | |
16 | ***************************************************************************/\r | |
17 | \r | |
18 | #include "stdafx.h"\r | |
19 | \r | |
20 | #define _IN_REGISTERS\r | |
21 | \r | |
22 | #include "externals.h"\r | |
23 | #include "registers.h"\r | |
ef79bbde P |
24 | \r |
25 | /*\r | |
26 | // adsr time values (in ms) by James Higgs ... see the end of\r | |
27 | // the adsr.c source for details\r | |
28 | \r | |
29 | #define ATTACK_MS 514L\r | |
30 | #define DECAYHALF_MS 292L\r | |
31 | #define DECAY_MS 584L\r | |
32 | #define SUSTAIN_MS 450L\r | |
33 | #define RELEASE_MS 446L\r | |
34 | */\r | |
35 | \r | |
36 | // we have a timebase of 1.020408f ms, not 1 ms... so adjust adsr defines\r | |
37 | #define ATTACK_MS 494L\r | |
38 | #define DECAYHALF_MS 286L\r | |
39 | #define DECAY_MS 572L\r | |
40 | #define SUSTAIN_MS 441L\r | |
41 | #define RELEASE_MS 437L\r | |
42 | \r | |
7e44d49d | 43 | static void SoundOn(int start,int end,unsigned short val);\r |
44 | static void SoundOff(int start,int end,unsigned short val);\r | |
45 | static void FModOn(int start,int end,unsigned short val);\r | |
46 | static void NoiseOn(int start,int end,unsigned short val);\r | |
47 | static void SetVolumeL(unsigned char ch,short vol);\r | |
48 | static void SetVolumeR(unsigned char ch,short vol);\r | |
49 | static void SetPitch(int ch,unsigned short val);\r | |
50 | static void ReverbOn(int start,int end,unsigned short val);\r | |
51 | \r | |
ef79bbde P |
52 | ////////////////////////////////////////////////////////////////////////\r |
53 | // WRITE REGISTERS: called by main emu\r | |
54 | ////////////////////////////////////////////////////////////////////////\r | |
55 | \r | |
56 | void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val)\r | |
57 | {\r | |
58 | const unsigned long r=reg&0xfff;\r | |
59 | regArea[(r-0xc00)>>1] = val;\r | |
60 | \r | |
61 | if(r>=0x0c00 && r<0x0d80) // some channel info?\r | |
62 | {\r | |
63 | int ch=(r>>4)-0xc0; // calc channel\r | |
64 | switch(r&0x0f)\r | |
65 | {\r | |
66 | //------------------------------------------------// r volume\r | |
67 | case 0: \r | |
68 | SetVolumeL((unsigned char)ch,val);\r | |
69 | break;\r | |
70 | //------------------------------------------------// l volume\r | |
71 | case 2: \r | |
72 | SetVolumeR((unsigned char)ch,val);\r | |
73 | break;\r | |
74 | //------------------------------------------------// pitch\r | |
75 | case 4: \r | |
76 | SetPitch(ch,val);\r | |
77 | break;\r | |
78 | //------------------------------------------------// start\r | |
79 | case 6: \r | |
7e44d49d | 80 | // taken from regArea later\r |
ef79bbde P |
81 | break;\r |
82 | //------------------------------------------------// level with pre-calcs\r | |
83 | case 8:\r | |
84 | {\r | |
6d866bb7 | 85 | const unsigned long lval=val;\r |
ef79bbde P |
86 | //---------------------------------------------//\r |
87 | s_chan[ch].ADSRX.AttackModeExp=(lval&0x8000)?1:0; \r | |
88 | s_chan[ch].ADSRX.AttackRate=(lval>>8) & 0x007f;\r | |
89 | s_chan[ch].ADSRX.DecayRate=(lval>>4) & 0x000f;\r | |
90 | s_chan[ch].ADSRX.SustainLevel=lval & 0x000f;\r | |
91 | //---------------------------------------------//\r | |
6d866bb7 | 92 | #if 0\r |
ef79bbde P |
93 | if(!iDebugMode) break;\r |
94 | //---------------------------------------------// stuff below is only for debug mode\r | |
95 | \r | |
96 | s_chan[ch].ADSR.AttackModeExp=(lval&0x8000)?1:0; //0x007f\r | |
97 | \r | |
98 | lx=(((lval>>8) & 0x007f)>>2); // attack time to run from 0 to 100% volume\r | |
99 | lx=min(31,lx); // no overflow on shift!\r | |
100 | if(lx) \r | |
101 | { \r | |
102 | lx = (1<<lx);\r | |
103 | if(lx<2147483) lx=(lx*ATTACK_MS)/10000L; // another overflow check\r | |
104 | else lx=(lx/10000L)*ATTACK_MS;\r | |
105 | if(!lx) lx=1;\r | |
106 | }\r | |
107 | s_chan[ch].ADSR.AttackTime=lx; \r | |
108 | \r | |
109 | s_chan[ch].ADSR.SustainLevel= // our adsr vol runs from 0 to 1024, so scale the sustain level\r | |
110 | (1024*((lval) & 0x000f))/15;\r | |
111 | \r | |
112 | lx=(lval>>4) & 0x000f; // decay:\r | |
113 | if(lx) // our const decay value is time it takes from 100% to 0% of volume\r | |
114 | {\r | |
115 | lx = ((1<<(lx))*DECAY_MS)/10000L;\r | |
116 | if(!lx) lx=1;\r | |
117 | }\r | |
118 | s_chan[ch].ADSR.DecayTime = // so calc how long does it take to run from 100% to the wanted sus level\r | |
119 | (lx*(1024-s_chan[ch].ADSR.SustainLevel))/1024;\r | |
6d866bb7 | 120 | #endif\r |
ef79bbde P |
121 | }\r |
122 | break;\r | |
123 | //------------------------------------------------// adsr times with pre-calcs\r | |
124 | case 10:\r | |
125 | {\r | |
6d866bb7 | 126 | const unsigned long lval=val;\r |
ef79bbde P |
127 | \r |
128 | //----------------------------------------------//\r | |
129 | s_chan[ch].ADSRX.SustainModeExp = (lval&0x8000)?1:0;\r | |
130 | s_chan[ch].ADSRX.SustainIncrease= (lval&0x4000)?0:1;\r | |
131 | s_chan[ch].ADSRX.SustainRate = (lval>>6) & 0x007f;\r | |
132 | s_chan[ch].ADSRX.ReleaseModeExp = (lval&0x0020)?1:0;\r | |
133 | s_chan[ch].ADSRX.ReleaseRate = lval & 0x001f;\r | |
134 | //----------------------------------------------//\r | |
6d866bb7 | 135 | #if 0\r |
ef79bbde P |
136 | if(!iDebugMode) break;\r |
137 | //----------------------------------------------// stuff below is only for debug mode\r | |
138 | \r | |
139 | s_chan[ch].ADSR.SustainModeExp = (lval&0x8000)?1:0;\r | |
140 | s_chan[ch].ADSR.ReleaseModeExp = (lval&0x0020)?1:0;\r | |
141 | \r | |
142 | lx=((((lval>>6) & 0x007f)>>2)); // sustain time... often very high\r | |
143 | lx=min(31,lx); // values are used to hold the volume\r | |
144 | if(lx) // until a sound stop occurs\r | |
145 | { // the highest value we reach (due to \r | |
146 | lx = (1<<lx); // overflow checking) is: \r | |
147 | if(lx<2147483) lx=(lx*SUSTAIN_MS)/10000L; // 94704 seconds = 1578 minutes = 26 hours... \r | |
148 | else lx=(lx/10000L)*SUSTAIN_MS; // should be enuff... if the stop doesn't \r | |
149 | if(!lx) lx=1; // come in this time span, I don't care :)\r | |
150 | }\r | |
151 | s_chan[ch].ADSR.SustainTime = lx;\r | |
152 | \r | |
153 | lx=(lval & 0x001f);\r | |
154 | s_chan[ch].ADSR.ReleaseVal =lx;\r | |
155 | if(lx) // release time from 100% to 0%\r | |
156 | { // note: the release time will be\r | |
157 | lx = (1<<lx); // adjusted when a stop is coming,\r | |
158 | if(lx<2147483) lx=(lx*RELEASE_MS)/10000L; // so at this time the adsr vol will \r | |
159 | else lx=(lx/10000L)*RELEASE_MS; // run from (current volume) to 0%\r | |
160 | if(!lx) lx=1;\r | |
161 | }\r | |
162 | s_chan[ch].ADSR.ReleaseTime=lx;\r | |
163 | \r | |
164 | if(lval & 0x4000) // add/dec flag\r | |
165 | s_chan[ch].ADSR.SustainModeDec=-1;\r | |
166 | else s_chan[ch].ADSR.SustainModeDec=1;\r | |
6d866bb7 | 167 | #endif\r |
ef79bbde P |
168 | }\r |
169 | break;\r | |
170 | //------------------------------------------------// adsr volume... mmm have to investigate this\r | |
171 | case 12:\r | |
172 | break;\r | |
173 | //------------------------------------------------//\r | |
174 | case 14: // loop?\r | |
7e44d49d | 175 | s_chan[ch].pLoop=spuMemC+((val&~1)<<3);\r |
be1cb678 | 176 | if(s_chan[ch].bJump)\r |
177 | // real machine would be most likely still doing the last block and use new value for the jump;\r | |
178 | // but we decode ahead a bit and already did the jump part, so compensate for that now.\r | |
179 | s_chan[ch].pCurr=s_chan[ch].pLoop;\r | |
ef79bbde P |
180 | break;\r |
181 | //------------------------------------------------//\r | |
182 | }\r | |
183 | iSpuAsyncWait=0;\r | |
184 | return;\r | |
185 | }\r | |
186 | \r | |
187 | switch(r)\r | |
188 | {\r | |
189 | //-------------------------------------------------//\r | |
190 | case H_SPUaddr:\r | |
191 | spuAddr = (unsigned long) val<<3;\r | |
192 | break;\r | |
193 | //-------------------------------------------------//\r | |
194 | case H_SPUdata:\r | |
195 | spuMem[spuAddr>>1] = val;\r | |
196 | spuAddr+=2;\r | |
197 | if(spuAddr>0x7ffff) spuAddr=0;\r | |
198 | break;\r | |
199 | //-------------------------------------------------//\r | |
200 | case H_SPUctrl:\r | |
3fc2a4c2 | 201 | if(!(spuCtrl & CTRL_IRQ))\r |
202 | spuStat&=~STAT_IRQ;\r | |
ef79bbde P |
203 | spuCtrl=val;\r |
204 | break;\r | |
205 | //-------------------------------------------------//\r | |
206 | case H_SPUstat:\r | |
207 | spuStat=val & 0xf800;\r | |
208 | break;\r | |
209 | //-------------------------------------------------//\r | |
210 | case H_SPUReverbAddr:\r | |
211 | if(val==0xFFFF || val<=0x200)\r | |
212 | {rvb.StartAddr=rvb.CurrAddr=0;}\r | |
213 | else\r | |
214 | {\r | |
215 | const long iv=(unsigned long)val<<2;\r | |
216 | if(rvb.StartAddr!=iv)\r | |
217 | {\r | |
218 | rvb.StartAddr=(unsigned long)val<<2;\r | |
219 | rvb.CurrAddr=rvb.StartAddr;\r | |
220 | }\r | |
221 | }\r | |
1775933a | 222 | rvb.dirty = 1;\r |
ef79bbde P |
223 | break;\r |
224 | //-------------------------------------------------//\r | |
225 | case H_SPUirqAddr:\r | |
226 | spuIrq = val;\r | |
3fc2a4c2 | 227 | pSpuIrq=spuMemC+(((unsigned long) val<<3)&~0xf);\r |
ef79bbde P |
228 | break;\r |
229 | //-------------------------------------------------//\r | |
230 | case H_SPUrvolL:\r | |
231 | rvb.VolLeft=val;\r | |
232 | break;\r | |
233 | //-------------------------------------------------//\r | |
234 | case H_SPUrvolR:\r | |
235 | rvb.VolRight=val;\r | |
236 | break;\r | |
237 | //-------------------------------------------------//\r | |
238 | \r | |
239 | /*\r | |
240 | case H_ExtLeft:\r | |
241 | //auxprintf("EL %d\n",val);\r | |
242 | break;\r | |
243 | //-------------------------------------------------//\r | |
244 | case H_ExtRight:\r | |
245 | //auxprintf("ER %d\n",val);\r | |
246 | break;\r | |
247 | //-------------------------------------------------//\r | |
248 | case H_SPUmvolL:\r | |
249 | //auxprintf("ML %d\n",val);\r | |
250 | break;\r | |
251 | //-------------------------------------------------//\r | |
252 | case H_SPUmvolR:\r | |
253 | //auxprintf("MR %d\n",val);\r | |
254 | break;\r | |
255 | //-------------------------------------------------//\r | |
256 | case H_SPUMute1:\r | |
257 | //auxprintf("M0 %04x\n",val);\r | |
258 | break;\r | |
259 | //-------------------------------------------------//\r | |
260 | case H_SPUMute2:\r | |
261 | //auxprintf("M1 %04x\n",val);\r | |
262 | break;\r | |
263 | */\r | |
264 | //-------------------------------------------------//\r | |
265 | case H_SPUon1:\r | |
266 | SoundOn(0,16,val);\r | |
267 | break;\r | |
268 | //-------------------------------------------------//\r | |
269 | case H_SPUon2:\r | |
270 | SoundOn(16,24,val);\r | |
271 | break;\r | |
272 | //-------------------------------------------------//\r | |
273 | case H_SPUoff1:\r | |
274 | SoundOff(0,16,val);\r | |
275 | break;\r | |
276 | //-------------------------------------------------//\r | |
277 | case H_SPUoff2:\r | |
278 | SoundOff(16,24,val);\r | |
279 | break;\r | |
280 | //-------------------------------------------------//\r | |
281 | case H_CDLeft:\r | |
282 | iLeftXAVol=val & 0x7fff;\r | |
283 | if(cddavCallback) cddavCallback(0,val);\r | |
284 | break;\r | |
285 | case H_CDRight:\r | |
286 | iRightXAVol=val & 0x7fff;\r | |
287 | if(cddavCallback) cddavCallback(1,val);\r | |
288 | break;\r | |
289 | //-------------------------------------------------//\r | |
290 | case H_FMod1:\r | |
291 | FModOn(0,16,val);\r | |
292 | break;\r | |
293 | //-------------------------------------------------//\r | |
294 | case H_FMod2:\r | |
295 | FModOn(16,24,val);\r | |
296 | break;\r | |
297 | //-------------------------------------------------//\r | |
298 | case H_Noise1:\r | |
299 | NoiseOn(0,16,val);\r | |
300 | break;\r | |
301 | //-------------------------------------------------//\r | |
302 | case H_Noise2:\r | |
303 | NoiseOn(16,24,val);\r | |
304 | break;\r | |
305 | //-------------------------------------------------//\r | |
306 | case H_RVBon1:\r | |
307 | ReverbOn(0,16,val);\r | |
308 | break;\r | |
309 | //-------------------------------------------------//\r | |
310 | case H_RVBon2:\r | |
311 | ReverbOn(16,24,val);\r | |
312 | break;\r | |
313 | //-------------------------------------------------//\r | |
1775933a | 314 | case H_Reverb+0 : rvb.FB_SRC_A=val*4; break;\r |
315 | case H_Reverb+2 : rvb.FB_SRC_B=val*4; break;\r | |
ef79bbde P |
316 | case H_Reverb+4 : rvb.IIR_ALPHA=(short)val; break;\r |
317 | case H_Reverb+6 : rvb.ACC_COEF_A=(short)val; break;\r | |
318 | case H_Reverb+8 : rvb.ACC_COEF_B=(short)val; break;\r | |
319 | case H_Reverb+10 : rvb.ACC_COEF_C=(short)val; break;\r | |
320 | case H_Reverb+12 : rvb.ACC_COEF_D=(short)val; break;\r | |
321 | case H_Reverb+14 : rvb.IIR_COEF=(short)val; break;\r | |
322 | case H_Reverb+16 : rvb.FB_ALPHA=(short)val; break;\r | |
323 | case H_Reverb+18 : rvb.FB_X=(short)val; break;\r | |
1775933a | 324 | case H_Reverb+20 : rvb.IIR_DEST_A0=val*4; break;\r |
325 | case H_Reverb+22 : rvb.IIR_DEST_A1=val*4; break;\r | |
326 | case H_Reverb+24 : rvb.ACC_SRC_A0=val*4; break;\r | |
327 | case H_Reverb+26 : rvb.ACC_SRC_A1=val*4; break;\r | |
328 | case H_Reverb+28 : rvb.ACC_SRC_B0=val*4; break;\r | |
329 | case H_Reverb+30 : rvb.ACC_SRC_B1=val*4; break;\r | |
330 | case H_Reverb+32 : rvb.IIR_SRC_A0=val*4; break;\r | |
331 | case H_Reverb+34 : rvb.IIR_SRC_A1=val*4; break;\r | |
332 | case H_Reverb+36 : rvb.IIR_DEST_B0=val*4; break;\r | |
333 | case H_Reverb+38 : rvb.IIR_DEST_B1=val*4; break;\r | |
334 | case H_Reverb+40 : rvb.ACC_SRC_C0=val*4; break;\r | |
335 | case H_Reverb+42 : rvb.ACC_SRC_C1=val*4; break;\r | |
336 | case H_Reverb+44 : rvb.ACC_SRC_D0=val*4; break;\r | |
337 | case H_Reverb+46 : rvb.ACC_SRC_D1=val*4; break;\r | |
338 | case H_Reverb+48 : rvb.IIR_SRC_B1=val*4; break;\r | |
339 | case H_Reverb+50 : rvb.IIR_SRC_B0=val*4; break;\r | |
340 | case H_Reverb+52 : rvb.MIX_DEST_A0=val*4; break;\r | |
341 | case H_Reverb+54 : rvb.MIX_DEST_A1=val*4; break;\r | |
342 | case H_Reverb+56 : rvb.MIX_DEST_B0=val*4; break;\r | |
343 | case H_Reverb+58 : rvb.MIX_DEST_B1=val*4; break;\r | |
ef79bbde P |
344 | case H_Reverb+60 : rvb.IN_COEF_L=(short)val; break;\r |
345 | case H_Reverb+62 : rvb.IN_COEF_R=(short)val; break;\r | |
346 | }\r | |
347 | \r | |
1775933a | 348 | if ((r & ~0x3f) == H_Reverb)\r |
349 | rvb.dirty = 1; // recalculate on next update\r | |
350 | \r | |
ef79bbde P |
351 | iSpuAsyncWait=0;\r |
352 | }\r | |
353 | \r | |
354 | ////////////////////////////////////////////////////////////////////////\r | |
355 | // READ REGISTER: called by main emu\r | |
356 | ////////////////////////////////////////////////////////////////////////\r | |
357 | \r | |
358 | unsigned short CALLBACK SPUreadRegister(unsigned long reg)\r | |
359 | {\r | |
360 | const unsigned long r=reg&0xfff;\r | |
361 | \r | |
362 | iSpuAsyncWait=0;\r | |
363 | \r | |
364 | if(r>=0x0c00 && r<0x0d80)\r | |
365 | {\r | |
366 | switch(r&0x0f)\r | |
367 | {\r | |
368 | case 12: // get adsr vol\r | |
369 | {\r | |
370 | const int ch=(r>>4)-0xc0;\r | |
6d866bb7 | 371 | if(dwNewChannel&(1<<ch)) return 1; // we are started, but not processed? return 1\r |
372 | if((dwChannelOn&(1<<ch)) && // same here... we haven't decoded one sample yet, so no envelope yet. return 1 as well\r | |
373 | !s_chan[ch].ADSRX.EnvelopeVol)\r | |
ef79bbde P |
374 | return 1;\r |
375 | return (unsigned short)(s_chan[ch].ADSRX.EnvelopeVol>>16);\r | |
376 | }\r | |
377 | \r | |
378 | case 14: // get loop address\r | |
379 | {\r | |
380 | const int ch=(r>>4)-0xc0;\r | |
ef79bbde P |
381 | return (unsigned short)((s_chan[ch].pLoop-spuMemC)>>3);\r |
382 | }\r | |
383 | }\r | |
384 | }\r | |
385 | \r | |
386 | switch(r)\r | |
387 | {\r | |
388 | case H_SPUctrl:\r | |
389 | return spuCtrl;\r | |
390 | \r | |
391 | case H_SPUstat:\r | |
392 | return spuStat;\r | |
393 | \r | |
394 | case H_SPUaddr:\r | |
395 | return (unsigned short)(spuAddr>>3);\r | |
396 | \r | |
397 | case H_SPUdata:\r | |
398 | {\r | |
399 | unsigned short s=spuMem[spuAddr>>1];\r | |
400 | spuAddr+=2;\r | |
401 | if(spuAddr>0x7ffff) spuAddr=0;\r | |
402 | return s;\r | |
403 | }\r | |
404 | \r | |
405 | case H_SPUirqAddr:\r | |
406 | return spuIrq;\r | |
407 | \r | |
408 | //case H_SPUIsOn1:\r | |
409 | // return IsSoundOn(0,16);\r | |
410 | \r | |
411 | //case H_SPUIsOn2:\r | |
412 | // return IsSoundOn(16,24);\r | |
413 | \r | |
414 | }\r | |
415 | \r | |
416 | return regArea[(r-0xc00)>>1];\r | |
417 | }\r | |
418 | \r | |
419 | ////////////////////////////////////////////////////////////////////////\r | |
420 | // SOUND ON register write\r | |
421 | ////////////////////////////////////////////////////////////////////////\r | |
422 | \r | |
7e44d49d | 423 | static void SoundOn(int start,int end,unsigned short val)\r |
ef79bbde P |
424 | {\r |
425 | int ch;\r | |
426 | \r | |
427 | for(ch=start;ch<end;ch++,val>>=1) // loop channels\r | |
428 | {\r | |
77d6fd63 | 429 | if((val&1) && regAreaGet(ch,6)) // mmm... start has to be set before key on !?!\r |
ef79bbde | 430 | {\r |
b00afb77 | 431 | // do this here, not in StartSound\r |
432 | // - fixes fussy timing issues\r | |
433 | s_chan[ch].bStop=0;\r | |
77d6fd63 | 434 | s_chan[ch].pCurr=spuMemC+((regAreaGet(ch,6)&~1)<<3); // must be block aligned\r |
435 | s_chan[ch].pLoop=spuMemC+((regAreaGet(ch,14)&~1)<<3);\r | |
be1cb678 | 436 | s_chan[ch].bJump=0;\r |
b00afb77 | 437 | \r |
ef79bbde | 438 | dwNewChannel|=(1<<ch); // bitfield for faster testing\r |
6d866bb7 | 439 | dwChannelOn|=1<<ch;\r |
174c454a | 440 | dwChannelDead&=~(1<<ch);\r |
ef79bbde P |
441 | }\r |
442 | }\r | |
443 | }\r | |
444 | \r | |
445 | ////////////////////////////////////////////////////////////////////////\r | |
446 | // SOUND OFF register write\r | |
447 | ////////////////////////////////////////////////////////////////////////\r | |
448 | \r | |
7e44d49d | 449 | static void SoundOff(int start,int end,unsigned short val)\r |
ef79bbde P |
450 | {\r |
451 | int ch;\r | |
452 | for(ch=start;ch<end;ch++,val>>=1) // loop channels\r | |
453 | {\r | |
454 | if(val&1) // && s_chan[i].bOn) mmm...\r | |
455 | {\r | |
456 | s_chan[ch].bStop=1;\r | |
b00afb77 | 457 | \r |
458 | // Jungle Book - Rhythm 'n Groove\r | |
459 | // - turns off buzzing sound (loop hangs)\r | |
b00afb77 | 460 | dwNewChannel &= ~(1<<ch);\r |
ef79bbde P |
461 | } \r |
462 | }\r | |
463 | }\r | |
464 | \r | |
465 | ////////////////////////////////////////////////////////////////////////\r | |
466 | // FMOD register write\r | |
467 | ////////////////////////////////////////////////////////////////////////\r | |
468 | \r | |
7e44d49d | 469 | static void FModOn(int start,int end,unsigned short val)\r |
ef79bbde P |
470 | {\r |
471 | int ch;\r | |
472 | \r | |
473 | for(ch=start;ch<end;ch++,val>>=1) // loop channels\r | |
474 | {\r | |
475 | if(val&1) // -> fmod on/off\r | |
476 | {\r | |
477 | if(ch>0) \r | |
478 | {\r | |
479 | s_chan[ch].bFMod=1; // --> sound channel\r | |
480 | s_chan[ch-1].bFMod=2; // --> freq channel\r | |
481 | }\r | |
482 | }\r | |
483 | else\r | |
484 | {\r | |
485 | s_chan[ch].bFMod=0; // --> turn off fmod\r | |
07a6dd2c | 486 | if(ch>0&&s_chan[ch-1].bFMod==2)\r |
487 | s_chan[ch-1].bFMod=0;\r | |
ef79bbde P |
488 | }\r |
489 | }\r | |
490 | }\r | |
491 | \r | |
492 | ////////////////////////////////////////////////////////////////////////\r | |
493 | // NOISE register write\r | |
494 | ////////////////////////////////////////////////////////////////////////\r | |
495 | \r | |
7e44d49d | 496 | static void NoiseOn(int start,int end,unsigned short val)\r |
ef79bbde P |
497 | {\r |
498 | int ch;\r | |
499 | \r | |
500 | for(ch=start;ch<end;ch++,val>>=1) // loop channels\r | |
501 | {\r | |
6d866bb7 | 502 | s_chan[ch].bNoise=val&1; // -> noise on/off\r |
ef79bbde P |
503 | }\r |
504 | }\r | |
505 | \r | |
506 | ////////////////////////////////////////////////////////////////////////\r | |
507 | // LEFT VOLUME register write\r | |
508 | ////////////////////////////////////////////////////////////////////////\r | |
509 | \r | |
510 | // please note: sweep and phase invert are wrong... but I've never seen\r | |
511 | // them used\r | |
512 | \r | |
7e44d49d | 513 | static void SetVolumeL(unsigned char ch,short vol) // LEFT VOLUME\r |
ef79bbde | 514 | {\r |
ef79bbde P |
515 | if(vol&0x8000) // sweep?\r |
516 | {\r | |
517 | short sInc=1; // -> sweep up?\r | |
518 | if(vol&0x2000) sInc=-1; // -> or down?\r | |
519 | if(vol&0x1000) vol^=0xffff; // -> mmm... phase inverted? have to investigate this\r | |
520 | vol=((vol&0x7f)+1)/2; // -> sweep: 0..127 -> 0..64\r | |
521 | vol+=vol/(2*sInc); // -> HACK: we don't sweep right now, so we just raise/lower the volume by the half!\r | |
522 | vol*=128;\r | |
523 | }\r | |
524 | else // no sweep:\r | |
525 | {\r | |
526 | if(vol&0x4000) // -> mmm... phase inverted? have to investigate this\r | |
527 | //vol^=0xffff;\r | |
528 | vol=0x3fff-(vol&0x3fff);\r | |
529 | }\r | |
530 | \r | |
531 | vol&=0x3fff;\r | |
532 | s_chan[ch].iLeftVolume=vol; // store volume\r | |
533 | }\r | |
534 | \r | |
535 | ////////////////////////////////////////////////////////////////////////\r | |
536 | // RIGHT VOLUME register write\r | |
537 | ////////////////////////////////////////////////////////////////////////\r | |
538 | \r | |
7e44d49d | 539 | static void SetVolumeR(unsigned char ch,short vol) // RIGHT VOLUME\r |
ef79bbde | 540 | {\r |
ef79bbde P |
541 | if(vol&0x8000) // comments... see above :)\r |
542 | {\r | |
543 | short sInc=1;\r | |
544 | if(vol&0x2000) sInc=-1;\r | |
545 | if(vol&0x1000) vol^=0xffff;\r | |
546 | vol=((vol&0x7f)+1)/2; \r | |
547 | vol+=vol/(2*sInc);\r | |
548 | vol*=128;\r | |
549 | }\r | |
550 | else \r | |
551 | {\r | |
552 | if(vol&0x4000) //vol=vol^=0xffff;\r | |
553 | vol=0x3fff-(vol&0x3fff);\r | |
554 | }\r | |
555 | \r | |
556 | vol&=0x3fff;\r | |
557 | \r | |
558 | s_chan[ch].iRightVolume=vol;\r | |
559 | }\r | |
560 | \r | |
561 | ////////////////////////////////////////////////////////////////////////\r | |
562 | // PITCH register write\r | |
563 | ////////////////////////////////////////////////////////////////////////\r | |
564 | \r | |
7e44d49d | 565 | static void SetPitch(int ch,unsigned short val) // SET PITCH\r |
ef79bbde P |
566 | {\r |
567 | int NP;\r | |
568 | if(val>0x3fff) NP=0x3fff; // get pitch val\r | |
569 | else NP=val;\r | |
570 | \r | |
571 | s_chan[ch].iRawPitch=NP;\r | |
7e44d49d | 572 | s_chan[ch].sinc=(NP<<4)|8;\r |
573 | if(iUseInterpolation==1) s_chan[ch].SB[32]=1; // -> freq change in simple interpolation mode: set flag\r | |
ef79bbde P |
574 | }\r |
575 | \r | |
576 | ////////////////////////////////////////////////////////////////////////\r | |
577 | // REVERB register write\r | |
578 | ////////////////////////////////////////////////////////////////////////\r | |
579 | \r | |
7e44d49d | 580 | static void ReverbOn(int start,int end,unsigned short val)\r |
ef79bbde P |
581 | {\r |
582 | int ch;\r | |
583 | \r | |
584 | for(ch=start;ch<end;ch++,val>>=1) // loop channels\r | |
585 | {\r | |
6d866bb7 | 586 | s_chan[ch].bReverb=val&1; // -> reverb on/off\r |
ef79bbde P |
587 | }\r |
588 | }\r |