public static Action<CpuThreadState> CreateDelegateForString(this CpuProcessor CpuProcessor, String Assembly, bool BreakPoint = false) { CpuProcessor.MethodCache.Clear(); Assembly += "\r\nbreak\r\n"; var MemoryStream = new MemoryStream(); MemoryStream.PreservePositionAndLock(() => { var MipsAssembler = new MipsAssembler(MemoryStream); MipsAssembler.Assemble(Assembly); }); //Console.WriteLine(Assembly); return (_CpuThreadState) => { _CpuThreadState.PC = 0; //Console.WriteLine("PC: {0:X}", _CpuThreadState.PC); try { while (true) { //Console.WriteLine("PC: {0:X}", _CpuThreadState.PC); var Delegate = CpuProcessor.CreateDelegateForPC(MemoryStream, _CpuThreadState.PC); _CpuThreadState.StepInstructionCount = 1000000; Delegate.Delegate(_CpuThreadState); } } catch (PspBreakException) { } }; }
public static MemoryStream SerializeToMemoryStream(Action<Stream> Serializer) { var Stream = new MemoryStream(); Stream.PreservePositionAndLock(() => { Serializer(Stream); Stream.Flush(); }); return Stream; }
public static Action<CpuThreadState> CreateDelegateForString(this CpuProcessor CpuProcessor, String Assembly, bool BreakPoint = false) { var MemoryStream = new MemoryStream(); MemoryStream.PreservePositionAndLock(() => { var MipsAssembler = new MipsAssembler(MemoryStream); MipsAssembler.Assemble(Assembly); }); var Delegate = CpuProcessor.CreateDelegateForPC(MemoryStream, 0); return (_CpuThreadState) => { _CpuThreadState.StepInstructionCount = 1000000; Delegate(_CpuThreadState); }; }
public void AssembleTest() { var MemoryStream = new MemoryStream(); var BinaryReader = new BinaryReader(MemoryStream); MemoryStream.PreservePositionAndLock(() => { var MipsAssembler = new MipsAssembler(MemoryStream); MipsAssembler.Assemble(@" add r1, r0, r2 sub r3, r31, r7 "); }); Assert.AreEqual(8, MemoryStream.Length); Assert.AreEqual((uint)0x00020820, BinaryReader.ReadUInt32()); Assert.AreEqual((uint)0x03E71822, BinaryReader.ReadUInt32()); }