|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Drawing; |
| 3 | +using System.IO; |
| 4 | + |
| 5 | +using BizHawk.Emulation.Common; |
| 6 | +using BizHawk.Emulation.Cores; |
| 7 | +using BizHawk.Emulation.Cores.Consoles.Sega.gpgx; |
| 8 | + |
| 9 | +using SMSHawk = BizHawk.Emulation.Cores.Sega.MasterSystem.SMS; |
| 10 | + |
| 11 | +using static BizHawk.Emulation.Cores.Consoles.Sega.gpgx.GPGX; |
| 12 | +using static BizHawk.Emulation.Cores.Consoles.Sega.gpgx.LibGPGX.InitSettings; |
| 13 | +using static BizHawk.Emulation.Cores.Sega.MasterSystem.SMS; |
| 14 | + |
| 15 | +namespace BizHawk.Tests.Testroms.SMS |
| 16 | +{ |
| 17 | + public static class SMSHelper |
| 18 | + { |
| 19 | + public readonly struct CoreSetup |
| 20 | + { |
| 21 | + public const string GPGX_MAME = $"{CoreNames.Gpgx}_MAMESound"; |
| 22 | + |
| 23 | + public const string GPGX_NUKED = $"{CoreNames.Gpgx}_NukedSound"; |
| 24 | + |
| 25 | + public static IReadOnlyCollection<CoreSetup> ValidSetupsFor() |
| 26 | + => new CoreSetup[] |
| 27 | + { |
| 28 | + new(GPGX_MAME), |
| 29 | + new(GPGX_MAME, useBios: false), |
| 30 | + new(GPGX_NUKED), |
| 31 | + new(GPGX_NUKED, useBios: false), |
| 32 | + new(CoreNames.SMSHawk), |
| 33 | + new(CoreNames.SMSHawk, useBios: false), |
| 34 | + }; |
| 35 | + |
| 36 | + public readonly string CoreName; |
| 37 | + |
| 38 | + public readonly bool UseBIOS; |
| 39 | + |
| 40 | + public CoreSetup(string coreName, bool useBios = true) |
| 41 | + { |
| 42 | + CoreName = coreName; |
| 43 | + UseBIOS = useBios; |
| 44 | + } |
| 45 | + |
| 46 | + public readonly override string ToString() |
| 47 | + => $"{CoreName}{(UseBIOS ? string.Empty : " (no BIOS)")}"; |
| 48 | + } |
| 49 | + |
| 50 | + private static readonly GPGXSyncSettings GPGXSyncSettings_MAME_NOBIOS = new() { LoadBIOS = false, SMSFMSoundChip = SMSFMSoundChipType.YM2413_MAME }; |
| 51 | + |
| 52 | + private static readonly GPGXSyncSettings GPGXSyncSettings_MAME_USEBIOS = new() { LoadBIOS = true, SMSFMSoundChip = SMSFMSoundChipType.YM2413_MAME }; |
| 53 | + |
| 54 | + private static readonly GPGXSyncSettings GPGXSyncSettings_NUKED_NOBIOS = new() { LoadBIOS = false, SMSFMSoundChip = SMSFMSoundChipType.YM2413_NUKED }; |
| 55 | + |
| 56 | + private static readonly GPGXSyncSettings GPGXSyncSettings_NUKED_USEBIOS = new() { LoadBIOS = true, SMSFMSoundChip = SMSFMSoundChipType.YM2413_NUKED }; |
| 57 | + |
| 58 | + private static readonly SmsSyncSettings SMSHawkSyncSettings_NOBIOS = new() { UseBios = false }; |
| 59 | + |
| 60 | + private static readonly SmsSyncSettings SMSHawkSyncSettings_USEBIOS = new() { UseBios = true }; |
| 61 | + |
| 62 | + private static bool AddEmbeddedSMSBIOS(this DummyFrontend.EmbeddedFirmwareProvider efp) |
| 63 | + => efp.AddIfExists(new("SMS", "Export"), "res.fw.SMS__Export__U_1_3.bin"); |
| 64 | + |
| 65 | + public static GPGXSyncSettings GetGPGXSyncSettings(string coreVariant, bool biosAvailable) |
| 66 | + => coreVariant is CoreSetup.GPGX_NUKED |
| 67 | + ? biosAvailable ? GPGXSyncSettings_NUKED_USEBIOS : GPGXSyncSettings_NUKED_NOBIOS |
| 68 | + : biosAvailable ? GPGXSyncSettings_MAME_USEBIOS : GPGXSyncSettings_MAME_NOBIOS; |
| 69 | + |
| 70 | + public static SmsSyncSettings GetSMSHawkSyncSettings(bool biosAvailable) |
| 71 | + => biosAvailable ? SMSHawkSyncSettings_USEBIOS : SMSHawkSyncSettings_NOBIOS; |
| 72 | + |
| 73 | + public static DummyFrontend.ClassInitCallbackDelegate InitSMSCore(CoreSetup setup, string romFilename, byte[] rom) |
| 74 | + => (efp, _, coreComm) => |
| 75 | + { |
| 76 | + efp.UseReflectionCache(ReflectionCache.EmbeddedResourceList(), ReflectionCache.EmbeddedResourceStream); |
| 77 | + if (setup.UseBIOS && !efp.AddEmbeddedSMSBIOS()) Assert.Inconclusive("BIOS not provided"); |
| 78 | + var game = Database.GetGameInfo(rom, romFilename); |
| 79 | + IEmulator newCore = setup.CoreName switch |
| 80 | + { |
| 81 | + CoreSetup.GPGX_MAME or CoreSetup.GPGX_NUKED => new GPGX(new CoreLoadParameters<GPGX.GPGXSettings, GPGX.GPGXSyncSettings> |
| 82 | + { |
| 83 | + Comm = coreComm, |
| 84 | + DeterministicEmulationRequested = true, |
| 85 | + Game = game, |
| 86 | + Roms = { new DummyRomAsset(rom, VSystemID.Raw.SMS) }, |
| 87 | + Settings = new(), |
| 88 | + SyncSettings = GetGPGXSyncSettings(setup.CoreName, setup.UseBIOS), |
| 89 | + }), |
| 90 | + CoreNames.SMSHawk => new SMSHawk(coreComm, game, rom, new(), GetSMSHawkSyncSettings(setup.UseBIOS)), |
| 91 | + _ => throw new InvalidOperationException("unknown SMS core"), |
| 92 | + }; |
| 93 | + return (newCore, setup.UseBIOS ? 388 : 5); |
| 94 | + }; |
| 95 | + |
| 96 | + public static TestUtils.TestSuccessState SMSScreenshotsEqual( |
| 97 | + Stream expectFile, |
| 98 | + Image? actual, |
| 99 | + bool expectingNotEqual, |
| 100 | + CoreSetup setup, |
| 101 | + (string Suite, string Case) id, |
| 102 | + IReadOnlyDictionary<int, int>? extraPaletteMap = null) |
| 103 | + { |
| 104 | + if (actual is null) |
| 105 | + { |
| 106 | + Assert.Fail("actual screenshot was null"); |
| 107 | + return TestUtils.TestSuccessState.Failure; // never hit |
| 108 | + } |
| 109 | + return ImageUtils.ScreenshotsEqualMagickDotNET( |
| 110 | + expectFile, |
| 111 | + extraPaletteMap is null ? actual : ImageUtils.PaletteSwap(actual, extraPaletteMap), |
| 112 | + expectingNotEqual, |
| 113 | + id); |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments