Switch.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Core.OsHle;
  3. using Ryujinx.Graphics.Gal;
  4. using Ryujinx.Graphics.Gpu;
  5. using System;
  6. using System.Runtime.InteropServices;
  7. namespace Ryujinx.Core
  8. {
  9. public class Switch : IDisposable
  10. {
  11. public IntPtr Ram {get; private set; }
  12. internal NsGpu Gpu { get; private set; }
  13. internal Horizon Os { get; private set; }
  14. internal VirtualFs VFs { get; private set; }
  15. internal Hid Hid { get; private set; }
  16. public event EventHandler Finish;
  17. public Switch(IGalRenderer Renderer)
  18. {
  19. Ram = Marshal.AllocHGlobal((IntPtr)AMemoryMgr.RamSize);
  20. Gpu = new NsGpu(Renderer);
  21. Os = new Horizon(this);
  22. VFs = new VirtualFs();
  23. Hid = new Hid(this);
  24. }
  25. public void FinalizeAllProcesses()
  26. {
  27. Os.FinalizeAllProcesses();
  28. }
  29. public void LoadCart(string ExeFsDir, string RomFsFile = null)
  30. {
  31. Os.LoadCart(ExeFsDir, RomFsFile);
  32. }
  33. public void LoadProgram(string FileName)
  34. {
  35. Os.LoadProgram(FileName);
  36. }
  37. public void SendControllerButtons(HidControllerID ControllerId,
  38. HidControllerLayouts Layout,
  39. HidControllerKeys Buttons,
  40. JoystickPosition LeftJoystick,
  41. JoystickPosition RightJoystick)
  42. {
  43. Hid.SendControllerButtons(ControllerId, Layout, Buttons, LeftJoystick, RightJoystick);
  44. }
  45. internal virtual void OnFinish(EventArgs e)
  46. {
  47. Finish?.Invoke(this, e);
  48. }
  49. public void Dispose()
  50. {
  51. Dispose(true);
  52. }
  53. protected virtual void Dispose(bool disposing)
  54. {
  55. if (disposing)
  56. {
  57. VFs.Dispose();
  58. }
  59. Marshal.FreeHGlobal(Ram);
  60. }
  61. }
  62. }