zzogl-pg: Work on GetRectMemAddress.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3639 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-08-14 08:15:19 +00:00
parent e4eec943de
commit 699e623998
7 changed files with 96 additions and 59 deletions

View File

@ -42,6 +42,8 @@ using namespace std;
#include <X11/extensions/xf86vmode.h>
#endif
#define MEMORY_END 0x00400000
class GLWindow
{
@ -312,6 +314,24 @@ enum PSM_value
// 16, 16S, 16Z, 16SZ -- 2, PSMT8 and 8H - 3, PSMT4, 4HL, 4HH -- 4.
inline int PSMT_BITMODE(int psm) {return (psm & 0x7);}
inline int PSMT_BITS_NUM(int psm)
{
switch (PSMT_BITMODE(psm))
{
case 4:
return 0;
case 3:
return 1;
case 2:
return 2;
default:
return 4;
}
}
// CLUT = Color look up table. Set proper color to table according CLUT table.
// Used for PSMT8, PSMT8H, PSMT4, PSMT4HH, PSMT4HL textures
inline bool PSMT_ISCLUT(int psm) { return (PSMT_BITMODE(psm) > 2);}

View File

@ -27,6 +27,8 @@
#include "zerogs.h"
#include "targets.h"
extern _getPixelAddress getPixelFun[64];
namespace ZeroGS
{
extern CRangeManager s_RangeMngr; // manages overwritten memory
@ -38,57 +40,59 @@
void GetRectMemAddress(int& start, int& end, int psm, int x, int y, int w, int h, int bp, int bw)
{
FUNCLOG
u32 bits = 0;
if (m_Blocks[psm].bpp == 0)
{
ZZLog::Error_Log("ZeroGS: Bad psm 0x%x.", psm);
start = 0;
end = 0x00400000;
end = MEMORY_END;
return;
}
if (PSMT_ISZTEX(psm) || psm == PSMCT16S)
if (PSMT_ISZTEX(psm))
{
// Somehow, I doubt this code is right. I'll have to look into it. For the moment, I'm keeping it the
// way it was. --arcum42
const BLOCK& b = m_Blocks[psm];
bw = (bw + b.width - 1) / b.width;
start = bp * 256 + ((y / b.height) * bw + (x / b.width)) * 0x2000;
end = bp * 256 + (((y + h - 1) / b.height) * bw + (x + w + b.width - 1) / b.width) * 0x2000;
return;
}
// For some reason, we have to treat these as 32 bit.
if ((psm == PSMT8H) || (psm == PSMT4HL) || (psm == PSMT4HH))
{
bits = 4;
}
else
{
bits = PSMT_BITS_NUM(psm);
}
start = getPixelFun[psm](x, y, bp, bw);
end = getPixelFun[psm](x + w - 1, y + h - 1, bp, bw) + 1;
if (bits > 0)
{
start *= bits;
end *= bits;
}
else
{
// just take the addresses
switch (psm)
{
case PSMCT32:
case PSMCT24:
case PSMT8H:
case PSMT4HL:
case PSMT4HH:
start = 4 * getPixelAddress32(x, y, bp, bw);
end = 4 * getPixelAddress32(x + w - 1, y + h - 1, bp, bw) + 4;
break;
case PSMCT16:
start = 2 * getPixelAddress16(x, y, bp, bw);
end = 2 * getPixelAddress16(x + w - 1, y + h - 1, bp, bw) + 2;
break;
case PSMT8:
start = getPixelAddress8(x, y, bp, bw);
end = getPixelAddress8(x + w - 1, y + h - 1, bp, bw) + 1;
break;
case PSMT4:
{
start = getPixelAddress4(x, y, bp, bw) / 2;
int newx = ((x + w - 1 + 31) & ~31) - 1;
int newy = ((y + h - 1 + 15) & ~15) - 1;
end = (getPixelAddress4(max(newx, x), max(newy, y), bp, bw) + 2) / 2;
break;
}
}
// This is what it used to do, which doesn't seem right.
// Keeping it for reference, in case removing it breaks anything.
//int newx = ((x + w - 1 + 31) & ~31) - 1;
//int newy = ((y + h - 1 + 15) & ~15) - 1;
//start = getPixelAddress4(x, y, bp, bw) / 2;
//end = (getPixelAddress4(max(newx, x), max(newy, y), bp, bw) + 2) / 2;
start /= 2;
end /= 2;
}
}
@ -114,6 +118,7 @@
assert(gs.imageEndX < 2048 && gs.imageEndY < 2048);
// This needs to be looked in to, since psm should *not* be 63.
// hack! viewful joe
if (gs.dstbuf.psm == 63) gs.dstbuf.psm = 0;
@ -121,11 +126,11 @@
GetRectMemAddress(start, end, gs.dstbuf.psm, gs.trxpos.dx, gs.trxpos.dy, gs.imageWnew, gs.imageHnew, gs.dstbuf.bp, gs.dstbuf.bw);
if (end > 0x00400000)
if (end > MEMORY_END)
{
ZZLog::Warn_Log("Host local out of bounds!");
//gs.imageTransfer = -1;
end = 0x00400000;
end = MEMORY_END;
}
gs_imageEnd = end;

View File

@ -302,6 +302,18 @@ _getPixelAddress_0 getPixelFun_0[64] =
NULL, NULL, getPixelAddress16SZ_0, NULL, NULL, NULL, NULL, NULL
};
_getPixelAddress getPixelFun[64] =
{
getPixelAddress32, getPixelAddress24, getPixelAddress16, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, getPixelAddress16S, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, getPixelAddress8, getPixelAddress4, NULL, NULL, NULL,
NULL, NULL, NULL, getPixelAddress8H, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, getPixelAddress4HL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, getPixelAddress4HH, NULL, NULL, NULL,
getPixelAddress32Z, getPixelAddress24Z, getPixelAddress16Z, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, getPixelAddress16SZ, NULL, NULL, NULL, NULL, NULL
};
_writePixel_0 writePixelFun_0[64] =
{
writePixel32_0, writePixel24_0, writePixel16_0, NULL, NULL, NULL, NULL, NULL,

View File

@ -47,7 +47,7 @@ extern u32 s_uTex1Data[2][2], s_uClampData[2];
int ZeroGS::Save(s8* pbydata)
{
if (pbydata == NULL)
return 40 + 0x00400000 + sizeof(gs) + 2*VBSAVELIMIT + 2*sizeof(frameInfo) + 4 + 256*4;
return 40 + MEMORY_END + sizeof(gs) + 2*VBSAVELIMIT + 2*sizeof(frameInfo) + 4 + 256*4;
s_RTs.ResolveAll();
s_DepthRTs.ResolveAll();
@ -64,8 +64,8 @@ int ZeroGS::Save(s8* pbydata)
pbydata += 4;
memcpy(pbydata, g_pbyGSMemory, 0x00400000);
pbydata += 0x00400000;
memcpy(pbydata, g_pbyGSMemory, MEMORY_END);
pbydata += MEMORY_END;
memcpy(pbydata, g_pbyGSClut, 256*4);
pbydata += 256 * 4;
@ -109,8 +109,8 @@ bool ZeroGS::Load(s8* pbydata)
savelimit = *(u32*)pbydata;
pbydata += 4;
memcpy(g_pbyGSMemory, pbydata, 0x00400000);
pbydata += 0x00400000;
memcpy(g_pbyGSMemory, pbydata, MEMORY_END);
pbydata += MEMORY_END;
memcpy(g_pbyGSClut, pbydata, 256*4);
pbydata += 256 * 4;

View File

@ -417,7 +417,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
{
case PSMCT32:
addr = getPixelAddress32(j, i, ptex->tbp0, ptex->tbw);
if (addr * 4 < 0x00400000)
if (addr * 4 < MEMORY_END)
u = readPixel32(psrc, j, i, ptex->tbp0, ptex->tbw);
else
u = 0;
@ -425,7 +425,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMCT24:
addr = getPixelAddress24(j, i, ptex->tbp0, ptex->tbw);
if (addr * 4 < 0x00400000)
if (addr * 4 < MEMORY_END)
u = readPixel24(psrc, j, i, ptex->tbp0, ptex->tbw);
else
u = 0;
@ -433,7 +433,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMCT16:
addr = getPixelAddress16(j, i, ptex->tbp0, ptex->tbw);
if (addr * 2 < 0x00400000)
if (addr * 2 < MEMORY_END)
{
u = readPixel16(psrc, j, i, ptex->tbp0, ptex->tbw);
u = RGBA16to32(u);
@ -446,7 +446,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMCT16S:
addr = getPixelAddress16(j, i, ptex->tbp0, ptex->tbw);
if (addr * 2 < 0x00400000)
if (addr * 2 < MEMORY_END)
{
u = readPixel16S(psrc, j, i, ptex->tbp0, ptex->tbw);
u = RGBA16to32(u);
@ -459,7 +459,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMT8:
addr = getPixelAddress8(j, i, ptex->tbp0, ptex->tbw);
if (addr < 0x00400000)
if (addr < MEMORY_END)
{
if (usevid)
{
@ -481,7 +481,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMT4:
addr = getPixelAddress4(j, i, ptex->tbp0, ptex->tbw);
if (addr < 2*0x00400000)
if (addr < 2*MEMORY_END)
{
if (usevid)
{
@ -504,7 +504,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMT8H:
addr = getPixelAddress8H(j, i, ptex->tbp0, ptex->tbw);
if (4*addr < 0x00400000)
if (4*addr < MEMORY_END)
{
if (usevid)
{
@ -526,7 +526,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMT4HL:
addr = getPixelAddress4HL(j, i, ptex->tbp0, ptex->tbw);
if (4*addr < 0x00400000)
if (4*addr < MEMORY_END)
{
if (usevid)
{
@ -548,7 +548,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMT4HH:
addr = getPixelAddress4HH(j, i, ptex->tbp0, ptex->tbw);
if (4*addr < 0x00400000)
if (4*addr < MEMORY_END)
{
if (usevid)
{
@ -570,7 +570,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMT32Z:
addr = getPixelAddress32Z(j, i, ptex->tbp0, ptex->tbw);
if (4*addr < 0x00400000)
if (4*addr < MEMORY_END)
u = readPixel32Z(psrc, j, i, ptex->tbp0, ptex->tbw);
else
u = 0;
@ -578,7 +578,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMT24Z:
addr = getPixelAddress24Z(j, i, ptex->tbp0, ptex->tbw);
if (4*addr < 0x00400000)
if (4*addr < MEMORY_END)
u = readPixel24Z(psrc, j, i, ptex->tbp0, ptex->tbw);
else
u = 0;
@ -586,7 +586,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMT16Z:
addr = getPixelAddress16Z(j, i, ptex->tbp0, ptex->tbw);
if (2*addr < 0x00400000)
if (2*addr < MEMORY_END)
u = readPixel16Z(psrc, j, i, ptex->tbp0, ptex->tbw);
else
u = 0;
@ -594,7 +594,7 @@ ZeroGS::SaveTex(tex0Info* ptex, int usevid)
case PSMT16SZ:
addr = getPixelAddress16SZ(j, i, ptex->tbp0, ptex->tbw);
if (2*addr < 0x00400000)
if (2*addr < MEMORY_END)
u = readPixel16SZ(psrc, j, i, ptex->tbp0, ptex->tbw);
else
u = 0;

View File

@ -1979,7 +1979,7 @@ void MemoryTarget_GetMemAddress(int& start, int& end, const tex0Info& tex0)
int nbStart, nbEnd;
GetRectMemAddress(nbStart, nbEnd, tex0.psm, 0, 0, tex0.tw, tex0.th, tex0.tbp0, tex0.tbw);
assert(nbStart < nbEnd);
nbEnd = min(nbEnd, 0x00400000);
nbEnd = min(nbEnd, MEMORY_END);
start = nbStart / (4 * GPU_TEXWIDTH);
end = (nbEnd + GPU_TEXWIDTH * 4 - 1) / (4 * GPU_TEXWIDTH);
@ -2947,7 +2947,7 @@ void FlushTransferRanges(const tex0Info* ptex)
\
Tsrc* src = (Tsrc*)(psrc); \
T* pPageOffset = (T*)g_pbyGSMemory + fbp*(256/sizeof(T)), *dst; \
int maxfbh = (0x00400000-fbp*256) / (sizeof(T) * fbw); \
int maxfbh = (MEMORY_END-fbp*256) / (sizeof(T) * fbw); \
if( maxfbh > fbh ) maxfbh = fbh; \
\
for(int i = 0; i < maxfbh; ++i) { \
@ -3092,7 +3092,7 @@ void _Resolve(const void* psrc, int fbp, int fbw, int fbh, int psm, u32 fbm, boo
Tsrc* src = (Tsrc*)(psrc); \
T* pPageOffset = (T*)g_pbyGSMemory + fbp*(256/sizeof(T)), *dst; \
int srcpitch = Pitch(fbw) * blockheight/sizeof(Tsrc); \
int maxfbh = (0x00400000-fbp*256) / (sizeof(T) * fbw); \
int maxfbh = (MEMORY_END-fbp*256) / (sizeof(T) * fbw); \
if( maxfbh > fbh ) maxfbh = fbh; \
for(i = 0; i < (maxfbh&~(blockheight-1))*X; i += blockheight) { \
/*if( smask2 && (i&1) == smask1 ) continue; */ \

View File

@ -166,7 +166,7 @@ class ZeroGSInit
public:
ZeroGSInit()
{
const u32 mem_size = 0x00400000 + 0x10000; // leave some room for out of range accesses (saves on the checks)
const u32 mem_size = MEMORY_END + 0x10000; // leave some room for out of range accesses (saves on the checks)
// clear
g_pbyGSMemory = (u8*)_aligned_malloc(mem_size, 1024);
memset(g_pbyGSMemory, 0, mem_size);