diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ISettable.cs index bdc6d40ff0..2aa660953b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ISettable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.ISettable.cs @@ -111,6 +111,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk set { _RTCInitialTime = Math.Max(0, Math.Min(1024 * 24 * 60 * 60, value)); } } + [DisplayName("RTC Offset")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset + { + get { return _RTCOffset; } + set { _RTCOffset = Math.Max(-127, Math.Min(127, value)); } + } + [DisplayName("Timer Div Initial Time")] [Description("Don't change from 0 unless it's hardware accurate. GBA GBC mode is known to be 8.")] [DefaultValue(8)] @@ -128,6 +137,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk [JsonIgnore] private int _RTCInitialTime; + private int _RTCOffset; [JsonIgnore] public ushort _DivInitialTime = 8; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs index 5a14b9ea93..3cb80bf96f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs @@ -470,28 +470,31 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (mppr == "MBC3") { Use_MT = true; + + mapper.RTC_Get(_syncSettings.RTCOffset, 5); + int days = (int)Math.Floor(_syncSettings.RTCInitialTime / 86400.0); int days_upper = ((days & 0x100) >> 8) | ((days & 0x200) >> 2); - mapper.RTC_Get((byte)days_upper, 4); - mapper.RTC_Get((byte)(days & 0xFF), 3); + mapper.RTC_Get(days_upper, 4); + mapper.RTC_Get(days & 0xFF, 3); int remaining = _syncSettings.RTCInitialTime - (days * 86400); int hours = (int)Math.Floor(remaining / 3600.0); - mapper.RTC_Get((byte)(hours & 0xFF), 2); + mapper.RTC_Get(hours & 0xFF, 2); remaining = remaining - (hours * 3600); int minutes = (int)Math.Floor(remaining / 60.0); - mapper.RTC_Get((byte)(minutes & 0xFF), 1); + mapper.RTC_Get(minutes & 0xFF, 1); remaining = remaining - (minutes * 60); - mapper.RTC_Get((byte)(remaining & 0xFF), 0); + mapper.RTC_Get(remaining & 0xFF, 0); } if (mppr == "HuC3") @@ -500,23 +503,23 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk int years = (int)Math.Floor(_syncSettings.RTCInitialTime / 31536000.0); - mapper.RTC_Get((byte)years, 24); + mapper.RTC_Get(years, 24); int remaining = _syncSettings.RTCInitialTime - (years * 31536000); int days = (int)Math.Floor(remaining / 86400.0); int days_upper = (days >> 8) & 0xF; - mapper.RTC_Get((byte)days_upper, 20); - mapper.RTC_Get((byte)(days & 0xFF), 12); + mapper.RTC_Get(days_upper, 20); + mapper.RTC_Get(days & 0xFF, 12); remaining = remaining - (days * 86400); int minutes = (int)Math.Floor(remaining / 60.0); int minutes_upper = (minutes >> 8) & 0xF; - mapper.RTC_Get((byte)(minutes_upper), 8); - mapper.RTC_Get((byte)(remaining & 0xFF), 0); + mapper.RTC_Get(minutes_upper, 8); + mapper.RTC_Get(remaining & 0xFF, 0); } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs index 73e70d1bb6..be4d482e12 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/MapperBase.cs @@ -43,7 +43,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { } - public virtual void RTC_Get(byte value, int index) + public virtual void RTC_Get(int value, int index) { } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs index 5347487ed4..6bcc6e6cd3 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_HuC3.cs @@ -243,7 +243,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - public override void RTC_Get(byte value, int index) + public override void RTC_Get(int value, int index) { time |= (uint)((value & 0xFF) << index); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs index 18fb03e603..1bfb5d0e29 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC3.cs @@ -20,6 +20,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public int RTC_timer; public int RTC_low_clock; public bool halt; + public int RTC_offset; public override void Initialize() { @@ -200,9 +201,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk WriteMemory(addr, value); } - public override void RTC_Get(byte value, int index) + public override void RTC_Get(int value, int index) { - RTC_regs[index] = value; + if (index < 5) + { + RTC_regs[index] = (byte)value; + } + else + { + RTC_offset = value; + + Console.WriteLine("RTC: " + RTC_offset); + } } public override void Mapper_Tick() @@ -217,10 +227,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk RTC_low_clock++; - if (RTC_low_clock == 32767) // the RTC appears to be off by one cycle (would be 32768) + if (RTC_low_clock == 32768) { RTC_low_clock = 0; + // adjust for slight RTC error + RTC_timer = RTC_offset; + RTC_regs[0]++; if (RTC_regs[0] > 59) @@ -273,6 +286,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk ser.Sync(nameof(RTC_regs_latch_wr), ref RTC_regs_latch_wr); ser.Sync(nameof(RTC_timer), ref RTC_timer); ser.Sync(nameof(RTC_low_clock), ref RTC_low_clock); + ser.Sync(nameof(RTC_offset), ref RTC_offset); } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.ISettable.cs index 79ab75ecc1..c609a28515 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.ISettable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.ISettable.cs @@ -102,6 +102,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink set { _RTCInitialTime_R = Math.Max(0, Math.Min(1024 * 24 * 60 * 60, value)); } } + [DisplayName("RTC Offset L")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset_L + { + get { return _RTCOffset_L; } + set { _RTCOffset_L = Math.Max(-127, Math.Min(127, value)); } + } + + [DisplayName("RTC Offset R")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset_R + { + get { return _RTCOffset_R; } + set { _RTCOffset_R = Math.Max(-127, Math.Min(127, value)); } + } + [DisplayName("Timer Div Initial Time L")] [Description("Don't change from 0 unless it's hardware accurate. GBA GBC mode is known to be 8.")] [DefaultValue(8)] @@ -128,6 +146,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink [JsonIgnore] private int _RTCInitialTime_L; private int _RTCInitialTime_R; + private int _RTCOffset_L; + private int _RTCOffset_R; [JsonIgnore] public ushort _DivInitialTime_L = 8; public ushort _DivInitialTime_R = 8; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.cs index cfce79de94..a38a4d091e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.cs @@ -56,6 +56,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink temp_sync_R.DivInitialTime = linkSyncSettings.DivInitialTime_R; temp_sync_L.RTCInitialTime = linkSyncSettings.RTCInitialTime_L; temp_sync_R.RTCInitialTime = linkSyncSettings.RTCInitialTime_R; + temp_sync_L.RTCOffset = linkSyncSettings.RTCOffset_L; + temp_sync_R.RTCOffset = linkSyncSettings.RTCOffset_R; L = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, game_L, rom_L, temp_set_L, temp_sync_L); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ISettable.cs index 8e74c66c2b..9c0adf8f7b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ISettable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.ISettable.cs @@ -122,6 +122,33 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x set { _RTCInitialTime_R = Math.Max(0, Math.Min(1024 * 24 * 60 * 60, value)); } } + [DisplayName("RTC Offset L")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset_L + { + get { return _RTCOffset_L; } + set { _RTCOffset_L = Math.Max(-127, Math.Min(127, value)); } + } + + [DisplayName("RTC Offset C")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset_C + { + get { return _RTCOffset_C; } + set { _RTCOffset_C = Math.Max(-127, Math.Min(127, value)); } + } + + [DisplayName("RTC Offset R")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset_R + { + get { return _RTCOffset_R; } + set { _RTCOffset_R = Math.Max(-127, Math.Min(127, value)); } + } + [DisplayName("Timer Div Initial Time L")] [Description("Don't change from 0 unless it's hardware accurate. GBA GBC mode is known to be 8.")] [DefaultValue(8)] @@ -158,6 +185,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x private int _RTCInitialTime_L; private int _RTCInitialTime_C; private int _RTCInitialTime_R; + private int _RTCOffset_L; + private int _RTCOffset_C; + private int _RTCOffset_R; [JsonIgnore] public ushort _DivInitialTime_L = 8; public ushort _DivInitialTime_C = 8; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.cs index f5ef14ac41..e939891b20 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.cs @@ -61,6 +61,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x temp_sync_L.RTCInitialTime = Link3xSyncSettings.RTCInitialTime_L; temp_sync_C.RTCInitialTime = Link3xSyncSettings.RTCInitialTime_C; temp_sync_R.RTCInitialTime = Link3xSyncSettings.RTCInitialTime_R; + temp_sync_L.RTCOffset = Link3xSyncSettings.RTCOffset_L; + temp_sync_C.RTCOffset = Link3xSyncSettings.RTCOffset_C; + temp_sync_R.RTCOffset = Link3xSyncSettings.RTCOffset_R; L = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, game_L, rom_L, temp_set_L, temp_sync_L); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.ISettable.cs index 65239aec31..b509dd1d3c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.ISettable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.ISettable.cs @@ -142,6 +142,42 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x set { _RTCInitialTime_D = Math.Max(0, Math.Min(1024 * 24 * 60 * 60, value)); } } + [DisplayName("RTC Offset A")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset_A + { + get { return _RTCOffset_A; } + set { _RTCOffset_A = Math.Max(-127, Math.Min(127, value)); } + } + + [DisplayName("RTC Offset B")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset_B + { + get { return _RTCOffset_B; } + set { _RTCOffset_B = Math.Max(-127, Math.Min(127, value)); } + } + + [DisplayName("RTC Offset C")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset_C + { + get { return _RTCOffset_C; } + set { _RTCOffset_C = Math.Max(-127, Math.Min(127, value)); } + } + + [DisplayName("RTC Offset D")] + [Description("Set error in RTC clocking (-127 to 127)")] + [DefaultValue(0)] + public int RTCOffset_D + { + get { return _RTCOffset_D; } + set { _RTCOffset_D = Math.Max(-127, Math.Min(127, value)); } + } + [DisplayName("Timer Div Initial Time A")] [Description("Don't change from 0 unless it's hardware accurate. GBA GBC mode is known to be 8.")] [DefaultValue(8)] @@ -188,6 +224,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x private int _RTCInitialTime_B; private int _RTCInitialTime_C; private int _RTCInitialTime_D; + private int _RTCOffset_A; + private int _RTCOffset_B; + private int _RTCOffset_C; + private int _RTCOffset_D; [JsonIgnore] public ushort _DivInitialTime_A = 8; public ushort _DivInitialTime_B = 8; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.cs index cf104fee68..6249d5f305 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.cs @@ -68,6 +68,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x temp_sync_B.RTCInitialTime = Link4xSyncSettings.RTCInitialTime_B; temp_sync_C.RTCInitialTime = Link4xSyncSettings.RTCInitialTime_C; temp_sync_D.RTCInitialTime = Link4xSyncSettings.RTCInitialTime_D; + temp_sync_A.RTCOffset = Link4xSyncSettings.RTCOffset_A; + temp_sync_B.RTCOffset = Link4xSyncSettings.RTCOffset_B; + temp_sync_C.RTCOffset = Link4xSyncSettings.RTCOffset_C; + temp_sync_D.RTCOffset = Link4xSyncSettings.RTCOffset_D; A = new GBHawk.GBHawk(new CoreComm(comm.ShowMessage, comm.Notify) { CoreFileProvider = comm.CoreFileProvider }, game_A, rom_A, temp_set_A, temp_sync_A);