This commit is contained in:
adelikat 2019-12-22 11:13:53 -06:00
parent d8eaafd47f
commit a7ccc3fdef
7 changed files with 153 additions and 174 deletions

View File

@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
@ -15,8 +10,8 @@ namespace BizHawk.Client.EmuHawk
{
public partial class BatchRun : Form
{
Thread thread = null;
List<BatchRunner.Result> MostRecentResults = null;
private Thread _thread;
private List<BatchRunner.Result> _mostRecentResults;
public BatchRun()
{
@ -25,10 +20,9 @@ namespace BizHawk.Client.EmuHawk
private void listBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link;
else
e.Effect = DragDropEffects.None;
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop)
? DragDropEffects.Link
: DragDropEffects.None;
}
private void SetCount()
@ -54,7 +48,7 @@ namespace BizHawk.Client.EmuHawk
private void buttonGo_Click(object sender, EventArgs e)
{
if (thread != null)
if (_thread != null)
{
MessageBox.Show("Old one still running!");
}
@ -67,23 +61,26 @@ namespace BizHawk.Client.EmuHawk
else
{
label3.Text = "Status: Running...";
int nframes = (int)numericUpDownFrames.Value;
int numFrames = (int)numericUpDownFrames.Value;
List<string> files = new List<string>(listBox1.Items.Count);
foreach (string s in listBox1.Items)
{
files.Add(s);
thread = new Thread(ThreadProc);
thread.Start(new Tuple<int, List<string>>(nframes, files));
}
_thread = new Thread(ThreadProc);
_thread.Start(new Tuple<int, List<string>>(numFrames, files));
}
}
}
void ProgressUpdate(int curr, int max)
private void ProgressUpdate(int curr, int max)
{
progressBar1.Maximum = max;
progressBar1.Value = curr;
}
void ThreadProc(object o)
private void ThreadProc(object o)
{
try
{
@ -91,14 +88,14 @@ namespace BizHawk.Client.EmuHawk
BatchRunner br = new BatchRunner(pp.Item2, pp.Item1);
br.OnProgress += br_OnProgress;
var results = br.Run();
this.Invoke(() => { label3.Text = "Status: Finished!"; MostRecentResults = results; });
this.Invoke(() => { label3.Text = "Status: Finished!"; _mostRecentResults = results; });
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "The Whole Thing Died!");
this.Invoke(() => label3.Text = "Deaded!");
}
this.Invoke(() => thread = null);
this.Invoke(() => _thread = null);
}
void br_OnProgress(object sender, BatchRunner.ProgressEventArgs e)
@ -109,7 +106,7 @@ namespace BizHawk.Client.EmuHawk
private void BatchRun_FormClosing(object sender, FormClosingEventArgs e)
{
if (thread != null)
if (_thread != null)
{
MessageBox.Show("Can't close while task is running!");
e.Cancel = true;
@ -118,18 +115,16 @@ namespace BizHawk.Client.EmuHawk
private void buttonDump_Click(object sender, EventArgs e)
{
if (MostRecentResults != null)
if (_mostRecentResults != null)
{
using (var sfd = new SaveFileDialog())
using var sfd = new SaveFileDialog();
var result = sfd.ShowDialog(this);
if (result == DialogResult.OK)
{
var result = sfd.ShowDialog(this);
if (result == DialogResult.OK)
using TextWriter tw = new StreamWriter(sfd.FileName);
foreach (var r in _mostRecentResults)
{
using (TextWriter tw = new StreamWriter(sfd.FileName))
{
foreach (var r in MostRecentResults)
r.DumpToTW(tw);
}
r.DumpTo(tw);
}
}
}

View File

@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using BizHawk.Common;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
using BizHawk.Emulation.Cores.Nintendo.GBA;
namespace BizHawk.Client.EmuHawk
{
@ -15,196 +13,198 @@ namespace BizHawk.Client.EmuHawk
{
public class ProgressEventArgs
{
public int Completed { get; private set; }
public int Total { get; private set; }
public int Completed { get; }
public int Total { get; }
public bool ShouldCancel { get; set; }
public ProgressEventArgs(int Completed, int Total)
public ProgressEventArgs(int completed, int total)
{
this.Completed = Completed;
this.Total = Total;
Completed = completed;
Total = total;
}
}
public delegate void ProgressEventHandler(object sender, ProgressEventArgs e);
public event ProgressEventHandler OnProgress;
List<string> files;
RomLoader ldr;
CoreComm Comm;
int numframes = 0;
int multiindex = 0;
bool multihasnext = false;
private readonly List<string> _files;
private readonly List<Result> _results = new List<Result>();
private readonly RomLoader _ldr;
private readonly CoreComm _comm;
private readonly int _numFrames;
List<Result> Results = new List<Result>();
Result current;
private int _multiIndex;
private bool _multiHasNext;
private Result _current;
public class Result
{
public string Filename; // name of file
public string Fullname; // filename + subfilename
public GameInfo GI;
public string Filename { get; set; } // name of file
public string Fullname { get; set; } // filename + subfilename
public GameInfo Game { get; set; }
public Type CoreType; // actual type of the core that was returned
public Type CoreType { get; set; } // actual type of the core that was returned
public enum EStatus
{
ExceptOnLoad, // exception thrown on load
ErrorOnLoad, // error method thrown on load
FalseOnLoad, // romloader returned false with no other information
FalseOnLoad, // RomLoader returned false with no other information
ExceptOnAdv, // exception thrown on frame advance
Success, // load fully complete
};
public EStatus Status; // what happened
public List<string> Messages = new List<string>();
}
public int Frames; // number of frames successfully run
public int LaggedFrames; // number of those that were lagged
public EStatus Status { get; set; } // what happened
public List<string> Messages { get; set; } = new List<string>();
public string BoardName; // iemulator's board name return (could be null!)
public int Frames { get; set; } // number of frames successfully run
public int LaggedFrames { get; set; } // number of those that were lagged
public void DumpToTW(System.IO.TextWriter tw)
public string BoardName { get; set; } // IEmulator's board name return (could be null!)
public void DumpTo(TextWriter tw)
{
tw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}", Filename, Fullname, CoreType, Status, Frames, LaggedFrames, GI.Hash, BoardName);
tw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}", Filename, Fullname, CoreType, Status, Frames, LaggedFrames, Game.Hash, BoardName);
}
}
public BatchRunner(IEnumerable<string> files, int numframes)
public BatchRunner(IEnumerable<string> files, int numFrames)
{
this.files = new List<string>(files);
this.numframes = numframes;
_files = new List<string>(files);
_numFrames = numFrames;
ldr = new RomLoader();
ldr.OnLoadError += OnLoadError;
ldr.ChooseArchive = ChooseArchive;
Comm = new CoreComm(CommMessage, CommMessage);
CoreFileProvider.SyncCoreCommInputSignals(Comm);
_ldr = new RomLoader();
_ldr.OnLoadError += OnLoadError;
_ldr.ChooseArchive = ChooseArchive;
_comm = new CoreComm(CommMessage, CommMessage);
CoreFileProvider.SyncCoreCommInputSignals(_comm);
}
void OnLoadError(object sender, RomLoader.RomErrorArgs e)
private void OnLoadError(object sender, RomLoader.RomErrorArgs e)
{
current.Status = Result.EStatus.ErrorOnLoad;
current.Messages.Add($"{nameof(OnLoadError)}: {e.AttemptedCoreLoad}, {e.Message}, {e.Type}");
_current.Status = Result.EStatus.ErrorOnLoad;
_current.Messages.Add($"{nameof(OnLoadError)}: {e.AttemptedCoreLoad}, {e.Message}, {e.Type}");
}
void CommMessage(string msg)
private void CommMessage(string msg)
{
current.Messages.Add($"{nameof(CommMessage)}: {msg}");
_current.Messages.Add($"{nameof(CommMessage)}: {msg}");
}
int? ChooseArchive(HawkFile hf)
private int? ChooseArchive(HawkFile hf)
{
int ret = multiindex;
multiindex++;
multihasnext = multiindex < hf.ArchiveItems.Count;
int ret = _multiIndex;
_multiIndex++;
_multiHasNext = _multiIndex < hf.ArchiveItems.Count;
return ret;
}
public List<Result> Run()
{
Results.Clear();
current = null;
_results.Clear();
_current = null;
RunInternal();
return new List<Result>(Results);
return new List<Result>(_results);
}
void RunInternal()
private void RunInternal()
{
for (int i = 0; i < files.Count; i++)
for (int i = 0; i < _files.Count; i++)
{
string f = files[i];
multihasnext = false;
multiindex = 0;
string f = _files[i];
_multiHasNext = false;
_multiIndex = 0;
do
{
LoadOne(f);
} while (multihasnext);
} while (_multiHasNext);
if (OnProgress != null)
{
var e = new ProgressEventArgs(i + 1, files.Count);
var e = new ProgressEventArgs(i + 1, _files.Count);
OnProgress(this, e);
if (e.ShouldCancel)
{
return;
}
}
}
}
void LoadOne(string f)
private void LoadOne(string f)
{
current = new Result { Filename = f };
bool result = false;
_current = new Result { Filename = f };
bool result;
try
{
result = ldr.LoadRom(f, Comm);
result = _ldr.LoadRom(f, _comm);
}
catch (Exception e)
{
current.Status = Result.EStatus.ExceptOnLoad;
current.Messages.Add(e.ToString());
Results.Add(current);
current = null;
_current.Status = Result.EStatus.ExceptOnLoad;
_current.Messages.Add(e.ToString());
_results.Add(_current);
_current = null;
return;
}
current.Fullname = ldr.CanonicalFullPath;
if (current.Status == Result.EStatus.ErrorOnLoad)
_current.Fullname = _ldr.CanonicalFullPath;
if (_current.Status == Result.EStatus.ErrorOnLoad)
{
Results.Add(current);
current = null;
_results.Add(_current);
_current = null;
return;
}
if (result == false)
{
current.Status = Result.EStatus.FalseOnLoad;
Results.Add(current);
current = null;
_current.Status = Result.EStatus.FalseOnLoad;
_results.Add(_current);
_current = null;
return;
}
using (IEmulator emu = ldr.LoadedEmulator)
using (IEmulator emu = _ldr.LoadedEmulator)
{
current.GI = ldr.Game;
current.CoreType = emu.GetType();
_current.Game = _ldr.Game;
_current.CoreType = emu.GetType();
var controller = new Controller(emu.ControllerDefinition);
current.BoardName = emu.HasBoardInfo() ? emu.AsBoardInfo().BoardName : null;
_current.BoardName = emu.HasBoardInfo() ? emu.AsBoardInfo().BoardName : null;
// hack
if (emu is Emulation.Cores.Nintendo.GBA.VBANext)
if (emu is VBANext vba)
{
current.BoardName = (emu as Emulation.Cores.Nintendo.GBA.VBANext).GameCode;
_current.BoardName = vba.GameCode;
}
current.Frames = 0;
current.LaggedFrames = 0;
_current.Frames = 0;
_current.LaggedFrames = 0;
for (int i = 0; i < numframes; i++)
for (int i = 0; i < _numFrames; i++)
{
try
{
int nsamp;
short[] samp;
emu.FrameAdvance(controller, true, true);
emu.FrameAdvance(controller, true);
// some cores really really really like it if you drain their audio every frame
if (emu.HasSoundProvider())
{
emu.AsSoundProvider().GetSamplesSync(out samp, out nsamp);
emu.AsSoundProvider().GetSamplesSync(out _, out _);
}
current.Frames++;
_current.Frames++;
if (emu.CanPollInput() && emu.AsInputPollable().IsLagFrame)
current.LaggedFrames++;
_current.LaggedFrames++;
}
catch (Exception e)
{
current.Messages.Add(e.ToString());
current.Status = Result.EStatus.ExceptOnAdv;
Results.Add(current);
current = null;
_current.Messages.Add(e.ToString());
_current.Status = Result.EStatus.ExceptOnAdv;
_results.Add(_current);
_current = null;
return;
}
}
}
current.Status = Result.EStatus.Success;
Results.Add(current);
current = null;
return;
_current.Status = Result.EStatus.Success;
_results.Add(_current);
_current = null;
}
}
}

