aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs
diff options
context:
space:
mode:
authorThomas Guillemard <me@thog.eu>2019-10-08 05:48:49 +0200
committerjduncanator <1518948+jduncanator@users.noreply.github.com>2019-10-08 14:48:49 +1100
commit1aba033ba7868d29f5f840c99ee11dd29d689972 (patch)
treea11692bbf3ba7d8f7d2780193356f112cfbb3356 /Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs
parent16869402bf81716ba3d1410621a3b1847bee389c (diff)
Update time implementation to 9.0.0 (#783)
* Fix 9.0.0 related services bindings This was wrong because of a mistake on switchbrew. * Fix wronog cmdid for ISteadyClock::GetTestOffset/SetTestOffset * Update ClockCore logics to 9.0.0 Also apply 9.0.0 permissions and comment time:u, and time:a (as those are going to be moved) * Move every clocks instances + timezone to a global manager * Start implementing time:m Also prepare the skeleton of the shared memory * Implement SystemClockContextUpdateCallback and co * Update StaticService to 9.0.0 * Update ISystemClock to 9.0.0 * Rename IStaticService and add glue's IStaticService * Implement psc's ITimeZoneService * Integrate psc layer into glue for TimeZoneService * Rename TimeZoneManagerForPsc => TimeZoneManager * Use correct TimeZoneService interface for both StaticService implementations * Accurately implement time shared memory operations * Fix two critical flaws in TimeZone logic The first one was the month range being different fron Nintendo one (0-11 instead of 1-12) The other flaw was a bad incrementation order during days & months computation. * Follow Nintendo's abort logic for TimeManager * Avoid crashing when timezone sysarchive isn't present * Update Readme * Address comments * Correctly align fields in ISystemClock * Fix code style and some typos * Improve timezone system archive warning/error messages * Rearrange using definitions in Horizon.cs * Address comments
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs')
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs142
1 files changed, 142 insertions, 0 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs b/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs
new file mode 100644
index 00000000..7acb0257
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Time/StaticService/ITimeZoneServiceForGlue.cs
@@ -0,0 +1,142 @@
+using ARMeilleure.Memory;
+using Ryujinx.Common;
+using Ryujinx.Common.Logging;
+using Ryujinx.HLE.HOS.Services.Time.TimeZone;
+using System;
+using System.Text;
+
+namespace Ryujinx.HLE.HOS.Services.Time.StaticService
+{
+ class ITimeZoneServiceForGlue : IpcService
+ {
+ private TimeZoneContentManager _timeZoneContentManager;
+ private ITimeZoneServiceForPsc _inner;
+ private bool _writePermission;
+
+ public ITimeZoneServiceForGlue(TimeZoneContentManager timeZoneContentManager, bool writePermission)
+ {
+ _timeZoneContentManager = timeZoneContentManager;
+ _writePermission = writePermission;
+ _inner = new ITimeZoneServiceForPsc(timeZoneContentManager.Manager, writePermission);
+ }
+
+ [Command(0)]
+ // GetDeviceLocationName() -> nn::time::LocationName
+ public ResultCode GetDeviceLocationName(ServiceCtx context)
+ {
+ return _inner.GetDeviceLocationName(context);
+ }
+
+ [Command(1)]
+ // SetDeviceLocationName(nn::time::LocationName)
+ public ResultCode SetDeviceLocationName(ServiceCtx context)
+ {
+ if (!_writePermission)
+ {
+ return ResultCode.PermissionDenied;
+ }
+
+ string locationName = Encoding.ASCII.GetString(context.RequestData.ReadBytes(0x24)).TrimEnd('\0');
+
+ return _timeZoneContentManager.SetDeviceLocationName(locationName);
+ }
+
+ [Command(2)]
+ // GetTotalLocationNameCount() -> u32
+ public ResultCode GetTotalLocationNameCount(ServiceCtx context)
+ {
+ return _inner.GetTotalLocationNameCount(context);
+ }
+
+ [Command(3)]
+ // LoadLocationNameList(u32 index) -> (u32 outCount, buffer<nn::time::LocationName, 6>)
+ public ResultCode LoadLocationNameList(ServiceCtx context)
+ {
+ uint index = context.RequestData.ReadUInt32();
+ long bufferPosition = context.Request.ReceiveBuff[0].Position;
+ long bufferSize = context.Request.ReceiveBuff[0].Size;
+
+ ResultCode errorCode = _timeZoneContentManager.LoadLocationNameList(index, out string[] locationNameArray, (uint)bufferSize / 0x24);
+
+ if (errorCode == 0)
+ {
+ uint offset = 0;
+
+ foreach (string locationName in locationNameArray)
+ {
+ int padding = 0x24 - locationName.Length;
+
+ if (padding < 0)
+ {
+ return ResultCode.LocationNameTooLong;
+ }
+
+ context.Memory.WriteBytes(bufferPosition + offset, Encoding.ASCII.GetBytes(locationName));
+ MemoryHelper.FillWithZeros(context.Memory, bufferPosition + offset + locationName.Length, padding);
+
+ offset += 0x24;
+ }
+
+ context.ResponseData.Write((uint)locationNameArray.Length);
+ }
+
+ return errorCode;
+ }
+
+ [Command(4)]
+ // LoadTimeZoneRule(nn::time::LocationName locationName) -> buffer<nn::time::TimeZoneRule, 0x16>
+ public ResultCode LoadTimeZoneRule(ServiceCtx context)
+ {
+ long bufferPosition = context.Request.ReceiveBuff[0].Position;
+ long bufferSize = context.Request.ReceiveBuff[0].Size;
+
+ if (bufferSize != 0x4000)
+ {
+ // TODO: find error code here
+ Logger.PrintError(LogClass.ServiceTime, $"TimeZoneRule buffer size is 0x{bufferSize:x} (expected 0x4000)");
+
+ throw new InvalidOperationException();
+ }
+
+ string locationName = Encoding.ASCII.GetString(context.RequestData.ReadBytes(0x24)).TrimEnd('\0');
+
+ ResultCode resultCode = _timeZoneContentManager.LoadTimeZoneRule(out TimeZoneRule rules, locationName);
+
+ // Write TimeZoneRule if success
+ if (resultCode == ResultCode.Success)
+ {
+ MemoryHelper.Write(context.Memory, bufferPosition, rules);
+ }
+
+ return resultCode;
+ }
+
+ [Command(100)]
+ // ToCalendarTime(nn::time::PosixTime time, buffer<nn::time::TimeZoneRule, 0x15> rules) -> (nn::time::CalendarTime, nn::time::sf::CalendarAdditionalInfo)
+ public ResultCode ToCalendarTime(ServiceCtx context)
+ {
+ return _inner.ToCalendarTime(context);
+ }
+
+ [Command(101)]
+ // ToCalendarTimeWithMyRule(nn::time::PosixTime) -> (nn::time::CalendarTime, nn::time::sf::CalendarAdditionalInfo)
+ public ResultCode ToCalendarTimeWithMyRule(ServiceCtx context)
+ {
+ return _inner.ToCalendarTimeWithMyRule(context);
+ }
+
+ [Command(201)]
+ // ToPosixTime(nn::time::CalendarTime calendarTime, buffer<nn::time::TimeZoneRule, 0x15> rules) -> (u32 outCount, buffer<nn::time::PosixTime, 0xa>)
+ public ResultCode ToPosixTime(ServiceCtx context)
+ {
+ return _inner.ToPosixTime(context);
+ }
+
+ [Command(202)]
+ // ToPosixTimeWithMyRule(nn::time::CalendarTime calendarTime) -> (u32 outCount, buffer<nn::time::PosixTime, 0xa>)
+ public ResultCode ToPosixTimeWithMyRule(ServiceCtx context)
+ {
+ return _inner.ToPosixTimeWithMyRule(context);
+ }
+ }
+} \ No newline at end of file