Skip to content

Commit ca06775

Browse files
committed
dsda: attempt to display internal load errors
see #4488
1 parent 76345f3 commit ca06775

File tree

6 files changed

+57
-33
lines changed

6 files changed

+57
-33
lines changed

Assets/dll/dsda.wbx.zst

22 Bytes
Binary file not shown.

src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public MAME(CoreLoadParameters<object, MAMESyncSettings> lp)
122122
private string _gameFullName = "Arcade";
123123
private string _gameShortName = "arcade";
124124
private string _driverSourceFile = "";
125-
private string _loadFailure = string.Empty;
125+
private string _loadFailure = "";
126126
private byte[] _configFile;
127127

128128
public string RomDetails { get; set; }

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

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ public partial class DSDA : IRomInfo
2626
public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
2727
{
2828
ServiceProvider = new BasicServiceProvider(this);
29+
Comm = lp.Comm;
2930
_finalSyncSettings = _syncSettings = lp.SyncSettings ?? new DoomSyncSettings();
3031
_settings = lp.Settings ?? new DoomSettings();
31-
Comm = lp.Comm;
3232
_loadCallback = LoadCallback;
33+
_errorCallback = ErrorCallback;
3334

3435
// Gathering information for the rest of the wads
3536
_wadFiles = lp.Roms;
@@ -48,12 +49,12 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
4849
if (foundIWAD)
4950
{
5051
throw new ArgumentException(
51-
$"More than one IWAD provided. Trying to load '{wadFile.RomPath}', but IWAD '{iwadName}' was already provided",
52+
$"More than one IWAD provided. Trying to load '{wadFile.RomPath}', but IWAD '{_iwadName}' was already provided",
5253
paramName: nameof(lp));
5354
}
5455

55-
iwadName = wadFile.RomPath;
56-
iwadData = wadFile.RomData;
56+
_iwadName = wadFile.RomPath;
57+
_iwadData = wadFile.RomData;
5758
foundIWAD = true;
5859
recognized = true;
5960
}
@@ -74,18 +75,18 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
7475
// Check at least one IWAD was provided
7576
if (!foundIWAD)
7677
{
77-
iwadData = lp.Comm.CoreFileProvider.GetFirmware(
78+
_iwadData = lp.Comm.CoreFileProvider.GetFirmware(
7879
new(VSystemID.Raw.Doom, "Doom2_IWAD"));
7980

80-
if (iwadData == null)
81+
if (_iwadData == null)
8182
{
8283
throw new ArgumentException(
8384
"No IWAD file provided",
8485
paramName: nameof(lp));
8586
}
8687

87-
_ = FirmwareDatabase.FirmwareFilesByHash.TryGetValue(SHA1Checksum.ComputeDigestHex(iwadData), out var ff);
88-
iwadName = ff.RecommendedName;
88+
_ = FirmwareDatabase.FirmwareFilesByHash.TryGetValue(SHA1Checksum.ComputeDigestHex(_iwadData), out var ff);
89+
_iwadName = ff.RecommendedName;
8990
}
9091

9192
// Getting dsda-doom.wad -- required by DSDA
@@ -98,9 +99,9 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
9899
totalWadSize += wadFile.FileData.Length;
99100
}
100101
int totalWadSizeKb = (totalWadSize / 1024) + 1;
101-
if (!string.IsNullOrEmpty(iwadName))
102+
if (!string.IsNullOrEmpty(_iwadName))
102103
{
103-
totalWadSizeKb += iwadData.Length / 1024;
104+
totalWadSizeKb += _iwadData.Length / 1024;
104105
}
105106
Console.WriteLine($"Reserving {totalWadSizeKb}kb for WAD file memory");
106107

@@ -173,7 +174,7 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
173174
{
174175
var callingConventionAdapter = CallingConventionAdapters.MakeWaterbox(
175176
[
176-
_loadCallback, _randomCallback
177+
_loadCallback, _randomCallback, _errorCallback
177178
], _elf);
178179

179180
using (_elf.EnterExit())
@@ -184,11 +185,11 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
184185
_core.dsda_add_wad_file(_dsdaWadFileName, _dsdaWadFileData.Length, _loadCallback);
185186

186187
// Adding IWAD file
187-
_gameMode = _core.dsda_add_wad_file(iwadName, iwadData.Length, _loadCallback);
188+
_gameMode = _core.dsda_add_wad_file(_iwadName, _iwadData.Length, _loadCallback);
188189
if (_gameMode is LibDSDA.GameMode.Fail)
189190
{
190191
throw new ArgumentException(
191-
$"Could not load IWAD file: '{iwadName}'",
192+
$"Could not load IWAD file: '{_iwadName}'",
192193
paramName: nameof(lp));
193194
}
194195

@@ -210,6 +211,8 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
210211
initSettings.DisplayPlayer = _settings.DisplayPlayer - 1;
211212
CreateArguments(initSettings);
212213

214+
_core.dsda_set_error_callback(_errorCallback);
215+
213216
var initResult = _core.dsda_init(ref initSettings, _args.Count, _args.ToArray());
214217
if (!initResult)
215218
{
@@ -223,9 +226,9 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
223226

224227
// db stores md5 for detection but it's nice to show both to user
225228
RomDetails = lp.Game.Name +
226-
$"\r\n\r\nIWAD: {Path.GetFileName(iwadName.SubstringAfter('|'))}" +
227-
$"\r\n{SHA1Checksum.ComputePrefixedHex(iwadData)}" +
228-
$"\r\n{MD5Checksum.ComputePrefixedHex(iwadData)}";
229+
$"\r\n\r\nIWAD: {Path.GetFileName(_iwadName.SubstringAfter('|'))}" +
230+
$"\r\n{SHA1Checksum.ComputePrefixedHex(_iwadData)}" +
231+
$"\r\n{MD5Checksum.ComputePrefixedHex(_iwadData)}";
229232

230233
if (_pwadFiles.Count > 0)
231234
{
@@ -338,10 +341,15 @@ private static bool PlayerPresent(DoomSyncSettings syncSettings, int port) =>
338341
private readonly LibDSDA.load_archive_cb _loadCallback;
339342
private readonly byte[] _dsdaWadFileData;
340343
private readonly byte[] _configFile;
344+
private readonly int[] _runSpeeds = [ 25, 50 ];
345+
private readonly int[] _strafeSpeeds = [ 24, 40 ];
346+
private readonly int[] _turnSpeeds = [ 640, 1280, 320 ];
347+
private readonly string _dsdaWadFileName = "dsda-doom.wad";
348+
341349
// order must match AspectRatio values since they're used as index
342350
private readonly Point[][] _resolutions =
343351
[
344-
// we want to support 1x widescreen so internal scale is universal,
352+
// we want to support 1x widescreen so that internal scale is universal,
345353
// but lowest widescreen multiple of native height (corrected or not) is 1280x720.
346354
// it doesn't divide nicely so we have to use
347355
// artificial lowres replacements that aren't exactly 16:9 or 16:10.
@@ -353,13 +361,9 @@ private static bool PlayerPresent(DoomSyncSettings syncSettings, int port) =>
353361
[ new(426, 256), new(854, 512), new(1280, 768) ],
354362
[ new(320, 240) ],
355363
];
356-
private readonly int[] _runSpeeds = [ 25, 50 ];
357-
private readonly int[] _strafeSpeeds = [ 24, 40 ];
358-
private readonly int[] _turnSpeeds = [ 640, 1280, 320 ];
359-
private readonly string _dsdaWadFileName = "dsda-doom.wad";
360-
private byte[] iwadData = Array.Empty<byte>();
361-
private string iwadName = "";
362364

365+
private string _iwadName = "";
366+
private byte[] _iwadData = Array.Empty<byte>();
363367
private int[] _turnHeld = [ 0, 0, 0, 0 ];
364368
private int _turnCarry; // Chocolate Doom mouse behaviour (enabled in upstream by default)
365369
private bool _lastGammaInput;
@@ -368,11 +372,16 @@ private static bool PlayerPresent(DoomSyncSettings syncSettings, int port) =>
368372
private List<IRomAsset> _pwadFiles;
369373
private LibDSDA.GameMode _gameMode;
370374
private LibDSDA.random_cb _randomCallback;
375+
private LibDSDA.error_cb _errorCallback;
371376

372377
public List<Action<int>> RandomCallbacks = [ ];
373-
374378
public string RomDetails { get; } // IRomInfo
375379

380+
private void ErrorCallback(string error)
381+
{
382+
throw new Exception($"\n\n{error}\n");
383+
}
384+
376385
/// <summary>
377386
/// core callback for file loading
378387
/// </summary>
@@ -400,14 +409,14 @@ private int LoadCallback(string filename, IntPtr buffer, int maxsize)
400409
srcdata = _dsdaWadFileData;
401410
}
402411

403-
if (filename == iwadName)
412+
if (filename == _iwadName)
404413
{
405-
if (iwadData == null)
414+
if (_iwadData == null)
406415
{
407-
Console.WriteLine($"Could not read from WAD file '{iwadName}'");
416+
Console.WriteLine($"Could not read from WAD file '{_iwadName}'");
408417
return 0;
409418
}
410-
srcdata = iwadData;
419+
srcdata = _iwadData;
411420
}
412421

413422
foreach (var wadFile in _wadFiles)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ public abstract bool dsda_frame_advance(
150150

151151
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
152152
public delegate void random_cb(int pr_class);
153-
154153
[BizImport(CallingConvention.Cdecl)]
155154
public abstract void dsda_set_random_callback(random_cb cb);
155+
156+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
157+
public delegate void error_cb(string error);
158+
[BizImport(CallingConvention.Cdecl)]
159+
public abstract void dsda_set_error_callback(error_cb cb);
156160
}
157161
}

waterbox/dsda/BizhawkInterface.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,19 +421,30 @@ ECL_EXPORT bool dsda_frame_advance(AutomapButtons buttons, struct PackedPlayerIn
421421
return !wipeDone;
422422
}
423423

424+
// P_Random() calls
424425
ECL_ENTRY void (*random_callback_cb)(int);
425-
426426
void biz_random_callback(int pr_class)
427427
{
428428
if (random_callback_cb)
429429
random_callback_cb(pr_class);
430430
}
431-
432431
ECL_EXPORT void dsda_set_random_callback(ECL_ENTRY void (*cb)(int))
433432
{
434433
random_callback_cb = cb;
435434
}
436435

436+
// showing errors to user
437+
ECL_ENTRY void (*error_callback_cb)(const char *);
438+
void biz_error_callback(const char *s)
439+
{
440+
if (error_callback_cb)
441+
error_callback_cb(s);
442+
}
443+
ECL_EXPORT void dsda_set_error_callback(ECL_ENTRY void (*cb)(const char *))
444+
{
445+
error_callback_cb = cb;
446+
}
447+
437448
ECL_EXPORT int dsda_init(struct InitSettings *settings, int argc, char **argv)
438449
{
439450
printf("Passing arguments: \n");

waterbox/dsda/core

0 commit comments

Comments
 (0)