2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2009-02-09 21:15:56 +00:00
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* 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, or (at your option)
|
|
|
|
* any later version.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2010-04-25 00:31:27 +00:00
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GS.h"
|
|
|
|
#include "GSLocalMemory.h"
|
|
|
|
#include "GSDrawingContext.h"
|
|
|
|
#include "GSDrawingEnvironment.h"
|
|
|
|
#include "GSVertex.h"
|
|
|
|
#include "GSVertexList.h"
|
|
|
|
#include "GSUtil.h"
|
|
|
|
#include "GSDirtyRect.h"
|
|
|
|
#include "GSPerfMon.h"
|
|
|
|
#include "GSVector.h"
|
|
|
|
#include "GSDevice.h"
|
|
|
|
#include "GSCrc.h"
|
|
|
|
#include "GSAlignedClass.h"
|
|
|
|
#include "GSDump.h"
|
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
class GSState : public GSAlignedClass<32>
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2010-07-19 15:49:30 +00:00
|
|
|
typedef void (GSState::*GIFPackedRegHandler)(const GIFPackedReg* r);
|
2011-02-18 01:56:05 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
GIFPackedRegHandler m_fpGIFPackedRegHandlers[16];
|
|
|
|
|
2010-07-19 15:49:30 +00:00
|
|
|
void GIFPackedRegHandlerNull(const GIFPackedReg* r);
|
|
|
|
void GIFPackedRegHandlerRGBA(const GIFPackedReg* r);
|
|
|
|
void GIFPackedRegHandlerSTQ(const GIFPackedReg* r);
|
|
|
|
void GIFPackedRegHandlerUV(const GIFPackedReg* r);
|
|
|
|
void GIFPackedRegHandlerXYZF2(const GIFPackedReg* r);
|
|
|
|
void GIFPackedRegHandlerXYZ2(const GIFPackedReg* r);
|
|
|
|
void GIFPackedRegHandlerFOG(const GIFPackedReg* r);
|
|
|
|
void GIFPackedRegHandlerA_D(const GIFPackedReg* r);
|
|
|
|
void GIFPackedRegHandlerNOP(const GIFPackedReg* r);
|
|
|
|
|
|
|
|
typedef void (GSState::*GIFRegHandler)(const GIFReg* r);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
GIFRegHandler m_fpGIFRegHandlers[256];
|
|
|
|
|
2011-02-18 01:56:05 +00:00
|
|
|
void ApplyTEX0(int i, GIFRegTEX0& TEX0);
|
2010-08-17 04:38:49 +00:00
|
|
|
void ApplyPRIM(const GIFRegPRIM& PRIM);
|
2010-07-19 15:49:30 +00:00
|
|
|
|
|
|
|
void GIFRegHandlerNull(const GIFReg* r);
|
|
|
|
void GIFRegHandlerPRIM(const GIFReg* r);
|
|
|
|
void GIFRegHandlerRGBAQ(const GIFReg* r);
|
|
|
|
void GIFRegHandlerST(const GIFReg* r);
|
|
|
|
void GIFRegHandlerUV(const GIFReg* r);
|
|
|
|
void GIFRegHandlerXYZF2(const GIFReg* r);
|
|
|
|
void GIFRegHandlerXYZ2(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerTEX0(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerCLAMP(const GIFReg* r);
|
|
|
|
void GIFRegHandlerFOG(const GIFReg* r);
|
|
|
|
void GIFRegHandlerXYZF3(const GIFReg* r);
|
|
|
|
void GIFRegHandlerXYZ3(const GIFReg* r);
|
|
|
|
void GIFRegHandlerNOP(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerTEX1(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerTEX2(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerXYOFFSET(const GIFReg* r);
|
|
|
|
void GIFRegHandlerPRMODECONT(const GIFReg* r);
|
|
|
|
void GIFRegHandlerPRMODE(const GIFReg* r);
|
|
|
|
void GIFRegHandlerTEXCLUT(const GIFReg* r);
|
|
|
|
void GIFRegHandlerSCANMSK(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerMIPTBP1(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerMIPTBP2(const GIFReg* r);
|
|
|
|
void GIFRegHandlerTEXA(const GIFReg* r);
|
|
|
|
void GIFRegHandlerFOGCOL(const GIFReg* r);
|
|
|
|
void GIFRegHandlerTEXFLUSH(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerSCISSOR(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerALPHA(const GIFReg* r);
|
|
|
|
void GIFRegHandlerDIMX(const GIFReg* r);
|
|
|
|
void GIFRegHandlerDTHE(const GIFReg* r);
|
|
|
|
void GIFRegHandlerCOLCLAMP(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerTEST(const GIFReg* r);
|
|
|
|
void GIFRegHandlerPABE(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerFBA(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerFRAME(const GIFReg* r);
|
|
|
|
template<int i> void GIFRegHandlerZBUF(const GIFReg* r);
|
|
|
|
void GIFRegHandlerBITBLTBUF(const GIFReg* r);
|
|
|
|
void GIFRegHandlerTRXPOS(const GIFReg* r);
|
|
|
|
void GIFRegHandlerTRXREG(const GIFReg* r);
|
|
|
|
void GIFRegHandlerTRXDIR(const GIFReg* r);
|
|
|
|
void GIFRegHandlerHWREG(const GIFReg* r);
|
|
|
|
void GIFRegHandlerSIGNAL(const GIFReg* r);
|
|
|
|
void GIFRegHandlerFINISH(const GIFReg* r);
|
|
|
|
void GIFRegHandlerLABEL(const GIFReg* r);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
int m_version;
|
|
|
|
int m_sssize;
|
|
|
|
|
|
|
|
bool m_mt;
|
|
|
|
void (*m_irq)();
|
|
|
|
bool m_path3hack;
|
|
|
|
|
2009-04-18 09:34:25 +00:00
|
|
|
struct GSTransferBuffer
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
int x, y;
|
|
|
|
int start, end, total;
|
2009-04-18 09:34:25 +00:00
|
|
|
bool overflow;
|
2009-05-14 16:41:52 +00:00
|
|
|
uint8* buff;
|
2009-04-18 09:34:25 +00:00
|
|
|
|
|
|
|
GSTransferBuffer();
|
|
|
|
virtual ~GSTransferBuffer();
|
|
|
|
|
|
|
|
void Init(int tx, int ty);
|
|
|
|
bool Update(int tw, int th, int bpp, int& len);
|
|
|
|
|
|
|
|
} m_tr;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
void FlushWrite();
|
|
|
|
|
|
|
|
protected:
|
2010-02-19 10:37:31 +00:00
|
|
|
bool IsBadFrame(int& skip, int UserHacks_SkipDraw);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
typedef void (GSState::*VertexKickPtr)(bool skip);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
VertexKickPtr m_vk[8][2][2];
|
|
|
|
VertexKickPtr m_vkf;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-18 01:56:05 +00:00
|
|
|
#define InitVertexKick3(T, P, N, M) \
|
2011-02-19 09:05:15 +00:00
|
|
|
m_vk[P][N][M] = (VertexKickPtr)(void (T::*)(bool))&T::VertexKick<P, N, M>;
|
2011-02-18 01:56:05 +00:00
|
|
|
|
|
|
|
#define InitVertexKick2(T, P) \
|
|
|
|
InitVertexKick3(T, P, 0, 0) \
|
|
|
|
InitVertexKick3(T, P, 0, 1) \
|
|
|
|
InitVertexKick3(T, P, 1, 0) \
|
|
|
|
InitVertexKick3(T, P, 1, 1) \
|
|
|
|
|
|
|
|
#define InitVertexKick(T) \
|
|
|
|
InitVertexKick2(T, GS_POINTLIST) \
|
|
|
|
InitVertexKick2(T, GS_LINELIST) \
|
|
|
|
InitVertexKick2(T, GS_LINESTRIP) \
|
|
|
|
InitVertexKick2(T, GS_TRIANGLELIST) \
|
2011-02-18 03:50:12 +00:00
|
|
|
InitVertexKick2(T, GS_TRIANGLESTRIP) \
|
2011-02-18 01:56:05 +00:00
|
|
|
InitVertexKick2(T, GS_TRIANGLEFAN) \
|
|
|
|
InitVertexKick2(T, GS_SPRITE) \
|
|
|
|
InitVertexKick2(T, GS_INVALID) \
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
void UpdateVertexKick()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-07 01:59:05 +00:00
|
|
|
m_vkf = m_vk[PRIM->PRIM][PRIM->TME][PRIM->FST];
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
void VertexKickNull(bool skip)
|
|
|
|
{
|
|
|
|
ASSERT(0);
|
|
|
|
}
|
2010-08-17 04:38:49 +00:00
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
void VertexKick(bool skip)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-07 01:59:05 +00:00
|
|
|
(this->*m_vkf)(skip);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2010-07-11 04:38:33 +00:00
|
|
|
GIFPath m_path[4];
|
2009-03-31 03:19:21 +00:00
|
|
|
GIFRegPRIM* PRIM;
|
|
|
|
GSPrivRegSet* m_regs;
|
2009-02-09 21:15:56 +00:00
|
|
|
GSLocalMemory m_mem;
|
|
|
|
GSDrawingEnvironment m_env;
|
|
|
|
GSDrawingContext* m_context;
|
|
|
|
GSVertex m_v;
|
|
|
|
float m_q;
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 m_vprim;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
GSPerfMon m_perfmon;
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 m_crc;
|
2009-02-09 21:15:56 +00:00
|
|
|
int m_options;
|
|
|
|
int m_frameskip;
|
2009-07-16 21:36:07 +00:00
|
|
|
bool m_framelimit;
|
2009-02-09 21:15:56 +00:00
|
|
|
CRC::Game m_game;
|
|
|
|
GSDump m_dump;
|
|
|
|
|
|
|
|
public:
|
2009-09-18 19:54:56 +00:00
|
|
|
GSState();
|
2009-02-09 21:15:56 +00:00
|
|
|
virtual ~GSState();
|
|
|
|
|
|
|
|
void ResetHandlers();
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
GSVector4i GetDisplayRect(int i = -1);
|
|
|
|
GSVector4i GetFrameRect(int i = -1);
|
2009-05-20 15:35:31 +00:00
|
|
|
GSVector2i GetDeviceSize(int i = -1);
|
2009-05-14 16:41:52 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
bool IsEnabled(int i);
|
2009-05-14 16:41:52 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
int GetFPS();
|
|
|
|
|
|
|
|
virtual void Reset();
|
|
|
|
virtual void Flush();
|
|
|
|
virtual void FlushPrim() = 0;
|
|
|
|
virtual void ResetPrim() = 0;
|
2009-05-14 16:41:52 +00:00
|
|
|
virtual void InvalidateVideoMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r) {}
|
|
|
|
virtual void InvalidateLocalMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r) {}
|
2009-02-09 21:15:56 +00:00
|
|
|
virtual void InvalidateTextureCache() {}
|
|
|
|
|
|
|
|
void Move();
|
2010-07-19 15:49:30 +00:00
|
|
|
void Write(const uint8* mem, int len);
|
2009-05-14 16:41:52 +00:00
|
|
|
void Read(uint8* mem, int len);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
void SoftReset(uint32 mask);
|
|
|
|
void WriteCSR(uint32 csr) {m_regs->CSR.u32[1] = csr;}
|
|
|
|
void ReadFIFO(uint8* mem, int size);
|
2010-07-19 15:49:30 +00:00
|
|
|
template<int index> void Transfer(const uint8* mem, uint32 size);
|
2009-02-09 21:15:56 +00:00
|
|
|
int Freeze(GSFreezeData* fd, bool sizeonly);
|
|
|
|
int Defrost(const GSFreezeData* fd);
|
2009-05-14 16:41:52 +00:00
|
|
|
void GetLastTag(uint32* tag) {*tag = m_path3hack; m_path3hack = 0;}
|
|
|
|
virtual void SetGameCRC(uint32 crc, int options);
|
2009-07-16 21:36:07 +00:00
|
|
|
void SetFrameSkip(int skip);
|
2009-09-18 23:48:12 +00:00
|
|
|
void SetRegsMem(uint8* basemem);
|
2009-09-18 19:54:56 +00:00
|
|
|
void SetIrqCallback(void (*irq)());
|
2011-02-07 01:59:05 +00:00
|
|
|
void SetMultithreaded(bool mt = true);
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|