more misc Client.Common cleanups

This commit is contained in:
adelikat 2017-05-17 13:18:26 -05:00
parent e930dd3326
commit 2a54517b52
46 changed files with 515 additions and 368 deletions

View File

@ -322,7 +322,6 @@ namespace BizHawk.Client.Common
sw.Flush();
}
public BinaryStateSaver(string path, bool notamovie = true) // notamovie is hack, really should have separate something
{
_zip = new IonicZipWriter(path, notamovie ? Global.Config.SaveStateCompressionLevelNormal : Global.Config.MovieCompressionLevel);

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.IO;
using System.Linq;
@ -97,12 +98,14 @@ namespace BizHawk.Client.Common
public class RealFirmwareReader : IDisposable
{
System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
private SHA1 _sha1 = SHA1.Create();
public void Dispose()
{
sha1.Dispose();
sha1 = null;
_sha1.Dispose();
_sha1 = null;
}
public RealFirmwareFile Read(FileInfo fi)
{
var rff = new RealFirmwareFile { FileInfo = fi };
@ -110,10 +113,10 @@ namespace BizHawk.Client.Common
using (var fs = fi.OpenRead())
{
sha1.ComputeHash(fs);
_sha1.ComputeHash(fs);
}
rff.Hash = sha1.Hash.BytesToHexString();
rff.Hash = _sha1.Hash.BytesToHexString();
dict[rff.Hash] = rff;
_files.Add(rff);
return rff;
@ -197,7 +200,6 @@ namespace BizHawk.Client.Common
}
DONE_FIRMWARE: ;
}
// apply user overrides

View File

@ -87,6 +87,7 @@ namespace BizHawk.Client.Common
{
Marshal.StructureToPtr(o, (IntPtr)p, false);
}
return ret;
}
@ -152,6 +153,7 @@ namespace BizHawk.Client.Common
{
dp[i] = sp[i * in_w / w];
}
dp += w;
}
}
@ -172,6 +174,7 @@ namespace BizHawk.Client.Common
{
dp[i] = sp[i * in_w / w];
}
dp += w;
}
}

View File

@ -9,6 +9,7 @@ namespace BizHawk.Client.Common
[JsonObject]
public class RecentFiles : IEnumerable
{
// ReSharper disable once FieldCanBeMadeReadOnly.Local
private List<string> recentlist;
public RecentFiles()

View File

@ -123,6 +123,7 @@ namespace BizHawk.Client.Common
output[(page * 0x4000) + (i * 2) + 1] = source[(page * 0x4000) + 0x0000 + i];
}
}
return output;
}

View File

@ -209,7 +209,6 @@ namespace BizHawk.Client.Common
using (var file = new HawkFile())
{
// only try mounting a file if a filename was given
if (!string.IsNullOrEmpty(path))
{
@ -330,7 +329,6 @@ namespace BizHawk.Client.Common
if (string.IsNullOrEmpty(ext))
{
}
else if (ext == ".m3u")
{
@ -498,6 +496,7 @@ namespace BizHawk.Client.Common
var genesis = new GPGX(nextComm, null, disc, GetCoreSettings<GPGX>(), GetCoreSyncSettings<GPGX>());
nextEmulator = genesis;
}
break;
case "SAT":
nextEmulator = new Yabause(nextComm, disc, GetCoreSyncSettings<Yabause>());
@ -521,6 +520,7 @@ namespace BizHawk.Client.Common
sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
}
break;
case "PCE":
case "PCECD":
@ -704,7 +704,6 @@ namespace BizHawk.Client.Common
rom.GameInfo.System = "NES";
}
if (string.IsNullOrEmpty(rom.GameInfo.System))
{
// Has the user picked a preference for this extension?
@ -737,7 +736,6 @@ namespace BizHawk.Client.Common
isXml = true;
}
CoreInventory.Core core = null;
switch (game.System)
@ -760,6 +758,7 @@ namespace BizHawk.Client.Common
ti83.LinkPort.SendFileToCalc(File.OpenRead(path), false);
nextEmulator = ti83;
}
break;
case "SNES":
if (Global.Config.SNES_InSnes9x && VersionInfo.DeveloperBuild)
@ -807,6 +806,7 @@ namespace BizHawk.Client.Common
core = CoreInventory.Instance["NES", "QuickNes"];
}
}
break;
case "GB":
@ -852,6 +852,7 @@ namespace BizHawk.Client.Common
{
core = CoreInventory.Instance["GBA", "VBA-Next"];
}
break;
case "PSX":
nextEmulator = new Octoshock(nextComm, null, null, rom.FileData, GetCoreSettings<Octoshock>(), GetCoreSyncSettings<Octoshock>());
@ -868,6 +869,7 @@ namespace BizHawk.Client.Common
{
core = CoreInventory.Instance["GEN", "Genplus-gx"];
}
break;
}

View File

@ -71,9 +71,14 @@ namespace BizHawk.Client.Common
int start = rpos;
int end = wpos;
if (end < start) // wrap
{
end = LEN;
}
if (end - start > count)
{
end = start + count;
}
int c = end - start;
if (c > 0)
@ -95,6 +100,7 @@ namespace BizHawk.Client.Common
}
}
}
return ret;
}
@ -145,9 +151,14 @@ namespace BizHawk.Client.Common
int start = wpos;
int end = (rpos - 1) & MASK;
if (end < start) // wrap
{
end = LEN;
}
if (end - start > count)
{
end = start + count;
}
int c = end - start;
if (c > 0)
@ -169,6 +180,7 @@ namespace BizHawk.Client.Common
}
}
}
return ret;
}
@ -183,9 +195,10 @@ namespace BizHawk.Client.Common
private class WStream : Stream
{
public override bool CanRead { get { return false; } }
public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return true; } }
public override bool CanRead => false;
public override bool CanSeek => false;
public override bool CanWrite => true;
public override void Flush() { }
public override long Length { get { throw new NotSupportedException(); } }
public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); }
@ -214,7 +227,9 @@ namespace BizHawk.Client.Common
int cnt = _r.Write(buffer, offset, count);
_total += cnt;
if (cnt < count)
{
throw new IOException("broken pipe");
}
#else
int end = offset + count;
while (offset < end)
@ -228,7 +243,9 @@ namespace BizHawk.Client.Common
public override void WriteByte(byte value)
{
if (!_r.WriteByte(value))
{
throw new IOException("broken pipe");
}
}
protected override void Dispose(bool disposing)
@ -238,9 +255,11 @@ namespace BizHawk.Client.Common
_r.CloseWrite();
_r = null;
}
base.Dispose(disposing);
}
}
private class RStream : Stream
{
public override bool CanRead { get { return true; } }
@ -303,6 +322,7 @@ namespace BizHawk.Client.Common
_r.CloseRead();
_r = null;
}
base.Dispose(disposing);
}
}
@ -377,6 +397,7 @@ namespace BizHawk.Client.Common
{
r.W.Dispose();
}
task.Wait();
}

View File

@ -66,7 +66,10 @@ namespace BizHawk.Client.Common
private static Binding Bind(string tabGroup, string displayName, string bindings = "", string defaultBinding = "", string toolTip = "")
{
if (string.IsNullOrEmpty(defaultBinding))
{
defaultBinding = bindings;
}
return new Binding { DisplayName = displayName, Bindings = bindings, TabGroup = tabGroup, DefaultBinding = defaultBinding, ToolTip = toolTip };
}
@ -75,21 +78,21 @@ namespace BizHawk.Client.Common
// TODO - this method is potentially disastrously O(N^2) slow due to linear search nested in loop
// Add missing entries
foreach (Binding default_binding in DefaultValues)
foreach (Binding defaultBinding in DefaultValues)
{
var binding = Bindings.FirstOrDefault(x => x.DisplayName == default_binding.DisplayName);
var binding = Bindings.FirstOrDefault(x => x.DisplayName == defaultBinding.DisplayName);
if (binding == null)
{
Bindings.Add(default_binding);
Bindings.Add(defaultBinding);
}
else
{
// patch entries with updated settings (necessary because of TODO LARP
binding.Ordinal = default_binding.Ordinal;
binding.DefaultBinding = default_binding.DefaultBinding;
binding.TabGroup = default_binding.TabGroup;
binding.ToolTip = default_binding.ToolTip;
binding.Ordinal = default_binding.Ordinal;
binding.Ordinal = defaultBinding.Ordinal;
binding.DefaultBinding = defaultBinding.DefaultBinding;
binding.TabGroup = defaultBinding.TabGroup;
binding.ToolTip = defaultBinding.ToolTip;
binding.Ordinal = defaultBinding.Ordinal;
}
}

View File

@ -107,6 +107,5 @@ namespace BizHawk.Client.Common
return sw.ToString();
}
}
}
}

View File

