2008-12-08 05:25:12 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// 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, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
// Games that uses this UCode:
|
|
|
|
// Zelda: The Windwaker, Mario Sunshine, Mario Kart, Twilight Princess
|
|
|
|
|
|
|
|
#include "../Globals.h"
|
|
|
|
#include "UCodes.h"
|
|
|
|
#include "UCode_Zelda.h"
|
2009-06-20 10:39:45 +00:00
|
|
|
#include "UCode_Zelda_ADPCM.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "../MailHandler.h"
|
|
|
|
|
2009-01-29 00:57:55 +00:00
|
|
|
#include "../main.h"
|
2009-03-26 09:29:14 +00:00
|
|
|
#include "Mixer.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-06-20 01:33:13 +00:00
|
|
|
#include "WaveFile.h"
|
2009-06-16 21:58:49 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
CUCode_Zelda::CUCode_Zelda(CMailHandler& _rMailHandler, u32 _CRC)
|
2008-12-08 05:25:12 +00:00
|
|
|
: IUCode(_rMailHandler)
|
2009-06-28 14:22:51 +00:00
|
|
|
, m_CRC(_CRC)
|
|
|
|
, m_bSyncInProgress(false)
|
|
|
|
, m_MaxVoice(0)
|
|
|
|
, m_NumVoices(0)
|
|
|
|
, m_bSyncCmdPending(false)
|
|
|
|
, m_CurVoice(0)
|
|
|
|
, m_CurBuffer(0)
|
|
|
|
, m_NumBuffers(0)
|
|
|
|
, m_VoicePBsAddr(0)
|
|
|
|
, m_UnkTableAddr(0)
|
|
|
|
, m_AFCCoefTableAddr(0)
|
|
|
|
, m_ReverbPBsAddr(0)
|
|
|
|
, m_RightBuffersAddr(0)
|
|
|
|
, m_LeftBuffersAddr(0)
|
2009-07-01 22:36:59 +00:00
|
|
|
, m_pos(0)
|
2009-06-28 14:22:51 +00:00
|
|
|
, m_DMABaseAddr(0)
|
2008-12-08 05:25:12 +00:00
|
|
|
, m_numSteps(0)
|
2009-07-01 22:36:59 +00:00
|
|
|
, m_bListInProgress(false)
|
2008-12-08 05:25:12 +00:00
|
|
|
, m_step(0)
|
|
|
|
, m_readOffset(0)
|
2009-06-20 01:33:13 +00:00
|
|
|
, m_MailState(WaitForMail)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-03-18 17:17:58 +00:00
|
|
|
DEBUG_LOG(DSPHLE, "UCode_Zelda - add boot mails for handshake");
|
2008-12-08 05:25:12 +00:00
|
|
|
m_rMailHandler.PushMail(DSP_INIT);
|
2009-06-09 19:51:19 +00:00
|
|
|
g_dspInitialize.pGenerateDSPInterrupt();
|
|
|
|
m_rMailHandler.PushMail(0xF3551111); // handshake
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
m_TempBuffer = new s32[256 * 1024];
|
|
|
|
m_LeftBuffer = new s32[256 * 1024];
|
|
|
|
m_RightBuffer = new s32[256 * 1024];
|
|
|
|
|
|
|
|
memset(m_Buffer, 0, sizeof(m_Buffer));
|
|
|
|
memset(m_SyncFlags, 0, sizeof(m_SyncFlags));
|
|
|
|
memset(m_AFCCoefTable, 0, sizeof(m_AFCCoefTable));
|
2009-06-20 01:33:13 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
CUCode_Zelda::~CUCode_Zelda()
|
|
|
|
{
|
|
|
|
m_rMailHandler.Clear();
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
delete [] m_TempBuffer;
|
|
|
|
delete [] m_LeftBuffer;
|
|
|
|
delete [] m_RightBuffer;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
#if 0
|
2009-06-20 01:33:13 +00:00
|
|
|
void CUCode_Zelda::UpdatePB(ZPB& _rPB, int *templbuffer, int *temprbuffer, u32 _Size)
|
|
|
|
{
|
|
|
|
u16* pTest = (u16*)&_rPB;
|
|
|
|
|
2009-06-21 08:39:21 +00:00
|
|
|
// Checks at 0293
|
2009-06-20 01:33:13 +00:00
|
|
|
if (pTest[0x00] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pTest[0x01] != 0)
|
|
|
|
return;
|
|
|
|
|
2009-06-21 08:39:21 +00:00
|
|
|
|
2009-06-20 01:33:13 +00:00
|
|
|
if (pTest[0x06] != 0x00)
|
|
|
|
{
|
2009-06-20 11:02:16 +00:00
|
|
|
// probably pTest[0x06] == 0 -> AFC (and variants)
|
2009-06-21 08:39:21 +00:00
|
|
|
// See 02a4
|
2009-06-20 01:33:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-21 08:39:21 +00:00
|
|
|
switch (_rPB.type) // or Bytes per Sample
|
2009-06-20 01:33:13 +00:00
|
|
|
{
|
|
|
|
case 0x05:
|
|
|
|
case 0x09:
|
|
|
|
{
|
|
|
|
// initialize "decoder" if the sample is played the first time
|
|
|
|
if (pTest[0x04] != 0)
|
|
|
|
{
|
2009-06-21 08:39:21 +00:00
|
|
|
// This is 0717_ReadOutPBStuff
|
|
|
|
|
|
|
|
// increment 4fb
|
|
|
|
|
2009-06-20 01:33:13 +00:00
|
|
|
// zelda:
|
|
|
|
// perhaps init or "has played before"
|
|
|
|
pTest[0x32] = 0x00;
|
2009-06-20 10:39:45 +00:00
|
|
|
pTest[0x66] = 0x00; // history1
|
2009-06-20 01:33:13 +00:00
|
|
|
pTest[0x67] = 0x00; // history2
|
|
|
|
|
|
|
|
// samplerate? length? num of samples? i dunno...
|
2009-06-20 10:39:45 +00:00
|
|
|
// Likely length...
|
2009-06-20 01:33:13 +00:00
|
|
|
pTest[0x3a] = pTest[0x8a];
|
|
|
|
pTest[0x3b] = pTest[0x8b];
|
|
|
|
|
2009-06-21 08:39:21 +00:00
|
|
|
// Copy ARAM addr from r to rw area.
|
2009-06-20 01:33:13 +00:00
|
|
|
pTest[0x38] = pTest[0x8c];
|
|
|
|
pTest[0x39] = pTest[0x8d];
|
|
|
|
}
|
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
if (pTest[0x01] != 0) // 0747 early out... i dunno if this can happen because we filter it above
|
2009-06-20 01:33:13 +00:00
|
|
|
return;
|
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
u32 ARAMAddr = (pTest[0x38] << 16) | pTest[0x39];
|
|
|
|
u32 NumberOfSamples = (pTest[0x3a] << 16) | pTest[0x3b];
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
// round upwards how many samples we need to copy, 0759
|
2009-06-20 01:33:13 +00:00
|
|
|
NumberOfSamples = (NumberOfSamples + 0xf) >> 4; // i think the lower 4 are the fraction
|
2009-06-20 10:39:45 +00:00
|
|
|
u32 frac = NumberOfSamples & 0xF;
|
2009-06-20 01:33:13 +00:00
|
|
|
|
|
|
|
u8 inBuffer[9];
|
|
|
|
short outbuf[16];
|
|
|
|
u32 sampleCount = 0;
|
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
// It must be something like this:
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
// The PB contains a small sample buffer of 0x4D decoded samples.
|
|
|
|
// If it's empty or "used", decode to it.
|
|
|
|
// Then, resample from this buffer to the output as you go. When it needs
|
|
|
|
// wrapping, decode more.
|
|
|
|
|
2009-06-21 08:39:21 +00:00
|
|
|
#define USE_RESAMPLE
|
|
|
|
#if !defined(USE_RESAMPLE)
|
|
|
|
for (int s = 0; s < _Size/16; s++)
|
2009-06-20 01:33:13 +00:00
|
|
|
{
|
2009-06-21 08:39:21 +00:00
|
|
|
for (int i = 0; i < 9; i++)
|
2009-06-20 01:33:13 +00:00
|
|
|
{
|
2009-06-21 08:39:21 +00:00
|
|
|
inBuffer[i] = g_dspInitialize.pARAM_Read_U8(ARAMAddr);
|
2009-06-20 01:33:13 +00:00
|
|
|
ARAMAddr++;
|
|
|
|
}
|
2009-06-20 10:39:45 +00:00
|
|
|
|
2009-06-20 01:33:13 +00:00
|
|
|
AFCdecodebuffer((char*)inBuffer, outbuf, (short*)&pTest[0x66], (short*)&pTest[0x67]);
|
|
|
|
|
2009-06-21 08:39:21 +00:00
|
|
|
for (int i = 0; i < 16; i++)
|
2009-06-20 01:33:13 +00:00
|
|
|
{
|
2009-06-20 10:39:45 +00:00
|
|
|
templbuffer[sampleCount] += outbuf[i];
|
|
|
|
temprbuffer[sampleCount] += outbuf[i];
|
2009-06-20 01:33:13 +00:00
|
|
|
sampleCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
NumberOfSamples--;
|
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
if (NumberOfSamples<=0)
|
|
|
|
break;
|
|
|
|
}
|
2009-06-20 01:33:13 +00:00
|
|
|
#else
|
2009-06-20 10:39:45 +00:00
|
|
|
while (NumberOfSamples > 0)
|
2009-06-20 01:33:13 +00:00
|
|
|
{
|
2009-06-20 10:39:45 +00:00
|
|
|
for (int i = 0; i < 9; i++)
|
2009-06-20 01:33:13 +00:00
|
|
|
{
|
|
|
|
inBuffer[i] = g_dspInitialize.pARAM_Read_U8(ARAMAddr);
|
|
|
|
ARAMAddr++;
|
|
|
|
}
|
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
AFCdecodebuffer(m_AFCCoefTable, (char*)inBuffer, outbuf, (short*)&pTest[0x66], (short*)&pTest[0x67], 9);
|
|
|
|
CResampler Sampler(outbuf, 16, 48000);
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
while (Sampler.m_queueSize > 0)
|
2009-06-20 01:33:13 +00:00
|
|
|
{
|
2009-06-20 10:39:45 +00:00
|
|
|
int sample = Sampler.sample_queue.front();
|
|
|
|
Sampler.sample_queue.pop();
|
2009-06-21 08:39:21 +00:00
|
|
|
Sampler.m_queueSize -= 1;
|
2009-06-20 10:39:45 +00:00
|
|
|
|
|
|
|
templbuffer[sampleCount] += sample;
|
|
|
|
temprbuffer[sampleCount] += sample;
|
2009-06-20 01:33:13 +00:00
|
|
|
sampleCount++;
|
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
if (sampleCount > _Size)
|
|
|
|
break;
|
|
|
|
}
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
if (sampleCount > _Size)
|
2009-06-20 01:33:13 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-20 10:39:45 +00:00
|
|
|
NumberOfSamples--;
|
|
|
|
}
|
2009-06-20 01:33:13 +00:00
|
|
|
#endif
|
|
|
|
if (NumberOfSamples == 0)
|
|
|
|
{
|
|
|
|
pTest[0x01] = 1; // we are done ??
|
|
|
|
}
|
|
|
|
|
|
|
|
// write back
|
|
|
|
NumberOfSamples = (NumberOfSamples << 4); // missing fraction
|
2009-06-20 10:39:45 +00:00
|
|
|
|
2009-06-20 01:33:13 +00:00
|
|
|
pTest[0x38] = ARAMAddr >> 16;
|
|
|
|
pTest[0x39] = ARAMAddr & 0xFFFF;
|
|
|
|
pTest[0x3a] = NumberOfSamples >> 16;
|
|
|
|
pTest[0x3b] = NumberOfSamples & 0xFFFF;
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
NumberOfSamples = (NumberOfSamples + 0xf) >> 4;
|
|
|
|
|
|
|
|
static u8 Buffer[500000];
|
|
|
|
for (int i =0; i<NumberOfSamples*9; i++)
|
|
|
|
{
|
2009-06-20 10:39:45 +00:00
|
|
|
Buffer[i] = g_dspInitialize.pARAM_Read_U8(ARAMAddr+i);
|
2009-06-20 01:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// yes, the dumps are really zelda sound ;)
|
|
|
|
DumpAFC(Buffer, NumberOfSamples*9, 0x3d00);
|
|
|
|
|
|
|
|
DumpPB(_rPB);
|
|
|
|
|
|
|
|
// exit(1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// i think pTest[0x3a] and pTest[0x3b] got an update after you have decoded some samples...
|
|
|
|
// just decrement them with the number of samples you have played
|
|
|
|
// and incrrease the ARAM Offset in pTest[0x38], pTest[0x39]
|
|
|
|
|
|
|
|
|
|
|
|
// end of block (Zelda 03b2)
|
|
|
|
if (pTest[0x06] == 0)
|
|
|
|
{
|
2009-06-21 08:39:21 +00:00
|
|
|
// 02a4
|
|
|
|
//
|
|
|
|
|
2009-06-20 01:33:13 +00:00
|
|
|
pTest[0x04] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-06-21 08:39:21 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
ERROR_LOG(DSPHLE, "Zelda Ucode: Unknown PB type %i", _rPB.type);
|
|
|
|
break;
|
2009-06-20 01:33:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-28 14:22:51 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-04-08 18:36:53 +00:00
|
|
|
void CUCode_Zelda::Update(int cycles)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-06-29 16:19:06 +00:00
|
|
|
if (m_rMailHandler.GetNextMail() == DSP_FRAME_END)
|
2009-06-28 14:22:51 +00:00
|
|
|
g_dspInitialize.pGenerateDSPInterrupt();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CUCode_Zelda::HandleMail(u32 _uMail)
|
|
|
|
{
|
2009-07-01 20:55:43 +00:00
|
|
|
// WARN_LOG(DSPHLE, "Zelda uCode: Handle mail %08X", _uMail);
|
2009-06-28 14:22:51 +00:00
|
|
|
// When we used to lose sync, the last mails we get before the audio goes bye-bye
|
|
|
|
// 0
|
|
|
|
// 0x00000
|
|
|
|
// 0
|
|
|
|
// 0x10000
|
|
|
|
// 0
|
|
|
|
// 0x20000
|
|
|
|
// 0
|
|
|
|
// 0x30000
|
|
|
|
// And then silence... Looks like some reverse countdown :)
|
|
|
|
if (m_bSyncInProgress)
|
|
|
|
{
|
|
|
|
if (m_bSyncCmdPending)
|
|
|
|
{
|
|
|
|
u32 n = (_uMail >> 16) & 0xF;
|
|
|
|
m_MaxVoice = (n + 1) << 4;
|
|
|
|
m_SyncFlags[n] = _uMail & 0xFFFF;
|
|
|
|
m_bSyncInProgress = false;
|
|
|
|
|
|
|
|
// Normally, we should mix to the buffers used by the game.
|
|
|
|
// We don't do it currently for a simple reason:
|
|
|
|
// if the game runs fast all the time, then it's OK,
|
|
|
|
// but if it runs slow, sound can become choppy.
|
|
|
|
// This problem won't happen when mixing to the buffer
|
|
|
|
// provided by MixAdd(), because the size of this buffer
|
|
|
|
// is automatically adjusted if the game runs slow.
|
|
|
|
#if 0
|
|
|
|
if (m_SyncFlags[n] & 0x8000)
|
|
|
|
{
|
|
|
|
for (; m_CurVoice < m_MaxVoice; m_CurVoice++)
|
|
|
|
{
|
|
|
|
if (m_CurVoice >= m_NumVoices)
|
|
|
|
break;
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
MixVoice(m_CurVoice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
m_CurVoice = m_MaxVoice;
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
if (m_CurVoice >= m_NumVoices)
|
|
|
|
{
|
|
|
|
m_CurBuffer++;
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
m_rMailHandler.PushMail(DSP_SYNC);
|
|
|
|
g_dspInitialize.pGenerateDSPInterrupt();
|
|
|
|
m_rMailHandler.PushMail(0xF355FF00 | m_CurBuffer);
|
|
|
|
|
|
|
|
m_CurVoice = 0;
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
if (m_CurBuffer == m_NumBuffers)
|
|
|
|
{
|
|
|
|
m_rMailHandler.PushMail(DSP_FRAME_END);
|
2009-06-29 16:19:06 +00:00
|
|
|
//g_dspInitialize.pGenerateDSPInterrupt();
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
soundStream->GetMixer()->SetHLEReady(true);
|
|
|
|
DEBUG_LOG(DSPHLE, "Update the SoundThread to be in sync");
|
|
|
|
soundStream->Update(); //do it in this thread to avoid sync problems
|
|
|
|
|
|
|
|
m_bSyncCmdPending = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bSyncInProgress = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2009-06-20 01:33:13 +00:00
|
|
|
|
|
|
|
}
|
2009-06-28 14:22:51 +00:00
|
|
|
|
|
|
|
if (m_bListInProgress)
|
|
|
|
{
|
|
|
|
if (m_step < 0 || m_step >= sizeof(m_Buffer)/4)
|
|
|
|
PanicAlert("m_step out of range");
|
|
|
|
|
|
|
|
((u32*)m_Buffer)[m_step] = _uMail;
|
|
|
|
m_step++;
|
|
|
|
|
|
|
|
if (m_step >= m_numSteps)
|
|
|
|
{
|
|
|
|
ExecuteList();
|
|
|
|
m_bListInProgress = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_uMail == 0)
|
|
|
|
{
|
|
|
|
m_bSyncInProgress = true;
|
|
|
|
}
|
|
|
|
else if ((_uMail >> 16) == 0)
|
|
|
|
{
|
|
|
|
m_bListInProgress = true;
|
|
|
|
m_numSteps = _uMail;
|
|
|
|
m_step = 0;
|
|
|
|
}
|
|
|
|
else if ((_uMail >> 16) == 0xCDD1) // A 0xCDD1000X mail should come right after we send a DSP_SYNCEND mail
|
|
|
|
{
|
|
|
|
// The low part of the mail tells the operation to perform
|
|
|
|
switch (_uMail & 0xFFFF)
|
|
|
|
{
|
|
|
|
case 0x0003: // Do nothing
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x0000: // Halt
|
|
|
|
case 0x0001: // Dump memory? and halt
|
|
|
|
case 0x0002: // Do something and halt
|
|
|
|
WARN_LOG(DSPHLE, "Zelda uCode: received halting operation %04X", _uMail & 0xFFFF);
|
|
|
|
return;
|
|
|
|
|
|
|
|
default: // Invalid (the real ucode would likely crash)
|
|
|
|
WARN_LOG(DSPHLE, "Zelda uCode: received invalid operation %04X", _uMail & 0xFFFF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN_LOG(DSPHLE, "Zelda uCode: unknown mail %08X", _uMail);
|
|
|
|
}
|
2009-06-20 01:33:13 +00:00
|
|
|
}
|
2009-06-09 19:51:19 +00:00
|
|
|
|
2009-06-20 01:33:13 +00:00
|
|
|
// zelda debug ..803F6418
|
2008-12-08 05:25:12 +00:00
|
|
|
void CUCode_Zelda::ExecuteList()
|
|
|
|
{
|
|
|
|
// begin with the list
|
|
|
|
m_readOffset = 0;
|
|
|
|
|
2009-06-09 19:51:19 +00:00
|
|
|
u32 CmdMail = Read32();
|
|
|
|
u32 Command = (CmdMail >> 24) & 0x7f;
|
|
|
|
u32 Sync = CmdMail >> 16;
|
2009-06-28 14:22:51 +00:00
|
|
|
u32 ExtraData = CmdMail & 0xFFFF;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
DEBUG_LOG(DSPHLE, "==============================================================================");
|
|
|
|
DEBUG_LOG(DSPHLE, "Zelda UCode - execute dlist (cmd: 0x%04x : sync: 0x%04x)", Command, Sync);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
switch (Command)
|
|
|
|
{
|
|
|
|
// DsetupTable ... zelda ww jumps to 0x0095
|
|
|
|
case 0x01:
|
|
|
|
{
|
2009-06-28 14:22:51 +00:00
|
|
|
m_NumVoices = ExtraData;
|
|
|
|
m_VoicePBsAddr = Read32() & 0x7FFFFFFF;
|
|
|
|
m_UnkTableAddr = Read32() & 0x7FFFFFFF;
|
|
|
|
m_AFCCoefTableAddr = Read32() & 0x7FFFFFFF;
|
2009-06-28 17:58:52 +00:00
|
|
|
m_ReverbPBsAddr = Read32() & 0x7FFFFFFF; // WARNING: reverb PBs are very different from voice PBs!
|
2009-06-28 14:22:51 +00:00
|
|
|
|
|
|
|
// Read AFC coef table
|
2009-06-28 17:58:52 +00:00
|
|
|
u16 *TempPtr = (u16*) g_dspInitialize.pGetMemoryPointer(m_AFCCoefTableAddr);
|
|
|
|
for (int i = 0; i < 32; i++)
|
2009-06-29 18:11:32 +00:00
|
|
|
m_AFCCoefTable[i] = (s16)Common::swap16(TempPtr[i]);
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
DEBUG_LOG(DSPHLE, "DsetupTable");
|
|
|
|
DEBUG_LOG(DSPHLE, "Num voice param blocks: %i", m_NumVoices);
|
|
|
|
DEBUG_LOG(DSPHLE, "Voice param blocks address: 0x%08x", m_VoicePBsAddr);
|
|
|
|
|
2009-06-28 17:58:52 +00:00
|
|
|
// This points to some strange data table. Don't know yet what it's for. Reverb coefs?
|
2009-06-28 14:22:51 +00:00
|
|
|
DEBUG_LOG(DSPHLE, "DSPRES_FILTER (size: 0x40): 0x%08x", m_UnkTableAddr);
|
|
|
|
|
|
|
|
// Zelda WW: This points to a 64-byte array of coefficients, which are EXACTLY the same
|
|
|
|
// as the AFC ADPCM coef array in decode.c of the in_cube winamp plugin,
|
2009-06-28 17:58:52 +00:00
|
|
|
// which can play Zelda audio. So, these should definitely be used when decoding AFC.
|
2009-06-28 14:22:51 +00:00
|
|
|
DEBUG_LOG(DSPHLE, "DSPADPCM_FILTER (size: 0x500): 0x%08x", m_AFCCoefTableAddr);
|
|
|
|
DEBUG_LOG(DSPHLE, "Reverb param blocks address: 0x%08x", m_ReverbPBsAddr);
|
|
|
|
}
|
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
// SyncFrame ... zelda ww jumps to 0x0243
|
|
|
|
case 0x02:
|
|
|
|
{
|
|
|
|
// soundStream->GetMixer()->SetHLEReady(true);
|
|
|
|
// DEBUG_LOG(DSPHLE, "Update the SoundThread to be in sync");
|
|
|
|
//soundStream->Update(); //do it in this thread to avoid sync problems
|
2009-06-16 19:35:54 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
m_bSyncCmdPending = true;
|
|
|
|
m_CurBuffer = 0;
|
|
|
|
m_NumBuffers = (CmdMail >> 16) & 0xFF;
|
2009-06-16 19:35:54 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
// Addresses for right & left buffers in main memory
|
|
|
|
// Each buffer is 160 bytes long. The number of (both left & right) buffers
|
|
|
|
// is set by the first mail of the list.
|
|
|
|
m_RightBuffersAddr = Read32() & 0x7FFFFFFF;
|
|
|
|
m_LeftBuffersAddr = Read32() & 0x7FFFFFFF;
|
2009-06-20 01:33:13 +00:00
|
|
|
|
|
|
|
DEBUG_LOG(DSPHLE, "DsyncFrame");
|
2009-06-28 14:22:51 +00:00
|
|
|
// These alternate between three sets of mixing buffers. They are all three fairly near,
|
|
|
|
// but not at, the ADMA read addresses.
|
|
|
|
DEBUG_LOG(DSPHLE, "Right buffer address: 0x%08x", m_RightBuffersAddr);
|
|
|
|
DEBUG_LOG(DSPHLE, "Left buffer address: 0x%08x", m_LeftBuffersAddr);
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-06-09 19:51:19 +00:00
|
|
|
return;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-06-29 21:41:13 +00:00
|
|
|
|
|
|
|
// Simply sends the sync messages
|
|
|
|
case 0x03: break;
|
|
|
|
|
|
|
|
/* case 0x04: break; // dunno ... zelda ww jmps to 0x0580
|
2009-06-20 10:39:45 +00:00
|
|
|
case 0x05: break; // dunno ... zelda ww jmps to 0x0592
|
|
|
|
case 0x06: break; // dunno ... zelda ww jmps to 0x0469
|
|
|
|
case 0x07: break; // dunno ... zelda ww jmps to 0x044d
|
|
|
|
case 0x08: break; // Mixer ... zelda ww jmps to 0x0485
|
|
|
|
case 0x09: break; // dunno ... zelda ww jmps to 0x044d
|
2008-12-08 05:25:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// DsetDolbyDelay ... zelda ww jumps to 0x00b2
|
|
|
|
case 0x0d:
|
|
|
|
{
|
2009-06-28 17:58:52 +00:00
|
|
|
u32 tmp = Read32();
|
2009-03-18 17:17:58 +00:00
|
|
|
DEBUG_LOG(DSPHLE, "DSetDolbyDelay");
|
2009-06-28 14:22:51 +00:00
|
|
|
DEBUG_LOG(DSPHLE, "DOLBY2_DELAY_BUF (size 0x960): 0x%08x", tmp);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
// This opcode, in the SMG ucode, sets the base address for audio data transfers from main memory (using DMA).
|
|
|
|
// In the Zelda ucode, it is dummy, because this ucode uses accelerator for audio data transfers.
|
2008-12-08 05:25:12 +00:00
|
|
|
case 0x0e:
|
2009-06-09 19:51:19 +00:00
|
|
|
{
|
2009-06-28 14:22:51 +00:00
|
|
|
m_DMABaseAddr = Read32() & 0x7FFFFFFF;
|
|
|
|
DEBUG_LOG(DSPHLE, "DsetDMABaseAddr");
|
|
|
|
DEBUG_LOG(DSPHLE, "DMA base address: 0x%08x", m_DMABaseAddr);
|
2009-06-09 19:51:19 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-28 17:58:52 +00:00
|
|
|
// default ... zelda ww jumps to 0x0043
|
2008-12-08 05:25:12 +00:00
|
|
|
default:
|
|
|
|
PanicAlert("Zelda UCode - unknown cmd: %x (size %i)", Command, m_numSteps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-13 12:02:02 +00:00
|
|
|
// sync, we are ready
|
2008-12-08 05:25:12 +00:00
|
|
|
m_rMailHandler.PushMail(DSP_SYNC);
|
2009-06-09 19:51:19 +00:00
|
|
|
g_dspInitialize.pGenerateDSPInterrupt();
|
2008-12-08 05:25:12 +00:00
|
|
|
m_rMailHandler.PushMail(0xF3550000 | Sync);
|
|
|
|
}
|
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
// size is in stereo samples.
|
|
|
|
void CUCode_Zelda::MixAdd(short* _Buffer, int _Size)
|
2009-06-20 01:33:13 +00:00
|
|
|
{
|
2009-06-28 14:22:51 +00:00
|
|
|
if (_Size > 256 * 1024)
|
|
|
|
_Size = 256 * 1024;
|
|
|
|
|
|
|
|
memset(m_LeftBuffer, 0, _Size * sizeof(s32));
|
|
|
|
memset(m_RightBuffer, 0, _Size * sizeof(s32));
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
for (u32 i = 0; i < m_NumVoices; i++)
|
|
|
|
{
|
|
|
|
u32 flags = m_SyncFlags[(i >> 4) & 0xF];
|
2009-06-29 18:11:32 +00:00
|
|
|
if (!(flags & 1 << (15 - (i & 0xF))))
|
2009-06-28 14:22:51 +00:00
|
|
|
continue;
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-28 14:22:51 +00:00
|
|
|
ZeldaVoicePB pb;
|
|
|
|
ReadVoicePB(m_VoicePBsAddr + (i * 0x180), pb);
|
|
|
|
|
|
|
|
if (pb.Status == 0)
|
|
|
|
continue;
|
|
|
|
if (pb.KeyOff != 0)
|
|
|
|
continue;
|
|
|
|
|
2009-07-01 20:55:43 +00:00
|
|
|
RenderAddVoice(pb, m_LeftBuffer, m_RightBuffer, _Size);
|
2009-06-28 14:22:51 +00:00
|
|
|
WritebackVoicePB(m_VoicePBsAddr + (i * 0x180), pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_Buffer)
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < _Size; i++)
|
|
|
|
{
|
|
|
|
s32 left = (s32)_Buffer[0] + m_LeftBuffer[i];
|
|
|
|
s32 right = (s32)_Buffer[1] + m_RightBuffer[i];
|
|
|
|
|
|
|
|
if (left < -32768) left = -32768;
|
|
|
|
if (left > 32767) left = 32767;
|
|
|
|
_Buffer[0] = (short)left;
|
|
|
|
|
|
|
|
if (right < -32768) right = -32768;
|
|
|
|
if (right > 32767) right = 32767;
|
|
|
|
_Buffer[1] = (short)right;
|
|
|
|
|
|
|
|
_Buffer += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-20 01:33:13 +00:00
|
|
|
|
2009-06-20 10:24:49 +00:00
|
|
|
void CUCode_Zelda::DoState(PointerWrap &p) {
|
2009-06-28 14:22:51 +00:00
|
|
|
//p.Do(m_MailState);
|
|
|
|
//p.Do(m_PBMask);
|
|
|
|
//p.Do(m_NumPBs);
|
|
|
|
//p.Do(m_PBAddress);
|
|
|
|
//p.Do(m_MaxSyncedPB);
|
|
|
|
//p.Do(m_PBs);
|
2009-06-20 10:24:49 +00:00
|
|
|
p.Do(m_readOffset);
|
2009-06-28 14:22:51 +00:00
|
|
|
//p.Do(m_NumberOfFramesToRender);
|
|
|
|
//p.Do(m_CurrentFrameToRender);
|
2009-06-20 10:24:49 +00:00
|
|
|
p.Do(m_numSteps);
|
|
|
|
p.Do(m_step);
|
|
|
|
p.Do(m_Buffer);
|
2009-06-29 21:41:13 +00:00
|
|
|
/*p.Do(m_CRC);
|
|
|
|
p.Do(m_bSyncInProgress);
|
|
|
|
p.Do(m_MaxVoice);
|
|
|
|
p.Do(m_NumVoices);
|
|
|
|
p.Do(m_bSyncCmdPending);
|
|
|
|
p.Do(m_CurVoice);
|
|
|
|
p.Do(m_CurBuffer);
|
|
|
|
p.Do(m_NumBuffers);
|
|
|
|
p.Do(m_VoicePBsAddr);
|
|
|
|
p.Do(m_UnkTableAddr);
|
|
|
|
p.Do(m_AFCCoefTableAddr);
|
|
|
|
p.Do(m_ReverbPBsAddr);
|
|
|
|
p.Do(m_RightBuffersAddr);
|
|
|
|
p.Do(m_LeftBuffersAddr);
|
|
|
|
p.Do(m_DMABaseAddr);
|
|
|
|
p.Do(m_numSteps);
|
|
|
|
p.Do(m_step);
|
|
|
|
p.Do(m_readOffset);
|
|
|
|
p.Do(m_MailState);*/
|
2009-06-20 10:24:49 +00:00
|
|
|
}
|
2009-06-28 14:22:51 +00:00
|
|
|
|