Skip to content

Commit c0f93b0

Browse files
committed
dsda: load wads correctly regardless of their order in xml
internal wad goes first, then whatever IWAD we found, then all the PWADs show all files in rom info
1 parent 631e5c3 commit c0f93b0

File tree

1 file changed

+27
-6
lines changed
  • src/BizHawk.Emulation.Cores/Computers/Doom

1 file changed

+27
-6
lines changed

src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using BizHawk.BizInvoke;
88
using BizHawk.Common;
99
using BizHawk.Common.PathExtensions;
10+
using BizHawk.Common.StringExtensions;
1011
using BizHawk.Emulation.Common;
1112
using BizHawk.Emulation.Cores.Properties;
1213
using BizHawk.Emulation.Cores.Waterbox;
@@ -35,6 +36,7 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
3536
_wadFiles = lp.Roms;
3637

3738
// Checking for correct IWAD configuration
39+
_pwadFiles = new();
3840
bool foundIWAD = false;
3941
string IWADName = "";
4042
foreach (var wadFile in _wadFiles)
@@ -45,11 +47,13 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
4547
// Check not more than one IWAD is provided
4648
if (foundIWAD) throw new Exception($"More than one IWAD provided. Trying to load '{wadFile.RomPath}', but IWAD '{IWADName}' was already provided");
4749
IWADName = wadFile.RomPath;
50+
_iwadFile = wadFile;
4851
foundIWAD = true;
4952
recognized = true;
5053
}
5154
else if (wadFile.RomData is [ (byte) 'P', (byte) 'W', (byte) 'A', (byte) 'D', .. ])
5255
{
56+
_pwadFiles.Add(wadFile);
5357
recognized = true;
5458
}
5559
if (!recognized) throw new Exception($"Unrecognized WAD provided: '{wadFile.RomPath}' has non-standard header.");
@@ -133,10 +137,15 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
133137
// Adding dsda-doom wad file
134138
_core.dsda_add_wad_file(_dsdaWadFileName, _dsdaWadFileData.Length, _loadCallback);
135139

136-
// Adding rom files
137-
foreach (var wadFile in _wadFiles)
140+
// Adding IWAD file
141+
var loadWadResult = _core.dsda_add_wad_file(_iwadFile.RomPath, _iwadFile.RomData.Length, _loadCallback);
142+
if (loadWadResult is 0) throw new Exception($"Could not load WAD file: '{_iwadFile.RomPath}'");
143+
_gameMode = (LibDSDA.GameMode)loadWadResult;
144+
145+
// Adding PWAD file(s)
146+
foreach (var wadFile in _pwadFiles)
138147
{
139-
var loadWadResult = _core.dsda_add_wad_file(wadFile.RomPath, wadFile.RomData.Length, _loadCallback);
148+
loadWadResult = _core.dsda_add_wad_file(wadFile.RomPath, wadFile.RomData.Length, _loadCallback);
140149
if (loadWadResult is 0) throw new Exception($"Could not load WAD file: '{wadFile.RomPath}'");
141150
_gameMode = (LibDSDA.GameMode)loadWadResult;
142151
}
@@ -148,11 +157,19 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
148157
var initResult = _core.dsda_init(ref initSettings, _args.Count, _args.ToArray());
149158
if (!initResult) throw new Exception($"{nameof(_core.dsda_init)}() failed");
150159

151-
int fps = 35;
152-
VsyncNumerator = fps;
160+
VsyncNumerator = 35;
153161
VsyncDenominator = 1;
154162

155-
RomDetails = $"{lp.Game.Name}\r\n{SHA1Checksum.ComputePrefixedHex(_wadFiles[0].RomData)}\r\n{MD5Checksum.ComputePrefixedHex(_wadFiles[0].RomData)}";
163+
RomDetails += $"IWAD: {GetFullName(_iwadFile)}" +
164+
$"\r\n{SHA1Checksum.ComputePrefixedHex(_iwadFile.RomData)}" +
165+
$"\r\n{MD5Checksum.ComputePrefixedHex(_iwadFile.RomData)}";
166+
167+
foreach (var file in _pwadFiles)
168+
{
169+
RomDetails += $"\r\n\r\nPWAD: {GetFullName(file)}" +
170+
$"\r\n{SHA1Checksum.ComputePrefixedHex(file.RomData)}" +
171+
$"\r\n{MD5Checksum.ComputePrefixedHex(file.RomData)}";
172+
}
156173

157174
_elf.Seal();
158175
}
@@ -206,6 +223,8 @@ private void ConditionalArg(bool condition, string setting)
206223
}
207224
}
208225

226+
private string GetFullName(IRomAsset rom) => Path.GetFileName(rom.RomPath.SubstringAfter('|'));
227+
209228
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
210229
private readonly WaterboxHost _elf;
211230
private readonly LibDSDA _core;
@@ -221,7 +240,9 @@ private void ConditionalArg(bool condition, string setting)
221240
private int _turnCarry = 0; // Chocolate Doom mouse behaviour (enabled in upstream by default)
222241
private bool _lastGammaInput = false;
223242
private List<string> _args;
243+
private IRomAsset _iwadFile;
224244
private List<IRomAsset> _wadFiles;
245+
private List<IRomAsset> _pwadFiles;
225246
private LibDSDA.GameMode _gameMode;
226247
public string RomDetails { get; } // IRomInfo
227248

0 commit comments

Comments
 (0)