GregMiscellaneous: zzogl-pg: Add a header for HostMemory.

git-svn-id: http://pcsx2.googlecode.com/svn/branches/GregMiscellaneous@3930 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-10-17 10:03:12 +00:00
parent d114ae7e93
commit 01c171e9e7
8 changed files with 610 additions and 542 deletions

View File

@ -82,6 +82,7 @@ set(zzoglHeaders
GifTransfer.h
# glprocs.h
GS.h
HostMemory.h
Mem.h
Mem_Swizzle.h
Mem_Transmit.h

View File

@ -25,6 +25,7 @@
#include "Util.h"
#include "GifTransfer.h"
#include "HostMemory.h"
using namespace std;
@ -33,31 +34,6 @@ extern float fFPS;
#define MEMORY_END 0x00400000
extern int g_LastCRC;
extern u8* g_pBasePS2Mem;
extern u8* g_pbyGSMemory;
class GSMemory
{
public:
void init();
void destroy();
u8* get();
u8* get(u32 addr);
u8* get_raw(u32 addr);
};
extern u8* g_pbyGSClut; // the temporary clut buffer
class GSClut
{
public:
void init();
void destroy();
u8* get();
u8* get(u32 addr);
u8* get_raw(u32 addr);
};
struct Vector_16F
{

View File

@ -27,63 +27,80 @@
#include "zerogs.h"
#include "targets.h"
u8* g_pbyGSMemory = NULL; // 4Mb GS system mem
u8* g_pbyGSMemory = NULL; // 4Mb GS system mem
void GSMemory::init()
{
void GSMemory::init()
{
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);
}
}
void GSMemory::destroy()
{
void GSMemory::destroy()
{
_aligned_free(g_pbyGSMemory);
g_pbyGSMemory = NULL;
}
}
u8* GSMemory::get() { return g_pbyGSMemory; }
u8* GSMemory::get()
{
return g_pbyGSMemory;
}
u8* GSMemory::get(u32 addr) { return &g_pbyGSMemory[addr*8]; }
u8* GSMemory::get_raw(u32 addr) { return &g_pbyGSMemory[addr]; }
u8* GSMemory::get(u32 addr)
{
return &g_pbyGSMemory[addr*8];
}
u8* GSMemory::get_raw(u32 addr)
{
return &g_pbyGSMemory[addr];
}
u8* g_pbyGSClut = NULL; // ZZ
u8* g_pbyGSClut = NULL; // ZZ
void GSClut::init()
{
void GSClut::init()
{
g_pbyGSClut = (u8*)_aligned_malloc(256 * 8, 1024); // need 512 alignment!
memset(g_pbyGSClut, 0, 256*8);
}
}
void GSClut::destroy()
{
void GSClut::destroy()
{
_aligned_free(g_pbyGSClut);
g_pbyGSClut = NULL;
}
}
u8* GSClut::get() { return g_pbyGSClut; }
u8* GSClut::get()
{
return g_pbyGSClut;
}
u8* GSClut::get(u32 addr) { return &g_pbyGSClut[addr*8]; }
u8* GSClut::get_raw(u32 addr) { return &g_pbyGSClut[addr]; }
u8* GSClut::get(u32 addr)
{
return &g_pbyGSClut[addr*8];
}
u8* GSClut::get_raw(u32 addr)
{
return &g_pbyGSClut[addr];
}
extern _getPixelAddress getPixelFun[64];
extern _getPixelAddress getPixelFun[64];
extern CRangeManager s_RangeMngr; // manages overwritten memory
extern void ResolveInRange(int start, int end);
extern CRangeManager s_RangeMngr; // manages overwritten memory
extern void ResolveInRange(int start, int end);
static vector<u8> s_vTempBuffer, s_vTransferCache;
static int gs_imageEnd = 0;
static vector<u8> s_vTempBuffer, s_vTransferCache;
static int gs_imageEnd = 0;
// From the start of monster labs. In all 3 cases, psm == 0.
// ZZogl-PG: GetRectMemAddress(0x3f4000, 0x404000, 0x0, 0x0, 0x0, 0x100, 0x40, 0x3f40, 0x100);
// ZZogl-PG: GetRectMemAddress(0x3f8000, 0x408000, 0x0, 0x0, 0x0, 0x100, 0x40, 0x3f80, 0x100);
// ZZogl-PG: GetRectMemAddress(0x3fc000, 0x40c000, 0x0, 0x0, 0x0, 0x100, 0x40, 0x3fc0, 0x100);
void GetRectMemAddress(int& start, int& end, int psm, int x, int y, int w, int h, int bp, int bw)
{
void GetRectMemAddress(int& start, int& end, int psm, int x, int y, int w, int h, int bp, int bw)
{
FUNCLOG
u32 bits = 0;
@ -130,17 +147,17 @@
start /= 2;
end /= 2;
}
}
}
void InitTransferHostLocal()
{
void InitTransferHostLocal()
{
FUNCLOG
#if defined(_DEBUG)
#if defined(_DEBUG)
// Xenosaga 1.
if (gs.trxpos.dx + gs.imageWnew > gs.dstbuf.bw)
ZZLog::Debug_Log("Transfer error, width exceeded. (0x%x > 0X%x)", gs.trxpos.dx + gs.imageWnew, gs.dstbuf.bw);
#endif
#endif
//bool bHasFlushed = false;
@ -179,10 +196,10 @@
if (vb[1].nCount > 0) Flush(1);
//ZZLog::Prim_Log("trans: bp:%x x:%x y:%x w:%x h:%x\n", gs.dstbuf.bp, gs.trxpos.dx, gs.trxpos.dy, gs.imageWnew, gs.imageHnew);
}
}
void TransferHostLocal(const void* pbyMem, u32 nQWordSize)
{
void TransferHostLocal(const void* pbyMem, u32 nQWordSize)
{
FUNCLOG
int start, end;
@ -247,7 +264,7 @@
s_vTransferCache.resize(0);
}
#if defined(_DEBUG)
#if defined(_DEBUG)
if (g_bSaveTrans)
{
tex0Info t;
@ -259,18 +276,18 @@
SaveTex(&t, 0);
}
#endif
}
#endif
}
void InitTransferLocalHost()
{
void InitTransferLocalHost()
{
FUNCLOG
assert(gs.trxpos.sx + gs.imageWnew <= 2048 && gs.trxpos.sy + gs.imageHnew <= 2048);
#if defined(_DEBUG)
#if defined(_DEBUG)
if (gs.trxpos.sx + gs.imageWnew > gs.srcbuf.bw)
ZZLog::Debug_Log("Transfer error, width exceeded. (0x%x > 0x%x)", gs.trxpos.sx + gs.imageWnew, gs.srcbuf.bw);
#endif
#endif
gs.imageX = gs.trxpos.sx;
gs.imageY = gs.trxpos.sy;
@ -285,11 +302,11 @@
GetRectMemAddress(start, end, gs.srcbuf.psm, gs.trxpos.sx, gs.trxpos.sy, gs.imageWnew, gs.imageHnew, gs.srcbuf.bp, gs.srcbuf.bw);
ResolveInRange(start, end);
}
}
template <class T>
void TransferLocalHost(void* pbyMem, u32 nQWordSize, int& x, int& y, u8 *pstart)
{
template <class T>
void TransferLocalHost(void* pbyMem, u32 nQWordSize, int& x, int& y, u8 *pstart)
{
_readPixel_0 rp = readPixelFun_0[gs.srcbuf.psm];
int i = x, j = y;
@ -314,10 +331,10 @@
break;
}
}
}
}
void TransferLocalHost_24(void* pbyMem, u32 nQWordSize, int& x, int& y, u8 *pstart)
{
void TransferLocalHost_24(void* pbyMem, u32 nQWordSize, int& x, int& y, u8 *pstart)
{
_readPixel_0 rp = readPixelFun_0[gs.srcbuf.psm];
int i = x, j = y;
@ -346,11 +363,11 @@
break;
}
}
}
}
// left/right, top/down
void TransferLocalHost(void* pbyMem, u32 nQWordSize)
{
// left/right, top/down
void TransferLocalHost(void* pbyMem, u32 nQWordSize)
{
FUNCLOG
assert(gs.imageTransfer == 1);
@ -358,11 +375,21 @@
switch(PSMT_BITMODE(gs.srcbuf.psm))
{
case 0: TransferLocalHost<u32>(pbyMem, nQWordSize, gs.imageY, gs.imageX, pstart); break;
case 1: TransferLocalHost_24(pbyMem, nQWordSize, gs.imageY, gs.imageX, pstart); break;
case 2: TransferLocalHost<u16>(pbyMem, nQWordSize, gs.imageY, gs.imageX, pstart); break;
case 3: TransferLocalHost<u8>(pbyMem, nQWordSize, gs.imageY, gs.imageX, pstart); break;
default: assert(0); break;
case 0:
TransferLocalHost<u32>(pbyMem, nQWordSize, gs.imageY, gs.imageX, pstart);
break;
case 1:
TransferLocalHost_24(pbyMem, nQWordSize, gs.imageY, gs.imageX, pstart);
break;
case 2:
TransferLocalHost<u16>(pbyMem, nQWordSize, gs.imageY, gs.imageX, pstart);
break;
case 3:
TransferLocalHost<u8>(pbyMem, nQWordSize, gs.imageY, gs.imageX, pstart);
break;
default:
assert(0);
break;
}
if (gs.imageY >= gs.imageEndY)
@ -371,7 +398,7 @@
assert(gs.imageY == gs.imageEndY);
gs.imageTransfer = -1;
}
}
}
__forceinline void _TransferLocalLocal()
{
@ -462,9 +489,9 @@ __forceinline void _TransferLocalLocal_4()
}
}
// dir depends on trxpos.dirx & trxpos.diry
void TransferLocalLocal()
{
// dir depends on trxpos.dirx & trxpos.diry
void TransferLocalLocal()
{
FUNCLOG
//ZZLog::Error_Log("I'z in your code, transferring your memory...");
@ -511,7 +538,7 @@ __forceinline void _TransferLocalLocal_4()
g_MemTargs.ClearRange(dststart, dstend);
#ifdef ZEROGS_DEVBUILD
#ifdef ZEROGS_DEVBUILD
if (g_bSaveTrans)
{
@ -531,5 +558,18 @@ __forceinline void _TransferLocalLocal_4()
SaveTex(&t, 0);
}
#endif
}
#endif
}
__forceinline void TerminateLocalHost()
{
FUNCLOG
//ZZLog::Error_Log("Terminate Local Host!");
}
__forceinline void TerminateHostLocal()
{
FUNCLOG
gs.imageTransfer = -1;
}

