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