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 | |
3154bfab | 24 | #include "spu_config.h"\r |
b71a957f | 25 | #include "spu.h"\r |
ef79bbde | 26 | \r |
7e44d49d | 27 | static void SoundOn(int start,int end,unsigned short val);\r |
28 | static void SoundOff(int start,int end,unsigned short val);\r | |
29 | static void FModOn(int start,int end,unsigned short val);\r | |
30 | static void NoiseOn(int start,int end,unsigned short val);\r | |
31 | static void SetVolumeL(unsigned char ch,short vol);\r | |
32 | static void SetVolumeR(unsigned char ch,short vol);\r | |
33 | static void SetPitch(int ch,unsigned short val);\r | |
34 | static void ReverbOn(int start,int end,unsigned short val);\r | |
35 | \r | |
ef79bbde P |
36 | ////////////////////////////////////////////////////////////////////////\r |
37 | // WRITE REGISTERS: called by main emu\r | |
38 | ////////////////////////////////////////////////////////////////////////\r | |
39 | \r | |
3fc2a418 | 40 | static const uint32_t ignore_dupe[16] = {\r |
650adfd2 | 41 | // ch 0-15 c40 c80 cc0\r |
42 | 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f,\r | |
43 | // ch 16-24 d40 control reverb\r | |
3fc2a418 | 44 | 0x7f7f7f7f, 0x7f7f7f7f, 0xff05ff0f, 0xffffffff,\r |
45 | 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,\r | |
46 | 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff\r | |
650adfd2 | 47 | };\r |
48 | \r | |
49 | void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val,\r | |
50 | unsigned int cycles)\r | |
ef79bbde | 51 | {\r |
3fc2a418 | 52 | int r = reg & 0xffe;\r |
650adfd2 | 53 | int rofs = (r - 0xc00) >> 1;\r |
3154bfab | 54 | int changed = spu.regArea[rofs] != val;\r |
55 | spu.regArea[rofs] = val;\r | |
650adfd2 | 56 | \r |
57 | if (!changed && (ignore_dupe[rofs >> 5] & (1 << (rofs & 0x1f))))\r | |
58 | return;\r | |
59 | // zero keyon/keyoff?\r | |
60 | if (val == 0 && (r & 0xff8) == 0xd88)\r | |
61 | return;\r | |
62 | \r | |
6183ddf9 | 63 | do_samples_if_needed(cycles, 0, 16);\r |
ef79bbde P |
64 | \r |
65 | if(r>=0x0c00 && r<0x0d80) // some channel info?\r | |
66 | {\r | |
67 | int ch=(r>>4)-0xc0; // calc channel\r | |
68 | switch(r&0x0f)\r | |
69 | {\r | |
70 | //------------------------------------------------// r volume\r | |
71 | case 0: \r | |
72 | SetVolumeL((unsigned char)ch,val);\r | |
73 | break;\r | |
74 | //------------------------------------------------// l volume\r | |
75 | case 2: \r | |
76 | SetVolumeR((unsigned char)ch,val);\r | |
77 | break;\r | |
78 | //------------------------------------------------// pitch\r | |
79 | case 4: \r | |
80 | SetPitch(ch,val);\r | |
650adfd2 | 81 | goto upd_irq;\r |
ef79bbde P |
82 | //------------------------------------------------// start\r |
83 | case 6: \r | |
7e44d49d | 84 | // taken from regArea later\r |
ef79bbde P |
85 | break;\r |
86 | //------------------------------------------------// level with pre-calcs\r | |
87 | case 8:\r | |
88 | {\r | |
6d866bb7 | 89 | const unsigned long lval=val;\r |
ef79bbde | 90 | //---------------------------------------------//\r |
5514a050 | 91 | spu.s_chan[ch].ADSRX.AttackModeExp=(lval&0x8000)?1:0;\r |
92 | spu.s_chan[ch].ADSRX.AttackRate=(lval>>8) & 0x007f;\r | |
93 | spu.s_chan[ch].ADSRX.DecayRate=(lval>>4) & 0x000f;\r | |
94 | spu.s_chan[ch].ADSRX.SustainLevel=lval & 0x000f;\r | |
ef79bbde | 95 | //---------------------------------------------//\r |
ef79bbde P |
96 | }\r |
97 | break;\r | |
98 | //------------------------------------------------// adsr times with pre-calcs\r | |
99 | case 10:\r | |
100 | {\r | |
6d866bb7 | 101 | const unsigned long lval=val;\r |
ef79bbde P |
102 | \r |
103 | //----------------------------------------------//\r | |
5514a050 | 104 | spu.s_chan[ch].ADSRX.SustainModeExp = (lval&0x8000)?1:0;\r |
105 | spu.s_chan[ch].ADSRX.SustainIncrease= (lval&0x4000)?0:1;\r | |
106 | spu.s_chan[ch].ADSRX.SustainRate = (lval>>6) & 0x007f;\r | |
107 | spu.s_chan[ch].ADSRX.ReleaseModeExp = (lval&0x0020)?1:0;\r | |
108 | spu.s_chan[ch].ADSRX.ReleaseRate = lval & 0x001f;\r | |
ef79bbde | 109 | //----------------------------------------------//\r |
ef79bbde P |
110 | }\r |
111 | break;\r | |
112 | //------------------------------------------------// adsr volume... mmm have to investigate this\r | |
113 | case 12:\r | |
114 | break;\r | |
115 | //------------------------------------------------//\r | |
116 | case 14: // loop?\r | |
5514a050 | 117 | spu.s_chan[ch].pLoop=spu.spuMemC+((val&~1)<<3);\r |
9601ca6d | 118 | spu.s_chan[ch].bIgnoreLoop = 1;\r |
650adfd2 | 119 | goto upd_irq;\r |
ef79bbde P |
120 | //------------------------------------------------//\r |
121 | }\r | |
ef79bbde P |
122 | return;\r |
123 | }\r | |
3fc2a418 | 124 | else if (0x0e00 <= r && r < 0x0e60)\r |
125 | {\r | |
126 | int ch = (r >> 2) & 0x1f;\r | |
127 | log_unhandled("c%02d w %cvol %04x\n", ch, (r & 2) ? 'r' : 'l', val);\r | |
128 | spu.s_chan[ch].iVolume[(r >> 1) & 1] = (signed short)val >> 1;\r | |
129 | }\r | |
ef79bbde P |
130 | \r |
131 | switch(r)\r | |
132 | {\r | |
133 | //-------------------------------------------------//\r | |
134 | case H_SPUaddr:\r | |
5fa59798 | 135 | spu.spuAddr = (unsigned int)val << 3;\r |
56e500f3 | 136 | //check_irq_io(spu.spuAddr);\r |
ef79bbde P |
137 | break;\r |
138 | //-------------------------------------------------//\r | |
139 | case H_SPUdata:\r | |
b71a957f | 140 | *(unsigned short *)(spu.spuMemC + spu.spuAddr) = HTOLE16(val);\r |
5514a050 | 141 | spu.spuAddr += 2;\r |
142 | spu.spuAddr &= 0x7fffe;\r | |
56e500f3 | 143 | check_irq_io(spu.spuAddr);\r |
ef79bbde P |
144 | break;\r |
145 | //-------------------------------------------------//\r | |
146 | case H_SPUctrl:\r | |
6109649c | 147 | spu.spuStat = (spu.spuStat & ~0x3f) | (val & 0x3f);\r |
5fa59798 | 148 | spu.spuStat &= ~STAT_IRQ | val;\r |
3154bfab | 149 | if (!(spu.spuCtrl & CTRL_IRQ)) {\r |
650adfd2 | 150 | if (val & CTRL_IRQ)\r |
151 | schedule_next_irq();\r | |
152 | }\r | |
3154bfab | 153 | spu.spuCtrl=val;\r |
ef79bbde P |
154 | break;\r |
155 | //-------------------------------------------------//\r | |
156 | case H_SPUstat:\r | |
5fa59798 | 157 | //spu.spuStat=val&0xf800;\r |
ef79bbde P |
158 | break;\r |
159 | //-------------------------------------------------//\r | |
160 | case H_SPUReverbAddr:\r | |
650adfd2 | 161 | goto rvbd;\r |
ef79bbde P |
162 | //-------------------------------------------------//\r |
163 | case H_SPUirqAddr:\r | |
54604e03 | 164 | //if (val & 1)\r |
165 | // log_unhandled("w irq with lsb: %08lx %04x\n", reg, val);\r | |
56e500f3 | 166 | spu.pSpuIrq = spu.spuMemC + (((int)val << 3) & ~0xf);\r |
167 | //check_irq_io(spu.spuAddr);\r | |
650adfd2 | 168 | goto upd_irq;\r |
ef79bbde P |
169 | //-------------------------------------------------//\r |
170 | case H_SPUrvolL:\r | |
986293e0 | 171 | spu.rvb->VolLeft = (int16_t)val;\r |
ef79bbde P |
172 | break;\r |
173 | //-------------------------------------------------//\r | |
174 | case H_SPUrvolR:\r | |
986293e0 | 175 | spu.rvb->VolRight = (int16_t)val;\r |
ef79bbde P |
176 | break;\r |
177 | //-------------------------------------------------//\r | |
178 | \r | |
7df2c03c | 179 | case H_SPUmvolL:\r |
180 | case H_SPUmvolR:\r | |
181 | if (val & 0x8000)\r | |
182 | log_unhandled("w master sweep: %08lx %04x\n", reg, val);\r | |
183 | break;\r | |
184 | \r | |
185 | case 0x0dac:\r | |
186 | if (val != 4)\r | |
187 | log_unhandled("1f801dac %04x\n", val);\r | |
188 | break;\r | |
189 | \r | |
ef79bbde P |
190 | /*\r |
191 | case H_ExtLeft:\r | |
192 | //auxprintf("EL %d\n",val);\r | |
193 | break;\r | |
194 | //-------------------------------------------------//\r | |
195 | case H_ExtRight:\r | |
196 | //auxprintf("ER %d\n",val);\r | |
197 | break;\r | |
198 | //-------------------------------------------------//\r | |
199 | case H_SPUmvolL:\r | |
200 | //auxprintf("ML %d\n",val);\r | |
201 | break;\r | |
202 | //-------------------------------------------------//\r | |
203 | case H_SPUmvolR:\r | |
204 | //auxprintf("MR %d\n",val);\r | |
205 | break;\r | |
206 | //-------------------------------------------------//\r | |
207 | case H_SPUMute1:\r | |
208 | //auxprintf("M0 %04x\n",val);\r | |
209 | break;\r | |
210 | //-------------------------------------------------//\r | |
211 | case H_SPUMute2:\r | |
212 | //auxprintf("M1 %04x\n",val);\r | |
213 | break;\r | |
214 | */\r | |
215 | //-------------------------------------------------//\r | |
216 | case H_SPUon1:\r | |
fcb93a4f | 217 | spu.last_keyon_cycles = cycles;\r |
6183ddf9 | 218 | do_samples_if_needed(cycles, 0, 2);\r |
ef79bbde P |
219 | SoundOn(0,16,val);\r |
220 | break;\r | |
221 | //-------------------------------------------------//\r | |
6183ddf9 | 222 | case H_SPUon2:\r |
fcb93a4f | 223 | spu.last_keyon_cycles = cycles;\r |
6183ddf9 | 224 | do_samples_if_needed(cycles, 0, 2);\r |
ef79bbde P |
225 | SoundOn(16,24,val);\r |
226 | break;\r | |
227 | //-------------------------------------------------//\r | |
228 | case H_SPUoff1:\r | |
fcb93a4f | 229 | if (cycles - spu.last_keyon_cycles < 786u) {\r |
230 | if (val & regAreaGet(H_SPUon1))\r | |
231 | log_unhandled("koff1 %04x %d\n", val, cycles - spu.last_keyon_cycles);\r | |
232 | val &= ~regAreaGet(H_SPUon1);\r | |
233 | }\r | |
df5f713b | 234 | do_samples_if_needed(cycles, 0, 2);\r |
ef79bbde P |
235 | SoundOff(0,16,val);\r |
236 | break;\r | |
237 | //-------------------------------------------------//\r | |
238 | case H_SPUoff2:\r | |
fcb93a4f | 239 | if (cycles - spu.last_keyon_cycles < 786u) {\r |
240 | if (val & regAreaGet(H_SPUon1))\r | |
241 | log_unhandled("koff2 %04x %d\n", val, cycles - spu.last_keyon_cycles);\r | |
242 | val &= ~regAreaGet(H_SPUon2);\r | |
243 | }\r | |
df5f713b | 244 | do_samples_if_needed(cycles, 0, 2);\r |
ef79bbde P |
245 | SoundOff(16,24,val);\r |
246 | break;\r | |
247 | //-------------------------------------------------//\r | |
248 | case H_CDLeft:\r | |
7d6997de | 249 | spu.iLeftXAVol=(int16_t)val;\r |
60073003 | 250 | //if(spu.cddavCallback) spu.cddavCallback(0,(int16_t)val);\r |
ef79bbde P |
251 | break;\r |
252 | case H_CDRight:\r | |
7d6997de | 253 | spu.iRightXAVol=(int16_t)val;\r |
60073003 | 254 | //if(spu.cddavCallback) spu.cddavCallback(1,(int16_t)val);\r |
ef79bbde P |
255 | break;\r |
256 | //-------------------------------------------------//\r | |
257 | case H_FMod1:\r | |
258 | FModOn(0,16,val);\r | |
259 | break;\r | |
260 | //-------------------------------------------------//\r | |
261 | case H_FMod2:\r | |
262 | FModOn(16,24,val);\r | |
263 | break;\r | |
264 | //-------------------------------------------------//\r | |
265 | case H_Noise1:\r | |
266 | NoiseOn(0,16,val);\r | |
267 | break;\r | |
268 | //-------------------------------------------------//\r | |
269 | case H_Noise2:\r | |
270 | NoiseOn(16,24,val);\r | |
271 | break;\r | |
272 | //-------------------------------------------------//\r | |
273 | case H_RVBon1:\r | |
274 | ReverbOn(0,16,val);\r | |
275 | break;\r | |
276 | //-------------------------------------------------//\r | |
277 | case H_RVBon2:\r | |
278 | ReverbOn(16,24,val);\r | |
279 | break;\r | |
280 | //-------------------------------------------------//\r | |
7b2c4897 | 281 | case H_Reverb+0 : goto rvbd;\r |
282 | case H_Reverb+2 : goto rvbd;\r | |
283 | case H_Reverb+4 : spu.rvb->IIR_ALPHA=(short)val; break;\r | |
284 | case H_Reverb+6 : spu.rvb->ACC_COEF_A=(short)val; break;\r | |
285 | case H_Reverb+8 : spu.rvb->ACC_COEF_B=(short)val; break;\r | |
286 | case H_Reverb+10 : spu.rvb->ACC_COEF_C=(short)val; break;\r | |
287 | case H_Reverb+12 : spu.rvb->ACC_COEF_D=(short)val; break;\r | |
288 | case H_Reverb+14 : spu.rvb->IIR_COEF=(short)val; break;\r | |
289 | case H_Reverb+16 : spu.rvb->FB_ALPHA=(short)val; break;\r | |
290 | case H_Reverb+18 : spu.rvb->FB_X=(short)val; break;\r | |
291 | case H_Reverb+20 : goto rvbd;\r | |
292 | case H_Reverb+22 : goto rvbd;\r | |
293 | case H_Reverb+24 : goto rvbd;\r | |
294 | case H_Reverb+26 : goto rvbd;\r | |
295 | case H_Reverb+28 : goto rvbd;\r | |
296 | case H_Reverb+30 : goto rvbd;\r | |
297 | case H_Reverb+32 : goto rvbd;\r | |
298 | case H_Reverb+34 : goto rvbd;\r | |
299 | case H_Reverb+36 : goto rvbd;\r | |
300 | case H_Reverb+38 : goto rvbd;\r | |
301 | case H_Reverb+40 : goto rvbd;\r | |
302 | case H_Reverb+42 : goto rvbd;\r | |
303 | case H_Reverb+44 : goto rvbd;\r | |
304 | case H_Reverb+46 : goto rvbd;\r | |
305 | case H_Reverb+48 : goto rvbd;\r | |
306 | case H_Reverb+50 : goto rvbd;\r | |
307 | case H_Reverb+52 : goto rvbd;\r | |
308 | case H_Reverb+54 : goto rvbd;\r | |
309 | case H_Reverb+56 : goto rvbd;\r | |
310 | case H_Reverb+58 : goto rvbd;\r | |
311 | case H_Reverb+60 : spu.rvb->IN_COEF_L=(short)val; break;\r | |
312 | case H_Reverb+62 : spu.rvb->IN_COEF_R=(short)val; break;\r | |
ef79bbde | 313 | }\r |
650adfd2 | 314 | return;\r |
315 | \r | |
316 | upd_irq:\r | |
3154bfab | 317 | if (spu.spuCtrl & CTRL_IRQ)\r |
650adfd2 | 318 | schedule_next_irq();\r |
319 | return;\r | |
ef79bbde | 320 | \r |
650adfd2 | 321 | rvbd:\r |
05c7cec7 | 322 | spu.rvb->dirty = 1; // recalculate on next update\r |
ef79bbde P |
323 | }\r |
324 | \r | |
325 | ////////////////////////////////////////////////////////////////////////\r | |
326 | // READ REGISTER: called by main emu\r | |
327 | ////////////////////////////////////////////////////////////////////////\r | |
328 | \r | |
6183ddf9 | 329 | unsigned short CALLBACK SPUreadRegister(unsigned long reg, unsigned int cycles)\r |
ef79bbde | 330 | {\r |
3fc2a418 | 331 | const unsigned long r = reg & 0xffe;\r |
ef79bbde | 332 | \r |
ef79bbde P |
333 | if(r>=0x0c00 && r<0x0d80)\r |
334 | {\r | |
335 | switch(r&0x0f)\r | |
336 | {\r | |
337 | case 12: // get adsr vol\r | |
338 | {\r | |
6183ddf9 | 339 | // this used to return 1 immediately after keyon to deal with\r |
340 | // some poor timing, but that causes Rayman 2 to lose track of\r | |
341 | // it's channels on busy scenes and start looping some of them forever\r | |
342 | const int ch = (r>>4) - 0xc0;\r | |
343 | if (spu.s_chan[ch].bStarting)\r | |
344 | do_samples_if_needed(cycles, 0, 2);\r | |
345 | return (unsigned short)(spu.s_chan[ch].ADSRX.EnvelopeVol >> 16);\r | |
ef79bbde P |
346 | }\r |
347 | \r | |
348 | case 14: // get loop address\r | |
349 | {\r | |
350 | const int ch=(r>>4)-0xc0;\r | |
5514a050 | 351 | return (unsigned short)((spu.s_chan[ch].pLoop-spu.spuMemC)>>3);\r |
ef79bbde P |
352 | }\r |
353 | }\r | |
354 | }\r | |
3fc2a418 | 355 | else if (0x0e00 <= r && r < 0x0e60)\r |
356 | {\r | |
357 | int ch = (r >> 2) & 0x1f;\r | |
358 | int v = spu.s_chan[ch].iVolume[(r >> 1) & 1] << 1;\r | |
359 | log_unhandled("c%02d r %cvol %04x\n", ch, (r & 2) ? 'r' : 'l', v);\r | |
360 | return v;\r | |
361 | }\r | |
ef79bbde P |
362 | \r |
363 | switch(r)\r | |
364 | {\r | |
365 | case H_SPUctrl:\r | |
3154bfab | 366 | return spu.spuCtrl;\r |
ef79bbde P |
367 | \r |
368 | case H_SPUstat:\r | |
6109649c | 369 | return spu.spuStat;\r |
ef79bbde P |
370 | \r |
371 | case H_SPUaddr:\r | |
3154bfab | 372 | return (unsigned short)(spu.spuAddr>>3);\r |
ef79bbde | 373 | \r |
56e500f3 | 374 | // this reportedly doesn't work on real hw\r |
ef79bbde P |
375 | case H_SPUdata:\r |
376 | {\r | |
b71a957f | 377 | unsigned short s = LE16TOH(*(unsigned short *)(spu.spuMemC + spu.spuAddr));\r |
5514a050 | 378 | spu.spuAddr += 2;\r |
379 | spu.spuAddr &= 0x7fffe;\r | |
56e500f3 | 380 | //check_irq_io(spu.spuAddr);\r |
ef79bbde P |
381 | return s;\r |
382 | }\r | |
383 | \r | |
ef79bbde P |
384 | //case H_SPUIsOn1:\r |
385 | // return IsSoundOn(0,16);\r | |
386 | \r | |
387 | //case H_SPUIsOn2:\r | |
388 | // return IsSoundOn(16,24);\r | |
389 | \r | |
7df2c03c | 390 | case H_SPUMute1:\r |
391 | case H_SPUMute2:\r | |
392 | log_unhandled("r isOn: %08lx\n", reg);\r | |
393 | break;\r | |
380cbc61 | 394 | \r |
395 | case 0x0dac:\r | |
396 | case H_SPUirqAddr:\r | |
397 | case H_CDLeft:\r | |
398 | case H_CDRight:\r | |
399 | case H_ExtLeft:\r | |
400 | case H_ExtRight:\r | |
401 | break;\r | |
402 | \r | |
403 | default:\r | |
404 | if (r >= 0xda0)\r | |
405 | log_unhandled("spu r %08lx\n", reg);\r | |
406 | break;\r | |
ef79bbde P |
407 | }\r |
408 | \r | |
3154bfab | 409 | return spu.regArea[(r-0xc00)>>1];\r |
ef79bbde P |
410 | }\r |
411 | \r | |
412 | ////////////////////////////////////////////////////////////////////////\r | |
413 | // SOUND ON register write\r | |
414 | ////////////////////////////////////////////////////////////////////////\r | |
415 | \r | |
7e44d49d | 416 | static void SoundOn(int start,int end,unsigned short val)\r |
ef79bbde P |
417 | {\r |
418 | int ch;\r | |
419 | \r | |
420 | for(ch=start;ch<end;ch++,val>>=1) // loop channels\r | |
421 | {\r | |
a0d4a8f5 | 422 | if((val&1) && regAreaGetCh(ch, 6)) // mmm... start has to be set before key on !?!\r |
ef79bbde | 423 | {\r |
9601ca6d | 424 | spu.s_chan[ch].bIgnoreLoop = 0;\r |
6183ddf9 | 425 | spu.s_chan[ch].bStarting = 1;\r |
3154bfab | 426 | spu.dwNewChannel|=(1<<ch);\r |
ef79bbde P |
427 | }\r |
428 | }\r | |
429 | }\r | |
430 | \r | |
431 | ////////////////////////////////////////////////////////////////////////\r | |
432 | // SOUND OFF register write\r | |
433 | ////////////////////////////////////////////////////////////////////////\r | |
434 | \r | |
7e44d49d | 435 | static void SoundOff(int start,int end,unsigned short val)\r |
ef79bbde P |
436 | {\r |
437 | int ch;\r | |
fcb93a4f | 438 | for (ch = start; val && ch < end; ch++, val >>= 1) // loop channels\r |
ef79bbde | 439 | {\r |
9ad8abfa | 440 | if(val&1)\r |
ef79bbde | 441 | {\r |
5514a050 | 442 | spu.s_chan[ch].ADSRX.State = ADSR_RELEASE;\r |
b00afb77 | 443 | \r |
444 | // Jungle Book - Rhythm 'n Groove\r | |
445 | // - turns off buzzing sound (loop hangs)\r | |
3154bfab | 446 | spu.dwNewChannel &= ~(1<<ch);\r |
ef79bbde P |
447 | } \r |
448 | }\r | |
449 | }\r | |
450 | \r | |
451 | ////////////////////////////////////////////////////////////////////////\r | |
452 | // FMOD register write\r | |
453 | ////////////////////////////////////////////////////////////////////////\r | |
454 | \r | |
7e44d49d | 455 | static void FModOn(int start,int end,unsigned short val)\r |
ef79bbde P |
456 | {\r |
457 | int ch;\r | |
458 | \r | |
459 | for(ch=start;ch<end;ch++,val>>=1) // loop channels\r | |
460 | {\r | |
461 | if(val&1) // -> fmod on/off\r | |
462 | {\r | |
463 | if(ch>0) \r | |
464 | {\r | |
5514a050 | 465 | spu.s_chan[ch].bFMod=1; // --> sound channel\r |
466 | spu.s_chan[ch-1].bFMod=2; // --> freq channel\r | |
ef79bbde P |
467 | }\r |
468 | }\r | |
469 | else\r | |
470 | {\r | |
5514a050 | 471 | spu.s_chan[ch].bFMod=0; // --> turn off fmod\r |
472 | if(ch>0&&spu.s_chan[ch-1].bFMod==2)\r | |
473 | spu.s_chan[ch-1].bFMod=0;\r | |
ef79bbde P |
474 | }\r |
475 | }\r | |
476 | }\r | |
477 | \r | |
478 | ////////////////////////////////////////////////////////////////////////\r | |
479 | // NOISE register write\r | |
480 | ////////////////////////////////////////////////////////////////////////\r | |
481 | \r | |
7e44d49d | 482 | static void NoiseOn(int start,int end,unsigned short val)\r |
ef79bbde P |
483 | {\r |
484 | int ch;\r | |
485 | \r | |
486 | for(ch=start;ch<end;ch++,val>>=1) // loop channels\r | |
487 | {\r | |
5514a050 | 488 | spu.s_chan[ch].bNoise=val&1; // -> noise on/off\r |
ef79bbde P |
489 | }\r |
490 | }\r | |
491 | \r | |
492 | ////////////////////////////////////////////////////////////////////////\r | |
493 | // LEFT VOLUME register write\r | |
494 | ////////////////////////////////////////////////////////////////////////\r | |
495 | \r | |
496 | // please note: sweep and phase invert are wrong... but I've never seen\r | |
497 | // them used\r | |
498 | \r | |
7e44d49d | 499 | static void SetVolumeL(unsigned char ch,short vol) // LEFT VOLUME\r |
ef79bbde | 500 | {\r |
ef79bbde P |
501 | if(vol&0x8000) // sweep?\r |
502 | {\r | |
503 | short sInc=1; // -> sweep up?\r | |
7df2c03c | 504 | log_unhandled("ch%d sweepl %04x\n", ch, vol);\r |
ef79bbde P |
505 | if(vol&0x2000) sInc=-1; // -> or down?\r |
506 | if(vol&0x1000) vol^=0xffff; // -> mmm... phase inverted? have to investigate this\r | |
507 | vol=((vol&0x7f)+1)/2; // -> sweep: 0..127 -> 0..64\r | |
508 | vol+=vol/(2*sInc); // -> HACK: we don't sweep right now, so we just raise/lower the volume by the half!\r | |
509 | vol*=128;\r | |
510 | }\r | |
511 | else // no sweep:\r | |
512 | {\r | |
513 | if(vol&0x4000) // -> mmm... phase inverted? have to investigate this\r | |
514 | //vol^=0xffff;\r | |
515 | vol=0x3fff-(vol&0x3fff);\r | |
516 | }\r | |
517 | \r | |
518 | vol&=0x3fff;\r | |
5514a050 | 519 | spu.s_chan[ch].iLeftVolume=vol; // store volume\r |
3fc2a418 | 520 | //spu.regArea[(0xe00-0xc00)/2 + ch*2 + 0] = vol << 1;\r |
ef79bbde P |
521 | }\r |
522 | \r | |
523 | ////////////////////////////////////////////////////////////////////////\r | |
524 | // RIGHT VOLUME register write\r | |
525 | ////////////////////////////////////////////////////////////////////////\r | |
526 | \r | |
7e44d49d | 527 | static void SetVolumeR(unsigned char ch,short vol) // RIGHT VOLUME\r |
ef79bbde | 528 | {\r |
ef79bbde P |
529 | if(vol&0x8000) // comments... see above :)\r |
530 | {\r | |
531 | short sInc=1;\r | |
7df2c03c | 532 | log_unhandled("ch%d sweepr %04x\n", ch, vol);\r |
ef79bbde P |
533 | if(vol&0x2000) sInc=-1;\r |
534 | if(vol&0x1000) vol^=0xffff;\r | |
535 | vol=((vol&0x7f)+1)/2; \r | |
536 | vol+=vol/(2*sInc);\r | |
537 | vol*=128;\r | |
538 | }\r | |
539 | else \r | |
540 | {\r | |
541 | if(vol&0x4000) //vol=vol^=0xffff;\r | |
542 | vol=0x3fff-(vol&0x3fff);\r | |
543 | }\r | |
544 | \r | |
545 | vol&=0x3fff;\r | |
546 | \r | |
5514a050 | 547 | spu.s_chan[ch].iRightVolume=vol;\r |
3fc2a418 | 548 | //spu.regArea[(0xe00-0xc00)/2 + ch*2 + 1] = vol << 1;\r |
ef79bbde P |
549 | }\r |
550 | \r | |
551 | ////////////////////////////////////////////////////////////////////////\r | |
552 | // PITCH register write\r | |
553 | ////////////////////////////////////////////////////////////////////////\r | |
554 | \r | |
7e44d49d | 555 | static void SetPitch(int ch,unsigned short val) // SET PITCH\r |
ef79bbde P |
556 | {\r |
557 | int NP;\r | |
558 | if(val>0x3fff) NP=0x3fff; // get pitch val\r | |
559 | else NP=val;\r | |
560 | \r | |
4f9efe54 | 561 | spu.s_chan[ch].iRawPitch = NP;\r |
562 | spu.s_chan[ch].sinc = NP << 4;\r | |
563 | spu.s_chan[ch].sinc_inv = 0;\r | |
df68316d | 564 | \r |
565 | // don't mess spu.dwChannelsAudible as adsr runs independently\r | |
ef79bbde P |
566 | }\r |
567 | \r | |
568 | ////////////////////////////////////////////////////////////////////////\r | |
569 | // REVERB register write\r | |
570 | ////////////////////////////////////////////////////////////////////////\r | |
571 | \r | |
7e44d49d | 572 | static void ReverbOn(int start,int end,unsigned short val)\r |
ef79bbde P |
573 | {\r |
574 | int ch;\r | |
575 | \r | |
576 | for(ch=start;ch<end;ch++,val>>=1) // loop channels\r | |
577 | {\r | |
5514a050 | 578 | spu.s_chan[ch].bReverb=val&1; // -> reverb on/off\r |
ef79bbde P |
579 | }\r |
580 | }\r | |
fcb93a4f | 581 | \r |
582 | // vim:shiftwidth=1:expandtab\r |