2009-05-15 01:06:59 +00:00
|
|
|
/* GSnull
|
|
|
|
* Copyright (C) 2004-2009 PCSX2 Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Processes a GIFtag & packet, and throws out some gsIRQs as needed.
|
|
|
|
// Used to keep interrupts in sync with the EE, while the GS itself
|
|
|
|
// runs potentially several frames behind.
|
|
|
|
// size - size of the packet in simd128's
|
|
|
|
|
|
|
|
#include "GS.h"
|
|
|
|
#include "GifTransfer.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2009-05-15 01:57:00 +00:00
|
|
|
u32 CSRw;
|
|
|
|
GIFPath m_path[3];
|
|
|
|
bool Path3transfer;
|
|
|
|
|
|
|
|
PCSX2_ALIGNED16( u8 g_RealGSMem[0x2000] );
|
|
|
|
#define GSCSRr *((u64*)(g_RealGSMem+0x1000))
|
|
|
|
#define GSIMR *((u32*)(g_RealGSMem+0x1010))
|
|
|
|
#define GSSIGLBLID ((GSRegSIGBLID*)(g_RealGSMem+0x1080))
|
|
|
|
|
2009-05-15 01:06:59 +00:00
|
|
|
static void RegHandlerSIGNAL(const u32* data)
|
|
|
|
{
|
2009-05-15 01:57:00 +00:00
|
|
|
GSSIGLBLID->SIGID = (GSSIGLBLID->SIGID&~data[1])|(data[0]&data[1]);
|
2009-05-15 01:06:59 +00:00
|
|
|
|
2009-05-15 01:57:00 +00:00
|
|
|
if ((CSRw & 0x1)) GSCSRr |= 1; // signal
|
2009-05-15 01:06:59 +00:00
|
|
|
|
2009-05-15 01:57:00 +00:00
|
|
|
if (!(GSIMR & 0x100) ) GSirq();
|
2009-05-15 01:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void RegHandlerFINISH(const u32* data)
|
|
|
|
{
|
2009-05-15 01:57:00 +00:00
|
|
|
if ((CSRw & 0x2)) GSCSRr |= 2; // finish
|
2009-05-15 01:06:59 +00:00
|
|
|
|
2009-05-15 01:57:00 +00:00
|
|
|
if (!(GSIMR & 0x200) ) GSirq();
|
2009-05-15 01:06:59 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RegHandlerLABEL(const u32* data)
|
|
|
|
{
|
2009-05-15 01:57:00 +00:00
|
|
|
GSSIGLBLID->LBLID = (GSSIGLBLID->LBLID&~data[1])|(data[0]&data[1]);
|
2009-05-15 01:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (*GIFRegHandler)(const u32* data);
|
|
|
|
static GIFRegHandler s_GSHandlers[3] =
|
|
|
|
{
|
|
|
|
RegHandlerSIGNAL, RegHandlerFINISH, RegHandlerLABEL
|
|
|
|
};
|
|
|
|
|
|
|
|
__forceinline void GIFPath::PrepRegs()
|
|
|
|
{
|
|
|
|
if( tag.nreg == 0 )
|
|
|
|
{
|
|
|
|
u32 tempreg = tag.regs[0];
|
|
|
|
for(u32 i=0; i<16; ++i, tempreg >>= 4)
|
|
|
|
{
|
|
|
|
if( i == 8 ) tempreg = tag.regs[1];
|
|
|
|
assert( (tempreg&0xf) < 0x64 );
|
|
|
|
regs[i] = tempreg & 0xf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u32 tempreg = tag.regs[0];
|
|
|
|
for(u32 i=0; i<tag.nreg; ++i, tempreg >>= 4)
|
|
|
|
{
|
|
|
|
assert( (tempreg&0xf) < 0x64 );
|
|
|
|
regs[i] = tempreg & 0xf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GIFPath::SetTag(const void* mem)
|
|
|
|
{
|
|
|
|
tag = *((GIFTAG*)mem);
|
|
|
|
curreg = 0;
|
|
|
|
|
|
|
|
PrepRegs();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GIFPath::GetReg()
|
|
|
|
{
|
|
|
|
return regs[curreg];
|
|
|
|
}
|
|
|
|
|
2009-05-21 22:19:54 +00:00
|
|
|
__forceinline bool GIFPath::StepReg()
|
2009-05-15 01:06:59 +00:00
|
|
|
{
|
2009-05-21 22:19:54 +00:00
|
|
|
if ((++curreg & 0xf) == tag.nreg)
|
|
|
|
{
|
|
|
|
curreg = 0;
|
|
|
|
|
|
|
|
if(--tag.nloop == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline u32 _gifTransfer( GIF_PATH pathidx, const u8* pMem, u32 size )
|
|
|
|
{ GIFPath& path = m_path[pathidx];
|
2009-05-15 01:06:59 +00:00
|
|
|
|
|
|
|
while(size > 0)
|
|
|
|
{
|
|
|
|
if(path.tag.nloop == 0)
|
|
|
|
{
|
|
|
|
path.SetTag( pMem );
|
|
|
|
|
|
|
|
pMem += sizeof(GIFTAG);
|
|
|
|
--size;
|
|
|
|
|
|
|
|
if(pathidx == 2 && path.tag.eop)
|
2009-05-21 22:19:54 +00:00
|
|
|
{
|
2009-05-15 01:06:59 +00:00
|
|
|
Path3transfer = FALSE;
|
2009-05-21 22:19:54 +00:00
|
|
|
}
|
2009-05-15 01:06:59 +00:00
|
|
|
|
|
|
|
if( pathidx == 0 )
|
|
|
|
{
|
|
|
|
// hack: if too much data for VU1, just ignore.
|
|
|
|
|
|
|
|
// The GIF is evil : if nreg is 0, it's really 16. Otherwise it's the value in nreg.
|
2009-05-21 22:19:54 +00:00
|
|
|
const int numregs = ((path.tag.nreg-1)&15)+1;
|
2009-05-15 01:06:59 +00:00
|
|
|
|
|
|
|
if((path.tag.nloop * numregs) > (size * ((path.tag.flg == 1) ? 2 : 1)))
|
|
|
|
{
|
|
|
|
path.tag.nloop = 0;
|
|
|
|
return ++size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-21 22:19:54 +00:00
|
|
|
else
|
2009-05-15 01:06:59 +00:00
|
|
|
{
|
2009-05-21 22:19:54 +00:00
|
|
|
// NOTE: size > 0 => do {} while(size > 0); should be faster than while(size > 0) {}
|
|
|
|
|
2009-05-15 01:06:59 +00:00
|
|
|
switch(path.tag.flg)
|
|
|
|
{
|
|
|
|
case GIF_FLG_PACKED:
|
|
|
|
|
2009-05-21 22:19:54 +00:00
|
|
|
do
|
2009-05-15 01:06:59 +00:00
|
|
|
{
|
|
|
|
if( path.GetReg() == 0xe )
|
|
|
|
{
|
|
|
|
const int handler = pMem[8];
|
|
|
|
if(handler >= 0x60 && handler < 0x63)
|
2009-05-21 22:19:54 +00:00
|
|
|
s_GSHandlers[handler&0x3]((const u32*)pMem);
|
2009-05-15 01:06:59 +00:00
|
|
|
}
|
2009-05-21 22:19:54 +00:00
|
|
|
|
2009-05-15 01:06:59 +00:00
|
|
|
size--;
|
|
|
|
pMem += 16; // 128 bits! //sizeof(GIFPackedReg);
|
|
|
|
}
|
2009-05-21 22:19:54 +00:00
|
|
|
while(path.StepReg() && size > 0);
|
|
|
|
|
2009-05-15 01:06:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIF_FLG_REGLIST:
|
|
|
|
|
|
|
|
size *= 2;
|
|
|
|
|
2009-05-21 22:19:54 +00:00
|
|
|
do
|
2009-05-15 01:06:59 +00:00
|
|
|
{
|
|
|
|
const int handler = path.GetReg();
|
2009-05-21 22:19:54 +00:00
|
|
|
if(handler >= 0x60 && handler < 0x63)
|
2009-05-15 01:06:59 +00:00
|
|
|
s_GSHandlers[handler&0x3]((const u32*)pMem);
|
|
|
|
|
|
|
|
size--;
|
|
|
|
pMem += 8; //sizeof(GIFReg); -- 64 bits!
|
|
|
|
}
|
2009-05-21 22:19:54 +00:00
|
|
|
while(path.StepReg() && size > 0);
|
2009-05-15 01:06:59 +00:00
|
|
|
|
2009-05-21 22:19:54 +00:00
|
|
|
if(size & 1) pMem += 8; //sizeof(GIFReg);
|
|
|
|
|
2009-05-15 01:06:59 +00:00
|
|
|
size /= 2;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIF_FLG_IMAGE2: // hmmm
|
|
|
|
assert(0);
|
|
|
|
path.tag.nloop = 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIF_FLG_IMAGE:
|
|
|
|
{
|
|
|
|
int len = (int)min(size, path.tag.nloop);
|
|
|
|
|
|
|
|
pMem += len * 16;
|
|
|
|
path.tag.nloop -= len;
|
|
|
|
size -= len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
jNO_DEFAULT;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-21 22:19:54 +00:00
|
|
|
if(pathidx == 0)
|
2009-05-15 01:06:59 +00:00
|
|
|
{
|
2009-05-21 22:19:54 +00:00
|
|
|
if(path.tag.eop && path.tag.nloop == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2009-05-15 01:06:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pathidx == 0)
|
|
|
|
{
|
2009-05-21 22:19:54 +00:00
|
|
|
if(size == 0 && path.tag.nloop > 0)
|
2009-05-15 01:06:59 +00:00
|
|
|
{
|
|
|
|
path.tag.nloop = 0;
|
2009-05-21 22:19:54 +00:00
|
|
|
SysPrintf( "path1 hack! \n" );
|
2009-05-15 01:06:59 +00:00
|
|
|
|
|
|
|
// This means that the giftag data got screwly somewhere
|
|
|
|
// along the way (often means curreg was in a bad state or something)
|
|
|
|
}
|
|
|
|
}
|
2009-05-21 22:19:54 +00:00
|
|
|
|
2009-05-15 01:06:59 +00:00
|
|
|
return size;
|
|
|
|
}
|
2009-05-15 01:57:00 +00:00
|
|
|
|
|
|
|
// This currently segfaults in the beginning of KH1 if defined.
|
|
|
|
//#define DO_GIF_TRANSFERS
|
|
|
|
|
|
|
|
void _GSgifTransfer1(u32 *pMem, u32 addr)
|
|
|
|
{
|
|
|
|
#ifdef DO_GIF_TRANSFERS
|
|
|
|
/* This needs looking at, since I quickly grabbed it from ZeroGS. */
|
|
|
|
addr &= 0x3fff;
|
|
|
|
_gifTransfer( GIF_PATH_1, ((u8*)pMem+(u8)addr), (0x4000-addr)/16);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void _GSgifTransfer2(u32 *pMem, u32 size)
|
|
|
|
{
|
|
|
|
#ifdef DO_GIF_TRANSFERS
|
|
|
|
_gifTransfer( GIF_PATH_2, (u8*)pMem, size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void _GSgifTransfer3(u32 *pMem, u32 size)
|
|
|
|
{
|
|
|
|
#ifdef DO_GIF_TRANSFERS
|
|
|
|
_gifTransfer( GIF_PATH_3, (u8*)pMem, size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|