1 /////////////////////////////////////////////////////////
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
9 /////////////////////////////////////////////////////////
11 // 0. Get type/name/version
16 // 5. Dma/register/xa calls...
19 /////////////////////////////////////////////////////////
26 // some ms windows compatibility define
30 ////////////////////////////////////////////////////////////////////////
32 ////////////////////////////////////////////////////////////////////////
34 const unsigned char version = 1;
35 const unsigned char revision = 1;
36 const unsigned char build = 1;
37 static char * libraryName = "Pete's Null Audio Driver";
38 static char * libraryInfo = "Pete's Null Audio Driver V1.1\nCoded by Pete Bernert\n";
40 ////////////////////////////////////////////////////////////////////////
42 unsigned short regArea[10000]; // psx buffer
43 unsigned short spuMem[256*1024];
44 unsigned char * spuMemC;
45 unsigned char * pSpuIrq=0;
47 unsigned short spuCtrl, spuStat, spuIrq=0; // some vars to store psx reg infos
48 unsigned long spuAddr=0xffffffff; // address into spu mem
51 ////////////////////////////////////////////////////////////////////////
53 ////////////////////////////////////////////////////////////////////////
55 void (CALLBACK *irqCallback)(void)=0; // func of main emu, called on spu irq
56 void (CALLBACK *cddavCallback)(unsigned short,unsigned short)=0;
58 ////////////////////////////////////////////////////////////////////////
60 ////////////////////////////////////////////////////////////////////////
62 void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, unsigned int cycles)
64 unsigned long r=reg&0xfff;
65 regArea[(r-0xc00)>>1] = val;
67 if(r>=0x0c00 && r<0x0d80)
72 //------------------------------------------------// l volume
76 //------------------------------------------------// r volume
80 //------------------------------------------------// pitch
84 //------------------------------------------------// start
86 //s_chan[ch].pStart=spuMemC+((unsigned long) val<<3);
88 //------------------------------------------------// adsr level
91 //------------------------------------------------// adsr rate
94 //------------------------------------------------// adsr volume
97 //------------------------------------------------// loop adr
100 //------------------------------------------------//
107 //-------------------------------------------------//
109 spuAddr = (unsigned long) val<<3;
111 //-------------------------------------------------//
113 spuMem[spuAddr>>1] = val;
115 if(spuAddr>0x7ffff) spuAddr=0;
117 //-------------------------------------------------//
121 //-------------------------------------------------//
123 spuStat=val & 0xf800;
125 //-------------------------------------------------//
128 pSpuIrq=spuMemC+((unsigned long) val<<3);
130 //-------------------------------------------------//
134 //-------------------------------------------------//
136 //SoundOn(16,24,val);
138 //-------------------------------------------------//
140 //SoundOff(0,16,val);
142 //-------------------------------------------------//
144 //SoundOff(16,24,val);
146 //-------------------------------------------------//
148 if(cddavCallback) cddavCallback(0,val);
151 if(cddavCallback) cddavCallback(1,val);
153 //-------------------------------------------------//
157 //-------------------------------------------------//
161 //-------------------------------------------------//
165 //-------------------------------------------------//
167 //NoiseOn(16,24,val);
169 //-------------------------------------------------//
171 //ReverbOn(0,16,val);
173 //-------------------------------------------------//
175 //ReverbOn(16,24,val);
177 //-------------------------------------------------//
183 ////////////////////////////////////////////////////////////////////////
\r
185 unsigned short CALLBACK SPUreadRegister(unsigned long reg)
187 unsigned long r=reg&0xfff;
189 if(r>=0x0c00 && r<0x0d80)
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;
201 case 14: // return curr loop adr
203 //int ch=(r>>4)-0xc0;
218 return (unsigned short)(spuAddr>>3);
222 unsigned short s=spuMem[spuAddr>>1];
224 if(spuAddr>0x7ffff) spuAddr=0;
231 return regArea[(r-0xc00)>>1];
234 ////////////////////////////////////////////////////////////////////////
236 unsigned short CALLBACK SPUreadDMA(void)
238 unsigned short s=spuMem[spuAddr>>1];
240 if(spuAddr>0x7ffff) spuAddr=0;
244 ////////////////////////////////////////////////////////////////////////
246 void CALLBACK SPUwriteDMA(unsigned short val)
248 spuMem[spuAddr>>1] = val; // spu addr got by writeregister
\r
249 spuAddr+=2; // inc spu addr
250 if(spuAddr>0x7ffff) spuAddr=0; // wrap
253 ////////////////////////////////////////////////////////////////////////
255 void CALLBACK SPUwriteDMAMem(unsigned short * pusPSXMem,int iSize,unsigned int cycles)
260 spuMem[spuAddr>>1] = *pusPSXMem++; // spu addr got by writeregister
\r
261 spuAddr+=2; // inc spu addr
262 if(spuAddr>0x7ffff) spuAddr=0; // wrap
266 ////////////////////////////////////////////////////////////////////////
268 void CALLBACK SPUreadDMAMem(unsigned short * pusPSXMem,int iSize,unsigned int cycles)
273 *pusPSXMem++=spuMem[spuAddr>>1]; // spu addr got by writeregister
274 spuAddr+=2; // inc spu addr
275 if(spuAddr>0x7ffff) spuAddr=0; // wrap
279 ////////////////////////////////////////////////////////////////////////
281 ////////////////////////////////////////////////////////////////////////
283 void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap)
287 ////////////////////////////////////////////////////////////////////////
289 ////////////////////////////////////////////////////////////////////////
291 ////////////////////////////////////////////////////////////////////////
293 long CALLBACK SPUinit(void)
295 spuMemC=(unsigned char *)spuMem; // just small setup
299 ////////////////////////////////////////////////////////////////////////
303 long CALLBACK SPUopen(void)
305 if(bSPUIsOpen) return 0;
309 //if(pConfigFile) ReadConfigFile(pConfigFile);
311 return PSE_SPU_ERR_SUCCESS;
314 ////////////////////////////////////////////////////////////////////////
316 void SPUsetConfigFile(char * pCfg)
321 ////////////////////////////////////////////////////////////////////////
323 long CALLBACK SPUclose(void)
325 if(!bSPUIsOpen) return 0;
330 ////////////////////////////////////////////////////////////////////////
332 long CALLBACK SPUshutdown(void)
337 ////////////////////////////////////////////////////////////////////////
339 ////////////////////////////////////////////////////////////////////////
341 long CALLBACK SPUtest(void)
346 void SPUasync(unsigned int cycle, unsigned int flags)
350 int SPUplayCDDAchannel(short *pcm, int nbytes)
355 ////////////////////////////////////////////////////////////////////////
356 // this functions will be called once,
357 // passes a callback that should be called on SPU-IRQ
359 void CALLBACK SPUregisterCallback(void (CALLBACK *callback)(void))
361 irqCallback = callback;
364 void CALLBACK SPUregisterCDDAVolume(void (CALLBACK *CDDAVcallback)(unsigned short,unsigned short))
366 cddavCallback = CDDAVcallback;
369 ////////////////////////////////////////////////////////////////////////
\r
371 char * CALLBACK PSEgetLibName(void)
376 ////////////////////////////////////////////////////////////////////////
378 unsigned long CALLBACK PSEgetLibType(void)
383 ////////////////////////////////////////////////////////////////////////
\r
385 unsigned long CALLBACK PSEgetLibVersion(void)
\r
387 return version<<16|revision<<8|build;
391 char * SPUgetLibInfos(void)
396 ////////////////////////////////////////////////////////////////////////
\r
401 unsigned long ulFreezeVersion;
402 unsigned long ulFreezeSize;
403 unsigned char cSPUPort[0x200];
404 unsigned char cSPURam[0x80000];
410 unsigned long Future[256];
414 ////////////////////////////////////////////////////////////////////////
\r
416 long CALLBACK SPUfreeze(unsigned long ulFreezeMode,SPUFreeze_t * pF,unsigned int cycles)
425 memset(pF,0,sizeof(SPUFreeze_t)+sizeof(SPUNULLFreeze_t));
427 strcpy(pF->szSPUName,"PBNUL");
428 pF->ulFreezeVersion=1;
429 pF->ulFreezeSize=sizeof(SPUFreeze_t)+sizeof(SPUNULLFreeze_t);
431 if(ulFreezeMode==2) return 1;
433 memcpy(pF->cSPURam,spuMem,0x80000);
434 memcpy(pF->cSPUPort,regArea,0x200);
436 memset(&pF->xaS,0,sizeof(xa_decode_t));
440 if(ulFreezeMode!=0) return 0;
442 memcpy(spuMem,pF->cSPURam,0x80000);
443 memcpy(regArea,pF->cSPUPort,0x200);
447 if(i!=H_SPUon1-0xc00 && i!=H_SPUon2-0xc00)
448 SPUwriteRegister(0x1f801c00+i*2,regArea[i],cycles);
450 SPUwriteRegister(H_SPUon1,regArea[(H_SPUon1-0xc00)/2],cycles);
451 SPUwriteRegister(H_SPUon2,regArea[(H_SPUon2-0xc00)/2],cycles);
457 ////////////////////////////////////////////////////////////////////////
458 ////////////////////////////////////////////////////////////////////////
459 ////////////////////////////////////////////////////////////////////////
460 // UNUSED WINDOWS FUNCS... YOU SHOULDN'T USE THEM IN LINUX
462 long CALLBACK SPUconfigure(void)
467 void CALLBACK SPUabout(void)
471 ////////////////////////////////////////////////////////////////////////
472 ////////////////////////////////////////////////////////////////////////
473 ////////////////////////////////////////////////////////////////////////
474 // OLD PSEMU 1 FUNCS... YOU SHOULDN'T USE THEM
476 unsigned short CALLBACK SPUgetOne(unsigned long val)
478 if(spuAddr!=0xffffffff)
482 if(val>=512*1024) val=512*1024-1;
483 return spuMem[val>>1];
486 void CALLBACK SPUputOne(unsigned long val,unsigned short data)
488 if(spuAddr!=0xffffffff)
493 if(val>=512*1024) val=512*1024-1;
494 spuMem[val>>1] = data;
497 void CALLBACK SPUplaySample(unsigned char ch)
501 void CALLBACK SPUsetAddr(unsigned char ch, unsigned short waddr)
503 //s_chan[ch].pStart=spuMemC+((unsigned long) waddr<<3);
506 void CALLBACK SPUsetPitch(unsigned char ch, unsigned short pitch)
508 //SetPitch(ch,pitch);
511 void CALLBACK SPUsetVolumeL(unsigned char ch, short vol)
513 //SetVolumeL(ch,vol);
516 void CALLBACK SPUsetVolumeR(unsigned char ch, short vol)
518 //SetVolumeR(ch,vol);
521 void CALLBACK SPUstartChannels1(unsigned short channels)
523 //SoundOn(0,16,channels);
526 void CALLBACK SPUstartChannels2(unsigned short channels)
528 //SoundOn(16,24,channels);
531 void CALLBACK SPUstopChannels1(unsigned short channels)
533 //SoundOff(0,16,channels);
536 void CALLBACK SPUstopChannels2(unsigned short channels)
538 //SoundOff(16,24,channels);