/// <summary> /// /// </summary> public override void InitializeComponent() { this.Config = PspEmulatorContext.PspConfig; this.Memory = PspEmulatorContext.GetInstance <PspMemory>(); this.TextureCache = PspEmulatorContext.GetInstance <TextureCache>(); this.VertexReader = new VertexReader(); }
public HleIoDriverMemoryStick(PspMemory Memory, IMemoryStickEventHandler MemoryStickEventHandler, IHleIoDriver HleIoDriver) : base(HleIoDriver) { this.Memory = Memory; this.MemoryStickEventHandler = MemoryStickEventHandler; }
public static void ClassInit(TestContext context) { PspConfig = new PspConfig(); PspEmulatorContext = new PspEmulatorContext(PspConfig); PspEmulatorContext.SetInstanceType <PspMemory, LazyPspMemory>(); Memory = PspEmulatorContext.GetInstance <PspMemory>(); }
//Action[] InstructionSwitch = new Action[256]; /// <summary> /// Constructor /// </summary> internal GpuDisplayList(PspMemory Memory, GpuProcessor GpuProcessor, int Id) { this.Memory = Memory; this.GpuProcessor = GpuProcessor; this.Id = Id; GlobalGpuState = GpuProcessor.GlobalGpuState; }
public static void ClassInit(TestContext context) { PspConfig = new PspConfig(); PspEmulatorContext = new PspEmulatorContext(PspConfig); PspEmulatorContext.SetInstanceType<PspMemory, LazyPspMemory>(); Memory = PspEmulatorContext.GetInstance<PspMemory>(); }
public static CpuProcessor CreateCpuProcessor(PspMemory Memory = null) { if (Memory == null) Memory = LazyPspMemory; var InjectContext = new InjectContext(); InjectContext.SetInstance<PspMemory>(Memory); InjectContext.SetInstance<ICpuConnector>(new TestConnector()); InjectContext.SetInstance<IInterruptManager>(new TestInterruptManager()); return InjectContext.GetInstance<CpuProcessor>(); }
public void SetUp() { PspConfig = new PspConfig(); PspEmulatorContext = new PspEmulatorContext(PspConfig); PspEmulatorContext.SetInstanceType<PspMemory, LazyPspMemory>(); Memory = PspEmulatorContext.GetInstance<PspMemory>(); Processor = PspEmulatorContext.GetInstance<CpuProcessor>(); MipsAssembler = new MipsAssembler(new PspMemoryStream(Memory)); }
//Action[] InstructionSwitch = new Action[256]; /// <summary> /// Constructor /// </summary> internal GpuDisplayList(PspMemory Memory, GpuProcessor GpuProcessor, int Id) { this.Memory = Memory; this.GpuProcessor = GpuProcessor; this.Id = Id; GpuDisplayListRunner = new GpuDisplayListRunner() { GpuDisplayList = this, }; }
public void SetUp() { PspConfig = new PspConfig(); PspEmulatorContext = new PspEmulatorContext(PspConfig); PspEmulatorContext.SetInstanceType <PspMemory, LazyPspMemory>(); Memory = PspEmulatorContext.GetInstance <PspMemory>(); Processor = PspEmulatorContext.GetInstance <CpuProcessor>(); MipsAssembler = new MipsAssembler(new PspMemoryStream(Memory)); }
public override void InitializeComponent() { CpuProcessor = PspEmulatorContext.GetInstance <CpuProcessor>(); PspRtc = PspEmulatorContext.GetInstance <PspRtc>(); ThreadManager = PspEmulatorContext.GetInstance <HleThreadManager>(); HleState = PspEmulatorContext.GetInstance <HleState>(); PspMemory = PspEmulatorContext.GetInstance <PspMemory>(); RegisterDevices(); }
// NB: the codes are in the relative format from the start of the user ram area. // So the absolute adress is relative adress +0x08800000 // To convert some cheat from the absolute format you need to // subtract 0x08800000 from the adress of the code // 16-bit Greater Than : Multiple Skip Ennndddd 3aaaaaaa // 16-bit Less Than : Multiple Skip 0xEnnndddd 0x2aaaaaaa // 16-bit Not Equal : Multiple Skip 0xEnnndddd 0x1aaaaaaa // 16-bit Equal : Multiple Skip 0xEnnndddd 0x0aaaaaaa // 16-bit greater than - TEST CODE - 0xDaaaaaaa 0x0030dddd // 16-bit less than - TEST CODE - 0xDaaaaaaa 0x0020dddd // 16-bit not equal - TEST CODE - 0xDaaaaaaa 0x0010dddd // 16-bit equal - TEST CODE - 0xDaaaaaaa 0x0000dddd // code stopper 0xCaaaaaaa 0xvvvvvvvv // Time Command 0xB0000000 0xnnnnnnnn (based on cheat delay) // [pointer command] 32-bit write 0x6aaaaaaa 0xvvvvvvvv 0x0002nnnn 0xiiiiiiii // [pointer command] 16-bit write 0x6aaaaaaa 0x0000vvvv 0x0001nnnn 0xiiiiiiii // [pointer command] 8-bit write 0x6aaaaaaa 0x000000vv 0x0000nnnn 0xiiiiiiii // copy byte 0x5aaaaaaa 0xnnnnnnnn 0xbbbbbbbb 0x00000000 // [tp]32-bit Multi-Address Write 0x4aaaaaaa 0xxxxxyyyy 0xdddddddd 0x00000000 // 32-bit decrement 0x30500000 0xaaaaaaaa 0xnnnnnnnn 0x00000000 // 32-bit increment 0x30400000 0xaaaaaaaa 0xnnnnnnnn 0x00000000 // 16-bit decrement 0x3030nnnn 0xaaaaaaaa // 16-bit increment 0x3020nnnn 0xaaaaaaaa // 8-bit decrement 0x301000nn 0xaaaaaaaa // 8-bit increment 0x300000nn 0xaaaaaaaa public void Patch(PspMemory PspMemory) { try { _Patch(PspMemory); } catch (Exception Exception) { Console.WriteLine(Exception); } }
public void Init(HleThreadManager ThreadManager, PspMemory PspMemory, HleMemoryManager MemoryManager) { var BlockType = Attributes.HasFlag(MsgPipeAttributes.UseHighAddress) ? MemoryPartition.Anchor.High : MemoryPartition.Anchor.Low ; this.ThreadManager = ThreadManager; this.PspMemory = PspMemory; this.PoolPartition = MemoryManager.GetPartition(PartitionId).Allocate(Size, BlockType, Alignment: 16); }
public static CpuProcessor CreateCpuProcessor(PspMemory memory = null) { if (memory == null) { memory = _lazyPspMemory; } var injectContext = new InjectContext(); injectContext.SetInstance <PspMemory>(memory); injectContext.SetInstance <ICpuConnector>(new TestConnector()); injectContext.SetInstance <IInterruptManager>(new TestInterruptManager()); return(injectContext.GetInstance <CpuProcessor>()); }
public void SetInstructionAddressStall(uint value) { InstructionAddressStall = value & PspMemory.MemoryMask; if (InstructionAddressStall != 0 && !PspMemory.IsAddressValid(InstructionAddressStall)) { throw new InvalidOperationException($"Invalid StallAddress! 0x{InstructionAddressStall}"); } if (Debug) { Console.WriteLine("GpuDisplayList.SetInstructionAddressStall:{0:X8}", value); } StallAddressUpdated.Set(); }
public void SetUp() { PspConfig = new PspConfig(); PspConfig.HleModulesDll = Assembly.GetExecutingAssembly(); PspEmulatorContext = new PspEmulatorContext(PspConfig); PspEmulatorContext.SetInstanceType<PspMemory, LazyPspMemory>(); PspEmulatorContext.SetInstanceType<GpuImpl, GpuImplNull>(); PspEmulatorContext.SetInstanceType<PspAudioImpl, AudioImplNull>(); Memory = PspEmulatorContext.GetInstance<PspMemory>(); ThreadManager = PspEmulatorContext.GetInstance<HleThreadManager>(); Processor = PspEmulatorContext.GetInstance<CpuProcessor>(); MipsAssembler = new MipsAssembler(new PspMemoryStream(Memory)); }
public SimplifiedPspEmulator(bool test = false, Action <InjectContext>?configure = null) { injector = PspInjectContext.CreateInjectContext(PspStoredConfig.Load(), test, configure); Emulator = injector.GetInstance <PspEmulator>(); //Emulator.PspRunner = null; //Emulator.CpuConfig.DebugSyscalls = true; //Emulator.CpuConfig.TrackCallStack = true; Rtc = injector.GetInstance <PspRtc>(); Display = injector.GetInstance <PspDisplay>(); DisplayComponent = injector.GetInstance <DisplayComponentThread>(); Memory = injector.GetInstance <PspMemory>(); Controller = injector.GetInstance <PspController>(); DisplayComponent.triggerStuff = true; }
public HleMemoryManager(PspMemory Memory) { #if true MemoryPartitionsUid.Set(0, new MemoryPartition(Low: 0x88000000, High: 0x88300000, Allocated: false, Name: "Kernel Partition 1")); // 3MB MemoryPartitionsUid.Set(1, new MemoryPartition(Low: 0x88300000, High: 0x88400000, Allocated: false, Name: "Kernel Partition 2")); // 1MB MemoryPartitionsUid.Set(2, new MemoryPartition(Low: 0x08800000, High: 0x0B000000, Allocated: false, Name: "User Partition")); // 24MB MemoryPartitionsUid.Set(3, new MemoryPartition(Low: 0x08400000, High: 0x08800000, Allocated: false, Name: "Volatile Partition")); // 4MB MemoryPartitionsUid.Set(4, new MemoryPartition(Low: 0x8A000000, High: 0x8BC00000, Allocated: false, Name: "UMD Cache Partition")); // 28MB MemoryPartitionsUid.Set(5, new MemoryPartition(Low: 0x8BC00000, High: 0x8C000000, Allocated: false, Name: "ME Partition")); // 4MB #else MemoryPartitionsUid.Set(0, new MemoryPartition(Low: 0x88000000, High: 0x88300000, Allocated: false, Name: "Kernel Partition 1")); // 3MB MemoryPartitionsUid.Set(1, new MemoryPartition(Low: 0x88300000, High: 0x88400000, Allocated: false, Name: "Kernel Partition 2")); // 1MB MemoryPartitionsUid.Set(2, new MemoryPartition(Low: 0x08800000, High: 0x0C000000, Allocated: false, Name: "User Partition")); // 48MB #endif this.Memory = Memory; }
/// <summary> /// /// </summary> /// <param name="PspConfig"></param> /// <param name="Memory"></param> public override void InitializeComponent() { if (sizeof(GpuStateStruct) > sizeof(uint) * 512) { throw (new InvalidProgramException("GpuStateStruct too big. Maybe x64? . Size: " + sizeof(GpuStateStruct))); } this.PspConfig = PspEmulatorContext.PspConfig; this.Memory = PspEmulatorContext.GetInstance <PspMemory>(); this.GpuImpl = PspEmulatorContext.GetInstance <GpuImpl>(); this.DisplayListQueue = new LinkedList <GpuDisplayList>(); this.DisplayListFreeQueue = new Queue <GpuDisplayList>(); for (int n = 0; n < DisplayLists.Length; n++) { var DisplayList = new GpuDisplayList(Memory, this, n); this.DisplayLists[n] = DisplayList; //this.DisplayListFreeQueue.Enqueue(DisplayLists[n]); EnqueueFreeDisplayList(DisplayLists[n]); } }
public AstNodeExpr MemoryGetPointer(PspMemory memory, AstNodeExpr address, bool safe, string errorDescription = "ERROR", InvalidAddressAsEnum invalidAddress = InvalidAddressAsEnum.Exception) { if (safe) { return(Ast.CallInstance( Ast.CpuThreadStateExpr, (AddressToPointerWithErrorFunc)CpuThreadState.Methods.GetMemoryPtrSafeWithError, Ast.Cast <uint>(address), errorDescription, true, Ast.Immediate(invalidAddress) )); } else { if (DynarecConfig.AllowFastMemory && memory.HasFixedGlobalAddress) { if (DynarecConfig.EnableFastPspMemoryUtilsGetFastMemoryReader) { return(Ast.CallStatic(FastPspMemoryUtils.GetFastMemoryReader(memory.FixedGlobalAddress), address)); } else { var addressMasked = Ast.Binary(address, "&", Ast.Immediate(FastPspMemory.FastMemoryMask)); return(Ast.Immediate(memory.FixedGlobalAddress) + addressMasked); } } else { return(Ast.CallInstance( Ast.CpuThreadStateExpr, (AddressToPointerFunc)CpuThreadState.Methods.GetMemoryPtr, address )); } } }
internal InternalFunctionCompiler(InjectContext injectContext, MipsMethodEmitter mipsMethodEmitter, DynarecFunctionCompiler dynarecFunctionCompiler, IInstructionReader instructionReader, Action <uint> exploreNewPcCallback, uint entryPc, bool doLog, bool checkValidAddress = true) { injectContext.InjectDependencesTo(this); _exploreNewPcCallback = exploreNewPcCallback; _mipsMethodEmitter = mipsMethodEmitter; _cpuEmitter = new CpuEmitter(injectContext, mipsMethodEmitter, instructionReader); _globalInstructionStats = _cpuProcessor.GlobalInstructionStats; //this.InstructionStats = MipsMethodEmitter.InstructionStats; _instructionStats = new Dictionary <string, uint>(); _newInstruction = new Dictionary <string, bool>(); _doLog = doLog; _dynarecFunctionCompiler = dynarecFunctionCompiler; _instructionReader = instructionReader; _entryPc = entryPc; if (checkValidAddress && !PspMemory.IsAddressValid(entryPc)) { throw new InvalidOperationException($"Trying to get invalid function 0x{entryPc:X8}"); } }
private void _Patch(PspMemory PspMemory) { byte OpCode = (byte)((this.Code & 0xF0000000) >> 28); uint Info = this.Code & 0x0FFFFFFF; uint Value = this.Value; uint Address = 0x08800000 + Info; try { switch (OpCode) { // [t]8-bit Constant Write 0x0aaaaaaa 0x000000dd case 0x0: PspMemory.WriteSafe(Address, (byte)(Value & 0xFF)); break; // [t]16-bit Constant write 0x1aaaaaaa 0x0000dddd case 0x1: PspMemory.WriteSafe(Address, (ushort)(Value & 0xFFFF)); break; // [t]32-bit Constant write 0x2aaaaaaa 0xdddddddd case 0x2: PspMemory.WriteSafe(Address, (uint)(Value & 0xFFFFFFFF)); break; // 16-bit XOR - 0x7aaaaaaa 0x0005vvvv // 8-bit XOR - 0x7aaaaaaa 0x000400vv // 16-bit AND - 0x7aaaaaaa 0x0003vvvv // 8-bit AND - 0x7aaaaaaa 0x000200vv // 16-bit OR - 0x7aaaaaaa 0x0001vvvv // 8-bit OR - 0x7aaaaaaa 0x000000vv case 0x7: { uint SubOpCode = (Value >> 16) & 0xFFFF; uint SubValue = (Value >> 0) & 0xFFFF; switch (SubOpCode) { // 8-bit OR - 0x7aaaaaaa 0x000000vv case 0: PspMemory.WriteSafe(Address, (byte)(PspMemory.ReadSafe<byte>(Address) | (SubValue & 0xFF))); break; default: Console.Error.WriteLine("Invalid CWCheatOpCode: 0x{0:X} : 0x{1:X}", OpCode, SubOpCode); break; } } break; default: Console.Error.WriteLine("Invalid CWCheatOpCode: 0x{0:X}", OpCode); break; } } catch (Exception Exception) { throw (new Exception(String.Format("At Address: 0x{0:X}", Address), Exception)); } }
private AstOptimizerPsp(PspMemory Memory) { this.Memory = Memory; }
public void Init(HleThreadManager ThreadManager, PspMemory PspMemory, HleMemoryManager MemoryManager) { var BlockType = Attributes.HasFlag(MsgPipeAttributes.UseHighAddress) ? MemoryPartition.Anchor.High : MemoryPartition.Anchor.Low ; this.ThreadManager = ThreadManager; this.PspMemory = PspMemory; this.PoolPartition = MemoryManager.GetPartition(PartitionId).Allocate( Size, BlockType, Alignment: 16, Name: "<MsgPipe> : " + Name ); }
/// <summary> /// PASS 1: Analyze Branches /// </summary> private void AnalyzeBranches() { _skipPc = new HashSet <uint>(); _analyzedPc = new HashSet <uint>(); var branchesToAnalyze = new Queue <uint>(); _labels[_entryPc] = AstLabel.CreateLabel("EntryPoint"); var endPc = _instructionReader.EndPc; _pc = _entryPc; _minPc = uint.MaxValue; _maxPc = uint.MinValue; branchesToAnalyze.Enqueue(_entryPc); while (true) { HandleNewBranch: var endOfBranchFound = false; if (branchesToAnalyze.Count == 0) { break; } for (_pc = branchesToAnalyze.Dequeue(); _pc <= endPc; _pc += 4) { // If already analyzed, stop scanning this branch. if (_analyzedPc.Contains(_pc)) { break; } _analyzedPc.Add(_pc); //Console.WriteLine("%08X".Sprintf(PC)); if (_analyzedPc.Count > MaxNumberOfInstructions) { throw new InvalidDataException( $"Code sequence too long: >= {MaxNumberOfInstructions} at 0x{_entryPc:X8}"); } UpdateMinMax(_pc); //Console.WriteLine(" PC:{0:X}", PC); var instruction = _instructionReader[_pc]; var branchInfo = DynarecBranchAnalyzer.GetBranchInfo(instruction); var disassemblerInfo = _mipsDisassembler.Disassemble(_pc, instruction); LogInstruction(_pc, instruction); // Break if (disassemblerInfo.InstructionInfo.Name == "break") { break; } // Branch instruction. //else if (BranchInfo.HasFlag(DynarecBranchAnalyzer.JumpFlags.JumpAlways)) else if (branchInfo.HasFlag(DynarecBranchAnalyzer.JumpFlags.JumpInstruction)) { //Console.WriteLine("Instruction"); var jumpAddress = instruction.GetJumpAddress(_memory, _pc); // Located a jump-always instruction with a delayed slot. Process next instruction too. if (branchInfo.HasFlag(DynarecBranchAnalyzer.JumpFlags.AndLink)) { // Just a function call. Continue analyzing. } else { if (PspMemory.IsAddressValid(jumpAddress)) { if (!_labelsJump.ContainsKey(jumpAddress)) { if (AddressInsideFunction(jumpAddress)) { //Console.WriteLine("JumpAddress: {0:X8}", JumpAddress); _labelsJump[jumpAddress] = AstLabel.CreateLabel($"Jump_0x{jumpAddress:X8}"); branchesToAnalyze.Enqueue(jumpAddress); } } } endOfBranchFound = true; continue; } } else if (branchInfo.HasFlag(DynarecBranchAnalyzer.JumpFlags.BranchOrJumpInstruction)) { var branchAddress = instruction.GetBranchAddress(_pc); if (!_labels.ContainsKey(branchAddress)) { //Console.WriteLine("BranchAddress: {0:X8}", BranchAddress); UpdateMinMax(branchAddress); _labels[branchAddress] = AstLabel.CreateLabel($"Label_0x{branchAddress:X8}"); branchesToAnalyze.Enqueue(branchAddress); } } else if (branchInfo.HasFlag(DynarecBranchAnalyzer.JumpFlags.SyscallInstruction)) { // On this special Syscall if (instruction.Code == SyscallInfo.NativeCallSyscallCode) { //PC += 4; goto HandleNewBranch; } } // Jump-Always found. And we have also processed the delayed branch slot. End the branch. if (endOfBranchFound) { endOfBranchFound = false; goto HandleNewBranch; } } } //Console.WriteLine("FunctionSegment({0:X8}-{1:X8})", MinPC, MaxPC); foreach (var labelAddress in _labelsJump.Keys.ToArray()) { if (!AddressInsideFunction(labelAddress)) { _labelsJump.Remove(labelAddress); } } _cpuEmitter.BranchCount = _labels.Count; }
/// <summary> /// /// </summary> public override void InitializeComponent() { this.Config = PspEmulatorContext.PspConfig; this.Memory = PspEmulatorContext.GetInstance<PspMemory>(); this.TextureCache = PspEmulatorContext.GetInstance<TextureCache>(); this.VertexReader = new VertexReader(); }
public AstNodeExpr MemoryGetValue(Type type, PspMemory memory, AstNodeExpr address) => MemoryGetPointerRef(type, memory, address);
public AstNodeStm MemorySetValue <T>(PspMemory memory, AstNodeExpr address, AstNodeExpr value) => MemorySetValue(typeof(T), memory, address, value);
public AstNodeStm MemorySetValue(Type type, PspMemory memory, AstNodeExpr address, AstNodeExpr value) => Ast.Assign( MemoryGetPointerRef(type, memory, address), Ast.Cast(type, value, false) );
private void _Patch(PspMemory PspMemory) { uint Info = this.Code & 0x0FFFFFFF; //uint Address = 0x08804000 + Info; uint Address = 0x08800000 + Info; try { switch (OpCode) { // [t]8-bit Constant Write 0x0aaaaaaa 0x000000dd case 0x0: PspMemory.WriteSafe(Address, (byte)BitUtils.Extract(Values[0], 0, 8)); break; // [t]16-bit Constant write 0x1aaaaaaa 0x0000dddd case 0x1: PspMemory.WriteSafe(Address, (ushort)BitUtils.Extract(Values[0], 0, 16)); break; // [t]32-bit Constant write 0x2aaaaaaa 0xdddddddd case 0x2: PspMemory.WriteSafe(Address, (uint)BitUtils.Extract(Values[0], 0, 32)); break; // 32-bit Multi-Address Write/Value increase 0x4aaaaaaa 0xxxxxyyyy 0xdddddddd 0xIIIIIIII case 0x4: { var Count = BitUtils.Extract(Values[0], 16, 16); var Increment = BitUtils.Extract(Values[0], 0, 16); var Value = BitUtils.Extract(Values[1], 0, 32); var IncrementValue = BitUtils.Extract(Values[2], 0, 32); for (int n = 0; n < Count; n++) { PspMemory.WriteSafe((uint)(Address + n * Increment), (uint)(Value + IncrementValue * n)); } } break; case 0x8: // 16-bit Multi-Address Write/Value increas 0x8aaaaaaa 0xxxxxyyyy 0x1000dddd 0xIIIIIIII if (BitUtils.Extract(Values[1], 28, 4) == 1) { var Count = BitUtils.Extract(Values[0], 16, 16); var Increment = BitUtils.Extract(Values[0], 0, 16); var Value = BitUtils.Extract(Values[1], 0, 16); var IncrementValue = BitUtils.Extract(Values[2], 0, 32); for (int n = 0; n < Count; n++) { PspMemory.WriteSafe((uint)(Address + n * Increment), (ushort)(Value + IncrementValue * n)); } } // 8-bit Multi-Address Write/Value increase 0x8aaaaaaa 0xxxxxyyyy 0x000000dd 0xIIIIIIII else { var Count = BitUtils.Extract(Values[0], 16, 16); var Increment = BitUtils.Extract(Values[0], 0, 16); var Value = BitUtils.Extract(Values[1], 0, 8); var IncrementValue = BitUtils.Extract(Values[2], 0, 32); for (int n = 0; n < Count; n++) { PspMemory.WriteSafe((uint)(Address + n * Increment), (byte)(Value + IncrementValue * n)); } } break; // 16-bit XOR - 0x7aaaaaaa 0x0005vvvv // 8-bit XOR - 0x7aaaaaaa 0x000400vv // 16-bit AND - 0x7aaaaaaa 0x0003vvvv // 8-bit AND - 0x7aaaaaaa 0x000200vv // 16-bit OR - 0x7aaaaaaa 0x0001vvvv // 8-bit OR - 0x7aaaaaaa 0x000000vv case 0x7: { uint SubOpCode = (Values[0] >> 16) & 0xFFFF; uint SubValue = (Values[0] >> 0) & 0xFFFF; switch (SubOpCode) { // 8-bit OR - 0x7aaaaaaa 0x000000vv case 0: PspMemory.WriteSafe(Address, (byte)(PspMemory.ReadSafe<byte>(Address) | (SubValue & 0xFF))); break; default: Console.Error.WriteLine("Invalid CWCheatOpCode: 0x{0:X} : 0x{1:X}", OpCode, SubOpCode); break; } } break; default: Console.Error.WriteLine("Invalid CWCheatOpCode: 0x{0:X}", OpCode); break; } } catch (Exception Exception) { throw (new Exception(String.Format("At Address: 0x{0:X}", Address), Exception)); } }
public override void InitializeComponent() { this.PspConfig = PspEmulatorContext.PspConfig; this.Memory = PspEmulatorContext.GetInstance <PspMemory>(); Reset(); }
public AstNodeExpr MemoryGetPointer(PspMemory memory, AstNodeExpr address) => MemoryGetPointer(memory, address, false);
public PspMemoryStream(PspMemory Memory) { this.Memory = Memory; }
public SceMpeg* GetSceMpeg(PspMemory PspMemory) { return (SceMpeg *)PspMemory.PspPointerToPointerSafe(SceMpeg); }
public AstNodeExpr MemoryGetValue <T>(PspMemory memory, AstNodeExpr address) => MemoryGetValue(typeof(T), memory, address);
/// <summary> /// /// </summary> /// <param name="PspConfig"></param> /// <param name="Memory"></param> public override void InitializeComponent() { if (sizeof(GpuStateStruct) > sizeof(uint) * 512) { throw (new InvalidProgramException("GpuStateStruct too big. Maybe x64? . Size: " + sizeof(GpuStateStruct))); } this.PspConfig = PspEmulatorContext.PspConfig; this.Memory = PspEmulatorContext.GetInstance<PspMemory>(); this.GpuImpl = PspEmulatorContext.GetInstance<GpuImpl>(); this.DisplayListQueue = new LinkedList<GpuDisplayList>(); this.DisplayListFreeQueue = new Queue<GpuDisplayList>(); for (int n = 0; n < DisplayLists.Length; n++) { var DisplayList = new GpuDisplayList(Memory, this, n); this.DisplayLists[n] = DisplayList; //this.DisplayListFreeQueue.Enqueue(DisplayLists[n]); EnqueueFreeDisplayList(DisplayLists[n]); } }
private void _Patch(PspMemory PspMemory) { uint Info = this.Code & 0x0FFFFFFF; //uint Address = 0x08804000 + Info; uint Address = 0x08800000 + Info; try { switch (OpCode) { // [t]8-bit Constant Write 0x0aaaaaaa 0x000000dd case 0x0: PspMemory.WriteSafe(Address, (byte)BitUtils.Extract(Values[0], 0, 8)); break; // [t]16-bit Constant write 0x1aaaaaaa 0x0000dddd case 0x1: PspMemory.WriteSafe(Address, (ushort)BitUtils.Extract(Values[0], 0, 16)); break; // [t]32-bit Constant write 0x2aaaaaaa 0xdddddddd case 0x2: PspMemory.WriteSafe(Address, (uint)BitUtils.Extract(Values[0], 0, 32)); break; // 32-bit Multi-Address Write/Value increase 0x4aaaaaaa 0xxxxxyyyy 0xdddddddd 0xIIIIIIII case 0x4: { var Count = BitUtils.Extract(Values[0], 16, 16); var Increment = BitUtils.Extract(Values[0], 0, 16); var Value = BitUtils.Extract(Values[1], 0, 32); var IncrementValue = BitUtils.Extract(Values[2], 0, 32); for (int n = 0; n < Count; n++) { PspMemory.WriteSafe((uint)(Address + n * Increment), (uint)(Value + IncrementValue * n)); } } break; case 0x8: // 16-bit Multi-Address Write/Value increas 0x8aaaaaaa 0xxxxxyyyy 0x1000dddd 0xIIIIIIII if (BitUtils.Extract(Values[1], 28, 4) == 1) { var Count = BitUtils.Extract(Values[0], 16, 16); var Increment = BitUtils.Extract(Values[0], 0, 16); var Value = BitUtils.Extract(Values[1], 0, 16); var IncrementValue = BitUtils.Extract(Values[2], 0, 32); for (int n = 0; n < Count; n++) { PspMemory.WriteSafe((uint)(Address + n * Increment), (ushort)(Value + IncrementValue * n)); } } // 8-bit Multi-Address Write/Value increase 0x8aaaaaaa 0xxxxxyyyy 0x000000dd 0xIIIIIIII else { var Count = BitUtils.Extract(Values[0], 16, 16); var Increment = BitUtils.Extract(Values[0], 0, 16); var Value = BitUtils.Extract(Values[1], 0, 8); var IncrementValue = BitUtils.Extract(Values[2], 0, 32); for (int n = 0; n < Count; n++) { PspMemory.WriteSafe((uint)(Address + n * Increment), (byte)(Value + IncrementValue * n)); } } break; // 16-bit XOR - 0x7aaaaaaa 0x0005vvvv // 8-bit XOR - 0x7aaaaaaa 0x000400vv // 16-bit AND - 0x7aaaaaaa 0x0003vvvv // 8-bit AND - 0x7aaaaaaa 0x000200vv // 16-bit OR - 0x7aaaaaaa 0x0001vvvv // 8-bit OR - 0x7aaaaaaa 0x000000vv case 0x7: { uint SubOpCode = (Values[0] >> 16) & 0xFFFF; uint SubValue = (Values[0] >> 0) & 0xFFFF; switch (SubOpCode) { // 8-bit OR - 0x7aaaaaaa 0x000000vv case 0: PspMemory.WriteSafe(Address, (byte)(PspMemory.ReadSafe <byte>(Address) | (SubValue & 0xFF))); break; default: Console.Error.WriteLine("Invalid CWCheatOpCode: 0x{0:X} : 0x{1:X}", OpCode, SubOpCode); break; } } break; default: Console.Error.WriteLine("Invalid CWCheatOpCode: 0x{0:X}", OpCode); break; } } catch (Exception Exception) { throw new Exception($"At Address: 0x{Address:X}", Exception); } }
public override void InitializeComponent() { PspMemory = PspEmulatorContext.GetInstance<PspMemory>(); }
//Action[] InstructionSwitch = new Action[256]; /// <summary> /// Constructor /// </summary> internal GpuDisplayList(PspMemory Memory, GpuProcessor GpuProcessor, int Id) { this.Memory = Memory; this.GpuProcessor = GpuProcessor; this.Id = Id; this.GlobalGpuState = GpuProcessor.GlobalGpuState; this.GpuDisplayListRunner = new GpuDisplayListRunner(this, GpuProcessor.GlobalGpuState); }
public SceMpeg *GetSceMpeg(PspMemory PspMemory) { return((SceMpeg *)PspMemory.PspPointerToPointerSafe(SceMpeg)); }
public override void InitializeComponent() { this.PspConfig = PspEmulatorContext.PspConfig; this.Memory = PspEmulatorContext.GetInstance<PspMemory>(); Reset(); }
public override void InitializeComponent() { PspMemory = PspEmulatorContext.GetInstance <PspMemory>(); }
public AstNodeExprLValue MemoryGetPointerRef(Type type, PspMemory memory, AstNodeExpr address) => Ast.Indirect(Ast.Cast(type.MakePointerType(), MemoryGetPointer(memory, address), false));
public AstRegisterReader(MethodInfo MethodInfo, PspMemory PspMemory) { this.MethodInfo = MethodInfo; this.PspMemory = PspMemory; }
private DynarecFunction _GenerateForPC(uint pc) { var memory = _cpuProcessor.Memory; if (DynarecConfig.DebugFunctionCreation) { Console.Write("PC=0x{0:X8}...", pc); } //var Stopwatch = new Logger.Stopwatch(); var time0 = DateTime.UtcNow; var dynarecFunction = _cpuProcessor.DynarecFunctionCompiler.CreateFunction( new InstructionStreamReader(new PspMemoryStream(memory)), pc); if (dynarecFunction.EntryPc != pc) { throw (new Exception("Unexpected error")); } if (DynarecConfig.AllowCreatingUsedFunctionsInBackground) { foreach (var callingPc in dynarecFunction.CallingPCs) { if (PspMemory.IsAddressValid(callingPc)) { AddPcLater(callingPc); } } } var time1 = DateTime.UtcNow; if (DynarecConfig.ImmediateLinking) { try { if (Platform.IsMono) { Marshal.Prelink(dynarecFunction.Delegate.Method); } dynarecFunction.Delegate(null); } catch (InvalidProgramException) { Console.Error.WriteLine("Invalid delegate:"); Console.Error.WriteLine(dynarecFunction.AstNode.ToCSharpString()); Console.Error.WriteLine(dynarecFunction.AstNode.ToIlString <Action <CpuThreadState> >()); throw; } } var time2 = DateTime.UtcNow; dynarecFunction.TimeLinking = time2 - time1; var timeAstGeneration = time1 - time0; if (DynarecConfig.DebugFunctionCreation) { ConsoleUtils.SaveRestoreConsoleColor( (timeAstGeneration + dynarecFunction.TimeLinking).TotalMilliseconds > 10 ? ConsoleColor.Red : ConsoleColor.Gray, () => { Console.WriteLine( "({0}): (analyze: {1}, generateAST: {2}, optimize: {3}, generateIL: {4}, createDelegate: {5}, link: {6}): ({1}, {2}, {3}, {4}, {5}, {6}) : {7} ms", (dynarecFunction.MaxPc - dynarecFunction.MinPc) / 4, (int)dynarecFunction.TimeAnalyzeBranches.TotalMilliseconds, (int)dynarecFunction.TimeGenerateAst.TotalMilliseconds, (int)dynarecFunction.TimeOptimize.TotalMilliseconds, (int)dynarecFunction.TimeGenerateIl.TotalMilliseconds, (int)dynarecFunction.TimeCreateDelegate.TotalMilliseconds, (int)dynarecFunction.TimeLinking.TotalMilliseconds, (int)(timeAstGeneration + dynarecFunction.TimeLinking).TotalMilliseconds ); }); } //DynarecFunction.AstNode = DynarecFunction.AstNode.Optimize(CpuProcessor); #if DEBUG_FUNCTION_CREATION CpuProcessor.DebugFunctionCreation = true; #endif //if (CpuProcessor.DebugFunctionCreation) //{ // Console.WriteLine("-------------------------------------"); // Console.WriteLine("Created function for PC=0x{0:X8}", PC); // Console.WriteLine("-------------------------------------"); // CpuThreadState.DumpRegistersCpu(Console.Out); // Console.WriteLine("-------------------------------------"); // Console.WriteLine(DynarecFunction.AstNode.ToCSharpString()); // Console.WriteLine("-------------------------------------"); //} return(dynarecFunction); }
public AstNodeExprLValue MemoryGetPointerRef <TType>(PspMemory memory, AstNodeExpr address) => MemoryGetPointerRef(typeof(TType), memory, address);