diff --git a/.gitmodules b/.gitmodules index 200d51d928..6a4289d928 100644 --- a/.gitmodules +++ b/.gitmodules @@ -46,3 +46,6 @@ [submodule "submodules/sameboy/libsameboy"] path = submodules/sameboy/libsameboy url = https://github.com/LIJI32/SameBoy.git +[submodule "waterbox/ares64/ares/thirdparty/angrylion-rdp"] + path = waterbox/ares64/ares/thirdparty/angrylion-rdp + url = https://github.com/TASEmulators/angrylion-rdp diff --git a/Assets/dll/ares64.wbx.gz b/Assets/dll/ares64.wbx.gz index 5d384ed8e5..4dc43f9075 100644 Binary files a/Assets/dll/ares64.wbx.gz and b/Assets/dll/ares64.wbx.gz differ diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index c84857fc3e..412303fb61 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -27,7 +27,7 @@ namespace BizHawk.Client.Common (new[] { VSystemID.Raw.SNES }, new[] { CoreNames.Faust, CoreNames.Snes9X, CoreNames.Bsnes, CoreNames.Bsnes115 }), (new[] { VSystemID.Raw.N64 }, - new[] { CoreNames.Mupen64Plus, CoreNames.Ares64Performance, CoreNames.Ares64Accuracy }), + new[] { CoreNames.Mupen64Plus, CoreNames.Ares64 }), (new[] { VSystemID.Raw.SGB }, new[] { CoreNames.Gambatte, CoreNames.Bsnes, CoreNames.Bsnes115}), (new[] { VSystemID.Raw.GB, VSystemID.Raw.GBC }, @@ -37,7 +37,7 @@ namespace BizHawk.Client.Common (new[] { VSystemID.Raw.PCE, VSystemID.Raw.PCECD, VSystemID.Raw.SGX }, new[] { CoreNames.TurboNyma, CoreNames.HyperNyma, CoreNames.PceHawk }), (new[] { VSystemID.Raw.PSX }, - new[] { CoreNames.Octoshock, CoreNames.Nymashock}), + new[] { CoreNames.Octoshock, CoreNames.Nymashock }), (new[] { VSystemID.Raw.TI83 }, new[] { CoreNames.TI83Hawk, CoreNames.Emu83 }), }; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Accuracy.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Accuracy.ISettable.cs deleted file mode 100644 index 5dc596fcfb..0000000000 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Accuracy.ISettable.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.ComponentModel; - -using BizHawk.Common; -using BizHawk.Emulation.Common; - -namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Accuracy -{ - public partial class Ares64 : ISettable - { - private Ares64SyncSettings _syncSettings; - - public object GetSettings() => null; - - public Ares64SyncSettings GetSyncSettings() => _syncSettings.Clone(); - - public PutSettingsDirtyBits PutSettings(object o) => PutSettingsDirtyBits.None; - - public PutSettingsDirtyBits PutSyncSettings(Ares64SyncSettings o) - { - var ret = Ares64SyncSettings.NeedsReboot(_syncSettings, o); - _syncSettings = o; - return ret ? PutSettingsDirtyBits.RebootCore : PutSettingsDirtyBits.None; - } - - public class Ares64SyncSettings - { - [DisplayName("Player 1 Controller")] - [Description("")] - [DefaultValue(LibAres64.ControllerType.Mempak)] - public LibAres64.ControllerType P1Controller { get; set; } - - [DisplayName("Player 2 Controller")] - [Description("")] - [DefaultValue(LibAres64.ControllerType.Unplugged)] - public LibAres64.ControllerType P2Controller { get; set; } - - [DisplayName("Player 3 Controller")] - [Description("")] - [DefaultValue(LibAres64.ControllerType.Unplugged)] - public LibAres64.ControllerType P3Controller { get; set; } - - [DisplayName("Player 4 Controller")] - [Description("")] - [DefaultValue(LibAres64.ControllerType.Unplugged)] - public LibAres64.ControllerType P4Controller { get; set; } - - [DisplayName("Restrict Analog Range")] - [Description("Restricts analog range to account for physical limitations.")] - [DefaultValue(false)] - public bool RestrictAnalogRange { get; set; } - - public Ares64SyncSettings() => SettingsUtil.SetDefaultValues(this); - - public Ares64SyncSettings Clone() => MemberwiseClone() as Ares64SyncSettings; - - public static bool NeedsReboot(Ares64SyncSettings x, Ares64SyncSettings y) => !DeepEquality.DeepEquals(x, y); - } - } -} diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Performance.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.ISettable.cs similarity index 59% rename from src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Performance.ISettable.cs rename to src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.ISettable.cs index 721ffc1053..0ce1d0d492 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Performance.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.ISettable.cs @@ -1,22 +1,25 @@ -using System; using System.ComponentModel; -using Newtonsoft.Json; - using BizHawk.Common; using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Performance +namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64 { - public partial class Ares64 : ISettable + public partial class Ares64 : ISettable { + private Ares64Settings _settings; private Ares64SyncSettings _syncSettings; - public object GetSettings() => null; + public Ares64Settings GetSettings() => _settings.Clone(); public Ares64SyncSettings GetSyncSettings() => _syncSettings.Clone(); - public PutSettingsDirtyBits PutSettings(object o) => PutSettingsDirtyBits.None; + public PutSettingsDirtyBits PutSettings(Ares64Settings o) + { + var ret = Ares64Settings.NeedsReboot(_settings, o); + _settings = o; + return ret ? PutSettingsDirtyBits.RebootCore : PutSettingsDirtyBits.None; + } public PutSettingsDirtyBits PutSyncSettings(Ares64SyncSettings o) { @@ -25,6 +28,21 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Performance return ret ? PutSettingsDirtyBits.RebootCore : PutSettingsDirtyBits.None; } + public class Ares64Settings + { + [DisplayName("Deinterlacer")] + [Description("Weave looks good for still images, but creates artifacts for moving images.\n" + + "Bob looks good for moving images, but makes the image bob up and down.")] + [DefaultValue(LibAres64.DeinterlacerType.Weave)] + public LibAres64.DeinterlacerType Deinterlacer { get; set; } + + public Ares64Settings() => SettingsUtil.SetDefaultValues(this); + + public Ares64Settings Clone() => MemberwiseClone() as Ares64Settings; + + public static bool NeedsReboot(Ares64Settings x, Ares64Settings y) => !DeepEquality.DeepEquals(x, y); + } + public class Ares64SyncSettings { [DisplayName("Player 1 Controller")] @@ -52,21 +70,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Performance [DefaultValue(false)] public bool RestrictAnalogRange { get; set; } - [DisplayName("Enable Vulkan")] - [Description("Enables Vulkan RDP. May fallback to software RDP if your GPU does not support Vulkan.")] - [DefaultValue(true)] - public bool EnableVulkan { get; set; } - - [DisplayName("Supersampling")] - [Description("Scales HD and UHD resolutions back down to SD")] - [DefaultValue(false)] - public bool SuperSample { get; set; } - - [DisplayName("Vulkan Upscale")] - [Description("")] - [DefaultValue(LibAres64.VulkanUpscaleOpts.SD)] - public LibAres64.VulkanUpscaleOpts VulkanUpscale { get; set; } - public Ares64SyncSettings() => SettingsUtil.SetDefaultValues(this); public Ares64SyncSettings Clone() => MemberwiseClone() as Ares64SyncSettings; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Performance.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Performance.cs deleted file mode 100644 index 7e9ee6880b..0000000000 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Performance.cs +++ /dev/null @@ -1,469 +0,0 @@ -using System; -using System.IO; -using System.Linq; - -using BizHawk.BizInvoke; -using BizHawk.Common; -using BizHawk.Emulation.Common; -using BizHawk.Emulation.Cores.Properties; -using BizHawk.Emulation.Cores.Waterbox; - -namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Performance -{ - [PortedCore(CoreNames.Ares64Performance, "ares team, Near", "v126", "https://ares-emulator.github.io/", singleInstance: true, isReleased: false)] - [ServiceNotApplicable(new[] { typeof(IDriveLight), })] - public partial class Ares64 : IEmulator, IVideoProvider, ISoundProvider, IStatable, IInputPollable, ISaveRam, IRegionable - { - private static readonly LibAres64Performance _core; - - static Ares64() - { - var resolver = new DynamicLibraryImportResolver( - OSTailoredCode.IsUnixHost ? "libares64.so" : "libares64.dll", hasLimitedLifetime: false); - _core = BizInvoker.GetInvoker(resolver, CallingConventionAdapters.Native); - } - - private readonly BasicServiceProvider _serviceProvider; - - public IEmulatorServiceProvider ServiceProvider => _serviceProvider; - - public int Frame { get; private set; } - - public int LagCount { get; set; } - - public bool IsLagFrame { get; set; } - - [FeatureNotImplemented] - public IInputCallbackSystem InputCallbacks => throw new NotImplementedException(); - - public string SystemId => VSystemID.Raw.N64; - - public bool DeterministicEmulation => false; - - public void ResetCounters() - { - Frame = 0; - LagCount = 0; - IsLagFrame = false; - } - - public void Dispose() => _core.Deinit(); - - [CoreConstructor(VSystemID.Raw.N64)] - public Ares64(CoreLoadParameters lp) - { - if (lp.DeterministicEmulationRequested) - { - lp.Comm.ShowMessage("This core is not deterministic, switch over to the Ares (Accuracy) core for deterministic movie recordings. You have been warned!"); - } - - _serviceProvider = new(this); - - _syncSettings = lp.SyncSettings ?? new(); - - int upscale = _syncSettings.EnableVulkan ? (int)_syncSettings.VulkanUpscale : 1; - _videoBuffer = new int[640 * upscale * 576 * upscale]; - - ControllerSettings = new[] - { - _syncSettings.P1Controller, - _syncSettings.P2Controller, - _syncSettings.P3Controller, - _syncSettings.P4Controller, - }; - - N64Controller = CreateControllerDefinition(ControllerSettings); - - var rom = lp.Roms[0].RomData; - - Region = rom[0x3E] switch - { - 0x44 or 0x46 or 0x49 or 0x50 or 0x53 or 0x55 or 0x58 or 0x59 => DisplayType.PAL, - _ => DisplayType.NTSC, - }; - - var pal = Region == DisplayType.PAL; - - VsyncNumerator = pal ? 50 : 60000; - VsyncDenominator = pal ? 1 : 1001; - - LibAres64.LoadFlags loadFlags = 0; - if (_syncSettings.RestrictAnalogRange) - loadFlags |= LibAres64.LoadFlags.RestrictAnalogRange; - if (pal) - loadFlags |= LibAres64.LoadFlags.Pal; - if (_syncSettings.EnableVulkan) - loadFlags |= LibAres64.LoadFlags.UseVulkan; - if (_syncSettings.SuperSample) - loadFlags |= LibAres64.LoadFlags.SuperSample; - - var pif = Util.DecompressGzipFile(new MemoryStream(pal ? Resources.PIF_PAL_ROM.Value : Resources.PIF_NTSC_ROM.Value)); - - unsafe - { - fixed (byte* pifPtr = pif, romPtr = rom) - { - var loadData = new LibAres64.LoadData() - { - PifData = (IntPtr)pifPtr, - PifLen = pif.Length, - RomData = (IntPtr)romPtr, - RomLen = rom.Length, - VulkanUpscale = upscale, - }; - if (!_core.Init(loadData, ControllerSettings, loadFlags)) - { - throw new InvalidOperationException("Init returned false!"); - } - } - } - - ResetCounters(); - - var areas = new LibWaterboxCore.MemoryArea[256]; - _core.GetMemoryAreas(areas); - _memoryAreas = areas.Where(a => a.Data != IntPtr.Zero && a.Size != 0 && !a.Flags.HasFlag(LibWaterboxCore.MemoryDomainFlags.FunctionHook)) - .ToArray(); - - var memoryDomains = _memoryAreas.Select(a => new WaterboxMemoryDomainPointer(a, _monitor)).ToList(); - var primaryDomain = memoryDomains - .Where(md => md.Definition.Flags.HasFlag(LibWaterboxCore.MemoryDomainFlags.Primary)) - .Single(); - - var mdl = new MemoryDomainList( - memoryDomains.Cast().ToList() - ) - { - MainMemory = primaryDomain - }; - _serviceProvider.Register(mdl); - - _saveramAreas = memoryDomains - .Where(md => md.Definition.Flags.HasFlag(LibWaterboxCore.MemoryDomainFlags.Saverammable)) - .ToArray(); - _saveramSize = (int)_saveramAreas.Sum(a => a.Size); - } - - public DisplayType Region { get; } - - public ControllerDefinition ControllerDefinition => N64Controller; - - private ControllerDefinition N64Controller { get; } - - public LibAres64.ControllerType[] ControllerSettings { get; } - - private static ControllerDefinition CreateControllerDefinition(LibAres64.ControllerType[] controllerSettings) - { - var ret = new ControllerDefinition("Nintendo 64 Controller"); - for (int i = 0; i < 4; i++) - { - if (controllerSettings[i] != LibAres64.ControllerType.Unplugged) - { - ret.BoolButtons.Add($"P{i + 1} DPad U"); - ret.BoolButtons.Add($"P{i + 1} DPad D"); - ret.BoolButtons.Add($"P{i + 1} DPad L"); - ret.BoolButtons.Add($"P{i + 1} DPad R"); - ret.BoolButtons.Add($"P{i + 1} Start"); - ret.BoolButtons.Add($"P{i + 1} Z"); - ret.BoolButtons.Add($"P{i + 1} B"); - ret.BoolButtons.Add($"P{i + 1} A"); - ret.BoolButtons.Add($"P{i + 1} C Up"); - ret.BoolButtons.Add($"P{i + 1} C Down"); - ret.BoolButtons.Add($"P{i + 1} C Left"); - ret.BoolButtons.Add($"P{i + 1} C Right"); - ret.BoolButtons.Add($"P{i + 1} L"); - ret.BoolButtons.Add($"P{i + 1} R"); - ret.AddXYPair($"P{i + 1} {{0}} Axis", AxisPairOrientation.RightAndUp, (-128).RangeTo(127), 0); - if (controllerSettings[i] == LibAres64.ControllerType.Rumblepak) - { - ret.HapticsChannels.Add($"P{i + 1} Rumble Pak"); - } - } - } - ret.BoolButtons.Add("Reset"); - ret.BoolButtons.Add("Power"); - return ret.MakeImmutable(); - } - - private static LibAres64.Buttons GetButtons(IController controller, int num) - { - LibAres64.Buttons ret = 0; - - if (controller.IsPressed($"P{num} DPad U")) - ret |= LibAres64.Buttons.UP; - if (controller.IsPressed($"P{num} DPad D")) - ret |= LibAres64.Buttons.DOWN; - if (controller.IsPressed($"P{num} DPad L")) - ret |= LibAres64.Buttons.LEFT; - if (controller.IsPressed($"P{num} DPad R")) - ret |= LibAres64.Buttons.RIGHT; - if (controller.IsPressed($"P{num} B")) - ret |= LibAres64.Buttons.B; - if (controller.IsPressed($"P{num} A")) - ret |= LibAres64.Buttons.A; - if (controller.IsPressed($"P{num} C Up")) - ret |= LibAres64.Buttons.C_UP; - if (controller.IsPressed($"P{num} C Down")) - ret |= LibAres64.Buttons.C_DOWN; - if (controller.IsPressed($"P{num} C Left")) - ret |= LibAres64.Buttons.C_LEFT; - if (controller.IsPressed($"P{num} C Right")) - ret |= LibAres64.Buttons.C_RIGHT; - if (controller.IsPressed($"P{num} L")) - ret |= LibAres64.Buttons.L; - if (controller.IsPressed($"P{num} R")) - ret |= LibAres64.Buttons.R; - if (controller.IsPressed($"P{num} Z")) - ret |= LibAres64.Buttons.Z; - if (controller.IsPressed($"P{num} Start")) - ret |= LibAres64.Buttons.START; - - return ret; - } - - private LibWaterboxCore.FrameInfo FrameAdvancePrep(IController controller, bool render, bool rendersound) - { - for (int i = 0; i < 4; i++) - { - if (ControllerSettings[i] == LibAres64.ControllerType.Rumblepak) - { - controller.SetHapticChannelStrength($"P{i + 1} Rumble Pak", _core.GetRumbleStatus(i) ? int.MaxValue : 0); - } - } - - return new LibAres64.FrameInfo - { - P1Buttons = GetButtons(controller, 1), - P1XAxis = (short)controller.AxisValue("P1 X Axis"), - P1YAxis = (short)controller.AxisValue("P1 Y Axis"), - - P2Buttons = GetButtons(controller, 2), - P2XAxis = (short)controller.AxisValue("P2 X Axis"), - P2YAxis = (short)controller.AxisValue("P2 Y Axis"), - - P3Buttons = GetButtons(controller, 3), - P3XAxis = (short)controller.AxisValue("P3 X Axis"), - P3YAxis = (short)controller.AxisValue("P3 Y Axis"), - - P4Buttons = GetButtons(controller, 4), - P4XAxis = (short)controller.AxisValue("P4 X Axis"), - P4YAxis = (short)controller.AxisValue("P4 Y Axis"), - - Reset = controller.IsPressed("Reset"), - Power = controller.IsPressed("Power"), - }; - } - - public unsafe bool FrameAdvance(IController controller, bool render, bool rendersound = true) - { - _core.SetInputCallback(null); - - fixed (int* vp = _videoBuffer) - fixed (short* sp = _soundBuffer) - { - var frame = FrameAdvancePrep(controller, render, rendersound); - frame.VideoBuffer = (IntPtr)vp; - frame.SoundBuffer = (IntPtr)sp; - - _core.FrameAdvance(frame); - - Frame++; - if (IsLagFrame = frame.Lagged != 0) - LagCount++; - - if (render) - { - BufferWidth = frame.Width; - BufferHeight = frame.Height; - } - if (rendersound) - { - _numSamples = frame.Samples; - } - else - { - _numSamples = 0; - } - - FrameAdvancePost(); - } - - return true; - } - - private void FrameAdvancePost() - { - if (BufferWidth == 1 && BufferHeight == 1) - { - BufferWidth = 640; - BufferHeight = 480; - _blankFrame = true; - } - else - { - _blankFrame = false; - } - } - - public int[] GetVideoBuffer() => _blankFrame ? _blankBuffer : _videoBuffer; - - private bool _blankFrame; - - private readonly int[] _blankBuffer = new int[640 * 480]; - - private readonly int[] _videoBuffer; - - public int VirtualWidth => 640; - - public int VirtualHeight => 480; - - public int BufferWidth { get; private set; } - - public int BufferHeight { get; private set; } - - public int VsyncNumerator { get; } - - public int VsyncDenominator { get; } - - public int BackgroundColor => unchecked((int)0xff000000); - - public void SetSyncMode(SyncSoundMode mode) - { - if (mode == SyncSoundMode.Async) - { - throw new NotSupportedException("Async mode is not supported."); - } - } - - public void GetSamplesSync(out short[] samples, out int nsamp) - { - samples = _soundBuffer; - nsamp = _numSamples; - } - - public void GetSamplesAsync(short[] samples) => throw new InvalidOperationException("Async mode is not supported."); - - public void DiscardSamples() {} - - private readonly short[] _soundBuffer = new short[2048 * 2]; - - private int _numSamples; - - public bool CanProvideAsync => false; - - public SyncSoundMode SyncMode => SyncSoundMode.Sync; - - private byte[] _stateBuffer = new byte[0]; - - public void SaveStateBinary(BinaryWriter writer) - { - var len = _core.SerializeSize(); - if (len != _stateBuffer.Length) - { - _stateBuffer = new byte[len]; - } - _core.Serialize(_stateBuffer); - writer.Write(_stateBuffer.Length); - writer.Write(_stateBuffer); - - // other variables - writer.Write(Frame); - writer.Write(LagCount); - writer.Write(IsLagFrame); - } - - public void LoadStateBinary(BinaryReader reader) - { - var len = reader.ReadInt32(); - if (len != _core.SerializeSize()) - { - throw new InvalidOperationException("Savestate size mismatch!"); - } - if (len != _stateBuffer.Length) - { - _stateBuffer = new byte[len]; - } - reader.Read(_stateBuffer, 0, len); - if (!_core.Unserialize(_stateBuffer, len)) - { - throw new Exception($"{nameof(_core.Unserialize)}() returned false!"); - } - - // other variables - Frame = reader.ReadInt32(); - LagCount = reader.ReadInt32(); - IsLagFrame = reader.ReadBoolean(); - } - - private readonly LibWaterboxCore.MemoryArea[] _memoryAreas; - - private readonly WaterboxMemoryDomain[] _saveramAreas; - private readonly int _saveramSize; - - public unsafe bool SaveRamModified - { - get - { - if (_saveramSize == 0) - return false; - var buff = new byte[4096]; - fixed (byte* bp = buff) - { - foreach (var area in _saveramAreas) - { - var stream = new MemoryDomainStream(area); - int cmp = (area.Definition.Flags & LibWaterboxCore.MemoryDomainFlags.OneFilled) != 0 ? -1 : 0; - while (true) - { - int nread = stream.Read(buff, 0, 4096); - if (nread == 0) - break; - - int* p = (int*)bp; - int* pend = p + nread / sizeof(int); - while (p < pend) - { - if (*p++ != cmp) - return true; - } - } - } - } - return false; - } - } - - public byte[] CloneSaveRam() - { - if (_saveramSize == 0) - return null; - var ret = new byte[_saveramSize]; - var dest = new MemoryStream(ret, true); - foreach (var area in _saveramAreas) - { - new MemoryDomainStream(area).CopyTo(dest); - } - return ret; - } - - public void StoreSaveRam(byte[] data) - { - if (data.Length != _saveramSize) - throw new InvalidOperationException("Saveram size mismatch"); - var source = new MemoryStream(data, false); - foreach (var area in _saveramAreas) - { - WaterboxUtils.CopySome(source, new MemoryDomainStream(area), area.Size); - } - } - - private readonly DummyMonitor _monitor = new(); - - private class DummyMonitor : IMonitor - { - public void Enter() { } - - public void Exit() { } - } - } -} diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Accuracy.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.cs similarity index 86% rename from src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Accuracy.cs rename to src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.cs index 0b8902ef99..594217ff93 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.Accuracy.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/Ares64.cs @@ -6,16 +6,16 @@ using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Properties; using BizHawk.Emulation.Cores.Waterbox; -namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Accuracy +namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64 { - [PortedCore(CoreNames.Ares64Accuracy, "ares team, Near", "v126", "https://ares-emulator.github.io/", isReleased: false)] + [PortedCore(CoreNames.Ares64, "ares team, Near", "v127", "https://ares-emulator.github.io/", isReleased: false)] [ServiceNotApplicable(new[] { typeof(IDriveLight), })] public partial class Ares64 : WaterboxCore, IRegionable { - private readonly LibAres64Accuracy _core; + private readonly LibAres64 _core; [CoreConstructor(VSystemID.Raw.N64)] - public Ares64(CoreLoadParameters lp) + public Ares64(CoreLoadParameters lp) : base(lp.Comm, new Configuration { DefaultWidth = 640, @@ -23,11 +23,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Accuracy MaxWidth = 640, MaxHeight = 576, MaxSamples = 2048, - DefaultFpsNumerator = 60000, - DefaultFpsDenominator = 1001, + DefaultFpsNumerator = 60, + DefaultFpsDenominator = 1, SystemId = VSystemID.Raw.N64, }) { + _settings = lp.Settings ?? new(); _syncSettings = lp.SyncSettings ?? new(); ControllerSettings = new[] @@ -40,7 +41,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Accuracy N64Controller = CreateControllerDefinition(ControllerSettings); - _core = PreInit(new WaterboxOptions + _core = PreInit(new WaterboxOptions { Filename = "ares64.wbx", SbrkHeapSizeKB = 2 * 1024, @@ -73,6 +74,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Accuracy loadFlags |= LibAres64.LoadFlags.RestrictAnalogRange; if (pal) loadFlags |= LibAres64.LoadFlags.Pal; + if (_settings.Deinterlacer == LibAres64.DeinterlacerType.Bob) + loadFlags |= LibAres64.LoadFlags.BobDeinterlace; var pif = Util.DecompressGzipFile(new MemoryStream(pal ? Resources.PIF_PAL_ROM.Value : Resources.PIF_NTSC_ROM.Value)); @@ -87,7 +90,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Accuracy RomData = (IntPtr)romPtr, RomLen = rom.Length, }; - if (!_core.Init(loadData, ControllerSettings, loadFlags)) + if (!_core.Init(ref loadData, ControllerSettings, loadFlags)) { throw new InvalidOperationException("Init returned false!"); } @@ -207,17 +210,5 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64.Accuracy Power = controller.IsPressed("Power"), }; } - - protected override void FrameAdvancePost() - { - if (BufferWidth == 0) - { - BufferWidth = BufferHeight == 239 ? 320 : 640; - } - } - - public override int VirtualWidth => 640; - - public override int VirtualHeight => 480; } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/LibAres64.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/LibAres64.cs index 5ffed5c253..a7029adff0 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/LibAres64.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Ares64/LibAres64.cs @@ -35,6 +35,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64 Rumblepak, } + public enum DeinterlacerType : uint + { + Weave, + Bob, + } + [StructLayout(LayoutKind.Sequential)] public new class FrameInfo : LibWaterboxCore.FrameInfo { @@ -64,52 +70,22 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64 { RestrictAnalogRange = 1 << 0, Pal = 1 << 1, - // performance only flags - UseVulkan = 1 << 2, - SuperSample = 1 << 3, - } - - public enum VulkanUpscaleOpts : uint - { - SD = 1, - HD = 2, - UHD = 4, + BobDeinterlace = 1 << 2, // weave otherwise } [StructLayout(LayoutKind.Sequential)] - public class LoadData + public struct LoadData { public IntPtr PifData; public int PifLen; public IntPtr RomData; public int RomLen; - // performance only data - public int VulkanUpscale; } [BizImport(CC)] - public abstract bool Init(LoadData loadData, ControllerType[] controllerSettings, LoadFlags loadFlags); + public abstract bool Init(ref LoadData loadData, ControllerType[] controllerSettings, LoadFlags loadFlags); [BizImport(CC)] public abstract bool GetRumbleStatus(int num); } - - public abstract class LibAres64Accuracy : LibAres64 - { - } - - public abstract class LibAres64Performance : LibAres64 - { - [BizImport(CC)] - public abstract void Deinit(); - - [BizImport(CC)] - public abstract int SerializeSize(); - - [BizImport(CC)] - public abstract void Serialize(byte[] buf); - - [BizImport(CC)] - public abstract bool Unserialize(byte[] buf, int sz); - } } diff --git a/src/BizHawk.Emulation.Cores/CoreNames.cs b/src/BizHawk.Emulation.Cores/CoreNames.cs index 60de16a832..747822d36f 100644 --- a/src/BizHawk.Emulation.Cores/CoreNames.cs +++ b/src/BizHawk.Emulation.Cores/CoreNames.cs @@ -10,8 +10,7 @@ namespace BizHawk.Emulation.Cores public static class CoreNames { public const string A7800Hawk = "A7800Hawk"; - public const string Ares64Accuracy = "Ares64 (Accuracy)"; - public const string Ares64Performance = "Ares64 (Performance)"; + public const string Ares64 = "Ares64"; public const string Atari2600Hawk = "Atari2600Hawk"; public const string Bsnes = "BSNES"; public const string Bsnes115 = "BSNESv115+"; diff --git a/src/BizHawk.Emulation.Cores/vpads_schemata/N64Schema.cs b/src/BizHawk.Emulation.Cores/vpads_schemata/N64Schema.cs index c070a7fd5c..647b3ff835 100644 --- a/src/BizHawk.Emulation.Cores/vpads_schemata/N64Schema.cs +++ b/src/BizHawk.Emulation.Cores/vpads_schemata/N64Schema.cs @@ -26,21 +26,11 @@ namespace BizHawk.Emulation.Cores } } } - else if (core is Consoles.Nintendo.Ares64.Accuracy.Ares64 ares64Acc) + else if (core is Ares64 ares64) { for (var i = 0; i < 4; i++) { - if (ares64Acc.ControllerSettings[i] != LibAres64.ControllerType.Unplugged) - { - yield return StandardController(i + 1); - } - } - } - else if (core is Consoles.Nintendo.Ares64.Performance.Ares64 ares64Perf) - { - for (var i = 0; i < 4; i++) - { - if (ares64Perf.ControllerSettings[i] != LibAres64.ControllerType.Unplugged) + if (ares64.ControllerSettings[i] != LibAres64.ControllerType.Unplugged) { yield return StandardController(i + 1); } diff --git a/waterbox/ares64/BizInterface.cpp b/waterbox/ares64/BizInterface.cpp index 1bd1519343..599c8e0896 100644 --- a/waterbox/ares64/BizInterface.cpp +++ b/waterbox/ares64/BizInterface.cpp @@ -1,17 +1,10 @@ #include -#if WATERBOXED #include #include -#endif #include -#ifndef WATERBOXED -#define ECL_EXPORT __attribute__((visibility("default"))) -#include "../emulibc/waterboxcore.h" -#endif - #define EXPORT extern "C" ECL_EXPORT typedef enum @@ -321,9 +314,7 @@ static inline SaveType DetectSaveType(u8* rom) return ret; } -namespace ares::Nintendo64 { extern bool RestrictAnalogRange; } - -bool Inited = false; +namespace ares::Nintendo64 { extern bool RestrictAnalogRange; extern bool BobDeinterlace; } typedef struct { @@ -331,27 +322,17 @@ typedef struct u32 PifLen; u8* RomData; u32 RomLen; -#ifndef WATERBOXED - u32 VulkanUpscale; -#endif } LoadData; typedef enum { RESTRICT_ANALOG_RANGE = 1 << 0, IS_PAL = 1 << 1, -#ifndef WATERBOXED - USE_VULKAN = 1 << 2, - SUPER_SAMPLE = 1 << 3, -#endif + BOB_DEINTERLACE = 1 << 2, // weave otherwise (todo: implement this) } LoadFlags; -EXPORT void Deinit(); - EXPORT bool Init(LoadData* loadData, ControllerType* controllers, LoadFlags loadFlags) { - if (Inited) Deinit(); - platform = new BizPlatform; platform->bizpak = new vfs::directory; @@ -397,7 +378,7 @@ EXPORT bool Init(LoadData* loadData, ControllerType* controllers, LoadFlags load case SRAM32KB: len = 32 * 1024; name = "save.ram"; break; case SRAM96KB: len = 96 * 1024; name = "save.ram"; break; case FLASH128KB: len = 128 * 1024; name = "save.flash"; break; - default: Deinit(); return false; + default: return false; } data = new u8[len]; memset(data, 0xFF, len); @@ -407,15 +388,8 @@ EXPORT bool Init(LoadData* loadData, ControllerType* controllers, LoadFlags load ares::platform = platform; -#ifndef WATERBOXED - ares::Nintendo64::option("Enable Vulkan", !!(loadFlags & USE_VULKAN)); - ares::Nintendo64::option("Quality", loadData->VulkanUpscale == 1 ? "SD" : (loadData->VulkanUpscale == 2 ? "HD" : "UHD")); - ares::Nintendo64::option("Supersampling", !!(loadFlags & SUPER_SAMPLE)); -#endif - if (!ares::Nintendo64::load(root, {"[Nintendo] Nintendo 64 (", region, ")"})) { - Deinit(); return false; } @@ -426,7 +400,6 @@ EXPORT bool Init(LoadData* loadData, ControllerType* controllers, LoadFlags load } else { - Deinit(); return false; } @@ -453,51 +426,23 @@ EXPORT bool Init(LoadData* loadData, ControllerType* controllers, LoadFlags load } else { - Deinit(); return false; } } else { - Deinit(); return false; } } ares::Nintendo64::RestrictAnalogRange = loadFlags & RESTRICT_ANALOG_RANGE; + ares::Nintendo64::BobDeinterlace = loadFlags & BOB_DEINTERLACE; root->power(false); HackeryDoo(); - Inited = true; return true; } -EXPORT void Deinit() -{ - if (root) root->unload(); - if (platform) - { - if (platform->bizpak) platform->bizpak.reset(); - delete platform; - } - if (pifData) - { - delete[] (u8*)pifData->data(); - delete pifData; - } - if (romData) - { - delete[] (u8*)romData->data(); - delete romData; - } - if (saveData) - { - delete[] (u8*)saveData->data(); - delete saveData; - } - Inited = false; -} - EXPORT bool GetRumbleStatus(u32 num) { ares::Nintendo64::Gamepad* c = nullptr; @@ -511,23 +456,6 @@ EXPORT bool GetRumbleStatus(u32 num) return c ? c->motor->enable() : false; } -EXPORT u32 SerializeSize() -{ - return root->serialize(false).size(); -} - -EXPORT void Serialize(u8* buf) -{ - auto s = root->serialize(false); - memcpy(buf, s.data(), s.size()); -} - -EXPORT bool Unserialize(u8* buf, u32 sz) -{ - serializer s(buf, sz); - return root->unserialize(s); -} - #define ADD_MEMORY_DOMAIN(mem, name, flags) do { \ m[i].Data = ares::Nintendo64::mem.data; \ m[i].Name = name; \ @@ -565,7 +493,6 @@ EXPORT void GetMemoryAreas(MemoryArea *m) ADD_MEMPAK_DOMAIN(4); } -// fixme: this mismatches the c# side due to some re-ordering c# is doing for some reason struct MyFrameInfo : public FrameInfo { Buttons_t P1Buttons; @@ -664,4 +591,4 @@ EXPORT void FrameAdvance(MyFrameInfo* f) EXPORT void SetInputCallback(void (*callback)()) { platform->inputcb = callback; - } +} diff --git a/waterbox/ares64/Accuracy.mak b/waterbox/ares64/Makefile similarity index 57% rename from waterbox/ares64/Accuracy.mak rename to waterbox/ares64/Makefile index 4e3014e2bc..fb70480bec 100644 --- a/waterbox/ares64/Accuracy.mak +++ b/waterbox/ares64/Makefile @@ -1,18 +1,15 @@ NEED_LIBCO := 1 ARES_PATH = $(ROOT_DIR)/ares/ares -MAME_PATH = $(ROOT_DIR)/ares/thirdparty/mame +ANGRYLION_PATH = $(ROOT_DIR)/ares/thirdparty/angrylion-rdp/mylittle-nocomment CXXFLAGS := -std=c++17 -msse4.2 \ -I../libco -I.$(ROOT_DIR)/ares/ -I.$(ROOT_DIR)/ares/thirdparty/ -I.$(ARES_PATH) \ - -Werror=int-to-pointer-cast -Wno-unused-but-set-variable -Wno-delete-non-virtual-dtor \ - -Wno-parentheses -Wno-reorder -Wno-unused-variable \ + -Werror=int-to-pointer-cast -Wno-unused-but-set-variable -Wno-format-security \ + -Wno-parentheses -Wno-reorder -Wno-unused-variable -Wno-delete-non-virtual-dtor \ -Wno-sign-compare -Wno-switch -Wno-unused-local-typedefs \ -fno-strict-aliasing -fwrapv -fno-operator-names \ - -I.$(MAME_PATH)/devices -I.$(MAME_PATH)/emu \ - -I.$(MAME_PATH)/lib/util -I.$(MAME_PATH)/mame \ - -I.$(MAME_PATH)/osd -DMAME_RDP -DLSB_FIRST -DPTR64 -DSDLMAME_EMSCRIPTEN \ - -DWATERBOXED + -I.$(ANGRYLION_PATH) -DANGRYLION_RDP TARGET = ares64.wbx @@ -42,17 +39,10 @@ SRCS_N64 = \ $(ARES_PATH)/n64/rdp/rdp.cpp \ $(ARES_PATH)/n64/rsp/rsp.cpp -SRCS_MAME = \ - $(MAME_PATH)/emu/emucore.cpp \ - $(MAME_PATH)/lib/util/delegate.cpp \ - $(MAME_PATH)/lib/util/strformat.cpp \ - $(MAME_PATH)/mame/video/n64.cpp \ - $(MAME_PATH)/mame/video/pin64.cpp \ - $(MAME_PATH)/mame/video/rdpblend.cpp \ - $(MAME_PATH)/mame/video/rdptpipe.cpp \ - $(MAME_PATH)/osd/osdcore.cpp \ - $(MAME_PATH)/osd/osdsync.cpp +SRCS_ANGRYLION = \ + $(ANGRYLION_PATH)/main.cpp \ + $(ANGRYLION_PATH)/n64video.cpp -SRCS = $(SRCS_PROCESSORS) $(SRCS_ARES) $(SRCS_N64) $(SRCS_MAME) BizInterface.cpp +SRCS = $(SRCS_PROCESSORS) $(SRCS_ARES) $(SRCS_N64) $(SRCS_ANGRYLION) BizInterface.cpp include ../common.mak diff --git a/waterbox/ares64/Performance.mak b/waterbox/ares64/Performance.mak deleted file mode 100644 index 55a868b6d4..0000000000 --- a/waterbox/ares64/Performance.mak +++ /dev/null @@ -1,160 +0,0 @@ -ARES_PATH = $(ROOT_DIR)/ares/ares -MAME_PATH = $(ROOT_DIR)/ares/thirdparty/mame -SLJIT_PATH = $(ROOT_DIR)/ares/thirdparty/sljit - -CCFLAGS := -std=c99 -Wall -Wno-format -Wno-parentheses - -CXXFLAGS := -std=c++17 -msse4.2 -O3 -flto -fvisibility=internal \ - -I../libco -I.$(ROOT_DIR)/ares/ -I.$(ROOT_DIR)/ares/thirdparty/ -I.$(ARES_PATH) \ - -Werror=int-to-pointer-cast -Wno-unused-but-set-variable \ - -Wno-parentheses -Wno-reorder -Wno-unused-variable \ - -Wno-sign-compare -Wno-switch -Wno-unused-local-typedefs \ - -fno-strict-aliasing -fwrapv -fno-operator-names \ - -I.$(MAME_PATH)/devices -I.$(MAME_PATH)/emu \ - -I.$(MAME_PATH)/lib/util -I.$(MAME_PATH)/mame \ - -I.$(MAME_PATH)/osd -DMAME_RDP -DLSB_FIRST -DPTR64 -DSLJIT_HAVE_CONFIG_PRE=1 -DSLJIT_HAVE_CONFIG_POST=1 -fPIC - -LDFLAGS := -shared - -ifeq ($(OS),Windows_NT) - CCFLAGS += -DVK_USE_PLATFORM_WIN32_KHR - CXXFLAGS += -DVK_USE_PLATFORM_WIN32_KHR -DOSD_WINDOWS=1 - TARGET = libares64.dll -else - CXXFLAGS += -DSDLMAME_LINUX - TARGET = libares64.so -endif - -SRCS_LIBCO = \ - $(ROOT_DIR)/ares/libco/libco.c - -SRCS_PROCESSORS = \ - $(ARES_PATH)/component/processor/sm5k/sm5k.cpp - -SRCS_ARES = \ - $(ARES_PATH)/ares/ares.cpp \ - $(ARES_PATH)/ares/memory/fixed-allocator.cpp - -SRCS_N64 = \ - $(ARES_PATH)/n64/memory/memory.cpp \ - $(ARES_PATH)/n64/system/system.cpp \ - $(ARES_PATH)/n64/cartridge/cartridge.cpp \ - $(ARES_PATH)/n64/controller/controller.cpp \ - $(ARES_PATH)/n64/dd/dd.cpp \ - $(ARES_PATH)/n64/sp/sp.cpp \ - $(ARES_PATH)/n64/dp/dp.cpp \ - $(ARES_PATH)/n64/mi/mi.cpp \ - $(ARES_PATH)/n64/vi/vi.cpp \ - $(ARES_PATH)/n64/ai/ai.cpp \ - $(ARES_PATH)/n64/pi/pi.cpp \ - $(ARES_PATH)/n64/ri/ri.cpp \ - $(ARES_PATH)/n64/si/si.cpp \ - $(ARES_PATH)/n64/rdram/rdram.cpp \ - $(ARES_PATH)/n64/cpu/cpu.cpp \ - $(ARES_PATH)/n64/rdp/rdp.cpp \ - $(ARES_PATH)/n64/rsp/rsp.cpp \ - $(ARES_PATH)/n64/vulkan/vulkan.cpp - -PARALLEL_RDP_IMPLEMENTATION = $(ARES_PATH)/n64/vulkan/parallel-rdp - -SRCS_PARALLEL_RDP = \ - $(wildcard $(PARALLEL_RDP_IMPLEMENTATION)/parallel-rdp/*.cpp) \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/buffer.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/buffer_pool.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/command_buffer.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/command_pool.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/context.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/cookie.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/descriptor_set.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/device.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/event_manager.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/fence.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/fence_manager.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/image.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/memory_allocator.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/pipeline_event.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/query_pool.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/render_pass.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/sampler.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/semaphore.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/semaphore_manager.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/shader.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/vulkan/texture_format.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/util/logging.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/util/thread_id.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/util/aligned_alloc.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/util/timer.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/util/timeline_trace_file.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/util/thread_name.cpp \ - $(PARALLEL_RDP_IMPLEMENTATION)/volk/volk.c - -PARALLEL_RDP_INCLUDE_DIRS = \ - -I.$(PARALLEL_RDP_IMPLEMENTATION)/parallel-rdp \ - -I.$(PARALLEL_RDP_IMPLEMENTATION)/volk \ - -I.$(PARALLEL_RDP_IMPLEMENTATION)/vulkan \ - -I.$(PARALLEL_RDP_IMPLEMENTATION)/vulkan-headers/include \ - -I.$(PARALLEL_RDP_IMPLEMENTATION)/util - -CXXFLAGS += $(PARALLEL_RDP_INCLUDE_DIRS) -DVULKAN -DGRANITE_VULKAN_MT -CCFLAGS += $(PARALLEL_RDP_INCLUDE_DIRS) - -SRCS_MAME = \ - $(MAME_PATH)/emu/emucore.cpp \ - $(MAME_PATH)/lib/util/delegate.cpp \ - $(MAME_PATH)/lib/util/strformat.cpp \ - $(MAME_PATH)/mame/video/n64.cpp \ - $(MAME_PATH)/mame/video/pin64.cpp \ - $(MAME_PATH)/mame/video/rdpblend.cpp \ - $(MAME_PATH)/mame/video/rdptpipe.cpp \ - $(MAME_PATH)/osd/osdcore.cpp \ - $(MAME_PATH)/osd/osdsync.cpp - -SRCS_SLJIT = \ - $(SLJIT_PATH)/../sljitAllocator.cpp \ - $(SLJIT_PATH)/sljit_src/sljitLir.c - -SRCS = $(SRCS_LIBCO) $(SRCS_PROCESSORS) $(SRCS_ARES) $(SRCS_N64) $(SRCS_PARALLEL_RDP) $(SRCS_MAME) $(SRCS_SLJIT) BizInterface.cpp - -ROOT_DIR := $(shell dirname $(realpath Performance.mak)) -OUTPUTDLL_DIR := $(realpath $(ROOT_DIR)/../../Assets/dll) -OUTPUTDLLCOPY_DIR := $(realpath $(ROOT_DIR)/../../output/dll) -OUT_DIR := $(ROOT_DIR)/obj -OBJ_DIR := $(OUT_DIR)/release_performance - -CC := gcc -CXX := g++ - -_OBJS := $(addsuffix .o,$(realpath $(SRCS))) -OBJS := $(patsubst $(ROOT_DIR)%,$(OBJ_DIR)%,$(_OBJS)) - -$(OBJ_DIR)/%.c.o: %.c - @echo cc $< - @mkdir -p $(@D) - @$(CC) -c -o $@ $< $(CCFLAGS) $(PER_FILE_FLAGS_$<) -$(OBJ_DIR)/%.cpp.o: %.cpp - @echo cxx $< - @mkdir -p $(@D) - @$(CXX) -c -o $@ $< $(CXXFLAGS) $(PER_FILE_FLAGS_$<) - -.DEFAULT_GOAL := install - -.PHONY: release install - -TARGET_RELEASE := $(OBJ_DIR)/$(TARGET) - -release: $(TARGET_RELEASE) - -$(TARGET_RELEASE): $(OBJS) - @echo ld $@ - @$(CXX) -o $@ $(LDFLAGS) $(CCFLAGS) $(CXXFLAGS) $(OBJS) - -install: $(TARGET_RELEASE) - @cp -f $(TARGET_RELEASE) $(OUTPUTDLL_DIR)/$(TARGET) - @cp -f $(TARGET_RELEASE) $(OUTPUTDLLCOPY_DIR)/$(TARGET) - @echo Release build of $(TARGET) installed. - -.PHONY: clean -clean: - rm -rf $(OUT_DIR) - --include $(OBJS:%o=%d) diff --git a/waterbox/ares64/ares/ares/ares/ares.hpp b/waterbox/ares64/ares/ares/ares/ares.hpp index ff9f200e9b..9a219dfe7f 100644 --- a/waterbox/ares64/ares/ares/ares/ares.hpp +++ b/waterbox/ares64/ares/ares/ares/ares.hpp @@ -1,11 +1,7 @@ #pragma once -#ifdef WATERBOXED #include #include -#else -#include -#endif #include @@ -61,11 +57,7 @@ namespace ares { } namespace Video { -#ifdef WATERBOXED static constexpr bool Threaded = false; -#else - static constexpr bool Threaded = true; -#endif } namespace Constants { diff --git a/waterbox/ares64/ares/ares/ares/node/video/screen.cpp b/waterbox/ares64/ares/ares/ares/node/video/screen.cpp index 6446bbc2ed..19fe96a044 100644 --- a/waterbox/ares64/ares/ares/ares/node/video/screen.cpp +++ b/waterbox/ares64/ares/ares/ares/node/video/screen.cpp @@ -3,17 +3,10 @@ Screen::Screen(string name, u32 width, u32 height) : Video(name) { _canvasHeight = height; if(width && height) { -#ifdef WATERBOXED _inputA = alloc_invisible(width * height); _inputB = alloc_invisible(width * height); _output = alloc_invisible(width * height); _rotate = alloc_invisible(width * height); -#else - _inputA = new u32[width * height](); - _inputB = new u32[width * height](); - _output = new u32[width * height](); - _rotate = new u32[width * height](); -#endif if constexpr(ares::Video::Threaded) { _thread = nall::thread::create({&Screen::main, this}); diff --git a/waterbox/ares64/ares/ares/n64/accuracy.hpp b/waterbox/ares64/ares/ares/n64/accuracy.hpp index 77d01fcb58..85eda162f7 100644 --- a/waterbox/ares64/ares/ares/n64/accuracy.hpp +++ b/waterbox/ares64/ares/ares/n64/accuracy.hpp @@ -1,10 +1,6 @@ struct Accuracy { //enable all accuracy flags -#ifdef WATERBOXED static constexpr bool Reference = 1; -#else - static constexpr bool Reference = 0; -#endif struct CPU { static constexpr bool Interpreter = 0 | Reference; diff --git a/waterbox/ares64/ares/ares/n64/n64.hpp b/waterbox/ares64/ares/ares/n64/n64.hpp index c02de37595..98c3c0ac35 100644 --- a/waterbox/ares64/ares/ares/n64/n64.hpp +++ b/waterbox/ares64/ares/ares/n64/n64.hpp @@ -15,10 +15,6 @@ using v128 = __m128i; #include #endif -#if defined(MAME_RDP) -class n64_state; -#endif - namespace ares::Nintendo64 { auto enumerate() -> vector; auto load(Node::System& node, string name) -> bool; diff --git a/waterbox/ares64/ares/ares/n64/rdp/rdp.cpp b/waterbox/ares64/ares/ares/n64/rdp/rdp.cpp index e9dd892507..b5bed6aa45 100644 --- a/waterbox/ares64/ares/ares/n64/rdp/rdp.cpp +++ b/waterbox/ares64/ares/ares/n64/rdp/rdp.cpp @@ -1,19 +1,7 @@ #include -#if defined(MAME_RDP) -#include "emu.h" -#include "includes/n64.h" - -struct n64_periphs_impl : public n64_periphs { - auto dp_full_sync() -> void override { - ares::Nintendo64::rdp.syncFull(); - } - - static auto instance() -> n64_periphs_impl* { - static n64_periphs_impl* inst = new n64_periphs_impl(); - return inst; - } -}; +#if defined(ANGRYLION_RDP) +#include "Gfx #1.3.h" #endif namespace ares::Nintendo64 { @@ -28,10 +16,9 @@ auto RDP::load(Node::Object parent) -> void { node = parent->append("RDP"); debugger.load(node); - #if defined(MAME_RDP) - state = new n64_state((u32*)rdram.ram.data, (u32*)rsp.dmem.data, n64_periphs_impl::instance()); + #if defined(ANGRYLION_RDP) puts("starting RDP video"); - state->video_start(); + angrylion::RomOpen(); #endif } @@ -39,8 +26,8 @@ auto RDP::unload() -> void { debugger = {}; node.reset(); - #if defined(MAME_RDP) - state.reset(); + #if defined(ANGRYLION_RDP) + angrylion::RomClosed(); #endif } diff --git a/waterbox/ares64/ares/ares/n64/rdp/rdp.hpp b/waterbox/ares64/ares/ares/n64/rdp/rdp.hpp index bebf4216ff..cba1869201 100644 --- a/waterbox/ares64/ares/ares/n64/rdp/rdp.hpp +++ b/waterbox/ares64/ares/ares/n64/rdp/rdp.hpp @@ -347,10 +347,6 @@ struct RDP : Thread, Memory::IO { n32 data; } test; } io{*this}; - - #if defined(MAME_RDP) - unique_pointer state; - #endif }; extern RDP rdp; diff --git a/waterbox/ares64/ares/ares/n64/rdp/render.cpp b/waterbox/ares64/ares/ares/n64/rdp/render.cpp index 94a961b7f7..ca4d92f469 100644 --- a/waterbox/ares64/ares/ares/n64/rdp/render.cpp +++ b/waterbox/ares64/ares/ares/n64/rdp/render.cpp @@ -49,15 +49,13 @@ auto RDP::render() -> void { if(vulkan.enable && vulkan.render()) return; #endif - #if defined(MAME_RDP) - auto rdp = state->rdp(); - rdp->set_current(command.current); - rdp->set_end(command.end); - rdp->set_status(command.source ? DP_STATUS_XBUS_DMA : 0); - rdp->process_command_list(); - command.current = rdp->get_current(); + #if defined(ANGRYLION_RDP) + if (angrylion::ProcessRDPList()) { + command.start = command.current = command.end; + } return; - #else + #endif + auto& memory = !command.source ? rdram.ram : rsp.dmem; auto fetch = [&]() -> u64 { @@ -553,7 +551,6 @@ auto RDP::render() -> void { } } -#endif } //0x00 diff --git a/waterbox/ares64/ares/ares/n64/vi/vi.cpp b/waterbox/ares64/ares/ares/n64/vi/vi.cpp index 32471b2363..d110974a81 100644 --- a/waterbox/ares64/ares/ares/n64/vi/vi.cpp +++ b/waterbox/ares64/ares/ares/n64/vi/vi.cpp @@ -1,5 +1,9 @@ #include +#if defined(ANGRYLION_RDP) +#include "Gfx #1.3.h" +#endif + namespace ares::Nintendo64 { VI vi; @@ -78,6 +82,16 @@ auto VI::main() -> void { } #endif + #if defined(ANGRYLION_RDP) + #if defined(VULKAN) + if (!vulkan.enable) { + #endif + angrylion::UpdateScreen(); + #if defined(VULKAN) + } + #endif + #endif + refreshed = true; screen->frame(); } @@ -91,6 +105,8 @@ auto VI::step(u32 clocks) -> void { Thread::clock += clocks; } +bool BobDeinterlace = 0; + auto VI::refresh() -> void { #if defined(VULKAN) if(vulkan.enable && gpuOutputValid) { @@ -116,6 +132,22 @@ auto VI::refresh() -> void { } #endif + #if defined(ANGRYLION_RDP) + #if defined(VULKAN) + if(!vulkan.enable) { + #else + { + #endif + u32 width = 640; + u32 height = Region::PAL() ? 576 : 480; + screen->setViewport(0, 0, width, height); + u32* src = angrylion::FinalizeFrame(BobDeinterlace); + u32* dst = screen->pixels(1).data(); + memcpy(dst, src, width * height * sizeof(u32)); + return; + } + #endif + u32 pitch = vi.io.width; u32 width = vi.io.width; //vi.io.xscale <= 0x300 ? 320 : 640; u32 height = vi.io.yscale <= 0x400 ? 239 : 478; diff --git a/waterbox/ares64/ares/thirdparty/angrylion-rdp b/waterbox/ares64/ares/thirdparty/angrylion-rdp new file mode 160000 index 0000000000..53dfbd3e6c --- /dev/null +++ b/waterbox/ares64/ares/thirdparty/angrylion-rdp @@ -0,0 +1 @@ +Subproject commit 53dfbd3e6c385bf1898de53d7ff176de6c4cffa1 diff --git a/waterbox/ares64/ares/thirdparty/mame/devices/video/poly.h b/waterbox/ares64/ares/thirdparty/mame/devices/video/poly.h deleted file mode 100644 index 92cdefee2f..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/devices/video/poly.h +++ /dev/null @@ -1,1472 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ville Linde, Aaron Giles -/*************************************************************************** - - poly.h - - Polygon helper routines. - -**************************************************************************** - - Pixel model: - - (0.0,0.0) (1.0,0.0) (2.0,0.0) (3.0,0.0) - +---------------+---------------+---------------+ - | | | | - | | | | - | (0.5,0.5) | (1.5,0.5) | (2.5,0.5) | - | * | * | * | - | | | | - | | | | - (0.0,1.0) (1.0,1.0) (2.0,1.0) (3.0,1.0) - +---------------+---------------+---------------+ - | | | | - | | | | - | (0.5,1.5) | (1.5,1.5) | (2.5,1.5) | - | * | * | * | - | | | | - | | | | - | | | | - +---------------+---------------+---------------+ - (0.0,2.0) (1.0,2.0) (2.0,2.0) (3.0,2.0) - -***************************************************************************/ - -#ifndef MAME_VIDEO_POLY_H -#define MAME_VIDEO_POLY_H - -#pragma once - -#include -#include - - -#define KEEP_POLY_STATISTICS 0 -#define TRACK_POLY_WAITS 0 - - - -//************************************************************************** -// CONSTANTS -//************************************************************************** - -static constexpr u8 POLY_FLAG_NO_WORK_QUEUE = 0x01; -static constexpr u8 POLY_FLAG_NO_CLIPPING = 0x02; - - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// base class for poly_array -class poly_array_base -{ -public: - // construction - poly_array_base() { } - - // destruction - virtual ~poly_array_base() { } - - // reset - virtual void reset() = 0; -}; - - -// class for managing an array of items -template -class poly_array : public poly_array_base -{ -public: - // this is really architecture-specific, but 64 is a reasonable - // value for most modern x64/ARM architectures - static constexpr size_t CACHE_LINE_SHIFT = 6; - static constexpr size_t CACHE_LINE_SIZE = 1 << CACHE_LINE_SHIFT; - static constexpr uintptr_t CACHE_LINE_MASK = ~uintptr_t(0) << CACHE_LINE_SHIFT; - - // size of an item, rounded up to the cache line size - static constexpr size_t ITEM_SIZE = ((sizeof(ArrayType) + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE) * CACHE_LINE_SIZE; - - // items are allocated in a 64k chunks - static constexpr size_t CHUNK_GRANULARITY = 65536; - - // number of items in a chunk - static constexpr u32 ITEMS_PER_CHUNK = CHUNK_GRANULARITY / ITEM_SIZE; - - // construction - poly_array() : - m_base(nullptr), - m_next(0), - m_max(0), - m_allocated(0) - { - for (int index = 0; index < TrackingCount; index++) - m_last[index] = nullptr; - - // allocate one chunk to start with - realloc(ITEMS_PER_CHUNK); - } - - // destruction - virtual ~poly_array() { m_base = nullptr; } - - // getters - u32 count() const { return m_next; } - u32 max() const { return m_max; } - size_t itemsize() const { return ITEM_SIZE; } - u32 allocated() const { return m_allocated; } - - // return an item by index - ArrayType &byindex(u32 index) - { - assert(index < m_next); - if (index < m_allocated) - return *item_ptr(index); - assert(m_chain); - return m_chain->byindex(index - m_allocated); - } - - // return a contiguous chunk of items - ArrayType *contiguous(u32 index, u32 count, u32 &chunk) - { - assert(index < m_next); - assert(index + count <= m_next); - if (index < m_allocated) - { - chunk = std::min(count, m_allocated - index); - return item_ptr(index); - } - assert(m_chain); - return m_chain->contiguous(index - m_allocated, count, chunk); - } - - // compute the index - int indexof(ArrayType &item) const - { - u32 result = (reinterpret_cast(&item) - m_base) / ITEM_SIZE; - if (result < m_allocated) - return result; - assert(m_chain); - return m_allocated + m_chain->indexof(item); - } - - // operations - virtual void reset() override - { - m_next = 0; - - // if we didn't have a chain, just repopulate - if (!m_chain) - repopulate(); - else - { - // otherwise, reallocate and get rid of the chain - realloc(m_max); - m_chain.reset(); - } - } - - // allocate a return a new item - ArrayType &next(int tracking_index = 0) - { - // track the maximum - if (m_next > m_max) - m_max = m_next; - - // fast case: fits within our array - ArrayType *item; - if (m_next < m_allocated) - item = new(item_ptr(m_next)) ArrayType; - - // otherwise, allocate from the chain - else - { - if (!m_chain) - m_chain = std::make_unique>(); - item = &m_chain->next(); - } - - // set the last item - m_next++; - if (TrackingCount > 0) - { - assert(tracking_index < TrackingCount); - m_last[tracking_index] = item; - } - return *item; - } - - // return the last - ArrayType &last(int tracking_index = 0) const - { - assert(tracking_index < TrackingCount); - assert(m_last[tracking_index] != nullptr); - return *m_last[tracking_index]; - } - -private: - // internal helper to make size pointers - ArrayType *item_ptr(u32 index) - { - assert(index < m_allocated); - return reinterpret_cast(m_base + index * ITEM_SIZE); - } - - // reallocate to the given size - void realloc(u32 count) - { - // round the count up to a chunk size - count = ((count + ITEMS_PER_CHUNK - 1) / ITEMS_PER_CHUNK) * ITEMS_PER_CHUNK; - - // allocate a fresh new array - std::unique_ptr new_alloc = std::make_unique(ITEM_SIZE * count + CACHE_LINE_SIZE); - std::fill_n(&new_alloc[0], ITEM_SIZE * count + CACHE_LINE_SIZE, 0); - - // align the base to a cache line - m_base = reinterpret_cast((uintptr_t(new_alloc.get()) + CACHE_LINE_SIZE - 1) & CACHE_LINE_MASK); - - // repopulate last items into the base of the new array - repopulate(); - - // replace the old allocation with the new one - m_alloc = std::move(new_alloc); - m_allocated = count; - } - - // repopulate items - void repopulate() - { - for (int tracking_index = 0; tracking_index < TrackingCount; tracking_index++) - if (m_last[tracking_index] != nullptr) - { - if (m_last[tracking_index] == item_ptr(m_next)) - m_next++; - else - next(tracking_index) = *m_last[tracking_index]; - } - } - - // internal state - u8 *m_base; - u32 m_next; - u32 m_max; - u32 m_allocated; - std::unique_ptr m_alloc; - std::unique_ptr> m_chain; - std::array m_last; -}; - - -// poly_manager is a template class -template -class poly_manager -{ -public: - // each vertex has an X/Y coordinate and a set of parameters - struct vertex_t - { - vertex_t() { } - vertex_t(BaseType _x, BaseType _y) { x = _x; y = _y; } - - BaseType x, y; // X, Y coordinates - std::array p; // iterated parameters - }; - - // a single extent describes a span and a list of parameter extents - struct extent_t - { - struct param_t - { - BaseType start; // parameter value at start - BaseType dpdx; // dp/dx relative to start - }; - int16_t startx, stopx; // starting (inclusive)/ending (exclusive) endpoints - std::array param; // array of parameter start/delays - void *userdata; // custom per-span data - }; - - // delegate type for scanline callbacks - using render_delegate = delegate; - - // poly_array of object data - using objectdata_array = poly_array; - - // construction/destruction - poly_manager(running_machine &machine); - virtual ~poly_manager(); - - // synchronization - void wait(char const *debug_reason = "general"); - - // return a reference to our ObjectType poly_array - objectdata_array &object_data() { return m_object; } - - // register a poly_array to be reset after a wait - void register_poly_array(poly_array_base &array) { m_arrays.push_back(&array); } - - // tiles - template - uint32_t render_tile(rectangle const &cliprect, render_delegate callback, vertex_t const &v1, vertex_t const &v2); - - // triangles - template - uint32_t render_triangle(rectangle const &cliprect, render_delegate callback, vertex_t const &v1, vertex_t const &v2, vertex_t const &v3); - template - uint32_t render_triangle_fan(rectangle const &cliprect, render_delegate callback, int numverts, vertex_t const *v); - template - uint32_t render_triangle_strip(rectangle const &cliprect, render_delegate callback, int numverts, vertex_t const *v); - - // polygons - template - uint32_t render_polygon(rectangle const &cliprect, render_delegate callback, vertex_t const *v); - - // direct custom extents - template - uint32_t render_extents(rectangle const &cliprect, render_delegate callback, int startscanline, int numscanlines, extent_t const *extents); - - // public helpers - template - int zclip_if_less(int numverts, vertex_t const *v, vertex_t *outv, BaseType clipval); - -private: - // number of profiling ticks before we consider a wait "long" - static constexpr osd_ticks_t POLY_LOG_WAIT_THRESHOLD = 1000; - - static constexpr int SCANLINES_PER_BUCKET = 32; - static constexpr int TOTAL_BUCKETS = (512 / SCANLINES_PER_BUCKET); - - // primitive_info describes a single primitive - struct primitive_info - { - poly_manager * m_owner; // pointer back to the poly manager - ObjectType * m_object; // object data pointer - render_delegate m_callback; // callback to handle a scanline's worth of work - }; - - // internal unit of work - struct work_unit - { - work_unit &operator=(work_unit const &rhs) - { - // this is just to satisfy the compiler; we don't actually copy - fatalerror("Attempt to copy work_unit"); - } - - std::atomic count_next; // number of scanlines and index of next item to process - primitive_info * primitive; // pointer to primitive - int32_t scanline; // starting scanline - uint32_t previtem; // index of previous item in the same bucket - extent_t extent[SCANLINES_PER_BUCKET]; // array of scanline extents - }; - - // internal array types - using primitive_array = poly_array; - using unit_array = poly_array; - - // round in a cross-platform consistent manner - inline int32_t round_coordinate(BaseType value) - { - int32_t result = int32_t(std::floor(value)); - if (value > 0 && result < 0) - return INT_MAX - 1; - return result + (value - BaseType(result) > BaseType(0.5)); - } - - // internal helpers - primitive_info &primitive_alloc(int minx, int maxx, int miny, int maxy, render_delegate callback) - { - // return and initialize the next one - primitive_info &primitive = m_primitive.next(); - primitive.m_owner = this; - primitive.m_object = &m_object.last(); - primitive.m_callback = callback; - return primitive; - } - - // enqueue work items in contiguous chunks - void queue_items(u32 start) - { - // do nothing if no queue; items will be processed on the next wait - if (m_queue == nullptr) - return; - - // enqueue the items in contiguous chunks - while (start < m_unit.count()) - { - u32 chunk; - work_unit *base = m_unit.contiguous(start, m_unit.count() - start, chunk); - osd_work_item_queue_multiple(m_queue, work_item_callback, chunk, base, m_unit.itemsize(), WORK_ITEM_FLAG_AUTO_RELEASE); - start += chunk; - } - } - - static void *work_item_callback(void *param, int threadid); - void presave() { wait("pre-save"); } - - // queue management - osd_work_queue *m_queue; // work queue - - // arrays - primitive_array m_primitive; // array of primitives - objectdata_array m_object; // array of object data - unit_array m_unit; // array of work units - std::vector m_arrays; // list of arrays we are managing - - // buckets - uint32_t m_unit_bucket[TOTAL_BUCKETS]; // buckets for tracking unit usage - - // statistics - uint32_t m_tiles; // number of tiles queued - uint32_t m_triangles; // number of triangles queued - uint32_t m_polygons; // number of polygons queued - uint64_t m_pixels; // number of pixels rendered -#if KEEP_POLY_STATISTICS - uint32_t m_conflicts[WORK_MAX_THREADS] = { 0 }; // number of conflicts found, per thread - uint32_t m_resolved[WORK_MAX_THREADS] = { 0 }; // number of conflicts resolved, per thread -#endif -#if TRACK_POLY_WAITS - static std::string friendly_number(u64 number); - struct wait_tracker - { - void update(int items, osd_ticks_t time) - { - total_waits++; - if (items > 0) - { - total_actual_waits++; - total_cycles += time; - if (time < 100) - bucket_waits[0]++; - else if (time < 1000) - bucket_waits[1]++; - else if (time < 10000) - bucket_waits[2]++; - else - bucket_waits[3]++; - } - } - - u32 total_waits = 0; - u32 total_actual_waits = 0; - u32 bucket_waits[4] = { 0 }; - u64 total_cycles = 0; - }; - using waitmap_t = std::unordered_map; - waitmap_t m_waitmap; -#endif -}; - - -//------------------------------------------------- -// poly_manager - constructor -//------------------------------------------------- - -template -poly_manager::poly_manager(running_machine &machine) : - m_queue(nullptr), - m_tiles(0), - m_triangles(0), - m_polygons(0), - m_pixels(0) -{ - // create the work queue - if (!(Flags & POLY_FLAG_NO_WORK_QUEUE)) - m_queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ); - - // initialize the buckets to empty - std::fill_n(&m_unit_bucket[0], std::size(m_unit_bucket), 0xffffffff); - - // register our arrays for reset - register_poly_array(m_primitive); - register_poly_array(m_object); - register_poly_array(m_unit); - -#if !defined(MAME_RDP) - // request a pre-save callback for synchronization - machine.save().register_presave(save_prepost_delegate(FUNC(poly_manager::presave), this)); -#endif -} - - -//------------------------------------------------- -// ~poly_manager - destructor -//------------------------------------------------- - -#if TRACK_POLY_WAITS -template -inline std::string poly_manager::friendly_number(u64 number) -{ - static char const s_suffixes[] = " kmbtqisp"; - double value = double(number); - int suffixnum = 0; - - if (number < 1000000) - return string_format("%6d ", int(number)); - while (value >= 1000) - { - value /= 1000.0; - suffixnum++; - } - if (value >= 100) - return string_format("%6.1f%c", value, s_suffixes[suffixnum]); - if (value >= 10) - return string_format("%6.2f%c", value, s_suffixes[suffixnum]); - return string_format("%6.3f%c", value, s_suffixes[suffixnum]); -} -#endif - -template -poly_manager::~poly_manager() -{ -#if KEEP_POLY_STATISTICS -{ - // accumulate stats over the entire collection - int conflicts = 0, resolved = 0; - for (int i = 0; i < std::size(m_conflicts); i++) - { - conflicts += m_conflicts[i]; - resolved += m_resolved[i]; - } - - // output global stats - osd_printf_info("Total triangles = %d\n", m_triangles); - osd_printf_info("Total polygons = %d\n", m_polygons); - if (m_pixels > 1000000000) - osd_printf_info("Total pixels = %d%09d\n", uint32_t(m_pixels / 1000000000), uint32_t(m_pixels % 1000000000)); - else - osd_printf_info("Total pixels = %d\n", uint32_t(m_pixels)); - - osd_printf_info("Conflicts: %d resolved, %d total\n", resolved, conflicts); - osd_printf_info("Units: %5d used, %5d allocated, %4d bytes each, %7d total\n", m_unit.max(), m_unit.allocated(), int(m_unit.itemsize()), int(m_unit.allocated() * m_unit.itemsize())); - osd_printf_info("Primitives: %5d used, %5d allocated, %4d bytes each, %7d total\n", m_primitive.max(), m_primitive.allocated(), int(m_primitive.itemsize()), int(m_primitive.allocated() * m_primitive.itemsize())); - osd_printf_info("Object data: %5d used, %5d allocated, %4d bytes each, %7d total\n", m_object.max(), m_object.allocated(), int(m_object.itemsize()), int(m_object.allocated() * m_object.itemsize())); -} -#endif -#if TRACK_POLY_WAITS -{ - osd_printf_info("Wait summary:\n"); - osd_printf_info("Cause Cycles Waits Actuals Average <100 100-1k 1k-10k 10k+\n"); - osd_printf_info("-------------------------- ------- ------- ------- ------- ------- ------- ------- -------\n"); - while (1) - { - typename waitmap_t::value_type *biggest = nullptr; - for (auto &item : m_waitmap) - if (item.second.total_cycles > 0) - if (biggest == nullptr || item.second.total_cycles > biggest->second.total_cycles) - biggest = &item; - - if (biggest == nullptr) - break; - - osd_printf_info("%-28s%-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s\n", - biggest->first.c_str(), - friendly_number(biggest->second.total_cycles).c_str(), - friendly_number(biggest->second.total_waits).c_str(), - friendly_number(biggest->second.total_actual_waits).c_str(), - (biggest->second.total_actual_waits == 0) ? "n/a" : friendly_number(biggest->second.total_cycles / biggest->second.total_actual_waits).c_str(), - friendly_number(biggest->second.bucket_waits[0]).c_str(), - friendly_number(biggest->second.bucket_waits[1]).c_str(), - friendly_number(biggest->second.bucket_waits[2]).c_str(), - friendly_number(biggest->second.bucket_waits[3]).c_str()); - - biggest->second.total_cycles = 0; - } -} -#endif - - // free the work queue - if (m_queue != nullptr) - osd_work_queue_free(m_queue); -} - - -//------------------------------------------------- -// work_item_callback - process a work item -//------------------------------------------------- - -template -void *poly_manager::work_item_callback(void *param, int threadid) -{ - while (1) - { - work_unit &unit = *(work_unit *)param; - primitive_info &primitive = *unit.primitive; - int count = unit.count_next & 0xff; - uint32_t orig_count_next; - - // if our previous item isn't done yet, enqueue this item to the end and proceed - if (unit.previtem != 0xffffffff) - { - work_unit &prevunit = primitive.m_owner->m_unit.byindex(unit.previtem); - if (prevunit.count_next != 0) - { - uint32_t unitnum = primitive.m_owner->m_unit.indexof(unit); - uint32_t new_count_next; - - // attempt to atomically swap in this new value - do - { - orig_count_next = prevunit.count_next; - new_count_next = orig_count_next | (unitnum << 8); - } while (!prevunit.count_next.compare_exchange_weak(orig_count_next, new_count_next, std::memory_order_release, std::memory_order_relaxed)); - -#if KEEP_POLY_STATISTICS - // track resolved conflicts - primitive.m_owner->m_conflicts[threadid]++; - if (orig_count_next != 0) - primitive.m_owner->m_resolved[threadid]++; -#endif - // if we succeeded, skip out early so we can do other work - if (orig_count_next != 0) - break; - } - } - - // iterate over extents - for (int curscan = 0; curscan < count; curscan++) - primitive.m_callback(unit.scanline + curscan, unit.extent[curscan], *primitive.m_object, threadid); - - // set our count to 0 and re-fetch the original count value - do - { - orig_count_next = unit.count_next; - } while (!unit.count_next.compare_exchange_weak(orig_count_next, 0, std::memory_order_release, std::memory_order_relaxed)); - - // if we have no more work to do, do nothing - orig_count_next >>= 8; - if (orig_count_next == 0) - break; - param = &primitive.m_owner->m_unit.byindex(orig_count_next); - } - return nullptr; -} - - -//------------------------------------------------- -// wait - stall until all work is complete -//------------------------------------------------- - -template -void poly_manager::wait(char const *debug_reason) -{ - // early out if no units outstanding - if (m_unit.count() == 0) - return; - -#if TRACK_POLY_WAITS - int items = osd_work_queue_items(m_queue); - osd_ticks_t time = get_profile_ticks(); -#endif - - // wait for all pending work items to complete - if (m_queue != nullptr) - osd_work_queue_wait(m_queue, osd_ticks_per_second() * 100); - - // if we don't have a queue, just run the whole list now - else - for (int unitnum = 0; unitnum < m_unit.count(); unitnum++) - work_item_callback(&m_unit.byindex(unitnum), 0); - -#if TRACK_POLY_WAITS - m_waitmap[debug_reason].update(items, get_profile_ticks() - time); -#endif - - // clear the buckets - std::fill_n(&m_unit_bucket[0], std::size(m_unit_bucket), 0xffffffff); - - // reset all the poly arrays - for (auto array : m_arrays) - array->reset(); -} - - -//------------------------------------------------- -// render_tile - render a tile -//------------------------------------------------- - -template -template -uint32_t poly_manager::render_tile(rectangle const &cliprect, render_delegate callback, vertex_t const &_v1, vertex_t const &_v2) -{ - vertex_t const *v1 = &_v1; - vertex_t const *v2 = &_v2; - - // first sort by Y - if (v2->y < v1->y) - std::swap(v1, v2); - - // compute some integral X/Y vertex values - int32_t v1y = round_coordinate(v1->y); - int32_t v2y = round_coordinate(v2->y); - - // clip coordinates - int32_t v1yclip = v1y; - int32_t v2yclip = v2y; - if (!(Flags & POLY_FLAG_NO_CLIPPING)) - { - v1yclip = std::max(v1yclip, cliprect.top()); - v2yclip = std::min(v2yclip, cliprect.bottom() + 1); - if (v2yclip - v1yclip <= 0) - return 0; - } - - // determine total X extents - BaseType minx = v1->x; - BaseType maxx = v2->x; - if (minx > maxx) - return 0; - - // allocate and populate a new primitive - primitive_info &primitive = primitive_alloc(round_coordinate(minx), round_coordinate(maxx), v1yclip, v2yclip, callback); - - // compute parameter deltas - std::array param_dpdx; - std::array param_dpdy; - if (ParamCount > 0) - { - BaseType oox = BaseType(1.0) / (v2->x - v1->x); - BaseType ooy = BaseType(1.0) / (v2->y - v1->y); - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - { - param_dpdx[paramnum] = oox * (v2->p[paramnum] - v1->p[paramnum]); - param_dpdy[paramnum] = ooy * (v2->p[paramnum] - v1->p[paramnum]); - } - } - - // clamp to full pixels - int32_t istartx = round_coordinate(v1->x); - int32_t istopx = round_coordinate(v2->x); - - // force start < stop - if (istartx > istopx) - std::swap(istartx, istopx); - - // apply left/right clipping - if (!(Flags & POLY_FLAG_NO_CLIPPING)) - { - istartx = std::max(istartx, cliprect.left()); - istopx = std::min(istopx, cliprect.right() + 1); - if (istartx >= istopx) - return 0; - } - - // compute the X extents for each scanline - int32_t pixels = 0; - uint32_t startunit = m_unit.count(); - int32_t scaninc = 1; - for (int32_t curscan = v1yclip; curscan < v2yclip; curscan += scaninc) - { - uint32_t bucketnum = (uint32_t(curscan) / SCANLINES_PER_BUCKET) % TOTAL_BUCKETS; - uint32_t unit_index = m_unit.count(); - work_unit &unit = m_unit.next(); - - // determine how much to advance to hit the next bucket - scaninc = SCANLINES_PER_BUCKET - uint32_t(curscan) % SCANLINES_PER_BUCKET; - - // fill in the work unit basics - unit.primitive = &primitive; - unit.count_next = std::min(v2yclip - curscan, scaninc); - unit.scanline = curscan; - unit.previtem = m_unit_bucket[bucketnum]; - m_unit_bucket[bucketnum] = unit_index; - - // iterate over extents - for (int extnum = 0; extnum < unit.count_next; extnum++) - { - // set the extent and update the total pixel count - extent_t &extent = unit.extent[extnum]; - extent.startx = istartx; - extent.stopx = istopx; - pixels += istopx - istartx; - - // fill in the parameters for the extent - if (ParamCount > 0) - { - BaseType fullstartx = BaseType(istartx) + BaseType(0.5); - BaseType fully = BaseType(curscan + extnum) + BaseType(0.5); - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - { - extent.param[paramnum].start = v1->p[paramnum] + fullstartx * param_dpdx[paramnum] + fully * param_dpdy[paramnum]; - extent.param[paramnum].dpdx = param_dpdx[paramnum]; - } - } - } - } - - // enqueue the work items - queue_items(startunit); - - // return the total number of pixels in the triangle - m_tiles++; - m_pixels += pixels; - return pixels; -} - - -//------------------------------------------------- -// render_triangle - render a single triangle -// given 3 vertexes -//------------------------------------------------- - -template -template -uint32_t poly_manager::render_triangle(const rectangle &cliprect, render_delegate callback, const vertex_t &_v1, const vertex_t &_v2, const vertex_t &_v3) -{ - vertex_t const *v1 = &_v1; - vertex_t const *v2 = &_v2; - vertex_t const *v3 = &_v3; - - // first sort by Y - if (v2->y < v1->y) - std::swap(v1, v2); - if (v3->y < v2->y) - { - std::swap(v2, v3); - if (v2->y < v1->y) - std::swap(v1, v2); - } - - // compute some integral X/Y vertex values - int32_t v1y = round_coordinate(v1->y); - int32_t v3y = round_coordinate(v3->y); - - // clip coordinates - int32_t v1yclip = v1y; - int32_t v3yclip = v3y; - if (!(Flags & POLY_FLAG_NO_CLIPPING)) - { - v1yclip = std::max(v1yclip, cliprect.top()); - v3yclip = std::min(v3yclip, cliprect.bottom() + 1); - if (v3yclip - v1yclip <= 0) - return 0; - } - - // determine total X extents - BaseType minx = std::min(std::min(v1->x, v2->x), v3->x); - BaseType maxx = std::max(std::max(v1->x, v2->x), v3->x); - - // allocate and populate a new primitive - primitive_info &primitive = primitive_alloc(round_coordinate(minx), round_coordinate(maxx), v1yclip, v3yclip, callback); - - // compute the slopes for each portion of the triangle - BaseType dxdy_v1v2 = (v2->y == v1->y) ? BaseType(0.0) : (v2->x - v1->x) / (v2->y - v1->y); - BaseType dxdy_v1v3 = (v3->y == v1->y) ? BaseType(0.0) : (v3->x - v1->x) / (v3->y - v1->y); - BaseType dxdy_v2v3 = (v3->y == v2->y) ? BaseType(0.0) : (v3->x - v2->x) / (v3->y - v2->y); - - // compute parameter starting points and deltas - std::array param_start; - std::array param_dpdx; - std::array param_dpdy; - if (ParamCount > 0) - { - BaseType a00 = v2->y - v3->y; - BaseType a01 = v3->x - v2->x; - BaseType a02 = v2->x*v3->y - v3->x*v2->y; - BaseType a10 = v3->y - v1->y; - BaseType a11 = v1->x - v3->x; - BaseType a12 = v3->x*v1->y - v1->x*v3->y; - BaseType a20 = v1->y - v2->y; - BaseType a21 = v2->x - v1->x; - BaseType a22 = v1->x*v2->y - v2->x*v1->y; - BaseType det = a02 + a12 + a22; - - if (std::abs(det) < BaseType(0.00001)) - { - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - { - param_dpdx[paramnum] = BaseType(0.0); - param_dpdy[paramnum] = BaseType(0.0); - param_start[paramnum] = v1->p[paramnum]; - } - } - else - { - BaseType idet = BaseType(1.0) / det; - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - { - param_dpdx[paramnum] = idet * (v1->p[paramnum]*a00 + v2->p[paramnum]*a10 + v3->p[paramnum]*a20); - param_dpdy[paramnum] = idet * (v1->p[paramnum]*a01 + v2->p[paramnum]*a11 + v3->p[paramnum]*a21); - param_start[paramnum] = idet * (v1->p[paramnum]*a02 + v2->p[paramnum]*a12 + v3->p[paramnum]*a22); - } - } - } - - // compute the X extents for each scanline - int32_t pixels = 0; - uint32_t startunit = m_unit.count(); - int32_t scaninc = 1; - for (int32_t curscan = v1yclip; curscan < v3yclip; curscan += scaninc) - { - uint32_t bucketnum = (uint32_t(curscan) / SCANLINES_PER_BUCKET) % TOTAL_BUCKETS; - uint32_t unit_index = m_unit.count(); - work_unit &unit = m_unit.next(); - - // determine how much to advance to hit the next bucket - scaninc = SCANLINES_PER_BUCKET - uint32_t(curscan) % SCANLINES_PER_BUCKET; - - // fill in the work unit basics - unit.primitive = &primitive; - unit.count_next = std::min(v3yclip - curscan, scaninc); - unit.scanline = curscan; - unit.previtem = m_unit_bucket[bucketnum]; - m_unit_bucket[bucketnum] = unit_index; - - // iterate over extents - for (int extnum = 0; extnum < unit.count_next; extnum++) - { - // compute the ending X based on which part of the triangle we're in - BaseType fully = BaseType(curscan + extnum) + BaseType(0.5); - BaseType startx = v1->x + (fully - v1->y) * dxdy_v1v3; - BaseType stopx; - if (fully < v2->y) - stopx = v1->x + (fully - v1->y) * dxdy_v1v2; - else - stopx = v2->x + (fully - v2->y) * dxdy_v2v3; - - // clamp to full pixels - int32_t istartx = round_coordinate(startx); - int32_t istopx = round_coordinate(stopx); - - // force start < stop - if (istartx > istopx) - std::swap(istartx, istopx); - - // apply left/right clipping - if (!(Flags & POLY_FLAG_NO_CLIPPING)) - { - istartx = std::max(istartx, cliprect.left()); - istopx = std::min(istopx, cliprect.right() + 1); - } - - // set the extent and update the total pixel count - if (istartx >= istopx) - istartx = istopx = 0; - extent_t &extent = unit.extent[extnum]; - extent.startx = istartx; - extent.stopx = istopx; - pixels += istopx - istartx; - - // fill in the parameters for the extent - BaseType fullstartx = BaseType(istartx) + BaseType(0.5); - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - { - extent.param[paramnum].start = param_start[paramnum] + fullstartx * param_dpdx[paramnum] + fully * param_dpdy[paramnum]; - extent.param[paramnum].dpdx = param_dpdx[paramnum]; - } - } - } - - // enqueue the work items - queue_items(startunit); - - // return the total number of pixels in the triangle - m_triangles++; - m_pixels += pixels; - return pixels; -} - - -//------------------------------------------------- -// render_triangle_fan - render a set of -// triangles in a fan -//------------------------------------------------- - -template -template -uint32_t poly_manager::render_triangle_fan(rectangle const &cliprect, render_delegate callback, int numverts, vertex_t const *v) -{ - // iterate over vertices - uint32_t pixels = 0; - for (int vertnum = 2; vertnum < numverts; vertnum++) - pixels += render_triangle(cliprect, callback, v[0], v[vertnum - 1], v[vertnum]); - return pixels; -} - - -//------------------------------------------------- -// render_triangle_strip - render a set of -// triangles in a strip -//------------------------------------------------- - -template -template -uint32_t poly_manager::render_triangle_strip(rectangle const &cliprect, render_delegate callback, int numverts, vertex_t const *v) -{ - // iterate over vertices - uint32_t pixels = 0; - for (int vertnum = 2; vertnum < numverts; vertnum++) - pixels += render_triangle(cliprect, callback, v[vertnum - 2], v[vertnum - 1], v[vertnum]); - return pixels; -} - - -//------------------------------------------------- -// render_extents - perform a custom render of -// an object, given specific extents -//------------------------------------------------- - -template -template -uint32_t poly_manager::render_extents(rectangle const &cliprect, render_delegate callback, int startscanline, int numscanlines, extent_t const *extents) -{ - // clip coordinates - int32_t v1yclip = startscanline; - int32_t v3yclip = startscanline + numscanlines; - if (!(Flags & POLY_FLAG_NO_CLIPPING)) - { - v1yclip = std::max(v1yclip, cliprect.top()); - v3yclip = std::min(v3yclip, cliprect.bottom() + 1); - if (v3yclip - v1yclip <= 0) - return 0; - } - - // allocate and populate a new primitive - primitive_info &primitive = primitive_alloc(0, 0, v1yclip, v3yclip, callback); - - // compute the X extents for each scanline - int32_t pixels = 0; - uint32_t startunit = m_unit.count(); - int32_t scaninc = 1; - for (int32_t curscan = v1yclip; curscan < v3yclip; curscan += scaninc) - { - uint32_t bucketnum = (uint32_t(curscan) / SCANLINES_PER_BUCKET) % TOTAL_BUCKETS; - uint32_t unit_index = m_unit.count(); - work_unit &unit = m_unit.next(); - - // determine how much to advance to hit the next bucket - scaninc = SCANLINES_PER_BUCKET - uint32_t(curscan) % SCANLINES_PER_BUCKET; - - // fill in the work unit basics - unit.primitive = &primitive; - unit.count_next = std::min(v3yclip - curscan, scaninc); - unit.scanline = curscan; - unit.previtem = m_unit_bucket[bucketnum]; - m_unit_bucket[bucketnum] = unit_index; - - // iterate over extents - for (int extnum = 0; extnum < unit.count_next; extnum++) - { - extent_t const &srcextent = extents[(curscan + extnum) - startscanline]; - int32_t istartx = srcextent.startx, istopx = srcextent.stopx; - - // apply left/right clipping - if (!(Flags & POLY_FLAG_NO_CLIPPING)) - { - istartx = std::max(istartx, cliprect.left()); - istartx = std::min(istartx, cliprect.right() + 1); - istopx = std::max(istopx, cliprect.left()); - istopx = std::min(istopx, cliprect.right() + 1); - } - - // set the extent and update the total pixel count - extent_t &extent = unit.extent[extnum]; - extent.startx = istartx; - extent.stopx = istopx; - - // fill in the parameters for the extent - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - { - extent.param[paramnum].start = srcextent.param[paramnum].start; - extent.param[paramnum].dpdx = srcextent.param[paramnum].dpdx; - } - extent.userdata = srcextent.userdata; - - if (istartx < istopx) - pixels += istopx - istartx; - else if (istopx < istartx) - pixels += istartx - istopx; - } - } - - // enqueue the work items - queue_items(startunit); - - // return the total number of pixels in the object - m_triangles++; - m_pixels += pixels; - return pixels; -} - - -//------------------------------------------------- -// render_polygon - render a single polygon up -// to 32 vertices -//------------------------------------------------- - -template -template -uint32_t poly_manager::render_polygon(rectangle const &cliprect, render_delegate callback, vertex_t const *v) -{ - // determine min/max Y vertices - BaseType minx = v[0].x; - BaseType maxx = v[0].x; - int minv = 0; - int maxv = 0; - for (int vertnum = 1; vertnum < NumVerts; vertnum++) - { - if (v[vertnum].y < v[minv].y) - minv = vertnum; - else if (v[vertnum].y > v[maxv].y) - maxv = vertnum; - minx = std::min(minx, v[vertnum].x); - maxx = std::max(maxx, v[vertnum].x); - } - - // determine start/end scanlines - int32_t miny = round_coordinate(v[minv].y); - int32_t maxy = round_coordinate(v[maxv].y); - - // clip coordinates - int32_t minyclip = miny; - int32_t maxyclip = maxy; - if (!(Flags & POLY_FLAG_NO_CLIPPING)) - { - minyclip = std::max(minyclip, cliprect.top()); - maxyclip = std::min(maxyclip, cliprect.bottom() + 1); - if (maxyclip - minyclip <= 0) - return 0; - } - - // allocate a new primitive - primitive_info &primitive = primitive_alloc(round_coordinate(minx), round_coordinate(maxx), minyclip, maxyclip, callback); - - // walk forward to build up the forward edge list - struct poly_edge - { - poly_edge *next; // next edge in sequence - int index; // index of this edge - vertex_t const *v1; // pointer to first vertex - vertex_t const *v2; // pointer to second vertex - BaseType dxdy; // dx/dy along the edge - std::array dpdy; // per-parameter dp/dy values - }; - poly_edge fedgelist[NumVerts - 1]; - poly_edge *edgeptr = &fedgelist[0]; - for (int curv = minv; curv != maxv; curv = (curv == NumVerts - 1) ? 0 : (curv + 1)) - { - // set the two vertices - edgeptr->v1 = &v[curv]; - edgeptr->v2 = &v[(curv == NumVerts - 1) ? 0 : (curv + 1)]; - - // if horizontal, skip altogether - if (edgeptr->v1->y == edgeptr->v2->y) - continue; - - // need dx/dy always, and parameter deltas as necessary - BaseType ooy = BaseType(1.0) / (edgeptr->v2->y - edgeptr->v1->y); - edgeptr->dxdy = (edgeptr->v2->x - edgeptr->v1->x) * ooy; - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - edgeptr->dpdy[paramnum] = (edgeptr->v2->p[paramnum] - edgeptr->v1->p[paramnum]) * ooy; - ++edgeptr; - } - - // walk backward to build up the backward edge list - poly_edge bedgelist[NumVerts - 1]; - edgeptr = &bedgelist[0]; - for (int curv = minv; curv != maxv; curv = (curv == 0) ? (NumVerts - 1) : (curv - 1)) - { - // set the two vertices - edgeptr->v1 = &v[curv]; - edgeptr->v2 = &v[(curv == 0) ? (NumVerts - 1) : (curv - 1)]; - - // if horizontal, skip altogether - if (edgeptr->v1->y == edgeptr->v2->y) - continue; - - // need dx/dy always, and parameter deltas as necessary - BaseType ooy = BaseType(1.0) / (edgeptr->v2->y - edgeptr->v1->y); - edgeptr->dxdy = (edgeptr->v2->x - edgeptr->v1->x) * ooy; - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - edgeptr->dpdy[paramnum] = (edgeptr->v2->p[paramnum] - edgeptr->v1->p[paramnum]) * ooy; - ++edgeptr; - } - - // determine which list is left/right: - // if the first vertex is shared, compare the slopes - // if the first vertex is not shared, compare the X coordinates - poly_edge const *ledge, *redge; - if ((fedgelist[0].v1 == bedgelist[0].v1 && fedgelist[0].dxdy < bedgelist[0].dxdy) || - (fedgelist[0].v1 != bedgelist[0].v1 && fedgelist[0].v1->x < bedgelist[0].v1->x)) - { - ledge = fedgelist; - redge = bedgelist; - } - else - { - ledge = bedgelist; - redge = fedgelist; - } - - // compute the X extents for each scanline - int32_t pixels = 0; - uint32_t startunit = m_unit.count(); - int32_t scaninc = 1; - for (int32_t curscan = minyclip; curscan < maxyclip; curscan += scaninc) - { - uint32_t bucketnum = (uint32_t(curscan) / SCANLINES_PER_BUCKET) % TOTAL_BUCKETS; - uint32_t unit_index = m_unit.count(); - work_unit &unit = m_unit.next(); - - // determine how much to advance to hit the next bucket - scaninc = SCANLINES_PER_BUCKET - uint32_t(curscan) % SCANLINES_PER_BUCKET; - - // fill in the work unit basics - unit.primitive = &primitive; - unit.count_next = std::min(maxyclip - curscan, scaninc); - unit.scanline = curscan; - unit.previtem = m_unit_bucket[bucketnum]; - m_unit_bucket[bucketnum] = unit_index; - - // iterate over extents - for (int extnum = 0; extnum < unit.count_next; extnum++) - { - // compute the ending X based on which part of the triangle we're in - BaseType fully = BaseType(curscan + extnum) + BaseType(0.5); - while (fully > ledge->v2->y && fully < v[maxv].y) - ++ledge; - while (fully > redge->v2->y && fully < v[maxv].y) - ++redge; - BaseType startx = ledge->v1->x + (fully - ledge->v1->y) * ledge->dxdy; - BaseType stopx = redge->v1->x + (fully - redge->v1->y) * redge->dxdy; - - // clamp to full pixels - int32_t istartx = round_coordinate(startx); - int32_t istopx = round_coordinate(stopx); - - // compute parameter starting points and deltas - extent_t &extent = unit.extent[extnum]; - if (ParamCount > 0) - { - BaseType ldy = fully - ledge->v1->y; - BaseType rdy = fully - redge->v1->y; - BaseType oox = BaseType(1.0) / (stopx - startx); - - // iterate over parameters - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - { - BaseType lparam = ledge->v1->p[paramnum] + ldy * ledge->dpdy[paramnum]; - BaseType rparam = redge->v1->p[paramnum] + rdy * redge->dpdy[paramnum]; - BaseType dpdx = (rparam - lparam) * oox; - - extent.param[paramnum].start = lparam;// - (BaseType(istartx) + 0.5f) * dpdx; - extent.param[paramnum].dpdx = dpdx; - } - } - - // apply left/right clipping - if (!(Flags & POLY_FLAG_NO_CLIPPING)) - { - if (istartx < cliprect.left()) - { - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - extent.param[paramnum].start += (cliprect.left() - istartx) * extent.param[paramnum].dpdx; - istartx = cliprect.left(); - } - if (istopx > cliprect.right()) - istopx = cliprect.right() + 1; - } - - // set the extent and update the total pixel count - if (istartx >= istopx) - istartx = istopx = 0; - extent.startx = istartx; - extent.stopx = istopx; - pixels += istopx - istartx; - } - } - - // enqueue the work items - queue_items(startunit); - - // return the total number of pixels in the polygon - m_polygons++; - m_pixels += pixels; - return pixels; -} - - -//------------------------------------------------- -// zclip_if_less - clip a polygon using p[0] as -// a z coordinate -//------------------------------------------------- - -template -template -int poly_manager::zclip_if_less(int numverts, vertex_t const *v, vertex_t *outv, BaseType clipval) -{ - bool prevclipped = (v[numverts - 1].p[0] < clipval); - vertex_t *nextout = outv; - - // iterate over vertices - for (int vertnum = 0; vertnum < numverts; vertnum++) - { - bool thisclipped = (v[vertnum].p[0] < clipval); - - // if we switched from clipped to non-clipped, interpolate a vertex - if (thisclipped != prevclipped) - { - vertex_t const &v1 = v[(vertnum == 0) ? (numverts - 1) : (vertnum - 1)]; - vertex_t const &v2 = v[vertnum]; - BaseType frac = (clipval - v1.p[0]) / (v2.p[0] - v1.p[0]); - nextout->x = v1.x + frac * (v2.x - v1.x); - nextout->y = v1.y + frac * (v2.y - v1.y); - for (int paramnum = 0; paramnum < ParamCount; paramnum++) - nextout->p[paramnum] = v1.p[paramnum] + frac * (v2.p[paramnum] - v1.p[paramnum]); - ++nextout; - } - - // if this vertex is not clipped, copy it in - if (!thisclipped) - *nextout++ = v[vertnum]; - - // remember the last state - prevclipped = thisclipped; - } - return nextout - outv; -} - - -template -struct frustum_clip_vertex -{ - BaseType x, y, z, w; // A 3d coordinate already transformed by a projection matrix - std::array p; // Additional parameters to clip -}; - - -template -int frustum_clip_w(frustum_clip_vertex const *v, int num_vertices, frustum_clip_vertex *out) -{ - if (num_vertices <= 0) - return 0; - - const BaseType W_PLANE = 0.000001f; - - frustum_clip_vertex clipv[10]; - int clip_verts = 0; - - int previ = num_vertices - 1; - - for (int i=0; i < num_vertices; i++) - { - int v1_side = (v[i].w < W_PLANE) ? -1 : 1; - int v2_side = (v[previ].w < W_PLANE) ? -1 : 1; - - if ((v1_side * v2_side) < 0) // edge goes through W plane - { - // insert vertex at intersection point - BaseType wdiv = v[previ].w - v[i].w; - if (wdiv == 0.0f) // 0 edge means degenerate polygon - return 0; - - BaseType t = fabs((W_PLANE - v[previ].w) / wdiv); - - clipv[clip_verts].x = v[previ].x + ((v[i].x - v[previ].x) * t); - clipv[clip_verts].y = v[previ].y + ((v[i].y - v[previ].y) * t); - clipv[clip_verts].z = v[previ].z + ((v[i].z - v[previ].z) * t); - clipv[clip_verts].w = v[previ].w + ((v[i].w - v[previ].w) * t); - - // Interpolate the rest of the parameters - for (int pi = 0; pi < MaxParams; pi++) - clipv[clip_verts].p[pi] = v[previ].p[pi] + ((v[i].p[pi] - v[previ].p[pi]) * t); - - ++clip_verts; - } - if (v1_side > 0) // current point is inside - { - clipv[clip_verts] = v[i]; - ++clip_verts; - } - - previ = i; - } - - memcpy(&out[0], &clipv[0], sizeof(out[0]) * clip_verts); - return clip_verts; -} - - -template -int frustum_clip(frustum_clip_vertex const *v, int num_vertices, frustum_clip_vertex *out, int axis, int sign) -{ - if (num_vertices <= 0) - return 0; - - frustum_clip_vertex clipv[10]; - int clip_verts = 0; - - int previ = num_vertices - 1; - - for (int i=0; i < num_vertices; i++) - { - int v1_side, v2_side; - BaseType* v1a = (BaseType*)&v[i]; - BaseType* v2a = (BaseType*)&v[previ]; - - BaseType v1_axis, v2_axis; - - if (sign) // +axis - { - v1_axis = v1a[axis]; - v2_axis = v2a[axis]; - } - else // -axis - { - v1_axis = -v1a[axis]; - v2_axis = -v2a[axis]; - } - - v1_side = (v1_axis <= v[i].w) ? 1 : -1; - v2_side = (v2_axis <= v[previ].w) ? 1 : -1; - - if ((v1_side * v2_side) < 0) // edge goes through W plane - { - // insert vertex at intersection point - BaseType wdiv = ((v[previ].w - v2_axis) - (v[i].w - v1_axis)); - - if (wdiv == 0.0f) // 0 edge means degenerate polygon - return 0; - - BaseType t = fabs((v[previ].w - v2_axis) / wdiv); - - clipv[clip_verts].x = v[previ].x + ((v[i].x - v[previ].x) * t); - clipv[clip_verts].y = v[previ].y + ((v[i].y - v[previ].y) * t); - clipv[clip_verts].z = v[previ].z + ((v[i].z - v[previ].z) * t); - clipv[clip_verts].w = v[previ].w + ((v[i].w - v[previ].w) * t); - - // Interpolate the rest of the parameters - for (int pi = 0; pi < MaxParams; pi++) - clipv[clip_verts].p[pi] = v[previ].p[pi] + ((v[i].p[pi] - v[previ].p[pi]) * t); - - ++clip_verts; - } - if (v1_side > 0) // current point is inside - { - clipv[clip_verts] = v[i]; - ++clip_verts; - } - - previ = i; - } - - memcpy(&out[0], &clipv[0], sizeof(out[0]) * clip_verts); - return clip_verts; -} - - -template -int frustum_clip_all(frustum_clip_vertex *clip_vert, int num_vertices, frustum_clip_vertex *out) -{ - num_vertices = frustum_clip_w(clip_vert, num_vertices, clip_vert); - num_vertices = frustum_clip(clip_vert, num_vertices, clip_vert, 0, 0); // W <= -X - num_vertices = frustum_clip(clip_vert, num_vertices, clip_vert, 0, 1); // W <= +X - num_vertices = frustum_clip(clip_vert, num_vertices, clip_vert, 1, 0); // W <= -Y - num_vertices = frustum_clip(clip_vert, num_vertices, clip_vert, 1, 1); // W <= +X - num_vertices = frustum_clip(clip_vert, num_vertices, clip_vert, 2, 0); // W <= -Z - num_vertices = frustum_clip(clip_vert, num_vertices, clip_vert, 2, 1); // W <= +Z - out = clip_vert; - return num_vertices; -} - - -#endif // MAME_DEVICES_VIDEO_POLY_H diff --git a/waterbox/ares64/ares/thirdparty/mame/emu/emu.h b/waterbox/ares64/ares/thirdparty/mame/emu/emu.h deleted file mode 100644 index b68cf64681..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/emu/emu.h +++ /dev/null @@ -1,115 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - emu.h - - Core header file to be included by most files. - - NOTE: The contents of this file are designed to meet the needs of - drivers and devices. In addition to this file, you will also need - to include the headers of any CPUs or other devices that are required. - - If you find yourself needing something outside of this file in a - driver or device, think carefully about what you are doing. - -***************************************************************************/ - -#ifndef __EMU_H__ -#define __EMU_H__ - -#include -#include -#include -#include -#include -#include -#include - -// core emulator headers -- must be first (profiler needs attotime, attotime needs xtal) -#include "emucore.h" -#include "osdcore.h" -#include "eminline.h" -#if !defined(MAME_RDP) -#include "xtal.h" -#include "attotime.h" -#include "profiler.h" - -// http interface helpers -#include "http.h" -#endif - -// commonly-referenced utilities imported from lib/util -#include "corealloc.h" -#if !defined(MAME_RDP) -#include "palette.h" -#endif - -// emulator-specific utilities -#include "hash.h" -#if !defined(MAME_RDP) -#include "fileio.h" -#endif -#include "delegate.h" -#if !defined(MAME_RDP) -#include "devdelegate.h" - -// memory and address spaces -#include "emumem.h" - -// machine-wide utilities -#include "romentry.h" -#include "save.h" - -// I/O -#include "input.h" -#include "ioport.h" -#include "output.h" - -// devices and callbacks -#include "device.h" -#include "devfind.h" -#include "addrmap.h" // Needs optional_device<> and required_device<> -#include "distate.h" -#include "dimemory.h" -#include "dipalette.h" -#include "digfx.h" -#include "diimage.h" -#include "dislot.h" -#include "disound.h" -#include "divideo.h" -#include "dinvram.h" -#include "schedule.h" -#include "dinetwork.h" - -// machine and driver configuration -#include "mconfig.h" -#include "gamedrv.h" -#include "parameters.h" - -// the running machine -#include "main.h" -#include "machine.h" -#include "driver.h" - -// common device interfaces -#include "diexec.h" -#include "devcpu.h" - -// video-related -#include "drawgfx.h" -#include "video.h" - -// sound-related -#include "sound.h" - -// generic helpers -#include "devcb.h" -#include "bookkeeping.h" -#include "video/generic.h" - -// member templates that don't like incomplete types -#include "device.ipp" -#endif - -#endif // __EMU_H__ diff --git a/waterbox/ares64/ares/thirdparty/mame/emu/emucore.cpp b/waterbox/ares64/ares/thirdparty/mame/emu/emucore.cpp deleted file mode 100644 index 3228709db9..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/emu/emucore.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Nicola Salmoria, Aaron Giles -/*************************************************************************** - - emucore.cpp - - Simple core functions that are defined in emucore.h and which may - need to be accessed by other MAME-related tools. - -****************************************************************************/ - -#include "emu.h" -#include "emucore.h" -#include "osdcore.h" - -emu_fatalerror::emu_fatalerror(util::format_argument_pack const &args) - : emu_fatalerror(0, args) -{ -#if !defined(MAME_RDP) - osd_break_into_debugger(m_text.c_str()); -#endif -} - -emu_fatalerror::emu_fatalerror(int _exitcode, util::format_argument_pack const &args) - : m_text(util::string_format(args)) - , m_code(_exitcode) -{ -} - - -#if !defined(MAME_RDP) -void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_type) -{ - throw emu_fatalerror("Error: bad downcast<> or device<>. Tried to convert a %s to a %s, which are incompatible.\n", - src_type.name(), dst_type.name()); -} - -void report_bad_device_cast(const device_t *dev, const std::type_info &src_type, const std::type_info &dst_type) -{ - throw emu_fatalerror("Error: bad downcast<> or device<>. Tried to convert the device %s (%s) of type %s to a %s, which are incompatible.\n", - dev->tag(), dev->name(), src_type.name(), dst_type.name()); -} -#endif diff --git a/waterbox/ares64/ares/thirdparty/mame/emu/emucore.h b/waterbox/ares64/ares/thirdparty/mame/emu/emucore.h deleted file mode 100644 index 768fa8c728..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/emu/emucore.h +++ /dev/null @@ -1,424 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Nicola Salmoria, Aaron Giles -/*************************************************************************** - - emucore.h - - General core utilities and macros used throughout the emulator. - -***************************************************************************/ - -#ifndef MAME_EMU_EMUCORE_H -#define MAME_EMU_EMUCORE_H - -#pragma once - -// standard C includes -#include -#include -#include -#include -#include -#include - -// some cleanups for Solaris for things defined in stdlib.h -#if defined(__sun__) && defined(__svr4__) -#undef si_status -#undef WWORD -#endif - -// standard C++ includes -#include -#include -#include -#include - -// core system includes -#include "osdcomm.h" -#include "coretmpl.h" -#include "bitmap.h" -#include "endianness.h" -#include "strformat.h" -#include "vecstream.h" - -#include "emufwd.h" - - -//************************************************************************** -// COMPILER-SPECIFIC NASTINESS -//************************************************************************** - -// Suppress warnings about redefining the macro 'PPC' on LinuxPPC. -#undef PPC - -// Suppress warnings about redefining the macro 'ARM' on ARM. -#undef ARM - - - -//************************************************************************** -// FUNDAMENTAL TYPES -//************************************************************************** - -// explicitly sized integers -using osd::u8; -using osd::u16; -using osd::u32; -using osd::u64; -using osd::s8; -using osd::s16; -using osd::s32; -using osd::s64; - -// useful utility functions -using util::underlying_value; -using util::enum_value; -using util::make_bitmask; -using util::BIT; -using util::bitswap; -using util::iabs; -using util::string_format; - -using endianness_t = util::endianness; - -using util::BYTE_XOR_BE; -using util::BYTE_XOR_LE; -using util::BYTE4_XOR_BE; -using util::BYTE4_XOR_LE; -using util::WORD_XOR_BE; -using util::WORD_XOR_LE; -using util::BYTE8_XOR_BE; -using util::BYTE8_XOR_LE; -using util::WORD2_XOR_BE; -using util::WORD2_XOR_LE; -using util::DWORD_XOR_BE; -using util::DWORD_XOR_LE; - - -// pen_t is used to represent pixel values in bitmaps -typedef u32 pen_t; - - - -//************************************************************************** -// USEFUL COMPOSITE TYPES -//************************************************************************** - -// PAIR is an endian-safe union useful for representing 32-bit CPU registers -union PAIR -{ -#ifdef LSB_FIRST - struct { u8 l,h,h2,h3; } b; - struct { u16 l,h; } w; - struct { s8 l,h,h2,h3; } sb; - struct { s16 l,h; } sw; -#else - struct { u8 h3,h2,h,l; } b; - struct { s8 h3,h2,h,l; } sb; - struct { u16 h,l; } w; - struct { s16 h,l; } sw; -#endif - u32 d; - s32 sd; -}; - - -// PAIR16 is a 16-bit extension of a PAIR -union PAIR16 -{ -#ifdef LSB_FIRST - struct { u8 l,h; } b; - struct { s8 l,h; } sb; -#else - struct { u8 h,l; } b; - struct { s8 h,l; } sb; -#endif - u16 w; - s16 sw; -}; - - -// PAIR64 is a 64-bit extension of a PAIR -union PAIR64 -{ -#ifdef LSB_FIRST - struct { u8 l,h,h2,h3,h4,h5,h6,h7; } b; - struct { u16 l,h,h2,h3; } w; - struct { u32 l,h; } d; - struct { s8 l,h,h2,h3,h4,h5,h6,h7; } sb; - struct { s16 l,h,h2,h3; } sw; - struct { s32 l,h; } sd; -#else - struct { u8 h7,h6,h5,h4,h3,h2,h,l; } b; - struct { u16 h3,h2,h,l; } w; - struct { u32 h,l; } d; - struct { s8 h7,h6,h5,h4,h3,h2,h,l; } sb; - struct { s16 h3,h2,h,l; } sw; - struct { s32 h,l; } sd; -#endif - u64 q; - s64 sq; -}; - - - -//************************************************************************** -// COMMON CONSTANTS -//************************************************************************** - -constexpr endianness_t ENDIANNESS_LITTLE = util::endianness::little; -constexpr endianness_t ENDIANNESS_BIG = util::endianness::big; -constexpr endianness_t ENDIANNESS_NATIVE = util::endianness::native; - - -// M_PI is not part of the C/C++ standards and is not present on -// strict ANSI compilers or when compiling under GCC with -ansi -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - - -/// \name Image orientation flags -/// \{ - -constexpr int ORIENTATION_FLIP_X = 0x0001; ///< Mirror horizontally (in the X direction) -constexpr int ORIENTATION_FLIP_Y = 0x0002; ///< Mirror vertically (in the Y direction) -constexpr int ORIENTATION_SWAP_XY = 0x0004; ///< Mirror along the top-left/bottom-right diagonal - -constexpr int ROT0 = 0; -constexpr int ROT90 = ORIENTATION_SWAP_XY | ORIENTATION_FLIP_X; ///< Rotate 90 degrees clockwise -constexpr int ROT180 = ORIENTATION_FLIP_X | ORIENTATION_FLIP_Y; ///< Rotate 180 degrees -constexpr int ROT270 = ORIENTATION_SWAP_XY | ORIENTATION_FLIP_Y; ///< Rotate 90 degrees anti-clockwise (270 degrees clockwise) - -/// \} - - -// these are UTF-8 encoded strings for common characters -#define UTF8_NBSP "\xc2\xa0" /* non-breaking space */ - -#define UTF8_MULTIPLY "\xc3\x97" /* multiplication sign */ -#define UTF8_DIVIDE "\xc3\xb7" /* division sign */ -#define UTF8_SQUAREROOT "\xe2\x88\x9a" /* square root symbol */ -#define UTF8_PLUSMINUS "\xc2\xb1" /* plusminus symbol */ - -#define UTF8_POW_2 "\xc2\xb2" /* superscript 2 */ -#define UTF8_POW_X "\xcb\xa3" /* superscript x */ -#define UTF8_POW_Y "\xca\xb8" /* superscript y */ -#define UTF8_PRIME "\xca\xb9" /* prime symbol */ -#define UTF8_DEGREES "\xc2\xb0" /* degrees symbol */ - -#define UTF8_SMALL_PI "\xcf\x80" /* Greek small letter pi */ -#define UTF8_CAPITAL_SIGMA "\xce\xa3" /* Greek capital letter sigma */ -#define UTF8_CAPITAL_DELTA "\xce\x94" /* Greek capital letter delta */ - -#define UTF8_MACRON "\xc2\xaf" /* macron symbol */ -#define UTF8_NONSPACE_MACRON "\xcc\x84" /* nonspace macron, use after another char */ - -#define a_RING "\xc3\xa5" /* small a with a ring */ -#define a_UMLAUT "\xc3\xa4" /* small a with an umlaut */ -#define o_UMLAUT "\xc3\xb6" /* small o with an umlaut */ -#define u_UMLAUT "\xc3\xbc" /* small u with an umlaut */ -#define e_ACUTE "\xc3\xa9" /* small e with an acute */ -#define n_TILDE "\xc3\xb1" /* small n with a tilde */ - -#define A_RING "\xc3\x85" /* capital A with a ring */ -#define A_UMLAUT "\xc3\x84" /* capital A with an umlaut */ -#define O_UMLAUT "\xc3\x96" /* capital O with an umlaut */ -#define U_UMLAUT "\xc3\x9c" /* capital U with an umlaut */ -#define E_ACUTE "\xc3\x89" /* capital E with an acute */ -#define N_TILDE "\xc3\x91" /* capital N with a tilde */ - -#define UTF8_LEFT "\xe2\x86\x90" /* cursor left */ -#define UTF8_RIGHT "\xe2\x86\x92" /* cursor right */ -#define UTF8_UP "\xe2\x86\x91" /* cursor up */ -#define UTF8_DOWN "\xe2\x86\x93" /* cursor down */ - - - -//************************************************************************** -// COMMON MACROS -//************************************************************************** - -// macro for defining a copy constructor and assignment operator to prevent copying -#define DISABLE_COPYING(TYPE) \ - TYPE(const TYPE &) = delete; \ - TYPE &operator=(const TYPE &) = delete - -// macro for declaring enumeration operators that increment/decrement like plain old C -#define DECLARE_ENUM_INCDEC_OPERATORS(TYPE) \ -inline TYPE &operator++(TYPE &value) { return value = TYPE(std::underlying_type_t(value) + 1); } \ -inline TYPE &operator--(TYPE &value) { return value = TYPE(std::underlying_type_t(value) - 1); } \ -inline TYPE operator++(TYPE &value, int) { TYPE const old(value); ++value; return old; } \ -inline TYPE operator--(TYPE &value, int) { TYPE const old(value); --value; return old; } - -// macro for declaring bitwise operators for an enumerated type -#define DECLARE_ENUM_BITWISE_OPERATORS(TYPE) \ -constexpr TYPE operator~(TYPE value) { return TYPE(~std::underlying_type_t(value)); } \ -constexpr TYPE operator&(TYPE a, TYPE b) { return TYPE(std::underlying_type_t(a) & std::underlying_type_t(b)); } \ -constexpr TYPE operator|(TYPE a, TYPE b) { return TYPE(std::underlying_type_t(a) | std::underlying_type_t(b)); } \ -inline TYPE &operator&=(TYPE &a, TYPE b) { return a = a & b; } \ -inline TYPE &operator|=(TYPE &a, TYPE b) { return a = a | b; } - - -// this macro passes an item followed by a string version of itself as two consecutive parameters -#define NAME(x) x, #x - -// this macro wraps a function 'x' and can be used to pass a function followed by its name -#define FUNC(x) &x, #x - - -// macros to convert radians to degrees and degrees to radians -template constexpr auto RADIAN_TO_DEGREE(T const &x) { return (180.0 / M_PI) * x; } -template constexpr auto DEGREE_TO_RADIAN(T const &x) { return (M_PI / 180.0) * x; } - - -//************************************************************************** -// EXCEPTION CLASSES -//************************************************************************** - -// emu_exception is the base class for all emu-related exceptions -class emu_exception : public std::exception { }; - - -// emu_fatalerror is a generic fatal exception that provides an error string -class emu_fatalerror : public emu_exception -{ -public: - emu_fatalerror(util::format_argument_pack const &args); - emu_fatalerror(int _exitcode, util::format_argument_pack const &args); - - template - emu_fatalerror(Format const &fmt, Params &&... args) - : emu_fatalerror(static_cast const &>(util::make_format_argument_pack(fmt, std::forward(args)...))) - { - } - template - emu_fatalerror(int _exitcode, Format const &fmt, Params &&... args) - : emu_fatalerror(_exitcode, static_cast const &>(util::make_format_argument_pack(fmt, std::forward(args)...))) - { - } - - virtual char const *what() const noexcept override { return m_text.c_str(); } - int exitcode() const noexcept { return m_code; } - -private: - std::string m_text; - int m_code; -}; - -class tag_add_exception -{ -public: - tag_add_exception(const char *tag) : m_tag(tag) { } - const char *tag() const { return m_tag.c_str(); } -private: - std::string m_tag; -}; - - -//************************************************************************** -// CASTING TEMPLATES -//************************************************************************** - -[[noreturn]] void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_type); -[[noreturn]] void report_bad_device_cast(const device_t *dev, const std::type_info &src_type, const std::type_info &dst_type); - -template -inline void report_bad_cast(Source *src) -{ - if constexpr (std::is_base_of_v) - { - if (src) report_bad_device_cast(src, typeid(Source), typeid(Dest)); - else report_bad_cast(typeid(Source), typeid(Dest)); - } - else - { - device_t const *dev(dynamic_cast(src)); - if (dev) report_bad_device_cast(dev, typeid(Source), typeid(Dest)); - else report_bad_cast(typeid(Source), typeid(Dest)); - } -} - -// template function for casting from a base class to a derived class that is checked -// in debug builds and fast in release builds -template -inline Dest downcast(Source *src) -{ -#if defined(MAME_DEBUG) - Dest const chk(dynamic_cast(src)); - if (chk != src) report_bad_cast, Source>(src); -#endif - return static_cast(src); -} - -template -inline Dest downcast(Source &src) -{ -#if defined(MAME_DEBUG) - std::remove_reference_t *const chk(dynamic_cast *>(&src)); - if (chk != &src) report_bad_cast, Source>(&src); -#endif - return static_cast(src); -} - - - -//************************************************************************** -// INLINE FUNCTIONS -//************************************************************************** - -template -[[noreturn]] inline void fatalerror(T &&... args) -{ - throw emu_fatalerror(std::forward(args)...); -} - - -// convert a series of 32 bits into a float -inline float u2f(u32 v) -{ - union { - float ff; - u32 vv; - } u; - u.vv = v; - return u.ff; -} - - -// convert a float into a series of 32 bits -inline u32 f2u(float f) -{ - union { - float ff; - u32 vv; - } u; - u.ff = f; - return u.vv; -} - - -// convert a series of 64 bits into a double -inline double u2d(u64 v) -{ - union { - double dd; - u64 vv; - } u; - u.vv = v; - return u.dd; -} - - -// convert a double into a series of 64 bits -inline u64 d2u(double d) -{ - union { - double dd; - u64 vv; - } u; - u.dd = d; - return u.vv; -} - -#endif // MAME_EMU_EMUCORE_H diff --git a/waterbox/ares64/ares/thirdparty/mame/emu/emufwd.h b/waterbox/ares64/ares/thirdparty/mame/emu/emufwd.h deleted file mode 100644 index 8b8e59b925..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/emu/emufwd.h +++ /dev/null @@ -1,255 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -/********************************************************************** - * emufwd.h - * - * Forward declarations for MAME famework. - * - * Please place forward declarations here rather than littering them - * throughout headers in src/emu. It makes it much easier to update - * them and remove obsolete ones. - **********************************************************************/ -#ifndef MAME_EMU_EMUFWD_H -#define MAME_EMU_EMUFWD_H - -#pragma once - -#include - - -//---------------------------------- -// 3rdparty -//---------------------------------- - -// declared in expat.h -struct XML_ParserStruct; - - - -//---------------------------------- -// osd -//---------------------------------- - -// declared in modules/output/output_module.h -class output_module; - -// declared in osdepend.h -class osd_font; -class osd_interface; - - - -//---------------------------------- -// lib/util -//---------------------------------- - -// declared in aviio.h -class avi_file; - -// declared in chd.h -class chd_file; - -// declared in unzip.h -namespace util { class archive_file; } - -// declared in xmlfile.h -namespace util::xml { class data_node; class file; } - - - -//---------------------------------- -// emu -//---------------------------------- - -// declared in addrmap.h -class address_map; -class address_map_entry; - -// declared in bookkeeping.h -class bookkeeping_manager; - -// declared in config.h -enum class config_type : int; -enum class config_level : int; -class configuration_manager; - -// declared in crsshair.h -class crosshair_manager; - -// declared in debug/debugcmd.h -class debugger_commands; - -// declared in debug/debugcon.h -class debugger_console; - -// declared in debug/debugcpu.h -class debugger_cpu; -class device_debug; - -// declared in debug/debugvw.h -class debug_view; -class debug_view_manager; - -// declared in debug/express.h -class parsed_expression; -class symbol_table; - -// declared in debug/points.h -class debug_breakpoint; -class debug_watchpoint; -class debug_registerpoint; - -// declared in debugger.h -class debugger_manager; - -// declared in devcb.h -class devcb_base; -template DefaultMask> class devcb_write; - -// declared in devfind.h -class finder_base; -template class device_finder; - -// declared in device.h -class device_interface; -class device_t; - -// declared in didisasm.h -class device_disasm_interface; - -// declared in diexec.h -class device_execute_interface; - -// declared in digfx.h -struct gfx_decode_entry; - -// declared in diimage.h -class device_image_interface; - -// declared in dimemory.h -class device_memory_interface; - -// declared in dipalette.h -class device_palette_interface; - -// declared in distate.h -class device_state_interface; - -// declared in drawgfx.h -class gfx_element; - -// declared in driver.h -class driver_device; - -// declared in emumem.h -class address_space; -class memory_bank; -class memory_manager; -class memory_region; -class memory_share; -class memory_view; - -// declared in emuopts.h -class emu_options; - -// declared in gamedrv.h -class game_driver; - -// declared in input.h -class input_manager; - -// declared in inputdev.h -class input_class; -class input_device; -class input_device_item; - -// declared in image.h -class image_manager; - -// declared in ioport.h -class analog_field; -struct input_device_default; -class ioport_field; -struct ioport_field_live; -class ioport_list; -class ioport_manager; -class ioport_port; -struct ioport_port_live; - -// declared in machine.h -class running_machine; - -// declared in mconfig.h -namespace emu::detail { class machine_config_replace; } -class machine_config; - -// declared in natkeyboard.h -class natural_keyboard; - -// declared in network.h -class network_manager; - -// declared in output.h -class output_manager; - -// declared in render.h -class render_container; -class render_manager; -class render_target; -class render_texture; - -// declared in rendfont.h -class render_font; - -// declared in rendlay.h -class layout_element; -class layout_view_item; -class layout_view; -class layout_file; - -// declared in romentry.h -class rom_entry; - -// declared in romload.h -class rom_load_manager; - -// declared in schedule.h -class device_scheduler; -class emu_timer; - -// declared in screen.h -class screen_device; - -// declared in softlist.h -class software_info; -class software_part; - -// declared in softlist_dev.h -class software_list_device; -class software_list_loader; - -// declared in sound.h -class sound_manager; -class sound_stream; - -// declared in speaker.h -class speaker_device; - -// declared in tilemap.h -class tilemap_device; -class tilemap_manager; -class tilemap_t; - -// declared in ui/uimain.h -class ui_manager; - -// declared in uiinput.h -class ui_input_manager; - -// declared in validity.h -class validity_checker; - -// declared in video.h -class video_manager; - -#endif // MAME_EMU_EMUFWD_H diff --git a/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbgen.h b/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbgen.h deleted file mode 100644 index e460208d9f..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbgen.h +++ /dev/null @@ -1,445 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb, Ryan Holtz -/*************************************************************************** - - rgbgen.h - - General RGB utilities. - -***************************************************************************/ - -#ifndef MAME_EMU_VIDEO_RGBGEN_H -#define MAME_EMU_VIDEO_RGBGEN_H - - -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -class rgbaint_t -{ -public: - rgbaint_t(): m_a(0), m_r(0), m_g(0), m_b(0) { } - explicit rgbaint_t(u32 rgba) { set(rgba); } - rgbaint_t(s32 a, s32 r, s32 g, s32 b) { set(a, r, g, b); } - explicit rgbaint_t(const rgb_t& rgba) { set(rgba); } - - rgbaint_t(const rgbaint_t& other) = default; - rgbaint_t &operator=(const rgbaint_t& other) = default; - - void set(const rgbaint_t& other) { set(other.m_a, other.m_r, other.m_g, other.m_b); } - void set(u32 rgba) { set((rgba >> 24) & 0xff, (rgba >> 16) & 0xff, (rgba >> 8) & 0xff, rgba & 0xff); } - void set(s32 a, s32 r, s32 g, s32 b) - { - m_a = a; - m_r = r; - m_g = g; - m_b = b; - } - void set(const rgb_t& rgba) { set(rgba.a(), rgba.r(), rgba.g(), rgba.b()); } - // This function sets all elements to the same val - void set_all(const s32& val) { set(val, val, val, val); } - // This function zeros all elements - void zero() { set_all(0); } - // This function zeros only the alpha element - void zero_alpha() { m_a = 0; } - - rgb_t to_rgba() const { return rgb_t(get_a(), get_r(), get_g(), get_b()); } - - rgb_t to_rgba_clamp() const - { - const u8 a = (m_a < 0) ? 0 : (m_a > 255) ? 255 : m_a; - const u8 r = (m_r < 0) ? 0 : (m_r > 255) ? 255 : m_r; - const u8 g = (m_g < 0) ? 0 : (m_g > 255) ? 255 : m_g; - const u8 b = (m_b < 0) ? 0 : (m_b > 255) ? 255 : m_b; - return rgb_t(a, r, g, b); - } - - void set_a16(const s32 value) { m_a = value; } - void set_a(const s32 value) { m_a = value; } - void set_r(const s32 value) { m_r = value; } - void set_g(const s32 value) { m_g = value; } - void set_b(const s32 value) { m_b = value; } - - u8 get_a() const { return u8(u32(m_a)); } - u8 get_r() const { return u8(u32(m_r)); } - u8 get_g() const { return u8(u32(m_g)); } - u8 get_b() const { return u8(u32(m_b)); } - - s32 get_a32() const { return m_a; } - s32 get_r32() const { return m_r; } - s32 get_g32() const { return m_g; } - s32 get_b32() const { return m_b; } - - // These selects return an rgbaint_t with all fields set to the element choosen (a, r, g, or b) - rgbaint_t select_alpha32() const { return rgbaint_t(get_a32(), get_a32(), get_a32(), get_a32()); } - rgbaint_t select_red32() const { return rgbaint_t(get_r32(), get_r32(), get_r32(), get_r32()); } - rgbaint_t select_green32() const { return rgbaint_t(get_g32(), get_g32(), get_g32(), get_g32()); } - rgbaint_t select_blue32() const { return rgbaint_t(get_b32(), get_b32(), get_b32(), get_b32()); } - - inline void add(const rgbaint_t& color) - { - add_imm_rgba(color.m_a, color.m_r, color.m_g, color.m_b); - } - - inline void add_imm(const s32 imm) - { - add_imm_rgba(imm, imm, imm, imm); - } - - inline void add_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_a += a; - m_r += r; - m_g += g; - m_b += b; - } - - inline void sub(const rgbaint_t& color) - { - sub_imm_rgba(color.m_a, color.m_r, color.m_g, color.m_b); - } - - inline void sub_imm(const s32 imm) - { - sub_imm_rgba(imm, imm, imm, imm); - } - - inline void sub_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_a -= a; - m_r -= r; - m_g -= g; - m_b -= b; - } - - inline void subr(const rgbaint_t& color) - { - subr_imm_rgba(color.m_a, color.m_r, color.m_g, color.m_b); - } - - inline void subr_imm(const s32 imm) - { - subr_imm_rgba(imm, imm, imm, imm); - } - - inline void subr_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_a = a - m_a; - m_r = r - m_r; - m_g = g - m_g; - m_b = b - m_b; - } - - inline void mul(const rgbaint_t& color) - { - mul_imm_rgba(color.m_a, color.m_r, color.m_g, color.m_b); - } - - inline void mul_imm(const s32 imm) - { - mul_imm_rgba(imm, imm, imm, imm); - } - - inline void mul_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_a *= a; - m_r *= r; - m_g *= g; - m_b *= b; - } - - inline void shl(const rgbaint_t& shift) - { - m_a <<= shift.m_a; - m_r <<= shift.m_r; - m_g <<= shift.m_g; - m_b <<= shift.m_b; - } - - inline void shl_imm(const u8 shift) - { - if (shift == 0) - return; - - m_a <<= shift; - m_r <<= shift; - m_g <<= shift; - m_b <<= shift; - } - - inline void shr(const rgbaint_t& shift) - { - m_a = s32(u32(m_a) >> shift.m_a); - m_r = s32(u32(m_r) >> shift.m_r); - m_g = s32(u32(m_g) >> shift.m_g); - m_b = s32(u32(m_b) >> shift.m_b); - } - - inline void shr_imm(const u8 shift) - { - if (shift == 0) - return; - - m_a = s32(u32(m_a) >> shift); - m_r = s32(u32(m_r) >> shift); - m_g = s32(u32(m_g) >> shift); - m_b = s32(u32(m_b) >> shift); - } - - inline void sra(const rgbaint_t& shift) - { - m_a >>= shift.m_a; - if (m_a & (1 << (31 - shift.m_a))) - m_a |= ~0 << (32 - shift.m_a); - - m_r >>= shift.m_r; - if (m_r & (1 << (31 - shift.m_r))) - m_r |= ~0 << (32 - shift.m_r); - - m_g >>= shift.m_g; - if (m_g & (1 << (31 - shift.m_g))) - m_g |= ~0 << (32 - shift.m_g); - - m_b >>= shift.m_b; - if (m_b & (1 << (31 - shift.m_b))) - m_b |= ~0 << (32 - shift.m_b); - } - - inline void sra_imm(const u8 shift) - { - const u32 high_bit = 1 << (31 - shift); - const u32 high_mask = ~0 << (32 - shift); - - m_a >>= shift; - if (m_a & high_bit) - m_a |= high_mask; - - m_r >>= shift; - if (m_r & high_bit) - m_r |= high_mask; - - m_g >>= shift; - if (m_g & high_bit) - m_g |= high_mask; - - m_b >>= shift; - if (m_b & high_bit) - m_b |= high_mask; - } - - void or_reg(const rgbaint_t& color) { or_imm_rgba(color.m_a, color.m_r, color.m_g, color.m_b); } - void and_reg(const rgbaint_t& color) { and_imm_rgba(color.m_a, color.m_r, color.m_g, color.m_b); } - void xor_reg(const rgbaint_t& color) { xor_imm_rgba(color.m_a, color.m_r, color.m_g, color.m_b); } - - void andnot_reg(const rgbaint_t& color) { and_imm_rgba(~color.m_a, ~color.m_r, ~color.m_g, ~color.m_b); } - - void or_imm(s32 imm) { or_imm_rgba(imm, imm, imm, imm); } - void and_imm(s32 imm) { and_imm_rgba(imm, imm, imm, imm); } - void xor_imm(s32 imm) { xor_imm_rgba(imm, imm, imm, imm); } - - inline void or_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_a |= a; - m_r |= r; - m_g |= g; - m_b |= b; - } - - inline void and_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_a &= a; - m_r &= r; - m_g &= g; - m_b &= b; - } - - inline void xor_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_a ^= a; - m_r ^= r; - m_g ^= g; - m_b ^= b; - } - - inline void clamp_and_clear(const u32 sign) - { - if (m_a & sign) m_a = 0; - if (m_r & sign) m_r = 0; - if (m_g & sign) m_g = 0; - if (m_b & sign) m_b = 0; - - clamp_to_uint8(); - } - - inline void clamp_to_uint8() - { - m_a = (m_a < 0) ? 0 : (m_a > 255) ? 255 : m_a; - m_r = (m_r < 0) ? 0 : (m_r > 255) ? 255 : m_r; - m_g = (m_g < 0) ? 0 : (m_g > 255) ? 255 : m_g; - m_b = (m_b < 0) ? 0 : (m_b > 255) ? 255 : m_b; - } - - inline void sign_extend(const u32 compare, const u32 sign) - { - if ((m_a & compare) == compare) - m_a |= sign; - - if ((m_r & compare) == compare) - m_r |= sign; - - if ((m_g & compare) == compare) - m_g |= sign; - - if ((m_b & compare) == compare) - m_b |= sign; - } - - inline void min(const s32 value) - { - m_a = (m_a > value) ? value : m_a; - m_r = (m_r > value) ? value : m_r; - m_g = (m_g > value) ? value : m_g; - m_b = (m_b > value) ? value : m_b; - } - - inline void max(const s32 value) - { - m_a = (m_a < value) ? value : m_a; - m_r = (m_r < value) ? value : m_r; - m_g = (m_g < value) ? value : m_g; - m_b = (m_b < value) ? value : m_b; - } - - void blend(const rgbaint_t& other, u8 factor); - - void scale_and_clamp(const rgbaint_t& scale); - void scale_imm_and_clamp(const s32 scale); - void scale2_add_and_clamp(const rgbaint_t& scale, const rgbaint_t& other, const rgbaint_t& scale2); - void scale_add_and_clamp(const rgbaint_t& scale, const rgbaint_t& other); - - void cmpeq(const rgbaint_t& value) { cmpeq_imm_rgba(value.m_a, value.m_r, value.m_g, value.m_b); } - void cmpgt(const rgbaint_t& value) { cmpgt_imm_rgba(value.m_a, value.m_r, value.m_g, value.m_b); } - void cmplt(const rgbaint_t& value) { cmplt_imm_rgba(value.m_a, value.m_r, value.m_g, value.m_b); } - - void cmpeq_imm(s32 value) { cmpeq_imm_rgba(value, value, value, value); } - void cmpgt_imm(s32 value) { cmpgt_imm_rgba(value, value, value, value); } - void cmplt_imm(s32 value) { cmplt_imm_rgba(value, value, value, value); } - - void cmpeq_imm_rgba(s32 a, s32 r, s32 g, s32 b) - { - m_a = (m_a == a) ? 0xffffffff : 0; - m_r = (m_r == r) ? 0xffffffff : 0; - m_g = (m_g == g) ? 0xffffffff : 0; - m_b = (m_b == b) ? 0xffffffff : 0; - } - - void cmpgt_imm_rgba(s32 a, s32 r, s32 g, s32 b) - { - m_a = (m_a > a) ? 0xffffffff : 0; - m_r = (m_r > r) ? 0xffffffff : 0; - m_g = (m_g > g) ? 0xffffffff : 0; - m_b = (m_b > b) ? 0xffffffff : 0; - } - - void cmplt_imm_rgba(s32 a, s32 r, s32 g, s32 b) - { - m_a = (m_a < a) ? 0xffffffff : 0; - m_r = (m_r < r) ? 0xffffffff : 0; - m_g = (m_g < g) ? 0xffffffff : 0; - m_b = (m_b < b) ? 0xffffffff : 0; - } - - void merge_alpha16(const rgbaint_t& alpha) - { - m_a = alpha.m_a; - } - - void merge_alpha(const rgbaint_t& alpha) - { - m_a = alpha.m_a; - } - - rgbaint_t& operator+=(const rgbaint_t& other) - { - add_imm_rgba(other.m_a, other.m_r, other.m_g, other.m_b); - return *this; - } - - rgbaint_t& operator+=(const s32 other) - { - add_imm_rgba(other, other, other, other); - return *this; - } - - rgbaint_t &operator-=(const rgbaint_t& other) - { - sub_imm_rgba(other.m_a, other.m_r, other.m_g, other.m_b); - return *this; - } - - rgbaint_t& operator*=(const rgbaint_t& other) - { - mul_imm_rgba(other.m_a, other.m_r, other.m_g, other.m_b); - return *this; - } - - rgbaint_t& operator*=(const s32 other) - { - mul_imm_rgba(other, other, other, other); - return *this; - } - - rgbaint_t& operator>>=(const s32 shift) - { - sra_imm(shift); - return *this; - } - - static u32 bilinear_filter(u32 rgb00, u32 rgb01, u32 rgb10, u32 rgb11, u8 u, u8 v) - { - u32 rb0 = (rgb00 & 0x00ff00ff) + ((((rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff)) * u) >> 8); - u32 rb1 = (rgb10 & 0x00ff00ff) + ((((rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff)) * u) >> 8); - - rgb00 >>= 8; - rgb01 >>= 8; - rgb10 >>= 8; - rgb11 >>= 8; - - u32 ag0 = (rgb00 & 0x00ff00ff) + ((((rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff)) * u) >> 8); - u32 ag1 = (rgb10 & 0x00ff00ff) + ((((rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff)) * u) >> 8); - - rb0 = (rb0 & 0x00ff00ff) + ((((rb1 & 0x00ff00ff) - (rb0 & 0x00ff00ff)) * v) >> 8); - ag0 = (ag0 & 0x00ff00ff) + ((((ag1 & 0x00ff00ff) - (ag0 & 0x00ff00ff)) * v) >> 8); - - return ((ag0 << 8) & 0xff00ff00) | (rb0 & 0x00ff00ff); - } - - void bilinear_filter_rgbaint(u32 rgb00, u32 rgb01, u32 rgb10, u32 rgb11, u8 u, u8 v) - { - u32 rb0 = (rgb00 & 0x00ff00ff) + ((((rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff)) * u) >> 8); - u32 rb1 = (rgb10 & 0x00ff00ff) + ((((rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff)) * u) >> 8); - - rgb00 >>= 8; - rgb01 >>= 8; - rgb10 >>= 8; - rgb11 >>= 8; - - u32 ag0 = (rgb00 & 0x00ff00ff) + ((((rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff)) * u) >> 8); - u32 ag1 = (rgb10 & 0x00ff00ff) + ((((rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff)) * u) >> 8); - - rb0 = (rb0 & 0x00ff00ff) + ((((rb1 & 0x00ff00ff) - (rb0 & 0x00ff00ff)) * v) >> 8); - ag0 = (ag0 & 0x00ff00ff) + ((((ag1 & 0x00ff00ff) - (ag0 & 0x00ff00ff)) * v) >> 8); - - u32 result = ((ag0 << 8) & 0xff00ff00) | (rb0 & 0x00ff00ff); - this->set(result); - } - -protected: - s32 m_a; - s32 m_r; - s32 m_g; - s32 m_b; -}; - -#endif // MAME_EMU_VIDEO_RGBGEN_H diff --git a/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbsse.h b/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbsse.h deleted file mode 100644 index ea3bc1e208..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbsse.h +++ /dev/null @@ -1,502 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb, Ryan Holtz -/*************************************************************************** - - rgbsse.h - - SSE optimized RGB utilities. - - WARNING: This code assumes SSE2 or greater capability. - -***************************************************************************/ - -#ifndef MAME_EMU_VIDEO_RGBSSE_H -#define MAME_EMU_VIDEO_RGBSSE_H - -#pragma once - -#include -#ifdef __SSE4_1__ -#include -#endif - - -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -class rgbaint_t -{ -public: - rgbaint_t() { } - explicit rgbaint_t(u32 rgba) { set(rgba); } - rgbaint_t(s32 a, s32 r, s32 g, s32 b) { set(a, r, g, b); } - explicit rgbaint_t(const rgb_t& rgb) { set(rgb); } - explicit rgbaint_t(__m128i rgba) { m_value = rgba; } - - rgbaint_t(const rgbaint_t& other) = default; - rgbaint_t &operator=(const rgbaint_t& other) = default; - - void set(const rgbaint_t& other) { m_value = other.m_value; } - void set(const u32& rgba) { m_value = _mm_unpacklo_epi16(_mm_unpacklo_epi8(_mm_cvtsi32_si128(rgba), _mm_setzero_si128()), _mm_setzero_si128()); } - void set(s32 a, s32 r, s32 g, s32 b) { m_value = _mm_set_epi32(a, r, g, b); } - void set(const rgb_t& rgb) { set((const u32&) rgb); } - // This function sets all elements to the same val - void set_all(const s32& val) { m_value = _mm_set1_epi32(val); } - // This function zeros all elements - void zero() { m_value = _mm_xor_si128(m_value, m_value); } - // This function zeros only the alpha element - void zero_alpha() { m_value = _mm_and_si128(m_value, alpha_mask()); } - - inline rgb_t to_rgba() const - { - return _mm_cvtsi128_si32(_mm_packus_epi16(_mm_packs_epi32(m_value, _mm_setzero_si128()), _mm_setzero_si128())); - } - - inline rgb_t to_rgba_clamp() const - { - return _mm_cvtsi128_si32(_mm_packus_epi16(_mm_packs_epi32(m_value, _mm_setzero_si128()), _mm_setzero_si128())); - } - - void set_a16(const s32 value) { m_value = _mm_insert_epi16(m_value, value, 6); } -#ifdef __SSE4_1__ - void set_a(const s32 value) { m_value = _mm_insert_epi32(m_value, value, 3); } - void set_r(const s32 value) { m_value = _mm_insert_epi32(m_value, value, 2); } - void set_g(const s32 value) { m_value = _mm_insert_epi32(m_value, value, 1); } - void set_b(const s32 value) { m_value = _mm_insert_epi32(m_value, value, 0); } -#else - void set_a(const s32 value) { m_value = _mm_or_si128(_mm_and_si128(m_value, alpha_mask()), _mm_set_epi32(value, 0, 0, 0)); } - void set_r(const s32 value) { m_value = _mm_or_si128(_mm_and_si128(m_value, red_mask()), _mm_set_epi32(0, value, 0, 0)); } - void set_g(const s32 value) { m_value = _mm_or_si128(_mm_and_si128(m_value, green_mask()), _mm_set_epi32(0, 0, value, 0)); } - void set_b(const s32 value) { m_value = _mm_or_si128(_mm_and_si128(m_value, blue_mask()), _mm_set_epi32(0, 0, 0, value)); } -#endif - - u8 get_a() const { return u8(unsigned(_mm_extract_epi16(m_value, 6))); } - u8 get_r() const { return u8(unsigned(_mm_extract_epi16(m_value, 4))); } - u8 get_g() const { return u8(unsigned(_mm_extract_epi16(m_value, 2))); } - u8 get_b() const { return u8(unsigned(_mm_cvtsi128_si32(m_value))); } - -#ifdef __SSE4_1__ - s32 get_a32() const { return _mm_extract_epi32(m_value, 3); } - s32 get_r32() const { return _mm_extract_epi32(m_value, 2); } - s32 get_g32() const { return _mm_extract_epi32(m_value, 1); } - s32 get_b32() const { return _mm_extract_epi32(m_value, 0); } -#else - s32 get_a32() const { return (_mm_cvtsi128_si32(_mm_shuffle_epi32(m_value, _MM_SHUFFLE(0, 0, 0, 3)))); } - s32 get_r32() const { return (_mm_cvtsi128_si32(_mm_shuffle_epi32(m_value, _MM_SHUFFLE(0, 0, 0, 2)))); } - s32 get_g32() const { return (_mm_cvtsi128_si32(_mm_shuffle_epi32(m_value, _MM_SHUFFLE(0, 0, 0, 1)))); } - s32 get_b32() const { return (_mm_cvtsi128_si32(m_value)); } -#endif - - // These selects return an rgbaint_t with all fields set to the element choosen (a, r, g, or b) - rgbaint_t select_alpha32() const { return (rgbaint_t)_mm_shuffle_epi32(m_value, _MM_SHUFFLE(3, 3, 3, 3)); } - rgbaint_t select_red32() const { return (rgbaint_t)_mm_shuffle_epi32(m_value, _MM_SHUFFLE(2, 2, 2, 2)); } - rgbaint_t select_green32() const { return (rgbaint_t)_mm_shuffle_epi32(m_value, _MM_SHUFFLE(1, 1, 1, 1)); } - rgbaint_t select_blue32() const { return (rgbaint_t)_mm_shuffle_epi32(m_value, _MM_SHUFFLE(0, 0, 0, 0)); } - - inline void add(const rgbaint_t& color2) - { - m_value = _mm_add_epi32(m_value, color2.m_value); - } - - inline void add_imm(const s32 imm) - { - m_value = _mm_add_epi32(m_value, _mm_set1_epi32(imm)); - } - - inline void add_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_value = _mm_add_epi32(m_value, _mm_set_epi32(a, r, g, b)); - } - - inline void sub(const rgbaint_t& color2) - { - m_value = _mm_sub_epi32(m_value, color2.m_value); - } - - inline void sub_imm(const s32 imm) - { - m_value = _mm_sub_epi32(m_value, _mm_set1_epi32(imm)); - } - - inline void sub_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_value = _mm_sub_epi32(m_value, _mm_set_epi32(a, r, g, b)); - } - - inline void subr(const rgbaint_t& color2) - { - m_value = _mm_sub_epi32(color2.m_value, m_value); - } - - inline void subr_imm(const s32 imm) - { - m_value = _mm_sub_epi32(_mm_set1_epi32(imm), m_value); - } - - inline void subr_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - m_value = _mm_sub_epi32(_mm_set_epi32(a, r, g, b), m_value); - } - - inline void mul(const rgbaint_t& color) - { - __m128i tmp1 = _mm_mul_epu32(m_value, color.m_value); - __m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(m_value, 4), _mm_srli_si128(color.m_value, 4)); - m_value = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUFFLE(0, 0, 2, 0)), _mm_shuffle_epi32(tmp2, _MM_SHUFFLE(0, 0, 2, 0))); - } - - inline void mul_imm(const s32 imm) - { - __m128i immv = _mm_set1_epi32(imm); - __m128i tmp1 = _mm_mul_epu32(m_value, immv); - __m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(m_value, 4), _mm_srli_si128(immv, 4)); - m_value = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUFFLE(0, 0, 2, 0)), _mm_shuffle_epi32(tmp2, _MM_SHUFFLE(0, 0, 2, 0))); - } - - inline void mul_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { - __m128i immv = _mm_set_epi32(a, r, g, b); - __m128i tmp1 = _mm_mul_epu32(m_value, immv); - __m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(m_value, 4), _mm_srli_si128(immv, 4)); - m_value = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUFFLE(0, 0, 2, 0)), _mm_shuffle_epi32(tmp2, _MM_SHUFFLE(0, 0, 2, 0))); - } - - inline void shl(const rgbaint_t& shift) - { - rgbaint_t areg(*this); - rgbaint_t rreg(*this); - rgbaint_t greg(*this); - rgbaint_t breg(*this); - rgbaint_t ashift(0, 0, 0, shift.get_a32()); - rgbaint_t rshift(0, 0, 0, shift.get_r32()); - rgbaint_t gshift(0, 0, 0, shift.get_g32()); - rgbaint_t bshift(0, 0, 0, shift.get_b32()); - areg.m_value = _mm_sll_epi32(areg.m_value, ashift.m_value); - rreg.m_value = _mm_sll_epi32(rreg.m_value, rshift.m_value); - greg.m_value = _mm_sll_epi32(greg.m_value, gshift.m_value); - breg.m_value = _mm_sll_epi32(breg.m_value, bshift.m_value); - set(areg.get_a32(), rreg.get_r32(), greg.get_g32(), breg.get_b32()); - } - - inline void shl_imm(const u8 shift) - { - m_value = _mm_slli_epi32(m_value, shift); - } - - inline void shr(const rgbaint_t& shift) - { - rgbaint_t areg(*this); - rgbaint_t rreg(*this); - rgbaint_t greg(*this); - rgbaint_t breg(*this); - rgbaint_t ashift(0, 0, 0, shift.get_a32()); - rgbaint_t rshift(0, 0, 0, shift.get_r32()); - rgbaint_t gshift(0, 0, 0, shift.get_g32()); - rgbaint_t bshift(0, 0, 0, shift.get_b32()); - areg.m_value = _mm_srl_epi32(areg.m_value, ashift.m_value); - rreg.m_value = _mm_srl_epi32(rreg.m_value, rshift.m_value); - greg.m_value = _mm_srl_epi32(greg.m_value, gshift.m_value); - breg.m_value = _mm_srl_epi32(breg.m_value, bshift.m_value); - set(areg.get_a32(), rreg.get_r32(), greg.get_g32(), breg.get_b32()); - } - - inline void shr_imm(const u8 shift) - { - m_value = _mm_srli_epi32(m_value, shift); - } - - inline void sra(const rgbaint_t& shift) - { - rgbaint_t areg(*this); - rgbaint_t rreg(*this); - rgbaint_t greg(*this); - rgbaint_t breg(*this); - rgbaint_t ashift(0, 0, 0, shift.get_a32()); - rgbaint_t rshift(0, 0, 0, shift.get_r32()); - rgbaint_t gshift(0, 0, 0, shift.get_g32()); - rgbaint_t bshift(0, 0, 0, shift.get_b32()); - areg.m_value = _mm_sra_epi32(areg.m_value, ashift.m_value); - rreg.m_value = _mm_sra_epi32(rreg.m_value, rshift.m_value); - greg.m_value = _mm_sra_epi32(greg.m_value, gshift.m_value); - breg.m_value = _mm_sra_epi32(breg.m_value, bshift.m_value); - set(areg.get_a32(), rreg.get_r32(), greg.get_g32(), breg.get_b32()); - } - - inline void sra_imm(const u8 shift) - { - m_value = _mm_srai_epi32(m_value, shift); - } - - void or_reg(const rgbaint_t& color2) { m_value = _mm_or_si128(m_value, color2.m_value); } - void and_reg(const rgbaint_t& color2) { m_value = _mm_and_si128(m_value, color2.m_value); } - void xor_reg(const rgbaint_t& color2) { m_value = _mm_xor_si128(m_value, color2.m_value); } - - void andnot_reg(const rgbaint_t& color2) { m_value = _mm_andnot_si128(color2.m_value, m_value); } - - void or_imm(s32 value) { m_value = _mm_or_si128(m_value, _mm_set1_epi32(value)); } - void and_imm(s32 value) { m_value = _mm_and_si128(m_value, _mm_set1_epi32(value)); } - void xor_imm(s32 value) { m_value = _mm_xor_si128(m_value, _mm_set1_epi32(value)); } - - void or_imm_rgba(s32 a, s32 r, s32 g, s32 b) { m_value = _mm_or_si128(m_value, _mm_set_epi32(a, r, g, b)); } - void and_imm_rgba(s32 a, s32 r, s32 g, s32 b) { m_value = _mm_and_si128(m_value, _mm_set_epi32(a, r, g, b)); } - void xor_imm_rgba(s32 a, s32 r, s32 g, s32 b) { m_value = _mm_xor_si128(m_value, _mm_set_epi32(a, r, g, b)); } - - inline void clamp_and_clear(const u32 sign) - { - __m128i vsign = _mm_set1_epi32(sign); - m_value = _mm_and_si128(m_value, _mm_cmpeq_epi32(_mm_and_si128(m_value, vsign), _mm_setzero_si128())); - vsign = _mm_srai_epi32(vsign, 1); - vsign = _mm_xor_si128(vsign, _mm_set1_epi32(0xffffffff)); - __m128i mask = _mm_cmpgt_epi32(m_value, vsign); - m_value = _mm_or_si128(_mm_and_si128(vsign, mask), _mm_and_si128(m_value, _mm_xor_si128(mask, _mm_set1_epi32(0xffffffff)))); - } - - inline void clamp_to_uint8() - { - m_value = _mm_packs_epi32(m_value, _mm_setzero_si128()); - m_value = _mm_packus_epi16(m_value, _mm_setzero_si128()); - m_value = _mm_unpacklo_epi8(m_value, _mm_setzero_si128()); - m_value = _mm_unpacklo_epi16(m_value, _mm_setzero_si128()); - } - - inline void sign_extend(const u32 compare, const u32 sign) - { - __m128i compare_vec = _mm_set1_epi32(compare); - __m128i compare_mask = _mm_cmpeq_epi32(_mm_and_si128(m_value, compare_vec), compare_vec); - __m128i compared = _mm_and_si128(_mm_set1_epi32(sign), compare_mask); - m_value = _mm_or_si128(m_value, compared); - } - - inline void min(const s32 value) - { - __m128i val = _mm_set1_epi32(value); -#ifdef __SSE4_1__ - m_value = _mm_min_epi32(m_value, val); -#else - __m128i is_greater_than = _mm_cmpgt_epi32(m_value, val); - - __m128i val_to_set = _mm_and_si128(val, is_greater_than); - __m128i keep_mask = _mm_xor_si128(is_greater_than, _mm_set1_epi32(0xffffffff)); - - m_value = _mm_and_si128(m_value, keep_mask); - m_value = _mm_or_si128(val_to_set, m_value); -#endif - } - - inline void max(const s32 value) - { - __m128i val = _mm_set1_epi32(value); -#ifdef __SSE4_1__ - m_value = _mm_max_epi32(m_value, val); -#else - __m128i is_less_than = _mm_cmplt_epi32(m_value, val); - - __m128i val_to_set = _mm_and_si128(val, is_less_than); - __m128i keep_mask = _mm_xor_si128(is_less_than, _mm_set1_epi32(0xffffffff)); - - m_value = _mm_and_si128(m_value, keep_mask); - m_value = _mm_or_si128(val_to_set, m_value); -#endif - } - - void blend(const rgbaint_t& other, u8 factor); - - void scale_and_clamp(const rgbaint_t& scale); - - // Leave this here in case Model3 blows up... - //inline void scale_imm_and_clamp(const s32 scale) - //{ - // mul_imm(scale); - // sra_imm(8); - // clamp_to_uint8(); - //} - - // This version needs absolute value of value and scale to be 11 bits or less - inline void scale_imm_and_clamp(const s16 scale) - { - // Set mult a 16 bit inputs to scale - __m128i immv = _mm_set1_epi16(scale); - // Shift up by 4 - immv = _mm_slli_epi16(immv, 4); - // Pack color into mult b 16 bit inputs - m_value = _mm_packs_epi32(m_value, _mm_setzero_si128()); - // Shift up by 4 - m_value = _mm_slli_epi16(m_value, 4); - // Do the 16 bit multiply, bottom 64 bits will contain 16 bit truncated results - m_value = _mm_mulhi_epi16(m_value, immv); - // Clamp to u8 - m_value = _mm_packus_epi16(m_value, _mm_setzero_si128()); - // Unpack up to s32 - m_value = _mm_unpacklo_epi8(m_value, _mm_setzero_si128()); - m_value = _mm_unpacklo_epi16(m_value, _mm_setzero_si128()); - } - - // This function needs absolute value of color and scale to be 15 bits or less - inline void scale_add_and_clamp(const rgbaint_t& scale, const rgbaint_t& other) - { -#ifdef __SSE4_1__ - m_value = _mm_mullo_epi32(m_value, scale.m_value); -#else - // Mask off the top 16 bits of each 32-bit value - m_value = _mm_and_si128(m_value, _mm_set1_epi32(0x0000ffff)); - // Do 16x16 multiplies and sum into 32-bit pairs; the AND above ensures upper pair is always 0 - m_value = _mm_madd_epi16(m_value, scale.m_value); -#endif - // Arithmetic shift down the result by 8 bits - sra_imm(8); - add(other); - clamp_to_uint8(); - } - - // This function needs absolute value of color and scale to be 15 bits or less - inline void scale2_add_and_clamp(const rgbaint_t& scale, const rgbaint_t& other, const rgbaint_t& scale2) - { - // Pack 32-bit values to 16-bit values in low half, and scales in top half - __m128i tmp1 = _mm_packs_epi32(m_value, scale.m_value); - // Same for other and scale2 - __m128i tmp2 = _mm_packs_epi32(other.m_value, scale2.m_value); - // Interleave the low halves (m_value, other) - __m128i tmp3 = _mm_unpacklo_epi16(tmp1, tmp2); - // Interleave the top halves (scale, scale2) - __m128i tmp4 = _mm_unpackhi_epi16(tmp1, tmp2); - // Multiply values by scales and add adjacent pairs - m_value = _mm_madd_epi16(tmp3, tmp4); - // Final shift by 8 - sra_imm(8); - clamp_to_uint8(); - } - - void cmpeq(const rgbaint_t& value) { m_value = _mm_cmpeq_epi32(m_value, value.m_value); } - void cmpgt(const rgbaint_t& value) { m_value = _mm_cmpgt_epi32(m_value, value.m_value); } - void cmplt(const rgbaint_t& value) { m_value = _mm_cmplt_epi32(m_value, value.m_value); } - - void cmpeq_imm(s32 value) { m_value = _mm_cmpeq_epi32(m_value, _mm_set1_epi32(value)); } - void cmpgt_imm(s32 value) { m_value = _mm_cmpgt_epi32(m_value, _mm_set1_epi32(value)); } - void cmplt_imm(s32 value) { m_value = _mm_cmplt_epi32(m_value, _mm_set1_epi32(value)); } - - void cmpeq_imm_rgba(s32 a, s32 r, s32 g, s32 b) { m_value = _mm_cmpeq_epi32(m_value, _mm_set_epi32(a, r, g, b)); } - void cmpgt_imm_rgba(s32 a, s32 r, s32 g, s32 b) { m_value = _mm_cmpgt_epi32(m_value, _mm_set_epi32(a, r, g, b)); } - void cmplt_imm_rgba(s32 a, s32 r, s32 g, s32 b) { m_value = _mm_cmplt_epi32(m_value, _mm_set_epi32(a, r, g, b)); } - - inline rgbaint_t& operator+=(const rgbaint_t& other) - { - m_value = _mm_add_epi32(m_value, other.m_value); - return *this; - } - - inline rgbaint_t& operator+=(const s32 other) - { - m_value = _mm_add_epi32(m_value, _mm_set1_epi32(other)); - return *this; - } - - inline rgbaint_t& operator-=(const rgbaint_t& other) - { - m_value = _mm_sub_epi32(m_value, other.m_value); - return *this; - } - - inline rgbaint_t& operator*=(const rgbaint_t& other) - { - m_value = _mm_unpacklo_epi32(_mm_shuffle_epi32(_mm_mul_epu32(m_value, other.m_value), _MM_SHUFFLE(0, 0, 2, 0)), _mm_shuffle_epi32(_mm_mul_epu32(_mm_srli_si128(m_value, 4), _mm_srli_si128(other.m_value, 4)), _MM_SHUFFLE(0, 0, 2, 0))); - return *this; - } - - inline rgbaint_t& operator*=(const s32 other) - { - const __m128i immv = _mm_set1_epi32(other); - m_value = _mm_unpacklo_epi32(_mm_shuffle_epi32(_mm_mul_epu32(m_value, immv), _MM_SHUFFLE(0, 0, 2, 0)), _mm_shuffle_epi32(_mm_mul_epu32(_mm_srli_si128(m_value, 4), _mm_srli_si128(immv, 4)), _MM_SHUFFLE(0, 0, 2, 0))); - return *this; - } - - inline rgbaint_t& operator>>=(const s32 shift) - { - m_value = _mm_srai_epi32(m_value, shift); - return *this; - } - - inline void merge_alpha16(const rgbaint_t& alpha) - { - m_value = _mm_insert_epi16(m_value, _mm_extract_epi16(alpha.m_value, 6), 6); - } - - inline void merge_alpha(const rgbaint_t& alpha) - { -#ifdef __SSE4_1__ - m_value = _mm_insert_epi32(m_value, _mm_extract_epi32(alpha.m_value, 3), 3); -#else - m_value = _mm_insert_epi16(m_value, _mm_extract_epi16(alpha.m_value, 7), 7); - m_value = _mm_insert_epi16(m_value, _mm_extract_epi16(alpha.m_value, 6), 6); -#endif - } - - static u32 bilinear_filter(u32 rgb00, u32 rgb01, u32 rgb10, u32 rgb11, u8 u, u8 v) - { - __m128i color00 = _mm_cvtsi32_si128(rgb00); - __m128i color01 = _mm_cvtsi32_si128(rgb01); - __m128i color10 = _mm_cvtsi32_si128(rgb10); - __m128i color11 = _mm_cvtsi32_si128(rgb11); - - /* interleave color01 and color00 at the byte level */ - color01 = _mm_unpacklo_epi8(color01, color00); - color11 = _mm_unpacklo_epi8(color11, color10); - color01 = _mm_unpacklo_epi8(color01, _mm_setzero_si128()); - color11 = _mm_unpacklo_epi8(color11, _mm_setzero_si128()); - color01 = _mm_madd_epi16(color01, scale_factor(u)); - color11 = _mm_madd_epi16(color11, scale_factor(u)); - color01 = _mm_slli_epi32(color01, 15); - color11 = _mm_srli_epi32(color11, 1); - color01 = _mm_max_epi16(color01, color11); - color01 = _mm_madd_epi16(color01, scale_factor(v)); - color01 = _mm_srli_epi32(color01, 15); - color01 = _mm_packs_epi32(color01, _mm_setzero_si128()); - color01 = _mm_packus_epi16(color01, _mm_setzero_si128()); - return _mm_cvtsi128_si32(color01); - } - - void bilinear_filter_rgbaint(u32 rgb00, u32 rgb01, u32 rgb10, u32 rgb11, u8 u, u8 v) - { - __m128i color00 = _mm_cvtsi32_si128(rgb00); - __m128i color01 = _mm_cvtsi32_si128(rgb01); - __m128i color10 = _mm_cvtsi32_si128(rgb10); - __m128i color11 = _mm_cvtsi32_si128(rgb11); - - /* interleave color01 and color00 at the byte level */ - color01 = _mm_unpacklo_epi8(color01, color00); - color11 = _mm_unpacklo_epi8(color11, color10); - color01 = _mm_unpacklo_epi8(color01, _mm_setzero_si128()); - color11 = _mm_unpacklo_epi8(color11, _mm_setzero_si128()); - color01 = _mm_madd_epi16(color01, scale_factor(u)); - color11 = _mm_madd_epi16(color11, scale_factor(u)); - color01 = _mm_slli_epi32(color01, 15); - color11 = _mm_srli_epi32(color11, 1); - color01 = _mm_max_epi16(color01, color11); - color01 = _mm_madd_epi16(color01, scale_factor(v)); - m_value = _mm_srli_epi32(color01, 15); - } - -protected: - struct _statics - { - __m128 dummy_for_alignment; - u16 alpha_mask[8]; - u16 red_mask[8]; - u16 green_mask[8]; - u16 blue_mask[8]; - s16 scale_table[256][8]; - }; - - static __m128i alpha_mask() { return *(__m128i *)&statics.alpha_mask[0]; } - static __m128i red_mask() { return *(__m128i *)&statics.red_mask[0]; } - static __m128i green_mask() { return *(__m128i *)&statics.green_mask[0]; } - static __m128i blue_mask() { return *(__m128i *)&statics.blue_mask[0]; } - static __m128i scale_factor(u8 index) { return *(__m128i *)&statics.scale_table[index][0]; } - - __m128i m_value; - - static const _statics statics; - -}; - -#endif /* MAME_EMU_VIDEO_RGBSSE_H */ diff --git a/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbutil.h b/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbutil.h deleted file mode 100644 index c6ee325c75..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbutil.h +++ /dev/null @@ -1,32 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - rgbutil.h - - Utility definitions for RGB manipulation. Allows RGB handling to be - performed in an abstracted fashion and optimized with SIMD. - -***************************************************************************/ - -#ifndef MAME_EMU_VIDEO_RGBUTIL_H -#define MAME_EMU_VIDEO_RGBUTIL_H - -// use SSE on 64-bit implementations, where it can be assumed -#if (!defined(MAME_DEBUG) || defined(__OPTIMIZE__)) && (defined(__SSE2__) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP >= 2))) - -#define MAME_RGB_HIGH_PRECISION -#include "rgbsse.h" - -#elif defined(__ALTIVEC__) - -#define MAME_RGB_HIGH_PRECISION -#include "rgbvmx.h" - -#else - -#include "rgbgen.h" - -#endif - -#endif // MAME_EMU_VIDEO_RGBUTIL_H diff --git a/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbvmx.h b/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbvmx.h deleted file mode 100644 index 05d26cd9e2..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/emu/video/rgbvmx.h +++ /dev/null @@ -1,728 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb, Ryan Holtz -/*************************************************************************** - - rgbvmx.h - - VMX/Altivec optimised RGB utilities. - -***************************************************************************/ - -#ifndef MAME_EMU_VIDEO_RGBVMX_H -#define MAME_EMU_VIDEO_RGBVMX_H - -#pragma once - -#include - -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -class rgbaint_t -{ -protected: - typedef __vector signed char VECS8; - typedef __vector unsigned char VECU8; - typedef __vector signed short VECS16; - typedef __vector unsigned short VECU16; - typedef __vector signed int VECS32; - typedef __vector unsigned int VECU32; - -public: - rgbaint_t() { set(0, 0, 0, 0); } - explicit rgbaint_t(u32 rgba) { set(rgba); } - rgbaint_t(s32 a, s32 r, s32 g, s32 b) { set(a, r, g, b); } - explicit rgbaint_t(const rgb_t& rgb) { set(rgb); } - explicit rgbaint_t(VECS32 rgba) : m_value(rgba) { } - - rgbaint_t(const rgbaint_t& other) = default; - rgbaint_t &operator=(const rgbaint_t& other) = default; - - void set(const rgbaint_t& other) { m_value = other.m_value; } - - void set(u32 rgba) - { - const VECU32 zero = { 0, 0, 0, 0 }; -#ifdef __LITTLE_ENDIAN__ - const VECS8 temp = *reinterpret_cast(&rgba); - m_value = VECS32(vec_mergeh(VECS16(vec_mergeh(temp, VECS8(zero))), VECS16(zero))); -#else - const VECS8 temp = VECS8(vec_perm(vec_lde(0, &rgba), zero, vec_lvsl(0, &rgba))); - m_value = VECS32(vec_mergeh(VECS16(zero), VECS16(vec_mergeh(VECS8(zero), temp)))); -#endif - } - - void set(s32 a, s32 r, s32 g, s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 result = { b, g, r, a }; -#else - const VECS32 result = { a, r, g, b }; -#endif - m_value = result; - } - - void set(const rgb_t& rgb) - { - const VECU32 zero = { 0, 0, 0, 0 }; -#ifdef __LITTLE_ENDIAN__ - const VECS8 temp = *reinterpret_cast(rgb.ptr()); - m_value = VECS32(vec_mergeh(VECS16(vec_mergeh(temp, VECS8(zero))), VECS16(zero))); -#else - const VECS8 temp = VECS8(vec_perm(vec_lde(0, rgb.ptr()), zero, vec_lvsl(0, rgb.ptr()))); - m_value = VECS32(vec_mergeh(VECS16(zero), VECS16(vec_mergeh(VECS8(zero), temp)))); -#endif - } - - // This function sets all elements to the same val - void set_all(const s32& val) { set(val, val, val, val); } - // This function zeros all elements - void zero() { set_all(0); } - // This function zeros only the alpha element - void zero_alpha() { set_a(0); } - - inline rgb_t to_rgba() const - { - VECU32 temp = VECU32(vec_packs(m_value, m_value)); - temp = VECU32(vec_packsu(VECS16(temp), VECS16(temp))); - u32 result; - vec_ste(temp, 0, &result); - return result; - } - - inline rgb_t to_rgba_clamp() const - { - VECU32 temp = VECU32(vec_packs(m_value, m_value)); - temp = VECU32(vec_packsu(VECS16(temp), VECS16(temp))); - u32 result; - vec_ste(temp, 0, &result); - return result; - } - - void set_a16(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_perm(m_value, temp, alpha_perm); - } - - void set_a(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_perm(m_value, temp, alpha_perm); - } - - void set_r(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_perm(m_value, temp, red_perm); - } - - void set_g(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_perm(m_value, temp, green_perm); - } - - void set_b(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_perm(m_value, temp, blue_perm); - } - - u8 get_a() const - { - u8 result; -#ifdef __LITTLE_ENDIAN__ - vec_ste(vec_splat(VECU8(m_value), 12), 0, &result); -#else - vec_ste(vec_splat(VECU8(m_value), 3), 0, &result); -#endif - return result; - } - - u8 get_r() const - { - u8 result; -#ifdef __LITTLE_ENDIAN__ - vec_ste(vec_splat(VECU8(m_value), 8), 0, &result); -#else - vec_ste(vec_splat(VECU8(m_value), 7), 0, &result); -#endif - return result; - } - - u8 get_g() const - { - u8 result; -#ifdef __LITTLE_ENDIAN__ - vec_ste(vec_splat(VECU8(m_value), 4), 0, &result); -#else - vec_ste(vec_splat(VECU8(m_value), 11), 0, &result); -#endif - return result; - } - - u8 get_b() const - { - u8 result; -#ifdef __LITTLE_ENDIAN__ - vec_ste(vec_splat(VECU8(m_value), 0), 0, &result); -#else - vec_ste(vec_splat(VECU8(m_value), 15), 0, &result); -#endif - return result; - } - - s32 get_a32() const - { - s32 result; -#ifdef __LITTLE_ENDIAN__ - vec_ste(vec_splat(m_value, 3), 0, &result); -#else - vec_ste(vec_splat(m_value, 0), 0, &result); -#endif - return result; - } - - s32 get_r32() const - { - s32 result; -#ifdef __LITTLE_ENDIAN__ - vec_ste(vec_splat(m_value, 2), 0, &result); -#else - vec_ste(vec_splat(m_value, 1), 0, &result); -#endif - return result; - } - - s32 get_g32() const - { - s32 result; -#ifdef __LITTLE_ENDIAN__ - vec_ste(vec_splat(m_value, 1), 0, &result); -#else - vec_ste(vec_splat(m_value, 2), 0, &result); -#endif - return result; - } - - s32 get_b32() const - { - s32 result; -#ifdef __LITTLE_ENDIAN__ - vec_ste(vec_splat(m_value, 0), 0, &result); -#else - vec_ste(vec_splat(m_value, 3), 0, &result); -#endif - return result; - } - - // These selects return an rgbaint_t with all fields set to the element choosen (a, r, g, or b) - rgbaint_t select_alpha32() const { return rgbaint_t(get_a32(), get_a32(), get_a32(), get_a32()); } - rgbaint_t select_red32() const { return rgbaint_t(get_r32(), get_r32(), get_r32(), get_r32()); } - rgbaint_t select_green32() const { return rgbaint_t(get_g32(), get_g32(), get_g32(), get_g32()); } - rgbaint_t select_blue32() const { return rgbaint_t(get_b32(), get_b32(), get_b32(), get_b32()); } - - inline void add(const rgbaint_t& color2) - { - m_value = vec_add(m_value, color2.m_value); - } - - inline void add_imm(const s32 imm) - { - const VECS32 temp = { imm, imm, imm, imm }; - m_value = vec_add(m_value, temp); - } - - inline void add_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 temp = { b, g, r, a }; -#else - const VECS32 temp = { a, r, g, b }; -#endif - m_value = vec_add(m_value, temp); - } - - inline void sub(const rgbaint_t& color2) - { - m_value = vec_sub(m_value, color2.m_value); - } - - inline void sub_imm(const s32 imm) - { - const VECS32 temp = { imm, imm, imm, imm }; - m_value = vec_sub(m_value, temp); - } - - inline void sub_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 temp = { b, g, r, a }; -#else - const VECS32 temp = { a, r, g, b }; -#endif - m_value = vec_sub(m_value, temp); - } - - inline void subr(const rgbaint_t& color2) - { - m_value = vec_sub(color2.m_value, m_value); - } - - inline void subr_imm(const s32 imm) - { - const VECS32 temp = { imm, imm, imm, imm }; - m_value = vec_sub(temp, m_value); - } - - inline void subr_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 temp = { b, g, r, a }; -#else - const VECS32 temp = { a, r, g, b }; -#endif - m_value = vec_sub(temp, m_value); - } - - inline void mul(const rgbaint_t& color) - { - const VECU32 shift = vec_splat_u32(-16); - const VECU32 temp = vec_msum(VECU16(m_value), VECU16(vec_rl(color.m_value, shift)), vec_splat_u32(0)); -#ifdef __LITTLE_ENDIAN__ - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mule(VECU16(m_value), VECU16(color.m_value)))); -#else - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mulo(VECU16(m_value), VECU16(color.m_value)))); -#endif - } - - inline void mul_imm(const s32 imm) - { - const VECU32 value = { u32(imm), u32(imm), u32(imm), u32(imm) }; - const VECU32 shift = vec_splat_u32(-16); - const VECU32 temp = vec_msum(VECU16(m_value), VECU16(vec_rl(value, shift)), vec_splat_u32(0)); -#ifdef __LITTLE_ENDIAN__ - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mule(VECU16(m_value), VECU16(value)))); -#else - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mulo(VECU16(m_value), VECU16(value)))); -#endif - } - - inline void mul_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECU32 value = { u32(b), u32(g), u32(r), u32(a) }; -#else - const VECU32 value = { u32(a), u32(r), u32(g), u32(b) }; -#endif - const VECU32 shift = vec_splat_u32(-16); - const VECU32 temp = vec_msum(VECU16(m_value), VECU16(vec_rl(value, shift)), vec_splat_u32(0)); -#ifdef __LITTLE_ENDIAN__ - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mule(VECU16(m_value), VECU16(value)))); -#else - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mulo(VECU16(m_value), VECU16(value)))); -#endif - } - - inline void shl(const rgbaint_t& shift) - { - const VECU32 limit = { 32, 32, 32, 32 }; - m_value = vec_and(vec_sl(m_value, VECU32(shift.m_value)), vec_cmpgt(limit, VECU32(shift.m_value))); - } - - inline void shl_imm(const u8 shift) - { - const VECU32 temp = { shift, shift, shift, shift }; - m_value = vec_sl(m_value, temp); - } - - inline void shr(const rgbaint_t& shift) - { - const VECU32 limit = { 32, 32, 32, 32 }; - m_value = vec_and(vec_sr(m_value, VECU32(shift.m_value)), vec_cmpgt(limit, VECU32(shift.m_value))); - } - - inline void shr_imm(const u8 shift) - { - const VECU32 temp = { shift, shift, shift, shift }; - m_value = vec_sr(m_value, temp); - } - - inline void sra(const rgbaint_t& shift) - { - const VECU32 limit = { 31, 31, 31, 31 }; - m_value = vec_sra(m_value, vec_min(VECU32(shift.m_value), limit)); - } - - inline void sra_imm(const u8 shift) - { - const VECU32 temp = { shift, shift, shift, shift }; - m_value = vec_sra(m_value, temp); - } - - inline void or_reg(const rgbaint_t& color2) - { - m_value = vec_or(m_value, color2.m_value); - } - - inline void or_imm(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_or(m_value, temp); - } - - inline void or_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 temp = { b, g, r, a }; -#else - const VECS32 temp = { a, r, g, b }; -#endif - m_value = vec_or(m_value, temp); - } - - inline void and_reg(const rgbaint_t& color) - { - m_value = vec_and(m_value, color.m_value); - } - - inline void andnot_reg(const rgbaint_t& color) - { - m_value = vec_andc(m_value, color.m_value); - } - - inline void and_imm(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_and(m_value, temp); - } - - inline void and_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 temp = { b, g, r, a }; -#else - const VECS32 temp = { a, r, g, b }; -#endif - m_value = vec_and(m_value, temp); - } - - inline void xor_reg(const rgbaint_t& color2) - { - m_value = vec_xor(m_value, color2.m_value); - } - - inline void xor_imm(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_xor(m_value, temp); - } - - inline void xor_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 temp = { b, g, r, a }; -#else - const VECS32 temp = { a, r, g, b }; -#endif - m_value = vec_xor(m_value, temp); - } - - inline void clamp_and_clear(const u32 sign) - { - const VECS32 vzero = { 0, 0, 0, 0 }; - VECS32 vsign = { s32(sign), s32(sign), s32(sign), s32(sign) }; - m_value = vec_and(m_value, vec_cmpeq(vec_and(m_value, vsign), vzero)); - vsign = vec_nor(vec_sra(vsign, vec_splat_u32(1)), vzero); - const VECS32 mask = VECS32(vec_cmpgt(m_value, vsign)); - m_value = vec_or(vec_and(vsign, mask), vec_and(m_value, vec_nor(mask, vzero))); - } - - inline void clamp_to_uint8() - { - const VECU32 zero = { 0, 0, 0, 0 }; - m_value = VECS32(vec_packs(m_value, m_value)); - m_value = VECS32(vec_packsu(VECS16(m_value), VECS16(m_value))); -#ifdef __LITTLE_ENDIAN__ - m_value = VECS32(vec_mergeh(VECU8(m_value), VECU8(zero))); - m_value = VECS32(vec_mergeh(VECS16(m_value), VECS16(zero))); -#else - m_value = VECS32(vec_mergeh(VECU8(zero), VECU8(m_value))); - m_value = VECS32(vec_mergeh(VECS16(zero), VECS16(m_value))); -#endif - } - - inline void sign_extend(const u32 compare, const u32 sign) - { - const VECS32 compare_vec = { s32(compare), s32(compare), s32(compare), s32(compare) }; - const VECS32 compare_mask = VECS32(vec_cmpeq(vec_and(m_value, compare_vec), compare_vec)); - const VECS32 sign_vec = { s32(sign), s32(sign), s32(sign), s32(sign) }; - m_value = vec_or(m_value, vec_and(sign_vec, compare_mask)); - } - - inline void min(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_min(m_value, temp); - } - - inline void max(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = vec_max(m_value, temp); - } - - void blend(const rgbaint_t& other, u8 factor); - - void scale_and_clamp(const rgbaint_t& scale); - void scale_imm_and_clamp(const s32 scale); - - void scale_add_and_clamp(const rgbaint_t& scale, const rgbaint_t& other) - { - mul(scale); - sra_imm(8); - add(other); - clamp_to_uint8(); - } - - void scale2_add_and_clamp(const rgbaint_t& scale, const rgbaint_t& other, const rgbaint_t& scale2) - { - rgbaint_t color2(other); - color2.mul(scale2); - - mul(scale); - add(color2); - sra_imm(8); - clamp_to_uint8(); - } - - inline void cmpeq(const rgbaint_t& value) - { - m_value = VECS32(vec_cmpeq(m_value, value.m_value)); - } - - inline void cmpeq_imm(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = VECS32(vec_cmpeq(m_value, temp)); - } - - inline void cmpeq_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 temp = { b, g, r, a }; -#else - const VECS32 temp = { a, r, g, b }; -#endif - m_value = VECS32(vec_cmpeq(m_value, temp)); - } - - inline void cmpgt(const rgbaint_t& value) - { - m_value = VECS32(vec_cmpgt(m_value, value.m_value)); - } - - inline void cmpgt_imm(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = VECS32(vec_cmpgt(m_value, temp)); - } - - inline void cmpgt_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 temp = { b, g, r, a }; -#else - const VECS32 temp = { a, r, g, b }; -#endif - m_value = VECS32(vec_cmpgt(m_value, temp)); - } - - inline void cmplt(const rgbaint_t& value) - { - m_value = VECS32(vec_cmplt(m_value, value.m_value)); - } - - inline void cmplt_imm(const s32 value) - { - const VECS32 temp = { value, value, value, value }; - m_value = VECS32(vec_cmplt(m_value, temp)); - } - - inline void cmplt_imm_rgba(const s32 a, const s32 r, const s32 g, const s32 b) - { -#ifdef __LITTLE_ENDIAN__ - const VECS32 temp = { b, g, r, a }; -#else - const VECS32 temp = { a, r, g, b }; -#endif - m_value = VECS32(vec_cmplt(m_value, temp)); - } - - inline rgbaint_t& operator+=(const rgbaint_t& other) - { - m_value = vec_add(m_value, other.m_value); - return *this; - } - - inline rgbaint_t& operator+=(const s32 other) - { - const VECS32 temp = { other, other, other, other }; - m_value = vec_add(m_value, temp); - return *this; - } - - inline rgbaint_t& operator-=(const rgbaint_t& other) - { - m_value = vec_sub(m_value, other.m_value); - return *this; - } - - inline rgbaint_t& operator*=(const rgbaint_t& other) - { - const VECU32 shift = vec_splat_u32(-16); - const VECU32 temp = vec_msum(VECU16(m_value), VECU16(vec_rl(other.m_value, shift)), vec_splat_u32(0)); -#ifdef __LITTLE_ENDIAN__ - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mule(VECU16(m_value), VECU16(other.m_value)))); -#else - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mulo(VECU16(m_value), VECU16(other.m_value)))); -#endif - return *this; - } - - inline rgbaint_t& operator*=(const s32 other) - { - const VECS32 value = { other, other, other, other }; - const VECU32 shift = vec_splat_u32(-16); - const VECU32 temp = vec_msum(VECU16(m_value), VECU16(vec_rl(value, shift)), vec_splat_u32(0)); -#ifdef __LITTLE_ENDIAN__ - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mule(VECU16(m_value), VECU16(value)))); -#else - m_value = VECS32(vec_add(vec_sl(temp, shift), vec_mulo(VECU16(m_value), VECU16(value)))); -#endif - return *this; - } - - inline rgbaint_t& operator>>=(const s32 shift) - { - const VECU32 temp = { u32(shift), u32(shift), u32(shift), u32(shift) }; - m_value = vec_sra(m_value, temp); - return *this; - } - - inline void merge_alpha16(const rgbaint_t& alpha) - { - m_value = vec_perm(m_value, alpha.m_value, alpha_perm); - } - - inline void merge_alpha(const rgbaint_t& alpha) - { - m_value = vec_perm(m_value, alpha.m_value, alpha_perm); - } - - static u32 bilinear_filter(const u32 &rgb00, const u32 &rgb01, const u32 &rgb10, const u32 &rgb11, u8 u, u8 v) - { - const VECS32 zero = vec_splat_s32(0); - - // put each packed value into first element of a vector register -#ifdef __LITTLE_ENDIAN__ - VECS32 color00 = *reinterpret_cast(&rgb00); - VECS32 color01 = *reinterpret_cast(&rgb01); - VECS32 color10 = *reinterpret_cast(&rgb10); - VECS32 color11 = *reinterpret_cast(&rgb11); -#else - VECS32 color00 = vec_perm(VECS32(vec_lde(0, &rgb00)), zero, vec_lvsl(0, &rgb00)); - VECS32 color01 = vec_perm(VECS32(vec_lde(0, &rgb01)), zero, vec_lvsl(0, &rgb01)); - VECS32 color10 = vec_perm(VECS32(vec_lde(0, &rgb10)), zero, vec_lvsl(0, &rgb10)); - VECS32 color11 = vec_perm(VECS32(vec_lde(0, &rgb11)), zero, vec_lvsl(0, &rgb11)); -#endif - - // interleave color01/color00 and color10/color11 at the byte level then zero-extend - color01 = VECS32(vec_mergeh(VECU8(color01), VECU8(color00))); - color11 = VECS32(vec_mergeh(VECU8(color11), VECU8(color10))); -#ifdef __LITTLE_ENDIAN__ - color01 = VECS32(vec_mergeh(VECU8(color01), VECU8(zero))); - color11 = VECS32(vec_mergeh(VECU8(color11), VECU8(zero))); -#else - color01 = VECS32(vec_mergeh(VECU8(zero), VECU8(color01))); - color11 = VECS32(vec_mergeh(VECU8(zero), VECU8(color11))); -#endif - - color01 = vec_msum(VECS16(color01), scale_table[u], zero); - color11 = vec_msum(VECS16(color11), scale_table[u], zero); - color01 = vec_sl(color01, vec_splat_u32(15)); - color11 = vec_sr(color11, vec_splat_u32(1)); - color01 = VECS32(vec_max(VECS16(color01), VECS16(color11))); - color01 = vec_msum(VECS16(color01), scale_table[v], zero); - color01 = vec_sr(color01, vec_splat_u32(15)); - color01 = VECS32(vec_packs(color01, color01)); - color01 = VECS32(vec_packsu(VECS16(color01), VECS16(color01))); - - u32 result; - vec_ste(VECU32(color01), 0, &result); - return result; - } - - void bilinear_filter_rgbaint(const u32 &rgb00, const u32 &rgb01, const u32 &rgb10, const u32 &rgb11, u8 u, u8 v) - { - const VECS32 zero = vec_splat_s32(0); - - // put each packed value into first element of a vector register -#ifdef __LITTLE_ENDIAN__ - VECS32 color00 = *reinterpret_cast(&rgb00); - VECS32 color01 = *reinterpret_cast(&rgb01); - VECS32 color10 = *reinterpret_cast(&rgb10); - VECS32 color11 = *reinterpret_cast(&rgb11); -#else - VECS32 color00 = vec_perm(VECS32(vec_lde(0, &rgb00)), zero, vec_lvsl(0, &rgb00)); - VECS32 color01 = vec_perm(VECS32(vec_lde(0, &rgb01)), zero, vec_lvsl(0, &rgb01)); - VECS32 color10 = vec_perm(VECS32(vec_lde(0, &rgb10)), zero, vec_lvsl(0, &rgb10)); - VECS32 color11 = vec_perm(VECS32(vec_lde(0, &rgb11)), zero, vec_lvsl(0, &rgb11)); -#endif - - // interleave color01/color00 and color10/color11 at the byte level then zero-extend - color01 = VECS32(vec_mergeh(VECU8(color01), VECU8(color00))); - color11 = VECS32(vec_mergeh(VECU8(color11), VECU8(color10))); -#ifdef __LITTLE_ENDIAN__ - color01 = VECS32(vec_mergeh(VECU8(color01), VECU8(zero))); - color11 = VECS32(vec_mergeh(VECU8(color11), VECU8(zero))); -#else - color01 = VECS32(vec_mergeh(VECU8(zero), VECU8(color01))); - color11 = VECS32(vec_mergeh(VECU8(zero), VECU8(color11))); -#endif - - color01 = vec_msum(VECS16(color01), scale_table[u], zero); - color11 = vec_msum(VECS16(color11), scale_table[u], zero); - color01 = vec_sl(color01, vec_splat_u32(15)); - color11 = vec_sr(color11, vec_splat_u32(1)); - color01 = VECS32(vec_max(VECS16(color01), VECS16(color11))); - color01 = vec_msum(VECS16(color01), scale_table[v], zero); - m_value = vec_sr(color01, vec_splat_u32(15)); - } - -protected: - VECS32 m_value; - - static const VECU8 alpha_perm; - static const VECU8 red_perm; - static const VECU8 green_perm; - static const VECU8 blue_perm; - static const VECS16 scale_table[256]; -}; - - - -// altivec.h somehow redefines "bool" in a bad way. really. -#ifdef vector -#undef vector -#endif -#ifdef bool -#undef bool -#endif -#ifdef pixel -#undef pixel -#endif - -#endif // MAME_EMU_VIDEO_RGBVMX_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/abi.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/abi.h deleted file mode 100644 index b9e18f1635..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/abi.h +++ /dev/null @@ -1,117 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -/// \file -/// \brief ABI feature macros -/// -/// Macros that are useful for writing ABI-dependent code. -#ifndef MAME_LIB_UTIL_ABI_H -#define MAME_LIB_UTIL_ABI_H - -#pragma once - - -/// \brief Itanium C++ ABI -/// -/// Value of #MAME_ABI_CXX_TYPE when compiled with a variant of the -/// Itanium C++ ABI. -/// \sa MAME_ABI_CXX_TYPE MAME_ABI_CXX_MSVC -#define MAME_ABI_CXX_ITANIUM 0 - -/// \brief Microsoft Visual C++ ABI -/// -/// Value of #MAME_ABI_CXX_TYPE when compiled with a variant of the -/// Microsoft Visual C++ ABI. -/// \sa MAME_ABI_CXX_TYPE MAME_ABI_CXX_ITANIUM -#define MAME_ABI_CXX_MSVC 1 - - -/// \brief Standard Itanium C++ ABI member function pointers -/// -/// Value of #MAME_ABI_CXX_ITANIUM_MFP_TYPE when compiled with a variant -/// of the Itanium C++ ABI using the standard representation of -/// pointers to non-static member functions. -/// \sa MAME_ABI_CXX_ITANIUM_MFP_TYPE MAME_ABI_CXX_ITANIUM_MFP_ARM -#define MAME_ABI_CXX_ITANIUM_MFP_STANDARD 0 - -/// \brief ARM Itanium C++ ABI member function pointers -/// -/// Value of #MAME_ABI_CXX_ITANIUM_MFP_TYPE when compiled with a variant -/// of the Itanium C++ ABI using the 32-bit ARM representation of -/// pointers to non-static member functions. -/// \sa MAME_ABI_CXX_ITANIUM_MFP_TYPE MAME_ABI_CXX_ITANIUM_MFP_STANDARD -#define MAME_ABI_CXX_ITANIUM_MFP_ARM 1 - - -/// \def MAME_ABI_FNDESC_SIZE -/// \brief Size of function descriptors -/// -/// Size of function descriptors as a multiple of the size of a pointer, -/// or zero if function pointers point to the function entry point -/// directly. -#if (defined(__ppc64__) || defined(__PPC64__)) && !defined(__APPLE__) && !defined(__LITTLE_ENDIAN__) - #define MAME_ABI_FNDESC_SIZE 3 // entry point (PC), TOC (R2), environment (R11) -#elif defined(__ia64__) - #define MAME_ABI_FNDESC_SIZE 2 // GP, entry point -#else - #define MAME_ABI_FNDESC_SIZE 0 // function pointers point to entry point directly -#endif - - -/// \def MAME_ABI_CXX_TYPE -/// \brief C++ ABI type -/// -/// A constant representing the C++ ABI. -/// \sa MAME_ABI_CXX_ITANIUM MAME_ABI_CXX_MSVC -#if defined(_MSC_VER) - #define MAME_ABI_CXX_TYPE MAME_ABI_CXX_MSVC -#else - #define MAME_ABI_CXX_TYPE MAME_ABI_CXX_ITANIUM -#endif - - -/// \def MAME_ABI_CXX_MEMBER_CALL -/// \brief Member function calling convention qualifier -/// -/// A qualifier for functions and function pointers that may be used to -/// specify that the calling convention for non-static member functions -/// should be used. -#if defined(__GNUC__) && defined(__MINGW32__) && !defined(__x86_64__) && defined(__i386__) - #define MAME_ABI_CXX_MEMBER_CALL __thiscall -#else - #define MAME_ABI_CXX_MEMBER_CALL -#endif - - -/// \def MAME_ABI_CXX_VTABLE_FNDESC -/// \brief Whether function descriptors are stored in virtual tables -/// -/// Non-zero if function descriptors are stored in virtual tables -/// directly, or zero if function entries in virtual tables are -/// conventional function pointers. -/// \sa MAME_ABI_FNDESC_SIZE -#if defined(__ia64__) - #define MAME_ABI_CXX_VTABLE_FNDESC 1 // function descriptors stored directly in vtable -#else - #define MAME_ABI_CXX_VTABLE_FNDESC 0 // conventional function pointers in vtable -#endif - - -/// \def MAME_ABI_CXX_ITANIUM_MFP_TYPE -/// Itanium C++ member function representation -/// -/// A constant representing the representation of pointers to non-static -/// member functions in use with the Itanium C++ ABI. Only valid if -/// compiled with a variant of the Itanium C++ ABI. -/// \sa MAME_ABI_CXX_ITANIUM_MFP_STANDARD MAME_ABI_CXX_ITANIUM_MFP_ARM -/// MAME_ABI_CXX_TYPE -#if defined(__arm__) || defined(__ARMEL__) || defined(__aarch64__) - #define MAME_ABI_CXX_ITANIUM_MFP_TYPE MAME_ABI_CXX_ITANIUM_MFP_ARM -#elif defined(__MIPSEL__) || defined(__mips_isa_rev) || defined(__mips64) - #define MAME_ABI_CXX_ITANIUM_MFP_TYPE MAME_ABI_CXX_ITANIUM_MFP_ARM -#elif defined(__EMSCRIPTEN__) - #define MAME_ABI_CXX_ITANIUM_MFP_TYPE MAME_ABI_CXX_ITANIUM_MFP_ARM -#else - #define MAME_ABI_CXX_ITANIUM_MFP_TYPE MAME_ABI_CXX_ITANIUM_MFP_STANDARD -#endif - -#endif // MAME_LIB_UTIL_ABI_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/bitmap.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/bitmap.h deleted file mode 100644 index 1b8dee3b5b..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/bitmap.h +++ /dev/null @@ -1,415 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - bitmap.h - - Core bitmap routines. - -***************************************************************************/ - -#ifndef MAME_UTIL_BITMAP_H -#define MAME_UTIL_BITMAP_H - -#pragma once - -#include "palette.h" - -#include -#include - - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// bitmap_format describes the various bitmap formats we use -enum bitmap_format -{ - BITMAP_FORMAT_INVALID = 0, // invalid forma - BITMAP_FORMAT_IND8, // 8bpp indexed - BITMAP_FORMAT_IND16, // 16bpp indexed - BITMAP_FORMAT_IND32, // 32bpp indexed - BITMAP_FORMAT_IND64, // 64bpp indexed - BITMAP_FORMAT_RGB32, // 32bpp 8-8-8 RGB - BITMAP_FORMAT_ARGB32, // 32bpp 8-8-8-8 ARGB - BITMAP_FORMAT_YUY16 // 16bpp 8-8 Y/Cb, Y/Cr in sequence -}; - - -// ======================> rectangle - -// rectangles describe a bitmap portion -class rectangle -{ -public: - // construction/destruction - constexpr rectangle() { } - constexpr rectangle(int32_t minx, int32_t maxx, int32_t miny, int32_t maxy) - : min_x(minx), max_x(maxx), min_y(miny), max_y(maxy) - { } - - // getters - constexpr int32_t left() const { return min_x; } - constexpr int32_t right() const { return max_x; } - constexpr int32_t top() const { return min_y; } - constexpr int32_t bottom() const { return max_y; } - - // compute intersection with another rect - rectangle &operator&=(const rectangle &src) - { - if (src.min_x > min_x) min_x = src.min_x; - if (src.max_x < max_x) max_x = src.max_x; - if (src.min_y > min_y) min_y = src.min_y; - if (src.max_y < max_y) max_y = src.max_y; - return *this; - } - - // compute union with another rect - rectangle &operator|=(const rectangle &src) - { - if (src.min_x < min_x) min_x = src.min_x; - if (src.max_x > max_x) max_x = src.max_x; - if (src.min_y < min_y) min_y = src.min_y; - if (src.max_y > max_y) max_y = src.max_y; - return *this; - } - - rectangle operator&(const rectangle &b) - { - rectangle a(*this); - a &= b; - return a; - } - - rectangle operator|(const rectangle &b) - { - rectangle a(*this); - a |= b; - return a; - } - - // comparisons - constexpr bool operator==(const rectangle &rhs) const { return min_x == rhs.min_x && max_x == rhs.max_x && min_y == rhs.min_y && max_y == rhs.max_y; } - constexpr bool operator!=(const rectangle &rhs) const { return min_x != rhs.min_x || max_x != rhs.max_x || min_y != rhs.min_y || max_y != rhs.max_y; } - constexpr bool operator>(const rectangle &rhs) const { return min_x < rhs.min_x && min_y < rhs.min_y && max_x > rhs.max_x && max_y > rhs.max_y; } - constexpr bool operator>=(const rectangle &rhs) const { return min_x <= rhs.min_x && min_y <= rhs.min_y && max_x >= rhs.max_x && max_y >= rhs.max_y; } - constexpr bool operator<(const rectangle &rhs) const { return min_x >= rhs.min_x || min_y >= rhs.min_y || max_x <= rhs.max_x || max_y <= rhs.max_y; } - constexpr bool operator<=(const rectangle &rhs) const { return min_x > rhs.min_x || min_y > rhs.min_y || max_x < rhs.max_x || max_y < rhs.max_y; } - - // other helpers - constexpr bool empty() const { return (min_x > max_x) || (min_y > max_y); } - constexpr bool contains(int32_t x, int32_t y) const { return (x >= min_x) && (x <= max_x) && (y >= min_y) && (y <= max_y); } - constexpr bool contains(const rectangle &rect) const { return (min_x <= rect.min_x) && (max_x >= rect.max_x) && (min_y <= rect.min_y) && (max_y >= rect.max_y); } - constexpr int32_t width() const { return max_x + 1 - min_x; } - constexpr int32_t height() const { return max_y + 1 - min_y; } - constexpr int32_t xcenter() const { return (min_x + max_x + 1) / 2; } - constexpr int32_t ycenter() const { return (min_y + max_y + 1) / 2; } - - // setters - void set(int32_t minx, int32_t maxx, int32_t miny, int32_t maxy) { min_x = minx; max_x = maxx; min_y = miny; max_y = maxy; } - void setx(int32_t minx, int32_t maxx) { min_x = minx; max_x = maxx; } - void sety(int32_t miny, int32_t maxy) { min_y = miny; max_y = maxy; } - void set_width(int32_t width) { max_x = min_x + width - 1; } - void set_height(int32_t height) { max_y = min_y + height - 1; } - void set_origin(int32_t x, int32_t y) { max_x += x - min_x; max_y += y - min_y; min_x = x; min_y = y; } - void set_size(int32_t width, int32_t height) { set_width(width); set_height(height); } - - // offset helpers - void offset(int32_t xdelta, int32_t ydelta) { min_x += xdelta; max_x += xdelta; min_y += ydelta; max_y += ydelta; } - void offsetx(int32_t delta) { min_x += delta; max_x += delta; } - void offsety(int32_t delta) { min_y += delta; max_y += delta; } - - // internal state - int32_t min_x = 0; // minimum X, or left coordinate - int32_t max_x = 0; // maximum X, or right coordinate (inclusive) - int32_t min_y = 0; // minimum Y, or top coordinate - int32_t max_y = 0; // maximum Y, or bottom coordinate (inclusive) -}; - - -// ======================> bitmap_t - -// bitmaps describe a rectangular array of pixels -class bitmap_t -{ -protected: - // construction/destruction -- subclasses only to ensure type correctness - bitmap_t(const bitmap_t &) = delete; - bitmap_t(bitmap_t &&that); - bitmap_t(bitmap_format format, uint8_t bpp, int width = 0, int height = 0, int xslop = 0, int yslop = 0); - bitmap_t(bitmap_format format, uint8_t bpp, void *base, int width, int height, int rowpixels); - bitmap_t(bitmap_format format, uint8_t bpp, bitmap_t &source, const rectangle &subrect); - virtual ~bitmap_t(); - - // prevent implicit copying - bitmap_t &operator=(const bitmap_t &) = delete; - bitmap_t &operator=(bitmap_t &&that); - -public: - // allocation/deallocation - void reset(); - - // getters - int32_t width() const { return m_width; } - int32_t height() const { return m_height; } - int32_t rowpixels() const { return m_rowpixels; } - int32_t rowbytes() const { return m_rowpixels * m_bpp / 8; } - uint8_t bpp() const { return m_bpp; } - bitmap_format format() const { return m_format; } - bool valid() const { return (m_base != nullptr); } - palette_t *palette() const { return m_palette; } - const rectangle &cliprect() const { return m_cliprect; } - - // allocation/sizing - void allocate(int width, int height, int xslop = 0, int yslop = 0); - void resize(int width, int height, int xslop = 0, int yslop = 0); - - // operations - void set_palette(palette_t *palette); - void fill(uint64_t color) { fill(color, m_cliprect); } - void fill(uint64_t color, const rectangle &bounds); - void plot_box(int32_t x, int32_t y, int32_t width, int32_t height, uint64_t color) - { - fill(color, rectangle(x, x + width - 1, y, y + height - 1)); - } - - // pixel access - void *raw_pixptr(int32_t y, int32_t x = 0) { return reinterpret_cast(m_base) + (y * m_rowpixels + x) * m_bpp / 8; } - void const *raw_pixptr(int32_t y, int32_t x = 0) const { return reinterpret_cast(m_base) + (y * m_rowpixels + x) * m_bpp / 8; } - -protected: - // for use by subclasses only to ensure type correctness - template PixelType &pixt(int32_t y, int32_t x = 0) { return *(reinterpret_cast(m_base) + y * m_rowpixels + x); } - template PixelType const &pixt(int32_t y, int32_t x = 0) const { return *(reinterpret_cast(m_base) + y * m_rowpixels + x); } - void wrap(void *base, int width, int height, int rowpixels); - void wrap(bitmap_t &source, const rectangle &subrect); - -private: - // internal helpers - int32_t compute_rowpixels(int width, int xslop); - void compute_base(int xslop, int yslop); - bool valid_format() const; - - // internal state - std::unique_ptr m_alloc; // pointer to allocated pixel memory - uint32_t m_allocbytes; // size of our allocation - void * m_base; // pointer to pixel (0,0) (adjusted for padding) - int32_t m_rowpixels; // pixels per row (including padding) - int32_t m_width; // width of the bitmap - int32_t m_height; // height of the bitmap - bitmap_format m_format; // format of the bitmap - uint8_t m_bpp; // bits per pixel - palette_t * m_palette; // optional palette - rectangle m_cliprect; // a clipping rectangle covering the full bitmap -}; - - -// ======================> bitmap_specific, bitmap8_t, bitmap16_t, bitmap32_t, bitmap64_t - -template -class bitmap_specific : public bitmap_t -{ - static constexpr int PIXEL_BITS = 8 * sizeof(PixelType); - -protected: - // construction/destruction -- subclasses only - bitmap_specific(bitmap_specific &&) = default; - bitmap_specific(bitmap_format format, int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap_t(format, PIXEL_BITS, width, height, xslop, yslop) { } - bitmap_specific(bitmap_format format, PixelType *base, int width, int height, int rowpixels) : bitmap_t(format, PIXEL_BITS, base, width, height, rowpixels) { } - bitmap_specific(bitmap_format format, bitmap_specific &source, const rectangle &subrect) : bitmap_t(format, PIXEL_BITS, source, subrect) { } - - bitmap_specific &operator=(bitmap_specific &&) = default; - -public: - using pixel_t = PixelType; - - // getters - uint8_t bpp() const { return PIXEL_BITS; } - - // pixel accessors - PixelType &pix(int32_t y, int32_t x = 0) { return pixt(y, x); } - PixelType const &pix(int32_t y, int32_t x = 0) const { return pixt(y, x); } - - // operations - void fill(PixelType color) { fill(color, cliprect()); } - void fill(PixelType color, const rectangle &bounds) - { - // if we have a cliprect, intersect with that - rectangle fill(bounds); - fill &= cliprect(); - if (!fill.empty()) - { - for (int32_t y = fill.top(); y <= fill.bottom(); y++) - std::fill_n(&pix(y, fill.left()), fill.width(), color); - } - } - void plot_box(int32_t x, int32_t y, int32_t width, int32_t height, PixelType color) - { - fill(color, rectangle(x, x + width - 1, y, y + height - 1)); - } -}; - -// 8bpp bitmaps -using bitmap8_t = bitmap_specific; -extern template class bitmap_specific; - -// 16bpp bitmaps -using bitmap16_t = bitmap_specific; -extern template class bitmap_specific; - -// 32bpp bitmaps -using bitmap32_t = bitmap_specific; -extern template class bitmap_specific; - -// 64bpp bitmaps -using bitmap64_t = bitmap_specific; -extern template class bitmap_specific; - - -// ======================> bitmap_ind8, bitmap_ind16, bitmap_ind32, bitmap_ind64 - -// BITMAP_FORMAT_IND8 bitmaps -class bitmap_ind8 : public bitmap8_t -{ - static const bitmap_format k_bitmap_format = BITMAP_FORMAT_IND8; - -public: - // construction/destruction - bitmap_ind8(bitmap_ind8 &&) = default; - bitmap_ind8(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap8_t(k_bitmap_format, width, height, xslop, yslop) { } - bitmap_ind8(uint8_t *base, int width, int height, int rowpixels) : bitmap8_t(k_bitmap_format, base, width, height, rowpixels) { } - bitmap_ind8(bitmap_ind8 &source, const rectangle &subrect) : bitmap8_t(k_bitmap_format, source, subrect) { } - void wrap(uint8_t *base, int width, int height, int rowpixels) { bitmap_t::wrap(base, width, height, rowpixels); } - void wrap(bitmap_ind8 &source, const rectangle &subrect) { bitmap_t::wrap(static_cast(source), subrect); } - - // getters - bitmap_format format() const { return k_bitmap_format; } - - bitmap_ind8 &operator=(bitmap_ind8 &&) = default; -}; - -// BITMAP_FORMAT_IND16 bitmaps -class bitmap_ind16 : public bitmap16_t -{ - static const bitmap_format k_bitmap_format = BITMAP_FORMAT_IND16; - -public: - // construction/destruction - bitmap_ind16(bitmap_ind16 &&) = default; - bitmap_ind16(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap16_t(k_bitmap_format, width, height, xslop, yslop) { } - bitmap_ind16(uint16_t *base, int width, int height, int rowpixels) : bitmap16_t(k_bitmap_format, base, width, height, rowpixels) { } - bitmap_ind16(bitmap_ind16 &source, const rectangle &subrect) : bitmap16_t(k_bitmap_format, source, subrect) { } - void wrap(uint16_t *base, int width, int height, int rowpixels) { bitmap_t::wrap(base, width, height, rowpixels); } - void wrap(bitmap_ind8 &source, const rectangle &subrect) { bitmap_t::wrap(static_cast(source), subrect); } - - // getters - bitmap_format format() const { return k_bitmap_format; } - - bitmap_ind16 &operator=(bitmap_ind16 &&) = default; -}; - -// BITMAP_FORMAT_IND32 bitmaps -class bitmap_ind32 : public bitmap32_t -{ - static const bitmap_format k_bitmap_format = BITMAP_FORMAT_IND32; - -public: - // construction/destruction - bitmap_ind32(bitmap_ind32 &&) = default; - bitmap_ind32(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap32_t(k_bitmap_format, width, height, xslop, yslop) { } - bitmap_ind32(uint32_t *base, int width, int height, int rowpixels) : bitmap32_t(k_bitmap_format, base, width, height, rowpixels) { } - bitmap_ind32(bitmap_ind32 &source, const rectangle &subrect) : bitmap32_t(k_bitmap_format, source, subrect) { } - void wrap(uint32_t *base, int width, int height, int rowpixels) { bitmap_t::wrap(base, width, height, rowpixels); } - void wrap(bitmap_ind8 &source, const rectangle &subrect) { bitmap_t::wrap(static_cast(source), subrect); } - - // getters - bitmap_format format() const { return k_bitmap_format; } - - bitmap_ind32 &operator=(bitmap_ind32 &&) = default; -}; - -// BITMAP_FORMAT_IND64 bitmaps -class bitmap_ind64 : public bitmap64_t -{ - static const bitmap_format k_bitmap_format = BITMAP_FORMAT_IND64; - -public: - // construction/destruction - bitmap_ind64(bitmap_ind64 &&) = default; - bitmap_ind64(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap64_t(k_bitmap_format, width, height, xslop, yslop) { } - bitmap_ind64(uint64_t *base, int width, int height, int rowpixels) : bitmap64_t(k_bitmap_format, base, width, height, rowpixels) { } - bitmap_ind64(bitmap_ind64 &source, const rectangle &subrect) : bitmap64_t(k_bitmap_format, source, subrect) { } - void wrap(uint64_t *base, int width, int height, int rowpixels) { bitmap_t::wrap(base, width, height, rowpixels); } - void wrap(bitmap_ind8 &source, const rectangle &subrect) { bitmap_t::wrap(static_cast(source), subrect); } - - // getters - bitmap_format format() const { return k_bitmap_format; } - - bitmap_ind64 &operator=(bitmap_ind64 &&) = default; -}; - - -// ======================> bitmap_yuy16, bitmap_rgb32, bitmap_argb32 - -// BITMAP_FORMAT_YUY16 bitmaps -class bitmap_yuy16 : public bitmap16_t -{ - static const bitmap_format k_bitmap_format = BITMAP_FORMAT_YUY16; - -public: - // construction/destruction - bitmap_yuy16(bitmap_yuy16 &&) = default; - bitmap_yuy16(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap16_t(k_bitmap_format, width, height, xslop, yslop) { } - bitmap_yuy16(uint16_t *base, int width, int height, int rowpixels) : bitmap16_t(k_bitmap_format, base, width, height, rowpixels) { } - bitmap_yuy16(bitmap_yuy16 &source, const rectangle &subrect) : bitmap16_t(k_bitmap_format, source, subrect) { } - void wrap(uint16_t *base, int width, int height, int rowpixels) { bitmap_t::wrap(base, width, height, rowpixels); } - void wrap(bitmap_yuy16 &source, const rectangle &subrect) { bitmap_t::wrap(static_cast(source), subrect); } - - // getters - bitmap_format format() const { return k_bitmap_format; } - - bitmap_yuy16 &operator=(bitmap_yuy16 &&) = default; -}; - -// BITMAP_FORMAT_RGB32 bitmaps -class bitmap_rgb32 : public bitmap32_t -{ - static const bitmap_format k_bitmap_format = BITMAP_FORMAT_RGB32; - -public: - // construction/destruction - bitmap_rgb32(bitmap_rgb32 &&) = default; - bitmap_rgb32(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap32_t(k_bitmap_format, width, height, xslop, yslop) { } - bitmap_rgb32(uint32_t *base, int width, int height, int rowpixels) : bitmap32_t(k_bitmap_format, base, width, height, rowpixels) { } - bitmap_rgb32(bitmap_rgb32 &source, const rectangle &subrect) : bitmap32_t(k_bitmap_format, source, subrect) { } - void wrap(uint32_t *base, int width, int height, int rowpixels) { bitmap_t::wrap(base, width, height, rowpixels); } - void wrap(bitmap_rgb32 &source, const rectangle &subrect) { bitmap_t::wrap(static_cast(source), subrect); } - - // getters - bitmap_format format() const { return k_bitmap_format; } - - bitmap_rgb32 &operator=(bitmap_rgb32 &&) = default; -}; - -// BITMAP_FORMAT_ARGB32 bitmaps -class bitmap_argb32 : public bitmap32_t -{ - static const bitmap_format k_bitmap_format = BITMAP_FORMAT_ARGB32; - -public: - // construction/destruction - bitmap_argb32(bitmap_argb32 &&) = default; - bitmap_argb32(int width = 0, int height = 0, int xslop = 0, int yslop = 0) : bitmap32_t(k_bitmap_format, width, height, xslop, yslop) { } - bitmap_argb32(uint32_t *base, int width, int height, int rowpixels) : bitmap32_t(k_bitmap_format, base, width, height, rowpixels) { } - bitmap_argb32(bitmap_argb32 &source, const rectangle &subrect) : bitmap32_t(k_bitmap_format, source, subrect) { } - void wrap(uint32_t *base, int width, int height, int rowpixels) { bitmap_t::wrap(base, width, height, rowpixels); } - void wrap(bitmap_argb32 &source, const rectangle &subrect) { bitmap_t::wrap(static_cast(source), subrect); } - - // getters - bitmap_format format() const { return k_bitmap_format; } - - bitmap_argb32 &operator=(bitmap_argb32 &&) = default; -}; - -#endif // MAME_UTIL_BITMAP_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/corealloc.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/corealloc.h deleted file mode 100644 index d70a0909f2..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/corealloc.h +++ /dev/null @@ -1,66 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - corealloc.h - - Memory allocation helpers for the helper library. - -***************************************************************************/ - -#ifndef MAME_LIB_UTIL_COREALLOC_H -#define MAME_LIB_UTIL_COREALLOC_H - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - - - -// global allocation helpers - -template struct MakeUniqClearT { typedef std::unique_ptr single_object; }; - -template struct MakeUniqClearT { typedef std::unique_ptr array; }; - -template struct MakeUniqClearT { struct invalid_type { }; }; - -/// make_unique_clear for single objects -template -inline typename MakeUniqClearT::single_object make_unique_clear(Params&&... args) -{ - void *const ptr = ::operator new(sizeof(Tp)); // allocate memory - std::memset(ptr, 0, sizeof(Tp)); - return std::unique_ptr(new(ptr) Tp(std::forward(args)...)); -} - -/// make_unique_clear for arrays of unknown bound -template -inline typename MakeUniqClearT::array make_unique_clear(size_t num) -{ - auto size = sizeof(std::remove_extent_t) * num; - unsigned char* ptr = new unsigned char[size]; // allocate memory - std::memset(ptr, 0, size); - return std::unique_ptr(new(ptr) std::remove_extent_t[num]()); -} - -template -inline typename MakeUniqClearT::array make_unique_clear(size_t num) -{ - auto size = sizeof(std::remove_extent_t) * num; - unsigned char* ptr = new unsigned char[size]; // allocate memory - std::memset(ptr, F, size); - return std::unique_ptr(new(ptr) std::remove_extent_t[num]()); -} - -/// Disable make_unique_clear for arrays of known bound -template -inline typename MakeUniqClearT::invalid_type make_unique_clear(Params&&...) = delete; - -#endif // MAME_LIB_UTIL_COREALLOC_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/coretmpl.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/coretmpl.h deleted file mode 100644 index 9d033f72d2..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/coretmpl.h +++ /dev/null @@ -1,689 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles, Vas Crabb -/*************************************************************************** - - coretmpl.h - - Core templates for basic non-string types. - -***************************************************************************/ -#ifndef MAME_UTIL_CORETMPL_H -#define MAME_UTIL_CORETMPL_H - -#pragma once - -#include "osdcomm.h" -#include "vecstream.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -// ======================> simple_list - -// a simple_list is a singly-linked list whose 'next' pointer is owned -// by the object -template -class simple_list final -{ -public: - class auto_iterator - { - public: - typedef int difference_type; - typedef ElementType value_type; - typedef ElementType *pointer; - typedef ElementType &reference; - typedef std::forward_iterator_tag iterator_category; - - // construction/destruction - auto_iterator() noexcept : m_current(nullptr) { } - auto_iterator(ElementType *ptr) noexcept : m_current(ptr) { } - - // required operator overloads - bool operator==(const auto_iterator &iter) const noexcept { return m_current == iter.m_current; } - bool operator!=(const auto_iterator &iter) const noexcept { return m_current != iter.m_current; } - ElementType &operator*() const noexcept { return *m_current; } - ElementType *operator->() const noexcept { return m_current; } - // note that ElementType::next() must not return a const ptr - auto_iterator &operator++() noexcept { m_current = m_current->next(); return *this; } - auto_iterator operator++(int) noexcept { auto_iterator result(*this); m_current = m_current->next(); return result; } - - private: - // private state - ElementType *m_current; - }; - - // construction/destruction - simple_list() noexcept { } - ~simple_list() noexcept { reset(); } - - // we don't support deep copying - simple_list(const simple_list &) = delete; - simple_list &operator=(const simple_list &) = delete; - - // but we do support cheap swap/move - simple_list(simple_list &&list) noexcept { operator=(std::move(list)); } - simple_list &operator=(simple_list &&list) - { - using std::swap; - swap(m_head, list.m_head); - swap(m_tail, list.m_tail); - swap(m_count, list.m_count); - return *this; - } - - // simple getters - ElementType *first() const noexcept { return m_head; } - ElementType *last() const noexcept { return m_tail; } - int count() const noexcept { return m_count; } - bool empty() const noexcept { return m_count == 0; } - - // range iterators - auto_iterator begin() const noexcept { return auto_iterator(m_head); } - auto_iterator end() const noexcept { return auto_iterator(nullptr); } - - // remove (free) all objects in the list, leaving an empty list - void reset() noexcept - { - while (m_head != nullptr) - remove(*m_head); - } - - // add the given object to the head of the list - ElementType &prepend(ElementType &object) noexcept - { - object.m_next = m_head; - m_head = &object; - if (m_tail == nullptr) - m_tail = m_head; - m_count++; - return object; - } - - // add the given list to the head of the list - void prepend_list(simple_list &list) noexcept - { - int count = list.count(); - if (count == 0) - return; - ElementType *tail = list.last(); - ElementType *head = list.detach_all(); - tail->m_next = m_head; - m_head = head; - if (m_tail == nullptr) - m_tail = tail; - m_count += count; - } - - // add the given object to the tail of the list - ElementType &append(ElementType &object) noexcept - { - object.m_next = nullptr; - if (m_tail != nullptr) - m_tail = m_tail->m_next = &object; - else - m_tail = m_head = &object; - m_count++; - return object; - } - - // add the given list to the tail of the list - void append_list(simple_list &list) noexcept - { - int count = list.count(); - if (count == 0) - return; - ElementType *tail = list.last(); - ElementType *head = list.detach_all(); - if (m_tail != nullptr) - m_tail->m_next = head; - else - m_head = head; - m_tail = tail; - m_count += count; - } - - // insert the given object after a particular object (nullptr means prepend) - ElementType &insert_after(ElementType &object, ElementType *insert_after) noexcept - { - if (insert_after == nullptr) - return prepend(object); - object.m_next = insert_after->m_next; - insert_after->m_next = &object; - if (m_tail == insert_after) - m_tail = &object; - m_count++; - return object; - } - - // insert the given object before a particular object (nullptr means append) - ElementType &insert_before(ElementType &object, ElementType *insert_before) noexcept - { - if (insert_before == nullptr) - return append(object); - for (ElementType **curptr = &m_head; *curptr != nullptr; curptr = &(*curptr)->m_next) - if (*curptr == insert_before) - { - object.m_next = insert_before; - *curptr = &object; - if (m_head == insert_before) - m_head = &object; - m_count++; - return object; - } - return object; - } - - // replace an item in the list at the same location, and remove it - ElementType &replace_and_remove(ElementType &object, ElementType &toreplace) noexcept - { - ElementType *prev = nullptr; - for (ElementType *cur = m_head; cur != nullptr; prev = cur, cur = cur->m_next) - if (cur == &toreplace) - { - if (prev != nullptr) - prev->m_next = &object; - else - m_head = &object; - if (m_tail == &toreplace) - m_tail = &object; - object.m_next = toreplace.m_next; - delete &toreplace; - return object; - } - return append(object); - } - - // detach the head item from the list, but don't free its memory - ElementType *detach_head() noexcept - { - ElementType *result = m_head; - if (result != nullptr) - { - m_head = result->m_next; - m_count--; - if (m_head == nullptr) - m_tail = nullptr; - } - return result; - } - - // detach the given item from the list, but don't free its memory - ElementType &detach(ElementType &object) noexcept - { - ElementType *prev = nullptr; - for (ElementType *cur = m_head; cur != nullptr; prev = cur, cur = cur->m_next) - if (cur == &object) - { - if (prev != nullptr) - prev->m_next = object.m_next; - else - m_head = object.m_next; - if (m_tail == &object) - m_tail = prev; - m_count--; - return object; - } - return object; - } - - // detach the entire list, returning the head, but don't free memory - ElementType *detach_all() noexcept - { - ElementType *result = m_head; - m_head = m_tail = nullptr; - m_count = 0; - return result; - } - - // remove the given object and free its memory - void remove(ElementType &object) noexcept - { - delete &detach(object); - } - - // find an object by index in the list - ElementType *find(int index) const noexcept - { - for (ElementType *cur = m_head; cur != nullptr; cur = cur->m_next) - if (index-- == 0) - return cur; - return nullptr; - } - - // return the index of the given object in the list - int indexof(const ElementType &object) const noexcept - { - int index = 0; - for (ElementType *cur = m_head; cur != nullptr; cur = cur->m_next) - { - if (cur == &object) - return index; - index++; - } - return -1; - } - -private: - // internal state - ElementType * m_head = nullptr; // head of the singly-linked list - ElementType * m_tail = nullptr; // tail of the singly-linked list - int m_count = 0; // number of objects in the list -}; - - -// ======================> fixed_allocator - -// a fixed_allocator is a simple class that maintains a free pool of objects -template -class fixed_allocator -{ - // we don't support deep copying - fixed_allocator(const fixed_allocator &); - fixed_allocator &operator=(const fixed_allocator &); - -public: - // construction/destruction - fixed_allocator() { } - - // allocate a new item, either by recycling an old one, or by allocating a new one - ItemType *alloc() - { - ItemType *result = m_freelist.detach_head(); - if (result == nullptr) - result = new ItemType; - return result; - } - - // reclaim an item by adding it to the free list - void reclaim(ItemType *item) { if (item != nullptr) m_freelist.append(*item); } - void reclaim(ItemType &item) { m_freelist.append(item); } - - // reclaim all items from a list - void reclaim_all(simple_list &_list) { m_freelist.append_list(_list); } - -private: - // internal state - simple_list m_freelist; // list of free objects -}; - - -// ======================> contiguous_sequence_wrapper - -namespace util { - -using osd::u8; -using osd::u16; -using osd::u32; -using osd::u64; - -using osd::s8; -using osd::s16; -using osd::s32; -using osd::s64; - - -// wraps an existing sequence of values -template -class contiguous_sequence_wrapper -{ -public: - typedef std::ptrdiff_t difference_type; - typedef std::size_t size_type; - typedef T value_type; - typedef T &reference; - typedef const T &const_reference; - typedef T *pointer; - typedef T *iterator; - typedef const T *const_iterator; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; - - contiguous_sequence_wrapper(T *ptr, std::size_t size) - : m_begin(ptr) - , m_end(ptr + size) - { - } - - contiguous_sequence_wrapper(const contiguous_sequence_wrapper &that) = default; - - // iteration - iterator begin() { return m_begin; } - const_iterator begin() const { return m_begin; } - const_iterator cbegin() const { return m_begin; } - iterator end() { return m_end; } - const_iterator end() const { return m_end; } - const_iterator cend() const { return m_end; } - - // reverse iteration - reverse_iterator rbegin() { return std::reverse_iterator(end()); } - const_reverse_iterator rbegin() const { return std::reverse_iterator(end()); } - const_reverse_iterator crbegin() const { return std::reverse_iterator(cend()); } - reverse_iterator rend() { return std::reverse_iterator(begin()); } - const_reverse_iterator rend() const { return std::reverse_iterator(begin()); } - const_reverse_iterator crend() const { return std::reverse_iterator(begin()); } - - // capacity - size_type size() const { return m_end - m_begin; } - size_type max_size() const { return size(); } - bool empty() const { return size() == 0; } - - // element access - reference front() { return operator[](0); } - const_reference front() const { return operator[](0); } - reference back() { return operator[](size() - 1); } - const_reference back() const { return operator[](size() - 1); } - reference operator[] (size_type n) { return m_begin[n]; } - const_reference operator[] (size_type n) const { return m_begin[n]; } - reference at(size_type n) { check_in_bounds(n); return operator[](n); } - const_reference at(size_type n) const { check_in_bounds(n); return operator[](n); } - -private: - iterator m_begin; - iterator m_end; - - void check_in_bounds(size_type n) - { - if (n < 0 || n >= size()) - throw std::out_of_range("invalid contiguous_sequence_wrapper subscript"); - } -}; - - -template -class fifo : protected std::array -{ -public: - fifo() - : std::array() - , m_head(this->begin()) - , m_tail(this->begin()) - , m_empty(true) - { - static_assert(0U < N, "FIFO must have at least one element"); - } - fifo(fifo const &) = delete; - fifo(fifo &&) = delete; - fifo &operator=(fifo const &) = delete; - fifo &operator=(fifo &&) = delete; - - template - fifo(fifo const &that) - : std::array(that) - , m_head(std::advance(this->begin(), std::distance(that.begin(), that.m_head))) - , m_tail(std::advance(this->begin(), std::distance(that.begin(), that.m_tail))) - , m_empty(that.m_empty) - { - } - - template - fifo(fifo &&that) - : std::array(std::move(that)) - , m_head(std::advance(this->begin(), std::distance(that.begin(), that.m_head))) - , m_tail(std::advance(this->begin(), std::distance(that.begin(), that.m_tail))) - , m_empty(that.m_empty) - { - } - - template - fifo &operator=(fifo const &that) - { - std::array::operator=(that); - m_head = std::advance(this->begin(), std::distance(that.begin(), that.m_head)); - m_tail = std::advance(this->begin(), std::distance(that.begin(), that.m_tail)); - m_empty = that.m_empty; - return *this; - } - - template - fifo &operator=(fifo &&that) - { - std::array::operator=(std::move(that)); - m_head = std::advance(this->begin(), std::distance(that.begin(), that.m_head)); - m_tail = std::advance(this->begin(), std::distance(that.begin(), that.m_tail)); - m_empty = that.m_empty; - return *this; - } - - bool full() const { return !m_empty && (m_head == m_tail); } - bool empty() const { return m_empty; } - - // number of currently enqueued elements - std::size_t queue_length() const - { - if (m_empty) - return 0; - - auto const distance = std::distance(m_head, m_tail); - - return (distance > 0) ? distance : (N + distance); - } - - void enqueue(T const &v) - { - if (WriteWrap || m_empty || (m_head != m_tail)) - { - *m_tail = v; - if (this->end() == ++m_tail) - m_tail = this->begin(); - m_empty = false; - } - } - - void enqueue(T &&v) - { - if (WriteWrap || m_empty || (m_head != m_tail)) - { - *m_tail = std::move(v); - if (this->end() == ++m_tail) - m_tail = this->begin(); - m_empty = false; - } - } - - T const &dequeue() - { - T const &result(*m_head); - if (ReadWrap || !m_empty) - { - if (this->end() == ++m_head) - m_head = this->begin(); - m_empty = (m_head == m_tail); - } - return result; - } - - void poke(T &v) - { - *m_tail = v; - } - - void poke(T &&v) - { - *m_tail = std::move(v); - } - - T const &peek() const - { - return *m_head; - } - - void clear() - { - m_head = m_tail = this->begin(); - m_empty = true; - } - -private: - typename fifo::iterator m_head, m_tail; - bool m_empty; -}; - - -// extract a string_view from an ovectorstream buffer -template -std::basic_string_view buf_to_string_view(basic_ovectorstream &stream) -{ - // this works on the assumption that the value tellp returns is the same both before and after vec is called - return std::basic_string_view(&stream.vec()[0], stream.tellp()); -} - - -// For declaring an array of the same dimensions as another array (including multi-dimensional arrays) -template struct equivalent_array_or_type { typedef T type; }; -template struct equivalent_array_or_type { typedef typename equivalent_array_or_type::type type[N]; }; -template using equivalent_array_or_type_t = typename equivalent_array_or_type::type; -template struct equivalent_array { }; -template struct equivalent_array { typedef equivalent_array_or_type_t type[N]; }; -template using equivalent_array_t = typename equivalent_array::type; -#define EQUIVALENT_ARRAY(a, T) util::equivalent_array_t > - - -template -using enable_enum_t = typename std::enable_if_t::value, typename std::underlying_type_t >; - -// template function which takes a strongly typed enumerator and returns its value as a compile-time constant -template -constexpr enable_enum_t underlying_value(E e) noexcept -{ - return static_cast >(e); -} - -// template function which takes an integral value and returns its representation as enumerator (even strongly typed) -template -constexpr typename std::enable_if_t::value && std::is_integral::value, E> enum_value(T value) noexcept -{ - return static_cast(value); -} - - -/// \defgroup bitutils Useful functions for bit shuffling -/// \{ - -/// \brief Generate a right-aligned bit mask -/// -/// Generates a right aligned mask of the specified width. Works with -/// signed and unsigned integer types. -/// \tparam T Desired output type. -/// \tparam U Type of the input (generally resolved by the compiler). -/// \param [in] n Width of the mask to generate in bits. -/// \return Right-aligned mask of the specified width. - -template constexpr T make_bitmask(U n) -{ - return T((n < (8 * sizeof(T)) ? (std::make_unsigned_t(1) << n) : std::make_unsigned_t(0)) - 1); -} - - -/// \brief Extract a single bit from an integer -/// -/// Extracts a single bit from an integer into the least significant bit -/// position. -/// -/// \param [in] x The integer to extract the bit from. -/// \param [in] n The bit to extract, where zero is the least -/// significant bit of the input. -/// \return Zero if the specified bit is unset, or one if it is set. -/// \sa bitswap -template constexpr T BIT(T x, U n) noexcept { return (x >> n) & T(1); } - - -/// \brief Extract a bit field from an integer -/// -/// Extracts and right-aligns a bit field from an integer. -/// -/// \param [in] x The integer to extract the bit field from. -/// \param [in] n The least significant bit position of the field to -/// extract, where zero is the least significant bit of the input. -/// \param [in] w The width of the field to extract in bits. -/// \return The field [n..(n+w-1)] from the input. -/// \sa bitswap -template constexpr T BIT(T x, U n, V w) -{ - return (x >> n) & make_bitmask(w); -} - - -/// \brief Extract bits in arbitrary order -/// -/// Extracts bits from an integer. Specify the bits in the order they -/// should be arranged in the output, from most significant to least -/// significant. The extracted bits will be packed into a right-aligned -/// field in the output. -/// -/// \param [in] val The integer to extract bits from. -/// \param [in] b The first bit to extract from the input -/// extract, where zero is the least significant bit of the input. -/// This bit will appear in the most significant position of the -/// right-aligned output field. -/// \param [in] c The remaining bits to extract, where zero is the -/// least significant bit of the input. -/// \return The extracted bits packed into a right-aligned field. -template constexpr T bitswap(T val, U b, V... c) noexcept -{ - if constexpr (sizeof...(c) > 0U) - return (BIT(val, b) << sizeof...(c)) | bitswap(val, c...); - else - return BIT(val, b); -} - - -/// \brief Extract bits in arbitrary order with explicit count -/// -/// Extracts bits from an integer. Specify the bits in the order they -/// should be arranged in the output, from most significant to least -/// significant. The extracted bits will be packed into a right-aligned -/// field in the output. The number of bits to extract must be supplied -/// as a template argument. -/// -/// A compile error will be generated if the number of bit positions -/// supplied does not match the specified number of bits to extract, or -/// if the output type is too small to hold the extracted bits. This -/// guards against some simple errors. -/// -/// \tparam B The number of bits to extract. Must match the number of -/// bit positions supplied. -/// \param [in] val The integer to extract bits from. -/// \param [in] b Bits to extract, where zero is the least significant -/// bit of the input. Specify bits in the order they should appear in -/// the output field, from most significant to least significant. -/// \return The extracted bits packed into a right-aligned field. -template T bitswap(T val, U... b) noexcept -{ - static_assert(sizeof...(b) == B, "wrong number of bits"); - static_assert((sizeof(std::remove_reference_t) * 8) >= B, "return type too small for result"); - return bitswap(val, b...); -} - -/// \} - - -// constexpr absolute value of an integer -template -constexpr std::enable_if_t::value, T> iabs(T v) noexcept -{ - return (v < T(0)) ? -v : v; -} - - -// reduce a fraction -template -inline void reduce_fraction(M &num, N &den) -{ - auto const div(std::gcd(num, den)); - if (div) - { - num /= div; - den /= div; - } -} - -} // namespace util - -#endif // MAME_UTIL_CORETMPL_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/delegate.cpp b/waterbox/ares64/ares/thirdparty/mame/lib/util/delegate.cpp deleted file mode 100644 index 8949f90f14..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/delegate.cpp +++ /dev/null @@ -1,287 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles,Vas Crabb -/*************************************************************************** - - delegate.cpp - - Templates and classes to enable delegates for callbacks. - -***************************************************************************/ - -#include "delegate.h" - -#include -#include - - -//************************************************************************** -// MACROS -//************************************************************************** - -#if defined(MAME_DELEGATE_LOG_ADJ) - #define LOG(...) printf(__VA_ARGS__) -#else - #define LOG(...) do { if (false) printf(__VA_ARGS__); } while (false) -#endif - - - -//************************************************************************** -// LATE BINDING EXCEPTION -//************************************************************************** - -binding_type_exception::binding_type_exception(std::type_info const &target_type, std::type_info const &actual_type) - : m_target_type(&target_type) - , m_actual_type(&actual_type) -{ - std::ostringstream os; - os << "Error performing late bind of function expecting type " << target_type.name() << " to instance of type " << actual_type.name(); - m_what = os.str(); -} - - -char const *binding_type_exception::what() const noexcept -{ - return m_what.c_str(); -} - - - -namespace util::detail { - -//************************************************************************** -// GLOBAL VARIABLES -//************************************************************************** - -const delegate_mfp_compatible::raw_mfp_data delegate_mfp_compatible::s_null_mfp = { { 0 } }; - - - -//************************************************************************** -// INTERNAL DELEGATE HELPERS -//************************************************************************** - -//------------------------------------------------- -// delegate_mfp_itanium::convert_to_generic - -// given an object pointer and member function -// pointer, apply the displacement and get the -// actual function pointer -//------------------------------------------------- - -delegate_generic_function delegate_mfp_itanium::convert_to_generic(delegate_generic_class *&object) const -{ - // apply the "this" delta to the object first - the value is shifted to the left one bit position for the ARM-like variant - LOG("Input this=%p ptr=%p adj=%ld ", reinterpret_cast(object), reinterpret_cast(m_function), long(m_this_delta)); - object = reinterpret_cast( - reinterpret_cast(object) + (m_this_delta >> ((MAME_ABI_CXX_ITANIUM_MFP_TYPE == MAME_ABI_CXX_ITANIUM_MFP_ARM) ? 1 : 0))); - LOG("Calculated this=%p ", reinterpret_cast(object)); - - // test the virtual member function flag - it's the low bit of either the ptr or adj field, depending on the variant - if ((MAME_ABI_CXX_ITANIUM_MFP_TYPE == MAME_ABI_CXX_ITANIUM_MFP_ARM) ? !(m_this_delta & 1) : !(m_function & 1)) - { - // conventional function pointer - LOG("ptr=%p\n", reinterpret_cast(m_function)); - return reinterpret_cast(m_function); - } - else - { - // byte index into the vtable to the function - std::uint8_t const *const vtable_ptr = *reinterpret_cast(object) + m_function - ((MAME_ABI_CXX_ITANIUM_MFP_TYPE == MAME_ABI_CXX_ITANIUM_MFP_ARM) ? 0 : 1); - delegate_generic_function result; - if (MAME_ABI_CXX_VTABLE_FNDESC) - result = reinterpret_cast(uintptr_t(vtable_ptr)); - else - result = *reinterpret_cast(vtable_ptr); - LOG("ptr=%p (vtable)\n", reinterpret_cast(result)); - return result; - } -} - - -//------------------------------------------------- -// delegate_mfp_msvc::adjust_this_pointer - given -// an object pointer and member function pointer, -// apply the displacement, and walk past -// recognisable thunks -//------------------------------------------------- - -delegate_generic_function delegate_mfp_msvc::adjust_this_pointer(delegate_generic_class *&object) const -{ - LOG("Input this=%p ", reinterpret_cast(object)); - if (sizeof(single_base_equiv) < m_size) - LOG("thisdelta=%d ", m_this_delta); - if (sizeof(unknown_base_equiv) == m_size) - LOG("vptrdelta=%d vindex=%d ", m_vptr_offs, m_vt_index); - std::uint8_t *byteptr = reinterpret_cast(object); - - // test for pointer to member function cast across virtual inheritance relationship - if ((sizeof(unknown_base_equiv) == m_size) && m_vt_index) - { - // add offset from "this" pointer to location of vptr, and add offset to virtual base from vtable - byteptr += m_vptr_offs; - std::uint8_t const *const vptr = *reinterpret_cast(byteptr); - byteptr += *reinterpret_cast(vptr + m_vt_index); - } - - // add "this" pointer displacement if present in the pointer to member function - if (sizeof(single_base_equiv) < m_size) - byteptr += m_this_delta; - LOG("Calculated this=%p\n", reinterpret_cast(byteptr)); - object = reinterpret_cast(byteptr); - - // walk past recognisable thunks -#if defined(__x86_64__) || defined(_M_X64) - std::uint8_t const *func = reinterpret_cast(m_function); - while (true) - { - // Assumes Windows calling convention, and doesn't consider that - // the "this" pointer could be in RDX if RCX is a pointer to - // space for an oversize scalar result. Since the result area - // is uninitialised on entry, you won't see something that looks - // like a vtable dispatch through RCX in this case - it won't - // behave badly, it just won't bypass virtual call thunks in the - // rare situations where the return type is an oversize scalar. - if (0xe9 == func[0]) - { - // relative jump with 32-bit displacement (typically a resolved PLT entry) - LOG("Found relative jump at %p ", func); - func += std::ptrdiff_t(5) + *reinterpret_cast(func + 1); - LOG("redirecting to %p\n", func); - continue; - } - else if ((0x48 == func[0]) && (0x8b == func[1]) && (0x01 == func[2])) - { - if ((0xff == func[3]) && ((0x20 == func[4]) || (0x60 == func[4]) || (0xa0 == func[4]))) - { - // MSVC virtual function call thunk - mov rax,QWORD PTR [rcx] ; jmp QWORD PTR [rax+...] - LOG("Found virtual member function thunk at %p ", func); - std::uint8_t const *const vptr = *reinterpret_cast(object); - if (0x20 == func[4]) // no displacement - func = *reinterpret_cast(vptr); - else if (0x60 == func[4]) // 8-bit displacement - func = *reinterpret_cast(vptr + *reinterpret_cast(func + 5)); - else // 32-bit displacement - func = *reinterpret_cast(vptr + *reinterpret_cast(func + 5)); - LOG("redirecting to %p\n", func); - continue; - } - else if ((0x48 == func[3]) && (0x8b == func[4])) - { - // clang virtual function call thunk - mov rax,QWORD PTR [rcx] ; mov rax,QWORD PTR [rax+...] ; jmp rax - if ((0x00 == func[5]) && (0x48 == func[6]) && (0xff == func[7]) && (0xe0 == func[8])) - { - // no displacement - LOG("Found virtual member function thunk at %p ", func); - std::uint8_t const *const vptr = *reinterpret_cast(object); - func = *reinterpret_cast(vptr); - LOG("redirecting to %p\n", func); - continue; - } - else if ((0x40 == func[5]) && (0x48 == func[7]) && (0xff == func[8]) && (0xe0 == func[9])) - { - // 8-bit displacement - LOG("Found virtual member function thunk at %p ", func); - std::uint8_t const *const vptr = *reinterpret_cast(object); - func = *reinterpret_cast(vptr + *reinterpret_cast(func + 6)); - LOG("redirecting to %p\n", func); - continue; - } - else if ((0x80 == func[5]) && (0x48 == func[10]) && (0xff == func[11]) && (0xe0 == func[12])) - { - // 32-bit displacement - LOG("Found virtual member function thunk at %p ", func); - std::uint8_t const *const vptr = *reinterpret_cast(object); - func = *reinterpret_cast(vptr + *reinterpret_cast(func + 6)); - LOG("redirecting to %p\n", func); - continue; - } - } - } - - // clang uses unoptimised thunks if optimisation is disabled - // Without optimisation, clang produces thunks like: - // 50 push rax - // 48 89 0c 24 mov QWORD PTR [rsp],rcx - // 48 8b 0c 24 mov rcx,QWORD PTR [rsp] - // 48 8b 01 mov rax,QWORD PTR [rcx] - // 48 8b 80 xx xx xx xx mov rax,QWORD PTR [rax+...] - // 41 5a pop r10 - // 48 ff e0 jmp rax - // Trying to decode these thunks likely isn't worth the effort. - // Chasing performance in unoptimised builds isn't very useful, - // and the format of these thunks may be fragile. - - // not something we can easily bypass - break; - } - return reinterpret_cast(std::uintptr_t(func)); -#elif defined(__aarch64__) || defined(_M_ARM64) - std::uint32_t const *func = reinterpret_cast(m_function); - while (true) - { - // Assumes little Endian mode. Instructions are always stored - // in little Endian format on AArch64, so if big Endian mode is - // to be supported, the values need to be swapped. - if ((0x90000010 == (func[0] & 0x9f00001f)) && (0x91000210 == (func[1] & 0xffc003ff)) && (0xd61f0200 == func[2])) - { - // page-relative jump with +/-4GB reach - adrp xip0,... ; add xip0,xip0,#... ; br xip0 - LOG("Found page-relative jump at %p ", func); - std::int64_t const page = - (std::uint64_t(func[0] & 0x60000000) >> 17) | - (std::uint64_t(func[0] & 0x00ffffe0) << 9) | - ((func[0] & 0x00800000) ? (~std::uint64_t(0) << 33) : 0); - std::uint32_t const offset = (func[1] & 0x003ffc00) >> 10; - func = reinterpret_cast(((std::uintptr_t(func) + page) & (~std::uintptr_t(0) << 12)) + offset); - LOG("redirecting to %p\n", func); - } - else if ((0xf9400010 == func[0]) && (0xf9400210 == (func[1] & 0xffc003ff)) && (0xd61f0200 == func[2])) - { - // virtual function call thunk - ldr xip0,[x0] ; ldr xip0,[x0,#...] ; br xip0 - LOG("Found virtual member function thunk at %p ", func); - std::uint32_t const *const *const vptr = *reinterpret_cast(object); - func = vptr[(func[1] & 0x003ffc00) >> 10]; - LOG("redirecting to %p\n", func); - } - else - { - // not something we can easily bypass - break; - } - - // clang uses horribly sub-optimal thunks for AArch64 - // Without optimisation, clang produces thunks like: - // d10143ff sub sp,sp,#80 - // f90027e7 str x7,[sp,#72] - // f90023e6 str x6,[sp,#64] - // f9001fe5 str x5,[sp,#56] - // f9001be4 str x4,[sp,#48] - // f90017e3 str x3,[sp,#40] - // f90013e2 str x2,[sp,#32] - // f9000fe1 str x1,[sp,#24] - // f90007e0 str x0,[sp,#8] - // f94007e0 ldr x0,[sp,#8] - // f9400009 ldr x9,[x0] - // f9400129 ldr x9,[x9,#...] - // 910143ff add sp,sp,#80 - // d61f0120 br x9 - // With optimisation, clang produces thunks like: - // d10103ff sub sp,sp,#64 - // a9008be1 stp x1,x2,[sp,#8] - // a90193e3 stp x3,x4,[sp,#24] - // a9029be5 stp x5,x6,[sp,#40] - // f9001fe7 str x7,[sp,#56] - // f9400009 ldr x9,[x0] - // f9400129 ldr x9,[x9,#...] - // 910103ff add sp,sp,#64 - // d61f0120 br x9 - // It's more effort than it's worth to try decoding these - // thunks. - - } - return reinterpret_cast(std::uintptr_t(func)); -#else - return reinterpret_cast(m_function); -#endif -} - -} // namespace util::detail diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/delegate.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/delegate.h deleted file mode 100644 index df1d6ebcba..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/delegate.h +++ /dev/null @@ -1,972 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles,Couriersud,Miodrag Milanovic,Vas Crabb -/*************************************************************************** - - delegate.h - - Templates and classes to enable delegates for callbacks. - -**************************************************************************** - - There are many implementations of delegate-like functionality for - C++ code, but none of them is a perfect drop-in fit for use in MAME. - In order to be useful in MAME, we need the following properties: - - * No significant overhead; we want to use these for memory - accessors, and memory accessor overhead is already the dominant - performance aspect for most drivers. - - * Existing static functions need to be bound with an additional - pointer parameter as the first argument. All existing - implementations that allow static function binding assume the - same signature as the member functions. - - * We must be able to bind the function separately from the - object. This is to allow configurations to bind functions - before the objects are created. - - Thus, the implementations below are based on existing works but are - really a new implementation that is specific to MAME. - - -------------------------------------------------------------------- - - The "compatible" version of delegates is based on an implementation - from Sergey Ryazanov, found here: - - https://www.codeproject.com/Articles/11015/The-Impossibly-Fast-C-Delegates - - These delegates essentially generate a templated static stub function - for each target function. The static function takes the first - parameter, uses it as the object pointer, and calls through the - member function. For static functions, the stub is compatible with - the signature of a static function, so we just set the stub directly. - - Pros: - * should work with any modern compiler - * static bindings are just as fast as direct calls - - Cons: - * lots of little stub functions generated - * double-hops on member function calls means more overhead - * calling through stub functions repackages parameters - - -------------------------------------------------------------------- - - The "Itanium" version of delegates makes use of the internal - structure of member function pointers in order to convert them at - binding time into simple static function pointers. This only works - on platforms where object->func(p1, p2) is equivalent in calling - convention to func(object, p1, p2). - - Pros: - * as fast as a standard function call in static and member cases - * no stub functions or double-hops needed - - Cons: - * requires internal knowledge of the member function pointer - * only works for two popular variants of the Itanium C++ ABI - - -------------------------------------------------------------------- - - The "MSVC" version of delegates makes use of the internal structure - of member function pointers in order to convert them at binding time - into simple static function pointers. This only works on platforms - where object->func(p1, p2) is equivalent in calling convention to - func(object, p1, p2). - - Pros: - * as fast as a standard function call in static and non-virtual - member cases - * no stub functions needed - - Cons: - * requires internal knowledge of the member function pointer - * only works works with MSVC ABI, and not on 32-bit x86 - * does not work for classes with virtual bases - * structure return does not work with member function pointers - * virtual member function lookup cannot be done in advance - - -------------------------------------------------------------------- - - Further reading: - - * http://itanium-cxx-abi.github.io/cxx-abi/abi.html#member-pointers - Formal specification for the most common member function pointer - implementations. - - * https://www.codeproject.com/Articles/7150/Member-Function-Pointers-and-the-Fastest-Possible - Discusses many member function pointer implementations. Based - on reverse-engineering, so not entirely accurate. In particular, - various fields are incorrectly assumed to be int-sized which is - not true in the general case. - - * https://devblogs.microsoft.com/oldnewthing/20040209-00/?p=40713 - Describes the MSVC implementation of pointers to member - functions for classes with single or multiple inheritance. Does - not mention the additional variants for virtual or unknown - inheritance. Incorrectly states that the "this" pointer - displacement is a size_t when in reality it is an int (important - for 64-bit architectures). - -***************************************************************************/ -#ifndef MAME_LIB_UTIL_DELEGATE_H -#define MAME_LIB_UTIL_DELEGATE_H - -#pragma once - -#include "abi.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -//************************************************************************** -// MACROS -//************************************************************************** - -// types of delegates supported -#define MAME_DELEGATE_TYPE_COMPATIBLE 0 -#define MAME_DELEGATE_TYPE_ITANIUM 1 -#define MAME_DELEGATE_TYPE_MSVC 2 - -// select which one we will be using -#if defined(MAME_DELEGATE_FORCE_COMPATIBLE) - #define MAME_DELEGATE_USE_TYPE MAME_DELEGATE_TYPE_COMPATIBLE -#elif defined(__GNUC__) - // 32bit MINGW asks for different convention - #if defined(__MINGW32__) && !defined(__x86_64__) && defined(__i386__) - #define MAME_DELEGATE_USE_TYPE MAME_DELEGATE_TYPE_COMPATIBLE - //#define MAME_DELEGATE_USE_TYPE MAME_DELEGATE_TYPE_ITANIUM - //#define MAME_DELEGATE_DIFFERENT_MEMBER_ABI 1 - #elif defined(__clang__) && defined(__i386__) && defined(_WIN32) - #define MAME_DELEGATE_USE_TYPE MAME_DELEGATE_TYPE_COMPATIBLE - #else - #define MAME_DELEGATE_USE_TYPE MAME_DELEGATE_TYPE_ITANIUM - #define MAME_DELEGATE_DIFFERENT_MEMBER_ABI 0 - #endif -#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64)) - #define MAME_DELEGATE_DIFFERENT_MEMBER_ABI 0 - #define MAME_DELEGATE_USE_TYPE MAME_DELEGATE_TYPE_MSVC -#else - #define MAME_DELEGATE_USE_TYPE MAME_DELEGATE_TYPE_COMPATIBLE -#endif - -#if MAME_DELEGATE_USE_TYPE == MAME_DELEGATE_TYPE_COMPATIBLE - #define MAME_DELEGATE_DIFFERENT_MEMBER_ABI 0 -#endif - - -/// \brief Base for objects used with late binding -/// -/// Default polymorphic class used as base for objects that can be bound -/// to after the target function has already been set. -class delegate_late_bind -{ -public: - virtual ~delegate_late_bind() = default; -}; - - -/// \brief Inappropriate late bind object error -/// -/// Thrown as an exception if the object supplied for late binding -/// cannot be cast to the target type for the delegate's function. -class binding_type_exception : public std::bad_cast -{ -public: - binding_type_exception(std::type_info const &target_type, std::type_info const &actual_type); - - virtual char const *what() const noexcept override; - - std::type_info const &target_type() const noexcept { return *m_target_type; } - std::type_info const &actual_type() const noexcept { return *m_actual_type; } - -private: - std::string m_what; - std::type_info const *m_target_type; - std::type_info const *m_actual_type; -}; - - - -namespace util::detail { - -//************************************************************************** -// HELPER CLASSES -//************************************************************************** - -// generic function type -using delegate_generic_function = void(*)(); - - -// ======================> generic_class - -// define a dummy generic class that is just straight single-inheritance -#ifdef _MSC_VER -class delegate_generic_class { }; -#else -class delegate_generic_class; -#endif - - -// ======================> delegate_traits - -// delegate_traits is a meta-template that is used to provide a static function pointer -// and member function pointer of the appropriate type and number of parameters - -template -struct delegate_traits -{ - using static_func_type = ReturnType (*)(ClassType *, Params...); - using static_ref_func_type = ReturnType (*)(ClassType &, Params...); - using member_func_type = ReturnType (ClassType::*)(Params...); - using const_member_func_type = ReturnType (ClassType::*)(Params...) const; -}; - - - -/// \brief Maximally compatible member function pointer wrapper -/// -/// Instantiates a static member function template on construction as -/// an adaptor thunk to call the supplied member function with the -/// supplied object. Adds one layer of indirection to calls. -/// -/// This implementation requires the representation of a null member -/// function pointer to be all zeroes. -class delegate_mfp_compatible -{ -public: - // default constructor - delegate_mfp_compatible() - : m_rawdata(s_null_mfp) - , m_realobject(nullptr) - , m_stubfunction(nullptr) - { } - - // copy constructor - delegate_mfp_compatible(const delegate_mfp_compatible &src) = default; - - // construct from any member function pointer - template - delegate_mfp_compatible(MemberFunctionType mfp, MemberFunctionClass *, ReturnType *, StaticFunctionType) - : m_rawdata(s_null_mfp) - , m_realobject(nullptr) - , m_stubfunction(make_generic(&delegate_mfp_compatible::method_stub)) - { - static_assert(sizeof(mfp) <= sizeof(m_rawdata), "Unsupported member function pointer size"); - *reinterpret_cast(&m_rawdata) = mfp; - } - - // comparison helpers - bool operator==(const delegate_mfp_compatible &rhs) const { return m_rawdata == rhs.m_rawdata; } - bool isnull() const { return m_rawdata == s_null_mfp; } - - // getters - delegate_generic_class *real_object(delegate_generic_class *original) const - { - return m_realobject; - } - - // binding helpers - template - void update_after_bind(FunctionType &funcptr, delegate_generic_class *&object); - - template - void update_after_copy(FunctionType &funcptr, delegate_generic_class *&object); - -private: - // helper stubs for calling encased member function pointers - template - static ReturnType method_stub(delegate_generic_class *object, Params ... args); - - // helper to convert a function of a given type to a generic function, forcing template - // instantiation to match the source type - template - static delegate_generic_function make_generic(SourceType funcptr) - { - return reinterpret_cast(funcptr); - } - - // FIXME: not properly aligned for storing pointers - struct raw_mfp_data - { -#if defined(__INTEL_COMPILER) && defined(_M_X64) // needed for "Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.2.176 Build 20140130" at least - int data[((sizeof(void *) + 4 * sizeof(int)) + (sizeof(int) - 1)) / sizeof(int)]; -#else // all other cases - for MSVC maximum size is one pointer, plus 3 ints; all other implementations seem to be smaller - int data[((sizeof(void *) + 3 * sizeof(int)) + (sizeof(int) - 1)) / sizeof(int)]; -#endif - bool operator==(const raw_mfp_data &rhs) const { return !std::memcmp(data, rhs.data, sizeof(data)); } - }; - - // internal state - raw_mfp_data m_rawdata; // raw buffer to hold the copy of the function pointer - delegate_generic_class * m_realobject; // pointer to the object used for calling - delegate_generic_function m_stubfunction; // pointer to our matching stub function - - static const raw_mfp_data s_null_mfp; // nullptr mfp -}; - - -template -void delegate_mfp_compatible::update_after_bind(FunctionType &funcptr, delegate_generic_class *&object) -{ - m_realobject = object; - object = reinterpret_cast(this); - funcptr = reinterpret_cast(m_stubfunction); -} - - -template -void delegate_mfp_compatible::update_after_copy(FunctionType &funcptr, delegate_generic_class *&object) -{ - assert(reinterpret_cast(m_stubfunction) == funcptr); - object = reinterpret_cast(this); -} - - -template -ReturnType delegate_mfp_compatible::method_stub(delegate_generic_class *object, Params ... args) -{ - using mfptype = ReturnType(FunctionClass::*)(Params...); - delegate_mfp_compatible &_this = *reinterpret_cast(object); - mfptype &mfp = *reinterpret_cast(&_this.m_rawdata); - return (reinterpret_cast(_this.m_realobject)->*mfp)(std::forward(args)...); -} - - - -/// \brief Itanium C++ ABI member function pointer wrapper -/// -/// Supports the two most popular pointer to member function -/// implementations described in the Itanium C++ ABI. Both of these -/// consist of a pointer followed by a ptrdiff_t. -/// -/// The first variant is used when member the least significant bit of a -/// member function pointer need never be set and vtable entry offsets -/// are guaranteed to be even numbers of bytes. If the pointer is even, -/// it is a conventional function pointer to the member function. If -/// the pointer is odd, it is a byte offset into the vtable plus one. -/// The ptrdiff_t is a byte offset to add to the this pointer. A null -/// member function pointer is represented by setting the pointer to a -/// null pointer. -/// -/// The second variant is used when the least significant bit of a -/// pointer to a member function may need to be set or it may not be -/// possible to distinguish between a vtable offset and a null pointer. -/// (This is the case for ARM where the least significant bit of a -/// pointer to a function is set if the function starts in Thumb mode.) -/// If the least significant bit of the ptrdiff_t is clear, the pointer -/// is a conventional function pointer to the member function. If the -/// least significant bit of the ptrdiff_t is set, the pointer is a byte -/// offset into the vtable. The ptrdiff_t must be shifted right one bit -/// position to make a byte offset to add to the this pointer. A null -/// member function pointer is represented by setting the pointer to a -/// null pointer and clearing the least significant bit of the -/// ptrdiff_t. -class delegate_mfp_itanium -{ -public: - // default constructor - delegate_mfp_itanium() = default; - - // copy constructor - delegate_mfp_itanium(const delegate_mfp_itanium &src) = default; - - // construct from any member function pointer - template - delegate_mfp_itanium(MemberFunctionType mfp, MemberFunctionClass *, ReturnType *, StaticFunctionType) - { - static_assert(sizeof(mfp) == sizeof(*this), "Unsupported member function pointer size"); - *reinterpret_cast(this) = mfp; - } - - // comparison helpers - bool operator==(const delegate_mfp_itanium &rhs) const - { - return (isnull() && rhs.isnull()) || ((m_function == rhs.m_function) && (m_this_delta == rhs.m_this_delta)); - } - - bool isnull() const - { - if (MAME_ABI_CXX_ITANIUM_MFP_TYPE == MAME_ABI_CXX_ITANIUM_MFP_ARM) - return !reinterpret_cast(m_function) && !(m_this_delta & 1); - else - return !reinterpret_cast(m_function); - } - - // getters - static delegate_generic_class *real_object(delegate_generic_class *original) - { - return original; - } - - // binding helpers - template - void update_after_bind(FunctionType &funcptr, delegate_generic_class *&object) - { - funcptr = reinterpret_cast(convert_to_generic(object)); - } - - template - void update_after_copy(FunctionType &funcptr, delegate_generic_class *&object) - { - } - -private: - // extract the generic function and adjust the object pointer - delegate_generic_function convert_to_generic(delegate_generic_class *&object) const; - - // actual state - uintptr_t m_function = reinterpret_cast(static_cast(nullptr)); // function pointer or vtable offset - ptrdiff_t m_this_delta = 0; // delta to apply to the 'this' pointer -}; - - - -/// \brief MSVC member function pointer wrapper -/// -/// MSVC uses space optimisation. A member function pointer is a -/// conventional function pointer followed by zero to three int values, -/// depending on whether the class has single, multiple, virtual or -/// unknown inheritance of base classes. The function pointer is always -/// a conventional function pointer (a thunk is used to call virtual -/// member functions through the vtable). -/// -/// If present, the first int value is a byte offset to add to the this -/// pointer before calling the function. -/// -/// For the virtual inheritance case, the offset to the vtable pointer -/// from the location the this pointer points to must be known by the -/// compiler when the member function pointer is called. The second int -/// value is a byte offset into the vtable to an int value containing an -/// additional byte offset to add to the this pointer. -/// -/// For the unknown inheritance case, the second int value is a byte -/// offset add to the this pointer to obtain a pointer to the vtable -/// pointer, or undefined if not required. If the third int value is -/// not zero, it is a byte offset into the vtable to an int value -/// containing an additional byte offset to add to the this pointer. -/// -/// It is not possible to support the virtual inheritance case without -/// some way of obtaining the offset to the vtable pointer. -class delegate_mfp_msvc -{ - struct single_base_equiv { delegate_generic_function fptr; }; - struct multi_base_equiv { delegate_generic_function fptr; int thisdisp; }; - struct unknown_base_equiv { delegate_generic_function fptr; int thisdisp, vptrdisp, vtdisp; }; - -public: - // default constructor - delegate_mfp_msvc() = default; - - // copy constructor - delegate_mfp_msvc(const delegate_mfp_msvc &src) = default; - - // construct from any member function pointer - template - delegate_mfp_msvc(MemberFunctionType mfp, MemberFunctionClass *, ReturnType *, StaticFunctionType) - { - // FIXME: this doesn't actually catch the unsupported virtual inheritance case on 64-bit targets - // alignment of the pointer means sizeof gives the same value for multiple inheritance and virtual inheritance cases - static_assert( - (sizeof(mfp) == sizeof(single_base_equiv)) || (sizeof(mfp) == sizeof(multi_base_equiv)) || (sizeof(mfp) == sizeof(unknown_base_equiv)), - "Unsupported member function pointer size"); - static_assert(sizeof(mfp) <= sizeof(*this), "Member function pointer is too large to support"); - *reinterpret_cast(this) = mfp; - m_size = sizeof(mfp); - } - - // comparison helpers - bool operator==(const delegate_mfp_msvc &rhs) const - { - if (m_function != rhs.m_function) - { - return false; - } - else if (sizeof(single_base_equiv) == m_size) - { - return (sizeof(single_base_equiv) == rhs.m_size) || (!rhs.m_this_delta && ((sizeof(multi_base_equiv) == rhs.m_size) || !rhs.m_vt_index)); - } - else if (sizeof(multi_base_equiv) == m_size) - { - if (sizeof(unknown_base_equiv) == rhs.m_size) - return (m_this_delta == rhs.m_this_delta) && !rhs.m_vt_index; - else - return (sizeof(single_base_equiv) == rhs.m_size) ? !m_this_delta : (m_this_delta == rhs.m_this_delta); - } - else if (sizeof(unknown_base_equiv) == rhs.m_size) - { - return (m_this_delta == rhs.m_this_delta) && (m_vt_index == rhs.m_vt_index) && (!m_vt_index || (m_vptr_offs == rhs.m_vptr_offs)); - } - else - { - return !m_vt_index && ((sizeof(multi_base_equiv) == rhs.m_size) ? (m_this_delta == rhs.m_this_delta) : !m_this_delta); - } - } - - bool isnull() const - { - return !reinterpret_cast(m_function); - } - - // getters - static delegate_generic_class *real_object(delegate_generic_class *original) { return original; } - - // binding helpers - template - void update_after_bind(FunctionType &funcptr, delegate_generic_class *&object) - { - funcptr = reinterpret_cast(adjust_this_pointer(object)); - } - - template - void update_after_copy(FunctionType &funcptr, delegate_generic_class *&object) - { - } - -private: - // adjust the object pointer and bypass thunks - delegate_generic_function adjust_this_pointer(delegate_generic_class *&object) const; - - // actual state - uintptr_t m_function = 0; // pointer to function or non-virtual thunk for virtual function call - int m_this_delta = 0; // delta to apply to the 'this' pointer for multiple inheritance - int m_vptr_offs = 0; // offset to apply to this pointer to obtain pointer to vptr - int m_vt_index = 0; // offset into vtable to additional delta to apply to the 'this' pointer - - unsigned m_size = 0; // overall size of the pointer to member function representation -}; - - - -#if MAME_DELEGATE_USE_TYPE == MAME_DELEGATE_TYPE_COMPATIBLE - -template -struct delegate_mfp { using type = delegate_mfp_compatible; }; - -#elif MAME_DELEGATE_USE_TYPE == MAME_DELEGATE_TYPE_ITANIUM - -template -struct delegate_mfp { using type = delegate_mfp_itanium; }; - -#elif MAME_DELEGATE_USE_TYPE == MAME_DELEGATE_TYPE_MSVC - -/// \brief Determine whether a type is returned conventionally -/// -/// Under the MSVC C++ ABI with the Microsoft calling convention for -/// x86-64 or AArch64, the calling convention for member functions is -/// not quite the same as a free function with the "this" pointer as the -/// first parameter. -/// -/// Conventionally, structure and union values can be returned in -/// registers if they are small enough and are aggregates (trivially -/// constructible, destructible, copyable and assignable). On x86-64, -/// if the value cannot be returned in registers, the pointer to the -/// area for the return value is conventionally passed in RCX and -/// explicit parameters are shifted by one position. On AArch64, if the -/// value cannot be returned in registers, the pointer to the area for -/// the return value is passed in X8 (explicit parameters do not need to -/// be shifted). -/// -/// For member functions, structure and union types are never returned -/// in registers, and the pointer to the area for the return value is -/// passed differently for structures and unions. When a structure or -/// union is to be returned, a pointer to the area for the return value -/// is effectively passed as a second implicit parameter. On x86-64, -/// the "this" pointer is passed in RCX and the pointer to the area for -/// the return value is passed in RDX; on AArch64, the "this" pointer is -/// passed in X0 and the pointer to the area for the return value is -/// passed in X1. Explicit parameters are shifted an additional -/// position to allow for the second implicit parameter. -/// -/// Note that pointer types are returned conventionally from member -/// functions even when they're too large to return in registers (e.g. a -/// pointer to a function member of a class with unknown inheritance). -/// -/// Because of this, we may need to use the #delegate_mfp_compatible -/// class to generate adaptor thunks depending on the return type. This -/// trait doesn't need to reliably be true for types that are returned -/// conventionally from member functions; it only needs to reliably be -/// false for types that aren't. Incorrectly yielding true will result -/// in incorrect behaviour while incorrectly yielding false will just -/// cause increased overhead (both compile-time and run-time). -template -using delegate_mfp_conventional_return = std::bool_constant< - std::is_void_v || - std::is_scalar_v || - std::is_reference_v >; - -template -struct delegate_mfp; - -template -struct delegate_mfp::value> > { using type = delegate_mfp_msvc; }; - -template -struct delegate_mfp::value> > { using type = delegate_mfp_compatible; }; - -#endif - -template using delegate_mfp_t = typename delegate_mfp::type; - - - -/// \brief Helper class for generating late bind functions -/// -/// Members of this class don't depend on the delegate's signature. -/// Keeping them here reduces the number of template instantiations as -/// you'll only need one late bind helper for each class used for late -/// binding, not for each class for each delegate signature. -template -class delegate_late_bind_helper -{ -public: - // make it default constructible and copyable - delegate_late_bind_helper() = default; - delegate_late_bind_helper(delegate_late_bind_helper const &) = default; - delegate_late_bind_helper(delegate_late_bind_helper &&) = default; - delegate_late_bind_helper &operator=(delegate_late_bind_helper const &) = default; - delegate_late_bind_helper &operator=(delegate_late_bind_helper &&) = default; - - template - delegate_late_bind_helper(FunctionClass *) - : m_latebinder(&delegate_late_bind_helper::late_bind_helper) - { - } - - delegate_generic_class *operator()(LateBindBase &object) { return m_latebinder(object); } - - explicit operator bool() const noexcept { return bool(m_latebinder); } - -private: - using late_bind_func = delegate_generic_class*(*)(LateBindBase &object); - - template static delegate_generic_class *late_bind_helper(LateBindBase &object); - - late_bind_func m_latebinder = nullptr; -}; - - -template -template -delegate_generic_class *delegate_late_bind_helper::late_bind_helper(LateBindBase &object) -{ - FunctionClass *result = dynamic_cast(&object); - if (result) - return reinterpret_cast(result); - throw binding_type_exception(typeid(FunctionClass), typeid(object)); -} - - - -//************************************************************************** -// COMMON DELEGATE BASE CLASS -//************************************************************************** - -template -class delegate_base -{ -public: - // define our traits - template using traits = delegate_traits; - using generic_static_func = typename traits::static_func_type; - typedef MAME_ABI_CXX_MEMBER_CALL generic_static_func generic_member_func; - - // generic constructor - delegate_base() = default; - - // copy constructor - delegate_base(const delegate_base &src) - : m_function(src.m_function) - , m_object(src.m_object) - , m_latebinder(src.m_latebinder) - , m_raw_function(src.m_raw_function) - , m_raw_mfp(src.m_raw_mfp) - { - if (src.object() && is_mfp()) - m_raw_mfp.update_after_copy(m_function, m_object); - } - - // copy constructor with late bind - delegate_base(const delegate_base &src, LateBindBase &object) - : m_function(src.m_function) - , m_latebinder(src.m_latebinder) - , m_raw_function(src.m_raw_function) - , m_raw_mfp(src.m_raw_mfp) - { - late_bind(object); - } - - // construct from member function with object pointer - template - delegate_base(typename traits::member_func_type funcptr, FunctionClass *object) - : m_latebinder(object) - , m_raw_mfp(funcptr, object, static_cast(nullptr), static_cast(nullptr)) - { - bind(object); - } - - // construct from const member function with object pointer - template - delegate_base(typename traits::const_member_func_type funcptr, FunctionClass *object) - : m_latebinder(object) - , m_raw_mfp(funcptr, object, static_cast(nullptr), static_cast(nullptr)) - { - bind(object); - } - - // construct from static reference function with object reference - template - delegate_base(typename traits::static_ref_func_type funcptr, FunctionClass *object) - : m_function(reinterpret_cast(funcptr)) - , m_latebinder(object) - , m_raw_function(reinterpret_cast(funcptr)) - { - bind(object); - } - - // copy operator - delegate_base &operator=(const delegate_base &src) - { - if (this != &src) - { - m_function = src.m_function; - m_object = src.m_object; - m_latebinder = src.m_latebinder; - m_raw_function = src.m_raw_function; - m_raw_mfp = src.m_raw_mfp; - - if (src.object() && is_mfp()) - m_raw_mfp.update_after_copy(m_function, m_object); - } - return *this; - } - - // comparison helper - bool operator==(const delegate_base &rhs) const - { - return (m_raw_function == rhs.m_raw_function) && (object() == rhs.object()) && (m_raw_mfp == rhs.m_raw_mfp); - } - - // call the function - ReturnType operator()(Params... args) const - { - if ((MAME_DELEGATE_DIFFERENT_MEMBER_ABI) && is_mfp()) - return (*reinterpret_cast(m_function))(m_object, std::forward(args)...); - else - return (*m_function)(m_object, std::forward(args)...); - } - - // getters - bool has_object() const { return object() != nullptr; } - bool isnull() const { return !m_raw_function && m_raw_mfp.isnull(); } - bool is_mfp() const { return !m_raw_mfp.isnull(); } - - // late binding - void late_bind(LateBindBase &object) - { - if (m_latebinder) - bind(m_latebinder(object)); - } - -protected: - // return the actual object (not the one we use for calling) - delegate_generic_class *object() const { return is_mfp() ? m_raw_mfp.real_object(m_object) : m_object; } - - // bind the actual object - template - void bind(FunctionClass *object) - { - m_object = reinterpret_cast(object); - - // if we're wrapping a member function pointer, handle special stuff - if (m_object && is_mfp()) - m_raw_mfp.update_after_bind(m_function, m_object); - } - - // internal state - generic_static_func m_function = nullptr; // resolved static function pointer - delegate_generic_class * m_object = nullptr; // resolved object to the post-cast object - delegate_late_bind_helper m_latebinder; // late binding helper - generic_static_func m_raw_function = nullptr; // raw static function pointer - delegate_mfp_t m_raw_mfp; // raw member function pointer -}; - -} // namespace util::detail - - - -//************************************************************************** -// NATURAL SYNTAX -//************************************************************************** - -// declare the base template -template class delegate; - -template -class delegate : public util::detail::delegate_base -{ -private: - using basetype = util::detail::delegate_base; - using functoid_setter = void (*)(delegate &); - - template struct functoid_type_unwrap { using type = std::remove_reference_t; }; - template struct functoid_type_unwrap > { using type = typename functoid_type_unwrap::type; }; - template using unwrapped_functoid_t = typename functoid_type_unwrap > >::type; - - template static constexpr bool matching_non_const_call(T &&) { return false; } - template static constexpr bool matching_non_const_call(ReturnType (T::*)(Params...)) { return true; } - template static constexpr bool matching_const_call(T &&) { return false; } - template static constexpr bool matching_const_call(ReturnType (T::*)(Params...) const) { return true; } - - template static T *unwrap_functoid(T *functoid) { return functoid; } - template static T *unwrap_functoid(std::reference_wrapper *functoid) { return &functoid->get(); } - - template - unwrapped_functoid_t *unwrap_functoid() noexcept - { - return unwrap_functoid(std::any_cast > >(&m_functoid)); - } - - template - static functoid_setter make_functoid_setter() - { - if constexpr (matching_non_const_call(&unwrapped_functoid_t::operator())) - { - return - [] (delegate &obj) - { - obj.basetype::operator=( - basetype( - static_cast::*)(Params...)>(&unwrapped_functoid_t::operator()), - obj.unwrap_functoid())); - }; - } - else if constexpr (matching_const_call(&unwrapped_functoid_t::operator())) - { - return - [] (delegate &obj) - { - obj.basetype::operator=( - basetype( - static_cast::*)(Params...) const>(&unwrapped_functoid_t::operator()), - obj.unwrap_functoid())); - }; - } - else - { - return - [] (delegate &obj) - { - obj.basetype::operator=( - basetype( - [] (unwrapped_functoid_t &f, Params... args) { return ReturnType(f(std::forward(args)...)); }, - obj.unwrap_functoid())); - }; - } - } - - std::any m_functoid; - functoid_setter m_set_functoid = nullptr; - -protected: - template using traits = typename basetype::template traits; - template using member_func_type = typename traits::member_func_type; - template using const_member_func_type = typename traits::const_member_func_type; - template using static_ref_func_type = typename traits::static_ref_func_type; - - template using suitable_functoid = std::is_invocable_r; - -public: - delegate() : basetype() { } - - delegate(delegate const &src) - : basetype(src.m_functoid.has_value() ? static_cast(basetype()) : src) - , m_functoid(src.m_functoid) - , m_set_functoid(src.m_set_functoid) - { - if (m_functoid.has_value()) - m_set_functoid(*this); - } - - delegate(delegate &src) - : delegate(const_cast(src)) - { - } - - delegate(delegate &&src) - : basetype(src.m_functoid.has_value() ? basetype() : std::move(src)) - , m_functoid(std::move(src.m_functoid)) - , m_set_functoid(std::move(src.m_set_functoid)) - { - if (m_functoid.has_value()) - m_set_functoid(*this); - } - - delegate(delegate const &src, LateBindBase &object) - : basetype(src.m_functoid.has_value() ? basetype() : basetype(src, object)) - , m_functoid(src.m_functoid) - , m_set_functoid(src.m_set_functoid) - { - if (m_functoid.has_value()) - m_set_functoid(*this); - } - - template delegate(member_func_type funcptr, FunctionClass *object) : basetype(funcptr, object) { } - template delegate(const_member_func_type funcptr, FunctionClass *object) : basetype(funcptr, object) { } - template delegate(static_ref_func_type funcptr, FunctionClass *object) : basetype(funcptr, object) { } - - template - explicit delegate(T &&functoid, std::enable_if_t::value, int> = 0) - : basetype() - , m_functoid(std::forward(functoid)) - , m_set_functoid(make_functoid_setter()) - { - m_set_functoid(*this); - } - - delegate &operator=(std::nullptr_t) noexcept - { - reset(); - return *this; - } - - delegate &operator=(delegate const &src) - { - m_functoid = src.m_functoid; - m_set_functoid = src.m_set_functoid; - if (m_functoid.has_value()) - m_set_functoid(*this); - else - basetype::operator=(src); - return *this; - } - - delegate &operator=(delegate &&src) - { - m_functoid = std::move(src.m_functoid); - m_set_functoid = std::move(src.m_set_functoid); - if (m_functoid.has_value()) - m_set_functoid(*this); - else - basetype::operator=(std::move(src)); - return *this; - } - - void reset() noexcept - { - basetype::operator=(basetype()); - m_functoid.reset(); - m_set_functoid = nullptr; - } -}; - -#endif // MAME_LIB_UTIL_DELEGATE_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/endianness.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/endianness.h deleted file mode 100644 index cef615fcb8..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/endianness.h +++ /dev/null @@ -1,76 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - endianness.h - - Endianness types and utility functions. - -***************************************************************************/ - -#ifndef MAME_LIB_UTIL_ENDIANNESS_H -#define MAME_LIB_UTIL_ENDIANNESS_H - -#pragma once - -#include - - -namespace util { - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// constants for expression endianness -enum class endianness -{ - little, - big, -#ifdef LSB_FIRST - native = little -#else - native = big -#endif -}; - - -//************************************************************************** -// MACROS AND INLINE FUNCTIONS -//************************************************************************** - -constexpr std::string_view endian_to_string_view(endianness e) { using namespace std::literals; return e == endianness::little ? "little"sv : "big"sv; } - -// endian-based value: first value is if native endianness is little-endian, second is if native is big-endian -#define NATIVE_ENDIAN_VALUE_LE_BE(leval,beval) ((util::endianness::native == util::endianness::little) ? (leval) : (beval)) - - -// inline functions for accessing bytes and words within larger chunks - -// read/write a byte to a 16-bit space -template constexpr T BYTE_XOR_BE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(1,0); } -template constexpr T BYTE_XOR_LE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(0,1); } - -// read/write a byte to a 32-bit space -template constexpr T BYTE4_XOR_BE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(3,0); } -template constexpr T BYTE4_XOR_LE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(0,3); } - -// read/write a word to a 32-bit space -template constexpr T WORD_XOR_BE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(2,0); } -template constexpr T WORD_XOR_LE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(0,2); } - -// read/write a byte to a 64-bit space -template constexpr T BYTE8_XOR_BE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(7,0); } -template constexpr T BYTE8_XOR_LE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(0,7); } - -// read/write a word to a 64-bit space -template constexpr T WORD2_XOR_BE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(6,0); } -template constexpr T WORD2_XOR_LE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(0,6); } - -// read/write a dword to a 64-bit space -template constexpr T DWORD_XOR_BE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(4,0); } -template constexpr T DWORD_XOR_LE(T a) { return a ^ NATIVE_ENDIAN_VALUE_LE_BE(0,4); } - -} // namespace util - -#endif // MAME_LIB_UTIL_ENDIANNESS_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/hash.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/hash.h deleted file mode 100644 index b13ac5556a..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/hash.h +++ /dev/null @@ -1,122 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - hash.h - - Function to handle hash functions (checksums) - - Based on original idea by Farfetch'd - -***************************************************************************/ - -#ifndef MAME_UTIL_HASH_H -#define MAME_UTIL_HASH_H - -#pragma once - -#include "hashing.h" - - -//************************************************************************** -// MACROS -//************************************************************************** - -// use these to define compile-time internal-format hash strings -#define CRC(x) "R" #x -#define SHA1(x) "S" #x -#define NO_DUMP "!" -#define BAD_DUMP "^" - - -namespace util { -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - - -// ======================> hash_collection - -// a collection of the various supported hashes and flags -class hash_collection -{ -public: - // hash types are identified by non-hex alpha values (G-Z) - static constexpr char HASH_CRC = 'R'; - static constexpr char HASH_SHA1 = 'S'; - - // common combinations for requests - static char const *const HASH_TYPES_CRC; - static char const *const HASH_TYPES_CRC_SHA1; - static char const *const HASH_TYPES_ALL; - - // flags are identified by punctuation marks - static constexpr char FLAG_NO_DUMP = '!'; - static constexpr char FLAG_BAD_DUMP = '^'; - - // construction/destruction - hash_collection(); - hash_collection(std::string_view string); - hash_collection(const hash_collection &src); - ~hash_collection(); - - // operators - hash_collection &operator=(const hash_collection &src); - bool operator==(const hash_collection &rhs) const; - bool operator!=(const hash_collection &rhs) const { return !(*this == rhs); } - - // getters - bool flag(char flag) const { return (m_flags.find_first_of(flag) != std::string::npos); } - std::string hash_types() const; - - // hash manipulators - void reset(); - bool add_from_string(char type, std::string_view string); - bool remove(char type); - - // CRC-specific helpers - bool crc(uint32_t &result) const { result = m_crc32; return m_has_crc32; } - void add_crc(uint32_t crc) { m_crc32 = crc; m_has_crc32 = true; } - - // SHA1-specific helpers - bool sha1(sha1_t &result) const { result = m_sha1; return m_has_sha1; } - void add_sha1(sha1_t sha1) { m_has_sha1 = true; m_sha1 = sha1; } - - // string conversion - std::string internal_string() const; - std::string macro_string() const; - std::string attribute_string() const; - bool from_internal_string(std::string_view string); - - // creation - void begin(const char *types = nullptr); - void buffer(const uint8_t *data, uint32_t length); - void end(); - void compute(const uint8_t *data, uint32_t length, const char *types = nullptr) { begin(types); buffer(data, length); end(); } - -private: - // internal helpers - void copyfrom(const hash_collection &src); - - // internal state - std::string m_flags; - bool m_has_crc32; - crc32_t m_crc32; - bool m_has_sha1; - sha1_t m_sha1; - - // creators - struct hash_creator - { - bool m_doing_crc32; - crc32_creator m_crc32_creator; - bool m_doing_sha1; - sha1_creator m_sha1_creator; - }; - hash_creator * m_creator; -}; - - -} // namespace util - -#endif // MAME_UTIL_HASH_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/hashing.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/hashing.h deleted file mode 100644 index 6cd73ac184..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/hashing.h +++ /dev/null @@ -1,314 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles, Vas Crabb -/*************************************************************************** - - hashing.h - - Hashing helper classes. - -***************************************************************************/ -#ifndef MAME_UTIL_HASHING_H -#define MAME_UTIL_HASHING_H - -#pragma once - -#include "md5.h" - -#include -#include -#include -#include -#include -#include - - -namespace util { - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - - -// ======================> SHA-1 - -// final digest -struct sha1_t -{ - bool operator==(const sha1_t &rhs) const { return memcmp(m_raw, rhs.m_raw, sizeof(m_raw)) == 0; } - bool operator!=(const sha1_t &rhs) const { return memcmp(m_raw, rhs.m_raw, sizeof(m_raw)) != 0; } - operator uint8_t *() { return m_raw; } - bool from_string(std::string_view string); - std::string as_string() const; - uint8_t m_raw[20]; - static const sha1_t null; -}; - -// creation helper -class sha1_creator -{ -public: - // construction/destruction - sha1_creator() { reset(); } - - // reset - void reset(); - - // append data - void append(const void *data, uint32_t length); - - // finalize and compute the final digest - sha1_t finish(); - - // static wrapper to just get the digest from a block - static sha1_t simple(const void *data, uint32_t length) - { - sha1_creator creator; - creator.append(data, length); - return creator.finish(); - } - -protected: - uint64_t m_cnt; - std::array m_st; - uint32_t m_buf[16]; -}; - - - -// ======================> MD5 - -// final digest -struct md5_t -{ - bool operator==(const md5_t &rhs) const { return memcmp(m_raw, rhs.m_raw, sizeof(m_raw)) == 0; } - bool operator!=(const md5_t &rhs) const { return memcmp(m_raw, rhs.m_raw, sizeof(m_raw)) != 0; } - operator uint8_t *() { return m_raw; } - bool from_string(std::string_view string); - std::string as_string() const; - uint8_t m_raw[16]; - static const md5_t null; -}; - -// creation helper -class md5_creator -{ -public: - // construction/destruction - md5_creator() { reset(); } - - // reset - void reset() { MD5Init(&m_context); } - - // append data - void append(const void *data, uint32_t length) { MD5Update(&m_context, reinterpret_cast(data), length); } - - // finalize and compute the final digest - md5_t finish() - { - md5_t result; - MD5Final(result.m_raw, &m_context); - return result; - } - - // static wrapper to just get the digest from a block - static md5_t simple(const void *data, uint32_t length) - { - md5_creator creator; - creator.append(data, length); - return creator.finish(); - } - -protected: - // internal state - struct MD5Context m_context; // internal context -}; - - - -// ======================> CRC-32 - -// final digest -struct crc32_t -{ - crc32_t() { } - constexpr crc32_t(const crc32_t &rhs) = default; - constexpr crc32_t(const uint32_t crc) : m_raw(crc) { } - - constexpr bool operator==(const crc32_t &rhs) const { return m_raw == rhs.m_raw; } - constexpr bool operator!=(const crc32_t &rhs) const { return m_raw != rhs.m_raw; } - - crc32_t &operator=(const crc32_t &rhs) = default; - crc32_t &operator=(const uint32_t crc) { m_raw = crc; return *this; } - - constexpr operator uint32_t() const { return m_raw; } - - bool from_string(std::string_view string); - std::string as_string() const; - - uint32_t m_raw; - - static const crc32_t null; -}; - -// creation helper -class crc32_creator -{ -public: - // construction/destruction - crc32_creator() { reset(); } - - // reset - void reset() { m_accum.m_raw = 0; } - - // append data - void append(const void *data, uint32_t length); - - // finalize and compute the final digest - crc32_t finish() { return m_accum; } - - // static wrapper to just get the digest from a block - static crc32_t simple(const void *data, uint32_t length) - { - crc32_creator creator; - creator.append(data, length); - return creator.finish(); - } - -protected: - // internal state - crc32_t m_accum; // internal accumulator -}; - - - -// ======================> CRC-16 - -// final digest -struct crc16_t -{ - crc16_t() { } - constexpr crc16_t(const crc16_t &rhs) = default; - constexpr crc16_t(const uint16_t crc) : m_raw(crc) { } - - constexpr bool operator==(const crc16_t &rhs) const { return m_raw == rhs.m_raw; } - constexpr bool operator!=(const crc16_t &rhs) const { return m_raw != rhs.m_raw; } - - crc16_t &operator=(const crc16_t &rhs) = default; - crc16_t &operator=(const uint16_t crc) { m_raw = crc; return *this; } - - constexpr operator uint16_t() const { return m_raw; } - - bool from_string(std::string_view string); - std::string as_string() const; - - uint16_t m_raw; - - static const crc16_t null; -}; - -// creation helper -class crc16_creator -{ -public: - // construction/destruction - crc16_creator() { reset(); } - - // reset - void reset() { m_accum.m_raw = 0xffff; } - - // append data - void append(const void *data, uint32_t length); - - // finalize and compute the final digest - crc16_t finish() { return m_accum; } - - // static wrapper to just get the digest from a block - static crc16_t simple(const void *data, uint32_t length) - { - crc16_creator creator; - creator.append(data, length); - return creator.finish(); - } - -protected: - // internal state - crc16_t m_accum; // internal accumulator -}; - - - -// ======================> SUM-16 - -// final digest -struct sum16_t -{ - sum16_t() { } - constexpr sum16_t(const sum16_t &rhs) = default; - constexpr sum16_t(const uint16_t sum) : m_raw(sum) { } - - constexpr bool operator==(const sum16_t &rhs) const { return m_raw == rhs.m_raw; } - constexpr bool operator!=(const sum16_t &rhs) const { return m_raw != rhs.m_raw; } - - sum16_t &operator=(const sum16_t &rhs) = default; - sum16_t &operator=(const uint16_t sum) { m_raw = sum; return *this; } - - constexpr operator uint16_t() const { return m_raw; } - - bool from_string(std::string_view string); - std::string as_string() const; - - uint16_t m_raw; - - static const sum16_t null; -}; - -// creation helper -class sum16_creator -{ -public: - // construction/destruction - sum16_creator() { reset(); } - - // reset - void reset() { m_accum.m_raw = 0; } - - // append data - void append(const void *data, uint32_t length); - - // finalize and compute the final digest - sum16_t finish() { return m_accum; } - - // static wrapper to just get the digest from a block - static sum16_t simple(const void *data, uint32_t length) - { - sum16_creator creator; - creator.append(data, length); - return creator.finish(); - } - -protected: - // internal state - sum16_t m_accum; // internal accumulator -}; - -} // namespace util - -namespace std { - -template <> struct hash<::util::crc32_t> -{ - typedef ::util::crc32_t argument_type; - typedef std::size_t result_type; - result_type operator()(argument_type const & s) const { return std::hash()(s); } -}; - -template <> struct hash<::util::crc16_t> -{ - typedef ::util::crc16_t argument_type; - typedef std::size_t result_type; - result_type operator()(argument_type const & s) const { return std::hash()(s); } -}; - -} // namespace std - -#endif // MAME_UTIL_HASHING_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/md5.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/md5.h deleted file mode 100644 index 8358e8c1e9..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/md5.h +++ /dev/null @@ -1,43 +0,0 @@ -// license:Public Domain -// copyright-holders:Colin Plumb -/* - * This is the header file for the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - * - * Changed so as no longer to depend on Colin Plumb's `usual.h' - * header definitions; now uses stuff from dpkg's config.h - * - Ian Jackson . - * Still in the public domain. - */ - -#ifndef MD5_H -#define MD5_H - -typedef unsigned int UWORD32; - -#define md5byte unsigned char - -struct MD5Context { - UWORD32 buf[4]; - UWORD32 bytes[2]; - UWORD32 in[16]; -}; - -void MD5Init(struct MD5Context *context); -void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len); -void MD5Final(unsigned char digest[16], struct MD5Context *context); -void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]); - -#endif /* !MD5_H */ diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/palette.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/palette.h deleted file mode 100644 index d21c8ca812..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/palette.h +++ /dev/null @@ -1,287 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/****************************************************************************** - - palette.h - - Core palette routines. - -***************************************************************************/ - -#ifndef MAME_UTIL_PALETTE_H -#define MAME_UTIL_PALETTE_H - -#pragma once - -#include -#include - - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// forward definitions -class palette_t; - -// an rgb15_t is a single combined 15-bit R,G,B value -typedef uint16_t rgb15_t; - - -// ======================> rgb_t - -// an rgb_t is a single combined R,G,B (and optionally alpha) value -class rgb_t -{ -public: - // construction/destruction - constexpr rgb_t() : m_data(0) { } - constexpr rgb_t(uint32_t data) : m_data(data) { } - constexpr rgb_t(uint8_t r, uint8_t g, uint8_t b) : m_data((255 << 24) | (r << 16) | (g << 8) | b) { } - constexpr rgb_t(uint8_t a, uint8_t r, uint8_t g, uint8_t b) : m_data((a << 24) | (r << 16) | (g << 8) | b) { } - - // getters - constexpr uint8_t a() const { return m_data >> 24; } - constexpr uint8_t r() const { return m_data >> 16; } - constexpr uint8_t g() const { return m_data >> 8; } - constexpr uint8_t b() const { return m_data >> 0; } - constexpr rgb15_t as_rgb15() const { return ((r() >> 3) << 10) | ((g() >> 3) << 5) | ((b() >> 3) << 0); } - constexpr uint8_t brightness() const { return (r() * 222 + g() * 707 + b() * 71) / 1000; } - constexpr uint32_t const *ptr() const { return &m_data; } - void expand_rgb(uint8_t &r, uint8_t &g, uint8_t &b) const { r = m_data >> 16; g = m_data >> 8; b = m_data >> 0; } - void expand_rgb(int &r, int &g, int &b) const { r = (m_data >> 16) & 0xff; g = (m_data >> 8) & 0xff; b = (m_data >> 0) & 0xff; } - - // setters - rgb_t &set_a(uint8_t a) { m_data &= ~0xff000000; m_data |= a << 24; return *this; } - rgb_t &set_r(uint8_t r) { m_data &= ~0x00ff0000; m_data |= r << 16; return *this; } - rgb_t &set_g(uint8_t g) { m_data &= ~0x0000ff00; m_data |= g << 8; return *this; } - rgb_t &set_b(uint8_t b) { m_data &= ~0x000000ff; m_data |= b << 0; return *this; } - - // implicit conversion operators - constexpr operator uint32_t() const { return m_data; } - - // operations - rgb_t &scale8(uint8_t scale) { m_data = rgb_t(clamphi((a() * scale) >> 8), clamphi((r() * scale) >> 8), clamphi((g() * scale) >> 8), clamphi((b() * scale) >> 8)); return *this; } - - // assignment operators - rgb_t &operator=(uint32_t rhs) { m_data = rhs; return *this; } - rgb_t &operator+=(const rgb_t &rhs) { m_data = uint32_t(*this + rhs); return *this; } - rgb_t &operator-=(const rgb_t &rhs) { m_data = uint32_t(*this - rhs); return *this; } - - // arithmetic operators - constexpr rgb_t operator+(const rgb_t &rhs) const { return rgb_t(clamphi(a() + rhs.a()), clamphi(r() + rhs.r()), clamphi(g() + rhs.g()), clamphi(b() + rhs.b())); } - constexpr rgb_t operator-(const rgb_t &rhs) const { return rgb_t(clamplo(a() - rhs.a()), clamplo(r() - rhs.r()), clamplo(g() - rhs.g()), clamplo(b() - rhs.b())); } - - // static helpers - static constexpr uint8_t clamp(int32_t value) { return (value < 0) ? 0 : (value > 255) ? 255 : value; } - static constexpr uint8_t clamphi(int32_t value) { return (value > 255) ? 255 : value; } - static constexpr uint8_t clamplo(int32_t value) { return (value < 0) ? 0 : value; } - - // constant factories - static constexpr rgb_t black() { return rgb_t(0, 0, 0); } - static constexpr rgb_t white() { return rgb_t(255, 255, 255); } - static constexpr rgb_t green() { return rgb_t(0, 255, 0); } - static constexpr rgb_t amber() { return rgb_t(247, 170, 0); } - static constexpr rgb_t transparent() { return rgb_t(0, 0, 0, 0); } - -private: - uint32_t m_data; -}; - - -// ======================> palette_client - -// a single palette client -class palette_client -{ -public: - // construction/destruction - palette_client(palette_t &palette); - ~palette_client(); - - // getters - palette_client *next() const { return m_next; } - palette_t &palette() const { return m_palette; } - const uint32_t *dirty_list(uint32_t &mindirty, uint32_t &maxdirty); - - // dirty marking - void mark_dirty(uint32_t index) { m_live->mark_dirty(index); } - -private: - // internal object to track dirty states - class dirty_state - { - public: - // construction - dirty_state(); - - // operations - const uint32_t *dirty_list(uint32_t &mindirty, uint32_t &maxdirty); - void resize(uint32_t colors); - void mark_dirty(uint32_t index); - void reset(); - - private: - // internal state - std::vector m_dirty; // bitmap of dirty entries - uint32_t m_mindirty; // minimum dirty entry - uint32_t m_maxdirty; // minimum dirty entry - }; - - // internal state - palette_t & m_palette; // reference to the palette - palette_client *m_next; // pointer to next client - dirty_state * m_live; // live dirty state - dirty_state * m_previous; // previous dirty state - dirty_state m_dirty[2]; // two dirty states -}; - - -// ======================> palette_t - -// a palette object -class palette_t -{ - friend class palette_client; - -public: - // static constructor: used to ensure same new/delete is used - static palette_t *alloc(uint32_t numcolors, uint32_t numgroups = 1); - - // reference counting - void ref() { m_refcount++; } - void deref(); - - // getters - int num_colors() const { return m_numcolors; } - int num_groups() const { return m_numgroups; } - int max_index() const { return m_numcolors * m_numgroups + 2; } - uint32_t black_entry() const { return m_numcolors * m_numgroups + 0; } - uint32_t white_entry() const { return m_numcolors * m_numgroups + 1; } - - // overall adjustments - void set_brightness(float brightness); - void set_contrast(float contrast); - void set_gamma(float gamma); - - // entry getters - rgb_t entry_color(uint32_t index) const { return (index < m_numcolors) ? m_entry_color[index] : rgb_t::black(); } - rgb_t entry_adjusted_color(uint32_t index) const { return (index < m_numcolors * m_numgroups) ? m_adjusted_color[index] : rgb_t::black(); } - float entry_contrast(uint32_t index) const { return (index < m_numcolors) ? m_entry_contrast[index] : 1.0f; } - - // entry setters - void entry_set_color(uint32_t index, rgb_t rgb); - void entry_set_red_level(uint32_t index, uint8_t level); - void entry_set_green_level(uint32_t index, uint8_t level); - void entry_set_blue_level(uint32_t index, uint8_t level); - void entry_set_contrast(uint32_t index, float contrast); - - // entry list getters - const rgb_t *entry_list_raw() const { return &m_entry_color[0]; } - const rgb_t *entry_list_adjusted() const { return &m_adjusted_color[0]; } - const rgb_t *entry_list_adjusted_rgb15() const { return &m_adjusted_rgb15[0]; } - - // group adjustments - void group_set_brightness(uint32_t group, float brightness); - void group_set_contrast(uint32_t group, float contrast); - - // utilities - void normalize_range(uint32_t start, uint32_t end, int lum_min = 0, int lum_max = 255); - -private: - // construction/destruction - palette_t(uint32_t numcolors, uint32_t numgroups = 1); - ~palette_t(); - - // internal helpers - rgb_t adjust_palette_entry(rgb_t entry, float brightness, float contrast, const uint8_t *gamma_map); - void update_adjusted_color(uint32_t group, uint32_t index); - - // internal state - uint32_t m_refcount; // reference count on the palette - uint32_t m_numcolors; // number of colors in the palette - uint32_t m_numgroups; // number of groups in the palette - - float m_brightness; // overall brightness value - float m_contrast; // overall contrast value - float m_gamma; // overall gamma value - uint8_t m_gamma_map[256]; // gamma map - - std::vector m_entry_color; // array of raw colors - std::vector m_entry_contrast; // contrast value for each entry - std::vector m_adjusted_color; // array of adjusted colors - std::vector m_adjusted_rgb15; // array of adjusted colors as RGB15 - - std::vector m_group_bright; // brightness value for each group - std::vector m_group_contrast; // contrast value for each group - - palette_client *m_client_list; // list of clients for this palette -}; - - - -//************************************************************************** -// INLINE FUNCTIONS -//************************************************************************** - -//------------------------------------------------- -// palexpand - expand a palette value to 8 bits -//------------------------------------------------- - -template -constexpr uint8_t palexpand(uint8_t bits) -{ - if (_NumBits == 1) { return (bits & 1) ? 0xff : 0x00; } - if (_NumBits == 2) { bits &= 3; return (bits << 6) | (bits << 4) | (bits << 2) | bits; } - if (_NumBits == 3) { bits &= 7; return (bits << 5) | (bits << 2) | (bits >> 1); } - if (_NumBits == 4) { bits &= 0xf; return (bits << 4) | bits; } - if (_NumBits == 5) { bits &= 0x1f; return (bits << 3) | (bits >> 2); } - if (_NumBits == 6) { bits &= 0x3f; return (bits << 2) | (bits >> 4); } - if (_NumBits == 7) { bits &= 0x7f; return (bits << 1) | (bits >> 6); } - return bits; -} - - -//------------------------------------------------- -// palxbit - convert an x-bit value to 8 bits -//------------------------------------------------- - -constexpr uint8_t pal1bit(uint8_t bits) { return palexpand<1>(bits); } -constexpr uint8_t pal2bit(uint8_t bits) { return palexpand<2>(bits); } -constexpr uint8_t pal3bit(uint8_t bits) { return palexpand<3>(bits); } -constexpr uint8_t pal4bit(uint8_t bits) { return palexpand<4>(bits); } -constexpr uint8_t pal5bit(uint8_t bits) { return palexpand<5>(bits); } -constexpr uint8_t pal6bit(uint8_t bits) { return palexpand<6>(bits); } -constexpr uint8_t pal7bit(uint8_t bits) { return palexpand<7>(bits); } - - -//------------------------------------------------- -// rgbexpand - expand a 32-bit raw data to 8-bit -// RGB -//------------------------------------------------- - -template -constexpr rgb_t rgbexpand(uint32_t data, uint8_t rshift, uint8_t gshift, uint8_t bshift) -{ - return rgb_t(palexpand<_RBits>(data >> rshift), palexpand<_GBits>(data >> gshift), palexpand<_BBits>(data >> bshift)); -} - -template -constexpr rgb_t argbexpand(uint32_t data, uint8_t ashift, uint8_t rshift, uint8_t gshift, uint8_t bshift) -{ - return rgb_t(palexpand<_ABits>(data >> ashift), palexpand<_RBits>(data >> rshift), palexpand<_GBits>(data >> gshift), palexpand<_BBits>(data >> bshift)); -} - - -//------------------------------------------------- -// palxxx - create an x-x-x color by extracting -// bits from a uint32_t -//------------------------------------------------- - -constexpr rgb_t pal332(uint32_t data, uint8_t rshift, uint8_t gshift, uint8_t bshift) { return rgbexpand<3,3,2>(data, rshift, gshift, bshift); } -constexpr rgb_t pal444(uint32_t data, uint8_t rshift, uint8_t gshift, uint8_t bshift) { return rgbexpand<4,4,4>(data, rshift, gshift, bshift); } -constexpr rgb_t pal555(uint32_t data, uint8_t rshift, uint8_t gshift, uint8_t bshift) { return rgbexpand<5,5,5>(data, rshift, gshift, bshift); } -constexpr rgb_t pal565(uint32_t data, uint8_t rshift, uint8_t gshift, uint8_t bshift) { return rgbexpand<5,6,5>(data, rshift, gshift, bshift); } -constexpr rgb_t pal888(uint32_t data, uint8_t rshift, uint8_t gshift, uint8_t bshift) { return rgbexpand<8,8,8>(data, rshift, gshift, bshift); } - -#endif // MAME_UTIL_PALETTE_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/strformat.cpp b/waterbox/ares64/ares/thirdparty/mame/lib/util/strformat.cpp deleted file mode 100644 index cec14635e1..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/strformat.cpp +++ /dev/null @@ -1,661 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -/*************************************************************************** - - strformat.h - - type-safe printf substitutes - -***************************************************************************/ - -#include "strformat.h" - -#include -#include - - -namespace util { - -namespace detail { - -template class format_chars; -template class format_chars; - -template void format_flags::apply(std::ostream &) const; -template void format_flags::apply(std::wostream &) const; -template void format_flags::apply(std::iostream &) const; -template void format_flags::apply(std::wiostream &) const; -template void format_flags::apply(std::ostringstream &) const; -template void format_flags::apply(std::wostringstream &) const; -template void format_flags::apply(std::stringstream &) const; -template void format_flags::apply(std::wstringstream &) const; -template void format_flags::apply(ovectorstream &) const; -template void format_flags::apply(wovectorstream &) const; -template void format_flags::apply(vectorstream &) const; -template void format_flags::apply(wvectorstream &) const; - -template class format_argument; -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument; -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template bool format_argument::static_make_integer(void const *, int &); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); -template void format_argument::static_store_integer(void const *, std::streamoff); - -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; -template class format_argument_pack; - -template std::ostream::off_type stream_format(std::ostream &, format_argument_pack const &); -template std::wostream::off_type stream_format(std::wostream &, format_argument_pack const &); -template std::iostream::off_type stream_format(std::iostream &, format_argument_pack const &); -template std::iostream::off_type stream_format(std::iostream &, format_argument_pack const &); -template std::wiostream::off_type stream_format(std::wiostream &, format_argument_pack const &); -template std::wiostream::off_type stream_format(std::wiostream &, format_argument_pack const &); -template std::ostringstream::off_type stream_format(std::ostringstream &, format_argument_pack const &); -template std::ostringstream::off_type stream_format(std::ostringstream &, format_argument_pack const &); -template std::wostringstream::off_type stream_format(std::wostringstream &, format_argument_pack const &); -template std::wostringstream::off_type stream_format(std::wostringstream &, format_argument_pack const &); -template std::stringstream::off_type stream_format(std::stringstream &, format_argument_pack const &); -template std::stringstream::off_type stream_format(std::stringstream &, format_argument_pack const &); -template std::stringstream::off_type stream_format(std::stringstream &, format_argument_pack const &); -template std::wstringstream::off_type stream_format(std::wstringstream &, format_argument_pack const &); -template std::wstringstream::off_type stream_format(std::wstringstream &, format_argument_pack const &); -template std::wstringstream::off_type stream_format(std::wstringstream &, format_argument_pack const &); -template ovectorstream::off_type stream_format(ovectorstream &, format_argument_pack const &); -template ovectorstream::off_type stream_format(ovectorstream &, format_argument_pack const &); -template wovectorstream::off_type stream_format(wovectorstream &, format_argument_pack const &); -template wovectorstream::off_type stream_format(wovectorstream &, format_argument_pack const &); -template vectorstream::off_type stream_format(vectorstream &, format_argument_pack const &); -template vectorstream::off_type stream_format(vectorstream &, format_argument_pack const &); -template vectorstream::off_type stream_format(vectorstream &, format_argument_pack const &); -template wvectorstream::off_type stream_format(wvectorstream &, format_argument_pack const &); -template wvectorstream::off_type stream_format(wvectorstream &, format_argument_pack const &); -template wvectorstream::off_type stream_format(wvectorstream &, format_argument_pack const &); - -} // namespace detail - -} // namespace util diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/strformat.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/strformat.h deleted file mode 100644 index e6d2ee0a0f..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/strformat.h +++ /dev/null @@ -1,2432 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -/*************************************************************************** - - strformat.h - - type-safe printf substitutes - - This header provides type-safe printf substitutes that output to - std::ostream- or std::string-like objects. Most format strings - supported by C99, SUS, glibc and MSVCRT are accepted. Not all - features are implemented, and semantics differ in some cases. Any - object with an appropriate stream output operator can be used as - a format argument with the %s conversion. - - Since the functions are implemented using C++ iostream, some - behaviour more closely resembles iostream output operator behaviour - than printf behaviour. You are also exposed to bugs in your C++ - iostream implementation (e.g. hexadecimal scientific format doesn't - work properly on MinGW). - - These functions are designed to be forgiving - using an - inappropriate conversion for an argument's type just results in the - default conversion for the type being used. Inappropriate types or - out-of-range positions for parameterised field width and precision - are treated as if no width/precision was specified. Out-of-range - argument positions result in the format specification being printed. - - Position specifiers for arguments (%123$), field width (*456$) and - precision (.*789$) are supported. Mixing explicit and implied - positions for arguments/widths/precisions is discouraged, although - it does produce deterministic behaviour. - - The following format flags are recognised: - - "#": alternate format - sets showbase/showpoint, and also - boolalpha for bool with s conversion - - "0": pad with zeroes rather than spaces, ignored if '-' flag is - specified or if precision is specified for d/i/u/o/x/X - conversion - - "-": left-align output, overrides '0' - - " ": recognised but not implemented, ignored for u/o/x/X - conversion - - "+": show sign for positive numbers, overrides ' ', ignored for - u/o/x/X conversions - - "'": recognised for SUS compatibility but ignored (digit grouping - is controlled by stream locale) - - "I": recognised for glibc compatibility but ignored (digits are - controlled by stream locale) - - Precision is supported for conversions by setting precision on the - stream. This works as expected for a/A/e/E/f/F/g/G conversions on - floating-point types, and may work for objects with user-defined - stream output operators. Precision for d/i/u/o/x/X conversions - (minimum digits to print) is not supported. Precision for s - conversions (maximum characters to print) is only honoured for - string-like types (output character pointer/array and - std::basic_string). - - Length specifiers are supported but not required for d/i/u/o/x/X - conversions with integer/char/bool arguments. They result in the - value being cast to the desired type before being printed. Length - specifiers are ignored for other conversions. - - The following length specifiers are recognised: - - hh: cast to char/unsigned char for d/i/u/o/x/X - - h: cast to short/unsigned short for d/i/u/o/x/X - - l: cast to long/unsigned long for d/i/u/o/x/X - - ll: cast to long long/unsigned long long for d/i/u/o/x/X - - L: always ignored - - j: cast to intmax_t/uintmax_t for d/i/u/o/x/X - - z: cast to ssize_t/size_t for d/i/u/o/x/X - - t: cast to ptrdiff_t for d/i/u/o/x/X - - I: cast to ssize_t/size_t for d/i/u/o/x/X - - I32: cast to int32_t/uint32_t for d/i/u/o/x/X - - I64: cast to int64_t/uint64_t for d/i/u/o/x/X - - w: always ignored - - The following conversions are recognised: - - d/i: signed decimal for integer/char/bool types - - u: unsigned decimal for integer/char/bool types - - o: unsigned octal for integer/char/bool types - - x/X: lower/uppercase unsigned hexadecimal for integer/char/bool - types or scientific hexadecimal for floating-point types - - e/E: lower/uppercase scientific decimal for floating-point types - - f/F: lower/uppercase fixed-point decimal for floating-point types - - g/G: default stream output format for floating-point types (may - differ from printf behaviour) - - a/A: lower/uppercase scientific hexadecimal for floating-point - types or hexadecimal for integer types - - c/C: cast integer types to stream's character type, no automatic - widening or narrowing - - s/S: default stream output behaviour for argument - - p/P: cast any integer/char/bool/pointer/array to void const * - - n: store characters printed so far, produces no output, argument - must be pointer to type that std::streamoff is convertible to - - m: output of std::strerror(errno), no automatic widening or - narrowing, does not consume an argument - - %: literal %, field width applied, does not consume an argument - - The output stream type for stream_format must be equivalent to a - std::basic_ostream for duck-typing purposes. The output string for - string type for string_format must provide value_type, traits_type - and allocator_type declarations, and must be constructible from a - std::basic_string using the same value, traits and allocator types. - - The format string type can be a pointer to a NUL-terminated string, - an array containing a NUL-terminated or non-terminated string, or a - STL contiguous container holding a string (e.g. std::string, - std::string_view, std::vector or std::array). Note that NUL - characters characters are only treated as terminators for pointers - and arrays, they are treated as normal characters for other - containers. Using a non-contiguous container (e.g. std::list or - std::deque) will result in undesirable behaviour likely culminating - in a crash. - - The value type of the format string and the character type of the - output stream/string need to match. You can't use a wchar_t format - to format char output and vice versa. - - The format string encoding must have contiguous decimal digits. The - character encoding must not use shift states or multi-byte sequences - that could result in a format character codepoint appearing as part - of a multi-byte sequence or being interpreted differently. ASCII, - ISO Latin, KOI-8, UTF-8, EUC, EBCDIC, and UTF-EBCDIC encodings meet - these requirements, while ISO-2022, UTF-7, KOI-7 and Shift-JIS - encodings do not. For character types other than char and wchar_t, - the encoding must be a strict superset of the char encoding. - - The following conditions cause assertion failures in debug builds: - - Unsupported conversion specifier - - Out-of-range argument/width/precision position - - Inappropriate type for parameterised width/precision - - Positional width/precision specifier not terminated with $ - - Inappropriate type for n conversion - - Default conversion for type that lacks stream out operator - - Some limitations have been described in passing. Major limitations - and bugs include: - - No automatic widening/narrowing support, so no simple way to - output wide characters/strings to narrow streams/strings and vice - versa. - - Precision ignored for d/i/u/o/x/X conversions (should set minimum - digits to print). - - Precision for s/S conversion is only honoured for string-like - types (output character pointer/array and std::basic_string). - - If the output character type is not char, signed char or unsgined - char, printing the a value of this type with d/i/u/o/x/X - conversion and no length specifier causes it to be printed as a - character. Can be worked around by casting to another integer - type or using length specifier. - - Printing with d/i/u/o/x/X conversions may not behave as expected - if the output character type is an integer type other than char, - signed char, unsigned char, or wchar_t. - - Only output character pointer/array is treated as a C string, any - other pointer/array will be printed as a pointer value. The - signed/unsigned/default char are not handled equivalently. - - There is no length specifier to force cast to int/unsigned. Can - be worked around by casting the argument. - - MSVCRT length specifiers I/I32/I64 will not be recognised if no - width or precision is specified, as they will be mistaken for - glibc alternate digits flag. - - The " " flag to prefix positive numbers with a space is not - implemented. - - The "'" and "I" flags are not implemented, as digit grouping and - characters are controlled by the output stream's locale. - - The characters used for space- and zero-padding are not locale- - aware. - -***************************************************************************/ - -#ifndef MAME_UTIL_STRFORMAT_H -#define MAME_UTIL_STRFORMAT_H - -#pragma once - -#include "vecstream.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace util { - -namespace detail { - -//************************************************************************** -// FORMAT CHARACTER DEFINITIONS -//************************************************************************** - -template -class format_chars -{ -public: - typedef Character char_type; - enum : Character { - nul = Character('\0'), - space = Character(' '), - point = Character('.'), - percent = Character('%'), - dollar = Character('$'), - hash = Character('#'), - minus = Character('-'), - plus = Character('+'), - asterisk = Character('*'), - quote = Character('\''), - zero = Character('0'), - nine = Character('9'), - a = Character('a'), - A = Character('A'), - c = Character('c'), - C = Character('C'), - d = Character('d'), - e = Character('e'), - E = Character('E'), - f = Character('f'), - F = Character('F'), - g = Character('g'), - G = Character('G'), - h = Character('h'), - i = Character('i'), - I = Character('I'), - j = Character('j'), - l = Character('l'), - L = Character('L'), - m = Character('m'), - n = Character('n'), - o = Character('o'), - p = Character('p'), - s = Character('s'), - S = Character('S'), - t = Character('t'), - u = Character('u'), - w = Character('w'), - x = Character('x'), - X = Character('X'), - z = Character('z') - }; -}; - -template <> -class format_chars -{ -public: - typedef wchar_t char_type; - enum : wchar_t { - nul = L'\0', - space = L' ', - point = L'.', - percent = L'%', - dollar = L'$', - hash = L'#', - minus = L'-', - plus = L'+', - asterisk = L'*', - quote = L'\'', - zero = L'0', - nine = L'9', - a = L'a', - A = L'A', - c = L'c', - C = L'C', - d = L'd', - e = L'e', - E = L'E', - f = L'f', - F = L'F', - g = L'g', - G = L'G', - h = L'h', - i = L'i', - I = L'I', - j = L'j', - l = L'l', - L = L'L', - m = L'm', - n = L'n', - o = L'o', - p = L'p', - s = L's', - S = L'S', - t = L't', - u = L'u', - w = L'w', - x = L'x', - X = L'X', - z = L'z' - }; -}; - - -//************************************************************************** -// FORMAT SPECIFIER ENCAPSULATION -//************************************************************************** - -class format_flags -{ -public: - enum class positive_sign { - none, - space, // ' ' - plus // + - }; - - enum class length { - unspecified, - character, // hh - short_integer, // h - long_integer, // l - long_long_integer, // ll - long_double, // L - integer_maximum, // j - size_type, // z, I - pointer_difference, // t - integer_32, // I32 - integer_64, // I64 - wide_character // w - }; - - enum class conversion { - unspecified, - signed_decimal, // i, d - unsigned_decimal, // u - octal, // o - hexadecimal, // x, X - scientific_decimal, // e, E - fixed_decimal, // f, F - floating_decimal, // g, G - scientific_hexadecimal, // a, A - character, // c, C - string, // s, S - pointer, // p - tell, // n - strerror, // m - percent // % - }; - - format_flags() - : m_alternate_format(false) - , m_zero_pad(false) - , m_left_align(false) - , m_positive_sign(positive_sign::none) - , m_digit_grouping(false) - , m_alternate_digits(false) - , m_field_width(0) - , m_precision(-1) - , m_length(length::unspecified) - , m_uppercase(false) - , m_conversion(conversion::unspecified) - { - } - - template void apply(Stream &stream) const - { - typedef format_chars chars; - - stream.unsetf( - Stream::basefield | - Stream::adjustfield | - Stream::floatfield | - Stream::boolalpha | - Stream::showbase | - Stream::showpoint | - Stream::showpos | - Stream::uppercase); - - if (get_alternate_format()) stream.setf(Stream::showbase | Stream::showpoint); - stream.fill(get_zero_pad() ? chars::zero : chars::space); - stream.setf(get_left_align() ? Stream::left : get_zero_pad() ? Stream::internal : Stream::right); - if (positive_sign::plus == get_positive_sign()) stream.setf(Stream::showpos); - stream.precision((get_precision() < 0) ? 6 : get_precision()); - stream.width(get_field_width()); - if (get_uppercase()) stream.setf(Stream::uppercase); - switch (get_conversion()) - { - case conversion::unspecified: - break; - case conversion::signed_decimal: - case conversion::unsigned_decimal: - stream.setf(Stream::dec); - break; - case conversion::octal: - stream.setf(Stream::oct); - break; - case conversion::hexadecimal: - stream.setf(Stream::hex | Stream::scientific | Stream::fixed); - break; - case conversion::scientific_decimal: - stream.setf(Stream::dec | Stream::scientific); - break; - case conversion::fixed_decimal: - stream.setf(Stream::dec | Stream::fixed); - break; - case conversion::floating_decimal: - stream.setf(Stream::dec); - break; - case conversion::scientific_hexadecimal: - stream.setf(Stream::hex | Stream::scientific | Stream::fixed); - break; - case conversion::character: - case conversion::string: - case conversion::pointer: - case conversion::tell: - case conversion::strerror: - case conversion::percent: - break; - } - } - - bool get_alternate_format() const { return m_alternate_format; } - bool get_zero_pad() const { return m_zero_pad; } - bool get_left_align() const { return m_left_align; } - positive_sign get_positive_sign() const { return m_positive_sign; } - bool get_digit_grouping() const { return m_digit_grouping; } - bool get_alternate_digits() const { return m_alternate_digits; } - unsigned get_field_width() const { return m_field_width; } - int get_precision() const { return m_precision; } - length get_length() const { return m_length; } - bool get_uppercase() const { return m_uppercase; } - conversion get_conversion() const { return m_conversion; } - - void set_alternate_format() - { - m_alternate_format = true; - } - - void set_zero_pad() - { - if (!m_left_align) - { - switch (m_conversion) - { - case conversion::signed_decimal: - case conversion::unsigned_decimal: - case conversion::octal: - case conversion::hexadecimal: - m_zero_pad = (0 > m_precision); - break; - default: - m_zero_pad = true; - } - } - } - - void set_left_align() - { - m_zero_pad = false; - m_left_align = true; - } - - void set_positive_sign_space() - { - switch (m_conversion) - { - case conversion::unsigned_decimal: - case conversion::octal: - case conversion::hexadecimal: - break; - default: - if (positive_sign::plus != m_positive_sign) - m_positive_sign = positive_sign::space; - } - } - - void set_positive_sign_plus() - { - switch (m_conversion) - { - case conversion::unsigned_decimal: - case conversion::octal: - case conversion::hexadecimal: - break; - default: - m_positive_sign = positive_sign::plus; - } - } - - void set_digit_grouping() - { - m_digit_grouping = true; - } - - void set_alternate_digits() - { - m_alternate_digits = true; - } - - void set_field_width(int value) - { - if (0 > value) - { - set_left_align(); - m_field_width = unsigned(-value); - } - else - { - m_field_width = unsigned(value); - } - } - - void set_precision(int value) - { - m_precision = value; - if (0 <= value) - { - switch (m_conversion) - { - case conversion::signed_decimal: - case conversion::unsigned_decimal: - case conversion::octal: - case conversion::hexadecimal: - m_zero_pad = false; - break; - default: - break; - } - } - } - - void set_length(length value) - { - m_length = value; - } - - void set_uppercase() - { - m_uppercase = true; - } - - void set_conversion(conversion value) - { - m_conversion = value; - switch (value) - { - case conversion::unsigned_decimal: - case conversion::octal: - case conversion::hexadecimal: - m_positive_sign = positive_sign::none; - [[fallthrough]]; - case conversion::signed_decimal: - if (0 <= m_precision) - m_zero_pad = false; - break; - default: - break; - } - } - -private: - bool m_alternate_format; // # - bool m_zero_pad; // 0 - bool m_left_align; // - - positive_sign m_positive_sign; // ' ', + - bool m_digit_grouping; // ' - bool m_alternate_digits; // I - unsigned m_field_width; - int m_precision; // . - length m_length; // hh, h, l, ll, L, j, z, I, t, w - bool m_uppercase; // X, E, F, G, A - conversion m_conversion; // i, d, u, o, x, X, e, E, f, F, g, G, a, A, c, C, s, S, p, m, % -}; - - -//************************************************************************** -// FORMAT OUTPUT HELPERS -//************************************************************************** - -template -class format_output -{ -private: - template - struct string_semantics : public std::false_type { }; - template - struct string_semantics > : public std::true_type { }; - template - struct string_semantics > : public std::true_type { }; - template - using signed_integer_semantics = std::bool_constant && std::is_signed_v >; - template - using unsigned_integer_semantics = std::bool_constant && !std::is_signed_v >; - - template - static std::enable_if_t, std::make_signed_t > || std::is_integral_v > apply_signed(Stream &str, U const &value) - { - if constexpr (std::is_same_v, std::make_signed_t >) - str << int(std::make_signed_t(value)); - else if constexpr (!std::is_signed_v || std::is_same_v) - str << std::make_signed_t(value); -#if __cplusplus > 201703L - else if constexpr (!std::is_invocable_v decltype(x << y) { return x << y; }), Stream &, U const &>) - str << std::make_signed_t(value); -#endif - else - str << value; - } - - template - static std::enable_if_t, std::make_unsigned_t > || std::is_integral_v > apply_unsigned(Stream &str, U const &value) - { - if constexpr (std::is_same_v, std::make_unsigned_t >) - str << unsigned(std::make_unsigned_t(value)); - else if constexpr (!std::is_unsigned_v || std::is_same_v) - str << std::make_unsigned_t(value); -#if __cplusplus > 201703L - else if constexpr (!std::is_invocable_v decltype(x << y) { return x << y; }), Stream &, U const &>) - str << std::make_unsigned_t(value); -#endif - else - str << value; - } - -public: - template - static void apply(Stream &str, format_flags const &flags, U const &value) - { - if constexpr (string_semantics::value) - { - int const precision(flags.get_precision()); - if ((0 <= precision) && (value.size() > unsigned(precision))) - { - if constexpr (std::is_same_v) - { - unsigned width(flags.get_field_width()); - bool const pad(unsigned(precision) < width); - typename Stream::fmtflags const adjust(str.flags() & Stream::adjustfield); - if (!pad || (Stream::left == adjust)) str.write(&*value.begin(), unsigned(precision)); - if (pad) - { - for (width -= precision; 0U < width; --width) str.put(str.fill()); - if (Stream::left != adjust) str.write(&*value.begin(), unsigned(precision)); - } - str.width(0); - } - else - { - str << value.substr(0, unsigned(precision)); - } - } - else - { - str << value; - } - } - else if constexpr (signed_integer_semantics::value) - { - switch (flags.get_conversion()) - { - case format_flags::conversion::signed_decimal: - switch (flags.get_length()) - { - case format_flags::length::character: - str << int(static_cast(value)); - break; - case format_flags::length::short_integer: - str << short(value); - break; - case format_flags::length::long_integer: - str << long(value); - break; - case format_flags::length::long_long_integer: - str << static_cast(value); - break; - case format_flags::length::integer_maximum: - str << std::intmax_t(value); - break; - case format_flags::length::size_type: - str << std::make_signed_t(value); - break; - case format_flags::length::pointer_difference: - str << std::make_signed_t(value); - break; - case format_flags::length::integer_32: - str << std::uint32_t(std::int32_t(value)); - break; - case format_flags::length::integer_64: - str << std::int64_t(value); - break; - default: - apply_signed(str, value); - } - break; - case format_flags::conversion::unsigned_decimal: - case format_flags::conversion::octal: - case format_flags::conversion::hexadecimal: - switch (flags.get_length()) - { - case format_flags::length::character: - str << unsigned(static_cast(static_cast(value))); - break; - case format_flags::length::short_integer: - str << static_cast(short(value)); - break; - case format_flags::length::long_integer: - str << static_cast(long(value)); - break; - case format_flags::length::long_long_integer: - str << static_cast(static_cast(value)); - break; - case format_flags::length::integer_maximum: - str << std::uintmax_t(std::intmax_t(value)); - break; - case format_flags::length::size_type: - str << std::make_unsigned_t(std::make_signed_t(value)); - break; - case format_flags::length::pointer_difference: - str << std::make_unsigned_t(std::make_signed_t(value)); - break; - case format_flags::length::integer_32: - str << std::uint32_t(std::int32_t(value)); - break; - case format_flags::length::integer_64: - str << std::uint64_t(std::int64_t(value)); - break; - default: - apply_unsigned(str, value); - } - break; - case format_flags::conversion::character: - if (std::is_signed::value) - str << typename Stream::char_type(value); - else - str << typename Stream::char_type(std::make_signed_t(value)); - break; - case format_flags::conversion::pointer: - str << reinterpret_cast(std::uintptr_t(std::intptr_t(value))); - break; - default: - str << value; - } - } - else if constexpr (unsigned_integer_semantics::value) - { - switch (flags.get_conversion()) - { - case format_flags::conversion::signed_decimal: - switch (flags.get_length()) - { - case format_flags::length::character: - str << int(static_cast(static_cast(value))); - break; - case format_flags::length::short_integer: - str << short(static_cast(value)); - break; - case format_flags::length::long_integer: - str << long(static_cast(value)); - break; - case format_flags::length::long_long_integer: - str << static_cast(static_cast(value)); - break; - case format_flags::length::integer_maximum: - str << std::intmax_t(std::uintmax_t(value)); - break; - case format_flags::length::size_type: - str << std::make_signed_t(std::make_unsigned_t(value)); - break; - case format_flags::length::pointer_difference: - str << std::make_signed_t(std::make_unsigned_t(value)); - break; - case format_flags::length::integer_32: - str << std::int32_t(std::uint32_t(value)); - break; - case format_flags::length::integer_64: - str << std::int64_t(std::uint64_t(value)); - break; - default: - apply_signed(str, value); - } - break; - case format_flags::conversion::unsigned_decimal: - case format_flags::conversion::octal: - case format_flags::conversion::hexadecimal: - switch (flags.get_length()) - { - case format_flags::length::character: - str << unsigned(static_cast(value)); - break; - case format_flags::length::short_integer: - str << static_cast(value); - break; - case format_flags::length::long_integer: - str << static_cast(value); - break; - case format_flags::length::long_long_integer: - str << static_cast(value); - break; - case format_flags::length::integer_maximum: - str << std::uintmax_t(value); - break; - case format_flags::length::size_type: - str << std::make_unsigned_t(value); - break; - case format_flags::length::pointer_difference: - str << std::make_unsigned_t(value); - break; - case format_flags::length::integer_32: - str << std::uint32_t(std::int32_t(value)); - break; - case format_flags::length::integer_64: - str << std::int64_t(value); - break; - default: - apply_unsigned(str, value); - } - break; - case format_flags::conversion::character: - if (std::is_signed::value) - str << typename Stream::char_type(value); - else - str << typename Stream::char_type(std::make_signed_t(value)); - break; - case format_flags::conversion::pointer: - str << reinterpret_cast(std::uintptr_t(value)); - break; - default: -#if __cplusplus > 201703L - if constexpr (!std::is_invocable_v decltype(x << y) { return x << y; }), Stream &, U const &>) - { - assert(false); // stream out operator not declared or declared deleted - str << '?'; - } - else -#endif - { - str << value; - } - } - } - else - { - str << value; - } - } - static void apply(Stream &str, format_flags const &flags, bool value) - { - switch (flags.get_conversion()) - { - case format_flags::conversion::signed_decimal: - case format_flags::conversion::unsigned_decimal: - case format_flags::conversion::octal: - case format_flags::conversion::hexadecimal: - case format_flags::conversion::scientific_decimal: - case format_flags::conversion::fixed_decimal: - case format_flags::conversion::floating_decimal: - case format_flags::conversion::scientific_hexadecimal: - case format_flags::conversion::character: - case format_flags::conversion::pointer: - apply(str, flags, unsigned(value)); - break; - default: - if (flags.get_alternate_format()) str.setf(Stream::boolalpha); - str << value; - } - } -}; - -template -class format_output -{ -protected: - template - using string_semantics = std::bool_constant, typename Stream::char_type> >; - -public: - template - static void apply(Stream &str, format_flags const &flags, U const *value) - { - if constexpr (string_semantics::value) - { - switch (flags.get_conversion()) - { - case format_flags::conversion::string: - { - int precision(flags.get_precision()); - if (0 <= flags.get_precision()) - { - std::streamsize cnt(0); - for ( ; (0 < precision) && (U(format_chars::nul) != value[cnt]); --precision, ++cnt) { } - unsigned width(flags.get_field_width()); - bool const pad(std::make_unsigned_t(cnt) < width); - typename Stream::fmtflags const adjust(str.flags() & Stream::adjustfield); - if (!pad || (Stream::left == adjust)) str.write(value, cnt); - if (pad) - { - for (width -= cnt; 0U < width; --width) str.put(str.fill()); - if (Stream::left != adjust) str.write(value, cnt); - } - str.width(0); - } - else - { - str << value; - } - } - break; - case format_flags::conversion::pointer: - str << reinterpret_cast(const_cast *>(value)); - break; - default: - str << value; - } - } - else - { - str << reinterpret_cast(const_cast *>(value)); - } - } -}; - -template -class format_output : protected format_output -{ -public: - template - static void apply(Stream &str, format_flags const &flags, U const *value) - { - static_assert( - !format_output::template string_semantics::value || (N <= size_t(unsigned((std::numeric_limits::max)()))), - "C string array length must not exceed maximum integer value"); - format_flags f(flags); - if (format_output::template string_semantics::value && ((0 > f.get_precision()) || (N < unsigned(f.get_precision())))) - f.set_precision(int(unsigned(N))); - format_output::apply(str, f, value); - } -}; - - -//************************************************************************** -// INTEGER INPUT HELPERS -//************************************************************************** - -template -class format_make_integer -{ -private: - template - using use_unsigned_cast = std::bool_constant && std::is_unsigned_v >; - template - using use_signed_cast = std::bool_constant::value && std::is_convertible_v >; - -public: - template static bool apply(U const &value, int &result) - { - if constexpr (use_unsigned_cast::value) - { - result = int(unsigned(value)); - return true; - } - else if constexpr (use_signed_cast::value) - { - result = int(value); - return true; - } - else - { - return false; - } - } -}; - - -//************************************************************************** -// INTEGER OUTPUT HELPERS -//************************************************************************** - -template -class format_store_integer -{ -private: - template - using is_non_const_ptr = std::bool_constant && !std::is_const_v > >; - template - using is_unsigned_ptr = std::bool_constant && std::is_unsigned_v > >; - template - using use_unsigned_cast = std::bool_constant::value && is_unsigned_ptr::value && std::is_convertible_v, std::remove_pointer_t > >; - template - using use_signed_cast = std::bool_constant::value && !use_unsigned_cast::value && std::is_convertible_v > >; - -public: - template static bool apply(U const &value, std::streamoff data) - { - if constexpr (use_unsigned_cast::value) - { - *value = std::remove_pointer_t(std::make_unsigned_t(data)); - return true; - } - else if constexpr (use_signed_cast::value) - { - *value = std::remove_pointer_t(std::make_signed_t(data)); - return true; - } - else - { - assert(false); // inappropriate type for storing characters written so far - return false; - } - } -}; - - -//************************************************************************** -// NON-POLYMORPHIC ARGUMENT WRAPPER -//************************************************************************** - -template -class format_argument -{ -public: - format_argument() - : m_value(nullptr) - , m_output_function(nullptr) - , m_make_integer_function(nullptr) - , m_store_integer_function(nullptr) - { - } - - template - format_argument(T const &value) - : m_value(reinterpret_cast(&value)) - , m_output_function(&static_output) - , m_make_integer_function(&static_make_integer) - , m_store_integer_function(&static_store_integer) - { - } - - void output(Stream &str, format_flags const &flags) const { m_output_function(str, flags, m_value); } - bool make_integer(int &result) const { return m_make_integer_function(m_value, result); } - void store_integer(std::streamoff data) const { m_store_integer_function(m_value, data); } - -private: - typedef void (*output_function)(Stream &str, format_flags const &flags, void const *value); - typedef bool (*make_integer_function)(void const *value, int &result); - typedef void (*store_integer_function)(void const *value, std::streamoff data); - - template static void static_output(Stream &str, format_flags const &flags, void const *value) - { - format_output::apply(str, flags, *reinterpret_cast(value)); - } - - template static bool static_make_integer(void const *value, int &result) - { - return format_make_integer::apply(*reinterpret_cast(value), result); - } - - template static void static_store_integer(void const *value, std::streamoff data) - { - format_store_integer::apply(*reinterpret_cast(value), data); - } - - void const *m_value; - output_function m_output_function; - make_integer_function m_make_integer_function; - store_integer_function m_store_integer_function; -}; - - -//************************************************************************** -// NON-POLYMORPHIC ARGUMENT PACK WRAPPER BASE -//************************************************************************** - -template -class format_argument_pack -{ -public: - typedef typename Stream::char_type char_type; - typedef char_type const *iterator; - iterator format_begin() const - { - return m_begin; - } - bool format_at_end(iterator it) const - { - return (m_end && (m_end == it)) || (m_check_nul && (format_chars::nul == *it)); - } - std::size_t argument_count() const - { - return m_argument_count; - } - format_argument const &operator[](std::size_t index) const - { - assert(m_argument_count > index); - return m_arguments[index]; - } - -protected: - template - using handle_char_ptr = std::bool_constant && std::is_same_v >, char_type> >; - template - using handle_char_array = std::bool_constant && std::is_same_v >, char_type> >; - template - using handle_container = std::bool_constant::value && !handle_char_array::value>; - - template - format_argument_pack( - Format &&fmt, - format_argument const *arguments, - std::enable_if_t >::value, std::size_t> argument_count) - : m_begin(fmt) - , m_end(nullptr) - , m_check_nul(true) - , m_arguments(arguments) - , m_argument_count(argument_count) - { - assert(m_begin); - assert(m_end || m_check_nul); - assert(!m_end || (m_end > m_begin)); - assert(m_arguments || !m_argument_count); - } - template - format_argument_pack( - Format &&fmt, - format_argument const *arguments, - std::enable_if_t >::value, std::size_t> argument_count) - : m_begin(std::cbegin(fmt)) - , m_end(std::cend(fmt)) - , m_check_nul(true) - , m_arguments(arguments) - , m_argument_count(argument_count) - { - assert(m_begin); - assert(m_end || m_check_nul); - assert(!m_end || (m_end > m_begin)); - assert(m_arguments || !m_argument_count); - } - template - format_argument_pack( - Format &&fmt, - format_argument const *arguments, - std::enable_if_t >::value, std::size_t> argument_count) - : m_begin(fmt.empty() ? nullptr : &*std::cbegin(fmt)) - , m_end(fmt.empty() ? nullptr : (m_begin + std::distance(std::cbegin(fmt), std::cend(fmt)))) - , m_check_nul(true) - , m_arguments(arguments) - , m_argument_count(argument_count) - { - assert(m_begin); - assert(m_end || m_check_nul); - assert(!m_end || (m_end > m_begin)); - assert(m_arguments || !m_argument_count); - } - - format_argument_pack(format_argument_pack const &) = default; - format_argument_pack(format_argument_pack &&) = default; - format_argument_pack &operator=(format_argument_pack const &) = default; - format_argument_pack &operator=(format_argument_pack &&) = default; - -private: - iterator m_begin; - iterator m_end; - bool m_check_nul; - format_argument const *m_arguments; - std::size_t m_argument_count; -}; - - -//************************************************************************** -// ARGUMENT PACK WRAPPER IMPLEMENTATION -//************************************************************************** - -template -class format_argument_pack_impl - : private std::array, Count> - , public format_argument_pack -{ -public: - using typename format_argument_pack::iterator; - using format_argument_pack::operator[]; - - template - format_argument_pack_impl(Format &&fmt, Params &&... args) - : std::array, Count>({ { format_argument(std::forward(args))... } }) - , format_argument_pack(std::forward(fmt), Count ? &*this->cbegin() : nullptr, Count) - { - static_assert(sizeof...(Params) == Count, "Wrong number of constructor arguments"); - } - - format_argument_pack_impl(format_argument_pack_impl const &) = default; - format_argument_pack_impl(format_argument_pack_impl &&) = default; - format_argument_pack_impl &operator=(format_argument_pack_impl const &) = default; - format_argument_pack_impl &operator=(format_argument_pack_impl &&) = default; -}; - - -//************************************************************************** -// ARGUMENT PACK CREATOR FUNCTION -//************************************************************************** - -template -inline format_argument_pack_impl make_format_argument_pack(Format &&fmt, Params &&... args) -{ - return format_argument_pack_impl(std::forward(fmt), std::forward(args)...); -} - - -//************************************************************************** -// FORMAT STRING PARSING HELPER -//************************************************************************** - -template -class format_helper : public format_chars -{ -public: - static bool parse_format( - Format const &fmt, - typename Format::iterator &it, - format_flags &flags, - int &next_position, - int &argument_position, - int &width_position, - int &precision_position) - { - static_assert((format_helper::nine - format_helper::zero) == 9, "Digits must be contiguous"); - assert(!fmt.format_at_end(it)); - assert(format_helper::percent == *it); - - int num; - int nxt(next_position); - ++it; - flags = format_flags(); - argument_position = -1; - width_position = -1; - precision_position = -1; - - // Leading zeroes are tricky - they could be a zero-pad flag or part of a position specifier - bool const leading_zero(!fmt.format_at_end(it) && (format_helper::zero == *it)); - while (!fmt.format_at_end(it) && (format_helper::zero == *it)) ++it; - - // Digits encountered at this point could be a field width or a position specifier - num = 0; - bool leading_num(have_digit(fmt, it)); - while (have_digit(fmt, it)) add_digit(num, *it++); - if (leading_num && !have_dollar(fmt, it)) - { - // No dollar sign, leading number is field width - if (leading_zero) flags.set_zero_pad(); - flags.set_field_width(num); - } - else - { - // If we hit a dollar sign after a number, that's a position specifier - if ((leading_zero || leading_num) && have_dollar(fmt, it)) - { - argument_position = num; - ++it; - } - else if (leading_zero) - { - flags.set_zero_pad(); - } - - // Parse flag characters - while (!fmt.format_at_end(it)) - { - switch (*it) - { - case format_helper::hash: ++it; flags.set_alternate_format(); continue; - case format_helper::zero: ++it; flags.set_zero_pad(); continue; - case format_helper::minus: ++it; flags.set_left_align(); continue; - case format_helper::space: ++it; flags.set_positive_sign_space(); continue; - case format_helper::plus: ++it; flags.set_positive_sign_plus(); continue; - case format_helper::quote: ++it; flags.set_digit_grouping(); continue; - case format_helper::I: ++it; flags.set_alternate_digits(); continue; - default: break; - } - break; - } - - // Check for literal or parameterised field width - if (!fmt.format_at_end(it)) - { - if (is_digit(*it)) - { - flags.set_field_width(read_number(fmt, it)); - } - else if (format_helper::asterisk == *it) - { - ++it; - if (have_digit(fmt, it)) - { - num = read_number(fmt, it); - assert(have_dollar(fmt, it)); // invalid positional width - if (!have_dollar(fmt, it)) return false; - width_position = num; - nxt = width_position + 1; - ++it; - } - else - { - width_position = nxt++; - } - } - } - } - - // Check for literal or parameterised precision - if (!fmt.format_at_end(it) && (*it == format_helper::point)) - { - ++it; - if (have_digit(fmt, it)) - { - flags.set_precision(read_number(fmt, it)); - } - else if (!fmt.format_at_end(it) && (format_helper::asterisk == *it)) - { - ++it; - if (have_digit(fmt, it)) - { - num = read_number(fmt, it); - assert(have_dollar(fmt, it)); // invalid positional precision - if (!have_dollar(fmt, it)) return false; - precision_position = num; - nxt = precision_position + 1; - ++it; - } - else - { - precision_position = nxt++; - } - } - else - { - flags.set_precision(0); - } - } - - // Check for length modifiers - if (!fmt.format_at_end(it)) switch (*it) - { - case format_helper::h: - ++it; - if (!fmt.format_at_end(it) && (format_helper::h == *it)) - { - ++it; - flags.set_length(format_flags::length::character); - } - else - { - flags.set_length(format_flags::length::short_integer); - } - break; - case format_helper::l: - ++it; - if (!fmt.format_at_end(it) && (format_helper::l == *it)) - { - ++it; - flags.set_length(format_flags::length::long_long_integer); - } - else - { - flags.set_length(format_flags::length::long_integer); - } - break; - case format_helper::L: - ++it; - flags.set_length(format_flags::length::long_double); - break; - case format_helper::j: - ++it; - flags.set_length(format_flags::length::integer_maximum); - break; - case format_helper::z: - ++it; - flags.set_length(format_flags::length::size_type); - break; - case format_helper::t: - ++it; - flags.set_length(format_flags::length::pointer_difference); - break; - case format_helper::I: - { - ++it; - format_flags::length length = format_flags::length::size_type; - if (!fmt.format_at_end(it)) - { - if ((typename format_helper::char_type(format_helper::zero) + 3) == *it) - { - typename Format::iterator tmp(it); - ++tmp; - if (!fmt.format_at_end(tmp) && ((typename format_helper::char_type(format_helper::zero) + 2) == *tmp)) - { - length = format_flags::length::integer_32; - it = ++tmp; - } - } - else if ((typename format_helper::char_type(format_helper::zero) + 6) == *it) - { - typename Format::iterator tmp(it); - ++tmp; - if (!fmt.format_at_end(tmp) && ((typename format_helper::char_type(format_helper::zero) + 4) == *tmp)) - { - length = format_flags::length::integer_64; - it = ++tmp; - } - } - } - flags.set_length(length); - } - break; - case format_helper::w: - ++it; - flags.set_length(format_flags::length::wide_character); - break; - default: - break; - } - - // Now we should find a conversion specifier - assert(!fmt.format_at_end(it)); // missing conversion - if (fmt.format_at_end(it)) return false; - switch (*it) - { - case format_helper::d: - case format_helper::i: - flags.set_conversion(format_flags::conversion::signed_decimal); - break; - case format_helper::o: - flags.set_conversion(format_flags::conversion::octal); - break; - case format_helper::u: - flags.set_conversion(format_flags::conversion::unsigned_decimal); - break; - case format_helper::X: - flags.set_uppercase(); - [[fallthrough]]; - case format_helper::x: - flags.set_conversion(format_flags::conversion::hexadecimal); - break; - case format_helper::E: - flags.set_uppercase(); - [[fallthrough]]; - case format_helper::e: - flags.set_conversion(format_flags::conversion::scientific_decimal); - break; - case format_helper::F: - flags.set_uppercase(); - [[fallthrough]]; - case format_helper::f: - flags.set_conversion(format_flags::conversion::fixed_decimal); - break; - case format_helper::G: - flags.set_uppercase(); - [[fallthrough]]; - case format_helper::g: - flags.set_conversion(format_flags::conversion::floating_decimal); - break; - case format_helper::A: - flags.set_uppercase(); - [[fallthrough]]; - case format_helper::a: - flags.set_conversion(format_flags::conversion::scientific_hexadecimal); - break; - case format_helper::C: - if (format_flags::length::unspecified == flags.get_length()) - flags.set_length(format_flags::length::long_integer); - [[fallthrough]]; - case format_helper::c: - flags.set_conversion(format_flags::conversion::character); - break; - case format_helper::S: - if (format_flags::length::unspecified == flags.get_length()) - flags.set_length(format_flags::length::long_integer); - [[fallthrough]]; - case format_helper::s: - flags.set_conversion(format_flags::conversion::string); - break; - case format_helper::p: - flags.set_conversion(format_flags::conversion::pointer); - break; - case format_helper::n: - flags.set_conversion(format_flags::conversion::tell); - break; - case format_helper::m: - flags.set_conversion(format_flags::conversion::strerror); - break; - case format_helper::percent: - flags.set_conversion(format_flags::conversion::percent); - break; - default: - assert(false); // unsupported conversion - return false; - } - ++it; - - // Finalise argument position - if (argument_position < 0) argument_position = nxt; - next_position = argument_position; - switch (flags.get_conversion()) - { - case format_flags::conversion::strerror: - case format_flags::conversion::percent: - break; - default: - ++next_position; - } - return true; - } - -private: - static bool have_dollar(Format const &fmt, typename Format::iterator const &it) - { - return !fmt.format_at_end(it) && (*it == format_helper::dollar); - } - - static bool have_digit(Format const &fmt, typename Format::iterator const &it) - { - return !fmt.format_at_end(it) && is_digit(*it); - } - - static bool is_digit(typename format_helper::char_type value) - { - return (format_helper::zero <= value) && (format_helper::nine >= value); - } - - static int digit_value(typename format_helper::char_type value) - { - assert(is_digit(value)); - return int(std::make_signed_t(value - format_helper::zero)); - } - - static void add_digit(int &num, typename format_helper::char_type digit) - { - num = (num * 10) + digit_value(digit); - } - - static int read_number(Format const &fmt, typename Format::iterator &it) - { - assert(have_digit(fmt, it)); - int value = 0; - do add_digit(value, *it++); while (have_digit(fmt, it)); - return value; - } -}; - - -//************************************************************************** -// CORE FORMATTING FUNCTION -//************************************************************************** - -template -typename Stream::off_type stream_format(Stream &str, format_argument_pack const &args) -{ - typedef format_helper > format_helper; - typedef typename format_argument_pack::iterator iterator; - class stream_preserver - { - public: - stream_preserver(Stream &stream) - : m_stream(stream) - , m_fill(stream.fill()) - , m_flags(stream.flags()) - , m_precision(stream.precision()) - , m_width(stream.width()) - { - } - ~stream_preserver() - { - m_stream.width(m_width); - m_stream.precision(m_precision); - m_stream.flags(m_flags); - m_stream.fill(m_fill); - } - private: - Stream &m_stream; - typename Stream::char_type m_fill; - typename Stream::fmtflags m_flags; - std::streamsize m_precision; - std::streamsize m_width; - }; - - typename Stream::pos_type const begin(str.tellp()); - stream_preserver const preserver(str); - int next_pos(1); - iterator start = args.format_begin(); - for (iterator it = start; !args.format_at_end(start); ) - { - while (!args.format_at_end(it) && (format_helper::percent != *it)) ++it; - if (start != it) - { - str.write(&*start, it - start); - start = it; - } - if (!args.format_at_end(it)) - { - // Try to parse a percent format specification - format_flags flags; - int arg_pos, width_pos, prec_pos; - if (!format_helper::parse_format(args, it, flags, next_pos, arg_pos, width_pos, prec_pos)) - continue; - - // Handle parameterised width - if (0 <= width_pos) - { - assert(flags.get_field_width() == 0U); - assert(0 < width_pos); - assert(args.argument_count() >= unsigned(width_pos)); - if ((0 < width_pos) && (args.argument_count() >= unsigned(width_pos))) - { - int width; - if (args[width_pos - 1].make_integer(width)) - { - if (0 > width) - { - flags.set_left_align(); - flags.set_field_width(unsigned(-width)); - } - else - { - flags.set_field_width(unsigned(width)); - } - } - else - { - assert(false); // inappropriate type passed as width argument - } - } - } - - // Handle parameterised precision - if (0 <= prec_pos) - { - assert(flags.get_precision() < 0); - assert(0 < prec_pos); - assert(args.argument_count() >= unsigned(prec_pos)); - if ((0 < prec_pos) && (args.argument_count() >= unsigned(prec_pos))) - { - int precision; - if (args[prec_pos - 1].make_integer(precision)) - flags.set_precision(precision); - else - assert(false); // inappropriate type passed as precision argument - } - } - - // Some conversions don't actually take an argument - get them out of the way - flags.apply(str); - if (format_flags::conversion::strerror == flags.get_conversion()) - { - str << std::strerror(errno); - start = it; - } - else if (format_flags::conversion::percent == flags.get_conversion()) - { - str << typename Stream::char_type(format_chars::percent); - start = it; - } - else - { - assert(0 < arg_pos); - assert(args.argument_count() >= unsigned(arg_pos)); - if ((0 >= arg_pos) || (args.argument_count() < unsigned(arg_pos))) - continue; - if (format_flags::conversion::tell == flags.get_conversion()) - { - typename Stream::pos_type const current(str.tellp()); - args[arg_pos - 1].store_integer( - ((typename Stream::pos_type(-1) == begin) || (typename Stream::pos_type(-1) == current)) - ? typename Stream::off_type(-1) - : (current - begin)); - } - else - { - args[arg_pos - 1].output(str, flags); - } - start = it; - } - } - } - typename Stream::pos_type const end(str.tellp()); - return ((typename Stream::pos_type(-1) == begin) || (typename Stream::pos_type(-1) == end)) - ? typename Stream::off_type(-1) - : (end - begin); -} - -} // namespace detail - - -//************************************************************************** -// FORMAT TO STREAM FUNCTIONS -//************************************************************************** - -template -inline typename Stream::off_type stream_format(Stream &str, Format const &fmt, Params &&... args) -{ - return detail::stream_format(str, detail::make_format_argument_pack(fmt, std::forward(args)...)); -} - -template -inline typename Stream::off_type stream_format(Stream &str, detail::format_argument_pack const &args) -{ - return detail::stream_format(str, args); -} - -template -inline typename Stream::off_type stream_format(Stream &str, detail::format_argument_pack &&args) -{ - return detail::stream_format(str, args); -} - - -//************************************************************************** -// FORMAT TO NEW STRING FUNCTIONS -//************************************************************************** - -template -inline String string_format(Format &&fmt, Params &&... args) -{ - typedef std::basic_ostringstream ostream; - ostream str; - stream_format(str, fmt, std::forward(args)...); - return str.str(); -}; - -template -inline String string_format(std::locale const &locale, Format &&fmt, Params &&... args) -{ - typedef std::basic_ostringstream ostream; - ostream str; - str.imbue(locale); - stream_format(str, fmt, std::forward(args)...); - return str.str(); -}; - -template -inline String string_format(detail::format_argument_pack const &args) -{ - typedef std::basic_ostringstream ostream; - ostream str; - detail::stream_format(str, args); - return str.str(); -}; - -template -inline String string_format(detail::format_argument_pack &&args) -{ - typedef std::basic_ostringstream ostream; - ostream str; - detail::stream_format(str, std::move(args)); - return str.str(); -}; - -template -inline String string_format(std::locale const &locale, detail::format_argument_pack const &args) -{ - typedef std::basic_ostringstream ostream; - ostream str; - str.imbue(locale); - detail::stream_format(str, args); - return str.str(); -}; - -template -inline String string_format(std::locale const &locale, detail::format_argument_pack &&args) -{ - typedef std::basic_ostringstream ostream; - ostream str; - str.imbue(locale); - detail::stream_format(str, std::move(args)); - return str.str(); -}; - - -//************************************************************************** -// CREATING ARGUMENT PACKS -//************************************************************************** - -using detail::format_argument_pack; -using detail::make_format_argument_pack; - -} // namespace util - - -//************************************************************************** -// EXTERNAL TEMPLATE INSTANTIATIONS -//************************************************************************** - -namespace util { - -namespace detail { - -extern template class format_chars; -extern template class format_chars; - -extern template void format_flags::apply(std::ostream &) const; -extern template void format_flags::apply(std::wostream &) const; -extern template void format_flags::apply(std::iostream &) const; -extern template void format_flags::apply(std::wiostream &) const; -extern template void format_flags::apply(std::ostringstream &) const; -extern template void format_flags::apply(std::wostringstream &) const; -extern template void format_flags::apply(std::stringstream &) const; -extern template void format_flags::apply(std::wstringstream &) const; -extern template void format_flags::apply(ovectorstream &) const; -extern template void format_flags::apply(wovectorstream &) const; -extern template void format_flags::apply(vectorstream &) const; -extern template void format_flags::apply(wvectorstream &) const; - -extern template class format_argument; -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::iostream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wiostream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::ostringstream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wostringstream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::stringstream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template void format_argument::static_output(std::wstringstream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(ovectorstream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wovectorstream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(vectorstream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument; -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template void format_argument::static_output(wvectorstream &, format_flags const &, void const *); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template bool format_argument::static_make_integer(void const *, int &); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); -extern template void format_argument::static_store_integer(void const *, std::streamoff); - -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; -extern template class format_argument_pack; - -extern template std::ostream::off_type stream_format(std::ostream &, format_argument_pack const &); -extern template std::wostream::off_type stream_format(std::wostream &, format_argument_pack const &); -extern template std::iostream::off_type stream_format(std::iostream &, format_argument_pack const &); -extern template std::iostream::off_type stream_format(std::iostream &, format_argument_pack const &); -extern template std::wiostream::off_type stream_format(std::wiostream &, format_argument_pack const &); -extern template std::wiostream::off_type stream_format(std::wiostream &, format_argument_pack const &); -extern template std::ostringstream::off_type stream_format(std::ostringstream &, format_argument_pack const &); -extern template std::ostringstream::off_type stream_format(std::ostringstream &, format_argument_pack const &); -extern template std::wostringstream::off_type stream_format(std::wostringstream &, format_argument_pack const &); -extern template std::wostringstream::off_type stream_format(std::wostringstream &, format_argument_pack const &); -extern template std::stringstream::off_type stream_format(std::stringstream &, format_argument_pack const &); -extern template std::stringstream::off_type stream_format(std::stringstream &, format_argument_pack const &); -extern template std::stringstream::off_type stream_format(std::stringstream &, format_argument_pack const &); -extern template std::wstringstream::off_type stream_format(std::wstringstream &, format_argument_pack const &); -extern template std::wstringstream::off_type stream_format(std::wstringstream &, format_argument_pack const &); -extern template std::wstringstream::off_type stream_format(std::wstringstream &, format_argument_pack const &); -extern template ovectorstream::off_type stream_format(ovectorstream &, format_argument_pack const &); -extern template ovectorstream::off_type stream_format(ovectorstream &, format_argument_pack const &); -extern template wovectorstream::off_type stream_format(wovectorstream &, format_argument_pack const &); -extern template wovectorstream::off_type stream_format(wovectorstream &, format_argument_pack const &); -extern template vectorstream::off_type stream_format(vectorstream &, format_argument_pack const &); -extern template vectorstream::off_type stream_format(vectorstream &, format_argument_pack const &); -extern template vectorstream::off_type stream_format(vectorstream &, format_argument_pack const &); -extern template wvectorstream::off_type stream_format(wvectorstream &, format_argument_pack const &); -extern template wvectorstream::off_type stream_format(wvectorstream &, format_argument_pack const &); -extern template wvectorstream::off_type stream_format(wvectorstream &, format_argument_pack const &); - -} // namespace detail - -} // namespace util - -#endif // MAME_UTIL_STRFORMAT_H diff --git a/waterbox/ares64/ares/thirdparty/mame/lib/util/vecstream.h b/waterbox/ares64/ares/thirdparty/mame/lib/util/vecstream.h deleted file mode 100644 index 1af7dd0cd8..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/lib/util/vecstream.h +++ /dev/null @@ -1,408 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -/*************************************************************************** - - vecstream.h - - streams with vector storage - - These types are useful if you want a persistent buffer for formatted - text and you need to use it like a character array or character - pointer, as you get read-only access to it without copying. The - storage is always guaranteed to be contiguous. Writing to the - stream may invalidate pointers to storage. - -***************************************************************************/ - -#ifndef MAME_UTIL_VECSTREAM_H -#define MAME_UTIL_VECSTREAM_H - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace util { - -template , typename Allocator = std::allocator > -class basic_vectorbuf : public std::basic_streambuf -{ -public: - typedef typename std::basic_streambuf::char_type char_type; - typedef typename std::basic_streambuf::int_type int_type; - typedef typename std::basic_streambuf::pos_type pos_type; - typedef typename std::basic_streambuf::off_type off_type; - typedef Allocator allocator_type; - typedef std::vector vector_type; - - basic_vectorbuf(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : std::basic_streambuf(), m_mode(mode), m_storage(), m_threshold(nullptr) - { - setup(); - } - - basic_vectorbuf(vector_type const &content, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : std::basic_streambuf(), m_mode(mode), m_storage(content), m_threshold(nullptr) - { - setup(); - } - - basic_vectorbuf(vector_type &&content, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : std::basic_streambuf(), m_mode(mode), m_storage(std::move(content)), m_threshold(nullptr) - { - setup(); - } - - basic_vectorbuf(basic_vectorbuf const &that) : std::basic_streambuf(that), m_mode(that.m_mode), m_storage(that.m_storage), m_threshold(nullptr) - { - adjust(); - } - - basic_vectorbuf(basic_vectorbuf &&that) : std::basic_streambuf(that), m_mode(that.m_mode), m_storage(std::move(that.m_storage)), m_threshold(that.m_threshold) - { - that.clear(); - } - - vector_type const &vec() const - { - if (m_mode & std::ios_base::out) - { - if (this->pptr() > m_threshold) m_threshold = this->pptr(); - auto const base(this->pbase()); - auto const end(m_threshold - base); - if (m_storage.size() > std::make_unsigned_t(end)) - { - m_storage.resize(std::make_unsigned_t(end)); - assert(&m_storage[0] == base); - auto const put_offset(this->pptr() - base); - const_cast(this)->setp(base, base + put_offset); - const_cast(this)->pbump(put_offset); - } - } - return m_storage; - } - - void vec(const vector_type &content) - { - m_storage = content; - setup(); - } - - void vec(vector_type &&content) - { - m_storage = std::move(content); - setup(); - } - - void clear() - { - m_storage.clear(); - setup(); - } - - void swap(basic_vectorbuf &that) - { - using std::swap; - std::basic_streambuf::swap(that); - swap(m_mode, that.m_mode); - swap(m_storage, that.m_storage); - swap(m_threshold, that.m_threshold); - } - - void reserve(typename vector_type::size_type size) - { - if ((m_mode & std::ios_base::out) && (m_storage.capacity() < size)) - { - m_storage.reserve(size); - adjust(); - } - } - - basic_vectorbuf &operator=(basic_vectorbuf const &that) - { - std::basic_streambuf::operator=(that); - m_mode = that.m_mode; - m_storage = that.m_storage; - m_threshold = that.m_threshold; - adjust(); - return *this; - } - - basic_vectorbuf &operator=(basic_vectorbuf &&that) - { - std::basic_streambuf::operator=(that); - m_mode = that.m_mode; - m_storage = std::move(that.m_storage); - m_threshold = that.m_threshold; - that.clear(); - return *this; - } - -protected: - virtual pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) override - { - bool const in(which & std::ios_base::in); - bool const out(which & std::ios_base::out); - if ((!in && !out) || - (in && out && (std::ios_base::cur == dir)) || - (in && !(m_mode & std::ios_base::in)) || - (out && !(m_mode & std::ios_base::out))) - { - return pos_type(off_type(-1)); - } - maximise_egptr(); - off_type const end((m_mode & std::ios_base::out) ? off_type(m_threshold - this->pbase()) : off_type(m_storage.size())); - switch (dir) - { - case std::ios_base::beg: - break; - case std::ios_base::end: - off += end; - break; - case std::ios_base::cur: - off += off_type(in ? (this->gptr() - this->eback()) : (this->pptr() - this->pbase())); - break; - default: - return pos_type(off_type(-1)); - } - if ((off_type(0) > off) || ((m_mode & std::ios_base::app) && out && (end != off))) return pos_type(off_type(-1)); - if ((out ? off_type(this->epptr() - this->pbase()) : end) < off) return pos_type(off_type(-1)); - if (out) - { - this->setp(this->pbase(), this->epptr()); - this->pbump(off); - if (m_threshold < this->pptr()) m_threshold = this->pptr(); - if (m_mode & std::ios_base::in) - { - if (in) this->setg(this->eback(), this->eback() + off, m_threshold); - else if (this->egptr() < m_threshold) this->setg(this->eback(), this->gptr(), m_threshold); - } - } - else if (in) - { - this->setg(this->eback(), this->eback() + off, this->egptr()); - } - return pos_type(off); - } - - virtual pos_type seekpos(pos_type pos, std::ios_base::openmode which = std::ios_base::in |std:: ios_base::out) override - { - return seekoff(off_type(pos), std::ios_base::beg, which); - } - - virtual int_type underflow() override - { - if (!this->gptr()) return Traits::eof(); - maximise_egptr(); - return (this->gptr() < this->egptr()) ? Traits::to_int_type(*this->gptr()) : Traits::eof(); - } - - virtual int_type overflow(int_type ch = Traits::eof()) override - { - if (!(m_mode & std::ios_base::out)) return Traits::eof(); - if (Traits::eq_int_type(ch, Traits::eof())) return Traits::not_eof(ch); - auto const put_offset(this->pptr() - this->pbase() + 1); - auto const threshold_offset((std::max)(m_threshold - this->pbase(), put_offset)); - m_storage.push_back(Traits::to_char_type(ch)); - m_storage.resize(m_storage.capacity()); - auto const base(&m_storage[0]); - this->setp(base, base + m_storage.size()); - m_threshold = base + threshold_offset; - if (m_mode & std::ios_base::in) this->setg(base, base + (this->gptr() - this->eback()), m_threshold); - this->pbump(int(put_offset)); - return ch; - } - - virtual int_type pbackfail(int_type ch = Traits::eof()) override - { - if (this->gptr() != this->eback()) - { - if (Traits::eq_int_type(ch, Traits::eof())) - { - this->gbump(-1); - return Traits::not_eof(ch); - } - else if (Traits::eq(Traits::to_char_type(ch), this->gptr()[-1])) - { - this->gbump(-1); - return ch; - } - else if (m_mode & std::ios_base::out) - { - this->gbump(-1); - *this->gptr() = Traits::to_char_type(ch); - return ch; - } - } - return Traits::eof(); - } - -private: - void setup() - { - if (m_mode & std::ios_base::out) - { - auto const end(m_storage.size()); - m_storage.resize(m_storage.capacity()); - if (m_storage.empty()) - { - m_threshold = nullptr; - this->setg(nullptr, nullptr, nullptr); - this->setp(nullptr, nullptr); - } - else - { - auto const base(&m_storage[0]); - m_threshold = base + end; - this->setp(base, base + m_storage.size()); - if (m_mode & std::ios_base::in) this->setg(base, base, m_threshold); - } - if (m_mode & (std::ios_base::app | std::ios_base::ate)) this->pbump(int(unsigned(end))); - } - else if (m_storage.empty()) - { - this->setg(nullptr, nullptr, nullptr); - } - else if (m_mode & std::ios_base::in) - { - auto const base(&m_storage[0]); - this->setg(base, base, base + m_storage.size()); - } - } - - void adjust() - { - auto const put_offset(this->pptr() - this->pbase()); - auto const get_offset(this->gptr() - this->eback()); - setup(); - if (m_mode & std::ios_base::out) - { - this->pbump(int(put_offset)); - m_threshold = this->pptr(); - if (m_mode & std::ios_base::in) - { - auto const base(&m_storage[0]); - this->setg(base, base + get_offset, m_threshold); - } - } - else if (m_mode & std::ios_base::in) - { - this->gbump(int(get_offset)); - } - } - - void maximise_egptr() - { - if (m_mode & std::ios_base::out) - { - if (m_threshold < this->pptr()) m_threshold = this->pptr(); - if ((m_mode & std::ios_base::in) && (this->egptr() < m_threshold)) this->setg(this->eback(), this->gptr(), m_threshold); - } - } - - std::ios_base::openmode m_mode; - mutable vector_type m_storage; - mutable CharT *m_threshold; -}; - -template , typename Allocator = std::allocator > -class basic_ivectorstream : public std::basic_istream -{ -public: - typedef typename basic_vectorbuf::vector_type vector_type; - - basic_ivectorstream(std::ios_base::openmode mode = std::ios_base::in) : std::basic_istream(&m_rdbuf), m_rdbuf(mode) { } - basic_ivectorstream(vector_type const &content, std::ios_base::openmode mode = std::ios_base::in) : std::basic_istream(&m_rdbuf), m_rdbuf(content, mode) { } - basic_ivectorstream(vector_type &&content, std::ios_base::openmode mode = std::ios_base::in) : std::basic_istream(&m_rdbuf), m_rdbuf(std::move(content), mode) { } - - basic_vectorbuf *rdbuf() const { return static_cast *>(std::basic_istream::rdbuf()); } - vector_type const &vec() const { return rdbuf()->vec(); } - void vec(const vector_type &content) { rdbuf()->vec(content); } - void vec(vector_type &&content) { rdbuf()->vec(std::move(content)); } - - void swap(basic_ivectorstream &that) { std::basic_istream::swap(that); rdbuf()->swap(*that.rdbuf()); } - -private: - basic_vectorbuf m_rdbuf; -}; - -template , typename Allocator = std::allocator > -class basic_ovectorstream : public std::basic_ostream -{ -public: - typedef typename basic_vectorbuf::vector_type vector_type; - - basic_ovectorstream(std::ios_base::openmode mode = std::ios_base::out) : std::basic_ostream(&m_rdbuf), m_rdbuf(mode) { } - basic_ovectorstream(vector_type const &content, std::ios_base::openmode mode = std::ios_base::out) : std::basic_ostream(&m_rdbuf), m_rdbuf(content, mode) { } - basic_ovectorstream(vector_type &&content, std::ios_base::openmode mode = std::ios_base::out) : std::basic_ostream(&m_rdbuf), m_rdbuf(std::move(content), mode) { } - - basic_vectorbuf *rdbuf() const { return static_cast *>(std::basic_ostream::rdbuf()); } - - vector_type const &vec() const { return rdbuf()->vec(); } - void vec(const vector_type &content) { rdbuf()->vec(content); } - void vec(vector_type &&content) { rdbuf()->vec(std::move(content)); } - basic_ovectorstream &reserve(typename vector_type::size_type size) { rdbuf()->reserve(size); return *this; } - - void swap(basic_ovectorstream &that) { std::basic_ostream::swap(that); rdbuf()->swap(*that.rdbuf()); } - -private: - basic_vectorbuf m_rdbuf; -}; - -template , typename Allocator = std::allocator > -class basic_vectorstream : public std::basic_iostream -{ -public: - typedef typename basic_vectorbuf::vector_type vector_type; - - basic_vectorstream(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : std::basic_iostream(&m_rdbuf), m_rdbuf(mode) { } - basic_vectorstream(vector_type const &content, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : std::basic_iostream(&m_rdbuf), m_rdbuf(content, mode) { } - basic_vectorstream(vector_type &&content, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) : std::basic_iostream(&m_rdbuf), m_rdbuf(std::move(content), mode) { } - - basic_vectorbuf *rdbuf() const { return static_cast *>(std::basic_iostream::rdbuf()); } - - vector_type const &vec() const { return rdbuf()->vec(); } - void vec(const vector_type &content) { rdbuf()->vec(content); } - void vec(vector_type &&content) { rdbuf()->vec(std::move(content)); } - basic_vectorstream &reserve(typename vector_type::size_type size) { rdbuf()->reserve(size); return *this; } - - void swap(basic_vectorstream &that) { std::basic_iostream::swap(that); rdbuf()->swap(*that.rdbuf()); } - -private: - basic_vectorbuf m_rdbuf; -}; - -typedef basic_ivectorstream ivectorstream; -typedef basic_ivectorstream wivectorstream; -typedef basic_ovectorstream ovectorstream; -typedef basic_ovectorstream wovectorstream; -typedef basic_vectorstream vectorstream; -typedef basic_vectorstream wvectorstream; - -template -void swap(basic_vectorbuf &a, basic_vectorbuf &b) { a.swap(b); } - -template -void swap(basic_ivectorstream &a, basic_ivectorstream &b) { a.swap(b); } -template -void swap(basic_ovectorstream &a, basic_ovectorstream &b) { a.swap(b); } -template -void swap(basic_vectorstream &a, basic_vectorstream &b) { a.swap(b); } - -extern template class basic_ivectorstream; -extern template class basic_ivectorstream; -extern template class basic_ovectorstream; -extern template class basic_ovectorstream; -extern template class basic_vectorstream; -extern template class basic_vectorstream; - -} // namespace util - -#endif // MAME_UTIL_VECSTREAM_H diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/includes/n64.h b/waterbox/ares64/ares/thirdparty/mame/mame/includes/n64.h deleted file mode 100644 index 3fa804c8bb..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/includes/n64.h +++ /dev/null @@ -1,470 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -#ifndef MAME_INCLUDES_N64_H -#define MAME_INCLUDES_N64_H - -#pragma once - -#if defined(MAME_RDP) -#include "video/n64.h" - -class running_machine -{ -public: - running_machine(n64_state* state) - : m_state(state), m_rand_seed(0x9d14abd7) - { } - - template DriverClass *driver_data() const; - - u32 rand() - { - m_rand_seed = 1664525 * m_rand_seed + 1013904223; - - // return rotated by 16 bits; the low bits have a short period - // and are frequently used - return (m_rand_seed >> 16) | (m_rand_seed << 16); - } - -private: - n64_state* m_state; - u32 m_rand_seed; // current random number seed -}; - -template <> inline n64_state *running_machine::driver_data() const { return m_state; } - -class n64_state -{ -public: - n64_state(uint32_t* rdram, uint32_t* rsp_dmem, n64_periphs* rcp_periphs) - : m_machine(this), m_rdram(rdram), m_rsp_dmem(rsp_dmem), m_rcp_periphs(rcp_periphs) - { } - - void video_start(); - - // Getters - n64_rdp* rdp() { return m_rdp.get(); } - - running_machine& machine() { return m_machine; } - -protected: - running_machine m_machine; - - uint32_t* m_rdram; - uint32_t* m_rsp_dmem; - - n64_periphs* m_rcp_periphs; - - /* video-related */ - std::unique_ptr m_rdp; -}; - -class n64_periphs -{ -public: - virtual void dp_full_sync() = 0; -}; -#else -#include "cpu/rsp/rsp.h" -#include "cpu/mips/mips3.h" -#include "sound/dmadac.h" -#include "video/n64.h" - -/*----------- driver state -----------*/ - -class n64_rdp; -class n64_periphs; - -class n64_state : public driver_device -{ -public: - n64_state(const machine_config &mconfig, device_type type, const char *tag) - : driver_device(mconfig, type, tag) - , m_vr4300(*this, "maincpu") - , m_rsp(*this, "rsp") - , m_sram(*this, "sram") - , m_rdram(*this, "rdram") - , m_rsp_imem(*this, "rsp_imem") - , m_rsp_dmem(*this, "rsp_dmem") - , m_rcp_periphs(*this, "rcp") - { - } - - virtual void machine_start() override; - virtual void machine_reset() override; - virtual void video_start() override; - void n64_machine_stop(); - - uint32_t screen_update_n64(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); - DECLARE_WRITE_LINE_MEMBER(screen_vblank_n64); - - // Getters - n64_rdp* rdp() { return m_rdp.get(); } - uint32_t* rdram() { return m_rdram; } - uint32_t* sram() { return m_sram; } - -protected: - required_device m_vr4300; - required_device m_rsp; - - optional_shared_ptr m_sram; - required_shared_ptr m_rdram; - required_shared_ptr m_rsp_imem; - required_shared_ptr m_rsp_dmem; - - required_device m_rcp_periphs; - - /* video-related */ - std::unique_ptr m_rdp; -}; - -/*----------- devices -----------*/ - -#define AUDIO_DMA_DEPTH 2 - -struct n64_savable_data_t -{ - uint8_t sram[0x20000]; - uint8_t eeprom[2048]; - uint8_t mempak[2][0x8000]; -}; - -class n64_periphs : public device_t, - public device_video_interface -{ -private: - struct AUDIO_DMA - { - uint32_t address; - uint32_t length; - }; - -public: - // construction/destruction - n64_periphs(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - - uint32_t is64_r(offs_t offset); - void is64_w(offs_t offset, uint32_t data); - uint32_t open_r(offs_t offset); - void open_w(uint32_t data); - uint32_t rdram_reg_r(offs_t offset, uint32_t mem_mask = ~0); - void rdram_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t mi_reg_r(offs_t offset, uint32_t mem_mask = ~0); - void mi_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t vi_reg_r(offs_t offset, uint32_t mem_mask = ~0); - void vi_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t ai_reg_r(offs_t offset, uint32_t mem_mask = ~0); - void ai_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t pi_reg_r(offs_t offset, uint32_t mem_mask = ~0); - void pi_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t ri_reg_r(offs_t offset, uint32_t mem_mask = ~0); - void ri_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t si_reg_r(offs_t offset); - void si_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t dd_reg_r(offs_t offset); - void dd_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t pif_ram_r(offs_t offset, uint32_t mem_mask = ~0); - void pif_ram_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - TIMER_CALLBACK_MEMBER(reset_timer_callback); - TIMER_CALLBACK_MEMBER(vi_scanline_callback); - TIMER_CALLBACK_MEMBER(dp_delay_callback); - TIMER_CALLBACK_MEMBER(ai_timer_callback); - TIMER_CALLBACK_MEMBER(pi_dma_callback); - TIMER_CALLBACK_MEMBER(si_dma_callback); - uint32_t dp_reg_r(offs_t offset, uint32_t mem_mask = ~0); - void dp_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - uint32_t sp_reg_r(offs_t offset); - void sp_reg_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); - void sp_set_status(uint32_t data); - void signal_rcp_interrupt(int interrupt); - void check_interrupts(); - - void dp_full_sync(); - void ai_timer_tick(); - void pi_dma_tick(); - void si_dma_tick(); - void reset_tick(); - void video_update(bitmap_rgb32 &bitmap); - - // Video Interface (VI) registers - uint32_t vi_width; - uint32_t vi_origin; - uint32_t vi_control; - uint32_t vi_blank; - uint32_t vi_hstart; - uint32_t vi_vstart; - uint32_t vi_xscale; - uint32_t vi_yscale; - uint32_t vi_burst; - uint32_t vi_vsync; - uint32_t vi_hsync; - uint32_t vi_leap; - uint32_t vi_intr; - uint32_t vi_vburst; - uint8_t field; - - // nvram-specific for the console - device_t *m_nvram_image; - - n64_savable_data_t m_save_data; - - uint32_t cart_length; - - bool dd_present; - bool disk_present; - bool cart_present; - - // Mouse X2/Y2 for delta position - int mouse_x2[4]; - int mouse_y2[4]; - - void poll_reset_button(bool button); - - uint32_t dp_clock; - -protected: - // device-level overrides - virtual void device_start() override; - virtual void device_reset() override; - -private: - n64_state* m_n64; - address_space *m_mem_map; - required_device m_vr4300; - required_device m_rsp; - required_shared_ptr m_rsp_imem; - required_shared_ptr m_rsp_dmem; - - uint32_t *m_rdram; - uint32_t *m_sram; - - void clear_rcp_interrupt(int interrupt); - - bool reset_held; - emu_timer *reset_timer; - emu_timer *dp_delay_timer; - - uint8_t is64_buffer[0x10000]; - - // Video interface (VI) registers and functions - emu_timer *vi_scanline_timer; - - // Audio Interface (AI) registers and functions - void ai_dma(); - AUDIO_DMA *ai_fifo_get_top(); - void ai_fifo_push(uint32_t address, uint32_t length); - void ai_fifo_pop(); - bool ai_delayed_carry; - - required_device_array ai_dac; - uint32_t ai_dram_addr; - uint32_t ai_len; - uint32_t ai_control; - int ai_dacrate; - int ai_bitrate; - uint32_t ai_status; - - emu_timer *ai_timer; - - AUDIO_DMA ai_fifo[AUDIO_DMA_DEPTH]; - int ai_fifo_wpos; - int ai_fifo_rpos; - int ai_fifo_num; - - // Memory Interface (MI) registers - uint32_t mi_version; - uint32_t mi_interrupt; - uint32_t mi_intr_mask; - uint32_t mi_mode; - - // RDRAM Interface (RI) registers - uint32_t rdram_regs[10]; - uint32_t ri_regs[8]; - - // RSP Interface (SP) registers - void sp_dma(int direction); - - uint32_t sp_mem_addr; - uint32_t sp_dram_addr; - uint32_t sp_mem_addr_start; - uint32_t sp_dram_addr_start; - int sp_dma_length; - int sp_dma_count; - int sp_dma_skip; - uint32_t sp_semaphore; - - // Disk Drive (DD) registers and functions - void dd_set_zone_and_track_offset(); - void dd_update_bm(); - void dd_write_sector(); - void dd_read_sector(); - void dd_read_C2(); - uint32_t dd_buffer[256]; - uint32_t dd_sector_data[64]; - uint32_t dd_ram_seq_data[16]; - uint32_t dd_data_reg; - uint32_t dd_status_reg; - uint32_t dd_track_reg; - uint32_t dd_buf_status_reg; - uint32_t dd_sector_err_reg; - uint32_t dd_seq_status_reg; - uint32_t dd_seq_ctrl_reg; - uint32_t dd_sector_reg; - uint32_t dd_reset_reg; - uint32_t dd_current_reg; - bool dd_bm_reset_held; - bool dd_write; - uint8_t dd_int; - uint8_t dd_start_block; - uint8_t dd_start_sector; - uint8_t dd_sectors_per_block; - uint8_t dd_sector_size; - uint8_t dd_zone; - uint32_t dd_track_offset; - - // Peripheral Interface (PI) registers and functions - emu_timer *pi_dma_timer; - uint32_t pi_dram_addr; - uint32_t pi_cart_addr; - uint32_t pi_rd_len; - uint32_t pi_wr_len; - uint32_t pi_status; - uint32_t pi_bsd_dom1_lat; - uint32_t pi_bsd_dom1_pwd; - uint32_t pi_bsd_dom1_pgs; - uint32_t pi_bsd_dom1_rls; - uint32_t pi_bsd_dom2_lat; - uint32_t pi_bsd_dom2_pwd; - uint32_t pi_bsd_dom2_pgs; - uint32_t pi_bsd_dom2_rls; - uint32_t pi_dma_dir; - - // Serial Interface (SI) registers and functions - emu_timer *si_dma_timer; - void pif_dma(int direction); - void handle_pif(); - int pif_channel_handle_command(int channel, int slength, uint8_t *sdata, int rlength, uint8_t *rdata); - uint8_t calc_mempak_crc(uint8_t *buffer, int length); - uint8_t pif_ram[0x40]; - uint8_t pif_cmd[0x40]; - uint32_t si_dram_addr; - uint32_t si_pif_addr; - uint32_t si_pif_addr_rd64b; - uint32_t si_pif_addr_wr64b; - uint32_t si_status_val; - uint32_t si_dma_dir; - uint32_t cic_status; - int cic_type; - - n64_savable_data_t savable_data; - - // Video Interface (VI) functions - void vi_recalculate_resolution(); - void video_update16(bitmap_rgb32 &bitmap); - void video_update32(bitmap_rgb32 &bitmap); - uint8_t random_seed; // %HACK%, adds 19 each time it's read and is more or less random - uint8_t get_random() { return random_seed += 0x13; } - - int32_t m_gamma_table[256]; - int32_t m_gamma_dither_table[0x4000]; - -}; - -// device type definition -DECLARE_DEVICE_TYPE(N64PERIPH, n64_periphs) -#endif - -/*----------- defined in video/n64.c -----------*/ - -#define DACRATE_NTSC (48681812) -#define DACRATE_PAL (49656530) -#define DACRATE_MPAL (48628316) - -/*----------- defined in machine/n64.c -----------*/ - -#define SP_INTERRUPT 0x1 -#define SI_INTERRUPT 0x2 -#define AI_INTERRUPT 0x4 -#define VI_INTERRUPT 0x8 -#define PI_INTERRUPT 0x10 -#define DP_INTERRUPT 0x20 - -#define SP_STATUS_HALT 0x0001 -#define SP_STATUS_BROKE 0x0002 -#define SP_STATUS_DMABUSY 0x0004 -#define SP_STATUS_DMAFULL 0x0008 -#define SP_STATUS_IOFULL 0x0010 -#define SP_STATUS_SSTEP 0x0020 -#define SP_STATUS_INTR_BREAK 0x0040 -#define SP_STATUS_SIGNAL0 0x0080 -#define SP_STATUS_SIGNAL1 0x0100 -#define SP_STATUS_SIGNAL2 0x0200 -#define SP_STATUS_SIGNAL3 0x0400 -#define SP_STATUS_SIGNAL4 0x0800 -#define SP_STATUS_SIGNAL5 0x1000 -#define SP_STATUS_SIGNAL6 0x2000 -#define SP_STATUS_SIGNAL7 0x4000 - -#define DP_STATUS_XBUS_DMA 0x01 -#define DP_STATUS_FREEZE 0x02 -#define DP_STATUS_FLUSH 0x04 -#define DP_STATUS_START_VALID 0x400 - -#define DD_ASIC_STATUS_DISK_CHANGE 0x00010000 -#define DD_ASIC_STATUS_MECHA_ERR 0x00020000 -#define DD_ASIC_STATUS_WRPROTECT_ERR 0x00040000 -#define DD_ASIC_STATUS_HEAD_RETRACT 0x00080000 -#define DD_ASIC_STATUS_MOTOR_OFF 0x00100000 -#define DD_ASIC_STATUS_RESET 0x00400000 -#define DD_ASIC_STATUS_BUSY 0x00800000 -#define DD_ASIC_STATUS_DISK 0x01000000 -#define DD_ASIC_STATUS_MECHA_INT 0x02000000 -#define DD_ASIC_STATUS_BM_INT 0x04000000 -#define DD_ASIC_STATUS_BM_ERROR 0x08000000 -#define DD_ASIC_STATUS_C2_XFER 0x10000000 -#define DD_ASIC_STATUS_DREQ 0x40000000 - -#define DD_TRACK_INDEX_LOCK 0x60000000 - -#define DD_BM_MECHA_INT_RESET 0x01000000 -#define DD_BM_XFERBLOCKS 0x02000000 -#define DD_BM_DISABLE_C1 0x04000000 -#define DD_BM_DISABLE_OR_CHK 0x08000000 -#define DD_BM_RESET 0x10000000 -#define DD_BM_INT_MASK 0x20000000 -#define DD_BM_MODE 0x40000000 -#define DD_BM_START 0x80000000 - -#define DD_BMST_RUNNING 0x80000000 -#define DD_BMST_ERROR 0x04000000 -#define DD_BMST_MICRO_STATUS 0x02000000 -#define DD_BMST_BLOCKS 0x01000000 -#define DD_BMST_C1_CORRECT 0x00800000 -#define DD_BMST_C1_DOUBLE 0x00400000 -#define DD_BMST_C1_SINGLE 0x00200000 -#define DD_BMST_C1_ERROR 0x00010000 - -#define DD_ASIC_ERR_AM_FAIL 0x80000000 -#define DD_ASIC_ERR_MICRO_FAIL 0x40000000 -#define DD_ASIC_ERR_SPINDLE_FAIL 0x20000000 -#define DD_ASIC_ERR_OVER_RUN 0x10000000 -#define DD_ASIC_ERR_OFFTRACK 0x08000000 -#define DD_ASIC_ERR_NO_DISK 0x04000000 -#define DD_ASIC_ERR_CLOCK_UNLOCK 0x02000000 -#define DD_ASIC_ERR_SELF_STOP 0x01000000 - -#define DD_SEQ_MICRO_INT_MASK 0x80000000 -#define DD_SEQ_MICRO_PC_ENABLE 0x40000000 - -#define SECTORS_PER_BLOCK 85 -#define BLOCKS_PER_TRACK 2 - -const unsigned int ddZoneSecSize[16] = {232,216,208,192,176,160,144,128, - 216,208,192,176,160,144,128,112}; -const unsigned int ddZoneTrackSize[16] = {158,158,149,149,149,149,149,114, - 158,158,149,149,149,149,149,114}; -const unsigned int ddStartOffset[16] = - {0x0,0x5F15E0,0xB79D00,0x10801A0,0x1523720,0x1963D80,0x1D414C0,0x20BBCE0, - 0x23196E0,0x28A1E00,0x2DF5DC0,0x3299340,0x36D99A0,0x3AB70E0,0x3E31900,0x4149200}; - -#endif // MAME_INCLUDES_N64_H diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/n64.cpp b/waterbox/ares64/ares/thirdparty/mame/mame/video/n64.cpp deleted file mode 100644 index 4a88912495..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/n64.cpp +++ /dev/null @@ -1,4415 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -/****************************************************************************** - - - SGI/Nintendo Reality Display Processor - ------------------- - - by Ryan Holtz - based on initial C code by Ville Linde - contains additional improvements from angrylion, Ziggy, Gonetz and Orkin - - -******************************************************************************* - -STATUS: - -Much behavior needs verification against real hardware. Many edge cases must -be verified on real hardware as well. - -TODO: - -- Further re-work class structure to avoid dependencies - -*******************************************************************************/ - -#include "emu.h" -#include "includes/n64.h" -#include "video/rdpblend.h" -#include "video/rdptpipe.h" -#if !defined(MAME_RDP) -#include "screen.h" -#endif - -#include - -#define LOG_RDP_EXECUTION 0 -#define DEBUG_RDP_PIXEL 0 -#define DRAW_FRAME_COUNTER 0 - -#if DEBUG_RDP_PIXEL -static bool s_debug_drawing = false; -#endif - -static FILE* rdp_exec; - -uint32_t n64_rdp::s_special_9bit_clamptable[512]; - -bool n64_rdp::rdp_range_check(uint32_t addr) -{ - if(m_misc_state.m_fb_size == 0) return false; - - int32_t fbcount = ((m_misc_state.m_fb_width * m_scissor.m_yl) << (m_misc_state.m_fb_size - 1)) * 3; - int32_t fbaddr = m_misc_state.m_fb_address & 0x007fffff; - if ((addr >= fbaddr) && (addr < (fbaddr + fbcount))) - { - return false; - } - - int32_t zbcount = m_misc_state.m_fb_width * m_scissor.m_yl * 2; - int32_t zbaddr = m_misc_state.m_zb_address & 0x007fffff; - if ((addr >= zbaddr) && (addr < (zbaddr + zbcount))) - { - return false; - } - - printf("Check failed: %08x vs. %08x-%08x, %08x-%08x (%d, %d)\n", addr, fbaddr, fbaddr + fbcount, zbaddr, zbaddr + zbcount, m_misc_state.m_fb_width, m_scissor.m_yl); - fflush(stdout); - return true; -} - -/*****************************************************************************/ - -// The functions in this file should be moved into the parent Processor class. -#include "rdpfiltr.hxx" - -int32_t n64_rdp::get_alpha_cvg(int32_t comb_alpha, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - int32_t temp = comb_alpha; - int32_t temp2 = userdata->m_current_pix_cvg; - int32_t temp3 = 0; - - if (object.m_other_modes.cvg_times_alpha) - { - temp3 = (temp * temp2) + 4; - userdata->m_current_pix_cvg = (temp3 >> 8) & 0xf; - } - if (object.m_other_modes.alpha_cvg_select) - { - temp = (m_other_modes.cvg_times_alpha) ? (temp3 >> 3) : (temp2 << 5); - } - if (temp > 0xff) - { - temp = 0xff; - } - return temp; -} - -/*****************************************************************************/ - -void n64_state::video_start() -{ - m_rdp = std::make_unique(*this, m_rdram, m_rsp_dmem); - - m_rdp->set_machine(machine()); - m_rdp->init_internal_state(); - m_rdp->set_n64_periphs(m_rcp_periphs); - - m_rdp->m_blender.set_machine(machine()); - m_rdp->m_blender.set_processor(m_rdp.get()); - - m_rdp->m_tex_pipe.set_machine(machine()); - - m_rdp->m_aux_buf = make_unique_clear(EXTENT_AUX_COUNT); - - if (LOG_RDP_EXECUTION) - { - rdp_exec = fopen("rdp_execute.txt", "wt"); - } -} - -#if !defined(MAME_RDP) -uint32_t n64_state::screen_update_n64(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) -{ - //uint16_t* frame_buffer = (uint16_t*)&rdram[(m_rcp_periphs->vi_origin & 0xffffff) >> 2]; - //uint8_t* cvg_buffer = &m_rdp.m_hidden_bits[((m_rcp_periphs->vi_origin & 0xffffff) >> 2) >> 1]; - //int32_t vibuffering = ((m_rcp_periphs->vi_control & 2) && fsaa && divot); - - //vibuffering = 0; // Disabled for now - - /* - if (vibuffering && ((m_rcp_periphs->vi_control & 3) == 2)) - { - if (frame_buffer) - { - for (j=0; j < vres; j++) - { - for (i=0; i < hres; i++) - { - uint16_t pix; - pix = frame_buffer[pixels ^ WORD_ADDR_XOR]; - curpixel_cvg = ((pix & 1) << 2) | (cvg_buffer[pixels ^ BYTE_ADDR_XOR] & 3); // Reuse of this variable - if (curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2) && fsaa) - { - newc = video_filter16(&frame_buffer[pixels ^ WORD_ADDR_XOR], &cvg_buffer[pixels ^ BYTE_ADDR_XOR], m_rcp_periphs->vi_width); - ViBuffer[i][j] = newc; - } - else - { - newc.i.r = ((pix >> 8) & 0xf8) | (pix >> 13); - newc.i.g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - newc.i.b = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - ViBuffer[i][j] = newc; - } - pixels++; - } - pixels += invisiblewidth; - } - } - } - */ - - m_rdp->mark_frame(); - - if (m_rcp_periphs->vi_blank) - { - bitmap.fill(0, screen.visible_area()); - return 0; - } - - m_rcp_periphs->video_update(bitmap); - - return 0; -} - -WRITE_LINE_MEMBER(n64_state::screen_vblank_n64) -{ -} - -void n64_periphs::video_update(bitmap_rgb32 &bitmap) -{ - - if (vi_control & 0x40) /* Interlace */ - { - field ^= 1; - } - else - { - field = 0; - } - - switch (vi_control & 0x3) - { - case PIXEL_SIZE_16BIT: - video_update16(bitmap); - break; - - case PIXEL_SIZE_32BIT: - video_update32(bitmap); - break; - - default: - //fatalerror("Unsupported framebuffer depth: m_fb_size=%d\n", m_misc_state.m_fb_size); - break; - } -} - -void n64_periphs::video_update16(bitmap_rgb32 &bitmap) -{ - //int32_t fsaa = (((n64->vi_control >> 8) & 3) < 2); - //int32_t divot = (n64->vi_control >> 4) & 1; - - //uint32_t prev_cvg = 0; - //uint32_t next_cvg = 0; - //int32_t dither_filter = (n64->vi_control >> 16) & 1; - //int32_t vibuffering = ((n64->vi_control & 2) && fsaa && divot); - - uint16_t* frame_buffer = (uint16_t*)&m_rdram[(vi_origin & 0xffffff) >> 2]; - //uint32_t hb = ((n64->vi_origin & 0xffffff) >> 2) >> 1; - //uint8_t* hidden_buffer = &m_hidden_bits[hb]; - - int32_t hend = vi_hstart & 0x3ff; - int32_t hstart = (vi_hstart >> 16) & 0x3ff; - int32_t hdiff = hend - hstart; - float hcoeff = ((float)(vi_xscale & 0xfff) / (1 << 10)); - uint32_t hres = ((float)hdiff * hcoeff); - - int32_t vend = (vi_vstart & 0x3ff) >> 1; - int32_t vstart = ((vi_vstart >> 16) & 0x3ff) >> 1; - int32_t vdiff = vend - vstart; - float vcoeff = ((float)(vi_yscale & 0xfff) / (1 << 10)); - uint32_t vres = ((float)vdiff * vcoeff); - - fflush(stdout); - - if (vdiff <= 0 || hdiff <= 0) - { - return; - } - - if (vres > bitmap.height()) // makes Perfect Dark boot w/o crashing - { - vres = bitmap.height(); - } - -#if DRAW_FRAME_COUNTER - static uint32_t frame_num = 0; - static const uint8_t s_numbers[10][9] = { - { 0x00, 0x3c, 0x66, 0x6e, 0x7e, 0x76, 0x66, 0x3c, 0x00 }, - { 0x00, 0x18, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00 }, - { 0x00, 0x3c, 0x66, 0x06, 0x3c, 0x60, 0x60, 0x7e, 0x00 }, - { 0x00, 0x3c, 0x66, 0x06, 0x0c, 0x06, 0x66, 0x3c, 0x00 }, - { 0x00, 0x66, 0x66, 0x66, 0x7e, 0x06, 0x06, 0x06, 0x00 }, - { 0x00, 0x7e, 0x60, 0x60, 0x7c, 0x06, 0x66, 0x3c, 0x00 }, - { 0x00, 0x3c, 0x66, 0x60, 0x7c, 0x66, 0x66, 0x3c, 0x00 }, - { 0x00, 0x7e, 0x66, 0x06, 0x0c, 0x18, 0x18, 0x18, 0x00 }, - { 0x00, 0x3c, 0x66, 0x66, 0x3c, 0x66, 0x66, 0x3c, 0x00 }, - { 0x00, 0x3c, 0x66, 0x66, 0x3e, 0x06, 0x66, 0x3c, 0x00 } - }; -#endif - - if (frame_buffer) - { -#if DRAW_FRAME_COUNTER - uint32_t digits[4] = { (frame_num / 1000) % 10, (frame_num / 100) % 10, (frame_num / 10) % 10, frame_num % 10 }; - - for (int32_t d = 0; d < 4; d++) - { - for (int32_t y = 0; y < 9; y++) - { - const uint8_t *pixdata = s_numbers[digits[d]]; - for (int32_t x = 0; x < 8; x++) - { - frame_buffer[((y + 16) * vi_width + d * 8 + x + 16) ^ WORD_ADDR_XOR] = BIT(pixdata[y], 7 - x) ? 0x0000 : 0xffff; - } - } - } -#if DEBUG_RDP_PIXEL - s_debug_drawing = (frame_num == 1392); -#endif - frame_num++; -#endif - - const uint32_t aa_control = (vi_control >> 8) & 3; - float v0 = 0.0f; - if (aa_control < 3) // Resample pixels - { - for (int32_t j = 0; j < vdiff; j++, v0 += vcoeff) - { - uint32_t *const d = &bitmap.pix(j); - - float u0 = (float)0.0f; - - int iv0 = (int)v0; - int pix_v0_line = iv0 * vi_width; - - int iv1 = (iv0 >= (vres - 1) ? iv0 : (iv0 + 1)); - int pix_v1_line = iv1 * vi_width; - - for (int32_t i = 0; i < hdiff; i++) - { - int iu0 = (int)u0; - int iu1 = (iu0 >= (hres - 1) ? iu0 : (iu0 + 1)); - uint16_t pix00 = frame_buffer[(pix_v0_line + iu0) ^ WORD_ADDR_XOR]; - uint16_t pix10 = frame_buffer[(pix_v0_line + iu1) ^ WORD_ADDR_XOR]; - uint16_t pix01 = frame_buffer[(pix_v1_line + iu0) ^ WORD_ADDR_XOR]; - uint16_t pix11 = frame_buffer[(pix_v1_line + iu1) ^ WORD_ADDR_XOR]; - - const uint8_t r00 = ((pix00 >> 8) & 0xf8) | (pix00 >> 13); - const uint8_t g00 = ((pix00 >> 3) & 0xf8) | ((pix00 >> 8) & 0x07); - const uint8_t b00 = ((pix00 << 2) & 0xf8) | ((pix00 >> 3) & 0x07); - - const uint8_t r10 = ((pix10 >> 8) & 0xf8) | (pix10 >> 13); - const uint8_t g10 = ((pix10 >> 3) & 0xf8) | ((pix10 >> 8) & 0x07); - const uint8_t b10 = ((pix10 << 2) & 0xf8) | ((pix10 >> 3) & 0x07); - - const uint8_t r01 = ((pix01 >> 8) & 0xf8) | (pix01 >> 13); - const uint8_t g01 = ((pix01 >> 3) & 0xf8) | ((pix01 >> 8) & 0x07); - const uint8_t b01 = ((pix01 << 2) & 0xf8) | ((pix01 >> 3) & 0x07); - - const uint8_t r11 = ((pix11 >> 8) & 0xf8) | (pix11 >> 13); - const uint8_t g11 = ((pix11 >> 3) & 0xf8) | ((pix11 >> 8) & 0x07); - const uint8_t b11 = ((pix11 << 2) & 0xf8) | ((pix11 >> 3) & 0x07); - - const float ut = u0 - (int)u0; - const float vt = v0 - (int)v0; - - float ur0 = (1.0f - ut) * r00 + ut * r10; - float ug0 = (1.0f - ut) * g00 + ut * g10; - float ub0 = (1.0f - ut) * b00 + ut * b10; - - float ur1 = (1.0f - ut) * r01 + ut * r11; - float ug1 = (1.0f - ut) * g01 + ut * g11; - float ub1 = (1.0f - ut) * b01 + ut * b11; - - float r = (1.0f - vt) * ur0 + vt * ur1; - float g = (1.0f - vt) * ug0 + vt * ug1; - float b = (1.0f - vt) * ub0 + vt * ub1; - - uint8_t r8 = std::clamp((uint8_t)r, (uint8_t)0, (uint8_t)255); - uint8_t g8 = std::clamp((uint8_t)g, (uint8_t)0, (uint8_t)255); - uint8_t b8 = std::clamp((uint8_t)b, (uint8_t)0, (uint8_t)255); - - d[iu0] = (r8 << 16) | (g8 << 8) | b8; - - u0 += hcoeff; - } - } - } - else // Replicate pixels - { - for (int32_t j = 0; j < vdiff; j++, v0 += vcoeff) - { - uint32_t *const d = &bitmap.pix(j); - - int iv0 = (int)v0; - int pix_v0_line = iv0 * vi_width; - - for (int32_t i = 0; i < hdiff; i++) - { - int u0 = (int)(i * hcoeff); - uint16_t pix = frame_buffer[(pix_v0_line + u0) ^ WORD_ADDR_XOR]; - - const uint8_t r = ((pix >> 8) & 0xf8) | (pix >> 13); - const uint8_t g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - const uint8_t b = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - d[u0] = (r << 16) | (g << 8) | b; - } - } - } - } -} - -void n64_periphs::video_update32(bitmap_rgb32 &bitmap) -{ - //int32_t gamma = (vi_control >> 3) & 1; - //int32_t gamma_dither = (vi_control >> 2) & 1; - //int32_t vibuffering = ((n64->vi_control & 2) && fsaa && divot); - - uint32_t* frame_buffer32 = (uint32_t*)&m_rdram[(vi_origin & 0xffffff) >> 2]; - - int32_t hend = vi_hstart & 0x3ff; - int32_t hstart = (vi_hstart >> 16) & 0x3ff; - int32_t hdiff = hend - hstart; - const float hcoeff = ((float)(vi_xscale & 0xfff) / (1 << 10)); - uint32_t hres = ((float)hdiff * hcoeff); - - int32_t vend = (vi_vstart & 0x3ff) >> 1; - int32_t vstart = ((vi_vstart >> 16) & 0x3ff) >> 1; - int32_t vdiff = vend - vstart; - const float vcoeff = ((float)(vi_yscale & 0xfff) / (1 << 10)); - const uint32_t vres = ((float)vdiff * vcoeff); - - if (vdiff <= 0 || hdiff <= 0) - { - return; - } - - //printf("hd,vd: %d,%d hc,vc: %f,%f hs,he: %d,%d vs,ve: %d,%d hr,vr: %d, %d viw: %d\n", hdiff, vdiff, hcoeff, vcoeff, hstart, hend, vstart, vend, hres, vres, vi_width); - - if (frame_buffer32) - { - const uint32_t aa_control = (vi_control >> 8) & 3; - float v0 = 0.0f; - if (aa_control < 3) // Resample pixels - { - for (int32_t j = 0; j < vres; j++, v0 += 1.0f) - { - uint32_t *const d = &bitmap.pix(j); - - float u0 = 0.0f; - - int iv0 = (int)v0; - int pix_v0_line = iv0 * vi_width; - - int iv1 = (iv0 >= (vres - 1) ? iv0 : (iv0 + 1)); - int pix_v1_line = iv1 * vi_width; - - for (int32_t i = 0; i < hdiff; i++) - { - int iu0 = (int)u0; - int iu1 = (iu0 >= (hres - 1) ? iu0 : (iu0 + 1)); - uint32_t pix00 = frame_buffer32[pix_v0_line + iu0]; - uint32_t pix10 = frame_buffer32[pix_v0_line + iu1]; - uint32_t pix01 = frame_buffer32[pix_v1_line + iu0]; - uint32_t pix11 = frame_buffer32[pix_v1_line + iu1]; - - const uint8_t r00 = (uint8_t)(pix00 >> 24); - const uint8_t g00 = (uint8_t)(pix00 >> 16); - const uint8_t b00 = (uint8_t)(pix00 >> 8); - - const uint8_t r10 = (uint8_t)(pix01 >> 24); - const uint8_t g10 = (uint8_t)(pix01 >> 16); - const uint8_t b10 = (uint8_t)(pix01 >> 8); - - const uint8_t r01 = (uint8_t)(pix10 >> 24); - const uint8_t g01 = (uint8_t)(pix10 >> 16); - const uint8_t b01 = (uint8_t)(pix10 >> 8); - - const uint8_t r11 = (uint8_t)(pix11 >> 24); - const uint8_t g11 = (uint8_t)(pix11 >> 16); - const uint8_t b11 = (uint8_t)(pix11 >> 8); - - const float ut = u0 - (int)u0; - const float vt = v0 - (int)v0; - - float ur0 = (1.0f - ut) * r00 + ut * r10; - float ug0 = (1.0f - ut) * g00 + ut * g10; - float ub0 = (1.0f - ut) * b00 + ut * b10; - - float ur1 = (1.0f - ut) * r01 + ut * r11; - float ug1 = (1.0f - ut) * g01 + ut * g11; - float ub1 = (1.0f - ut) * b01 + ut * b11; - - float r = (1.0f - vt) * ur0 + vt * ur1; - float g = (1.0f - vt) * ug0 + vt * ug1; - float b = (1.0f - vt) * ub0 + vt * ub1; - - uint8_t r8 = std::clamp((uint8_t)r, (uint8_t)0, (uint8_t)255); - uint8_t g8 = std::clamp((uint8_t)g, (uint8_t)0, (uint8_t)255); - uint8_t b8 = std::clamp((uint8_t)b, (uint8_t)0, (uint8_t)255); - - d[iu0] = (r8 << 16) | (g8 << 8) | b8; - - u0 += hcoeff; - } - } - } - else // Replicate pixels - { - for (int32_t j = 0; j < vdiff; j++, v0 += vcoeff) - { - uint32_t *const d = &bitmap.pix(j); - - int iv0 = (int)v0; - int pix_v0_line = iv0 * vi_width; - - for (int32_t i = 0; i < hdiff; i++) - { - int u0 = (int)(i * hcoeff); - d[u0] = (frame_buffer32[pix_v0_line + u0] >> 8); - } - } - } - } -} -#endif - -/*****************************************************************************/ - -void n64_rdp::tc_div_no_perspective(int32_t ss, int32_t st, int32_t sw, int32_t* sss, int32_t* sst) -{ - *sss = (SIGN16(ss)) & 0x1ffff; - *sst = (SIGN16(st)) & 0x1ffff; -} - -void n64_rdp::tc_div(int32_t ss, int32_t st, int32_t sw, int32_t* sss, int32_t* sst) -{ - int32_t w_carry = 0; - if ((sw & 0x8000) || !(sw & 0x7fff)) - { - w_carry = 1; - } - - sw &= 0x7fff; - - int32_t shift; - for (shift = 1; shift <= 14 && !((sw << shift) & 0x8000); shift++); - shift -= 1; - - int32_t normout = (sw << shift) & 0x3fff; - int32_t wnorm = (normout & 0xff) << 2; - normout >>= 8; - - int32_t temppoint = m_norm_point_rom[normout]; - int32_t tempslope = m_norm_slope_rom[normout]; - - int32_t tlu_rcp = ((-(tempslope * wnorm)) >> 10) + temppoint; - - int32_t sprod = SIGN16(ss) * tlu_rcp; - int32_t tprod = SIGN16(st) * tlu_rcp; - int32_t tempmask = ((1 << (shift + 1)) - 1) << (29 - shift); - int32_t shift_value = 13 - shift; - - int32_t outofbounds_s = sprod & tempmask; - int32_t outofbounds_t = tprod & tempmask; - if (shift == 0xe) - { - *sss = sprod << 1; - *sst = tprod << 1; - } - else - { - *sss = sprod = (sprod >> shift_value); - *sst = tprod = (tprod >> shift_value); - } - //compute clamp flags - int32_t under_s = 0; - int32_t under_t = 0; - int32_t over_s = 0; - int32_t over_t = 0; - - if (outofbounds_s != tempmask && outofbounds_s != 0) - { - if (sprod & (1 << 29)) - { - under_s = 1; - } - else - { - over_s = 1; - } - } - - if (outofbounds_t != tempmask && outofbounds_t != 0) - { - if (tprod & (1 << 29)) - { - under_t = 1; - } - else - { - over_t = 1; - } - } - - over_s |= w_carry; - over_t |= w_carry; - - *sss = (*sss & 0x1ffff) | (over_s << 18) | (under_s << 17); - *sst = (*sst & 0x1ffff) | (over_t << 18) | (under_t << 17); -} - -int32_t n64_rdp::color_combiner_equation(int32_t a, int32_t b, int32_t c, int32_t d) -{ - a = KURT_AKELEY_SIGN9(a); - b = KURT_AKELEY_SIGN9(b); - c = SIGN9(c); - d = KURT_AKELEY_SIGN9(d); - a = (((a - b) * c) + (d << 8) + 0x80); - a = SIGN17(a) >> 8; - a = s_special_9bit_clamptable[a & 0x1ff]; - return a; -} - -int32_t n64_rdp::alpha_combiner_equation(int32_t a, int32_t b, int32_t c, int32_t d) -{ - a = KURT_AKELEY_SIGN9(a); - b = KURT_AKELEY_SIGN9(b); - c = SIGN9(c); - d = KURT_AKELEY_SIGN9(d); - a = (((a - b) * c) + (d << 8) + 0x80) >> 8; - a = SIGN9(a); - a = s_special_9bit_clamptable[a & 0x1ff]; - return a; -} - -void n64_rdp::set_suba_input_rgb(color_t** input, int32_t code, rdp_span_aux* userdata) -{ - switch (code & 0xf) - { - case 0: *input = &userdata->m_combined_color; break; - case 1: *input = &userdata->m_texel0_color; break; - case 2: *input = &userdata->m_texel1_color; break; - case 3: *input = &userdata->m_prim_color; break; - case 4: *input = &userdata->m_shade_color; break; - case 5: *input = &userdata->m_env_color; break; - case 6: *input = &m_one; break; - case 7: *input = &userdata->m_noise_color; break; - case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: - { - *input = &m_zero; break; - } - } -} - -void n64_rdp::set_subb_input_rgb(color_t** input, int32_t code, rdp_span_aux* userdata) -{ - switch (code & 0xf) - { - case 0: *input = &userdata->m_combined_color; break; - case 1: *input = &userdata->m_texel0_color; break; - case 2: *input = &userdata->m_texel1_color; break; - case 3: *input = &userdata->m_prim_color; break; - case 4: *input = &userdata->m_shade_color; break; - case 5: *input = &userdata->m_env_color; break; - case 6: fatalerror("SET_SUBB_RGB_INPUT: key_center\n"); - case 7: *input = &userdata->m_k4; break; - case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: - { - *input = &m_zero; break; - } - } -} - -void n64_rdp::set_mul_input_rgb(color_t** input, int32_t code, rdp_span_aux* userdata) -{ - switch (code & 0x1f) - { - case 0: *input = &userdata->m_combined_color; break; - case 1: *input = &userdata->m_texel0_color; break; - case 2: *input = &userdata->m_texel1_color; break; - case 3: *input = &userdata->m_prim_color; break; - case 4: *input = &userdata->m_shade_color; break; - case 5: *input = &userdata->m_env_color; break; - case 6: *input = &userdata->m_key_scale; break; - case 7: *input = &userdata->m_combined_alpha; break; - case 8: *input = &userdata->m_texel0_alpha; break; - case 9: *input = &userdata->m_texel1_alpha; break; - case 10: *input = &userdata->m_prim_alpha; break; - case 11: *input = &userdata->m_shade_alpha; break; - case 12: *input = &userdata->m_env_alpha; break; - case 13: *input = &userdata->m_lod_fraction; break; - case 14: *input = &userdata->m_prim_lod_fraction; break; - case 15: *input = &userdata->m_k5; break; - case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: - case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: - { - *input = &m_zero; break; - } - } -} - -void n64_rdp::set_add_input_rgb(color_t** input, int32_t code, rdp_span_aux* userdata) -{ - switch (code & 0x7) - { - case 0: *input = &userdata->m_combined_color; break; - case 1: *input = &userdata->m_texel0_color; break; - case 2: *input = &userdata->m_texel1_color; break; - case 3: *input = &userdata->m_prim_color; break; - case 4: *input = &userdata->m_shade_color; break; - case 5: *input = &userdata->m_env_color; break; - case 6: *input = &m_one; break; - case 7: *input = &m_zero; break; - } -} - -void n64_rdp::set_sub_input_alpha(color_t** input, int32_t code, rdp_span_aux* userdata) -{ - switch (code & 0x7) - { - case 0: *input = &userdata->m_combined_alpha; break; - case 1: *input = &userdata->m_texel0_alpha; break; - case 2: *input = &userdata->m_texel1_alpha; break; - case 3: *input = &userdata->m_prim_alpha; break; - case 4: *input = &userdata->m_shade_alpha; break; - case 5: *input = &userdata->m_env_alpha; break; - case 6: *input = &m_one; break; - case 7: *input = &m_zero; break; - } -} - -void n64_rdp::set_mul_input_alpha(color_t** input, int32_t code, rdp_span_aux* userdata) -{ - switch (code & 0x7) - { - case 0: *input = &userdata->m_lod_fraction; break; - case 1: *input = &userdata->m_texel0_alpha; break; - case 2: *input = &userdata->m_texel1_alpha; break; - case 3: *input = &userdata->m_prim_alpha; break; - case 4: *input = &userdata->m_shade_alpha; break; - case 5: *input = &userdata->m_env_alpha; break; - case 6: *input = &userdata->m_prim_lod_fraction; break; - case 7: *input = &m_zero; break; - } -} - -void n64_rdp::set_blender_input(int32_t cycle, int32_t which, color_t** input_rgb, color_t** input_a, int32_t a, int32_t b, rdp_span_aux* userdata) -{ - switch (a & 0x3) - { - case 0: - *input_rgb = cycle == 0 ? &userdata->m_pixel_color : &userdata->m_blended_pixel_color; - break; - - case 1: - *input_rgb = &userdata->m_memory_color; - break; - - case 2: - *input_rgb = &userdata->m_blend_color; - break; - - case 3: - *input_rgb = &userdata->m_fog_color; - break; - } - - if (which == 0) - { - switch (b & 0x3) - { - case 0: *input_a = &userdata->m_pixel_color; break; - case 1: *input_a = &userdata->m_fog_color; break; - case 2: *input_a = &userdata->m_shade_color; break; - case 3: *input_a = &m_zero; break; - } - } - else - { - switch (b & 0x3) - { - case 0: *input_a = &userdata->m_inv_pixel_color; break; - case 1: *input_a = &userdata->m_memory_color; break; - case 2: *input_a = &m_one; break; - case 3: *input_a = &m_zero; break; - } - } -} - -uint8_t const n64_rdp::s_bayer_matrix[16] = -{ /* Bayer matrix */ - 0, 4, 1, 5, - 6, 2, 7, 3, - 1, 5, 0, 4, - 7, 3, 6, 2 -}; - -uint8_t const n64_rdp::s_magic_matrix[16] = -{ /* Magic square matrix */ - 0, 4, 3, 7, - 6, 2, 5, 1, - 1, 5, 2, 6, - 7, 3, 4, 0 -}; - -z_decompress_entry_t const n64_rdp::m_z_dec_table[8] = -{ - { 6, 0x00000 }, - { 5, 0x20000 }, - { 4, 0x30000 }, - { 3, 0x38000 }, - { 2, 0x3c000 }, - { 1, 0x3e000 }, - { 0, 0x3f000 }, - { 0, 0x3f800 }, -}; - -/*****************************************************************************/ - -void n64_rdp::z_build_com_table(void) -{ - uint16_t altmem = 0; - for(int32_t z = 0; z < 0x40000; z++) - { - switch((z >> 11) & 0x7f) - { - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - case 0x08: - case 0x09: - case 0x0a: - case 0x0b: - case 0x0c: - case 0x0d: - case 0x0e: - case 0x0f: - case 0x10: - case 0x11: - case 0x12: - case 0x13: - case 0x14: - case 0x15: - case 0x16: - case 0x17: - case 0x18: - case 0x19: - case 0x1a: - case 0x1b: - case 0x1c: - case 0x1d: - case 0x1e: - case 0x1f: - case 0x20: - case 0x21: - case 0x22: - case 0x23: - case 0x24: - case 0x25: - case 0x26: - case 0x27: - case 0x28: - case 0x29: - case 0x2a: - case 0x2b: - case 0x2c: - case 0x2d: - case 0x2e: - case 0x2f: - case 0x30: - case 0x31: - case 0x32: - case 0x33: - case 0x34: - case 0x35: - case 0x36: - case 0x37: - case 0x38: - case 0x39: - case 0x3a: - case 0x3b: - case 0x3c: - case 0x3d: - case 0x3e: - case 0x3f: - altmem = (z >> 4) & 0x1ffc; - break; - case 0x40: - case 0x41: - case 0x42: - case 0x43: - case 0x44: - case 0x45: - case 0x46: - case 0x47: - case 0x48: - case 0x49: - case 0x4a: - case 0x4b: - case 0x4c: - case 0x4d: - case 0x4e: - case 0x4f: - case 0x50: - case 0x51: - case 0x52: - case 0x53: - case 0x54: - case 0x55: - case 0x56: - case 0x57: - case 0x58: - case 0x59: - case 0x5a: - case 0x5b: - case 0x5c: - case 0x5d: - case 0x5e: - case 0x5f: - altmem = ((z >> 3) & 0x1ffc) | 0x2000; - break; - case 0x60: - case 0x61: - case 0x62: - case 0x63: - case 0x64: - case 0x65: - case 0x66: - case 0x67: - case 0x68: - case 0x69: - case 0x6a: - case 0x6b: - case 0x6c: - case 0x6d: - case 0x6e: - case 0x6f: - altmem = ((z >> 2) & 0x1ffc) | 0x4000; - break; - case 0x70: - case 0x71: - case 0x72: - case 0x73: - case 0x74: - case 0x75: - case 0x76: - case 0x77: - altmem = ((z >> 1) & 0x1ffc) | 0x6000; - break; - case 0x78://uncompressed z = 0x3c000 - case 0x79: - case 0x7a: - case 0x7b: - altmem = (z & 0x1ffc) | 0x8000; - break; - case 0x7c://uncompressed z = 0x3e000 - case 0x7d: - altmem = ((z << 1) & 0x1ffc) | 0xa000; - break; - case 0x7e://uncompressed z = 0x3f000 - altmem = ((z << 2) & 0x1ffc) | 0xc000; - break; - case 0x7f://uncompressed z = 0x3f000 - altmem = ((z << 2) & 0x1ffc) | 0xe000; - break; - } - - m_z_com_table[z] = altmem; - - } -} - -void n64_rdp::precalc_cvmask_derivatives(void) -{ - const uint8_t yarray[16] = {0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0}; - const uint8_t xarray[16] = {0, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}; - - for (int32_t i = 0; i < 0x10000; i++) - { - m_compressed_cvmasks[i] = (i & 1) | ((i & 4) >> 1) | ((i & 0x20) >> 3) | ((i & 0x80) >> 4) | - ((i & 0x100) >> 4) | ((i & 0x400) >> 5) | ((i & 0x2000) >> 7) | ((i & 0x8000) >> 8); - } - - for (int32_t i = 0; i < 0x100; i++) - { - uint16_t mask = decompress_cvmask_frombyte(i); - cvarray[i].cvg = cvarray[i].cvbit = 0; - cvarray[i].cvbit = (i >> 7) & 1; - for (int32_t k = 0; k < 8; k++) - { - cvarray[i].cvg += ((i >> k) & 1); - } - - uint16_t masky = 0; - for (int32_t k = 0; k < 4; k++) - { - masky |= ((mask & (0xf000 >> (k << 2))) > 0) << k; - } - uint8_t offy = yarray[masky]; - - uint16_t maskx = (mask & (0xf000 >> (offy << 2))) >> ((offy ^ 3) << 2); - uint8_t offx = xarray[maskx]; - - cvarray[i].xoff = offx; - cvarray[i].yoff = offy; - } -} - -uint16_t n64_rdp::decompress_cvmask_frombyte(uint8_t x) -{ - uint16_t y = (x & 1) | ((x & 2) << 1) | ((x & 4) << 3) | ((x & 8) << 4) | - ((x & 0x10) << 4) | ((x & 0x20) << 5) | ((x & 0x40) << 7) | ((x & 0x80) << 8); - return y; -} - -void n64_rdp::lookup_cvmask_derivatives(uint32_t mask, uint8_t* offx, uint8_t* offy, rdp_span_aux* userdata) -{ - const uint32_t index = m_compressed_cvmasks[mask]; - userdata->m_current_pix_cvg = cvarray[index].cvg; - userdata->m_current_cvg_bit = cvarray[index].cvbit; - *offx = cvarray[index].xoff; - *offy = cvarray[index].yoff; -} - -void n64_rdp::z_store(const rdp_poly_state &object, uint32_t zcurpixel, uint32_t dzcurpixel, uint32_t z, uint32_t enc) -{ - uint16_t zval = m_z_com_table[z & 0x3ffff]|(enc >> 2); - if(zcurpixel <= MEM16_LIMIT) - { - ((uint16_t*)m_rdram)[zcurpixel ^ WORD_ADDR_XOR] = zval; - } - if(dzcurpixel <= MEM8_LIMIT) - { - m_hidden_bits[dzcurpixel ^ BYTE_ADDR_XOR] = enc & 3; - } -} - -int32_t n64_rdp::normalize_dzpix(int32_t sum) -{ - if (sum & 0xc000) - { - return 0x8000; - } - if (!(sum & 0xffff)) - { - return 1; - } - for(int32_t count = 0x2000; count > 0; count >>= 1) - { - if (sum & count) - { - return(count << 1); - } - } - return 0; -} - -uint32_t n64_rdp::z_decompress(uint32_t zcurpixel) -{ - return m_z_complete_dec_table[(RREADIDX16(zcurpixel) >> 2) & 0x3fff]; -} - -uint32_t n64_rdp::dz_decompress(uint32_t zcurpixel, uint32_t dzcurpixel) -{ - const uint16_t zval = RREADIDX16(zcurpixel); - const uint8_t dzval = (((dzcurpixel) <= 0x7fffff) ? (m_hidden_bits[(dzcurpixel) ^ BYTE_ADDR_XOR]) : 0); - const uint32_t dz_compressed = ((zval & 3) << 2) | (dzval & 3); - return (1 << dz_compressed); -} - -uint32_t n64_rdp::dz_compress(uint32_t value) -{ - int32_t j = 0; - for (; value > 1; j++, value >>= 1); - return j; -} - -void n64_rdp::get_dither_values(int32_t x, int32_t y, int32_t* cdith, int32_t* adith, const rdp_poly_state& object) -{ - const int32_t dithindex = ((y & 3) << 2) | (x & 3); - switch((object.m_other_modes.rgb_dither_sel << 2) | object.m_other_modes.alpha_dither_sel) - { - case 0: - *adith = *cdith = s_magic_matrix[dithindex]; - break; - case 1: - *cdith = s_magic_matrix[dithindex]; - *adith = (~(*cdith)) & 7; - break; - case 2: - *cdith = s_magic_matrix[dithindex]; - *adith = machine().rand() & 7; - break; - case 3: - *cdith = s_magic_matrix[dithindex]; - *adith = 0; - break; - case 4: - *adith = *cdith = s_bayer_matrix[dithindex]; - break; - case 5: - *cdith = s_bayer_matrix[dithindex]; - *adith = (~(*cdith)) & 7; - break; - case 6: - *cdith = s_bayer_matrix[dithindex]; - *adith = machine().rand() & 7; - break; - case 7: - *cdith = s_bayer_matrix[dithindex]; - *adith = 0; - break; - case 8: - *cdith = machine().rand() & 7; - *adith = s_magic_matrix[dithindex]; - break; - case 9: - *cdith = machine().rand() & 7; - *adith = (~s_magic_matrix[dithindex]) & 7; - break; - case 10: - *cdith = machine().rand() & 7; - *adith = (*cdith + 17) & 7; - break; - case 11: - *cdith = machine().rand() & 7; - *adith = 0; - break; - case 12: - *cdith = 0; - *adith = s_bayer_matrix[dithindex]; - break; - case 13: - *cdith = 0; - *adith = (~s_bayer_matrix[dithindex]) & 7; - break; - case 14: - *cdith = 0; - *adith = machine().rand() & 7; - break; - case 15: - *adith = *cdith = 0; - break; - } -} - -int32_t CLAMP(int32_t in, int32_t min, int32_t max) -{ - if(in < min) return min; - if(in > max) return max; - return in; -} - -bool n64_rdp::z_compare(uint32_t zcurpixel, uint32_t dzcurpixel, uint32_t sz, uint16_t dzpix, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - bool force_coplanar = false; - sz &= 0x3ffff; - - uint32_t oz; - uint32_t dzmem; - uint32_t zval; - int32_t rawdzmem; - - if (object.m_other_modes.z_compare_en) - { - oz = z_decompress(zcurpixel); - dzmem = dz_decompress(zcurpixel, dzcurpixel); - zval = RREADIDX16(zcurpixel); - rawdzmem = ((zval & 3) << 2) | ((((dzcurpixel) <= 0x3fffff) ? (m_hidden_bits[(dzcurpixel) ^ BYTE_ADDR_XOR]) : 0) & 3); - } - else - { - oz = 0; - dzmem = 1 << 0xf; - zval = 0x3; - rawdzmem = 0xf; - } - - userdata->m_dzpix_enc = dz_compress(dzpix & 0xffff); - userdata->m_shift_a = CLAMP(userdata->m_dzpix_enc - rawdzmem, 0, 4); - userdata->m_shift_b = CLAMP(rawdzmem - userdata->m_dzpix_enc, 0, 4); - - int32_t precision_factor = (zval >> 13) & 0xf; - if (precision_factor < 3) - { - int32_t dzmemmodifier = 16 >> precision_factor; - if (dzmem == 0x8000) - { - force_coplanar = true; - } - dzmem <<= 1; - if (dzmem <= dzmemmodifier) - { - dzmem = dzmemmodifier; - } - if (!dzmem) - { - dzmem = 0xffff; - } - } - if (dzmem > 0x8000) - { - dzmem = 0xffff; - } - - uint32_t dznew = (dzmem > dzpix) ? dzmem : (uint32_t)dzpix; - uint32_t dznotshift = dznew; - dznew <<= 3; - - bool farther = (sz + dznew) >= oz; - bool infront = sz < oz; - - if (force_coplanar) - { - farther = true; - } - - bool overflow = ((userdata->m_current_mem_cvg + userdata->m_current_pix_cvg) & 8) > 0; - userdata->m_blend_enable = (object.m_other_modes.force_blend || (!overflow && object.m_other_modes.antialias_en && farther)) ? 1 : 0; - userdata->m_pre_wrap = overflow; - - int32_t cvgcoeff = 0; - uint32_t dzenc = 0; - - if (object.m_other_modes.z_mode == 1 && infront && farther && overflow) - { - dzenc = dz_compress(dznotshift & 0xffff); - cvgcoeff = ((oz >> dzenc) - (sz >> dzenc)) & 0xf; - userdata->m_current_pix_cvg = ((cvgcoeff * userdata->m_current_pix_cvg) >> 3) & 0xf; - } - - if (!object.m_other_modes.z_compare_en) - { - return true; - } - - int32_t diff = (int32_t)sz - (int32_t)dznew; - bool nearer = diff <= (int32_t)oz; - bool max = (oz == 0x3ffff); - if (force_coplanar) - { - nearer = true; - } - - switch(object.m_other_modes.z_mode) - { - case 0: - return (max || (overflow ? infront : nearer)); - case 1: - return (max || (overflow ? infront : nearer)); - case 2: - return (infront || max); - case 3: - return (farther && nearer && !max); - } - - return false; -} - -uint32_t n64_rdp::get_log2(uint32_t lod_clamp) -{ - if (lod_clamp < 2) - { - return 0; - } - else - { - for (int32_t i = 7; i > 0; i--) - { - if ((lod_clamp >> i) & 1) - { - return i; - } - } - } - - return 0; -} - -/*****************************************************************************/ - -uint64_t n64_rdp::read_data(uint32_t address) -{ - if (m_status & 0x1) // XBUS_DMEM_DMA enabled - { - return (uint64_t(m_dmem[(address & 0xfff) / 4]) << 32) | m_dmem[((address + 4) & 0xfff) / 4]; - } - else - { - return (uint64_t(m_rdram[((address & 0xffffff) / 4)]) << 32) | m_rdram[(((address + 4) & 0xffffff) / 4)]; - } -} - -char const *const n64_rdp::s_image_format[] = { "RGBA", "YUV", "CI", "IA", "I", "???", "???", "???" }; -char const *const n64_rdp::s_image_size[] = { "4-bit", "8-bit", "16-bit", "32-bit" }; - -int32_t const n64_rdp::s_rdp_command_length[64] = -{ - 8, // 0x00, No Op - 8, // 0x01, ??? - 8, // 0x02, ??? - 8, // 0x03, ??? - 8, // 0x04, ??? - 8, // 0x05, ??? - 8, // 0x06, ??? - 8, // 0x07, ??? - 32, // 0x08, Non-Shaded Triangle - 32+16, // 0x09, Non-Shaded, Z-Buffered Triangle - 32+64, // 0x0a, Textured Triangle - 32+64+16, // 0x0b, Textured, Z-Buffered Triangle - 32+64, // 0x0c, Shaded Triangle - 32+64+16, // 0x0d, Shaded, Z-Buffered Triangle - 32+64+64, // 0x0e, Shaded+Textured Triangle - 32+64+64+16,// 0x0f, Shaded+Textured, Z-Buffered Triangle - 8, // 0x10, ??? - 8, // 0x11, ??? - 8, // 0x12, ??? - 8, // 0x13, ??? - 8, // 0x14, ??? - 8, // 0x15, ??? - 8, // 0x16, ??? - 8, // 0x17, ??? - 8, // 0x18, ??? - 8, // 0x19, ??? - 8, // 0x1a, ??? - 8, // 0x1b, ??? - 8, // 0x1c, ??? - 8, // 0x1d, ??? - 8, // 0x1e, ??? - 8, // 0x1f, ??? - 8, // 0x20, ??? - 8, // 0x21, ??? - 8, // 0x22, ??? - 8, // 0x23, ??? - 16, // 0x24, Texture_Rectangle - 16, // 0x25, Texture_Rectangle_Flip - 8, // 0x26, Sync_Load - 8, // 0x27, Sync_Pipe - 8, // 0x28, Sync_Tile - 8, // 0x29, Sync_Full - 8, // 0x2a, Set_Key_GB - 8, // 0x2b, Set_Key_R - 8, // 0x2c, Set_Convert - 8, // 0x2d, Set_Scissor - 8, // 0x2e, Set_Prim_Depth - 8, // 0x2f, Set_Other_Modes - 8, // 0x30, Load_TLUT - 8, // 0x31, ??? - 8, // 0x32, Set_Tile_Size - 8, // 0x33, Load_Block - 8, // 0x34, Load_Tile - 8, // 0x35, Set_Tile - 8, // 0x36, Fill_Rectangle - 8, // 0x37, Set_Fill_Color - 8, // 0x38, Set_Fog_Color - 8, // 0x39, Set_Blend_Color - 8, // 0x3a, Set_Prim_Color - 8, // 0x3b, Set_Env_Color - 8, // 0x3c, Set_Combine - 8, // 0x3d, Set_Texture_Image - 8, // 0x3e, Set_Mask_Image - 8 // 0x3f, Set_Color_Image -}; - -void n64_rdp::disassemble(uint64_t *cmd_buf, char* buffer) -{ - char sl[32], tl[32], sh[32], th[32]; - char s[32], t[32], w[32]; - char dsdx[32], dtdx[32], dwdx[32]; - char dsdy[32], dtdy[32], dwdy[32]; - char dsde[32], dtde[32], dwde[32]; - char yl[32], yh[32], ym[32], xl[32], xh[32], xm[32]; - char dxldy[32], dxhdy[32], dxmdy[32]; - char rt[32], gt[32], bt[32], at[32]; - char drdx[32], dgdx[32], dbdx[32], dadx[32]; - char drdy[32], dgdy[32], dbdy[32], dady[32]; - char drde[32], dgde[32], dbde[32], dade[32]; - - const int32_t tile = (cmd_buf[0] >> 56) & 0x7; - sprintf(sl, "%4.2f", (float)((cmd_buf[0] >> 44) & 0xfff) / 4.0f); - sprintf(tl, "%4.2f", (float)((cmd_buf[0] >> 32) & 0xfff) / 4.0f); - sprintf(sh, "%4.2f", (float)((cmd_buf[0] >> 12) & 0xfff) / 4.0f); - sprintf(th, "%4.2f", (float)((cmd_buf[0] >> 0) & 0xfff) / 4.0f); - - const char* format = s_image_format[(cmd_buf[0] >> 53) & 0x7]; - const char* size = s_image_size[(cmd_buf[0] >> 51) & 0x3]; - - const uint32_t r = (cmd_buf[0] >> 24) & 0xff; - const uint32_t g = (cmd_buf[0] >> 16) & 0xff; - const uint32_t b = (cmd_buf[0] >> 8) & 0xff; - const uint32_t a = (cmd_buf[0] >> 0) & 0xff; - - const uint32_t command = (cmd_buf[0] >> 56) & 0x3f; - switch (command) - { - case 0x00: sprintf(buffer, "No Op"); break; - case 0x08: // Tri_NoShade - { - const int32_t lft = (cmd_buf[0] >> 55) & 0x1; - - sprintf(yl, "%4.4f", (float)((cmd_buf[0] >> 32) & 0x1fff) / 4.0f); - sprintf(ym, "%4.4f", (float)((cmd_buf[0] >> 16) & 0x1fff) / 4.0f); - sprintf(yh, "%4.4f", (float)((cmd_buf[0] >> 0) & 0x1fff) / 4.0f); - sprintf(xl, "%4.4f", (float)int32_t(cmd_buf[1] >> 32) / 65536.0f); - sprintf(dxldy, "%4.4f", (float)int32_t(cmd_buf[1]) / 65536.0f); - sprintf(xh, "%4.4f", (float)int32_t(cmd_buf[2] >> 32) / 65536.0f); - sprintf(dxhdy, "%4.4f", (float)int32_t(cmd_buf[2]) / 65536.0f); - sprintf(xm, "%4.4f", (float)int32_t(cmd_buf[3] >> 32) / 65536.0f); - sprintf(dxmdy, "%4.4f", (float)int32_t(cmd_buf[3]) / 65536.0f); - - sprintf(buffer, "Tri_NoShade %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); - break; - } - case 0x09: // Tri_NoShadeZ - { - const int32_t lft = (cmd_buf[0] >> 55) & 0x1; - - sprintf(yl, "%4.4f", (float)((cmd_buf[0] >> 32) & 0x1fff) / 4.0f); - sprintf(ym, "%4.4f", (float)((cmd_buf[0] >> 16) & 0x1fff) / 4.0f); - sprintf(yh, "%4.4f", (float)((cmd_buf[0] >> 0) & 0x1fff) / 4.0f); - sprintf(xl, "%4.4f", (float)int32_t(cmd_buf[1] >> 32) / 65536.0f); - sprintf(dxldy, "%4.4f", (float)int32_t(cmd_buf[1]) / 65536.0f); - sprintf(xh, "%4.4f", (float)int32_t(cmd_buf[2] >> 32) / 65536.0f); - sprintf(dxhdy, "%4.4f", (float)int32_t(cmd_buf[2]) / 65536.0f); - sprintf(xm, "%4.4f", (float)int32_t(cmd_buf[3] >> 32) / 65536.0f); - sprintf(dxmdy, "%4.4f", (float)int32_t(cmd_buf[3]) / 65536.0f); - - sprintf(buffer, "Tri_NoShadeZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); - break; - } - case 0x0a: // Tri_Tex - { - const int32_t lft = (cmd_buf[0] >> 55) & 0x1; - - sprintf(yl, "%4.4f", (float)((cmd_buf[0] >> 32) & 0x1fff) / 4.0f); - sprintf(ym, "%4.4f", (float)((cmd_buf[0] >> 16) & 0x1fff) / 4.0f); - sprintf(yh, "%4.4f", (float)((cmd_buf[0] >> 0) & 0x1fff) / 4.0f); - sprintf(xl, "%4.4f", (float)int32_t(cmd_buf[1] >> 32) / 65536.0f); - sprintf(dxldy, "%4.4f", (float)int32_t(cmd_buf[1]) / 65536.0f); - sprintf(xh, "%4.4f", (float)int32_t(cmd_buf[2] >> 32) / 65536.0f); - sprintf(dxhdy, "%4.4f", (float)int32_t(cmd_buf[2]) / 65536.0f); - sprintf(xm, "%4.4f", (float)int32_t(cmd_buf[3] >> 32) / 65536.0f); - sprintf(dxmdy, "%4.4f", (float)int32_t(cmd_buf[3]) / 65536.0f); - - sprintf(s, "%4.4f", (float)int32_t( ((cmd_buf[4] >> 32) & 0xffff0000) | ((cmd_buf[ 6] >> 48) & 0xffff)) / 65536.0f); - sprintf(t, "%4.4f", (float)int32_t((((cmd_buf[4] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 6] >> 32) & 0xffff)) / 65536.0f); - sprintf(w, "%4.4f", (float)int32_t( (cmd_buf[4] & 0xffff0000) | ((cmd_buf[ 6] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsdx, "%4.4f", (float)int32_t( ((cmd_buf[5] >> 32) & 0xffff0000) | ((cmd_buf[ 7] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtdx, "%4.4f", (float)int32_t((((cmd_buf[5] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 7] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwdx, "%4.4f", (float)int32_t( (cmd_buf[5] & 0xffff0000) | ((cmd_buf[ 7] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsde, "%4.4f", (float)int32_t( ((cmd_buf[8] >> 32) & 0xffff0000) | ((cmd_buf[10] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtde, "%4.4f", (float)int32_t((((cmd_buf[8] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[10] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwde, "%4.4f", (float)int32_t( (cmd_buf[8] & 0xffff0000) | ((cmd_buf[10] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsdy, "%4.4f", (float)int32_t( ((cmd_buf[9] >> 32) & 0xffff0000) | ((cmd_buf[11] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtdy, "%4.4f", (float)int32_t((((cmd_buf[9] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[11] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwdy, "%4.4f", (float)int32_t( (cmd_buf[9] & 0xffff0000) | ((cmd_buf[11] >> 16) & 0xffff)) / 65536.0f); - - buffer+=sprintf(buffer, "Tri_Tex %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy); - break; - } - case 0x0b: // Tri_TexZ - { - const int32_t lft = (cmd_buf[0] >> 55) & 0x1; - - sprintf(yl, "%4.4f", (float)((cmd_buf[0] >> 32) & 0x1fff) / 4.0f); - sprintf(ym, "%4.4f", (float)((cmd_buf[0] >> 16) & 0x1fff) / 4.0f); - sprintf(yh, "%4.4f", (float)((cmd_buf[0] >> 0) & 0x1fff) / 4.0f); - sprintf(xl, "%4.4f", (float)int32_t(cmd_buf[1] >> 32) / 65536.0f); - sprintf(dxldy, "%4.4f", (float)int32_t(cmd_buf[1]) / 65536.0f); - sprintf(xh, "%4.4f", (float)int32_t(cmd_buf[2] >> 32) / 65536.0f); - sprintf(dxhdy, "%4.4f", (float)int32_t(cmd_buf[2]) / 65536.0f); - sprintf(xm, "%4.4f", (float)int32_t(cmd_buf[3] >> 32) / 65536.0f); - sprintf(dxmdy, "%4.4f", (float)int32_t(cmd_buf[3]) / 65536.0f); - - sprintf(s, "%4.4f", (float)int32_t( ((cmd_buf[4] >> 32) & 0xffff0000) | ((cmd_buf[ 6] >> 48) & 0xffff)) / 65536.0f); - sprintf(t, "%4.4f", (float)int32_t((((cmd_buf[4] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 6] >> 32) & 0xffff)) / 65536.0f); - sprintf(w, "%4.4f", (float)int32_t( (cmd_buf[4] & 0xffff0000) | ((cmd_buf[ 6] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsdx, "%4.4f", (float)int32_t( ((cmd_buf[5] >> 32) & 0xffff0000) | ((cmd_buf[ 7] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtdx, "%4.4f", (float)int32_t((((cmd_buf[5] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 7] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwdx, "%4.4f", (float)int32_t( (cmd_buf[5] & 0xffff0000) | ((cmd_buf[ 7] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsde, "%4.4f", (float)int32_t( ((cmd_buf[8] >> 32) & 0xffff0000) | ((cmd_buf[10] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtde, "%4.4f", (float)int32_t((((cmd_buf[8] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[10] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwde, "%4.4f", (float)int32_t( (cmd_buf[8] & 0xffff0000) | ((cmd_buf[10] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsdy, "%4.4f", (float)int32_t( ((cmd_buf[9] >> 32) & 0xffff0000) | ((cmd_buf[11] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtdy, "%4.4f", (float)int32_t((((cmd_buf[9] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[11] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwdy, "%4.4f", (float)int32_t( (cmd_buf[9] & 0xffff0000) | ((cmd_buf[11] >> 16) & 0xffff)) / 65536.0f); - - buffer+=sprintf(buffer, "Tri_TexZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy); - break; - } - case 0x0c: // Tri_Shade - { - const int32_t lft = (cmd_buf[0] >> 23) & 0x1; - - sprintf(yl, "%4.4f", (float)((cmd_buf[0] >> 32) & 0x1fff) / 4.0f); - sprintf(ym, "%4.4f", (float)((cmd_buf[0] >> 16) & 0x1fff) / 4.0f); - sprintf(yh, "%4.4f", (float)((cmd_buf[0] >> 0) & 0x1fff) / 4.0f); - sprintf(xl, "%4.4f", (float)int32_t(cmd_buf[1] >> 32) / 65536.0f); - sprintf(dxldy, "%4.4f", (float)int32_t(cmd_buf[1]) / 65536.0f); - sprintf(xh, "%4.4f", (float)int32_t(cmd_buf[2] >> 32) / 65536.0f); - sprintf(dxhdy, "%4.4f", (float)int32_t(cmd_buf[2]) / 65536.0f); - sprintf(xm, "%4.4f", (float)int32_t(cmd_buf[3] >> 32) / 65536.0f); - sprintf(dxmdy, "%4.4f", (float)int32_t(cmd_buf[3]) / 65536.0f); - - sprintf(rt, "%4.4f", (float)int32_t( ((cmd_buf[4] >> 32) & 0xffff0000) | ((cmd_buf[ 6] >> 48) & 0xffff)) / 65536.0f); - sprintf(gt, "%4.4f", (float)int32_t((((cmd_buf[4] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 6] >> 32) & 0xffff)) / 65536.0f); - sprintf(bt, "%4.4f", (float)int32_t( (cmd_buf[4] & 0xffff0000) | ((cmd_buf[ 6] >> 16) & 0xffff)) / 65536.0f); - sprintf(at, "%4.4f", (float)int32_t( ((cmd_buf[4] & 0x0000ffff) << 16) | ( cmd_buf[ 6] & 0xffff)) / 65536.0f); - sprintf(drdx, "%4.4f", (float)int32_t( ((cmd_buf[5] >> 32) & 0xffff0000) | ((cmd_buf[ 7] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgdx, "%4.4f", (float)int32_t((((cmd_buf[5] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 7] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbdx, "%4.4f", (float)int32_t( (cmd_buf[5] & 0xffff0000) | ((cmd_buf[ 7] >> 16) & 0xffff)) / 65536.0f); - sprintf(dadx, "%4.4f", (float)int32_t( ((cmd_buf[5] & 0x0000ffff) << 16) | ( cmd_buf[ 7] & 0xffff)) / 65536.0f); - sprintf(drde, "%4.4f", (float)int32_t( ((cmd_buf[8] >> 32) & 0xffff0000) | ((cmd_buf[10] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgde, "%4.4f", (float)int32_t((((cmd_buf[8] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[10] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbde, "%4.4f", (float)int32_t( (cmd_buf[8] & 0xffff0000) | ((cmd_buf[10] >> 16) & 0xffff)) / 65536.0f); - sprintf(dade, "%4.4f", (float)int32_t( ((cmd_buf[8] & 0x0000ffff) << 16) | ( cmd_buf[10] & 0xffff)) / 65536.0f); - sprintf(drdy, "%4.4f", (float)int32_t( ((cmd_buf[9] >> 32) & 0xffff0000) | ((cmd_buf[11] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgdy, "%4.4f", (float)int32_t((((cmd_buf[9] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[11] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbdy, "%4.4f", (float)int32_t( (cmd_buf[9] & 0xffff0000) | ((cmd_buf[11] >> 16) & 0xffff)) / 65536.0f); - sprintf(dady, "%4.4f", (float)int32_t( ((cmd_buf[9] & 0x0000ffff) << 16) | ( cmd_buf[11] & 0xffff)) / 65536.0f); - - buffer+=sprintf(buffer, "Tri_Shade %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady); - break; - } - case 0x0d: // Tri_ShadeZ - { - const int32_t lft = (cmd_buf[0] >> 23) & 0x1; - - sprintf(yl, "%4.4f", (float)((cmd_buf[0] >> 32) & 0x1fff) / 4.0f); - sprintf(ym, "%4.4f", (float)((cmd_buf[0] >> 16) & 0x1fff) / 4.0f); - sprintf(yh, "%4.4f", (float)((cmd_buf[0] >> 0) & 0x1fff) / 4.0f); - sprintf(xl, "%4.4f", (float)int32_t(cmd_buf[1] >> 32) / 65536.0f); - sprintf(dxldy, "%4.4f", (float)int32_t(cmd_buf[1]) / 65536.0f); - sprintf(xh, "%4.4f", (float)int32_t(cmd_buf[2] >> 32) / 65536.0f); - sprintf(dxhdy, "%4.4f", (float)int32_t(cmd_buf[2]) / 65536.0f); - sprintf(xm, "%4.4f", (float)int32_t(cmd_buf[3] >> 32) / 65536.0f); - sprintf(dxmdy, "%4.4f", (float)int32_t(cmd_buf[3]) / 65536.0f); - - sprintf(rt, "%4.4f", (float)int32_t( ((cmd_buf[4] >> 32) & 0xffff0000) | ((cmd_buf[ 6] >> 48) & 0xffff)) / 65536.0f); - sprintf(gt, "%4.4f", (float)int32_t((((cmd_buf[4] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 6] >> 32) & 0xffff)) / 65536.0f); - sprintf(bt, "%4.4f", (float)int32_t( (cmd_buf[4] & 0xffff0000) | ((cmd_buf[ 6] >> 16) & 0xffff)) / 65536.0f); - sprintf(at, "%4.4f", (float)int32_t( ((cmd_buf[4] & 0x0000ffff) << 16) | ( cmd_buf[ 6] & 0xffff)) / 65536.0f); - sprintf(drdx, "%4.4f", (float)int32_t( ((cmd_buf[5] >> 32) & 0xffff0000) | ((cmd_buf[ 7] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgdx, "%4.4f", (float)int32_t((((cmd_buf[5] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 7] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbdx, "%4.4f", (float)int32_t( (cmd_buf[5] & 0xffff0000) | ((cmd_buf[ 7] >> 16) & 0xffff)) / 65536.0f); - sprintf(dadx, "%4.4f", (float)int32_t( ((cmd_buf[5] & 0x0000ffff) << 16) | ( cmd_buf[ 7] & 0xffff)) / 65536.0f); - sprintf(drde, "%4.4f", (float)int32_t( ((cmd_buf[8] >> 32) & 0xffff0000) | ((cmd_buf[10] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgde, "%4.4f", (float)int32_t((((cmd_buf[8] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[10] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbde, "%4.4f", (float)int32_t( (cmd_buf[8] & 0xffff0000) | ((cmd_buf[10] >> 16) & 0xffff)) / 65536.0f); - sprintf(dade, "%4.4f", (float)int32_t( ((cmd_buf[8] & 0x0000ffff) << 16) | ( cmd_buf[10] & 0xffff)) / 65536.0f); - sprintf(drdy, "%4.4f", (float)int32_t( ((cmd_buf[9] >> 32) & 0xffff0000) | ((cmd_buf[11] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgdy, "%4.4f", (float)int32_t((((cmd_buf[9] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[11] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbdy, "%4.4f", (float)int32_t( (cmd_buf[9] & 0xffff0000) | ((cmd_buf[11] >> 16) & 0xffff)) / 65536.0f); - sprintf(dady, "%4.4f", (float)int32_t( ((cmd_buf[9] & 0x0000ffff) << 16) | ( cmd_buf[11] & 0xffff)) / 65536.0f); - - buffer+=sprintf(buffer, "Tri_ShadeZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady); - break; - } - case 0x0e: // Tri_TexShade - { - const int32_t lft = (cmd_buf[0] >> 23) & 0x1; - - sprintf(yl, "%4.4f", (float)((cmd_buf[0] >> 32) & 0x1fff) / 4.0f); - sprintf(ym, "%4.4f", (float)((cmd_buf[0] >> 16) & 0x1fff) / 4.0f); - sprintf(yh, "%4.4f", (float)((cmd_buf[0] >> 0) & 0x1fff) / 4.0f); - sprintf(xl, "%4.4f", (float)int32_t(cmd_buf[1] >> 32) / 65536.0f); - sprintf(dxldy, "%4.4f", (float)int32_t(cmd_buf[1]) / 65536.0f); - sprintf(xh, "%4.4f", (float)int32_t(cmd_buf[2] >> 32) / 65536.0f); - sprintf(dxhdy, "%4.4f", (float)int32_t(cmd_buf[2]) / 65536.0f); - sprintf(xm, "%4.4f", (float)int32_t(cmd_buf[3] >> 32) / 65536.0f); - sprintf(dxmdy, "%4.4f", (float)int32_t(cmd_buf[3]) / 65536.0f); - - sprintf(rt, "%4.4f", (float)int32_t( ((cmd_buf[4] >> 32) & 0xffff0000) | ((cmd_buf[ 6] >> 48) & 0xffff)) / 65536.0f); - sprintf(gt, "%4.4f", (float)int32_t((((cmd_buf[4] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 6] >> 32) & 0xffff)) / 65536.0f); - sprintf(bt, "%4.4f", (float)int32_t( (cmd_buf[4] & 0xffff0000) | ((cmd_buf[ 6] >> 16) & 0xffff)) / 65536.0f); - sprintf(at, "%4.4f", (float)int32_t( ((cmd_buf[4] & 0x0000ffff) << 16) | ( cmd_buf[ 6] & 0xffff)) / 65536.0f); - sprintf(drdx, "%4.4f", (float)int32_t( ((cmd_buf[5] >> 32) & 0xffff0000) | ((cmd_buf[ 7] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgdx, "%4.4f", (float)int32_t((((cmd_buf[5] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 7] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbdx, "%4.4f", (float)int32_t( (cmd_buf[5] & 0xffff0000) | ((cmd_buf[ 7] >> 16) & 0xffff)) / 65536.0f); - sprintf(dadx, "%4.4f", (float)int32_t( ((cmd_buf[5] & 0x0000ffff) << 16) | ( cmd_buf[ 7] & 0xffff)) / 65536.0f); - sprintf(drde, "%4.4f", (float)int32_t( ((cmd_buf[8] >> 32) & 0xffff0000) | ((cmd_buf[10] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgde, "%4.4f", (float)int32_t((((cmd_buf[8] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[10] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbde, "%4.4f", (float)int32_t( (cmd_buf[8] & 0xffff0000) | ((cmd_buf[10] >> 16) & 0xffff)) / 65536.0f); - sprintf(dade, "%4.4f", (float)int32_t( ((cmd_buf[8] & 0x0000ffff) << 16) | ( cmd_buf[10] & 0xffff)) / 65536.0f); - sprintf(drdy, "%4.4f", (float)int32_t( ((cmd_buf[9] >> 32) & 0xffff0000) | ((cmd_buf[11] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgdy, "%4.4f", (float)int32_t((((cmd_buf[9] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[11] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbdy, "%4.4f", (float)int32_t( (cmd_buf[9] & 0xffff0000) | ((cmd_buf[11] >> 16) & 0xffff)) / 65536.0f); - sprintf(dady, "%4.4f", (float)int32_t( ((cmd_buf[9] & 0x0000ffff) << 16) | ( cmd_buf[11] & 0xffff)) / 65536.0f); - - sprintf(s, "%4.4f", (float)int32_t( ((cmd_buf[4] >> 32) & 0xffff0000) | ((cmd_buf[ 6] >> 48) & 0xffff)) / 65536.0f); - sprintf(t, "%4.4f", (float)int32_t((((cmd_buf[4] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 6] >> 32) & 0xffff)) / 65536.0f); - sprintf(w, "%4.4f", (float)int32_t( (cmd_buf[4] & 0xffff0000) | ((cmd_buf[ 6] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsdx, "%4.4f", (float)int32_t( ((cmd_buf[5] >> 32) & 0xffff0000) | ((cmd_buf[ 7] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtdx, "%4.4f", (float)int32_t((((cmd_buf[5] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 7] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwdx, "%4.4f", (float)int32_t( (cmd_buf[5] & 0xffff0000) | ((cmd_buf[ 7] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsde, "%4.4f", (float)int32_t( ((cmd_buf[8] >> 32) & 0xffff0000) | ((cmd_buf[10] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtde, "%4.4f", (float)int32_t((((cmd_buf[8] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[10] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwde, "%4.4f", (float)int32_t( (cmd_buf[8] & 0xffff0000) | ((cmd_buf[10] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsdy, "%4.4f", (float)int32_t( ((cmd_buf[9] >> 32) & 0xffff0000) | ((cmd_buf[11] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtdy, "%4.4f", (float)int32_t((((cmd_buf[9] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[11] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwdy, "%4.4f", (float)int32_t( (cmd_buf[9] & 0xffff0000) | ((cmd_buf[11] >> 16) & 0xffff)) / 65536.0f); - - buffer+=sprintf(buffer, "Tri_TexShade %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady); - - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy); - break; - } - case 0x0f: // Tri_TexShadeZ - { - const int32_t lft = (cmd_buf[0] >> 23) & 0x1; - - sprintf(yl, "%4.4f", (float)((cmd_buf[0] >> 32) & 0x1fff) / 4.0f); - sprintf(ym, "%4.4f", (float)((cmd_buf[0] >> 16) & 0x1fff) / 4.0f); - sprintf(yh, "%4.4f", (float)((cmd_buf[0] >> 0) & 0x1fff) / 4.0f); - sprintf(xl, "%4.4f", (float)int32_t(cmd_buf[1] >> 32) / 65536.0f); - sprintf(dxldy, "%4.4f", (float)int32_t(cmd_buf[1]) / 65536.0f); - sprintf(xh, "%4.4f", (float)int32_t(cmd_buf[2] >> 32) / 65536.0f); - sprintf(dxhdy, "%4.4f", (float)int32_t(cmd_buf[2]) / 65536.0f); - sprintf(xm, "%4.4f", (float)int32_t(cmd_buf[3] >> 32) / 65536.0f); - sprintf(dxmdy, "%4.4f", (float)int32_t(cmd_buf[3]) / 65536.0f); - - sprintf(rt, "%4.4f", (float)int32_t( ((cmd_buf[4] >> 32) & 0xffff0000) | ((cmd_buf[ 6] >> 48) & 0xffff)) / 65536.0f); - sprintf(gt, "%4.4f", (float)int32_t((((cmd_buf[4] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 6] >> 32) & 0xffff)) / 65536.0f); - sprintf(bt, "%4.4f", (float)int32_t( (cmd_buf[4] & 0xffff0000) | ((cmd_buf[ 6] >> 16) & 0xffff)) / 65536.0f); - sprintf(at, "%4.4f", (float)int32_t( ((cmd_buf[4] & 0x0000ffff) << 16) | ( cmd_buf[ 6] & 0xffff)) / 65536.0f); - sprintf(drdx, "%4.4f", (float)int32_t( ((cmd_buf[5] >> 32) & 0xffff0000) | ((cmd_buf[ 7] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgdx, "%4.4f", (float)int32_t((((cmd_buf[5] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 7] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbdx, "%4.4f", (float)int32_t( (cmd_buf[5] & 0xffff0000) | ((cmd_buf[ 7] >> 16) & 0xffff)) / 65536.0f); - sprintf(dadx, "%4.4f", (float)int32_t( ((cmd_buf[5] & 0x0000ffff) << 16) | ( cmd_buf[ 7] & 0xffff)) / 65536.0f); - sprintf(drde, "%4.4f", (float)int32_t( ((cmd_buf[8] >> 32) & 0xffff0000) | ((cmd_buf[10] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgde, "%4.4f", (float)int32_t((((cmd_buf[8] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[10] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbde, "%4.4f", (float)int32_t( (cmd_buf[8] & 0xffff0000) | ((cmd_buf[10] >> 16) & 0xffff)) / 65536.0f); - sprintf(dade, "%4.4f", (float)int32_t( ((cmd_buf[8] & 0x0000ffff) << 16) | ( cmd_buf[10] & 0xffff)) / 65536.0f); - sprintf(drdy, "%4.4f", (float)int32_t( ((cmd_buf[9] >> 32) & 0xffff0000) | ((cmd_buf[11] >> 48) & 0xffff)) / 65536.0f); - sprintf(dgdy, "%4.4f", (float)int32_t((((cmd_buf[9] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[11] >> 32) & 0xffff)) / 65536.0f); - sprintf(dbdy, "%4.4f", (float)int32_t( (cmd_buf[9] & 0xffff0000) | ((cmd_buf[11] >> 16) & 0xffff)) / 65536.0f); - sprintf(dady, "%4.4f", (float)int32_t( ((cmd_buf[9] & 0x0000ffff) << 16) | ( cmd_buf[11] & 0xffff)) / 65536.0f); - - sprintf(s, "%4.4f", (float)int32_t( ((cmd_buf[4] >> 32) & 0xffff0000) | ((cmd_buf[ 6] >> 48) & 0xffff)) / 65536.0f); - sprintf(t, "%4.4f", (float)int32_t((((cmd_buf[4] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 6] >> 32) & 0xffff)) / 65536.0f); - sprintf(w, "%4.4f", (float)int32_t( (cmd_buf[4] & 0xffff0000) | ((cmd_buf[ 6] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsdx, "%4.4f", (float)int32_t( ((cmd_buf[5] >> 32) & 0xffff0000) | ((cmd_buf[ 7] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtdx, "%4.4f", (float)int32_t((((cmd_buf[5] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[ 7] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwdx, "%4.4f", (float)int32_t( (cmd_buf[5] & 0xffff0000) | ((cmd_buf[ 7] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsde, "%4.4f", (float)int32_t( ((cmd_buf[8] >> 32) & 0xffff0000) | ((cmd_buf[10] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtde, "%4.4f", (float)int32_t((((cmd_buf[8] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[10] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwde, "%4.4f", (float)int32_t( (cmd_buf[8] & 0xffff0000) | ((cmd_buf[10] >> 16) & 0xffff)) / 65536.0f); - sprintf(dsdy, "%4.4f", (float)int32_t( ((cmd_buf[9] >> 32) & 0xffff0000) | ((cmd_buf[11] >> 48) & 0xffff)) / 65536.0f); - sprintf(dtdy, "%4.4f", (float)int32_t((((cmd_buf[9] >> 32) & 0x0000ffff) << 16) | ((cmd_buf[11] >> 32) & 0xffff)) / 65536.0f); - sprintf(dwdy, "%4.4f", (float)int32_t( (cmd_buf[9] & 0xffff0000) | ((cmd_buf[11] >> 16) & 0xffff)) / 65536.0f); - - buffer+=sprintf(buffer, "Tri_TexShadeZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady); - - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde); - buffer+=sprintf(buffer, " "); - buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy); - break; - } - case 0x24: - case 0x25: - { - sprintf(s, "%4.4f", (float)int16_t((cmd_buf[1] >> 48) & 0xffff) / 32.0f); - sprintf(t, "%4.4f", (float)int16_t((cmd_buf[1] >> 32) & 0xffff) / 32.0f); - sprintf(dsdx, "%4.4f", (float)int16_t((cmd_buf[1] >> 16) & 0xffff) / 1024.0f); - sprintf(dtdy, "%4.4f", (float)int16_t((cmd_buf[1] >> 0) & 0xffff) / 1024.0f); - - if (command == 0x24) - sprintf(buffer, "Texture_Rectangle %d, %s, %s, %s, %s, %s, %s, %s, %s", tile, sh, th, sl, tl, s, t, dsdx, dtdy); - else - sprintf(buffer, "Texture_Rectangle_Flip %d, %s, %s, %s, %s, %s, %s, %s, %s", tile, sh, th, sl, tl, s, t, dsdx, dtdy); - - break; - } - case 0x26: sprintf(buffer, "Sync_Load"); break; - case 0x27: sprintf(buffer, "Sync_Pipe"); break; - case 0x28: sprintf(buffer, "Sync_Tile"); break; - case 0x29: sprintf(buffer, "Sync_Full"); break; - case 0x2d: sprintf(buffer, "Set_Scissor %s, %s, %s, %s", sl, tl, sh, th); break; - case 0x2e: sprintf(buffer, "Set_Prim_Depth %04X, %04X", uint32_t(cmd_buf[0] >> 16) & 0xffff, (uint32_t)cmd_buf[0] & 0xffff); break; - case 0x2f: sprintf(buffer, "Set_Other_Modes %08X %08X", uint32_t(cmd_buf[0] >> 32), (uint32_t)cmd_buf[0]); break; - case 0x30: sprintf(buffer, "Load_TLUT %d, %s, %s, %s, %s", tile, sl, tl, sh, th); break; - case 0x32: sprintf(buffer, "Set_Tile_Size %d, %s, %s, %s, %s", tile, sl, tl, sh, th); break; - case 0x33: sprintf(buffer, "Load_Block %d, %03X, %03X, %03X, %03X", tile, uint32_t(cmd_buf[0] >> 44) & 0xfff, uint32_t(cmd_buf[0] >> 32) & 0xfff, uint32_t(cmd_buf[0] >> 12) & 0xfff, uint32_t(cmd_buf[0]) & 0xfff); break; - case 0x34: sprintf(buffer, "Load_Tile %d, %s, %s, %s, %s", tile, sl, tl, sh, th); break; - case 0x35: sprintf(buffer, "Set_Tile %d, %s, %s, %d, %04X", tile, format, size, (uint32_t(cmd_buf[0] >> 41) & 0x1ff) * 8, (uint32_t(cmd_buf[0] >> 32) & 0x1ff) * 8); break; - case 0x36: sprintf(buffer, "Fill_Rectangle %s, %s, %s, %s", sh, th, sl, tl); break; - case 0x37: sprintf(buffer, "Set_Fill_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break; - case 0x38: sprintf(buffer, "Set_Fog_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break; - case 0x39: sprintf(buffer, "Set_Blend_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break; - case 0x3a: sprintf(buffer, "Set_Prim_Color %d, %d, R: %d, G: %d, B: %d, A: %d", uint32_t(cmd_buf[0] >> 40) & 0x1f, uint32_t(cmd_buf[0] >> 32) & 0xff, r, g, b, a); break; - case 0x3b: sprintf(buffer, "Set_Env_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break; - case 0x3c: sprintf(buffer, "Set_Combine %08X %08X", uint32_t(cmd_buf[0] >> 32), (uint32_t)cmd_buf[0]); break; - case 0x3d: sprintf(buffer, "Set_Texture_Image %s, %s, %d, %08X", format, size, (uint32_t(cmd_buf[0] >> 32) & 0x1ff) + 1, (uint32_t)cmd_buf[0]); break; - case 0x3e: sprintf(buffer, "Set_Mask_Image %08X", (uint32_t)cmd_buf[0]); break; - case 0x3f: sprintf(buffer, "Set_Color_Image %s, %s, %d, %08X", format, size, (uint32_t(cmd_buf[0] >> 32) & 0x1ff) + 1, (uint32_t)cmd_buf[0]); break; - default: sprintf(buffer, "Unknown (%08X %08X)", uint32_t(cmd_buf[0] >> 32), (uint32_t)cmd_buf[0]); break; - } -} - -/*****************************************************************************/ - -static uint32_t rightcvghex(uint32_t x, uint32_t fmask) -{ - uint32_t stickybit = ((x >> 1) & 0x1fff) > 0; - uint32_t covered = ((x >> 14) & 3) + stickybit; - covered = (0xf0 >> covered) & 0xf; - return (covered & fmask); -} - -static uint32_t leftcvghex(uint32_t x, uint32_t fmask) -{ - uint32_t stickybit = ((x >> 1) & 0x1fff) > 0; - uint32_t covered = ((x >> 14) & 3) + stickybit; - covered = 0xf >> covered; - return (covered & fmask); -} - -static int32_t CLIP(int32_t value,int32_t min,int32_t max) -{ - if (value < min) - { - return min; - } - else if (value > max) - { - return max; - } - else - { - return value; - } -} - -void n64_rdp::compute_cvg_noflip(extent_t* spans, int32_t* majorx, int32_t* minorx, int32_t* majorxint, int32_t* minorxint, int32_t scanline, int32_t yh, int32_t yl, int32_t base) -{ - int32_t purgestart = 0xfff; - int32_t purgeend = 0; - const bool writablescanline = !(scanline & ~0x3ff); - const int32_t scanlinespx = scanline << 2; - - if (!writablescanline) return; - - for(int32_t i = 0; i < 4; i++) - { - if (minorxint[i] < purgestart) - { - purgestart = minorxint[i]; - } - if (majorxint[i] > purgeend) - { - purgeend = majorxint[i]; - } - } - - purgestart = CLIP(purgestart, 0, 1023); - purgeend = CLIP(purgeend, 0, 1023); - int32_t length = purgeend - purgestart; - - if (length < 0) return; - - rdp_span_aux* userdata = (rdp_span_aux*)spans[scanline - base].userdata; - memset(&userdata->m_cvg[purgestart], 0, (length + 1) << 1); - - for(int32_t i = 0; i < 4; i++) - { - int32_t minorcur = minorx[i]; - int32_t majorcur = majorx[i]; - int32_t minorcurint = minorxint[i]; - int32_t majorcurint = majorxint[i]; - length = majorcurint - minorcurint; - - int32_t fmask = (i & 1) ? 5 : 0xa; - int32_t maskshift = (i ^ 3) << 2; - int32_t fmaskshifted = fmask << maskshift; - int32_t fleft = CLIP(minorcurint + 1, 0, 647); - int32_t fright = CLIP(majorcurint - 1, 0, 647); - bool valid_y = ((scanlinespx + i) >= yh && (scanlinespx + i) < yl); - if (valid_y && length >= 0) - { - if (minorcurint != majorcurint) - { - if (!(minorcurint & ~0x3ff)) - { - userdata->m_cvg[minorcurint] |= (leftcvghex(minorcur, fmask) << maskshift); - } - if (!(majorcurint & ~0x3ff)) - { - userdata->m_cvg[majorcurint] |= (rightcvghex(majorcur, fmask) << maskshift); - } - } - else - { - if (!(majorcurint & ~0x3ff)) - { - int32_t samecvg = leftcvghex(minorcur, fmask) & rightcvghex(majorcur, fmask); - userdata->m_cvg[majorcurint] |= (samecvg << maskshift); - } - } - for (; fleft <= fright; fleft++) - { - userdata->m_cvg[fleft] |= fmaskshifted; - } - } - } -} - -void n64_rdp::compute_cvg_flip(extent_t* spans, int32_t* majorx, int32_t* minorx, int32_t* majorxint, int32_t* minorxint, int32_t scanline, int32_t yh, int32_t yl, int32_t base) -{ - int32_t purgestart = 0xfff; - int32_t purgeend = 0; - const bool writablescanline = !(scanline & ~0x3ff); - const int32_t scanlinespx = scanline << 2; - - if(!writablescanline) return; - - for(int32_t i = 0; i < 4; i++) - { - if (majorxint[i] < purgestart) - { - purgestart = majorxint[i]; - } - if (minorxint[i] > purgeend) - { - purgeend = minorxint[i]; - } - } - - purgestart = CLIP(purgestart, 0, 1023); - purgeend = CLIP(purgeend, 0, 1023); - - int32_t length = purgeend - purgestart; - - if (length < 0) return; - - rdp_span_aux* userdata = (rdp_span_aux*)spans[scanline - base].userdata; - memset(&userdata->m_cvg[purgestart], 0, (length + 1) << 1); - - for(int32_t i = 0; i < 4; i++) - { - int32_t minorcur = minorx[i]; - int32_t majorcur = majorx[i]; - int32_t minorcurint = minorxint[i]; - int32_t majorcurint = majorxint[i]; - length = minorcurint - majorcurint; - - int32_t fmask = (i & 1) ? 5 : 0xa; - int32_t maskshift = (i ^ 3) << 2; - int32_t fmaskshifted = fmask << maskshift; - int32_t fleft = CLIP(majorcurint + 1, 0, 647); - int32_t fright = CLIP(minorcurint - 1, 0, 647); - bool valid_y = ((scanlinespx + i) >= yh && (scanlinespx + i) < yl); - if (valid_y && length >= 0) - { - if (minorcurint != majorcurint) - { - if (!(minorcurint & ~0x3ff)) - { - userdata->m_cvg[minorcurint] |= (rightcvghex(minorcur, fmask) << maskshift); - } - if (!(majorcurint & ~0x3ff)) - { - userdata->m_cvg[majorcurint] |= (leftcvghex(majorcur, fmask) << maskshift); - } - } - else - { - if (!(majorcurint & ~0x3ff)) - { - int32_t samecvg = rightcvghex(minorcur, fmask) & leftcvghex(majorcur, fmask); - userdata->m_cvg[majorcurint] |= (samecvg << maskshift); - } - } - for (; fleft <= fright; fleft++) - { - userdata->m_cvg[fleft] |= fmaskshifted; - } - } - } -} - -#define SIGN(x, numb) (((x) & ((1 << numb) - 1)) | -((x) & (1 << (numb - 1)))) - -void n64_rdp::draw_triangle(uint64_t *cmd_buf, bool shade, bool texture, bool zbuffer, bool rect) -{ - const uint64_t* cmd_data = rect ? m_temp_rect_data : cmd_buf; - const uint64_t w1 = cmd_data[0]; - - int32_t flip = int32_t(w1 >> 55) & 1; - m_misc_state.m_max_level = uint32_t(w1 >> 51) & 7; - int32_t tilenum = int32_t(w1 >> 48) & 0x7; - - int32_t dsdiff = 0, dtdiff = 0, dwdiff = 0, drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0, dzdiff = 0; - int32_t dsdeh = 0, dtdeh = 0, dwdeh = 0, drdeh = 0, dgdeh = 0, dbdeh = 0, dadeh = 0, dzdeh = 0; - int32_t dsdxh = 0, dtdxh = 0, dwdxh = 0, drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0, dzdxh = 0; - int32_t dsdyh = 0, dtdyh = 0, dwdyh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0, dzdyh = 0; - - int32_t maxxmx = 0; // maxxmx / minxhx very opaque names, consider re-naming - int32_t minxmx = 0; - int32_t maxxhx = 0; - int32_t minxhx = 0; - - int32_t shade_base = 4; - int32_t texture_base = 4; - int32_t zbuffer_base = 4; - if(shade) - { - texture_base += 8; - zbuffer_base += 8; - } - if(texture) - { - zbuffer_base += 8; - } - - uint64_t w2 = cmd_data[1]; - uint64_t w3 = cmd_data[2]; - uint64_t w4 = cmd_data[3]; - - int32_t yl = int32_t(w1 >> 32) & 0x3fff; - int32_t ym = int32_t(w1 >> 16) & 0x3fff; - int32_t yh = int32_t(w1 >> 0) & 0x3fff; - int32_t xl = (int32_t)(w2 >> 32) & 0x3fffffff; - int32_t xh = (int32_t)(w3 >> 32) & 0x3fffffff; - int32_t xm = (int32_t)(w4 >> 32) & 0x3fffffff; - // Inverse slopes in 16.16 format - int32_t dxldy = (int32_t)w2; - int32_t dxhdy = (int32_t)w3; - int32_t dxmdy = (int32_t)w4; - - if (yl & 0x2000) yl |= 0xffffc000; - if (ym & 0x2000) ym |= 0xffffc000; - if (yh & 0x2000) yh |= 0xffffc000; - - if (xl & 0x20000000) xl |= 0xc0000000; - if (xm & 0x20000000) xm |= 0xc0000000; - if (xh & 0x20000000) xh |= 0xc0000000; - - int32_t r = int32_t(((cmd_data[shade_base] >> 32) & 0xffff0000) | ((cmd_data[shade_base + 2] >> 48) & 0x0000ffff)); - int32_t g = int32_t(((cmd_data[shade_base] >> 16) & 0xffff0000) | ((cmd_data[shade_base + 2] >> 32) & 0x0000ffff)); - int32_t b = int32_t( (cmd_data[shade_base] & 0xffff0000) | ((cmd_data[shade_base + 2] >> 16) & 0x0000ffff)); - int32_t a = int32_t(((cmd_data[shade_base] << 16) & 0xffff0000) | (cmd_data[shade_base + 2] & 0x0000ffff)); - const int32_t drdx = int32_t(((cmd_data[shade_base + 1] >> 32) & 0xffff0000) | ((cmd_data[shade_base + 3] >> 48) & 0x0000ffff)); - const int32_t dgdx = int32_t(((cmd_data[shade_base + 1] >> 16) & 0xffff0000) | ((cmd_data[shade_base + 3] >> 32) & 0x0000ffff)); - const int32_t dbdx = int32_t( (cmd_data[shade_base + 1] & 0xffff0000) | ((cmd_data[shade_base + 3] >> 16) & 0x0000ffff)); - const int32_t dadx = int32_t(((cmd_data[shade_base + 1] << 16) & 0xffff0000) | (cmd_data[shade_base + 3] & 0x0000ffff)); - const int32_t drde = int32_t(((cmd_data[shade_base + 4] >> 32) & 0xffff0000) | ((cmd_data[shade_base + 6] >> 48) & 0x0000ffff)); - const int32_t dgde = int32_t(((cmd_data[shade_base + 4] >> 16) & 0xffff0000) | ((cmd_data[shade_base + 6] >> 32) & 0x0000ffff)); - const int32_t dbde = int32_t( (cmd_data[shade_base + 4] & 0xffff0000) | ((cmd_data[shade_base + 6] >> 16) & 0x0000ffff)); - const int32_t dade = int32_t(((cmd_data[shade_base + 4] << 16) & 0xffff0000) | (cmd_data[shade_base + 6] & 0x0000ffff)); - const int32_t drdy = int32_t(((cmd_data[shade_base + 5] >> 32) & 0xffff0000) | ((cmd_data[shade_base + 7] >> 48) & 0x0000ffff)); - const int32_t dgdy = int32_t(((cmd_data[shade_base + 5] >> 16) & 0xffff0000) | ((cmd_data[shade_base + 7] >> 32) & 0x0000ffff)); - const int32_t dbdy = int32_t( (cmd_data[shade_base + 5] & 0xffff0000) | ((cmd_data[shade_base + 7] >> 16) & 0x0000ffff)); - const int32_t dady = int32_t(((cmd_data[shade_base + 5] << 16) & 0xffff0000) | (cmd_data[shade_base + 7] & 0x0000ffff)); - - int32_t s = int32_t(((cmd_data[texture_base] >> 32) & 0xffff0000) | ((cmd_data[texture_base+ 2 ] >> 48) & 0x0000ffff)); - int32_t t = int32_t(((cmd_data[texture_base] >> 16) & 0xffff0000) | ((cmd_data[texture_base+ 2 ] >> 32) & 0x0000ffff)); - int32_t w = int32_t( (cmd_data[texture_base] & 0xffff0000) | ((cmd_data[texture_base+ 2 ] >> 16) & 0x0000ffff)); - const int32_t dsdx = int32_t(((cmd_data[texture_base + 1] >> 32) & 0xffff0000) | ((cmd_data[texture_base + 3] >> 48) & 0x0000ffff)); - const int32_t dtdx = int32_t(((cmd_data[texture_base + 1] >> 16) & 0xffff0000) | ((cmd_data[texture_base + 3] >> 32) & 0x0000ffff)); - const int32_t dwdx = int32_t( (cmd_data[texture_base + 1] & 0xffff0000) | ((cmd_data[texture_base + 3] >> 16) & 0x0000ffff)); - const int32_t dsde = int32_t(((cmd_data[texture_base + 4] >> 32) & 0xffff0000) | ((cmd_data[texture_base + 6] >> 48) & 0x0000ffff)); - const int32_t dtde = int32_t(((cmd_data[texture_base + 4] >> 16) & 0xffff0000) | ((cmd_data[texture_base + 6] >> 32) & 0x0000ffff)); - const int32_t dwde = int32_t( (cmd_data[texture_base + 4] & 0xffff0000) | ((cmd_data[texture_base + 6] >> 16) & 0x0000ffff)); - const int32_t dsdy = int32_t(((cmd_data[texture_base + 5] >> 32) & 0xffff0000) | ((cmd_data[texture_base + 7] >> 48) & 0x0000ffff)); - const int32_t dtdy = int32_t(((cmd_data[texture_base + 5] >> 16) & 0xffff0000) | ((cmd_data[texture_base + 7] >> 32) & 0x0000ffff)); - const int32_t dwdy = int32_t( (cmd_data[texture_base + 5] & 0xffff0000) | ((cmd_data[texture_base + 7] >> 16) & 0x0000ffff)); - - int32_t z = int32_t(cmd_data[zbuffer_base] >> 32); - const int32_t dzdx = int32_t(cmd_data[zbuffer_base]); - const int32_t dzde = int32_t(cmd_data[zbuffer_base+1] >> 32); - const int32_t dzdy = int32_t(cmd_data[zbuffer_base+1]); - - const int32_t dzdy_dz = (dzdy >> 16) & 0xffff; - const int32_t dzdx_dz = (dzdx >> 16) & 0xffff; - - extent_t spans[2048]; -#ifdef MAME_DEBUG - memset(spans, 0xcc, sizeof(spans)); -#endif - - m_span_base.m_span_drdy = drdy; - m_span_base.m_span_dgdy = dgdy; - m_span_base.m_span_dbdy = dbdy; - m_span_base.m_span_dady = dady; - m_span_base.m_span_dzdy = m_other_modes.z_source_sel ? 0 : dzdy; - - uint32_t temp_dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz); - m_span_base.m_span_dr = drdx & ~0x1f; - m_span_base.m_span_dg = dgdx & ~0x1f; - m_span_base.m_span_db = dbdx & ~0x1f; - m_span_base.m_span_da = dadx & ~0x1f; - m_span_base.m_span_ds = dsdx; - m_span_base.m_span_dt = dtdx; - m_span_base.m_span_dw = dwdx; - m_span_base.m_span_dz = m_other_modes.z_source_sel ? 0 : dzdx; - m_span_base.m_span_dymax = 0; - m_span_base.m_span_dzpix = m_dzpix_normalize[temp_dzpix & 0xffff]; - - int32_t xleft_inc = (dxmdy >> 2) & ~1; - int32_t xright_inc = (dxhdy >> 2) & ~1; - - int32_t xright = xh & ~1; - int32_t xleft = xm & ~1; - - const int32_t sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0; - const int32_t do_offset = !(sign_dxhdy ^ (flip)); - - if (do_offset) - { - dsdeh = dsde >> 9; dsdyh = dsdy >> 9; - dtdeh = dtde >> 9; dtdyh = dtdy >> 9; - dwdeh = dwde >> 9; dwdyh = dwdy >> 9; - drdeh = drde >> 9; drdyh = drdy >> 9; - dgdeh = dgde >> 9; dgdyh = dgdy >> 9; - dbdeh = dbde >> 9; dbdyh = dbdy >> 9; - dadeh = dade >> 9; dadyh = dady >> 9; - dzdeh = dzde >> 9; dzdyh = dzdy >> 9; - - dsdiff = (dsdeh << 8) + (dsdeh << 7) - (dsdyh << 8) - (dsdyh << 7); - dtdiff = (dtdeh << 8) + (dtdeh << 7) - (dtdyh << 8) - (dtdyh << 7); - dwdiff = (dwdeh << 8) + (dwdeh << 7) - (dwdyh << 8) - (dwdyh << 7); - drdiff = (drdeh << 8) + (drdeh << 7) - (drdyh << 8) - (drdyh << 7); - dgdiff = (dgdeh << 8) + (dgdeh << 7) - (dgdyh << 8) - (dgdyh << 7); - dbdiff = (dbdeh << 8) + (dbdeh << 7) - (dbdyh << 8) - (dbdyh << 7); - dadiff = (dadeh << 8) + (dadeh << 7) - (dadyh << 8) - (dadyh << 7); - dzdiff = (dzdeh << 8) + (dzdeh << 7) - (dzdyh << 8) - (dzdyh << 7); - } - else - { - dsdiff = dtdiff = dwdiff = drdiff = dgdiff = dbdiff = dadiff = dzdiff = 0; - } - - dsdxh = dsdx >> 8; - dtdxh = dtdx >> 8; - dwdxh = dwdx >> 8; - drdxh = drdx >> 8; - dgdxh = dgdx >> 8; - dbdxh = dbdx >> 8; - dadxh = dadx >> 8; - dzdxh = dzdx >> 8; - - const int32_t ycur = yh & ~3; - const int32_t ylfar = yl | 3; - const int32_t ldflag = (sign_dxhdy ^ flip) ? 0 : 3; - int32_t majorx[4]; - int32_t minorx[4]; - int32_t majorxint[4]; - int32_t minorxint[4]; - - int32_t xfrac = ((xright >> 8) & 0xff); - - const int32_t clipy1 = m_scissor.m_yh; - const int32_t clipy2 = m_scissor.m_yl; - - // Trivial reject - if((ycur >> 2) >= clipy2 && (ylfar >> 2) >= clipy2) - { - return; - } - if((ycur >> 2) < clipy1 && (ylfar >> 2) < clipy1) - { - return; - } - - bool new_object = true; - rdp_poly_state* object = nullptr; - bool valid = false; - - int32_t* minx = flip ? &minxhx : &minxmx; - int32_t* maxx = flip ? &maxxmx : &maxxhx; - int32_t* startx = flip ? maxx : minx; - int32_t* endx = flip ? minx : maxx; - - for (int32_t k = ycur; k <= ylfar; k++) - { - if (k == ym) - { - xleft = xl & ~1; - xleft_inc = (dxldy >> 2) & ~1; - } - - const int32_t xstart = xleft >> 16; - const int32_t xend = xright >> 16; - const int32_t j = k >> 2; - const int32_t spanidx = (k - ycur) >> 2; - const int32_t spix = k & 3; - bool valid_y = !(k < yh || k >= yl); - - if (spanidx >= 0 && spanidx < 2048) - { - majorxint[spix] = xend; - minorxint[spix] = xstart; - majorx[spix] = xright; - minorx[spix] = xleft; - - if (spix == 0) - { - *maxx = 0; - *minx = 0xfff; - } - - if (valid_y) - { - if (flip) - { - *maxx = std::max(xstart, *maxx); - *minx = std::min(xend, *minx); - } - else - { - *minx = std::min(xstart, *minx); - *maxx = std::max(xend, *maxx); - } - } - - if (spix == 0) - { - if(new_object) - { - object = &object_data().next(); - memcpy(object->m_tmem, m_tmem.get(), 0x1000); - new_object = false; - } - - spans[spanidx].userdata = (void*)((uint8_t*)m_aux_buf.get() + m_aux_buf_ptr); - valid = true; - m_aux_buf_ptr += sizeof(rdp_span_aux); - - if(m_aux_buf_ptr >= EXTENT_AUX_COUNT) - { - fatalerror("n64_rdp::draw_triangle: span aux buffer overflow\n"); - } - - rdp_span_aux* userdata = (rdp_span_aux*)spans[spanidx].userdata; - memcpy(&userdata->m_combine, &m_combine, sizeof(combine_modes_t)); - userdata->m_tmem = object->m_tmem; - - userdata->m_blend_color = m_blend_color; - userdata->m_prim_color = m_prim_color; - userdata->m_env_color = m_env_color; - userdata->m_fog_color = m_fog_color; - userdata->m_prim_alpha = m_prim_alpha; - userdata->m_env_alpha = m_env_alpha; - userdata->m_key_scale = m_key_scale; - userdata->m_lod_fraction = m_lod_fraction; - userdata->m_prim_lod_fraction = m_prim_lod_fraction; - userdata->m_k4 = m_k4; - userdata->m_k5 = m_k5; - - // Setup blender data for this scanline - set_blender_input(0, 0, &userdata->m_color_inputs.blender1a_rgb[0], &userdata->m_color_inputs.blender1b_a[0], m_other_modes.blend_m1a_0, m_other_modes.blend_m1b_0, userdata); - set_blender_input(0, 1, &userdata->m_color_inputs.blender2a_rgb[0], &userdata->m_color_inputs.blender2b_a[0], m_other_modes.blend_m2a_0, m_other_modes.blend_m2b_0, userdata); - set_blender_input(1, 0, &userdata->m_color_inputs.blender1a_rgb[1], &userdata->m_color_inputs.blender1b_a[1], m_other_modes.blend_m1a_1, m_other_modes.blend_m1b_1, userdata); - set_blender_input(1, 1, &userdata->m_color_inputs.blender2a_rgb[1], &userdata->m_color_inputs.blender2b_a[1], m_other_modes.blend_m2a_1, m_other_modes.blend_m2b_1, userdata); - - // Setup color combiner data for this scanline - set_suba_input_rgb(&userdata->m_color_inputs.combiner_rgbsub_a[0], m_combine.sub_a_rgb0, userdata); - set_subb_input_rgb(&userdata->m_color_inputs.combiner_rgbsub_b[0], m_combine.sub_b_rgb0, userdata); - set_mul_input_rgb(&userdata->m_color_inputs.combiner_rgbmul[0], m_combine.mul_rgb0, userdata); - set_add_input_rgb(&userdata->m_color_inputs.combiner_rgbadd[0], m_combine.add_rgb0, userdata); - set_sub_input_alpha(&userdata->m_color_inputs.combiner_alphasub_a[0], m_combine.sub_a_a0, userdata); - set_sub_input_alpha(&userdata->m_color_inputs.combiner_alphasub_b[0], m_combine.sub_b_a0, userdata); - set_mul_input_alpha(&userdata->m_color_inputs.combiner_alphamul[0], m_combine.mul_a0, userdata); - set_sub_input_alpha(&userdata->m_color_inputs.combiner_alphaadd[0], m_combine.add_a0, userdata); - - set_suba_input_rgb(&userdata->m_color_inputs.combiner_rgbsub_a[1], m_combine.sub_a_rgb1, userdata); - set_subb_input_rgb(&userdata->m_color_inputs.combiner_rgbsub_b[1], m_combine.sub_b_rgb1, userdata); - set_mul_input_rgb(&userdata->m_color_inputs.combiner_rgbmul[1], m_combine.mul_rgb1, userdata); - set_add_input_rgb(&userdata->m_color_inputs.combiner_rgbadd[1], m_combine.add_rgb1, userdata); - set_sub_input_alpha(&userdata->m_color_inputs.combiner_alphasub_a[1], m_combine.sub_a_a1, userdata); - set_sub_input_alpha(&userdata->m_color_inputs.combiner_alphasub_b[1], m_combine.sub_b_a1, userdata); - set_mul_input_alpha(&userdata->m_color_inputs.combiner_alphamul[1], m_combine.mul_a1, userdata); - set_sub_input_alpha(&userdata->m_color_inputs.combiner_alphaadd[1], m_combine.add_a1, userdata); - } - - if (spix == 3) - { - spans[spanidx].startx = *startx; - spans[spanidx].stopx = *endx; - ((this)->*(m_compute_cvg[flip]))(spans, majorx, minorx, majorxint, minorxint, j, yh, yl, ycur >> 2); - } - - if (spix == ldflag) - { - ((rdp_span_aux*)spans[spanidx].userdata)->m_unscissored_rx = xend; - xfrac = ((xright >> 8) & 0xff); - spans[spanidx].param[SPAN_R].start = ((r >> 9) << 9) + drdiff - (xfrac * drdxh); - spans[spanidx].param[SPAN_G].start = ((g >> 9) << 9) + dgdiff - (xfrac * dgdxh); - spans[spanidx].param[SPAN_B].start = ((b >> 9) << 9) + dbdiff - (xfrac * dbdxh); - spans[spanidx].param[SPAN_A].start = ((a >> 9) << 9) + dadiff - (xfrac * dadxh); - spans[spanidx].param[SPAN_S].start = (((s >> 9) << 9) + dsdiff - (xfrac * dsdxh)) & ~0x1f; - spans[spanidx].param[SPAN_T].start = (((t >> 9) << 9) + dtdiff - (xfrac * dtdxh)) & ~0x1f; - spans[spanidx].param[SPAN_W].start = (((w >> 9) << 9) + dwdiff - (xfrac * dwdxh)) & ~0x1f; - spans[spanidx].param[SPAN_Z].start = ((z >> 9) << 9) + dzdiff - (xfrac * dzdxh); - } - } - - if (spix == 3) - { - r += drde; - g += dgde; - b += dbde; - a += dade; - s += dsde; - t += dtde; - w += dwde; - z += dzde; - } - xleft += xleft_inc; - xright += xright_inc; - } - - if(!new_object && valid) - { - render_spans(yh >> 2, yl >> 2, tilenum, flip ? true : false, spans, rect, object); - } - m_aux_buf_ptr = 0; // Spans can be reused once render completes - //wait("draw_triangle"); -} - -/*****************************************************************************/ - -//////////////////////// -// RDP COMMANDS -//////////////////////// - -void n64_rdp::triangle(uint64_t *cmd_buf, bool shade, bool texture, bool zbuffer) -{ - draw_triangle(cmd_buf, shade, texture, zbuffer, false); - m_pipe_clean = false; -} - -void n64_rdp::cmd_tex_rect(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - const uint64_t w2 = cmd_buf[1]; - - const uint64_t tilenum = (w1 >> 24) & 0x7; - const uint64_t xh = (w1 >> 12) & 0xfff; - const uint64_t xl = (w1 >> 44) & 0xfff; - const uint64_t yh = (w1 >> 0) & 0xfff; - uint64_t yl = (w1 >> 32) & 0xfff; - - const uint64_t s = (w2 >> 48) & 0xffff; - const uint64_t t = (w2 >> 32) & 0xffff; - const uint64_t dsdx = SIGN16((w2 >> 16) & 0xffff); - const uint64_t dtdy = SIGN16((w2 >> 0) & 0xffff); - - if (m_other_modes.cycle_type == CYCLE_TYPE_FILL || m_other_modes.cycle_type == CYCLE_TYPE_COPY) - { - yl |= 3; - } - - const uint64_t xlint = (xl >> 2) & 0x3ff; - const uint64_t xhint = (xh >> 2) & 0x3ff; - - uint64_t* ewdata = m_temp_rect_data; - ewdata[0] = ((uint64_t)0x24 << 56) | ((0x80L | tilenum) << 48) | (yl << 32) | (yl << 16) | yh; // command, flipped, tile, yl - ewdata[1] = (xlint << 48) | ((xl & 3) << 46); // xl, xl frac, dxldy (0), dxldy frac (0) - ewdata[2] = (xhint << 48) | ((xh & 3) << 46); // xh, xh frac, dxhdy (0), dxhdy frac (0) - ewdata[3] = (xlint << 48) | ((xl & 3) << 46); // xm, xm frac, dxmdy (0), dxmdy frac (0) - memset(&ewdata[4], 0, 8 * sizeof(uint64_t)); // shade - ewdata[12] = (s << 48) | (t << 32); // s, t, w (0) - ewdata[13] = (dsdx >> 5) << 48; // dsdx, dtdx, dwdx (0) - ewdata[14] = 0; // s frac (0), t frac (0), w frac (0) - ewdata[15] = (dsdx & 0x1f) << 59; // dsdx frac, dtdx frac, dwdx frac (0) - ewdata[16] = ((dtdy >> 5) & 0xffff) << 32; // dsde, dtde, dwde (0) - ewdata[17] = ((dtdy >> 5) & 0xffff) << 32; // dsdy, dtdy, dwdy (0) - ewdata[18] = ((dtdy & 0x1f) << 11) << 32; // dsde frac, dtde frac, dwde frac (0) - ewdata[19] = ((dtdy & 0x1f) << 11) << 32; // dsdy frac, dtdy frac, dwdy frac (0) - // ewdata[40-43] = 0; // depth - - draw_triangle(cmd_buf, true, true, false, true); -} - -void n64_rdp::cmd_tex_rect_flip(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - const uint64_t w2 = cmd_buf[1]; - - const uint64_t tilenum = (w1 >> 24) & 0x7; - const uint64_t xh = (w1 >> 12) & 0xfff; - const uint64_t xl = (w1 >> 44) & 0xfff; - const uint64_t yh = (w1 >> 0) & 0xfff; - uint64_t yl = (w1 >> 32) & 0xfff; - - const uint64_t s = (w2 >> 48) & 0xffff; - const uint64_t t = (w2 >> 32) & 0xffff; - const uint64_t dsdx = SIGN16((w2 >> 16) & 0xffff); - const uint64_t dtdy = SIGN16((w2 >> 0) & 0xffff); - - if (m_other_modes.cycle_type == CYCLE_TYPE_FILL || m_other_modes.cycle_type == CYCLE_TYPE_COPY) - { - yl |= 3; - } - - const uint64_t xlint = (xl >> 2) & 0x3ff; - const uint64_t xhint = (xh >> 2) & 0x3ff; - - uint64_t* ewdata = m_temp_rect_data; - ewdata[0] = ((uint64_t)0x25 << 56) | ((0x80L | tilenum) << 48) | (yl << 32) | (yl << 16) | yh; // command, flipped, tile, yl - ewdata[1] = (xlint << 48) | ((xl & 3) << 46); // xl, xl frac, dxldy (0), dxldy frac (0) - ewdata[2] = (xhint << 48) | ((xh & 3) << 46); // xh, xh frac, dxhdy (0), dxhdy frac (0) - ewdata[3] = (xlint << 48) | ((xl & 3) << 46); // xm, xm frac, dxmdy (0), dxmdy frac (0) - memset(&ewdata[4], 0, 8 * sizeof(uint64_t)); // shade - ewdata[12] = (s << 48) | (t << 32); // s, t, w (0) - ewdata[13] = ((dtdy >> 5) & 0xffff) << 32; // dsdx, dtdx, dwdx (0) - ewdata[14] = 0; // s frac (0), t frac (0), w frac (0) - ewdata[15] = ((dtdy & 0x1f) << 43); // dsdx frac, dtdx frac, dwdx frac (0) - ewdata[16] = (dsdx >> 5) << 48; // dsde, dtde, dwde (0) - ewdata[17] = (dsdx >> 5) << 48; // dsdy, dtdy, dwdy (0) - ewdata[18] = (dsdx & 0x1f) << 59; // dsde frac, dtde frac, dwde frac (0) - ewdata[19] = (dsdx & 0x1f) << 59; // dsdy frac, dtdy frac, dwdy frac (0) - - draw_triangle(cmd_buf, true, true, false, true); -} - -void n64_rdp::cmd_sync_load(uint64_t *cmd_buf) -{ - //wait("SyncLoad"); -} - -void n64_rdp::cmd_sync_pipe(uint64_t *cmd_buf) -{ - //wait("SyncPipe"); -} - -void n64_rdp::cmd_sync_tile(uint64_t *cmd_buf) -{ - //wait("SyncTile"); -} - -void n64_rdp::cmd_sync_full(uint64_t *cmd_buf) -{ - //wait("SyncFull"); - m_n64_periphs->dp_full_sync(); -} - -void n64_rdp::cmd_set_key_gb(uint64_t *cmd_buf) -{ - m_key_scale.set_b(uint32_t(cmd_buf[0] >> 0) & 0xff); - m_key_scale.set_g(uint32_t(cmd_buf[0] >> 16) & 0xff); -} - -void n64_rdp::cmd_set_key_r(uint64_t *cmd_buf) -{ - m_key_scale.set_r(uint32_t(cmd_buf[0] & 0xff)); -} - -void n64_rdp::cmd_set_fill_color32(uint64_t *cmd_buf) -{ - //wait("SetFillColor"); - m_fill_color = (uint32_t)cmd_buf[0]; -} - -void n64_rdp::cmd_set_convert(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - - if(!m_pipe_clean) { m_pipe_clean = true; wait("SetConvert"); } - int32_t k0 = int32_t(w1 >> 45) & 0x1ff; - int32_t k1 = int32_t(w1 >> 36) & 0x1ff; - int32_t k2 = int32_t(w1 >> 27) & 0x1ff; - int32_t k3 = int32_t(w1 >> 18) & 0x1ff; - int32_t k4 = int32_t(w1 >> 9) & 0x1ff; - int32_t k5 = int32_t(w1 >> 0) & 0x1ff; - - k0 = (SIGN9(k0) << 1) + 1; - k1 = (SIGN9(k1) << 1) + 1; - k2 = (SIGN9(k2) << 1) + 1; - k3 = (SIGN9(k3) << 1) + 1; - - set_yuv_factors(rgbaint_t(0, k0, k2, 0), rgbaint_t(0, 0, k1, k3), rgbaint_t(k4, k4, k4, k4), rgbaint_t(k5, k5, k5, k5)); -} - -void n64_rdp::cmd_set_scissor(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - - m_scissor.m_xh = ((w1 >> 44) & 0xfff) >> 2; - m_scissor.m_yh = ((w1 >> 32) & 0xfff) >> 2; - m_scissor.m_xl = ((w1 >> 12) & 0xfff) >> 2; - m_scissor.m_yl = ((w1 >> 0) & 0xfff) >> 2; - - // TODO: handle f & o? -} - -void n64_rdp::cmd_set_prim_depth(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - m_misc_state.m_primitive_z = (uint16_t)(w1 >> 16) & 0x7fff; - m_misc_state.m_primitive_dz = (uint16_t)(w1 >> 32); -} - -void n64_rdp::cmd_set_other_modes(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - //wait("SetOtherModes"); - m_other_modes.cycle_type = (w1 >> 52) & 0x3; // 01 - m_other_modes.persp_tex_en = (w1 >> 51) & 1; // 1 - m_other_modes.detail_tex_en = (w1 >> 50) & 1; // 0 - m_other_modes.sharpen_tex_en = (w1 >> 49) & 1; // 0 - m_other_modes.tex_lod_en = (w1 >> 48) & 1; // 0 - m_other_modes.en_tlut = (w1 >> 47) & 1; // 0 - m_other_modes.tlut_type = (w1 >> 46) & 1; // 0 - m_other_modes.sample_type = (w1 >> 45) & 1; // 1 - m_other_modes.mid_texel = (w1 >> 44) & 1; // 0 - m_other_modes.bi_lerp0 = (w1 >> 43) & 1; // 1 - m_other_modes.bi_lerp1 = (w1 >> 42) & 1; // 1 - m_other_modes.convert_one = (w1 >> 41) & 1; // 0 - m_other_modes.key_en = (w1 >> 40) & 1; // 0 - m_other_modes.rgb_dither_sel = (w1 >> 38) & 0x3; // 00 - m_other_modes.alpha_dither_sel = (w1 >> 36) & 0x3; // 01 - m_other_modes.blend_m1a_0 = (w1 >> 30) & 0x3; // 11 - m_other_modes.blend_m1a_1 = (w1 >> 28) & 0x3; // 00 - m_other_modes.blend_m1b_0 = (w1 >> 26) & 0x3; // 10 - m_other_modes.blend_m1b_1 = (w1 >> 24) & 0x3; // 00 - m_other_modes.blend_m2a_0 = (w1 >> 22) & 0x3; // 00 - m_other_modes.blend_m2a_1 = (w1 >> 20) & 0x3; // 01 - m_other_modes.blend_m2b_0 = (w1 >> 18) & 0x3; // 00 - m_other_modes.blend_m2b_1 = (w1 >> 16) & 0x3; // 01 - m_other_modes.force_blend = (w1 >> 14) & 1; // 0 - m_other_modes.blend_shift = m_other_modes.force_blend ? 5 : 2; - m_other_modes.alpha_cvg_select = (w1 >> 13) & 1; // 1 - m_other_modes.cvg_times_alpha = (w1 >> 12) & 1; // 0 - m_other_modes.z_mode = (w1 >> 10) & 0x3; // 00 - m_other_modes.cvg_dest = (w1 >> 8) & 0x3; // 00 - m_other_modes.color_on_cvg = (w1 >> 7) & 1; // 0 - m_other_modes.image_read_en = (w1 >> 6) & 1; // 1 - m_other_modes.z_update_en = (w1 >> 5) & 1; // 1 - m_other_modes.z_compare_en = (w1 >> 4) & 1; // 1 - m_other_modes.antialias_en = (w1 >> 3) & 1; // 1 - m_other_modes.z_source_sel = (w1 >> 2) & 1; // 0 - m_other_modes.dither_alpha_en = (w1 >> 1) & 1; // 0 - m_other_modes.alpha_compare_en = (w1 >> 0) & 1; // 0 - m_other_modes.alpha_dither_mode = (m_other_modes.alpha_compare_en << 1) | m_other_modes.dither_alpha_en; -} - -void n64_rdp::cmd_load_tlut(uint64_t *cmd_buf) -{ - //wait("LoadTLUT"); - n64_tile_t* tile = m_tiles; - const uint64_t w1 = cmd_buf[0]; - - const int32_t tilenum = (w1 >> 24) & 0x7; - const int32_t sl = tile[tilenum].sl = int32_t(w1 >> 44) & 0xfff; - const int32_t tl = tile[tilenum].tl = int32_t(w1 >> 32) & 0xfff; - const int32_t sh = tile[tilenum].sh = int32_t(w1 >> 12) & 0xfff; - const int32_t th = tile[tilenum].th = int32_t(w1 >> 0) & 0xfff; - - if (tl != th) - { - fatalerror("Load tlut: tl=%d, th=%d\n",tl,th); - } - - m_capture.data_begin(); - - const int32_t count = ((sh >> 2) - (sl >> 2) + 1) << 2; - - switch (m_misc_state.m_ti_size) - { - case PIXEL_SIZE_16BIT: - { - if (tile[tilenum].tmem < 256) - { - fatalerror("rdp_load_tlut: loading tlut into low half at %d qwords\n",tile[tilenum].tmem); - } - int32_t srcstart = (m_misc_state.m_ti_address + (tl >> 2) * (m_misc_state.m_ti_width << 1) + (sl >> 1)) >> 1; - int32_t dststart = tile[tilenum].tmem << 2; - uint16_t* dst = get_tmem16(); - - for (int32_t i = 0; i < count; i += 4) - { - if (dststart < 2048) - { - dst[dststart] = U_RREADIDX16(srcstart); - m_capture.data_block()->put16(dst[dststart]); - dst[dststart + 1] = dst[dststart]; - dst[dststart + 2] = dst[dststart]; - dst[dststart + 3] = dst[dststart]; - dststart += 4; - srcstart += 1; - } - } - break; - } - default: fatalerror("RDP: load_tlut: size = %d\n", m_misc_state.m_ti_size); - } - - m_capture.data_end(); - - m_tiles[tilenum].sth = rgbaint_t(m_tiles[tilenum].sh, m_tiles[tilenum].sh, m_tiles[tilenum].th, m_tiles[tilenum].th); - m_tiles[tilenum].stl = rgbaint_t(m_tiles[tilenum].sl, m_tiles[tilenum].sl, m_tiles[tilenum].tl, m_tiles[tilenum].tl); -} - -void n64_rdp::cmd_set_tile_size(uint64_t *cmd_buf) -{ - //wait("SetTileSize"); - const uint64_t w1 = cmd_buf[0]; - const int32_t tilenum = int32_t(w1 >> 24) & 0x7; - - m_tiles[tilenum].sl = int32_t(w1 >> 44) & 0xfff; - m_tiles[tilenum].tl = int32_t(w1 >> 32) & 0xfff; - m_tiles[tilenum].sh = int32_t(w1 >> 12) & 0xfff; - m_tiles[tilenum].th = int32_t(w1 >> 0) & 0xfff; - - m_tiles[tilenum].sth = rgbaint_t(m_tiles[tilenum].sh, m_tiles[tilenum].sh, m_tiles[tilenum].th, m_tiles[tilenum].th); - m_tiles[tilenum].stl = rgbaint_t(m_tiles[tilenum].sl, m_tiles[tilenum].sl, m_tiles[tilenum].tl, m_tiles[tilenum].tl); -} - -void n64_rdp::cmd_load_block(uint64_t *cmd_buf) -{ - //wait("LoadBlock"); - n64_tile_t* tile = m_tiles; - const uint64_t w1 = cmd_buf[0]; - - const uint8_t tilenum = uint8_t(w1 >> 24) & 0x7; - uint16_t* tc = get_tmem16(); - - int32_t sl, tl, sh, dxt; - tile[tilenum].sl = sl = int32_t((w1 >> 44) & 0xfff); - tile[tilenum].tl = tl = int32_t((w1 >> 32) & 0xfff); - tile[tilenum].sh = sh = int32_t((w1 >> 12) & 0xfff); - tile[tilenum].th = dxt = int32_t((w1 >> 0) & 0xfff); - - /*uint16_t tl_masked = tl & 0x3ff; - - int32_t load_edge_walker_data[10] = { - ((cmd_buf[0] >> 32) & 0xff000000) | (0x10 << 19) | (tilenum << 16) | ((tl_masked << 2) | 3), - (((tl_masked << 2) | 3) << 16) | (tl_masked << 2), - sh << 16, - sl << 16, - sh << 16, - ((sl << 3) << 16) | (tl << 3), - (dxt & 0xff) << 8, - ((0x80 >> wstate->ti_size) << 16) | (dxt >> 8), - 0x20, - 0x20 - }; - - do_load_edge_walker(load_edge_walker_data);*/ - - int32_t width = (sh - sl) + 1; - - width = (width << m_misc_state.m_ti_size) >> 1; - if (width & 7) - { - width = (width & ~7) + 8; - } - width >>= 3; - - const int32_t tb = tile[tilenum].tmem << 2; - - const int32_t tiwinwords = (m_misc_state.m_ti_width << m_misc_state.m_ti_size) >> 2; - const int32_t slinwords = (sl << m_misc_state.m_ti_size) >> 2; - - const uint32_t src = (m_misc_state.m_ti_address >> 1) + (tl * tiwinwords) + slinwords; - - m_capture.data_begin(); - - if (dxt != 0) - { - int32_t j = 0; - int32_t t = 0; - int32_t oldt = 0; - - if (tile[tilenum].size != PIXEL_SIZE_32BIT && tile[tilenum].format != FORMAT_YUV) - { - for (int32_t i = 0; i < width; i ++) - { - oldt = t; - t = ((j >> 11) & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; - if (t != oldt) - { - i += tile[tilenum].line; - } - - int32_t ptr = tb + (i << 2); - int32_t srcptr = src + (i << 2); - - tc[(ptr ^ t) & 0x7ff] = U_RREADIDX16(srcptr); - tc[((ptr + 1) ^ t) & 0x7ff] = U_RREADIDX16(srcptr + 1); - tc[((ptr + 2) ^ t) & 0x7ff] = U_RREADIDX16(srcptr + 2); - tc[((ptr + 3) ^ t) & 0x7ff] = U_RREADIDX16(srcptr + 3); - - m_capture.data_block()->put16(U_RREADIDX16(srcptr)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+1)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+2)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+3)); - - j += dxt; - } - } - else if (tile[tilenum].format == FORMAT_YUV) - { - for (int32_t i = 0; i < width; i ++) - { - oldt = t; - t = ((j >> 11) & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; - if (t != oldt) - { - i += tile[tilenum].line; - } - - int32_t ptr = ((tb + (i << 1)) ^ t) & 0x3ff; - int32_t srcptr = src + (i << 2); - - int32_t first = U_RREADIDX16(srcptr); - int32_t sec = U_RREADIDX16(srcptr + 1); - tc[ptr] = ((first >> 8) << 8) | (sec >> 8); - tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff); - - ptr = ((tb + (i << 1) + 1) ^ t) & 0x3ff; - first = U_RREADIDX16(srcptr + 2); - sec = U_RREADIDX16(srcptr + 3); - tc[ptr] = ((first >> 8) << 8) | (sec >> 8); - tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff); - - m_capture.data_block()->put16(U_RREADIDX16(srcptr)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+1)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+2)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+3)); - j += dxt; - } - } - else - { - for (int32_t i = 0; i < width; i ++) - { - oldt = t; - t = ((j >> 11) & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; - if (t != oldt) - i += tile[tilenum].line; - - int32_t ptr = ((tb + (i << 1)) ^ t) & 0x3ff; - int32_t srcptr = src + (i << 2); - tc[ptr] = U_RREADIDX16(srcptr); - tc[ptr | 0x400] = U_RREADIDX16(srcptr + 1); - - ptr = ((tb + (i << 1) + 1) ^ t) & 0x3ff; - tc[ptr] = U_RREADIDX16(srcptr + 2); - tc[ptr | 0x400] = U_RREADIDX16(srcptr + 3); - - m_capture.data_block()->put16(U_RREADIDX16(srcptr)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+1)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+2)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+3)); - - j += dxt; - } - } - tile[tilenum].th = tl + (j >> 11); - } - else - { - if (tile[tilenum].size != PIXEL_SIZE_32BIT && tile[tilenum].format != FORMAT_YUV) - { - for (int32_t i = 0; i < width; i ++) - { - int32_t ptr = tb + (i << 2); - int32_t srcptr = src + (i << 2); - tc[(ptr ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr); - tc[((ptr + 1) ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr + 1); - tc[((ptr + 2) ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr + 2); - tc[((ptr + 3) ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr + 3); - - m_capture.data_block()->put16(U_RREADIDX16(srcptr)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+1)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+2)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+3)); - } - } - else if (tile[tilenum].format == FORMAT_YUV) - { - for (int32_t i = 0; i < width; i ++) - { - int32_t ptr = ((tb + (i << 1)) ^ WORD_ADDR_XOR) & 0x3ff; - int32_t srcptr = src + (i << 2); - int32_t first = U_RREADIDX16(srcptr); - int32_t sec = U_RREADIDX16(srcptr + 1); - tc[ptr] = ((first >> 8) << 8) | (sec >> 8);//UV pair - tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff); - - ptr = ((tb + (i << 1) + 1) ^ WORD_ADDR_XOR) & 0x3ff; - first = U_RREADIDX16(srcptr + 2); - sec = U_RREADIDX16(srcptr + 3); - tc[ptr] = ((first >> 8) << 8) | (sec >> 8); - tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff); - - m_capture.data_block()->put16(U_RREADIDX16(srcptr)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+1)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+2)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+3)); - } - } - else - { - for (int32_t i = 0; i < width; i ++) - { - int32_t ptr = ((tb + (i << 1)) ^ WORD_ADDR_XOR) & 0x3ff; - int32_t srcptr = src + (i << 2); - tc[ptr] = U_RREADIDX16(srcptr); - tc[ptr | 0x400] = U_RREADIDX16(srcptr + 1); - - ptr = ((tb + (i << 1) + 1) ^ WORD_ADDR_XOR) & 0x3ff; - tc[ptr] = U_RREADIDX16(srcptr + 2); - tc[ptr | 0x400] = U_RREADIDX16(srcptr + 3); - - m_capture.data_block()->put16(U_RREADIDX16(srcptr)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+1)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+2)); - m_capture.data_block()->put16(U_RREADIDX16(srcptr+3)); - } - } - tile[tilenum].th = tl; - } - - m_capture.data_end(); - - m_tiles[tilenum].sth = rgbaint_t(m_tiles[tilenum].sh, m_tiles[tilenum].sh, m_tiles[tilenum].th, m_tiles[tilenum].th); - m_tiles[tilenum].stl = rgbaint_t(m_tiles[tilenum].sl, m_tiles[tilenum].sl, m_tiles[tilenum].tl, m_tiles[tilenum].tl); -} - -void n64_rdp::cmd_load_tile(uint64_t *cmd_buf) -{ - //wait("LoadTile"); - n64_tile_t* tile = m_tiles; - const uint64_t w1 = cmd_buf[0]; - const int32_t tilenum = int32_t(w1 >> 24) & 0x7; - - tile[tilenum].sl = int32_t(w1 >> 44) & 0xfff; - tile[tilenum].tl = int32_t(w1 >> 32) & 0xfff; - tile[tilenum].sh = int32_t(w1 >> 12) & 0xfff; - tile[tilenum].th = int32_t(w1 >> 0) & 0xfff; - - const int32_t sl = tile[tilenum].sl >> 2; - const int32_t tl = tile[tilenum].tl >> 2; - const int32_t sh = tile[tilenum].sh >> 2; - const int32_t th = tile[tilenum].th >> 2; - - const int32_t width = (sh - sl) + 1; - const int32_t height = (th - tl) + 1; -/* - int32_t topad; - if (m_misc_state.m_ti_size < 3) - { - topad = (width * m_misc_state.m_ti_size) & 0x7; - } - else - { - topad = (width << 2) & 0x7; - } - topad = 0; // ???? -*/ - - m_capture.data_begin(); - - switch (m_misc_state.m_ti_size) - { - case PIXEL_SIZE_8BIT: - { - const uint32_t src = m_misc_state.m_ti_address; - const int32_t tb = tile[tilenum].tmem << 3; - uint8_t* tc = get_tmem8(); - - for (int32_t j = 0; j < height; j++) - { - const int32_t tline = tb + ((tile[tilenum].line << 3) * j); - const int32_t s = ((j + tl) * m_misc_state.m_ti_width) + sl; - const int32_t xorval8 = ((j & 1) ? BYTE_XOR_DWORD_SWAP : BYTE_ADDR_XOR); - - for (int32_t i = 0; i < width; i++) - { - const uint8_t data = U_RREADADDR8(src + s + i); - m_capture.data_block()->put8(data); - tc[((tline + i) ^ xorval8) & 0xfff] = data; - } - } - break; - } - case PIXEL_SIZE_16BIT: - { - const uint32_t src = m_misc_state.m_ti_address >> 1; - uint16_t* tc = get_tmem16(); - - if (tile[tilenum].format != FORMAT_YUV) - { - for (int32_t j = 0; j < height; j++) - { - const int32_t tb = tile[tilenum].tmem << 2; - const int32_t tline = tb + ((tile[tilenum].line << 2) * j); - const int32_t s = ((j + tl) * m_misc_state.m_ti_width) + sl; - const int32_t xorval16 = (j & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; - - for (int32_t i = 0; i < width; i++) - { - const uint32_t taddr = (tline + i) ^ xorval16; - const uint16_t data = U_RREADIDX16(src + s + i); - m_capture.data_block()->put16(data); - tc[taddr & 0x7ff] = data; - } - } - } - else - { - for (int32_t j = 0; j < height; j++) - { - const int32_t tb = tile[tilenum].tmem << 3; - const int32_t tline = tb + ((tile[tilenum].line << 3) * j); - const int32_t s = ((j + tl) * m_misc_state.m_ti_width) + sl; - const int32_t xorval8 = (j & 1) ? BYTE_XOR_DWORD_SWAP : BYTE_ADDR_XOR; - - for (int32_t i = 0; i < width; i++) - { - uint32_t taddr = ((tline + i) ^ xorval8) & 0x7ff; - uint16_t yuvword = U_RREADIDX16(src + s + i); - m_capture.data_block()->put16(yuvword); - get_tmem8()[taddr] = yuvword >> 8; - get_tmem8()[taddr | 0x800] = yuvword & 0xff; - } - } - } - break; - } - case PIXEL_SIZE_32BIT: - { - const uint32_t src = m_misc_state.m_ti_address >> 2; - const int32_t tb = (tile[tilenum].tmem << 2); - uint16_t* tc16 = get_tmem16(); - - for (int32_t j = 0; j < height; j++) - { - const int32_t tline = tb + ((tile[tilenum].line << 2) * j); - - const int32_t s = ((j + tl) * m_misc_state.m_ti_width) + sl; - const int32_t xorval32cur = (j & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; - for (int32_t i = 0; i < width; i++) - { - uint32_t c = U_RREADIDX32(src + s + i); - m_capture.data_block()->put32(c); - uint32_t ptr = ((tline + i) ^ xorval32cur) & 0x3ff; - tc16[ptr] = c >> 16; - tc16[ptr | 0x400] = c & 0xffff; - } - } - break; - } - - default: fatalerror("RDP: load_tile: size = %d\n", m_misc_state.m_ti_size); - } - - m_capture.data_end(); - - m_tiles[tilenum].sth = rgbaint_t(m_tiles[tilenum].sh, m_tiles[tilenum].sh, m_tiles[tilenum].th, m_tiles[tilenum].th); - m_tiles[tilenum].stl = rgbaint_t(m_tiles[tilenum].sl, m_tiles[tilenum].sl, m_tiles[tilenum].tl, m_tiles[tilenum].tl); -} - -void n64_rdp::cmd_set_tile(uint64_t *cmd_buf) -{ - //wait("SetTile"); - const uint64_t w1 = cmd_buf[0]; - const int32_t tilenum = int32_t(w1 >> 24) & 0x7; - n64_tile_t* tex_tile = &m_tiles[tilenum]; - - tex_tile->format = int32_t(w1 >> 53) & 0x7; - tex_tile->size = int32_t(w1 >> 51) & 0x3; - tex_tile->line = int32_t(w1 >> 41) & 0x1ff; - tex_tile->tmem = int32_t(w1 >> 32) & 0x1ff; - tex_tile->palette = int32_t(w1 >> 20) & 0xf; - tex_tile->ct = int32_t(w1 >> 19) & 0x1; - tex_tile->mt = int32_t(w1 >> 18) & 0x1; - tex_tile->mask_t = int32_t(w1 >> 14) & 0xf; - tex_tile->shift_t = int32_t(w1 >> 10) & 0xf; - tex_tile->cs = int32_t(w1 >> 9) & 0x1; - tex_tile->ms = int32_t(w1 >> 8) & 0x1; - tex_tile->mask_s = int32_t(w1 >> 4) & 0xf; - tex_tile->shift_s = int32_t(w1 >> 0) & 0xf; - - tex_tile->lshift_s = (tex_tile->shift_s >= 11) ? (16 - tex_tile->shift_s) : 0; - tex_tile->rshift_s = (tex_tile->shift_s < 11) ? tex_tile->shift_s : 0; - tex_tile->lshift_t = (tex_tile->shift_t >= 11) ? (16 - tex_tile->shift_t) : 0; - tex_tile->rshift_t = (tex_tile->shift_t < 11) ? tex_tile->shift_t : 0; - tex_tile->wrapped_mask_s = (tex_tile->mask_s > 10 ? 10 : tex_tile->mask_s); - tex_tile->wrapped_mask_t = (tex_tile->mask_t > 10 ? 10 : tex_tile->mask_t); - tex_tile->wrapped_mask = rgbaint_t(tex_tile->wrapped_mask_s, tex_tile->wrapped_mask_s, tex_tile->wrapped_mask_t, tex_tile->wrapped_mask_t); - tex_tile->clamp_s = tex_tile->cs || !tex_tile->mask_s; - tex_tile->clamp_t = tex_tile->ct || !tex_tile->mask_t; - tex_tile->mm = rgbaint_t(tex_tile->ms ? ~0 : 0, tex_tile->ms ? ~0 : 0, tex_tile->mt ? ~0 : 0, tex_tile->mt ? ~0 : 0); - tex_tile->invmm = rgbaint_t(tex_tile->ms ? 0 : ~0, tex_tile->ms ? 0 : ~0, tex_tile->mt ? 0 : ~0, tex_tile->mt ? 0 : ~0); - tex_tile->mask = rgbaint_t(tex_tile->mask_s ? ~0 : 0, tex_tile->mask_s ? ~0 : 0, tex_tile->mask_t ? ~0 : 0, tex_tile->mask_t ? ~0 : 0); - tex_tile->invmask = rgbaint_t(tex_tile->mask_s ? 0 : ~0, tex_tile->mask_s ? 0 : ~0, tex_tile->mask_t ? 0 : ~0, tex_tile->mask_t ? 0 : ~0); - tex_tile->lshift = rgbaint_t(tex_tile->lshift_s, tex_tile->lshift_s, tex_tile->lshift_t, tex_tile->lshift_t); - tex_tile->rshift = rgbaint_t(tex_tile->rshift_s, tex_tile->rshift_s, tex_tile->rshift_t, tex_tile->rshift_t); - tex_tile->clamp_st = rgbaint_t(tex_tile->clamp_s ? ~0 : 0, tex_tile->clamp_s ? ~0 : 0, tex_tile->clamp_t ? ~0 : 0, tex_tile->clamp_t ? ~0 : 0); - - if (tex_tile->format == FORMAT_I && tex_tile->size > PIXEL_SIZE_8BIT) - { - tex_tile->format = FORMAT_RGBA; // Used by Supercross 2000 (in-game) - } - if (tex_tile->format == FORMAT_CI && tex_tile->size > PIXEL_SIZE_8BIT) - { - tex_tile->format = FORMAT_RGBA; // Used by Clay Fighter - Sculptor's Cut - } - - if (tex_tile->format == FORMAT_RGBA && tex_tile->size < PIXEL_SIZE_16BIT) - { - tex_tile->format = FORMAT_CI; // Used by Exterem-G2, Madden Football 64, and Rat Attack - } - - //m_pending_mode_block = true; -} - -void n64_rdp::cmd_fill_rect(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; } - const uint64_t xh = (w1 >> 12) & 0xfff; - const uint64_t xl = (w1 >> 44) & 0xfff; - const uint64_t yh = (w1 >> 0) & 0xfff; - uint64_t yl = (w1 >> 32) & 0xfff; - - if (m_other_modes.cycle_type == CYCLE_TYPE_FILL || m_other_modes.cycle_type == CYCLE_TYPE_COPY) - { - yl |= 3; - } - - const uint64_t xlint = (xl >> 2) & 0x3ff; - const uint64_t xhint = (xh >> 2) & 0x3ff; - - uint64_t* ewdata = m_temp_rect_data; - ewdata[0] = ((uint64_t)0x3680 << 48) | (yl << 32) | (yl << 16) | yh; // command, flipped, tile, yl, ym, yh - ewdata[1] = (xlint << 48) | ((xl & 3) << 46); // xl, xl frac, dxldy (0), dxldy frac (0) - ewdata[2] = (xhint << 48) | ((xh & 3) << 46); // xh, xh frac, dxhdy (0), dxhdy frac (0) - ewdata[3] = (xlint << 48) | ((xl & 3) << 46); // xm, xm frac, dxmdy (0), dxmdy frac (0) - memset(&ewdata[4], 0, 18 * sizeof(uint64_t));//shade, texture, depth - - draw_triangle(cmd_buf, false, false, false, true); -} - -void n64_rdp::cmd_set_fog_color(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - m_fog_color.set(uint8_t(w1), uint8_t(w1 >> 24), uint8_t(w1 >> 16), uint8_t(w1 >> 8)); -} - -void n64_rdp::cmd_set_blend_color(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - m_blend_color.set(uint8_t(w1), uint8_t(w1 >> 24), uint8_t(w1 >> 16), uint8_t(w1 >> 8)); -} - -void n64_rdp::cmd_set_prim_color(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - m_misc_state.m_min_level = uint32_t(w1 >> 40) & 0x1f; - const uint8_t prim_lod_fraction(w1 >> 32); - m_prim_lod_fraction.set(prim_lod_fraction, prim_lod_fraction, prim_lod_fraction, prim_lod_fraction); - - const uint8_t alpha(w1); - m_prim_color.set(alpha, uint8_t(w1 >> 24), uint8_t(w1 >> 16), uint8_t(w1 >> 8)); - m_prim_alpha.set(alpha, alpha, alpha, alpha); -} - -void n64_rdp::cmd_set_env_color(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - const uint8_t alpha(w1); - m_env_color.set(alpha, uint8_t(w1 >> 24), uint8_t(w1 >> 16), uint8_t(w1 >> 8)); - m_env_alpha.set(alpha, alpha, alpha, alpha); -} - -void n64_rdp::cmd_set_combine(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - m_combine.sub_a_rgb0 = uint32_t(w1 >> 52) & 0xf; - m_combine.mul_rgb0 = uint32_t(w1 >> 47) & 0x1f; - m_combine.sub_a_a0 = uint32_t(w1 >> 44) & 0x7; - m_combine.mul_a0 = uint32_t(w1 >> 41) & 0x7; - m_combine.sub_a_rgb1 = uint32_t(w1 >> 37) & 0xf; - m_combine.mul_rgb1 = uint32_t(w1 >> 32) & 0x1f; - - m_combine.sub_b_rgb0 = uint32_t(w1 >> 28) & 0xf; - m_combine.sub_b_rgb1 = uint32_t(w1 >> 24) & 0xf; - m_combine.sub_a_a1 = uint32_t(w1 >> 21) & 0x7; - m_combine.mul_a1 = uint32_t(w1 >> 18) & 0x7; - m_combine.add_rgb0 = uint32_t(w1 >> 15) & 0x7; - m_combine.sub_b_a0 = uint32_t(w1 >> 12) & 0x7; - m_combine.add_a0 = uint32_t(w1 >> 9) & 0x7; - m_combine.add_rgb1 = uint32_t(w1 >> 6) & 0x7; - m_combine.sub_b_a1 = uint32_t(w1 >> 3) & 0x7; - m_combine.add_a1 = uint32_t(w1 >> 0) & 0x7; - - /*static const char *s_suba_rgb[16] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "ONE", "NOISE", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO" }; - static const char *s_subb_rgb[16] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "KEYC", "K4", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO" }; - static const char *s_mul_rgb[32] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "KEYS", "CombinedA", "TEX0A", "TEX1A", "PRIMA", "SHADEA", "ENVA", "LODF", "PLODF", "K5", - "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO" }; - static const char *s_add_rgb[8] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "ONE", "ZERO" }; - static const char *s_sub_a[16] = { "CombinedA", "TEX0A", "TEX1A", "PRIMA", "SHADEA", "ENVA", "ONE", "ZERO" }; - static const char *s_mul_a[16] = { "LODF", "TEX0A", "TEX1A", "PRIMA", "SHADEA", "ENVA", "PLODF", "ZERO" }; - printf("Cycle 0, Color: (%s - %s) * %s + %s\n", s_suba_rgb[m_combine.sub_a_rgb0], s_subb_rgb[m_combine.sub_b_rgb0], s_mul_rgb[m_combine.mul_rgb0], s_add_rgb[m_combine.add_rgb0]); - printf("Cycle 0, Alpha: (%s - %s) * %s + %s\n", s_sub_a[m_combine.sub_a_a0], s_sub_a[m_combine.sub_b_a0], s_mul_a[m_combine.mul_a0], s_add_rgb[m_combine.add_a0]); - printf("Cycle 1, Color: (%s - %s) * %s + %s\n", s_suba_rgb[m_combine.sub_a_rgb1], s_subb_rgb[m_combine.sub_b_rgb1], s_mul_rgb[m_combine.mul_rgb1], s_add_rgb[m_combine.add_rgb1]); - printf("Cycle 1, Alpha: (%s - %s) * %s + %s\n\n", s_sub_a[m_combine.sub_a_a1], s_sub_a[m_combine.sub_b_a1], s_mul_a[m_combine.mul_a1], s_add_rgb[m_combine.add_a1]);*/ -} - -void n64_rdp::cmd_set_texture_image(uint64_t *cmd_buf) -{ - const uint64_t w1 = cmd_buf[0]; - m_misc_state.m_ti_format = uint32_t(w1 >> 53) & 0x7; - m_misc_state.m_ti_size = uint32_t(w1 >> 51) & 0x3; - m_misc_state.m_ti_width = (uint32_t(w1 >> 32) & 0x3ff) + 1; - m_misc_state.m_ti_address = uint32_t(w1) & 0x01ffffff; -} - -void n64_rdp::cmd_set_mask_image(uint64_t *cmd_buf) -{ - //wait("SetMaskImage"); - const uint64_t w1 = cmd_buf[0]; - m_misc_state.m_zb_address = uint32_t(w1) & 0x01ffffff; -} - -void n64_rdp::cmd_set_color_image(uint64_t *cmd_buf) -{ - //wait("SetColorImage"); - const uint64_t w1 = cmd_buf[0]; - m_misc_state.m_fb_format = uint32_t(w1 >> 53) & 0x7; - m_misc_state.m_fb_size = uint32_t(w1 >> 51) & 0x3; - m_misc_state.m_fb_width = (uint32_t(w1 >> 32) & 0x3ff) + 1; - m_misc_state.m_fb_address = uint32_t(w1) & 0x01ffffff; -} - -/*****************************************************************************/ - -void n64_rdp::cmd_noop(uint64_t *cmd_buf) -{ - // Do nothing -} - - -void n64_rdp::process_command_list() -{ - int32_t length = m_end - m_current; - - if (length <= 0) - { - m_current = m_end; - return; - } - - //printf("length: %08x\n", (uint32_t)length); fflush(stdout); - - set_status(get_status() &~ DP_STATUS_FREEZE); - - uint64_t curr_cmd_buf[176]; - - while (m_current < m_end) - { - uint32_t start = m_current; - uint32_t buf_index = 0; - curr_cmd_buf[buf_index++] = read_data(m_current & 0x1fffffff); - uint8_t cmd = (curr_cmd_buf[0] >> 56) & 0x3f; - - if ((m_end - m_current) < s_rdp_command_length[cmd]) - { - // Not enough data, continue waiting. - break; - } - m_current += 8; - - while ((buf_index << 3) < s_rdp_command_length[cmd]) - { - curr_cmd_buf[buf_index++] = read_data(m_current & 0x1fffffff); - m_current += 8; - } - - m_capture.command(&curr_cmd_buf[0], s_rdp_command_length[cmd] / 8); - - if (LOG_RDP_EXECUTION) - { - char string[4000]; - disassemble(curr_cmd_buf, string); - - fprintf(rdp_exec, "%08X: %08X%08X %s\n", start, (uint32_t)(curr_cmd_buf[0] >> 32), (uint32_t)curr_cmd_buf[0], string); - fflush(rdp_exec); - } - - // execute the command - switch(cmd) - { - case 0x00: cmd_noop(curr_cmd_buf); break; - - case 0x08: triangle(curr_cmd_buf, false, false, false); break; - case 0x09: triangle(curr_cmd_buf, false, false, true); break; - case 0x0a: triangle(curr_cmd_buf, false, true, false); break; - case 0x0b: triangle(curr_cmd_buf, false, true, true); break; - case 0x0c: triangle(curr_cmd_buf, true, false, false); break; - case 0x0d: triangle(curr_cmd_buf, true, false, true); break; - case 0x0e: triangle(curr_cmd_buf, true, true, false); break; - case 0x0f: triangle(curr_cmd_buf, true, true, true); break; - - case 0x24: cmd_tex_rect(curr_cmd_buf); break; - case 0x25: cmd_tex_rect_flip(curr_cmd_buf); break; - - case 0x26: cmd_sync_load(curr_cmd_buf); break; - case 0x27: cmd_sync_pipe(curr_cmd_buf); break; - case 0x28: cmd_sync_tile(curr_cmd_buf); break; - case 0x29: cmd_sync_full(curr_cmd_buf); break; - - case 0x2a: cmd_set_key_gb(curr_cmd_buf); break; - case 0x2b: cmd_set_key_r(curr_cmd_buf); break; - - case 0x2c: cmd_set_convert(curr_cmd_buf); break; - case 0x3c: cmd_set_combine(curr_cmd_buf); break; - case 0x2d: cmd_set_scissor(curr_cmd_buf); break; - case 0x2e: cmd_set_prim_depth(curr_cmd_buf); break; - case 0x2f: cmd_set_other_modes(curr_cmd_buf);break; - - case 0x30: cmd_load_tlut(curr_cmd_buf); break; - case 0x33: cmd_load_block(curr_cmd_buf); break; - case 0x34: cmd_load_tile(curr_cmd_buf); break; - - case 0x32: cmd_set_tile_size(curr_cmd_buf); break; - case 0x35: cmd_set_tile(curr_cmd_buf); break; - - case 0x36: cmd_fill_rect(curr_cmd_buf); break; - - case 0x37: cmd_set_fill_color32(curr_cmd_buf); break; - case 0x38: cmd_set_fog_color(curr_cmd_buf); break; - case 0x39: cmd_set_blend_color(curr_cmd_buf);break; - case 0x3a: cmd_set_prim_color(curr_cmd_buf); break; - case 0x3b: cmd_set_env_color(curr_cmd_buf); break; - - case 0x3d: cmd_set_texture_image(curr_cmd_buf); break; - case 0x3e: cmd_set_mask_image(curr_cmd_buf); break; - case 0x3f: cmd_set_color_image(curr_cmd_buf); break; - } - }; -} - -/*****************************************************************************/ - -n64_rdp::n64_rdp(n64_state &state, uint32_t* rdram, uint32_t* dmem) : poly_manager(state.machine()) -{ - ignore = false; - dolog = false; - - m_rdram = rdram; - m_dmem = dmem; - - m_aux_buf_ptr = 0; - m_aux_buf = nullptr; - m_pipe_clean = true; - - m_pending_mode_block = false; - - m_start = 0; - m_end = 0; - m_current = 0; - m_status = 0x88; - - m_one.set(0xff, 0xff, 0xff, 0xff); - m_zero.set(0, 0, 0, 0); - - m_tmem = nullptr; - - m_machine = nullptr; - m_n64_periphs = nullptr; - - //memset(m_hidden_bits, 3, 8388608); - - m_prim_lod_fraction.set(0, 0, 0, 0); - z_build_com_table(); - - memset(m_temp_rect_data, 0, sizeof(uint32_t) * 0x1000); - - for (int32_t i = 0; i < 0x4000; i++) - { - uint32_t exponent = (i >> 11) & 7; - uint32_t mantissa = i & 0x7ff; - m_z_complete_dec_table[i] = ((mantissa << m_z_dec_table[exponent].shift) + m_z_dec_table[exponent].add) & 0x3fffff; - } - - precalc_cvmask_derivatives(); - - for(int32_t i = 0; i < 0x200; i++) - { - switch((i >> 7) & 3) - { - case 0: - case 1: - s_special_9bit_clamptable[i] = i & 0xff; - break; - case 2: - s_special_9bit_clamptable[i] = 0xff; - break; - case 3: - s_special_9bit_clamptable[i] = 0; - break; - } - } - - for(int32_t i = 0; i < 32; i++) - { - m_replicated_rgba[i] = (i << 3) | ((i >> 2) & 7); - } - - for(int32_t i = 0; i < 0x10000; i++) - { - m_dzpix_normalize[i] = (uint16_t)normalize_dzpix(i & 0xffff); - } - - m_compute_cvg[0] = &n64_rdp::compute_cvg_noflip; - m_compute_cvg[1] = &n64_rdp::compute_cvg_flip; - - m_write_pixel[0] = &n64_rdp::write_pixel4; - m_write_pixel[1] = &n64_rdp::write_pixel8; - m_write_pixel[2] = &n64_rdp::write_pixel16; - m_write_pixel[3] = &n64_rdp::write_pixel32; - - m_read_pixel[0] = &n64_rdp::read_pixel4; - m_read_pixel[1] = &n64_rdp::read_pixel8; - m_read_pixel[2] = &n64_rdp::read_pixel16; - m_read_pixel[3] = &n64_rdp::read_pixel32; - - m_copy_pixel[0] = &n64_rdp::copy_pixel4; - m_copy_pixel[1] = &n64_rdp::copy_pixel8; - m_copy_pixel[2] = &n64_rdp::copy_pixel16; - m_copy_pixel[3] = &n64_rdp::copy_pixel32; - - m_fill_pixel[0] = &n64_rdp::fill_pixel4; - m_fill_pixel[1] = &n64_rdp::fill_pixel8; - m_fill_pixel[2] = &n64_rdp::fill_pixel16; - m_fill_pixel[3] = &n64_rdp::fill_pixel32; -} - -void n64_rdp::render_spans(int32_t start, int32_t end, int32_t tilenum, bool flip, extent_t* spans, bool rect, rdp_poly_state* object) -{ - const int32_t clipy1 = m_scissor.m_yh; - const int32_t clipy2 = m_scissor.m_yl; - const rectangle clip(m_scissor.m_xh, m_scissor.m_xl, m_scissor.m_yh, m_scissor.m_yl); - - int32_t offset = 0; - - if (clipy2 <= 0) - { - return; - } - - if (start < clipy1) - { - offset = clipy1 - start; - start = clipy1; - } - if (start >= clipy2) - { - offset = start - (clipy2 - 1); - start = clipy2 - 1; - } - if (end < clipy1) - { - end = clipy1; - } - if (end >= clipy2) - { - end = clipy2 - 1; - } - - object->m_rdp = this; - memcpy(&object->m_misc_state, &m_misc_state, sizeof(misc_state_t)); - memcpy(&object->m_other_modes, &m_other_modes, sizeof(other_modes_t)); - memcpy(&object->m_span_base, &m_span_base, sizeof(span_base_t)); - memcpy(&object->m_scissor, &m_scissor, sizeof(rectangle_t)); - memcpy(&object->m_tiles, &m_tiles, 8 * sizeof(n64_tile_t)); - object->tilenum = tilenum; - object->flip = flip; - object->m_fill_color = m_fill_color; - object->rect = rect; - - switch(m_other_modes.cycle_type) - { - case CYCLE_TYPE_1: - render_extents<8>(clip, render_delegate(&n64_rdp::span_draw_1cycle, this), start, (end - start) + 1, spans + offset); - break; - - case CYCLE_TYPE_2: - render_extents<8>(clip, render_delegate(&n64_rdp::span_draw_2cycle, this), start, (end - start) + 1, spans + offset); - break; - - case CYCLE_TYPE_COPY: - render_extents<8>(clip, render_delegate(&n64_rdp::span_draw_copy, this), start, (end - start) + 1, spans + offset); - break; - - case CYCLE_TYPE_FILL: - render_extents<8>(clip, render_delegate(&n64_rdp::span_draw_fill, this), start, (end - start) + 1, spans + offset); - break; - } - wait("render spans"); -} - -void n64_rdp::rgbaz_clip(int32_t sr, int32_t sg, int32_t sb, int32_t sa, int32_t* sz, rdp_span_aux* userdata) -{ - userdata->m_shade_color.set(sa, sr, sg, sb); - userdata->m_shade_color.clamp_and_clear(0xfffffe00); - uint32_t a = userdata->m_shade_color.get_a(); - userdata->m_shade_alpha.set(a, a, a, a); - - int32_t zanded = (*sz) & 0x60000; - - zanded >>= 17; - switch(zanded) - { - case 0: *sz &= 0x3ffff; break; - case 1: *sz &= 0x3ffff; break; - case 2: *sz = 0x3ffff; break; - case 3: *sz = 0x3ffff; break; - } -} - -void n64_rdp::rgbaz_correct_triangle(int32_t offx, int32_t offy, int32_t* r, int32_t* g, int32_t* b, int32_t* a, int32_t* z, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - if (userdata->m_current_pix_cvg == 8) - { - *r >>= 2; - *g >>= 2; - *b >>= 2; - *a >>= 2; - *z = (*z >> 3) & 0x7ffff; - } - else - { - int32_t summand_xr = offx * SIGN13(object.m_span_base.m_span_dr >> 14); - int32_t summand_yr = offy * SIGN13(object.m_span_base.m_span_drdy >> 14); - int32_t summand_xb = offx * SIGN13(object.m_span_base.m_span_db >> 14); - int32_t summand_yb = offy * SIGN13(object.m_span_base.m_span_dbdy >> 14); - int32_t summand_xg = offx * SIGN13(object.m_span_base.m_span_dg >> 14); - int32_t summand_yg = offy * SIGN13(object.m_span_base.m_span_dgdy >> 14); - int32_t summand_xa = offx * SIGN13(object.m_span_base.m_span_da >> 14); - int32_t summand_ya = offy * SIGN13(object.m_span_base.m_span_dady >> 14); - - int32_t summand_xz = offx * SIGN22(object.m_span_base.m_span_dz >> 10); - int32_t summand_yz = offy * SIGN22(object.m_span_base.m_span_dzdy >> 10); - - *r = ((*r << 2) + summand_xr + summand_yr) >> 4; - *g = ((*g << 2) + summand_xg + summand_yg) >> 4; - *b = ((*b << 2) + summand_xb + summand_yb) >> 4; - *a = ((*a << 2) + summand_xa + summand_ya) >> 4; - *z = (((*z << 2) + summand_xz + summand_yz) >> 5) & 0x7ffff; - } -} - -void n64_rdp::write_pixel4(uint32_t curpixel, color_t& color, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - // Not yet implemented -#if DEBUG_RDP_PIXEL - if (s_debug_drawing) - { - uint32_t y = curpixel / object.m_misc_state.m_fb_width; - uint32_t x = curpixel % object.m_misc_state.m_fb_width; - if (x == 157 && y == 89) - { - printf("Writing 4-bit final color: %08x\n", (uint32_t)color.to_rgba()); - } - } -#endif -} - -void n64_rdp::write_pixel8(uint32_t curpixel, color_t& color, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - const uint8_t c = (color.get_r() & 0xf8) | ((color.get_g() & 0xf8) >> 5); - if (c != 0) - RWRITEADDR8(object.m_misc_state.m_fb_address + curpixel, c); - -#if DEBUG_RDP_PIXEL - if (s_debug_drawing) - { - uint32_t y = curpixel / object.m_misc_state.m_fb_width; - uint32_t x = curpixel % object.m_misc_state.m_fb_width; - if (x == 157 && y == 89) - { - printf("Writing 8-bit final color: %08x\n", (uint32_t)color.to_rgba()); - } - } -#endif -} - -void n64_rdp::write_pixel16(uint32_t curpixel, color_t& color, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - const uint32_t fb = (object.m_misc_state.m_fb_address >> 1) + curpixel; - - uint16_t finalcolor; - if (object.m_other_modes.color_on_cvg && !userdata->m_pre_wrap) - { - finalcolor = RREADIDX16(fb) & 0xfffe; - } - else - { - color.shr_imm(3); - finalcolor = (color.get_r() << 11) | (color.get_g() << 6) | (color.get_b() << 1); - } - -#if DEBUG_RDP_PIXEL - if (s_debug_drawing) - { - uint32_t y = curpixel / object.m_misc_state.m_fb_width; - uint32_t x = curpixel % object.m_misc_state.m_fb_width; - if (x == 157 && y == 89) - { - printf("Writing 16-bit final color: %04x\n", finalcolor); - } - } -#endif - - switch (object.m_other_modes.cvg_dest) - { - case 0: - if (userdata->m_blend_enable) - { - uint32_t finalcvg = userdata->m_current_pix_cvg + userdata->m_current_mem_cvg; - if (finalcvg & 8) - { - finalcvg = 7; - } - RWRITEIDX16(fb, finalcolor | (finalcvg >> 2)); - HWRITEADDR8(fb, finalcvg & 3); - } - else - { - const uint32_t finalcvg = (userdata->m_current_pix_cvg - 1) & 7; - RWRITEIDX16(fb, finalcolor | (finalcvg >> 2)); - HWRITEADDR8(fb, finalcvg & 3); - } - break; - case 1: - { - const uint32_t finalcvg = (userdata->m_current_pix_cvg + userdata->m_current_mem_cvg) & 7; - RWRITEIDX16(fb, finalcolor | (finalcvg >> 2)); - HWRITEADDR8(fb, finalcvg & 3); - break; - } - case 2: - RWRITEIDX16(fb, finalcolor | 1); - HWRITEADDR8(fb, 3); - break; - case 3: - RWRITEIDX16(fb, finalcolor | (userdata->m_current_mem_cvg >> 2)); - HWRITEADDR8(fb, userdata->m_current_mem_cvg & 3); - break; - } -} - -void n64_rdp::write_pixel32(uint32_t curpixel, color_t& color, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - const uint32_t fb = (object.m_misc_state.m_fb_address >> 2) + curpixel; - - uint32_t finalcolor; - if (object.m_other_modes.color_on_cvg && !userdata->m_pre_wrap) - { - finalcolor = RREADIDX32(fb) & 0xffffff00; - } - else - { - finalcolor = (color.get_r() << 24) | (color.get_g() << 16) | (color.get_b() << 8); - } - -#if DEBUG_RDP_PIXEL - if (s_debug_drawing) - { - uint32_t y = curpixel / object.m_misc_state.m_fb_width; - uint32_t x = curpixel % object.m_misc_state.m_fb_width; - if (x == 157 && y == 89) - { - printf("Writing 32-bit final color: %08x\n", finalcolor); - } - } -#endif - - switch (object.m_other_modes.cvg_dest) - { - case 0: - if (userdata->m_blend_enable) - { - uint32_t finalcvg = userdata->m_current_pix_cvg + userdata->m_current_mem_cvg; - if (finalcvg & 8) - { - finalcvg = 7; - } - - RWRITEIDX32(fb, finalcolor | (finalcvg << 5)); - } - else - { - RWRITEIDX32(fb, finalcolor | (((userdata->m_current_pix_cvg - 1) & 7) << 5)); - } - break; - case 1: - RWRITEIDX32(fb, finalcolor | (((userdata->m_current_pix_cvg + userdata->m_current_mem_cvg) & 7) << 5)); - break; - case 2: - RWRITEIDX32(fb, finalcolor | 0xE0); - break; - case 3: - RWRITEIDX32(fb, finalcolor | (userdata->m_current_mem_cvg << 5)); - break; - } -} - -void n64_rdp::read_pixel4(uint32_t curpixel, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - userdata->m_memory_color.set(0, 0, 0, 0); - userdata->m_current_mem_cvg = 7; -} - -void n64_rdp::read_pixel8(uint32_t curpixel, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - const uint8_t fbyte = RREADADDR8(object.m_misc_state.m_fb_address + curpixel); - const uint8_t r8 = (fbyte & 0xf8) | (fbyte >> 5); - uint8_t g8 = (fbyte & 0x07); - g8 |= g8 << 3; - g8 |= g8 << 6; - userdata->m_memory_color.set(0, r8, g8, 0); - userdata->m_memory_color.set_a(0xff); - userdata->m_current_mem_cvg = 7; -} - -void n64_rdp::read_pixel16(uint32_t curpixel, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - const uint16_t fword = RREADIDX16((object.m_misc_state.m_fb_address >> 1) + curpixel); - - userdata->m_memory_color.set(0, GETHICOL(fword), GETMEDCOL(fword), GETLOWCOL(fword)); - if (object.m_other_modes.image_read_en) - { - uint8_t hbyte = HREADADDR8((object.m_misc_state.m_fb_address >> 1) + curpixel); - userdata->m_memory_color.set_a(userdata->m_current_mem_cvg << 5); - userdata->m_current_mem_cvg = ((fword & 1) << 2) | (hbyte & 3); - } - else - { - userdata->m_memory_color.set_a(0xff); - userdata->m_current_mem_cvg = 7; - } -} - -void n64_rdp::read_pixel32(uint32_t curpixel, rdp_span_aux* userdata, const rdp_poly_state &object) -{ - const uint32_t mem = RREADIDX32((object.m_misc_state.m_fb_address >> 2) + curpixel); - userdata->m_memory_color.set(0, (mem >> 24) & 0xff, (mem >> 16) & 0xff, (mem >> 8) & 0xff); - if (object.m_other_modes.image_read_en) - { - userdata->m_memory_color.set_a(mem & 0xff); - userdata->m_current_mem_cvg = (mem >> 5) & 7; - } - else - { - userdata->m_memory_color.set_a(0xff); - userdata->m_current_mem_cvg = 7; - } -} - -void n64_rdp::copy_pixel4(uint32_t curpixel, color_t& color, const rdp_poly_state &object) -{ - // Not yet implemented -} - -void n64_rdp::copy_pixel8(uint32_t curpixel, color_t& color, const rdp_poly_state &object) -{ - const uint8_t c = (color.get_r() & 0xf8) | ((color.get_g() & 0xf8) >> 5); - if (c != 0) - RWRITEADDR8(object.m_misc_state.m_fb_address + curpixel, c); -} - -void n64_rdp::copy_pixel16(uint32_t curpixel, color_t& color, const rdp_poly_state &object) -{ - const uint32_t current_pix_cvg = color.get_a() ? 7 : 0; - const uint8_t r = color.get_r(); // Vectorize me - const uint8_t g = color.get_g(); - const uint8_t b = color.get_b(); - RWRITEIDX16((object.m_misc_state.m_fb_address >> 1) + curpixel, ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1) | ((current_pix_cvg >> 2) & 1)); - HWRITEADDR8((object.m_misc_state.m_fb_address >> 1) + curpixel, current_pix_cvg & 3); -} - -void n64_rdp::copy_pixel32(uint32_t curpixel, color_t& color, const rdp_poly_state &object) -{ - const uint32_t current_pix_cvg = color.get_a() ? 7 : 0; - const uint8_t r = color.get_r(); // Vectorize me - const uint8_t g = color.get_g(); - const uint8_t b = color.get_b(); - RWRITEIDX32((object.m_misc_state.m_fb_address >> 2) + curpixel, (r << 24) | (g << 16) | (b << 8) | (current_pix_cvg << 5)); -} - -void n64_rdp::fill_pixel4(uint32_t curpixel, const rdp_poly_state &object) -{ - // Not yet implemented -} - -void n64_rdp::fill_pixel8(uint32_t curpixel, const rdp_poly_state &object) -{ - const uint8_t byte_shift = ((curpixel & 3) ^ BYTE_ADDR_XOR) << 3; - RWRITEADDR8(object.m_misc_state.m_fb_address + curpixel, (uint8_t)(object.m_fill_color >> byte_shift)); -} - -void n64_rdp::fill_pixel16(uint32_t curpixel, const rdp_poly_state &object) -{ - uint16_t val; - if (curpixel & 1) - { - val = object.m_fill_color & 0xffff; - } - else - { - val = (object.m_fill_color >> 16) & 0xffff; - } - RWRITEIDX16((object.m_misc_state.m_fb_address >> 1) + curpixel, val); - HWRITEADDR8((object.m_misc_state.m_fb_address >> 1) + curpixel, ((val & 1) << 1) | (val & 1)); -} - -void n64_rdp::fill_pixel32(uint32_t curpixel, const rdp_poly_state &object) -{ - RWRITEIDX32((object.m_misc_state.m_fb_address >> 2) + curpixel, object.m_fill_color); - HWRITEADDR8((object.m_misc_state.m_fb_address >> 1) + (curpixel << 1), (object.m_fill_color & 0x10000) ? 3 : 0); - HWRITEADDR8((object.m_misc_state.m_fb_address >> 1) + (curpixel << 1) + 1, (object.m_fill_color & 0x1) ? 3 : 0); -} - -void n64_rdp::span_draw_1cycle(int32_t scanline, const extent_t &extent, const rdp_poly_state &object, int32_t threadid) -{ - assert(object.m_misc_state.m_fb_size < 4); - - const int32_t clipx1 = object.m_scissor.m_xh; - const int32_t clipx2 = object.m_scissor.m_xl; - const int32_t tilenum = object.tilenum; - const bool flip = object.flip; - - span_param_t r; r.w = extent.param[SPAN_R].start; - span_param_t g; g.w = extent.param[SPAN_G].start; - span_param_t b; b.w = extent.param[SPAN_B].start; - span_param_t a; a.w = extent.param[SPAN_A].start; - span_param_t z; z.w = extent.param[SPAN_Z].start; - span_param_t s; s.w = extent.param[SPAN_S].start; - span_param_t t; t.w = extent.param[SPAN_T].start; - span_param_t w; w.w = extent.param[SPAN_W].start; - - const uint32_t zb = object.m_misc_state.m_zb_address >> 1; - const uint32_t zhb = object.m_misc_state.m_zb_address; - -#ifdef PTR64 - assert(extent.userdata != (const void *)0xcccccccccccccccc); -#else - assert(extent.userdata != (const void *)0xcccccccc); -#endif - rdp_span_aux* userdata = (rdp_span_aux*)extent.userdata; - - m_tex_pipe.calculate_clamp_diffs(tilenum, userdata, object); - - const bool partialreject = (userdata->m_color_inputs.blender2b_a[0] == &userdata->m_inv_pixel_color && userdata->m_color_inputs.blender1b_a[0] == &userdata->m_pixel_color); - const int32_t sel0 = (userdata->m_color_inputs.blender2b_a[0] == &userdata->m_memory_color) ? 1 : 0; - - int32_t drinc, dginc, dbinc, dainc; - int32_t dzinc, dzpix; - int32_t dsinc, dtinc, dwinc; - int32_t xinc; - - if (!flip) - { - drinc = -object.m_span_base.m_span_dr; - dginc = -object.m_span_base.m_span_dg; - dbinc = -object.m_span_base.m_span_db; - dainc = -object.m_span_base.m_span_da; - dzinc = -object.m_span_base.m_span_dz; - dsinc = -object.m_span_base.m_span_ds; - dtinc = -object.m_span_base.m_span_dt; - dwinc = -object.m_span_base.m_span_dw; - xinc = -1; - } - else - { - drinc = object.m_span_base.m_span_dr; - dginc = object.m_span_base.m_span_dg; - dbinc = object.m_span_base.m_span_db; - dainc = object.m_span_base.m_span_da; - dzinc = object.m_span_base.m_span_dz; - dsinc = object.m_span_base.m_span_ds; - dtinc = object.m_span_base.m_span_dt; - dwinc = object.m_span_base.m_span_dw; - xinc = 1; - } - - const int32_t fb_index = object.m_misc_state.m_fb_width * scanline; - - const int32_t xstart = extent.startx; - const int32_t xend = userdata->m_unscissored_rx; - const int32_t xend_scissored = extent.stopx; - - int32_t x = xend; - - const int32_t length = flip ? (xstart - xend) : (xend - xstart); - - if(object.m_other_modes.z_source_sel) - { - z.w = (uint32_t)object.m_misc_state.m_primitive_z << 16; - dzpix = object.m_misc_state.m_primitive_dz; - dzinc = 0; - } - else - { - dzpix = object.m_span_base.m_span_dzpix; - } - - if (object.m_misc_state.m_fb_size > 4) - fatalerror("unsupported m_fb_size %d\n", object.m_misc_state.m_fb_size); - - const int32_t blend_index = (object.m_other_modes.alpha_cvg_select ? 2 : 0) | ((object.m_other_modes.rgb_dither_sel < 3) ? 1 : 0); - const int32_t cycle0 = ((object.m_other_modes.sample_type & 1) << 1) | (object.m_other_modes.bi_lerp0 & 1); - - int32_t sss = 0; - int32_t sst = 0; - - if (object.m_other_modes.persp_tex_en) - { - tc_div(s.w >> 16, t.w >> 16, w.w >> 16, &sss, &sst); - } - else - { - tc_div_no_perspective(s.w >> 16, t.w >> 16, w.w >> 16, &sss, &sst); - } - - userdata->m_start_span = true; - for (int32_t j = 0; j <= length; j++) - { - int32_t sr = r.w >> 14; - int32_t sg = g.w >> 14; - int32_t sb = b.w >> 14; - int32_t sa = a.w >> 14; - int32_t sz = (z.w >> 10) & 0x3fffff; - const bool valid_x = (flip) ? (x >= xend_scissored) : (x <= xend_scissored); - - if (x >= clipx1 && x < clipx2 && valid_x) - { - uint8_t offx, offy; - lookup_cvmask_derivatives(userdata->m_cvg[x], &offx, &offy, userdata); - - m_tex_pipe.lod_1cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc, userdata, object); - - rgbaz_correct_triangle(offx, offy, &sr, &sg, &sb, &sa, &sz, userdata, object); - rgbaz_clip(sr, sg, sb, sa, &sz, userdata); - - ((m_tex_pipe).*(m_tex_pipe.m_cycle[cycle0]))(&userdata->m_texel0_color, &userdata->m_texel0_color, sss, sst, tilenum, 0, userdata, object/*, false*/); - uint32_t t0a = userdata->m_texel0_color.get_a(); - userdata->m_texel0_alpha.set(t0a, t0a, t0a, t0a); - userdata->m_texel1_color = userdata->m_texel0_color; - userdata->m_texel1_alpha = userdata->m_texel0_alpha; - - const uint8_t noise = machine().rand() << 3; // Not accurate - userdata->m_noise_color.set(0, noise, noise, noise); - - rgbaint_t rgbsub_a(*userdata->m_color_inputs.combiner_rgbsub_a[1]); - rgbaint_t rgbsub_b(*userdata->m_color_inputs.combiner_rgbsub_b[1]); - rgbaint_t rgbmul(*userdata->m_color_inputs.combiner_rgbmul[1]); - rgbaint_t rgbadd(*userdata->m_color_inputs.combiner_rgbadd[1]); - - rgbsub_a.merge_alpha(*userdata->m_color_inputs.combiner_alphasub_a[1]); - rgbsub_b.merge_alpha(*userdata->m_color_inputs.combiner_alphasub_b[1]); - rgbmul.merge_alpha(*userdata->m_color_inputs.combiner_alphamul[1]); - rgbadd.merge_alpha(*userdata->m_color_inputs.combiner_alphaadd[1]); - - rgbsub_a.sign_extend(0x180, 0xfffffe00); - rgbsub_b.sign_extend(0x180, 0xfffffe00); - rgbadd.sign_extend(0x180, 0xfffffe00); - - rgbadd.shl_imm(8); - rgbsub_a.sub(rgbsub_b); - rgbsub_a.mul(rgbmul); - rgbsub_a.add(rgbadd); - rgbsub_a.add_imm(0x0080); - rgbsub_a.sra_imm(8); - rgbsub_a.clamp_and_clear(0xfffffe00); - - userdata->m_pixel_color = rgbsub_a; - - //Alpha coverage combiner - userdata->m_pixel_color.set_a(get_alpha_cvg(userdata->m_pixel_color.get_a(), userdata, object)); - - const uint32_t curpixel = fb_index + x; - const uint32_t zbcur = zb + curpixel; - const uint32_t zhbcur = zhb + curpixel; - - ((this)->*(m_read_pixel[object.m_misc_state.m_fb_size]))(curpixel, userdata, object); - -#if DEBUG_RDP_PIXEL - if (s_debug_drawing) - { - //uint32_t x = curpixel % m_n64_periphs->vi_width; - //uint32_t y = curpixel / m_n64_periphs->vi_width; - //printf("%d, %d ", x, scanline); - if (x == 157 && scanline == 89) - { - if (true)//finalcolor == 0) - { - static const char *s_fb_format[4] = { "I", "IA", "CI", "RGBA" }; - static const char *s_blend1a_c0[4] = { "PIXC", "MEMC", "BLENDC", "FOGC" }; - static const char *s_blend1b_c0[4] = { "PIXA", "FOGA", "SHADEA", "ZERO" }; - static const char *s_blend2a_c0[4] = { "PIXC", "MEMC", "BLENDC", "FOGC" }; - static const char *s_blend2b_c0[4] = { "INVPIXA", "MEMA", "ONE", "ZERO" }; - static const char *s_blend1a_c1[4] = { "BPIXC", "MEMC", "BLENDC", "FOGC" }; - static const char *s_blend1b_c1[4] = { "PIXA", "FOGA", "SHADEA", "ZERO" }; - static const char *s_blend2a_c1[4] = { "BPIXC", "MEMC", "BLENDC", "FOGC" }; - static const char *s_blend2b_c1[4] = { "INVPIXA", "MEMA", "ONE", "ZERO" }; - static const char *s_suba_rgb[16] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "ONE", "NOISE", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO" }; - static const char *s_subb_rgb[16] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "KEYC", "K4", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO" }; - static const char *s_mul_rgb[32] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "KEYS", "CombinedA", "TEX0A", "TEX1A", "PRIMA", "SHADEA", "ENVA", "LODF", "PLODF", "K5", - "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO" }; - static const char *s_add_rgb[8] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "ONE", "ZERO" }; - static const char *s_sub_a[16] = { "CombinedA", "TEX0A", "TEX1A", "PRIMA", "SHADEA", "ENVA", "ONE", "ZERO" }; - static const char *s_mul_a[16] = { "LODF", "TEX0A", "TEX1A", "PRIMA", "SHADEA", "ENVA", "PLODF", "ZERO" }; - - printf("Write to %08x: %d, %d\n", curpixel, x, scanline); - printf("m_fb_size: %d\n", 4 << object.m_misc_state.m_fb_size); - printf("m_fb_format: %s\n", s_fb_format[object.m_misc_state.m_fb_format]); - printf("blend enable: %d\n", userdata->m_blend_enable); - printf("other modes:\n"); - printf(" cycle_type: %d\n", object.m_other_modes.cycle_type); - printf(" persp_tex_en: %d\n", object.m_other_modes.persp_tex_en); - printf(" detail_tex_en: %d\n", object.m_other_modes.detail_tex_en); - printf(" sharpen_tex_en: %d\n", object.m_other_modes.sharpen_tex_en); - printf(" tex_lod_en: %d\n", object.m_other_modes.tex_lod_en); - printf(" en_tlut: %d\n", object.m_other_modes.en_tlut); - printf(" tlut_type: %d\n", object.m_other_modes.tlut_type); - printf(" sample_type: %d\n", object.m_other_modes.sample_type); - printf(" mid_texel: %d\n", object.m_other_modes.mid_texel); - printf(" bi_lerp0: %d\n", object.m_other_modes.bi_lerp0); - printf(" bi_lerp1: %d\n", object.m_other_modes.bi_lerp1); - printf(" convert_one: %d\n", object.m_other_modes.convert_one); - printf(" key_en: %d\n", object.m_other_modes.key_en); - printf(" rgb_dither_sel: %d\n", object.m_other_modes.rgb_dither_sel); - printf(" alpha_dither_sel: %d\n", object.m_other_modes.alpha_dither_sel); - printf(" blend_m1a_0 (A Cycle 0, 1): %s\n", s_blend1a_c0[object.m_other_modes.blend_m1a_0]); - printf(" blend_m1a_1 (A Cycle 1, 1): %s\n", s_blend1a_c1[object.m_other_modes.blend_m1a_1]); - printf(" blend_m1b_0 (B Cycle 0, 1): %s\n", s_blend1b_c0[object.m_other_modes.blend_m1b_0]); - printf(" blend_m1b_1 (B Cycle 1, 1): %s\n", s_blend1b_c1[object.m_other_modes.blend_m1b_1]); - printf(" blend_m2a_0 (A Cycle 0, 2): %s\n", s_blend2a_c0[object.m_other_modes.blend_m2a_0]); - printf(" blend_m2a_1 (A Cycle 1, 2): %s\n", s_blend2a_c1[object.m_other_modes.blend_m2a_1]); - printf(" blend_m2b_0 (B Cycle 0, 2): %s\n", s_blend2b_c0[object.m_other_modes.blend_m2b_0]); - printf(" blend_m2b_1 (B Cycle 1, 2): %s\n", s_blend2b_c1[object.m_other_modes.blend_m2b_1]); - printf(" tex_edge: %d\n", object.m_other_modes.tex_edge); - printf(" force_blend: %d\n", object.m_other_modes.force_blend); - printf(" blend_shift: %d\n", object.m_other_modes.blend_shift); - printf(" alpha_cvg_select: %d\n", object.m_other_modes.alpha_cvg_select); - printf(" cvg_times_alpha: %d\n", object.m_other_modes.cvg_times_alpha); - printf(" z_mode: %d\n", object.m_other_modes.z_mode); - printf(" cvg_dest: %d\n", object.m_other_modes.cvg_dest); - printf(" color_on_cvg: %d\n", object.m_other_modes.color_on_cvg); - printf(" image_read_en: %d\n", object.m_other_modes.image_read_en); - printf(" z_update_en: %d\n", object.m_other_modes.z_update_en); - printf(" z_compare_en: %d\n", object.m_other_modes.z_compare_en); - printf(" antialias_en: %d\n", object.m_other_modes.antialias_en); - printf(" z_source_sel: %d\n", object.m_other_modes.z_source_sel); - printf(" dither_alpha_en: %d\n", object.m_other_modes.dither_alpha_en); - printf(" alpha_compare_en: %d\n", object.m_other_modes.alpha_compare_en); - printf(" alpha_dither_mode: %d\n", object.m_other_modes.alpha_dither_mode); - printf("combine:\n"); - printf(" RGB sub A, cycle 0: %s\n", s_suba_rgb[m_combine.sub_a_rgb0]); - printf(" RGB sub B, cycle 0: %s\n", s_subb_rgb[m_combine.sub_b_rgb0]); - printf(" RGB mul, cycle 0: %s\n", s_mul_rgb[m_combine.mul_rgb0]); - printf(" RGB add, cycle 0: %s\n", s_add_rgb[m_combine.add_rgb0]); - printf(" Alpha sub A, cycle 0: %s\n", s_sub_a[m_combine.sub_a_a0]); - printf(" Alpha sub B, cycle 0: %s\n", s_sub_a[m_combine.sub_b_a0]); - printf(" Alpha mul, cycle 0: %s\n", s_mul_a[m_combine.mul_a0]); - printf(" Alpha add, cycle 0: %s\n\n", s_add_rgb[m_combine.add_a0]); - printf(" RGB sub A, cycle 1: %s\n", s_suba_rgb[m_combine.sub_a_rgb1]); - printf(" RGB sub B, cycle 1: %s\n", s_subb_rgb[m_combine.sub_b_rgb1]); - printf(" RGB mul, cycle 1: %s\n", s_mul_rgb[m_combine.mul_rgb1]); - printf(" RGB add, cycle 1: %s\n", s_add_rgb[m_combine.add_rgb1]); - printf(" Alpha sub A, cycle 1: %s\n", s_sub_a[m_combine.sub_a_a1]); - printf(" Alpha sub B, cycle 1: %s\n", s_sub_a[m_combine.sub_b_a1]); - printf(" Alpha mul, cycle 1: %s\n", s_mul_a[m_combine.mul_a1]); - printf(" Alpha add, cycle 1: %s\n\n", s_add_rgb[m_combine.add_a1]); - printf("Texel 0: %08x\n", (uint32_t)userdata->m_texel0_color.to_rgba()); - printf("Texel 1: %08x\n", (uint32_t)userdata->m_texel1_color.to_rgba()); - printf("Env: %08x\n", (uint32_t)userdata->m_env_color.to_rgba()); - printf("Prim: %08x\n", (uint32_t)userdata->m_prim_color.to_rgba()); - printf("Mem: %08x\n", (uint32_t)userdata->m_memory_color.to_rgba()); - printf("Shade: %08x\n", (uint32_t)userdata->m_shade_color.to_rgba()); - printf("sargb: %08x, %08x, %08x, %08x\n", (uint32_t)sa, (uint32_t)sr, (uint32_t)sg, (uint32_t)sb); - - printf("Blend index: %d\n", (userdata->m_blend_enable << 2) | blend_index); - int32_t cdith = 0; - int32_t adith = 0; - get_dither_values(scanline, j, &cdith, &adith, object); - color_t reblended_pixel; - ((&m_blender)->*(m_blender.blend1[(userdata->m_blend_enable << 2) | blend_index]))(reblended_pixel, cdith, adith, partialreject, sel0, userdata, object/*, true*/); - - //((m_tex_pipe).*(m_tex_pipe.m_cycle[cycle0]))(&userdata->m_texel0_color, &userdata->m_texel0_color, sss, sst, tilenum, 0, userdata, object/*, true*/); - } - } - } -#endif - - if (z_compare(zbcur, zhbcur, sz, dzpix, userdata, object)) - { - int32_t cdith = 0; - int32_t adith = 0; - get_dither_values(scanline, j, &cdith, &adith, object); - - color_t blended_pixel; - bool rendered = ((&m_blender)->*(m_blender.blend1[(userdata->m_blend_enable << 2) | blend_index]))(blended_pixel, cdith, adith, partialreject, sel0, userdata, object/*, false*/); - - if (rendered) - { -#if DEBUG_RDP_PIXEL - if (x == 157 && scanline == 89 && s_debug_drawing) - { - printf("WRITE1: %08x\n", (uint32_t)blended_pixel.to_rgba()); - } -#endif - ((this)->*(m_write_pixel[object.m_misc_state.m_fb_size]))(curpixel, blended_pixel, userdata, object); - if (object.m_other_modes.z_update_en) - { - z_store(object, zbcur, zhbcur, sz, userdata->m_dzpix_enc); - } - } - } - - sss = userdata->m_precomp_s; - sst = userdata->m_precomp_t; - } - - r.w += drinc; - g.w += dginc; - b.w += dbinc; - a.w += dainc; - s.w += dsinc; - t.w += dtinc; - w.w += dwinc; - z.w += dzinc; - - x += xinc; - } -} - -void n64_rdp::span_draw_2cycle(int32_t scanline, const extent_t &extent, const rdp_poly_state &object, int32_t threadid) -{ - assert(object.m_misc_state.m_fb_size < 4); - - const int32_t clipx1 = object.m_scissor.m_xh; - const int32_t clipx2 = object.m_scissor.m_xl; - const int32_t tilenum = object.tilenum; - const bool flip = object.flip; - - span_param_t r; r.w = extent.param[SPAN_R].start; - span_param_t g; g.w = extent.param[SPAN_G].start; - span_param_t b; b.w = extent.param[SPAN_B].start; - span_param_t a; a.w = extent.param[SPAN_A].start; - span_param_t z; z.w = extent.param[SPAN_Z].start; - span_param_t s; s.w = extent.param[SPAN_S].start; - span_param_t t; t.w = extent.param[SPAN_T].start; - span_param_t w; w.w = extent.param[SPAN_W].start; - - const uint32_t zb = object.m_misc_state.m_zb_address >> 1; - const uint32_t zhb = object.m_misc_state.m_zb_address; - - int32_t tile2 = (tilenum + 1) & 7; - int32_t tile1 = tilenum; - const uint32_t prim_tile = tilenum; - - int32_t newtile1 = tile1; - int32_t news = 0; - int32_t newt = 0; - -#ifdef PTR64 - assert(extent.userdata != (const void *)0xcccccccccccccccc); -#else - assert(extent.userdata != (const void *)0xcccccccc); -#endif - rdp_span_aux* userdata = (rdp_span_aux*)extent.userdata; - - m_tex_pipe.calculate_clamp_diffs(tile1, userdata, object); - - bool partialreject = (userdata->m_color_inputs.blender2b_a[1] == &userdata->m_inv_pixel_color && userdata->m_color_inputs.blender1b_a[1] == &userdata->m_pixel_color); - int32_t sel0 = (userdata->m_color_inputs.blender2b_a[0] == &userdata->m_memory_color) ? 1 : 0; - int32_t sel1 = (userdata->m_color_inputs.blender2b_a[1] == &userdata->m_memory_color) ? 1 : 0; - - int32_t drinc, dginc, dbinc, dainc; - int32_t dzinc, dzpix; - int32_t dsinc, dtinc, dwinc; - int32_t xinc; - - if (!flip) - { - drinc = -object.m_span_base.m_span_dr; - dginc = -object.m_span_base.m_span_dg; - dbinc = -object.m_span_base.m_span_db; - dainc = -object.m_span_base.m_span_da; - dzinc = -object.m_span_base.m_span_dz; - dsinc = -object.m_span_base.m_span_ds; - dtinc = -object.m_span_base.m_span_dt; - dwinc = -object.m_span_base.m_span_dw; - xinc = -1; - } - else - { - drinc = object.m_span_base.m_span_dr; - dginc = object.m_span_base.m_span_dg; - dbinc = object.m_span_base.m_span_db; - dainc = object.m_span_base.m_span_da; - dzinc = object.m_span_base.m_span_dz; - dsinc = object.m_span_base.m_span_ds; - dtinc = object.m_span_base.m_span_dt; - dwinc = object.m_span_base.m_span_dw; - xinc = 1; - } - - const int32_t fb_index = object.m_misc_state.m_fb_width * scanline; - - int32_t cdith = 0; - int32_t adith = 0; - - const int32_t xstart = extent.startx; - const int32_t xend = userdata->m_unscissored_rx; - const int32_t xend_scissored = extent.stopx; - - int32_t x = xend; - - const int32_t length = flip ? (xstart - xend) : (xend - xstart); - - if(object.m_other_modes.z_source_sel) - { - z.w = (uint32_t)object.m_misc_state.m_primitive_z << 16; - dzpix = object.m_misc_state.m_primitive_dz; - dzinc = 0; - } - else - { - dzpix = object.m_span_base.m_span_dzpix; - } - - if (object.m_misc_state.m_fb_size > 4) - fatalerror("unsupported m_fb_size %d\n", object.m_misc_state.m_fb_size); - - const int32_t blend_index = (object.m_other_modes.alpha_cvg_select ? 2 : 0) | ((object.m_other_modes.rgb_dither_sel < 3) ? 1 : 0); - const int32_t cycle0 = ((object.m_other_modes.sample_type & 1) << 1) | (object.m_other_modes.bi_lerp0 & 1); - const int32_t cycle1 = ((object.m_other_modes.sample_type & 1) << 1) | (object.m_other_modes.bi_lerp1 & 1); - - int32_t sss = 0; - int32_t sst = 0; - - if (object.m_other_modes.persp_tex_en) - { - tc_div(s.w >> 16, t.w >> 16, w.w >> 16, &sss, &sst); - } - else - { - tc_div_no_perspective(s.w >> 16, t.w >> 16, w.w >> 16, &sss, &sst); - } - - userdata->m_start_span = true; - for (int32_t j = 0; j <= length; j++) - { - int32_t sr = r.w >> 14; - int32_t sg = g.w >> 14; - int32_t sb = b.w >> 14; - int32_t sa = a.w >> 14; - int32_t sz = (z.w >> 10) & 0x3fffff; - - const bool valid_x = (flip) ? (x >= xend_scissored) : (x <= xend_scissored); - - if (x >= clipx1 && x < clipx2 && valid_x) - { - const uint32_t compidx = m_compressed_cvmasks[userdata->m_cvg[x]]; - userdata->m_current_pix_cvg = cvarray[compidx].cvg; - userdata->m_current_cvg_bit = cvarray[compidx].cvbit; - const uint8_t offx = cvarray[compidx].xoff; - const uint8_t offy = cvarray[compidx].yoff; - //lookup_cvmask_derivatives(userdata->m_cvg[x], &offx, &offy, userdata); - - m_tex_pipe.lod_2cycle(&sss, &sst, s.w, t.w, w.w, dsinc, dtinc, dwinc, prim_tile, &tile1, &tile2, userdata, object); - - news = userdata->m_precomp_s; - newt = userdata->m_precomp_t; - m_tex_pipe.lod_2cycle_limited(&news, &newt, s.w + dsinc, t.w + dtinc, w.w + dwinc, dsinc, dtinc, dwinc, prim_tile, &newtile1, object); - - rgbaz_correct_triangle(offx, offy, &sr, &sg, &sb, &sa, &sz, userdata, object); - rgbaz_clip(sr, sg, sb, sa, &sz, userdata); - - ((m_tex_pipe).*(m_tex_pipe.m_cycle[cycle0]))(&userdata->m_texel0_color, &userdata->m_texel0_color, sss, sst, tile1, 0, userdata, object/*, false*/); - ((m_tex_pipe).*(m_tex_pipe.m_cycle[cycle1]))(&userdata->m_texel1_color, &userdata->m_texel0_color, sss, sst, tile2, 1, userdata, object/*, false*/); - - uint32_t t0a = userdata->m_texel0_color.get_a(); - uint32_t t1a = userdata->m_texel1_color.get_a(); - uint32_t tna = userdata->m_next_texel_color.get_a(); - userdata->m_texel0_alpha.set(t0a, t0a, t0a, t0a); - userdata->m_texel1_alpha.set(t1a, t1a, t1a, t1a); - userdata->m_next_texel_alpha.set(tna, tna, tna, tna); - - const uint8_t noise = machine().rand() << 3; // Not accurate - userdata->m_noise_color.set(0, noise, noise, noise); - - rgbaint_t rgbsub_a(*userdata->m_color_inputs.combiner_rgbsub_a[0]); - rgbaint_t rgbsub_b(*userdata->m_color_inputs.combiner_rgbsub_b[0]); - rgbaint_t rgbmul(*userdata->m_color_inputs.combiner_rgbmul[0]); - rgbaint_t rgbadd(*userdata->m_color_inputs.combiner_rgbadd[0]); - - rgbsub_a.merge_alpha(*userdata->m_color_inputs.combiner_alphasub_a[0]); - rgbsub_b.merge_alpha(*userdata->m_color_inputs.combiner_alphasub_b[0]); - rgbmul.merge_alpha(*userdata->m_color_inputs.combiner_alphamul[0]); - rgbadd.merge_alpha(*userdata->m_color_inputs.combiner_alphaadd[0]); - - rgbsub_a.sign_extend(0x180, 0xfffffe00); - rgbsub_b.sign_extend(0x180, 0xfffffe00); - rgbadd.sign_extend(0x180, 0xfffffe00); - - rgbadd.shl_imm(8); - rgbsub_a.sub(rgbsub_b); - rgbsub_a.mul(rgbmul); - - rgbsub_a.add(rgbadd); - rgbsub_a.add_imm(0x0080); - rgbsub_a.sra_imm(8); - rgbsub_a.clamp_and_clear(0xfffffe00); - - userdata->m_combined_color.set(rgbsub_a); - - rgbaint_t temp_color(userdata->m_texel0_color); - userdata->m_texel0_color = userdata->m_texel1_color; - userdata->m_texel1_color = temp_color; - - uint32_t ca = userdata->m_combined_color.get_a(); - userdata->m_combined_alpha.set(ca, ca, ca, ca); - userdata->m_texel0_alpha.set(userdata->m_texel1_alpha); - userdata->m_texel1_alpha.set(userdata->m_next_texel_alpha); - - rgbsub_a.set(*userdata->m_color_inputs.combiner_rgbsub_a[1]); - rgbsub_b.set(*userdata->m_color_inputs.combiner_rgbsub_b[1]); - rgbmul.set(*userdata->m_color_inputs.combiner_rgbmul[1]); - rgbadd.set(*userdata->m_color_inputs.combiner_rgbadd[1]); - - rgbsub_a.merge_alpha(*userdata->m_color_inputs.combiner_alphasub_a[1]); - rgbsub_b.merge_alpha(*userdata->m_color_inputs.combiner_alphasub_b[1]); - rgbmul.merge_alpha(*userdata->m_color_inputs.combiner_alphamul[1]); - rgbadd.merge_alpha(*userdata->m_color_inputs.combiner_alphaadd[1]); - - rgbsub_a.sign_extend(0x180, 0xfffffe00); - rgbsub_b.sign_extend(0x180, 0xfffffe00); - rgbadd.sign_extend(0x180, 0xfffffe00); - - rgbadd.shl_imm(8); - rgbsub_a.sub(rgbsub_b); - rgbsub_a.mul(rgbmul); - rgbsub_a.add(rgbadd); - rgbsub_a.add_imm(0x0080); - rgbsub_a.sra_imm(8); - rgbsub_a.clamp_and_clear(0xfffffe00); - - userdata->m_pixel_color.set(rgbsub_a); - - //Alpha coverage combiner - userdata->m_pixel_color.set_a(get_alpha_cvg(userdata->m_pixel_color.get_a(), userdata, object)); - - const uint32_t curpixel = fb_index + x; - const uint32_t zbcur = zb + curpixel; - const uint32_t zhbcur = zhb + curpixel; - - ((this)->*(m_read_pixel[object.m_misc_state.m_fb_size]))(curpixel, userdata, object); - -#if DEBUG_RDP_PIXEL - if (s_debug_drawing) - { - //uint32_t x = curpixel % m_n64_periphs->vi_width; - //uint32_t y = curpixel / m_n64_periphs->vi_width; - //printf("%d, %d ", x, scanline); - if (x == 157 && scanline == 89) - { - if (true)//finalcolor == 0) - { - static const char *s_fb_format[4] = { "I", "IA", "CI", "RGBA" }; - static const char *s_blend1a_c0[4] = { "PIXC", "MEMC", "BLENDC", "FOGC" }; - static const char *s_blend1b_c0[4] = { "PIXA", "FOGA", "SHADEA", "ZERO" }; - static const char *s_blend2a_c0[4] = { "PIXC", "MEMC", "BLENDC", "FOGC" }; - static const char *s_blend2b_c0[4] = { "INVPIXA", "MEMA", "ONE", "ZERO" }; - static const char *s_blend1a_c1[4] = { "BPIXC", "MEMC", "BLENDC", "FOGC" }; - static const char *s_blend1b_c1[4] = { "PIXA", "FOGA", "SHADEA", "ZERO" }; - static const char *s_blend2a_c1[4] = { "BPIXC", "MEMC", "BLENDC", "FOGC" }; - static const char *s_blend2b_c1[4] = { "INVPIXA", "MEMA", "ONE", "ZERO" }; - static const char *s_suba_rgb[16] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "ONE", "NOISE", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO" }; - static const char *s_subb_rgb[16] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "KEYC", "K4", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO" }; - static const char *s_mul_rgb[32] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "KEYS", "CombinedA", "TEX0A", "TEX1A", "PRIMA", "SHADEA", "ENVA", "LODF", "PLODF", "K5", - "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO", "ZERO" }; - static const char *s_add_rgb[8] = { "Combined", "TEX0C", "TEX1C", "PRIMC", "SHADEC", "ENVC", "ONE", "ZERO" }; - static const char *s_sub_a[16] = { "CombinedA", "TEX0A", "TEX1A", "PRIMA", "SHADEA", "ENVA", "ONE", "ZERO" }; - static const char *s_mul_a[16] = { "LODF", "TEX0A", "TEX1A", "PRIMA", "SHADEA", "ENVA", "PLODF", "ZERO" }; - - printf("Write to %08x: %d, %d\n", curpixel, x, scanline); - printf("m_fb_size: %d\n", 4 << object.m_misc_state.m_fb_size); - printf("m_fb_format: %s\n", s_fb_format[object.m_misc_state.m_fb_format]); - printf("blend enable: %d\n", userdata->m_blend_enable); - printf("other modes:\n"); - printf(" cycle_type: %d\n", object.m_other_modes.cycle_type); - printf(" persp_tex_en: %d\n", object.m_other_modes.persp_tex_en); - printf(" detail_tex_en: %d\n", object.m_other_modes.detail_tex_en); - printf(" sharpen_tex_en: %d\n", object.m_other_modes.sharpen_tex_en); - printf(" tex_lod_en: %d\n", object.m_other_modes.tex_lod_en); - printf(" en_tlut: %d\n", object.m_other_modes.en_tlut); - printf(" tlut_type: %d\n", object.m_other_modes.tlut_type); - printf(" sample_type: %d\n", object.m_other_modes.sample_type); - printf(" mid_texel: %d\n", object.m_other_modes.mid_texel); - printf(" bi_lerp0: %d\n", object.m_other_modes.bi_lerp0); - printf(" bi_lerp1: %d\n", object.m_other_modes.bi_lerp1); - printf(" convert_one: %d\n", object.m_other_modes.convert_one); - printf(" key_en: %d\n", object.m_other_modes.key_en); - printf(" rgb_dither_sel: %d\n", object.m_other_modes.rgb_dither_sel); - printf(" alpha_dither_sel: %d\n", object.m_other_modes.alpha_dither_sel); - printf(" blend_m1a_0 (A Cycle 0, 1): %s\n", s_blend1a_c0[object.m_other_modes.blend_m1a_0]); - printf(" blend_m1a_1 (A Cycle 1, 1): %s\n", s_blend1a_c1[object.m_other_modes.blend_m1a_1]); - printf(" blend_m1b_0 (B Cycle 0, 1): %s\n", s_blend1b_c0[object.m_other_modes.blend_m1b_0]); - printf(" blend_m1b_1 (B Cycle 1, 1): %s\n", s_blend1b_c1[object.m_other_modes.blend_m1b_1]); - printf(" blend_m2a_0 (A Cycle 0, 2): %s\n", s_blend2a_c0[object.m_other_modes.blend_m2a_0]); - printf(" blend_m2a_1 (A Cycle 1, 2): %s\n", s_blend2a_c1[object.m_other_modes.blend_m2a_1]); - printf(" blend_m2b_0 (B Cycle 0, 2): %s\n", s_blend2b_c0[object.m_other_modes.blend_m2b_0]); - printf(" blend_m2b_1 (B Cycle 1, 2): %s\n", s_blend2b_c1[object.m_other_modes.blend_m2b_1]); - printf(" tex_edge: %d\n", object.m_other_modes.tex_edge); - printf(" force_blend: %d\n", object.m_other_modes.force_blend); - printf(" blend_shift: %d\n", object.m_other_modes.blend_shift); - printf(" alpha_cvg_select: %d\n", object.m_other_modes.alpha_cvg_select); - printf(" cvg_times_alpha: %d\n", object.m_other_modes.cvg_times_alpha); - printf(" z_mode: %d\n", object.m_other_modes.z_mode); - printf(" cvg_dest: %d\n", object.m_other_modes.cvg_dest); - printf(" color_on_cvg: %d\n", object.m_other_modes.color_on_cvg); - printf(" image_read_en: %d\n", object.m_other_modes.image_read_en); - printf(" z_update_en: %d\n", object.m_other_modes.z_update_en); - printf(" z_compare_en: %d\n", object.m_other_modes.z_compare_en); - printf(" antialias_en: %d\n", object.m_other_modes.antialias_en); - printf(" z_source_sel: %d\n", object.m_other_modes.z_source_sel); - printf(" dither_alpha_en: %d\n", object.m_other_modes.dither_alpha_en); - printf(" alpha_compare_en: %d\n", object.m_other_modes.alpha_compare_en); - printf(" alpha_dither_mode: %d\n", object.m_other_modes.alpha_dither_mode); - printf("combine:\n"); - printf(" RGB sub A, cycle 0: %s\n", s_suba_rgb[m_combine.sub_a_rgb0]); - printf(" RGB sub B, cycle 0: %s\n", s_subb_rgb[m_combine.sub_b_rgb0]); - printf(" RGB mul, cycle 0: %s\n", s_mul_rgb[m_combine.mul_rgb0]); - printf(" RGB add, cycle 0: %s\n", s_add_rgb[m_combine.add_rgb0]); - printf(" Alpha sub A, cycle 0: %s\n", s_sub_a[m_combine.sub_a_a0]); - printf(" Alpha sub B, cycle 0: %s\n", s_sub_a[m_combine.sub_b_a0]); - printf(" Alpha mul, cycle 0: %s\n", s_mul_a[m_combine.mul_a0]); - printf(" Alpha add, cycle 0: %s\n\n", s_add_rgb[m_combine.add_a0]); - printf(" RGB sub A, cycle 1: %s\n", s_suba_rgb[m_combine.sub_a_rgb1]); - printf(" RGB sub B, cycle 1: %s\n", s_subb_rgb[m_combine.sub_b_rgb1]); - printf(" RGB mul, cycle 1: %s\n", s_mul_rgb[m_combine.mul_rgb1]); - printf(" RGB add, cycle 1: %s\n", s_add_rgb[m_combine.add_rgb1]); - printf(" Alpha sub A, cycle 1: %s\n", s_sub_a[m_combine.sub_a_a1]); - printf(" Alpha sub B, cycle 1: %s\n", s_sub_a[m_combine.sub_b_a1]); - printf(" Alpha mul, cycle 1: %s\n", s_mul_a[m_combine.mul_a1]); - printf(" Alpha add, cycle 1: %s\n\n", s_add_rgb[m_combine.add_a1]); - printf("Texel 0: %08x\n", (uint32_t)userdata->m_texel0_color.to_rgba()); - printf("Texel 1: %08x\n", (uint32_t)userdata->m_texel1_color.to_rgba()); - printf("Env: %08x\n", (uint32_t)userdata->m_env_color.to_rgba()); - printf("Prim: %08x\n", (uint32_t)userdata->m_prim_color.to_rgba()); - printf("Mem: %08x\n", (uint32_t)userdata->m_memory_color.to_rgba()); - printf("Shade: %08x\n", (uint32_t)userdata->m_shade_color.to_rgba()); - printf("sargb: %08x, %08x, %08x, %08x\n", (uint32_t)sa, (uint32_t)sr, (uint32_t)sg, (uint32_t)sb); - - printf("Blend index: %d\n", (userdata->m_blend_enable << 2) | blend_index); - int32_t cdith = 0; - int32_t adith = 0; - get_dither_values(scanline, j, &cdith, &adith, object); - color_t reblended_pixel; - ((&m_blender)->*(m_blender.blend2[(userdata->m_blend_enable << 2) | blend_index]))(reblended_pixel, cdith, adith, partialreject, sel0, sel1, userdata, object/*, true*/); - - //((m_tex_pipe).*(m_tex_pipe.m_cycle[cycle0]))(&userdata->m_texel0_color, &userdata->m_texel0_color, sss, sst, tilenum, 0, userdata, object/*, true*/); - } - } - } -#endif - - if(z_compare(zbcur, zhbcur, sz, dzpix, userdata, object)) - { - get_dither_values(scanline, j, &cdith, &adith, object); - - color_t blended_pixel; - bool rendered = ((&m_blender)->*(m_blender.blend2[(userdata->m_blend_enable << 2) | blend_index]))(blended_pixel, cdith, adith, partialreject, sel0, sel1, userdata, object/*, false*/); - - if (rendered) - { -#if DEBUG_RDP_PIXEL - if (x == 157 && scanline == 89 && s_debug_drawing) - { - printf("WRITE2: %08x\n", (uint32_t)blended_pixel.to_rgba()); - } -#endif - ((this)->*(m_write_pixel[object.m_misc_state.m_fb_size]))(curpixel, blended_pixel, userdata, object); - if (object.m_other_modes.z_update_en) - { - z_store(object, zbcur, zhbcur, sz, userdata->m_dzpix_enc); - } - } - } - sss = userdata->m_precomp_s; - sst = userdata->m_precomp_t; - } - - r.w += drinc; - g.w += dginc; - b.w += dbinc; - a.w += dainc; - s.w += dsinc; - t.w += dtinc; - w.w += dwinc; - z.w += dzinc; - - x += xinc; - } -} - -void n64_rdp::span_draw_copy(int32_t scanline, const extent_t &extent, const rdp_poly_state &object, int32_t threadid) -{ - const int32_t clipx1 = object.m_scissor.m_xh; - const int32_t clipx2 = object.m_scissor.m_xl; - const int32_t tilenum = object.tilenum; - const bool flip = object.flip; - - rdp_span_aux* userdata = (rdp_span_aux*)extent.userdata; - const int32_t xstart = extent.startx; - const int32_t xend = userdata->m_unscissored_rx; - const int32_t xend_scissored = extent.stopx; - const int32_t xinc = flip ? 1 : -1; - const int32_t length = flip ? (xstart - xend) : (xend - xstart); - - span_param_t s; s.w = extent.param[SPAN_S].start; - span_param_t t; t.w = extent.param[SPAN_T].start; - - const int32_t ds = object.m_span_base.m_span_ds / 4; - const int32_t dt = object.m_span_base.m_span_dt / 4; - const int32_t dsinc = flip ? (ds) : -ds; - const int32_t dtinc = flip ? (dt) : -dt; - - const int32_t fb_index = object.m_misc_state.m_fb_width * scanline; - - int32_t x = xend; - - for (int32_t j = 0; j <= length; j++) - { - const bool valid_x = (flip) ? (x >= xend_scissored) : (x <= xend_scissored); - - if (x >= clipx1 && x < clipx2 && valid_x) - { - int32_t sss = s.h.h; - int32_t sst = t.h.h; - m_tex_pipe.copy(&userdata->m_texel0_color, sss, sst, tilenum, object, userdata); - - uint32_t curpixel = fb_index + x; - if (userdata->m_texel0_color.get_a() != 0 || !object.m_other_modes.alpha_compare_en || object.m_misc_state.m_fb_size == 1) - { - ((this)->*(m_copy_pixel[object.m_misc_state.m_fb_size]))(curpixel, userdata->m_texel0_color, object); - } - } - - s.w += dsinc; - t.w += dtinc; - x += xinc; - } -} - -void n64_rdp::span_draw_fill(int32_t scanline, const extent_t &extent, const rdp_poly_state &object, int32_t threadid) -{ - assert(object.m_misc_state.m_fb_size < 4); - - const bool flip = object.flip; - - const int32_t clipx1 = object.m_scissor.m_xh; - const int32_t clipx2 = object.m_scissor.m_xl; - - const int32_t xinc = flip ? 1 : -1; - - const int32_t fb_index = object.m_misc_state.m_fb_width * scanline; - - const int32_t xstart = extent.startx; - const int32_t xend_scissored = extent.stopx; - - int32_t x = xend_scissored; - - const int32_t length = flip ? (xstart - xend_scissored) : (xend_scissored - xstart); - - for (int32_t j = 0; j <= length; j++) - { - if (x >= clipx1 && x < clipx2) - { - ((this)->*(m_fill_pixel[object.m_misc_state.m_fb_size]))(fb_index + x, object); - } - - x += xinc; - } -} diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/n64.h b/waterbox/ares64/ares/thirdparty/mame/mame/video/n64.h deleted file mode 100644 index 764219c964..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/n64.h +++ /dev/null @@ -1,426 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -#ifndef _VIDEO_N64_H_ -#define _VIDEO_N64_H_ - -#include "video/poly.h" -#include "pin64.h" - -/*****************************************************************************/ - -#define PIXEL_SIZE_4BIT 0 -#define PIXEL_SIZE_8BIT 1 -#define PIXEL_SIZE_16BIT 2 -#define PIXEL_SIZE_32BIT 3 - -#define CYCLE_TYPE_1 0 -#define CYCLE_TYPE_2 1 -#define CYCLE_TYPE_COPY 2 -#define CYCLE_TYPE_FILL 3 - -#define SAMPLE_TYPE_1x1 0 -#define SAMPLE_TYPE_2x2 1 - -#define BYTE_ADDR_XOR BYTE4_XOR_BE(0) -#define WORD_ADDR_XOR (WORD_XOR_BE(0) >> 1) - -#define XOR_SWAP_BYTE_SHIFT 2 -#define XOR_SWAP_WORD_SHIFT 1 -#define XOR_SWAP_DWORD_SHIFT 0 - -#define XOR_SWAP_BYTE 4 -#define XOR_SWAP_WORD 2 -#define XOR_SWAP_DWORD 1 - -#define FORMAT_RGBA 0 -#define FORMAT_YUV 1 -#define FORMAT_CI 2 -#define FORMAT_IA 3 -#define FORMAT_I 4 - -#ifdef LSB_FIRST -#define BYTE_XOR_DWORD_SWAP 7 -#define WORD_XOR_DWORD_SWAP 3 -#else -#define BYTE_XOR_DWORD_SWAP 4 -#define WORD_XOR_DWORD_SWAP 2 -#endif -#define DWORD_XOR_DWORD_SWAP 1 - -#define GET_LOW_RGBA16_TMEM(x) (m_rdp->m_replicated_rgba[((x) >> 1) & 0x1f]) -#define GET_MED_RGBA16_TMEM(x) (m_rdp->m_replicated_rgba[((x) >> 6) & 0x1f]) -#define GET_HI_RGBA16_TMEM(x) (m_rdp->m_replicated_rgba[((x) >> 11) & 0x1f]) - -#define MEM8_LIMIT 0x7fffff -#define MEM16_LIMIT 0x3fffff -#define MEM32_LIMIT 0x1fffff - -#define RDP_RANGE_CHECK (0) - -#if RDP_RANGE_CHECK -#define CHECK8(in) if(rdp_range_check((in))) { printf("Check8: Address %08x out of range!\n", (in)); fflush(stdout); fatalerror("Address %08x out of range!\n", (in)); } -#define CHECK16(in) if(rdp_range_check((in) << 1)) { printf("Check16: Address %08x out of range!\n", (in) << 1); fflush(stdout); fatalerror("Address %08x out of range!\n", (in) << 1); } -#define CHECK32(in) if(rdp_range_check((in) << 2)) { printf("Check32: Address %08x out of range!\n", (in) << 2); fflush(stdout); fatalerror("Address %08x out of range!\n", (in) << 2); } -#else -#define CHECK8(in) { } -#define CHECK16(in) { } -#define CHECK32(in) { } -#endif - -#if RDP_RANGE_CHECK -#define RREADADDR8(in) ((rdp_range_check((in))) ? 0 : (((uint8_t*)m_rdram)[(in) ^ BYTE_ADDR_XOR])) -#define RREADIDX16(in) ((rdp_range_check((in) << 1)) ? 0 : (((uint16_t*)m_rdram)[(in) ^ WORD_ADDR_XOR])) -#define RREADIDX32(in) ((rdp_range_check((in) << 2)) ? 0 : m_rdram[(in)]) - -#define RWRITEADDR8(in, val) if(rdp_range_check((in))) { printf("Write8: Address %08x out of range!\n", (in)); fflush(stdout); fatalerror("Address %08x out of range!\n", (in)); } else { ((uint8_t*)m_rdram)[(in) ^ BYTE_ADDR_XOR] = val;} -#define RWRITEIDX16(in, val) if(rdp_range_check((in) << 1)) { printf("Write16: Address %08x out of range!\n", ((object.m_misc_state.m_fb_address >> 1) + curpixel) << 1); fflush(stdout); fatalerror("Address out of range\n"); } else { ((uint16_t*)m_rdram)[(in) ^ WORD_ADDR_XOR] = val;} -#define RWRITEIDX32(in, val) if(rdp_range_check((in) << 2)) { printf("Write32: Address %08x out of range!\n", (in) << 2); fflush(stdout); fatalerror("Address %08x out of range!\n", (in) << 2); } else { m_rdram[(in)] = val;} -#else -#define RREADADDR8(in) (((uint8_t*)m_rdram)[(in) ^ BYTE_ADDR_XOR]) -#define RREADIDX16(in) (((uint16_t*)m_rdram)[(in) ^ WORD_ADDR_XOR]) -#define RREADIDX32(in) (m_rdram[(in)]) - -#define RWRITEADDR8(in, val) ((uint8_t*)m_rdram)[(in) ^ BYTE_ADDR_XOR] = val; -#define RWRITEIDX16(in, val) ((uint16_t*)m_rdram)[(in) ^ WORD_ADDR_XOR] = val; -#define RWRITEIDX32(in, val) m_rdram[(in)] = val -#endif - -#define U_RREADADDR8(in) (((uint8_t*)m_rdram)[(in) ^ BYTE_ADDR_XOR]) -#define U_RREADIDX16(in) (((uint16_t*)m_rdram)[(in) ^ WORD_ADDR_XOR]) -#define U_RREADIDX32(in) (m_rdram[(in)]) - -#define GETLOWCOL(x) (((x) & 0x3e) << 2) -#define GETMEDCOL(x) (((x) & 0x7c0) >> 3) -#define GETHICOL(x) (((x) & 0xf800) >> 8) - -#define HREADADDR8(in) /*(((in) <= MEM8_LIMIT) ? */(m_hidden_bits[(in) ^ BYTE_ADDR_XOR])/* : 0)*/ -#define HWRITEADDR8(in, val) /*{if ((in) <= MEM8_LIMIT) */m_hidden_bits[(in) ^ BYTE_ADDR_XOR] = val;/*}*/ - -//sign-extension macros -#define SIGN22(x) (((x & 0x00200000) * 0x7ff) | (x & 0x1fffff)) -#define SIGN17(x) (((x & 0x00010000) * 0xffff) | (x & 0xffff)) -#define SIGN16(x) (((x & 0x00008000) * 0x1ffff) | (x & 0x7fff)) -#define SIGN13(x) (((x & 0x00001000) * 0xfffff) | (x & 0xfff)) -#define SIGN11(x) (((x & 0x00000400) * 0x3fffff) | (x & 0x3ff)) -#define SIGN9(x) (((x & 0x00000100) * 0xffffff) | (x & 0xff)) -#define SIGN8(x) (((x & 0x00000080) * 0x1ffffff) | (x & 0x7f)) - -#define KURT_AKELEY_SIGN9(x) ((((x) & 0x180) == 0x180) ? ((x) | ~0x1ff) : ((x) & 0x1ff)) - -#define SPAN_R (0) -#define SPAN_G (1) -#define SPAN_B (2) -#define SPAN_A (3) -#define SPAN_S (4) -#define SPAN_T (5) -#define SPAN_W (6) -#define SPAN_Z (7) - -#define EXTENT_AUX_COUNT (sizeof(rdp_span_aux)*(480*192)) // Screen coverage *192, more or less - -/*****************************************************************************/ - -class n64_periphs; -class n64_rdp; - -#include "video/n64types.h" -#include "video/rdpblend.h" -#include "video/rdptpipe.h" - -class n64_state; - -class n64_rdp : public poly_manager -{ -public: - n64_rdp(n64_state &state, uint32_t* rdram, uint32_t* dmem); - - running_machine &machine() const { assert(m_machine != nullptr); return *m_machine; } - - void init_internal_state() - { - m_tmem = std::make_unique(0x1000); - memset(m_tmem.get(), 0, 0x1000); - -#if !defined(MAME_RDP) - uint8_t* normpoint = machine().root_device().memregion("normpoint")->base(); - uint8_t* normslope = machine().root_device().memregion("normslope")->base(); - - for(int32_t i = 0; i < 64; i++) - { - m_norm_point_rom[i] = (normpoint[(i << 1) + 1] << 8) | normpoint[i << 1]; - m_norm_slope_rom[i] = (normslope[(i << 1) + 1] << 8) | normslope[i << 1]; - } -#endif - - memset(m_tiles, 0, 8 * sizeof(n64_tile_t)); - memset(m_cmd_data, 0, sizeof(m_cmd_data)); - - for (int32_t i = 0; i < 8; i++) - { - m_tiles[i].num = i; - m_tiles[i].invmm = rgbaint_t(~0, ~0, ~0, ~0); - m_tiles[i].invmask = rgbaint_t(~0, ~0, ~0, ~0); - } - } - - void process_command_list(); - uint64_t read_data(uint32_t address); - void disassemble(uint64_t *cmd_buf, char* buffer); - - void set_machine(running_machine& machine) { m_machine = &machine; } - void set_n64_periphs(n64_periphs* periphs) { m_n64_periphs = periphs; } - - // CPU-visible registers - void set_start(uint32_t val) { m_start = val; } - uint32_t get_start() const { return m_start; } - - void set_end(uint32_t val) { m_end = val; } - uint32_t get_end() const { return m_end; } - - void set_current(uint32_t val) { m_current = val; } - uint32_t get_current() const { return m_current; } - - void set_status(uint32_t val) { m_status = val; } - uint32_t get_status() const { return m_status; } - - // Color Combiner - int32_t color_combiner_equation(int32_t a, int32_t b, int32_t c, int32_t d); - int32_t alpha_combiner_equation(int32_t a, int32_t b, int32_t c, int32_t d); - void set_suba_input_rgb(color_t** input, int32_t code, rdp_span_aux* userdata); - void set_subb_input_rgb(color_t** input, int32_t code, rdp_span_aux* userdata); - void set_mul_input_rgb(color_t** input, int32_t code, rdp_span_aux* userdata); - void set_add_input_rgb(color_t** input, int32_t code, rdp_span_aux* userdata); - void set_sub_input_alpha(color_t** input, int32_t code, rdp_span_aux* userdata); - void set_mul_input_alpha(color_t** input, int32_t code, rdp_span_aux* userdata); - - // Texture memory - uint8_t* get_tmem8() { return m_tmem.get(); } - uint16_t* get_tmem16() { return (uint16_t*)m_tmem.get(); } - - // YUV Factors - void set_yuv_factors(color_t k02, color_t k13, color_t k4, color_t k5) { m_k02 = k02; m_k13 = k13; m_k4 = k4; m_k5 = k5; } - color_t& get_k02() { return m_k02; } - color_t& get_k13() { return m_k13; } - - // Blender-related (move into RDP::Blender) - void set_blender_input(int32_t cycle, int32_t which, color_t** input_rgb, color_t** input_a, int32_t a, int32_t b, rdp_span_aux* userdata); - - // Span rasterization - void span_draw_1cycle(int32_t scanline, const extent_t &extent, const rdp_poly_state &object, int32_t threadid); - void span_draw_2cycle(int32_t scanline, const extent_t &extent, const rdp_poly_state &object, int32_t threadid); - void span_draw_copy(int32_t scanline, const extent_t &extent, const rdp_poly_state &object, int32_t threadid); - void span_draw_fill(int32_t scanline, const extent_t &extent, const rdp_poly_state &object, int32_t threadid); - - // Render-related (move into eventual drawing-related classes?) - void tc_div(int32_t ss, int32_t st, int32_t sw, int32_t* sss, int32_t* sst); - void tc_div_no_perspective(int32_t ss, int32_t st, int32_t sw, int32_t* sss, int32_t* sst); - uint32_t get_log2(uint32_t lod_clamp); - void render_spans(int32_t start, int32_t end, int32_t tilenum, bool flip, extent_t* spans, bool rect, rdp_poly_state* object); - int32_t get_alpha_cvg(int32_t comb_alpha, rdp_span_aux* userdata, const rdp_poly_state &object); - - void z_store(const rdp_poly_state &object, uint32_t zcurpixel, uint32_t dzcurpixel, uint32_t z, uint32_t enc); - uint32_t z_decompress(uint32_t zcurpixel); - uint32_t dz_decompress(uint32_t zcurpixel, uint32_t dzcurpixel); - uint32_t dz_compress(uint32_t value); - int32_t normalize_dzpix(int32_t sum); - bool z_compare(uint32_t zcurpixel, uint32_t dzcurpixel, uint32_t sz, uint16_t dzpix, rdp_span_aux* userdata, const rdp_poly_state &object); - - // Commands - void cmd_noop(uint64_t *cmd_buf); - void cmd_tex_rect(uint64_t *cmd_buf); - void cmd_tex_rect_flip(uint64_t *cmd_buf); - void cmd_sync_load(uint64_t *cmd_buf); - void cmd_sync_pipe(uint64_t *cmd_buf); - void cmd_sync_tile(uint64_t *cmd_buf); - void cmd_sync_full(uint64_t *cmd_buf); - void cmd_set_key_gb(uint64_t *cmd_buf); - void cmd_set_key_r(uint64_t *cmd_buf); - void cmd_set_fill_color32(uint64_t *cmd_buf); - void cmd_set_convert(uint64_t *cmd_buf); - void cmd_set_scissor(uint64_t *cmd_buf); - void cmd_set_prim_depth(uint64_t *cmd_buf); - void cmd_set_other_modes(uint64_t *cmd_buf); - void cmd_load_tlut(uint64_t *cmd_buf); - void cmd_set_tile_size(uint64_t *cmd_buf); - void cmd_load_block(uint64_t *cmd_buf); - void cmd_load_tile(uint64_t *cmd_buf); - void cmd_fill_rect(uint64_t *cmd_buf); - void cmd_set_tile(uint64_t *cmd_buf); - void cmd_set_fog_color(uint64_t *cmd_buf); - void cmd_set_blend_color(uint64_t *cmd_buf); - void cmd_set_prim_color(uint64_t *cmd_buf); - void cmd_set_env_color(uint64_t *cmd_buf); - void cmd_set_combine(uint64_t *cmd_buf); - void cmd_set_texture_image(uint64_t *cmd_buf); - void cmd_set_mask_image(uint64_t *cmd_buf); - void cmd_set_color_image(uint64_t *cmd_buf); - - void rgbaz_clip(int32_t sr, int32_t sg, int32_t sb, int32_t sa, int32_t* sz, rdp_span_aux* userdata); - void rgbaz_correct_triangle(int32_t offx, int32_t offy, int32_t* r, int32_t* g, int32_t* b, int32_t* a, int32_t* z, rdp_span_aux* userdata, const rdp_poly_state &object); - - void triangle(uint64_t *cmd_buf, bool shade, bool texture, bool zbuffer); - - void get_dither_values(int32_t x, int32_t y, int32_t* cdith, int32_t* adith, const rdp_poly_state &object); - - uint16_t decompress_cvmask_frombyte(uint8_t x); - void lookup_cvmask_derivatives(uint32_t mask, uint8_t* offx, uint8_t* offy, rdp_span_aux* userdata); - - void mark_frame() { m_capture.mark_frame(*m_machine); } - - misc_state_t m_misc_state; - - // Color constants - color_t m_blend_color; /* constant blend color */ - color_t m_prim_color; /* flat primitive color */ - color_t m_prim_alpha; /* flat primitive alpha */ - color_t m_env_color; /* generic color constant ('environment') */ - color_t m_env_alpha; /* generic alpha constant ('environment') */ - color_t m_fog_color; /* generic color constant ('fog') */ - color_t m_key_scale; /* color-keying constant */ - color_t m_lod_fraction; /* Z-based LOD fraction for this poly */ - color_t m_prim_lod_fraction; /* fixed LOD fraction for this poly */ - - color_t m_one; - color_t m_zero; - - uint32_t m_fill_color; - - other_modes_t m_other_modes; - - n64_blender_t m_blender; - - n64_texture_pipe_t m_tex_pipe; - - uint8_t m_hidden_bits[0x800000]; - - uint8_t m_replicated_rgba[32]; - - uint16_t m_dzpix_normalize[0x10000]; - - rectangle_t m_scissor; - span_base_t m_span_base; - - void draw_triangle(uint64_t *cmd_buf, bool shade, bool texture, bool zbuffer, bool rect); - - std::unique_ptr m_aux_buf; - uint32_t m_aux_buf_ptr; - uint32_t m_aux_buf_index; - - bool rdp_range_check(uint32_t addr); - - n64_tile_t m_tiles[8]; - -private: - void compute_cvg_noflip(extent_t* spans, int32_t* majorx, int32_t* minorx, int32_t* majorxint, int32_t* minorxint, int32_t scanline, int32_t yh, int32_t yl, int32_t base); - void compute_cvg_flip(extent_t* spans, int32_t* majorx, int32_t* minorx, int32_t* majorxint, int32_t* minorxint, int32_t scanline, int32_t yh, int32_t yl, int32_t base); - - void write_pixel4(uint32_t curpixel, color_t& color, rdp_span_aux* userdata, const rdp_poly_state &object); - void write_pixel8(uint32_t curpixel, color_t& color, rdp_span_aux* userdata, const rdp_poly_state &object); - void write_pixel16(uint32_t curpixel, color_t& color, rdp_span_aux* userdata, const rdp_poly_state &object); - void write_pixel32(uint32_t curpixel, color_t& color, rdp_span_aux* userdata, const rdp_poly_state &object); - void read_pixel4(uint32_t curpixel, rdp_span_aux* userdata, const rdp_poly_state &object); - void read_pixel8(uint32_t curpixel, rdp_span_aux* userdata, const rdp_poly_state &object); - void read_pixel16(uint32_t curpixel, rdp_span_aux* userdata, const rdp_poly_state &object); - void read_pixel32(uint32_t curpixel, rdp_span_aux* userdata, const rdp_poly_state &object); - void copy_pixel4(uint32_t curpixel, color_t& color, const rdp_poly_state &object); - void copy_pixel8(uint32_t curpixel, color_t& color, const rdp_poly_state &object); - void copy_pixel16(uint32_t curpixel, color_t& color, const rdp_poly_state &object); - void copy_pixel32(uint32_t curpixel, color_t& color, const rdp_poly_state &object); - void fill_pixel4(uint32_t curpixel, const rdp_poly_state &object); - void fill_pixel8(uint32_t curpixel, const rdp_poly_state &object); - void fill_pixel16(uint32_t curpixel, const rdp_poly_state &object); - void fill_pixel32(uint32_t curpixel, const rdp_poly_state &object); - - void precalc_cvmask_derivatives(void); - void z_build_com_table(void); - - typedef void (n64_rdp::*compute_cvg_t) (extent_t* spans, int32_t* majorx, int32_t* minorx, int32_t* majorxint, int32_t* minorxint, int32_t scanline, int32_t yh, int32_t yl, int32_t base); - compute_cvg_t m_compute_cvg[2]; - - typedef void (n64_rdp::*write_pixel_t) (uint32_t curpixel, color_t& color, rdp_span_aux* userdata, const rdp_poly_state &object); - typedef void (n64_rdp::*read_pixel_t) (uint32_t curpixel, rdp_span_aux* userdata, const rdp_poly_state &object); - typedef void (n64_rdp::*copy_pixel_t) (uint32_t curpixel, color_t& color, const rdp_poly_state &object); - typedef void (n64_rdp::*fill_pixel_t) (uint32_t curpixel, const rdp_poly_state &object); - - write_pixel_t m_write_pixel[4]; - read_pixel_t m_read_pixel[4]; - copy_pixel_t m_copy_pixel[4]; - fill_pixel_t m_fill_pixel[4]; - - running_machine* m_machine; - uint32_t* m_rdram; - uint32_t* m_dmem; - n64_periphs* m_n64_periphs; - - combine_modes_t m_combine; - bool m_pending_mode_block; - bool m_pipe_clean; - - cv_mask_derivative_t cvarray[(1 << 8)]; - - uint16_t m_z_com_table[0x40000]; //precalced table of compressed z values, 18b: 512 KB array! - uint32_t m_z_complete_dec_table[0x4000]; //the same for decompressed z values, 14b - uint8_t m_compressed_cvmasks[0x10000]; //16bit cvmask -> to byte - - uint64_t m_cmd_data[0x800]; - uint64_t m_temp_rect_data[0x800]; - - uint32_t m_start; - uint32_t m_end; - uint32_t m_current; - uint32_t m_status; - - std::unique_ptr m_tmem; - - // YUV factors - color_t m_k02; - color_t m_k13; - color_t m_k4; - color_t m_k5; - - // Texture perspective division -#if !defined(MAME_RDP) - int32_t m_norm_point_rom[64]; - int32_t m_norm_slope_rom[64]; -#else - int32_t m_norm_point_rom[64] = - { - 0x4000, 0x3f04, 0x3e10, 0x3d22, 0x3c3c, 0x3b5d, 0x3a83, 0x39b1, - 0x38e4, 0x381c, 0x375a, 0x369d, 0x35e5, 0x3532, 0x3483, 0x33d9, - 0x3333, 0x3291, 0x31f4, 0x3159, 0x30c3, 0x3030, 0x2fa1, 0x2f15, - 0x2e8c, 0x2e06, 0x2d83, 0x2d03, 0x2c86, 0x2c0b, 0x2b93, 0x2b1e, - 0x2aab, 0x2a3a, 0x29cc, 0x2960, 0x28f6, 0x288e, 0x2828, 0x27c4, - 0x2762, 0x2702, 0x26a4, 0x2648, 0x25ed, 0x2594, 0x253d, 0x24e7, - 0x2492, 0x243f, 0x23ee, 0x239e, 0x234f, 0x2302, 0x22b6, 0x226c, - 0x2222, 0x21da, 0x2193, 0x214d, 0x2108, 0x20c5, 0x2082, 0x2041, - }; - int32_t m_norm_slope_rom[64] = - { - 0xfc, 0xf4, 0xee, 0xe6, 0xdf, 0xda, 0xd2, 0xcd, - 0xc8, 0xc2, 0xbd, 0xb8, 0xb3, 0xaf, 0xaa, 0xa6, - 0xa2, 0x9d, 0x9b, 0x96, 0x93, 0x8f, 0x8c, 0x89, - 0x86, 0x83, 0x80, 0x7d, 0x7b, 0x78, 0x75, 0x73, - 0x71, 0x6e, 0x6c, 0x6a, 0x68, 0x66, 0x64, 0x62, - 0x60, 0x5e, 0x5c, 0x5b, 0x59, 0x57, 0x56, 0x55, - 0x53, 0x51, 0x50, 0x4f, 0x4d, 0x4c, 0x4a, 0x4a, - 0x48, 0x47, 0x46, 0x45, 0x43, 0x43, 0x41, 0x41, - }; -#endif - - pin64_t m_capture; - - static uint32_t s_special_9bit_clamptable[512]; - static z_decompress_entry_t const m_z_dec_table[8]; - - static uint8_t const s_bayer_matrix[16]; - static uint8_t const s_magic_matrix[16]; - static int32_t const s_rdp_command_length[]; - static char const *const s_image_format[]; - static char const *const s_image_size[]; - -public: - bool ignore; - bool dolog; -}; - -#endif // _VIDEO_N64_H_ diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/n64types.h b/waterbox/ares64/ares/thirdparty/mame/mame/video/n64types.h deleted file mode 100644 index 4fd845593f..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/n64types.h +++ /dev/null @@ -1,340 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz - -#ifndef _VIDEO_N64TYPES_H_ -#define _VIDEO_N64TYPES_H_ - -#include "video/rgbutil.h" - -struct misc_state_t -{ - misc_state_t() - { - m_max_level = 0; - m_min_level = 0; - } - - int32_t m_fb_format; // Framebuffer pixel format index (0 - I, 1 - IA, 2 - CI, 3 - RGBA) - int32_t m_fb_size; // Framebuffer pixel size index (0 - 4bpp, 1 - 8bpp, 2 - 16bpp, 3 - 32bpp) - int32_t m_fb_width; // Framebuffer width, in pixels - int32_t m_fb_height; // Framebuffer height, in pixels - uint32_t m_fb_address; // Framebuffer source address offset (in bytes) from start of RDRAM - - uint32_t m_zb_address; // Z-buffer source address offset (in bytes) from start of RDRAM - - int32_t m_ti_format; // Format for Texture Interface (TI) transfers - int32_t m_ti_size; // Size (in bytes) of TI transfers - int32_t m_ti_width; // Width (in pixels) of TI transfers - uint32_t m_ti_address; // Destination address for TI transfers - - uint32_t m_max_level; // Maximum LOD level for texture filtering - uint32_t m_min_level; // Minimum LOD level for texture filtering - - uint16_t m_primitive_z; // Forced Z value for current primitive, if applicable - uint16_t m_primitive_dz; // Forced Delta-Z value for current primitive, if applicable -}; - -#if 0 -class color_t -{ - public: - color_t() - { - c = 0; - } - - color_t(uint32_t color) - { - set(color); - } - - color_t(uint8_t a, uint8_t r, uint8_t g, uint8_t b) - { - set(a, r, g, b); - } - - inline void set(color_t& other) - { - c = other.c; - } - - inline void set(uint32_t color) - { - i.a = (color >> 24) & 0xff; - i.r = (color >> 16) & 0xff; - i.g = (color >> 8) & 0xff; - i.b = color & 0xff; - } - - void set(uint8_t a, uint8_t r, uint8_t g, uint8_t b) - { - i.a = a; - i.r = r; - i.g = g; - i.b = b; - } - - inline void set_direct(uint32_t color) - { - c = color; - } - - uint32_t get() - { - return i.a << 24 | i.r << 16 | i.g << 8 | i.b; - } - - union - { - uint32_t c; -#ifdef LSB_FIRST - struct { uint8_t a, b, g, r; } i; -#else - struct { uint8_t r, g, b, a; } i; -#endif - }; -}; -#else -#define color_t rgbaint_t -#endif - -enum -{ - BIT_DEPTH_32 = 0, - BIT_DEPTH_16, - - BIT_DEPTH_COUNT -}; - -struct n64_tile_t -{ - int32_t format; // Image data format: RGBA, YUV, CI, IA, I - int32_t size; // Size of texel element: 4b, 8b, 16b, 32b - int32_t line; // Size of tile line in bytes - int32_t tmem; // Starting tmem address for this tile in bytes - int32_t palette; // Palette number for 4b CI texels - int32_t ct, mt, cs, ms; // Clamp / mirror enable bits for S / T direction - int32_t mask_t, shift_t, mask_s, shift_s; // Mask values / LOD shifts - int32_t lshift_s, rshift_s, lshift_t, rshift_t; - int32_t wrapped_mask_s, wrapped_mask_t; - bool clamp_s, clamp_t; - rgbaint_t mm, invmm; - rgbaint_t wrapped_mask; - rgbaint_t mask; - rgbaint_t invmask; - rgbaint_t lshift; - rgbaint_t rshift; - rgbaint_t sth; - rgbaint_t stl; - rgbaint_t clamp_st; - uint16_t sl, tl, sh, th; // 10.2 fixed-point, starting and ending texel row / column - int32_t num; -}; - -struct span_base_t -{ - int32_t m_span_dr; - int32_t m_span_dg; - int32_t m_span_db; - int32_t m_span_da; - int32_t m_span_ds; - int32_t m_span_dt; - int32_t m_span_dw; - int32_t m_span_dz; - int32_t m_span_dymax; - int32_t m_span_dzpix; - int32_t m_span_drdy; - int32_t m_span_dgdy; - int32_t m_span_dbdy; - int32_t m_span_dady; - int32_t m_span_dzdy; -}; - -struct combine_modes_t -{ - int32_t sub_a_rgb0; - int32_t sub_b_rgb0; - int32_t mul_rgb0; - int32_t add_rgb0; - int32_t sub_a_a0; - int32_t sub_b_a0; - int32_t mul_a0; - int32_t add_a0; - - int32_t sub_a_rgb1; - int32_t sub_b_rgb1; - int32_t mul_rgb1; - int32_t add_rgb1; - int32_t sub_a_a1; - int32_t sub_b_a1; - int32_t mul_a1; - int32_t add_a1; -}; - -struct color_inputs_t -{ - // combiner inputs - color_t* combiner_rgbsub_a[2]; - color_t* combiner_rgbsub_b[2]; - color_t* combiner_rgbmul[2]; - color_t* combiner_rgbadd[2]; - - color_t* combiner_alphasub_a[2]; - color_t* combiner_alphasub_b[2]; - color_t* combiner_alphamul[2]; - color_t* combiner_alphaadd[2]; - - // blender input - color_t* blender1a_rgb[2]; - color_t* blender1b_a[2]; - color_t* blender2a_rgb[2]; - color_t* blender2b_a[2]; -}; - -struct other_modes_t -{ - int32_t cycle_type; - bool persp_tex_en; - bool detail_tex_en; - bool sharpen_tex_en; - bool tex_lod_en; - bool en_tlut; - bool tlut_type; - bool sample_type; - bool mid_texel; - bool bi_lerp0; - bool bi_lerp1; - bool convert_one; - bool key_en; - int32_t rgb_dither_sel; - int32_t alpha_dither_sel; - int32_t blend_m1a_0; - int32_t blend_m1a_1; - int32_t blend_m1b_0; - int32_t blend_m1b_1; - int32_t blend_m2a_0; - int32_t blend_m2a_1; - int32_t blend_m2b_0; - int32_t blend_m2b_1; - int32_t tex_edge; - int32_t force_blend; - int32_t blend_shift; - bool alpha_cvg_select; - bool cvg_times_alpha; - int32_t z_mode; - int32_t cvg_dest; - bool color_on_cvg; - uint8_t image_read_en; - bool z_update_en; - bool z_compare_en; - bool antialias_en; - bool z_source_sel; - int32_t dither_alpha_en; - int32_t alpha_compare_en; - int32_t alpha_dither_mode; -}; - -struct rectangle_t -{ - uint16_t m_xl; // 10.2 fixed-point - uint16_t m_yl; // 10.2 fixed-point - uint16_t m_xh; // 10.2 fixed-point - uint16_t m_yh; // 10.2 fixed-point -}; - -struct rdp_poly_state -{ - n64_rdp* m_rdp; /* pointer back to the RDP state */ - - misc_state_t m_misc_state; /* miscellaneous rasterizer bits */ - other_modes_t m_other_modes; /* miscellaneous rasterizer bits (2) */ - span_base_t m_span_base; /* span initial values for triangle rasterization */ - rectangle_t m_scissor; /* screen-space scissor bounds */ - uint32_t m_fill_color; /* poly fill color */ - n64_tile_t m_tiles[8]; /* texture tile state */ - uint8_t m_tmem[0x1000]; /* texture cache */ - int32_t tilenum; /* texture tile index */ - bool flip; /* left-major / right-major flip */ - bool rect; /* primitive is rectangle (vs. triangle) */ -}; - -#define RDP_CVG_SPAN_MAX (1024) - -// This is enormous and horrible -struct rdp_span_aux -{ - uint32_t m_unscissored_rx; - uint16_t m_cvg[RDP_CVG_SPAN_MAX]; - color_t m_memory_color; - color_t m_pixel_color; - color_t m_inv_pixel_color; - color_t m_blended_pixel_color; - - color_t m_combined_color; - color_t m_combined_alpha; - color_t m_texel0_color; - color_t m_texel0_alpha; - color_t m_texel1_color; - color_t m_texel1_alpha; - color_t m_next_texel_color; - color_t m_next_texel_alpha; - color_t m_blend_color; /* constant blend color */ - color_t m_prim_color; /* flat primitive color */ - color_t m_prim_alpha; /* flat primitive alpha */ - color_t m_env_color; /* generic color constant ('environment') */ - color_t m_env_alpha; /* generic alpha constant ('environment') */ - color_t m_fog_color; /* generic color constant ('fog') */ - color_t m_shade_color; /* gouraud-shaded color */ - color_t m_shade_alpha; /* gouraud-shaded alpha */ - color_t m_key_scale; /* color-keying constant */ - color_t m_noise_color; /* noise */ - color_t m_lod_fraction; /* Z-based LOD fraction for this poly */ - color_t m_prim_lod_fraction; /* fixed LOD fraction for this poly */ - color_t m_k4; - color_t m_k5; - color_inputs_t m_color_inputs; - uint32_t m_current_pix_cvg; - uint32_t m_current_mem_cvg; - uint32_t m_current_cvg_bit; - int32_t m_shift_a; - int32_t m_shift_b; - int32_t m_precomp_s; - int32_t m_precomp_t; - int32_t m_blend_enable; - bool m_pre_wrap; - int32_t m_dzpix_enc; - uint8_t* m_tmem; /* pointer to texture cache for this polygon */ - bool m_start_span; - rgbaint_t m_clamp_diff[8]; - combine_modes_t m_combine; -}; - -struct z_decompress_entry_t -{ - uint32_t shift; - uint32_t add; -}; - -struct cv_mask_derivative_t -{ - uint8_t cvg; - uint8_t cvbit; - uint8_t xoff; - uint8_t yoff; -}; - -class span_param_t -{ - public: - union - { - uint32_t w; -#ifdef LSB_FIRST - struct { uint16_t l; int16_t h; } h; -#else - struct { int16_t h; uint16_t l; } h; -#endif - }; -}; - -#endif // _VIDEO_N64TYPES_H_ diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/pin64.cpp b/waterbox/ares64/ares/thirdparty/mame/mame/video/pin64.cpp deleted file mode 100644 index ba9b217d4f..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/pin64.cpp +++ /dev/null @@ -1,511 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz - -#include "emu.h" -#include "pin64.h" - -#define CAP_NAME "pin64_%d.cap" - -// pin64_fileutil_t members - -void pin64_fileutil_t::write(FILE* file, uint32_t data) { - if (!file) - return; - - uint8_t temp(data >> 24); - fwrite(&temp, 1, 1, file); - - temp = (uint8_t)(data >> 16); - fwrite(&temp, 1, 1, file); - - temp = (uint8_t)(data >> 8); - fwrite(&temp, 1, 1, file); - - temp = (uint8_t)data; - fwrite(&temp, 1, 1, file); -} - -void pin64_fileutil_t::write(FILE* file, const uint8_t* data, uint32_t size) { - if (!file) - return; - - fwrite(data, 1, size, file); -} - - - -// pin64_data_t members - -void pin64_data_t::put8(uint8_t data) { - m_data.push_back(data); - m_offset++; -} - -void pin64_data_t::put16(uint16_t data) { - put8((uint8_t)(data >> 8)); - put8((uint8_t)data); -} - -void pin64_data_t::put32(uint32_t data) { - put16((uint16_t)(data >> 16)); - put16((uint16_t)data); -} - -void pin64_data_t::put64(uint64_t data) { - put32((uint32_t)(data >> 32)); - put32((uint32_t)data); -} - -uint8_t pin64_data_t::get8() { - if (m_offset >= m_data.size()) - fatalerror("PIN64: Call to pin64_data_t::get8() at end of block (requested offset %x, size %x)\n", m_offset, (uint32_t)m_data.size()); - - uint8_t ret = m_data[m_offset]; - m_offset++; - - return ret; -} - -uint16_t pin64_data_t::get16() { - uint16_t ret = (uint16_t)get8() << 8; - return ret | get8(); -} - -uint32_t pin64_data_t::get32() { - uint32_t ret = (uint32_t)get16() << 16; - return ret | get16(); -} - -uint64_t pin64_data_t::get64() { - uint64_t ret = (uint64_t)get32() << 32; - return ret | get32(); -} - -uint8_t pin64_data_t::get8(uint32_t offset, bool temp_access) { - update_offset(offset, temp_access); - - uint8_t ret = get8(); - m_offset = m_old_offset; - return ret; -} - -uint16_t pin64_data_t::get16(uint32_t offset, bool temp_access) { - update_offset(offset, temp_access); - - uint16_t ret = get16(); - m_offset = m_old_offset; - return ret; -} - -uint32_t pin64_data_t::get32(uint32_t offset, bool temp_access) { - update_offset(offset, temp_access); - - uint32_t ret = get32(); - m_offset = m_old_offset; - return ret; -} - -uint64_t pin64_data_t::get64(uint32_t offset, bool temp_access) { - update_offset(offset, temp_access); - - uint32_t ret = get64(); - m_offset = m_old_offset; - return ret; -} - -void pin64_data_t::reset() { - m_old_offset = 0; - m_offset = 0; -} - -void pin64_data_t::clear() { - reset(); - m_data.clear(); -} - -void pin64_data_t::update_offset(uint32_t offset, bool update_current) { - m_old_offset = (update_current ? offset : m_offset); - m_offset = offset; -} - - - -// pin64_printer_t members - -void pin64_printer_t::print_data(pin64_block_t* block) { - pin64_data_t* data = block->data(); - - printf(" CRC32: %08x\n", (uint32_t)block->crc32()); fflush(stdout); - printf(" Data Size: %08x\n", (uint32_t)data->size()); fflush(stdout); - printf(" Data: "); fflush(stdout); - - const uint32_t data_size = data->size(); - const uint32_t row_count = (data_size + 31) / 32; - const uint8_t* bytes = data->bytes(); - for (uint32_t row = 0; row < row_count; row++) { - const uint32_t row_index = row * 32; - const uint32_t data_remaining = data_size - row_index; - const uint32_t col_count = (data_remaining > 32 ? 32 : data_remaining); - for (uint32_t col = 0; col < col_count; col++) { - printf("%02x ", bytes[row_index + col]); fflush(stdout); - } - - if (row == (row_count - 1)) { - printf("\n"); fflush(stdout); - } else { - printf("\n "); fflush(stdout); - } - } - - printf("\n"); fflush(stdout); -} - -void pin64_printer_t::print_command(int cmd_start, int cmd, std::unordered_map& blocks, std::vector& commands) { - pin64_block_t* block = blocks[commands[cmd]]; - pin64_data_t* data = block->data(); - - printf(" Command %d:\n", cmd - cmd_start); fflush(stdout); - const uint32_t cmd_size(data->get32()); - printf(" CRC32: %08x\n", (uint32_t)commands[cmd]); fflush(stdout); - printf(" Packet Data Size: %d words\n", cmd_size); fflush(stdout); - printf(" Packet Data: "); fflush(stdout); - - bool load_command = false; - for (int i = 0; i < cmd_size; i++) { - const uint64_t cmd_entry(data->get64()); - if (i == 0) { - const uint8_t top_byte = uint8_t(cmd_entry >> 56) & 0x3f; - if (top_byte == 0x30 || top_byte == 0x33 || top_byte == 0x34) - load_command = true; - } - printf("%08x%08x\n", uint32_t(cmd_entry >> 32), (uint32_t)cmd_entry); fflush(stdout); - - if (i < (cmd_size - 1)) { - printf(" "); fflush(stdout); - } - } - - printf(" Data Block Present: %s\n", load_command ? "Yes" : "No"); fflush(stdout); - - if (load_command) { - printf(" Data Block CRC32: %08x\n", data->get32()); fflush(stdout); - } - - data->reset(); -}; - - - -// pin64_block_t members - -void pin64_block_t::finalize() { -#if !defined(MAME_RDP) - if (m_data.size() > 0) - m_crc32 = util::crc32_creator::simple(m_data.bytes(), m_data.size()); - else -#endif - m_crc32 = ~0; - m_data.reset(); -} - -void pin64_block_t::clear() { - m_crc32 = 0; - m_data.clear(); -} - -void pin64_block_t::write(FILE* file) { - pin64_fileutil_t::write(file, m_crc32); - pin64_fileutil_t::write(file, m_data.size()); - if (m_data.size() > 0) - pin64_fileutil_t::write(file, m_data.bytes(), m_data.size()); -} - -uint32_t pin64_block_t::size() { - return sizeof(uint32_t) // data CRC32 - + sizeof(uint32_t) // data size - + m_data.size(); // data -} - - - -// pin64_t members - -const uint8_t pin64_t::CAP_ID[8] = { 'P', 'I', 'N', '6', '4', 'C', 'A', 'P' }; - -pin64_t::~pin64_t() { - if (m_capture_file) - finish(); - - clear(); -} - -void pin64_t::start(int frames) -{ - if (m_capture_index == ~0) - init_capture_index(); - - if (m_capture_file) - fatalerror("PIN64: Call to start() while already capturing\n"); - - char name_buf[256]; - sprintf(name_buf, CAP_NAME, m_capture_index); - m_capture_index++; - - m_capture_file = fopen(name_buf, "wb"); - - m_capture_frames = frames; - - m_frames.push_back(0); -} - -void pin64_t::finish() { - if (!m_capture_file) - return; - - finalize(); - print(); - - write(m_capture_file); - fclose(m_capture_file); - m_capture_file = nullptr; - - clear(); -} - -void pin64_t::finalize() { - finish_command(); - data_end(); -} - -void pin64_t::play(int index) { -} - -void pin64_t::mark_frame(running_machine& machine) { - if (m_capture_file) { - if (m_frames.size() == m_capture_frames && m_capture_frames > 0) { - printf("\n"); - finish(); -#if !defined(MAME_RDP) - machine.popmessage("Done recording."); -#endif - } else { - printf("%d ", (uint32_t)m_commands.size()); - m_frames.push_back((uint32_t)m_commands.size()); - } - } - -#if PIN64_ENABLE_CAPTURE - if (machine.input().code_pressed_once(KEYCODE_N) && !m_capture_file) { - start(1); - machine.popmessage("Capturing PIN64 snapshot to pin64_%d.cap", m_capture_index - 1); - } else if (machine.input().code_pressed_once(KEYCODE_M)) { - if (m_capture_file) { - finish(); - machine.popmessage("Done recording."); - } else { - start(); - machine.popmessage("Recording PIN64 movie to pin64_%d.cap", m_capture_index - 1); - } - } -#endif -} - -void pin64_t::command(uint64_t* cmd_data, uint32_t size) { - if (!capturing()) - return; - - finish_command(); - - m_current_command = new pin64_block_t(); - m_current_command->data()->put32(size); - - for (uint32_t i = 0 ; i < size; i++) - m_current_command->data()->put64(cmd_data[i]); -} - -void pin64_t::finish_command() { - if (!m_current_command) - return; - - m_current_command->finalize(); - if (m_blocks.find(m_current_command->crc32()) == m_blocks.end()) - m_blocks[m_current_command->crc32()] = m_current_command; - - m_commands.push_back(m_current_command->crc32()); -} - -void pin64_t::data_begin() { - if (!capturing()) - return; - - if (m_current_data) - data_end(); - - m_current_data = new pin64_block_t(); -} - -pin64_data_t* pin64_t::data_block() { - if (!capturing() || !m_current_data) - return &m_dummy_data; - - return m_current_data->data(); -} - -void pin64_t::data_end() { - if (!capturing() || !m_current_data) - return; - - m_current_data->finalize(); - m_current_command->data()->put32(m_current_data->crc32()); - finish_command(); - - if (m_blocks.find(m_current_data->crc32()) == m_blocks.end()) - m_blocks[m_current_data->crc32()] = m_current_data; - - m_current_data = nullptr; -} - -size_t pin64_t::size() { - return header_size() + block_directory_size() + cmdlist_directory_size() + cmdlist_size(); -} - -size_t pin64_t::header_size() { - return sizeof(uint8_t) * 8 // "PIN64CAP" - + sizeof(uint32_t) // total file size - + sizeof(uint32_t) // start of block directory data - + sizeof(uint32_t) // start of command-list directory data - + sizeof(uint32_t) // start of blocks - + sizeof(uint32_t); // start of commands -} - -size_t pin64_t::block_directory_size() { - return (m_blocks.size() + 1) * sizeof(uint32_t); -} - -size_t pin64_t::cmdlist_directory_size() { - return (m_frames.size() + 1) * sizeof(uint16_t); -} - -size_t pin64_t::blocks_size() { - size_t block_size = 0; - for (std::pair block_pair : m_blocks) - block_size += (block_pair.second)->size(); - - return block_size; -} - -size_t pin64_t::cmdlist_size() { - return (m_commands.size() + 1) * sizeof(uint32_t); -} - -void pin64_t::print() -{ - printf("Total Size: %9x bytes\n", (uint32_t)size()); fflush(stdout); - printf("Header Size: %9x bytes\n", (uint32_t)header_size()); fflush(stdout); - printf("Block Dir Size: %9x bytes\n", (uint32_t)block_directory_size()); fflush(stdout); - printf("Cmdlist Dir Size: %9x bytes\n", (uint32_t)cmdlist_directory_size()); fflush(stdout); - printf("Blocks Size: %9x bytes\n", (uint32_t)blocks_size()); fflush(stdout); - printf("Cmdlist Size: %9x bytes\n", (uint32_t)cmdlist_size()); fflush(stdout); - - printf("Command-List Count: %d\n", (uint32_t)m_frames.size()); fflush(stdout); - for (int i = 0; i < m_frames.size(); i++) { - printf(" List %d:\n", i); fflush(stdout); - - const int next_start = ((i == (m_frames.size() - 1)) ? m_commands.size() : m_frames[i+1]); - for (int cmd = m_frames[i]; cmd < next_start; cmd++) { - pin64_printer_t::print_command(m_frames[i], cmd, m_blocks, m_commands); - } - if (i == (m_frames.size() - 1)) { - printf("\n"); fflush(stdout); - } - } - - printf("\nData Block Count: %d\n", (uint32_t)m_blocks.size()); fflush(stdout); - int i = 0; - for (std::pair block_pair : m_blocks) { - printf(" Block %d:\n", i); fflush(stdout); - - pin64_printer_t::print_data((block_pair.second)); - if (i == (m_blocks.size() - 1)) { - printf("\n"); fflush(stdout); - } - i++; - } -} - -void pin64_t::write(FILE* file) { - const uint32_t size_total = size(); - const uint32_t size_header = header_size(); - const uint32_t size_block_dir = block_directory_size(); - const uint32_t size_cmdlist_dir = cmdlist_directory_size(); - const uint32_t size_blocks_dir = blocks_size(); - - pin64_fileutil_t::write(file, CAP_ID, 8); - pin64_fileutil_t::write(file, size_total); - pin64_fileutil_t::write(file, size_header); - pin64_fileutil_t::write(file, size_header + size_block_dir); - pin64_fileutil_t::write(file, size_header + size_block_dir + size_cmdlist_dir); - pin64_fileutil_t::write(file, size_header + size_block_dir + size_cmdlist_dir + size_blocks_dir); - - write_data_directory(file); - write_cmdlist_directory(file); - - for (std::pair block_pair : m_blocks) - (block_pair.second)->write(file); - - pin64_fileutil_t::write(file, m_commands.size()); - for (util::crc32_t crc : m_commands) - pin64_fileutil_t::write(file, crc); -} - -void pin64_t::write_data_directory(FILE* file) { - pin64_fileutil_t::write(file, m_blocks.size()); - size_t offset(header_size()); - for (std::pair block_pair : m_blocks) { - pin64_fileutil_t::write(file, offset); - offset += (block_pair.second)->size(); - } -} - -void pin64_t::write_cmdlist_directory(FILE* file) { - pin64_fileutil_t::write(file, m_frames.size()); - for (uint32_t frame : m_frames) - pin64_fileutil_t::write(file, frame); -} - -void pin64_t::clear() { - if (m_capture_file != nullptr) { - fclose(m_capture_file); - m_capture_file = nullptr; - } - - for (std::pair block_pair : m_blocks) - delete block_pair.second; - - m_blocks.clear(); - m_commands.clear(); - m_frames.clear(); - - m_current_data = nullptr; - m_current_command = nullptr; -} - -void pin64_t::init_capture_index() -{ - char name_buf[256]; - bool found = true; - - m_capture_index = 0; - - do { - sprintf(name_buf, CAP_NAME, m_capture_index); - - FILE* temp = fopen(name_buf, "rb"); - if (temp == nullptr) { - break; - } else { - fclose(temp); - m_capture_index++; - } - } while(found); -} diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/pin64.h b/waterbox/ares64/ares/thirdparty/mame/mame/video/pin64.h deleted file mode 100644 index 31b836f7ed..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/pin64.h +++ /dev/null @@ -1,180 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -#ifndef MAME_VIDEO_PIN64_H -#define MAME_VIDEO_PIN64_H - -#pragma once - -#include -#include -#include - - -#define PIN64_ENABLE_CAPTURE (0) - - -class pin64_fileutil_t { -public: - static void write(FILE* file, uint32_t data); - static void write(FILE* file, const uint8_t* data, uint32_t size); -}; - -class pin64_command_t { -public: - std::vector data; -}; - -class pin64_data_t { -public: - pin64_data_t() - : m_offset(0) - , m_old_offset(0) { } - - void reset(); - void clear(); - - // setters - virtual void put8(uint8_t data); - virtual void put16(uint16_t data); - virtual void put32(uint32_t data); - virtual void put64(uint64_t data); - - // getters - virtual uint8_t get8(); - virtual uint8_t get8(uint32_t offset, bool temp_access = false); - virtual uint16_t get16(); - virtual uint16_t get16(uint32_t offset, bool temp_access = false); - virtual uint32_t get32(); - virtual uint32_t get32(uint32_t offset, bool temp_access = false); - virtual uint64_t get64(); - virtual uint64_t get64(uint32_t offset, bool temp_access = false); - virtual uint32_t offset() { return m_offset; } - uint8_t* bytes() { return (m_data.size() > 0) ? &m_data[0] : nullptr; } - uint32_t size() { return m_data.size(); } - -private: - void update_offset(uint32_t offset, bool temp_access = false); - -protected: - std::vector m_data; - - uint32_t m_offset; - uint32_t m_old_offset; -}; - -class pin64_dummy_data_t : public pin64_data_t { -public: - void put8(uint8_t data) override { } - void put16(uint16_t data) override { } - void put32(uint32_t data) override { } - void put64(uint64_t data) override { } - - uint8_t get8() override { return 0; } - uint8_t get8(uint32_t offset, bool update_current = true) override { return 0; } - uint16_t get16() override { return 0; } - uint16_t get16(uint32_t offset, bool update_current = true) override { return 0; } - uint32_t get32() override { return 0; } - uint32_t get32(uint32_t offset, bool update_current = true) override { return 0; } - uint64_t get64() override { return 0; } - uint64_t get64(uint32_t offset, bool update_current = true) override { return 0; } - - uint32_t offset() override { return 0; } -}; - -class pin64_block_t { -public: - pin64_block_t() - : m_crc32{0} { } - virtual ~pin64_block_t() { } - - void finalize(); - void clear(); - - void write(FILE* file); - - // getters - uint32_t size(); - pin64_data_t* data() { return &m_data; } - util::crc32_t crc32() const { return m_crc32; } - -protected: - util::crc32_t m_crc32; - pin64_data_t m_data; -}; - -class pin64_printer_t { -public: - static void print_data(pin64_block_t* block); - static void print_command(int cmd_start, int cmd, std::unordered_map& blocks, std::vector& commands); -}; - -class pin64_t -{ -public: - pin64_t() - : m_capture_file(nullptr) - , m_capture_index(~0) - , m_capture_frames(0) - , m_current_data(nullptr) - , m_current_command(nullptr) - , m_playing(false) - { } - ~pin64_t(); - - void start(int frames = 0); - void finish(); - void clear(); - void print(); - - void mark_frame(running_machine& machine); - void play(int index); - - void command(uint64_t* cmd_data, uint32_t size); - - void data_begin(); - pin64_data_t* data_block(); - pin64_block_t& block() { return *m_current_data; } - void data_end(); - - bool capturing() const { return m_capture_file != nullptr; } - bool playing() const { return m_playing; } - - size_t size(); - -private: - void start_command_block(); - - void write(FILE* file); - - size_t header_size(); - size_t block_directory_size(); - size_t cmdlist_directory_size(); - size_t blocks_size(); - size_t cmdlist_size(); - - void finish_command(); - - void write_data_directory(FILE* file); - void write_cmdlist_directory(FILE* file); - void init_capture_index(); - - void finalize(); - - FILE *m_capture_file; - int32_t m_capture_index; - int m_capture_frames; - - pin64_block_t* m_current_data; - pin64_block_t* m_current_command; - std::unordered_map m_blocks; - - std::vector m_commands; - std::vector m_frames; - - bool m_playing; - - pin64_dummy_data_t m_dummy_data; - static const uint8_t CAP_ID[8]; -}; - -#endif // MAME_VIDEO_PIN64_H diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdpblend.cpp b/waterbox/ares64/ares/thirdparty/mame/mame/video/rdpblend.cpp deleted file mode 100644 index 7e20b68aa6..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdpblend.cpp +++ /dev/null @@ -1,461 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -/****************************************************************************** - - - SGI/Nintendo Reality Display Processor Blend Unit (BL) - ------------------- - - by Ryan Holtz - based on initial C code by Ville Linde - contains additional improvements from angrylion, Ziggy, Gonetz and Orkin - - -******************************************************************************/ - -#include "emu.h" -#include "includes/n64.h" -#include "video/n64.h" - -n64_blender_t::n64_blender_t() -{ - blend1[0] = &n64_blender_t::cycle1_noblend_noacvg_nodither; - blend1[1] = &n64_blender_t::cycle1_noblend_noacvg_dither; - blend1[2] = &n64_blender_t::cycle1_noblend_acvg_nodither; - blend1[3] = &n64_blender_t::cycle1_noblend_acvg_dither; - blend1[4] = &n64_blender_t::cycle1_blend_noacvg_nodither; - blend1[5] = &n64_blender_t::cycle1_blend_noacvg_dither; - blend1[6] = &n64_blender_t::cycle1_blend_acvg_nodither; - blend1[7] = &n64_blender_t::cycle1_blend_acvg_dither; - - blend2[0] = &n64_blender_t::cycle2_noblend_noacvg_nodither; - blend2[1] = &n64_blender_t::cycle2_noblend_noacvg_dither; - blend2[2] = &n64_blender_t::cycle2_noblend_acvg_nodither; - blend2[3] = &n64_blender_t::cycle2_noblend_acvg_dither; - blend2[4] = &n64_blender_t::cycle2_blend_noacvg_nodither; - blend2[5] = &n64_blender_t::cycle2_blend_noacvg_dither; - blend2[6] = &n64_blender_t::cycle2_blend_acvg_nodither; - blend2[7] = &n64_blender_t::cycle2_blend_acvg_dither; - - for (int value = 0; value < 256; value++) - { - for (int dither = 0; dither < 8; dither++) - { - m_color_dither[(value << 3) | dither] = (uint8_t)dither_color(value, dither); - m_alpha_dither[(value << 3) | dither] = (uint8_t)dither_alpha(value, dither); - } - } -} - -int32_t n64_blender_t::dither_alpha(int32_t alpha, int32_t dither) -{ - return min(alpha + dither, 0xff); -} - -int32_t n64_blender_t::dither_color(int32_t color, int32_t dither) -{ - if ((color & 7) > dither) - { - color = (color & 0xf8) + 8; - if (color > 247) - { - color = 255; - } - } - return color; -} - -bool n64_blender_t::test_for_reject(rdp_span_aux* userdata, const rdp_poly_state& object) -{ - if (alpha_reject(userdata, object)) - { - return true; - } - if (object.m_other_modes.antialias_en ? !userdata->m_current_pix_cvg : !userdata->m_current_cvg_bit) - { - return true; - } - return false; -} - -bool n64_blender_t::alpha_reject(rdp_span_aux* userdata, const rdp_poly_state& object) -{ - switch (object.m_other_modes.alpha_dither_mode) - { - case 0: - case 1: - return false; - - case 2: - return userdata->m_pixel_color.get_a() < userdata->m_blend_color.get_a(); - - case 3: - return userdata->m_pixel_color.get_a() < (machine().rand() & 0xff); - - default: - return false; - } -} - -bool n64_blender_t::cycle1_noblend_noacvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_pixel_color.set_a(m_alpha_dither[((uint8_t)userdata->m_pixel_color.get_a() << 3) | adseed]); - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - if (test_for_reject(userdata, object)) - { - return false; - } - blended_pixel.set(*userdata->m_color_inputs.blender1a_rgb[0]); - - return true; -} - -bool n64_blender_t::cycle1_noblend_noacvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_pixel_color.set_a(m_alpha_dither[((uint8_t)userdata->m_pixel_color.get_a() << 3) | adseed]); - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - if (test_for_reject(userdata, object)) - { - return false; - } - - rgbaint_t index(*userdata->m_color_inputs.blender1a_rgb[0]); - index.shl_imm(3); - index.or_imm(dith); - index.and_imm(0x7ff); - blended_pixel.set(0, m_color_dither[index.get_r32()], m_color_dither[index.get_g32()], m_color_dither[index.get_b32()]); - - return true; -} - -bool n64_blender_t::cycle1_noblend_acvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - blended_pixel.set(*userdata->m_color_inputs.blender1a_rgb[0]); - - return true; -} - -bool n64_blender_t::cycle1_noblend_acvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - rgbaint_t index(*userdata->m_color_inputs.blender1a_rgb[0]); - index.shl_imm(3); - index.or_imm(dith); - index.and_imm(0x7ff); - blended_pixel.set(0, m_color_dither[index.get_r32()], m_color_dither[index.get_g32()], m_color_dither[index.get_b32()]); - - return true; -} - -bool n64_blender_t::cycle1_blend_noacvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_pixel_color.set_a(m_alpha_dither[((uint8_t)userdata->m_pixel_color.get_a() << 3) | adseed]); - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - blend_with_partial_reject(blended_pixel, 0, partialreject, sel0, userdata, object); - - return true; -} - -bool n64_blender_t::cycle1_blend_noacvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_pixel_color.set_a(m_alpha_dither[((uint8_t)userdata->m_pixel_color.get_a() << 3) | adseed]); - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - color_t rgb; - blend_with_partial_reject(rgb, 0, partialreject, sel0, userdata, object); - - rgb.shl_imm(3); - rgb.or_imm(dith); - rgb.and_imm(0x7ff); - blended_pixel.set(0, m_color_dither[rgb.get_r32()], m_color_dither[rgb.get_g32()], m_color_dither[rgb.get_b32()]); - - return true; -} - -bool n64_blender_t::cycle1_blend_acvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - blend_with_partial_reject(blended_pixel, 0, partialreject, sel0, userdata, object); - - return true; -} - -bool n64_blender_t::cycle1_blend_acvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - color_t rgb; - blend_with_partial_reject(rgb, 0, partialreject, sel0, userdata, object); - - rgb.shl_imm(3); - rgb.or_imm(dith); - rgb.and_imm(0x7ff); - blended_pixel.set(0, m_color_dither[rgb.get_r32()], m_color_dither[rgb.get_g32()], m_color_dither[rgb.get_b32()]); - - return true; -} - -bool n64_blender_t::cycle2_noblend_noacvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_pixel_color.set_a(m_alpha_dither[((uint8_t)userdata->m_pixel_color.get_a() << 3) | adseed]); - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - userdata->m_inv_pixel_color.set_a(0xff - userdata->m_color_inputs.blender1b_a[0]->get_a()); - blend_pipe(0, sel0, userdata->m_blended_pixel_color, userdata, object); - userdata->m_blended_pixel_color.set_a(userdata->m_pixel_color.get_a()); - - blended_pixel.set(*userdata->m_color_inputs.blender1a_rgb[1]); - - return true; -} - -bool n64_blender_t::cycle2_noblend_noacvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_pixel_color.set_a(m_alpha_dither[((uint8_t)userdata->m_pixel_color.get_a() << 3) | adseed]); - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - userdata->m_inv_pixel_color.set_a(0xff - (uint8_t)userdata->m_color_inputs.blender1b_a[0]->get_a()); - blend_pipe(0, sel0, userdata->m_blended_pixel_color, userdata, object); - userdata->m_blended_pixel_color.set_a(userdata->m_pixel_color.get_a()); - - rgbaint_t index(*userdata->m_color_inputs.blender1a_rgb[1]); - index.shl_imm(3); - index.or_imm(dith); - index.and_imm(0x7ff); - blended_pixel.set(0, m_color_dither[index.get_r32()], m_color_dither[index.get_g32()], m_color_dither[index.get_b32()]); - - return true; -} - -bool n64_blender_t::cycle2_noblend_acvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - userdata->m_inv_pixel_color.set_a(0xff - userdata->m_color_inputs.blender1b_a[0]->get_a()); - blend_pipe(0, sel0, userdata->m_blended_pixel_color, userdata, object); - userdata->m_blended_pixel_color.set_a(userdata->m_pixel_color.get_a()); - - blended_pixel.set(*userdata->m_color_inputs.blender1a_rgb[1]); - - return true; -} - -bool n64_blender_t::cycle2_noblend_acvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - userdata->m_inv_pixel_color.set_a(0xff - userdata->m_color_inputs.blender1b_a[0]->get_a()); - blend_pipe(0, sel0, userdata->m_blended_pixel_color, userdata, object); - userdata->m_blended_pixel_color.set_a(userdata->m_pixel_color.get_a()); - - rgbaint_t index(*userdata->m_color_inputs.blender1a_rgb[1]); - index.shl_imm(3); - index.or_imm(dith); - index.and_imm(0x7ff); - blended_pixel.set(0, m_color_dither[index.get_r32()], m_color_dither[index.get_g32()], m_color_dither[index.get_b32()]); - - return true; -} - -bool n64_blender_t::cycle2_blend_noacvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_pixel_color.set_a(m_alpha_dither[((uint8_t)userdata->m_pixel_color.get_a() << 3) | adseed]); - userdata->m_shade_color.set_a(m_alpha_dither[((uint8_t)userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - userdata->m_inv_pixel_color.set_a(0xff - userdata->m_color_inputs.blender1b_a[0]->get_a()); - blend_pipe(0, sel0, userdata->m_blended_pixel_color, userdata, object); - userdata->m_blended_pixel_color.set_a(userdata->m_pixel_color.get_a()); - - blend_with_partial_reject(blended_pixel, 1, partialreject, sel1, userdata, object); - - return true; -} - -bool n64_blender_t::cycle2_blend_noacvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_pixel_color.set_a(m_alpha_dither[(userdata->m_pixel_color.get_a() << 3) | adseed]); - userdata->m_shade_color.set_a(m_alpha_dither[(userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - userdata->m_inv_pixel_color.set_a(0xff - userdata->m_color_inputs.blender1b_a[0]->get_a()); - blend_pipe(0, sel0, userdata->m_blended_pixel_color, userdata, object); - userdata->m_blended_pixel_color.set_a(userdata->m_pixel_color.get_a()); - - color_t rgb; - blend_with_partial_reject(rgb, 1, partialreject, sel1, userdata, object); - - rgb.shl_imm(3); - rgb.or_imm(dith); - rgb.and_imm(0x7ff); - blended_pixel.set(0, m_color_dither[rgb.get_r32()], m_color_dither[rgb.get_g32()], m_color_dither[rgb.get_b32()]); - - return true; -} - -bool n64_blender_t::cycle2_blend_acvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_shade_color.set_a(m_alpha_dither[(userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - userdata->m_inv_pixel_color.set_a(0xff - userdata->m_color_inputs.blender1b_a[0]->get_a()); - blend_pipe(0, sel0, userdata->m_blended_pixel_color, userdata, object); - userdata->m_blended_pixel_color.set_a(userdata->m_pixel_color.get_a()); - - blend_with_partial_reject(blended_pixel, 1, partialreject, sel1, userdata, object); - - return true; -} - -bool n64_blender_t::cycle2_blend_acvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - userdata->m_shade_color.set_a(m_alpha_dither[(userdata->m_shade_color.get_a() << 3) | adseed]); - - if (test_for_reject(userdata, object)) - { - return false; - } - - userdata->m_inv_pixel_color.set_a(0xff - userdata->m_color_inputs.blender1b_a[0]->get_a()); - blend_pipe(0, sel0, userdata->m_blended_pixel_color, userdata, object); - userdata->m_blended_pixel_color.set_a(userdata->m_pixel_color.get_a()); - - color_t rgb; - blend_with_partial_reject(rgb, 1, partialreject, sel1, userdata, object); - - rgb.shl_imm(3); - rgb.or_imm(dith); - rgb.and_imm(0x7ff); - blended_pixel.set(0, m_color_dither[rgb.get_r32()], m_color_dither[rgb.get_g32()], m_color_dither[rgb.get_b32()]); - - return true; -} - -void n64_blender_t::blend_with_partial_reject(color_t& out, int32_t cycle, int32_t partialreject, int32_t select, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - if (partialreject && userdata->m_pixel_color.get_a() >= 0xff) - { - out.set(*userdata->m_color_inputs.blender1a_rgb[cycle]); - } - else - { - userdata->m_inv_pixel_color.set_a(0xff - userdata->m_color_inputs.blender1b_a[cycle]->get_a()); - blend_pipe(cycle, select, out, userdata, object); - } -} - -void n64_blender_t::blend_pipe(const int cycle, const int special, color_t& out, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - const int32_t mask = 0xff &~ (0x73 * special); - const int32_t shift_a = 3 + userdata->m_shift_a * special; - const int32_t shift_b = 3 + userdata->m_shift_b * special; - const int32_t blend1a = (userdata->m_color_inputs.blender1b_a[cycle]->get_a() >> shift_a) & mask; - const int32_t blend2a = (userdata->m_color_inputs.blender2b_a[cycle]->get_a() >> shift_b) & mask; - const int32_t special_shift = special << 1; - - rgbaint_t temp(*userdata->m_color_inputs.blender1a_rgb[cycle]); - temp.mul_imm(blend1a); - - rgbaint_t secondary(*userdata->m_color_inputs.blender2a_rgb[cycle]); - rgbaint_t other(*userdata->m_color_inputs.blender2a_rgb[cycle]); - other.mul_imm(blend2a); - - temp.add(other); - secondary.shl_imm(special_shift); - temp.add(secondary); - temp.shr_imm(object.m_other_modes.blend_shift); - - int32_t factor_sum = 0; - if (!object.m_other_modes.force_blend) - { - factor_sum = ((blend1a >> 2) + (blend2a >> 2) + 1) & 0xf; - if (factor_sum) - { - temp.set_r(temp.get_r32() / factor_sum); - temp.set_g(temp.get_g32() / factor_sum); - temp.set_b(temp.get_b32() / factor_sum); - } - else - { - temp.set(0, 0xff, 0xff, 0xff); - } - } - - temp.min(255); - out.set(temp); -} - -inline int32_t n64_blender_t::min(const int32_t x, const int32_t min) -{ - if (x < min) - { - return x; - } - return min; -} diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdpblend.h b/waterbox/ares64/ares/thirdparty/mame/mame/video/rdpblend.h deleted file mode 100644 index b81e817e2b..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdpblend.h +++ /dev/null @@ -1,72 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -/****************************************************************************** - - - SGI/Nintendo Reality Display Processor Blend Unit (BL) - ------------------- - - by Ryan Holtz - based on initial C code by Ville Linde - contains additional improvements from angrylion, Ziggy, Gonetz and Orkin - - -******************************************************************************/ - -#ifndef _VIDEO_RDPBLEND_H_ -#define _VIDEO_RDPBLEND_H_ - -#include "video/n64.h" - -class n64_blender_t -{ - public: - typedef bool (n64_blender_t::*blender1)(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object); - typedef bool (n64_blender_t::*blender2)(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object); - - n64_blender_t(); - - blender1 blend1[8]; - blender2 blend2[8]; - - void set_machine(running_machine& machine) { m_machine = &machine; } - void set_processor(n64_rdp* rdp) { m_rdp = rdp; } - - running_machine &machine() const { assert(m_machine != nullptr); return *m_machine; } - - private: - running_machine* m_machine; - n64_rdp* m_rdp; - - int32_t min(const int32_t x, const int32_t min); - bool alpha_reject(rdp_span_aux* userdata, const rdp_poly_state& object); - bool test_for_reject(rdp_span_aux* userdata, const rdp_poly_state& object); - void blend_pipe(const int cycle, const int special, color_t& out, rdp_span_aux* userdata, const rdp_poly_state& object); - void blend_with_partial_reject(color_t& out, int32_t cycle, int32_t partialreject, int32_t select, rdp_span_aux* userdata, const rdp_poly_state& object); - - bool cycle1_noblend_noacvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle1_noblend_noacvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle1_noblend_acvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle1_noblend_acvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle1_blend_noacvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle1_blend_noacvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle1_blend_acvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle1_blend_acvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, rdp_span_aux* userdata, const rdp_poly_state& object); - - bool cycle2_noblend_noacvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle2_noblend_noacvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle2_noblend_acvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle2_noblend_acvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle2_blend_noacvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle2_blend_noacvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle2_blend_acvg_nodither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object); - bool cycle2_blend_acvg_dither(color_t& blended_pixel, int dith, int adseed, int partialreject, int sel0, int sel1, rdp_span_aux* userdata, const rdp_poly_state& object); - - int32_t dither_alpha(int32_t alpha, int32_t dither); - int32_t dither_color(int32_t color, int32_t dither); - - uint8_t m_color_dither[256 * 8]; - uint8_t m_alpha_dither[256 * 8]; -}; - -#endif // _VIDEO_RDPBLEND_H_ diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdpfiltr.hxx b/waterbox/ares64/ares/thirdparty/mame/mame/video/rdpfiltr.hxx deleted file mode 100644 index ff8fbfb371..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdpfiltr.hxx +++ /dev/null @@ -1,617 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -#if 0 -static inline void video_filter16(int *out_r, int *out_g, int *out_b, uint16_t* vbuff, uint8_t* hbuff, const uint32_t hres); -static inline void divot_filter16(uint8_t* r, uint8_t* g, uint8_t* b, uint16_t* fbuff, uint32_t fbuff_index); -static inline void restore_filter16(int32_t* r, int32_t* g, int32_t* b, uint16_t* fbuff, uint32_t fbuff_index, uint32_t hres); -static inline void divot_filter16_buffer(int32_t* r, int32_t* g, int32_t* b, color_t* vibuffer); -static inline void restore_filter16_buffer(int32_t* r, int32_t* g, int32_t* b, color_t* vibuff, uint32_t hres); -static inline void restore_two(color_t* filtered, color_t* neighbour); -static inline void video_max(uint32_t* Pixels, uint8_t* max, uint32_t* enb); -static inline uint32_t ge_two(uint32_t enb); - -static inline void video_filter16(int *out_r, int *out_g, int *out_b, uint16_t* vbuff, uint8_t* hbuff, const uint32_t hres) -{ - color_t penumax, penumin, max, min; - uint16_t pix = *vbuff; - const uint8_t centercvg = (*hbuff & 3) + ((pix & 1) << 2) + 1; - uint32_t numoffull = 1; - uint32_t cvg; - uint32_t backr[7], backg[7], backb[7]; - uint32_t invr[7], invg[7], invb[7]; - int32_t coeff; - int32_t leftup = -hres - 2; - int32_t leftdown = hres - 2; - int32_t toleft = -2; - uint32_t colr, colg, colb; - uint32_t enb; - uint32_t r = ((pix >> 8) & 0xf8) | (pix >> 13); - uint32_t g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - uint32_t b = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - - *out_r = *out_g = *out_b = 0; - - backr[0] = r; - backg[0] = g; - backb[0] = b; - invr[0] = ~r; - invg[0] = ~g; - invb[0] = ~b; - - if (centercvg == 8) - { - *out_r = r; - *out_g = g; - *out_b = b; - return; - } - - for(int i = 0; i < 5; i++) - { - pix = vbuff[leftup ^ WORD_ADDR_XOR]; - cvg = hbuff[leftup ^ BYTE_ADDR_XOR] & 3; - if(i & 1) - { - if (cvg == 3 && (pix & 1)) - { - backr[numoffull] = ((pix >> 8) & 0xf8) | (pix >> 13); - backg[numoffull] = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - backb[numoffull] = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - invr[numoffull] = ~backr[numoffull]; - invg[numoffull] = ~backg[numoffull]; - invb[numoffull] = ~backb[numoffull]; - } - else - { - backr[numoffull] = invr[numoffull] = 0; - backg[numoffull] = invg[numoffull] = 0; - backb[numoffull] = invb[numoffull] = 0; - } - numoffull++; - } - leftup++; - } - - for(int i = 0; i < 5; i++) - { - pix = vbuff[leftdown ^ WORD_ADDR_XOR]; - cvg = hbuff[leftdown ^ BYTE_ADDR_XOR] & 3; - if (i&1) - { - if (cvg == 3 && (pix & 1)) - { - backr[numoffull] = ((pix >> 8) & 0xf8) | (pix >> 13); - backg[numoffull] = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - backb[numoffull] = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - invr[numoffull] = ~backr[numoffull]; - invg[numoffull] = ~backg[numoffull]; - invb[numoffull] = ~backb[numoffull]; - } - else - { - backr[numoffull] = invr[numoffull] = 0; - backg[numoffull] = invg[numoffull] = 0; - backb[numoffull] = invb[numoffull] = 0; - } - numoffull++; - } - leftdown++; - } - - for(int i = 0; i < 5; i++) - { - pix = vbuff[toleft ^ WORD_ADDR_XOR]; - cvg = hbuff[toleft ^ BYTE_ADDR_XOR] & 3; - if (!(i&3)) - { - if (cvg == 3 && (pix & 1)) - { - backr[numoffull] = ((pix >> 8) & 0xf8) | (pix >> 13); - backg[numoffull] = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - backb[numoffull] = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - invr[numoffull] = ~backr[numoffull]; - invg[numoffull] = ~backg[numoffull]; - invb[numoffull] = ~backb[numoffull]; - } - else - { - backr[numoffull] = invr[numoffull] = 0; - backg[numoffull] = invg[numoffull] = 0; - backb[numoffull] = invb[numoffull] = 0; - } - numoffull++; - } - toleft++; - } - - video_max(&backr[0], &max.i.r, &enb); - for(int i = 1; i < 7; i++) - { - if (!((enb >> i) & 1)) - { - backr[i] = 0; - } - } - video_max(&backg[0], &max.i.g, &enb); - for (int i = 1; i < 7; i++) - { - if (!((enb >> i) & 1)) - { - backg[i] = 0; - } - } - video_max(&backb[0], &max.i.b, &enb); - for (int i = 1; i < 7; i++) - { - if (!((enb >> i) & 1)) - { - backb[i] = 0; - } - } - video_max(&invr[0], &min.i.r, &enb); - for (int i = 1; i < 7; i++) - { - if (!((enb >> i) & 1)) - { - backr[i] = 0; - } - } - video_max(&invg[0], &min.i.g, &enb); - for (int i = 1; i < 7; i++) - { - if (!((enb >> i) & 1)) - { - backg[i] = 0; - } - } - video_max(&invb[0], &min.i.b, &enb); - for (int i = 1; i < 7; i++) - { - if (!((enb >> i) & 1)) - { - backb[i] = 0; - } - } - - video_max(&backr[0], &penumax.i.r, &enb); - penumax.i.r = ge_two(enb) ? max.i.r : penumax.i.r; - - video_max(&backg[0], &penumax.i.g, &enb); - penumax.i.g = ge_two(enb) ? max.i.g : penumax.i.g; - - video_max(&backb[0], &penumax.i.b, &enb); - penumax.i.b = ge_two(enb) ? max.i.b : penumax.i.b; - - video_max(&invr[0], &penumin.i.r, &enb); - penumin.i.r = ge_two(enb) ? min.i.r : penumin.i.r; - - video_max(&invg[0], &penumin.i.g, &enb); - penumin.i.g = ge_two(enb) ? min.i.g : penumin.i.g; - - video_max(&invb[0], &penumin.i.b, &enb); - penumin.i.b = ge_two(enb) ? min.i.b : penumin.i.b; - - penumin.i.r = ~penumin.i.r; - penumin.i.g = ~penumin.i.g; - penumin.i.b = ~penumin.i.b; - - colr = (uint32_t)penumin.i.r + (uint32_t)penumax.i.r - (r << 1); - colg = (uint32_t)penumin.i.g + (uint32_t)penumax.i.g - (g << 1); - colb = (uint32_t)penumin.i.b + (uint32_t)penumax.i.b - (b << 1); - coeff = 8 - centercvg; - colr = (((colr * coeff) + 4) >> 3) + r; - colg = (((colg * coeff) + 4) >> 3) + g; - colb = (((colb * coeff) + 4) >> 3) + b; - - *out_r = colr & 0xff; - *out_g = colg & 0xff; - *out_b = colb & 0xff; - return; -} - -// This needs to be fixed for endianness. -static inline void divot_filter16(uint8_t* r, uint8_t* g, uint8_t* b, uint16_t* fbuff, uint32_t fbuff_index) -{ - uint8_t leftr, leftg, leftb, rightr, rightg, rightb; - uint16_t leftpix, rightpix; - uint16_t* next, *prev; - uint32_t Lsw = fbuff_index & 1; - next = (Lsw) ? (uint16_t*)(fbuff - 1) : (uint16_t*)(fbuff + 3); - prev = (Lsw) ? (uint16_t*)(fbuff - 3) : (uint16_t*)(fbuff + 1); - leftpix = *prev; - rightpix = *next; - - //leftpix = *(fbuff - 1); //for BE targets - //rightpix = *(fbuff + 1); - - leftr = ((leftpix >> 8) & 0xf8) | (leftpix >> 13); - leftg = ((leftpix >> 3) & 0xf8) | ((leftpix >> 8) & 0x07); - leftb = ((leftpix << 2) & 0xf8) | ((leftpix >> 3) & 0x07); - rightr = ((rightpix >> 8) & 0xf8) | (rightpix >> 13); - rightg = ((rightpix >> 3) & 0xf8) | ((rightpix >> 8) & 0x07); - rightb = ((rightpix << 2) & 0xf8) | ((rightpix >> 3) & 0x07); - if ((leftr >= *r && rightr >= leftr) || (leftr >= rightr && *r >= leftr)) - { - *r = leftr; //left = median value - } - if ((rightr >= *r && leftr >= rightr) || (rightr >= leftr && *r >= rightr)) - { - *r = rightr; //right = median, else *r itself is median - } - if ((leftg >= *g && rightg >= leftg) || (leftg >= rightg && *g >= leftg)) - { - *g = leftg; - } - if ((rightg >= *g && leftg >= rightg) || (rightg >= leftg && *g >= rightg)) - { - *g = rightg; - } - if ((leftb >= *b && rightb >= leftb) || (leftb >= rightb && *b >= leftb)) - { - *b = leftb; - } - if ((rightb >= *b && leftb >= rightb) || (rightb >= leftb && *b >= rightb)) - { - *b = rightb; - } -} - -static inline void divot_filter16_buffer(int* r, int* g, int* b, color_t* vibuffer) -{ - color_t leftpix = vibuffer[-1]; - color_t rightpix = vibuffer[1]; - color_t filtered = *vibuffer; - - *r = filtered.i.r; - *g = filtered.i.g; - *b = filtered.i.b; - uint32_t leftr = leftpix.i.r; - uint32_t leftg = leftpix.i.g; - uint32_t leftb = leftpix.i.b; - uint32_t rightr = rightpix.i.r; - uint32_t rightg = rightpix.i.g; - uint32_t rightb = rightpix.i.b; - - if ((leftr >= *r && rightr >= leftr) || (leftr >= rightr && *r >= leftr)) - { - *r = leftr; //left = median value - } - if ((rightr >= *r && leftr >= rightr) || (rightr >= leftr && *r >= rightr)) - { - *r = rightr; //right = median, else *r itself is median - } - if ((leftg >= *g && rightg >= leftg) || (leftg >= rightg && *g >= leftg)) - { - *g = leftg; - } - if ((rightg >= *g && leftg >= rightg) || (rightg >= leftg && *g >= rightg)) - { - *g = rightg; - } - if ((leftb >= *b && rightb >= leftb) || (leftb >= rightb && *b >= leftb)) - { - *b = leftb; - } - if ((rightb >= *b && leftb >= rightb) || (rightb >= leftb && *b >= rightb)) - { - *b = rightb; - } - - filtered.i.r = *r; - filtered.i.g = *g; - filtered.i.b = *b; -} - -// Fix me. -static inline void restore_filter16(int* r, int* g, int* b, uint16_t* fbuff, uint32_t fbuff_index, uint32_t hres) -{ - int32_t leftuppix = -hres - 1; - int32_t leftdownpix = hres - 1; - int32_t toleftpix = -1; - uint8_t tempr, tempg, tempb; - uint16_t pix; - int i; - - uint8_t r5 = *r; - uint8_t g5 = *g; - uint8_t b5 = *b; - r5 &= ~7; - g5 &= ~7; - b5 &= ~7; - - for (i = 0; i < 3; i++) - { - pix = fbuff[leftuppix ^ 1]; - tempr = ((pix >> 8) & 0xf8) | (pix >> 13); - tempg = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - tempb = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - tempr &= ~7; - tempg &= ~7; - tempb &= ~7; - if (tempr > r5) - { - *r += 1; - } - if (tempr < r5) - { - *r -= 1; - } - if (tempg > g5) - { - *g += 1; - } - if (tempg < g5) - { - *g -= 1; - } - if (tempb > b5) - { - *b += 1; - } - if (tempb < b5) - { - *b -= 1; - } - leftuppix++; - } - - for (i = 0; i < 3; i++) - { - pix = fbuff[leftdownpix ^ 1]; - tempr = ((pix >> 8) & 0xf8) | (pix >> 13); - tempg = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - tempb = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - tempr &= ~7; - tempg &= ~7; - tempb &= ~7; - if (tempr > r5) - { - *r += 1; - } - if (tempr < r5) - { - *r -= 1; - } - if (tempg > g5) - { - *g += 1; - } - if (tempg < g5) - { - *g -= 1; - } - if (tempb > b5) - { - *b += 1; - } - if (tempb < b5) - { - *b -= 1; - } - leftdownpix++; - } - for(i = 0; i < 3; i++) - { - if (!(i & 1)) - { - pix = fbuff[toleftpix ^ 1]; - tempr = ((pix >> 8) & 0xf8) | (pix >> 13); - tempg = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); - tempb = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); - tempr &= ~7; - tempg &= ~7; - tempb &= ~7; - if (tempr > r5) - { - *r += 1; - } - if (tempr < r5) - { - *r -= 1; - } - if (tempg > g5) - { - *g += 1; - } - if (tempg < g5) - { - *g -= 1; - } - if (tempb > b5) - { - *b += 1; - } - if (tempb < b5) - { - *b -= 1; - } - } - toleftpix++; - } -} - -static inline void restore_filter16_buffer(int32_t* r, int32_t* g, int32_t* b, color_t* vibuff, uint32_t hres) -{ - color_t filtered; - color_t leftuppix, leftdownpix, leftpix; - color_t rightuppix, rightdownpix, rightpix; - color_t uppix, downpix; - int32_t ihres = (int32_t)hres; //can't apply unary minus to unsigned - - leftuppix = vibuff[-ihres - 1]; - leftdownpix = vibuff[ihres - 1]; - leftpix = vibuff[-1]; - - rightuppix = vibuff[-ihres + 1]; - rightdownpix = vibuff[ihres + 1]; - rightpix = vibuff[1]; - - uppix = vibuff[-ihres]; - downpix = vibuff[ihres]; - filtered = *vibuff; - - restore_two(&filtered, &leftuppix); - restore_two(&filtered, &uppix); - restore_two(&filtered, &rightuppix); - - restore_two(&filtered, &leftpix); - restore_two(&filtered, &rightpix); - - restore_two(&filtered, &leftdownpix); - restore_two(&filtered, &downpix); - restore_two(&filtered, &rightdownpix); - - *r = filtered.i.r; - *g = filtered.i.g; - *b = filtered.i.b; - - if(*r < 0) *r = 0; - else if(*r > 255) *r = 255; - if(*g < 0) *g = 0; - else if(*g > 255) *g = 255; - if(*b < 0) *b = 0; - else if(*b > 255) *b = 255; -} - -// This is wrong, only the 5 upper bits are compared. -static inline void restore_two(color_t* filtered, color_t* neighbour) -{ - if (neighbour->i.r > filtered->i.r) - { - filtered->i.r += 1; - } - if (neighbour->i.r < filtered->i.r) - { - filtered->i.r -= 1; - } - if (neighbour->i.g > filtered->i.g) - { - filtered->i.g += 1; - } - if (neighbour->i.g < filtered->i.g) - { - filtered->i.g -= 1; - } - if (neighbour->i.b > filtered->i.b) - { - filtered->i.b += 1; - } - if (neighbour->i.b < filtered->i.b) - { - filtered->i.b -= 1; - } -} - -static inline void video_max(uint32_t* Pixels, uint8_t* max, uint32_t* enb) -{ - int i; - int pos = 0; - *enb = 0; - for(i = 0; i < 7; i++) - { - if (Pixels[i] > Pixels[pos]) - { - *enb += (1 << i); - pos = i; - } - else if (Pixels[i] < Pixels[pos]) - { - *enb += (1 << i); - } - else - { - pos = i; - } - } - *max = Pixels[pos]; -} - -static inline uint32_t ge_two(uint32_t enb) -{ - if(enb & 1) - { - if(enb & 2) - return 1; - if(enb & 4) - return 1; - if(enb & 8) - return 1; - if(enb & 16) - return 1; - if(enb & 32) - return 1; - if(enb & 64) - return 1; - if(enb & 128) - return 1; - return 0; - } - else if(enb & 2) - { - if(enb & 4) - return 1; - if(enb & 8) - return 1; - if(enb & 16) - return 1; - if(enb & 32) - return 1; - if(enb & 64) - return 1; - if(enb & 128) - return 1; - return 0; - } - else if(enb & 4) - { - if(enb & 8) - return 1; - if(enb & 16) - return 1; - if(enb & 32) - return 1; - if(enb & 64) - return 1; - if(enb & 128) - return 1; - return 0; - } - else if(enb & 8) - { - if(enb & 16) - return 1; - if(enb & 32) - return 1; - if(enb & 64) - return 1; - if(enb & 128) - return 1; - return 0; - } - else if(enb & 16) - { - if(enb & 32) - return 1; - if(enb & 64) - return 1; - if(enb & 128) - return 1; - return 0; - } - else if(enb & 32) - { - if(enb & 64) - return 1; - if(enb & 128) - return 1; - return 0; - } - else if(enb & 64) - { - if(enb & 128) - return 1; - return 0; - } - return 0; -} -#endif diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdptpipe.cpp b/waterbox/ares64/ares/thirdparty/mame/mame/video/rdptpipe.cpp deleted file mode 100644 index 4cb556eb1c..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdptpipe.cpp +++ /dev/null @@ -1,1023 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -/****************************************************************************** - - - SGI/Nintendo Reality Display Texture Fetch Unit (TF) - ------------------- - - by Ryan Holtz - based on initial C code by Ville Linde - contains additional improvements from angrylion, Ziggy, Gonetz and Orkin - - -******************************************************************************/ - -#include "emu.h" -#include "includes/n64.h" -#include "video/rdptpipe.h" -#include "video/n64.h" -#include "video/rgbutil.h" - -#define RELATIVE(x, y) ((((x) >> 3) - (y)) << 3) | (x & 7); - -void n64_texture_pipe_t::set_machine(running_machine &machine) -{ - n64_state* state = machine.driver_data(); - - m_rdp = state->rdp(); - - for(int32_t i = 0; i < 0x10000; i++) - { - m_expand_16to32_table[i] = color_t((i & 1) ? 0xff : 0x00, m_rdp->m_replicated_rgba[(i >> 11) & 0x1f], m_rdp->m_replicated_rgba[(i >> 6) & 0x1f], m_rdp->m_replicated_rgba[(i >> 1) & 0x1f]); - } - - for(uint32_t i = 0; i < 0x80000; i++) - { - if (i & 0x40000) - { - m_lod_lookup[i] = 0x7fff; - } - else if (i & 0x20000) - { - m_lod_lookup[i] = 0x8000; - } - else - { - if ((i & 0x18000) == 0x8000) - { - m_lod_lookup[i] = 0x7fff; - } - else if ((i & 0x18000) == 0x10000) - { - m_lod_lookup[i] = 0x8000; - } - else - { - m_lod_lookup[i] = i & 0xffff; - } - } - } - - m_st2_add.set(1, 0, 1, 0); - m_v1.set(1, 1, 1, 1); -} - -void n64_texture_pipe_t::mask(rgbaint_t& sstt, const n64_tile_t& tile) -{ - uint32_t s_mask_bits = m_maskbits_table[tile.mask_s]; - uint32_t t_mask_bits = m_maskbits_table[tile.mask_t]; - rgbaint_t maskbits(s_mask_bits, s_mask_bits, t_mask_bits, t_mask_bits); - - rgbaint_t do_wrap(sstt); - do_wrap.sra(tile.wrapped_mask); - do_wrap.and_reg(m_v1); - do_wrap.cmpeq(m_v1); - do_wrap.and_reg(tile.mm); - - rgbaint_t wrapped(sstt); - wrapped.xor_reg(do_wrap); - wrapped.and_reg(maskbits); - wrapped.and_reg(tile.mask); - sstt.and_reg(tile.invmask); - sstt.or_reg(wrapped); -} - -rgbaint_t n64_texture_pipe_t::shift_cycle(rgbaint_t& st, const n64_tile_t& tile) -{ - st.sign_extend(0x00008000, 0xffff8000); - st.sra(tile.rshift); - st.shl(tile.lshift); - - rgbaint_t maxst(st); - maxst.sra_imm(3); - rgbaint_t maxst_eq(maxst); - maxst.cmpgt(tile.sth); - maxst_eq.cmpeq(tile.sth); - maxst.or_reg(maxst_eq); - - rgbaint_t stlsb(st); - stlsb.and_imm(7); - - st.sra_imm(3); - st.sub(tile.stl); - st.shl_imm(3); - st.or_reg(stlsb); - - return maxst; -} - -inline void n64_texture_pipe_t::shift_copy(rgbaint_t& st, const n64_tile_t& tile) -{ - st.shr(tile.rshift); - st.shl(tile.lshift); -} - -void n64_texture_pipe_t::clamp_cycle(rgbaint_t& st, rgbaint_t& stfrac, rgbaint_t& maxst, const int32_t tilenum, const n64_tile_t& tile, rdp_span_aux* userdata) -{ - rgbaint_t not_clamp(tile.clamp_st); - not_clamp.xor_imm(0xffffffff); - - rgbaint_t highbit_mask(0x10000, 0x10000, 0x10000, 0x10000); - rgbaint_t highbit(st); - highbit.and_reg(highbit_mask); - highbit.cmpeq(highbit_mask); - - rgbaint_t not_highbit(highbit); - not_highbit.xor_imm(0xffffffff); - - rgbaint_t not_maxst(maxst); - not_maxst.xor_imm(0xffffffff); - not_maxst.and_reg(not_highbit); - not_maxst.or_reg(not_clamp); - - rgbaint_t shifted_st(st); - shifted_st.sign_extend(0x00010000, 0xffff0000); - shifted_st.shr_imm(5); - shifted_st.and_imm(0x1fff); - shifted_st.and_reg(not_maxst); - stfrac.and_reg(not_maxst); - - rgbaint_t clamp_diff(userdata->m_clamp_diff[tilenum]); - clamp_diff.and_reg(tile.clamp_st); - clamp_diff.and_reg(maxst); - - st.set(shifted_st); - st.or_reg(clamp_diff); -} - -void n64_texture_pipe_t::clamp_cycle_light(rgbaint_t& st, rgbaint_t& maxst, const int32_t tilenum, const n64_tile_t& tile, rdp_span_aux* userdata) -{ - rgbaint_t not_clamp(tile.clamp_st); - not_clamp.xor_imm(0xffffffff); - - rgbaint_t highbit_mask(0x10000, 0x10000, 0x10000, 0x10000); - rgbaint_t highbit(st); - highbit.and_reg(highbit_mask); - highbit.cmpeq(highbit_mask); - - rgbaint_t not_highbit(highbit); - not_highbit.xor_imm(0xffffffff); - - rgbaint_t not_maxst(maxst); - not_maxst.xor_imm(0xffffffff); - not_maxst.and_reg(not_highbit); - not_maxst.or_reg(not_clamp); - - rgbaint_t shifted_st(st); - shifted_st.sign_extend(0x00010000, 0xffff0000); - shifted_st.shr_imm(5); - shifted_st.and_imm(0x1fff); - shifted_st.and_reg(not_maxst); - - rgbaint_t clamp_diff(userdata->m_clamp_diff[tilenum]); - clamp_diff.and_reg(tile.clamp_st); - clamp_diff.and_reg(maxst); - - st.set(shifted_st); - st.or_reg(clamp_diff); -} - -void n64_texture_pipe_t::cycle_nearest(color_t* TEX, color_t* prev, int32_t SSS, int32_t SST, uint32_t tilenum, uint32_t cycle, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - const n64_tile_t& tile = object.m_tiles[tilenum]; - const uint32_t index = (tile.format << 4) | (tile.size << 2) | ((uint32_t) object.m_other_modes.en_tlut << 1) | (uint32_t) object.m_other_modes.tlut_type; - - rgbaint_t st(0, SSS, 0, SST); - rgbaint_t maxst = shift_cycle(st, tile); - clamp_cycle_light(st, maxst, tilenum, tile, userdata); - mask(st, tile); - - uint32_t tbase = tile.tmem + ((tile.line * st.get_b32()) & 0x1ff); - - rgbaint_t t0; - ((this)->*(m_texel_fetch[index]))(t0, st.get_r32(), st.get_b32(), tbase, tile.palette, userdata); - if (object.m_other_modes.convert_one && cycle) - { - t0.set(*prev); - } - - t0.sign_extend(0x00000100, 0xffffff00); - - rgbaint_t k13r(m_rdp->get_k13()); - k13r.mul_imm(t0.get_r32()); - - TEX->set(m_rdp->get_k02()); - TEX->mul_imm(t0.get_g32()); - TEX->add(k13r); - TEX->add_imm(0x80); - TEX->shr_imm(8); - TEX->add_imm(t0.get_b32()); - TEX->and_imm(0x1ff); -} - -void n64_texture_pipe_t::cycle_nearest_lerp(color_t* TEX, color_t* prev, int32_t SSS, int32_t SST, uint32_t tilenum, uint32_t cycle, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - const n64_tile_t& tile = object.m_tiles[tilenum]; - const uint32_t index = (tile.format << 4) | (tile.size << 2) | ((uint32_t) object.m_other_modes.en_tlut << 1) | (uint32_t) object.m_other_modes.tlut_type; - - rgbaint_t st(0, SSS, 0, SST); - rgbaint_t maxst = shift_cycle(st, tile); - clamp_cycle_light(st, maxst, tilenum, tile, userdata); - mask(st, tile); - - uint32_t tbase = tile.tmem + ((tile.line * st.get_b32()) & 0x1ff); - - ((this)->*(m_texel_fetch[index]))(*TEX, st.get_r32(), st.get_b32(), tbase, tile.palette, userdata); -} - -void n64_texture_pipe_t::cycle_linear(color_t* TEX, color_t* prev, int32_t SSS, int32_t SST, uint32_t tilenum, uint32_t cycle, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - const n64_tile_t& tile = object.m_tiles[tilenum]; - const uint32_t index = (tile.format << 4) | (tile.size << 2) | ((uint32_t) object.m_other_modes.en_tlut << 1) | (uint32_t) object.m_other_modes.tlut_type; - - rgbaint_t st(0, SSS, 0, SST); - rgbaint_t maxst = shift_cycle(st, tile); - - clamp_cycle_light(st, maxst, tilenum, tile, userdata); - - mask(st, tile); - - const uint32_t tbase = tile.tmem + ((tile.line * st.get_b32()) & 0x1ff); - - rgbaint_t t0; - ((this)->*(m_texel_fetch[index]))(t0, st.get_r32(), st.get_b32(), tbase, tile.palette, userdata); - if (object.m_other_modes.convert_one && cycle) - { - t0.set(*prev); - } - - t0.sign_extend(0x00000100, 0xffffff00); - - rgbaint_t k13r(m_rdp->get_k13()); - k13r.mul_imm(t0.get_r32()); - - TEX->set(m_rdp->get_k02()); - TEX->mul_imm(t0.get_g32()); - TEX->add(k13r); - TEX->add_imm(0x80); - TEX->shr_imm(8); - TEX->add_imm(t0.get_b32()); - TEX->and_imm(0x1ff); -} - -void n64_texture_pipe_t::cycle_linear_lerp(color_t* TEX, color_t* prev, int32_t SSS, int32_t SST, uint32_t tilenum, uint32_t cycle, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - const n64_tile_t& tile = object.m_tiles[tilenum]; - - uint32_t tpal = tile.palette; - uint32_t index = (tile.format << 4) | (tile.size << 2) | ((uint32_t) object.m_other_modes.en_tlut << 1) | (uint32_t) object.m_other_modes.tlut_type; - - rgbaint_t sstt(SSS, SSS, SST, SST); - rgbaint_t maxst = shift_cycle(sstt, tile); - rgbaint_t stfrac = sstt; - stfrac.and_imm(0x1f); - - clamp_cycle(sstt, stfrac, maxst, tilenum, tile, userdata); - - sstt.add(m_st2_add); - - mask(sstt, tile); - - const uint32_t tbase1 = tile.tmem + ((tile.line * sstt.get_b32()) & 0x1ff); - const uint32_t tbase2 = tile.tmem + ((tile.line * sstt.get_g32()) & 0x1ff); - - bool upper = ((stfrac.get_r32() + stfrac.get_b32()) >= 0x20); - - rgbaint_t invstf(stfrac); - if (upper) - { - invstf.subr_imm(0x20); - invstf.shl_imm(3); - } - - stfrac.shl_imm(3); - - bool center = (stfrac.get_r32() == 0x10) && (stfrac.get_b32() == 0x10) && object.m_other_modes.mid_texel; - - rgbaint_t t2; - ((this)->*(m_texel_fetch[index]))(*TEX, sstt.get_a32(), sstt.get_b32(), tbase1, tpal, userdata); - ((this)->*(m_texel_fetch[index]))(t2, sstt.get_r32(), sstt.get_g32(), tbase2, tpal, userdata); - - if (!center) - { - if (upper) - { - rgbaint_t t3; - ((this)->*(m_texel_fetch[index]))(t3, sstt.get_a32(), sstt.get_g32(), tbase2, tpal, userdata); - - TEX->sub(t3); - t2.sub(t3); - - TEX->mul_imm(invstf.get_b32()); - t2.mul_imm(invstf.get_r32()); - - TEX->add(t2); - TEX->add_imm(0x0080); - TEX->sra_imm(8); - TEX->add(t3); - } - else - { - rgbaint_t t0; - ((this)->*(m_texel_fetch[index]))(t0, sstt.get_r32(), sstt.get_b32(), tbase1, tpal, userdata); - - TEX->sub(t0); - t2.sub(t0); - - TEX->mul_imm(stfrac.get_r32()); - t2.mul_imm(stfrac.get_b32()); - - TEX->add(t2); - TEX->add_imm(0x80); - TEX->sra_imm(8); - TEX->add(t0); - } - } - else - { - rgbaint_t t0, t3; - ((this)->*(m_texel_fetch[index]))(t0, sstt.get_r32(), sstt.get_b32(), tbase1, tpal, userdata); - ((this)->*(m_texel_fetch[index]))(t3, sstt.get_a32(), sstt.get_g32(), tbase2, tpal, userdata); - TEX->add(t0); - TEX->add(t2); - TEX->add(t3); - TEX->sra_imm(2); - } -} - -void n64_texture_pipe_t::copy(color_t* TEX, int32_t SSS, int32_t SST, uint32_t tilenum, const rdp_poly_state& object, rdp_span_aux* userdata) -{ - const n64_tile_t* tiles = object.m_tiles; - const n64_tile_t& tile = tiles[tilenum]; - - rgbaint_t st(0, SSS, 0, SST); - shift_copy(st, tile); - rgbaint_t stlsb(st); - stlsb.and_imm(7); - st.shr_imm(3); - st.sub(rgbaint_t(0, tile.sl, 0, tile.tl)); - st.shl_imm(3); - st.add(stlsb); - st.sign_extend(0x00010000, 0xffff0000); - st.shr_imm(5); - st.and_imm(0x1fff); - mask(st, tile); - - const uint32_t index = (tile.format << 4) | (tile.size << 2) | ((uint32_t) object.m_other_modes.en_tlut << 1) | (uint32_t) object.m_other_modes.tlut_type; - const uint32_t tbase = tile.tmem + ((tile.line * st.get_b32()) & 0x1ff); - ((this)->*(m_texel_fetch[index]))(*TEX, st.get_r32(), st.get_b32(), tbase, tile.palette, userdata); -} - -void n64_texture_pipe_t::lod_1cycle(int32_t* sss, int32_t* sst, const int32_t s, const int32_t t, const int32_t w, const int32_t dsinc, const int32_t dtinc, const int32_t dwinc, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - const int32_t nextsw = (w + dwinc) >> 16; - int32_t nexts = (s + dsinc) >> 16; - int32_t nextt = (t + dtinc) >> 16; - - if (object.m_other_modes.persp_tex_en) - { - m_rdp->tc_div(nexts, nextt, nextsw, &nexts, &nextt); - } - else - { - m_rdp->tc_div_no_perspective(nexts, nextt, nextsw, &nexts, &nextt); - } - - userdata->m_start_span = false; - userdata->m_precomp_s = nexts; - userdata->m_precomp_t = nextt; - - const int32_t lodclamp = (((*sst & 0x60000) > 0) | ((nextt & 0x60000) > 0)) || (((*sss & 0x60000) > 0) | ((nexts & 0x60000) > 0)); - - int32_t horstep = SIGN17(nexts & 0x1ffff) - SIGN17(*sss & 0x1ffff); - int32_t vertstep = SIGN17(nextt & 0x1ffff) - SIGN17(*sst & 0x1ffff); - if (horstep & 0x20000) - { - horstep = ~horstep & 0x1ffff; - } - if (vertstep & 0x20000) - { - vertstep = ~vertstep & 0x1ffff; - } - - int32_t lod = (horstep >= vertstep) ? horstep : vertstep; - - *sss = m_lod_lookup[*sss & 0x7ffff]; - *sst = m_lod_lookup[*sst & 0x7ffff]; - - if ((lod & 0x4000) || lodclamp) - { - lod = 0x7fff; - } - else if (lod < object.m_misc_state.m_min_level) - { - lod = object.m_misc_state.m_min_level; - } - - int32_t l_tile = m_rdp->get_log2((lod >> 5) & 0xff); - const bool magnify = (lod < 32); - const bool distant = ((lod & 0x6000) || (l_tile >= object.m_misc_state.m_max_level)); - - uint8_t lod_fraction = ((lod << 3) >> l_tile) & 0xff; - - if(!object.m_other_modes.sharpen_tex_en && !object.m_other_modes.detail_tex_en) - { - if (distant) - { - lod_fraction = 0xff; - } - else if (magnify) - { - lod_fraction = 0; - } - } - - userdata->m_lod_fraction.set(lod_fraction, lod_fraction, lod_fraction, lod_fraction); - /* FIXME: ??? - if(object.m_other_modes.sharpen_tex_en && magnify) - { - userdata->m_lod_fraction |= 0x100; - } - */ -} - -void n64_texture_pipe_t::lod_2cycle(int32_t* sss, int32_t* sst, const int32_t s, const int32_t t, const int32_t w, const int32_t dsinc, const int32_t dtinc, const int32_t dwinc, const int32_t prim_tile, int32_t* t1, int32_t* t2, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - const int32_t nextsw = (w + dwinc) >> 16; - int32_t nexts = (s + dsinc) >> 16; - int32_t nextt = (t + dtinc) >> 16; - - if (object.m_other_modes.persp_tex_en) - { - m_rdp->tc_div(nexts, nextt, nextsw, &nexts, &nextt); - } - else - { - m_rdp->tc_div_no_perspective(nexts, nextt, nextsw, &nexts, &nextt); - } - - userdata->m_start_span = false; - userdata->m_precomp_s = nexts; - userdata->m_precomp_t = nextt; - - const int32_t lodclamp = (((*sst & 0x60000) > 0) | ((nextt & 0x60000) > 0)) || (((*sss & 0x60000) > 0) | ((nexts & 0x60000) > 0)); - - int32_t horstep = SIGN17(nexts & 0x1ffff) - SIGN17(*sss & 0x1ffff); - int32_t vertstep = SIGN17(nextt & 0x1ffff) - SIGN17(*sst & 0x1ffff); - if (horstep & 0x20000) - { - horstep = ~horstep & 0x1ffff; - } - if (vertstep & 0x20000) - { - vertstep = ~vertstep & 0x1ffff; - } - - int32_t lod = (horstep >= vertstep) ? horstep : vertstep; - - *sss = m_lod_lookup[*sss & 0x7ffff]; - *sst = m_lod_lookup[*sst & 0x7ffff]; - - if ((lod & 0x4000) || lodclamp) - { - lod = 0x7fff; - } - else if (lod < object.m_misc_state.m_min_level) - { - lod = object.m_misc_state.m_min_level; - } - - int32_t l_tile = m_rdp->get_log2((lod >> 5) & 0xff); - const bool magnify = (lod < 32); - const bool distant = ((lod & 0x6000) || (l_tile >= object.m_misc_state.m_max_level)); - - uint8_t lod_fraction = ((lod << 3) >> l_tile) & 0xff; - - if(!object.m_other_modes.sharpen_tex_en && !object.m_other_modes.detail_tex_en) - { - if (distant) - { - lod_fraction = 0xff; - } - else if (magnify) - { - lod_fraction = 0; - } - } - - userdata->m_lod_fraction.set(lod_fraction, lod_fraction, lod_fraction, lod_fraction); - - /* FIXME: ??? - if(object.m_other_modes.sharpen_tex_en && magnify) - { - userdata->m_lod_fraction |= 0x100; - }*/ - - if (object.m_other_modes.tex_lod_en) - { - if (distant) - { - l_tile = object.m_misc_state.m_max_level; - } - if (!object.m_other_modes.detail_tex_en) - { - *t1 = (prim_tile + l_tile) & 7; - if (!(distant || (!object.m_other_modes.sharpen_tex_en && magnify))) - { - *t2 = (*t1 + 1) & 7; - } - else - { - *t2 = *t1; // World Driver Championship, Stunt Race 64, Beetle Adventure Racing - } - } - else // Beetle Adventure Racing, World Driver Championship (ingame_, NFL Blitz 2001, Pilotwings - { - if (!magnify) - { - *t1 = (prim_tile + l_tile + 1); - } - else - { - *t1 = (prim_tile + l_tile); - } - *t1 &= 7; - if (!distant && !magnify) - { - *t2 = (prim_tile + l_tile + 2) & 7; - } - else - { - *t2 = (prim_tile + l_tile + 1) & 7; - } - } - } -} - -void n64_texture_pipe_t::lod_2cycle_limited(int32_t* sss, int32_t* sst, const int32_t s, const int32_t t, const int32_t w, const int32_t dsinc, const int32_t dtinc, const int32_t dwinc, const int32_t prim_tile, int32_t* t1, const rdp_poly_state& object) -{ - const int32_t nextsw = (w + dwinc) >> 16; - int32_t nexts = (s + dsinc) >> 16; - int32_t nextt = (t + dtinc) >> 16; - - if (object.m_other_modes.persp_tex_en) - { - m_rdp->tc_div(nexts, nextt, nextsw, &nexts, &nextt); - } - else - { - m_rdp->tc_div_no_perspective(nexts, nextt, nextsw, &nexts, &nextt); - } - - const int32_t lodclamp = (((*sst & 0x60000) > 0) | ((nextt & 0x60000) > 0)) || (((*sss & 0x60000) > 0) | ((nexts & 0x60000) > 0)); - - int32_t horstep = SIGN17(nexts & 0x1ffff) - SIGN17(*sss & 0x1ffff); - int32_t vertstep = SIGN17(nextt & 0x1ffff) - SIGN17(*sst & 0x1ffff); - if (horstep & 0x20000) - { - horstep = ~horstep & 0x1ffff; - } - if (vertstep & 0x20000) - { - vertstep = ~vertstep & 0x1ffff; - } - - int32_t lod = (horstep >= vertstep) ? horstep : vertstep; - - *sss = m_lod_lookup[*sss & 0x7ffff]; - *sst = m_lod_lookup[*sst & 0x7ffff]; - - if ((lod & 0x4000) || lodclamp) - { - lod = 0x7fff; - } - else if (lod < object.m_misc_state.m_min_level) - { - lod = object.m_misc_state.m_min_level; - } - - int32_t l_tile = m_rdp->get_log2((lod >> 5) & 0xff); - const bool magnify = (lod < 32); - const bool distant = (lod & 0x6000) || (l_tile >= object.m_misc_state.m_max_level); - - if (object.m_other_modes.tex_lod_en) - { - if (distant) - { - l_tile = object.m_misc_state.m_max_level; - } - if (!object.m_other_modes.detail_tex_en) - { - *t1 = (prim_tile + l_tile) & 7; - } - else - { - if (!magnify) - { - *t1 = (prim_tile + l_tile + 1); - } - else - { - *t1 = (prim_tile + l_tile); - } - *t1 &= 7; - } - } -} - -void n64_texture_pipe_t::calculate_clamp_diffs(uint32_t prim_tile, rdp_span_aux* userdata, const rdp_poly_state& object) -{ - const n64_tile_t* tiles = object.m_tiles; - if (object.m_other_modes.cycle_type == CYCLE_TYPE_2) - { - if (object.m_other_modes.tex_lod_en) - { - for (int32_t start = 0; start <= 7; start++) - { - userdata->m_clamp_diff[start].set((tiles[start].sh >> 2) - (tiles[start].sl >> 2), (tiles[start].sh >> 2) - (tiles[start].sl >> 2), (tiles[start].th >> 2) - (tiles[start].tl >> 2), (tiles[start].th >> 2) - (tiles[start].tl >> 2)); - } - } - else - { - const int32_t start = prim_tile; - const int32_t end = (prim_tile + 1) & 7; - userdata->m_clamp_diff[start].set((tiles[start].sh >> 2) - (tiles[start].sl >> 2), (tiles[start].sh >> 2) - (tiles[start].sl >> 2), (tiles[start].th >> 2) - (tiles[start].tl >> 2), (tiles[start].th >> 2) - (tiles[start].tl >> 2)); - userdata->m_clamp_diff[end].set((tiles[end].sh >> 2) - (tiles[end].sl >> 2), (tiles[end].sh >> 2) - (tiles[end].sl >> 2), (tiles[end].th >> 2) - (tiles[end].tl >> 2), (tiles[end].th >> 2) - (tiles[end].tl >> 2)); - } - } - else//1-cycle or copy - { - userdata->m_clamp_diff[prim_tile].set((tiles[prim_tile].sh >> 2) - (tiles[prim_tile].sl >> 2), (tiles[prim_tile].sh >> 2) - (tiles[prim_tile].sl >> 2), (tiles[prim_tile].th >> 2) - (tiles[prim_tile].tl >> 2), (tiles[prim_tile].th >> 2) - (tiles[prim_tile].tl >> 2)); - } -} - -#define USE_64K_LUT (1) - -static int32_t sTexAddrSwap16[2] = { WORD_ADDR_XOR, WORD_XOR_DWORD_SWAP }; -static int32_t sTexAddrSwap8[2] = { BYTE_ADDR_XOR, BYTE_XOR_DWORD_SWAP }; - -void n64_texture_pipe_t::fetch_rgba16_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - int32_t taddr = (((tbase << 2) + s) ^ sTexAddrSwap16[t & 1]) & 0x7ff; - - uint16_t c = ((uint16_t*)userdata->m_tmem)[taddr]; - c = ((uint16_t*)(userdata->m_tmem + 0x800))[(c >> 8) << 2]; - -#if USE_64K_LUT - out.set(m_expand_16to32_table[c]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_rgba16_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const int32_t taddr = (((tbase << 2) + s) ^ sTexAddrSwap16[t & 1]) & 0x7ff; - - uint16_t c = ((uint16_t*)userdata->m_tmem)[taddr]; - c = ((uint16_t*)(userdata->m_tmem + 0x800))[(c >> 8) << 2]; - - const uint8_t k = (c >> 8) & 0xff; - out.set(c & 0xff, k, k, k); -} - -void n64_texture_pipe_t::fetch_rgba16_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const int32_t taddr = (((tbase << 2) + s) ^ sTexAddrSwap16[t & 1]) & 0x7ff; - - const uint16_t c = ((uint16_t*)userdata->m_tmem)[taddr]; - -#if USE_64K_LUT - out.set(m_expand_16to32_table[c]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_rgba32_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint32_t *tc = ((uint32_t*)userdata->m_tmem); - const int32_t taddr = (((tbase << 2) + s) ^ sTexAddrSwap16[t & 1]) & 0x3ff; - - uint32_t c = tc[taddr]; - c = ((uint16_t*)(userdata->m_tmem + 0x800))[(c >> 24) << 2]; - -#if USE_64K_LUT - out.set(m_expand_16to32_table[c]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_rgba32_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint32_t *tc = ((uint32_t*)userdata->m_tmem); - const int32_t taddr = (((tbase << 2) + s) ^ sTexAddrSwap16[t & 1]) & 0x3ff; - - uint32_t c = tc[taddr]; - c = ((uint16_t*)(userdata->m_tmem + 0x800))[(c >> 24) << 2]; - - const uint8_t k = (c >> 8) & 0xff; - out.set(c & 0xff, k, k, k); -} - -void n64_texture_pipe_t::fetch_rgba32_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const int32_t taddr = (((tbase << 2) + s) ^ sTexAddrSwap16[t & 1]) & 0x3ff; - - const uint16_t cl = ((uint16_t*)userdata->m_tmem)[taddr]; - const uint16_t ch = ((uint16_t*)userdata->m_tmem)[taddr | 0x400]; - - out.set(ch & 0xff, cl >> 8, cl & 0xff, ch >> 8); -} - -void n64_texture_pipe_t::fetch_nop(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) { } - -void n64_texture_pipe_t::fetch_yuv(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint16_t *tc = ((uint16_t*)userdata->m_tmem); - - const int32_t taddr = (tbase << 3) + s; - const int32_t taddrhi = (taddr ^ sTexAddrSwap8[t & 1]) & 0x7ff; - const int32_t taddrlow = ((taddr >> 1) ^ sTexAddrSwap16[t & 1]) & 0x3ff; - - const uint16_t c = tc[taddrlow]; - - int32_t y = userdata->m_tmem[taddrhi | 0x800]; - int32_t u = c >> 8; - int32_t v = c & 0xff; - - v ^= 0x80; u ^= 0x80; - u |= ((u & 0x80) << 1); - v |= ((v & 0x80) << 1); - - out.set(y, u, v, y); -} - -void n64_texture_pipe_t::fetch_ci4_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = ((((tbase << 4) + s) >> 1) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t p = (s & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); - const uint16_t c = ((uint16_t*)(userdata->m_tmem + 0x800))[((tpal << 4) | p) << 2]; - -#if USE_64K_LUT - out.set(m_expand_16to32_table[c]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_ci4_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - int32_t taddr = ((((tbase << 4) + s) >> 1) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t p = (s & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); - const uint16_t c = ((uint16_t*)(userdata->m_tmem + 0x800))[((tpal << 4) | p) << 2]; - - const uint8_t k = (c >> 8) & 0xff; - out.set(c & 0xff, k, k, k); -} - -void n64_texture_pipe_t::fetch_ci4_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = ((((tbase << 4) + s) >> 1) ^ sTexAddrSwap8[t & 1]) & 0xfff; - - uint8_t p = (s & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); - p = (tpal << 4) | p; - - out.set(p, p, p, p); -} - -void n64_texture_pipe_t::fetch_ci8_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = (((tbase << 3) + s) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t p = tc[taddr]; - const uint16_t c = ((uint16_t*)(userdata->m_tmem + 0x800))[p << 2]; - -#if USE_64K_LUT - out.set(m_expand_16to32_table[c]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_ci8_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = (((tbase << 3) + s) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t p = tc[taddr]; - const uint16_t c = ((uint16_t*)(userdata->m_tmem + 0x800))[p << 2]; - - const uint8_t k = (c >> 8) & 0xff; - out.set(c & 0xff, k, k, k); -} - -void n64_texture_pipe_t::fetch_ci8_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = (((tbase << 3) + s) ^ sTexAddrSwap8[t & 1]) & 0xfff; - - const uint8_t p = tc[taddr]; - out.set(p, p, p, p); -} - -void n64_texture_pipe_t::fetch_ia4_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = ((((tbase << 4) + s) >> 1) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t p = ((s) & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); - const uint16_t c = ((uint16_t*)(userdata->m_tmem + 0x800))[((tpal << 4) | p) << 2]; - -#if USE_64K_LUT - out.set(m_expand_16to32_table[c]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_ia4_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = ((((tbase << 4) + s) >> 1) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t p = ((s) & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); - const uint16_t c = ((uint16_t*)(userdata->m_tmem + 0x800))[((tpal << 4) | p) << 2]; - - const uint8_t k = (c >> 8) & 0xff; - out.set(c & 0xff, k, k, k); -} - -void n64_texture_pipe_t::fetch_ia4_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = ((((tbase << 4) + s) >> 1) ^ sTexAddrSwap8[t & 1]) & 0xfff; - - const uint8_t p = ((s) & 1) ? (tc[taddr] & 0xf) : (tc[taddr] >> 4); - uint8_t i = p & 0xe; - i = (i << 4) | (i << 1) | (i >> 2); - - out.set((p & 1) * 0xff, i, i, i); -} - -void n64_texture_pipe_t::fetch_ia8_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = (((tbase << 3) + s) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t p = tc[taddr]; - const uint16_t c = ((uint16_t*)(userdata->m_tmem + 0x800))[p << 2]; - -#if USE_64K_LUT - out.set(m_expand_16to32_table[c]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_ia8_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = (((tbase << 3) + s) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t p = tc[taddr]; - const uint16_t c = ((uint16_t*)(userdata->m_tmem + 0x800))[p << 2]; - - const uint8_t k = (c >> 8) & 0xff; - out.set(c & 0xff, k, k, k); -} - -void n64_texture_pipe_t::fetch_ia8_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = (((tbase << 3) + s) ^ sTexAddrSwap8[t & 1]) & 0xfff; - - const uint8_t p = tc[taddr]; - uint8_t i = p & 0xf0; - i |= (i >> 4); - - out.set(((p << 4) | (p & 0xf)) & 0xff, i, i, i); -} - -void n64_texture_pipe_t::fetch_ia16_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint16_t *tc = ((uint16_t*)userdata->m_tmem); - const int32_t taddr = (((tbase << 2) + s) ^ sTexAddrSwap16[t & 1]) & 0x3ff; - - uint16_t c = tc[taddr]; - c = ((uint16_t*)(userdata->m_tmem + 0x800))[(c >> 8) << 2]; - -#if USE_64K_LUT - out.set(m_expand_16to32_table[c]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_ia16_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint16_t *tc = ((uint16_t*)userdata->m_tmem); - const int32_t taddr = (((tbase << 2) + s) ^ sTexAddrSwap16[t & 1]) & 0x3ff; - - uint16_t c = tc[taddr]; - c = ((uint16_t*)(userdata->m_tmem + 0x800))[(c >> 8) << 2]; - - const uint8_t k = (c >> 8) & 0xff; - out.set(c & 0xff, k, k, k); -} - -void n64_texture_pipe_t::fetch_ia16_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint16_t *tc = ((uint16_t*)userdata->m_tmem); - const int32_t taddr = (((tbase << 2) + s) ^ sTexAddrSwap16[t & 1]) & 0x7ff; - - const uint16_t c = tc[taddr]; - const uint8_t i = (c >> 8); - out.set(c & 0xff, i, i, i); -} - -void n64_texture_pipe_t::fetch_i4_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = ((((tbase << 4) + s) >> 1) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t byteval = tc[taddr]; - const uint8_t c = ((s & 1)) ? (byteval & 0xf) : ((byteval >> 4) & 0xf); - -#if USE_64K_LUT - const uint16_t k = ((uint16_t*)(userdata->m_tmem + 0x800))[((tpal << 4) | c) << 2]; - out.set(m_expand_16to32_table[k]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_i4_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = ((((tbase << 4) + s) >> 1) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t byteval = tc[taddr]; - const uint8_t c = ((s & 1)) ? (byteval & 0xf) : ((byteval >> 4) & 0xf); - const uint16_t k = ((uint16_t*)(userdata->m_tmem + 0x800))[((tpal << 4) | c) << 2]; - - const uint8_t i = (k >> 8) & 0xff; - out.set(k & 0xff, i, i, i); -} - -void n64_texture_pipe_t::fetch_i4_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = ((((tbase << 4) + s) >> 1) ^ sTexAddrSwap8[t & 1]) & 0xfff; - - const uint8_t byteval = tc[taddr]; - uint8_t c = ((s & 1)) ? (byteval & 0xf) : ((byteval >> 4) & 0xf); - c |= (c << 4); - - out.set(c, c, c, c); -} - -void n64_texture_pipe_t::fetch_i8_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = (((tbase << 3) + s) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t c = tc[taddr]; - -#if USE_64K_LUT - const uint16_t k = ((uint16_t*)(userdata->m_tmem + 0x800))[c << 2]; - out.set(m_expand_16to32_table[k]); -#else - out.set((c & 1) * 0xff, GET_HI_RGBA16_TMEM(c), GET_MED_RGBA16_TMEM(c), GET_LOW_RGBA16_TMEM(c)); -#endif -} - -void n64_texture_pipe_t::fetch_i8_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = (((tbase << 3) + s) ^ sTexAddrSwap8[t & 1]) & 0x7ff; - - const uint8_t c = tc[taddr]; - const uint16_t k = ((uint16_t*)(userdata->m_tmem + 0x800))[c << 2]; - - const uint8_t i = (k >> 8) & 0xff; - out.set(k & 0xff, i, i, i); -} - -void n64_texture_pipe_t::fetch_i8_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata) -{ - const uint8_t *tc = userdata->m_tmem; - const int32_t taddr = (((tbase << 3) + s) ^ sTexAddrSwap8[t & 1]) & 0xfff; - - const uint8_t c = tc[taddr]; - - out.set(c, c, c, c); -} diff --git a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdptpipe.h b/waterbox/ares64/ares/thirdparty/mame/mame/video/rdptpipe.h deleted file mode 100644 index b9c80e1535..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/mame/video/rdptpipe.h +++ /dev/null @@ -1,165 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Ryan Holtz -/****************************************************************************** - - - SGI/Nintendo Reality Display Texture Fetch Unit (TF) - ------------------- - - by Ryan Holtz - based on initial C code by Ville Linde - contains additional improvements from angrylion, Ziggy, Gonetz and Orkin - - -******************************************************************************/ - -#ifndef _VIDEO_RDPTEXPIPE_H_ -#define _VIDEO_RDPTEXPIPE_H_ - -#include "video/n64types.h" - -class n64_texture_pipe_t -{ - public: - typedef void (n64_texture_pipe_t::*texel_fetcher_t) (rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - typedef void (n64_texture_pipe_t::*texel_cycler_t) (color_t* TEX, color_t* prev, int32_t SSS, int32_t SST, uint32_t tilenum, uint32_t cycle, rdp_span_aux* userdata, const rdp_poly_state& object); - - n64_texture_pipe_t() - { - m_maskbits_table[0] = 0xffff; - for(int i = 1; i < 16; i++) - { - m_maskbits_table[i] = ((uint16_t)(0xffff) >> (16 - i)) & 0x3ff; - } - m_start_span = false; - - for (auto & elem : m_texel_fetch) - { - elem = &n64_texture_pipe_t::fetch_nop; - } - - m_texel_fetch[ 8] = &n64_texture_pipe_t::fetch_rgba16_raw; - m_texel_fetch[ 9] = &n64_texture_pipe_t::fetch_rgba16_raw; - m_texel_fetch[10] = &n64_texture_pipe_t::fetch_rgba16_tlut0; - m_texel_fetch[11] = &n64_texture_pipe_t::fetch_rgba16_tlut1; - m_texel_fetch[12] = &n64_texture_pipe_t::fetch_rgba32_raw; - m_texel_fetch[13] = &n64_texture_pipe_t::fetch_rgba32_raw; - m_texel_fetch[14] = &n64_texture_pipe_t::fetch_rgba32_tlut0; - m_texel_fetch[15] = &n64_texture_pipe_t::fetch_rgba32_tlut1; - - m_texel_fetch[24] = &n64_texture_pipe_t::fetch_yuv; - m_texel_fetch[25] = &n64_texture_pipe_t::fetch_yuv; - m_texel_fetch[26] = &n64_texture_pipe_t::fetch_yuv; - m_texel_fetch[27] = &n64_texture_pipe_t::fetch_yuv; - - m_texel_fetch[32] = &n64_texture_pipe_t::fetch_ci4_raw; - m_texel_fetch[33] = &n64_texture_pipe_t::fetch_ci4_raw; - m_texel_fetch[34] = &n64_texture_pipe_t::fetch_ci4_tlut0; - m_texel_fetch[35] = &n64_texture_pipe_t::fetch_ci4_tlut1; - m_texel_fetch[36] = &n64_texture_pipe_t::fetch_ci8_raw; - m_texel_fetch[37] = &n64_texture_pipe_t::fetch_ci8_raw; - m_texel_fetch[38] = &n64_texture_pipe_t::fetch_ci8_tlut0; - m_texel_fetch[39] = &n64_texture_pipe_t::fetch_ci8_tlut1; - - m_texel_fetch[48] = &n64_texture_pipe_t::fetch_ia4_raw; - m_texel_fetch[49] = &n64_texture_pipe_t::fetch_ia4_raw; - m_texel_fetch[50] = &n64_texture_pipe_t::fetch_ia4_tlut0; - m_texel_fetch[51] = &n64_texture_pipe_t::fetch_ia4_tlut1; - m_texel_fetch[52] = &n64_texture_pipe_t::fetch_ia8_raw; - m_texel_fetch[53] = &n64_texture_pipe_t::fetch_ia8_raw; - m_texel_fetch[54] = &n64_texture_pipe_t::fetch_ia8_tlut0; - m_texel_fetch[55] = &n64_texture_pipe_t::fetch_ia8_tlut1; - m_texel_fetch[56] = &n64_texture_pipe_t::fetch_ia16_raw; - m_texel_fetch[57] = &n64_texture_pipe_t::fetch_ia16_raw; - m_texel_fetch[58] = &n64_texture_pipe_t::fetch_ia16_tlut0; - m_texel_fetch[59] = &n64_texture_pipe_t::fetch_ia16_tlut1; - - m_texel_fetch[64] = &n64_texture_pipe_t::fetch_i4_raw; - m_texel_fetch[65] = &n64_texture_pipe_t::fetch_i4_raw; - m_texel_fetch[66] = &n64_texture_pipe_t::fetch_i4_tlut0; - m_texel_fetch[67] = &n64_texture_pipe_t::fetch_i4_tlut1; - m_texel_fetch[68] = &n64_texture_pipe_t::fetch_i8_raw; - m_texel_fetch[69] = &n64_texture_pipe_t::fetch_i8_raw; - m_texel_fetch[70] = &n64_texture_pipe_t::fetch_i8_tlut0; - m_texel_fetch[71] = &n64_texture_pipe_t::fetch_i8_tlut1; - - m_cycle[0] = &n64_texture_pipe_t::cycle_nearest; - m_cycle[1] = &n64_texture_pipe_t::cycle_nearest_lerp; - m_cycle[2] = &n64_texture_pipe_t::cycle_linear; - m_cycle[3] = &n64_texture_pipe_t::cycle_linear_lerp; - } - - void cycle_nearest(color_t* TEX, color_t* prev, int32_t SSS, int32_t SST, uint32_t tilenum, uint32_t cycle, rdp_span_aux* userdata, const rdp_poly_state& object); - void cycle_nearest_lerp(color_t* TEX, color_t* prev, int32_t SSS, int32_t SST, uint32_t tilenum, uint32_t cycle, rdp_span_aux* userdata, const rdp_poly_state& object); - void cycle_linear(color_t* TEX, color_t* prev, int32_t SSS, int32_t SST, uint32_t tilenum, uint32_t cycle, rdp_span_aux* userdata, const rdp_poly_state& object); - void cycle_linear_lerp(color_t* TEX, color_t* prev, int32_t SSS, int32_t SST, uint32_t tilenum, uint32_t cycle, rdp_span_aux* userdata, const rdp_poly_state& object); - - texel_cycler_t m_cycle[4]; - - void copy(color_t* TEX, int32_t SSS, int32_t SST, uint32_t tilenum, const rdp_poly_state& object, rdp_span_aux* userdata); - void calculate_clamp_diffs(uint32_t prim_tile, rdp_span_aux* userdata, const rdp_poly_state& object); - void lod_1cycle(int32_t* sss, int32_t* sst, const int32_t s, const int32_t t, const int32_t w, const int32_t dsinc, const int32_t dtinc, const int32_t dwinc, rdp_span_aux* userdata, const rdp_poly_state& object); - void lod_2cycle(int32_t* sss, int32_t* sst, const int32_t s, const int32_t t, const int32_t w, const int32_t dsinc, const int32_t dtinc, const int32_t dwinc, const int32_t prim_tile, int32_t* t1, int32_t* t2, rdp_span_aux* userdata, const rdp_poly_state& object); - void lod_2cycle_limited(int32_t* sss, int32_t* sst, const int32_t s, const int32_t t, int32_t w, const int32_t dsinc, const int32_t dtinc, const int32_t dwinc, const int32_t prim_tile, int32_t* t1, const rdp_poly_state& object); - - void set_machine(running_machine& machine); - - bool m_start_span; - - private: - void mask(rgbaint_t& sstt, const n64_tile_t& tile); - - rgbaint_t shift_cycle(rgbaint_t& st, const n64_tile_t& tile); - void shift_copy(rgbaint_t& st, const n64_tile_t& tile); - - void clamp_cycle(rgbaint_t& st, rgbaint_t& stfrac, rgbaint_t& maxst, const int32_t tilenum, const n64_tile_t& tile, rdp_span_aux* userdata); - void clamp_cycle_light(rgbaint_t& st, rgbaint_t& maxst, const int32_t tilenum, const n64_tile_t& tile, rdp_span_aux* userdata); - - void fetch_nop(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - - void fetch_rgba16_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_rgba16_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_rgba16_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_rgba32_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_rgba32_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_rgba32_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - - void fetch_yuv(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - - void fetch_ci4_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ci4_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ci4_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ci8_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ci8_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ci8_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - - void fetch_ia4_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ia4_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ia4_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ia8_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ia8_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ia8_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ia16_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ia16_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_ia16_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - - void fetch_i4_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_i4_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_i4_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_i8_tlut0(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_i8_tlut1(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - void fetch_i8_raw(rgbaint_t& out, int32_t s, int32_t t, int32_t tbase, int32_t tpal, rdp_span_aux* userdata); - - texel_fetcher_t m_texel_fetch[16*5]; - - n64_rdp* m_rdp; - - int32_t m_maskbits_table[16]; - color_t m_expand_16to32_table[0x10000]; - uint16_t m_lod_lookup[0x80000]; - - rgbaint_t m_st2_add; - rgbaint_t m_v1; -}; - -#endif // _VIDEO_RDPTEXPIPE_H_ diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/eigcc.h b/waterbox/ares64/ares/thirdparty/mame/osd/eigcc.h deleted file mode 100644 index 2c5bf34ba7..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/eigcc.h +++ /dev/null @@ -1,148 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -/*************************************************************************** - - eigccppc.h - - Inline implementations for GCC compilers. This code is automatically - included if appropriate by eminline.h. - -***************************************************************************/ - -#ifndef MAME_OSD_EIGCC_H -#define MAME_OSD_EIGCC_H - -#include - - -/*************************************************************************** - INLINE MATH FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - addu_32x32_co - perform an unsigned 32 bit + 32 - bit addition and return the result with carry - out --------------------------------------------------*/ - -#ifndef addu_32x32_co -#define addu_32x32_co _addu_32x32_co -inline bool _addu_32x32_co(uint32_t a, uint32_t b, uint32_t &sum) -{ - return __builtin_add_overflow(a, b, &sum); -} -#endif - - -/*------------------------------------------------- - addu_64x64_co - perform an unsigned 64 bit + 64 - bit addition and return the result with carry - out --------------------------------------------------*/ - -#ifndef addu_64x64_co -#define addu_64x64_co _addu_64x64_co -inline bool _addu_64x64_co(uint64_t a, uint64_t b, uint64_t &sum) -{ - return __builtin_add_overflow(a, b, &sum); -} -#endif - - - -/*************************************************************************** - INLINE BIT MANIPULATION FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - count_leading_zeros_32 - return the number of - leading zero bits in a 32-bit value --------------------------------------------------*/ - -#ifndef count_leading_zeros_32 -#define count_leading_zeros_32 _count_leading_zeros_32 -inline uint8_t _count_leading_zeros_32(uint32_t val) -{ - // uses CPU feature if available, otherwise falls back to runtime library call - static_assert(sizeof(val) == sizeof(unsigned), "expected 32-bit unsigned int"); - return uint8_t(unsigned(val ? __builtin_clz(val) : 32)); -} -#endif - - -/*------------------------------------------------- - count_leading_ones_32 - return the number of - leading one bits in a 32-bit value --------------------------------------------------*/ - -#ifndef count_leading_ones_32 -#define count_leading_ones_32 _count_leading_ones_32 -inline uint8_t _count_leading_ones_32(uint32_t val) -{ - return count_leading_zeros_32(~val); -} -#endif - - -/*------------------------------------------------- - count_leading_zeros_64 - return the number of - leading zero bits in a 64-bit value --------------------------------------------------*/ - -#ifndef count_leading_zeros_64 -#define count_leading_zeros_64 _count_leading_zeros_64 -inline uint8_t _count_leading_zeros_64(uint64_t val) -{ - // uses CPU feature if available, otherwise falls back to runtime library call - static_assert(sizeof(val) == sizeof(unsigned long long), "expected 64-bit unsigned long long int"); - return uint8_t(unsigned(val ? __builtin_clzll(val) : 64)); -} -#endif - - -/*------------------------------------------------- - count_leading_ones_64 - return the number of - leading one bits in a 64-bit value --------------------------------------------------*/ - -#ifndef count_leading_ones_64 -#define count_leading_ones_64 _count_leading_ones_64 -inline uint8_t _count_leading_ones_64(uint64_t val) -{ - return count_leading_zeros_64(~val); -} -#endif - - -/*------------------------------------------------- - population_count_32 - return the number of - one bits in a 32-bit value --------------------------------------------------*/ - -#ifndef population_count_32 -#define population_count_32 _population_count_32 -inline unsigned _population_count_32(uint32_t val) -{ - // uses CPU feature if available, otherwise falls back to implementation similar to eminline.h - static_assert(sizeof(val) == sizeof(unsigned), "expected 32-bit unsigned int"); - return unsigned(__builtin_popcount(static_cast(val))); -} -#endif - - -/*------------------------------------------------- - population_count_64 - return the number of - one bits in a 64-bit value --------------------------------------------------*/ - -#ifndef population_count_64 -#define population_count_64 _population_count_64 -inline unsigned _population_count_64(uint64_t val) -{ - // uses CPU feature if available, otherwise falls back to implementation similar to eminline.h - static_assert(sizeof(val) == sizeof(unsigned long long), "expected 64-bit unsigned long long int"); - return unsigned(__builtin_popcountll(static_cast(val))); -} -#endif - -#endif // MAME_OSD_EIGCC_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/eigccarm.h b/waterbox/ares64/ares/thirdparty/mame/osd/eigccarm.h deleted file mode 100644 index 90004daf9d..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/eigccarm.h +++ /dev/null @@ -1,332 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -/*************************************************************************** - - eigccarm.h - - ARM/AArch64 inline implementations for GCC compilers. This code is - automatically included if appropriate by eminline.h. - -***************************************************************************/ - -#ifndef MAME_OSD_EIGCCARM_H -#define MAME_OSD_EIGCCARM_H - - -/*************************************************************************** - INLINE MATH FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - mul_32x32 - perform a signed 32 bit x 32 bit - multiply and return the full 64 bit result --------------------------------------------------*/ - -// GCC can do a good job of this. - - -/*------------------------------------------------- - mulu_32x32 - perform an unsigned 32 bit x - 32 bit multiply and return the full 64 bit - result --------------------------------------------------*/ - -// GCC can do a good job of this - - -/*------------------------------------------------- - mul_32x32_hi - perform a signed 32 bit x 32 bit - multiply and return the upper 32 bits of the - result --------------------------------------------------*/ - -// GCC can do a good job of this - - -/*------------------------------------------------- - mulu_32x32_hi - perform an unsigned 32 bit x - 32 bit multiply and return the upper 32 bits - of the result --------------------------------------------------*/ - -// GCC can do a good job of this - - -/*------------------------------------------------- - mul_32x32_shift - perform a signed 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#if !defined(__aarch64__) -#define mul_32x32_shift _mul_32x32_shift -inline int32_t ATTR_CONST ATTR_FORCE_INLINE -_mul_32x32_shift(int32_t val1, int32_t val2, uint8_t shift) -{ - uint32_t l, h; - - __asm__ ( - " smull %[l], %[h], %[val1], %[val2] \n" - : [l] "=r" (l) - , [h] "=r" (h) - : [val1] "%r" (val1) - , [val2] "r" (val2) - ); - - // Valid for (0 <= shift <= 31) - return int32_t((l >> shift) | (h << (32 - shift))); -} -#endif - - -/*------------------------------------------------- - mulu_32x32_shift - perform an unsigned 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#if !defined(__aarch64__) -#define mulu_32x32_shift _mulu_32x32_shift -inline uint32_t ATTR_CONST ATTR_FORCE_INLINE -_mulu_32x32_shift(uint32_t val1, uint32_t val2, uint8_t shift) -{ - uint32_t l, h; - - __asm__ ( - " umull %[l], %[h], %[val1], %[val2] \n" - : [l] "=r" (l) - , [h] "=r" (h) - : [val1] "%r" (val1) - , [val2] "r" (val2) - ); - - // Valid for (0 <= shift <= 31) - return (l >> shift) | (h << (32 - shift)); -} -#endif - - -/*------------------------------------------------- - div_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - divu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - div_64x32_rem - perform a signed 64 bit x 32 - bit divide and return the 32 bit quotient and - 32 bit remainder --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - divu_64x32_rem - perform an unsigned 64 bit x - 32 bit divide and return the 32 bit quotient - and 32 bit remainder --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - div_32x32_shift - perform a signed divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - divu_32x32_shift - perform an unsigned divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - mod_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - modu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - recip_approx - compute an approximate floating - point reciprocal --------------------------------------------------*/ - -#if defined(__aarch64__) -#define recip_approx _recip_approx -inline float ATTR_CONST ATTR_FORCE_INLINE -_recip_approx(float value) -{ - float result; - - __asm__ ( - " frecpe %s[result], %s[value] \n" - : [result] "=w" (result) - : [value] "w" (value) - ); - - return result; -} -#endif - - -/*------------------------------------------------- - mul_64x64 - perform a signed 64 bit x 64 bit - multiply and return the full 128 bit result --------------------------------------------------*/ - -#if defined(__aarch64__) -#define mul_64x64 _mul_64x64 -inline int64_t ATTR_FORCE_INLINE -_mul_64x64(int64_t a, int64_t b, int64_t &hi) -{ - __int128 const r(__int128(a) * b); - hi = int64_t(uint64_t((unsigned __int128)r >> 64)); - return int64_t(uint64_t((unsigned __int128)r)); -} -#endif - - -/*------------------------------------------------- - mulu_64x64 - perform an unsigned 64 bit x 64 - bit multiply and return the full 128 bit result --------------------------------------------------*/ - -#if defined(__aarch64__) -#define mulu_64x64 _mulu_64x64 -inline uint64_t ATTR_FORCE_INLINE -_mulu_64x64(uint64_t a, uint64_t b, uint64_t &hi) -{ - unsigned __int128 const r((unsigned __int128)a * b); - hi = uint64_t(r >> 64); - return uint64_t(r); -} -#endif - - - -/*************************************************************************** - INLINE BIT MANIPULATION FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - count_leading_zeros_32 - return the number of - leading zero bits in a 32-bit value --------------------------------------------------*/ - -#if defined(__aarch64__) -#define count_leading_zeros_32 _count_leading_zeros_32 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_zeros_32(uint32_t value) -{ - uint32_t result; - - __asm__ ( - " clz %w[result], %w[value] \n" - : [result] "=r" (result) - : [value] "r" (value) - ); - - return uint8_t(result); -} -#endif - - -/*------------------------------------------------- - count_leading_ones_32 - return the number of - leading one bits in a 32-bit value --------------------------------------------------*/ - -#if defined(__aarch64__) -#define count_leading_ones_32 _count_leading_ones_32 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_ones_32(uint32_t value) -{ - uint32_t result; - - __asm__ ( - " clz %w[result], %w[value] \n" - : [result] "=r" (result) - : [value] "r" (~value) - ); - - return uint8_t(result); -} -#endif - - -/*------------------------------------------------- - count_leading_zeros_64 - return the number of - leading zero bits in a 64-bit value --------------------------------------------------*/ - -#if defined(__aarch64__) -#define count_leading_zeros_64 _count_leading_zeros_64 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_zeros_64(uint64_t value) -{ - uint64_t result; - - __asm__ ( - " clz %[result], %[value] \n" - : [result] "=r" (result) - : [value] "r" (value) - ); - - return uint8_t(result); -} -#endif - - -/*------------------------------------------------- - count_leading_ones_64 - return the number of - leading one bits in a 64-bit value --------------------------------------------------*/ - -#if defined(__aarch64__) -#define count_leading_ones_64 _count_leading_ones_64 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_ones_64(uint64_t value) -{ - uint64_t result; - - __asm__ ( - " clz %[result], %[value] \n" - : [result] "=r" (result) - : [value] "r" (~value) - ); - - return uint8_t(result); -} -#endif - -#endif // MAME_OSD_EIGCCARM_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/eigccppc.h b/waterbox/ares64/ares/thirdparty/mame/osd/eigccppc.h deleted file mode 100644 index b1f0fc638a..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/eigccppc.h +++ /dev/null @@ -1,328 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -/*************************************************************************** - - eigccppc.h - - PowerPC (32 and 64-bit) inline implementations for GCC compilers. This - code is automatically included if appropriate by eminline.h. - -***************************************************************************/ - -#ifndef MAME_OSD_EIGCCPPC_H -#define MAME_OSD_EIGCCPPC_H - - -/*************************************************************************** - INLINE MATH FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - mul_32x32 - perform a signed 32 bit x 32 bit - multiply and return the full 64 bit result --------------------------------------------------*/ - -// GCC can do a good job of this. - - -/*------------------------------------------------- - mulu_32x32 - perform an unsigned 32 bit x - 32 bit multiply and return the full 64 bit - result --------------------------------------------------*/ - -// GCC can do a good job of this - - -/*------------------------------------------------- - mul_32x32_hi - perform a signed 32 bit x 32 bit - multiply and return the upper 32 bits of the - result --------------------------------------------------*/ - -// GCC can do a good job of this - - -/*------------------------------------------------- - mulu_32x32_hi - perform an unsigned 32 bit x - 32 bit multiply and return the upper 32 bits - of the result --------------------------------------------------*/ - -// GCC can do a good job of this - - -/*------------------------------------------------- - mul_32x32_shift - perform a signed 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#if !defined(__ppc64__) && !defined(__PPC64__) && !defined(_ARCH_PPC64) -#define mul_32x32_shift _mul_32x32_shift -inline int32_t ATTR_CONST ATTR_FORCE_INLINE -_mul_32x32_shift(int32_t val1, int32_t val2, uint8_t shift) -{ - uint32_t l, h; - - __asm__ ( - " mullw %[l], %[val1], %[val2] \n" - " mulhw %[h], %[val1], %[val2] \n" - : [l] "=&r" (l) - , [h] "=r" (h) - : [val1] "%r" (val1) - , [val2] "r" (val2) - ); - - // Valid for (0 <= shift <= 31) - return int32_t((l >> shift) | (h << (32 - shift))); -} -#endif - - -/*------------------------------------------------- - mulu_32x32_shift - perform an unsigned 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#if !defined(__ppc64__) && !defined(__PPC64__) && !defined(_ARCH_PPC64) -#define mulu_32x32_shift _mulu_32x32_shift -inline uint32_t ATTR_CONST ATTR_FORCE_INLINE -_mulu_32x32_shift(uint32_t val1, uint32_t val2, uint8_t shift) -{ - uint32_t l, h; - - __asm__ ( - " mullw %[l], %[val1], %[val2] \n" - " mulhwu %[h], %[val1], %[val2] \n" - : [l] "=&r" (l) - , [h] "=r" (h) - : [val1] "%r" (val1) - , [val2] "r" (val2) - ); - - // Valid for (0 <= shift <= 31) - return (l >> shift) | (h << (32 - shift)); -} -#endif - - -/*------------------------------------------------- - div_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - divu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - div_64x32_rem - perform a signed 64 bit x 32 - bit divide and return the 32 bit quotient and - 32 bit remainder --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - divu_64x32_rem - perform an unsigned 64 bit x - 32 bit divide and return the 32 bit quotient - and 32 bit remainder --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - div_32x32_shift - perform a signed divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - divu_32x32_shift - perform an unsigned divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - mod_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - modu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -// TBD - - -/*------------------------------------------------- - recip_approx - compute an approximate floating - point reciprocal --------------------------------------------------*/ - -#define recip_approx _recip_approx -inline float ATTR_CONST ATTR_FORCE_INLINE -_recip_approx(float value) -{ - float result; - - __asm__ ( - " fres %[result], %[value] \n" - : [result] "=f" (result) - : [value] "f" (value) - ); - - return result; -} - - -/*------------------------------------------------- - mul_64x64 - perform a signed 64 bit x 64 bit - multiply and return the full 128 bit result --------------------------------------------------*/ - -#if defined(__ppc64__) || defined(__PPC64___) || defined(_ARCH_PPC64) -#define mul_64x64 _mul_64x64 -inline int64_t ATTR_FORCE_INLINE -_mul_64x64(int64_t a, int64_t b, int64_t &hi) -{ - __int128 const r(__int128(a) * b); - hi = int64_t(uint64_t((unsigned __int128)r >> 64)); - return int64_t(uint64_t((unsigned __int128)r)); -} -#endif - - -/*------------------------------------------------- - mulu_64x64 - perform an unsigned 64 bit x 64 - bit multiply and return the full 128 bit result --------------------------------------------------*/ - -#if defined(__ppc64__) || defined(__PPC64___) || defined(_ARCH_PPC64) -#define mulu_64x64 _mulu_64x64 -inline uint64_t ATTR_FORCE_INLINE -_mulu_64x64(uint64_t a, uint64_t b, uint64_t &hi) -{ - unsigned __int128 const r((unsigned __int128)a * b); - hi = uint64_t(r >> 64); - return uint64_t(r); -} -#endif - - - -/*************************************************************************** - INLINE BIT MANIPULATION FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - count_leading_zeros_32 - return the number of - leading zero bits in a 32-bit value --------------------------------------------------*/ - -#define count_leading_zeros_32 _count_leading_zeros_32 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_zeros_32(uint32_t value) -{ - uint32_t result; - - __asm__ ( - " cntlzw %[result], %[value] \n" - : [result] "=r" (result) - : [value] "r" (value) - ); - - return uint8_t(result); -} - - -/*------------------------------------------------- - count_leading_ones_32 - return the number of - leading one bits in a 32-bit value --------------------------------------------------*/ - -#define count_leading_ones_32 _count_leading_ones_32 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_ones_32(uint32_t value) -{ - uint32_t result; - - __asm__ ( - " cntlzw %[result], %[value] \n" - : [result] "=r" (result) - : [value] "r" (~value) - ); - - return uint8_t(result); -} - - -/*------------------------------------------------- - count_leading_zeros_64 - return the number of - leading zero bits in a 64-bit value --------------------------------------------------*/ - -#if defined(__ppc64__) || defined(__PPC64___) || defined(_ARCH_PPC64) -#define count_leading_zeros_64 _count_leading_zeros_64 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_zeros_64(uint64_t value) -{ - uint64_t result; - - __asm__ ( - " cntlzd %[result], %[value] \n" - : [result] "=r" (result) - : [value] "r" (value) - ); - - return uint8_t(result); -} -#endif - - -/*------------------------------------------------- - count_leading_ones_64 - return the number of - leading one bits in a 64-bit value --------------------------------------------------*/ - -#if defined(__ppc64__) || defined(__PPC64___) || defined(_ARCH_PPC64) -#define count_leading_ones_64 _count_leading_ones_64 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_ones_64(uint64_t value) -{ - uint64_t result; - - __asm__ ( - " cntlzd %[result], %[value] \n" - : [result] "=r" (result) - : [value] "r" (~value) - ); - - return uint8_t(result); -} -#endif - -#endif // MAME_OSD_EIGCCPPC_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/eigccx86.h b/waterbox/ares64/ares/thirdparty/mame/osd/eigccx86.h deleted file mode 100644 index 35f02e12f5..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/eigccx86.h +++ /dev/null @@ -1,526 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -/*************************************************************************** - - eigccx86.h - - x86 (32 and 64-bit) inline implementations for GCC compilers. This - code is automatically included if appropriate by eminline.h. - -***************************************************************************/ - -#ifndef MAME_OSD_EIGCCX86_H -#define MAME_OSD_EIGCCX86_H - -// Include MMX/SSE intrinsics headers - -#ifdef __SSE2__ -#include -#include // MMX -#include // SSE -#include // SSE2 -#endif - - -/*************************************************************************** - INLINE MATH FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - mul_32x32 - perform a signed 32 bit x 32 bit - multiply and return the full 64 bit result --------------------------------------------------*/ - -// GCC can do a good job of this. - - -/*------------------------------------------------- - mulu_32x32 - perform an unsigned 32 bit x - 32 bit multiply and return the full 64 bit - result --------------------------------------------------*/ - -// GCC can do a good job of this. - - -/*------------------------------------------------- - mul_32x32_hi - perform a signed 32 bit x 32 bit - multiply and return the upper 32 bits of the - result --------------------------------------------------*/ - -// GCC can do a good job of this. - - -/*------------------------------------------------- - mulu_32x32_hi - perform an unsigned 32 bit x - 32 bit multiply and return the upper 32 bits - of the result --------------------------------------------------*/ - -// GCC can do a good job of this. - - -/*------------------------------------------------- - mul_32x32_shift - perform a signed 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#ifndef __x86_64__ -#define mul_32x32_shift _mul_32x32_shift -inline int32_t ATTR_CONST ATTR_FORCE_INLINE -_mul_32x32_shift(int32_t a, int32_t b, uint8_t shift) -{ - int32_t result; - - // Valid for (0 <= shift <= 31) - __asm__ ( - " imull %[b] ;" - " shrdl %[shift], %%edx, %[result] ;" - : [result] "=a" (result) // result ends up in eax - : [a] "%0" (a) // 'a' should also be in eax on entry - , [b] "rm" (b) // 'b' can be memory or register - , [shift] "Ic" (shift) // 'shift' must be constant in 0-31 range or in cl - : "%edx", "cc" // clobbers edx and condition codes - ); - - return result; -} -#endif - - -/*------------------------------------------------- - mulu_32x32_shift - perform an unsigned 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#ifndef __x86_64__ -#define mulu_32x32_shift _mulu_32x32_shift -inline uint32_t ATTR_CONST ATTR_FORCE_INLINE -_mulu_32x32_shift(uint32_t a, uint32_t b, uint8_t shift) -{ - uint32_t result; - - // Valid for (0 <= shift <= 31) - __asm__ ( - " mull %[b] ;" - " shrdl %[shift], %%edx, %[result] ;" - : [result] "=a" (result) // result ends up in eax - : [a] "%0" (a) // 'a' should also be in eax on entry - , [b] "rm" (b) // 'b' can be memory or register - , [shift] "Ic" (shift) // 'shift' must be constant in 0-31 range or in cl - : "%edx", "cc" // clobbers edx and condition codes - ); - - return result; -} -#endif - - -/*------------------------------------------------- - div_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -#ifndef __x86_64__ -#define div_64x32 _div_64x32 -inline int32_t ATTR_CONST ATTR_FORCE_INLINE -_div_64x32(int64_t a, int32_t b) -{ - int32_t result, temp; - - // Throws arithmetic exception if result doesn't fit in 32 bits - __asm__ ( - " idivl %[b] ;" - : [result] "=a" (result) // result ends up in eax - , [temp] "=d" (temp) // this is effectively a clobber - : [a] "A" (a) // 'a' in edx:eax - , [b] "rm" (b) // 'b' in register or memory - : "cc" // clobbers condition codes - ); - - return result; -} -#endif - - -/*------------------------------------------------- - divu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -#ifndef __x86_64__ -#define divu_64x32 _divu_64x32 -inline uint32_t ATTR_CONST ATTR_FORCE_INLINE -_divu_64x32(uint64_t a, uint32_t b) -{ - uint32_t result, temp; - - // Throws arithmetic exception if result doesn't fit in 32 bits - __asm__ ( - " divl %[b] ;" - : [result] "=a" (result) // result ends up in eax - , [temp] "=d" (temp) // this is effectively a clobber - : [a] "A" (a) // 'a' in edx:eax - , [b] "rm" (b) // 'b' in register or memory - : "cc" // clobbers condition codes - ); - - return result; -} -#endif - - -/*------------------------------------------------- - div_64x32_rem - perform a signed 64 bit x 32 - bit divide and return the 32 bit quotient and - 32 bit remainder --------------------------------------------------*/ - -#define div_64x32_rem _div_64x32_rem -inline int32_t ATTR_FORCE_INLINE -_div_64x32_rem(int64_t dividend, int32_t divisor, int32_t &remainder) -{ - int32_t quotient; -#ifndef __x86_64__ - // Throws arithmetic exception if result doesn't fit in 32 bits - __asm__ ( - " idivl %[divisor] ;" - : [result] "=a" (quotient) // quotient ends up in eax - , [remainder] "=d" (remainder) // remainder ends up in edx - : [dividend] "A" (dividend) // 'dividend' in edx:eax - , [divisor] "rm" (divisor) // 'divisor' in register or memory - : "cc" // clobbers condition codes - ); -#else - int32_t const divh{ int32_t(uint32_t(uint64_t(dividend) >> 32)) }; - int32_t const divl{ int32_t(uint32_t(uint64_t(dividend))) }; - - // Throws arithmetic exception if result doesn't fit in 32 bits - __asm__ ( - " idivl %[divisor] ;" - : [result] "=a" (quotient) // quotient ends up in eax - , [remainder] "=d" (remainder) // remainder ends up in edx - : [divl] "a" (divl) // 'dividend' in edx:eax - , [divh] "d" (divh) - , [divisor] "rm" (divisor) // 'divisor' in register or memory - : "cc" // clobbers condition codes - ); -#endif - return quotient; -} - - -/*------------------------------------------------- - divu_64x32_rem - perform an unsigned 64 bit x - 32 bit divide and return the 32 bit quotient - and 32 bit remainder --------------------------------------------------*/ - -#define divu_64x32_rem _divu_64x32_rem -inline uint32_t ATTR_FORCE_INLINE -_divu_64x32_rem(uint64_t dividend, uint32_t divisor, uint32_t &remainder) -{ - uint32_t quotient; -#ifndef __x86_64__ - // Throws arithmetic exception if result doesn't fit in 32 bits - __asm__ ( - " divl %[divisor] ;" - : [result] "=a" (quotient) // quotient ends up in eax - , [remainder] "=d" (remainder) // remainder ends up in edx - : [dividend] "A" (dividend) // 'dividend' in edx:eax - , [divisor] "rm" (divisor) // 'divisor' in register or memory - : "cc" // clobbers condition codes - ); -#else - uint32_t const divh{ uint32_t(dividend >> 32) }; - uint32_t const divl{ uint32_t(dividend) }; - - // Throws arithmetic exception if result doesn't fit in 32 bits - __asm__ ( - " divl %[divisor] ;" - : [result] "=a" (quotient) // quotient ends up in eax - , [remainder] "=d" (remainder) // remainder ends up in edx - : [divl] "a" (divl) // 'dividend' in edx:eax - , [divh] "d" (divh) - , [divisor] "rm" (divisor) // 'divisor' in register or memory - : "cc" // clobbers condition codes - ); - -#endif - return quotient; -} - - -/*------------------------------------------------- - div_32x32_shift - perform a signed divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -#ifndef __x86_64__ -#define div_32x32_shift _div_32x32_shift -inline int32_t ATTR_CONST ATTR_FORCE_INLINE -_div_32x32_shift(int32_t a, int32_t b, uint8_t shift) -{ - int32_t result; - - // Valid for (0 <= shift <= 31) - // Throws arithmetic exception if result doesn't fit in 32 bits - __asm__ ( - " cdq ;" - " shldl %[shift], %[a], %%edx ;" - " shll %[shift], %[a] ;" - " idivl %[b] ;" - : [result] "=&a" (result) // result ends up in eax - : [a] "0" (a) // 'a' should also be in eax on entry - , [b] "rm" (b) // 'b' can be memory or register - , [shift] "Ic" (shift) // 'shift' must be constant in 0-31 range or in cl - : "%edx", "cc" // clobbers edx and condition codes - ); - - return result; -} -#endif - - -/*------------------------------------------------- - divu_32x32_shift - perform an unsigned divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -#ifndef __x86_64__ -#define divu_32x32_shift _divu_32x32_shift -inline uint32_t ATTR_CONST ATTR_FORCE_INLINE -_divu_32x32_shift(uint32_t a, uint32_t b, uint8_t shift) -{ - int32_t result; - - // Valid for (0 <= shift <= 31) - // Throws arithmetic exception if result doesn't fit in 32 bits - __asm__ ( - " clr %%edx ;" - " shldl %[shift], %[a], %%edx ;" - " shll %[shift], %[a] ;" - " divl %[b] ;" - : [result] "=&a" (result) // result ends up in eax - : [a] "0" (a) // 'a' should also be in eax on entry - , [b] "rm" (b) // 'b' can be memory or register - , [shift] "Ic" (shift) // 'shift' must be constant in 0-31 range or in cl - : "%edx", "cc" // clobbers edx and condition codes - ); - - return result; -} -#endif - - -/*------------------------------------------------- - mod_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -#ifndef __x86_64__ -#define mod_64x32 _mod_64x32 -inline int32_t ATTR_CONST ATTR_FORCE_INLINE -_mod_64x32(int64_t a, int32_t b) -{ - int32_t result, temp; - - // Throws arithmetic exception if quotient doesn't fit in 32 bits - __asm__ ( - " idivl %[b] ;" - : [result] "=d" (result) // Result ends up in edx - , [temp] "=a" (temp) // This is effectively a clobber - : [a] "A" (a) // 'a' in edx:eax - , [b] "rm" (b) // 'b' in register or memory - : "cc" // Clobbers condition codes - ); - - return result; -} -#endif - - -/*------------------------------------------------- - modu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -#ifndef __x86_64__ -#define modu_64x32 _modu_64x32 -inline uint32_t ATTR_CONST ATTR_FORCE_INLINE -_modu_64x32(uint64_t a, uint32_t b) -{ - uint32_t result, temp; - - // Throws arithmetic exception if quotient doesn't fit in 32 bits - __asm__ ( - " divl %[b] ;" - : [result] "=d" (result) // Result ends up in edx - , [temp] "=a" (temp) // This is effectively a clobber - : [a] "A" (a) // 'a' in edx:eax - , [b] "rm" (b) // 'b' in register or memory - : "cc" // Clobbers condition codes - ); - - return result; -} -#endif - - -/*------------------------------------------------- - recip_approx - compute an approximate floating - point reciprocal --------------------------------------------------*/ - -#ifdef __SSE2__ -#define recip_approx _recip_approx -inline float ATTR_CONST ATTR_FORCE_INLINE -_recip_approx(float value) -{ - __m128 const value_xmm(_mm_set_ss(value)); - __m128 const result_xmm(_mm_rcp_ss(value_xmm)); - float result; - _mm_store_ss(&result, result_xmm); - return result; -} -#endif - - -/*------------------------------------------------- - mul_64x64 - perform a signed 64 bit x 64 bit - multiply and return the full 128 bit result --------------------------------------------------*/ - -#ifdef __x86_64__ -#define mul_64x64 _mul_64x64 -inline int64_t ATTR_FORCE_INLINE -_mul_64x64(int64_t a, int64_t b, int64_t &hi) -{ - __int128 const r(__int128(a) * b); - hi = int64_t(uint64_t((unsigned __int128)r >> 64)); - return int64_t(uint64_t((unsigned __int128)r)); -} -#endif - - -/*------------------------------------------------- - mulu_64x64 - perform an unsigned 64 bit x 64 - bit multiply and return the full 128 bit result --------------------------------------------------*/ - -#ifdef __x86_64__ -#define mulu_64x64 _mulu_64x64 -inline uint64_t ATTR_FORCE_INLINE -_mulu_64x64(uint64_t a, uint64_t b, uint64_t &hi) -{ - unsigned __int128 const r((unsigned __int128)a * b); - hi = uint64_t(r >> 64); - return uint64_t(r); -} -#endif - - - -/*************************************************************************** - INLINE BIT MANIPULATION FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - count_leading_zeros_32 - return the number of - leading zero bits in a 32-bit value --------------------------------------------------*/ - -#define count_leading_zeros_32 _count_leading_zeros_32 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_zeros_32(uint32_t value) -{ - uint32_t result; - __asm__ ( - " bsrl %[value], %[result] ;" - " cmovzl %[bias], %[result] ;" - : [result] "=&r" (result) // result can be in any register - : [value] "rm" (value) // 'value' can be register or memory - , [bias] "rm" (~uint32_t(0)) // 'bias' can be register or memory - : "cc" // clobbers condition codes - ); - return uint8_t(31U - result); -} - - -/*------------------------------------------------- - count_leading_ones_32 - return the number of - leading one bits in a 32-bit value --------------------------------------------------*/ - -#define count_leading_ones_32 _count_leading_ones_32 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_ones_32(uint32_t value) -{ - uint32_t result; - __asm__ ( - " bsrl %[value], %[result] ;" - " cmovzl %[bias], %[result] ;" - : [result] "=&r" (result) // result can be in any register - : [value] "rm" (~value) // 'value' can be register or memory - , [bias] "rm" (~uint32_t(0)) // 'bias' can be register or memory - : "cc" // clobbers condition codes - ); - return uint8_t(31U - result); -} - - -/*------------------------------------------------- - count_leading_zeros_64 - return the number of - leading zero bits in a 64-bit value --------------------------------------------------*/ - -#ifdef __x86_64__ -#define count_leading_zeros_64 _count_leading_zeros_64 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_zeros_64(uint64_t value) -{ - uint64_t result; - __asm__ ( - " bsrq %[value], %[result] ;" - " cmovzq %[bias], %[result] ;" - : [result] "=&r" (result) // result can be in any register - : [value] "rm" (value) // 'value' can be register or memory - , [bias] "rm" (~uint64_t(0)) // 'bias' can be register or memory - : "cc" // clobbers condition codes - ); - return uint8_t(63U - result); -} -#endif - - -/*------------------------------------------------- - count_leading_ones_64 - return the number of - leading one bits in a 64-bit value --------------------------------------------------*/ - -#ifdef __x86_64__ -#define count_leading_ones_64 _count_leading_ones_64 -inline uint8_t ATTR_CONST ATTR_FORCE_INLINE -_count_leading_ones_64(uint64_t value) -{ - uint64_t result; - __asm__ ( - " bsrq %[value], %[result] ;" - " cmovzq %[bias], %[result] ;" - : [result] "=&r" (result) // result can be in any register - : [value] "rm" (~value) // 'value' can be register or memory - , [bias] "rm" (~uint64_t(0)) // 'bias' can be register or memory - : "cc" // clobbers condition codes - ); - return uint8_t(63U - result); -} -#endif - -#endif // MAME_OSD_EIGCCX86_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/eivc.h b/waterbox/ares64/ares/thirdparty/mame/osd/eivc.h deleted file mode 100644 index 2ffd0e7633..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/eivc.h +++ /dev/null @@ -1,94 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -//============================================================ -// -// eivc.h -// -// Inline implementations for MSVC compiler. -// -//============================================================ - -#ifndef MAME_OSD_EIVC_H -#define MAME_OSD_EIVC_H - -#pragma once - -#include -#pragma intrinsic(_BitScanReverse) -#ifdef PTR64 -#pragma intrinsic(_BitScanReverse64) -#endif - - -/*************************************************************************** - INLINE BIT MANIPULATION FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - count_leading_zeros_32 - return the number of - leading zero bits in a 32-bit value --------------------------------------------------*/ - -#ifndef count_leading_zeros_32 -#define count_leading_zeros_32 _count_leading_zeros_32 -__forceinline uint8_t _count_leading_zeros_32(uint32_t value) -{ - unsigned long index; - return _BitScanReverse(&index, value) ? (31U - index) : 32U; -} -#endif - - -/*------------------------------------------------- - count_leading_ones_32 - return the number of - leading one bits in a 32-bit value --------------------------------------------------*/ - -#ifndef count_leading_ones_32 -#define count_leading_ones_32 _count_leading_ones_32 -__forceinline uint8_t _count_leading_ones_32(uint32_t value) -{ - unsigned long index; - return _BitScanReverse(&index, ~value) ? (31U - index) : 32U; -} -#endif - - -/*------------------------------------------------- - count_leading_zeros_64 - return the number of - leading zero bits in a 64-bit value --------------------------------------------------*/ - -#ifndef count_leading_zeros_64 -#define count_leading_zeros_64 _count_leading_zeros_64 -__forceinline uint8_t _count_leading_zeros_64(uint64_t value) -{ - unsigned long index; -#ifdef PTR64 - return _BitScanReverse64(&index, value) ? (63U - index) : 64U; -#else - return _BitScanReverse(&index, uint32_t(value >> 32)) ? (31U - index) : _BitScanReverse(&index, uint32_t(value)) ? (63U - index) : 64U; -#endif -} -#endif - - -/*------------------------------------------------- - count_leading_ones_64 - return the number of - leading one bits in a 64-bit value --------------------------------------------------*/ - -#ifndef count_leading_ones_64 -#define count_leading_ones_64 _count_leading_ones_64 -__forceinline uint8_t _count_leading_ones_64(uint64_t value) -{ - unsigned long index; -#ifdef PTR64 - return _BitScanReverse64(&index, ~value) ? (63U - index) : 64U; -#else - return _BitScanReverse(&index, ~uint32_t(value >> 32)) ? (31U - index) : _BitScanReverse(&index, ~uint32_t(value)) ? (63U - index) : 64U; -#endif -} -#endif - -#endif // MAME_OSD_EIVC_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/eivcarm.h b/waterbox/ares64/ares/thirdparty/mame/osd/eivcarm.h deleted file mode 100644 index 5e612cb25f..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/eivcarm.h +++ /dev/null @@ -1,75 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Vas Crabb -//============================================================ -// -// eivcarm.h -// -// ARM/AArch64 inline implementations for MSVC compiler. -// -//============================================================ - -#ifndef MAME_OSD_EIVCARM_H -#define MAME_OSD_EIVCARM_H - -#pragma once - -#include - -#pragma intrinsic(_CountLeadingZeros) -#pragma intrinsic(_CountLeadingZeros64) -#pragma intrinsic(_CountLeadingOnes) -#pragma intrinsic(_CountLeadingOnes64) - - -/*************************************************************************** - INLINE BIT MANIPULATION FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - count_leading_zeros_32 - return the number of - leading zero bits in a 32-bit value --------------------------------------------------*/ - -#define count_leading_zeros_32 _count_leading_zeros_32 -__forceinline uint8_t _count_leading_zeros_32(uint32_t value) -{ - return uint8_t(_CountLeadingZeros(value)); -} - - -/*------------------------------------------------- - count_leading_ones_32 - return the number of - leading one bits in a 32-bit value --------------------------------------------------*/ - -#define count_leading_ones_32 _count_leading_ones_32 -__forceinline uint8_t _count_leading_ones_32(uint32_t value) -{ - return uint8_t(_CountLeadingOnes(value)); -} - - -/*------------------------------------------------- - count_leading_zeros_64 - return the number of - leading zero bits in a 64-bit value --------------------------------------------------*/ - -#define count_leading_zeros_64 _count_leading_zeros_64 -__forceinline uint8_t _count_leading_zeros_64(uint64_t value) -{ - return uint8_t(_CountLeadingZeros64(value)); -} - - -/*------------------------------------------------- - count_leading_ones_64 - return the number of - leading one bits in a 64-bit value --------------------------------------------------*/ - -#define count_leading_ones_64 _count_leading_ones_64 -__forceinline uint8_t _count_leading_ones_64(uint64_t value) -{ - return uint8_t(_CountLeadingOnes64(value)); -} - -#endif // MAME_OSD_EIVCARM_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/eivcx86.h b/waterbox/ares64/ares/thirdparty/mame/osd/eivcx86.h deleted file mode 100644 index eb8811ad8b..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/eivcx86.h +++ /dev/null @@ -1,468 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -//============================================================ -// -// eivcx86.h -// -// x86 inline implementations for MSVC compiler. -// -//============================================================ - -#ifndef MAME_OSD_EIVCX86_H -#define MAME_OSD_EIVCX86_H - -#pragma once - -#ifdef PTR64 -#include -#endif - -#include - - -/*************************************************************************** - INLINE MATH FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - mul_32x32 - perform a signed 32 bit x 32 bit - multiply and return the full 64 bit result --------------------------------------------------*/ - -#ifndef PTR64 -#define mul_32x32 _mul_32x32 -inline int64_t _mul_32x32(int32_t a, int32_t b) -{ - // in theory this should work, but it is untested - __asm - { - mov eax,a - imul b - // leave results in edx:eax - } -} -#endif - - -/*------------------------------------------------- - mulu_32x32 - perform an unsigned 32 bit x - 32 bit multiply and return the full 64 bit - result --------------------------------------------------*/ - -#ifndef PTR64 -#define mulu_32x32 _mulu_32x32 -inline uint64_t _mulu_32x32(uint32_t a, uint32_t b) -{ - // in theory this should work, but it is untested - __asm - { - mov eax,a - mul b - // leave results in edx:eax - } -} -#endif - - -/*------------------------------------------------- - mul_32x32_hi - perform a signed 32 bit x 32 bit - multiply and return the upper 32 bits of the - result --------------------------------------------------*/ - -#ifndef PTR64 -#define mul_32x32_hi _mul_32x32_hi -inline int32_t _mul_32x32_hi(int32_t a, int32_t b) -{ - int32_t result; - - __asm - { - mov eax,a - imul b - mov result,edx - } - - return result; -} -#endif - - -/*------------------------------------------------- - mulu_32x32_hi - perform an unsigned 32 bit x - 32 bit multiply and return the upper 32 bits - of the result --------------------------------------------------*/ - -#ifndef PTR64 -#define mulu_32x32_hi _mulu_32x32_hi -inline uint32_t _mulu_32x32_hi(uint32_t a, uint32_t b) -{ - int32_t result; - - __asm - { - mov eax,a - mul b - mov result,edx - } - - return result; -} -#endif - - -/*------------------------------------------------- - mul_32x32_shift - perform a signed 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#ifndef PTR64 -#define mul_32x32_shift _mul_32x32_shift -static inline int32_t _mul_32x32_shift(int32_t a, int32_t b, uint8_t shift) -{ - int32_t result; - - __asm - { - mov eax,a - imul b - mov cl,shift - shrd eax,edx,cl - mov result,eax - } - - return result; -} -#endif - - -/*------------------------------------------------- - mulu_32x32_shift - perform an unsigned 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#ifndef PTR64 -#define mulu_32x32_shift _mulu_32x32_shift -inline uint32_t _mulu_32x32_shift(uint32_t a, uint32_t b, uint8_t shift) -{ - int32_t result; - - __asm - { - mov eax,a - mul b - mov cl,shift - shrd eax,edx,cl - mov result,eax - } - - return result; -} -#endif - - -/*------------------------------------------------- - div_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -#ifndef PTR64 -#define div_64x32 _div_64x32 -inline int32_t _div_64x32(int64_t a, int32_t b) -{ - int32_t result; - int32_t alow = a; - int32_t ahigh = a >> 32; - - __asm - { - mov eax,alow - mov edx,ahigh - idiv b - mov result,eax - } - - return result; -} -#endif - - -/*------------------------------------------------- - divu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -#ifndef PTR64 -#define divu_64x32 _divu_64x32 -inline uint32_t _divu_64x32(uint64_t a, uint32_t b) -{ - uint32_t result; - uint32_t alow = a; - uint32_t ahigh = a >> 32; - - __asm - { - mov eax,alow - mov edx,ahigh - div b - mov result,eax - } - - return result; -} -#endif - - -/*------------------------------------------------- - div_64x32_rem - perform a signed 64 bit x 32 - bit divide and return the 32 bit quotient and - 32 bit remainder --------------------------------------------------*/ - -#ifndef PTR64 -#define div_64x32_rem _div_64x32_rem -inline int32_t _div_64x32_rem(int64_t a, int32_t b, int32_t &remainder) -{ - int32_t result; - int32_t alow = a; - int32_t ahigh = a >> 32; - int32_t rem; - - __asm - { - mov eax,alow - mov edx,ahigh - idiv b - mov result,eax - mov rem,edx - } - - remainder = rem; - return result; -} -#endif - - -/*------------------------------------------------- - divu_64x32_rem - perform an unsigned 64 bit x - 32 bit divide and return the 32 bit quotient - and 32 bit remainder --------------------------------------------------*/ - -#ifndef PTR64 -#define divu_64x32_rem _divu_64x32_rem -inline uint32_t _divu_64x32_rem(uint64_t a, uint32_t b, uint32_t &remainder) -{ - uint32_t result; - uint32_t alow = a; - uint32_t ahigh = a >> 32; - uint32_t rem; - - __asm - { - mov eax,alow - mov edx,ahigh - div b - mov result,eax - mov rem,edx - } - - remainder = rem; - return result; -} -#endif - - -/*------------------------------------------------- - div_32x32_shift - perform a signed divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -#ifndef PTR64 -#define div_32x32_shift _div_32x32_shift -inline int32_t _div_32x32_shift(int32_t a, int32_t b, uint8_t shift) -{ - int32_t result; - - __asm - { - mov eax,a - cdq - mov cl,shift - shld edx,eax,cl - shl eax,cl - idiv b - mov result,eax - } - - return result; -} -#endif - - -/*------------------------------------------------- - divu_32x32_shift - perform an unsigned divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -#ifndef PTR64 -#define divu_32x32_shift _divu_32x32_shift -inline uint32_t _divu_32x32_shift(uint32_t a, uint32_t b, uint8_t shift) -{ - uint32_t result; - - __asm - { - mov eax,a - xor edx,edx - mov cl,shift - shld edx,eax,cl - shl eax,cl - div b - mov result,eax - } - - return result; -} -#endif - - -/*------------------------------------------------- - mod_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -#ifndef PTR64 -#define mod_64x32 _mod_64x32 -static inline int32_t _mod_64x32(int64_t a, int32_t b) -{ - int32_t result; - int32_t alow = a; - int32_t ahigh = a >> 32; - - __asm - { - mov eax,alow - mov edx,ahigh - idiv b - mov result,edx - } - - return result; -} -#endif - - -/*------------------------------------------------- - modu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -#ifndef PTR64 -#define modu_64x32 _modu_64x32 -inline uint32_t _modu_64x32(uint64_t a, uint32_t b) -{ - uint32_t result; - uint32_t alow = a; - uint32_t ahigh = a >> 32; - - __asm - { - mov eax,alow - mov edx,ahigh - div b - mov result,edx - } - - return result; -} -#endif - - -/*------------------------------------------------- - recip_approx - compute an approximate floating - point reciprocal --------------------------------------------------*/ - -#ifdef PTR64 -#define recip_approx _recip_approx -inline float _recip_approx(float z) -{ - __m128 const mz = _mm_set_ss(z); - __m128 const mooz = _mm_rcp_ss(mz); - float ooz; - _mm_store_ss(&ooz, mooz); - return ooz; -} -#endif - - -/*------------------------------------------------- - mul_64x64 - perform a signed 64 bit x 64 bit - multiply and return the full 128 bit result --------------------------------------------------*/ - -#ifdef PTR64 -#define mul_64x64 _mul_64x64 -__forceinline int64_t _mul_64x64(int64_t a, int64_t b, int64_t &hi) -{ - return _mul128(a, b, &hi); -} -#endif - - -/*------------------------------------------------- - mulu_64x64 - perform an unsigned 64 bit x 64 - bit multiply and return the full 128 bit result --------------------------------------------------*/ - -#ifdef PTR64 -#define mulu_64x64 _mulu_64x64 -__forceinline int64_t _mulu_64x64(uint64_t a, uint64_t b, uint64_t &hi) -{ - return _umul128(a, b, &hi); -} -#endif - - -/*------------------------------------------------- - addu_32x32_co - perform an unsigned 32 bit + 32 - bit addition and return the result with carry - out --------------------------------------------------*/ - -#define addu_32x32_co _addu_32x32_co -__forceinline bool _addu_32x32_co(uint32_t a, uint32_t b, uint32_t &sum) -{ - return _addcarry_u32(0, a, b, &sum); -} - - -/*------------------------------------------------- - addu_64x64_co - perform an unsigned 64 bit + 64 - bit addition and return the result with carry - out --------------------------------------------------*/ - -#define addu_64x64_co _addu_64x64_co -__forceinline bool _addu_64x64_co(uint64_t a, uint64_t b, uint64_t &sum) -{ -#ifdef PTR64 - return _addcarry_u64(0, a, b, &sum); -#else - uint32_t l, h; - bool const result = _addcarry_u32(_addcarry_u32(0, uint32_t(a), uint32_t(b), &l), uint32_t(a >> 32), uint32_t(b >> 32), &h); - sum = (uint64_t(h) << 32) | l; - return result; -#endif -} - -#endif // MAME_OSD_EIVCX86_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/eminline.h b/waterbox/ares64/ares/thirdparty/mame/osd/eminline.h deleted file mode 100644 index 02bd22b3fd..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/eminline.h +++ /dev/null @@ -1,495 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - eminline.h - - Definitions for inline functions that can be overridden by OSD- - specific code. - -***************************************************************************/ - -#ifndef MAME_OSD_EMINLINE_H -#define MAME_OSD_EMINLINE_H - -#pragma once - -#include "osdcomm.h" -#include "osdcore.h" - -#if !defined(MAME_NOASM) - -#if defined(__GNUC__) - -#if defined(__i386__) || defined(__x86_64__) -#include "eigccx86.h" -#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__) -#include "eigccppc.h" -#elif defined(__arm__) || defined(__aarch64__) -#include "eigccarm.h" -#endif - -#include "eigcc.h" - -#elif defined(_MSC_VER) - -#if defined(_M_IX86) || defined(_M_X64) -#include "eivcx86.h" -#elif defined(_M_ARM) || defined(_M_ARM64) -#include "eivcarm.h" -#endif - -#include "eivc.h" - -#endif - -#endif // !defined(MAME_NOASM) - - -/*************************************************************************** - INLINE MATH FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - mul_32x32 - perform a signed 32 bit x 32 bit - multiply and return the full 64 bit result --------------------------------------------------*/ - -#ifndef mul_32x32 -constexpr int64_t mul_32x32(int32_t a, int32_t b) -{ - return int64_t(a) * int64_t(b); -} -#endif - - -/*------------------------------------------------- - mulu_32x32 - perform an unsigned 32 bit x - 32 bit multiply and return the full 64 bit - result --------------------------------------------------*/ - -#ifndef mulu_32x32 -constexpr uint64_t mulu_32x32(uint32_t a, uint32_t b) -{ - return uint64_t(a) * uint64_t(b); -} -#endif - - -/*------------------------------------------------- - mul_32x32_hi - perform a signed 32 bit x 32 bit - multiply and return the upper 32 bits of the - result --------------------------------------------------*/ - -#ifndef mul_32x32_hi -constexpr int32_t mul_32x32_hi(int32_t a, int32_t b) -{ - return uint32_t((int64_t(a) * int64_t(b)) >> 32); -} -#endif - - -/*------------------------------------------------- - mulu_32x32_hi - perform an unsigned 32 bit x - 32 bit multiply and return the upper 32 bits - of the result --------------------------------------------------*/ - -#ifndef mulu_32x32_hi -constexpr uint32_t mulu_32x32_hi(uint32_t a, uint32_t b) -{ - return uint32_t((uint64_t(a) * uint64_t(b)) >> 32); -} -#endif - - -/*------------------------------------------------- - mul_32x32_shift - perform a signed 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#ifndef mul_32x32_shift -constexpr int32_t mul_32x32_shift(int32_t a, int32_t b, uint8_t shift) -{ - return int32_t((int64_t(a) * int64_t(b)) >> shift); -} -#endif - - -/*------------------------------------------------- - mulu_32x32_shift - perform an unsigned 32 bit x - 32 bit multiply and shift the result by the - given number of bits before truncating the - result to 32 bits --------------------------------------------------*/ - -#ifndef mulu_32x32_shift -constexpr uint32_t mulu_32x32_shift(uint32_t a, uint32_t b, uint8_t shift) -{ - return uint32_t((uint64_t(a) * uint64_t(b)) >> shift); -} -#endif - - -/*------------------------------------------------- - div_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -#ifndef div_64x32 -constexpr int32_t div_64x32(int64_t a, int32_t b) -{ - return a / int64_t(b); -} -#endif - - -/*------------------------------------------------- - divu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit quotient --------------------------------------------------*/ - -#ifndef divu_64x32 -constexpr uint32_t divu_64x32(uint64_t a, uint32_t b) -{ - return a / uint64_t(b); -} -#endif - - -/*------------------------------------------------- - div_64x32_rem - perform a signed 64 bit x 32 - bit divide and return the 32 bit quotient and - 32 bit remainder --------------------------------------------------*/ - -#ifndef div_64x32_rem -inline int32_t div_64x32_rem(int64_t a, int32_t b, int32_t &remainder) -{ - int32_t const res(div_64x32(a, b)); - remainder = a - (int64_t(b) * res); - return res; -} -#endif - - -/*------------------------------------------------- - divu_64x32_rem - perform an unsigned 64 bit x - 32 bit divide and return the 32 bit quotient - and 32 bit remainder --------------------------------------------------*/ - -#ifndef divu_64x32_rem -inline uint32_t divu_64x32_rem(uint64_t a, uint32_t b, uint32_t &remainder) -{ - uint32_t const res(divu_64x32(a, b)); - remainder = a - (uint64_t(b) * res); - return res; -} -#endif - - -/*------------------------------------------------- - div_32x32_shift - perform a signed divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -#ifndef div_32x32_shift -constexpr int32_t div_32x32_shift(int32_t a, int32_t b, uint8_t shift) -{ - return (int64_t(a) << shift) / int64_t(b); -} -#endif - - -/*------------------------------------------------- - divu_32x32_shift - perform an unsigned divide of - two 32 bit values, shifting the first before - division, and returning the 32 bit quotient --------------------------------------------------*/ - -#ifndef divu_32x32_shift -constexpr uint32_t divu_32x32_shift(uint32_t a, uint32_t b, uint8_t shift) -{ - return (uint64_t(a) << shift) / uint64_t(b); -} -#endif - - -/*------------------------------------------------- - mod_64x32 - perform a signed 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -#ifndef mod_64x32 -constexpr int32_t mod_64x32(int64_t a, int32_t b) -{ - return a - (b * div_64x32(a, b)); -} -#endif - - -/*------------------------------------------------- - modu_64x32 - perform an unsigned 64 bit x 32 bit - divide and return the 32 bit remainder --------------------------------------------------*/ - -#ifndef modu_64x32 -constexpr uint32_t modu_64x32(uint64_t a, uint32_t b) -{ - return a - (b * divu_64x32(a, b)); -} -#endif - - -/*------------------------------------------------- - recip_approx - compute an approximate floating - point reciprocal --------------------------------------------------*/ - -#ifndef recip_approx -constexpr float recip_approx(float value) -{ - return 1.0f / value; -} -#endif - - -/*------------------------------------------------- - mul_64x64 - perform a signed 64 bit x 64 bit - multiply and return the full 128 bit result --------------------------------------------------*/ - -#ifndef mul_64x64 -inline int64_t mul_64x64(int64_t a, int64_t b, int64_t &hi) -{ - uint64_t const a_hi = uint64_t(a) >> 32; - uint64_t const b_hi = uint64_t(b) >> 32; - uint64_t const a_lo = uint32_t(uint64_t(a)); - uint64_t const b_lo = uint32_t(uint64_t(b)); - - uint64_t const ab_lo = a_lo * b_lo; - uint64_t const ab_m1 = a_hi * b_lo; - uint64_t const ab_m2 = a_lo * b_hi; - uint64_t const ab_hi = a_hi * b_hi; - uint64_t const carry = ((ab_lo >> 32) + uint32_t(ab_m1) + uint32_t(ab_m2)) >> 32; - - hi = ab_hi + (ab_m1 >> 32) + (ab_m2 >> 32) + carry; - - // adjust for sign - if (a < 0) - hi -= b; - if (b < 0) - hi -= a; - - return ab_lo + (ab_m1 << 32) + (ab_m2 << 32); -} -#endif - - -/*------------------------------------------------- - mulu_64x64 - perform an unsigned 64 bit x 64 - bit multiply and return the full 128 bit result --------------------------------------------------*/ - -#ifndef mulu_64x64 -inline uint64_t mulu_64x64(uint64_t a, uint64_t b, uint64_t &hi) -{ - uint64_t const a_hi = uint32_t(a >> 32); - uint64_t const b_hi = uint32_t(b >> 32); - uint64_t const a_lo = uint32_t(a); - uint64_t const b_lo = uint32_t(b); - - uint64_t const ab_lo = a_lo * b_lo; - uint64_t const ab_m1 = a_hi * b_lo; - uint64_t const ab_m2 = a_lo * b_hi; - uint64_t const ab_hi = a_hi * b_hi; - uint64_t const carry = ((ab_lo >> 32) + uint32_t(ab_m1) + uint32_t(ab_m2)) >> 32; - - hi = ab_hi + (ab_m1 >> 32) + (ab_m2 >> 32) + carry; - - return ab_lo + (ab_m1 << 32) + (ab_m2 << 32); -} -#endif - - -/*------------------------------------------------- - addu_32x32_co - perform an unsigned 32 bit + 32 - bit addition and return the result with carry - out --------------------------------------------------*/ - -#ifndef addu_32x32_co -inline bool addu_32x32_co(uint32_t a, uint32_t b, uint32_t &sum) -{ - sum = a + b; - return (a > sum) || (b > sum); -} -#endif - - -/*------------------------------------------------- - addu_64x64_co - perform an unsigned 64 bit + 64 - bit addition and return the result with carry - out --------------------------------------------------*/ - -#ifndef addu_64x64_co -inline bool addu_64x64_co(uint64_t a, uint64_t b, uint64_t &sum) -{ - sum = a + b; - return (a > sum) || (b > sum); -} -#endif - - - -/*************************************************************************** - INLINE BIT MANIPULATION FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - count_leading_zeros_32 - return the number of - leading zero bits in a 32-bit value --------------------------------------------------*/ - -#ifndef count_leading_zeros_32 -inline uint8_t count_leading_zeros_32(uint32_t val) -{ - if (!val) return 32U; - uint8_t count; - for (count = 0; int32_t(val) >= 0; count++) val <<= 1; - return count; -} -#endif - - -/*------------------------------------------------- - count_leading_ones_32 - return the number of - leading one bits in a 32-bit value --------------------------------------------------*/ - -#ifndef count_leading_ones_32 -inline uint8_t count_leading_ones_32(uint32_t val) -{ - uint8_t count; - for (count = 0; int32_t(val) < 0; count++) val <<= 1; - return count; -} -#endif - - -/*------------------------------------------------- - count_leading_zeros_64 - return the number of - leading zero bits in a 64-bit value --------------------------------------------------*/ - -#ifndef count_leading_zeros_64 -inline uint8_t count_leading_zeros_64(uint64_t val) -{ - if (!val) return 64U; - uint8_t count; - for (count = 0; int64_t(val) >= 0; count++) val <<= 1; - return count; -} -#endif - - -/*------------------------------------------------- - count_leading_ones_64 - return the number of - leading one bits in a 64-bit value --------------------------------------------------*/ - -#ifndef count_leading_ones_64 -inline uint8_t count_leading_ones_64(uint64_t val) -{ - uint8_t count; - for (count = 0; int64_t(val) < 0; count++) val <<= 1; - return count; -} -#endif - - -/*------------------------------------------------- - population_count_32 - return the number of - one bits in a 32-bit value --------------------------------------------------*/ - -#ifndef population_count_32 -inline unsigned population_count_32(uint32_t val) -{ -#if defined(__NetBSD__) - return popcount32(val); -#else - // optimal Hamming weight assuming fast 32*32->32 - constexpr uint32_t m1(0x55555555); - constexpr uint32_t m2(0x33333333); - constexpr uint32_t m4(0x0f0f0f0f); - constexpr uint32_t h01(0x01010101); - val -= (val >> 1) & m1; - val = (val & m2) + ((val >> 2) & m2); - val = (val + (val >> 4)) & m4; - return unsigned((val * h01) >> 24); -#endif -} -#endif - - -/*------------------------------------------------- - population_count_64 - return the number of - one bits in a 64-bit value --------------------------------------------------*/ - -#ifndef population_count_64 -inline unsigned population_count_64(uint64_t val) -{ -#if defined(__NetBSD__) - return popcount64(val); -#else - // guess that architectures with 64-bit pointers have 64-bit multiplier - if (sizeof(void *) >= sizeof(uint64_t)) - { - // optimal Hamming weight assuming fast 64*64->64 - constexpr uint64_t m1(0x5555555555555555); - constexpr uint64_t m2(0x3333333333333333); - constexpr uint64_t m4(0x0f0f0f0f0f0f0f0f); - constexpr uint64_t h01(0x0101010101010101); - val -= (val >> 1) & m1; - val = (val & m2) + ((val >> 2) & m2); - val = (val + (val >> 4)) & m4; - return unsigned((val * h01) >> 56); - } - else - { - // fall back to two 32-bit operations to avoid slow multiply - return population_count_32(uint32_t(val)) + population_count_32(uint32_t(val >> 32)); - } -#endif -} -#endif - - -/*************************************************************************** - INLINE TIMING FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - get_profile_ticks - return a tick counter - from the processor that can be used for - profiling. It does not need to run at any - particular rate. --------------------------------------------------*/ - -#ifndef get_profile_ticks -inline int64_t get_profile_ticks() -{ - return osd_ticks(); -} -#endif - -#endif // MAME_OSD_EMINLINE_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/osdcomm.h b/waterbox/ares64/ares/thirdparty/mame/osd/osdcomm.h deleted file mode 100644 index 75370f1b81..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/osdcomm.h +++ /dev/null @@ -1,119 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - osdcomm.h - - Common definitions shared by the OSD layer. This includes the most - fundamental integral types as well as compiler-specific tweaks. - -***************************************************************************/ -#ifndef MAME_OSD_OSDCOMM_H -#define MAME_OSD_OSDCOMM_H - -#pragma once - -#include -#include -#include - -#include - - -/*************************************************************************** - COMPILER-SPECIFIC NASTINESS -***************************************************************************/ - -// The Win32 port requires this constant for variable arg routines. -#ifndef CLIB_DECL -#define CLIB_DECL -#endif - - -// Some optimizations/warnings cleanups for GCC -#if defined(__GNUC__) -#define ATTR_PRINTF(x,y) __attribute__((format(printf, x, y))) -#define ATTR_CONST __attribute__((const)) -#define ATTR_FORCE_INLINE __attribute__((always_inline)) -#define ATTR_HOT __attribute__((hot)) -#define ATTR_COLD __attribute__((cold)) -#define UNEXPECTED(exp) __builtin_expect(!!(exp), 0) -#define EXPECTED(exp) __builtin_expect(!!(exp), 1) -#define RESTRICT __restrict__ -#else -#define ATTR_PRINTF(x,y) -#define ATTR_CONST -#define ATTR_FORCE_INLINE __forceinline -#define ATTR_HOT -#define ATTR_COLD -#define UNEXPECTED(exp) (exp) -#define EXPECTED(exp) (exp) -#define RESTRICT -#endif - - - -/*************************************************************************** - FUNDAMENTAL TYPES -***************************************************************************/ - -namespace osd { - -using u8 = std::uint8_t; -using u16 = std::uint16_t; -using u32 = std::uint32_t; -using u64 = std::uint64_t; - -using s8 = std::int8_t; -using s16 = std::int16_t; -using s32 = std::int32_t; -using s64 = std::int64_t; - -} // namespace OSD - -/*************************************************************************** - FUNDAMENTAL MACROS -***************************************************************************/ - -// Concatenate/extract 32-bit halves of 64-bit values -constexpr uint64_t concat_64(uint32_t hi, uint32_t lo) { return (uint64_t(hi) << 32) | uint32_t(lo); } -constexpr uint32_t extract_64hi(uint64_t val) { return uint32_t(val >> 32); } -constexpr uint32_t extract_64lo(uint64_t val) { return uint32_t(val); } - -// Macros for normalizing data into big or little endian formats -constexpr uint16_t swapendian_int16(uint16_t val) { return (val << 8) | (val >> 8); } - -constexpr uint32_t swapendian_int32_partial16(uint32_t val) { return ((val << 8) & 0xFF00FF00U) | ((val >> 8) & 0x00FF00FFU); } -constexpr uint32_t swapendian_int32(uint32_t val) { return (swapendian_int32_partial16(val) << 16) | (swapendian_int32_partial16(val) >> 16); } - -constexpr uint64_t swapendian_int64_partial16(uint64_t val) { return ((val << 8) & 0xFF00FF00FF00FF00U) | ((val >> 8) & 0x00FF00FF00FF00FFU); } -constexpr uint64_t swapendian_int64_partial32(uint64_t val) { return ((swapendian_int64_partial16(val) << 16) & 0xFFFF0000FFFF0000U) | ((swapendian_int64_partial16(val) >> 16) & 0x0000FFFF0000FFFFU); } -constexpr uint64_t swapendian_int64(uint64_t val) { return (swapendian_int64_partial32(val) << 32) | (swapendian_int64_partial32(val) >> 32); } - -#ifdef LSB_FIRST -constexpr uint16_t big_endianize_int16(uint16_t x) { return swapendian_int16(x); } -constexpr uint32_t big_endianize_int32(uint32_t x) { return swapendian_int32(x); } -constexpr uint64_t big_endianize_int64(uint64_t x) { return swapendian_int64(x); } -constexpr uint16_t little_endianize_int16(uint16_t x) { return x; } -constexpr uint32_t little_endianize_int32(uint32_t x) { return x; } -constexpr uint64_t little_endianize_int64(uint64_t x) { return x; } -#else -constexpr uint16_t big_endianize_int16(uint16_t x) { return x; } -constexpr uint32_t big_endianize_int32(uint32_t x) { return x; } -constexpr uint64_t big_endianize_int64(uint64_t x) { return x; } -constexpr uint16_t little_endianize_int16(uint16_t x) { return swapendian_int16(x); } -constexpr uint32_t little_endianize_int32(uint32_t x) { return swapendian_int32(x); } -constexpr uint64_t little_endianize_int64(uint64_t x) { return swapendian_int64(x); } -#endif // LSB_FIRST - -#ifdef _MSC_VER -using ssize_t = std::make_signed_t; -#endif - -#ifdef __GNUC__ -#ifndef alloca -#define alloca(size) __builtin_alloca(size) -#endif -#endif - -#endif // MAME_OSD_OSDCOMM_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/osdcore.cpp b/waterbox/ares64/ares/thirdparty/mame/osd/osdcore.cpp deleted file mode 100644 index fc73218ff2..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/osdcore.cpp +++ /dev/null @@ -1,223 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles - -#include "osdcore.h" -#include -#include - -#if defined(SDLMAME_ANDROID) -#include -#endif - -#ifdef _WIN32 -#include -#include -#include -#if !defined(MAME_RDP) -#include "strconv.h" -#endif -#endif - -static const int MAXSTACK = 10; -static osd_output *m_stack[MAXSTACK]; -static int m_ptr = -1; - -/*------------------------------------------------- - osd_output --------------------------------------------------*/ - -void osd_output::push(osd_output *delegate) -{ - if (m_ptr < MAXSTACK - 1) - { - delegate->m_chain = (m_ptr >= 0 ? m_stack[m_ptr] : nullptr); - m_ptr++; - m_stack[m_ptr] = delegate; - } -} - -void osd_output::pop(osd_output *delegate) -{ - int f = -1; - for (int i = 0; i <= m_ptr; i++) - if (m_stack[i] == delegate) - { - f = i; - break; - } - if (f >= 0) - { - if (f < m_ptr) - m_stack[f+1]->m_chain = m_stack[f]->m_chain; - m_ptr--; - for (int i = f; i <= m_ptr; i++) - m_stack[i] = m_stack[i+1]; - } -} - - -/*************************************************************************** - OUTPUT MANAGEMENT -***************************************************************************/ - -/*------------------------------------------------- - osd_vprintf_error - output an error to the - appropriate callback --------------------------------------------------*/ - -void osd_vprintf_error(util::format_argument_pack const &args) -{ -#if defined(SDLMAME_ANDROID) - __android_log_write(ANDROID_LOG_ERROR, "%s", util::string_format(args).c_str()); -#else - if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_ERROR, args); -#endif -} - - -/*------------------------------------------------- - osd_vprintf_warning - output a warning to the - appropriate callback --------------------------------------------------*/ - -void osd_vprintf_warning(util::format_argument_pack const &args) -{ -#if defined(SDLMAME_ANDROID) - __android_log_write(ANDROID_LOG_WARN, "%s", util::string_format(args).c_str()); -#else - if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_WARNING, args); -#endif -} - - -/*------------------------------------------------- - osd_vprintf_info - output info text to the - appropriate callback --------------------------------------------------*/ - -void osd_vprintf_info(util::format_argument_pack const &args) -{ -#if defined(SDLMAME_ANDROID) - __android_log_write(ANDROID_LOG_INFO, "%s", util::string_format(args).c_str()); -#else - if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_INFO, args); -#endif -} - - -/*------------------------------------------------- - osd_vprintf_verbose - output verbose text to - the appropriate callback --------------------------------------------------*/ - -void osd_vprintf_verbose(util::format_argument_pack const &args) -{ -#if defined(SDLMAME_ANDROID) - __android_log_write( ANDROID_LOG_VERBOSE, "%s", util::string_format(args).c_str()); -#else - if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_VERBOSE, args); -#endif -} - - -/*------------------------------------------------- - osd_vprintf_debug - output debug text to the - appropriate callback --------------------------------------------------*/ - -void osd_vprintf_debug(util::format_argument_pack const &args) -{ -#if defined(SDLMAME_ANDROID) - __android_log_write(ANDROID_LOG_DEBUG, "%s", util::string_format(args).c_str()); -#else - if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_DEBUG, args); -#endif -} - - -//============================================================ -// osd_ticks -//============================================================ - -osd_ticks_t osd_ticks() -{ -#ifdef _WIN32 - LARGE_INTEGER val; - QueryPerformanceCounter(&val); - return val.QuadPart; -#else - return std::chrono::high_resolution_clock::now().time_since_epoch().count(); -#endif -} - - -//============================================================ -// osd_ticks_per_second -//============================================================ - -osd_ticks_t osd_ticks_per_second() -{ -#ifdef _WIN32 - LARGE_INTEGER val; - QueryPerformanceFrequency(&val); - return val.QuadPart; -#else - return std::chrono::high_resolution_clock::period::den / std::chrono::high_resolution_clock::period::num; -#endif -} - -//============================================================ -// osd_sleep -//============================================================ - -void osd_sleep(osd_ticks_t duration) -{ -#ifdef _WIN32 -// sleep_for appears to oversleep on Windows with gcc 8 - Sleep(duration / (osd_ticks_per_second() / 1000)); -#else - std::this_thread::sleep_for(std::chrono::high_resolution_clock::duration(duration)); -#endif -} - - -#if !defined(MAME_RDP) -//============================================================ -// osd_get_command_line - returns command line arguments -// in an std::vector in UTF-8 -// -// The real purpose of this call is to hide details necessary -// on Windows (provided that one wants to avoid using wmain) -//============================================================ - -std::vector osd_get_command_line(int argc, char *argv[]) -{ - std::vector results; -#ifdef _WIN32 - { - // Get the command line from Windows - int count; - LPWSTR *wide_args = CommandLineToArgvW(GetCommandLineW(), &count); - - // Convert the returned command line arguments to UTF8 std::vector - results.reserve(count); - for (int i = 0; i < count; i++) - { - std::string arg = osd::text::from_wstring(wide_args[i]); - results.push_back(std::move(arg)); - } - - LocalFree(wide_args); - } -#else // !_WIN32 - { - // for non Windows platforms, we are assuming that arguments are - // already UTF-8; we just need to convert to std::vector - results.reserve(argc); - for (int i = 0; i < argc; i++) - results.emplace_back(argv[i]); - } -#endif // _WIN32 - return results; -} -#endif diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/osdcore.h b/waterbox/ares64/ares/thirdparty/mame/osd/osdcore.h deleted file mode 100644 index a7f652470d..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/osdcore.h +++ /dev/null @@ -1,676 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/// \file -/// \brief Core OS-dependent code interface -/// -/// The prototypes in this file describe the interfaces that the MAME -/// core and various tools rely on to interact with the outside world. -/// They are broken out into several categories. -#ifndef MAME_OSD_OSDCORE_H -#define MAME_OSD_OSDCORE_H - -#pragma once - - -#include "osdcomm.h" - -#include "strformat.h" - -#include -#include -#include -#include -#include -#include - - -/// \brief Get environment variable value -/// -/// \param [in] name Name of the environment variable as a -/// NUL-terminated string. -/// \return Pointer to environment variable value as a NUL-terminated -/// string if found, or nullptr if not found. -const char *osd_getenv(const char *name); - - -/// \brief Get current process ID -/// -/// \return The process ID of the current process. -int osd_getpid(); - - -/*----------------------------------------------------------------------------- - osd_uchar_from_osdchar: convert the given character or sequence of - characters from the OS-default encoding to a Unicode character - - Parameters: - - uchar - pointer to a uint32_t to receive the resulting unicode - character - - osdchar - pointer to one or more chars that are in the OS-default - encoding - - count - number of characters provided in the OS-default encoding - - Return value: - - The number of characters required to form a Unicode character. ------------------------------------------------------------------------------*/ -int osd_uchar_from_osdchar(char32_t *uchar, const char *osdchar, size_t count); - - - -/*************************************************************************** - TIMING INTERFACES -***************************************************************************/ - -/* a osd_ticks_t is a 64-bit unsigned integer that is used as a core type in timing interfaces */ -typedef uint64_t osd_ticks_t; - - -/*----------------------------------------------------------------------------- - osd_ticks: return the current running tick counter - - Parameters: - - None - - Return value: - - an osd_ticks_t value which represents the current tick counter - - Notes: - - The resolution of this counter should be 1ms or better for accurate - performance. It is also important that the source of this timer be - accurate. It is ok if this call is not ultra-fast, since it is - primarily used for once/frame synchronization. ------------------------------------------------------------------------------*/ -osd_ticks_t osd_ticks(); - - -/*----------------------------------------------------------------------------- - osd_ticks_per_second: return the number of ticks per second - - Parameters: - - None - - Return value: - - an osd_ticks_t value which represents the number of ticks per - second ------------------------------------------------------------------------------*/ -osd_ticks_t osd_ticks_per_second(); - - -/*----------------------------------------------------------------------------- - osd_sleep: sleep for the specified time interval - - Parameters: - - duration - an osd_ticks_t value that specifies how long we should - sleep - - Return value: - - None - - Notes: - - The OSD layer should try to sleep for as close to the specified - duration as possible, or less. This is used as a mechanism to - "give back" unneeded time to other programs running in the system. - On a simple, non multitasking system, this routine can be a no-op. - If there is significant volatility in the amount of time that the - sleep occurs for, the OSD layer should strive to sleep for less time - than specified rather than sleeping too long. ------------------------------------------------------------------------------*/ -void osd_sleep(osd_ticks_t duration); - -/*************************************************************************** - WORK ITEM INTERFACES -***************************************************************************/ - -/* this is the maximum number of supported threads for a single work queue */ -/* threadid values are expected to range from 0..WORK_MAX_THREADS-1 */ -#define WORK_MAX_THREADS 16 - -/* these flags can be set when creating a queue to give hints to the code about - how to configure the queue */ -#define WORK_QUEUE_FLAG_IO 0x0001 -#define WORK_QUEUE_FLAG_MULTI 0x0002 -#define WORK_QUEUE_FLAG_HIGH_FREQ 0x0004 - -/* these flags can be set when queueing a work item to indicate how to handle - its deconstruction */ -#define WORK_ITEM_FLAG_AUTO_RELEASE 0x0001 - -/* osd_work_queue is an opaque type which represents a queue of work items */ -struct osd_work_queue; - -/* osd_work_item is an opaque type which represents a single work item */ -struct osd_work_item; - -/* osd_work_callback is a callback function that does work */ -typedef void *(*osd_work_callback)(void *param, int threadid); - - -/*----------------------------------------------------------------------------- - osd_work_queue_alloc: create a new work queue - - Parameters: - - flags - one or more of the WORK_QUEUE_FLAG_* values ORed together: - - WORK_QUEUE_FLAG_IO - indicates that the work queue will do some - I/O; this may be a useful hint so that threads are created - even on single-processor systems since I/O can often be - overlapped with other work - - WORK_QUEUE_FLAG_MULTI - indicates that the work queue should - take advantage of as many processors as it can; items queued - here are assumed to be fully independent or shared - - WORK_QUEUE_FLAG_HIGH_FREQ - indicates that items are expected - to be queued at high frequency and acted upon quickly; in - general, this implies doing some spin-waiting internally - before falling back to OS-specific synchronization - - Return value: - - A pointer to an allocated osd_work_queue object. - - Notes: - - A work queue abstracts the notion of how potentially threaded work - can be performed. If no threading support is available, it is a - simple matter to execute the work items as they are queued. ------------------------------------------------------------------------------*/ -osd_work_queue *osd_work_queue_alloc(int flags); - - -/*----------------------------------------------------------------------------- - osd_work_queue_items: return the number of pending items in the queue - - Parameters: - - queue - pointer to an osd_work_queue that was previously created via - osd_work_queue_alloc - - Return value: - - The number of incomplete items remaining in the queue. ------------------------------------------------------------------------------*/ -int osd_work_queue_items(osd_work_queue *queue); - - -/*----------------------------------------------------------------------------- - osd_work_queue_wait: wait for the queue to be empty - - Parameters: - - queue - pointer to an osd_work_queue that was previously created via - osd_work_queue_alloc - - timeout - a timeout value in osd_ticks_per_second() - - Return value: - - true if the queue is empty; false if the wait timed out before the - queue was emptied. ------------------------------------------------------------------------------*/ -bool osd_work_queue_wait(osd_work_queue *queue, osd_ticks_t timeout); - - -/*----------------------------------------------------------------------------- - osd_work_queue_free: free a work queue, waiting for all items to complete - - Parameters: - - queue - pointer to an osd_work_queue that was previously created via - osd_work_queue_alloc - - Return value: - - None. ------------------------------------------------------------------------------*/ -void osd_work_queue_free(osd_work_queue *queue); - - -/*----------------------------------------------------------------------------- - osd_work_item_queue_multiple: queue a set of work items - - Parameters: - - queue - pointer to an osd_work_queue that was previously created via - osd_work_queue_alloc - - callback - pointer to a function that will do the work - - numitems - number of work items to queue - - param - a void * parameter that can be used to pass data to the - function - - paramstep - the number of bytes to increment param by for each item - queued; for example, if you have an array of work_unit objects, - you can point param to the base of the array and set paramstep to - sizeof(work_unit) - - flags - one or more of the WORK_ITEM_FLAG_* values ORed together: - - WORK_ITEM_FLAG_AUTO_RELEASE - indicates that the work item - should be automatically freed when it is complete - - Return value: - - A pointer to the final allocated osd_work_item in the list. - - Notes: - - On single-threaded systems, this function may actually execute the - work item immediately before returning. ------------------------------------------------------------------------------*/ -osd_work_item *osd_work_item_queue_multiple(osd_work_queue *queue, osd_work_callback callback, int32_t numitems, void *parambase, int32_t paramstep, uint32_t flags); - - -/* inline helper to queue a single work item using the same interface */ -static inline osd_work_item *osd_work_item_queue(osd_work_queue *queue, osd_work_callback callback, void *param, uint32_t flags) -{ - return osd_work_item_queue_multiple(queue, callback, 1, param, 0, flags); -} - - -/*----------------------------------------------------------------------------- - osd_work_item_wait: wait for a work item to complete - - Parameters: - - item - pointer to an osd_work_item that was previously returned from - osd_work_item_queue - - timeout - a timeout value in osd_ticks_per_second() - - Return value: - - true if the item completed; false if the wait timed out before the - item completed. ------------------------------------------------------------------------------*/ -bool osd_work_item_wait(osd_work_item *item, osd_ticks_t timeout); - - -/*----------------------------------------------------------------------------- - osd_work_item_result: get the result of a work item - - Parameters: - - item - pointer to an osd_work_item that was previously returned from - osd_work_item_queue - - Return value: - - A void * that represents the work item's result. ------------------------------------------------------------------------------*/ -void *osd_work_item_result(osd_work_item *item); - - -/*----------------------------------------------------------------------------- - osd_work_item_release: release the memory allocated to a work item - - Parameters: - - item - pointer to an osd_work_item that was previously returned from - osd_work_item_queue - - Return value: - - None. - - Notes: - - The osd_work_item exists until explicitly released, even if it has - long since completed. It is the queuer's responsibility to release - any work items it has queued. ------------------------------------------------------------------------------*/ -void osd_work_item_release(osd_work_item *item); - - - -/*************************************************************************** - MISCELLANEOUS INTERFACES -***************************************************************************/ - -/// \brief Break into host debugger if attached -/// -/// This function is called when a fatal error occurs. If a debugger is -/// attached, it should break and display the specified message. -/// \param [in] message Message to output to the debugger as a -/// NUL-terminated string. -void osd_break_into_debugger(const char *message); - - -/// \brief Get clipboard text -/// -/// Gets current clipboard content as UTF-8 text. Returns an empty -/// string if the clipboard contents cannot be converted to plain text. -/// \return Clipboard contents or an empty string. -std::string osd_get_clipboard_text(); - - -/*************************************************************************** - MIDI I/O INTERFACES -***************************************************************************/ - -class osd_midi_device -{ -public: - virtual ~osd_midi_device() { } - // free result with osd_close_midi_channel() - virtual bool open_input(const char *devname) = 0; - // free result with osd_close_midi_channel() - virtual bool open_output(const char *devname) = 0; - virtual void close() = 0; - virtual bool poll() = 0; - virtual int read(uint8_t *pOut) = 0; - virtual void write(uint8_t data) = 0; -}; - -//FIXME: really needed here? -void osd_list_network_adapters(); - - -/*************************************************************************** - UNCATEGORIZED INTERFACES -***************************************************************************/ - -/*----------------------------------------------------------------------------- - osd_subst_env: substitute environment variables with values - - Parameters: - - dst - result pointer - src - source string - ------------------------------------------------------------------------------*/ -void osd_subst_env(std::string &dst, std::string const &src); - -class osd_gpu -{ -public: - osd_gpu() { } - virtual ~osd_gpu() { } - - typedef uint64_t handle_t; - - class vertex_decl - { - public: - enum attr_type : uint32_t - { - FLOAT32, - FLOAT16, - UINT32, - UINT16, - UINT8, - - MAX_TYPES - }; - - static constexpr size_t TYPE_SIZES[MAX_TYPES] = { 4, 2, 4, 2, 1 }; - - static constexpr uint32_t MAX_COLORS = 2; - static constexpr uint32_t MAX_TEXCOORDS = 8; - - enum attr_usage : uint32_t - { - POSITION, - COLOR, - TEXCOORD = COLOR + MAX_COLORS, - NORMAL = TEXCOORD + MAX_TEXCOORDS, - BINORMAL, - TANGENT, - - MAX_ATTRS - }; - - class attr_entry - { - public: - attr_entry() : m_usage(POSITION), m_type(FLOAT32), m_count(3), m_size(12) { } - attr_entry(attr_usage usage, attr_type type, size_t count) : m_usage(usage), m_type(type), m_count(count), m_size(TYPE_SIZES[type] * count) { } - - attr_usage usage() const { return m_usage; } - attr_type type() const { return m_type; } - size_t count() const { return m_count; } - size_t size() const { return m_size; } - - private: - attr_usage m_usage; - attr_type m_type; - size_t m_count; - size_t m_size; - }; - - vertex_decl() - : m_entry_count(0) - , m_size(0) - { - } - - vertex_decl & add_attr(attr_usage usage, attr_type type, size_t count) - { - m_entries[m_entry_count] = attr_entry(usage, type, count); - m_size += m_entries[m_entry_count].size(); - m_entry_count++; - return *this; - } - - size_t entry_count() const { return m_entry_count; } - size_t size() const { return m_size; } - const attr_entry &entry(const uint32_t index) const { return m_entries[index]; } - - protected: - attr_entry m_entries[MAX_ATTRS]; - size_t m_entry_count; - size_t m_size; - }; - - class vertex_buffer_interface - { - public: - vertex_buffer_interface(vertex_decl &decl, uint32_t flags) - : m_decl(decl) - , m_flags(flags) - { - } - virtual ~vertex_buffer_interface() {} - - const vertex_decl &decl() const { return m_decl; } - uint32_t flags() const { return m_flags; } - handle_t handle() { return m_handle; } - - virtual size_t count() const = 0; - virtual size_t size() const = 0; - virtual void upload() = 0; - - protected: - const vertex_decl &m_decl; - const uint32_t m_flags; - handle_t m_handle; - }; - - class static_vertex_buffer_interface : public vertex_buffer_interface - { - public: - enum vertex_buffer_flags : uint32_t - { - RETAIN_ON_CPU = 0x00000001 - }; - - static_vertex_buffer_interface(vertex_decl &decl, size_t count, uint32_t flags) - : vertex_buffer_interface(decl, flags) - , m_count(count) - , m_size(decl.size() * count) - { - } - - virtual ~static_vertex_buffer_interface() - { - if (m_data) - delete [] m_data; - } - - size_t count() const override { return m_count; } - size_t size() const override { return m_size; } - - void set_data(void *data) - { - allocate_if_needed(); - memcpy(m_data, data, m_size); - } - - protected: - void allocate_if_needed() - { - if ((m_flags & RETAIN_ON_CPU) != 0 && m_data == nullptr) - m_data = new uint8_t[m_size]; - } - - const size_t m_count; - const size_t m_size; - uint8_t *m_data; - }; - - virtual void bind_buffer(vertex_buffer_interface *vb) = 0; - virtual void unbind_buffer(vertex_buffer_interface *vb) = 0; -}; - - -/// \defgroup osd_printf Diagnostic output functions -/// \{ - -// output channels -enum osd_output_channel -{ - OSD_OUTPUT_CHANNEL_ERROR, - OSD_OUTPUT_CHANNEL_WARNING, - OSD_OUTPUT_CHANNEL_INFO, - OSD_OUTPUT_CHANNEL_DEBUG, - OSD_OUTPUT_CHANNEL_VERBOSE, - OSD_OUTPUT_CHANNEL_LOG, - OSD_OUTPUT_CHANNEL_COUNT -}; - -class osd_output -{ -public: - osd_output() { } - virtual ~osd_output() { } - - virtual void output_callback(osd_output_channel channel, util::format_argument_pack const &args) = 0; - - static void push(osd_output *delegate); - static void pop(osd_output *delegate); - -protected: - - void chain_output(osd_output_channel channel, util::format_argument_pack const &args) const - { - if (m_chain) - m_chain->output_callback(channel, args); - } - -private: - osd_output *m_chain = nullptr; -}; - -void osd_vprintf_error(util::format_argument_pack const &args); -void osd_vprintf_warning(util::format_argument_pack const &args); -void osd_vprintf_info(util::format_argument_pack const &args); -void osd_vprintf_verbose(util::format_argument_pack const &args); -void osd_vprintf_debug(util::format_argument_pack const &args); - -/// \brief Print error message -/// -/// By default, error messages are sent to standard error. The relaxed -/// format rules used by util::string_format apply. -/// \param [in] fmt Message format string. -/// \param [in] args Optional message format arguments. -/// \sa util::string_format -template void osd_printf_error(Format &&fmt, Params &&...args) -{ - return osd_vprintf_error(util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); -} - -/// \brief Print warning message -/// -/// By default, warning messages are sent to standard error. The -/// relaxed format rules used by util::string_format apply. -/// \param [in] fmt Message format string. -/// \param [in] args Optional message format arguments. -/// \sa util::string_format -template void osd_printf_warning(Format &&fmt, Params &&...args) -{ - return osd_vprintf_warning(util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); -} - -/// \brief Print informational message -/// -/// By default, informational messages are sent to standard output. -/// The relaxed format rules used by util::string_format apply. -/// \param [in] fmt Message format string. -/// \param [in] args Optional message format arguments. -/// \sa util::string_format -template void osd_printf_info(Format &&fmt, Params &&...args) -{ - return osd_vprintf_info(util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); -} - -/// \brief Print verbose diagnostic message -/// -/// Verbose diagnostic messages are disabled by default. If enabled, -/// they are sent to standard output by default. The relaxed format -/// rules used by util::string_format apply. Note that the format -/// string and arguments will always be evaluated, even if verbose -/// diagnostic messages are disabled. -/// \param [in] fmt Message format string. -/// \param [in] args Optional message format arguments. -/// \sa util::string_format -template void osd_printf_verbose(Format &&fmt, Params &&...args) -{ - return osd_vprintf_verbose(util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); -} - -/// \brief Print debug message -/// -/// By default, debug messages are sent to standard output for debug -/// builds only. The relaxed format rules used by util::string_format -/// apply. Note that the format string and arguments will always be -/// evaluated, even if debug messages are disabled. -/// \param [in] fmt Message format string. -/// \param [in] args Optional message format arguments. -/// \sa util::string_format -template void osd_printf_debug(Format &&fmt, Params &&...args) -{ - return osd_vprintf_debug(util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); -} - -/// \} - - -// returns command line arguments as an std::vector in UTF-8 -std::vector osd_get_command_line(int argc, char *argv[]); - -/* discourage the use of printf directly */ -/* sadly, can't do this because of the ATTR_PRINTF under GCC */ -/* -#undef printf -#define printf !MUST_USE_osd_printf_*_CALLS_WITHIN_THE_CORE! -*/ - -// specifies "aggressive focus" - should MAME capture input for any windows co-habiting a MAME window? -void osd_set_aggressive_input_focus(bool aggressive_focus); - -#endif // MAME_OSD_OSDCORE_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/osdfile.h b/waterbox/ares64/ares/thirdparty/mame/osd/osdfile.h deleted file mode 100644 index bc3efbde80..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/osdfile.h +++ /dev/null @@ -1,287 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/// \file -/// \brief Core OS-dependent file interface -/// -/// The prototypes in this file describe the interfaces that the MAME -/// core and various tools rely on to interact with the outside world. -/// They are broken out into several categories. - -#ifndef MAME_OSD_OSDFILE_H -#define MAME_OSD_OSDFILE_H - -#pragma once - -#include -#include -#include -#include -#include -#include - - -/*************************************************************************** - FILE I/O INTERFACES -***************************************************************************/ - -/* Make sure we have a path separator (default to /) */ -#ifndef PATH_SEPARATOR -#if defined(_WIN32) -#define PATH_SEPARATOR "\\" -#else -#define PATH_SEPARATOR "/" -#endif -#endif - -/// \defgroup openflags File open flags -/// \{ - -/// Open file for reading. -constexpr uint32_t OPEN_FLAG_READ = 0x0001; - -/// Open file for writing. -constexpr uint32_t OPEN_FLAG_WRITE = 0x0002; - -/// Create the file, or truncate it if it exists. -constexpr uint32_t OPEN_FLAG_CREATE = 0x0004; - -/// Create non-existent directories in the path. -constexpr uint32_t OPEN_FLAG_CREATE_PATHS = 0x0008; - -/// Do not decompress into memory on open. -constexpr uint32_t OPEN_FLAG_NO_PRELOAD = 0x0010; - -/// \} - - -/// \brief Interface to file-like resources -/// -/// This interface is used to access file-like and stream-like -/// resources. Examples include plain files, TCP socket, named pipes, -/// pseudo-terminals, and compressed archive members. -class osd_file -{ -public: - /// \brief Smart pointer to a file handle - typedef std::unique_ptr ptr; - - /// \brief Open a new file handle - /// - /// This function is called by core_fopen and several other places - /// in the core to access files. These functions will construct - /// paths by concatenating various search paths held in the - /// options.c options database with partial paths specified by the - /// core. The core assumes that the path separator is the first - /// character of the string PATH_SEPARATOR, but does not interpret - /// any path separators in the search paths, so if you use a - /// different path separator in a search path, you may get a mixture - /// of PATH_SEPARATORs (from the core) and alternate path separators - /// (specified by users and placed into the options database). - /// \param [in] path Path to the file to open. - /// \param [in] openflags Combination of #OPEN_FLAG_READ, - /// #OPEN_FLAG_WRITE, #OPEN_FLAG_CREATE and - /// #OPEN_FLAG_CREATE_PATHS specifying the requested access mode - /// and open behaviour. - /// \param [out] file Receives the file handle if the operation - /// succeeds. Not valid if the operation fails. - /// \param [out] filesize Receives the size of the opened file if - /// the operation succeeded. Not valid if the operation failed. - /// Will be zero for stream-like objects (e.g. TCP sockets or - /// named pipes). - /// \return Result of the operation. - static std::error_condition open(std::string const &path, std::uint32_t openflags, ptr &file, std::uint64_t &filesize) noexcept; - - /// \brief Create a new pseudo-terminal (PTY) pair - /// - /// \param [out] file Receives the handle of the master side of the - /// pseudo-terminal if the operation succeeds. Not valid if the - /// operation fails. - /// \param [out] name Receives the name of the slave side of the - /// pseudo-terminal if the operation succeeds. Not valid if the - /// operation fails. - /// \return Result of the operation. - static std::error_condition openpty(ptr &file, std::string &name) noexcept; - - /// \brief Close an open file - virtual ~osd_file() { } - - /// \brief Read from an open file - /// - /// Read data from an open file at specified offset. Note that the - /// seek and read are not guaranteed to be atomic, which may cause - /// issues in multi-threaded applications. - /// \param [out] buffer Pointer to memory that will receive the data - /// read. - /// \param [in] offset Byte offset within the file to read at, - /// relative to the start of the file. Ignored for stream-like - /// objects (e.g. TCP sockets or named pipes). - /// \param [in] length Number of bytes to read. Fewer bytes may be - /// read if the end of file is reached, or if no data is - /// available. - /// \param [out] actual Receives the number of bytes read if the - /// operation succeeds. Not valid if the operation fails. - /// \return Result of the operation. - virtual std::error_condition read(void *buffer, std::uint64_t offset, std::uint32_t length, std::uint32_t &actual) noexcept = 0; - - /// \brief Write to an open file - /// - /// Write data to an open file at specified offset. Note that the - /// seek and write are not guaranteed to be atomic, which may cause - /// issues in multi-threaded applications. - /// \param [in] buffer Pointer to memory containing data to write. - /// \param [in] offset Byte offset within the file to write at, - /// relative to the start of the file. Ignored for stream-like - /// objects (e.g. TCP sockets or named pipes). - /// \param [in] length Number of bytes to write. - /// \param [out] actual Receives the number of bytes written if the - /// operation succeeds. Not valid if the operation fails. - /// \return Result of the operation. - virtual std::error_condition write(void const *buffer, std::uint64_t offset, std::uint32_t length, std::uint32_t &actual) noexcept = 0; - - /// \brief Change the size of an open file - /// - /// \param [in] offset Desired size of the file. - /// \return Result of the operation. - virtual std::error_condition truncate(std::uint64_t offset) noexcept = 0; - - /// \brief Flush file buffers - /// - /// This flushes any data cached by the application, but does not - /// guarantee that all prior writes have reached persistent storage. - /// \return Result of the operation. - virtual std::error_condition flush() noexcept = 0; - - /// \brief Delete a file - /// - /// \param [in] filename Path to the file to delete. - /// \return Result of the operation. - static std::error_condition remove(std::string const &filename) noexcept; -}; - - -/// \brief Describe geometry of physical drive -/// -/// If the given path points to a physical drive, return the geometry of -/// that drive. -/// -/// \param [in] filename Pointer to a path which might describe a -/// physical drive. -/// \param [out] cylinders Pointer to a uint32_t to receive the number of -/// cylinders of the physical drive. -/// \param [out] heads Pointer to a uint32_t to receive the number of -/// heads per cylinder of the physical drive. -/// \param [out] sectors Pointer to a uint32_t to receive the number of -/// sectors per cylinder of the physical drive. -/// \param [out] bps Pointer to a uint32_t to receive the number of -/// bytes per sector of the physical drive. -/// \return true if the filename points to a physical drive and if the -/// values pointed to by cylinders, heads, sectors, and bps are valid; -/// false in any other case -bool osd_get_physical_drive_geometry(const char *filename, uint32_t *cylinders, uint32_t *heads, uint32_t *sectors, uint32_t *bps) noexcept; - - -/// \brief Is the given character legal for filenames? -/// -/// \param [in] uchar The character to check. -/// \return Whether this character is legal in a filename. -bool osd_is_valid_filename_char(char32_t uchar) noexcept; - - -/// \brief Is the given character legal for paths? -/// -/// \param [in] uchar The character to check. -/// \return Whether this character is legal in a file path. -bool osd_is_valid_filepath_char(char32_t uchar) noexcept; - - -/*************************************************************************** - DIRECTORY INTERFACES -***************************************************************************/ - -namespace osd -{ - // directory is an opaque type which represents an open directory - class directory - { - public: - typedef std::unique_ptr ptr; - - // osd::directory::entry contains basic information about a file when iterating through - // a directory - class entry - { - public: - enum class entry_type - { - NONE, - FILE, - DIR, - OTHER - }; - - const char * name; // name of the entry - entry_type type; // type of the entry - std::uint64_t size; // size of the entry - std::chrono::system_clock::time_point last_modified; // last modified time - }; - - /// \brief Open a directory for iteration. - /// - /// \param [in] dirname Path to the directory in question. - /// \return Upon success, a directory pointer which contains opaque - /// data necessary to traverse the directory; on failure, nullptr. - static ptr open(std::string const &dirname); - - /// \brief Close an open directory. - virtual ~directory() { } - - /// \brief Return information about the next entry in the directory. - /// - /// \return A constant pointer to an entry representing the current - /// item in the directory, or nullptr, indicating that no more - /// entries are present. - virtual const entry *read() = 0; - }; -}; - - -/// \brief Return a directory entry for a path. -/// -/// \param [in] path The path in question. -/// \return An allocated pointer to an osd::directory::entry representing -/// info on the path; even if the file does not exist. -std::unique_ptr osd_stat(std::string const &path); - - -/*************************************************************************** - PATH INTERFACES -***************************************************************************/ - -/// \brief Returns whether the specified path is absolute. -/// -/// \param [in] path The path in question. -/// \return true if the path is absolute, false otherwise. -bool osd_is_absolute_path(const std::string &path) noexcept; - - -/// \brief Retrieves the full path. -/// \param [in] path The path in question. -/// \param [out] dst Reference to receive new path. -/// \return File error. -std::error_condition osd_get_full_path(std::string &dst, std::string const &path) noexcept; - - -/// \brief Retrieves the volume name. -/// -/// \param [in] idx Index number of volume. -/// \return Volume name or empty string of out of range. -std::string osd_get_volume_name(int idx); - - -/// \brief Retrieves volume names. -/// -/// \return Names of all mounted volumes. -std::vector osd_get_volume_names(); - - -#endif // MAME_OSD_OSDFILE_H diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/osdsync.cpp b/waterbox/ares64/ares/thirdparty/mame/osd/osdsync.cpp deleted file mode 100644 index a81e6b06a1..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/osdsync.cpp +++ /dev/null @@ -1,823 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -//============================================================ -// -// osdsync.c - OSD core work item functions -// -//============================================================ -#if defined(OSD_WINDOWS) || defined(SDLMAME_WIN32) -// standard windows headers -#include -#include -#include -#include - -#ifdef __GNUC__ -#include -#endif -#endif -#include -#include -#include -#include -#include -// MAME headers -#include "osdcore.h" -#include "osdsync.h" - -#include "eminline.h" - -#if defined(SDLMAME_LINUX) || defined(SDLMAME_BSD) || defined(SDLMAME_HAIKU) || defined(SDLMAME_EMSCRIPTEN) || defined(SDLMAME_MACOSX) -#include -#endif - -#if defined(MAME_RDP) -#define osd_getenv getenv -#endif - -//============================================================ -// DEBUGGING -//============================================================ - -#define KEEP_STATISTICS (0) - -//============================================================ -// PARAMETERS -//============================================================ - -#define ENV_PROCESSORS "OSDPROCESSORS" -#define ENV_WORKQUEUEMAXTHREADS "OSDWORKQUEUEMAXTHREADS" - -#define SPIN_LOOP_TIME (osd_ticks_per_second() / 10000) - -//============================================================ -// MACROS -//============================================================ - -#if KEEP_STATISTICS -#define add_to_stat(v,x) do { (v) += (x); } while (0) -#define begin_timing(v) do { (v) -= get_profile_ticks(); } while (0) -#define end_timing(v) do { (v) += get_profile_ticks(); } while (0) -#else -#define add_to_stat(v,x) do { } while (0) -#define begin_timing(v) do { } while (0) -#define end_timing(v) do { } while (0) -#endif - -template -static void spin_while(const volatile _AtomType * volatile atom, const _MainType val, const osd_ticks_t timeout, const int invert = 0) -{ - osd_ticks_t stopspin = osd_ticks() + timeout; - - do { - int spin = 10000; - while (--spin) - { - if ((*atom != val) ^ invert) - return; - } - } while (((*atom == val) ^ invert) && osd_ticks() < stopspin); -} - -template -static void spin_while_not(const volatile _AtomType * volatile atom, const _MainType val, const osd_ticks_t timeout) -{ - spin_while<_AtomType, _MainType>(atom, val, timeout, 1); -} - -//============================================================ -// osd_num_processors -//============================================================ - -int osd_get_num_processors() -{ -#if defined(SDLMAME_EMSCRIPTEN) - // multithreading is not supported at this time - return 1; -#else - // max out at 4 for now since scaling above that seems to do poorly - return std::min(std::thread::hardware_concurrency(), 4U); -#endif -} - -//============================================================ -// TYPE DEFINITIONS -//============================================================ - -struct work_thread_info -{ - work_thread_info(uint32_t aid, osd_work_queue &aqueue) - : queue(aqueue) - , handle(nullptr) - , wakeevent(false, false) // auto-reset, not signalled - , active(0) - , id(aid) -#if KEEP_STATISTICS - , itemsdone(0) - , actruntime(0) - , runtime(0) - , spintime(0) - , waittime(0) -#endif - { - } - osd_work_queue & queue; // pointer back to the queue - std::thread * handle; // handle to the thread - osd_event wakeevent; // wake event for the thread - std::atomic active; // are we actively processing work? - uint32_t id; - -#if KEEP_STATISTICS - int32_t itemsdone; - osd_ticks_t actruntime; - osd_ticks_t runtime; - osd_ticks_t spintime; - osd_ticks_t waittime; -#endif -}; - - -struct osd_work_queue -{ - osd_work_queue() - : list(nullptr) - , tailptr(nullptr) - , free(nullptr) - , items(0) - , livethreads(0) - , waiting(0) - , exiting(0) - , threads(0) - , flags(0) - , doneevent(true, true) // manual reset, signalled -#if KEEP_STATISTICS - , itemsqueued(0) - , setevents(0) - , extraitems(0) - , spinloops(0) -#endif - { - } - - std::mutex lock; // lock for protecting the queue - std::atomic list; // list of items in the queue - osd_work_item ** volatile tailptr; // pointer to the tail pointer of work items in the queue - std::atomic free; // free list of work items - std::atomic items; // items in the queue - std::atomic livethreads; // number of live threads - std::atomic waiting; // is someone waiting on the queue to complete? - std::atomic exiting; // should the threads exit on their next opportunity? - uint32_t threads; // number of threads in this queue - uint32_t flags; // creation flags - std::vector thread; // array of thread information - osd_event doneevent; // event signalled when work is complete - -#if KEEP_STATISTICS - std::atomic itemsqueued; // total items queued - std::atomic setevents; // number of times we called SetEvent - std::atomic extraitems; // how many extra items we got after the first in the queue loop - std::atomic spinloops; // how many times spinning bought us more items -#endif -}; - - -struct osd_work_item -{ - osd_work_item(osd_work_queue &aqueue) - : next(nullptr) - , queue(aqueue) - , callback(nullptr) - , param(nullptr) - , result(nullptr) - , event(nullptr) // manual reset, not signalled - , flags(0) - , done(false) - { - } - - osd_work_item * next; // pointer to next item - osd_work_queue & queue; // pointer back to the owning queue - osd_work_callback callback; // callback function - void * param; // callback parameter - void * result; // callback result - osd_event * event; // event signalled when complete - uint32_t flags; // creation flags - std::atomic done; // is the item done? -}; - -//============================================================ -// GLOBAL VARIABLES -//============================================================ - -int osd_num_processors = 0; - -//============================================================ -// FUNCTION PROTOTYPES -//============================================================ - -static int effective_num_processors(); -static void * worker_thread_entry(void *param); -static void worker_thread_process(osd_work_queue *queue, work_thread_info *thread); -static bool queue_has_list_items(osd_work_queue *queue); - -//============================================================ -// osd_thread_adjust_priority -//============================================================ - -int thread_adjust_priority(std::thread *thread, int adjust) -{ -#if defined(OSD_WINDOWS) || defined(SDLMAME_WIN32) - if (adjust) - SetThreadPriority((HANDLE)thread->native_handle(), THREAD_PRIORITY_ABOVE_NORMAL); - else - SetThreadPriority((HANDLE)thread->native_handle(), GetThreadPriority(GetCurrentThread())); -#endif -#if defined(SDLMAME_LINUX) || defined(SDLMAME_BSD) || defined(SDLMAME_HAIKU) || defined(SDLMAME_DARWIN) - struct sched_param sched; - int policy; - - if (pthread_getschedparam(thread->native_handle(), &policy, &sched) == 0) - { - sched.sched_priority += adjust; - if (pthread_setschedparam(thread->native_handle(), policy, &sched) == 0) - return true; - else - return false; - } -#endif - return true; -} - -//============================================================ -// osd_work_queue_alloc -//============================================================ - -osd_work_queue *osd_work_queue_alloc(int flags) -{ - int threadnum; - int numprocs = effective_num_processors(); - osd_work_queue *queue; - int osdthreadnum = 0; - int allocthreadnum; - const char *osdworkqueuemaxthreads = osd_getenv(ENV_WORKQUEUEMAXTHREADS); - - // allocate a new queue - queue = new osd_work_queue(); - - // initialize basic queue members - queue->tailptr = (osd_work_item **)&queue->list; - queue->flags = flags; - - // determine how many threads to create... - // on a single-CPU system, create 1 thread for I/O queues, and 0 threads for everything else - if (numprocs == 1) - threadnum = (flags & WORK_QUEUE_FLAG_IO) ? 1 : 0; - // on an n-CPU system, create n-1 threads for multi queues, and 1 thread for everything else - else - threadnum = (flags & WORK_QUEUE_FLAG_MULTI) ? (numprocs - 1) : 1; - - if (osdworkqueuemaxthreads != nullptr && sscanf(osdworkqueuemaxthreads, "%d", &osdthreadnum) == 1 && threadnum > osdthreadnum) - threadnum = osdthreadnum; - -#if defined(SDLMAME_EMSCRIPTEN) - // threads are not supported at all - threadnum = 0; -#endif - - // clamp to the maximum - queue->threads = std::min(threadnum, WORK_MAX_THREADS); - - // allocate memory for thread array (+1 to count the calling thread if WORK_QUEUE_FLAG_MULTI) - if (flags & WORK_QUEUE_FLAG_MULTI) - allocthreadnum = queue->threads + 1; - else - allocthreadnum = queue->threads; - -#if KEEP_STATISTICS - printf("osdprocs: %d effecprocs: %d threads: %d allocthreads: %d osdthreads: %d maxthreads: %d queuethreads: %d\n", osd_num_processors, numprocs, threadnum, allocthreadnum, osdthreadnum, WORK_MAX_THREADS, queue->threads); -#endif - - for (threadnum = 0; threadnum < allocthreadnum; threadnum++) - queue->thread.push_back(new work_thread_info(threadnum, *queue)); - - // iterate over threads - for (threadnum = 0; threadnum < queue->threads; threadnum++) - { - work_thread_info *thread = queue->thread[threadnum]; - - // create the thread - thread->handle = new std::thread(worker_thread_entry, thread); - if (thread->handle == nullptr) - goto error; - - // set its priority: I/O threads get high priority because they are assumed to be - // blocked most of the time; other threads just match the creator's priority - if (flags & WORK_QUEUE_FLAG_IO) - thread_adjust_priority(thread->handle, 1); - else - thread_adjust_priority(thread->handle, 0); - } - - // start a timer going for "waittime" on the main thread - if (flags & WORK_QUEUE_FLAG_MULTI) - { - begin_timing(queue->thread[queue->threads]->waittime); - } - return queue; - -error: - osd_work_queue_free(queue); - return nullptr; -} - - -//============================================================ -// osd_work_queue_items -//============================================================ - -int osd_work_queue_items(osd_work_queue *queue) -{ - // return the number of items currently in the queue - return queue->items; -} - - -//============================================================ -// osd_work_queue_wait -//============================================================ - -bool osd_work_queue_wait(osd_work_queue *queue, osd_ticks_t timeout) -{ - // if no threads, no waiting - if (queue->threads == 0) - return true; - - // if no items, we're done - if (queue->items == 0) - return true; - - // if this is a multi queue, help out rather than doing nothing - if (queue->flags & WORK_QUEUE_FLAG_MULTI) - { - work_thread_info *thread = queue->thread[queue->threads]; - - end_timing(thread->waittime); - - // process what we can as a worker thread - worker_thread_process(queue, thread); - - // if we're a high frequency queue, spin until done - if (queue->flags & WORK_QUEUE_FLAG_HIGH_FREQ && queue->items != 0) - { - // spin until we're done - begin_timing(thread->spintime); - spin_while_not,int>(&queue->items, 0, timeout); - end_timing(thread->spintime); - - begin_timing(thread->waittime); - return (queue->items == 0); - } - begin_timing(thread->waittime); - } - - // reset our done event and double-check the items before waiting - queue->doneevent.reset(); - queue->waiting = true; - if (queue->items != 0) - queue->doneevent.wait(timeout); - queue->waiting = false; - - // return true if we actually hit 0 - return (queue->items == 0); -} - - -//============================================================ -// osd_work_queue_free -//============================================================ - -void osd_work_queue_free(osd_work_queue *queue) -{ - // stop the timer for "waittime" on the main thread - if (queue->flags & WORK_QUEUE_FLAG_MULTI) - { - end_timing(queue->thread[queue->threads]->waittime); - } - - // signal all the threads to exit - queue->exiting = true; - for (int threadnum = 0; threadnum < queue->threads; threadnum++) - { - work_thread_info *thread = queue->thread[threadnum]; - thread->wakeevent.set(); - } - - // wait for all the threads to go away - for (int threadnum = 0; threadnum < queue->threads; threadnum++) - { - work_thread_info *thread = queue->thread[threadnum]; - - // block on the thread going away, then close the handle - if (thread->handle != nullptr) - { - thread->handle->join(); - delete thread->handle; - } - - } - -#if KEEP_STATISTICS - // output per-thread statistics - for (work_thread_info *thread : queue->thread) - { - osd_ticks_t total = thread->runtime + thread->waittime + thread->spintime; - printf("Thread %d: items=%9d run=%5.2f%% (%5.2f%%) spin=%5.2f%% wait/other=%5.2f%% total=%9d\n", - thread->id, thread->itemsdone, - (double)thread->runtime * 100.0 / (double)total, - (double)thread->actruntime * 100.0 / (double)total, - (double)thread->spintime * 100.0 / (double)total, - (double)thread->waittime * 100.0 / (double)total, - (uint32_t) total); - } -#endif - - // free the list - for (auto & th : queue->thread) - delete th; - queue->thread.clear(); - - // free all items in the free list - while (queue->free.load() != nullptr) - { - auto *item = (osd_work_item *)queue->free; - queue->free = item->next; - delete item->event; - delete item; - } - - // free all items in the active list - while (queue->list.load() != nullptr) - { - auto *item = (osd_work_item *)queue->list; - queue->list = item->next; - delete item->event; - delete item; - } - -#if KEEP_STATISTICS - printf("Items queued = %9d\n", queue->itemsqueued.load()); - printf("SetEvent calls = %9d\n", queue->setevents.load()); - printf("Extra items = %9d\n", queue->extraitems.load()); - printf("Spin loops = %9d\n", queue->spinloops.load()); -#endif - - // free the queue itself - delete queue; -} - - -//============================================================ -// osd_work_item_queue_multiple -//============================================================ - -osd_work_item *osd_work_item_queue_multiple(osd_work_queue *queue, osd_work_callback callback, int32_t numitems, void *parambase, int32_t paramstep, uint32_t flags) -{ - osd_work_item *itemlist = nullptr, *lastitem = nullptr; - osd_work_item **item_tailptr = &itemlist; - int itemnum; - - // loop over items, building up a local list of work - for (itemnum = 0; itemnum < numitems; itemnum++) - { - osd_work_item *item; - - // first allocate a new work item; try the free list first - { - std::lock_guard lock(queue->lock); - do - { - item = (osd_work_item *)queue->free; - } while (item != nullptr && !queue->free.compare_exchange_weak(item, item->next, std::memory_order_release, std::memory_order_relaxed)); - } - - // if nothing, allocate something new - if (item == nullptr) - { - // allocate the item - item = new osd_work_item(*queue); - if (item == nullptr) - return nullptr; - } - else - { - item->done = false; // needs to be set this way to prevent data race/usage of uninitialized memory on Linux - } - - // fill in the basics - item->next = nullptr; - item->callback = callback; - item->param = parambase; - item->result = nullptr; - item->flags = flags; - - // advance to the next - lastitem = item; - *item_tailptr = item; - item_tailptr = &item->next; - parambase = (uint8_t *)parambase + paramstep; - } - - // enqueue the whole thing within the critical section - { - std::lock_guard lock(queue->lock); - *queue->tailptr = itemlist; - queue->tailptr = item_tailptr; - } - - // increment the number of items in the queue - queue->items += numitems; - add_to_stat(queue->itemsqueued, numitems); - - // look for free threads to do the work - if (queue->livethreads < queue->threads) - { - int threadnum; - - // iterate over all the threads - for (threadnum = 0; threadnum < queue->threads; threadnum++) - { - work_thread_info *thread = queue->thread[threadnum]; - - // if this thread is not active, wake him up - if (!thread->active) - { - thread->wakeevent.set(); - add_to_stat(queue->setevents, 1); - - // for non-shared, the first one we find is good enough - if (--numitems == 0) - break; - } - } - } - - // if no threads, run the queue now on this thread - if (queue->threads == 0) - { - end_timing(queue->thread[0]->waittime); - worker_thread_process(queue, queue->thread[0]); - begin_timing(queue->thread[0]->waittime); - } - // only return the item if it won't get released automatically - return (flags & WORK_ITEM_FLAG_AUTO_RELEASE) ? nullptr : lastitem; -} - - -//============================================================ -// osd_work_item_wait -//============================================================ - -bool osd_work_item_wait(osd_work_item *item, osd_ticks_t timeout) -{ - // if we're done already, just return - if (item->done) - return true; - - // if we don't have an event, create one - if (item->event == nullptr) - { - std::lock_guard lock(item->queue.lock); - item->event = new osd_event(true, false); // manual reset, not signalled - } - else - item->event->reset(); - - // if we don't have an event, we need to spin (shouldn't ever really happen) - if (item->event == nullptr) - { - // TODO: do we need to measure the spin time here as well? and how can we do it? - spin_while,int>(&item->done, 0, timeout); - } - - // otherwise, block on the event until done - else if (!item->done) - item->event->wait(timeout); - - // return true if the refcount actually hit 0 - return item->done; -} - - -//============================================================ -// osd_work_item_result -//============================================================ - -void *osd_work_item_result(osd_work_item *item) -{ - return item->result; -} - - -//============================================================ -// osd_work_item_release -//============================================================ - -void osd_work_item_release(osd_work_item *item) -{ - osd_work_item *next; - - // make sure we're done first - osd_work_item_wait(item, 100 * osd_ticks_per_second()); - - // add us to the free list on our queue - std::lock_guard lock(item->queue.lock); - do - { - next = (osd_work_item *) item->queue.free; - item->next = next; - } while (!item->queue.free.compare_exchange_weak(next, item, std::memory_order_release, std::memory_order_relaxed)); -} - - -//============================================================ -// effective_num_processors -//============================================================ - -static int effective_num_processors() -{ - int physprocs = osd_get_num_processors(); - - // osd_num_processors == 0 for 'auto' - if (osd_num_processors > 0) - { - return std::min(4 * physprocs, osd_num_processors); - } - else - { - int numprocs = 0; - - // if the OSDPROCESSORS environment variable is set, use that value if valid - // note that we permit more than the real number of processors for testing - const char *procsoverride = osd_getenv(ENV_PROCESSORS); - if (procsoverride != nullptr && sscanf(procsoverride, "%d", &numprocs) == 1 && numprocs > 0) - return std::min(4 * physprocs, numprocs); - - // otherwise, return the info from the system - return physprocs; - } -} - - -//============================================================ -// worker_thread_entry -//============================================================ - -static void *worker_thread_entry(void *param) -{ - auto *thread = (work_thread_info *)param; - osd_work_queue &queue = thread->queue; - - // loop until we exit - for ( ;; ) - { - // block waiting for work or exit - // bail on exit, and only wait if there are no pending items in queue - if (queue.exiting) - break; - - if (!queue_has_list_items(&queue)) - { - begin_timing(thread->waittime); - thread->wakeevent.wait( OSD_EVENT_WAIT_INFINITE); - end_timing(thread->waittime); - } - - if (queue.exiting) - break; - - // indicate that we are live - thread->active = true; - ++queue.livethreads; - - // process work items - for ( ;; ) - { - // process as much as we can - worker_thread_process(&queue, thread); - - // if we're a high frequency queue, spin for a while before giving up - if (queue.flags & WORK_QUEUE_FLAG_HIGH_FREQ && queue.list.load() == nullptr) - { - // spin for a while looking for more work - begin_timing(thread->spintime); - spin_while, osd_work_item *>(&queue.list, (osd_work_item *)nullptr, SPIN_LOOP_TIME); - end_timing(thread->spintime); - } - - // if nothing more, release the processor - if (!queue_has_list_items(&queue)) - break; - add_to_stat(queue.spinloops, 1); - } - - // decrement the live thread count - thread->active = false; - --queue.livethreads; - } - - return nullptr; -} - - -//============================================================ -// worker_thread_process -//============================================================ - -static void worker_thread_process(osd_work_queue *queue, work_thread_info *thread) -{ - int threadid = thread->id; - - begin_timing(thread->runtime); - - // loop until everything is processed - while (true) - { - osd_work_item *item = nullptr; - - bool end_loop = false; - - // use a critical section to synchronize the removal of items - { - std::lock_guard lock(queue->lock); - - if (queue->list.load() == nullptr) - { - end_loop = true; - } - else - { - // pull the item from the queue - item = (osd_work_item *)queue->list; - if (item != nullptr) - { - queue->list = item->next; - if (queue->list.load() == nullptr) - queue->tailptr = (osd_work_item **)&queue->list; - } - } - } - - if (end_loop) - break; - - // process non-NULL items - if (item != nullptr) - { - // call the callback and stash the result - begin_timing(thread->actruntime); - item->result = (*item->callback)(item->param, threadid); - end_timing(thread->actruntime); - - // decrement the item count after we are done - --queue->items; - item->done = true; - add_to_stat(thread->itemsdone, 1); - - // if it's an auto-release item, release it - if (item->flags & WORK_ITEM_FLAG_AUTO_RELEASE) - osd_work_item_release(item); - - // set the result and signal the event - else - { - std::lock_guard lock(queue->lock); - - if (item->event != nullptr) - { - item->event->set(); - add_to_stat(item->queue.setevents, 1); - } - } - - // if we removed an item and there's still work to do, bump the stats - if (queue_has_list_items(queue)) - add_to_stat(queue->extraitems, 1); - } - } - - // we don't need to set the doneevent for multi queues because they spin - if (queue->waiting) - { - queue->doneevent.set(); - add_to_stat(queue->setevents, 1); - } - - end_timing(thread->runtime); -} - -bool queue_has_list_items(osd_work_queue *queue) -{ - std::lock_guard lock(queue->lock); - bool has_list_items = (queue->list.load() != nullptr); - return has_list_items; -} diff --git a/waterbox/ares64/ares/thirdparty/mame/osd/osdsync.h b/waterbox/ares64/ares/thirdparty/mame/osd/osdsync.h deleted file mode 100644 index 3a286b60af..0000000000 --- a/waterbox/ares64/ares/thirdparty/mame/osd/osdsync.h +++ /dev/null @@ -1,167 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Olivier Galibert, R. Belmont -//============================================================ -// -// osdsync.h - Core synchronization functions -// -//============================================================ -#ifndef MAME_OSD_OSDSYNC_H -#define MAME_OSD_OSDSYNC_H - -#pragma once - -// C++ headers -#include -#include -#include - -#include "osdcomm.h" - -/*************************************************************************** - SYNCHRONIZATION INTERFACES - Events -***************************************************************************/ - -#define OSD_EVENT_WAIT_INFINITE (~(osd_ticks_t)0) - -/* osd_event is an opaque type which represents a setable/resettable event */ - -class osd_event -{ -public: - /*----------------------------------------------------------------------------- - constructor: allocate a new event - - Parameters: - - manualreset - boolean. If true, the event will be automatically set - to non-signalled after a thread successfully waited for - it. - initialstate - boolean. If true, the event is signalled initially. - - Return value: - - A pointer to the allocated event. - -----------------------------------------------------------------------------*/ - osd_event(int manualreset, int initialstate) - { - m_signalled = initialstate; - m_autoreset = !manualreset; - } - - ~osd_event() - { - } - - /*----------------------------------------------------------------------------- - wait: wait for an event to be signalled - If the event is in signalled state, the - function returns immediately. If not it will wait for the event - to become signalled. - - Parameters: - - timeout - timeout in osd_ticks - - Return value: - - true: The event was signalled - false: A timeout occurred - -----------------------------------------------------------------------------*/ - - bool wait(osd_ticks_t timeout) - { - if (timeout == OSD_EVENT_WAIT_INFINITE) - timeout = osd_ticks_per_second() * (osd_ticks_t)10000; - - std::unique_lock lock(m_mutex); - if (!timeout) - { - if (!m_signalled) - { - return false; - } - } - else - { - if (!m_signalled) - { - uint64_t msec = timeout * 1000 / osd_ticks_per_second(); - - do { - if (m_cond.wait_for(lock, std::chrono::milliseconds(msec)) == std::cv_status::timeout) - { - if (!m_signalled) - { - return false; - } - else - break; - } else - break; - - } while (true); - } - } - - if (m_autoreset) - m_signalled = 0; - - return true; - } - - /*----------------------------------------------------------------------------- - osd_event_reset: reset an event to non-signalled state - - Parameters: - - None - - Return value: - - None - -----------------------------------------------------------------------------*/ - void reset() - { - m_mutex.lock(); - m_signalled = false; - m_mutex.unlock(); - } - - /*----------------------------------------------------------------------------- - osd_event_set: set an event to signalled state - - Parameters: - - None - - Return value: - - None - - Notes: - - All threads waiting for the event will be signalled. - -----------------------------------------------------------------------------*/ - void set() - { - m_mutex.lock(); - if (m_signalled == false) - { - m_signalled = true; - if (m_autoreset) - m_cond.notify_one(); - else - m_cond.notify_all(); - } - m_mutex.unlock(); - } - -private: - std::mutex m_mutex; - std::condition_variable m_cond; - std::atomic m_autoreset; - std::atomic m_signalled; - -}; - -#endif // MAME_OSD_OSDSYNC_H diff --git a/waterbox/melon/melonDS b/waterbox/melon/melonDS index 7e45e3582b..70e45e69f4 160000 --- a/waterbox/melon/melonDS +++ b/waterbox/melon/melonDS @@ -1 +1 @@ -Subproject commit 7e45e3582be653db468293189d63349c2632c3cb +Subproject commit 70e45e69f466fb6750abc786200cf027ade11867