@ -9,8 +9,8 @@ namespace BizHawk.Client.Common
{
public class ToolDialogSettings
{
private int? _wndx = null;
private int? _wndy = null;
private int? _wndx;
private int? _wndy;
public ToolDialogSettings()
{
@ -65,8 +65,8 @@ namespace BizHawk.Client.Common
}
/// <summary>
/// Gets a value that represents the top left corner coordinate, if Wndx and Wndy form a valid point
/// Throws an InvalidOperationException if Wndx or Wndy is null
/// Gets a value that represents the top left corner coordinate, if <see cref="Wndx"/> and <see cref="Wndy"/> form a valid point
/// Throws an InvalidOperationException if <see cref="Wndx"/> or <see cref="Wndy"/> is null
/// It is expected to check for this before using this property
/// </summary>
[JsonIgnore]
@ -92,41 +92,18 @@ namespace BizHawk.Client.Common
public bool AutoLoad { get; set; }
[JsonIgnore]
public bool UseWindowPosition
{
get
{
return SaveWindowPosition && Wndx.HasValue && Wndy.HasValue
&& Wndx != -32000 && Wndy != -32000; // Windows OS annoyance, this is saved if the tool was minimized when closing
}
}
public bool UseWindowPosition => SaveWindowPosition && Wndx.HasValue
&& Wndy.HasValue
&& Wndx != -32000 && Wndy != -32000;
[JsonIgnore]
public bool UseWindowSize
{
get
{
return SaveWindowPosition && Width.HasValue && Height.HasValue;
}
}
public bool UseWindowSize => SaveWindowPosition && Width.HasValue && Height.HasValue;
[JsonIgnore]
public Point WindowPosition
{
get
{
return new Point(Wndx ?? 0, Wndy ?? 0);
}
}
public Point WindowPosition => new Point(Wndx ?? 0, Wndy ?? 0);
[JsonIgnore]
public Size WindowSize
{
get
{
return new Size(Width ?? 0, Height ?? 0);
}
}
public Size WindowSize => new Size(Width ?? 0, Height ?? 0);
public class ColumnList : List<Column>
{

View File

@ -85,7 +85,7 @@
}
/// <summary>
/// Sinple on/off pattern, using the given values as on/off.
/// Simple on/off pattern, using the given values as on/off.
/// </summary>
public AutoPatternFloat(float valueOn, int on, float valueOff, int off, bool skip_lag = true, int offset = 0, int loop = 0)
{

View File

@ -173,19 +173,18 @@ namespace BizHawk.Client.Common
return false;
}
public ControllerDefinition Definition
{
get { return Source.Definition; }
}
public ControllerDefinition Definition => Source.Definition;
public bool IsPressed(string button)
{
var source = Source.IsPressed(button);
bool patternValue = false;
if (_boolPatterns.ContainsKey(button))
{ // I can't figure a way to determine right here if it should Peek or Get.
{
// I can't figure a way to determine right here if it should Peek or Get.
patternValue = _boolPatterns[button].PeekNextValue();
}
source ^= patternValue;
return source;

View File

@ -80,7 +80,9 @@ namespace BizHawk.Client.Common
MemoryDomain domain = MemoryDomains.SystemBus;
if (!string.IsNullOrEmpty(name))
{
domain = MemoryDomains[name];
}
var d = DisassemblableCore.Disassemble(domain, pc, out l);
return new { disasm = d, length = l };
@ -113,10 +115,7 @@ namespace BizHawk.Client.Common
}
catch (NotImplementedException)
{
Log(string.Format(
"Error: {0} does not yet implement getregister()",
Emulator.Attributes().CoreName));
Log($"Error: {Emulator.Attributes().CoreName} does not yet implement getregister()");
return 0;
}
}

View File

@ -36,18 +36,18 @@ namespace BizHawk.Client.Common
public void CallExitEvent(Lua thread)
{
var exitCallbacks = _luaFunctions.Where(x => x.Lua == thread && x.Event == "OnExit");
var exitCallbacks = _luaFunctions.Where(l => l.Lua == thread && l.Event == "OnExit");
foreach (var exitCallback in exitCallbacks)
{
exitCallback.Call();
}
}
public LuaFunctionList RegisteredFunctions { get { return _luaFunctions; } }
public LuaFunctionList RegisteredFunctions => _luaFunctions;
public void CallSaveStateEvent(string name)
{
var lfs = _luaFunctions.Where(x => x.Event == "OnSavestateSave").ToList();
var lfs = _luaFunctions.Where(l => l.Event == "OnSavestateSave").ToList();
if (lfs.Any())
{
try
@ -69,7 +69,7 @@ namespace BizHawk.Client.Common
public void CallLoadStateEvent(string name)
{
var lfs = _luaFunctions.Where(x => x.Event == "OnSavestateLoad").ToList();
var lfs = _luaFunctions.Where(l => l.Event == "OnSavestateLoad").ToList();
if (lfs.Any())
{
try
@ -91,7 +91,7 @@ namespace BizHawk.Client.Common
public void CallFrameBeforeEvent()
{
var lfs = _luaFunctions.Where(x => x.Event == "OnFrameStart").ToList();
var lfs = _luaFunctions.Where(l => l.Event == "OnFrameStart").ToList();
if (lfs.Any())
{
try
@ -113,7 +113,7 @@ namespace BizHawk.Client.Common
public void CallFrameAfterEvent()
{
var lfs = _luaFunctions.Where(x => x.Event == "OnFrameEnd").ToList();
var lfs = _luaFunctions.Where(l => l.Event == "OnFrameEnd").ToList();
if (lfs.Any())
{
try
@ -143,17 +143,18 @@ namespace BizHawk.Client.Common
return true;
}
}
return false;
}
private void LogMemoryCallbacksNotImplemented()
{
Log(string.Format("{0} does not implement memory callbacks", Emulator.Attributes().CoreName));
Log($"{Emulator.Attributes().CoreName} does not implement memory callbacks");
}
private void LogMemoryExecuteCallbacksNotImplemented()
{
Log(string.Format("{0} does not implement memory execute callbacks", Emulator.Attributes().CoreName));
Log($"{Emulator.Attributes().CoreName} does not implement memory execute callbacks");
}
#endregion

View File

@ -12,7 +12,6 @@ namespace BizHawk.Client.Common
public MovieLuaLibrary(Lua lua, Action<string> logOutputCallback)
: base(lua, logOutputCallback) { }
public override string Name => "movie";
[LuaMethodAttributes(

View File

@ -51,7 +51,6 @@ namespace BizHawk.Client.Common
CurrentThread = luaThread;
}
}
protected void Log(object message)
{

View File

@ -55,6 +55,7 @@ namespace BizHawk.Client.Common
{
Log($"Unable to find domain: {domain}, falling back to current");
}
return Domain.Name;
}

View File

@ -22,7 +22,7 @@ namespace BizHawk.Client.Common
CurrentDirectory = dir;
}
string CurrentDirectory;
private string CurrentDirectory;
#if WINDOWS
[DllImport("kernel32.dll", SetLastError = true)]
@ -39,9 +39,14 @@ namespace BizHawk.Client.Common
// yeah I know, not the smoothest move to compare strings here, in case path normalization is happening at some point
// but you got any better ideas?
if (currDirSpeedHack == null)
{
currDirSpeedHack = CoolGetCurrentDirectory();
}
if (currDirSpeedHack == path)
{
return true;
}
// WARNING: setting the current directory is SLOW!!! security checks for some reason.
// so we're bypassing it with windows hacks
@ -54,11 +59,14 @@ namespace BizHawk.Client.Common
Environment.CurrentDirectory = CurrentDirectory; // thats right, you can't set a directory as current that doesnt exist because .net's got to do SENSELESS SLOW-ASS SECURITY CHECKS on it and it can't do that on a NONEXISTENT DIRECTORY
return true;
}
else return false;
else
{
return false;
}
#endif
}
string CoolGetCurrentDirectory()
private string CoolGetCurrentDirectory()
{
// GUESS WHAT!
// .NET DOES A SECURITY CHECK ON THE DIRECTORY WE JUST RETRIEVED
@ -76,7 +84,7 @@ namespace BizHawk.Client.Common
#endif
}
void Sandbox(Action callback, Action exceptionCallback)
private void Sandbox(Action callback, Action exceptionCallback)
{
string savedEnvironmentCurrDir = null;
try
@ -84,7 +92,9 @@ namespace BizHawk.Client.Common
savedEnvironmentCurrDir = Environment.CurrentDirectory;
if (CurrentDirectory != null)
{
CoolSetCurrentDirectory(CurrentDirectory, savedEnvironmentCurrDir);
}
EnvironmentSandbox.Sandbox(callback);
}
@ -97,7 +107,9 @@ namespace BizHawk.Client.Common
finally
{
if (CurrentDirectory != null)
{
CoolSetCurrentDirectory(savedEnvironmentCurrDir);
}
}
}
@ -123,13 +135,13 @@ namespace BizHawk.Client.Common
{
LuaSandbox sandbox;
if (SandboxForThread.TryGetValue(thread, out sandbox))
return sandbox;
else
{
// for now: throw exception (I want to manually creating them)
// return CreateSandbox(thread);
throw new InvalidOperationException("HOARY GORILLA HIJINX");
return sandbox;
}
// for now: throw exception (I want to manually creating them)
// return CreateSandbox(thread);
throw new InvalidOperationException("HOARY GORILLA HIJINX");
}
}

View File

@ -80,7 +80,9 @@ namespace BizHawk.Client.Common
var sb = new StringBuilder();
List<Subtitle> subs = new List<Subtitle>();
foreach (var subtitle in this)
{
subs.Add(subtitle);
}
// absense of line wrap forces miltiline subtitle macros
// so we sort them just in case and optionally concat back to a single unit
@ -116,7 +118,9 @@ namespace BizHawk.Client.Common
}
foreach (var subtitle in subs)
{
sb.Append(subtitle.ToSubRip(index++, fps, AddColorTag));
}
return sb.ToString();
}

View File

