Skip to content

Commit

Permalink
Some leftover work from unfinished DX9 Access EFB. In DSP HLE, 0x0004…
Browse files Browse the repository at this point in the history
…,7,b,c are almost done, all that's left to do is resample from 0x50 to _Size.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4313 8ced0084-cf51-0410-be5f-012b33b47a6e
  • Loading branch information
tbennun committed Sep 24, 2009
1 parent 750ad4f commit ebfceb1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
40 changes: 33 additions & 7 deletions Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda_Synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ void CUCode_Zelda::RenderSynth_Constant(ZeldaVoicePB &PB, s32* _Buffer, int _Siz
_Buffer[i] = (s32)PB.RatioInt;
}

// A piece of code from LLE so we can see how the wrap register affects the sound

// HORRIBLE UGLINESS, someone please fix.
// See http://code.google.com/p/dolphin-emu/source/detail?r=3125
inline u16 ToMask(u16 a)
{
a = a | (a >> 8);
a = a | (a >> 4);
a = a | (a >> 2);
return a | (a >> 1);
}

inline s16 AddValueToReg(s16 reg, s32 value)
{
s16 tmp = reg;
u16 tmb = ToMask(0x003f);

for(int i = 0; i < value; i++) {
if ((tmp & tmb) == tmb)
tmp ^= 0x003f;
else
tmp++;
}

return tmp;
}

void CUCode_Zelda::RenderSynth_WaveTable(ZeldaVoicePB &PB, s32* _Buffer, int _Size)
{
Expand All @@ -139,24 +165,24 @@ void CUCode_Zelda::RenderSynth_WaveTable(ZeldaVoicePB &PB, s32* _Buffer, int _Si
break;
}

// TODO: What about the 0x003f wrap register?
// TODO: Resample this!
WARN_LOG(DSPHLE, "Synthesizing the incomplete format 0x%04x", PB.Format);

//WARN_LOG(DSPHLE, "Not synthesizing un-REd format 0x%04x", PB.Format);
u64 ACC0 = PB.CurSampleFrac << 6;

ACC0 &= 0x3f0000;
ACC0 &= 0xffff003fffff;

address += (ACC0 >> 16);
ACC0 &= 0xffff;
address = AddValueToReg(address, ((ACC0 >> 16) & 0xffff));
ACC0 &= 0xffff0000ffff;

for(int i = 0; i < _Size; i++)
{
_Buffer[i] = m_MiscTable[address];

ACC0 += PB.RatioInt << 5;
address += ((ACC0 >> 16) & 0x003f);
address = AddValueToReg(address, ((ACC0 >> 16) & 0xffff));

ACC0 &= 0xffff;
ACC0 &= 0xffff0000ffff;
}

ACC0 = address << 16;
Expand Down
27 changes: 26 additions & 1 deletion Source/Plugins/Plugin_VideoDX9/Src/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ bool Renderer::Init()
for (int stage = 0; stage < 8; stage++)
D3D::SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, g_ActiveConfig.iMaxAnisotropy);

D3D::dev->Clear(0, NULL, D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(255,255,255),1.0f,0);
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET, 0x0, 0, 0);

D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
Expand Down Expand Up @@ -465,7 +466,31 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
int srcY = (targetPixelRc.top + targetPixelRc.bottom) / 2;

u32 z = 0;
// glReadPixels(srcX, srcY, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, &z);
float val = 0.0f;

LPDIRECT3DSURFACE9 pZBuffer = NULL;
if (D3D::dev->GetDepthStencilSurface(&pZBuffer) == D3DERR_NOTFOUND)
pZBuffer = NULL;

//D3DLOCKED_RECT drect;
//HRESULT hr;

if(!pZBuffer) {
PanicAlert("No Z-Buffer!");
return 0;
}

// TODO: Fix
//if((hr = pZBuffer->LockRect(0, &drect, NULL, NULL)) != D3D_OK)
// PanicAlert("IT WAS AS I THOUGHT, %s", hr == D3DERR_WASSTILLDRAWING ? "Still drawing" :
// hr == D3DERR_INVALIDCALL ? "Invalid call" : "w00t");

//val = ((float *)drect.pBits)[0];

//pZBuffer->UnlockRect(0);

// [0.0, 1.0] ==> [0, 0xFFFFFFFF]
z = val * 0xFFFFFFFF;

// Scale the 32-bit value returned by glReadPixels to a 24-bit
// value (GC uses a 24-bit Z-buffer).
Expand Down
2 changes: 1 addition & 1 deletion docs/DSP/DSP_UC_Zelda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3213,7 +3213,7 @@ void 0919_Decoder0x6_Constant(AR0, AX0.L) {

void 091c_Decoder0x7_WaveTable(ACC0, AR0, AX0.L) {
// So AR2 is where it reads the data from, and it updates ACC0 to the final read address in the end
// Questions: What is IX2 used for? And how does the wrap register change the data access?
// Questions: How does the wrap register change the data access?

// 091c 0082 0100 lri $AR2, #0x0100
// 091e 008a 003f lri $WR2, #0x003f
Expand Down

0 comments on commit ebfceb1

Please sign in to comment.