2010-04-24 21:37:39 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-24 21:37:39 +00:00
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PrecompiledHeader.h"
|
|
|
|
#include "Common.h"
|
|
|
|
#include "Vif_Dma.h"
|
|
|
|
#include "GS.h"
|
2011-07-24 13:02:50 +00:00
|
|
|
#include "Gif_Unit.h"
|
2010-04-24 21:37:39 +00:00
|
|
|
#include "VUmicro.h"
|
|
|
|
#include "newVif.h"
|
|
|
|
|
2011-10-15 10:45:31 +00:00
|
|
|
u32 g_vif1Cycles = 0;
|
2010-06-22 23:10:40 +00:00
|
|
|
|
2010-08-09 04:10:38 +00:00
|
|
|
__fi void vif1FLUSH()
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2016-09-10 18:08:14 +00:00
|
|
|
if(vif1Regs.stat.VEW)
|
2011-11-07 16:08:30 +00:00
|
|
|
{
|
2012-04-07 01:48:34 +00:00
|
|
|
vif1.waitforvu = true;
|
2013-02-18 21:17:35 +00:00
|
|
|
vif1.vifstalled.enabled = VifStallEnable(vif1ch);
|
2012-08-16 23:03:27 +00:00
|
|
|
vif1.vifstalled.value = VIF_TIMING_BREAK;
|
2010-06-22 23:10:40 +00:00
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void vif1TransferToMemory()
|
|
|
|
{
|
2010-09-08 11:34:39 +00:00
|
|
|
u128* pMem = (u128*)dmaGetAddr(vif1ch.madr, false);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
|
|
|
// VIF from gsMemory
|
2011-08-01 03:16:42 +00:00
|
|
|
if (pMem == NULL) { // Is vif0ptag empty?
|
2010-04-24 21:37:39 +00:00
|
|
|
Console.WriteLn("Vif1 Tag BUSERR");
|
2011-08-01 03:16:42 +00:00
|
|
|
dmacRegs.stat.BEIS = true; // Bus Error
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1Regs.stat.FQC = 0;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1ch.qwc = 0;
|
2010-04-24 21:37:39 +00:00
|
|
|
vif1.done = true;
|
|
|
|
CPU_INT(DMAC_VIF1, 0);
|
2011-08-01 03:16:42 +00:00
|
|
|
return; // An error has occurred.
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MTGS concerns: The MTGS is inherently disagreeable with the idea of downloading
|
|
|
|
// stuff from the GS. The *only* way to handle this case safely is to flush the GS
|
|
|
|
// completely and execute the transfer there-after.
|
2010-08-31 05:22:26 +00:00
|
|
|
//Console.Warning("Real QWC %x", vif1ch.qwc);
|
2014-08-14 06:47:03 +00:00
|
|
|
const u32 size = std::min(vif1.GSLastDownloadSize, (u32)vif1ch.qwc);
|
2016-08-07 11:27:28 +00:00
|
|
|
//const u128* pMemEnd = vif1.GSLastDownloadSize + pMem;
|
|
|
|
|
2011-07-26 08:47:47 +00:00
|
|
|
if (size) {
|
|
|
|
// Checking if any crazy game does a partial
|
|
|
|
// gs primitive and then does a gs download...
|
|
|
|
Gif_Path& p1 = gifUnit.gifPath[GIF_PATH_1];
|
|
|
|
Gif_Path& p2 = gifUnit.gifPath[GIF_PATH_2];
|
|
|
|
Gif_Path& p3 = gifUnit.gifPath[GIF_PATH_3];
|
|
|
|
pxAssert(p1.isDone() || !p1.gifTag.isValid);
|
|
|
|
pxAssert(p2.isDone() || !p2.gifTag.isValid);
|
|
|
|
pxAssert(p3.isDone() || !p3.gifTag.isValid);
|
|
|
|
}
|
|
|
|
|
2011-08-01 03:16:42 +00:00
|
|
|
GetMTGS().WaitGS();
|
2014-05-02 21:03:02 +00:00
|
|
|
if (GSinitReadFIFO2) {
|
|
|
|
GetMTGS().SendPointerPacket(GS_RINGTYPE_INIT_READ_FIFO2, size, pMem);
|
|
|
|
GetMTGS().WaitGS(false); // wait without reg sync
|
|
|
|
}
|
|
|
|
GSreadFIFO2((u64*)pMem, size);
|
2016-08-07 11:27:28 +00:00
|
|
|
// pMem += size;
|
|
|
|
|
|
|
|
//Some games such as Alex Ferguson's Player Manager 2001 reads less than GSLastDownloadSize by VIF then reads the remainder by FIFO
|
|
|
|
//Clearing the memory is clearing memory it shouldn't be and kills it.
|
|
|
|
//The only scenario where this could be used is the transfer size really is less than QWC, not the other way around as it was doing
|
|
|
|
//That said, I think this is pointless and a waste of cycles and could cause more problems than good. We will alert this situation below anyway.
|
|
|
|
/*if (vif1.GSLastDownloadSize < vif1ch.qwc) {
|
|
|
|
if (pMem < pMemEnd) {
|
|
|
|
DevCon.Warning("GS Transfer < VIF QWC, Clearing end of space GST %x QWC %x", vif1.GSLastDownloadSize, (u32)vif1ch.qwc);
|
2010-05-09 19:02:06 +00:00
|
|
|
|
2016-08-07 11:27:28 +00:00
|
|
|
__m128 zeroreg = _mm_setzero_ps();
|
|
|
|
do {
|
|
|
|
_mm_store_ps((float*)pMem, zeroreg);
|
|
|
|
} while (++pMem < pMemEnd);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
g_vif1Cycles += size * 2;
|
|
|
|
vif1ch.madr += size * 16; // mgs3 scene changes
|
2011-08-01 03:16:42 +00:00
|
|
|
if (vif1.GSLastDownloadSize >= vif1ch.qwc) {
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1.GSLastDownloadSize -= vif1ch.qwc;
|
2014-08-14 06:47:03 +00:00
|
|
|
vif1Regs.stat.FQC = std::min((u32)16, vif1.GSLastDownloadSize);
|
2016-08-07 11:27:28 +00:00
|
|
|
vif1ch.qwc = 0;
|
2010-05-09 19:02:06 +00:00
|
|
|
}
|
2011-08-01 03:16:42 +00:00
|
|
|
else {
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1Regs.stat.FQC = 0;
|
2016-08-07 11:27:28 +00:00
|
|
|
vif1ch.qwc -= vif1.GSLastDownloadSize;
|
2010-05-09 19:30:30 +00:00
|
|
|
vif1.GSLastDownloadSize = 0;
|
2016-08-07 11:27:28 +00:00
|
|
|
//This could be potentially bad and cause hangs. I guess we will find out.
|
|
|
|
DevCon.Warning("QWC left on VIF FIFO Reverse");
|
2010-05-09 19:02:06 +00:00
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2016-08-07 11:27:28 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool _VIF1chain()
|
|
|
|
{
|
|
|
|
u32 *pMem;
|
|
|
|
|
2010-08-31 05:22:26 +00:00
|
|
|
if (vif1ch.qwc == 0)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2010-08-11 09:16:12 +00:00
|
|
|
vif1.inprogress &= ~1;
|
2012-08-16 23:03:27 +00:00
|
|
|
vif1.irqoffset.value = 0;
|
|
|
|
vif1.irqoffset.enabled = false;
|
2010-04-24 21:37:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clarification - this is TO memory mode, for some reason i used the other way round >.<
|
|
|
|
if (vif1.dmamode == VIF_NORMAL_TO_MEM_MODE)
|
|
|
|
{
|
|
|
|
vif1TransferToMemory();
|
2010-08-11 09:16:12 +00:00
|
|
|
vif1.inprogress &= ~1;
|
2010-04-24 21:37:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-31 05:22:26 +00:00
|
|
|
pMem = (u32*)dmaGetAddr(vif1ch.madr, !vif1ch.chcr.DIR);
|
2010-04-24 21:37:39 +00:00
|
|
|
if (pMem == NULL)
|
|
|
|
{
|
|
|
|
vif1.cmd = 0;
|
|
|
|
vif1.tag.size = 0;
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1ch.qwc = 0;
|
2010-04-24 21:37:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIF_LOG("VIF1chain size=%d, madr=%lx, tadr=%lx",
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1ch.qwc, vif1ch.madr, vif1ch.tadr);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-08-16 23:03:27 +00:00
|
|
|
if (vif1.irqoffset.enabled)
|
|
|
|
return VIF1transfer(pMem + vif1.irqoffset.value, vif1ch.qwc * 4 - vif1.irqoffset.value, false);
|
2010-04-24 21:37:39 +00:00
|
|
|
else
|
2010-11-19 16:29:28 +00:00
|
|
|
return VIF1transfer(pMem, vif1ch.qwc * 4, false);
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
2010-08-09 04:10:38 +00:00
|
|
|
__fi void vif1SetupTransfer()
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
|
|
|
tDMA_TAG *ptag;
|
2010-07-22 12:20:11 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
ptag = dmaGetAddr(vif1ch.tadr, false); //Set memory pointer to TADR
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
if (!(vif1ch.transfer("Vif1 Tag", ptag))) return;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
vif1ch.madr = ptag[1]._u32; //MADR = ADDR field + SPR
|
|
|
|
g_vif1Cycles += 1; // Add 1 g_vifCycles from the QW read for the tag
|
|
|
|
vif1.inprogress &= ~1;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
VIF_LOG("VIF1 Tag %8.8x_%8.8x size=%d, id=%d, madr=%lx, tadr=%lx",
|
|
|
|
ptag[1]._u32, ptag[0]._u32, vif1ch.qwc, ptag->ID, vif1ch.madr, vif1ch.tadr);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
if (!vif1.done && ((dmacRegs.ctrl.STD == STD_VIF1) && (ptag->ID == TAG_REFS))) // STD == VIF1
|
|
|
|
{
|
|
|
|
// there are still bugs, need to also check if gif->madr +16*qwc >= stadr, if not, stall
|
|
|
|
if ((vif1ch.madr + vif1ch.qwc * 16) >= dmacRegs.stadr.ADDR)
|
|
|
|
{
|
|
|
|
//DevCon.Warning("VIF1 DMA Stall");
|
|
|
|
// stalled
|
|
|
|
hwDmacIrq(DMAC_STALL_SIS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-06-30 00:55:22 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
if (vif1ch.chcr.TTE)
|
|
|
|
{
|
|
|
|
// Transfer dma tag if tte is set
|
2010-07-22 12:20:11 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
bool ret;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
static __aligned16 u128 masked_tag;
|
2010-11-11 21:48:55 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
masked_tag._u64[0] = 0;
|
|
|
|
masked_tag._u64[1] = *((u64*)ptag + 1);
|
|
|
|
|
|
|
|
VIF_LOG("\tVIF1 SrcChain TTE=1, data = 0x%08x.%08x", masked_tag._u32[3], masked_tag._u32[2]);
|
|
|
|
|
|
|
|
if (vif1.irqoffset.enabled)
|
|
|
|
{
|
|
|
|
ret = VIF1transfer((u32*)&masked_tag + vif1.irqoffset.value, 4 - vif1.irqoffset.value, true); //Transfer Tag on stall
|
|
|
|
//ret = VIF1transfer((u32*)ptag + (2 + vif1.irqoffset), 2 - vif1.irqoffset); //Transfer Tag on stall
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Some games (like killzone) do Tags mid unpack, the nops will just write blank data
|
|
|
|
//to the VU's, which breaks stuff, this is where the 128bit packet will fail, so we ignore the first 2 words
|
|
|
|
vif1.irqoffset.value = 2;
|
|
|
|
vif1.irqoffset.enabled = true;
|
|
|
|
ret = VIF1transfer((u32*)&masked_tag + 2, 2, true); //Transfer Tag
|
|
|
|
//ret = VIF1transfer((u32*)ptag + 2, 2); //Transfer Tag
|
|
|
|
}
|
2010-06-22 23:10:40 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
if (!ret && vif1.irqoffset.enabled)
|
|
|
|
{
|
|
|
|
vif1.inprogress &= ~1; //Better clear this so it has to do it again (Jak 1)
|
|
|
|
return; //IRQ set by VIFTransfer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vif1.irqoffset.value = 0;
|
|
|
|
vif1.irqoffset.enabled = false;
|
2010-07-22 12:20:11 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
vif1.done |= hwDmacSrcChainWithStack(vif1ch, ptag->ID);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
if(vif1ch.qwc > 0) vif1.inprogress |= 1;
|
2010-06-30 00:55:22 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
//Check TIE bit of CHCR and IRQ bit of tag
|
|
|
|
if (vif1ch.chcr.TIE && ptag->IRQ)
|
|
|
|
{
|
|
|
|
VIF_LOG("dmaIrq Set");
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
//End Transfer
|
|
|
|
vif1.done = true;
|
|
|
|
return;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-07 01:48:34 +00:00
|
|
|
__fi void vif1VUFinish()
|
|
|
|
{
|
|
|
|
if (VU0.VI[REG_VPU_STAT].UL & 0x100)
|
|
|
|
{
|
|
|
|
int _cycles = VU1.cycle;
|
|
|
|
//DevCon.Warning("Finishing VU1");
|
|
|
|
vu1Finish();
|
|
|
|
CPU_INT(VIF_VU1_FINISH, (VU1.cycle - _cycles) * BIAS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vif1Regs.stat.VEW = false;
|
2012-08-16 23:03:27 +00:00
|
|
|
VIF_LOG("VU1 finished");
|
2013-02-08 23:41:28 +00:00
|
|
|
|
|
|
|
if( gifRegs.stat.APATH == 1 )
|
|
|
|
{
|
|
|
|
VIF_LOG("Clear APATH1");
|
|
|
|
gifRegs.stat.APATH = 0;
|
|
|
|
gifRegs.stat.OPH = 0;
|
2013-02-10 15:06:10 +00:00
|
|
|
vif1Regs.stat.VGW = false; //Let vif continue if it's stuck on a flush
|
|
|
|
|
2013-02-08 23:41:28 +00:00
|
|
|
if(!vif1.waitforvu)
|
|
|
|
{
|
|
|
|
if(gifUnit.checkPaths(0,1,1)) gifUnit.Execute(false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-09-10 18:08:14 +00:00
|
|
|
if(vif1.waitforvu)
|
2012-04-07 01:48:34 +00:00
|
|
|
{
|
|
|
|
vif1.waitforvu = false;
|
|
|
|
ExecuteVU(1);
|
2012-04-07 12:27:19 +00:00
|
|
|
//Check if VIF is already scheduled to interrupt, if it's waiting, kick it :P
|
2016-09-10 18:08:14 +00:00
|
|
|
if((cpuRegs.interrupt & (1<<DMAC_VIF1 | 1 << DMAC_MFIFO_VIF)) == 0 && vif1ch.chcr.STR && !vif1Regs.stat.INT)
|
2012-04-07 12:27:19 +00:00
|
|
|
{
|
|
|
|
if(dmacRegs.ctrl.MFD == MFD_VIF1)
|
|
|
|
vifMFIFOInterrupt();
|
|
|
|
else
|
|
|
|
vif1Interrupt();
|
|
|
|
}
|
2012-04-07 01:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//DevCon.Warning("VU1 state cleared");
|
|
|
|
}
|
|
|
|
|
2010-08-09 04:10:38 +00:00
|
|
|
__fi void vif1Interrupt()
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2012-04-07 01:48:34 +00:00
|
|
|
VIF_LOG("vif1Interrupt: %8.8x chcr %x, done %x, qwc %x", cpuRegs.cycle, vif1ch.chcr._u32, vif1.done, vif1ch.qwc);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2011-10-15 10:45:31 +00:00
|
|
|
g_vif1Cycles = 0;
|
2011-02-01 01:24:37 +00:00
|
|
|
|
2013-02-10 18:31:35 +00:00
|
|
|
if( gifRegs.stat.APATH == 2 && gifUnit.gifPath[GIF_PATH_2].isDone())
|
2013-02-08 23:41:28 +00:00
|
|
|
{
|
|
|
|
gifRegs.stat.APATH = 0;
|
|
|
|
gifRegs.stat.OPH = 0;
|
2013-02-10 15:06:10 +00:00
|
|
|
vif1Regs.stat.VGW = false; //Let vif continue if it's stuck on a flush
|
2013-02-08 23:41:28 +00:00
|
|
|
|
|
|
|
if(gifUnit.checkPaths(1,0,1)) gifUnit.Execute(false, true);
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
//Some games (Fahrenheit being one) start vif first, let it loop through blankness while it sets MFIFO mode, so we need to check it here.
|
2011-07-24 13:02:50 +00:00
|
|
|
if (dmacRegs.ctrl.MFD == MFD_VIF1) {
|
2010-04-24 21:37:39 +00:00
|
|
|
//Console.WriteLn("VIFMFIFO\n");
|
|
|
|
// Test changed because the Final Fantasy 12 opening somehow has the tag in *Undefined* mode, which is not in the documentation that I saw.
|
2010-08-31 05:22:26 +00:00
|
|
|
if (vif1ch.chcr.MOD == NORMAL_MODE) Console.WriteLn("MFIFO mode is normal (which isn't normal here)! %x", vif1ch.chcr._u32);
|
2014-08-14 06:47:03 +00:00
|
|
|
vif1Regs.stat.FQC = std::min((u16)0x10, vif1ch.qwc);
|
2010-04-24 21:37:39 +00:00
|
|
|
vifMFIFOInterrupt();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-24 13:02:50 +00:00
|
|
|
// We need to check the direction, if it is downloading
|
|
|
|
// from the GS then we handle that separately (KH2 for testing)
|
|
|
|
if (vif1ch.chcr.DIR) {
|
2011-07-25 07:43:31 +00:00
|
|
|
bool isDirect = (vif1.cmd & 0x7f) == 0x50;
|
|
|
|
bool isDirectHL = (vif1.cmd & 0x7f) == 0x51;
|
|
|
|
if((isDirect && !gifUnit.CanDoPath2())
|
|
|
|
|| (isDirectHL && !gifUnit.CanDoPath2HL())) {
|
|
|
|
GUNIT_WARN("vif1Interrupt() - Waiting for Path 2 to be ready");
|
|
|
|
CPU_INT(DMAC_VIF1, 128);
|
2013-11-05 14:40:25 +00:00
|
|
|
if(gifRegs.stat.APATH == 3) vif1Regs.stat.VGW = 1; //We're waiting for path 3. Gunslinger II
|
2011-07-25 07:43:31 +00:00
|
|
|
return;
|
2011-07-24 13:02:50 +00:00
|
|
|
}
|
2013-11-05 14:40:25 +00:00
|
|
|
vif1Regs.stat.VGW = 0; //Path 3 isn't busy so we don't need to wait for it.
|
2014-08-14 06:47:03 +00:00
|
|
|
vif1Regs.stat.FQC = std::min(vif1ch.qwc, (u16)16);
|
2010-06-25 23:13:41 +00:00
|
|
|
//Simulated GS transfer time done, clear the flags
|
|
|
|
}
|
2010-06-22 23:10:40 +00:00
|
|
|
|
2016-09-10 18:08:14 +00:00
|
|
|
if(vif1.waitforvu)
|
2012-04-07 01:48:34 +00:00
|
|
|
{
|
|
|
|
//DevCon.Warning("Waiting on VU1");
|
2012-04-07 12:27:19 +00:00
|
|
|
//CPU_INT(DMAC_VIF1, 16);
|
2012-04-07 01:48:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-08-31 05:22:26 +00:00
|
|
|
if (!vif1ch.chcr.STR) Console.WriteLn("Vif1 running when CHCR == %x", vif1ch.chcr._u32);
|
2010-06-22 23:10:40 +00:00
|
|
|
|
2015-06-27 21:47:21 +00:00
|
|
|
if (vif1.irq && vif1.vifstalled.enabled && vif1.vifstalled.value == VIF_IRQ_STALL)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2011-01-21 15:17:29 +00:00
|
|
|
VIF_LOG("VIF IRQ Firing");
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1Regs.stat.INT = true;
|
2014-01-26 18:00:14 +00:00
|
|
|
|
|
|
|
//Yakuza watches VIF_STAT so lets do this here.
|
|
|
|
if (((vif1Regs.code >> 24) & 0x7f) != 0x7) {
|
|
|
|
vif1Regs.stat.VIS = true;
|
|
|
|
}
|
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
hwIntcIrq(VIF1intc);
|
|
|
|
--vif1.irq;
|
2014-01-26 18:00:14 +00:00
|
|
|
|
2010-08-31 05:22:26 +00:00
|
|
|
if (vif1Regs.stat.test(VIF1_STAT_VSS | VIF1_STAT_VIS | VIF1_STAT_VFS))
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2010-08-31 05:22:26 +00:00
|
|
|
//vif1Regs.stat.FQC = 0;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-07-22 12:20:11 +00:00
|
|
|
//NFSHPS stalls when the whole packet has gone across (it stalls in the last 32bit cmd)
|
2010-06-22 23:10:40 +00:00
|
|
|
//In this case VIF will end
|
2014-08-14 06:47:03 +00:00
|
|
|
vif1Regs.stat.FQC = std::min((u16)0x10, vif1ch.qwc);
|
2012-05-22 12:31:56 +00:00
|
|
|
if((vif1ch.qwc > 0 || !vif1.done) && !CHECK_VIF1STALLHACK)
|
2011-01-21 15:17:29 +00:00
|
|
|
{
|
|
|
|
VIF_LOG("VIF1 Stalled");
|
|
|
|
return;
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 23:03:27 +00:00
|
|
|
vif1.vifstalled.enabled = false;
|
|
|
|
|
2011-01-21 15:17:29 +00:00
|
|
|
//Mirroring change to VIF0
|
|
|
|
if (vif1.cmd)
|
|
|
|
{
|
|
|
|
if (vif1.done && (vif1ch.qwc == 0)) vif1Regs.stat.VPS = VPS_WAITING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vif1Regs.stat.VPS = VPS_IDLE;
|
|
|
|
}
|
2012-04-07 01:48:34 +00:00
|
|
|
|
|
|
|
if (vif1.inprogress & 0x1)
|
2012-06-07 21:41:00 +00:00
|
|
|
{
|
|
|
|
_VIF1chain();
|
|
|
|
// VIF_NORMAL_FROM_MEM_MODE is a very slow operation.
|
|
|
|
// Timesplitters 2 depends on this beeing a bit higher than 128.
|
2014-08-14 06:47:03 +00:00
|
|
|
if (vif1ch.chcr.DIR) vif1Regs.stat.FQC = std::min(vif1ch.qwc, (u16)16);
|
2012-06-25 20:55:31 +00:00
|
|
|
|
|
|
|
if(!(vif1Regs.stat.VGW && gifUnit.gifPath[GIF_PATH_3].state != GIF_PATH_IDLE)) //If we're waiting on GIF, stop looping, (can be over 1000 loops!)
|
|
|
|
CPU_INT(DMAC_VIF1, g_vif1Cycles);
|
2012-06-07 21:41:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vif1.done)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!(dmacRegs.ctrl.DMAE))
|
|
|
|
{
|
|
|
|
Console.WriteLn("vif1 dma masked");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vif1.inprogress & 0x1) == 0) vif1SetupTransfer();
|
2014-08-14 06:47:03 +00:00
|
|
|
if (vif1ch.chcr.DIR) vif1Regs.stat.FQC = std::min(vif1ch.qwc, (u16)16);
|
2012-06-25 20:55:31 +00:00
|
|
|
|
|
|
|
if(!(vif1Regs.stat.VGW && gifUnit.gifPath[GIF_PATH_3].state != GIF_PATH_IDLE)) //If we're waiting on GIF, stop looping, (can be over 1000 loops!)
|
|
|
|
CPU_INT(DMAC_VIF1, g_vif1Cycles);
|
2012-06-07 21:41:00 +00:00
|
|
|
return;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
2012-08-16 23:03:27 +00:00
|
|
|
if (vif1.vifstalled.enabled && vif1.done)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2012-08-16 23:03:27 +00:00
|
|
|
DevCon.WriteLn("VIF1 looping on stall at end\n");
|
2010-04-24 21:37:39 +00:00
|
|
|
CPU_INT(DMAC_VIF1, 0);
|
|
|
|
return; //Dont want to end if vif is stalled.
|
|
|
|
}
|
|
|
|
#ifdef PCSX2_DEVBUILD
|
2010-08-31 05:22:26 +00:00
|
|
|
if (vif1ch.qwc > 0) Console.WriteLn("VIF1 Ending with %x QWC left", vif1ch.qwc);
|
2010-04-24 21:37:39 +00:00
|
|
|
if (vif1.cmd != 0) Console.WriteLn("vif1.cmd still set %x tag size %x", vif1.cmd, vif1.tag.size);
|
|
|
|
#endif
|
|
|
|
|
2010-08-31 05:22:26 +00:00
|
|
|
if((vif1ch.chcr.DIR == VIF_NORMAL_TO_MEM_MODE) && vif1.GSLastDownloadSize <= 16)
|
2010-07-22 19:17:10 +00:00
|
|
|
{
|
|
|
|
//Reverse fifo has finished and nothing is left, so lets clear the outputting flag
|
2010-08-31 05:22:26 +00:00
|
|
|
gifRegs.stat.OPH = false;
|
2010-07-22 19:17:10 +00:00
|
|
|
}
|
|
|
|
|
2014-08-14 06:47:03 +00:00
|
|
|
if (vif1ch.chcr.DIR) vif1Regs.stat.FQC = std::min(vif1ch.qwc, (u16)16);
|
2011-01-21 16:24:54 +00:00
|
|
|
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1ch.chcr.STR = false;
|
2012-08-16 23:03:27 +00:00
|
|
|
vif1.vifstalled.enabled = false;
|
|
|
|
vif1.irqoffset.enabled = false;
|
2016-09-10 18:08:14 +00:00
|
|
|
if(vif1.queued_program) vifExecQueue(1);
|
2011-10-15 10:45:31 +00:00
|
|
|
g_vif1Cycles = 0;
|
2011-02-24 11:07:13 +00:00
|
|
|
DMA_LOG("VIF1 DMA End");
|
2010-04-24 21:37:39 +00:00
|
|
|
hwDmacIrq(DMAC_VIF1);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dmaVIF1()
|
|
|
|
{
|
|
|
|
VIF_LOG("dmaVIF1 chcr = %lx, madr = %lx, qwc = %lx\n"
|
|
|
|
" tadr = %lx, asr0 = %lx, asr1 = %lx",
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1ch.chcr._u32, vif1ch.madr, vif1ch.qwc,
|
|
|
|
vif1ch.tadr, vif1ch.asr0, vif1ch.asr1);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2011-10-15 10:45:31 +00:00
|
|
|
g_vif1Cycles = 0;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
|
|
|
#ifdef PCSX2_DEVBUILD
|
2010-08-31 05:22:26 +00:00
|
|
|
if (dmacRegs.ctrl.STD == STD_VIF1)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
|
|
|
//DevCon.WriteLn("VIF Stall Control Source = %x, Drain = %x", (psHu32(0xe000) >> 4) & 0x3, (psHu32(0xe000) >> 6) & 0x3);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-25 13:36:23 +00:00
|
|
|
if (vif1ch.qwc > 0) // Normal Mode
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2010-08-12 19:58:19 +00:00
|
|
|
|
|
|
|
// ignore tag if it's a GS download (Def Jam Fight for NY)
|
2011-08-25 13:36:23 +00:00
|
|
|
if(vif1ch.chcr.MOD == CHAIN_MODE && vif1ch.chcr.DIR)
|
2010-06-22 23:10:40 +00:00
|
|
|
{
|
|
|
|
vif1.dmamode = VIF_CHAIN_MODE;
|
2010-11-19 16:29:28 +00:00
|
|
|
//DevCon.Warning(L"VIF1 QWC on Chain CHCR " + vif1ch.chcr.desc());
|
2010-06-25 23:13:41 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
if ((vif1ch.chcr.tag().ID == TAG_REFE) || (vif1ch.chcr.tag().ID == TAG_END) || (vif1ch.chcr.tag().IRQ && vif1ch.chcr.TIE))
|
2010-06-22 23:10:40 +00:00
|
|
|
{
|
|
|
|
vif1.done = true;
|
|
|
|
}
|
2011-08-25 13:36:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
vif1.done = false;
|
|
|
|
}
|
2010-06-22 23:10:40 +00:00
|
|
|
}
|
2011-08-25 13:36:23 +00:00
|
|
|
else //Assume normal mode for reverse FIFO and Normal.
|
|
|
|
{
|
|
|
|
if (dmacRegs.ctrl.STD == STD_VIF1)
|
2014-02-26 22:34:02 +00:00
|
|
|
Console.WriteLn("DMA Stall Control on VIF1 normal not implemented - Report which game to PCSX2 Team");
|
2011-08-25 13:36:23 +00:00
|
|
|
|
2014-02-26 22:34:02 +00:00
|
|
|
if (vif1ch.chcr.DIR) // from Memory
|
2011-08-25 13:36:23 +00:00
|
|
|
vif1.dmamode = VIF_NORMAL_FROM_MEM_MODE;
|
|
|
|
else
|
|
|
|
vif1.dmamode = VIF_NORMAL_TO_MEM_MODE;
|
|
|
|
|
2016-09-10 18:08:14 +00:00
|
|
|
if(vif1.irqoffset.enabled && !vif1.done) DevCon.Warning("Warning! VIF1 starting a Normal transfer with vif offset set (Possible force stop?)");
|
2011-08-25 13:36:23 +00:00
|
|
|
vif1.done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
vif1.inprogress |= 1;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-10 18:08:14 +00:00
|
|
|
if(vif1.irqoffset.enabled && !vif1.done) DevCon.Warning("Warning! VIF1 starting a new Chain transfer with vif offset set (Possible force stop?)");
|
2010-04-24 21:37:39 +00:00
|
|
|
vif1.dmamode = VIF_CHAIN_MODE;
|
2010-06-30 00:55:22 +00:00
|
|
|
vif1.done = false;
|
2012-04-07 01:48:34 +00:00
|
|
|
vif1.inprogress &= ~0x1;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
2014-08-14 06:47:03 +00:00
|
|
|
if (vif1ch.chcr.DIR) vif1Regs.stat.FQC = std::min((u16)0x10, vif1ch.qwc);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
|
|
|
// Chain Mode
|
2010-06-30 00:55:22 +00:00
|
|
|
CPU_INT(DMAC_VIF1, 4);
|
2010-04-24 20:14:09 +00:00
|
|
|
}
|