dsda: expose resolution factor and gamma

see #4236

rename Core to _core since it's private
This commit is contained in:
feos 2025-03-01 20:58:23 +03:00
parent 4a7e0c6008
commit 7c5d050cde
7 changed files with 44 additions and 25 deletions

View File

@ -116,7 +116,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
renderInfo._RenderAudio = renderAudio ? 1 : 0;
renderInfo._PlayerPointOfView = _settings.DisplayPlayer - 1;
Core.dsda_frame_advance(
_core.dsda_frame_advance(
ref players[0],
ref players[1],
ref players[2],

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
addr =>
{
if (addr > 0xFFFFFF) throw new ArgumentOutOfRangeException(paramName: nameof(addr), addr, message: "address out of range");
return Core.dsda_read_memory_array(CInterface.MemoryArrayType.Things, (uint)addr);
return _core.dsda_read_memory_array(CInterface.MemoryArrayType.Things, (uint)addr);
},
null,
1),

View File

@ -118,6 +118,20 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
[CoreSettings]
public class DoomSettings
{
[DisplayName("Internal Resolution Scale Factor")]
[Description("Which factor to increase internal resolution by [1 - 12]. Affects \"quality\" of rendered image at the cost of accuracy. Native resolution is 320x200 resized to 4:3 DAR on a CRT monitor.")]
[Range(1, 12)]
[DefaultValue(1)]
[TypeConverter(typeof(ConstrainedIntConverter))]
public int ScaleFactor { get; set; }
[DisplayName("Gamma Correction Level")]
[Description("Increases brightness [0 - 4]. Default value in vanilla Doom is 0 (\"OFF\").")]
[Range(0, 4)]
[DefaultValue(0)]
[TypeConverter(typeof(ConstrainedIntConverter))]
public int Gamma { get; set; }
[JsonIgnore]
[DisplayName("Player Point of View")]
[Description("Which of the players' point of view to use during rendering")]

View File

@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
private unsafe void UpdateAudio()
{
var src = IntPtr.Zero;
Core.dsda_get_audio(ref _nsamp, ref src);
_core.dsda_get_audio(ref _nsamp, ref src);
if (src != IntPtr.Zero)
{

View File

@ -12,7 +12,6 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
{
_elf.LoadStateBinary(reader);
// Getting last mouse positions
_turnHeld[0] = reader.ReadInt32();
_turnHeld[1] = reader.ReadInt32();
_turnHeld[2] = reader.ReadInt32();
@ -20,7 +19,6 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
Frame = reader.ReadInt32();
// any managed pointers that we sent to the core need to be resent now!
//Core.stella_set_input_callback(_inputCallback);
UpdateVideo();
}
@ -28,7 +26,6 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
{
_elf.SaveStateBinary(writer);
// Writing last mouse positions
writer.Write(_turnHeld[0]);
writer.Write(_turnHeld[1]);
writer.Write(_turnHeld[2]);

View File

@ -32,7 +32,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
{
var videoBufferSrc = IntPtr.Zero;
var palletteBufferSrc = IntPtr.Zero;
Core.dsda_get_video(out var width, out var height, out var pitch, ref videoBufferSrc, out var paletteSize, ref palletteBufferSrc);
_core.dsda_get_video(out var width, out var height, out var pitch, ref videoBufferSrc, out var paletteSize, ref palletteBufferSrc);
// Handling pallette buffer
PaletteSize = paletteSize;

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
@ -70,9 +71,16 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
uint totalWadSize = (uint)_dsdaWadFileData.Length;
foreach (var wadFile in _wadFiles) totalWadSize += (uint) wadFile.FileData.Length;
uint totalWadSizeKb = (totalWadSize / 1024) + 1;
Console.WriteLine("Reserving {0}kb for WAD file memory", totalWadSizeKb);
Console.WriteLine($"Reserving {totalWadSizeKb}kb for WAD file memory");
_configFile = Encoding.ASCII.GetBytes("screen_resolution \"320x200\"");
_configFile = Encoding.ASCII.GetBytes($"screen_resolution \"{
_nativeResolution.X * _settings.ScaleFactor}x{
_nativeResolution.Y * _settings.ScaleFactor}\"\n"
+ $"usegamma {_settings.Gamma}\n"
+ "uncapped_framerate 0\n"
+ "render_stretch_hud 0\n"
+ "render_stretchsky 0\n"
);
_elf = new WaterboxHost(new WaterboxOptions
{
@ -96,15 +104,15 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
using (_elf.EnterExit())
{
Core = BizInvoker.GetInvoker<CInterface>(_elf, _elf, callingConventionAdapter);
_core = BizInvoker.GetInvoker<CInterface>(_elf, _elf, callingConventionAdapter);
// Adding dsda-doom wad file
Core.dsda_add_wad_file(_dsdaWadFileName, _dsdaWadFileData.Length, _loadCallback);
_core.dsda_add_wad_file(_dsdaWadFileName, _dsdaWadFileData.Length, _loadCallback);
// Adding rom files
foreach (var wadFile in _wadFiles)
{
var loadWadResult = Core.dsda_add_wad_file(wadFile.RomPath, wadFile.RomData.Length, _loadCallback);
var loadWadResult = _core.dsda_add_wad_file(wadFile.RomPath, wadFile.RomData.Length, _loadCallback);
if (!loadWadResult) throw new Exception($"Could not load WAD file: '{wadFile.RomPath}'");
}
@ -112,8 +120,8 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
var initSettings = _syncSettings.GetNativeSettings(lp.Game);
CreateArguments(initSettings);
var initResult = Core.dsda_init(ref initSettings, _args.Count, _args.ToArray());
if (!initResult) throw new Exception($"{nameof(Core.dsda_init)}() failed");
var initResult = _core.dsda_init(ref initSettings, _args.Count, _args.ToArray());
if (!initResult) throw new Exception($"{nameof(_core.dsda_init)}() failed");
int fps = 35;
VsyncNumerator = fps;
@ -169,17 +177,17 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
}
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
private readonly CInterface.load_archive_cb _loadCallback;
private readonly string _dsdaWadFileName = "dsda-doom.wad";
private readonly byte[] _dsdaWadFileData;
private readonly CInterface Core;
private readonly WaterboxHost _elf;
private readonly CInterface _core;
private readonly CInterface.load_archive_cb _loadCallback;
private readonly DoomControllerDeck _controllerDeck;
private readonly byte[] _configFile;
private readonly Point _nativeResolution = new(320, 200);
private readonly int[] _runSpeeds = [ 25, 50 ];
private readonly int[] _strafeSpeeds = [ 24, 40 ];
private readonly int[] _turnSpeeds = [ 640, 1280, 320 ];
private readonly string _dsdaWadFileName = "dsda-doom.wad";
private readonly byte[] _dsdaWadFileData;
private readonly byte[] _configFile;
private int[] _turnHeld = [ 0, 0, 0, 0 ];
private List<string> _args;
private List<IRomAsset> _wadFiles;
@ -197,7 +205,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
if (buffer == IntPtr.Zero)
{
Console.WriteLine("Couldn't satisfy firmware request {0} because buffer == NULL", filename);
Console.WriteLine($"Couldn't satisfy firmware request {filename} because buffer == NULL");
return 0;
}
@ -217,7 +225,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
{
if (wadFile.FileData == null)
{
Console.WriteLine("Could not read from WAD file '{0}'", filename);
Console.WriteLine($"Could not read from WAD file '{filename}'");
return 0;
}
srcdata = wadFile.FileData;
@ -228,14 +236,14 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
{
if (srcdata.Length > maxsize)
{
Console.WriteLine("Couldn't satisfy firmware request {0} because {1} > {2}", filename, srcdata.Length, maxsize);
Console.WriteLine($"Couldn't satisfy firmware request {filename} because {srcdata.Length} > {maxsize}");
return 0;
}
else
{
Console.WriteLine("Copying Data from " + srcdata + " to " + buffer + " Size: " + srcdata.Length);
Console.WriteLine($"Copying Data from {srcdata} to {buffer}. Size: {srcdata.Length}");
Marshal.Copy(srcdata, 0, buffer, srcdata.Length);
Console.WriteLine("Firmware request {0} satisfied at size {1}", filename, srcdata.Length);
Console.WriteLine($"Firmware request {filename} satisfied at size {srcdata.Length}");
return srcdata.Length;
}
}