From d2ef4099fc1779f14963576955bd770a22e5c8c3 Mon Sep 17 00:00:00 2001 From: gabest11 Date: Mon, 16 Mar 2009 22:17:50 +0000 Subject: [PATCH] LilyPad: fix0red the save state reload crash (memset overflow randomly null'ed the global dm variable and other things). git-svn-id: http://pcsx2.googlecode.com/svn/trunk@799 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GSDrawScanlineCodeGenerator.cpp | 16 +-- plugins/GSdx/GSRasterizer.cpp | 104 ++++++++++--------- plugins/GSdx/GSState.cpp | 2 + plugins/LilyPad/LilyPad.cpp | 2 +- 4 files changed, 64 insertions(+), 60 deletions(-) diff --git a/plugins/GSdx/GSDrawScanlineCodeGenerator.cpp b/plugins/GSdx/GSDrawScanlineCodeGenerator.cpp index c08aaaaa10..5b0c12411c 100644 --- a/plugins/GSdx/GSDrawScanlineCodeGenerator.cpp +++ b/plugins/GSdx/GSDrawScanlineCodeGenerator.cpp @@ -373,22 +373,22 @@ void GSDrawScanlineCodeGenerator::Init(int params) if(m_sel.fb) { - if(m_sel.edge) + if(m_sel.edge || m_sel.tfx != TFX_NONE) { movaps(xmm4, xmmword[ebx + 32]); // v.t + } - cvttps2dq(xmm4, xmm4); + if(m_sel.edge) + { + pshufhw(xmm3, xmm4, _MM_SHUFFLE(2, 2, 2, 2)); + pshufd(xmm3, xmm3, _MM_SHUFFLE(3, 3, 3, 3)); + psrlw(xmm3, 9); - pshufhw(xmm4, xmm4, _MM_SHUFFLE(2, 2, 2, 2)); - pshufd(xmm4, xmm4, _MM_SHUFFLE(3, 3, 3, 3)); - - movdqa(xmmword[&m_env.temp.cov], xmm4); + movdqa(xmmword[&m_env.temp.cov], xmm3); } if(m_sel.tfx != TFX_NONE) { - movaps(xmm4, xmmword[ebx + 32]); // v.t - if(m_sel.fst) { // GSVector4i vti(vt); diff --git a/plugins/GSdx/GSRasterizer.cpp b/plugins/GSdx/GSRasterizer.cpp index 1dcea7f61c..6b0b0a61ee 100644 --- a/plugins/GSdx/GSRasterizer.cpp +++ b/plugins/GSdx/GSRasterizer.cpp @@ -478,6 +478,8 @@ void GSRasterizer::DrawTriangleSection(int top, int bottom, GSVertexSW& l, const GSVertexSW scan = l + dscan * (lrmax - l.p).xxxx(); + ASSERT(m_dsf.ssl); + m_dsf.ssl(right, left, top, scan); } } @@ -519,6 +521,8 @@ void GSRasterizer::DrawTriangleSection(int top, int bottom, GSVertexSW& l, const GSVertexSW scan = l + dscan * (lrmax - l.p).xxxx(); + ASSERT(m_dsf.ssl); + m_dsf.ssl(right, left, top, scan); } } @@ -667,28 +671,29 @@ void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GS edge += dedge * (tbmax.wwww() - edge.p.yyyy()); } + GSVector4i p = GSVector4i(edge.p.upl(dedge.p) * 0x10000); + + int x = p.extract32<0>(); + int dx = p.extract32<1>(); + if(side) { while(1) { do { - if((top % m_threads) == m_id) + int xi = x >> 16; + int xf = x & 0xffff; + + if(scissor.x <= xi && xi < scissor.z && (xi % m_threads) == m_id) { - GSVector4 p = edge.p.ceil(); - - if(((fscissor.xxxx() < p) & (p <= fscissor.zzzz())).mask() & 1) - { - GSVector4 coverage = (p - edge.p).xxxx(); + m_stats.pixels++; - edge.t = edge.t.xyxy(edge.t.uph(coverage * 0x80)); // coverage => t.w + edge.t.u32[3] = (0x10000 - xf) & 0xffff; - int x = GSVector4i(p).extract32<0>() - 1; - - m_stats.pixels++; - - m_dsf.ssle(x + 1, x, top, edge); - } + m_dsf.ssle(xi + 1, xi, top, edge); + + edge.t.u32[3] = 0; } } while(0); @@ -696,6 +701,7 @@ void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GS if(++top >= bottom) break; edge += dedge; + x += dx; } } else @@ -704,22 +710,18 @@ void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GS { do { - if((top % m_threads) == m_id) + int xi = (x >> 16) + 1; + int xf = x & 0xffff; + + if(scissor.x <= xi && xi < scissor.z && (xi % m_threads) == m_id) { - GSVector4 p = edge.p.floor(); - - if(((fscissor.xxxx() <= p) & (p < fscissor.zzzz())).mask() & 1) - { - GSVector4 coverage = (edge.p - p).xxxx(); + m_stats.pixels++; - edge.t = edge.t.xyxy(edge.t.uph(coverage * 0x80)); // coverage => t.w + edge.t.u32[3] = xf; - int x = GSVector4i(p).extract32<0>() + 1; + m_dsf.ssle(xi + 1, xi, top, edge); - m_stats.pixels++; - - m_dsf.ssle(x + 1, x, top, edge); - } + edge.t.u32[3] = 0; } } while(0); @@ -727,6 +729,7 @@ void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GS if(++top >= bottom) break; edge += dedge; + x += dx; } } } @@ -766,28 +769,29 @@ void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GS edge += dedge * (lrmax.yyyy() - edge.p.xxxx()); } + GSVector4i p = GSVector4i(edge.p.upl(dedge.p) * 0x10000); + + int y = p.extract32<2>(); + int dy = p.extract32<3>(); + if(side) { while(1) { do { - GSVector4 p = edge.p.ceil(); - - if(((fscissor.yyyy() < p) & (p <= fscissor.wwww())).mask() & 2) + int yi = y >> 16; + int yf = y & 0xffff; + + if(scissor.y <= yi && yi < scissor.w && (yi % m_threads) == m_id) { - int y = GSVector4i(p).extract32<1>() - 1; + m_stats.pixels++; - if((y % m_threads) == m_id) - { - GSVector4 coverage = (p - edge.p).yyyy(); + edge.t.u32[3] = (0x10000 - yf) & 0xffff; - edge.t = edge.t.xyxy(edge.t.uph(coverage * 0x80)); // coverage => t.w - - m_stats.pixels++; - - m_dsf.ssle(left + 1, left, y, edge); - } + m_dsf.ssle(left + 1, left, yi, edge); + + edge.t.u32[3] = 0; } } while(0); @@ -795,6 +799,7 @@ void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GS if(++left >= right) break; edge += dedge; + y += dy; } } else @@ -803,22 +808,18 @@ void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GS { do { - GSVector4 p = edge.p.floor(); - - if(((fscissor.yyyy() <= p) & (p < fscissor.wwww())).mask() & 2) + int yi = (y >> 16) + 1; + int yf = y & 0xffff; + + if(scissor.y <= yi && yi < scissor.w && (yi % m_threads) == m_id) { - int y = GSVector4i(p).extract32<1>() + 1; + m_stats.pixels++; - if((y % m_threads) == m_id) - { - GSVector4 coverage = (edge.p - p).yyyy(); + edge.t.u32[3] = yf; - edge.t = edge.t.xyxy(edge.t.uph(coverage * 0x80)); // coverage => t.w - - m_stats.pixels++; - - m_dsf.ssle(left + 1, left, y, edge); - } + m_dsf.ssle(left + 1, left, yi, edge); + + edge.t.u32[3] = 0; } } while(0); @@ -826,6 +827,7 @@ void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GS if(++left >= right) break; edge += dedge; + y += dy; } } } diff --git a/plugins/GSdx/GSState.cpp b/plugins/GSdx/GSState.cpp index 3920f19301..e3f98cb122 100644 --- a/plugins/GSdx/GSState.cpp +++ b/plugins/GSdx/GSState.cpp @@ -107,6 +107,8 @@ GSState::GSState(BYTE* base, bool mt, void (*irq)(), int nloophack) BUSDIR = (GSRegBUSDIR*)(base + GS_BUSDIR); SIGLBLID = (GSRegSIGLBLID*)(base + GS_SIGLBLID); + memset(PMODE, 0, 0x1100); + PRIM = &m_env.PRIM; // CSR->rREV = 0x20; m_env.PRMODECONT.AC = 1; diff --git a/plugins/LilyPad/LilyPad.cpp b/plugins/LilyPad/LilyPad.cpp index 70f628b172..3fc6ad00f0 100644 --- a/plugins/LilyPad/LilyPad.cpp +++ b/plugins/LilyPad/LilyPad.cpp @@ -568,7 +568,7 @@ inline void ResetVibrate(int port, int slot) { } void ResetPad(int port, int slot) { - memset(&pads[port][slot], 0, sizeof(pads[0])); + memset(&pads[port][slot], 0, sizeof(pads[0][0])); pads[port][slot].mode = MODE_DIGITAL; pads[port][slot].umask[0] = pads[port][slot].umask[1] = 0xFF; ResetVibrate(port, slot);