2020-12-29 12:34:47 -05:00
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <cassert>
|
2020-12-29 12:47:39 -05:00
|
|
|
#include <cstring>
|
2020-12-29 12:34:47 -05:00
|
|
|
|
|
|
|
#include "Ps2Const.h"
|
|
|
|
|
|
|
|
CTest::CTest()
|
2020-12-31 09:07:13 -05:00
|
|
|
: m_ram(new uint8[PS2::SPU_RAM_SIZE])
|
2023-05-17 16:55:50 -04:00
|
|
|
, m_spuCore0(m_ram, PS2::SPU_RAM_SIZE, &m_spuSampleCache, 0)
|
|
|
|
, m_spuCore1(m_ram, PS2::SPU_RAM_SIZE, &m_spuSampleCache, 1)
|
2020-12-31 09:07:13 -05:00
|
|
|
, m_spu(m_spuCore0, m_spuCore1)
|
2020-12-29 12:34:47 -05:00
|
|
|
{
|
|
|
|
memset(m_ram, 0, PS2::SPU_RAM_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
CTest::~CTest()
|
|
|
|
{
|
2020-12-31 09:07:13 -05:00
|
|
|
delete[] m_ram;
|
2020-12-29 12:34:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTest::RunSpu(unsigned int ticks)
|
|
|
|
{
|
|
|
|
static const unsigned int DST_SAMPLE_RATE = 44100;
|
|
|
|
unsigned int blockSize = ticks * 2;
|
|
|
|
std::vector<int16> samples(blockSize);
|
|
|
|
m_spuCore0.Render(samples.data(), blockSize, DST_SAMPLE_RATE);
|
|
|
|
m_spuCore1.Render(samples.data(), blockSize, DST_SAMPLE_RATE);
|
|
|
|
}
|
|
|
|
|
2020-12-30 16:31:00 -05:00
|
|
|
uint32 CTest::GetCoreRegister(unsigned int coreIndex, uint32 address)
|
|
|
|
{
|
|
|
|
assert(coreIndex == 0);
|
|
|
|
return m_spu.ReadRegister(address);
|
|
|
|
}
|
|
|
|
|
2020-12-29 12:34:47 -05:00
|
|
|
void CTest::SetCoreRegister(unsigned int coreIndex, uint32 address, uint32 value)
|
|
|
|
{
|
|
|
|
assert(coreIndex == 0);
|
|
|
|
m_spu.WriteRegister(address, value);
|
|
|
|
}
|
|
|
|
|
2020-12-30 16:31:00 -05:00
|
|
|
uint32 CTest::GetCoreAddress(unsigned int coreIndex, uint32 registerAddress)
|
|
|
|
{
|
|
|
|
assert((registerAddress & 0x2) == 0);
|
|
|
|
uint32 addrHi = GetCoreRegister(coreIndex, registerAddress + 0);
|
|
|
|
uint32 addrLo = GetCoreRegister(coreIndex, registerAddress + 2);
|
|
|
|
return (addrHi << 17) | (addrLo << 1);
|
|
|
|
}
|
|
|
|
|
2020-12-29 12:34:47 -05:00
|
|
|
void CTest::SetCoreAddress(unsigned int coreIndex, uint32 registerAddress, uint32 targetAddress)
|
|
|
|
{
|
|
|
|
assert((registerAddress & 0x2) == 0);
|
|
|
|
SetCoreRegister(coreIndex, registerAddress + 0, (targetAddress >> 17) & 0xFFFE);
|
|
|
|
SetCoreRegister(coreIndex, registerAddress + 2, (targetAddress >> 1) & 0xFFFE);
|
|
|
|
}
|
|
|
|
|
2022-04-08 08:49:06 -04:00
|
|
|
uint32 CTest::GetVoiceRegister(unsigned int coreIndex, uint32 voiceIndex, uint32 address)
|
|
|
|
{
|
|
|
|
uint32 voiceAddress = address + (voiceIndex * 0x10);
|
|
|
|
return GetCoreRegister(coreIndex, voiceAddress);
|
|
|
|
}
|
|
|
|
|
2020-12-29 12:34:47 -05:00
|
|
|
void CTest::SetVoiceRegister(unsigned int coreIndex, uint32 voiceIndex, uint32 address, uint32 value)
|
|
|
|
{
|
|
|
|
uint32 voiceAddress = address + (voiceIndex * 0x10);
|
|
|
|
SetCoreRegister(coreIndex, voiceAddress, value);
|
|
|
|
}
|
|
|
|
|
2020-12-30 16:31:00 -05:00
|
|
|
uint32 CTest::GetVoiceAddress(unsigned int coreIndex, unsigned int voiceIndex, uint32 registerAddress)
|
|
|
|
{
|
|
|
|
uint32 voiceAddress = registerAddress + (voiceIndex * 12);
|
|
|
|
return GetCoreAddress(coreIndex, voiceAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTest::SetVoiceAddress(unsigned int coreIndex, unsigned int voiceIndex, uint32 registerAddress, uint32 targetAddress)
|
2020-12-29 12:34:47 -05:00
|
|
|
{
|
|
|
|
uint32 voiceAddress = registerAddress + (voiceIndex * 12);
|
|
|
|
SetCoreAddress(coreIndex, voiceAddress, targetAddress);
|
|
|
|
}
|