mirror of https://github.com/PCSX2/pcsx2.git
Rewritten all the dump functionality to be completely managed by my application and not relying anymore on gsdx REPLAY function. This is the first of a series of commit. The plan is to have a decent debug tool to understand problems with gsdx. Plan to do some other commit to clear up the code not used anymore
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4104 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
8a69681505
commit
5ef3d80f47
|
@ -55,11 +55,9 @@ namespace GSDumpGUI
|
|||
Directory.SetCurrentDirectory(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + Path.GetFileName(DLLPath) + "\\"));
|
||||
if (Operation == "GSReplay")
|
||||
{
|
||||
GSDump dump = GSDump.LoadDump(DumpPath);
|
||||
wrap.Run(dump, Renderer);
|
||||
ChangeIcon = true;
|
||||
if (Renderer != -1)
|
||||
wrap.GSReplayDump(Renderer + " " + DumpPath);
|
||||
else
|
||||
wrap.GSReplayDump(DumpPath);
|
||||
}
|
||||
else
|
||||
wrap.GSConfig();
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
@ -54,6 +54,8 @@
|
|||
<Compile Include="Forms\frmMain.Designer.cs">
|
||||
<DependentUpon>frmMain.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Library\GSDump\GSData.cs" />
|
||||
<Compile Include="Library\GSDump\GSDump.cs" />
|
||||
<Compile Include="Library\GSDXWrapper.cs" />
|
||||
<Compile Include="Library\NativeMethods.cs" />
|
||||
<Compile Include="Core\Program.cs" />
|
||||
|
|
|
@ -6,21 +6,48 @@ using System.IO;
|
|||
|
||||
namespace GSDumpGUI
|
||||
{
|
||||
public delegate void GSReplay(IntPtr HWND, IntPtr HInstance, String File, Boolean Show);
|
||||
public delegate void GSgifTransfer1(IntPtr data, int size);
|
||||
public delegate void GSgifTransfer2(IntPtr data, int size);
|
||||
public delegate void GSgifTransfer3(IntPtr data, int size);
|
||||
public delegate void GSVSync(byte field);
|
||||
public delegate void GSreadFIFO2(IntPtr data, int size);
|
||||
public delegate void GSsetGameCRC(int crc, int options);
|
||||
public delegate void GSfreeze(int mode, IntPtr data);
|
||||
public delegate void GSopen(IntPtr hwnd, String Title, int renderer);
|
||||
public delegate void GSclose();
|
||||
public delegate void GSshutdown();
|
||||
public delegate void GSConfigure();
|
||||
public delegate void GSsetBaseMem(IntPtr data);
|
||||
public delegate IntPtr PSEgetLibName();
|
||||
public delegate void GSinit();
|
||||
|
||||
public class GSDXWrapper
|
||||
{
|
||||
private delegate void GSReplay(IntPtr HWND, IntPtr HInstance, String File, Boolean Show);
|
||||
private delegate void GSConfigure();
|
||||
private delegate IntPtr PSEgetLibName();
|
||||
|
||||
private GSReplay gsReplay;
|
||||
private GSConfigure gsConfigure;
|
||||
private PSEgetLibName PsegetLibName;
|
||||
private GSgifTransfer1 GSgifTransfer1;
|
||||
private GSgifTransfer2 GSgifTransfer2;
|
||||
private GSgifTransfer3 GSgifTransfer3;
|
||||
private GSVSync GSVSync;
|
||||
private GSreadFIFO2 GSreadFIFO2;
|
||||
private GSsetGameCRC GSsetGameCRC;
|
||||
private GSfreeze GSfreeze;
|
||||
private GSopen GSopen;
|
||||
private GSclose GSclose;
|
||||
private GSshutdown GSshutdown;
|
||||
private GSsetBaseMem GSsetBaseMem;
|
||||
private GSinit GSinit;
|
||||
|
||||
private Boolean Loaded;
|
||||
|
||||
private String DLL;
|
||||
private IntPtr DLLAddr;
|
||||
|
||||
private Boolean Running;
|
||||
|
||||
static public Boolean IsValidGSDX(String DLL)
|
||||
{
|
||||
NativeMethods.SetErrorMode(0x8007);
|
||||
|
@ -34,6 +61,19 @@ namespace GSDumpGUI
|
|||
IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PS2EgetLibName");
|
||||
IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
|
||||
|
||||
IntPtr funcaddrGIF1 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer1");
|
||||
IntPtr funcaddrGIF2 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer2");
|
||||
IntPtr funcaddrGIF3 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer3");
|
||||
IntPtr funcaddrVSync = NativeMethods.GetProcAddress(hmod, "GSvsync");
|
||||
IntPtr funcaddrSetBaseMem = NativeMethods.GetProcAddress(hmod, "GSsetBaseMem");
|
||||
IntPtr funcaddrOpen = NativeMethods.GetProcAddress(hmod, "GSopen");
|
||||
IntPtr funcaddrSetCRC = NativeMethods.GetProcAddress(hmod, "GSsetGameCRC");
|
||||
IntPtr funcaddrClose = NativeMethods.GetProcAddress(hmod, "GSclose");
|
||||
IntPtr funcaddrShutdown = NativeMethods.GetProcAddress(hmod, "GSshutdown");
|
||||
IntPtr funcaddrFreeze = NativeMethods.GetProcAddress(hmod, "GSfreeze");
|
||||
IntPtr funcaddrGSreadFIFO2 = NativeMethods.GetProcAddress(hmod, "GSreadFIFO2");
|
||||
IntPtr funcaddrinit = NativeMethods.GetProcAddress(hmod, "GSinit");
|
||||
|
||||
NativeMethods.FreeLibrary(hmod);
|
||||
if (!((funcaddrConfig.ToInt64() > 0) && (funcaddrLibName.ToInt64() > 0) && (funcaddrReplay.ToInt64() > 0)))
|
||||
{
|
||||
|
@ -73,9 +113,36 @@ namespace GSDumpGUI
|
|||
IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PS2EgetLibName");
|
||||
IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
|
||||
|
||||
IntPtr funcaddrGIF1 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer1");
|
||||
IntPtr funcaddrGIF2 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer2");
|
||||
IntPtr funcaddrGIF3 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer3");
|
||||
IntPtr funcaddrVSync = NativeMethods.GetProcAddress(hmod, "GSvsync");
|
||||
IntPtr funcaddrSetBaseMem = NativeMethods.GetProcAddress(hmod, "GSsetBaseMem");
|
||||
IntPtr funcaddrOpen = NativeMethods.GetProcAddress(hmod, "GSopen");
|
||||
IntPtr funcaddrSetCRC = NativeMethods.GetProcAddress(hmod, "GSsetGameCRC");
|
||||
IntPtr funcaddrClose = NativeMethods.GetProcAddress(hmod, "GSclose");
|
||||
IntPtr funcaddrShutdown = NativeMethods.GetProcAddress(hmod, "GSshutdown");
|
||||
IntPtr funcaddrFreeze = NativeMethods.GetProcAddress(hmod, "GSfreeze");
|
||||
IntPtr funcaddrGSreadFIFO2 = NativeMethods.GetProcAddress(hmod, "GSreadFIFO2");
|
||||
IntPtr funcaddrinit = NativeMethods.GetProcAddress(hmod, "GSinit");
|
||||
|
||||
gsReplay = (GSReplay)Marshal.GetDelegateForFunctionPointer(funcaddrReplay, typeof(GSReplay));
|
||||
gsConfigure = (GSConfigure)Marshal.GetDelegateForFunctionPointer(funcaddrConfig, typeof(GSConfigure));
|
||||
PsegetLibName = (PSEgetLibName)Marshal.GetDelegateForFunctionPointer(funcaddrLibName, typeof(PSEgetLibName));
|
||||
|
||||
this.GSgifTransfer1 = (GSgifTransfer1)Marshal.GetDelegateForFunctionPointer(funcaddrGIF1, typeof(GSgifTransfer1));
|
||||
this.GSgifTransfer2 = (GSgifTransfer2)Marshal.GetDelegateForFunctionPointer(funcaddrGIF2, typeof(GSgifTransfer2));
|
||||
this.GSgifTransfer3 = (GSgifTransfer3)Marshal.GetDelegateForFunctionPointer(funcaddrGIF3, typeof(GSgifTransfer3));
|
||||
this.GSVSync = (GSVSync)Marshal.GetDelegateForFunctionPointer(funcaddrVSync, typeof(GSVSync));
|
||||
this.GSsetBaseMem = (GSsetBaseMem)Marshal.GetDelegateForFunctionPointer(funcaddrSetBaseMem, typeof(GSsetBaseMem));
|
||||
this.GSopen = (GSopen)Marshal.GetDelegateForFunctionPointer(funcaddrOpen, typeof(GSopen));
|
||||
this.GSsetGameCRC = (GSsetGameCRC)Marshal.GetDelegateForFunctionPointer(funcaddrSetCRC, typeof(GSsetGameCRC));
|
||||
this.GSclose = (GSclose)Marshal.GetDelegateForFunctionPointer(funcaddrClose, typeof(GSclose));
|
||||
this.GSshutdown = (GSshutdown)Marshal.GetDelegateForFunctionPointer(funcaddrShutdown, typeof(GSshutdown));
|
||||
this.GSfreeze = (GSfreeze)Marshal.GetDelegateForFunctionPointer(funcaddrFreeze, typeof(GSfreeze));
|
||||
this.GSreadFIFO2 = (GSreadFIFO2)Marshal.GetDelegateForFunctionPointer(funcaddrGSreadFIFO2, typeof(GSreadFIFO2));
|
||||
this.GSinit = (GSinit)Marshal.GetDelegateForFunctionPointer(funcaddrinit, typeof(GSinit));
|
||||
|
||||
DLLAddr = hmod;
|
||||
}
|
||||
NativeMethods.SetErrorMode(0x0000);
|
||||
|
@ -107,5 +174,89 @@ namespace GSDumpGUI
|
|||
throw new Exception("GSDX is not loaded");
|
||||
return Marshal.PtrToStringAnsi(PsegetLibName.Invoke());
|
||||
}
|
||||
|
||||
public unsafe void Run(GSDump dump, int rendererOverride)
|
||||
{
|
||||
Running = true;
|
||||
GSinit();
|
||||
fixed (byte* pointer = dump.Registers)
|
||||
{
|
||||
GSsetBaseMem(new IntPtr(pointer));
|
||||
Int32 HWND = 0;
|
||||
GSopen(new IntPtr(&HWND), "", rendererOverride);
|
||||
GSsetGameCRC(dump.CRC, 0);
|
||||
fixed (byte* freeze = dump.StateData)
|
||||
{
|
||||
GSfreeze(0, new IntPtr(freeze));
|
||||
GSVSync(1);
|
||||
|
||||
while (Running)
|
||||
{ /*"C:\Users\Alessio\Desktop\Plugins\Dll\gsdx-sse4-r3878.dll" "C:\Users\Alessio\Desktop\Plugins\Dumps\gsdx_20100603052628.gs" "GSReplay" 0*/
|
||||
if (!NativeMethods.IsWindowVisible(new IntPtr(HWND)))
|
||||
{
|
||||
Running = false;
|
||||
break;
|
||||
}
|
||||
foreach (var itm in dump.Data)
|
||||
{
|
||||
switch (itm.id)
|
||||
{
|
||||
case GSType.Transfer:
|
||||
switch (itm.data[0])
|
||||
{
|
||||
case 0:
|
||||
fixed (byte* gifdata = itm.data)
|
||||
{
|
||||
byte[] data = new byte[4];
|
||||
data[0]=*(gifdata+1);
|
||||
data[1]=*(gifdata+2);
|
||||
data[2]=*(gifdata+3);
|
||||
data[3]=*(gifdata+4);
|
||||
Int32 size = BitConverter.ToInt32(data, 0);
|
||||
GSgifTransfer1(new IntPtr(gifdata + 5), 16384 - size);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
fixed (byte* gifdata = itm.data)
|
||||
{
|
||||
GSgifTransfer2(new IntPtr(gifdata + 1), (itm.data.Length - 1) / 16);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
fixed (byte* gifdata = itm.data)
|
||||
{
|
||||
GSgifTransfer3(new IntPtr(gifdata + 1), (itm.data.Length - 1) / 16);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GSType.VSync:
|
||||
GSVSync(itm.data[0]);
|
||||
break;
|
||||
case GSType.ReadFIFO2:
|
||||
fixed (byte* FIFO = itm.data)
|
||||
{
|
||||
GSreadFIFO2(new IntPtr(FIFO), itm.data.Length / 16);
|
||||
}
|
||||
break;
|
||||
case GSType.Registers:
|
||||
Marshal.Copy(itm.data, 0, new IntPtr(pointer), 8192);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GSclose();
|
||||
GSshutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
Running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace GSDumpGUI
|
||||
{
|
||||
public class GSData
|
||||
{
|
||||
public GSType id;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
public enum GSType
|
||||
{
|
||||
Transfer = 0,
|
||||
VSync = 1,
|
||||
ReadFIFO2 = 2,
|
||||
Registers = 3
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace GSDumpGUI
|
||||
{
|
||||
public class GSDump
|
||||
{
|
||||
public Int32 CRC;
|
||||
public byte[] StateData;
|
||||
public byte[] Registers; // 8192 bytes
|
||||
|
||||
public List<GSData> Data;
|
||||
|
||||
public GSDump()
|
||||
{
|
||||
Data = new List<GSData>();
|
||||
}
|
||||
|
||||
static public GSDump LoadDump(String FileName)
|
||||
{
|
||||
GSDump dmp = new GSDump();
|
||||
|
||||
BinaryReader br = new BinaryReader(System.IO.File.Open(FileName, FileMode.Open));
|
||||
dmp.CRC = br.ReadInt32();
|
||||
Int32 ss = br.ReadInt32();
|
||||
dmp.StateData = br.ReadBytes(ss);
|
||||
dmp.Registers = br.ReadBytes(8192);
|
||||
|
||||
while (br.PeekChar() != -1)
|
||||
{
|
||||
GSData data = new GSData();
|
||||
data.id = (GSType)br.ReadByte();
|
||||
|
||||
switch (data.id)
|
||||
{
|
||||
case GSType.Transfer:
|
||||
byte index = br.ReadByte();
|
||||
if (index == 0)
|
||||
{
|
||||
Int32 size = br.ReadInt32();
|
||||
|
||||
byte[] dat = new byte[16384];
|
||||
List<byte> Data = new List<byte>();
|
||||
Data.Add(index);
|
||||
Data.AddRange(BitConverter.GetBytes(size));
|
||||
Data.AddRange(dat);
|
||||
|
||||
int startaddr = 16389 - size;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
Data[startaddr + i] = br.ReadByte();
|
||||
data.data = Data.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
Int32 size = br.ReadInt32();
|
||||
|
||||
List<byte> Data = new List<byte>();
|
||||
Data.Add(index);
|
||||
Data.AddRange(br.ReadBytes(size));
|
||||
data.data = Data.ToArray();
|
||||
}
|
||||
break;
|
||||
case GSType.VSync:
|
||||
data.data = br.ReadBytes(1);
|
||||
break;
|
||||
case GSType.ReadFIFO2:
|
||||
Int32 sF = br.ReadInt32();
|
||||
data.data = br.ReadBytes(sF);
|
||||
break;
|
||||
case GSType.Registers:
|
||||
data.data = br.ReadBytes(8192);
|
||||
break;
|
||||
}
|
||||
dmp.Data.Add(data);
|
||||
}
|
||||
br.Close();
|
||||
|
||||
return dmp;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,5 +35,9 @@ namespace GSDumpGUI
|
|||
[SuppressUnmanagedCodeSecurityAttribute]
|
||||
[DllImport("user32", CharSet = CharSet.Ansi)]
|
||||
public extern static int SetClassLong(IntPtr HWND, int index, long newlong);
|
||||
|
||||
[SuppressUnmanagedCodeSecurityAttribute]
|
||||
[DllImport("user32", CharSet = CharSet.Ansi)]
|
||||
public extern static bool IsWindowVisible(IntPtr HWND);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue