Beispiel #1
0
        [CommandHipc(300)] // 4.0.0+
        // CalculateMonotonicSystemClockBaseTimePoint(nn::time::SystemClockContext) -> s64
        public ResultCode CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context)
        {
            SteadyClockCore steadyClock = _timeManager.StandardSteadyClock;

            if (!steadyClock.IsInitialized())
            {
                return(ResultCode.UninitializedClock);
            }

            ITickSource tickSource = context.Device.System.TickSource;

            SystemClockContext   otherContext     = context.RequestData.ReadStruct <SystemClockContext>();
            SteadyClockTimePoint currentTimePoint = steadyClock.GetCurrentTimePoint(tickSource);

            ResultCode result = ResultCode.TimeMismatch;

            if (currentTimePoint.ClockSourceId == otherContext.SteadyTimePoint.ClockSourceId)
            {
                TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);
                long         baseTimePoint = otherContext.Offset + currentTimePoint.TimePoint - ticksTimeSpan.ToSeconds();

                context.ResponseData.Write(baseTimePoint);

                result = ResultCode.Success;
            }

            return(result);
        }
Beispiel #2
0
        internal void Initialize(TimeManager timeManager, Switch device)
        {
            InitializeInstance(device.FileSystem, device.System.ContentManager, device.System.FsIntegrityCheckLevel);

            ITickSource tickSource = device.System.TickSource;

            SteadyClockTimePoint timeZoneUpdatedTimePoint = timeManager.StandardSteadyClock.GetCurrentTimePoint(tickSource);

            string deviceLocationName = SanityCheckDeviceLocationName(device.Configuration.TimeZone);

            ResultCode result = GetTimeZoneBinary(deviceLocationName, out Stream timeZoneBinaryStream, out LocalStorage ncaFile);

            if (result == ResultCode.Success)
            {
                // TODO: Read TimeZoneVersion from sysarchive.
                timeManager.SetupTimeZoneManager(deviceLocationName, timeZoneUpdatedTimePoint, (uint)LocationNameCache.Length, new UInt128(), timeZoneBinaryStream);

                ncaFile.Dispose();
            }
            else
            {
                // In the case the user don't have the timezone system archive, we just mark the manager as initialized.
                Manager.MarkInitialized();
            }
        }
Beispiel #3
0
 public BarRow(Timeframes tf, ITickSource tickSrc, int insID)
     : this(tf, insID)
 {
     _tSource         = tickSrc;
     _tSource.OnTick += TSource_Tick;
     _insID           = insID;
 }
Beispiel #4
0
        // SetStandardUserSystemClockAutomaticCorrectionEnabled(b8)
        public ResultCode SetStandardUserSystemClockAutomaticCorrectionEnabled(ServiceCtx context)
        {
            SteadyClockCore             steadyClock = _timeManager.StandardSteadyClock;
            StandardUserSystemClockCore userClock   = _timeManager.StandardUserSystemClock;

            if (!userClock.IsInitialized() || !steadyClock.IsInitialized())
            {
                return(ResultCode.UninitializedClock);
            }

            if ((_permissions & TimePermissions.UserSystemClockWritableMask) == 0)
            {
                return(ResultCode.PermissionDenied);
            }

            bool autoCorrectionEnabled = context.RequestData.ReadBoolean();

            ITickSource tickSource = context.Device.System.TickSource;

            ResultCode result = userClock.SetAutomaticCorrectionEnabled(tickSource, autoCorrectionEnabled);

            if (result == ResultCode.Success)
            {
                _timeManager.SharedMemory.SetAutomaticCorrectionEnabled(autoCorrectionEnabled);

                SteadyClockTimePoint currentTimePoint = userClock.GetSteadyClockCore().GetCurrentTimePoint(tickSource);

                userClock.SetAutomaticCorrectionUpdatedTime(currentTimePoint);
                userClock.SignalAutomaticCorrectionEvent();
            }

            return(result);
        }
Beispiel #5
0
        public static RegisterInfo GetRegisterInfo(ITickSource tickSource, string amiiboId, string nickname)
        {
            VirtualAmiiboFile amiiboFile = LoadAmiiboFile(amiiboId);

            UtilityImpl utilityImpl = new UtilityImpl(tickSource);
            CharInfo    charInfo    = new CharInfo();

            charInfo.SetFromStoreData(StoreData.BuildDefault(utilityImpl, 0));

            charInfo.Nickname = Nickname.FromString(nickname);

            RegisterInfo registerInfo = new RegisterInfo()
            {
                MiiCharInfo     = charInfo,
                FirstWriteYear  = (ushort)amiiboFile.FirstWriteDate.Year,
                FirstWriteMonth = (byte)amiiboFile.FirstWriteDate.Month,
                FirstWriteDay   = (byte)amiiboFile.FirstWriteDate.Day,
                FontRegion      = 0,
                Reserved1       = new Array64 <byte>(),
                Reserved2       = new Array58 <byte>()
            };

            Encoding.ASCII.GetBytes("Ryujinx").CopyTo(registerInfo.Nickname.ToSpan());

            return(registerInfo);
        }
Beispiel #6
0
 public void Initialize(IExecutable executableObject, SetupData setupData, XmlNode setupNode, ITickSource timer)
 {
     this.m_setupData = setupData;
     this.m_setupNode = setupNode;
     this.m_tick      = timer;
     this.UpdateFromSetup();
 }
Beispiel #7
0
        [CommandHipc(400)] // 4.0.0+
        // GetClockSnapshot(u8) -> buffer<nn::time::sf::ClockSnapshot, 0x1a>
        public ResultCode GetClockSnapshot(ServiceCtx context)
        {
            byte type = context.RequestData.ReadByte();

            context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf <ClockSnapshot>());

            ITickSource tickSource = context.Device.System.TickSource;

            ResultCode result = _timeManager.StandardUserSystemClock.GetClockContext(tickSource, out SystemClockContext userContext);

            if (result == ResultCode.Success)
            {
                result = _timeManager.StandardNetworkSystemClock.GetClockContext(tickSource, out SystemClockContext networkContext);

                if (result == ResultCode.Success)
                {
                    result = GetClockSnapshotFromSystemClockContextInternal(tickSource, userContext, networkContext, type, out ClockSnapshot clockSnapshot);

                    if (result == ResultCode.Success)
                    {
                        WriteClockSnapshotFromBuffer(context, context.Request.RecvListBuff[0], clockSnapshot);
                    }
                }
            }

            return(result);
        }
Beispiel #8
0
        [CommandHipc(200)] // 3.0.0+
        // IsStandardNetworkSystemClockAccuracySufficient() -> bool
        public ResultCode IsStandardNetworkSystemClockAccuracySufficient(ServiceCtx context)
        {
            ITickSource tickSource = context.Device.System.TickSource;

            context.ResponseData.Write(_timeManager.StandardNetworkSystemClock.IsStandardNetworkSystemClockAccuracySufficient(tickSource));

            return(ResultCode.Success);
        }
Beispiel #9
0
        public void SetStandardSteadyClockRtcOffset(ITickSource tickSource, TimeSpanType rtcOffset)
        {
            StandardSteadyClock.SetSetupValue(rtcOffset);

            TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(tickSource);

            SharedMemory.SetSteadyClockRawTimePoint(tickSource, currentTimePoint);
        }
Beispiel #10
0
        private ResultCode GetClockSnapshotFromSystemClockContextInternal(ITickSource tickSource, SystemClockContext userContext, SystemClockContext networkContext, byte type, out ClockSnapshot clockSnapshot)
        {
            clockSnapshot = new ClockSnapshot();

            SteadyClockCore      steadyClockCore  = _timeManager.StandardSteadyClock;
            SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(tickSource);

            clockSnapshot.IsAutomaticCorrectionEnabled = _timeManager.StandardUserSystemClock.IsAutomaticCorrectionEnabled();
            clockSnapshot.UserContext          = userContext;
            clockSnapshot.NetworkContext       = networkContext;
            clockSnapshot.SteadyClockTimePoint = currentTimePoint;

            ResultCode result = _timeManager.TimeZone.Manager.GetDeviceLocationName(out string deviceLocationName);

            if (result != ResultCode.Success)
            {
                return(result);
            }

            char[] tzName       = deviceLocationName.ToCharArray();
            char[] locationName = new char[0x24];

            Array.Copy(tzName, locationName, tzName.Length);

            clockSnapshot.LocationName = locationName;

            result = ClockSnapshot.GetCurrentTime(out clockSnapshot.UserTime, currentTimePoint, clockSnapshot.UserContext);

            if (result == ResultCode.Success)
            {
                result = _timeManager.TimeZone.Manager.ToCalendarTimeWithMyRules(clockSnapshot.UserTime, out CalendarInfo userCalendarInfo);

                if (result == ResultCode.Success)
                {
                    clockSnapshot.UserCalendarTime           = userCalendarInfo.Time;
                    clockSnapshot.UserCalendarAdditionalTime = userCalendarInfo.AdditionalInfo;

                    if (ClockSnapshot.GetCurrentTime(out clockSnapshot.NetworkTime, currentTimePoint, clockSnapshot.NetworkContext) != ResultCode.Success)
                    {
                        clockSnapshot.NetworkTime = 0;
                    }

                    result = _timeManager.TimeZone.Manager.ToCalendarTimeWithMyRules(clockSnapshot.NetworkTime, out CalendarInfo networkCalendarInfo);

                    if (result == ResultCode.Success)
                    {
                        clockSnapshot.NetworkCalendarTime           = networkCalendarInfo.Time;
                        clockSnapshot.NetworkCalendarAdditionalTime = networkCalendarInfo.AdditionalInfo;
                        clockSnapshot.Type = type;

                        // Probably a version field?
                        clockSnapshot.Unknown = 0;
                    }
                }
            }

            return(result);
        }
Beispiel #11
0
        public ResultCode InitializeDatabase(ITickSource tickSource, HorizonClient horizonClient)
        {
            _utilityImpl = new UtilityImpl(tickSource);
            _miiDatabase.InitializeDatabase(horizonClient);
            _miiDatabase.LoadFromFile(out _isBroken);

            // Nintendo ignores any error code from before.
            return(ResultCode.Success);
        }
Beispiel #12
0
        public void SetSteadyClockRawTimePoint(ITickSource tickSource, TimeSpanType currentTimePoint)
        {
            SteadyClockContext context       = ReadObjectFromSharedMemory <SteadyClockContext>(SteadyClockContextOffset, 4);
            TimeSpanType       ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);

            context.InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds);

            WriteObjectToSharedMemory(SteadyClockContextOffset, 4, context);
        }
Beispiel #13
0
        public SteadyClockTimePoint GetCurrentTimePoint(ITickSource tickSource)
        {
            SteadyClockTimePoint result = GetTimePoint(tickSource);

            result.TimePoint += GetTestOffset().ToSeconds();
            result.TimePoint += GetInternalOffset().ToSeconds();

            return(result);
        }
Beispiel #14
0
 public void Initialize(IExecutable executableObject, SetupData setupData, XmlNode setupNode, ITickSource timer)
 {
     this.m_executable         = executableObject;
     this.m_timer              = timer;
     this.m_setupData          = setupData;
     this.m_setupNode          = setupNode;
     this.m_portAddress        = (ushort)this.m_setupData.GetInteger(this.m_setupNode, "address", 0x378);
     this.m_useWithScript      = this.m_setupData.GetBoolean(this.m_setupNode, "useWithScript", false);
     executableObject.UserData = this.m_frames;
 }
        public BufferQueueProducer(BufferQueueCore core, ITickSource tickSource)
        {
            Core        = core;
            _tickSource = tickSource;

            _stickyTransform       = 0;
            _callbackTicket        = 0;
            _nextCallbackTicket    = 0;
            _currentCallbackTicket = 0;
        }
        public override SteadyClockTimePoint GetTimePoint(ITickSource tickSource)
        {
            SteadyClockTimePoint result = new SteadyClockTimePoint
            {
                TimePoint     = GetCurrentRawTimePoint(tickSource).ToSeconds(),
                ClockSourceId = GetClockSourceId()
            };

            return(result);
        }
Beispiel #17
0
 public void Initialize(IExecutable executableObject, SetupData setupData, XmlNode setupNode, ITickSource timer)
 {
     this.m_executable = executableObject;
     this.m_timer = timer;
     this.m_setupData = setupData;
     this.m_setupNode = setupNode;
     this.m_portAddress = (ushort) this.m_setupData.GetInteger(this.m_setupNode, "address", 0x378);
     this.m_useWithScript = this.m_setupData.GetBoolean(this.m_setupNode, "useWithScript", false);
     executableObject.UserData = this.m_frames;
 }
Beispiel #18
0
        public void SetupStandardSteadyClock(ITickSource tickSource, UInt128 clockSourceId, TimeSpanType setupValue, TimeSpanType internalOffset, TimeSpanType testOffset, bool isRtcResetDetected)
        {
            SetupInternalStandardSteadyClock(clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);

            TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(tickSource);

            SharedMemory.SetupStandardSteadyClock(tickSource, clockSourceId, currentTimePoint);

            // TODO: propagate IPC late binding of "time:s" and "time:p"
        }
        // SetStandardSteadyClockRtcOffset(nn::TimeSpanType rtc_offset)
        public ResultCode SetStandardSteadyClockRtcOffset(ServiceCtx context)
        {
            TimeSpanType rtcOffset = context.RequestData.ReadStruct <TimeSpanType>();

            ITickSource tickSource = context.Device.System.TickSource;

            _timeManager.SetStandardSteadyClockRtcOffset(tickSource, rtcOffset);

            return(ResultCode.Success);
        }
Beispiel #20
0
        public UtilityImpl(ITickSource tickSource)
        {
            _x = 123456789;
            _y = 362436069;

            TimeSpanType time = TimeManager.Instance.TickBasedSteadyClock.GetCurrentRawTimePoint(tickSource);

            _w = (uint)(time.NanoSeconds & uint.MaxValue);
            _z = (uint)((time.NanoSeconds >> 32) & uint.MaxValue);
        }
Beispiel #21
0
        public KernelContext(
            ITickSource tickSource,
            Switch device,
            MemoryBlock memory,
            MemorySize memorySize,
            MemoryArrange memoryArrange)
        {
            TickSource = tickSource;
            Device     = device;
            Memory     = memory;

            Running = true;

            Syscall = new Syscall(this);

            SyscallHandler = new SyscallHandler(this);

            ResourceLimit = new KResourceLimit(this);

            KernelInit.InitializeResourceLimit(ResourceLimit, memorySize);

            MemoryManager = new KMemoryManager(memorySize, memoryArrange);

            LargeMemoryBlockSlabManager = new KMemoryBlockSlabManager(KernelConstants.MemoryBlockAllocatorSize * 2);
            SmallMemoryBlockSlabManager = new KMemoryBlockSlabManager(KernelConstants.MemoryBlockAllocatorSize);

            UserSlabHeapPages = new KSlabHeap(
                KernelConstants.UserSlabHeapBase,
                KernelConstants.UserSlabHeapItemSize,
                KernelConstants.UserSlabHeapSize);

            memory.Commit(KernelConstants.UserSlabHeapBase - DramMemoryMap.DramBase, KernelConstants.UserSlabHeapSize);

            CriticalSection  = new KCriticalSection(this);
            Schedulers       = new KScheduler[KScheduler.CpuCoresCount];
            PriorityQueue    = new KPriorityQueue();
            TimeManager      = new KTimeManager(this);
            Synchronization  = new KSynchronization(this);
            ContextIdManager = new KContextIdManager();

            for (int core = 0; core < KScheduler.CpuCoresCount; core++)
            {
                Schedulers[core] = new KScheduler(this, core);
            }

            StartPreemptionThread();

            KernelInitialized = true;

            Processes       = new ConcurrentDictionary <ulong, KProcess>();
            AutoObjectNames = new ConcurrentDictionary <string, KAutoObject>();

            _kipId     = KernelConstants.InitialKipId;
            _processId = KernelConstants.InitialProcessId;
        }
        public ResultCode SetAutomaticCorrectionEnabled(ITickSource tickSource, bool autoCorrectionEnabled)
        {
            ResultCode result = ApplyAutomaticCorrection(tickSource, autoCorrectionEnabled);

            if (result == ResultCode.Success)
            {
                _autoCorrectionEnabled = autoCorrectionEnabled;
            }

            return(result);
        }
        // SetupStandardLocalSystemClock(nn::time::SystemClockContext context, nn::time::PosixTime posix_time)
        public ResultCode SetupStandardLocalSystemClock(ServiceCtx context)
        {
            SystemClockContext clockContext = context.RequestData.ReadStruct <SystemClockContext>();
            long posixTime = context.RequestData.ReadInt64();

            ITickSource tickSource = context.Device.System.TickSource;

            _timeManager.SetupStandardLocalSystemClock(tickSource, clockContext, posixTime);

            return(ResultCode.Success);
        }
Beispiel #24
0
        public override void Init(Core core)
        {
            mCore = core;
            base.Init(core);
            mInputSource  = core;
            core.KeyDown += new Action <Core, KeyEventArgs>(mCoordinator_KeyDown);
            core.KeyUp   += new Action <Core, KeyEventArgs>(mCoordinator_KeyUp);

            //if (mEnabled) {
            //core.Tick += mTickListener;
            //}
        }
Beispiel #25
0
        public void SetupStandardSteadyClock(ITickSource tickSource, UInt128 clockSourceId, TimeSpanType currentTimePoint)
        {
            TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);

            SteadyClockContext context = new SteadyClockContext
            {
                InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds),
                ClockSourceId  = clockSourceId
            };

            WriteObjectToSharedMemory(SteadyClockContextOffset, 4, context);
        }
