aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Core/Switch.cs
blob: a755ea0c747230841c014364a8bb8f584414e68f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Ryujinx.Audio;
using Ryujinx.Core.Input;
using Ryujinx.Core.Logging;
using Ryujinx.Core.OsHle;
using Ryujinx.Core.Settings;
using Ryujinx.Graphics.Gal;
using Ryujinx.Core.Gpu;
using System;

namespace Ryujinx.Core
{
    public class Switch : IDisposable
    {
        internal IAalOutput AudioOut { get; private set; }

        public Logger Log { get; private set; }

        internal NvGpu Gpu { get; private set; }

        internal VirtualFileSystem VFs { get; private set; }

        public Horizon Os { get; private set; }

        public SystemSettings Settings { get; private set; }

        public PerformanceStatistics Statistics { get; private set; }

        public Hid Hid { get; private set; }

        public event EventHandler Finish;

        public Switch(IGalRenderer Renderer, IAalOutput AudioOut)
        {
            if (Renderer == null)
            {
                throw new ArgumentNullException(nameof(Renderer));
            }

            if (AudioOut == null)
            {
                throw new ArgumentNullException(nameof(AudioOut));
            }

            this.AudioOut = AudioOut;

            Log = new Logger();

            Gpu = new NvGpu(Renderer);

            VFs = new VirtualFileSystem();

            Os = new Horizon(this);

            Settings = new SystemSettings();

            Statistics = new PerformanceStatistics();

            Hid = new Hid(Log);

            Os.HidSharedMem.MemoryMapped   += Hid.ShMemMap;
            Os.HidSharedMem.MemoryUnmapped += Hid.ShMemUnmap;
        }

        public void LoadCart(string ExeFsDir, string RomFsFile = null)
        {
            Os.LoadCart(ExeFsDir, RomFsFile);
        }

        public void LoadProgram(string FileName)
        {
            Os.LoadProgram(FileName);
        }

        internal virtual void OnFinish(EventArgs e)
        {
            Finish?.Invoke(this, e);
        }

        public void Dispose()
        {
            Dispose(true);
        }

        protected virtual void Dispose(bool Disposing)
        {
            if (Disposing)
            {
                Os.Dispose();
                VFs.Dispose();
            }
        }
    }
}