Switch.cs 1.8 KB

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