Skip to content

Commit

Permalink
Merge pull request #1474 from phire/DSPHLE_cleanups
Browse files Browse the repository at this point in the history
DSPHLE: Remove individual byteswaps and replace with generic function.
  • Loading branch information
phire committed Nov 24, 2015
2 parents f92a36d + d2b03e1 commit 83bda3b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Common/CommonFuncs.h
Expand Up @@ -167,7 +167,7 @@ inline void swap<8>(u8* data)
template <typename T>
inline T FromBigEndian(T data)
{
//static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types");
static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types");

swap<sizeof(data)>(reinterpret_cast<u8*>(&data));
return data;
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp
Expand Up @@ -403,8 +403,7 @@ void AXUCode::ProcessPBList(u32 pb_addr)
m_samples_auxB_surround
}};

if (!ReadPB(pb_addr, pb))
break;
ReadPB(pb_addr, pb);

u32 updates_addr = HILO_TO_32(pb.updates.data);
u16* updates = (u16*)HLEMemory_Get_Pointer(updates_addr);
Expand Down
22 changes: 4 additions & 18 deletions Source/Core/Core/HW/DSPHLE/UCodes/AXVoice.h
Expand Up @@ -78,31 +78,17 @@ union AXBuffers
};

// Read a PB from MRAM/ARAM
bool ReadPB(u32 addr, PB_TYPE& pb)
void ReadPB(u32 addr, PB_TYPE& pb)
{
u16* dst = (u16*)&pb;
const u16* src = (const u16*)Memory::GetPointer(addr);
if (!src)
return false;

for (u32 i = 0; i < sizeof (pb) / sizeof (u16); ++i)
dst[i] = Common::swap16(src[i]);

return true;
Memory::CopyFromEmuSwapped<u16>(dst, addr, sizeof(pb));
}

// Write a PB back to MRAM/ARAM
bool WritePB(u32 addr, const PB_TYPE& pb)
void WritePB(u32 addr, const PB_TYPE& pb)
{
const u16* src = (const u16*)&pb;
u16* dst = (u16*)Memory::GetPointer(addr);
if (!dst)
return false;

for (u32 i = 0; i < sizeof (pb) / sizeof (u16); ++i)
dst[i] = Common::swap16(src[i]);

return true;
Memory::CopyToEmuSwapped<u16>(addr, src, sizeof(pb));
}

#if 0
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Core/HW/DSPHLE/UCodes/AXWii.cpp
Expand Up @@ -455,8 +455,7 @@ void AXWiiUCode::ProcessPBList(u32 pb_addr)
m_samples_aux3
}};

if (!ReadPB(pb_addr, pb))
break;
ReadPB(pb_addr, pb);

u16 num_updates[3];
u16 updates[1024];
Expand Down
25 changes: 25 additions & 0 deletions Source/Core/Core/HW/Memmap.h
Expand Up @@ -92,4 +92,29 @@ void Write_U64(const u64 var, const u32 address);
void Write_U32_Swap(const u32 var, const u32 address);
void Write_U64_Swap(const u64 var, const u32 address);

// Templated functions for byteswapped copies.
template <typename T>
void CopyFromEmuSwapped(T* data, u32 address, size_t size)
{
const T* src = reinterpret_cast<T*>(GetPointer(address));

if(src == nullptr)
return;

for (size_t i = 0; i < size / sizeof(T); i++)
data[i] = Common::FromBigEndian(src[i]);
}

template <typename T>
void CopyToEmuSwapped(u32 address, const T* data, size_t size)
{
T* dest = reinterpret_cast<T*>(GetPointer(address));

if (dest == nullptr)
return;

for (size_t i = 0; i < size / sizeof(T); i++)
dest[i] = Common::FromBigEndian(data[i]);
}

}

0 comments on commit 83bda3b

Please sign in to comment.