ZeroSPU2: Change the ini file to be more easily editable by hand in Linux, and assorted cleanup.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@622 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2009-02-27 03:30:25 +00:00
parent b7d3c6316a
commit 1504b88a75
2 changed files with 187 additions and 128 deletions

View File

@ -68,12 +68,14 @@ void SoundFeedVoiceData(unsigned char* pSound,long lBytes)
GtkWidget *MsgDlg, *ConfDlg;
void OnMsg_Ok() {
void OnMsg_Ok()
{
gtk_widget_destroy(MsgDlg);
gtk_main_quit();
}
void SysMessage(char *fmt, ...) {
void SysMessage(char *fmt, ...)
{
GtkWidget *Ok,*Txt;
GtkWidget *Box,*Box1;
va_list list;
@ -147,7 +149,9 @@ void on_Conf_Ok (GtkButton *button, gpointer user_data)
conf.options |= OPTION_RECORDING;
if (is_checked(ConfDlg, "mutebutton"))
conf.options |= OPTION_MUTE;
conf.Log = is_checked(ConfDlg, "loggingbutton");
SaveConfig();
gtk_widget_destroy(ConfDlg);
gtk_main_quit();
@ -173,14 +177,22 @@ void SaveConfig()
char cfg[255];
strcpy(cfg, s_strIniPath.c_str());
f = fopen(cfg,"w");
if (f == NULL)
{
ERROR_LOG("Failed to open %s\n", s_strIniPath.c_str());
return;
}
fprintf(f, "log = %d\n", conf.Log);
fprintf(f, "options = %d\n", conf.options);
//fprintf(f, "options = %d\n", conf.options);
fprintf(f, "realtime = %d\n", is_checked(ConfDlg, "realtimebutton"));
fprintf(f, "timestretch = %d\n", is_checked(ConfDlg, "timescalingbutton"));
fprintf(f, "recording = %d\n", is_checked(ConfDlg, "recordingbutton"));
fprintf(f, "mute = %d\n", is_checked(ConfDlg, "mutebutton"));
fclose(f);
}
@ -188,10 +200,12 @@ void LoadConfig()
{
FILE *f;
char cfg[255];
int temp;
memset(&conf, 0, sizeof(conf));
strcpy(cfg, s_strIniPath.c_str());
f = fopen(cfg, "r");
if (f == NULL)
{
@ -201,7 +215,22 @@ void LoadConfig()
SaveConfig();//save and return
return;
}
fscanf(f, "log = %d\n", &conf.Log);
fscanf(f, "realtime = %d\n", &temp);
if (temp) conf.options |= OPTION_REALTIME;
fscanf(f, "timestretch = %d\n", &temp);
if (temp) conf.options |= OPTION_TIMESTRETCH;
fscanf(f, "recording = %d\n", &temp);
if (temp) conf.options |= OPTION_RECORDING;
fscanf(f, "mute = %d\n", &temp);
if (temp) conf.options |= OPTION_MUTE;
fscanf(f, "options = %d\n", &conf.options);
fclose(f);
}

View File

@ -600,10 +600,9 @@ void MixChannels(int core)
// simulate SPU2 for 1ms
void SPU2Worker()
{
int s_1,s_2,fa;
u8* start;
u32 nSample;
int ch,predict_nr,shift_factor,flags,d,s;
int ch, predict_nr, shift_factor, flags;
// assume s_buffers are zeroed out
if ( dwNewChannel2[0] || dwNewChannel2[1] )
@ -629,8 +628,10 @@ void SPU2Worker()
while(ns<NSSIZE)
{
if (pChannel->bFMod==1 && iFMod[ns]) // fmod freq channel
pChannel->FModChangeFrequency(ns);
int s_1, s_2, fa;
// fmod freq channel
if (pChannel->bFMod==1 && iFMod[ns]) pChannel->FModChangeFrequency(ns);
while(pChannel->spos >= 0x10000 )
{
@ -647,21 +648,23 @@ void SPU2Worker()
goto ENDX; // -> and done for this channel
}
pChannel->iSBPos=0;
// decode the 16byte packet
s_1=pChannel->s_1;
s_2=pChannel->s_2;
predict_nr=(s32)start[0];
shift_factor=predict_nr&0xf;
predict_nr >>= 4;
flags=(s32)start[1];
start += 2;
pChannel->iSBPos=0;
// decode the 16byte packet
s_1=pChannel->s_1;
s_2=pChannel->s_2;
for (nSample=0; nSample<28; ++start)
{
d = (int)*start;
int s;
int d = (int)*start;
s = ((d & 0xf)<<12);
if (s & 0x8000) s |= 0xffff0000;
@ -669,23 +672,22 @@ void SPU2Worker()
fa += ((s_1 * f[predict_nr][0]) >> 6) + ((s_2 * f[predict_nr][1]) >> 6);
s_2 = s_1;
s_1 = fa;
s = ((d & 0xf0) << 8);
pChannel->SB[nSample++]=fa;
s = ((d & 0xf0) << 8);
if (s & 0x8000) s|=0xffff0000;
fa = (s>>shift_factor);
fa += ((s_1 * f[predict_nr][0])>>6) + ((s_2 * f[predict_nr][1]) >> 6);
s_2 = s_1;
s_1 = fa;
pChannel->SB[nSample++]=fa;
}
// irq occurs no matter what core access the address
for (int core = 0; core < 2; ++core)
{
if (((SPU_CONTROL_*)(spu2regs + 0x400 * core + REG_C0_CTRL))->irq) // some callback and irq active?
if (((SPU_CONTROL_*)(spu2regs + (0x400 * core) + REG_C0_CTRL))->irq) // some callback and irq active?
{
// if irq address reached or irq on looping addr, when stop/loop flag is set
u8* pirq = (u8*)pSpuIrq[core];
@ -700,7 +702,7 @@ void SPU2Worker()
// flag handler
if ((flags&4) && (!pChannel->bIgnoreLoop))
pChannel->pLoop=start-16; // loop adress
pChannel->pLoop=start-16; // loop address
if (flags&1) // 1: stop/loop
{
@ -1457,39 +1459,98 @@ int CALLBACK SPU2setupRecording(int start, void* pData)
return 1;
}
s32 CALLBACK SPU2freeze(int mode, freezeData *data)
void save_data(freezeData *data)
{
LOG_CALLBACK("SPU2freeze()\n");
SPU2freezeData *spud;
int i;
assert( g_pDMABaseAddr != 0 );
if (mode == FREEZE_LOAD)
{
spud = (SPU2freezeData*)data->data;
spud->version = 0x70000001;
memcpy(spud->spu2regs, spu2regs, 0x10000);
memcpy(spud->spu2mem, spu2mem, 0x200000);
spud->nSpuIrq[0] = (int)(pSpuIrq[0] - spu2mem);
spud->nSpuIrq[1] = (int)(pSpuIrq[1] - spu2mem);
memcpy(spud->dwNewChannel2, dwNewChannel2, 4*2);
memcpy(spud->dwEndChannel2, dwEndChannel2, 4*2);
spud->dwNoiseVal = dwNoiseVal;
spud->interrupt = interrupt;
memcpy(spud->iFMod, iFMod, sizeof(iFMod));
memcpy(spud->MemAddr, MemAddr, sizeof(MemAddr));
spud->adma[0] = Adma4;
spud->adma[1] = Adma7;
spud->Adma4MemAddr = (u32)((uptr)Adma4.MemAddr - g_pDMABaseAddr);
spud->Adma7MemAddr = (u32)((uptr)Adma7.MemAddr - g_pDMABaseAddr);
spud->SPUCycles = SPUCycles;
spud->SPUWorkerCycles = SPUWorkerCycles;
memcpy(spud->SPUStartCycle, SPUStartCycle, sizeof(SPUStartCycle));
memcpy(spud->SPUTargetCycle, SPUTargetCycle, sizeof(SPUTargetCycle));
for (i = 0; i < ARRAYSIZE(s_nDurations); ++i)
{
s_nDurations[i] = NSFRAMES*1000;
}
s_nTotalDuration = ARRAYSIZE(s_nDurations)*NSFRAMES*1000;
s_nCurDuration = 0;
spud->voicesize = SPU_VOICE_STATE_SIZE;
for (i = 0; i < ARRAYSIZE(voices); ++i)
{
memcpy(&spud->voices[i], &voices[i], SPU_VOICE_STATE_SIZE);
spud->voices[i].pStart = (u8*)((uptr)voices[i].pStart-(uptr)spu2mem);
spud->voices[i].pLoop = (u8*)((uptr)voices[i].pLoop-(uptr)spu2mem);
spud->voices[i].pCurr = (u8*)((uptr)voices[i].pCurr-(uptr)spu2mem);
}
g_startcount=0xffffffff;
s_GlobalTimeStamp = 0;
s_nDropPacket = 0;
}
void load_data(freezeData *data)
{
SPU2freezeData *spud;
int i;
spud = (SPU2freezeData*)data->data;
if (spud->version != 0x70000001)
{
ERROR_LOG("zerospu2: data wrong format\n");
return 0;
ERROR_LOG("zerospu2: Sound data either corrupted or from another plugin. Ignoring.\n");
return;
}
memcpy(spu2regs, spud->spu2regs, 0x10000);
memcpy(spu2mem, spud->spu2mem, 0x200000);
pSpuIrq[0] = spu2mem + spud->nSpuIrq[0];
pSpuIrq[1] = spu2mem + spud->nSpuIrq[1];
memcpy(dwNewChannel2, spud->dwNewChannel2, 4*2);
memcpy(dwEndChannel2, spud->dwEndChannel2, 4*2);
dwNoiseVal = spud->dwNoiseVal;
memcpy(iFMod, spud->iFMod, sizeof(iFMod));
interrupt = spud->interrupt;
memcpy(iFMod, spud->iFMod, sizeof(iFMod));
memcpy(MemAddr, spud->MemAddr, sizeof(MemAddr));
Adma4 = spud->adma[0];
Adma4.MemAddr = (u16*)(g_pDMABaseAddr+spud->Adma4MemAddr);
Adma7 = spud->adma[1];
Adma4.MemAddr = (u16*)(g_pDMABaseAddr+spud->Adma4MemAddr);
Adma7.MemAddr = (u16*)(g_pDMABaseAddr+spud->Adma7MemAddr);
SPUCycles = spud->SPUCycles;
SPUWorkerCycles = spud->SPUWorkerCycles;
memcpy(SPUStartCycle, spud->SPUStartCycle, sizeof(SPUStartCycle));
memcpy(SPUTargetCycle, spud->SPUTargetCycle, sizeof(SPUTargetCycle));
@ -1514,56 +1575,25 @@ s32 CALLBACK SPU2freeze(int mode, freezeData *data)
s_nQueuedBuffers = 0;
s_nDropPacket = 0;
}
else if (mode == FREEZE_SAVE)
s32 CALLBACK SPU2freeze(int mode, freezeData *data)
{
spud = (SPU2freezeData*)data->data;
spud->version = 0x70000001;
LOG_CALLBACK("SPU2freeze()\n");
assert( g_pDMABaseAddr != 0 );
memcpy(spud->spu2regs, spu2regs, 0x10000);
memcpy(spud->spu2mem, spu2mem, 0x200000);
spud->nSpuIrq[0] = (int)(pSpuIrq[0] - spu2mem);
spud->nSpuIrq[1] = (int)(pSpuIrq[1] - spu2mem);
memcpy(spud->dwNewChannel2, dwNewChannel2, 4*2);
memcpy(spud->dwEndChannel2, dwEndChannel2, 4*2);
spud->dwNoiseVal = dwNoiseVal;
memcpy(spud->iFMod, iFMod, sizeof(iFMod));
spud->interrupt = interrupt;
memcpy(spud->MemAddr, MemAddr, sizeof(MemAddr));
spud->adma[0] = Adma4;
spud->Adma4MemAddr = (u32)((uptr)Adma4.MemAddr - g_pDMABaseAddr);
spud->adma[1] = Adma7;
spud->Adma7MemAddr = (u32)((uptr)Adma7.MemAddr - g_pDMABaseAddr);
spud->SPUCycles = SPUCycles;
spud->SPUWorkerCycles = SPUWorkerCycles;
memcpy(spud->SPUStartCycle, SPUStartCycle, sizeof(SPUStartCycle));
memcpy(spud->SPUTargetCycle, SPUTargetCycle, sizeof(SPUTargetCycle));
for (i = 0; i < ARRAYSIZE(s_nDurations); ++i)
{
s_nDurations[i] = NSFRAMES*1000;
}
s_nTotalDuration = ARRAYSIZE(s_nDurations)*NSFRAMES*1000;
s_nCurDuration = 0;
spud->voicesize = SPU_VOICE_STATE_SIZE;
for (i = 0; i < ARRAYSIZE(voices); ++i)
{
memcpy(&spud->voices[i], &voices[i], SPU_VOICE_STATE_SIZE);
spud->voices[i].pStart = (u8*)((uptr)voices[i].pStart-(uptr)spu2mem);
spud->voices[i].pLoop = (u8*)((uptr)voices[i].pLoop-(uptr)spu2mem);
spud->voices[i].pCurr = (u8*)((uptr)voices[i].pCurr-(uptr)spu2mem);
}
g_startcount=0xffffffff;
s_GlobalTimeStamp = 0;
s_nDropPacket = 0;
}
else if (mode == FREEZE_SIZE)
switch (mode)
{
case FREEZE_LOAD:
load_data(data);
break;
case FREEZE_SAVE:
save_data(data);
break;
case FREEZE_SIZE:
data->size = sizeof(SPU2freezeData);
break;
default:
break;
}
return 0;