2010-03-19 01:33:59 +00:00
|
|
|
/* ZeroGS KOSMOS
|
|
|
|
* Copyright (C) 2005-2006 zerofrog@gmail.com
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GifTransfer.h"
|
|
|
|
|
|
|
|
void GIFtag(pathInfo *path, u32 *data) {
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
path->tag.nloop = data[0] & 0x7fff;
|
|
|
|
path->tag.eop = (data[0] >> 15) & 0x1;
|
|
|
|
u32 tagpre = (data[1] >> 14) & 0x1;
|
|
|
|
u32 tagprim = (data[1] >> 15) & 0x7ff;
|
|
|
|
u32 tagflg = (data[1] >> 26) & 0x3;
|
|
|
|
path->tag.nreg = (data[1] >> 28)<<2;
|
|
|
|
|
|
|
|
if (path->tag.nreg == 0) path->tag.nreg = 64;
|
|
|
|
|
|
|
|
// GS_LOG("GIFtag: %8.8lx_%8.8lx_%8.8lx_%8.8lx: EOP=%d, NLOOP=%x, FLG=%x, NREG=%d, PRE=%d\n",
|
|
|
|
// data[3], data[2], data[1], data[0],
|
|
|
|
// path->tag.eop, path->tag.nloop, tagflg, path->tag.nreg, tagpre);
|
|
|
|
|
2010-04-02 05:53:14 +00:00
|
|
|
path->mode = tagflg;
|
2010-03-19 01:33:59 +00:00
|
|
|
|
2010-04-02 05:53:14 +00:00
|
|
|
switch (tagflg)
|
|
|
|
{
|
2010-03-19 01:33:59 +00:00
|
|
|
case 0x0:
|
|
|
|
path->regs = *(u64 *)(data+2);
|
|
|
|
path->regn = 0;
|
|
|
|
if (tagpre)
|
|
|
|
GIFRegHandlerPRIM((u32*)&tagprim);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1:
|
|
|
|
path->regs = *(u64 *)(data+2);
|
|
|
|
path->regn = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _GSgifPacket(pathInfo *path, u32 *pMem) { // 128bit
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
int reg = (int)((path->regs >> path->regn) & 0xf);
|
|
|
|
g_GIFPackedRegHandlers[reg](pMem);
|
|
|
|
|
|
|
|
path->regn += 4;
|
|
|
|
if (path->tag.nreg == path->regn) {
|
|
|
|
path->regn = 0;
|
|
|
|
path->tag.nloop--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _GSgifRegList(pathInfo *path, u32 *pMem) { // 64bit
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
reg = (int)((path->regs >> path->regn) & 0xf);
|
|
|
|
|
|
|
|
g_GIFRegHandlers[reg](pMem);
|
|
|
|
path->regn += 4;
|
|
|
|
if (path->tag.nreg == path->regn) {
|
|
|
|
path->regn = 0;
|
|
|
|
path->tag.nloop--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nPath3Hack = 0;
|
|
|
|
|
|
|
|
void CALLBACK GSgetLastTag(u64* ptag)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
*(u32*)ptag = nPath3Hack;
|
|
|
|
nPath3Hack = 0;
|
|
|
|
}
|
|
|
|
|
2010-03-27 01:01:31 +00:00
|
|
|
#ifdef _WIN32
|
2010-03-26 12:14:49 +00:00
|
|
|
// for debug assertion checks (thread affinity checks)
|
|
|
|
extern HANDLE g_hCurrentThread;
|
2010-03-27 01:01:31 +00:00
|
|
|
#endif
|
2010-03-26 12:14:49 +00:00
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
__forceinline void gifTransferLog(int index, u32 *pMem, u32 size)
|
2010-03-19 01:33:59 +00:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
2010-04-02 02:44:14 +00:00
|
|
|
if( conf.log & 0x20 )
|
|
|
|
{
|
|
|
|
static int nSaveIndex = 0;
|
|
|
|
GS_LOG("%d: p:%d %x\n", nSaveIndex++, index + 1, size);
|
2010-03-19 01:33:59 +00:00
|
|
|
int vals[4] = {0};
|
2010-04-02 02:44:14 +00:00
|
|
|
for(int i = 0; i < size; i++)
|
|
|
|
{
|
2010-03-19 01:33:59 +00:00
|
|
|
for(int j = 0; j < 4; ++j )
|
|
|
|
vals[j] ^= pMem[4*i+j];
|
|
|
|
}
|
|
|
|
GS_LOG("%x %x %x %x\n", vals[0], vals[1], vals[2], vals[3]);
|
|
|
|
}
|
|
|
|
#endif
|
2010-04-02 02:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int index> void _GSgifTransfer(u32 *pMem, u32 size)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
pathInfo *path = &gs.path[index];
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
assert( g_hCurrentThread == GetCurrentThread() );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
gifTransferLog(index, pMem, size);
|
|
|
|
#endif
|
2010-03-19 01:33:59 +00:00
|
|
|
|
|
|
|
while(size > 0)
|
|
|
|
{
|
|
|
|
//LOG(_T("Transfer(%08x, %d) START\n"), pMem, size);
|
|
|
|
if (path->tag.nloop == 0)
|
|
|
|
{
|
|
|
|
GIFtag(path, pMem);
|
2010-04-02 05:53:14 +00:00
|
|
|
gs.q = 1;
|
|
|
|
pMem += 4;
|
2010-03-19 01:33:59 +00:00
|
|
|
size--;
|
|
|
|
|
2010-04-02 05:53:14 +00:00
|
|
|
if ((g_GameSettings & GAME_PATH3HACK) && (index == 2) && path->tag.eop) nPath3Hack = 1;
|
2010-03-19 01:33:59 +00:00
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
if (index == 0)
|
2010-03-19 01:33:59 +00:00
|
|
|
{
|
2010-04-02 05:53:14 +00:00
|
|
|
if (path->mode == GIF_FLG_PACKED)
|
2010-03-19 01:33:59 +00:00
|
|
|
{
|
|
|
|
// check if 0xb is in any reg, if yes, exit (kh2)
|
|
|
|
for(int i = 0; i < path->tag.nreg; i += 4)
|
|
|
|
{
|
|
|
|
if (((path->regs >> i)&0xf) == 11)
|
|
|
|
{
|
|
|
|
ERROR_LOG_SPAM("Invalid unpack type\n");
|
|
|
|
path->tag.nloop = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(path->tag.nloop == 0 )
|
|
|
|
{
|
2010-04-02 02:44:14 +00:00
|
|
|
if (index == 0)
|
2010-03-19 01:33:59 +00:00
|
|
|
{
|
|
|
|
// ffx hack
|
2010-04-02 02:44:14 +00:00
|
|
|
if( path->tag.eop ) return;
|
2010-03-19 01:33:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-04-02 05:53:14 +00:00
|
|
|
/*if( !path->tag.eop )
|
2010-03-19 01:33:59 +00:00
|
|
|
{
|
|
|
|
//DEBUG_LOG("continuing from eop\n");
|
|
|
|
continue;
|
2010-04-02 05:53:14 +00:00
|
|
|
}*/
|
2010-03-19 01:33:59 +00:00
|
|
|
|
|
|
|
// Issue 174 fix!
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
switch(path->mode)
|
|
|
|
{
|
2010-04-02 05:53:14 +00:00
|
|
|
case GIF_FLG_PACKED:
|
2010-03-19 01:33:59 +00:00
|
|
|
{
|
|
|
|
assert( path->tag.nloop > 0 );
|
|
|
|
for(; size > 0; size--, pMem += 4)
|
|
|
|
{
|
|
|
|
int reg = (int)((path->regs >> path->regn) & 0xf);
|
|
|
|
|
|
|
|
g_GIFPackedRegHandlers[reg](pMem);
|
|
|
|
|
|
|
|
path->regn += 4;
|
2010-04-02 05:53:14 +00:00
|
|
|
|
2010-03-19 01:33:59 +00:00
|
|
|
if (path->tag.nreg == path->regn)
|
|
|
|
{
|
|
|
|
path->regn = 0;
|
|
|
|
if( path->tag.nloop-- <= 1 )
|
|
|
|
{
|
|
|
|
size--;
|
|
|
|
pMem += 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-04-02 05:53:14 +00:00
|
|
|
case GIF_FLG_REGLIST:
|
2010-03-19 01:33:59 +00:00
|
|
|
{
|
|
|
|
//GS_LOG("%8.8x%8.8x %d L\n", ((u32*)&gs.regs)[1], *(u32*)&gs.regs, path->tag.nreg/4);
|
|
|
|
assert( path->tag.nloop > 0 );
|
|
|
|
size *= 2;
|
2010-04-02 05:53:14 +00:00
|
|
|
|
2010-03-19 01:33:59 +00:00
|
|
|
for(; size > 0; pMem+= 2, size--)
|
|
|
|
{
|
|
|
|
int reg = (int)((path->regs >> path->regn) & 0xf);
|
2010-04-02 05:53:14 +00:00
|
|
|
|
2010-03-19 01:33:59 +00:00
|
|
|
g_GIFRegHandlers[reg](pMem);
|
2010-04-02 05:53:14 +00:00
|
|
|
|
2010-03-19 01:33:59 +00:00
|
|
|
path->regn += 4;
|
2010-04-02 05:53:14 +00:00
|
|
|
|
2010-03-19 01:33:59 +00:00
|
|
|
if (path->tag.nreg == path->regn)
|
|
|
|
{
|
|
|
|
path->regn = 0;
|
|
|
|
if( path->tag.nloop-- <= 1 )
|
|
|
|
{
|
|
|
|
size--;
|
|
|
|
pMem += 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( size & 1 ) pMem += 2;
|
|
|
|
size /= 2;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-02 05:53:14 +00:00
|
|
|
case GIF_FLG_IMAGE: // FROM_VFRAM
|
|
|
|
case GIF_FLG_IMAGE2: // Used in the DirectX version, so we'll use it here too.
|
2010-03-19 01:33:59 +00:00
|
|
|
{
|
|
|
|
if(gs.imageTransfer >= 0 && gs.imageTransfer <= 1)
|
|
|
|
{
|
|
|
|
int process = min((int)size, path->tag.nloop);
|
|
|
|
|
|
|
|
if( process > 0 )
|
|
|
|
{
|
|
|
|
if ( gs.imageTransfer )
|
|
|
|
ZeroGS::TransferLocalHost(pMem, process);
|
|
|
|
else
|
|
|
|
ZeroGS::TransferHostLocal(pMem, process*4);
|
|
|
|
|
|
|
|
path->tag.nloop -= process;
|
|
|
|
pMem += process*4; size -= process;
|
|
|
|
|
|
|
|
assert( size == 0 || path->tag.nloop == 0 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// simulate
|
|
|
|
int process = min((int)size, path->tag.nloop);
|
2010-04-02 05:53:14 +00:00
|
|
|
|
2010-03-19 01:33:59 +00:00
|
|
|
path->tag.nloop -= process;
|
2010-04-02 05:53:14 +00:00
|
|
|
pMem += process*4;
|
|
|
|
size -= process;
|
2010-03-19 01:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: // GIF_IMAGE
|
|
|
|
GS_LOG("*** WARNING **** Unexpected GIFTag flag\n");
|
|
|
|
assert(0);
|
|
|
|
path->tag.nloop = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
if ((index == 0) && path->tag.eop) return;
|
2010-03-19 01:33:59 +00:00
|
|
|
}
|
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
// This is the case when not all data was readed from one try: VU1 has too much data.
|
|
|
|
// So we should redo reading from the start.
|
|
|
|
if ((index == 0) && size == 0 && path->tag.nloop > 0)
|
|
|
|
{
|
2010-03-19 01:33:59 +00:00
|
|
|
ERROR_LOG_SPAMA("VU1 too much data, ignore if gfx are fine %d\n", path->tag.nloop)
|
2010-04-02 02:44:14 +00:00
|
|
|
// TODO: this code is not working correctly. Anyway, ringing work only in single-threaded mode.
|
|
|
|
// _GSgifTransfer(&gs.path[0], (u32*)((u8*)pMem-0x4000), (0x4000)/16);
|
2010-03-19 01:33:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK GSgifTransfer1(u32 *pMem, u32 addr)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
2010-04-02 05:53:14 +00:00
|
|
|
pathInfo *path = &gs.path[0];
|
2010-03-19 01:33:59 +00:00
|
|
|
|
|
|
|
//GS_LOG("GSgifTransfer1 0x%x (mode %d)\n", addr, path->mode);
|
|
|
|
|
|
|
|
// addr &= 0x3fff;
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
PRIM_LOG("count: %d\n", count);
|
|
|
|
count++;
|
|
|
|
#endif
|
|
|
|
|
2010-04-02 05:53:14 +00:00
|
|
|
path->tag.nloop = 0;
|
|
|
|
path->tag.eop = 0;
|
2010-04-02 02:44:14 +00:00
|
|
|
_GSgifTransfer<0>((u32*)((u8*)pMem+addr), (0x4000 - addr)/16);
|
2010-03-19 01:33:59 +00:00
|
|
|
|
2010-04-02 05:53:14 +00:00
|
|
|
if (!path->tag.eop && (path->tag.nloop > 0))
|
2010-04-02 02:44:14 +00:00
|
|
|
{
|
2010-03-19 01:33:59 +00:00
|
|
|
assert( (addr&0xf) == 0 ); //BUG
|
2010-04-02 05:53:14 +00:00
|
|
|
path->tag.nloop = 0;
|
2010-03-19 01:33:59 +00:00
|
|
|
ERROR_LOG("Transfer1 - 2\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
void CALLBACK GSgifTransfer2(u32 *pMem, u32 size)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
//GS_LOG("GSgifTransfer2 size = %lx (mode %d, gs.path2.tag.nloop = %d)\n", size, gs.path[1].mode, gs.path[1].tag.nloop);
|
|
|
|
|
|
|
|
_GSgifTransfer<1>(pMem, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK GSgifTransfer3(u32 *pMem, u32 size)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
//GS_LOG("GSgifTransfer3 size = %lx (mode %d, gs.path3.tag.nloop = %d)\n", size, gs.path[2].mode, gs.path[2].tag.nloop);
|
|
|
|
|
|
|
|
nPath3Hack = 0;
|
|
|
|
_GSgifTransfer<2>(pMem, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
static int count = 0;
|
|
|
|
#endif
|