2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/HW/Memmap.h"
|
|
|
|
#include "VideoBackends/Software/Clipper.h"
|
|
|
|
#include "VideoBackends/Software/CPMemLoader.h"
|
|
|
|
#include "VideoBackends/Software/XFMemLoader.h"
|
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
void InitXFMemory()
|
|
|
|
{
|
2014-04-27 18:59:04 +00:00
|
|
|
memset(&xfmem, 0, sizeof(xfmem));
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XFWritten(u32 transferSize, u32 baseAddress)
|
|
|
|
{
|
2013-04-14 03:54:02 +00:00
|
|
|
u32 topAddress = baseAddress + transferSize;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-04-14 03:54:02 +00:00
|
|
|
if (baseAddress <= 0x1026 && topAddress >= 0x1020)
|
|
|
|
Clipper::SetViewOffset();
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-10-29 05:23:17 +00:00
|
|
|
// fix lights so invalid values don't trash the lighting computations
|
2010-06-09 01:37:08 +00:00
|
|
|
if (baseAddress <= 0x067f && topAddress >= 0x0604)
|
|
|
|
{
|
2014-04-27 18:59:04 +00:00
|
|
|
u32* x = xfmem.lights;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
// go through all lights
|
|
|
|
for (int light = 0; light < 8; light++)
|
|
|
|
{
|
|
|
|
// skip to floating point values
|
|
|
|
x += 4;
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++)
|
|
|
|
{
|
|
|
|
u32 xVal = *x;
|
|
|
|
|
|
|
|
// if the exponent is 255 then the number is inf or nan
|
|
|
|
if ((xVal & 0x7f800000) == 0x7f800000)
|
|
|
|
*x = 0;
|
|
|
|
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-03 19:55:30 +00:00
|
|
|
void SWLoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2013-04-14 03:54:02 +00:00
|
|
|
// do not allow writes past registers
|
|
|
|
if (baseAddress + transferSize > 0x1058)
|
|
|
|
{
|
2014-04-16 21:51:18 +00:00
|
|
|
INFO_LOG(VIDEO, "XF load exceeds address space: %x %d bytes", baseAddress, transferSize);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2013-04-14 03:54:02 +00:00
|
|
|
if (baseAddress >= 0x1058)
|
2014-04-16 21:51:18 +00:00
|
|
|
transferSize = 0;
|
2013-04-14 03:54:02 +00:00
|
|
|
else
|
2014-04-16 21:51:18 +00:00
|
|
|
transferSize = 0x1058 - baseAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
// write to XF regs
|
|
|
|
if (transferSize > 0)
|
2013-04-14 03:54:02 +00:00
|
|
|
{
|
2014-05-15 09:19:39 +00:00
|
|
|
memcpy((u32*)(&xfmem) + baseAddress, pData, transferSize * 4);
|
2013-04-14 03:54:02 +00:00
|
|
|
XFWritten(transferSize, baseAddress);
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 19:55:30 +00:00
|
|
|
void SWLoadIndexedXF(u32 val, int array)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2013-04-14 03:54:02 +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
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
u32 *pData = (u32*)Memory::GetPointer(arraybases[array] + arraystrides[array]*index);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2010-12-02 05:38:48 +00:00
|
|
|
// byteswap data
|
|
|
|
u32 buffer[16];
|
|
|
|
for (int i = 0; i < size; ++i)
|
|
|
|
buffer[i] = Common::swap32(*(pData + i));
|
|
|
|
|
2011-02-03 19:55:30 +00:00
|
|
|
SWLoadXFReg(size, address, buffer);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|