Beispiel #26
0
        public static void Init(ITickSource source)
        {
            if (!sTracking)
            {
                GetController();
                source.Tick += new Action(source_Tick);
                sTracking    = true;

#if DEBUG
                StatisticsCollection.AddStatistics(sStatistics, "GamepadManager");
#endif
            }
        }
        /// <summary>
        /// Create a new <see cref="AudioRendererManager"/>.
        /// </summary>
        /// <param name="tickSource">Tick source used to measure elapsed time.</param>
        public AudioRendererManager(ITickSource tickSource)
        {
            Processor           = new AudioProcessor();
            TickSource          = tickSource;
            _sessionIds         = new int[Constants.AudioRendererSessionCountMax];
            _sessions           = new AudioRenderSystem[Constants.AudioRendererSessionCountMax];
            _activeSessionCount = 0;

            for (int i = 0; i < _sessionIds.Length; i++)
            {
                _sessionIds[i] = i;
            }
        }
Beispiel #28
0
        public bool IsClockSetup(ITickSource tickSource)
        {
            ResultCode result = GetClockContext(tickSource, out SystemClockContext context);

            if (result == ResultCode.Success)
            {
                SteadyClockTimePoint steadyClockTimePoint = _steadyClockCore.GetCurrentTimePoint(tickSource);

                return(steadyClockTimePoint.ClockSourceId == context.SteadyTimePoint.ClockSourceId);
            }

            return(false);
        }
Beispiel #29
0
 public void CloseBarRow()
 {
     if (_tSource != null)
     {
         _tSource.OnTick -= TSource_Tick;
     }
     if (_tDisp != null)
     {
         _tDisp.Unsubscribe(this, _insID);
     }
     _tSource = null;
     _tDisp   = null;
 }
        public override ResultCode GetClockContext(ITickSource tickSource, out SystemClockContext context)
        {
            ResultCode result = ApplyAutomaticCorrection(tickSource, false);

            context = new SystemClockContext();

            if (result == ResultCode.Success)
            {
                return(_localSystemClockCore.GetClockContext(tickSource, out context));
            }

            return(result);
        }
        // SetupStandardSteadyClock(nn::util::Uuid clock_source_id, nn::TimeSpanType setup_value,  nn::TimeSpanType internal_offset,  nn::TimeSpanType test_offset, bool is_rtc_reset_detected)
        public ResultCode SetupStandardSteadyClock(ServiceCtx context)
        {
            UInt128      clockSourceId      = context.RequestData.ReadStruct <UInt128>();
            TimeSpanType setupValue         = context.RequestData.ReadStruct <TimeSpanType>();
            TimeSpanType internalOffset     = context.RequestData.ReadStruct <TimeSpanType>();
            TimeSpanType testOffset         = context.RequestData.ReadStruct <TimeSpanType>();
            bool         isRtcResetDetected = context.RequestData.ReadBoolean();

            ITickSource tickSource = context.Device.System.TickSource;

            _timeManager.SetupStandardSteadyClock(tickSource, clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);

            return(ResultCode.Success);
        }
Beispiel #32
0
 public void Initialize(IExecutable executableObject, SetupData setupData, XmlNode setupNode, ITickSource timer)
 {
     this.m_setupNode = setupNode;
     this.m_setupData = setupData;
     this.m_timer = timer;
     XmlNode node = ((EventSequence) executableObject).Extensions[".led"]["Boards"];
     this.m_useWithScript = node == null;
     if (node != null)
     {
         this.m_boardLayout = new Size(int.Parse(node.Attributes["width"].Value), int.Parse(node.Attributes["height"].Value));
     }
     else
     {
         string[] strArray = this.m_setupData.GetString(this.m_setupNode, "BoardLayout", "1,1").Split(new char[] { ',' });
         this.m_boardLayout = new Size(int.Parse(strArray[0].Trim()), int.Parse(strArray[1].Trim()));
     }
     this.m_ledSize = this.m_setupData.GetInteger(this.m_setupNode, "LEDSize", 3);
     this.m_ledColor = Color.FromArgb(this.m_setupData.GetInteger(this.m_setupNode, "LEDColor", -65536));
     this.m_dotPitch = this.m_setupData.GetInteger(this.m_setupNode, "DotPitch", 9);
     executableObject.UserData = this.m_frames;
     this.m_executable = executableObject;
 }
Beispiel #33
0
 public void Initialize(IExecutable executableObject, SetupData setupData, XmlNode setupNode, ITickSource timer)
 {
     this.m_setupData = setupData;
     this.m_setupNode = setupNode;
     this.m_tick = timer;
     this.UpdateFromSetup();
 }
        public static void Init(ITickSource source)
        {
            if (!sTracking) {
                GetController();
                source.Tick += new Action(source_Tick);
                sTracking = true;

            #if DEBUG
                StatisticsCollection.AddStatistics(sStatistics, "GamepadManager");
            #endif
            }
        }
Beispiel #35
0
 public void Init(ITickSource source)
 {
     GamepadManager.Init(source);
 }