drc: merge Ari64's patch: 14_dont_save_or_restore_temporary
[pcsx_rearmed.git] / plugins / spunull / spunull.c
CommitLineData
0d464c77 1/////////////////////////////////////////////////////////
2
3#define PSE_LT_SPU 4
4#define PSE_SPU_ERR_SUCCESS 0
5#define PSE_SPU_ERR -60
6#define PSE_SPU_ERR_NOTCONFIGURED PSE_SPU_ERR -1
7#define PSE_SPU_ERR_INIT PSE_SPU_ERR -2
8
9/////////////////////////////////////////////////////////
10// main emu calls:
11// 0. Get type/name/version
12// 1. Init
13// 2. SetCallbacks
14// 3. SetConfigFile
15// 4. Open
16// 5. Dma/register/xa calls...
17// 6. Close
18// 7. Shutdown
19/////////////////////////////////////////////////////////
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include "xa.h"
25#include "register.h"
26// some ms windows compatibility define
27#undef CALLBACK
28#define CALLBACK
29
30////////////////////////////////////////////////////////////////////////
31
32////////////////////////////////////////////////////////////////////////
33
34const unsigned char version = 1;
35const unsigned char revision = 1;
36const unsigned char build = 1;
37static char * libraryName = "Pete's Null Audio Driver";
38static char * libraryInfo = "Pete's Null Audio Driver V1.1\nCoded by Pete Bernert\n";
39
40////////////////////////////////////////////////////////////////////////
41
42unsigned short regArea[10000]; // psx buffer
43unsigned short spuMem[256*1024];
44unsigned char * spuMemC;
45unsigned char * pSpuIrq=0;
46
47unsigned short spuCtrl, spuStat, spuIrq=0; // some vars to store psx reg infos
48unsigned long spuAddr=0xffffffff; // address into spu mem
49char * pConfigFile=0;
50
51////////////////////////////////////////////////////////////////////////
52
53////////////////////////////////////////////////////////////////////////
54
55void (CALLBACK *irqCallback)(void)=0; // func of main emu, called on spu irq
56void (CALLBACK *cddavCallback)(unsigned short,unsigned short)=0;
57
58////////////////////////////////////////////////////////////////////////
59// CODE AREA
60////////////////////////////////////////////////////////////////////////
61
62void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val)
63{
64 unsigned long r=reg&0xfff;
65 regArea[(r-0xc00)>>1] = val;
66
67 if(r>=0x0c00 && r<0x0d80)
68 {
69 //int ch=(r>>4)-0xc0;
70 switch(r&0x0f)
71 {
72 //------------------------------------------------// l volume
73 case 0:
74 //SetVolumeL(ch,val);
75 return;
76 //------------------------------------------------// r volume
77 case 2:
78 //SetVolumeR(ch,val);
79 return;
80 //------------------------------------------------// pitch
81 case 4:
82 //SetPitch(ch,val);
83 return;
84 //------------------------------------------------// start
85 case 6:
86 //s_chan[ch].pStart=spuMemC+((unsigned long) val<<3);
87 return;
88 //------------------------------------------------// adsr level
89 case 8:
90 return;
91 //------------------------------------------------// adsr rate
92 case 10:
93 return;
94 //------------------------------------------------// adsr volume
95 case 12:
96 return;
97 //------------------------------------------------// loop adr
98 case 14:
99 return;
100 //------------------------------------------------//
101 }
102 return;
103 }
104
105 switch(r)
106 {
107 //-------------------------------------------------//
108 case H_SPUaddr:
109 spuAddr = (unsigned long) val<<3;
110 return;
111 //-------------------------------------------------//
112 case H_SPUdata:
113 spuMem[spuAddr>>1] = val;
114 spuAddr+=2;
115 if(spuAddr>0x7ffff) spuAddr=0;
116 return;
117 //-------------------------------------------------//
118 case H_SPUctrl:
119 spuCtrl=val;
120 return;
121 //-------------------------------------------------//
122 case H_SPUstat:
123 spuStat=val & 0xf800;
124 return;
125 //-------------------------------------------------//
126 case H_SPUirqAddr:
127 spuIrq = val;
128 pSpuIrq=spuMemC+((unsigned long) val<<3);
129 return;
130 //-------------------------------------------------//
131 case H_SPUon1:
132 //SoundOn(0,16,val);
133 return;
134 //-------------------------------------------------//
135 case H_SPUon2:
136 //SoundOn(16,24,val);
137 return;
138 //-------------------------------------------------//
139 case H_SPUoff1:
140 //SoundOff(0,16,val);
141 return;
142 //-------------------------------------------------//
143 case H_SPUoff2:
144 //SoundOff(16,24,val);
145 return;
146 //-------------------------------------------------//
147 case H_CDLeft:
148 if(cddavCallback) cddavCallback(0,val);
149 return;
150 case H_CDRight:
151 if(cddavCallback) cddavCallback(1,val);
152 return;
153 //-------------------------------------------------//
154 case H_FMod1:
155 //FModOn(0,16,val);
156 return;
157 //-------------------------------------------------//
158 case H_FMod2:
159 //FModOn(16,24,val);
160 return;
161 //-------------------------------------------------//
162 case H_Noise1:
163 //NoiseOn(0,16,val);
164 return;
165 //-------------------------------------------------//
166 case H_Noise2:
167 //NoiseOn(16,24,val);
168 return;
169 //-------------------------------------------------//
170 case H_RVBon1:
171 //ReverbOn(0,16,val);
172 return;
173 //-------------------------------------------------//
174 case H_RVBon2:
175 //ReverbOn(16,24,val);
176 return;
177 //-------------------------------------------------//
178 case H_Reverb:
179 return;
180 }
181}
182
183////////////////////////////////////////////////////////////////////////\r
184
185unsigned short CALLBACK SPUreadRegister(unsigned long reg)
186{
187 unsigned long r=reg&0xfff;
188
189 if(r>=0x0c00 && r<0x0d80)
190 {
191 switch(r&0x0f)
192 {
193 case 12: // adsr vol
194 {
195 //int ch=(r>>4)-0xc0;
196 static unsigned short adsr_dummy_vol=0;
197 adsr_dummy_vol=!adsr_dummy_vol;
198 return adsr_dummy_vol;
199 }
200
201 case 14: // return curr loop adr
202 {
203 //int ch=(r>>4)-0xc0;
204 return 0;
205 }
206 }
207 }
208
209 switch(r)
210 {
211 case H_SPUctrl:
212 return spuCtrl;
213
214 case H_SPUstat:
215 return spuStat;
216
217 case H_SPUaddr:
218 return (unsigned short)(spuAddr>>3);
219
220 case H_SPUdata:
221 {
222 unsigned short s=spuMem[spuAddr>>1];
223 spuAddr+=2;
224 if(spuAddr>0x7ffff) spuAddr=0;
225 return s;
226 }
227
228 case H_SPUirqAddr:
229 return spuIrq;
230 }
231 return regArea[(r-0xc00)>>1];
232}
233
234////////////////////////////////////////////////////////////////////////
235
236unsigned short CALLBACK SPUreadDMA(void)
237{
238 unsigned short s=spuMem[spuAddr>>1];
239 spuAddr+=2;
240 if(spuAddr>0x7ffff) spuAddr=0;
241 return s;
242}
243
244////////////////////////////////////////////////////////////////////////
245
246void CALLBACK SPUwriteDMA(unsigned short val)
247{
248 spuMem[spuAddr>>1] = val; // spu addr got by writeregister\r
249 spuAddr+=2; // inc spu addr
250 if(spuAddr>0x7ffff) spuAddr=0; // wrap
251}
252
253////////////////////////////////////////////////////////////////////////
254
255void CALLBACK SPUwriteDMAMem(unsigned short * pusPSXMem,int iSize)
256{
257 int i;
258 for(i=0;i<iSize;i++)
259 {
260 spuMem[spuAddr>>1] = *pusPSXMem++; // spu addr got by writeregister\r
261 spuAddr+=2; // inc spu addr
262 if(spuAddr>0x7ffff) spuAddr=0; // wrap
263 }
264}
265
266////////////////////////////////////////////////////////////////////////
267
268void CALLBACK SPUreadDMAMem(unsigned short * pusPSXMem,int iSize)
269{
270 int i;
271 for(i=0;i<iSize;i++)
272 {
273 *pusPSXMem++=spuMem[spuAddr>>1]; // spu addr got by writeregister
274 spuAddr+=2; // inc spu addr
275 if(spuAddr>0x7ffff) spuAddr=0; // wrap
276 }
277}
278
279////////////////////////////////////////////////////////////////////////
280// XA AUDIO
281////////////////////////////////////////////////////////////////////////
282
283void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap)
284{
285}
286
287////////////////////////////////////////////////////////////////////////
288
289////////////////////////////////////////////////////////////////////////
290// INIT/EXIT STUFF
291////////////////////////////////////////////////////////////////////////
292
293long CALLBACK SPUinit(void)
294{
295 spuMemC=(unsigned char *)spuMem; // just small setup
296 return 0;
297}
298
299////////////////////////////////////////////////////////////////////////
300
301int bSPUIsOpen=0;
302
303long CALLBACK SPUopen(void)
304{
305 if(bSPUIsOpen) return 0;
306
307 bSPUIsOpen=1;
308
309 //if(pConfigFile) ReadConfigFile(pConfigFile);
310
311 return PSE_SPU_ERR_SUCCESS;
312}
313
314////////////////////////////////////////////////////////////////////////
315
316void SPUsetConfigFile(char * pCfg)
317{
318 pConfigFile=pCfg;
319}
320
321////////////////////////////////////////////////////////////////////////
322
323long CALLBACK SPUclose(void)
324{
325 if(!bSPUIsOpen) return 0;
326 bSPUIsOpen=0;
327 return 0;
328}
329
330////////////////////////////////////////////////////////////////////////
331
332long CALLBACK SPUshutdown(void)
333{
334 return 0;
335}
336
337////////////////////////////////////////////////////////////////////////
338// MISC STUFF
339////////////////////////////////////////////////////////////////////////
340
341long CALLBACK SPUtest(void)
342{
343 return 0;
344}
345
346void SPUasync(unsigned int cycle)
347{
348}
349
350void SPUplayCDDAchannel(short *pcm, int nbytes)
351{
352}
353
354////////////////////////////////////////////////////////////////////////
355// this functions will be called once,
356// passes a callback that should be called on SPU-IRQ
357
358void CALLBACK SPUregisterCallback(void (CALLBACK *callback)(void))
359{
360 irqCallback = callback;
361}
362
363void CALLBACK SPUregisterCDDAVolume(void (CALLBACK *CDDAVcallback)(unsigned short,unsigned short))
364{
365 cddavCallback = CDDAVcallback;
366}
367
368////////////////////////////////////////////////////////////////////////\r
369
370char * CALLBACK PSEgetLibName(void)
371{
372 return libraryName;
373}
374
375////////////////////////////////////////////////////////////////////////
376
377unsigned long CALLBACK PSEgetLibType(void)
378{
379 return PSE_LT_SPU;
380}
381
382////////////////////////////////////////////////////////////////////////\r
383
384unsigned long CALLBACK PSEgetLibVersion(void)\r
385{
386 return version<<16|revision<<8|build;
387}
388
389
390char * SPUgetLibInfos(void)
391{
392 return libraryInfo;
393}
394
395////////////////////////////////////////////////////////////////////////\r
396
397typedef struct\r
398{
399 char szSPUName[8];
400 unsigned long ulFreezeVersion;
401 unsigned long ulFreezeSize;
402 unsigned char cSPUPort[0x200];
403 unsigned char cSPURam[0x80000];
404 xa_decode_t xaS;
405} SPUFreeze_t;
406
407typedef struct
408{
409 unsigned long Future[256];
410
411} SPUNULLFreeze_t;
412
413////////////////////////////////////////////////////////////////////////\r
414
415long CALLBACK SPUfreeze(unsigned long ulFreezeMode,SPUFreeze_t * pF)
416{
417 int i;
418
419 if(!pF) return 0;
420
421 if(ulFreezeMode)
422 {
423 if(ulFreezeMode==1)
424 memset(pF,0,sizeof(SPUFreeze_t)+sizeof(SPUNULLFreeze_t));
425
426 strcpy(pF->szSPUName,"PBNUL");
427 pF->ulFreezeVersion=1;
428 pF->ulFreezeSize=sizeof(SPUFreeze_t)+sizeof(SPUNULLFreeze_t);
429
430 if(ulFreezeMode==2) return 1;
431
432 memcpy(pF->cSPURam,spuMem,0x80000);
433 memcpy(pF->cSPUPort,regArea,0x200);
434 // dummy:
435 memset(&pF->xaS,0,sizeof(xa_decode_t));
436 return 1;
437 }
438
439 if(ulFreezeMode!=0) return 0;
440
441 memcpy(spuMem,pF->cSPURam,0x80000);
442 memcpy(regArea,pF->cSPUPort,0x200);
443
444 for(i=0;i<0x100;i++)
445 {
446 if(i!=H_SPUon1-0xc00 && i!=H_SPUon2-0xc00)
447 SPUwriteRegister(0x1f801c00+i*2,regArea[i]);
448 }
449 SPUwriteRegister(H_SPUon1,regArea[(H_SPUon1-0xc00)/2]);
450 SPUwriteRegister(H_SPUon2,regArea[(H_SPUon2-0xc00)/2]);
451
452 return 1;
453}
454
455
456////////////////////////////////////////////////////////////////////////
457////////////////////////////////////////////////////////////////////////
458////////////////////////////////////////////////////////////////////////
459// UNUSED WINDOWS FUNCS... YOU SHOULDN'T USE THEM IN LINUX
460
461long CALLBACK SPUconfigure(void)
462{
463 return 0;
464}
465
466void CALLBACK SPUabout(void)
467{
468}
469
470////////////////////////////////////////////////////////////////////////
471////////////////////////////////////////////////////////////////////////
472////////////////////////////////////////////////////////////////////////
473// OLD PSEMU 1 FUNCS... YOU SHOULDN'T USE THEM
474
475unsigned short CALLBACK SPUgetOne(unsigned long val)
476{
477 if(spuAddr!=0xffffffff)
478 {
479 return SPUreadDMA();
480 }
481 if(val>=512*1024) val=512*1024-1;
482 return spuMem[val>>1];
483}
484
485void CALLBACK SPUputOne(unsigned long val,unsigned short data)
486{
487 if(spuAddr!=0xffffffff)
488 {
489 SPUwriteDMA(data);
490 return;
491 }
492 if(val>=512*1024) val=512*1024-1;
493 spuMem[val>>1] = data;
494}
495
496void CALLBACK SPUplaySample(unsigned char ch)
497{
498}
499
500void CALLBACK SPUsetAddr(unsigned char ch, unsigned short waddr)
501{
502 //s_chan[ch].pStart=spuMemC+((unsigned long) waddr<<3);
503}
504
505void CALLBACK SPUsetPitch(unsigned char ch, unsigned short pitch)
506{
507 //SetPitch(ch,pitch);
508}
509
510void CALLBACK SPUsetVolumeL(unsigned char ch, short vol)
511{
512 //SetVolumeL(ch,vol);
513}
514
515void CALLBACK SPUsetVolumeR(unsigned char ch, short vol)
516{
517 //SetVolumeR(ch,vol);
518}
519
520void CALLBACK SPUstartChannels1(unsigned short channels)
521{
522 //SoundOn(0,16,channels);
523}
524
525void CALLBACK SPUstartChannels2(unsigned short channels)
526{
527 //SoundOn(16,24,channels);
528}
529
530void CALLBACK SPUstopChannels1(unsigned short channels)
531{
532 //SoundOff(0,16,channels);
533}
534
535void CALLBACK SPUstopChannels2(unsigned short channels)
536{
537 //SoundOff(16,24,channels);
538}