View File

@ -0,0 +1,84 @@
/* ZZ Open GL graphics plugin
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef HOSTMEMORY_H_INCLUDED
#define HOSTMEMORY_H_INCLUDED
extern int GPU_TEXWIDTH;
extern u8* g_pBasePS2Mem;
extern u8* g_pbyGSMemory;
class GSMemory
{
public:
void init();
void destroy();
u8* get();
u8* get(u32 addr);
u8* get_raw(u32 addr);
};
extern u8* g_pbyGSClut; // the temporary clut buffer
class GSClut
{
public:
void init();
void destroy();
u8* get();
u8* get(u32 addr);
u8* get_raw(u32 addr);
};
// The size in bytes of x strings (of texture).
inline int MemorySize(int x)
{
return 4 * GPU_TEXWIDTH * x;
}
// Return the address in memory of data block for string x.
inline u8* MemoryAddress(int x)
{
return g_pbyGSMemory + MemorySize(x);
}
template <u32 mult>
inline u8* _MemoryAddress(int x)
{
return g_pbyGSMemory + mult * x;
}
extern void GetRectMemAddress(int& start, int& end, int psm, int x, int y, int w, int h, int bp, int bw);
// called when trxdir is accessed. If host is involved, transfers memory to temp buffer byTransferBuf.
// Otherwise performs the transfer. TODO: Perhaps divide the transfers into chunks?
extern void InitTransferHostLocal();
extern void TransferHostLocal(const void* pbyMem, u32 nQWordSize);
extern void InitTransferLocalHost();
extern void TransferLocalHost(void* pbyMem, u32 nQWordSize);
extern void TransferLocalLocal();
extern void TerminateLocalHost();
extern void TerminateHostLocal();
#endif // HOSTMEMORY_H_INCLUDED

View File

@ -106,6 +106,7 @@
<Unit filename="../../GifTransfer.cpp" />
<Unit filename="../../GifTransfer.h" />
<Unit filename="../../HostMemory.cpp" />
<Unit filename="../../HostMemory.h" />
<Unit filename="../Conf.cpp" />
<Unit filename="../Linux.cpp" />
<Unit filename="../Linux.h" />

View File

@ -869,7 +869,7 @@ void __gifCall GIFRegHandlerTRXDIR(const u32* data)
switch (gs.imageTransfer)
{
case 0: // host->loc
gs.imageTransfer = -1;
TerminateHostLocal();
break;
case 1: // loc->host

View File

@ -900,7 +900,7 @@ void __gifCall GIFRegHandlerTRXDIR(const u32* data)
{
case 0: // host->loc
gs.imageTransfer = -1;
TerminateHostLocal();
break;
case 1: // loc->host

View File

@ -100,42 +100,8 @@ void SetFogColor(GIFRegFOGCOL* fog);
void SaveTex(tex0Info* ptex, int usevid);
char* NamedSaveTex(tex0Info* ptex, int usevid);
// called when trxdir is accessed. If host is involved, transfers memory to temp buffer byTransferBuf.
// Otherwise performs the transfer. TODO: Perhaps divide the transfers into chunks?
void InitTransferHostLocal();
void TransferHostLocal(const void* pbyMem, u32 nQWordSize);
void InitTransferLocalHost();
void TransferLocalHost(void* pbyMem, u32 nQWordSize);
inline void TerminateLocalHost() {}
void TransferLocalLocal();
// switches the render target to the real target, flushes the current render targets and renders the real image
void RenderCRTC(int interlace);
void ResetRenderTarget(int index);
// private methods
// returns the first and last addresses aligned to a page that cover
void GetRectMemAddress(int& start, int& end, int psm, int x, int y, int w, int h, int bp, int bw);
// The size in bytes of x strings (of texture).
inline int MemorySize(int x)
{
return 4 * GPU_TEXWIDTH * x;
}
// Return the address in memory of data block for string x.
inline u8* MemoryAddress(int x)
{
return g_pbyGSMemory + MemorySize(x);
}
template <u32 mult>
inline u8* _MemoryAddress(int x)
{
return g_pbyGSMemory + mult * x;
}
#endif