Switch.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using Ryujinx.Audio;
  2. using Ryujinx.Graphics.Gal;
  3. using Ryujinx.HLE.Font;
  4. using Ryujinx.HLE.Gpu;
  5. using Ryujinx.HLE.Input;
  6. using Ryujinx.HLE.Logging;
  7. using Ryujinx.HLE.OsHle;
  8. using System;
  9. namespace Ryujinx.HLE
  10. {
  11. public class Switch : IDisposable
  12. {
  13. internal IAalOutput AudioOut { get; private set; }
  14. public Logger Log { get; private set; }
  15. internal NvGpu Gpu { get; private set; }
  16. internal VirtualFileSystem VFs { get; private set; }
  17. public Horizon Os { get; private set; }
  18. public PerformanceStatistics Statistics { get; private set; }
  19. public Hid Hid { get; private set; }
  20. public SharedFontManager Font { get; private set; }
  21. public event EventHandler Finish;
  22. public Switch(IGalRenderer Renderer, IAalOutput AudioOut)
  23. {
  24. if (Renderer == null)
  25. {
  26. throw new ArgumentNullException(nameof(Renderer));
  27. }
  28. if (AudioOut == null)
  29. {
  30. throw new ArgumentNullException(nameof(AudioOut));
  31. }
  32. this.AudioOut = AudioOut;
  33. Log = new Logger();
  34. Gpu = new NvGpu(Renderer);
  35. VFs = new VirtualFileSystem();
  36. Os = new Horizon(this);
  37. Statistics = new PerformanceStatistics();
  38. Hid = new Hid(Log);
  39. Font = new SharedFontManager(Log, VFs.GetSystemPath());
  40. Os.HidSharedMem.MemoryMapped += Hid.ShMemMap;
  41. Os.HidSharedMem.MemoryUnmapped += Hid.ShMemUnmap;
  42. Os.FontSharedMem.MemoryMapped += Font.ShMemMap;
  43. Os.FontSharedMem.MemoryUnmapped += Font.ShMemUnmap;
  44. }
  45. public void LoadCart(string ExeFsDir, string RomFsFile = null)
  46. {
  47. Os.LoadCart(ExeFsDir, RomFsFile);
  48. }
  49. public void LoadProgram(string FileName)
  50. {
  51. Os.LoadProgram(FileName);
  52. }
  53. public bool WaitFifo()
  54. {
  55. return Gpu.Fifo.Event.WaitOne(8);
  56. }
  57. public void ProcessFrame()
  58. {
  59. Gpu.Fifo.DispatchCalls();
  60. }
  61. public virtual void OnFinish(EventArgs e)
  62. {
  63. Os.Dispose();
  64. Finish?.Invoke(this, e);
  65. }
  66. public void Dispose()
  67. {
  68. Dispose(true);
  69. }
  70. protected virtual void Dispose(bool Disposing)
  71. {
  72. if (Disposing)
  73. {
  74. Os.Dispose();
  75. VFs.Dispose();
  76. }
  77. }
  78. }
  79. }