View File

@ -19,13 +19,13 @@ namespace BizHawk.Client.EmuHawk
{
public partial class CDL : ToolFormBase, IToolFormAutoConfig
{
private RecentFiles _recent_fld = new RecentFiles();
private RecentFiles _recentFld = new RecentFiles();
[ConfigPersist]
private RecentFiles _recent
{
get => _recent_fld;
set => _recent_fld = value;
get => _recentFld;
set => _recentFld = value;
}
void SetCurrentFilename(string fname)
@ -42,7 +42,7 @@ namespace BizHawk.Client.EmuHawk
[RequiredService]
private ICodeDataLogger CodeDataLogger { get; set; }
private string _currentFilename = null;
private string _currentFilename;
private CodeDataLog _cdl;
public CDL()
@ -95,12 +95,12 @@ namespace BizHawk.Client.EmuHawk
UpdateDisplay(true);
}
void SetLoggingActiveCheck(bool value)
private void SetLoggingActiveCheck(bool value)
{
tsbLoggingActive.Checked = value;
}
string[][] listContents = new string[0][];
private string[][] _listContents = new string[0][];
private void UpdateDisplay(bool force)
{
@ -114,7 +114,7 @@ namespace BizHawk.Client.EmuHawk
return;
}
listContents = new string[_cdl.Count][];
_listContents = new string[_cdl.Count][];
int idx = 0;
foreach (var kvp in _cdl)
@ -155,7 +155,7 @@ namespace BizHawk.Client.EmuHawk
var bm = _cdl.GetBlockMap();
long addr = bm[kvp.Key];
var lvi = listContents[idx++] = new string[13];
var lvi = _listContents[idx++] = new string[13];
lvi[0] = $"{addr:X8}";
lvi[1] = kvp.Key;
lvi[2] = $"{total / (float)kvp.Value.Length * 100f:0.00}%";
@ -229,7 +229,7 @@ namespace BizHawk.Client.EmuHawk
public bool UpdateBefore => false;
bool autoloading = false;
private bool _autoloading;
public void LoadFile(string path)
{
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
@ -242,7 +242,7 @@ namespace BizHawk.Client.EmuHawk
CodeDataLogger.NewCDL(testCDL);
if (!newCDL.Check(testCDL))
{
if(!autoloading)
if(!_autoloading)
MessageBox.Show(this, "CDL file does not match emulator's current memory map!");
return;
}
@ -483,31 +483,33 @@ namespace BizHawk.Client.EmuHawk
{
try
{
autoloading = true;
var autoresume_file = $"{PathManager.FilesystemSafeName(Global.Game)}.cdl";
var autoresume_dir = PathManager.MakeAbsolutePath(Config.PathEntries.LogPathFragment, null);
var autoresume_path = Path.Combine(autoresume_dir, autoresume_file);
if (File.Exists(autoresume_path))
LoadFile(autoresume_path);
_autoloading = true;
var autoResumeFile = $"{PathManager.FilesystemSafeName(Global.Game)}.cdl";
var autoResumeDir = PathManager.MakeAbsolutePath(Config.PathEntries.LogPathFragment, null);
var autoResumePath = Path.Combine(autoResumeDir, autoResumeFile);
if (File.Exists(autoResumePath))
{
LoadFile(autoResumePath);
}
}
finally
{
autoloading = false;
_autoloading = false;
}
}
if (_recent_fld.AutoLoad && !_recent_fld.Empty)
if (_recentFld.AutoLoad && !_recentFld.Empty)
{
if (File.Exists(_recent.MostRecent))
{
try
{
autoloading = true;
_autoloading = true;
LoadFile(_recent.MostRecent);
}
finally
{
autoloading = false;
_autoloading = false;
}
SetCurrentFilename(_recent.MostRecent);
}
@ -552,13 +554,13 @@ namespace BizHawk.Client.EmuHawk
private void lvCDL_QueryItemText(int index, RollColumn column, out string text, ref int offsetX, ref int offsetY)
{
var subItem = lvCDL.AllColumns.IndexOf(column);
text = listContents[index][subItem];
text = _listContents[index][subItem];
}
private void tsbExportText_Click(object sender, EventArgs e)
{
using var sw = new StringWriter();
foreach(var line in listContents)
foreach(var line in _listContents)
{
foreach (var entry in line)
sw.Write("{0} |", entry);

View File

@ -102,7 +102,6 @@
this.DebugSubMenu.Name = "DebugSubMenu";
this.DebugSubMenu.Size = new System.Drawing.Size(50, 20);
this.DebugSubMenu.Text = "&Debug";
this.DebugSubMenu.DropDownOpened += new System.EventHandler(this.DebugSubMenu_DropDownOpened);
//
// StepIntoMenuItem
//
@ -367,7 +366,6 @@
this.Name = "GenericDebugger";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Debugger";
this.Load += new System.EventHandler(this.GenericDebugger_Load);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.GenericDebugger_MouseMove);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();

View File

@ -4,7 +4,6 @@ using System.Linq;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
@ -40,10 +39,6 @@ namespace BizHawk.Client.EmuHawk
});
}
private void GenericDebugger_Load(object sender, EventArgs e)
{
}
private void EngageDebugger()
{
_disassemblyLines.Clear();
@ -185,7 +180,7 @@ namespace BizHawk.Client.EmuHawk
private void OnCpuDropDownIndexChanged(object sender, EventArgs e)
{
Disassembler.Cpu = (sender as ComboBox).SelectedItem.ToString();
Disassembler.Cpu = ((ComboBox) sender).SelectedItem.ToString();
}
#region File
@ -199,10 +194,6 @@ namespace BizHawk.Client.EmuHawk
#region Debug
private void DebugSubMenu_DropDownOpened(object sender, EventArgs e)
{
}
private void RunBtn_Click(object sender, EventArgs e)
{
GlobalWin.MainForm.UnpauseEmulator();

View File

@ -72,9 +72,9 @@ namespace BizHawk.Client.EmuHawk
var tsb = new ToolStripButton
{
Image = (instance as Form).Icon.ToBitmap(),
Text = (instance as Form).Text,
DisplayStyle = (instance as Form).ShowIcon ? ToolStripItemDisplayStyle.Image : ToolStripItemDisplayStyle.Text
Image = ((Form) instance).Icon.ToBitmap(),
Text = ((Form) instance).Text,
DisplayStyle = ((Form) instance).ShowIcon ? ToolStripItemDisplayStyle.Image : ToolStripItemDisplayStyle.Text
};
tsb.Click += (o, e) =>
@ -94,13 +94,7 @@ namespace BizHawk.Client.EmuHawk
}
// Provide LINQ capabilities to an outdated form collection
private IEnumerable<ToolStripItem> ToolBoxItems
{
get
{
return ToolBoxStrip.Items.Cast<ToolStripItem>();
}
}
private IEnumerable<ToolStripItem> ToolBoxItems => ToolBoxStrip.Items.Cast<ToolStripItem>();
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
@ -109,10 +103,8 @@ namespace BizHawk.Client.EmuHawk
Close();
return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
}

View File

@ -344,6 +344,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stateable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subdirectory/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Subfile/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subfilename/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subframe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Subshell/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Syncless/@EntryIndexedValue">True</s:Boolean>