@ -34,7 +34,11 @@ namespace BizHawk.Client.Common
public string Filename
{
get { return _filename; }
get
{
return _filename;
}
set
{
_filename = value;

View File

@ -13,12 +13,12 @@ namespace BizHawk.Client.Common
public bool IsPressed(string button)
{
return MyBoolButtons[button];
return _myBoolButtons[button];
}
public float GetFloat(string name)
{
return MyFloatControls[name];
return _myFloatControls[name];
}
#endregion
@ -44,7 +44,7 @@ namespace BizHawk.Client.Common
}
var val = playerSource.IsPressed(button);
MyBoolButtons[button] = val;
_myBoolButtons[button] = val;
}
}
@ -55,12 +55,12 @@ namespace BizHawk.Client.Common
{
foreach (var button in Definition.BoolButtons)
{
MyBoolButtons[button] = source.IsPressed(button);
_myBoolButtons[button] = source.IsPressed(button);
}
foreach (var name in Definition.FloatControls)
{
MyFloatControls[name] = source.GetFloat(name);
_myFloatControls[name] = source.GetFloat(name);
}
}
@ -71,7 +71,7 @@ namespace BizHawk.Client.Common
{
foreach (var button in Definition.BoolButtons)
{
MyBoolButtons[button] = Global.AutofireStickyXORAdapter.IsSticky(button);
_myBoolButtons[button] = Global.AutofireStickyXORAdapter.IsSticky(button);
}
}
@ -161,7 +161,7 @@ namespace BizHawk.Client.Common
var c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
int start = 3;
if (ControlType == "NES Controller")
@ -207,50 +207,70 @@ namespace BizHawk.Client.Common
Force("Reset", true);
}
}
if (ControlType == "Gameboy Controller")
{
if (mnemonic.Length < 2) return;
if (mnemonic.Length < 2)
{
return;
}
Force("Power", mnemonic[1] != '.');
}
if (ControlType == "Genesis 3-Button Controller")
{
if (mnemonic.Length < 2) return;
if (mnemonic.Length < 2)
{
return;
}
Force("Reset", mnemonic[1] != '.');
}
if (ControlType == "SMS Controller" || ControlType == "TI83 Controller" || ControlType == "ColecoVision Basic Controller")
{
start = 1;
}
if (ControlType == "Atari 2600 Basic Controller")
{
if (mnemonic.Length < 2) return;
if (mnemonic.Length < 2)
{
return;
}
Force("Reset", mnemonic[1] != '.' && mnemonic[1] != '0');
Force("Select", mnemonic[2] != '.' && mnemonic[2] != '0');
start = 4;
}
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[ControlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
{
int srcindex = (player - 1) * (BkmMnemonicConstants.BUTTONS[ControlType].Count + 1);
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
int ctr = start;
if (mnemonic.Length < srcindex + ctr + BkmMnemonicConstants.BUTTONS[ControlType].Count - 1)
if (mnemonic.Length < srcindex + ctr + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
{
return;
}
string prefix = "";
if (ControlType != "Gameboy Controller" && ControlType != "TI83 Controller")
{
prefix = "P" + player + " ";
}
foreach (string button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{
Force(prefix + button, c[srcindex + ctr++]);
}
}
if (ControlType == "SMS Controller")
{
int srcindex = BkmMnemonicConstants.PLAYERS[ControlType] * (BkmMnemonicConstants.BUTTONS[ControlType].Count + 1);
int srcindex = BkmMnemonicConstants.Players[ControlType] * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
int ctr = start;
foreach (var command in BkmMnemonicConstants.COMMANDS[ControlType].Keys)
foreach (var command in BkmMnemonicConstants.Commands[ControlType].Keys)
{
Force(command, c[srcindex + ctr++]);
}
@ -259,8 +279,8 @@ namespace BizHawk.Client.Common
#endregion
private readonly WorkingDictionary<string, bool> MyBoolButtons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, float> MyFloatControls = new WorkingDictionary<string, float>();
private readonly WorkingDictionary<string, bool> _myBoolButtons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, float> _myFloatControls = new WorkingDictionary<string, float>();
private bool IsGenesis6Button()
{
@ -269,12 +289,12 @@ namespace BizHawk.Client.Common
private void Force(string button, bool state)
{
MyBoolButtons[button] = state;
_myBoolButtons[button] = state;
}
private void Force(string name, float state)
{
MyFloatControls[name] = state;
_myFloatControls[name] = state;
}
private string ControlType => Definition.Name;
@ -282,17 +302,19 @@ namespace BizHawk.Client.Common
private void SetGBAControllersAsMnemonic(string mnemonic)
{
MnemonicChecker c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
if (mnemonic.Length < 2)
{
return;
}
if (mnemonic[1] == 'P')
{
Force("Power", true);
}
int start = 3;
foreach (string button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{
Force(button, c[start++]);
}
@ -301,7 +323,7 @@ namespace BizHawk.Client.Common
private void SetGenesis6ControllersAsMnemonic(string mnemonic)
{
MnemonicChecker c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
if (mnemonic.Length < 2)
{
@ -322,17 +344,17 @@ namespace BizHawk.Client.Common
return;
}
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[ControlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
{
int srcindex = (player - 1) * (BkmMnemonicConstants.BUTTONS[ControlType].Count + 1);
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.BUTTONS[ControlType].Count - 1)
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
{
return;
}
int start = 3;
foreach (string button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{
Force("P" + player + " " + button, c[srcindex + start++]);
}
@ -342,7 +364,7 @@ namespace BizHawk.Client.Common
private void SetGenesis3ControllersAsMnemonic(string mnemonic)
{
MnemonicChecker c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
if (mnemonic.Length < 2)
{
@ -363,17 +385,17 @@ namespace BizHawk.Client.Common
return;
}
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[ControlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
{
int srcindex = (player - 1) * (BkmMnemonicConstants.BUTTONS["GPGX 3-Button Controller"].Count + 1);
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons["GPGX 3-Button Controller"].Count + 1);
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.BUTTONS["GPGX 3-Button Controller"].Count - 1)
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons["GPGX 3-Button Controller"].Count - 1)
{
return;
}
int start = 3;
foreach (string button in BkmMnemonicConstants.BUTTONS["GPGX 3-Button Controller"].Keys)
foreach (string button in BkmMnemonicConstants.Buttons["GPGX 3-Button Controller"].Keys)
{
Force("P" + player + " " + button, c[srcindex + start++]);
}
@ -383,7 +405,7 @@ namespace BizHawk.Client.Common
private void SetSNESControllersAsMnemonic(string mnemonic)
{
var c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
if (mnemonic.Length < 2)
{
@ -399,17 +421,17 @@ namespace BizHawk.Client.Common
Force("Reset", true);
}
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[ControlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
{
int srcindex = (player - 1) * (BkmMnemonicConstants.BUTTONS[ControlType].Count + 1);
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.BUTTONS[ControlType].Count - 1)
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
{
return;
}
int start = 3;
foreach (var button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{
Force("P" + player + " " + button, c[srcindex + start++]);
}
@ -419,7 +441,7 @@ namespace BizHawk.Client.Common
private void SetLynxControllersAsMnemonic(string mnemonic)
{
var c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
if (mnemonic.Length < 2)
{
@ -431,17 +453,17 @@ namespace BizHawk.Client.Common
Force("Power", true);
}
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[ControlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
{
int srcindex = (player - 1) * (BkmMnemonicConstants.BUTTONS[ControlType].Count + 1);
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.BUTTONS[ControlType].Count - 1)
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
{
return;
}
int start = 3;
foreach (var button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{
Force(button, c[srcindex + start++]);
}
@ -451,7 +473,7 @@ namespace BizHawk.Client.Common
private void SetN64ControllersAsMnemonic(string mnemonic)
{
MnemonicChecker c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
if (mnemonic.Length < 2)
{
@ -467,22 +489,22 @@ namespace BizHawk.Client.Common
Force("Reset", true);
}
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[ControlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
{
int srcindex = (player - 1) * (BkmMnemonicConstants.BUTTONS[ControlType].Count + BkmMnemonicConstants.ANALOGS[ControlType].Count * 4 + 1 + 1);
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + BkmMnemonicConstants.Analogs[ControlType].Count * 4 + 1 + 1);
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.BUTTONS[ControlType].Count - 1)
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
{
return;
}
int start = 3;
foreach (string button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{
Force("P" + player + " " + button, c[srcindex + start++]);
}
foreach (string name in BkmMnemonicConstants.ANALOGS[ControlType].Keys)
foreach (string name in BkmMnemonicConstants.Analogs[ControlType].Keys)
{
Force("P" + player + " " + name, int.Parse(mnemonic.Substring(srcindex + start, 4)));
start += 5;
@ -493,7 +515,7 @@ namespace BizHawk.Client.Common
private void SetSaturnControllersAsMnemonic(string mnemonic)
{
MnemonicChecker c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
if (mnemonic.Length < 2)
{
@ -509,17 +531,17 @@ namespace BizHawk.Client.Common
Force("Reset", true);
}
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[ControlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
{
int srcindex = (player - 1) * (BkmMnemonicConstants.BUTTONS[ControlType].Count + 1);
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.BUTTONS[ControlType].Count - 1)
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
{
return;
}
int start = 3;
foreach (string button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{
Force("P" + player + " " + button, c[srcindex + start++]);
}
@ -529,39 +551,43 @@ namespace BizHawk.Client.Common
private void SetAtari7800AsMnemonic(string mnemonic)
{
MnemonicChecker c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
if (mnemonic.Length < 5)
{
return;
}
if (mnemonic[1] == 'P')
{
Force("Power", true);
}
if (mnemonic[2] == 'r')
{
Force("Reset", true);
}
if (mnemonic[3] == 's')
{
Force("Select", true);
}
if (mnemonic[4] == 'p')
{
Force("Pause", true);
}
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[ControlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
{
int srcindex = (player - 1) * (BkmMnemonicConstants.BUTTONS[ControlType].Count + 1);
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
int start = 6;
if (mnemonic.Length < srcindex + start + BkmMnemonicConstants.BUTTONS[ControlType].Count)
if (mnemonic.Length < srcindex + start + BkmMnemonicConstants.Buttons[ControlType].Count)
{
return;
}
foreach (string button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{
Force("P" + player + " " + button, c[srcindex + start++]);
}
@ -571,10 +597,10 @@ namespace BizHawk.Client.Common
private void SetDualGameBoyControllerAsMnemonic(string mnemonic)
{
var checker = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
for (int i = 0; i < BkmMnemonicConstants.DGBMnemonic.Length; i++)
_myBoolButtons.Clear();
for (int i = 0; i < BkmMnemonicConstants.DgbMnemonic.Length; i++)
{
var t = BkmMnemonicConstants.DGBMnemonic[i];
var t = BkmMnemonicConstants.DgbMnemonic[i];
if (t.Item1 != null)
{
Force(t.Item1, checker[i]);
@ -585,10 +611,10 @@ namespace BizHawk.Client.Common
private void SetWonderSwanControllerAsMnemonic(string mnemonic)
{
var checker = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
for (int i = 0; i < BkmMnemonicConstants.WSMnemonic.Length; i++)
_myBoolButtons.Clear();
for (int i = 0; i < BkmMnemonicConstants.WsMnemonic.Length; i++)
{
var t = BkmMnemonicConstants.WSMnemonic[i];
var t = BkmMnemonicConstants.WsMnemonic[i];
if (t.Item1 != null)
{
Force(t.Item1, checker[i]);
@ -599,27 +625,26 @@ namespace BizHawk.Client.Common
private void SetC64ControllersAsMnemonic(string mnemonic)
{
var c = new MnemonicChecker(mnemonic);
MyBoolButtons.Clear();
_myBoolButtons.Clear();
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[ControlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
{
int srcindex = (player - 1) * (BkmMnemonicConstants.BUTTONS[ControlType].Count + 1);
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
if (mnemonic.Length < srcindex + 1 + BkmMnemonicConstants.BUTTONS[ControlType].Count - 1)
if (mnemonic.Length < srcindex + 1 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
{
return;
}
int start = 1;
foreach (var button in BkmMnemonicConstants.BUTTONS[ControlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{
Force("P" + player + " " + button, c[srcindex + start++]);
}
}
int startk = 13;
foreach (string button in BkmMnemonicConstants.BUTTONS["Commodore 64 Keyboard"].Keys)
foreach (string button in BkmMnemonicConstants.Buttons["Commodore 64 Keyboard"].Keys)
{
Force(button, c[startk++]);
}

View File

@ -106,7 +106,7 @@ namespace BizHawk.Client.Common
}
}
public string SystemID
public string SystemId
{
get
{

View File

@ -96,15 +96,15 @@ namespace BizHawk.Client.Common
{
if (IsBasePressed("Power"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Power"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Power"]);
}
else if (IsBasePressed("Reset"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Reset"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Reset"]);
}
else if (IsBasePressed("FDS Eject"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["FDS Eject"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["FDS Eject"]);
}
else if (IsBasePressed("FDS Insert 0"))
{
@ -124,11 +124,11 @@ namespace BizHawk.Client.Common
}
else if (IsBasePressed("VS Coin 1"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["VS Coin 1"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["VS Coin 1"]);
}
else if (IsBasePressed("VS Coin 2"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["VS Coin 2"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["VS Coin 2"]);
}
else
{
@ -139,11 +139,11 @@ namespace BizHawk.Client.Common
{
if (IsBasePressed("Power"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Power"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Power"]);
}
else if (IsBasePressed("Reset"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Reset"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Reset"]);
}
else
{
@ -152,7 +152,7 @@ namespace BizHawk.Client.Common
}
else if (_controlType == "Gameboy Controller")
{
input.Append(IsBasePressed("Power") ? BkmMnemonicConstants.COMMANDS[_controlType]["Power"] : ".");
input.Append(IsBasePressed("Power") ? BkmMnemonicConstants.Commands[_controlType]["Power"] : ".");
}
if (_controlType != "SMS Controller" && _controlType != "TI83 Controller" && _controlType != "ColecoVision Basic Controller")
@ -160,7 +160,7 @@ namespace BizHawk.Client.Common
input.Append("|");
}
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[_controlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[_controlType]; player++)
{
var prefix = "";
if (_controlType != "Gameboy Controller" && _controlType != "TI83 Controller")
@ -168,9 +168,9 @@ namespace BizHawk.Client.Common
prefix = "P" + player + " ";
}
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed(prefix + button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed(prefix + button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
input.Append("|");
@ -178,9 +178,9 @@ namespace BizHawk.Client.Common
if (_controlType == "SMS Controller")
{
foreach (var command in BkmMnemonicConstants.COMMANDS[_controlType].Keys)
foreach (var command in BkmMnemonicConstants.Commands[_controlType].Keys)
{
input.Append(IsBasePressed(command) ? BkmMnemonicConstants.COMMANDS[_controlType][command] : ".");
input.Append(IsBasePressed(command) ? BkmMnemonicConstants.Commands[_controlType][command] : ".");
}
input.Append("|");
@ -274,7 +274,7 @@ namespace BizHawk.Client.Common
var input = new StringBuilder("|");
if (IsBasePressed("Power"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Power"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Power"]);
}
else
{
@ -282,9 +282,9 @@ namespace BizHawk.Client.Common
}
input.Append("|");
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed(button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed(button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
input.Append("|");
@ -297,11 +297,11 @@ namespace BizHawk.Client.Common
if (IsBasePressed("Power"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Power"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Power"]);
}
else if (IsBasePressed("Reset"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Reset"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Reset"]);
}
else
{
@ -309,11 +309,11 @@ namespace BizHawk.Client.Common
}
input.Append("|");
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[_controlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[_controlType]; player++)
{
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
input.Append("|");
@ -326,19 +326,19 @@ namespace BizHawk.Client.Common
{
var input = new StringBuilder("|");
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[_controlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[_controlType]; player++)
{
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
input.Append('|');
}
foreach (var button in BkmMnemonicConstants.BUTTONS["Commodore 64 Keyboard"].Keys)
foreach (var button in BkmMnemonicConstants.Buttons["Commodore 64 Keyboard"].Keys)
{
input.Append(IsBasePressed(button) ? BkmMnemonicConstants.BUTTONS["Commodore 64 Keyboard"][button] : ".");
input.Append(IsBasePressed(button) ? BkmMnemonicConstants.Buttons["Commodore 64 Keyboard"][button] : ".");
}
input.Append('|');
@ -350,7 +350,7 @@ namespace BizHawk.Client.Common
// |.|........|.|........|
var input = new StringBuilder();
foreach (var t in BkmMnemonicConstants.DGBMnemonic)
foreach (var t in BkmMnemonicConstants.DgbMnemonic)
{
if (t.Item1 != null)
{
@ -370,7 +370,7 @@ namespace BizHawk.Client.Common
// |....|....|...|
var input = new StringBuilder();
foreach (var t in BkmMnemonicConstants.WSMnemonic)
foreach (var t in BkmMnemonicConstants.WsMnemonic)
{
if (t.Item1 != null)
{
@ -394,11 +394,11 @@ namespace BizHawk.Client.Common
input.Append(IsBasePressed("Pause") ? 'p' : '.');
input.Append('|');
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[_controlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[_controlType]; player++)
{
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
input.Append('|');
@ -413,11 +413,11 @@ namespace BizHawk.Client.Common
input.Append(IsBasePressed("Power") ? 'P' : '.');
input.Append('|');
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[_controlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[_controlType]; player++)
{
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed(button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed(button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
input.Append('|');
@ -444,16 +444,16 @@ namespace BizHawk.Client.Common
input.Append('|');
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[_controlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[_controlType]; player++)
{
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
if (BkmMnemonicConstants.ANALOGS[_controlType].Keys.Count > 0)
if (BkmMnemonicConstants.Analogs[_controlType].Keys.Count > 0)
{
foreach (var name in BkmMnemonicConstants.ANALOGS[_controlType].Keys)
foreach (var name in BkmMnemonicConstants.Analogs[_controlType].Keys)
{
int val;
@ -528,11 +528,11 @@ namespace BizHawk.Client.Common
input.Append('|');
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[_controlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[_controlType]; player++)
{
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
input.Append('|');
@ -547,11 +547,11 @@ namespace BizHawk.Client.Common
if (IsBasePressed("Power"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Power"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Power"]);
}
else if (IsBasePressed("Reset"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Reset"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Reset"]);
}
else
{
@ -559,11 +559,11 @@ namespace BizHawk.Client.Common
}
input.Append("|");
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[_controlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[_controlType]; player++)
{
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
input.Append("|");
@ -579,11 +579,11 @@ namespace BizHawk.Client.Common
if (IsBasePressed("Power"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Power"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Power"]);
}
else if (IsBasePressed("Reset"))
{
input.Append(BkmMnemonicConstants.COMMANDS[_controlType]["Reset"]);
input.Append(BkmMnemonicConstants.Commands[_controlType]["Reset"]);
}
else
{
@ -591,11 +591,11 @@ namespace BizHawk.Client.Common
}
input.Append("|");
for (int player = 1; player <= BkmMnemonicConstants.PLAYERS[_controlType]; player++)
for (int player = 1; player <= BkmMnemonicConstants.Players[_controlType]; player++)
{
foreach (var button in BkmMnemonicConstants.BUTTONS[_controlType].Keys)
foreach (var button in BkmMnemonicConstants.Buttons[_controlType].Keys)
{
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.BUTTONS[_controlType][button] : ".");
input.Append(IsBasePressed("P" + player + " " + button) ? BkmMnemonicConstants.Buttons[_controlType][button] : ".");
}
input.Append("|");

View File

@ -5,7 +5,7 @@ namespace BizHawk.Client.Common
{
public static class BkmMnemonicConstants
{
public static readonly Dictionary<string, Dictionary<string, string>> BUTTONS = new Dictionary<string, Dictionary<string, string>>
public static readonly Dictionary<string, Dictionary<string, string>> Buttons = new Dictionary<string, Dictionary<string, string>>
{
{
"Gameboy Controller", new Dictionary<string, string>
@ -142,12 +142,12 @@ namespace BizHawk.Client.Common
}
};
public static readonly Dictionary<string, Dictionary<string, string>> ANALOGS = new Dictionary<string, Dictionary<string, string>>
public static readonly Dictionary<string, Dictionary<string, string>> Analogs = new Dictionary<string, Dictionary<string, string>>
{
{ "Nintento 64 Controller", new Dictionary<string, string> { { "X Axis", "X" }, { "Y Axis", "Y" } } }
};
public static readonly Dictionary<string, Dictionary<string, string>> COMMANDS = new Dictionary<string, Dictionary<string, string>>
public static readonly Dictionary<string, Dictionary<string, string>> Commands = new Dictionary<string, Dictionary<string, string>>
{
{ "Atari 2600 Basic Controller", new Dictionary<string, string> { { "Reset", "r" }, { "Select", "s" } } },
{ "Atari 7800 ProLine Joystick Controller", new Dictionary<string, string> { { "Reset", "r" }, { "Select", "s" } } },
@ -165,7 +165,7 @@ namespace BizHawk.Client.Common
{ "GPGX 3-Button Controller", new Dictionary<string, string> { { "Power", "P" }, { "Reset", "r" } } }
};
public static readonly Dictionary<string, int> PLAYERS = new Dictionary<string, int>
public static readonly Dictionary<string, int> Players = new Dictionary<string, int>
{
{ "Gameboy Controller", 1 }, { "GBA Controller", 1 }, { "Genesis 3-Button Controller", 2 }, { "GPGX Genesis Controller", 2 }, { "NES Controller", 4 },
{ "SNES Controller", 4 }, { "PC Engine Controller", 5 }, { "SMS Controller", 2 }, { "TI83 Controller", 1 }, { "Atari 2600 Basic Controller", 2 }, { "Atari 7800 ProLine Joystick Controller", 2 },
@ -175,7 +175,7 @@ namespace BizHawk.Client.Common
// just experimenting with different possibly more painful ways to handle mnemonics
// |P|UDLRsSBA|
public static readonly Tuple<string, char>[] DGBMnemonic =
public static readonly Tuple<string, char>[] DgbMnemonic =
{
new Tuple<string, char>(null, '|'),
new Tuple<string, char>("P1 Power", 'P'),
@ -202,7 +202,7 @@ namespace BizHawk.Client.Common
new Tuple<string, char>(null, '|')
};
public static readonly Tuple<string, char>[] WSMnemonic =
public static readonly Tuple<string, char>[] WsMnemonic =
{
new Tuple<string, char>(null, '|'),
new Tuple<string, char>("P1 X1", '1'),

View File

@ -42,8 +42,8 @@ namespace BizHawk.Client.Common
public string SystemID
{
get { return Header.SystemID; }
set { Header.SystemID = value; }
get { return Header.SystemId; }
set { Header.SystemId = value; }
}
public string Hash

View File

@ -18,10 +18,10 @@ namespace BizHawk.Client.Common
return;
}
var directory_info = new FileInfo(Filename).Directory;
if (directory_info != null)
var directoryInfo = new FileInfo(Filename).Directory;
if (directoryInfo != null)
{
Directory.CreateDirectory(directory_info.FullName);
Directory.CreateDirectory(directoryInfo.FullName);
}
Write(Filename);
@ -49,10 +49,10 @@ namespace BizHawk.Client.Common
backupName = backupName.Insert(Filename.LastIndexOf("."), $".{DateTime.Now:yyyy-MM-dd HH.mm.ss}");
backupName = Path.Combine(Global.Config.PathEntries["Global", "Movie backups"].Path, Path.GetFileName(backupName));
var directory_info = new FileInfo(backupName).Directory;
if (directory_info != null)
var directoryInfo = new FileInfo(backupName).Directory;
if (directoryInfo != null)
{
Directory.CreateDirectory(directory_info.FullName);
Directory.CreateDirectory(directoryInfo.FullName);
}
Write(backupName);
@ -166,14 +166,20 @@ namespace BizHawk.Client.Common
{
int c = sr.Read();
if (c == -1)
{
break;
}
if (c == '\r')
{
usesR = true;
break;
}
if (c == '\n')
{
break;
}
}
int lineLen = line.Length + 1; // account for \n
@ -194,9 +200,11 @@ namespace BizHawk.Client.Common
for (;;)
{
int c = sr.Read();
if (c == -1) break;
if (c == '\n') break;
if (c == ' ') break;
if (c == -1 || c == '\n' || c == ' ')
{
break;
}
sbLine.Append((char)c);
}
@ -213,15 +221,16 @@ namespace BizHawk.Client.Common
for (;;)
{
int c = stream.ReadByte();
if (c == -1) break;
if (c == '\n') break;
if (c == -1 || c == '\n')
{
break;
}
}
// proceed to next line
continue;
}
var remainder = sr.ReadLine();
sbLine.Append(' ');
sbLine.Append(remainder);

View File

@ -4,7 +4,7 @@ namespace BizHawk.Client.Common
{
public partial class BkmMovie : IMovie
{
private bool _makeBackup = true;
private bool _makeBackup;
private bool _changes;
private int? _loopOffset;

View File

@ -310,7 +310,6 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
movie.HeaderEntries.Add(key, firmware.Hash);
}
}
}
if (Global.Emulator is Gameboy && (Global.Emulator as Gameboy).IsCGBMode())

View File

@ -169,26 +169,25 @@ namespace BizHawk.Client.Common
{
return null;
}
if (blob[0] == '0' && (blob[1] == 'x' || blob[1] == 'X'))
{
// hex
return Util.HexStringToBytes(blob.Substring(2));
}
else
// base64
if (!blob.ToLower().StartsWith("base64:"))
{
// base64
if (!blob.ToLower().StartsWith("base64:"))
{
return null;
}
try
{
return Convert.FromBase64String(blob.Substring(7));
}
catch (FormatException)
{
return null;
}
return null;
}
try
{
return Convert.FromBase64String(blob.Substring(7));
}
catch (FormatException)
{
return null;
}
}
}

View File

@ -37,7 +37,7 @@ namespace BizHawk.Client.Common
if (!SourceFile.Exists)
{
Result.Errors.Add(string.Format("Could not find the file {0}", path));
Result.Errors.Add($"Could not find the file {path}");
return Result;
}
@ -49,7 +49,6 @@ namespace BizHawk.Client.Common
return Result;
}
protected ImportResult Result = new ImportResult();
protected FileInfo SourceFile;
@ -76,7 +75,7 @@ namespace BizHawk.Client.Common
}
public IList<string> Warnings { get; private set; }
public IList<string> Errors { get; private set; }
public IList<string> Errors { get; }
public Bk2Movie Movie { get; set; }
}

View File

@ -53,7 +53,6 @@ namespace BizHawk.Client.Common
if (!string.IsNullOrWhiteSpace(warningMsg))
{
messageCallback(warningMsg);
}
else
{
@ -96,8 +95,16 @@ namespace BizHawk.Client.Common
try
{
var result = importer.Import(path);
if (result.Errors.Count > 0) errorMsg = result.Errors.First();
if (result.Warnings.Count > 0) warningMsg = result.Warnings.First();
if (result.Errors.Count > 0)
{
errorMsg = result.Errors.First();
}
if (result.Warnings.Count > 0)
{
warningMsg = result.Warnings.First();
}
movie = result.Movie;
}
catch (Exception ex)
@ -143,31 +150,31 @@ namespace BizHawk.Client.Common
switch (ext)
{
case ".FCM":
m = ImportFCM(path, out errorMsg, out warningMsg);
m = ImportFcm(path, out errorMsg, out warningMsg);
break;
case ".FM2":
m = ImportFM2(path, out errorMsg, out warningMsg);
m = ImportFm2(path, out errorMsg, out warningMsg);
break;
case ".FMV":
m = ImportFmv(path, out errorMsg, out warningMsg);
break;
case ".GMV":
m = ImportGMV(path, out errorMsg, out warningMsg);
m = ImportGmv(path, out errorMsg, out warningMsg);
break;
case ".LSMV":
m = ImportLSMV(path, out errorMsg, out warningMsg);
m = ImportLsmv(path, out errorMsg, out warningMsg);
break;
case ".MCM":
m = ImportMCM(path, out errorMsg, out warningMsg);
m = ImportMcm(path, out errorMsg, out warningMsg);
break;
case ".MC2":
m = ImportMC2(path, out errorMsg, out warningMsg);
m = ImportMc2(path, out errorMsg, out warningMsg);
break;
case ".MMV":
m = ImportMMV(path, out errorMsg, out warningMsg);
m = ImportMmv(path, out errorMsg, out warningMsg);
break;
case ".NMV":
m = ImportNMV(path, out errorMsg, out warningMsg);
m = ImportNmv(path, out errorMsg, out warningMsg);
break;
case ".SMV":
m = ImportSmv(path, out errorMsg, out warningMsg);
@ -241,7 +248,7 @@ namespace BizHawk.Client.Common
emptyController["Reset"] = false;
emptyController["Power"] = false;
string[] buttons = new[] { "B", "Y", "Select", "Start", "Up", "Down", "Left", "Right", "A", "X", "L", "R" };
string[] buttons = { "B", "Y", "Select", "Start", "Up", "Down", "Left", "Right", "A", "X", "L", "R" };
string[] sections = line.Split('|');
for (int section = 2; section < sections.Length - 1; section++)
{
@ -301,7 +308,7 @@ namespace BizHawk.Client.Common
controllers["Reset"] = sections[1][0] == '1';
// Get the first invalid command warning message that arises.
if (string.IsNullOrEmpty((warningMsg)))
if (string.IsNullOrEmpty(warningMsg))
{
switch (sections[1][0])
{
@ -310,7 +317,7 @@ namespace BizHawk.Client.Common
case '1':
break;
case '2':
if (m.FrameCount != 0)
if ((int)m.FrameCount != 0)
{
warningMsg = "hard reset";
}
@ -333,6 +340,7 @@ namespace BizHawk.Client.Common
}
}
}
if (ext == ".LSMV" && sections.Length != 0)
{
string flags = sections[0];
@ -361,24 +369,26 @@ namespace BizHawk.Client.Common
controllers["Reset"] = reset;
}
/*
Skip the first two sections of the split, which consist of everything before the starting | and the command.
Do not use the section after the last |. In other words, get the sections for the players.
*/
int start = 2;
int end = sections.Length - 1;
int player_offset = -1;
int playerOffset = -1;
if (ext == ".LSMV")
{
// LSNES frames don't start or end with a |.
start--;
end++;
player_offset++;
playerOffset++;
}
for (int section = start; section < end; section++)
{
// The player number is one less than the section number for the reasons explained above.
int player = section + player_offset;
int player = section + playerOffset;
string prefix = "P" + player + " ";
// Gameboy doesn't currently have a prefix saying which player the input is for.
@ -390,7 +400,7 @@ namespace BizHawk.Client.Common
// Only count lines with that have the right number of buttons and are for valid players.
if (
sections[section].Length == buttons.Length &&
player <= BkmMnemonicConstants.PLAYERS[controllers.Definition.Name])
player <= BkmMnemonicConstants.Players[controllers.Definition.Name])
{
for (int button = 0; button < buttons.Length; button++)
{
@ -462,6 +472,7 @@ namespace BizHawk.Client.Common
platform = "Sega Saturn";
break;
}
m.Header[HeaderKeys.PLATFORM] = platform;
int lineNum = 0;
string line;
@ -472,7 +483,8 @@ namespace BizHawk.Client.Common
{
continue;
}
else if (line[0] == '|')
if (line[0] == '|')
{
m = ImportTextFrame(line, lineNum, m, path, platform, ref warningMsg);
if (errorMsg != "")
@ -600,26 +612,26 @@ namespace BizHawk.Client.Common
{
return null;
}
if (blob[0] == '0' && (blob[1] == 'x' || blob[1] == 'X'))
{
// hex
return Util.HexStringToBytes(blob.Substring(2));
}
else
// base64
if (!blob.ToLower().StartsWith("base64:"))
{
// base64
if (!blob.ToLower().StartsWith("base64:"))
{
return null;
}
try
{
return Convert.FromBase64String(blob.Substring(7));
}
catch (FormatException)
{
return null;
}
return null;
}
try
{
return Convert.FromBase64String(blob.Substring(7));
}
catch (FormatException)
{
return null;
}
}
@ -631,11 +643,12 @@ namespace BizHawk.Client.Common
{
str = str.Substring(0, pos);
}
return str;
}
// FCM file format: http://code.google.com/p/fceu/wiki/FCM
private static BkmMovie ImportFCM(string path, out string errorMsg, out string warningMsg)
private static BkmMovie ImportFcm(string path, out string errorMsg, out string warningMsg)
{
errorMsg = warningMsg = "";
BkmMovie m = new BkmMovie(path);
@ -661,6 +674,7 @@ namespace BizHawk.Client.Common
fs.Close();
return null;
}
m.Comments.Add(MOVIEORIGIN + " .FCM version " + version);
// 008 1-byte flags
@ -785,6 +799,7 @@ namespace BizHawk.Client.Common
{
frames += r.ReadByte() * (int)Math.Pow(2, b * 8);
}
frame += frames;
while (frames > 0)
{
@ -911,7 +926,7 @@ namespace BizHawk.Client.Common
}
// FM2 file format: http://www.fceux.com/web/FM2.html
private static BkmMovie ImportFM2(string path, out string errorMsg, out string warningMsg)
private static BkmMovie ImportFm2(string path, out string errorMsg, out string warningMsg)
{
return ImportText(path, out errorMsg, out warningMsg);
}
@ -960,16 +975,15 @@ namespace BizHawk.Client.Common
else
{
fds = false;
}
m.Header[HeaderKeys.PLATFORM] = "NES";
// bit 6: uses controller 2
bool controller2 = (((flags >> 6) & 0x1) != 0);
bool controller2 = ((flags >> 6) & 0x1) != 0;
// bit 7: uses controller 1
bool controller1 = (((flags >> 7) & 0x1) != 0);
bool controller1 = ((flags >> 7) & 0x1) != 0;
// other bits: unknown, set to 0
// 006 4-byte little-endian unsigned int: unknown, set to 00000000
@ -1058,7 +1072,7 @@ namespace BizHawk.Client.Common
{
for (int button = 0; button < buttons.Length; button++)
{
controllers["P" + player + " " + buttons[button]] = (((controllerState >> button) & 0x1) != 0);
controllers["P" + player + " " + buttons[button]] = ((controllerState >> button) & 0x1) != 0;
}
}
else
@ -1076,7 +1090,7 @@ namespace BizHawk.Client.Common
}
// GMV file format: http://code.google.com/p/gens-rerecording/wiki/GMV
private static BkmMovie ImportGMV(string path, out string errorMsg, out string warningMsg)
private static BkmMovie ImportGmv(string path, out string errorMsg, out string warningMsg)
{
errorMsg = warningMsg = "";
var m = new BkmMovie(path);
@ -1127,7 +1141,7 @@ namespace BizHawk.Client.Common
second The file format has no means of identifying NTSC/"PAL", but the FPS can still be derived from the
header.
*/
bool pal = (((flags >> 7) & 0x1) != 0);
bool pal = ((flags >> 7) & 0x1) != 0;
m.Header[HeaderKeys.PAL] = pal.ToString();
// bit 6: if "1", movie requires a savestate.
@ -1218,7 +1232,7 @@ namespace BizHawk.Client.Common
}
// LSMV file format: http://tasvideos.org/Lsnes/Movieformat.html
private static BkmMovie ImportLSMV(string path, out string errorMsg, out string warningMsg)
private static BkmMovie ImportLsmv(string path, out string errorMsg, out string warningMsg)
{
errorMsg = warningMsg = "";
var m = new BkmMovie(path);
@ -1230,6 +1244,7 @@ namespace BizHawk.Client.Common
errorMsg = "This is not an archive.";
return null;
}
string platform = "SNES";
foreach (var item in hf.ArchiveItems)
{
@ -1238,8 +1253,8 @@ namespace BizHawk.Client.Common
hf.BindArchiveMember(item.Index);
var stream = hf.GetStream();
string authors = Encoding.UTF8.GetString(stream.ReadAllBytes());
string author_list = "";
string author_last = "";
string authorList = "";
string authorLast = "";
using (var reader = new StringReader(authors))
{
string line;
@ -1250,27 +1265,27 @@ namespace BizHawk.Client.Common
string author = line.Trim();
if (author != "")
{
if (author_last != "")
if (authorLast != "")
{
author_list += author_last + ", ";
authorList += authorLast + ", ";
}
author_last = author;
authorLast = author;
}
}
}
if (author_list != "")
if (authorList != "")
{
author_list += "and ";
authorList += "and ";
}
if (author_last != "")
if (authorLast != "")
{
author_list += author_last;
authorList += authorLast;
}
m.Header[HeaderKeys.AUTHOR] = author_list;
m.Header[HeaderKeys.AUTHOR] = authorList;
hf.Unbind();
}
else if (item.Name == "coreversion")
@ -1485,7 +1500,7 @@ namespace BizHawk.Client.Common
MCM file format: http://code.google.com/p/mednafen-rr/wiki/MCM
Mednafen-rr switched to MC2 from r261, so see r260 for details.
*/
private static BkmMovie ImportMCM(string path, out string errorMsg, out string warningMsg)
private static BkmMovie ImportMcm(string path, out string errorMsg, out string warningMsg)
{
errorMsg = warningMsg = "";
BkmMovie m = new BkmMovie(path);
@ -1523,37 +1538,35 @@ namespace BizHawk.Client.Common
// 070 uint32 Re-record Count
uint rerecordCount = r.ReadUInt32();
m.Rerecords = (ulong)rerecordCount;
m.Rerecords = rerecordCount;
// 074 5-byte Console indicator (pce, ngp, pcfx, wswan)
string platform = NullTerminated(r.ReadStringFixedAscii(5));
Dictionary<string, Dictionary<string, object>> platforms = new Dictionary<string, Dictionary<string, object>>
{
// Normally, NES receives from 5 input ports, where the first 4 have a length of 1 byte, and the last has
// a length of 0. For the sake of simplicity, it is interpreted as 4 ports of 1 byte length for
// re-recording.
["nes"] = new Dictionary<string, object>
{
/*
Normally, NES receives from 5 input ports, where the first 4 have a length of 1 byte, and the last has
a length of 0. For the sake of simplicity, it is interpreted as 4 ports of 1 byte length for
re-recording.
*/
"nes", new Dictionary<string, object>
{
{ "name", "NES" }, { "ports", 4 }, { "bytesPerPort", 1 },
{ "buttons", new[] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" } }
}
["name"] = "NES",
["ports"] = 4,
["bytesPerPort"] = 1,
["buttons"] = new[] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" }
},
["pce"] = new Dictionary<string, object>
{
"pce", new Dictionary<string, object>
{
{ "name", "PC Engine" }, { "ports", 5 }, { "bytesPerPort", 2 },
{ "buttons", new[] { "B1", "B2", "Select", "Run", "Up", "Right", "Down", "Left" } }
}
["name"] = "PC Engine",
["ports"] = 5,
["bytesPerPort"] = 2,
["buttons"] = new[] { "B1", "B2", "Select", "Run", "Up", "Right", "Down", "Left" }
},
["lynx"] = new Dictionary<string, object>
{
"lynx", new Dictionary<string, object>
{
{ "name", "Lynx" }, { "ports", 2 }, { "bytesPerPort", 1 },
{ "buttons", new[] { "A", "B", "Up", "Down", "Left", "Right" }}
}
["name"] = "Lynx",
["ports"] = 2,
["bytesPerPort"] = 1,
["buttons"] = new[] { "A", "B", "Up", "Down", "Left", "Right" }
}
};
if (!platforms.ContainsKey(platform))
@ -1606,6 +1619,7 @@ namespace BizHawk.Client.Common
// Discard the first byte.
r.ReadByte();
}
ushort controllerState = r.ReadByte();
for (int button = 0; button < buttons.Length; button++)
{
@ -1613,6 +1627,7 @@ namespace BizHawk.Client.Common
controllers[prefix + buttons[button]] = ((controllerState >> button) & 0x1) != 0;
}
}
r.ReadByte();
if (platform == "nes" && warningMsg == "")
{
@ -1628,13 +1643,13 @@ namespace BizHawk.Client.Common
}
// MC2 file format: http://code.google.com/p/pcejin/wiki/MC2
private static BkmMovie ImportMC2(string path, out string errorMsg, out string warningMsg)
private static BkmMovie ImportMc2(string path, out string errorMsg, out string warningMsg)
{
return ImportText(path, out errorMsg, out warningMsg);
}
// MMV file format: http://tasvideos.org/MMV.html
private static BkmMovie ImportMMV(string path, out string errorMsg, out string warningMsg)
private static BkmMovie ImportMmv(string path, out string errorMsg, out string warningMsg)
{
errorMsg = warningMsg = "";
BkmMovie m = new BkmMovie(path);
@ -1695,7 +1710,7 @@ namespace BizHawk.Client.Common
m.Header[HeaderKeys.PAL] = pal.ToString();
// bit 2: Japan
bool japan = (((flags >> 2) & 0x1) != 0);
bool japan = ((flags >> 2) & 0x1) != 0;
m.Header[JAPAN] = japan.ToString();
// bit 3: Game Gear (version 1.16+)
@ -1767,7 +1782,7 @@ namespace BizHawk.Client.Common
}
// NMV file format: http://tasvideos.org/NMV.html
private static BkmMovie ImportNMV(string path, out string errorMsg, out string warningMsg)
private static BkmMovie ImportNmv(string path, out string errorMsg, out string warningMsg)
{
errorMsg = warningMsg = "";
var m = new BkmMovie(path);
@ -1997,6 +2012,7 @@ namespace BizHawk.Client.Common
{
continue;
}
byte controllerState = r.ReadByte();
if (player != 5)
{
@ -2035,6 +2051,7 @@ namespace BizHawk.Client.Common
fs.Close();
return null;
}
m.Header[HeaderKeys.PLATFORM] = "SNES";
// 004 4-byte little-endian unsigned int: version number
@ -2057,6 +2074,7 @@ namespace BizHawk.Client.Common
fs.Close();
return null;
}
m.Comments.Add(EMULATIONORIGIN + " Snes9x version " + version);
m.Comments.Add(MOVIEORIGIN + " .SMV");
/*
@ -2104,8 +2122,9 @@ namespace BizHawk.Client.Common
}
// bit 1: if "0", movie is NTSC (60 fps); if "1", movie is PAL (50 fps)
bool pal = (((movieFlags >> 1) & 0x1) != 0);
bool pal = ((movieFlags >> 1) & 0x1) != 0;
m.Header[HeaderKeys.PAL] = pal.ToString();
// other: reserved, set to 0
/*
016 1-byte flags "sync options":
@ -2279,7 +2298,7 @@ namespace BizHawk.Client.Common
}
ushort controllerState = (ushort)(((controllerState1 << 4) & 0x0F00) | controllerState2);
if (player <= BkmMnemonicConstants.PLAYERS[controllers.Definition.Name])
if (player <= BkmMnemonicConstants.Players[controllers.Definition.Name])
{
for (int button = 0; button < buttons.Length; button++)
{
@ -2398,7 +2417,7 @@ namespace BizHawk.Client.Common
bool[] controllersUsed = new bool[4];
for (int controller = 1; controller <= controllersUsed.Length; controller++)
{
controllersUsed[controller - 1] = (((controllerFlags >> (controller - 1)) & 0x1) != 0);
controllersUsed[controller - 1] = ((controllerFlags >> (controller - 1)) & 0x1) != 0;
}
if (!controllersUsed[0])
@ -2502,7 +2521,7 @@ namespace BizHawk.Client.Common
032 2-byte little-endian unsigned short: the internal Checksum of the ROM used while recording, or a
calculated CRC16 of the BIOS if GBA
*/
ushort checksum_crc16 = r.ReadUInt16();
ushort checksumCRC16 = r.ReadUInt16();
/*
034 4-byte little-endian unsigned int: the Game Code of the ROM used while recording, or the Unit Code if not
GBA
@ -2510,12 +2529,12 @@ namespace BizHawk.Client.Common
uint gameCodeUnitCode = r.ReadUInt32();
if (platform == "GBA")
{
m.Header[CRC16] = checksum_crc16.ToString();
m.Header[CRC16] = checksumCRC16.ToString();
m.Header[GAMECODE] = gameCodeUnitCode.ToString();
}
else
{
m.Header[INTERNALCHECKSUM] = checksum_crc16.ToString();
m.Header[INTERNALCHECKSUM] = checksumCRC16.ToString();
m.Header[UNITCODE] = gameCodeUnitCode.ToString();
}
@ -2534,14 +2553,10 @@ namespace BizHawk.Client.Common
m.Comments.Add(COMMENT + " " + movieDescription);
r.BaseStream.Position = firstFrameOffset;
SimpleController controllers = new SimpleController { Definition = new ControllerDefinition() };
if (platform != "GBA")
{
controllers.Definition.Name = "Gameboy Controller";
}
else
{
controllers.Definition.Name = "GBA Controller";
}
controllers.Definition.Name = platform != "GBA"
? "Gameboy Controller"
: "GBA Controller";
/*
* 01 00 A
* 02 00 B
@ -2654,10 +2669,10 @@ namespace BizHawk.Client.Common
bool[] controllersUsed = new bool[4];
for (int controller = 1; controller <= controllersUsed.Length; controller++)
{
controllersUsed[controller - 1] = (((flags >> (controller - 1)) & 0x1) != 0);
controllersUsed[controller - 1] = ((flags >> (controller - 1)) & 0x1) != 0;
}
bool fourscore = (controllersUsed[2] || controllersUsed[3]);
bool fourscore = controllersUsed[2] || controllersUsed[3];
m.Header[HeaderKeys.FOURSCORE] = fourscore.ToString();
/*
bit 6: 1=reset-based, 0=savestate-based (movie version <= 0x300 is always savestate-based)
@ -2678,6 +2693,7 @@ namespace BizHawk.Client.Common
becomes the controller data. TODO: Figure out what this means.
Other bits: reserved, set to 0
*/
// 014 DWORD Ext0; // ROM:program CRC FDS:program ID
r.ReadBytes(4);
@ -2705,7 +2721,7 @@ namespace BizHawk.Client.Common
r.ReadByte();
// 023 1-byte flag: 0=NTSC (60 Hz), 1="PAL" (50 Hz)
bool pal = (r.ReadByte() == 1);
bool pal = r.ReadByte() == 1;
m.Header[HeaderKeys.PAL] = pal.ToString();
// 024 8-bytes: reserved, set to 0
@ -2978,8 +2994,9 @@ namespace BizHawk.Client.Common
// if "11", movie begins from power-on with SRAM clear
// bit 5: if "0", movie is NTSC (60 fps); if "1", movie is PAL (50 fps)
bool pal = (((movieFlags >> 5) & 0x1) != 0);
bool pal = ((movieFlags >> 5) & 0x1) != 0;
m.Header[HeaderKeys.PAL] = pal.ToString();
// other: reserved, set to 0
/*
028 3-byte little-endian unsigned int: initial save state size, highest bit specifies compression, next 23
@ -3037,7 +3054,8 @@ namespace BizHawk.Client.Common
m.AppendFrame(controllers);
controllers["Reset"] = false;
}
// TODO: Other commands.
/*TODO: Other commands.*/
}
else if (((flag >> 1) & 0x1) != 0)
{
@ -3147,8 +3165,9 @@ namespace BizHawk.Client.Common
controllerState |= (uint)(controllerState2 << 12);
}
}
leftOver = !leftOver;
if (player <= BkmMnemonicConstants.PLAYERS[controllers.Definition.Name])
if (player <= BkmMnemonicConstants.Players[controllers.Definition.Name])
{
if (player != 2 || !superScope)
{

View File

@ -277,6 +277,7 @@ namespace BizHawk.Client.Common
{
controllers["Open"] = true;
}
isCdTrayOpen = !isCdTrayOpen;
}
else
@ -384,7 +385,6 @@ namespace BizHawk.Client.Common
string rightXRaw = new string(br.ReadChars(4)).Trim();
string rightYRaw = new string(br.ReadChars(4)).Trim();
Tuple<string, float> leftX = new Tuple<string, float>("P2 LStick X", float.Parse(leftXRaw));
Tuple<string, float> leftY = new Tuple<string, float>("P2 LStick Y", float.Parse(leftYRaw));
Tuple<string, float> rightX = new Tuple<string, float>("P2 RStick X", float.Parse(rightXRaw));
@ -410,6 +410,7 @@ namespace BizHawk.Client.Common
{
controllers["Open"] = true;
}
isCdTrayOpen = !isCdTrayOpen;
}
else
@ -443,6 +444,5 @@ namespace BizHawk.Client.Common
public bool parseSuccessful = false;
}
}
}

View File

@ -57,23 +57,40 @@ namespace BizHawk.Client.Common
bool wasValue;
if (frame < LagLog.Count)
{
wasValue = LagLog[frame];
}
else if (frame == WasLag.Count)
{
wasValue = value.Value;
}
else
{
wasValue = WasLag[frame];
}
if (frame == WasLag.Count)
{
WasLag.Add(wasValue);
}
else
{
WasLag[frame] = wasValue;
}
if (frame != 0)
{
WasLag[frame - 1] = LagLog[frame - 1];
}
if (frame >= LagLog.Count)
{
LagLog.Add(value.Value);
}
else
{
LagLog[frame] = value.Value;
}
}
}

View File

@ -321,7 +321,10 @@ namespace BizHawk.Client.Common
for (int i = 0; i < states.Count; i++)
{
if (_log.Count <= frame + i)
{
break;
}
lg.SetSource(states[i]);
_log[frame + i] = lg.GenerateLogEntry();
}

View File

@ -460,6 +460,7 @@ namespace BizHawk.Client.Common
{
movie.InsertEmptyFrame(FirstFrame, length - _undoLength);
}
if (_redoLength != length)
{
movie.RemoveFrames(FirstFrame, movie.InputLogLength - _redoLength);

View File

@ -77,7 +77,9 @@ namespace BizHawk.Client.Common
}
if (!backup)
{
Changes = false;
}
}
public override bool Load(bool preload)
@ -268,7 +270,9 @@ namespace BizHawk.Client.Common
// Movie should always have a state at frame 0.
if (!StartsFromSavestate && Global.Emulator.Frame == 0)
{
_stateManager.Capture();
}
}
}

View File

@ -242,6 +242,7 @@ namespace BizHawk.Client.Common
{
OnListChanged(NotifyCollectionChangedAction.Remove);
}
return removeCount;
}

View File

@ -67,15 +67,9 @@ namespace BizHawk.Client.Common
}
}
private int maxStates
{
get { return (int)(Settings.Cap / _expectedStateSize) + (int)((ulong)Settings.DiskCapacitymb * 1024 * 1024 / _expectedStateSize); }
}
private int maxStates => (int)(Settings.Cap / _expectedStateSize) + (int)((ulong)Settings.DiskCapacitymb * 1024 * 1024 / _expectedStateSize);
private int _stateGap
{
get { return 1 << Settings.StateGap; }
}
private int _stateGap => 1 << Settings.StateGap;
public TasStateManager(TasMovie movie)
{
@ -86,7 +80,9 @@ namespace BizHawk.Client.Common
accessed = new List<StateManagerState>();
if (_movie.StartsFromSavestate)
{
SetState(0, _movie.BinarySavestate);
}
}
public void Dispose()
@ -215,7 +211,11 @@ namespace BizHawk.Client.Common
if (Used > Settings.Cap)
{
int lastMemState = -1;
do { lastMemState++; } while (States[accessed[lastMemState].Frame] == null);
do
{
lastMemState++;
}
while (States[accessed[lastMemState].Frame] == null);
MoveStateToDisk(accessed[lastMemState].Frame);
}
}
@ -260,7 +260,8 @@ namespace BizHawk.Client.Common
}
i++;
} while (StateIsMarker(shouldRemove.X, shouldRemove.Y) && markerSkips > -1 || shouldRemove.X == 0);
}
while (StateIsMarker(shouldRemove.X, shouldRemove.Y) && markerSkips > -1 || shouldRemove.X == 0);
// by last accessed
markerSkips = maxStates / 2;
@ -286,7 +287,8 @@ namespace BizHawk.Client.Common
}
i++;
} while (StateIsMarker(shouldRemove.X, shouldRemove.Y) && markerSkips > -1 || shouldRemove.X == 0);
}
while (StateIsMarker(shouldRemove.X, shouldRemove.Y) && markerSkips > -1 || shouldRemove.X == 0);
}
if (shouldRemove.X < 1) // only found marker states above
@ -557,7 +559,12 @@ namespace BizHawk.Client.Common
int index = -1;
while (DiskUsed > (ulong)Settings.DiskCapacitymb * 1024uL * 1024uL)
{
do { index++; } while (!accessed[index].IsOnDisk);
do
{
index++;
}
while (!accessed[index].IsOnDisk);
accessed[index].MoveToRAM();
}
@ -576,16 +583,22 @@ namespace BizHawk.Client.Common
// still leave marker states
for (int i = 1; i < States.Count; i++)
{
if (_movie.Markers.IsMarker(States.ElementAt(i).Key + 1) ||
States.ElementAt(i).Key % _stateGap == 0)
if (_movie.Markers.IsMarker(States.ElementAt(i).Key + 1)
|| States.ElementAt(i).Key % _stateGap == 0)
{
continue;
}
ret.Add(i);
if (States.ElementAt(i).Value.IsOnDisk)
{
saveUsed -= _expectedStateSize;
}
else
{
saveUsed -= (ulong)States.ElementAt(i).Value.Length;
}
}
// if the size is still too big, exclude states form the beginning
@ -597,19 +610,27 @@ namespace BizHawk.Client.Common
{
index++;
if (index >= States.Count)
{
break;
}
}
while (_movie.Markers.IsMarker(States.ElementAt(index).Key + 1));
if (index >= States.Count)
{
break;
}
ret.Add(index);
if (States.ElementAt(index).Value.IsOnDisk)
{
saveUsed -= _expectedStateSize;
}
else
{
saveUsed -= (ulong)States.ElementAt(index).Value.Length;
}
}
// if there are enough markers to still be over the limit, remove marker frames
@ -618,11 +639,18 @@ namespace BizHawk.Client.Common
{
index++;
if (!ret.Contains(index))
{
ret.Add(index);
}
if (States.ElementAt(index).Value.IsOnDisk)
{
saveUsed -= _expectedStateSize;
}
else
{
saveUsed -= (ulong)States.ElementAt(index).Value.Length;
}
}
return ret;
@ -636,7 +664,9 @@ namespace BizHawk.Client.Common
for (int i = 0; i < States.Count; i++)
{
if (noSave.Contains(i))
{
continue;
}
StateAccessed(States.ElementAt(i).Key);
KeyValuePair<int, StateManagerState> kvp = States.ElementAt(i);
@ -715,7 +745,6 @@ namespace BizHawk.Client.Common
}
}
public KeyValuePair<int, byte[]> GetStateClosestToFrame(int frame)
{
var s = States.LastOrDefault(state => state.Key < frame);
@ -816,7 +845,9 @@ namespace BizHawk.Client.Common
// Get the state instance
if (branchHash == -1)
{
stateToMatch = States[frame];
}
else
{
if (!BranchStates[frame].ContainsKey(branchHash))

View File

@ -69,6 +69,7 @@ namespace BizHawk.Client.Common
{
savestateCopy = null;
}
if (savestateCopy == null)
{
savestateCopy = new byte[coreSavestate.Length];

View File

@ -197,6 +197,7 @@ namespace BizHawk.Client.Common
{
_lastState = new byte[length];
}
Buffer.BlockCopy(state, index, _lastState, 0, length);
}

View File

@ -305,6 +305,7 @@ namespace BizHawk.Client.Common
test_rewindFellationBuf = inbuf;
return null;
}
static byte[] test_rewindFellationBuf;
private static void test(string[] args)
@ -317,11 +318,17 @@ namespace BizHawk.Client.Common
{
int len = r.Next(1024) + 1;
if (r.Next(100) == 0)
{
len = 1024;
}
ArraySegment<byte> seg = new ArraySegment<byte>(temp, 0, len);
Console.WriteLine("{0} - {1}", trials, seg.Count);
if (seg.Count == 1024)
{
Console.Write("*************************");
}
trials++;
sbb.Push(seg);
}

View File

@ -196,38 +196,44 @@ namespace BizHawk.Client.Common
{
_watch.Poke(GetStringForPulse(_val));
}
break;
case COMPARISONTYPE.GREATER_THAN:
if (_compare.Value > _watch.ValueNoFreeze)
{
_watch.Poke(GetStringForPulse(_val));
}
break;
case COMPARISONTYPE.GREATER_THAN_OR_EQUAL:
if (_compare.Value >= _watch.ValueNoFreeze)
{
_watch.Poke(GetStringForPulse(_val));
}
break;
case COMPARISONTYPE.LESS_THAN:
if (_compare.Value < _watch.ValueNoFreeze)
{
_watch.Poke(GetStringForPulse(_val));
}
break;
case COMPARISONTYPE.LESS_THAN_OR_EQUAL:
if (_compare.Value <= _watch.ValueNoFreeze)
{
_watch.Poke(GetStringForPulse(_val));
}
break;
case COMPARISONTYPE.NOT_EQUAL:
if (_compare.Value != _watch.ValueNoFreeze)
{
_watch.Poke(GetStringForPulse(_val));
}
break;
}
}
}
else
{

View File

@ -49,7 +49,6 @@
/// This tool dialog edits a file. Returning false will tell the client the user wants to cancel the given action,
/// Return false to tell the client to back out of an action (such as closing the emulator)
/// </summary>
/// <returns></returns>
bool AskSaveChanges();
/// <summary>

View File

@ -1083,6 +1083,7 @@ namespace BizHawk.Client.Common
{
_previous = _prevFrame;
}
break;
}

View File

@ -54,7 +54,7 @@
FixedPoint_16_16,
/// <summary>
/// The traditionnal float type as in C++ <seealso cref="float"/>
/// The traditional float type as in C++ <seealso cref="float"/>
/// Used only by <see cref="DWordWatch"/> as it is 32 bits length
/// </summary>
Float

View File

@ -15,7 +15,6 @@ namespace BizHawk.Client.Common
private sealed class WatchValueDifferenceComparer
: WatchEqualityComparer, IComparer<Watch>
{
/// <summary>
/// Compares two <see cref="Watch"/> between them
/// and determines which one comes first.