2006-06-15 04:19:30 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include "VIF.h"
|
2008-03-22 02:37:01 +00:00
|
|
|
#include "VPU.h"
|
|
|
|
#include "VPU1.h"
|
2006-06-15 04:19:30 +00:00
|
|
|
#include "GIF.h"
|
2006-07-18 12:08:40 +00:00
|
|
|
#include "Profiler.h"
|
2008-03-21 01:53:44 +00:00
|
|
|
#include "Ps2Const.h"
|
2008-03-22 02:37:01 +00:00
|
|
|
#include "RegisterStateFile.h"
|
2006-07-18 12:08:40 +00:00
|
|
|
|
|
|
|
#ifdef PROFILE
|
|
|
|
#define PROFILE_VIFZONE "VIF"
|
|
|
|
#define PROFILE_VU1ZONE "VU0"
|
|
|
|
#endif
|
2006-06-15 04:19:30 +00:00
|
|
|
|
2008-03-22 02:37:01 +00:00
|
|
|
#define STATE_REGS_XML ("vif/regs.xml")
|
|
|
|
#define STATE_REGS_VPU_STAT ("VPU_STAT")
|
|
|
|
|
2006-06-15 04:19:30 +00:00
|
|
|
using namespace Framework;
|
2008-03-21 01:53:44 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace boost;
|
2006-06-15 04:19:30 +00:00
|
|
|
|
2006-07-04 22:07:57 +00:00
|
|
|
//REMOVE
|
|
|
|
static int nExecTimes = 0;
|
2006-06-15 04:19:30 +00:00
|
|
|
|
2008-03-21 01:53:44 +00:00
|
|
|
CVIF::CVIF(CGIF& gif, uint8* ram, const VPUINIT& vpu0Init, const VPUINIT& vpu1Init) :
|
|
|
|
m_gif(gif),
|
2008-03-22 02:37:01 +00:00
|
|
|
m_ram(ram)
|
2008-03-21 01:53:44 +00:00
|
|
|
{
|
2008-03-22 02:37:01 +00:00
|
|
|
m_pVPU[0] = new CVPU(*this, 0, vpu0Init);
|
|
|
|
m_pVPU[1] = new CVPU1(*this, 1, vpu1Init);
|
2008-03-21 01:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CVIF::~CVIF()
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
2008-03-21 01:53:44 +00:00
|
|
|
for(unsigned int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
delete m_pVPU[i];
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 04:19:30 +00:00
|
|
|
|
|
|
|
void CVIF::Reset()
|
|
|
|
{
|
2008-03-21 01:53:44 +00:00
|
|
|
m_pVPU[0]->Reset();
|
|
|
|
m_pVPU[1]->Reset();
|
|
|
|
m_VPU_STAT = 0;
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 02:37:01 +00:00
|
|
|
void CVIF::SaveState(CZipArchiveWriter& archive)
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
2008-03-22 02:37:01 +00:00
|
|
|
{
|
|
|
|
CRegisterStateFile* registerFile = new CRegisterStateFile(STATE_REGS_XML);
|
|
|
|
registerFile->SetRegister32(STATE_REGS_VPU_STAT, m_VPU_STAT);
|
|
|
|
archive.InsertFile(registerFile);
|
|
|
|
}
|
2006-06-15 04:19:30 +00:00
|
|
|
|
2008-03-22 02:37:01 +00:00
|
|
|
m_pVPU[0]->SaveState(archive);
|
|
|
|
m_pVPU[1]->SaveState(archive);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 02:37:01 +00:00
|
|
|
void CVIF::LoadState(CZipArchiveReader& archive)
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
2008-03-22 02:37:01 +00:00
|
|
|
CRegisterStateFile registerFile(*archive.BeginReadFile(STATE_REGS_XML));
|
|
|
|
m_VPU_STAT = registerFile.GetRegister32(STATE_REGS_VPU_STAT);
|
2006-06-15 04:19:30 +00:00
|
|
|
|
2008-03-22 02:37:01 +00:00
|
|
|
m_pVPU[0]->LoadState(archive);
|
|
|
|
m_pVPU[1]->LoadState(archive);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CVIF::ReceiveDMA1(uint32 nAddress, uint32 nQWC, bool nTagIncluded)
|
|
|
|
{
|
2006-07-18 12:08:40 +00:00
|
|
|
|
|
|
|
#ifdef PROFILE
|
|
|
|
CProfiler::GetInstance().BeginZone(PROFILE_VIFZONE);
|
|
|
|
#endif
|
|
|
|
|
2006-06-15 04:19:30 +00:00
|
|
|
if(nTagIncluded)
|
|
|
|
{
|
|
|
|
m_pVPU[1]->ProcessPacket(nAddress + 8, (nQWC * 0x10) - 8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pVPU[1]->ProcessPacket(nAddress, nQWC * 0x10);
|
|
|
|
}
|
2006-07-18 12:08:40 +00:00
|
|
|
|
|
|
|
#ifdef PROFILE
|
|
|
|
CProfiler::GetInstance().EndZone();
|
|
|
|
#endif
|
|
|
|
|
2006-06-15 04:19:30 +00:00
|
|
|
return nQWC;
|
|
|
|
}
|
|
|
|
|
2008-03-24 01:18:20 +00:00
|
|
|
uint32 CVIF::GetTop1()
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
|
|
|
return m_pVPU[1]->GetTOP();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CVIF::StopVU(CMIPS* pCtx)
|
|
|
|
{
|
2008-03-21 01:53:44 +00:00
|
|
|
if(pCtx == &m_pVPU[1]->GetContext())
|
|
|
|
{
|
2006-06-15 04:19:30 +00:00
|
|
|
m_VPU_STAT &= ~STAT_VBS1;
|
2008-03-21 01:53:44 +00:00
|
|
|
}
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CVIF::ProcessXGKICK(uint32 nAddress)
|
|
|
|
{
|
|
|
|
nAddress &= 0xFFFF;
|
|
|
|
nAddress *= 0x10;
|
|
|
|
|
2008-03-21 01:53:44 +00:00
|
|
|
m_gif.ProcessPacket(m_pVPU[1]->GetVuMemory(), nAddress, PS2::VUMEM1SIZE);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CVIF::IsVU1Running()
|
|
|
|
{
|
|
|
|
return (m_VPU_STAT & STAT_VBS1) != 0;
|
|
|
|
}
|
|
|
|
|
2008-03-22 02:37:01 +00:00
|
|
|
void CVIF::SingleStepVU1()
|
2008-03-21 01:53:44 +00:00
|
|
|
{
|
2008-03-22 02:37:01 +00:00
|
|
|
if(!IsVU1Running())
|
|
|
|
{
|
|
|
|
throw exception();
|
|
|
|
}
|
|
|
|
m_pVPU[1]->SingleStep();
|
2008-03-21 01:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8* CVIF::GetRam() const
|
|
|
|
{
|
|
|
|
return m_ram;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGIF& CVIF::GetGif() const
|
|
|
|
{
|
|
|
|
return m_gif;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CVIF::GetStat() const
|
|
|
|
{
|
|
|
|
return m_VPU_STAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CVIF::SetStat(uint32 stat)
|
|
|
|
{
|
|
|
|
m_VPU_STAT = stat;
|
|
|
|
}
|