Switch.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. public void SendTouchScreenEntry(HidTouchScreenEntryTouch TouchPoint)
  46. {
  47. Hid.SendTouchPoint(TouchPoint);
  48. }
  49. internal virtual void OnFinish(EventArgs e)
  50. {
  51. Finish?.Invoke(this, e);
  52. }
  53. public void Dispose()
  54. {
  55. Dispose(true);
  56. }
  57. protected virtual void Dispose(bool disposing)
  58. {
  59. if (disposing)
  60. {
  61. VFs.Dispose();
  62. }
  63. Marshal.FreeHGlobal(Ram);
  64. }
  65. }
  66. }