diff --git a/tools/GSDumpGUI/GSDumpGUI.csproj b/tools/GSDumpGUI/GSDumpGUI.csproj index f2a833b17c..241b609c60 100644 --- a/tools/GSDumpGUI/GSDumpGUI.csproj +++ b/tools/GSDumpGUI/GSDumpGUI.csproj @@ -56,15 +56,17 @@ frmMain.cs + + + - - + diff --git a/tools/GSDumpGUI/Library/GSDXWrapper.cs b/tools/GSDumpGUI/Library/GSDXWrapper.cs index 28300decfc..b7e17af236 100644 --- a/tools/GSDumpGUI/Library/GSDXWrapper.cs +++ b/tools/GSDumpGUI/Library/GSDXWrapper.cs @@ -415,51 +415,7 @@ namespace GSDumpGUI val += "regs~"; foreach (var itm in tag.regs) { - if (itm.GetType().IsSubclassOf(typeof(GIFReg))) - { - if (itm.GetType() == typeof(GIFRegPrim)) - { - GIFRegPrim p = (GIFRegPrim)itm; - val += "Packed Primitive@Primitive Type : " + p.PrimitiveType.ToString() + "@IIP : " + p.IIP.ToString() + "@TME : " + p.TME.ToString() + "@FGE : " + p.FGE.ToString() - + "@ABE : " + p.ABE.ToString() + "@AA1 : " + p.AA1.ToString() + "@FST : " + p.FST.ToString() + "@CTXT : " + p.CTXT.ToString() + "@FIX : " + p.FIX.ToString() + "~"; - } - if (itm.GetType() == typeof(GIFRegRGBAQ)) - { - GIFRegRGBAQ p = (GIFRegRGBAQ)itm; - val += "Packed RGBAQ@Red : " + p.R.ToString() + "@Green : " + p.G.ToString() + "@Blue : " + p.B.ToString() + "@Alpha : " + p.A.ToString() + "~"; - } - if (itm.GetType() == typeof(GIFRegST)) - { - GIFRegST p = (GIFRegST)itm; - val += "Packed ST@S : " + p.S.ToString("F8") + "@T : " + p.T.ToString("F8") + "@Q : " + p.Q.ToString("F8") + "~"; - } - if (itm.GetType() == typeof(GIFRegUV)) - { - GIFRegUV p = (GIFRegUV)itm; - val += "Packed UV@U : " + p.U.ToString("F4") + "@V : " + p.V.ToString("F4") + "~"; - } - if (itm.GetType() == typeof(GIFRegXYZF)) - { - GIFRegXYZF p = (GIFRegXYZF)itm; - val += "Packed XYZF@X : " + p.X.ToString("F4") + "@Y : " + p.Y.ToString("F4") + "@Z : " + p.Z.ToString() + "@F : " + p.F.ToString() + "@ADC : " + p.ADC.ToString() + "~"; - } - if (itm.GetType() == typeof(GIFRegXYZ)) - { - GIFRegXYZ p = (GIFRegXYZ)itm; - val += "Packed XYZ@X : " + p.X.ToString("F4") + "@Y : " + p.Y.ToString("F4") + "@Z : " + p.Z.ToString() + "@ADC : " + p.ADC.ToString() + "~"; - } - if (itm.GetType() == typeof(GIFRegTEX0)) - { - GIFRegTEX0 p = (GIFRegTEX0)itm; - val += "Packed TEX0@TBP0 : " + p.TBP0.ToString() + "@TBW : " + p.TBW.ToString() + "@PSM : " + p.PSM.ToString() + "@TW : " + p.TW.ToString() + "@TH : " + p.TH.ToString() - + "@TCC : " + p.TCC.ToString() + "@TFX : " + p.TFX.ToString() + "@CBP : " + p.CBP.ToString() + "@CPSM : " + p.CPSM.ToString() + "@CSM : " + p.CSM.ToString() - + "@CSA : " + p.CSA.ToString() + "@CLD : " + p.CLD.ToString() + "~"; - } - } - else - { - - } + val += itm.ToString() + "~"; } break; case GSType.VSync: diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFReg.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFReg.cs index 153792423c..a847d6dea2 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFReg.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFReg.cs @@ -10,7 +10,12 @@ namespace GSDumpGUI static public UInt64 GetBit(UInt64 value, byte lower, byte count) { - return (value >> lower) & (ulong)((Math.Pow(2, count)) - 1); + return (value >> lower) & (ulong)((1 << count) - 1); + } + + public override string ToString() + { + return Descriptor.ToString(); } } @@ -27,11 +32,51 @@ namespace GSDumpGUI CLAMP_1 = 0x08, CLAMP_2 = 0x09, FOG = 0x0a, - Reserved = 0x0b, XYZF3 = 0x0c, XYZ3 = 0x0d, AD = 0x0e, - NOP = 0x0f + NOP = 0x0f, // actually, 0xf is the standard GIF NOP and 0x7f is the standard GS NOP, but all unregistered addresses act as NOPs... probably + TEX1_1 = 0x14, + TEX1_2 = 0x15, + TEX2_1 = 0x16, + TEX2_2 = 0x17, + XYOFFSET_1 = 0x18, + XYOFFSET_2 = 0x19, + PRMODECONT = 0x1a, + PRMODE = 0x1b, + TEXCLUT = 0x1c, + SCANMSK = 0x22, + MIPTBP1_1 = 0x34, + MIPTBP1_2 = 0x35, + MIPTBP2_1 = 0x36, + MIPTBP2_2 = 0x37, + TEXA = 0x3b, + FOGCOL = 0x3d, + TEXFLUSH = 0x3f, + SCISSOR_1 = 0x40, + SCISSOR_2 = 0x41, + ALPHA_1 = 0x42, + ALPHA_2 = 0x43, + DIMX = 0x44, + DTHE = 0x45, + COLCLAMP = 0x46, + TEST_1 = 0x47, + TEST_2 = 0x48, + PABE = 0x49, + FBA_1 = 0x4a, + FBA_2 = 0x4b, + FRAME_1 = 0x4c, + FRAME_2 = 0x4d, + ZBUF_1 = 0x4e, + ZBUF_2 = 0x4f, + BITBLTBUF = 0x50, + TRXPOS = 0x51, + TRXREG = 0x52, + TRXDIR = 0x53, + HWREG = 0x54, + SIGNAL = 0x60, + FINISH = 0x61, + LABEL = 0x62, } } diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegAD.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegAD.cs new file mode 100644 index 0000000000..054743f7ac --- /dev/null +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegAD.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace GSDumpGUI +{ + public class GIFRegAD : GIFReg + { + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) + { + int reg = (int)GetBit(HighData, 0, 8); + if (reg == (int)GIFRegDescriptor.AD) + return GIFRegNOP.Unpack(tag, reg, LowData, HighData, PackedFormat); + return GIFTag.GetUnpack(reg)(tag, reg, LowData, 0, false); + } + } +} diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegFOG.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegFOG.cs index c2c8f3da73..78dcaa6565 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegFOG.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegFOG.cs @@ -8,11 +8,14 @@ namespace GSDumpGUI { public double F; - static public GIFReg Unpack(UInt64 LowData, UInt64 HighData, bool PlainFormat) + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) { GIFRegFOG u = new GIFRegFOG(); - u.Descriptor = GIFRegDescriptor.FOG; - u.F = (UInt16)(GIFReg.GetBit(HighData, 36, 8)); + u.Descriptor = (GIFRegDescriptor)addr; + if (PackedFormat) + u.F = (UInt16)(GetBit(HighData, 36, 8)); + else + u.F = GetBit(LowData, 56, 8); return u; } } diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegNOP.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegNOP.cs new file mode 100644 index 0000000000..53af7b5790 --- /dev/null +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegNOP.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace GSDumpGUI +{ + public class GIFRegNOP : GIFReg + { + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) + { + GIFRegNOP nop = new GIFRegNOP(); + nop.Descriptor = GIFRegDescriptor.NOP; + return nop; + } + } +} diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegPrim.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegPrim.cs index 6b937a660f..f1e041ad67 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegPrim.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegPrim.cs @@ -4,7 +4,7 @@ using System.Text; namespace GSDumpGUI { - public class GIFRegPrim : GIFReg + public class GIFRegPRIM : GIFReg { public GS_PRIM PrimitiveType; public GSIIP IIP; @@ -16,21 +16,27 @@ namespace GSDumpGUI public GSCTXT CTXT; public GSFIX FIX; - static public GIFReg Unpack(UInt64 LowData, UInt64 HighData, bool PlainFormat) + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) { - GIFRegPrim pr = new GIFRegPrim(); - pr.Descriptor = GIFRegDescriptor.PRIM; - pr.PrimitiveType = (GS_PRIM)GIFReg.GetBit(LowData, 0, 3); - pr.IIP = (GSIIP)GIFReg.GetBit(LowData, 3, 1); - pr.TME = Convert.ToBoolean(GIFReg.GetBit(LowData, 4, 1)); - pr.FGE = Convert.ToBoolean(GIFReg.GetBit(LowData, 5, 1)); - pr.ABE = Convert.ToBoolean(GIFReg.GetBit(LowData, 6, 1)); - pr.AA1 = Convert.ToBoolean(GIFReg.GetBit(LowData, 7, 1)); - pr.FST = (GSFST)(GIFReg.GetBit(LowData, 8, 1)); - pr.CTXT = (GSCTXT)(GIFReg.GetBit(LowData, 9, 1)); - pr.FIX = (GSFIX)(GIFReg.GetBit(LowData, 10, 1)); + GIFRegPRIM pr = new GIFRegPRIM(); + pr.Descriptor = (GIFRegDescriptor)addr; + pr.PrimitiveType = (GS_PRIM)GetBit(LowData, 0, 3); + pr.IIP = (GSIIP)GetBit(LowData, 3, 1); + pr.TME = Convert.ToBoolean(GetBit(LowData, 4, 1)); + pr.FGE = Convert.ToBoolean(GetBit(LowData, 5, 1)); + pr.ABE = Convert.ToBoolean(GetBit(LowData, 6, 1)); + pr.AA1 = Convert.ToBoolean(GetBit(LowData, 7, 1)); + pr.FST = (GSFST)(GetBit(LowData, 8, 1)); + pr.CTXT = (GSCTXT)(GetBit(LowData, 9, 1)); + pr.FIX = (GSFIX)(GetBit(LowData, 10, 1)); return pr; } + + public override string ToString() + { + return Descriptor.ToString() + "@Primitive Type : " + PrimitiveType.ToString() + "@IIP : " + IIP.ToString() + "@TME : " + TME.ToString() + "@FGE : " + FGE.ToString() + + "@ABE : " + ABE.ToString() + "@AA1 : " + AA1.ToString() + "@FST : " + FST.ToString() + "@CTXT : " + CTXT.ToString() + "@FIX : " + FIX.ToString(); + } } public enum GSIIP diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegRGBAQ.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegRGBAQ.cs index 8913948623..cc2939b899 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegRGBAQ.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegRGBAQ.cs @@ -10,16 +10,34 @@ namespace GSDumpGUI public int G; public int B; public int A; + public float Q; - static public GIFReg Unpack(UInt64 LowData, UInt64 HighData, bool PlainFormat) + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) { GIFRegRGBAQ r = new GIFRegRGBAQ(); - r.Descriptor = GIFRegDescriptor.RGBAQ; - r.R = (int)GIFReg.GetBit(LowData, 0, 8); - r.G = (int)GIFReg.GetBit(LowData, 32, 8); - r.B = (int)GIFReg.GetBit(HighData, 0, 8); - r.A = (int)GIFReg.GetBit(HighData, 32, 8); + r.Descriptor = (GIFRegDescriptor)addr; + if (PackedFormat) + { + r.R = (int)GetBit(LowData, 0, 8); + r.G = (int)GetBit(LowData, 32, 8); + r.B = (int)GetBit(HighData, 0, 8); + r.A = (int)GetBit(HighData, 32, 8); + r.Q = tag.Q; + } + else + { + r.R = (int)GetBit(LowData, 0, 8); + r.G = (int)GetBit(LowData, 8, 8); + r.B = (int)GetBit(LowData, 16, 8); + r.A = (int)GetBit(LowData, 24, 8); + r.Q = BitConverter.ToSingle(BitConverter.GetBytes(LowData), 4); + } return r; } + + public override string ToString() + { + return Descriptor.ToString() + "@Red : " + R.ToString() + "@Green : " + G.ToString() + "@Blue : " + B.ToString() + "@Alpha : " + A.ToString(); + } } } diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegST.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegST.cs index b9bcec8803..2610a027f7 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegST.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegST.cs @@ -10,26 +10,30 @@ namespace GSDumpGUI public float T; public float Q; - static public GIFReg Unpack(UInt64 LowData, UInt64 HighData, bool PlainFormat) + public bool isSTQ; + + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) { - unsafe + GIFRegST st = new GIFRegST(); + st.Descriptor = (GIFRegDescriptor)addr; + + st.S = BitConverter.ToSingle(BitConverter.GetBytes(LowData), 0); + st.T = BitConverter.ToSingle(BitConverter.GetBytes(LowData), 4); + if (PackedFormat) { - GIFRegST st = new GIFRegST(); - st.Descriptor = GIFRegDescriptor.ST; - - ulong pt = GIFReg.GetBit(LowData, 0, 32); - void* ptt = &pt; - st.S = *(float*)ptt; - - pt = GIFReg.GetBit(LowData, 32, 32); - ptt = &pt; - st.T = *(float*)ptt; - - pt = GIFReg.GetBit(HighData, 0, 32); - ptt = &pt; - st.Q = *(float*)ptt; - return st; + st.Q = BitConverter.ToSingle(BitConverter.GetBytes(HighData), 0); + tag.Q = st.Q; + st.isSTQ = true; } + else + st.isSTQ = false; + + return st; + } + + public override string ToString() + { + return Descriptor.ToString() + "@S : " + S.ToString("F8") + "@T : " + T.ToString("F8") + (isSTQ ? "@Q : " + Q.ToString("F8") : ""); } } } diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegTEX0.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegTEX0.cs index 5441429d25..1baf8ced10 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegTEX0.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegTEX0.cs @@ -19,23 +19,30 @@ namespace GSDumpGUI public int CSA; public int CLD; - static public GIFReg Unpack(UInt64 LowData, UInt64 HighData, bool PlainFormat) + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) { - GIFRegTEX0 r = new GIFRegTEX0(); - r.Descriptor = GIFRegDescriptor.TEX0_1; - r.TBP0 = (int)GetBit(LowData, 0, 14); - r.TBW = (int)GetBit(LowData, 14, 6); - r.PSM = (TEXPSM)(int)GetBit(LowData, 20, 6); - r.TW = (int)GetBit(LowData, 26, 4); - r.TH = (int)GetBit(LowData, 30, 4); - r.TCC = (TEXTCC)(int)GetBit(LowData, 34, 1); - r.TFX = (TEXTFX)(int)GetBit(LowData, 35, 2); - r.CBP = (int)GetBit(LowData, 37, 14); - r.CPSM = (TEXCPSM)(int)GetBit(LowData, 51, 4); - r.CSM = (TEXCSM)(int)GetBit(LowData, 55, 1); - r.CSA = (int)GetBit(LowData, 56, 5); - r.CLD = (int)GetBit(LowData, 61, 3); - return r; + GIFRegTEX0 tex0 = new GIFRegTEX0(); + tex0.Descriptor = (GIFRegDescriptor)addr; + tex0.TBP0 = (int)GetBit(LowData, 0, 14); + tex0.TBW = (int)GetBit(LowData, 14, 6); + tex0.PSM = (TEXPSM)(int)GetBit(LowData, 20, 6); + tex0.TW = (int)GetBit(LowData, 26, 4); + tex0.TH = (int)GetBit(LowData, 30, 4); + tex0.TCC = (TEXTCC)(int)GetBit(LowData, 34, 1); + tex0.TFX = (TEXTFX)(int)GetBit(LowData, 35, 2); + tex0.CBP = (int)GetBit(LowData, 37, 14); + tex0.CPSM = (TEXCPSM)(int)GetBit(LowData, 51, 4); + tex0.CSM = (TEXCSM)(int)GetBit(LowData, 55, 1); + tex0.CSA = (int)GetBit(LowData, 56, 5); + tex0.CLD = (int)GetBit(LowData, 61, 3); + return tex0; + } + + public override string ToString() + { + return Descriptor.ToString() + "@TBP0 : " + TBP0.ToString() + "@TBW : " + TBW.ToString() + "@PSM : " + PSM.ToString() + "@TW : " + TW.ToString() + "@TH : " + TH.ToString() + + "@TCC : " + TCC.ToString() + "@TFX : " + TFX.ToString() + "@CBP : " + CBP.ToString() + "@CPSM : " + CPSM.ToString() + "@CSM : " + CSM.ToString() + + "@CSA : " + CSA.ToString() + "@CLD : " + CLD.ToString(); } } diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegUV.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegUV.cs index 65b51dcfd8..469bec35c8 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegUV.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegUV.cs @@ -9,13 +9,26 @@ namespace GSDumpGUI public double U; public double V; - static public GIFReg Unpack(UInt64 LowData, UInt64 HighData, bool PlainFormat) + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) { - GIFRegUV u = new GIFRegUV(); - u.Descriptor = GIFRegDescriptor.UV; - u.U = GIFReg.GetBit(LowData, 0, 14) / 16d; - u.V = GIFReg.GetBit(LowData, 32, 14) / 16d; - return u; + GIFRegUV uv = new GIFRegUV(); + uv.Descriptor = (GIFRegDescriptor)addr; + if (PackedFormat) + { + uv.U = GetBit(LowData, 0, 14) / 16d; + uv.V = GetBit(LowData, 32, 14) / 16d; + } + else + { + uv.U = GetBit(LowData, 0, 14) / 16d; + uv.V = GetBit(LowData, 16, 14) / 16d; + } + return uv; + } + + public override string ToString() + { + return Descriptor.ToString() + "@U : " + U.ToString("F4") + "@V : " + V.ToString("F4"); } } } diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegUnimpl.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegUnimpl.cs new file mode 100644 index 0000000000..2171bdaeb0 --- /dev/null +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegUnimpl.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace GSDumpGUI +{ + public class GIFRegUnimpl : GIFReg + { + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) + { + GIFRegUnimpl u = new GIFRegUnimpl(); + u.Descriptor = (GIFRegDescriptor)addr; + return u; + } + } +} diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegXYZ.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegXYZ.cs deleted file mode 100644 index d228c47b3d..0000000000 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegXYZ.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace GSDumpGUI -{ - public class GIFRegXYZ : GIFReg - { - public double X; - public double Y; - public UInt32 Z; - public bool ADC; - - static public GIFReg Unpack(UInt64 LowData, UInt64 HighData, bool PlainFormat) - { - GIFRegXYZ xf = new GIFRegXYZ(); - xf.ADC = GIFReg.GetBit(HighData, 47, 1) == 1; - xf.Descriptor = (xf.ADC == true ? GIFRegDescriptor.XYZ3 : GIFRegDescriptor.XYZ2); - xf.X = GIFReg.GetBit(LowData, 0, 16) / 16d; - xf.Y = GIFReg.GetBit(LowData, 32, 16) / 16d; - xf.Z = (UInt32)(GIFReg.GetBit(HighData, 4, 24)); - return xf; - } - } -} diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegXYZF.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegXYZF.cs index cafca3d1a3..8c86ddc299 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegXYZF.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GIFRegXYZF.cs @@ -10,18 +10,64 @@ namespace GSDumpGUI public double Y; public UInt32 Z; public UInt16 F; - public bool ADC; - static public GIFReg Unpack(UInt64 LowData, UInt64 HighData, bool PlainFormat) + public bool IsXYZF; + + static public GIFReg UnpackXYZ(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) { - GIFRegXYZF xf2 = new GIFRegXYZF(); - xf2.ADC = GIFReg.GetBit(HighData, 47, 1) == 1; - xf2.Descriptor = (xf2.ADC == true ? GIFRegDescriptor.XYZF3 : GIFRegDescriptor.XYZF2); - xf2.X = GIFReg.GetBit(LowData, 0, 16) / 16d; - xf2.Y = GIFReg.GetBit(LowData, 32, 16) / 16d; - xf2.Z = (UInt32)(GIFReg.GetBit(HighData, 4, 24)); - xf2.F = (UInt16)(GIFReg.GetBit(HighData, 36, 8)); - return xf2; + GIFRegXYZF xyzf = new GIFRegXYZF(); + + xyzf.IsXYZF = false; + if (PackedFormat && addr == (int)GIFRegDescriptor.XYZ2 && GetBit(HighData, 47, 1) == 1) + xyzf.Descriptor = GIFRegDescriptor.XYZ3; + else + xyzf.Descriptor = (GIFRegDescriptor)addr; + + if (PackedFormat) + { + xyzf.X = GetBit(LowData, 0, 16) / 16d; + xyzf.Y = GetBit(LowData, 32, 16) / 16d; + xyzf.Z = (UInt32)(GetBit(HighData, 0, 32)); + } + else + { + xyzf.X = GetBit(LowData, 0, 16) / 16d; + xyzf.Y = GetBit(LowData, 16, 16) / 16d; + xyzf.Z = (UInt32)(GetBit(LowData, 32, 32)); + } + return xyzf; + } + + static public GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat) + { + GIFRegXYZF xyzf = new GIFRegXYZF(); + + xyzf.IsXYZF = true; + if (PackedFormat && addr == (int)GIFRegDescriptor.XYZF2 && GetBit(HighData, 47, 1) == 1) + xyzf.Descriptor = GIFRegDescriptor.XYZF3; + else + xyzf.Descriptor = (GIFRegDescriptor)addr; + + if (PackedFormat) + { + xyzf.X = GetBit(LowData, 0, 16) / 16d; + xyzf.Y = GetBit(LowData, 32, 16) / 16d; + xyzf.Z = (UInt32)(GetBit(HighData, 4, 24)); + xyzf.F = (UInt16)(GetBit(HighData, 36, 8)); + } + else + { + xyzf.X = GetBit(LowData, 0, 16) / 16d; + xyzf.Y = GetBit(LowData, 16, 16) / 16d; + xyzf.Z = (UInt32)(GetBit(LowData, 32, 24)); + xyzf.F = (UInt16)(GetBit(LowData, 56, 8)); + } + return xyzf; + } + + public override string ToString() + { + return Descriptor.ToString() + "@X : " + X.ToString("F4") + "@Y : " + Y.ToString("F4") + "@Z : " + Z.ToString() + (IsXYZF ? "@F : " + F.ToString() : ""); } } } diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GifImage.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GifImage.cs index b7f08ee6f1..2e69c6e7ed 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GifImage.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFReg/GifImage.cs @@ -6,7 +6,6 @@ namespace GSDumpGUI { public class GifImage : IGifData { - public byte[] LowData; - public byte[] HighData; + public byte[] Data; } } diff --git a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFTag.cs b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFTag.cs index fcefd9abd1..c83dd97e1e 100644 --- a/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFTag.cs +++ b/tools/GSDumpGUI/Library/GSDump/GSData/GIFPacket/GIFTag.cs @@ -6,8 +6,8 @@ namespace GSDumpGUI { public class GIFTag { - public delegate GIFReg Unpack(UInt64 LowData, UInt64 HighData, bool PlainFormat); - static public Dictionary Registers; + public delegate GIFReg Unpack(GIFTag tag, int addr, UInt64 LowData, UInt64 HighData, bool PackedFormat); + static public Dictionary UnpackReg; public Int32 nloop; public Int32 eop; @@ -18,22 +18,78 @@ namespace GSDumpGUI public GIFFLG flg; public Int32 nreg; public List regs; - - static internal unsafe GIFTag ExtractGifTag(byte[] data) + public float Q; // GIF has an internal Q register which is reset to 1.0 at the tag and updated on packed ST(Q) for output at next RGBAQ + + static GIFTag() { - Registers = new Dictionary(); - Registers.Add((int)GIFRegDescriptor.PRIM, new Unpack(GIFRegPrim.Unpack)); - Registers.Add((int)GIFRegDescriptor.ST, new Unpack(GIFRegST.Unpack)); - Registers.Add((int)GIFRegDescriptor.TEX0_1, new Unpack(GIFRegTEX0.Unpack)); - Registers.Add((int)GIFRegDescriptor.TEX0_2, new Unpack(GIFRegTEX0.Unpack)); - Registers.Add((int)GIFRegDescriptor.XYZ2, new Unpack(GIFRegXYZ.Unpack)); - Registers.Add((int)GIFRegDescriptor.XYZ3, new Unpack(GIFRegXYZ.Unpack)); - Registers.Add((int)GIFRegDescriptor.XYZF2, new Unpack(GIFRegXYZF.Unpack)); - Registers.Add((int)GIFRegDescriptor.XYZF3, new Unpack(GIFRegXYZF.Unpack)); - Registers.Add((int)GIFRegDescriptor.FOG, new Unpack(GIFRegFOG.Unpack)); - Registers.Add((int)GIFRegDescriptor.UV, new Unpack(GIFRegUV.Unpack)); - Registers.Add((int)GIFRegDescriptor.RGBAQ, new Unpack(GIFRegRGBAQ.Unpack)); + UnpackReg = new Dictionary(); + UnpackReg.Add((int)GIFRegDescriptor.PRIM, GIFRegPRIM.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.RGBAQ, GIFRegRGBAQ.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.ST, GIFRegST.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.UV, GIFRegUV.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.XYZF2, GIFRegXYZF.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.XYZ2, GIFRegXYZF.UnpackXYZ); + UnpackReg.Add((int)GIFRegDescriptor.TEX0_1, GIFRegTEX0.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEX0_2, GIFRegTEX0.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.CLAMP_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.CLAMP_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.FOG, GIFRegFOG.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.XYZF3, GIFRegXYZF.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.XYZ3, GIFRegXYZF.UnpackXYZ); + UnpackReg.Add((int)GIFRegDescriptor.AD, GIFRegAD.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEX1_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEX1_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEX2_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEX2_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.XYOFFSET_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.XYOFFSET_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.PRMODECONT, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.PRMODE, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEXCLUT, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.SCANMSK, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.MIPTBP1_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.MIPTBP1_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.MIPTBP2_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.MIPTBP2_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEXA, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.FOGCOL, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEXFLUSH, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.SCISSOR_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.SCISSOR_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.ALPHA_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.ALPHA_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.DIMX, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.DTHE, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.COLCLAMP, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEST_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TEST_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.PABE, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.FBA_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.FBA_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.FRAME_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.FRAME_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.ZBUF_1, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.ZBUF_2, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.BITBLTBUF, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TRXPOS, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TRXREG, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.TRXDIR, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.HWREG, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.SIGNAL, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.FINISH, GIFRegUnimpl.Unpack); + UnpackReg.Add((int)GIFRegDescriptor.LABEL, GIFRegUnimpl.Unpack); + } + public static Unpack GetUnpack(int reg) + { + Unpack ret; + if (!UnpackReg.TryGetValue(reg, out ret)) + return GIFRegNOP.Unpack; + return ret; + } + + static internal GIFTag ExtractGifTag(byte[] data) + { Int16 nloopEOP = 0; Int16 pad1 = 0; Int32 pad2PrePrimFlgNReg = 0; @@ -45,6 +101,7 @@ namespace GSDumpGUI regs = BitConverter.ToInt64(data, 8); GIFTag t = new GIFTag(); + t.Q = 1f; t.nloop = (nloopEOP & 0x7FFF); t.eop = (nloopEOP & 0x8000) >> 15; t._pad1 = pad1; @@ -57,57 +114,51 @@ namespace GSDumpGUI t.flg = (GIFFLG)((pad2PrePrimFlgNReg & 0xC000000) >> 26); t.nreg = (int)(pad2PrePrimFlgNReg & 0xF0000000) >> 28; + if (t.nreg == 0) + t.nreg = 16; - List registers = new List(); + int[] registers = new int[t.nreg]; + Unpack[] regsunpack = new Unpack[t.nreg]; t.regs = new List(); for (int i = 0; i < t.nreg; i++) - registers.Add((GIFRegDescriptor)((regs & (Convert.ToInt32(Math.Pow(16, i + 1)) - 1)) >> i * 4)); - - for (int j = 0; j < t.nloop; j++) { - for (int i = 0; i < registers.Count; i++) - { - UInt64 LowData = BitConverter.ToUInt64(data, (16 + (i * 16) + (j * 16 * registers.Count))); - UInt64 HighData = BitConverter.ToUInt64(data, (16 + (i * 16) + 8 + (j * 16 * registers.Count))); + int reg = (int)(regs >> (i * 4) & 15); + registers[i] = reg; + regsunpack[i] = GetUnpack(reg); + } - switch (t.flg) - { - case GIFFLG.GIF_FLG_PACKED: - try - { - if (registers[i] == GIFRegDescriptor.AD) - { - int destaddr = (int)(HighData & 0xF); - t.regs.Add(Registers[destaddr].Invoke(LowData, HighData, false)); - } - else - t.regs.Add(Registers[(int)registers[i]].Invoke(LowData, HighData, false)); - } - catch (Exception) - { - // For now till we get all regs implemented - } - break; - case GIFFLG.GIF_FLG_REGLIST: - t.regs.Add(Registers[(int)registers[i]].Invoke(LowData, HighData, true)); - break; - case GIFFLG.GIF_FLG_IMAGE: - GifImage image = new GifImage(); - image.LowData = BitConverter.GetBytes(LowData); - image.HighData = BitConverter.GetBytes(HighData); - t.regs.Add(image); - break; - case GIFFLG.GIF_FLG_IMAGE2: - GifImage image2 = new GifImage(); - image2.LowData = BitConverter.GetBytes(LowData); - image2.HighData = BitConverter.GetBytes(HighData); - t.regs.Add(image2); - break; - default: - break; - } - } + int p = 16; + switch (t.flg) + { + case GIFFLG.GIF_FLG_PACKED: + for (int j = 0; j < t.nloop; j++) + for (int i = 0; i < t.nreg; i++) + { + UInt64 LowData = BitConverter.ToUInt64(data, p); + UInt64 HighData = BitConverter.ToUInt64(data, p + 8); + t.regs.Add(regsunpack[i](t, registers[i], LowData, HighData, true)); + p += 16; + } + break; + case GIFFLG.GIF_FLG_REGLIST: + for (int j = 0; j < t.nloop; j++) + for (int i = 0; i < t.nreg; i++) + { + UInt64 Data = BitConverter.ToUInt64(data, p); + t.regs.Add(regsunpack[i](t, registers[i], Data, 0, false)); + p += 8; + } + break; + case GIFFLG.GIF_FLG_IMAGE: + case GIFFLG.GIF_FLG_IMAGE2: + GifImage image = new GifImage(); + image.Data = new byte[t.nloop * 16]; + Array.Copy(data, 16, image.Data, 0, t.nloop * 16); + t.regs.Add(image); + break; + default: + break; } return t; }