/[pcsx2_0.9.7]/trunk/pcsx2/Vif_Codes.cpp
ViewVC logotype

Diff of /trunk/pcsx2/Vif_Codes.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/pcsx2/Vif_Codes.cpp	2010/09/07 06:28:05	61
+++ trunk/pcsx2/Vif_Codes.cpp	2010/09/07 11:08:22	62
@@ -21,7 +21,7 @@
 #include "newVif.h"
 #include "VUmicro.h"
 
-#define vifOp(vifCodeName) _vifT int __fastcall vifCodeName(int pass, u32 *data)
+#define vifOp(vifCodeName) _vifT int __fastcall vifCodeName(int pass, const u32 *data)
 #define pass1 if (pass == 0)
 #define pass2 if (pass == 1)
 #define pass3 if (pass == 2)
@@ -32,59 +32,74 @@
 // Vif0/Vif1 Misc Functions
 //------------------------------------------------------------------
 
-static _f void vifFlush(int idx) {
+static __fi void vifFlush(int idx) {
 	if (!idx) vif0FLUSH();
 	else	  vif1FLUSH();
 }
 
-static _f void vuExecMicro(int idx, u32 addr) {
+static __fi void vuExecMicro(int idx, u32 addr) {
 	VURegs* VU = nVif[idx].VU;
-	vifFlush(idx);
+	VIFregisters& vifRegs = VU->GetVifRegs();
+	int startcycles = 0;
+	//vifFlush(idx);
 
-	if (VU->vifRegs->itops  > (idx ? 0x3ffu : 0xffu)) {
-		Console.WriteLn("VIF%d ITOP overrun! %x", idx, VU->vifRegs->itops);
-		VU->vifRegs->itops &= (idx ? 0x3ffu : 0xffu);
+	//if(vifX.vifstalled == true) return;
+
+	if (vifRegs.itops  > (idx ? 0x3ffu : 0xffu)) {
+		Console.WriteLn("VIF%d ITOP overrun! %x", idx, vifRegs.itops);
+		vifRegs.itops &= (idx ? 0x3ffu : 0xffu);
 	}
 
-	VU->vifRegs->itop = VU->vifRegs->itops;
+	vifRegs.itop = vifRegs.itops;
 
 	if (idx) {
 		// in case we're handling a VIF1 execMicro, set the top with the tops value
-		VU->vifRegs->top = VU->vifRegs->tops & 0x3ff;
+		vifRegs.top = vifRegs.tops & 0x3ff;
 
 		// is DBF flag set in VIF_STAT?
-		if (VU->vifRegs->stat.DBF) {
+		if (vifRegs.stat.DBF) {
 			// it is, so set tops with base, and clear the stat DBF flag
-			VU->vifRegs->tops = VU->vifRegs->base;
-			VU->vifRegs->stat.DBF = false;
+			vifRegs.tops = vifRegs.base;
+			vifRegs.stat.DBF = false;
 		}
 		else {
 			// it is not, so set tops with base + offset, and set stat DBF flag
-			VU->vifRegs->tops = VU->vifRegs->base + VU->vifRegs->ofst;
-			VU->vifRegs->stat.DBF = true;
+			vifRegs.tops = vifRegs.base + vifRegs.ofst;
+			vifRegs.stat.DBF = true;
 		}
 	}
 
+	if(!idx)startcycles = VU0.cycle;
+	else    startcycles = VU1.cycle;
+
 	if (!idx) vu0ExecMicro(addr);
 	else	  vu1ExecMicro(addr);
+
+	if(!idx) { g_vu0Cycles += (VU0.cycle-startcycles) * BIAS; g_packetsizeonvu = vif0.vifpacketsize; }
+	else     { g_vu1Cycles += (VU1.cycle-startcycles) * BIAS; g_packetsizeonvu = vif1.vifpacketsize; }
+	//DevCon.Warning("Ran VU%x, VU0 Cycles %x, VU1 Cycles %x", idx, g_vu0Cycles, g_vu1Cycles);
+	GetVifX.vifstalled = true;
 }
 
 u8 schedulepath3msk = 0;
 
 void Vif1MskPath3() {
 
-	vif1Regs->mskpath3 = schedulepath3msk & 0x1;
-	//Console.WriteLn("VIF MSKPATH3 %x", vif1Regs->mskpath3);
-	gifRegs->stat.M3P = vif1Regs->mskpath3;
-	if (!vif1Regs->mskpath3) {
-		//Let the Gif know it can transfer again (making sure any vif stall isnt unset prematurely)
-		if(gif->chcr.STR == true)
+	vif1Regs.mskpath3 = schedulepath3msk & 0x1;
+	GIF_LOG("VIF MSKPATH3 %x gif str %x path3 status %x", vif1Regs.mskpath3, gifch.chcr.STR, GSTransferStatus.PTH3);
+	gifRegs.stat.M3P = vif1Regs.mskpath3;
+
+	if (!vif1Regs.mskpath3)
+	{
+		//if(GSTransferStatus.PTH3 > TRANSFER_MODE && gif->chcr.STR) GSTransferStatus.PTH3 = TRANSFER_MODE;
+		//DevCon.Warning("Mask off");
+		//if(GSTransferStatus.PTH3 >= PENDINGSTOP_MODE) GSTransferStatus.PTH3 = IDLE_MODE;
+		if(gifRegs.stat.P3Q) 
 		{
-			GSTransferStatus.PTH3 = 3;
-			CPU_INT(DMAC_GIF, 4);
+			gsInterrupt();//gsInterrupt();
 		}
-
-	}
+	
+	}// else if(!gif->chcr.STR && GSTransferStatus.PTH3 == IDLE_MODE) GSTransferStatus.PTH3 = STOPPED_MODE;//else DevCon.Warning("Mask on");
 
 	schedulepath3msk = 0;
 }
@@ -95,160 +110,231 @@
 
 vifOp(vifCode_Base) {
 	vif1Only();
-	pass1 { vif1Regs->base = vif1Regs->code & 0x3ff; vif1.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_Base"); }
+	pass1 { vif1Regs.base = vif1Regs.code & 0x3ff; vif1.cmd = 0; }
+	pass3 { VifCodeLog("Base"); }
 	return 0;
 }
 
-template<int idx> _f int _vifCode_Direct(int pass, u8* data, bool isDirectHL) {
+extern bool SIGNAL_IMR_Pending;
+
+template<int idx> __fi int _vifCode_Direct(int pass, const u8* data, bool isDirectHL) {
 	pass1 {
 		vif1Only();
-		int vifImm    = (u16)vif1Regs->code;
+		int vifImm    = (u16)vif1Regs.code;
 		vif1.tag.size = vifImm ? (vifImm*4) : (65536*4);
-		return 1;
+		vif1.vifstalled    = true;
+		gifRegs.stat.P2Q = true;
+		if (gifRegs.stat.PSE)  // temporarily stop
+		{
+			Console.WriteLn("Gif dma temp paused? VIF DIRECT");
+			vif1.GifWaitState = 3;
+			vif1Regs.stat.VGW = true;
+		}
+		//Should cause this to split here to try and time PATH3 right.		
+		return 0;
 	}
 	pass2 {
 		vif1Only();
-		//return vifTrans_DirectHL<idx>((u32*)data);
-		gifRegs->stat.P2Q = true;
-		//Should probably do this for both types of transfer seen as the GS hates taking 2 seperate chunks
-		//if (isDirectHL) {
-		if (GSTransferStatus.PTH3 < STOPPED_MODE || GSTransferStatus.PTH1 != STOPPED_MODE)
+
+		if (GSTransferStatus.PTH3 < IDLE_MODE || gifRegs.stat.P1Q == true)
+		{
+			if(gifRegs.stat.APATH == GIF_APATH2 || ((GSTransferStatus.PTH3 <= IMAGE_MODE && gifRegs.stat.IMT && (vif1.cmd & 0x7f) == 0x50)) && gifRegs.stat.P1Q == false)
+			{
+				//Do nothing, allow it
+				vif1Regs.stat.VGW = false;
+				//if(gifRegs.stat.APATH != GIF_APATH2)DevCon.Warning("Continue DIRECT/HL %x P3 %x APATH %x P1Q %x", vif1.cmd, GSTransferStatus.PTH3, gifRegs.stat.APATH, gifRegs.stat.P1Q);
+			}
+			else
+			{
+				//DevCon.Warning("Stall DIRECT/HL %x P3 %x APATH %x P1Q %x", vif1.cmd, GSTransferStatus.PTH3, gifRegs.stat.APATH, gifRegs.stat.P1Q);
+				vif1Regs.stat.VGW = true; // PATH3 is in image mode (DIRECTHL), or busy (BOTH no IMT)
+				vif1.GifWaitState = 0;
+				vif1.vifstalled    = true;
+				return 0;
+			}
+		}
+		if(SIGNAL_IMR_Pending == true)
 		{
-			/*if(!isDirectHL) DevCon.WriteLn("Direct: Waiting for Path3 to finish!");
-			else DevCon.WriteLn("DirectHL: Waiting for Path3 to finish!");*/
-			//VIF_LOG("Mask %x, GIF STR %x, PTH1 %x, PTH2 %x, PTH3 %x", vif1Regs->mskpath3, gif->chcr.STR, GSTransferStatus.PTH1, GSTransferStatus.PTH2, GSTransferStatus.PTH3);
-			vif1Regs->stat.VGW = true; // PATH3 is in image mode, so wait for end of transfer
+			DevCon.Warning("Path 2 Paused (At start)");
 			vif1.vifstalled    = true;
 			return 0;
 		}
-		//}
-		gifRegs->stat.clear_flags(GIF_STAT_P2Q);
+		if (gifRegs.stat.PSE)  // temporarily stop
+		{
+			Console.WriteLn("Gif dma temp paused? VIF DIRECT");
+			vif1.GifWaitState = 3;
+			vif1.vifstalled    = true;
+			vif1Regs.stat.VGW = true;
+			return 0;
+		}
+
+		// HACK ATTACK!
+		// we shouldn't be clearing the queue flag here at all.  Ideally, the queue statuses
+		// should be checked, handled, and cleared from the EOP check in GIFPath only. --air
+		gifRegs.stat.clear_flags(GIF_STAT_P2Q);
+
+		uint minSize	 = aMin(vif1.vifpacketsize, vif1.tag.size);
+		uint ret;
 
-		Registers::Freeze();
-		nVifStruct&	v	 = nVif[1];
-		const int	ret	 = aMin(vif1.vifpacketsize, vif1.tag.size);
-		u32			size = ret << 2;
-
-		gifRegs->stat.APATH = GIF_APATH2; //Flag is cleared in vif1interrupt to simulate it being in progress.
-
-		if (ret == v.vif->tag.size) { // Full Transfer
-			if (v.bSize) { // Last transfer was partial
-				memcpy_fast(&v.buffer[v.bSize], data, size);
-				v.bSize += size;
-				data = v.buffer;
-				size = v.bSize;
+		if(minSize < 4)
+		{
+			// When TTE==1, the VIF might end up sending us 8-byte packets instead of the usual 16-byte
+			// variety, if DIRECT tags cross chain dma boundaries.  The actual behavior of real hardware
+			// is unknown at this time, but it seems that games *only* ever try to upload zero'd data
+			// in this situation.
+			//
+			// Games that use TTE==1 and DIRECT in this fashion:  ICO
+			//
+			// Because DIRECT normally has a strict QWC alignment requirement, and this funky behavior
+			// only seems to happen on TTE mode transfers with their split-64-bit packets, there shouldn't
+			// be any need to worry about queuing more than 16 bytes of data,
+			//
+
+			static __aligned16 u32 partial_write[4];
+			static uint partial_count = 0;
+
+			for( uint i=0; i<(minSize & 3); ++i)
+				partial_write[partial_count++] = ((u32*)data)[i];
+
+			pxAssume( partial_count <= 4 );
+			ret = 0;
+			if (partial_count == 4)
+			{
+				GetMTGS().PrepDataPacket(GIF_PATH_2, 1);
+				GIFPath_CopyTag(GIF_PATH_2, (u128*)partial_write, 1);
+				GetMTGS().SendDataPacket();
+				partial_count = 0;
+				ret = 4;
 			}
-			if (!size) { DevCon.WriteLn("Path2: No Data Transfer?"); }
-			const uint count = GetMTGS().PrepDataPacket(GIF_PATH_2, data, size >> 4);
-			memcpy_fast(GetMTGS().GetDataPacketPtr(), data, count << 4);
-			GetMTGS().SendDataPacket();
-			vif1.tag.size = 0;
-			vif1.cmd = 0;
-			v.bSize  = 0;
 		}
-		else { // Partial Transfer
-			//DevCon.WriteLn("DirectHL: Partial Transfer [%d]", size);			
-			memcpy_fast(&v.buffer[v.bSize], data, size);
-			v.bSize		  += size;
-			vif1.tag.size -= ret;
+		else
+		{
+			if (!minSize)
+				DevCon.Warning("VIF DIRECT (PATH2): No Data Transfer?");
+
+			// TTE=1 mode is the only time we should be getting DIRECT packet sizes that are
+			// not a multiple of QWC, and those are assured to be under 128 bits in size.
+			// So if this assert is triggered then it probably means something else is amiss.
+			pxAssertMsg((minSize & 3) == 0, "DIRECT packet size is not a multiple of QWC." );
+
+			GetMTGS().PrepDataPacket(GIF_PATH_2, minSize/4);
+			ret = GIFPath_CopyTag(GIF_PATH_2, (u128*)data, minSize/4)*4;
+			GetMTGS().SendDataPacket();
 		}
 
-		Registers::Thaw();
+		vif1.tag.size -= ret;
+
+		if(vif1.tag.size == 0) 
+		{
+			vif1.cmd = 0;
+		}
+		vif1.vifstalled    = true;
 		return ret;
 	}
 	return 0;
 }
 
 vifOp(vifCode_Direct) {
-	pass3 { DevCon.WriteLn("vifCode_Direct"); }
+	pass3 { VifCodeLog("Direct"); }
 	return _vifCode_Direct<idx>(pass, (u8*)data, 0);
 }
 
 vifOp(vifCode_DirectHL) {
-	pass3 { DevCon.WriteLn("vifCode_DirectHL"); }
+	pass3 { VifCodeLog("DirectHL"); }
 	return _vifCode_Direct<idx>(pass, (u8*)data, 1);
 }
 
 // ToDo: FixMe
 vifOp(vifCode_Flush) {
 	vif1Only();
-	pass1 { vifFlush(idx); vifX.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_Flush"); }
+	vifStruct& vifX = GetVifX;
+	pass1 { vifFlush(idx);  vifX.cmd = 0; }
+	pass3 { VifCodeLog("Flush"); }
 	return 0;
 }
 
 // ToDo: FixMe
 vifOp(vifCode_FlushA) {
 	vif1Only();
+	vifStruct& vifX = GetVifX;
 	pass1 {
+		vifFlush(idx);
 		// Gif is already transferring so wait for it.
-		if (GSTransferStatus.PTH3 < STOPPED_MODE) {
+		if (gifRegs.stat.P1Q || GSTransferStatus.PTH3 <= PENDINGSTOP_MODE) {
+			//DevCon.Warning("VIF FlushA Wait MSK = %x", vif1Regs.mskpath3);
+			//
+			
 			//DevCon.WriteLn("FlushA path3 Wait! PTH3 MD %x STR %x", GSTransferStatus.PTH3, gif->chcr.STR);
-			vif1Regs->stat.VGW = true;
+			vif1Regs.stat.VGW = true;
+			vifX.GifWaitState  = 1;
 			vifX.vifstalled    = true;
-		}
-		vifFlush(idx);
+		}	// else DevCon.WriteLn("FlushA path3 no Wait! PTH3 MD %x STR %x", GSTransferStatus.PTH3, gif->chcr.STR);	
+		
 		vifX.cmd = 0;
 	}
-	pass3 { DevCon.WriteLn("vifCode_FlushA"); }
+	pass3 { VifCodeLog("FlushA"); }
 	return 0;
 }
 
 // ToDo: FixMe
 vifOp(vifCode_FlushE) {
+	vifStruct& vifX = GetVifX;
 	pass1 { vifFlush(idx); vifX.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_FlushE"); }
+	pass3 { VifCodeLog("FlushE"); }
 	return 0;
 }
 
 vifOp(vifCode_ITop) {
-	pass1 { vifXRegs->itops = vifXRegs->code & 0x3ff; vifX.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_ITop"); }
+	pass1 { vifXRegs.itops = vifXRegs.code & 0x3ff; GetVifX.cmd = 0; }
+	pass3 { VifCodeLog("ITop"); }
 	return 0;
 }
 
 vifOp(vifCode_Mark) {
+	vifStruct& vifX = GetVifX;
 	pass1 {
-		vifXRegs->mark     = (u16)vifXRegs->code;
-		vifXRegs->stat.MRK = true;
+		vifXRegs.mark     = (u16)vifXRegs.code;
+		vifXRegs.stat.MRK = true;
 		vifX.cmd           = 0;
 	}
-	pass3 { DevCon.WriteLn("vifCode_Mark"); }
+	pass3 { VifCodeLog("Mark"); }
 	return 0;
 }
 
-_f void _vifCode_MPG(int idx, u32 addr, u32 *data, int size) {
+static __fi void _vifCode_MPG(int idx, u32 addr, const u32 *data, int size) {
 	VURegs& VUx = idx ? VU1 : VU0;
 	pxAssume(VUx.Micro > 0);
 
-	if (memcmp(VUx.Micro + addr, data, size << 2)) {
-		if (!idx)  CpuVU0->Clear(addr, size << 2); // Clear before writing!
-		else	   CpuVU1->Clear(addr, size << 2); // Clear before writing!
-		memcpy_fast(VUx.Micro + addr, data, size << 2);
+	if (memcmp_mmx(VUx.Micro + addr, data, size*4)) {
+		// Clear VU memory before writing!
+		// (VUs expect size to be 32-bit scale, same as VIF's internal working sizes)
+		if (!idx)  CpuVU0->Clear(addr, size);
+		else	   CpuVU1->Clear(addr, size);
+		memcpy_fast(VUx.Micro + addr, data, size*4);
 	}
 }
 
 vifOp(vifCode_MPG) {
+	vifStruct& vifX = GetVifX;
 	pass1 {
-		int    vifNum =  (u8)(vifXRegs->code >> 16);
-		vifX.tag.addr = (u16)(vifXRegs->code <<  3) & (idx ? 0x3fff : 0xfff);
+		int    vifNum =  (u8)(vifXRegs.code >> 16);
+		vifX.tag.addr = (u16)(vifXRegs.code <<  3) & (idx ? 0x3fff : 0xfff);
 		vifX.tag.size = vifNum ? (vifNum*2) : 512;
+		//vifFlush(idx);
 		return 1;
 	}
 	pass2 {
-		vifFlush(idx);
 		if (vifX.vifpacketsize < vifX.tag.size) { // Partial Transfer
-			if((vifX.tag.addr +  vifX.vifpacketsize) > (idx ? 0x4000 : 0x1000)) {
+			if((vifX.tag.addr + vifX.vifpacketsize*4) > (idx ? 0x4000 : 0x1000)) {
 				DevCon.Warning("Vif%d MPG Split Overflow", idx);
 			}
 			_vifCode_MPG(idx,    vifX.tag.addr, data, vifX.vifpacketsize);
-			vifX.tag.addr   +=   vifX.vifpacketsize << 2;
+			vifX.tag.addr   +=   vifX.vifpacketsize * 4;
 			vifX.tag.size   -=   vifX.vifpacketsize;
 			return vifX.vifpacketsize;
 		}
 		else { // Full Transfer
-			if((vifX.tag.addr + vifX.tag.size) > (idx ? 0x4000 : 0x1000)) {
+			if((vifX.tag.addr + vifX.tag.size*4) > (idx ? 0x4000 : 0x1000)) {
 				DevCon.Warning("Vif%d MPG Split Overflow", idx);
 			}
 			_vifCode_MPG(idx,  vifX.tag.addr, data, vifX.tag.size);
@@ -258,25 +344,28 @@
 			return ret;
 		}
 	}
-	pass3 { DevCon.WriteLn("vifCode_MPG"); }
+	pass3 { VifCodeLog("MPG"); }
 	return 0;
 }
 
 vifOp(vifCode_MSCAL) {
-	pass1 { vuExecMicro(idx, (u16)(vifXRegs->code) << 3); vifX.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_MSCAL"); }
+	vifStruct& vifX = GetVifX;
+	pass1 { vifFlush(idx); vuExecMicro(idx, (u16)(vifXRegs.code) << 3); vifX.cmd = 0;}
+	pass3 { VifCodeLog("MSCAL"); }
 	return 0;
 }
 
 vifOp(vifCode_MSCALF) {
-	pass1 { vuExecMicro(idx, (u16)(vifXRegs->code) << 3); vifX.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_MSCALF"); }
+	vifStruct& vifX = GetVifX;
+	pass1 { vifFlush(idx); vuExecMicro(idx, (u16)(vifXRegs.code) << 3); vifX.cmd = 0; }
+	pass3 { VifCodeLog("MSCALF"); }
 	return 0;
 }
 
 vifOp(vifCode_MSCNT) {
-	pass1 { vuExecMicro(idx, -1); vifX.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_MSCNT"); }
+	vifStruct& vifX = GetVifX;
+	pass1 { vifFlush(idx); vuExecMicro(idx, -1); vifX.cmd = 0; }
+	pass3 { VifCodeLog("MSCNT"); }
 	return 0;
 }
 
@@ -284,58 +373,60 @@
 vifOp(vifCode_MskPath3) {
 	vif1Only();
 	pass1 {
-		if (vif1ch->chcr.STR) {
-			schedulepath3msk = 0x10 | ((vif1Regs->code >> 15) & 0x1);
+		if (vif1ch.chcr.STR && vif1.lastcmd != 0x13) {
+			schedulepath3msk = 0x10 | ((vif1Regs.code >> 15) & 0x1);
 			vif1.vifstalled = true;
 		}
 		else {
-			schedulepath3msk = (vif1Regs->code >> 15) & 0x1;
+			schedulepath3msk = (vif1Regs.code >> 15) & 0x1;
 			Vif1MskPath3();
 		}
-		vifX.cmd = 0;
+		vif1.cmd = 0;
 	}
-	pass3 { DevCon.WriteLn("vifCode_MskPath3"); }
+	pass3 { VifCodeLog("MskPath3"); }
 	return 0;
 }
 
 vifOp(vifCode_Nop) {
-	pass1 { vifX.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_Nop"); }
+	pass1 { GetVifX.cmd = 0; }
+	pass3 { VifCodeLog("Nop"); }
 	return 0;
 }
 
 // ToDo: Review Flags
 vifOp(vifCode_Null) {
+	vifStruct& vifX = GetVifX;
 	pass1 {
 		// if ME1, then force the vif to interrupt
-		if (!(vifXRegs->err.ME1)) { // Ignore vifcode and tag mismatch error
+		if (!(vifXRegs.err.ME1)) { // Ignore vifcode and tag mismatch error
 			Console.WriteLn("Vif%d: Unknown VifCmd! [%x]", idx, vifX.cmd);
-			vifXRegs->stat.ER1 = true;
-			vifX.vifstalled    = true;
+			vifXRegs.stat.ER1 = true;
+			vifX.vifstalled = true;
 			//vifX.irq++;
 		}
 		vifX.cmd = 0;
 	}
 	pass2 { Console.Error("Vif%d bad vifcode! [CMD = %x]", idx, vifX.cmd); }
-	pass3 { DevCon.WriteLn("vifCode_Null"); }
+	pass3 { VifCodeLog("Null"); }
 	return 0;
 }
 
 vifOp(vifCode_Offset) {
 	vif1Only();
 	pass1 {
-		vif1Regs->stat.DBF	= false;
-		vif1Regs->ofst		= vif1Regs->code & 0x3ff;
-		vif1Regs->tops		= vif1Regs->base;
-		vifX.cmd			= 0;
+		vif1Regs.stat.DBF	= false;
+		vif1Regs.ofst		= vif1Regs.code & 0x3ff;
+		vif1Regs.tops		= vif1Regs.base;
+		vif1.cmd			= 0;
 	}
-	pass3 { DevCon.WriteLn("vifCode_Offset"); }
+	pass3 { VifCodeLog("Offset"); }
 	return 0;
 }
 
-template<int idx> _f int _vifCode_STColRow(u32* data, u32* pmem1, u32* pmem2) {
-	int ret;
-	ret = min(4 - vifX.tag.addr, vifX.vifpacketsize);
+template<int idx> static __fi int _vifCode_STColRow(const u32* data, u32* pmem1, u32* pmem2) {
+	vifStruct& vifX = GetVifX;
+
+	int ret = min(4 - vifX.tag.addr, vifX.vifpacketsize);
 	pxAssume(vifX.tag.addr < 4);
 	pxAssume(ret > 0);
 
@@ -364,6 +455,7 @@
 }
 
 vifOp(vifCode_STCol) {
+	vifStruct& vifX = GetVifX;
 	pass1 {
 		vifX.tag.addr = 0;
 		vifX.tag.size = 4;
@@ -371,15 +463,17 @@
 	}
 	pass2 {
 		u32* cols  = idx ? g_vifmask.Col1 : g_vifmask.Col0;
-		u32* pmem1 = &vifXRegs->c0 + (vifX.tag.addr << 2);
+		u32* pmem1 = &vifXRegs.c0 + (vifX.tag.addr << 2);
 		u32* pmem2 = cols		   +  vifX.tag.addr;
 		return _vifCode_STColRow<idx>(data, pmem1, pmem2);
 	}
-	pass3 { DevCon.WriteLn("vifCode_STCol"); }
+	pass3 { VifCodeLog("STCol"); }
 	return 0;
 }
 
 vifOp(vifCode_STRow) {
+	vifStruct& vifX = GetVifX;
+
 	pass1 {
 		vifX.tag.addr = 0;
 		vifX.tag.size = 4;
@@ -387,45 +481,47 @@
 	}
 	pass2 {
 		u32* rows  = idx ? g_vifmask.Row1 : g_vifmask.Row0;
-		u32* pmem1 = &vifXRegs->r0 + (vifX.tag.addr << 2);
+		u32* pmem1 = &vifXRegs.r0 + (vifX.tag.addr << 2);
 		u32* pmem2 = rows		   +  vifX.tag.addr;
 		return _vifCode_STColRow<idx>(data, pmem1, pmem2);
 	}
-	pass3 { DevCon.WriteLn("vifCode_STRow"); }
+	pass3 { VifCodeLog("STRow"); }
 	return 0;
 }
 
 vifOp(vifCode_STCycl) {
+	vifStruct& vifX = GetVifX;
 	pass1 {
-		vifXRegs->cycle.cl = (u8)(vifXRegs->code);
-		vifXRegs->cycle.wl = (u8)(vifXRegs->code >> 8);
+		vifXRegs.cycle.cl = (u8)(vifXRegs.code);
+		vifXRegs.cycle.wl = (u8)(vifXRegs.code >> 8);
 		vifX.cmd		   = 0;
 	}
-	pass3 { DevCon.WriteLn("vifCode_STCycl"); }
+	pass3 { VifCodeLog("STCycl"); }
 	return 0;
 }
 
 vifOp(vifCode_STMask) {
+	vifStruct& vifX = GetVifX;
 	pass1 { vifX.tag.size = 1; }
-	pass2 { vifXRegs->mask = data[0]; vifX.tag.size = 0; vifX.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_STMask"); }
+	pass2 { vifXRegs.mask = data[0]; vifX.tag.size = 0; vifX.cmd = 0; }
+	pass3 { VifCodeLog("STMask"); }
 	return 1;
 }
 
 vifOp(vifCode_STMod) {
-	pass1 { vifXRegs->mode = vifXRegs->code & 0x3; vifX.cmd = 0; }
-	pass3 { DevCon.WriteLn("vifCode_STMod"); }
+	pass1 { vifXRegs.mode = vifXRegs.code & 0x3; GetVifX.cmd = 0; }
+	pass3 { VifCodeLog("STMod"); }
 	return 0;
 }
 
 vifOp(vifCode_Unpack) {
 	pass1 {
-		if (!idx) vif0UnpackSetup(data);
-		else	  vif1UnpackSetup(data);
+		if (!idx) vifUnpackSetup<0>(data);
+		else	  vifUnpackSetup<1>(data);
 		return 1;
 	}
 	pass2 { return nVifUnpack(idx, (u8*)data); }
-	pass3 { DevCon.WriteLn("vifCode_Unpack");  }
+	pass3 { VifCodeLog("Unpack");  }
 	return 0;
 }
 
@@ -433,40 +529,42 @@
 // Vif0/Vif1 Code Tables
 //------------------------------------------------------------------
 
-int (__fastcall *vif0Code[128])(int pass, u32 *data) = {
-	vifCode_Nop<0>     , vifCode_STCycl<0>  , vifCode_Offset<0>	, vifCode_Base<0>   , vifCode_ITop<0>   , vifCode_STMod<0>  , vifCode_MskPath3<0>, vifCode_Mark<0>,   /*0x00*/
-	vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x08*/
-	vifCode_FlushE<0>  , vifCode_Flush<0>   , vifCode_Null<0>	, vifCode_FlushA<0> , vifCode_MSCAL<0>  , vifCode_MSCALF<0> , vifCode_Null<0>	 , vifCode_MSCNT<0>,  /*0x10*/
-	vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x18*/
-	vifCode_STMask<0>  , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>	 , vifCode_Null<0>,   /*0x20*/
-	vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>	 , vifCode_Null<0>,   /*0x28*/
-	vifCode_STRow<0>   , vifCode_STCol<0>	, vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>	 , vifCode_Null<0>,   /*0x30*/
-	vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x38*/
-	vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x40*/
-	vifCode_Null<0>    , vifCode_Null<0>    , vifCode_MPG<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x48*/
-	vifCode_Direct<0>  , vifCode_DirectHL<0>, vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x50*/
-	vifCode_Null<0>	   , vifCode_Null<0>	, vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x58*/
-	vifCode_Unpack<0>  , vifCode_Unpack<0>  , vifCode_Unpack<0>	, vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0>  , vifCode_Null<0>,   /*0x60*/
-	vifCode_Unpack<0>  , vifCode_Unpack<0>  , vifCode_Unpack<0>	, vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0>  , vifCode_Unpack<0>, /*0x68*/
-	vifCode_Unpack<0>  , vifCode_Unpack<0>  , vifCode_Unpack<0>	, vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0>  , vifCode_Null<0>,   /*0x70*/
-	vifCode_Unpack<0>  , vifCode_Unpack<0>  , vifCode_Unpack<0>	, vifCode_Null<0>   , vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0>  , vifCode_Unpack<0>  /*0x78*/
-};
-
-int (__fastcall *vif1Code[128])(int pass, u32 *data) = {
-	vifCode_Nop<1>     , vifCode_STCycl<1>  , vifCode_Offset<1>	, vifCode_Base<1>   , vifCode_ITop<1>   , vifCode_STMod<1>  , vifCode_MskPath3<1>, vifCode_Mark<1>,   /*0x00*/
-	vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x08*/
-	vifCode_FlushE<1>  , vifCode_Flush<1>   , vifCode_Null<1>	, vifCode_FlushA<1> , vifCode_MSCAL<1>  , vifCode_MSCALF<1> , vifCode_Null<1>	 , vifCode_MSCNT<1>,  /*0x10*/
-	vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x18*/
-	vifCode_STMask<1>  , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>	 , vifCode_Null<1>,   /*0x20*/
-	vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>	 , vifCode_Null<1>,   /*0x28*/
-	vifCode_STRow<1>   , vifCode_STCol<1>	, vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>	 , vifCode_Null<1>,   /*0x30*/
-	vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x38*/
-	vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x40*/
-	vifCode_Null<1>    , vifCode_Null<1>    , vifCode_MPG<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x48*/
-	vifCode_Direct<1>  , vifCode_DirectHL<1>, vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x50*/
-	vifCode_Null<1>	   , vifCode_Null<1>	, vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x58*/
-	vifCode_Unpack<1>  , vifCode_Unpack<1>  , vifCode_Unpack<1>	, vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1>  , vifCode_Null<1>,   /*0x60*/
-	vifCode_Unpack<1>  , vifCode_Unpack<1>  , vifCode_Unpack<1>	, vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1>  , vifCode_Unpack<1>, /*0x68*/
-	vifCode_Unpack<1>  , vifCode_Unpack<1>  , vifCode_Unpack<1>	, vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1>  , vifCode_Null<1>,   /*0x70*/
-	vifCode_Unpack<1>  , vifCode_Unpack<1>  , vifCode_Unpack<1>	, vifCode_Null<1>   , vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1>  , vifCode_Unpack<1>  /*0x78*/
+__aligned16 FnType_VifCmdHandler* const vifCmdHandler[2][128] =
+{
+	{
+		vifCode_Nop<0>     , vifCode_STCycl<0>  , vifCode_Offset<0>	, vifCode_Base<0>   , vifCode_ITop<0>   , vifCode_STMod<0>  , vifCode_MskPath3<0>, vifCode_Mark<0>,   /*0x00*/
+		vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x08*/
+		vifCode_FlushE<0>  , vifCode_Flush<0>   , vifCode_Null<0>	, vifCode_FlushA<0> , vifCode_MSCAL<0>  , vifCode_MSCALF<0> , vifCode_Null<0>	 , vifCode_MSCNT<0>,  /*0x10*/
+		vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x18*/
+		vifCode_STMask<0>  , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>	 , vifCode_Null<0>,   /*0x20*/
+		vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>	 , vifCode_Null<0>,   /*0x28*/
+		vifCode_STRow<0>   , vifCode_STCol<0>	, vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>	 , vifCode_Null<0>,   /*0x30*/
+		vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x38*/
+		vifCode_Null<0>    , vifCode_Null<0>    , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x40*/
+		vifCode_Null<0>    , vifCode_Null<0>    , vifCode_MPG<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x48*/
+		vifCode_Direct<0>  , vifCode_DirectHL<0>, vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x50*/
+		vifCode_Null<0>	   , vifCode_Null<0>	, vifCode_Null<0>	, vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>   , vifCode_Null<0>    , vifCode_Null<0>,   /*0x58*/
+		vifCode_Unpack<0>  , vifCode_Unpack<0>  , vifCode_Unpack<0>	, vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0>  , vifCode_Null<0>,   /*0x60*/
+		vifCode_Unpack<0>  , vifCode_Unpack<0>  , vifCode_Unpack<0>	, vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0>  , vifCode_Unpack<0>, /*0x68*/
+		vifCode_Unpack<0>  , vifCode_Unpack<0>  , vifCode_Unpack<0>	, vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0>  , vifCode_Null<0>,   /*0x70*/
+		vifCode_Unpack<0>  , vifCode_Unpack<0>  , vifCode_Unpack<0>	, vifCode_Null<0>   , vifCode_Unpack<0> , vifCode_Unpack<0> , vifCode_Unpack<0>  , vifCode_Unpack<0>  /*0x78*/
+	},
+	{
+		vifCode_Nop<1>     , vifCode_STCycl<1>  , vifCode_Offset<1>	, vifCode_Base<1>   , vifCode_ITop<1>   , vifCode_STMod<1>  , vifCode_MskPath3<1>, vifCode_Mark<1>,   /*0x00*/
+		vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x08*/
+		vifCode_FlushE<1>  , vifCode_Flush<1>   , vifCode_Null<1>	, vifCode_FlushA<1> , vifCode_MSCAL<1>  , vifCode_MSCALF<1> , vifCode_Null<1>	 , vifCode_MSCNT<1>,  /*0x10*/
+		vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x18*/
+		vifCode_STMask<1>  , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>	 , vifCode_Null<1>,   /*0x20*/
+		vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>	 , vifCode_Null<1>,   /*0x28*/
+		vifCode_STRow<1>   , vifCode_STCol<1>	, vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>	 , vifCode_Null<1>,   /*0x30*/
+		vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x38*/
+		vifCode_Null<1>    , vifCode_Null<1>    , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x40*/
+		vifCode_Null<1>    , vifCode_Null<1>    , vifCode_MPG<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x48*/
+		vifCode_Direct<1>  , vifCode_DirectHL<1>, vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x50*/
+		vifCode_Null<1>	   , vifCode_Null<1>	, vifCode_Null<1>	, vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>   , vifCode_Null<1>    , vifCode_Null<1>,   /*0x58*/
+		vifCode_Unpack<1>  , vifCode_Unpack<1>  , vifCode_Unpack<1>	, vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1>  , vifCode_Null<1>,   /*0x60*/
+		vifCode_Unpack<1>  , vifCode_Unpack<1>  , vifCode_Unpack<1>	, vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1>  , vifCode_Unpack<1>, /*0x68*/
+		vifCode_Unpack<1>  , vifCode_Unpack<1>  , vifCode_Unpack<1>	, vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1>  , vifCode_Null<1>,   /*0x70*/
+		vifCode_Unpack<1>  , vifCode_Unpack<1>  , vifCode_Unpack<1>	, vifCode_Null<1>   , vifCode_Unpack<1> , vifCode_Unpack<1> , vifCode_Unpack<1>  , vifCode_Unpack<1>  /*0x78*/
+	}
 };

 

  ViewVC Help
Powered by ViewVC 1.1.22