diff --git a/Source/Core/Core/Src/Boot/Boot.cpp b/Source/Core/Core/Src/Boot/Boot.cpp index d67332eed4..c65857aafa 100644 --- a/Source/Core/Core/Src/Boot/Boot.cpp +++ b/Source/Core/Core/Src/Boot/Boot.cpp @@ -299,10 +299,14 @@ bool CBoot::BootUp() } // load image or create virtual drive from directory - if (!_StartupPara.m_strDVDRoot.empty()) + if (!_StartupPara.m_strDVDRoot.empty()) { + NOTICE_LOG(BOOT, "Setting DVDroot %s", _StartupPara.m_strDefaultGCM.c_str()); VolumeHandler::SetVolumeDirectory(_StartupPara.m_strDVDRoot, elfWii); - else if (!_StartupPara.m_strDefaultGCM.empty()) + } + else if (!_StartupPara.m_strDefaultGCM.empty()) { + NOTICE_LOG(BOOT, "Loading default ISO %s", _StartupPara.m_strDefaultGCM.c_str()); VolumeHandler::SetVolumeName(_StartupPara.m_strDefaultGCM); + } else VolumeHandler::SetVolumeDirectory(_StartupPara.m_strFilename, elfWii); @@ -313,6 +317,9 @@ bool CBoot::BootUp() Boot_ELF(_StartupPara.m_strFilename.c_str()); UpdateDebugger_MapLoaded(); Debugger::AddAutoBreakpoints(); + + + HLE::PatchFunctions(); } break; diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index f452eb6da7..40bdeda330 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -342,10 +342,7 @@ THREAD_RETURN CpuThread(void *pArg) } - - // Initalize plugins and create emulation thread - // Call browser: Init():g_EmuThread(). See the BootManager.cpp file description for a complete call schedule. THREAD_RETURN EmuThread(void *pArg) { @@ -387,7 +384,6 @@ THREAD_RETURN EmuThread(void *pArg) VideoInitialize.pBBox = &PixelEngine::bbox[0]; VideoInitialize.pBBoxActive = &PixelEngine::bbox_active; - // May be needed for Stop and Start #ifdef SETUP_FREE_VIDEO_PLUGIN_ON_BOOT Plugins.FreeVideo(); @@ -414,6 +410,7 @@ THREAD_RETURN EmuThread(void *pArg) dspInit.pEmulatorState = (int *)PowerPC::GetStatePtr(); dspInit.bWii = _CoreParameter.bWii; dspInit.bOnThread = _CoreParameter.bDSPThread; + // May be needed for Stop and Start #ifdef SETUP_FREE_DSP_PLUGIN_ON_BOOT Plugins.FreeDSP(); diff --git a/Source/Core/Core/Src/HW/CommandProcessor.cpp b/Source/Core/Core/Src/HW/CommandProcessor.cpp index 4630de0dd7..7916999f78 100644 --- a/Source/Core/Core/Src/HW/CommandProcessor.cpp +++ b/Source/Core/Core/Src/HW/CommandProcessor.cpp @@ -263,6 +263,7 @@ void Read16(u16& _rReturnValue, const u32 _Address) , m_CPStatusReg.UnderflowLoWatermark ? "ON" : "OFF" ); return; + case CTRL_REGISTER: _rReturnValue = m_CPCtrlReg.Hex; return; case CLEAR_REGISTER: _rReturnValue = m_CPClearReg.Hex; return; @@ -286,55 +287,59 @@ void Read16(u16& _rReturnValue, const u32 _Address) //_rReturnValue = ReadLow (fifo.CPReadWriteDistance); // hack: CPU will always believe fifo is empty and on idle _rReturnValue = 0; - DEBUG_LOG(COMMANDPROCESSOR,"read FIFO_RW_DISTANCE_LO : %04x", _rReturnValue); + DEBUG_LOG(COMMANDPROCESSOR, "read FIFO_RW_DISTANCE_LO : %04x", _rReturnValue); return; case FIFO_RW_DISTANCE_HI: //_rReturnValue = ReadHigh(fifo.CPReadWriteDistance); // hack: CPU will always believe fifo is empty and on idle _rReturnValue = 0; - DEBUG_LOG(COMMANDPROCESSOR,"read FIFO_RW_DISTANCE_HI : %04x", _rReturnValue); + DEBUG_LOG(COMMANDPROCESSOR, "read FIFO_RW_DISTANCE_HI : %04x", _rReturnValue); return; case FIFO_WRITE_POINTER_LO: _rReturnValue = ReadLow (fifo.CPWritePointer); - DEBUG_LOG(COMMANDPROCESSOR,"read FIFO_WRITE_POINTER_LO : %04x", _rReturnValue); + DEBUG_LOG(COMMANDPROCESSOR, "read FIFO_WRITE_POINTER_LO : %04x", _rReturnValue); return; case FIFO_WRITE_POINTER_HI: _rReturnValue = ReadHigh(fifo.CPWritePointer); - DEBUG_LOG(COMMANDPROCESSOR,"read FIFO_WRITE_POINTER_HI : %04x", _rReturnValue); + DEBUG_LOG(COMMANDPROCESSOR, "read FIFO_WRITE_POINTER_HI : %04x", _rReturnValue); return; case FIFO_READ_POINTER_LO: //_rReturnValue = ReadLow (fifo.CPReadPointer); // hack: CPU will always believe fifo is empty and on idle _rReturnValue = ReadLow (fifo.CPWritePointer); - DEBUG_LOG(COMMANDPROCESSOR,"read FIFO_READ_POINTER_LO : %04x", _rReturnValue); + DEBUG_LOG(COMMANDPROCESSOR, "read FIFO_READ_POINTER_LO : %04x", _rReturnValue); return; case FIFO_READ_POINTER_HI: //_rReturnValue = ReadHigh(fifo.CPReadPointer); // hack: CPU will always believe fifo is empty and on idle _rReturnValue = ReadHigh(fifo.CPWritePointer); - DEBUG_LOG(COMMANDPROCESSOR,"read FIFO_READ_POINTER_HI : %04x", _rReturnValue); + DEBUG_LOG(COMMANDPROCESSOR, "read FIFO_READ_POINTER_HI : %04x", _rReturnValue); return; - case FIFO_BP_LO: _rReturnValue = ReadLow (fifo.CPBreakpoint); return; - case FIFO_BP_HI: _rReturnValue = ReadHigh(fifo.CPBreakpoint); return; -// case 0x42: // first metric reg (I guess) read in case of "fifo unknown state" -// Crash(); -// return; + case FIFO_BP_LO: _rReturnValue = ReadLow (fifo.CPBreakpoint); return; + case FIFO_BP_HI: _rReturnValue = ReadHigh(fifo.CPBreakpoint); return; + + case CP_PERF0_L: _rReturnValue = 0; WARN_LOG(COMMANDPROCESSOR, "Read from PERF0_L: %04x", _rReturnValue); break; // XF counters + case CP_PERF0_H: _rReturnValue = 0; WARN_LOG(COMMANDPROCESSOR, "Read from PERF0_H: %04x", _rReturnValue); break; + + case CP_PERF1_L: _rReturnValue = 0; WARN_LOG(COMMANDPROCESSOR, "Read from PERF1_L: %04x", _rReturnValue); break; + case CP_PERF1_H: _rReturnValue = 0; WARN_LOG(COMMANDPROCESSOR, "Read from PERF1_H: %04x", _rReturnValue); break; + + case CP_PERF2_L: _rReturnValue = 0; WARN_LOG(COMMANDPROCESSOR, "Read from PERF2_L: %04x", _rReturnValue); break; + case CP_PERF2_H: _rReturnValue = 0; WARN_LOG(COMMANDPROCESSOR, "Read from PERF2_H: %04x", _rReturnValue); break; + + case CP_PERF3_L: _rReturnValue = 0; WARN_LOG(COMMANDPROCESSOR, "Read from PERF3_L: %04x", _rReturnValue); break; + case CP_PERF3_H: _rReturnValue = 0; WARN_LOG(COMMANDPROCESSOR, "Read from PERF3_H: %04x", _rReturnValue); break; // case 0x64: // return 4; //Number of clocks per vertex.. todo: calculate properly //add all the other regs here? are they ever read? default: - { -// char szTemp[111]; -// sprintf(szTemp, "CCommandProcessor 0x%x", (_Address&0xFFF)); -// MessageBox(NULL, szTemp, "mm", MB_OK); - } + WARN_LOG(COMMANDPROCESSOR, "(r16) unknown CP reg @ %08x", _Address); _rReturnValue = 0; - return; + return; } - } bool AllowIdleSkipping() @@ -462,11 +467,18 @@ void Write16(const u16 _Value, const u32 _Address) } break; + case PERF_SELECT: + { + WARN_LOG(COMMANDPROCESSOR, "write to PERF_SELECT: %04x", _Value); + // Seems to select which set of perf counters should be exposed. + } + break; + case CLEAR_REGISTER: { + // ???? UCPClearReg tmpClearReg(_Value); m_CPClearReg.Hex = 0; - INFO_LOG(COMMANDPROCESSOR,"\t write to CLEAR_REGISTER : %04x",_Value); } break; @@ -556,6 +568,8 @@ void Write16(const u16 _Value, const u32 _Address) //WriteLow((u32 &)fifo.CPReadWriteDistance, _Value); DEBUG_LOG(COMMANDPROCESSOR,"try to write to FIFO_RW_DISTANCE_LO : %04x", _Value); break; + default: + WARN_LOG(COMMANDPROCESSOR, "(w16) unknown CP reg write %04x @ %08x", _Value, _Address); } // TODO(mb2): better. Check if it help: avoid CPReadPointer overwrites when stupidly done like in Super Monkey Ball diff --git a/Source/Core/Core/Src/HW/CommandProcessor.h b/Source/Core/Core/Src/HW/CommandProcessor.h index 719021b4e5..e1408e07d3 100644 --- a/Source/Core/Core/Src/HW/CommandProcessor.h +++ b/Source/Core/Core/Src/HW/CommandProcessor.h @@ -31,6 +31,7 @@ enum STATUS_REGISTER = 0x00, CTRL_REGISTER = 0x02, CLEAR_REGISTER = 0x04, + PERF_SELECT = 0x06, FIFO_TOKEN_REGISTER = 0x0E, FIFO_BOUNDING_BOX_LEFT = 0x10, FIFO_BOUNDING_BOX_RIGHT = 0x12, @@ -51,7 +52,15 @@ enum FIFO_READ_POINTER_LO = 0x38, FIFO_READ_POINTER_HI = 0x3A, FIFO_BP_LO = 0x3C, - FIFO_BP_HI = 0x3E + FIFO_BP_HI = 0x3E, + CP_PERF0_L = 0x40, + CP_PERF0_H = 0x42, + CP_PERF1_L = 0x44, + CP_PERF1_H = 0x46, + CP_PERF2_L = 0x48, + CP_PERF2_H = 0x4a, + CP_PERF3_L = 0x4c, + CP_PERF3_H = 0x4e, }; extern SCPFifoStruct fifo; diff --git a/Source/Core/Core/Src/HW/PixelEngine.cpp b/Source/Core/Core/Src/HW/PixelEngine.cpp index 480e9653b2..dfd12ce8a3 100644 --- a/Source/Core/Core/Src/HW/PixelEngine.cpp +++ b/Source/Core/Core/Src/HW/PixelEngine.cpp @@ -216,6 +216,21 @@ void Read16(u16& _uReturnValue, const u32 _iAddress) case PE_BBOX_TOP: _uReturnValue = bbox[2]; INFO_LOG(PIXELENGINE, "R: BBOX_TOP = %i", bbox[2]); bbox_active = false; break; case PE_BBOX_BOTTOM: _uReturnValue = bbox[3]; INFO_LOG(PIXELENGINE, "R: BBOX_BOTTOM = %i", bbox[3]); bbox_active = false; break; + case PE_PERF_0L: + case PE_PERF_0H: + case PE_PERF_1L: + case PE_PERF_1H: + case PE_PERF_2L: + case PE_PERF_2H: + case PE_PERF_3L: + case PE_PERF_3H: + case PE_PERF_4L: + case PE_PERF_4H: + case PE_PERF_5L: + case PE_PERF_5H: + WARN_LOG(PIXELENGINE, "(r16) perf counter @ %08x", _iAddress); + break; + default: WARN_LOG(PIXELENGINE, "(r16) unknown @ %08x", _iAddress); _uReturnValue = 1; diff --git a/Source/Core/Core/Src/HW/PixelEngine.h b/Source/Core/Core/Src/HW/PixelEngine.h index ed8e7a164d..de505aa156 100644 --- a/Source/Core/Core/Src/HW/PixelEngine.h +++ b/Source/Core/Core/Src/HW/PixelEngine.h @@ -35,6 +35,20 @@ enum PE_BBOX_RIGHT = 0x12, // Flip Right PE_BBOX_TOP = 0x14, // Flip Top PE_BBOX_BOTTOM = 0x16, // Flip Bottom + + // These have not yet been RE:d. They are the perf counters. + PE_PERF_0L = 0x18, + PE_PERF_0H = 0x1a, + PE_PERF_1L = 0x1c, + PE_PERF_1H = 0x1e, + PE_PERF_2L = 0x20, + PE_PERF_2H = 0x22, + PE_PERF_3L = 0x24, + PE_PERF_3H = 0x26, + PE_PERF_4L = 0x28, + PE_PERF_4H = 0x2a, + PE_PERF_5L = 0x2c, + PE_PERF_5H = 0x2e, }; namespace PixelEngine diff --git a/Source/Core/DSPCore/Src/SConscript b/Source/Core/DSPCore/Src/SConscript index f79d9e06f1..17d08b29cb 100644 --- a/Source/Core/DSPCore/Src/SConscript +++ b/Source/Core/DSPCore/Src/SConscript @@ -1,32 +1,32 @@ -# -*- python -*- - -Import('env') - -files = [ - "assemble.cpp", - "disassemble.cpp", - "DSPAccelerator.cpp", +# -*- python -*- + +Import('env') + +files = [ + "assemble.cpp", + "disassemble.cpp", + "DSPAccelerator.cpp", "DSPBreakpoints.cpp", - "DSPIntCCUtil.cpp", - "DSPIntExtOps.cpp", - "DSPHWInterface.cpp", - "DSPInterpreter.cpp", - "DSPMemoryMap.cpp", - "DSPStacks.cpp", - "DSPAnalyzer.cpp", - "DspIntArithmetic.cpp", - "DspIntBranch.cpp", - "DspIntLoadStore.cpp", - "DspIntMisc.cpp", - "DspIntMultiplier.cpp", - "DSPJit.cpp", - "DSPCodeUtil.cpp", - "LabelMap.cpp", - "DSPCore.cpp", - "DSPTables.cpp", - ] - -acenv = env.Clone() -acenv.Append(CXXFLAGS = [ '-fPIC' ]) - -acenv.StaticLibrary(env['local_libs'] + 'dspcore', files, LIBS = [ 'common'] ) + "DSPIntCCUtil.cpp", + "DSPIntExtOps.cpp", + "DSPHWInterface.cpp", + "DSPInterpreter.cpp", + "DSPMemoryMap.cpp", + "DSPStacks.cpp", + "DSPAnalyzer.cpp", + "DspIntArithmetic.cpp", + "DspIntBranch.cpp", + "DspIntLoadStore.cpp", + "DspIntMisc.cpp", + "DspIntMultiplier.cpp", + "DSPJit.cpp", + "DSPCodeUtil.cpp", + "LabelMap.cpp", + "DSPCore.cpp", + "DSPTables.cpp", + ] + +acenv = env.Clone() +acenv.Append(CXXFLAGS = [ '-fPIC' ]) + +acenv.StaticLibrary(env['local_libs'] + 'dspcore', files, LIBS = [ 'common'] ) diff --git a/Source/Core/DolphinWX/Src/Globals.h b/Source/Core/DolphinWX/Src/Globals.h index e7dd6499c4..eb726e8655 100644 --- a/Source/Core/DolphinWX/Src/Globals.h +++ b/Source/Core/DolphinWX/Src/Globals.h @@ -22,7 +22,6 @@ #define _GLOBALS_H #include "Common.h" -#include "svnrev.h" // Constant Colors const unsigned long COLOR_GRAY = 0xDCDCDC; diff --git a/Source/Core/DolphinWX/Src/InfoWindow.cpp b/Source/Core/DolphinWX/Src/InfoWindow.cpp index 36ea2fdf6e..10bae7a546 100644 --- a/Source/Core/DolphinWX/Src/InfoWindow.cpp +++ b/Source/Core/DolphinWX/Src/InfoWindow.cpp @@ -15,6 +15,7 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ +#include "svnrev.h" #include "Globals.h" #include "InfoWindow.h" #include "CPUDetect.h" diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index cb3cd07e8a..52603e3cc8 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -26,6 +26,8 @@ // Mash together all the inputs that contribute to the code of a generated pixel shader into // a unique identifier, basically containing all the bits. Yup, it's a lot .... +// It would likely be a lot more efficient to build this incrementally as the attributes +// are set... void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 dstAlphaEnable) { u32 projtexcoords = 0; @@ -90,7 +92,7 @@ void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 dstAlphaEnable if ((bpmem.genMode.numtevstages + 1) & 1) { // odd u32 val0; if (bpmem.tevorders[bpmem.genMode.numtevstages/2].hex & 0x40) - val0 = bpmem.tevorders[bpmem.genMode.numtevstages/2].hex&0x3ff; + val0 = bpmem.tevorders[bpmem.genMode.numtevstages/2].hex & 0x3ff; else val0 = bpmem.tevorders[bpmem.genMode.numtevstages/2].hex & 0x380; @@ -104,11 +106,11 @@ void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 dstAlphaEnable if ((bpmem.genMode.numtevstages % 3) != 2) ++pcurvalue; - uid.tevstages = (u32)(pcurvalue-&uid.values[0]-hdr); + uid.tevstages = (u32)(pcurvalue - &uid.values[0] - hdr); for (u32 i = 0; i < bpmem.genMode.numindstages; ++i) { u32 val = bpmem.tevind[i].hex & 0x1fffff; // 21 bits - switch (i%3) { + switch (i % 3) { case 0: pcurvalue[0] = val; break; case 1: pcurvalue[0] |= val << 21; pcurvalue[1] = val >> 11; ++pcurvalue; break; case 2: pcurvalue[0] |= val << 10; ++pcurvalue; break; @@ -320,8 +322,8 @@ static const char *tevAInputTable2[] = // CA static const char *tevRasTable[] = { - "colors[0]", - "colors[1]", + "colors_0", + "colors_1", "ERROR", //2 "ERROR", //3 "ERROR", //4 @@ -356,7 +358,6 @@ static char text[16384]; static void BuildSwapModeTable() { - //bpmem.tevregs[0]. for (int i = 0; i < 4; i++) { swapModeTable[i][0] = swapColors[bpmem.tevksel[i*2].swap1]; @@ -442,7 +443,7 @@ const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL WRITE(p, " in float%d uv%d : TEXCOORD%d, \n", i<4?4:3, i, i); } - WRITE(p, " in float4 colors[2] : COLOR0){\n"); + WRITE(p, " in float4 colors_0 : COLOR0, in float4 colors_1 : COLOR1){\n"); char* pmainstart = p; @@ -628,7 +629,7 @@ static void WriteStage(char *&p, int n, u32 texture_mask) } } - WRITE(p, "rastemp=%s.%s;\n",tevRasTable[bpmem.tevorders[n/2].getColorChan(n&1)],rasswap); + WRITE(p, "rastemp=%s.%s;\n", tevRasTable[bpmem.tevorders[n / 2].getColorChan(n & 1)],rasswap); if (bpmem.tevorders[n/2].getEnable(n&1)) { int texmap = bpmem.tevorders[n/2].getTexMap(n&1); diff --git a/Source/Core/VideoCommon/Src/VertexLoader.cpp b/Source/Core/VideoCommon/Src/VertexLoader.cpp index d02e0afcfd..7cf7eef14c 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader.cpp @@ -107,11 +107,16 @@ void LOADERDECL UpdateBoundingBox() t[2] = p[0] * world_matrix[8] + p[1] * world_matrix[9] + p[2] * world_matrix[10] + world_matrix[11]; float o[4]; + o[2] = t[0] * proj_matrix[8] + t[1] * proj_matrix[9] + t[2] * proj_matrix[10] + proj_matrix[11]; + // Depth culling + if (o[2] < 0.0) { + // No pixels are likely to be drawn - don't update bounding box. + return; + } o[0] = t[0] * proj_matrix[0] + t[1] * proj_matrix[1] + t[2] * proj_matrix[2] + proj_matrix[3]; o[1] = t[0] * proj_matrix[4] + t[1] * proj_matrix[5] + t[2] * proj_matrix[6] + proj_matrix[7]; - o[2] = t[0] * proj_matrix[8] + t[1] * proj_matrix[9] + t[2] * proj_matrix[10] + proj_matrix[11]; o[3] = t[0] * proj_matrix[12] + t[1] * proj_matrix[13] + t[2] * proj_matrix[14] + proj_matrix[15]; - + o[0] /= o[3]; o[1] /= o[3]; diff --git a/Source/Plugins/Plugin_DSP_HLE/Plugin_DSP_HLE.vcproj b/Source/Plugins/Plugin_DSP_HLE/Plugin_DSP_HLE.vcproj index 45eca9c5c3..ab6df2c916 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Plugin_DSP_HLE.vcproj +++ b/Source/Plugins/Plugin_DSP_HLE/Plugin_DSP_HLE.vcproj @@ -668,6 +668,10 @@ + + @@ -684,6 +688,10 @@ RelativePath=".\Src\UCodes\UCode_Zelda_ADPCM.h" > + + diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp index e066965383..bfc434faba 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp +++ b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp @@ -30,28 +30,41 @@ #include "WaveFile.h" CUCode_Zelda::CUCode_Zelda(CMailHandler& _rMailHandler, u32 _CRC) - : IUCode(_rMailHandler) - , 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) - , m_pos(0) - , m_DMABaseAddr(0) - , m_numSteps(0) - , m_bListInProgress(false) - , m_step(0) - , m_readOffset(0) - , m_MailState(WaitForMail) + : + IUCode(_rMailHandler), + m_CRC(_CRC), + + m_bSyncInProgress(0), + m_MaxVoice(0), + + m_NumVoices(0), + + m_bSyncCmdPending(0), + m_CurVoice(0), + m_CurBuffer(0), + m_NumBuffers(0), + + m_VoicePBsAddr(0), + m_UnkTableAddr(0), + m_ReverbPBsAddr(0), + + m_RightBuffersAddr(0), + m_LeftBuffersAddr(0), + m_pos(0), + + m_DMABaseAddr(0), + + m_numSteps(0), + m_bListInProgress(0), + m_step(0), + + m_readOffset(0), + + m_MailState(WaitForMail), + + m_NumPBs(0), + m_PBAddress(0), + m_PBAddress2(0) { DEBUG_LOG(DSPHLE, "UCode_Zelda - add boot mails for handshake"); m_rMailHandler.PushMail(DSP_INIT); @@ -65,6 +78,7 @@ CUCode_Zelda::CUCode_Zelda(CMailHandler& _rMailHandler, u32 _CRC) memset(m_Buffer, 0, sizeof(m_Buffer)); memset(m_SyncFlags, 0, sizeof(m_SyncFlags)); memset(m_AFCCoefTable, 0, sizeof(m_AFCCoefTable)); + memset(m_PBMask, 0, sizeof(m_PBMask)); } CUCode_Zelda::~CUCode_Zelda() @@ -76,186 +90,6 @@ CUCode_Zelda::~CUCode_Zelda() delete [] m_RightBuffer; } -#if 0 -void CUCode_Zelda::UpdatePB(ZPB& _rPB, int *templbuffer, int *temprbuffer, u32 _Size) -{ - u16* pTest = (u16*)&_rPB; - - // Checks at 0293 - if (pTest[0x00] == 0) - return; - - if (pTest[0x01] != 0) - return; - - - if (pTest[0x06] != 0x00) - { - // probably pTest[0x06] == 0 -> AFC (and variants) - // See 02a4 - } - else - { - switch (_rPB.type) // or Bytes per Sample - { - case 0x05: - case 0x09: - { - // initialize "decoder" if the sample is played the first time - if (pTest[0x04] != 0) - { - // This is 0717_ReadOutPBStuff - - // increment 4fb - - // zelda: - // perhaps init or "has played before" - pTest[0x32] = 0x00; - pTest[0x66] = 0x00; // history1 - pTest[0x67] = 0x00; // history2 - - // samplerate? length? num of samples? i dunno... - // Likely length... - pTest[0x3a] = pTest[0x8a]; - pTest[0x3b] = pTest[0x8b]; - - // Copy ARAM addr from r to rw area. - pTest[0x38] = pTest[0x8c]; - pTest[0x39] = pTest[0x8d]; - } - - if (pTest[0x01] != 0) // 0747 early out... i dunno if this can happen because we filter it above - return; - - u32 ARAMAddr = (pTest[0x38] << 16) | pTest[0x39]; - u32 NumberOfSamples = (pTest[0x3a] << 16) | pTest[0x3b]; - - // round upwards how many samples we need to copy, 0759 - NumberOfSamples = (NumberOfSamples + 0xf) >> 4; // i think the lower 4 are the fraction - u32 frac = NumberOfSamples & 0xF; - - u8 inBuffer[9]; - short outbuf[16]; - u32 sampleCount = 0; - - // It must be something like this: - - // 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. - -#define USE_RESAMPLE -#if !defined(USE_RESAMPLE) - for (int s = 0; s < _Size/16; s++) - { - for (int i = 0; i < 9; i++) - { - inBuffer[i] = g_dspInitialize.pARAM_Read_U8(ARAMAddr); - ARAMAddr++; - } - - AFCdecodebuffer((char*)inBuffer, outbuf, (short*)&pTest[0x66], (short*)&pTest[0x67]); - - for (int i = 0; i < 16; i++) - { - templbuffer[sampleCount] += outbuf[i]; - temprbuffer[sampleCount] += outbuf[i]; - sampleCount++; - } - - NumberOfSamples--; - - if (NumberOfSamples<=0) - break; - } -#else - while (NumberOfSamples > 0) - { - for (int i = 0; i < 9; i++) - { - inBuffer[i] = g_dspInitialize.pARAM_Read_U8(ARAMAddr); - ARAMAddr++; - } - - AFCdecodebuffer(m_AFCCoefTable, (char*)inBuffer, outbuf, (short*)&pTest[0x66], (short*)&pTest[0x67], 9); - CResampler Sampler(outbuf, 16, 48000); - - while (Sampler.m_queueSize > 0) - { - int sample = Sampler.sample_queue.front(); - Sampler.sample_queue.pop(); - Sampler.m_queueSize -= 1; - - templbuffer[sampleCount] += sample; - temprbuffer[sampleCount] += sample; - sampleCount++; - - if (sampleCount > _Size) - break; - } - - if (sampleCount > _Size) - break; - - NumberOfSamples--; - } -#endif - if (NumberOfSamples == 0) - { - pTest[0x01] = 1; // we are done ?? - } - - // write back - NumberOfSamples = (NumberOfSamples << 4); // missing fraction - - 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 AFC (and variants) + // See 02a4 + } + else + { + switch (_rPB.type) // or Bytes per Sample + { + case 0x05: + case 0x09: + { + // initialize "decoder" if the sample is played the first time + if (pTest[0x04] != 0) + { + // This is 0717_ReadOutPBStuff + + // increment 4fb + + // zelda: + // perhaps init or "has played before" + pTest[0x32] = 0x00; + pTest[0x66] = 0x00; // history1 + pTest[0x67] = 0x00; // history2 + + // samplerate? length? num of samples? i dunno... + // Likely length... + pTest[0x3a] = pTest[0x8a]; + pTest[0x3b] = pTest[0x8b]; + + // Copy ARAM addr from r to rw area. + pTest[0x38] = pTest[0x8c]; + pTest[0x39] = pTest[0x8d]; + } + + if (pTest[0x01] != 0) // 0747 early out... i dunno if this can happen because we filter it above + return; + + u32 ARAMAddr = (pTest[0x38] << 16) | pTest[0x39]; + u32 NumberOfSamples = (pTest[0x3a] << 16) | pTest[0x3b]; + + // round upwards how many samples we need to copy, 0759 + NumberOfSamples = (NumberOfSamples + 0xf) >> 4; // i think the lower 4 are the fraction + u32 frac = NumberOfSamples & 0xF; + + u8 inBuffer[9]; + short outbuf[16]; + u32 sampleCount = 0; + + // It must be something like this: + + // 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. + +#define USE_RESAMPLE +#if !defined(USE_RESAMPLE) + for (int s = 0; s < _Size/16; s++) + { + for (int i = 0; i < 9; i++) + { + inBuffer[i] = g_dspInitialize.pARAM_Read_U8(ARAMAddr); + ARAMAddr++; + } + + AFCdecodebuffer((char*)inBuffer, outbuf, (short*)&pTest[0x66], (short*)&pTest[0x67]); + + for (int i = 0; i < 16; i++) + { + templbuffer[sampleCount] += outbuf[i]; + temprbuffer[sampleCount] += outbuf[i]; + sampleCount++; + } + + NumberOfSamples--; + + if (NumberOfSamples<=0) + break; + } +#else + while (NumberOfSamples > 0) + { + for (int i = 0; i < 9; i++) + { + inBuffer[i] = g_dspInitialize.pARAM_Read_U8(ARAMAddr); + ARAMAddr++; + } + + AFCdecodebuffer(m_AFCCoefTable, (char*)inBuffer, outbuf, (short*)&pTest[0x66], (short*)&pTest[0x67], 9); + CResampler Sampler(outbuf, 16, 48000); + + while (Sampler.m_queueSize > 0) + { + int sample = Sampler.sample_queue.front(); + Sampler.sample_queue.pop(); + Sampler.m_queueSize -= 1; + + templbuffer[sampleCount] += sample; + temprbuffer[sampleCount] += sample; + sampleCount++; + + if (sampleCount > _Size) + break; + } + + if (sampleCount > _Size) + break; + + NumberOfSamples--; + } +#endif + if (NumberOfSamples == 0) + { + pTest[0x01] = 1; // we are done ?? + } + + // write back + NumberOfSamples = (NumberOfSamples << 4); // missing fraction + + 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; iSetupVertexPointers(); GL_REPORT_ERRORD();