diff --git a/plugins/GSdx/GS.h b/plugins/GSdx/GS.h index f7b1276795..388af54658 100644 --- a/plugins/GSdx/GS.h +++ b/plugins/GSdx/GS.h @@ -36,30 +36,6 @@ // sps2registers.h // -enum GS_REG -{ - GS_PMODE = 0x12000000, - GS_SMODE1 = 0x12000010, - GS_SMODE2 = 0x12000020, - GS_SRFSH = 0x12000030, - GS_SYNCH1 = 0x12000040, - GS_SYNCH2 = 0x12000050, - GS_SYNCV = 0x12000060, - GS_DISPFB1 = 0x12000070, - GS_DISPLAY1 = 0x12000080, - GS_DISPFB2 = 0x12000090, - GS_DISPLAY2 = 0x120000a0, - GS_EXTBUF = 0x120000b0, - GS_EXTDATA = 0x120000c0, - GS_EXTWRITE = 0x120000d0, - GS_BGCOLOR = 0x120000e0, - GS_UNKNOWN = 0x12000400, - GS_CSR = 0x12001000, - GS_IMR = 0x12001010, - GS_BUSDIR = 0x12001040, - GS_SIGLBLID = 0x12001080 -}; - enum GS_PRIM { GS_POINTLIST = 0, @@ -340,7 +316,7 @@ REG64_(GSReg, DISPFB) // (-1/2) UINT32 DBY:11; UINT32 _PAD2:10; REG_END2 - UINT32 Block() {return FBP<<5;} + UINT32 Block() const {return FBP << 5;} REG_END2 REG64_(GSReg, DISPLAY) // (-1/2) @@ -461,6 +437,22 @@ REG64_(GSReg, SMODE2) UINT32 _PAD3:32; REG_END +REG64_(GSReg, SRFSH) + // TODO +REG_END + +REG64_(GSReg, SYNCH1) + // TODO +REG_END + +REG64_(GSReg, SYNCH2) + // TODO +REG_END + +REG64_(GSReg, SYNCV) + // TODO +REG_END + REG64_SET(GSReg) GSRegBGCOLOR BGCOLOR; GSRegBUSDIR BUSDIR; @@ -1087,6 +1079,65 @@ __declspec(align(16)) struct GIFPath } }; +struct GSPrivRegSet +{ + union + { + struct + { + GSRegPMODE PMODE; + UINT64 _pad1; + GSRegSMODE1 SMODE1; + UINT64 _pad2; + GSRegSMODE2 SMODE2; + UINT64 _pad3; + GSRegSRFSH SRFSH; + UINT64 _pad4; + GSRegSYNCH1 SYNCH1; + UINT64 _pad5; + GSRegSYNCH2 SYNCH2; + UINT64 _pad6; + GSRegSYNCV SYNCV; + UINT64 _pad7; + struct { + GSRegDISPFB DISPFB; + UINT64 _pad1; + GSRegDISPLAY DISPLAY; + UINT64 _pad2; + } DISP[2]; + GSRegEXTBUF EXTBUF; + UINT64 _pad8; + GSRegEXTDATA EXTDATA; + UINT64 _pad9; + GSRegEXTWRITE EXTWRITE; + UINT64 _pad10; + GSRegBGCOLOR BGCOLOR; + UINT64 _pad11; + }; + + BYTE _pad12[0x1000]; + }; + + union + { + struct + { + GSRegCSR CSR; + UINT64 _pad13; + GSRegIMR IMR; + UINT64 _pad14; + UINT64 _unk1[4]; + GSRegBUSDIR BUSDIR; + UINT64 _pad15; + UINT64 _unk2[6]; + GSRegSIGLBLID SIGLBLID; + UINT64 _pad16; + }; + + BYTE _pad17[0x1000]; + }; +}; + #pragma pack(pop) enum {KEYPRESS=1, KEYRELEASE=2}; diff --git a/plugins/GSdx/GSDump.cpp b/plugins/GSdx/GSDump.cpp index 8c7edf1020..70421b35db 100644 --- a/plugins/GSdx/GSDump.cpp +++ b/plugins/GSdx/GSDump.cpp @@ -36,7 +36,7 @@ GSDump::~GSDump() Close(); } -void GSDump::Open(const CString& fn, DWORD crc, const GSFreezeData& fd, const void* regs) +void GSDump::Open(const CString& fn, DWORD crc, const GSFreezeData& fd, const GSPrivRegSet* regs) { m_gs = _tfopen(fn + _T(".gs"), _T("wb")); m_obj = _tfopen(fn + _T(".obj"), _T("wt")); @@ -50,7 +50,7 @@ void GSDump::Open(const CString& fn, DWORD crc, const GSFreezeData& fd, const vo fwrite(&crc, 4, 1, m_gs); fwrite(&fd.size, 4, 1, m_gs); fwrite(fd.data, fd.size, 1, m_gs); - fwrite(regs, 0x2000, 1, m_gs); + fwrite(regs, sizeof(*regs), 1, m_gs); } } @@ -80,12 +80,12 @@ void GSDump::ReadFIFO(UINT32 size) } } -void GSDump::VSync(int field, bool last, const void* regs) +void GSDump::VSync(int field, bool last, const GSPrivRegSet* regs) { if(m_gs) { fputc(3, m_gs); - fwrite(regs, 0x2000, 1, m_gs); + fwrite(regs, sizeof(*regs), 1, m_gs); fputc(1, m_gs); fputc(field, m_gs); diff --git a/plugins/GSdx/GSDump.h b/plugins/GSdx/GSDump.h index cc60c25ca4..bfa2d0682b 100644 --- a/plugins/GSdx/GSDump.h +++ b/plugins/GSdx/GSDump.h @@ -55,11 +55,11 @@ public: GSDump(); virtual ~GSDump(); - void Open(const CString& fn, DWORD crc, const GSFreezeData& fd, const void* regs); + void Open(const CString& fn, DWORD crc, const GSFreezeData& fd, const GSPrivRegSet* regs); void Close(); void ReadFIFO(UINT32 size); void Transfer(int index, BYTE* mem, size_t size); - void VSync(int field, bool last, const void* regs); + void VSync(int field, bool last, const GSPrivRegSet* regs); void Object(GSVertexSW* vertices, int count, GS_PRIM_CLASS primclass); operator bool() {return m_gs != NULL;} }; diff --git a/plugins/GSdx/GSRenderer.h b/plugins/GSdx/GSRenderer.h index b7a9f8b568..f7a5b05df0 100644 --- a/plugins/GSdx/GSRenderer.h +++ b/plugins/GSdx/GSRenderer.h @@ -165,10 +165,15 @@ protected: // // NOTE: probably the technique explained in graphtip.pdf (Antialiasing by Supersampling / 4. Reading Odd/Even Scan Lines Separately with the PCRTC then Blending) - bool samesrc = en[0] && en[1] && DISPFB[0]->FBP == DISPFB[1]->FBP && DISPFB[0]->FBW == DISPFB[1]->FBW && DISPFB[0]->PSM == DISPFB[1]->PSM; + bool samesrc = + en[0] && en[1] && + m_regs->DISP[0].DISPFB.FBP == m_regs->DISP[1].DISPFB.FBP && + m_regs->DISP[0].DISPFB.FBW == m_regs->DISP[1].DISPFB.FBW && + m_regs->DISP[0].DISPFB.PSM == m_regs->DISP[1].DISPFB.PSM; + bool blurdetected = false; - if(samesrc && PMODE->SLBG == 0 && PMODE->MMOD == 1 && PMODE->ALP == 0x80) + if(samesrc && m_regs->PMODE.SLBG == 0 && m_regs->PMODE.MMOD == 1 && m_regs->PMODE.ALP == 0x80) { if(fr[0] == fr[1] + CRect(0, 1, 0, 0) && dr[0] == dr[1] + CRect(0, 0, 0, 1) || fr[1] == fr[0] + CRect(0, 1, 0, 0) && dr[1] == dr[0] + CRect(0, 0, 0, 1)) @@ -251,7 +256,7 @@ protected: if(dr[i].Height() > 512) // hmm { int y = GetDeviceSize(i).cy; - if(SMODE2->INT && SMODE2->FFMD) y /= 2; + if(m_regs->SMODE2.INT && m_regs->SMODE2.FFMD) y /= 2; r.bottom = r.top + y; } @@ -282,7 +287,7 @@ protected: o.y = tex[i].m_scale.y * (dr[i].top - baseline); } - if(SMODE2->INT && SMODE2->FFMD) o.y /= 2; + if(m_regs->SMODE2.INT && m_regs->SMODE2.FFMD) o.y /= 2; dst[i].x = o.x; dst[i].y = o.y; @@ -296,23 +301,23 @@ protected: ds.cx = fs.cx; ds.cy = fs.cy; - if(SMODE2->INT && SMODE2->FFMD) ds.cy *= 2; + if(m_regs->SMODE2.INT && m_regs->SMODE2.FFMD) ds.cy *= 2; - bool slbg = PMODE->SLBG; - bool mmod = PMODE->MMOD; + bool slbg = m_regs->PMODE.SLBG; + bool mmod = m_regs->PMODE.MMOD; if(tex[0] || tex[1]) { GSVector4 c; - c.r = (float)BGCOLOR->R / 255; - c.g = (float)BGCOLOR->G / 255; - c.b = (float)BGCOLOR->B / 255; - c.a = (float)PMODE->ALP / 255; + c.r = (float)m_regs->BGCOLOR.R / 255; + c.g = (float)m_regs->BGCOLOR.G / 255; + c.b = (float)m_regs->BGCOLOR.B / 255; + c.a = (float)m_regs->PMODE.ALP / 255; m_dev.Merge(tex, src, dst, fs, slbg, mmod, c); - if(SMODE2->INT && m_interlace > 0) + if(m_regs->SMODE2.INT && m_interlace > 0) { int field2 = 1 - ((m_interlace - 1) & 1); int mode = (m_interlace - 1) >> 1; @@ -340,7 +345,7 @@ protected: fd.data = new BYTE[fd.size]; Freeze(&fd, false); - m_dump.Open(m_snapshot, m_crc, fd, PMODE); + m_dump.Open(m_snapshot, m_crc, fd, m_regs); delete [] fd.data; } @@ -353,7 +358,7 @@ protected: { if(m_dump) { - m_dump.VSync(field, !(::GetAsyncKeyState(VK_CONTROL) & 0x8000), PMODE); + m_dump.VSync(field, !(::GetAsyncKeyState(VK_CONTROL) & 0x8000), m_regs); } } } @@ -481,7 +486,7 @@ public: s_stats.Format( _T("%I64d | %d x %d | %.2f fps (%d%%) | %s - %s | %s | %d/%d/%d | %d%% CPU | %.2f | %.2f"), m_perfmon.GetFrame(), GetDisplaySize().cx, GetDisplaySize().cy, fps, (int)(100.0 * fps / GetFPS()), - SMODE2->INT ? (CString(_T("Interlaced ")) + (SMODE2->FFMD ? _T("(frame)") : _T("(field)"))) : _T("Progressive"), + m_regs->SMODE2.INT ? (CString(_T("Interlaced ")) + (m_regs->SMODE2.FFMD ? _T("(frame)") : _T("(field)"))) : _T("Progressive"), GSSettingsDlg::g_interlace[m_interlace].name, GSSettingsDlg::g_aspectratio[m_aspectratio].name, (int)m_perfmon.Get(GSPerfMon::Quad), diff --git a/plugins/GSdx/GSRendererHW.h b/plugins/GSdx/GSRendererHW.h index 3fc3f346e7..2ad320f9e8 100644 --- a/plugins/GSdx/GSRendererHW.h +++ b/plugins/GSdx/GSRendererHW.h @@ -245,11 +245,13 @@ protected: bool GetOutput(int i, Texture& t) { + const GSRegDISPFB& DISPFB = m_regs->DISP[i].DISPFB; + GIFRegTEX0 TEX0; - TEX0.TBP0 = DISPFB[i]->Block(); - TEX0.TBW = DISPFB[i]->FBW; - TEX0.PSM = DISPFB[i]->PSM; + TEX0.TBP0 = DISPFB.Block(); + TEX0.TBW = DISPFB.FBW; + TEX0.PSM = DISPFB.PSM; TRACE(_T("[%d] GetOutput %d %05x (%d)\n"), (int)m_perfmon.GetFrame(), i, (int)TEX0.TBP0, (int)TEX0.PSM); diff --git a/plugins/GSdx/GSRendererSW.h b/plugins/GSdx/GSRendererSW.h index cf8fcc3383..0d47499b06 100644 --- a/plugins/GSdx/GSRendererSW.h +++ b/plugins/GSdx/GSRendererSW.h @@ -71,7 +71,15 @@ protected: bool GetOutput(int i, Texture& t) { - CRect r(0, 0, DISPFB[i]->FBW * 64, GetFrameRect(i).bottom); + const GSRegDISPFB& DISPFB = m_regs->DISP[i].DISPFB; + + GIFRegTEX0 TEX0; + + TEX0.TBP0 = DISPFB.Block(); + TEX0.TBW = DISPFB.FBW; + TEX0.PSM = DISPFB.PSM; + + CRect r(0, 0, TEX0.TBW * 64, GetFrameRect(i).bottom); // TODO: round up bottom @@ -85,12 +93,6 @@ protected: return false; } - GIFRegTEX0 TEX0; - - TEX0.TBP0 = DISPFB[i]->Block(); - TEX0.TBW = DISPFB[i]->FBW; - TEX0.PSM = DISPFB[i]->PSM; - GIFRegCLAMP CLAMP; CLAMP.WMS = CLAMP.WMT = 1; diff --git a/plugins/GSdx/GSState.cpp b/plugins/GSdx/GSState.cpp index 4dcadccdb2..6e546a9bcc 100644 --- a/plugins/GSdx/GSState.cpp +++ b/plugins/GSdx/GSState.cpp @@ -87,27 +87,9 @@ GSState::GSState(BYTE* base, bool mt, void (*irq)(), int nloophack) ASSERT(base); - PMODE = (GSRegPMODE*)(base + GS_PMODE); - SMODE1 = (GSRegSMODE1*)(base + GS_SMODE1); - SMODE2 = (GSRegSMODE2*)(base + GS_SMODE2); - // SRFSH = (GSRegPMODE*)(base + GS_SRFSH); - // SYNCH1 = (GSRegPMODE*)(base + GS_SYNCH1); - // SYNCH2 = (GSRegPMODE*)(base + GS_SYNCH2); - // SYNCV = (GSRegPMODE*)(base + GS_SYNCV); - DISPFB[0] = (GSRegDISPFB*)(base + GS_DISPFB1); - DISPFB[1] = (GSRegDISPFB*)(base + GS_DISPFB2); - DISPLAY[0] = (GSRegDISPLAY*)(base + GS_DISPLAY1); - DISPLAY[1] = (GSRegDISPLAY*)(base + GS_DISPLAY2); - EXTBUF = (GSRegEXTBUF*)(base + GS_EXTBUF); - EXTDATA = (GSRegEXTDATA*)(base + GS_EXTDATA); - EXTWRITE = (GSRegEXTWRITE*)(base + GS_EXTWRITE); - BGCOLOR = (GSRegBGCOLOR*)(base + GS_BGCOLOR); - CSR = (GSRegCSR*)(base + GS_CSR); - IMR = (GSRegIMR*)(base + GS_IMR); - BUSDIR = (GSRegBUSDIR*)(base + GS_BUSDIR); - SIGLBLID = (GSRegSIGLBLID*)(base + GS_SIGLBLID); + m_regs = (GSPrivRegSet*)(base + 0x12000000); - memset(PMODE, 0, 0x1100); + memset(m_regs, 0, sizeof(GSPrivRegSet)); PRIM = &m_env.PRIM; // CSR->rREV = 0x20; @@ -234,8 +216,8 @@ CPoint GSState::GetDisplayPos(int i) CPoint p; - p.x = DISPLAY[i]->DX / (DISPLAY[i]->MAGH + 1); - p.y = DISPLAY[i]->DY / (DISPLAY[i]->MAGV + 1); + p.x = m_regs->DISP[i].DISPLAY.DX / (m_regs->DISP[i].DISPLAY.MAGH + 1); + p.y = m_regs->DISP[i].DISPLAY.DY / (m_regs->DISP[i].DISPLAY.MAGV + 1); return p; } @@ -246,8 +228,8 @@ CSize GSState::GetDisplaySize(int i) CSize s; - s.cx = (DISPLAY[i]->DW + 1) / (DISPLAY[i]->MAGH + 1); - s.cy = (DISPLAY[i]->DH + 1) / (DISPLAY[i]->MAGV + 1); + s.cx = (m_regs->DISP[i].DISPLAY.DW + 1) / (m_regs->DISP[i].DISPLAY.MAGH + 1); + s.cy = (m_regs->DISP[i].DISPLAY.DH + 1) / (m_regs->DISP[i].DISPLAY.MAGV + 1); return s; } @@ -276,14 +258,14 @@ CPoint GSState::GetFramePos(int i) { ASSERT(i >= 0 && i < 2); - return CPoint(DISPFB[i]->DBX, DISPFB[i]->DBY); + return CPoint(m_regs->DISP[i].DISPFB.DBX, m_regs->DISP[i].DISPFB.DBY); } CSize GSState::GetFrameSize(int i) { CSize s = GetDisplaySize(i); - if(SMODE2->INT && SMODE2->FFMD && s.cy > 1) s.cy >>= 1; + if(m_regs->SMODE2.INT && m_regs->SMODE2.FFMD && s.cy > 1) s.cy >>= 1; return s; } @@ -322,7 +304,7 @@ CSize GSState::GetDeviceSize(int i) } else { - s.cy = (SMODE1->CMOD & 1) ? 512 : 448; + s.cy = (m_regs->SMODE1.CMOD & 1) ? 512 : 448; } return s; @@ -338,13 +320,13 @@ bool GSState::IsEnabled(int i) { ASSERT(i >= 0 && i < 2); - if(i == 0 && PMODE->EN1) + if(i == 0 && m_regs->PMODE.EN1) { - return DISPLAY[0]->DW || DISPLAY[0]->DH; + return m_regs->DISP[0].DISPLAY.DW || m_regs->DISP[0].DISPLAY.DH; } - else if(i == 1 && PMODE->EN2) + else if(i == 1 && m_regs->PMODE.EN2) { - return DISPLAY[1]->DW || DISPLAY[1]->DH; + return m_regs->DISP[1].DISPLAY.DW || m_regs->DISP[1].DISPLAY.DH; } return false; @@ -352,7 +334,7 @@ bool GSState::IsEnabled(int i) int GSState::GetFPS() { - return ((SMODE1->CMOD & 1) ? 50 : 60) / (SMODE2->INT ? 1 : 2); + return ((m_regs->SMODE1.CMOD & 1) ? 50 : 60) / (m_regs->SMODE2.INT ? 1 : 2); } // GIFPackedRegHandler* @@ -985,25 +967,25 @@ void GSState::GIFRegHandlerSIGNAL(GIFReg* r) { if(m_mt) return; - SIGLBLID->SIGID = (SIGLBLID->SIGID & ~r->SIGNAL.IDMSK) | (r->SIGNAL.ID & r->SIGNAL.IDMSK); + m_regs->SIGLBLID.SIGID = (m_regs->SIGLBLID.SIGID & ~r->SIGNAL.IDMSK) | (r->SIGNAL.ID & r->SIGNAL.IDMSK); - if(CSR->wSIGNAL) CSR->rSIGNAL = 1; - if(!IMR->SIGMSK && m_irq) m_irq(); + if(m_regs->CSR.wSIGNAL) m_regs->CSR.rSIGNAL = 1; + if(!m_regs->IMR.SIGMSK && m_irq) m_irq(); } void GSState::GIFRegHandlerFINISH(GIFReg* r) { if(m_mt) return; - if(CSR->wFINISH) CSR->rFINISH = 1; - if(!IMR->FINISHMSK && m_irq) m_irq(); + if(m_regs->CSR.wFINISH) m_regs->CSR.rFINISH = 1; + if(!m_regs->IMR.FINISHMSK && m_irq) m_irq(); } void GSState::GIFRegHandlerLABEL(GIFReg* r) { if(m_mt) return; - SIGLBLID->LBLID = (SIGLBLID->LBLID & ~r->LABEL.IDMSK) | (r->LABEL.ID & r->LABEL.IDMSK); + m_regs->SIGLBLID.LBLID = (m_regs->SIGLBLID.LBLID & ~r->LABEL.IDMSK) | (r->LABEL.ID & r->LABEL.IDMSK); } // diff --git a/plugins/GSdx/GSState.h b/plugins/GSdx/GSState.h index b1d805cf28..1e1915c0cc 100644 --- a/plugins/GSdx/GSState.h +++ b/plugins/GSdx/GSState.h @@ -189,22 +189,9 @@ protected: } public: - GIFRegPRIM* PRIM; - GSRegPMODE* PMODE; - GSRegSMODE1* SMODE1; - GSRegSMODE2* SMODE2; - GSRegDISPFB* DISPFB[2]; - GSRegDISPLAY* DISPLAY[2]; - GSRegEXTBUF* EXTBUF; - GSRegEXTDATA* EXTDATA; - GSRegEXTWRITE* EXTWRITE; - GSRegBGCOLOR* BGCOLOR; - GSRegCSR* CSR; - GSRegIMR* IMR; - GSRegBUSDIR* BUSDIR; - GSRegSIGLBLID* SIGLBLID; - GIFPath m_path[3]; + GIFRegPRIM* PRIM; + GSPrivRegSet* m_regs; GSLocalMemory m_mem; GSDrawingEnvironment m_env; GSDrawingContext* m_context; @@ -256,7 +243,7 @@ public: void Read(BYTE* mem, int len); void SoftReset(BYTE mask); - void WriteCSR(UINT32 csr) {CSR->ai32[1] = csr;} + void WriteCSR(UINT32 csr) {m_regs->CSR.ai32[1] = csr;} void ReadFIFO(BYTE* mem, int size); template void Transfer(BYTE* mem, UINT32 size); int Freeze(GSFreezeData* fd, bool sizeonly);