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
|
/***************************************************************************
freeze.c - description
-------------------
begin : Wed May 15 2002
copyright : (C) 2002 by Pete Bernert
email : BlackDove@addcom.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. See also the license.txt file for *
* additional informations. *
* *
***************************************************************************/
#include "stdafx.h"
#define _IN_FREEZE
#include "externals.h"
#include "registers.h"
#include "spu.h"
#include "regs.h"
////////////////////////////////////////////////////////////////////////
// freeze structs
////////////////////////////////////////////////////////////////////////
typedef struct
{
char szSPUName[8];
uint32_t ulFreezeVersion;
uint32_t ulFreezeSize;
unsigned char cSPUPort[0x200];
unsigned char cSPURam[0x80000];
xa_decode_t xaS;
} SPUFreeze_t;
typedef struct
{
unsigned short spuIrq;
uint32_t pSpuIrq;
uint32_t spuAddr;
uint32_t dummy1;
uint32_t dummy2;
uint32_t dummy3;
SPUCHAN s_chan[MAXCHAN];
} SPUOSSFreeze_t;
////////////////////////////////////////////////////////////////////////
void LoadStateV5(SPUFreeze_t * pF); // newest version
void LoadStateUnknown(SPUFreeze_t * pF); // unknown format
extern int lastch;
////////////////////////////////////////////////////////////////////////
// SPUFREEZE: called by main emu on savestate load/save
////////////////////////////////////////////////////////////////////////
long CALLBACK SPUfreeze(uint32_t ulFreezeMode,SPUFreeze_t * pF)
{
int i;SPUOSSFreeze_t * pFO;
if(!pF) return 0; // first check
if(ulFreezeMode) // info or save?
{//--------------------------------------------------//
if(ulFreezeMode==1)
memset(pF,0,sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t));
strcpy(pF->szSPUName,"PBOSS");
pF->ulFreezeVersion=5;
pF->ulFreezeSize=sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t);
if(ulFreezeMode==2) return 1; // info mode? ok, bye
// save mode:
RemoveTimer(); // stop timer
memcpy(pF->cSPURam,spuMem,0x80000); // copy common infos
memcpy(pF->cSPUPort,regArea,0x200);
if(xapGlobal && XAPlay!=XAFeed) // some xa
{
pF->xaS=*xapGlobal;
}
else
memset(&pF->xaS,0,sizeof(xa_decode_t)); // or clean xa
pFO=(SPUOSSFreeze_t *)(pF+1); // store special stuff
pFO->spuIrq=spuIrq;
if(pSpuIrq) pFO->pSpuIrq = (unsigned long)pSpuIrq-(unsigned long)spuMemC;
pFO->spuAddr=spuAddr;
if(pFO->spuAddr==0) pFO->spuAddr=0xbaadf00d;
for(i=0;i<MAXCHAN;i++)
{
memcpy((void *)&pFO->s_chan[i],(void *)&s_chan[i],sizeof(SPUCHAN));
if(pFO->s_chan[i].pStart)
pFO->s_chan[i].pStart-=(unsigned long)spuMemC;
if(pFO->s_chan[i].pCurr)
pFO->s_chan[i].pCurr-=(unsigned long)spuMemC;
if(pFO->s_chan[i].pLoop)
pFO->s_chan[i].pLoop-=(unsigned long)spuMemC;
}
SetupTimer(); // sound processing on again
return 1;
//--------------------------------------------------//
}
if(ulFreezeMode!=0) return 0; // bad mode? bye
RemoveTimer(); // we stop processing while doing the save!
memcpy(spuMem,pF->cSPURam,0x80000); // get ram
memcpy(regArea,pF->cSPUPort,0x200);
if(pF->xaS.nsamples<=4032) // start xa again
SPUplayADPCMchannel(&pF->xaS);
xapGlobal=0;
if(!strcmp(pF->szSPUName,"PBOSS") && pF->ulFreezeVersion==5)
LoadStateV5(pF);
else LoadStateUnknown(pF);
lastch = -1;
// repair some globals
for(i=0;i<=62;i+=2)
SPUwriteRegister(H_Reverb+i,regArea[(H_Reverb+i-0xc00)>>1]);
SPUwriteRegister(H_SPUReverbAddr,regArea[(H_SPUReverbAddr-0xc00)>>1]);
SPUwriteRegister(H_SPUrvolL,regArea[(H_SPUrvolL-0xc00)>>1]);
SPUwriteRegister(H_SPUrvolR,regArea[(H_SPUrvolR-0xc00)>>1]);
SPUwriteRegister(H_SPUctrl,(unsigned short)(regArea[(H_SPUctrl-0xc00)>>1]|0x4000));
SPUwriteRegister(H_SPUstat,regArea[(H_SPUstat-0xc00)>>1]);
SPUwriteRegister(H_CDLeft,regArea[(H_CDLeft-0xc00)>>1]);
SPUwriteRegister(H_CDRight,regArea[(H_CDRight-0xc00)>>1]);
// fix to prevent new interpolations from crashing
for(i=0;i<MAXCHAN;i++) s_chan[i].SB[28]=0;
SetupTimer(); // start sound processing again
return 1;
}
////////////////////////////////////////////////////////////////////////
void LoadStateV5(SPUFreeze_t * pF)
{
int i;SPUOSSFreeze_t * pFO;
pFO=(SPUOSSFreeze_t *)(pF+1);
spuIrq = pFO->spuIrq;
if(pFO->pSpuIrq) pSpuIrq = pFO->pSpuIrq+spuMemC; else pSpuIrq=NULL;
if(pFO->spuAddr)
{
spuAddr = pFO->spuAddr;
if (spuAddr == 0xbaadf00d) spuAddr = 0;
}
for(i=0;i<MAXCHAN;i++)
{
memcpy((void *)&s_chan[i],(void *)&pFO->s_chan[i],sizeof(SPUCHAN));
s_chan[i].pStart+=(unsigned long)spuMemC;
s_chan[i].pCurr+=(unsigned long)spuMemC;
s_chan[i].pLoop+=(unsigned long)spuMemC;
s_chan[i].iMute=0;
s_chan[i].iIrqDone=0;
}
}
////////////////////////////////////////////////////////////////////////
void LoadStateUnknown(SPUFreeze_t * pF)
{
int i;
for(i=0;i<MAXCHAN;i++)
{
s_chan[i].bOn=0;
s_chan[i].bNew=0;
s_chan[i].bStop=0;
s_chan[i].ADSR.lVolume=0;
s_chan[i].pLoop=spuMemC;
s_chan[i].pStart=spuMemC;
s_chan[i].pLoop=spuMemC;
s_chan[i].iMute=0;
s_chan[i].iIrqDone=0;
}
dwNewChannel=0;
pSpuIrq=0;
for(i=0;i<0xc0;i++)
{
SPUwriteRegister(0x1f801c00+i*2,regArea[i]);
}
}
////////////////////////////////////////////////////////////////////////
|