From dd14f8e3af91b15935b1f3a9a1ec275cc0639303 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Sat, 18 Jun 2022 10:40:00 -0700 Subject: [PATCH 01/27] merge SGB into a mode option of Gambatte --- src/BizHawk.Client.Common/movie/import/VbmImport.cs | 7 +++++-- .../Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs | 3 ++- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 11 +++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/import/VbmImport.cs b/src/BizHawk.Client.Common/movie/import/VbmImport.cs index 3226e06a3b9..a65dc39c7d0 100644 --- a/src/BizHawk.Client.Common/movie/import/VbmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/VbmImport.cs @@ -18,6 +18,7 @@ protected override void RunImport() using var fs = SourceFile.Open(FileMode.Open, FileAccess.Read); using var r = new BinaryReader(fs); bool is_GBC = false; + bool is_SGB = false; // 000 4-byte signature: 56 42 4D 1A "VBM\x1A" string signature = new string(r.ReadChars(4)); @@ -124,7 +125,8 @@ recording time in Unix epoch format if (isSGB) { - Result.Errors.Add("SGB imports are not currently supported"); + is_SGB = true; + platform = VSystemID.Raw.SGB; } Result.Movie.HeaderEntries[HeaderKeys.Platform] = platform; @@ -282,7 +284,8 @@ A stream of 2-byte bitvectors which indicate which buttons are pressed at each p case CoreNames.Gambatte: Result.Movie.SyncSettingsJson = ConfigService.SaveWithType(new Gameboy.GambatteSyncSettings { - ConsoleMode = is_GBC ? Gameboy.GambatteSyncSettings.ConsoleModeType.GBC : Gameboy.GambatteSyncSettings.ConsoleModeType.GB, + ConsoleMode = is_SGB ? Gameboy.GambatteSyncSettings.ConsoleModeType.SGB : + is_GBC ? Gameboy.GambatteSyncSettings.ConsoleModeType.GBC : Gameboy.GambatteSyncSettings.ConsoleModeType.GB, }); break; case CoreNames.GbHawk: diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs index e80f937d927..ebef5fa0113 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs @@ -109,12 +109,13 @@ public enum ConsoleModeType { Auto, GB, + SGB, GBC, GBA } [DisplayName("Console Mode")] - [Description("Pick which console to run, 'Auto' chooses from ROM header; 'GB', 'GBC', and 'GBA' chooses the respective system. Does nothing in SGB mode.")] + [Description("Pick which console to run, 'Auto' chooses from ROM header; 'GB', 'SGB', 'GBC', and 'GBA' chooses the respective system.")] [DefaultValue(ConsoleModeType.Auto)] public ConsoleModeType ConsoleMode { get; set; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index 4ba18f628f3..089675b60f3 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -53,6 +53,11 @@ public Gameboy(CoreComm comm, IGameInfo game, byte[] file, GambatteSettings sett { case GambatteSyncSettings.ConsoleModeType.GB: break; + case GambatteSyncSettings.ConsoleModeType.SGB: + flags &= ~(LibGambatte.LoadFlags.CGB_MODE | LibGambatte.LoadFlags.GBA_FLAG); + flags |= LibGambatte.LoadFlags.SGB_MODE; + IsSgb = true; + break; case GambatteSyncSettings.ConsoleModeType.GBC: flags |= LibGambatte.LoadFlags.CGB_MODE; break; @@ -67,11 +72,9 @@ public Gameboy(CoreComm comm, IGameInfo game, byte[] file, GambatteSettings sett throw new InvalidOperationException(); } - if (game.System == VSystemID.Raw.SGB) + if (_syncSettings.MulticartCompat) { - flags &= ~(LibGambatte.LoadFlags.CGB_MODE | LibGambatte.LoadFlags.GBA_FLAG); - flags |= LibGambatte.LoadFlags.SGB_MODE; - IsSgb = true; + flags |= LibGambatte.LoadFlags.MULTICART_COMPAT; } IsCgb = (flags & LibGambatte.LoadFlags.CGB_MODE) == LibGambatte.LoadFlags.CGB_MODE; From 5f95a9385f9408fc12df881c5b871438dae21623 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Sat, 18 Jun 2022 15:30:00 -0700 Subject: [PATCH 02/27] merge the core choices for SGB --- quicknes/core | 2 +- src/BizHawk.Client.Common/RomLoader.cs | 5 ----- src/BizHawk.Client.Common/config/Config.cs | 7 ++----- src/BizHawk.Client.Common/movie/import/LsmvImport.cs | 1 - src/BizHawk.Client.EmuHawk/MainForm.cs | 8 -------- .../Consoles/Nintendo/BSNES/BsnesCore.cs | 3 ++- .../Consoles/Nintendo/SNES/LibsnesCore.cs | 9 +++++---- submodules/gambatte | 2 +- waterbox/melon/melonDS | 2 +- 9 files changed, 12 insertions(+), 27 deletions(-) diff --git a/quicknes/core b/quicknes/core index 027f63aee19..74c1a73fe8b 160000 --- a/quicknes/core +++ b/quicknes/core @@ -1 +1 @@ -Subproject commit 027f63aee19840ac1bf571a5d00d7758ca517220 +Subproject commit 74c1a73fe8baf08ed02b66248b9bf12b4a77076c diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index 159416ac514..8faf6b9cfd1 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -482,11 +482,6 @@ private void LoadOther( ); return; } - - if (_config.GbAsSgb) - { - game.System = VSystemID.Raw.SGB; - } break; case VSystemID.Raw.PSX when ext is ".bin": const string FILE_EXT_CUE = ".cue"; diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index b1d972188a6..84904092a69 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -25,12 +25,10 @@ public class Config /// public static readonly IReadOnlyList<(string[] AppliesTo, string[] CoreNames)> CorePickerUIData = new List<(string[], string[])> { - ([ VSystemID.Raw.GB, VSystemID.Raw.GBC ], - [ CoreNames.Gambatte, CoreNames.Sameboy, CoreNames.GbHawk, CoreNames.SubGbHawk ]), + ([ VSystemID.Raw.GB, VSystemID.Raw.GBC, VSystemID.Raw.SGB ], + [ CoreNames.Gambatte, CoreNames.Sameboy, CoreNames.GbHawk, CoreNames.SubGbHawk, CoreNames.Bsnes, CoreNames.Bsnes115, CoreNames.SubBsnes115 ]), ([ VSystemID.Raw.GBL ], [ CoreNames.GambatteLink, CoreNames.GBHawkLink, CoreNames.GBHawkLink3x, CoreNames.GBHawkLink4x ]), - ([ VSystemID.Raw.SGB ], - [ CoreNames.Gambatte, CoreNames.Bsnes115, CoreNames.SubBsnes115, CoreNames.Bsnes ]), ([ VSystemID.Raw.GEN ], [ CoreNames.Gpgx, CoreNames.PicoDrive ]), ([ VSystemID.Raw.N64 ], @@ -389,7 +387,6 @@ public void SetWindowScaleFor(string sysID, int windowScale) public Dictionary> AllTrollersFeedbacks { get; set; } = new Dictionary>(); /// as this setting spans multiple cores and doesn't actually affect the behavior of any core, it hasn't been absorbed into the new system - public bool GbAsSgb { get; set; } public string LibretroCore { get; set; } public Dictionary PreferredCores = GenDefaultCorePreferences(); diff --git a/src/BizHawk.Client.Common/movie/import/LsmvImport.cs b/src/BizHawk.Client.Common/movie/import/LsmvImport.cs index a863a1369a6..8413d359c03 100644 --- a/src/BizHawk.Client.Common/movie/import/LsmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/LsmvImport.cs @@ -160,7 +160,6 @@ protected override void RunImport() case "sgb_ntsc": case "sgb_pal": platform = VSystemID.Raw.SNES; - Config.GbAsSgb = true; break; } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index f6a4efb3812..3d03e26cb03 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -121,17 +121,9 @@ void ClickHandler(object clickSender, EventArgs clickArgs) CoresSubMenu.DropDownItems.Add(submenu); } CoresSubMenu.DropDownItems.Add(new ToolStripSeparator { AutoSize = true }); - var GBInSGBMenuItem = new ToolStripMenuItem { Text = "GB in SGB" }; - GBInSGBMenuItem.Click += (_, _) => - { - Config.GbAsSgb ^= true; - if (Emulator.SystemId is VSystemID.Raw.GB or VSystemID.Raw.GBC or VSystemID.Raw.SGB) FlagNeedsReboot(); - }; - CoresSubMenu.DropDownItems.Add(GBInSGBMenuItem); var setLibretroCoreToolStripMenuItem = new ToolStripMenuItem { Text = "Set Libretro Core..." }; setLibretroCoreToolStripMenuItem.Click += (_, _) => RunLibretroCoreChooser(); CoresSubMenu.DropDownItems.Add(setLibretroCoreToolStripMenuItem); - CoresSubMenu.DropDownOpened += (_, _) => GBInSGBMenuItem.Checked = Config.GbAsSgb; ToolStripMenuItemEx recentCoreSettingsSubmenu = new() { Text = "Recent" }; recentCoreSettingsSubmenu.DropDownItems.AddRange(CreateCoreSettingsSubmenus().ToArray()); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs index 9834a7e23fd..d238e1a2dac 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs @@ -18,8 +18,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES [ServiceNotApplicable(new[] { typeof(IDriveLight) })] public partial class BsnesCore : IEmulator, IDebuggable, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ISettable, IBSNESForGfxDebugger, IBoardInfo { + [CoreConstructor(VSystemID.Raw.GB)] + [CoreConstructor(VSystemID.Raw.GBC)] [CoreConstructor(VSystemID.Raw.Satellaview)] - [CoreConstructor(VSystemID.Raw.SGB)] [CoreConstructor(VSystemID.Raw.SNES)] public BsnesCore(CoreLoadParameters loadParameters) : this(loadParameters, false) { } public BsnesCore(CoreLoadParameters loadParameters, bool subframe = false) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index 91a956308d5..25f4a3e13fb 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -23,7 +23,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES public unsafe partial class LibsnesCore : IEmulator, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ICodeDataLogger, IDebuggable, ISettable, IBSNESForGfxDebugger { - [CoreConstructor(VSystemID.Raw.SGB)] + [CoreConstructor(VSystemID.Raw.GB)] + [CoreConstructor(VSystemID.Raw.GBC)] [CoreConstructor(VSystemID.Raw.SNES)] public LibsnesCore(GameInfo game, byte[] rom, CoreComm comm, LibsnesCore.SnesSettings settings, LibsnesCore.SnesSyncSettings syncSettings) @@ -46,8 +47,9 @@ public LibsnesCore(GameInfo game, byte[] romData, byte[] xmlData, string baseRom CoreComm = comm; byte[] sgbRomData = null; - if (game.System == VSystemID.Raw.SGB) + if (game.System == VSystemID.Raw.GB || game.System == VSystemID.Raw.GBC) { + IsSGB = true; if ((romData[0x143] & 0xc0) == 0xc0) { throw new CGBNotSupportedException(); @@ -110,9 +112,8 @@ public LibsnesCore(GameInfo game, byte[] romData, byte[] xmlData, string baseRom romData = newData; } - if (game.System == VSystemID.Raw.SGB) + if (IsSGB) { - IsSGB = true; SystemId = VSystemID.Raw.SNES; ser.Register(new SGBBoardInfo()); diff --git a/submodules/gambatte b/submodules/gambatte index 0838651ca7c..e35e24de89f 160000 --- a/submodules/gambatte +++ b/submodules/gambatte @@ -1 +1 @@ -Subproject commit 0838651ca7c06d8c236834dcf5aa307092b2a82e +Subproject commit e35e24de89f06642852f622d7d4159ba6a4abea2 diff --git a/waterbox/melon/melonDS b/waterbox/melon/melonDS index 4e02967468c..3c9510523bf 160000 --- a/waterbox/melon/melonDS +++ b/waterbox/melon/melonDS @@ -1 +1 @@ -Subproject commit 4e02967468c3b5ea853f5fdb0ca0b25a02fd601c +Subproject commit 3c9510523bfbdf7d39e5185dcfbc72146bb8b52f From f8b294f9a3ee786e22db811ce8159bfbf947f164 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Sun, 19 Jun 2022 01:41:52 -0700 Subject: [PATCH 03/27] GBL compatibility --- .../movie/bk2/Bk2MnemonicLookup.cs | 4 +++ .../Gameboy/GambatteLink.IEmulator.cs | 6 ++++- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 26 ++++++++++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2MnemonicLookup.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2MnemonicLookup.cs index 24b5a9254d6..8528d8feabd 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2MnemonicLookup.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2MnemonicLookup.cs @@ -14,6 +14,10 @@ public static char Lookup(string button, string systemId) var key = button.Replace("Key ", ""); if (key.StartsWith('P')) { + if (systemId.Equals(VSystemID.Raw.GBL) && key.Contains("-")) // Deal with SGB in GBL + { + key = key.Substring(5); + } if (key.Length > 2 && key[1] == '1' && key[2] >= '0' && key[2] <= '9') // Hack to support 10-20 controllers, TODO: regex this thing instead { key = key.Substring(4); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index 861bd1d5364..12a89eea822 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -23,7 +23,11 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = { for (int i = 0; i < _numCores; i++) { - if (s.Contains($"P{i + 1} ")) + if (s.Contains($"P{i + 1} -")) + { + _linkedConts[i].Set(s.Replace($"P{i + 1} - ", "")); + } + else if (s.Contains($"P{i + 1} ")) { _linkedConts[i].Set(s.Replace($"P{i + 1} ", "")); } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index cf5d337b9bd..3947da863b6 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -50,7 +50,7 @@ public GambatteLink(CoreLoadParameters $"P{i + 1} {s}")); + if (isSGB(i)) + { + for (int j = 0; j < 4; j++) + { + ret.BoolButtons.AddRange( + new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start" } + .Select(s => $"P{i + 1} - P{j + 1} {s}")); + } + ret.BoolButtons.Add($"P{i + 1} Power"); + } + else + { + ret.BoolButtons.AddRange( + new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start", "Power" } + .Select(s => $"P{i + 1} {s}")); + } } ret.BoolButtons.Add("Toggle Link Connection"); if (_numCores > 2) @@ -160,6 +173,11 @@ private ControllerDefinition CreateControllerDefinition() return ret.MakeImmutable(); } + private Boolean isSGB(int i) + { + return _syncSettings._linkedSyncSettings[i].ConsoleMode.ToString().Equals(VSystemID.Raw.SGB); + } + private const int P1 = 0; private const int P2 = 1; private const int P3 = 2; From eecee3050d30fec5875b0f3807c446c0c8284e34 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Sun, 19 Jun 2022 02:58:58 -0700 Subject: [PATCH 04/27] rename SGB mode to SGB2 for Gambatte and fix BSNES initialization --- src/BizHawk.Client.Common/movie/import/VbmImport.cs | 2 +- .../Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs | 6 +++--- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 9 ++++----- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/import/VbmImport.cs b/src/BizHawk.Client.Common/movie/import/VbmImport.cs index a65dc39c7d0..397c303227b 100644 --- a/src/BizHawk.Client.Common/movie/import/VbmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/VbmImport.cs @@ -284,7 +284,7 @@ A stream of 2-byte bitvectors which indicate which buttons are pressed at each p case CoreNames.Gambatte: Result.Movie.SyncSettingsJson = ConfigService.SaveWithType(new Gameboy.GambatteSyncSettings { - ConsoleMode = is_SGB ? Gameboy.GambatteSyncSettings.ConsoleModeType.SGB : + ConsoleMode = is_SGB ? Gameboy.GambatteSyncSettings.ConsoleModeType.SGB2 : is_GBC ? Gameboy.GambatteSyncSettings.ConsoleModeType.GBC : Gameboy.GambatteSyncSettings.ConsoleModeType.GB, }); break; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs index ebef5fa0113..34bd21002d6 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs @@ -109,13 +109,13 @@ public enum ConsoleModeType { Auto, GB, - SGB, GBC, - GBA + GBA, + SGB2 } [DisplayName("Console Mode")] - [Description("Pick which console to run, 'Auto' chooses from ROM header; 'GB', 'SGB', 'GBC', and 'GBA' chooses the respective system.")] + [Description("Pick which console to run, 'Auto' chooses from ROM header; 'GB', 'GBC', 'GBA', and 'SGB2' chooses the respective system.")] [DefaultValue(ConsoleModeType.Auto)] public ConsoleModeType ConsoleMode { get; set; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index 089675b60f3..db1dde61de4 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -53,17 +53,16 @@ public Gameboy(CoreComm comm, IGameInfo game, byte[] file, GambatteSettings sett { case GambatteSyncSettings.ConsoleModeType.GB: break; - case GambatteSyncSettings.ConsoleModeType.SGB: - flags &= ~(LibGambatte.LoadFlags.CGB_MODE | LibGambatte.LoadFlags.GBA_FLAG); - flags |= LibGambatte.LoadFlags.SGB_MODE; - IsSgb = true; - break; case GambatteSyncSettings.ConsoleModeType.GBC: flags |= LibGambatte.LoadFlags.CGB_MODE; break; case GambatteSyncSettings.ConsoleModeType.GBA: flags |= LibGambatte.LoadFlags.CGB_MODE | LibGambatte.LoadFlags.GBA_FLAG; break; + case GambatteSyncSettings.ConsoleModeType.SGB2: + flags |= LibGambatte.LoadFlags.SGB_MODE; + IsSgb = true; + break; case GambatteSyncSettings.ConsoleModeType.Auto: if (game.System == VSystemID.Raw.GBC) flags |= LibGambatte.LoadFlags.CGB_MODE; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 3947da863b6..40ad431204c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -175,7 +175,7 @@ private ControllerDefinition CreateControllerDefinition() private Boolean isSGB(int i) { - return _syncSettings._linkedSyncSettings[i].ConsoleMode.ToString().Equals(VSystemID.Raw.SGB); + return _syncSettings._linkedSyncSettings[i].ConsoleMode.ToString().Equals("SGB2"); } private const int P1 = 0; From dd6abbc549763482c3a2895931292f602ab865c8 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Tue, 21 Jun 2022 02:15:04 -0700 Subject: [PATCH 05/27] SGB border in GBL --- .../Gameboy/GambatteLink.IEmulator.cs | 20 ++++++++++- .../Gameboy/GambatteLink.IVideoProvider.cs | 33 +++++++++++++++---- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 27 ++++++++++++--- .../Consoles/Nintendo/Gameboy/LibGambatte.cs | 2 ++ 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index 12a89eea822..bc22e923ae1 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -72,10 +72,11 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = unsafe { - fixed (int* fbuff = &FrameBuffer[0]) + fixed (int* fbuff = &FrameBuffer[0], svbuff = &SgbVideoBuffer[0]) { // use pitch to have both cores write to the same frame buffer, interleaved int Pitch = 160 * _numCores; + int sgbPitch = 256 * _numCores; fixed (short* sbuff = &SoundBuffer[0]) { @@ -108,6 +109,23 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = { Array.Copy(FrameBuffer, (i * 160) + (j * Pitch), VideoBuffer, (i * 160) + (j * Pitch), 160); } + if (isAnySgb) + { + if (isSgb[i]) // all SGB borders will be displayed when any of them has the option enabled + { + if (LibGambatte.gambatte_updatescreenborder(_linkedCores[i].GambatteState, svbuff + (i * 256), sgbPitch) != 0) + { + throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_updatescreenborder)}() returned non-zero (border error???)"); + } + } + else + { + for (int j = 0; j < 144; j++) + { + Array.Copy(FrameBuffer, (i * 160) + (j * Pitch), SgbVideoBuffer, (i * 256 + 48) + (40 + j) * sgbPitch, 160); + } + } + } } n[i] += (int)nsamp; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs index 178f0f70f44..0cea25c5faf 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs @@ -4,10 +4,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy { public partial class GambatteLink : IVideoProvider { - public int VirtualWidth => 160 * _numCores; - public int VirtualHeight => 144; - public int BufferWidth => 160 * _numCores; - public int BufferHeight => 144; + public int VirtualWidth => (showAnyBorder() ? 256 : 160) * _numCores; + + public int VirtualHeight => showAnyBorder() ? 224 : 144; + + public int BufferWidth => (showAnyBorder() ? 256 : 160) * _numCores; + + public int BufferHeight => showAnyBorder() ? 224 : 144; public int VsyncNumerator => _linkedCores[P1].VsyncNumerator; @@ -17,13 +20,18 @@ public partial class GambatteLink : IVideoProvider private readonly int[] FrameBuffer; - public int[] GetVideoBuffer() => VideoBuffer; + public int[] GetVideoBuffer() + { + return showAnyBorder() ? SgbVideoBuffer : VideoBuffer; + } private readonly int[] VideoBuffer; - + + private readonly int[] SgbVideoBuffer; + private int[] CreateVideoBuffer() { - var b = new int[BufferWidth * BufferHeight]; + var b = new int[160 * _numCores * 144]; for (int i = 0; i < b.Length; i++) { b[i] = -1; // GB/C screen is disabled on bootup, so it always starts as white, not black @@ -31,5 +39,16 @@ private int[] CreateVideoBuffer() return b; } + private int[] CreateSGBVideoBuffer() + { + if (isAnySgb) + { + return new int[256 * _numCores * 224]; + } + else + { + return new int[1]; // create a dummy so that the fixed statement can work regardless + } + } } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 40ad431204c..52864bff1a6 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -50,7 +50,9 @@ public GambatteLink(CoreLoadParameters Date: Tue, 21 Jun 2022 22:53:25 -0700 Subject: [PATCH 06/27] adjust sgb core detection --- .../Nintendo/Gameboy/GambatteLink.IEmulator.cs | 2 +- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index bc22e923ae1..e5ec5095c39 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -111,7 +111,7 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = } if (isAnySgb) { - if (isSgb[i]) // all SGB borders will be displayed when any of them has the option enabled + if (isSgb(i)) // all SGB borders will be displayed when any of them has the option enabled { if (LibGambatte.gambatte_updatescreenborder(_linkedCores[i].GambatteState, svbuff + (i * 256), sgbPitch) != 0) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 52864bff1a6..4f103415762 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -50,9 +50,8 @@ public GambatteLink(CoreLoadParameters Date: Thu, 30 Jun 2022 00:52:21 -0700 Subject: [PATCH 07/27] reformat controller button naming --- .../Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs | 4 ++-- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index e5ec5095c39..4b823cb8a90 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -23,9 +23,9 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = { for (int i = 0; i < _numCores; i++) { - if (s.Contains($"P{i + 1} -")) + if (s.Contains($"P{i + 1} - C")) { - _linkedConts[i].Set(s.Replace($"P{i + 1} - ", "")); + _linkedConts[i].Set(s.Replace($"P{i + 1} - C", "P")); } else if (s.Contains($"P{i + 1} ")) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 4f103415762..96256dc3c32 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -155,7 +155,7 @@ private ControllerDefinition CreateControllerDefinition() { ret.BoolButtons.AddRange( new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start" } - .Select(s => $"P{i + 1} - P{j + 1} {s}")); + .Select(s => $"P{i + 1} - C{j + 1} {s}")); } ret.BoolButtons.Add($"P{i + 1} Power"); } From 2e6f59ba8c3db12b0c94efe5c09ba8b9af51e2ad Mon Sep 17 00:00:00 2001 From: Fortranm Date: Sun, 16 Apr 2023 02:41:07 -0700 Subject: [PATCH 08/27] adjust for 2.9 --- .../Consoles/Nintendo/BSNES/BsnesCore.cs | 5 +++-- .../Consoles/Nintendo/BSNES/SubBsnesCore.cs | 3 ++- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 3 +-- .../Consoles/Nintendo/SNES/LibsnesCore.cs | 9 ++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs index d238e1a2dac..4d5f0546501 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs @@ -31,13 +31,14 @@ public BsnesCore(CoreLoadParameters loadParamete this._romPath = Path.ChangeExtension(loadParameters.Roms[0].RomPath, null); CoreComm = loadParameters.Comm; _syncSettings = loadParameters.SyncSettings ?? new SnesSyncSettings(); - SystemId = loadParameters.Game.System; - _isSGB = SystemId == VSystemID.Raw.SGB; + _isSGB = loadParameters.Game.System is VSystemID.Raw.GB or VSystemID.Raw.GBC; + SystemId = _isSGB ? VSystemID.Raw.SGB : loadParameters.Game.System; _currentMsuTrack = new ProxiedFile(); byte[] sgbRomData = null; if (_isSGB) { + SystemId = VSystemID.Raw.SGB; if ((loadParameters.Roms[0].RomData[0x143] & 0xc0) == 0xc0) { throw new CGBNotSupportedException(); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs index f84cf5c905e..a66178219ca 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs @@ -8,8 +8,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES [ServiceNotApplicable(new[] { typeof(IDriveLight) })] public class SubBsnesCore : IEmulator, ICycleTiming { + [CoreConstructor(VSystemID.Raw.GB)] + [CoreConstructor(VSystemID.Raw.GBC)] [CoreConstructor(VSystemID.Raw.Satellaview)] - [CoreConstructor(VSystemID.Raw.SGB)] [CoreConstructor(VSystemID.Raw.SNES)] public SubBsnesCore(CoreLoadParameters loadParameters) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index db1dde61de4..fe424747877 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -22,8 +22,7 @@ public partial class Gameboy : IInputPollable, IRomInfo, IGameboyCommon, ICycleT [CoreConstructor(VSystemID.Raw.GB)] [CoreConstructor(VSystemID.Raw.GBC)] - [CoreConstructor(VSystemID.Raw.SGB)] - public Gameboy(CoreComm comm, IGameInfo game, byte[] file, GambatteSettings settings, GambatteSyncSettings syncSettings, bool deterministic) + public Gameboy(CoreComm comm, GameInfo game, byte[] file, GambatteSettings settings, GambatteSyncSettings syncSettings, bool deterministic) { _serviceProvider = new(this); _serviceProvider.Register(_disassembler); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index 25f4a3e13fb..91a956308d5 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -23,8 +23,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES public unsafe partial class LibsnesCore : IEmulator, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ICodeDataLogger, IDebuggable, ISettable, IBSNESForGfxDebugger { - [CoreConstructor(VSystemID.Raw.GB)] - [CoreConstructor(VSystemID.Raw.GBC)] + [CoreConstructor(VSystemID.Raw.SGB)] [CoreConstructor(VSystemID.Raw.SNES)] public LibsnesCore(GameInfo game, byte[] rom, CoreComm comm, LibsnesCore.SnesSettings settings, LibsnesCore.SnesSyncSettings syncSettings) @@ -47,9 +46,8 @@ public LibsnesCore(GameInfo game, byte[] romData, byte[] xmlData, string baseRom CoreComm = comm; byte[] sgbRomData = null; - if (game.System == VSystemID.Raw.GB || game.System == VSystemID.Raw.GBC) + if (game.System == VSystemID.Raw.SGB) { - IsSGB = true; if ((romData[0x143] & 0xc0) == 0xc0) { throw new CGBNotSupportedException(); @@ -112,8 +110,9 @@ public LibsnesCore(GameInfo game, byte[] romData, byte[] xmlData, string baseRom romData = newData; } - if (IsSGB) + if (game.System == VSystemID.Raw.SGB) { + IsSGB = true; SystemId = VSystemID.Raw.SNES; ser.Register(new SGBBoardInfo()); From 2e534a99ae09d8cf5c97f4a834c0dda0c8b56f46 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Sun, 16 Apr 2023 14:09:59 -0700 Subject: [PATCH 09/27] adjust for 2.9 again --- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 5 ----- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index fe424747877..3a741f899f5 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -70,11 +70,6 @@ public Gameboy(CoreComm comm, GameInfo game, byte[] file, GambatteSettings setti throw new InvalidOperationException(); } - if (_syncSettings.MulticartCompat) - { - flags |= LibGambatte.LoadFlags.MULTICART_COMPAT; - } - IsCgb = (flags & LibGambatte.LoadFlags.CGB_MODE) == LibGambatte.LoadFlags.CGB_MODE; bool ForceBios() diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 96256dc3c32..8d74f04f736 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -51,7 +51,7 @@ public GambatteLink(CoreLoadParameters Date: Fri, 23 Jun 2023 01:56:28 -0700 Subject: [PATCH 10/27] revert changes to BSNES CoreConstructor The system id will still be SGB for BSNES cores by default --- src/BizHawk.Client.Common/RomLoader.cs | 5 +++++ .../Consoles/Nintendo/BSNES/BsnesCore.cs | 4 +--- .../Consoles/Nintendo/BSNES/SubBsnesCore.cs | 3 +-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index 8faf6b9cfd1..0058de8f066 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -482,6 +482,11 @@ private void LoadOther( ); return; } + + if (_config.PreferredCores[game.System].Contains(CoreNames.Bsnes115)) + { + game.System = VSystemID.Raw.SGB; + } break; case VSystemID.Raw.PSX when ext is ".bin": const string FILE_EXT_CUE = ".cue"; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs index 4d5f0546501..9195ec42582 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs @@ -18,9 +18,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES [ServiceNotApplicable(new[] { typeof(IDriveLight) })] public partial class BsnesCore : IEmulator, IDebuggable, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ISettable, IBSNESForGfxDebugger, IBoardInfo { - [CoreConstructor(VSystemID.Raw.GB)] - [CoreConstructor(VSystemID.Raw.GBC)] [CoreConstructor(VSystemID.Raw.Satellaview)] + [CoreConstructor(VSystemID.Raw.SGB)] [CoreConstructor(VSystemID.Raw.SNES)] public BsnesCore(CoreLoadParameters loadParameters) : this(loadParameters, false) { } public BsnesCore(CoreLoadParameters loadParameters, bool subframe = false) @@ -38,7 +37,6 @@ public BsnesCore(CoreLoadParameters loadParamete byte[] sgbRomData = null; if (_isSGB) { - SystemId = VSystemID.Raw.SGB; if ((loadParameters.Roms[0].RomData[0x143] & 0xc0) == 0xc0) { throw new CGBNotSupportedException(); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs index a66178219ca..f84cf5c905e 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs @@ -8,9 +8,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES [ServiceNotApplicable(new[] { typeof(IDriveLight) })] public class SubBsnesCore : IEmulator, ICycleTiming { - [CoreConstructor(VSystemID.Raw.GB)] - [CoreConstructor(VSystemID.Raw.GBC)] [CoreConstructor(VSystemID.Raw.Satellaview)] + [CoreConstructor(VSystemID.Raw.SGB)] [CoreConstructor(VSystemID.Raw.SNES)] public SubBsnesCore(CoreLoadParameters loadParameters) { From c183e6e150a0b611ae64b6b46dba79a18de9baad Mon Sep 17 00:00:00 2001 From: Fortranm Date: Fri, 23 Jun 2023 15:06:21 -0700 Subject: [PATCH 11/27] one Player tab per SNES controller for SGB --- .../movie/bk2/Bk2MnemonicLookup.cs | 4 --- .../Gameboy/GambatteLink.IEmulator.cs | 27 ++++++++++++++++--- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 21 +++++++-------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2MnemonicLookup.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2MnemonicLookup.cs index 8528d8feabd..24b5a9254d6 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2MnemonicLookup.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2MnemonicLookup.cs @@ -14,10 +14,6 @@ public static char Lookup(string button, string systemId) var key = button.Replace("Key ", ""); if (key.StartsWith('P')) { - if (systemId.Equals(VSystemID.Raw.GBL) && key.Contains("-")) // Deal with SGB in GBL - { - key = key.Substring(5); - } if (key.Length > 2 && key[1] == '1' && key[2] >= '0' && key[2] <= '9') // Hack to support 10-20 controllers, TODO: regex this thing instead { key = key.Substring(4); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index 4b823cb8a90..85719100558 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -21,15 +21,34 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = { if (controller.IsPressed(s)) { + int p = 0; for (int i = 0; i < _numCores; i++) { - if (s.Contains($"P{i + 1} - C")) + if (isSgb(i)) { - _linkedConts[i].Set(s.Replace($"P{i + 1} - C", "P")); + for (int j = 1; j <= 4; j++) + { + p += 1; + if (s.Contains($"P{p} ")) + { + if (s.Contains($"Power")) + { + _linkedConts[i].Set(s.Replace($"P{p} ", "")); + } + else + { + _linkedConts[i].Set(s.Replace($"P{p} ", $"P{j} ")); + } + } + } } - else if (s.Contains($"P{i + 1} ")) + else { - _linkedConts[i].Set(s.Replace($"P{i + 1} ", "")); + p += 1; + if (s.Contains($"P{p} ")) + { + _linkedConts[i].Set(s.Replace($"P{p} ", "")); + } } } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 8d74f04f736..2f06c696c75 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -147,23 +147,22 @@ public IGameboyCommon First private ControllerDefinition CreateControllerDefinition() { ControllerDefinition ret = new($"GB Link {_numCores}x Controller"); + int p = 0; for (int i = 0; i < _numCores; i++) { - if (isSgb(i)) + p += 1; + ret.BoolButtons.AddRange( + new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start", "Power" } + .Select(s => $"P{p} {s}")); + if (isSgb(i)) // one Player tab per SNES controller for SGB; SNES power button on the first Player tab { - for (int j = 0; j < 4; j++) + for (int j = 1; j < 4; j++) { + p += 1; ret.BoolButtons.AddRange( - new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start" } - .Select(s => $"P{i + 1} - C{j + 1} {s}")); + new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start" } + .Select(s => $"P{p} {s}")); } - ret.BoolButtons.Add($"P{i + 1} Power"); - } - else - { - ret.BoolButtons.AddRange( - new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start", "Power" } - .Select(s => $"P{i + 1} {s}")); } } ret.BoolButtons.Add("Toggle Link Connection"); From 0a3a72726a831f50e7948465dac0ea70ab3edd0d Mon Sep 17 00:00:00 2001 From: Fortranm Date: Wed, 12 Jul 2023 14:21:33 -0700 Subject: [PATCH 12/27] idiomatic rephrase for showAnyBorder --- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 2f06c696c75..71f215efd4b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -189,14 +189,7 @@ private bool showBorder(int i) public bool showAnyBorder() { - for (int i = 0; i < _numCores; i++) - { - if (showBorder(i)) - { - return true; - } - } - return false; + return Enumerable.Range(0, _numCores).Any(showBorder); } private const int P1 = 0; From ef87a485bff7d307845b3561b7330e6e2b5aa143 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Wed, 12 Jul 2023 14:27:53 -0700 Subject: [PATCH 13/27] no dummy for CreateSGBVideoBuffer --- .../Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs | 2 +- .../Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index 85719100558..709ab2f4f13 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -91,7 +91,7 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = unsafe { - fixed (int* fbuff = &FrameBuffer[0], svbuff = &SgbVideoBuffer[0]) + fixed (int* fbuff = &FrameBuffer[0], svbuff = SgbVideoBuffer) { // use pitch to have both cores write to the same frame buffer, interleaved int Pitch = 160 * _numCores; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs index 0cea25c5faf..4f38d1f89a5 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs @@ -45,10 +45,7 @@ private int[] CreateSGBVideoBuffer() { return new int[256 * _numCores * 224]; } - else - { - return new int[1]; // create a dummy so that the fixed statement can work regardless - } + return null; } } } From c0ff230512b0d62fe06d3f15c7ba7309c26d87c5 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Thu, 13 Jul 2023 02:07:41 -0700 Subject: [PATCH 14/27] fix SGB conversion in LsmvImport --- src/BizHawk.Client.Common/movie/import/LsmvImport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BizHawk.Client.Common/movie/import/LsmvImport.cs b/src/BizHawk.Client.Common/movie/import/LsmvImport.cs index 8413d359c03..738214c11b8 100644 --- a/src/BizHawk.Client.Common/movie/import/LsmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/LsmvImport.cs @@ -159,7 +159,7 @@ protected override void RunImport() break; case "sgb_ntsc": case "sgb_pal": - platform = VSystemID.Raw.SNES; + platform = VSystemID.Raw.SGB; break; } From b2a472050d90dbd0e3b7ab7c3a198d5d6a320be6 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Thu, 13 Jul 2023 02:17:03 -0700 Subject: [PATCH 15/27] add legacy BSNES option for (S)GB --- src/BizHawk.Client.Common/RomLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index 0058de8f066..4ec1a513e8e 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -483,7 +483,7 @@ private void LoadOther( return; } - if (_config.PreferredCores[game.System].Contains(CoreNames.Bsnes115)) + if (_config.PreferredCores[game.System].Contains(CoreNames.Bsnes)) { game.System = VSystemID.Raw.SGB; } From e8aa24add92eb411ed29f7e2bdc0a0b23b28eaeb Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Wed, 29 May 2024 17:07:57 +0200 Subject: [PATCH 16/27] minor cosmetic changes --- src/BizHawk.Client.Common/RomLoader.cs | 2 +- src/BizHawk.Client.Common/config/Config.cs | 1 - .../Gameboy/GambatteLink.IEmulator.cs | 6 +++--- .../Gameboy/GambatteLink.IVideoProvider.cs | 12 ++++++------ .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 19 +++++++++---------- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index 4ec1a513e8e..9f9566c87f2 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -483,7 +483,7 @@ private void LoadOther( return; } - if (_config.PreferredCores[game.System].Contains(CoreNames.Bsnes)) + if (_config.PreferredCores[game.System] is CoreNames.Bsnes or CoreNames.Bsnes115 or CoreNames.SubBsnes115) { game.System = VSystemID.Raw.SGB; } diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index 84904092a69..c2ba45730c4 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -386,7 +386,6 @@ public void SetWindowScaleFor(string sysID, int windowScale) public Dictionary> AllTrollersAnalog { get; set; } = new Dictionary>(); public Dictionary> AllTrollersFeedbacks { get; set; } = new Dictionary>(); - /// as this setting spans multiple cores and doesn't actually affect the behavior of any core, it hasn't been absorbed into the new system public string LibretroCore { get; set; } public Dictionary PreferredCores = GenDefaultCorePreferences(); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index 709ab2f4f13..e4206d389c2 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -24,7 +24,7 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = int p = 0; for (int i = 0; i < _numCores; i++) { - if (isSgb(i)) + if (IsSgb(i)) { for (int j = 1; j <= 4; j++) { @@ -128,9 +128,9 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = { Array.Copy(FrameBuffer, (i * 160) + (j * Pitch), VideoBuffer, (i * 160) + (j * Pitch), 160); } - if (isAnySgb) + if (IsAnySgb) { - if (isSgb(i)) // all SGB borders will be displayed when any of them has the option enabled + if (IsSgb(i)) // all SGB borders will be displayed when any of them has the option enabled { if (LibGambatte.gambatte_updatescreenborder(_linkedCores[i].GambatteState, svbuff + (i * 256), sgbPitch) != 0) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs index 4f38d1f89a5..6072a009ad7 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs @@ -4,13 +4,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy { public partial class GambatteLink : IVideoProvider { - public int VirtualWidth => (showAnyBorder() ? 256 : 160) * _numCores; + public int VirtualWidth => (ShowAnyBorder() ? 256 : 160) * _numCores; - public int VirtualHeight => showAnyBorder() ? 224 : 144; + public int VirtualHeight => ShowAnyBorder() ? 224 : 144; - public int BufferWidth => (showAnyBorder() ? 256 : 160) * _numCores; + public int BufferWidth => (ShowAnyBorder() ? 256 : 160) * _numCores; - public int BufferHeight => showAnyBorder() ? 224 : 144; + public int BufferHeight => ShowAnyBorder() ? 224 : 144; public int VsyncNumerator => _linkedCores[P1].VsyncNumerator; @@ -22,7 +22,7 @@ public partial class GambatteLink : IVideoProvider public int[] GetVideoBuffer() { - return showAnyBorder() ? SgbVideoBuffer : VideoBuffer; + return ShowAnyBorder() ? SgbVideoBuffer : VideoBuffer; } private readonly int[] VideoBuffer; @@ -41,7 +41,7 @@ private int[] CreateVideoBuffer() private int[] CreateSGBVideoBuffer() { - if (isAnySgb) + if (IsAnySgb) { return new int[256 * _numCores * 224]; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 71f215efd4b..33e44c13e43 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -50,8 +50,8 @@ public GambatteLink(CoreLoadParameters $"P{p} {s}")); - if (isSgb(i)) // one Player tab per SNES controller for SGB; SNES power button on the first Player tab + if (IsSgb(i)) // one Player tab per SNES controller for SGB; SNES power button on the first Player tab { for (int j = 1; j < 4; j++) { @@ -174,22 +174,21 @@ private ControllerDefinition CreateControllerDefinition() return ret.MakeImmutable(); } - private bool isSgb(int i) + private bool IsSgb(int i) { return _linkedCores[i].IsSgb; } + public bool IsAnySgb { get; set; } - public bool isAnySgb { get; set; } - - private bool showBorder(int i) + private bool ShowBorder(int i) { - return isSgb(i) && _settings._linkedSettings[i].ShowBorder; + return IsSgb(i) && _settings._linkedSettings[i].ShowBorder; } - public bool showAnyBorder() + public bool ShowAnyBorder() { - return Enumerable.Range(0, _numCores).Any(showBorder); + return Enumerable.Range(0, _numCores).Any(ShowBorder); } private const int P1 = 0; From 378625838927196f0b173555d0d808b53c91b68f Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 31 May 2024 06:30:57 +1000 Subject: [PATCH 17/27] Fix `.vbm` importer when Gambatte isn't the preferred GB core --- .../movie/import/VbmImport.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/import/VbmImport.cs b/src/BizHawk.Client.Common/movie/import/VbmImport.cs index 397c303227b..a0ae4c94307 100644 --- a/src/BizHawk.Client.Common/movie/import/VbmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/VbmImport.cs @@ -18,7 +18,6 @@ protected override void RunImport() using var fs = SourceFile.Open(FileMode.Open, FileAccess.Read); using var r = new BinaryReader(fs); bool is_GBC = false; - bool is_SGB = false; // 000 4-byte signature: 56 42 4D 1A "VBM\x1A" string signature = new string(r.ReadChars(4)); @@ -123,10 +122,15 @@ recording time in Unix epoch format Result.Movie.HeaderEntries.Add("IsCGBMode", "1"); } + var finalCoreName = Config.PreferredCores[VSystemID.Raw.GB]; if (isSGB) { - is_SGB = true; platform = VSystemID.Raw.SGB; + if (finalCoreName is not CoreNames.Gambatte) + { + Result.Warnings.Add($"{finalCoreName} doesn't support SGB; will use {CoreNames.Gambatte}"); + finalCoreName = CoreNames.Gambatte; + } } Result.Movie.HeaderEntries[HeaderKeys.Platform] = platform; @@ -278,14 +282,15 @@ A stream of 2-byte bitvectors which indicate which buttons are pressed at each p } else { - Result.Movie.HeaderEntries[HeaderKeys.Core] = Config.PreferredCores[VSystemID.Raw.GB]; - switch (Config.PreferredCores[VSystemID.Raw.GB]) + Result.Movie.HeaderEntries[HeaderKeys.Core] = finalCoreName; + switch (finalCoreName) { case CoreNames.Gambatte: Result.Movie.SyncSettingsJson = ConfigService.SaveWithType(new Gameboy.GambatteSyncSettings { - ConsoleMode = is_SGB ? Gameboy.GambatteSyncSettings.ConsoleModeType.SGB2 : - is_GBC ? Gameboy.GambatteSyncSettings.ConsoleModeType.GBC : Gameboy.GambatteSyncSettings.ConsoleModeType.GB, + ConsoleMode = isSGB + ? Gameboy.GambatteSyncSettings.ConsoleModeType.SGB2 + : is_GBC ? Gameboy.GambatteSyncSettings.ConsoleModeType.GBC : Gameboy.GambatteSyncSettings.ConsoleModeType.GB, }); break; case CoreNames.GbHawk: From 0f5cc8d9234bc39a82b7db42186d3882b4838083 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 31 May 2024 06:54:08 +1000 Subject: [PATCH 18/27] Fix button mapping spaghetti --- .../Gameboy/GambatteLink.IEmulator.cs | 51 ++++++++----------- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 27 +++++----- 2 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index e4206d389c2..e4dcb065a14 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -1,5 +1,7 @@ using System; +using System.Diagnostics; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.Gameboy @@ -19,39 +21,26 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = foreach (var s in GBLinkController.BoolButtons) { - if (controller.IsPressed(s)) + if (!controller.IsPressed(s)) continue; + Debug.Assert(s[0] is 'P'); + var iSpace = s.IndexOf(' '); + var playerNum = int.Parse(s.Substring(startIndex: 1, length: iSpace - 1)); + var consoleNum = 0; + var isSGB = false; + while (consoleNum < _numCores) { - int p = 0; - for (int i = 0; i < _numCores; i++) - { - if (IsSgb(i)) - { - for (int j = 1; j <= 4; j++) - { - p += 1; - if (s.Contains($"P{p} ")) - { - if (s.Contains($"Power")) - { - _linkedConts[i].Set(s.Replace($"P{p} ", "")); - } - else - { - _linkedConts[i].Set(s.Replace($"P{p} ", $"P{j} ")); - } - } - } - } - else - { - p += 1; - if (s.Contains($"P{p} ")) - { - _linkedConts[i].Set(s.Replace($"P{p} ", "")); - } - } - } + isSGB = IsSgb(consoleNum); + var playersForConsole = isSGB ? 4 : 1; + if (playerNum <= playersForConsole) break; + playerNum -= playersForConsole; + consoleNum++; } + //TODO rather than this string manipulation, could construct a lookup ahead of time + _linkedConts[consoleNum].Set(s.EndsWithOrdinal("Power") + ? "Power" + : isSGB + ? $"P{playerNum} {s.Substring(startIndex: iSpace + 1)}" + : s.Substring(startIndex: iSpace + 1)); } bool linkDiscoSignalNew = controller.IsPressed("Toggle Link Connection"); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 33e44c13e43..39eab1ac037 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -146,23 +146,22 @@ public IGameboyCommon First private ControllerDefinition CreateControllerDefinition() { + static void AddGBButtonsForPlayer(int p, ControllerDefinition ret) + { + var pfx = $"P{p} "; + ret.BoolButtons.AddRange(new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start" } + .Select(s => pfx + s)); + } ControllerDefinition ret = new($"GB Link {_numCores}x Controller"); - int p = 0; - for (int i = 0; i < _numCores; i++) + for (int i = 0, p = 1; i < _numCores; i++) { - p += 1; - ret.BoolButtons.AddRange( - new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start", "Power" } - .Select(s => $"P{p} {s}")); - if (IsSgb(i)) // one Player tab per SNES controller for SGB; SNES power button on the first Player tab + AddGBButtonsForPlayer(p, ret); + ret.BoolButtons.Add($"P{p} Power"); + p++; + if (IsSgb(i)) { - for (int j = 1; j < 4; j++) - { - p += 1; - ret.BoolButtons.AddRange( - new[] { "Up", "Down", "Left", "Right", "A", "B", "Select", "Start" } - .Select(s => $"P{p} {s}")); - } + // add 3 more gamepads without a Power button + for (int e = p + 3; p < e; p++) AddGBButtonsForPlayer(p, ret); } } ret.BoolButtons.Add("Toggle Link Connection"); From b910c38f7f6cf051a673c3657703079a82dc595b Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 31 May 2024 06:54:29 +1000 Subject: [PATCH 19/27] Code style nitpicks --- src/BizHawk.Client.Common/RomLoader.cs | 5 ++-- .../Nintendo/Gameboy/Gambatte.ISettable.cs | 4 ++-- .../Gameboy/GambatteLink.IEmulator.cs | 8 +++++-- .../Gameboy/GambatteLink.IVideoProvider.cs | 24 ++++++++----------- .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 15 +++++------- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index 9f9566c87f2..56acc049a3b 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -482,8 +482,9 @@ private void LoadOther( ); return; } - - if (_config.PreferredCores[game.System] is CoreNames.Bsnes or CoreNames.Bsnes115 or CoreNames.SubBsnes115) + static bool IsPreferredCoreSGB(Config config) + => config.PreferredCores[VSystemID.Raw.GB] is CoreNames.Bsnes or CoreNames.Bsnes115 or CoreNames.SubBsnes115; + if (IsPreferredCoreSGB(_config)) { game.System = VSystemID.Raw.SGB; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs index 34bd21002d6..f06075a25f1 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs @@ -111,11 +111,11 @@ public enum ConsoleModeType GB, GBC, GBA, - SGB2 + SGB2, } [DisplayName("Console Mode")] - [Description("Pick which console to run, 'Auto' chooses from ROM header; 'GB', 'GBC', 'GBA', and 'SGB2' chooses the respective system.")] + [Description("Which console to emulate ('Auto' picks based on the rom header)")] [DefaultValue(ConsoleModeType.Auto)] public ConsoleModeType ConsoleMode { get; set; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index e4dcb065a14..a1de6b526f6 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -119,9 +119,13 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = } if (IsAnySgb) { - if (IsSgb(i)) // all SGB borders will be displayed when any of them has the option enabled + // all SGB borders will be displayed when any of them has the option enabled + if (IsSgb(i)) { - if (LibGambatte.gambatte_updatescreenborder(_linkedCores[i].GambatteState, svbuff + (i * 256), sgbPitch) != 0) + if (LibGambatte.gambatte_updatescreenborder( + _linkedCores[i].GambatteState, + svbuff + (i * 256), + sgbPitch) is not 0) { throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_updatescreenborder)}() returned non-zero (border error???)"); } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs index 6072a009ad7..493fd0ef34d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs @@ -4,13 +4,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy { public partial class GambatteLink : IVideoProvider { - public int VirtualWidth => (ShowAnyBorder() ? 256 : 160) * _numCores; + public int VirtualWidth + => (ShowAnyBorder() ? 256 : 160) * _numCores; - public int VirtualHeight => ShowAnyBorder() ? 224 : 144; + public int VirtualHeight + => ShowAnyBorder() ? 224 : 144; - public int BufferWidth => (ShowAnyBorder() ? 256 : 160) * _numCores; + public int BufferWidth + => VirtualWidth; - public int BufferHeight => ShowAnyBorder() ? 224 : 144; + public int BufferHeight + => VirtualHeight; public int VsyncNumerator => _linkedCores[P1].VsyncNumerator; @@ -21,9 +25,7 @@ public partial class GambatteLink : IVideoProvider private readonly int[] FrameBuffer; public int[] GetVideoBuffer() - { - return ShowAnyBorder() ? SgbVideoBuffer : VideoBuffer; - } + => ShowAnyBorder() ? SgbVideoBuffer : VideoBuffer; private readonly int[] VideoBuffer; @@ -40,12 +42,6 @@ private int[] CreateVideoBuffer() } private int[] CreateSGBVideoBuffer() - { - if (IsAnySgb) - { - return new int[256 * _numCores * 224]; - } - return null; - } + => IsAnySgb ? new int[256 * _numCores * 224] : null; } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 39eab1ac037..29a7c1dd526 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -50,7 +50,7 @@ public GambatteLink(CoreLoadParameters _linkedCores[i].IsSgb; - public bool IsAnySgb { get; set; } + public bool IsAnySgb { get; private set; } private bool ShowBorder(int i) - { - return IsSgb(i) && _settings._linkedSettings[i].ShowBorder; - } + => IsSgb(i) && _settings._linkedSettings[i].ShowBorder; public bool ShowAnyBorder() { - return Enumerable.Range(0, _numCores).Any(ShowBorder); + for (var i = 0; i < _numCores; i++) if (ShowBorder(i)) return true; + return false; } private const int P1 = 0; From 864ee92ab4b589e4f7a75e05742dd4530e317f1a Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Thu, 20 Jun 2024 01:07:32 +0200 Subject: [PATCH 20/27] minor cleanups in Gambatte.cs --- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index 3a741f899f5..27620aef075 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -633,7 +633,7 @@ public IGPUMemoryAreas LockGPU() Vram = _vram, Oam = _oam, Sppal = _sppal, - Bgpal = _bgpal, + Bgpal = _bgpal, }; } From c68e9dbc95162e134cd3a9e95db30a19c8c76519 Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Thu, 20 Jun 2024 01:09:02 +0200 Subject: [PATCH 21/27] Remove special SGB handling and mark bsnes* as GB/GBC cores --- src/BizHawk.Client.Common/RomLoader.cs | 11 ----------- .../Consoles/Nintendo/BSNES/BsnesCore.cs | 3 ++- .../Consoles/Nintendo/BSNES/SubBsnesCore.cs | 3 ++- .../Consoles/Nintendo/SNES/LibsnesCore.cs | 9 +++++---- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index 56acc049a3b..b55dfbdbd86 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -482,12 +482,6 @@ private void LoadOther( ); return; } - static bool IsPreferredCoreSGB(Config config) - => config.PreferredCores[VSystemID.Raw.GB] is CoreNames.Bsnes or CoreNames.Bsnes115 or CoreNames.SubBsnes115; - if (IsPreferredCoreSGB(_config)) - { - game.System = VSystemID.Raw.SGB; - } break; case VSystemID.Raw.PSX when ext is ".bin": const string FILE_EXT_CUE = ".cue"; @@ -853,11 +847,6 @@ private void DispatchErrorMessage(Exception ex, string system, string path) { DoLoadErrorCallback(ex.Message, system, path, Deterministic, LoadErrorType.MissingFirmware); } - else if (ex is CGBNotSupportedException) - { - // failed to load SGB bios or game does not support SGB mode. - DoLoadErrorCallback("Failed to load a GB rom in SGB mode. You might try disabling SGB Mode.", system); - } else if (ex is NoAvailableCoreException) { // handle exceptions thrown by the new detected systems that BizHawk does not have cores for diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs index 9195ec42582..1246b98db4f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs @@ -18,8 +18,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES [ServiceNotApplicable(new[] { typeof(IDriveLight) })] public partial class BsnesCore : IEmulator, IDebuggable, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ISettable, IBSNESForGfxDebugger, IBoardInfo { + [CoreConstructor(VSystemID.Raw.GB)] + [CoreConstructor(VSystemID.Raw.GBC)] [CoreConstructor(VSystemID.Raw.Satellaview)] - [CoreConstructor(VSystemID.Raw.SGB)] [CoreConstructor(VSystemID.Raw.SNES)] public BsnesCore(CoreLoadParameters loadParameters) : this(loadParameters, false) { } public BsnesCore(CoreLoadParameters loadParameters, bool subframe = false) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs index f84cf5c905e..a66178219ca 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/SubBsnesCore.cs @@ -8,8 +8,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES [ServiceNotApplicable(new[] { typeof(IDriveLight) })] public class SubBsnesCore : IEmulator, ICycleTiming { + [CoreConstructor(VSystemID.Raw.GB)] + [CoreConstructor(VSystemID.Raw.GBC)] [CoreConstructor(VSystemID.Raw.Satellaview)] - [CoreConstructor(VSystemID.Raw.SGB)] [CoreConstructor(VSystemID.Raw.SNES)] public SubBsnesCore(CoreLoadParameters loadParameters) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index 91a956308d5..00e61b16f92 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -23,7 +23,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES public unsafe partial class LibsnesCore : IEmulator, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable, ICodeDataLogger, IDebuggable, ISettable, IBSNESForGfxDebugger { - [CoreConstructor(VSystemID.Raw.SGB)] + [CoreConstructor(VSystemID.Raw.GB)] + [CoreConstructor(VSystemID.Raw.GBC)] [CoreConstructor(VSystemID.Raw.SNES)] public LibsnesCore(GameInfo game, byte[] rom, CoreComm comm, LibsnesCore.SnesSettings settings, LibsnesCore.SnesSyncSettings syncSettings) @@ -45,8 +46,9 @@ public LibsnesCore(GameInfo game, byte[] romData, byte[] xmlData, string baseRom _game = game; CoreComm = comm; byte[] sgbRomData = null; + IsSGB = game.System is VSystemID.Raw.GB or VSystemID.Raw.GBC; - if (game.System == VSystemID.Raw.SGB) + if (IsSGB) { if ((romData[0x143] & 0xc0) == 0xc0) { @@ -110,9 +112,8 @@ public LibsnesCore(GameInfo game, byte[] romData, byte[] xmlData, string baseRom romData = newData; } - if (game.System == VSystemID.Raw.SGB) + if (IsSGB) { - IsSGB = true; SystemId = VSystemID.Raw.SNES; ser.Register(new SGBBoardInfo()); From c56f0471c41194ba91e391193cd6fe3ba0ee4ade Mon Sep 17 00:00:00 2001 From: Fortranm Date: Mon, 1 Jul 2024 12:04:10 -0700 Subject: [PATCH 22/27] remove SGB from CorePickerUIData This fixes failures in CorePickerStabilityTests (https://ci.appveyor.com/project/zeromus/bizhawk-udexo/builds/50119675). It's not necessary to put SGB there as the system id is only ever switched to SGB after a relevant core is already initiated. --- src/BizHawk.Client.Common/config/Config.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index c2ba45730c4..cca9c214934 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -25,7 +25,7 @@ public class Config /// public static readonly IReadOnlyList<(string[] AppliesTo, string[] CoreNames)> CorePickerUIData = new List<(string[], string[])> { - ([ VSystemID.Raw.GB, VSystemID.Raw.GBC, VSystemID.Raw.SGB ], + ([ VSystemID.Raw.GB, VSystemID.Raw.GBC ], [ CoreNames.Gambatte, CoreNames.Sameboy, CoreNames.GbHawk, CoreNames.SubGbHawk, CoreNames.Bsnes, CoreNames.Bsnes115, CoreNames.SubBsnes115 ]), ([ VSystemID.Raw.GBL ], [ CoreNames.GambatteLink, CoreNames.GBHawkLink, CoreNames.GBHawkLink3x, CoreNames.GBHawkLink4x ]), From f148272c14eba3c132eac9d4a7f02656f9d205ec Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 2 Jul 2024 05:39:25 +1000 Subject: [PATCH 23/27] Un-revert submodule pull --- quicknes/core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quicknes/core b/quicknes/core index 74c1a73fe8b..027f63aee19 160000 --- a/quicknes/core +++ b/quicknes/core @@ -1 +1 @@ -Subproject commit 74c1a73fe8baf08ed02b66248b9bf12b4a77076c +Subproject commit 027f63aee19840ac1bf571a5d00d7758ca517220 From cddb11325df53f402bc7c655ad7b4123ec3c935e Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 2 Jul 2024 05:48:19 +1000 Subject: [PATCH 24/27] Un-revert other submodule pulls --- submodules/gambatte | 2 +- waterbox/melon/melonDS | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/submodules/gambatte b/submodules/gambatte index e35e24de89f..0838651ca7c 160000 --- a/submodules/gambatte +++ b/submodules/gambatte @@ -1 +1 @@ -Subproject commit e35e24de89f06642852f622d7d4159ba6a4abea2 +Subproject commit 0838651ca7c06d8c236834dcf5aa307092b2a82e diff --git a/waterbox/melon/melonDS b/waterbox/melon/melonDS index 3c9510523bf..4e02967468c 160000 --- a/waterbox/melon/melonDS +++ b/waterbox/melon/melonDS @@ -1 +1 @@ -Subproject commit 3c9510523bfbdf7d39e5185dcfbc72146bb8b52f +Subproject commit 4e02967468c3b5ea853f5fdb0ca0b25a02fd601c From 02746efd63fd28191e1610c00f2d34aea85e369c Mon Sep 17 00:00:00 2001 From: Fortranm Date: Tue, 2 Jul 2024 15:40:45 -0700 Subject: [PATCH 25/27] fix the crash from Toggle Link Connection --- .../Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index a1de6b526f6..a30cb00e04d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -22,7 +22,7 @@ public bool FrameAdvance(IController controller, bool render, bool rendersound = foreach (var s in GBLinkController.BoolButtons) { if (!controller.IsPressed(s)) continue; - Debug.Assert(s[0] is 'P'); + if (s[0] is not 'P') continue; var iSpace = s.IndexOf(' '); var playerNum = int.Parse(s.Substring(startIndex: 1, length: iSpace - 1)); var consoleNum = 0; From 06496c695f690b67bebfdad8e179d04b1fdb8278 Mon Sep 17 00:00:00 2001 From: Fortranm Date: Wed, 3 Jul 2024 20:29:17 -0700 Subject: [PATCH 26/27] remove inaccurate description of how Auto works for console --- .../Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs index f06075a25f1..874d0926620 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISettable.cs @@ -115,7 +115,7 @@ public enum ConsoleModeType } [DisplayName("Console Mode")] - [Description("Which console to emulate ('Auto' picks based on the rom header)")] + [Description("Picks which console to emulate.")] [DefaultValue(ConsoleModeType.Auto)] public ConsoleModeType ConsoleMode { get; set; } From 0e32693d06bceb256260412c0796eecad94aec8f Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sat, 6 Jul 2024 02:20:57 +1000 Subject: [PATCH 27/27] Remove unused import --- .../Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs index 969b69ebbe5..7549f3e416f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IEmulator.cs @@ -1,5 +1,3 @@ -using System.Diagnostics; - using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common;