2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2009-03-07 08:35:01 +00:00
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
#include "VideoCommon.h"
|
|
|
|
#include "XFMemory.h"
|
|
|
|
#include "CPMemory.h"
|
2010-10-03 00:41:06 +00:00
|
|
|
#include "VertexManagerBase.h"
|
2009-03-07 08:35:01 +00:00
|
|
|
#include "VertexShaderManager.h"
|
|
|
|
#include "PixelShaderManager.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "HW/Memmap.h"
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2011-02-05 18:25:34 +00:00
|
|
|
void XFMemWritten(u32 transferSize, u32 baseAddress)
|
|
|
|
{
|
|
|
|
VertexManager::Flush();
|
|
|
|
VertexShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
|
|
|
|
PixelShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XFRegWritten(int transferSize, u32 baseAddress, u32 *pData)
|
2009-03-07 08:35:01 +00:00
|
|
|
{
|
2011-02-05 18:25:34 +00:00
|
|
|
u32 address = baseAddress;
|
|
|
|
u32 dataIndex = 0;
|
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
while (transferSize > 0 && address < 0x1058)
|
|
|
|
{
|
|
|
|
u32 newValue = pData[dataIndex];
|
2011-02-05 18:25:34 +00:00
|
|
|
u32 nextAddress = address + 1;
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
switch (address)
|
|
|
|
{
|
|
|
|
case XFMEM_ERROR:
|
|
|
|
case XFMEM_DIAG:
|
|
|
|
case XFMEM_STATE0: // internal state 0
|
|
|
|
case XFMEM_STATE1: // internal state 1
|
|
|
|
case XFMEM_CLOCK:
|
2011-02-05 18:25:34 +00:00
|
|
|
case XFMEM_SETGPMETRIC:
|
|
|
|
nextAddress = 0x1007;
|
2013-03-20 01:51:12 +00:00
|
|
|
break;
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_CLIPDISABLE:
|
2011-02-05 18:25:34 +00:00
|
|
|
//if (data & 1) {} // disable clipping detection
|
|
|
|
//if (data & 2) {} // disable trivial rejection
|
|
|
|
//if (data & 4) {} // disable cpoly clipping acceleration
|
2013-03-20 01:51:12 +00:00
|
|
|
break;
|
2009-11-19 02:28:41 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_VTXSPECS: //__GXXfVtxSpecs, wrote 0004
|
|
|
|
break;
|
2011-02-05 18:25:34 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_SETNUMCHAN:
|
2011-02-05 18:25:34 +00:00
|
|
|
if (xfregs.numChan.numColorChans != (newValue & 3))
|
2013-03-20 01:51:12 +00:00
|
|
|
VertexManager::Flush();
|
|
|
|
break;
|
2011-02-05 18:25:34 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color
|
2011-02-05 18:25:34 +00:00
|
|
|
case XFMEM_SETCHAN1_AMBCOLOR:
|
2009-11-19 02:28:41 +00:00
|
|
|
{
|
2011-02-05 18:25:34 +00:00
|
|
|
u8 chan = address - XFMEM_SETCHAN0_AMBCOLOR;
|
|
|
|
if (xfregs.ambColor[chan] != newValue)
|
2009-07-26 09:52:35 +00:00
|
|
|
{
|
2011-02-05 18:25:34 +00:00
|
|
|
VertexManager::Flush();
|
|
|
|
VertexShaderManager::SetMaterialColorChanged(chan);
|
|
|
|
PixelShaderManager::SetMaterialColorChanged(chan);
|
2013-03-20 01:51:12 +00:00
|
|
|
}
|
2011-02-05 18:25:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_SETCHAN0_MATCOLOR: // Channel Material Color
|
2011-02-05 18:25:34 +00:00
|
|
|
case XFMEM_SETCHAN1_MATCOLOR:
|
|
|
|
{
|
|
|
|
u8 chan = address - XFMEM_SETCHAN0_MATCOLOR;
|
|
|
|
if (xfregs.matColor[chan] != newValue)
|
2009-07-26 09:52:35 +00:00
|
|
|
{
|
2011-02-05 18:25:34 +00:00
|
|
|
VertexManager::Flush();
|
|
|
|
VertexShaderManager::SetMaterialColorChanged(chan + 2);
|
|
|
|
PixelShaderManager::SetMaterialColorChanged(chan + 2);
|
2009-07-26 09:52:35 +00:00
|
|
|
}
|
2011-02-05 18:25:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-07-26 09:52:35 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_SETCHAN0_COLOR: // Channel Color
|
2011-02-05 18:25:34 +00:00
|
|
|
case XFMEM_SETCHAN1_COLOR:
|
|
|
|
case XFMEM_SETCHAN0_ALPHA: // Channel Alpha
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_SETCHAN1_ALPHA:
|
2011-02-05 18:25:34 +00:00
|
|
|
if (((u32*)&xfregs)[address - 0x1000] != (newValue & 0x7fff))
|
2013-03-20 01:51:12 +00:00
|
|
|
VertexManager::Flush();
|
2011-02-05 18:25:34 +00:00
|
|
|
break;
|
2009-07-26 09:52:35 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_DUALTEX:
|
2011-02-05 18:25:34 +00:00
|
|
|
if (xfregs.dualTexTrans.enabled != (newValue & 1))
|
2013-03-20 01:51:12 +00:00
|
|
|
VertexManager::Flush();
|
|
|
|
break;
|
2009-07-26 09:52:35 +00:00
|
|
|
|
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_SETMATRIXINDA:
|
|
|
|
//_assert_msg_(GX_XF, 0, "XF matrixindex0");
|
2011-02-05 18:25:34 +00:00
|
|
|
VertexShaderManager::SetTexMatrixChangedA(newValue);
|
2013-03-20 01:51:12 +00:00
|
|
|
break;
|
|
|
|
case XFMEM_SETMATRIXINDB:
|
|
|
|
//_assert_msg_(GX_XF, 0, "XF matrixindex1");
|
|
|
|
VertexShaderManager::SetTexMatrixChangedB(newValue);
|
|
|
|
break;
|
2011-02-05 18:25:34 +00:00
|
|
|
|
|
|
|
case XFMEM_SETVIEWPORT:
|
|
|
|
case XFMEM_SETVIEWPORT+1:
|
|
|
|
case XFMEM_SETVIEWPORT+2:
|
|
|
|
case XFMEM_SETVIEWPORT+3:
|
|
|
|
case XFMEM_SETVIEWPORT+4:
|
|
|
|
case XFMEM_SETVIEWPORT+5:
|
2012-11-19 20:09:31 +00:00
|
|
|
VertexManager::Flush();
|
|
|
|
VertexShaderManager::SetViewportChanged();
|
|
|
|
PixelShaderManager::SetViewportChanged();
|
2011-02-05 18:25:34 +00:00
|
|
|
|
2012-11-19 20:09:31 +00:00
|
|
|
nextAddress = XFMEM_SETVIEWPORT + 6;
|
|
|
|
break;
|
2011-02-05 18:25:34 +00:00
|
|
|
|
|
|
|
case XFMEM_SETPROJECTION:
|
|
|
|
case XFMEM_SETPROJECTION+1:
|
|
|
|
case XFMEM_SETPROJECTION+2:
|
|
|
|
case XFMEM_SETPROJECTION+3:
|
|
|
|
case XFMEM_SETPROJECTION+4:
|
|
|
|
case XFMEM_SETPROJECTION+5:
|
|
|
|
case XFMEM_SETPROJECTION+6:
|
2013-03-20 01:51:12 +00:00
|
|
|
VertexManager::Flush();
|
2012-11-19 20:09:31 +00:00
|
|
|
VertexShaderManager::SetProjectionChanged();
|
2011-02-05 18:25:34 +00:00
|
|
|
|
2012-11-19 20:09:31 +00:00
|
|
|
nextAddress = XFMEM_SETPROJECTION + 7;
|
|
|
|
break;
|
2009-07-26 09:52:35 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens
|
2011-02-05 18:25:34 +00:00
|
|
|
if (xfregs.numTexGen.numTexGens != (newValue & 15))
|
2012-11-19 20:09:31 +00:00
|
|
|
VertexManager::Flush();
|
2013-03-20 01:51:12 +00:00
|
|
|
break;
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2011-02-05 18:25:34 +00:00
|
|
|
case XFMEM_SETTEXMTXINFO:
|
|
|
|
case XFMEM_SETTEXMTXINFO+1:
|
|
|
|
case XFMEM_SETTEXMTXINFO+2:
|
|
|
|
case XFMEM_SETTEXMTXINFO+3:
|
|
|
|
case XFMEM_SETTEXMTXINFO+4:
|
|
|
|
case XFMEM_SETTEXMTXINFO+5:
|
|
|
|
case XFMEM_SETTEXMTXINFO+6:
|
|
|
|
case XFMEM_SETTEXMTXINFO+7:
|
2012-11-19 20:09:31 +00:00
|
|
|
VertexManager::Flush();
|
2011-10-01 00:36:03 +00:00
|
|
|
|
2012-11-19 20:09:31 +00:00
|
|
|
nextAddress = XFMEM_SETTEXMTXINFO + 8;
|
|
|
|
break;
|
2011-02-05 18:25:34 +00:00
|
|
|
|
|
|
|
case XFMEM_SETPOSMTXINFO:
|
|
|
|
case XFMEM_SETPOSMTXINFO+1:
|
|
|
|
case XFMEM_SETPOSMTXINFO+2:
|
|
|
|
case XFMEM_SETPOSMTXINFO+3:
|
|
|
|
case XFMEM_SETPOSMTXINFO+4:
|
|
|
|
case XFMEM_SETPOSMTXINFO+5:
|
|
|
|
case XFMEM_SETPOSMTXINFO+6:
|
|
|
|
case XFMEM_SETPOSMTXINFO+7:
|
2012-11-19 20:09:31 +00:00
|
|
|
VertexManager::Flush();
|
2011-10-01 00:36:03 +00:00
|
|
|
|
2012-11-19 20:09:31 +00:00
|
|
|
nextAddress = XFMEM_SETPOSMTXINFO + 8;
|
|
|
|
break;
|
2011-02-05 18:25:34 +00:00
|
|
|
|
|
|
|
// --------------
|
|
|
|
// Unknown Regs
|
|
|
|
// --------------
|
|
|
|
|
|
|
|
// Maybe these are for Normals?
|
|
|
|
case 0x1048: //xfregs.texcoords[0].nrmmtxinfo.hex = data; break; ??
|
2013-03-20 01:51:12 +00:00
|
|
|
case 0x1049:
|
|
|
|
case 0x104a:
|
|
|
|
case 0x104b:
|
|
|
|
case 0x104c:
|
|
|
|
case 0x104d:
|
|
|
|
case 0x104e:
|
|
|
|
case 0x104f:
|
2011-02-05 18:25:34 +00:00
|
|
|
DEBUG_LOG(VIDEO, "Possible Normal Mtx XF reg?: %x=%x\n", address, newValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1013:
|
2013-03-20 01:51:12 +00:00
|
|
|
case 0x1014:
|
|
|
|
case 0x1015:
|
|
|
|
case 0x1016:
|
|
|
|
case 0x1017:
|
2011-02-05 18:25:34 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
default:
|
|
|
|
WARN_LOG(VIDEO, "Unknown XF Reg: %x=%x\n", address, newValue);
|
|
|
|
break;
|
|
|
|
}
|
2011-02-05 18:25:34 +00:00
|
|
|
|
|
|
|
int transferred = nextAddress - address;
|
|
|
|
address = nextAddress;
|
|
|
|
|
|
|
|
transferSize -= transferred;
|
|
|
|
dataIndex += transferred;
|
2013-03-20 01:51:12 +00:00
|
|
|
}
|
2011-02-05 18:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
|
|
|
|
{
|
2013-03-20 01:51:12 +00:00
|
|
|
// do not allow writes past registers
|
|
|
|
if (baseAddress + transferSize > 0x1058)
|
|
|
|
{
|
2013-04-01 04:10:54 +00:00
|
|
|
INFO_LOG(VIDEO, "XF load exceeds address space: %x %d bytes\n", baseAddress, transferSize);
|
2011-02-05 18:25:34 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
if (baseAddress >= 0x1058)
|
|
|
|
transferSize = 0;
|
|
|
|
else
|
|
|
|
transferSize = 0x1058 - baseAddress;
|
|
|
|
}
|
2011-02-05 18:25:34 +00:00
|
|
|
|
|
|
|
// write to XF mem
|
|
|
|
if (baseAddress < 0x1000 && transferSize > 0)
|
|
|
|
{
|
|
|
|
u32 end = baseAddress + transferSize;
|
|
|
|
|
|
|
|
u32 xfMemBase = baseAddress;
|
|
|
|
u32 xfMemTransferSize = transferSize;
|
|
|
|
|
|
|
|
if (end >= 0x1000)
|
|
|
|
{
|
|
|
|
xfMemTransferSize = 0x1000 - baseAddress;
|
|
|
|
|
|
|
|
baseAddress = 0x1000;
|
|
|
|
transferSize = end - 0x1000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
transferSize = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-19 20:09:31 +00:00
|
|
|
XFMemWritten(xfMemTransferSize, xfMemBase);
|
|
|
|
memcpy_gc(&xfmem[xfMemBase], pData, xfMemTransferSize * 4);
|
2011-02-05 18:25:34 +00:00
|
|
|
|
|
|
|
pData += xfMemTransferSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// write to XF regs
|
2013-03-20 01:51:12 +00:00
|
|
|
if (transferSize > 0)
|
2011-02-05 18:25:34 +00:00
|
|
|
{
|
|
|
|
XFRegWritten(transferSize, baseAddress, pData);
|
|
|
|
memcpy_gc((u32*)(&xfregs) + (baseAddress - 0x1000), pData, transferSize * 4);
|
2013-03-20 01:51:12 +00:00
|
|
|
}
|
2009-03-07 08:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO - verify that it is correct. Seems to work, though.
|
2011-05-25 18:14:29 +00:00
|
|
|
void LoadIndexedXF(u32 val, int refarray)
|
2009-03-07 08:35:01 +00:00
|
|
|
{
|
2012-05-19 08:54:40 +00:00
|
|
|
int index = val >> 16;
|
|
|
|
int address = val & 0xFFF; // check mask
|
|
|
|
int size = ((val >> 12) & 0xF) + 1;
|
|
|
|
//load stuff from array to address in xf mem
|
2009-03-07 08:35:01 +00:00
|
|
|
|
2012-05-20 20:16:21 +00:00
|
|
|
u32* currData = (u32*)(xfmem + address);
|
2012-05-19 08:54:40 +00:00
|
|
|
u32* newData = (u32*)Memory::GetPointer(arraybases[refarray] + arraystrides[refarray] * index);
|
2012-05-20 20:16:21 +00:00
|
|
|
bool changed = false;
|
|
|
|
for (int i = 0; i < size; ++i)
|
2012-05-19 08:54:40 +00:00
|
|
|
{
|
2012-05-20 20:16:21 +00:00
|
|
|
if (currData[i] != Common::swap32(newData[i]))
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
XFMemWritten(size, address);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < size; ++i)
|
|
|
|
currData[i] = Common::swap32(newData[i]);
|
2012-05-19 08:54:40 +00:00
|
|
|
}
|
2009-03-07 08:35:01 +00:00
|
|
|
}
|