diff --git a/MixAssembler/Assembler.cs b/MixAssembler/Assembler.cs index a1969c3..c28f7ac 100644 --- a/MixAssembler/Assembler.cs +++ b/MixAssembler/Assembler.cs @@ -84,9 +84,11 @@ public static InstructionInstanceBase[] Assemble(string[] sourceLines, out PreIn public static InstructionInstanceBase Assemble(string instructionLine, int locationCounter, out ParsedSourceLine parsedLine, SymbolCollection symbols, out AssemblyFindingCollection findings) { - var status = new ParsingStatus(symbols); - status.LocationCounter = locationCounter; - status.LineNumber = 0; + var status = new ParsingStatus(symbols) + { + LocationCounter = locationCounter, + LineNumber = 0 + }; parsedLine = Parser.ParseInstructionLine(instructionLine, status); findings = status.Findings; diff --git a/MixAssembler/Finding/AssemblyFindingCollection.cs b/MixAssembler/Finding/AssemblyFindingCollection.cs index 1ab905f..873db34 100644 --- a/MixAssembler/Finding/AssemblyFindingCollection.cs +++ b/MixAssembler/Finding/AssemblyFindingCollection.cs @@ -5,15 +5,15 @@ namespace MixAssembler.Finding { public class AssemblyFindingCollection : Collection { - public bool ContainsDebugs => contains(Severity.Debug); + public bool ContainsDebugs => Contains(Severity.Debug); - public bool ContainsErrors => contains(Severity.Error); + public bool ContainsErrors => Contains(Severity.Error); - public bool ContainsInfos => contains(Severity.Info); + public bool ContainsInfos => Contains(Severity.Info); - public bool ContainsWarnings => contains(Severity.Warning); + public bool ContainsWarnings => Contains(Severity.Warning); - bool contains(Severity severity) + bool Contains(Severity severity) { foreach (AssemblyFinding finding in Items) { diff --git a/MixAssembler/Instruction/MixInstructionParameters.cs b/MixAssembler/Instruction/MixInstructionParameters.cs index f1a1945..a50b1ab 100644 --- a/MixAssembler/Instruction/MixInstructionParameters.cs +++ b/MixAssembler/Instruction/MixInstructionParameters.cs @@ -30,7 +30,7 @@ public class MixInstructionParameters : IInstructionParameters mTextLength = textLength; } - bool areValuesDefined(AssemblingStatus status) + bool AreValuesDefined(AssemblingStatus status) { if (!mAddress.IsValueDefined(status.LocationCounter)) { @@ -68,7 +68,7 @@ public InstructionInstanceBase CreateInstance(InstructionBase instruction, Assem var mixInstruction = (MixInstruction)instruction; - if (!areValuesDefined(status)) return null; + if (!AreValuesDefined(status)) return null; var addressMagnitude = mAddress.GetMagnitude(status.LocationCounter); var word = new Word(MixInstruction.AddressByteCount); @@ -79,12 +79,14 @@ public InstructionInstanceBase CreateInstance(InstructionBase instruction, Assem } word.MagnitudeLongValue = addressMagnitude; - var fieldSpecValue = getFieldSpecValue(status, mixInstruction); + var fieldSpecValue = GetFieldSpecValue(status, mixInstruction); if (fieldSpecValue == null) return null; - var instructionWord = new FullWord(); - instructionWord.Sign = mAddress.GetSign(status.LocationCounter); - for (int i = 0; i < word.ByteCount; i++) + var instructionWord = new FullWord + { + Sign = mAddress.GetSign(status.LocationCounter) + }; + for (int i = 0; i < word.ByteCount; i++) { instructionWord[i] = word[i]; } @@ -94,12 +96,12 @@ public InstructionInstanceBase CreateInstance(InstructionBase instruction, Assem instructionWord[MixInstruction.OpcodeByte] = mixInstruction.Opcode; var instance = mixInstruction.CreateInstance(instructionWord); - reportInstanceErrors(status, instance); + ReportInstanceErrors(status, instance); return instance; } - MixByte getFieldSpecValue(AssemblingStatus status, MixInstruction mixInstruction) + MixByte GetFieldSpecValue(AssemblingStatus status, MixInstruction mixInstruction) { var fieldValue = mField.GetValue(status.LocationCounter); @@ -174,7 +176,7 @@ public static IInstructionParameters ParseAddressField(InstructionBase instructi return new MixInstructionParameters(address, indexCharIndex, index, sectionCharIndex, field, addressField.Length); } - void reportInstanceErrors(AssemblingStatus status, MixInstruction.Instance instance) + void ReportInstanceErrors(AssemblingStatus status, MixInstruction.Instance instance) { var errorArray = instance.Validate(); if (errorArray != null) diff --git a/MixAssembler/Parser.cs b/MixAssembler/Parser.cs index 8297429..7039475 100644 --- a/MixAssembler/Parser.cs +++ b/MixAssembler/Parser.cs @@ -27,16 +27,16 @@ public static class Parser static InstructionSet mInstructionSet = new InstructionSet(); static LoaderInstructions mLoaderInstructions = new LoaderInstructions(); - static bool isCommentLine(string sourceLine) => sourceLine.Trim().Length == 0 || sourceLine[0] == '*'; + static bool IsCommentLine(string sourceLine) => sourceLine.Trim().Length == 0 || sourceLine[0] == '*'; /// /// This method parses an "in-memory" instruction. That is: an instruction without a location field. /// public static ParsedSourceLine ParseInstructionLine(string instructionLine, ParsingStatus status) => // add an empty location field, then parse as usual. - parseLine(" " + instructionLine, status); + ParseLine(" " + instructionLine, status); - static int findFirstNonWhiteSpace(string sourceLine, int searchBeyondIndex) + static int FindFirstNonWhiteSpace(string sourceLine, int searchBeyondIndex) { for (int i = searchBeyondIndex + 1; i < sourceLine.Length; i++) { @@ -46,7 +46,7 @@ static int findFirstNonWhiteSpace(string sourceLine, int searchBeyondIndex) return -1; } - static int findFirstWhiteSpace(string sourceLine, int searchBeyondIndex) + static int FindFirstWhiteSpace(string sourceLine, int searchBeyondIndex) { for (int i = searchBeyondIndex + 1; i < sourceLine.Length; i++) { @@ -59,7 +59,7 @@ static int findFirstWhiteSpace(string sourceLine, int searchBeyondIndex) /// /// This method is used to handle instructions targeted at the assembler itself. /// - static bool handleAssemblyInstruction(string opField, string addressField, SymbolBase symbol, ParsingStatus status) + static bool HandleAssemblyInstruction(string opField, string addressField, SymbolBase symbol, ParsingStatus status) { IValue expression; status.LineSection = LineSection.AddressField; @@ -108,7 +108,7 @@ static bool handleAssemblyInstruction(string opField, string addressField, Symbo return false; } - static void getMixOrLoaderInstructionAndParameters(string opField, string addressField, ParsingStatus status, out InstructionBase instruction, out IInstructionParameters instructionParameters) + static void GetMixOrLoaderInstructionAndParameters(string opField, string addressField, ParsingStatus status, out InstructionBase instruction, out IInstructionParameters instructionParameters) { status.LineSection = LineSection.AddressField; instructionParameters = null; @@ -131,14 +131,12 @@ static void getMixOrLoaderInstructionAndParameters(string opField, string addres } } - static ParsedSourceLine parseLine(string sourceLine, ParsingStatus status) + static ParsedSourceLine ParseLine(string sourceLine, ParsingStatus status) { - IInstructionParameters instructionParameters; - InstructionBase instruction; - if (isCommentLine(sourceLine)) return new ParsedSourceLine(status.LineNumber, sourceLine); + if (IsCommentLine(sourceLine)) return new ParsedSourceLine(status.LineNumber, sourceLine); - var lineFields = splitLine(sourceLine); + var lineFields = SplitLine(sourceLine); lineFields[locFieldIndex] = lineFields[locFieldIndex].ToUpper(); lineFields[opFieldIndex] = lineFields[opFieldIndex].ToUpper(); lineFields[addressFieldIndex] = lineFields[addressFieldIndex].ToUpper(); @@ -150,14 +148,14 @@ static ParsedSourceLine parseLine(string sourceLine, ParsingStatus status) return new ParsedSourceLine(status.LineNumber, lineFields[0], "", "", "", null, null); } - var symbol = parseLocField(lineFields[locFieldIndex], status); + var symbol = ParseLocField(lineFields[locFieldIndex], status); // if the location field contains a symbol name, set its value to the location counter symbol?.SetValue(status.LocationCounter); - getMixOrLoaderInstructionAndParameters(lineFields[opFieldIndex], lineFields[addressFieldIndex], status, out instruction, out instructionParameters); + GetMixOrLoaderInstructionAndParameters(lineFields[opFieldIndex], lineFields[addressFieldIndex], status, out InstructionBase instruction, out IInstructionParameters instructionParameters); // the following call must be made even if a MIX or loader instruction was found, as some loader instructions require the assembler to act, as well - var assemblyInstructionHandled = handleAssemblyInstruction(lineFields[opFieldIndex], lineFields[addressFieldIndex], symbol, status); + var assemblyInstructionHandled = HandleAssemblyInstruction(lineFields[opFieldIndex], lineFields[addressFieldIndex], symbol, status); // if the line isn't a comment or a MIX or loader instruction, it must be an assembler instruction. If not, we don't know the mnemonic if (instruction == null && !assemblyInstructionHandled) @@ -168,7 +166,7 @@ static ParsedSourceLine parseLine(string sourceLine, ParsingStatus status) return new ParsedSourceLine(status.LineNumber, lineFields[locFieldIndex], lineFields[opFieldIndex], lineFields[addressFieldIndex], lineFields[commentFieldIndex], instruction, instructionParameters); } - static SymbolBase parseLocField(string locField, ParsingStatus status) + static SymbolBase ParseLocField(string locField, ParsingStatus status) { if (locField == "") return null; @@ -208,14 +206,14 @@ public static PreInstruction[] ParseSource(string[] sourceLines, ParsingStatus s { status.LineNumber = lineNumber; - if (endLineNumber != -1 && !isCommentLine(sourceLines[lineNumber])) + if (endLineNumber != -1 && !IsCommentLine(sourceLines[lineNumber])) { status.ReportParsingWarning(LineSection.CommentField, 0, sourceLines[lineNumber].Length, "END has been parsed; line will be treated as comment"); preInstructions.Add(new ParsedSourceLine(lineNumber, sourceLines[lineNumber])); } else { - var parsedLine = parseLine(sourceLines[lineNumber], status); + var parsedLine = ParseLine(sourceLines[lineNumber], status); preInstructions.Add(parsedLine); if (parsedLine.OpField == "END") { @@ -250,23 +248,23 @@ public static PreInstruction[] ParseSource(string[] sourceLines, ParsingStatus s return preInstructions.ToArray(); } - static string[] splitLine(string sourceLine) + static string[] SplitLine(string sourceLine) { int addressFieldEnd; - var searchBeyondIndex = findFirstWhiteSpace(sourceLine, -1); + var searchBeyondIndex = FindFirstWhiteSpace(sourceLine, -1); if (searchBeyondIndex == -1) return new string[] { sourceLine, "", "", "" }; - var opFieldStart = findFirstNonWhiteSpace(sourceLine, searchBeyondIndex); + var opFieldStart = FindFirstNonWhiteSpace(sourceLine, searchBeyondIndex); if (opFieldStart == -1) return new string[] { sourceLine.Substring(0, searchBeyondIndex), "", "", "" }; - var opFieldEnd = findFirstWhiteSpace(sourceLine, opFieldStart); + var opFieldEnd = FindFirstWhiteSpace(sourceLine, opFieldStart); if (opFieldEnd == -1) { return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart), "", "" }; } int opFieldLength = opFieldEnd - opFieldStart; - var addressFieldStart = findFirstNonWhiteSpace(sourceLine, opFieldEnd); + var addressFieldStart = FindFirstNonWhiteSpace(sourceLine, opFieldEnd); if (addressFieldStart == -1) { return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), "", "" }; @@ -286,7 +284,7 @@ static string[] splitLine(string sourceLine) } else { - addressFieldEnd = findFirstWhiteSpace(sourceLine, addressFieldStart); + addressFieldEnd = FindFirstWhiteSpace(sourceLine, addressFieldStart); } if (addressFieldEnd == -1) @@ -295,7 +293,7 @@ static string[] splitLine(string sourceLine) } int addressFieldLength = addressFieldEnd - addressFieldStart; - var commentFieldStart = findFirstNonWhiteSpace(sourceLine, addressFieldEnd); + var commentFieldStart = FindFirstNonWhiteSpace(sourceLine, addressFieldEnd); if (commentFieldStart == -1) { return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), "" }; diff --git a/MixAssembler/Symbol/LiteralConstantSymbol.cs b/MixAssembler/Symbol/LiteralConstantSymbol.cs index a45dff4..dcbb625 100644 --- a/MixAssembler/Symbol/LiteralConstantSymbol.cs +++ b/MixAssembler/Symbol/LiteralConstantSymbol.cs @@ -36,7 +36,7 @@ public class LiteralConstantSymbol : SymbolBase public override bool IsValueDefined(int currentAddress) => mValueDefined; - static string getName(Word.Signs literalSign, long literalMagnitude, int count) => + static string GetName(Word.Signs literalSign, long literalMagnitude, int count) => string.Concat("=", (literalSign.IsNegative() ? "-" : ""), literalMagnitude, '=', count); public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status) @@ -50,12 +50,12 @@ public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus var literalSign = expressionValue.GetSign(status.LocationCounter); int count = 0; - var name = getName(literalSign, literalMagnitude, count); + var name = GetName(literalSign, literalMagnitude, count); while (status.Symbols[name] != null) { count++; - name = getName(literalSign, literalMagnitude, count); + name = GetName(literalSign, literalMagnitude, count); } SymbolBase literalConstantSymbol = new LiteralConstantSymbol(literalSign, literalMagnitude, name); diff --git a/MixAssembler/Symbol/LocalSymbol.cs b/MixAssembler/Symbol/LocalSymbol.cs index cb7294d..a231aac 100644 --- a/MixAssembler/Symbol/LocalSymbol.cs +++ b/MixAssembler/Symbol/LocalSymbol.cs @@ -25,15 +25,15 @@ public LocalSymbol(int index) : base(index.ToString()) public override void SetValue(long value) => mAddresses.Add(value); - static bool isBackwardReferenceChar(char c) => c == 'B'; + static bool IsBackwardReferenceChar(char c) => c == 'B'; - static bool isDefinitionChar(char c) => c == 'H'; + static bool IsDefinitionChar(char c) => c == 'H'; - static bool isForwardReferenceChar(char c) => c == 'F'; + static bool IsForwardReferenceChar(char c) => c == 'F'; - static bool isLocalSymbol(string text) => (text.Length == 2 && char.IsNumber(text[0])) && isLocalSymbolChar(text[1]); + static bool IsLocalSymbol(string text) => (text.Length == 2 && char.IsNumber(text[0])) && IsLocalSymbolChar(text[1]); - static bool isLocalSymbolChar(char c) => "BHF".IndexOf(c) >= 0; + static bool IsLocalSymbolChar(char c) => "BHF".IndexOf(c) >= 0; public override bool IsValueDefined(int currentAddress) => false; @@ -46,9 +46,9 @@ public override long GetValue(int currentAddress) public static SymbolBase ParseDefinition(string text, int sectionCharIndex, ParsingStatus status) { - if (!isLocalSymbol(text)) return null; + if (!IsLocalSymbol(text)) return null; - if (!isDefinitionChar(text[1])) + if (!IsDefinitionChar(text[1])) { status.ReportParsingError(sectionCharIndex + 1, 1, "local symbol reference found where definition was expected"); } @@ -67,7 +67,7 @@ public static SymbolBase ParseDefinition(string text, int sectionCharIndex, Pars public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status) { - if (!isLocalSymbol(text)) return null; + if (!IsLocalSymbol(text)) return null; char localSymbolChar = text[0]; SymbolBase symbol = status.Symbols[new string(localSymbolChar, 1)]; @@ -84,13 +84,13 @@ public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus return symbol; } - if (isDefinitionChar(text[1])) + if (IsDefinitionChar(text[1])) { status.ReportParsingError(sectionCharIndex + 1, 1, "local symbol definition found where reference was expected"); return symbol; } - return new reference((LocalSymbol)symbol, isForwardReferenceChar(text[1]) ? reference.Directions.Forwards : reference.Directions.Backwards); + return new Reference((LocalSymbol)symbol, IsForwardReferenceChar(text[1]) ? Reference.Directions.Forwards : Reference.Directions.Backwards); } public ICollection Addresses @@ -112,12 +112,12 @@ public override Word.Signs GetSign(int currentAddress) throw new NotImplementedException(); } - class reference : IValue + class Reference : IValue { Directions mDirection; LocalSymbol mReferee; - public reference(LocalSymbol referee, Directions direction) + public Reference(LocalSymbol referee, Directions direction) { mReferee = referee; mDirection = direction; diff --git a/MixAssembler/Value/ExpressionValue.cs b/MixAssembler/Value/ExpressionValue.cs index 7a97a24..3562f47 100644 --- a/MixAssembler/Value/ExpressionValue.cs +++ b/MixAssembler/Value/ExpressionValue.cs @@ -13,34 +13,34 @@ public static class ExpressionValue const long fullWordModulusMask = 1L << fullWordBitCount; // Holds the mappings of binary operation identifiers to the methods (delegates) that perform the actual action - static SortedList mBinaryOperations = new SortedList(new operationComparator()); + static SortedList mBinaryOperations = new SortedList(new OperationComparator()); static ExpressionValue() { - mBinaryOperations["+"] = doAdd; - mBinaryOperations["-"] = doSubstract; - mBinaryOperations["*"] = doMultiply; - mBinaryOperations["/"] = doDivide; - mBinaryOperations["//"] = doFractionDivide; - mBinaryOperations[":"] = doCalculateField; + mBinaryOperations["+"] = DoAdd; + mBinaryOperations["-"] = DoSubstract; + mBinaryOperations["*"] = DoMultiply; + mBinaryOperations["/"] = DoDivide; + mBinaryOperations["//"] = DoFractionDivide; + mBinaryOperations[":"] = DoCalculateField; } - static IValue doAdd(IValue left, IValue right, int currentAddress) => + static IValue DoAdd(IValue left, IValue right, int currentAddress) => new NumberValue((left.GetValue(currentAddress) + right.GetValue(currentAddress)) % fullWordModulusMask); - static IValue doCalculateField(IValue left, IValue right, int currentAddress) => + static IValue DoCalculateField(IValue left, IValue right, int currentAddress) => new NumberValue(((left.GetValue(currentAddress) * 8L) + right.GetValue(currentAddress)) % fullWordModulusMask); - static IValue doDivide(IValue left, IValue right, int currentAddress) => + static IValue DoDivide(IValue left, IValue right, int currentAddress) => new NumberValue((left.GetValue(currentAddress) / right.GetValue(currentAddress)) % fullWordModulusMask); - static IValue doMultiply(IValue left, IValue right, int currentAddress) => + static IValue DoMultiply(IValue left, IValue right, int currentAddress) => new NumberValue((left.GetValue(currentAddress) * right.GetValue(currentAddress)) % fullWordModulusMask); - static IValue doSubstract(IValue left, IValue right, int currentAddress) => + static IValue DoSubstract(IValue left, IValue right, int currentAddress) => new NumberValue((left.GetValue(currentAddress) - right.GetValue(currentAddress)) % fullWordModulusMask); - static IValue doFractionDivide(IValue left, IValue right, int currentAddress) + static IValue DoFractionDivide(IValue left, IValue right, int currentAddress) { var divider = new decimal(left.GetValue(currentAddress)); divider *= fullWordModulusMask; @@ -110,7 +110,7 @@ public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus } // compare operators. Longer operators end up higher than shorter ones - class operationComparator : IComparer + class OperationComparator : IComparer { public int Compare(string left, string right) { diff --git a/MixEmul/Components/AboutForm.cs b/MixEmul/Components/AboutForm.cs index ca26ae2..cf68554 100644 --- a/MixEmul/Components/AboutForm.cs +++ b/MixEmul/Components/AboutForm.cs @@ -47,9 +47,9 @@ public AboutForm() mCopyrightLabel.Text = copyright; } - void mFullVersionLabel_Click(object sender, EventArgs e) => Clipboard.SetText(mVersionString); + void MFullVersionLabel_Click(object sender, EventArgs e) => Clipboard.SetText(mVersionString); - void mFullVersionLabel_DoubleClick(object sender, EventArgs e) => Clipboard.SetText(mVersionString.Replace('.', '_')); + void MFullVersionLabel_DoubleClick(object sender, EventArgs e) => Clipboard.SetText(mVersionString.Replace('.', '_')); void InitializeComponent() { @@ -106,8 +106,8 @@ void InitializeComponent() mFullVersionLabel.TabIndex = 1; mFullVersionLabel.Text = "Full version number: "; mFullVersionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - mFullVersionLabel.Click += mFullVersionLabel_Click; - mFullVersionLabel.DoubleClick += mFullVersionLabel_DoubleClick; + mFullVersionLabel.Click += MFullVersionLabel_Click; + mFullVersionLabel.DoubleClick += MFullVersionLabel_DoubleClick; // // AboutForm // @@ -126,13 +126,13 @@ void InitializeComponent() ShowInTaskbar = false; StartPosition = FormStartPosition.CenterScreen; Text = "About"; - KeyPress += this_KeyPress; + KeyPress += This_KeyPress; ((ISupportInitialize)(mLogoBox)).EndInit(); ResumeLayout(false); } - void this_KeyPress(object sender, KeyPressEventArgs e) + void This_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Escape) { diff --git a/MixEmul/Components/AssemblyFindingListView.cs b/MixEmul/Components/AssemblyFindingListView.cs index 83dc8f1..acf373e 100644 --- a/MixEmul/Components/AssemblyFindingListView.cs +++ b/MixEmul/Components/AssemblyFindingListView.cs @@ -38,7 +38,7 @@ public AssemblyFindingListView() mFindingsListView.Size = Size; mFindingsListView.TabIndex = 0; mFindingsListView.View = View.Details; - mFindingsListView.SelectedIndexChanged += selectedIndexChanged; + mFindingsListView.SelectedIndexChanged += SelectedIndexChanged; Controls.Add(mFindingsListView); Name = "AssemblyFindingListView"; @@ -47,12 +47,14 @@ public AssemblyFindingListView() protected void OnSelectionChanged(SelectionChangedEventArgs args) => SelectionChanged?.Invoke(this, args); - void selectedIndexChanged(object sender, EventArgs e) => OnSelectionChanged(new SelectionChangedEventArgs(SelectedFinding)); + void SelectedIndexChanged(object sender, EventArgs e) => OnSelectionChanged(new SelectionChangedEventArgs(SelectedFinding)); - void addFinding(AssemblyFinding finding) + void AddFinding(AssemblyFinding finding) { - var item = new ListViewItem(new string[] { finding.Severity.ToString(), (finding.LineNumber == int.MinValue) ? "" : ((finding.LineNumber + 1)).ToString(), finding.Message }, (int)finding.Severity); - item.Tag = finding; + var item = new ListViewItem(new string[] { finding.Severity.ToString(), (finding.LineNumber == int.MinValue) ? "" : ((finding.LineNumber + 1)).ToString(), finding.Message }, (int)finding.Severity) + { + Tag = finding + }; mFindingsListView.Items.Add(item); } @@ -65,11 +67,11 @@ public AssemblyFindingCollection Findings if (value != null) { var list = new List(value); - list.Sort(new findingComparer()); + list.Sort(new FindingComparer()); foreach (AssemblyFinding finding in list) { - addFinding(finding); + AddFinding(finding); } if (mFindingsListView.Items.Count > 0) @@ -103,7 +105,7 @@ public ImageList SeverityImageList } } - class findingComparer : IComparer + class FindingComparer : IComparer { public int Compare(AssemblyFinding x, AssemblyFinding y) { diff --git a/MixEmul/Components/BinaryFileDeviceEditor.Designer.cs b/MixEmul/Components/BinaryFileDeviceEditor.Designer.cs index b7160bc..bf34664 100644 --- a/MixEmul/Components/BinaryFileDeviceEditor.Designer.cs +++ b/MixEmul/Components/BinaryFileDeviceEditor.Designer.cs @@ -76,7 +76,7 @@ private void InitializeComponent() this.mRecordTrackBar.TabIndex = 4; this.mRecordTrackBar.TickFrequency = 256; this.mRecordTrackBar.TickStyle = System.Windows.Forms.TickStyle.None; - this.mRecordTrackBar.ValueChanged += new System.EventHandler(this.mRecordTrackBar_ValueChanged); + this.mRecordTrackBar.ValueChanged += new System.EventHandler(this.MRecordTrackBar_ValueChanged); // // mSetClipboardLabel // @@ -99,7 +99,7 @@ private void InitializeComponent() this.mRecordUpDown.Name = "mRecordUpDown"; this.mRecordUpDown.Size = new System.Drawing.Size(52, 20); this.mRecordUpDown.TabIndex = 3; - this.mRecordUpDown.ValueChanged += new System.EventHandler(this.mRecordUpDown_ValueChanged); + this.mRecordUpDown.ValueChanged += new System.EventHandler(this.MRecordUpDown_ValueChanged); // // mReadOnlyCheckBox // @@ -109,7 +109,7 @@ private void InitializeComponent() this.mReadOnlyCheckBox.Size = new System.Drawing.Size(15, 14); this.mReadOnlyCheckBox.TabIndex = 1; this.mReadOnlyCheckBox.UseVisualStyleBackColor = true; - this.mReadOnlyCheckBox.CheckedChanged += new System.EventHandler(this.mReadOnlyCheckBox_CheckedChanged); + this.mReadOnlyCheckBox.CheckedChanged += new System.EventHandler(this.MReadOnlyCheckBox_CheckedChanged); // // mReadOnlyLabel // @@ -129,7 +129,7 @@ private void InitializeComponent() this.mRevertButton.TabIndex = 10; this.mRevertButton.Text = "&Revert"; this.mRevertButton.UseVisualStyleBackColor = true; - this.mRevertButton.Click += new System.EventHandler(this.mRevertButton_Click); + this.mRevertButton.Click += new System.EventHandler(this.MRevertButton_Click); // // mSaveButton // @@ -140,17 +140,17 @@ private void InitializeComponent() this.mSaveButton.TabIndex = 10; this.mSaveButton.Text = "&Save"; this.mSaveButton.UseVisualStyleBackColor = true; - this.mSaveButton.Click += new System.EventHandler(this.mSaveButton_Click); + this.mSaveButton.Click += new System.EventHandler(this.MSaveButton_Click); // // mDeviceFileWatcher // this.mDeviceFileWatcher.EnableRaisingEvents = true; this.mDeviceFileWatcher.NotifyFilter = ((System.IO.NotifyFilters)((System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite))); this.mDeviceFileWatcher.SynchronizingObject = this; - this.mDeviceFileWatcher.Changed += new System.IO.FileSystemEventHandler(this.mDeviceFileWatcher_Event); - this.mDeviceFileWatcher.Created += new System.IO.FileSystemEventHandler(this.mDeviceFileWatcher_Event); - this.mDeviceFileWatcher.Deleted += new System.IO.FileSystemEventHandler(this.mDeviceFileWatcher_Event); - this.mDeviceFileWatcher.Renamed += new System.IO.RenamedEventHandler(this.mDeviceFileWatcher_Renamed); + this.mDeviceFileWatcher.Changed += new System.IO.FileSystemEventHandler(this.MDeviceFileWatcher_Event); + this.mDeviceFileWatcher.Created += new System.IO.FileSystemEventHandler(this.MDeviceFileWatcher_Event); + this.mDeviceFileWatcher.Deleted += new System.IO.FileSystemEventHandler(this.MDeviceFileWatcher_Event); + this.mDeviceFileWatcher.Renamed += new System.IO.RenamedEventHandler(this.MDeviceFileWatcher_Renamed); // // mWordEditorList // @@ -168,7 +168,7 @@ private void InitializeComponent() this.mWordEditorList.ResizeInProgress = false; this.mWordEditorList.Size = new System.Drawing.Size(278, 32); this.mWordEditorList.TabIndex = 9; - this.mWordEditorList.FirstVisibleIndexChanged += new MixGui.Components.EditorList.FirstVisibleIndexChangedHandler(this.mWordEditorList_FirstVisibleIndexChanged); + this.mWordEditorList.FirstVisibleIndexChanged += new MixGui.Components.EditorList.FirstVisibleIndexChangedHandler(this.MWordEditorList_FirstVisibleIndexChanged); // // mMixCharButtons // @@ -194,12 +194,12 @@ private void InitializeComponent() this.mFirstWordTextBox.SupportNegativeZero = false; this.mFirstWordTextBox.TabIndex = 6; this.mFirstWordTextBox.Text = "0"; - this.mFirstWordTextBox.ValueChanged += new MixGui.Components.LongValueTextBox.ValueChangedEventHandler(this.mFirstWordTextBox_ValueChanged); + this.mFirstWordTextBox.ValueChanged += new MixGui.Components.LongValueTextBox.ValueChangedEventHandler(this.MFirstWordTextBox_ValueChanged); // // mIODelayTimer // this.mIODelayTimer.Interval = 500; - this.mIODelayTimer.Tick += new System.EventHandler(this.mIODelayTimer_Tick); + this.mIODelayTimer.Tick += new System.EventHandler(this.MIODelayTimer_Tick); // // mAppendButton // @@ -210,7 +210,7 @@ private void InitializeComponent() this.mAppendButton.TabIndex = 11; this.mAppendButton.Text = "A&ppend"; this.mAppendButton.UseVisualStyleBackColor = true; - this.mAppendButton.Click += new System.EventHandler(this.mAppendButton_Click); + this.mAppendButton.Click += new System.EventHandler(this.MAppendButton_Click); // // mTruncateButton // @@ -221,7 +221,7 @@ private void InitializeComponent() this.mTruncateButton.TabIndex = 11; this.mTruncateButton.Text = "&Truncate"; this.mTruncateButton.UseVisualStyleBackColor = true; - this.mTruncateButton.Click += new System.EventHandler(this.mTruncateButton_Click); + this.mTruncateButton.Click += new System.EventHandler(this.MTruncateButton_Click); // // BinaryFileDeviceEditor // diff --git a/MixEmul/Components/BinaryFileDeviceEditor.cs b/MixEmul/Components/BinaryFileDeviceEditor.cs index 982a35a..e6e0168 100644 --- a/MixEmul/Components/BinaryFileDeviceEditor.cs +++ b/MixEmul/Components/BinaryFileDeviceEditor.cs @@ -54,7 +54,7 @@ public BinaryFileDeviceEditor() RecordName = "record"; mShowReadOnly = true; mLastLoadTime = DateTime.Now; - setDeviceRecordCount(1); + SetDeviceRecordCount(1); mIODelayTimer.Interval = DeviceSettings.DeviceReloadInterval; mInitialized = false; @@ -64,37 +64,37 @@ public BinaryFileDeviceEditor() public bool SupportsAppending => mCalculateRecordCount != null && !mReadOnlyCheckBox.Checked; - bool loadRecord() => loadRecord(loadErrorHandlingMode.SilentIfSameRecord); + bool LoadRecord() => LoadRecord(LoadErrorHandlingMode.SilentIfSameRecord); - public bool writeRecord() => writeRecord(false); + public bool WriteRecord() => WriteRecord(false); public new void Update() => mWordEditorList.Update(); - public bool SaveCurrentSector() => writeRecord(true); + public bool SaveCurrentSector() => WriteRecord(true); - bool processRecordSelectionChange() => writeRecord() && loadRecord(); + bool ProcessRecordSelectionChange() => WriteRecord() && LoadRecord(); - void mSaveButton_Click(object sender, EventArgs e) => writeRecord(true); + void MSaveButton_Click(object sender, EventArgs e) => WriteRecord(true); - void mRevertButton_Click(object sender, EventArgs e) => revert(); + void MRevertButton_Click(object sender, EventArgs e) => Revert(); - void mDeviceFileWatcher_Event(object sender, FileSystemEventArgs e) => handleFileWatcherEvent(); + void MDeviceFileWatcher_Event(object sender, FileSystemEventArgs e) => HandleFileWatcherEvent(); - void DeviceEditor_VisibleChanged(object sender, EventArgs e) => processVisibility(); + void DeviceEditor_VisibleChanged(object sender, EventArgs e) => ProcessVisibility(); - void mDeviceFileWatcher_Renamed(object sender, RenamedEventArgs e) => handleFileWatcherEvent(); + void MDeviceFileWatcher_Renamed(object sender, RenamedEventArgs e) => HandleFileWatcherEvent(); public void Initialize(long recordCount, long wordsPerRecord, OpenStreamCallback openStream, CalculateBytePositionCallback calculateBytePosition, ReadWordsCallback readWords, WriteWordsCallback writeWords) { - initialize(recordCount, wordsPerRecord, openStream, calculateBytePosition, readWords, writeWords, null); + Initialize(recordCount, wordsPerRecord, openStream, calculateBytePosition, readWords, writeWords, null); } public void Initialize(CalculateRecordCountCallback calculateRecordCount, long wordsPerRecord, OpenStreamCallback openStream, CalculateBytePositionCallback calculateBytePosition, ReadWordsCallback readWords, WriteWordsCallback writeWords) { - initialize(1, wordsPerRecord, openStream, calculateBytePosition, readWords, writeWords, calculateRecordCount); + Initialize(1, wordsPerRecord, openStream, calculateBytePosition, readWords, writeWords, calculateRecordCount); } - void initialize(long recordCount, long wordsPerRecord, OpenStreamCallback openStream, CalculateBytePositionCallback calculateBytePosition, ReadWordsCallback readWords, WriteWordsCallback writeWords, CalculateRecordCountCallback calculateRecordCount) + void Initialize(long recordCount, long wordsPerRecord, OpenStreamCallback openStream, CalculateBytePositionCallback calculateBytePosition, ReadWordsCallback readWords, WriteWordsCallback writeWords, CalculateRecordCountCallback calculateRecordCount) { if (mInitialized) { @@ -110,7 +110,7 @@ void initialize(long recordCount, long wordsPerRecord, OpenStreamCallback openSt mRecordUpDown.Minimum = 0; mRecordTrackBar.Minimum = 0; - setDeviceRecordCount(recordCount); + SetDeviceRecordCount(recordCount); mFirstWordTextBox.ClearZero = false; mFirstWordTextBox.MinValue = 0L; @@ -124,15 +124,15 @@ void initialize(long recordCount, long wordsPerRecord, OpenStreamCallback openSt } mWordEditorList.MaxIndex = (int)mDeviceWordsPerRecord - 1; - mWordEditorList.CreateEditor = createWordEditor; - mWordEditorList.LoadEditor = loadWordEditor; + mWordEditorList.CreateEditor = CreateWordEditor; + mWordEditorList.LoadEditor = LoadWordEditor; mChangesPending = false; mLoadRecordRetryCount = 0; - processSupportsAppending(); - processVisibility(); + ProcessSupportsAppending(); + ProcessVisibility(); } public string RecordName @@ -149,7 +149,7 @@ public string RecordName } } - void processSupportsAppending() + void ProcessSupportsAppending() { bool supportsAppending = SupportsAppending; @@ -199,29 +199,29 @@ public bool ShowReadOnly mEditorListWithButtonsHeight += mReadOnlyGap; } - processReadOnlySettings(); + ProcessReadOnlySettings(); } } - void processReadOnlySettings() + void ProcessReadOnlySettings() { bool showSaveRevertButtons = !mWordEditorList.ReadOnly || mShowReadOnly; mRevertButton.Visible = showSaveRevertButtons; mSaveButton.Visible = showSaveRevertButtons; - processSupportsAppending(); - processButtonVisibility(); + ProcessSupportsAppending(); + ProcessButtonVisibility(); } - void processButtonVisibility() + void ProcessButtonVisibility() { bool anyButtonShown = mAppendButton.Visible || mTruncateButton.Visible || mRevertButton.Visible || mSaveButton.Visible; mWordEditorList.Height = anyButtonShown ? mEditorListWithButtonsHeight : (Height - mWordEditorList.Top); } - void setDeviceRecordCount(long recordCount) + void SetDeviceRecordCount(long recordCount) { if (recordCount < 1) { @@ -234,46 +234,48 @@ void setDeviceRecordCount(long recordCount) mRecordTrackBar.Maximum = (int)(mDeviceRecordCount - 1); mRecordTrackBar.LargeChange = (int)(mDeviceRecordCount / 20); - setTruncateEnabledState(); + SetTruncateEnabledState(); } - void setTruncateEnabledState() + void SetTruncateEnabledState() { mTruncateButton.Enabled = mLastReadRecord == mDeviceRecordCount - 1 && mDeviceRecordCount > 1; } - IWordEditor createWordEditor(int index) + IWordEditor CreateWordEditor(int index) { - var editor = new DeviceWordEditor(index == -1 ? new FullWord(0) : mRecordEditWords[index]); - editor.WordIndex = index; - editor.ValueChanged += editor_ValueChanged; + var editor = new DeviceWordEditor(index == -1 ? new FullWord(0) : mRecordEditWords[index]) + { + WordIndex = index + }; + editor.ValueChanged += Editor_ValueChanged; return editor; } - void processVisibility() + void ProcessVisibility() { if (Visible) { mDeviceFileWatcher.EnableRaisingEvents |= mDevice != null; - loadRecord(); + LoadRecord(); } else { - if (changesPending) writeRecord(); + if (ChangesPending) WriteRecord(); mDeviceFileWatcher.EnableRaisingEvents &= mDevice == null; } } - void editor_ValueChanged(IWordEditor sender, MixGui.Events.WordEditorValueChangedEventArgs args) + void Editor_ValueChanged(IWordEditor sender, Events.WordEditorValueChangedEventArgs args) { - changesPending = true; + ChangesPending = true; } - void loadWordEditor(IWordEditor editor, int index) + void LoadWordEditor(IWordEditor editor, int index) { var deviceEditor = (DeviceWordEditor)editor; deviceEditor.DeviceWord = index >= 0 ? mRecordEditWords[index] : new FullWord(0L); @@ -288,18 +290,18 @@ public bool SetDevice(FileBasedDevice device) FileBasedDevice oldDevice = mDevice; mDevice = device; - initDeviceFileWatcher(); + InitDeviceFileWatcher(); - bool success = applyRecordCount() && loadRecord(loadErrorHandlingMode.ReportAlways); + bool success = ApplyRecordCount() && LoadRecord(LoadErrorHandlingMode.ReportAlways); if (!success) { mDevice = oldDevice; - initDeviceFileWatcher(); + InitDeviceFileWatcher(); } else { - setTruncateEnabledState(); + SetTruncateEnabledState(); } return success; @@ -307,14 +309,14 @@ public bool SetDevice(FileBasedDevice device) public void UpdateSettings() { - initDeviceFileWatcher(); + InitDeviceFileWatcher(); - if (Visible) loadRecord(); + if (Visible) LoadRecord(); mIODelayTimer.Interval = DeviceSettings.DeviceReloadInterval; } - bool applyRecordCount() + bool ApplyRecordCount() { if (!SupportsAppending) return true; @@ -339,7 +341,7 @@ bool applyRecordCount() stream = null; - setDeviceRecordCount(recordCount); + SetDeviceRecordCount(recordCount); } catch (Exception ex) { @@ -366,7 +368,7 @@ bool applyRecordCount() return true; } - void initDeviceFileWatcher() + void InitDeviceFileWatcher() { if (mDevice != null) { @@ -377,7 +379,7 @@ void initDeviceFileWatcher() } } - bool changesPending + bool ChangesPending { get { @@ -392,7 +394,7 @@ bool changesPending } } - bool loadRecord(loadErrorHandlingMode errorHandlingMode) + bool LoadRecord(LoadErrorHandlingMode errorHandlingMode) { if (!Visible) return true; if (mDevice == null) return false; @@ -428,7 +430,7 @@ bool loadRecord(loadErrorHandlingMode errorHandlingMode) mRecordEditWords[i].LongValue = readWords[i].LongValue; } - changesPending = false; + ChangesPending = false; mLastReadRecord = record; mLastLoadTime = DateTime.Now; @@ -439,9 +441,9 @@ bool loadRecord(loadErrorHandlingMode errorHandlingMode) } catch (Exception ex) { - if (errorHandlingMode == loadErrorHandlingMode.RetryOnError || (mLoadRecordRetryCount > 0 && mLoadRecordRetryCount <= maxLoadSectorRetryCount)) + if (errorHandlingMode == LoadErrorHandlingMode.RetryOnError || (mLoadRecordRetryCount > 0 && mLoadRecordRetryCount <= maxLoadSectorRetryCount)) { - mDelayedIOOperation = loadRecord; + mDelayedIOOperation = LoadRecord; mLoadRecordRetryCount++; mIODelayTimer.Start(); @@ -455,7 +457,7 @@ bool loadRecord(loadErrorHandlingMode errorHandlingMode) return false; } - if (errorHandlingMode == loadErrorHandlingMode.ReportAlways || mRecordUpDown.Value != mLastReadRecord) + if (errorHandlingMode == LoadErrorHandlingMode.ReportAlways || mRecordUpDown.Value != mLastReadRecord) { MessageBox.Show(this, "Unable to load device data: " + ex.Message, "Error loading data", MessageBoxButtons.OK, MessageBoxIcon.Hand); } @@ -474,7 +476,7 @@ bool loadRecord(loadErrorHandlingMode errorHandlingMode) return true; } - public bool writeRecord(bool force) + public bool WriteRecord(bool force) { if (!mChangesPending) return true; if (mReadOnlyCheckBox.Checked || (!force && mLastReadRecord == mRecordUpDown.Value)) return false; @@ -497,7 +499,7 @@ public bool writeRecord(bool force) stream = null; - changesPending = false; + ChangesPending = false; } catch (Exception ex) { @@ -522,23 +524,23 @@ public void UpdateLayout() mWordEditorList.UpdateLayout(); } - void mReadOnlyCheckBox_CheckedChanged(object sender, EventArgs e) + void MReadOnlyCheckBox_CheckedChanged(object sender, EventArgs e) { mWordEditorList.ReadOnly = mReadOnlyCheckBox.Checked; - if (mReadOnlyCheckBox.Checked && mRevertButton.Enabled) revert(); + if (mReadOnlyCheckBox.Checked && mRevertButton.Enabled) Revert(); - processReadOnlySettings(); + ProcessReadOnlySettings(); } - void mRecordTrackBar_ValueChanged(object sender, EventArgs e) + void MRecordTrackBar_ValueChanged(object sender, EventArgs e) { if (mLastReadRecord == mRecordTrackBar.Value) return; - if (processRecordSelectionChange()) + if (ProcessRecordSelectionChange()) { mRecordUpDown.Value = mRecordTrackBar.Value; - setTruncateEnabledState(); + SetTruncateEnabledState(); } else { @@ -546,14 +548,14 @@ void mRecordTrackBar_ValueChanged(object sender, EventArgs e) } } - void mRecordUpDown_ValueChanged(object sender, EventArgs e) + void MRecordUpDown_ValueChanged(object sender, EventArgs e) { if (mLastReadRecord == mRecordUpDown.Value) return; - if (processRecordSelectionChange()) + if (ProcessRecordSelectionChange()) { mRecordTrackBar.Value = (int)mRecordUpDown.Value; - setTruncateEnabledState(); + SetTruncateEnabledState(); } else { @@ -561,24 +563,24 @@ void mRecordUpDown_ValueChanged(object sender, EventArgs e) } } - void mFirstWordTextBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) + void MFirstWordTextBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) { mWordEditorList.FirstVisibleIndex = (int)args.NewValue; } - void mWordEditorList_FirstVisibleIndexChanged(EditorList sender, WordEditorList.FirstVisibleIndexChangedEventArgs args) + void MWordEditorList_FirstVisibleIndexChanged(EditorList sender, WordEditorList.FirstVisibleIndexChangedEventArgs args) { mFirstWordTextBox.LongValue = mWordEditorList.FirstVisibleIndex; } - void revert() + void Revert() { for (int i = 0; i < mRecordReadWords.Length; i++) { mRecordEditWords[i].LongValue = mRecordReadWords[i].LongValue; } - changesPending = false; + ChangesPending = false; Update(); } @@ -607,45 +609,45 @@ public bool ResizeInProgress } } - void handleFileWatcherEvent() + void HandleFileWatcherEvent() { if (mLoading || mIODelayTimer.Enabled) return; if ((DateTime.Now - mLastLoadTime).TotalMilliseconds > mIODelayTimer.Interval) { - loadRecord(loadErrorHandlingMode.RetryOnError); + LoadRecord(LoadErrorHandlingMode.RetryOnError); } else { - mDelayedIOOperation = loadRecord; + mDelayedIOOperation = LoadRecord; mIODelayTimer.Start(); } } - void mIODelayTimer_Tick(object sender, EventArgs e) + void MIODelayTimer_Tick(object sender, EventArgs e) { mIODelayTimer.Stop(); mDelayedIOOperation(); } - enum loadErrorHandlingMode + enum LoadErrorHandlingMode { ReportAlways, SilentIfSameRecord, RetryOnError } - void mAppendButton_Click(object sender, EventArgs e) + void MAppendButton_Click(object sender, EventArgs e) { - setDeviceRecordCount(mDeviceRecordCount + 1); + SetDeviceRecordCount(mDeviceRecordCount + 1); mRecordUpDown.Value = mDeviceRecordCount - 1; - if (mRecordUpDown.Value != mDeviceRecordCount - 1) setDeviceRecordCount(mDeviceRecordCount - 1); + if (mRecordUpDown.Value != mDeviceRecordCount - 1) SetDeviceRecordCount(mDeviceRecordCount - 1); } - void mTruncateButton_Click(object sender, EventArgs e) + void MTruncateButton_Click(object sender, EventArgs e) { mRecordUpDown.Value = mDeviceRecordCount - 2; @@ -683,7 +685,7 @@ void mTruncateButton_Click(object sender, EventArgs e) mDeviceFileWatcher.EnableRaisingEvents |= watcherRaisesEvents; } - if (success) setDeviceRecordCount(mDeviceRecordCount - 1); + if (success) SetDeviceRecordCount(mDeviceRecordCount - 1); } } @@ -708,8 +710,8 @@ public void DeleteDeviceFile() mRecordUpDown.Value = 0; - applyRecordCount(); - loadRecord(); + ApplyRecordCount(); + LoadRecord(); } } } diff --git a/MixEmul/Components/DeviceEditorForm.Designer.cs b/MixEmul/Components/DeviceEditorForm.Designer.cs index e8e3398..afbdf4c 100644 --- a/MixEmul/Components/DeviceEditorForm.Designer.cs +++ b/MixEmul/Components/DeviceEditorForm.Designer.cs @@ -103,7 +103,7 @@ private void InitializeComponent() this.mCloseButton.TabIndex = 1; this.mCloseButton.Text = "&Close"; this.mCloseButton.UseVisualStyleBackColor = true; - this.mCloseButton.Click += new System.EventHandler(this.mCloseButton_Click); + this.mCloseButton.Click += new System.EventHandler(this.MCloseButton_Click); // // mDisksTab // @@ -130,7 +130,7 @@ private void InitializeComponent() this.mDiskDeleteButton.TabIndex = 3; this.mDiskDeleteButton.Text = "&Delete"; this.mDiskDeleteButton.UseVisualStyleBackColor = true; - this.mDiskDeleteButton.Click += new System.EventHandler(this.mDiskDeleteButton_Click); + this.mDiskDeleteButton.Click += new System.EventHandler(this.MDiskDeleteButton_Click); // // mDiskPathBox // @@ -161,7 +161,7 @@ private void InitializeComponent() this.mDiskSelectorComboBox.Name = "mDiskSelectorComboBox"; this.mDiskSelectorComboBox.Size = new System.Drawing.Size(67, 21); this.mDiskSelectorComboBox.TabIndex = 1; - this.mDiskSelectorComboBox.SelectedIndexChanged += new System.EventHandler(this.mDiskSelectorComboBox_SelectedIndexChanged); + this.mDiskSelectorComboBox.SelectedIndexChanged += new System.EventHandler(this.MDiskSelectorComboBox_SelectedIndexChanged); // // mDeviceTypeTabs // @@ -179,7 +179,7 @@ private void InitializeComponent() this.mDeviceTypeTabs.SelectedIndex = 0; this.mDeviceTypeTabs.Size = new System.Drawing.Size(318, 343); this.mDeviceTypeTabs.TabIndex = 0; - this.mDeviceTypeTabs.SelectedIndexChanged += new System.EventHandler(this.mDeviceTypeTabs_SelectedIndexChanged); + this.mDeviceTypeTabs.SelectedIndexChanged += new System.EventHandler(this.MDeviceTypeTabs_SelectedIndexChanged); // // mTapesTab // @@ -206,7 +206,7 @@ private void InitializeComponent() this.mTapeDeleteButton.TabIndex = 3; this.mTapeDeleteButton.Text = "&Delete"; this.mTapeDeleteButton.UseVisualStyleBackColor = true; - this.mTapeDeleteButton.Click += new System.EventHandler(this.mTapeDeleteButton_Click); + this.mTapeDeleteButton.Click += new System.EventHandler(this.MTapeDeleteButton_Click); // // mTapePathBox // @@ -229,7 +229,7 @@ private void InitializeComponent() this.mTapeSelectorComboBox.Name = "mTapeSelectorComboBox"; this.mTapeSelectorComboBox.Size = new System.Drawing.Size(67, 21); this.mTapeSelectorComboBox.TabIndex = 1; - this.mTapeSelectorComboBox.SelectedIndexChanged += new System.EventHandler(this.mTapeSelectorComboBox_SelectedIndexChanged); + this.mTapeSelectorComboBox.SelectedIndexChanged += new System.EventHandler(this.MTapeSelectorComboBox_SelectedIndexChanged); // // mTapeSelectorLabel // @@ -264,7 +264,7 @@ private void InitializeComponent() this.mCardReaderLoadButton.TabIndex = 2; this.mCardReaderLoadButton.Text = "&Load..."; this.mCardReaderLoadButton.UseVisualStyleBackColor = true; - this.mCardReaderLoadButton.Click += new System.EventHandler(this.mCardReaderLoadButton_Click); + this.mCardReaderLoadButton.Click += new System.EventHandler(this.MCardReaderLoadButton_Click); // // mCardReaderDeleteButton // @@ -275,7 +275,7 @@ private void InitializeComponent() this.mCardReaderDeleteButton.TabIndex = 3; this.mCardReaderDeleteButton.Text = "&Delete"; this.mCardReaderDeleteButton.UseVisualStyleBackColor = true; - this.mCardReaderDeleteButton.Click += new System.EventHandler(this.mCardReaderDeleteButton_Click); + this.mCardReaderDeleteButton.Click += new System.EventHandler(this.MCardReaderDeleteButton_Click); // // mCardReaderPathBox // @@ -320,7 +320,7 @@ private void InitializeComponent() this.mCardPunchDeleteButton.TabIndex = 2; this.mCardPunchDeleteButton.Text = "&Delete"; this.mCardPunchDeleteButton.UseVisualStyleBackColor = true; - this.mCardPunchDeleteButton.Click += new System.EventHandler(this.mCardPunchDeleteButton_Click); + this.mCardPunchDeleteButton.Click += new System.EventHandler(this.MCardPunchDeleteButton_Click); // // mCardWriterPathBox // @@ -365,7 +365,7 @@ private void InitializeComponent() this.mPrinterDeleteButton.TabIndex = 3; this.mPrinterDeleteButton.Text = "&Delete"; this.mPrinterDeleteButton.UseVisualStyleBackColor = true; - this.mPrinterDeleteButton.Click += new System.EventHandler(this.mPrinterDeleteButton_Click); + this.mPrinterDeleteButton.Click += new System.EventHandler(this.MPrinterDeleteButton_Click); // // mPrinterPathBox // @@ -410,7 +410,7 @@ private void InitializeComponent() this.mPaperTapeDeleteButton.TabIndex = 2; this.mPaperTapeDeleteButton.Text = "&Delete"; this.mPaperTapeDeleteButton.UseVisualStyleBackColor = true; - this.mPaperTapeDeleteButton.Click += new System.EventHandler(this.mPaperTapeDeleteButton_Click); + this.mPaperTapeDeleteButton.Click += new System.EventHandler(this.MPaperTapeDeleteButton_Click); // // mPaperTapePathBox // diff --git a/MixEmul/Components/DeviceEditorForm.cs b/MixEmul/Components/DeviceEditorForm.cs index 23e60af..0e9a0a4 100644 --- a/MixEmul/Components/DeviceEditorForm.cs +++ b/MixEmul/Components/DeviceEditorForm.cs @@ -41,27 +41,27 @@ public DeviceEditorForm(Devices devices) mLastSelectedDeviceTab = 0; } - void mCloseButton_Click(object sender, EventArgs e) => Hide(); + void MCloseButton_Click(object sender, EventArgs e) => Hide(); - void mTapeDeleteButton_Click(object sender, EventArgs e) => - deleteBinaryDeviceFile(mTapeSelectorComboBox.SelectedItem.ToString(), mTapeEditor); + void MTapeDeleteButton_Click(object sender, EventArgs e) => + DeleteBinaryDeviceFile(mTapeSelectorComboBox.SelectedItem.ToString(), mTapeEditor); - void mDiskDeleteButton_Click(object sender, EventArgs e) => - deleteBinaryDeviceFile(mDiskSelectorComboBox.SelectedItem.ToString(), mDiskEditor); + void MDiskDeleteButton_Click(object sender, EventArgs e) => + DeleteBinaryDeviceFile(mDiskSelectorComboBox.SelectedItem.ToString(), mDiskEditor); - void mCardReaderDeleteButton_Click(object sender, EventArgs e) => deleteTextDeviceFile("card reader", mCardReaderEditor); + void MCardReaderDeleteButton_Click(object sender, EventArgs e) => DeleteTextDeviceFile("card reader", mCardReaderEditor); - void mCardPunchDeleteButton_Click(object sender, EventArgs e) => deleteTextDeviceFile("card punch", mCardWriterEditor); + void MCardPunchDeleteButton_Click(object sender, EventArgs e) => DeleteTextDeviceFile("card punch", mCardWriterEditor); - void mPrinterDeleteButton_Click(object sender, EventArgs e) => deleteTextDeviceFile("printer", mPrinterEditor); + void MPrinterDeleteButton_Click(object sender, EventArgs e) => DeleteTextDeviceFile("printer", mPrinterEditor); - void mPaperTapeDeleteButton_Click(object sender, EventArgs e) => deleteTextDeviceFile("paper tape", mPaperTapeEditor); + void MPaperTapeDeleteButton_Click(object sender, EventArgs e) => DeleteTextDeviceFile("paper tape", mPaperTapeEditor); - void mDiskSelectorComboBox_SelectedIndexChanged(object sender, EventArgs e) + void MDiskSelectorComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (mLastSelectedDisk == mDiskSelectorComboBox.SelectedIndex) return; - if (updateDiskControls()) + if (UpdateDiskControls()) { mLastSelectedDisk = mDiskSelectorComboBox.SelectedIndex; } @@ -71,11 +71,11 @@ void mDiskSelectorComboBox_SelectedIndexChanged(object sender, EventArgs e) } } - void mTapeSelectorComboBox_SelectedIndexChanged(object sender, EventArgs e) + void MTapeSelectorComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (mLastSelectedTape == mTapeSelectorComboBox.SelectedIndex) return; - if (updateTapeControls()) + if (UpdateTapeControls()) { mLastSelectedTape = mTapeSelectorComboBox.SelectedIndex; } @@ -88,7 +88,7 @@ void mTapeSelectorComboBox_SelectedIndexChanged(object sender, EventArgs e) public new void Hide() { - if (saveCurrentTabRecord()) base.Hide(); + if (SaveCurrentTabRecord()) base.Hide(); } public void ShowDevice(MixDevice device) @@ -181,7 +181,7 @@ public Devices Devices mDiskSelectorComboBox.SelectedIndex = 0; } - updateDiskControls(); + UpdateDiskControls(); mLastSelectedTape = 0; @@ -190,7 +190,7 @@ public Devices Devices mTapeSelectorComboBox.SelectedIndex = 0; } - updateTapeControls(); + UpdateTapeControls(); } } @@ -203,15 +203,15 @@ public void UpdateSettings() mPrinterEditor.UpdateSettings(); mPaperTapeEditor.UpdateSettings(); - updateTapeControls(); - updateDiskControls(); + UpdateTapeControls(); + UpdateDiskControls(); mCardReaderPathBox.Text = mCardReaderEditor.Device.FilePath; mCardWriterPathBox.Text = mCardWriterEditor.Device.FilePath; mPrinterPathBox.Text = mPrinterEditor.Device.FilePath; mPaperTapePathBox.Text = mPaperTapeEditor.Device.FilePath; } - bool updateDiskControls() + bool UpdateDiskControls() { bool success = true; @@ -244,7 +244,7 @@ public void UpdateLayout() mPaperTapeEditor.UpdateLayout(); } - bool updateTapeControls() + bool UpdateTapeControls() { bool success = true; @@ -294,11 +294,11 @@ void DeviceEditorForm_FormClosing(object sender, FormClosingEventArgs e) Hide(); } - void mDeviceTypeTabs_SelectedIndexChanged(object sender, EventArgs e) + void MDeviceTypeTabs_SelectedIndexChanged(object sender, EventArgs e) { if (mDeviceTypeTabs.SelectedIndex == mLastSelectedDeviceTab) return; - if (saveCurrentTabRecord()) + if (SaveCurrentTabRecord()) { mLastSelectedDeviceTab = mDeviceTypeTabs.SelectedIndex; } @@ -308,7 +308,7 @@ void mDeviceTypeTabs_SelectedIndexChanged(object sender, EventArgs e) } } - bool saveCurrentTabRecord() + bool SaveCurrentTabRecord() { bool success = true; @@ -342,7 +342,7 @@ bool saveCurrentTabRecord() return success; } - void deleteBinaryDeviceFile(string deviceName, BinaryFileDeviceEditor editor) + void DeleteBinaryDeviceFile(string deviceName, BinaryFileDeviceEditor editor) { if (MessageBox.Show(this, "Are you sure you want to delete the file for device " + deviceName + "?", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { @@ -350,7 +350,7 @@ void deleteBinaryDeviceFile(string deviceName, BinaryFileDeviceEditor editor) } } - void deleteTextDeviceFile(string deviceName, TextFileDeviceEditor editor) + void DeleteTextDeviceFile(string deviceName, TextFileDeviceEditor editor) { if (MessageBox.Show(this, "Are you sure you want to delete the device file for the " + deviceName + "?", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { @@ -358,7 +358,7 @@ void deleteTextDeviceFile(string deviceName, TextFileDeviceEditor editor) } } - void mCardReaderLoadButton_Click(object sender, EventArgs e) + void MCardReaderLoadButton_Click(object sender, EventArgs e) { if (mCardReaderLoadFileDialog.ShowDialog(this) == DialogResult.OK) { diff --git a/MixEmul/Components/DeviceMixByteCollectionEditor.cs b/MixEmul/Components/DeviceMixByteCollectionEditor.cs index a90171f..42e375b 100644 --- a/MixEmul/Components/DeviceMixByteCollectionEditor.cs +++ b/MixEmul/Components/DeviceMixByteCollectionEditor.cs @@ -34,7 +34,7 @@ public DeviceMixByteCollectionEditor(IMixByteCollection mixByteCollection) mCharTextBox = new MixByteCollectionCharTextBox(mDeviceMixByteCollection); mMixByteCollectionIndexLabel = new Label(); - initializeComponent(); + InitializeComponent(); } public Control EditorControl => this; @@ -49,10 +49,10 @@ public DeviceMixByteCollectionEditor(IMixByteCollection mixByteCollection) protected virtual void OnValueChanged(MixByteCollectionEditorValueChangedEventArgs args) => ValueChanged?.Invoke(this, args); - void mMixByteCollectionEditor_ValueChanged(IMixByteCollectionEditor sender, MixByteCollectionEditorValueChangedEventArgs args) => + void MMixByteCollectionEditor_ValueChanged(IMixByteCollectionEditor sender, MixByteCollectionEditorValueChangedEventArgs args) => OnValueChanged(args); - void initializeComponent() + void InitializeComponent() { SuspendLayout(); @@ -68,8 +68,8 @@ void initializeComponent() mCharTextBox.Location = new Point(mMixByteCollectionIndexLabel.Right, 0); mCharTextBox.Name = "mCharTextBox"; mCharTextBox.TabIndex = 1; - mCharTextBox.ValueChanged += mMixByteCollectionEditor_ValueChanged; - mCharTextBox.NavigationKeyDown += keyDown; + mCharTextBox.ValueChanged += MMixByteCollectionEditor_ValueChanged; + mCharTextBox.NavigationKeyDown += This_KeyDown; mCharTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; mCharTextBox.BorderStyle = BorderStyle.None; mCharTextBox.Height = 13; @@ -78,11 +78,11 @@ void initializeComponent() Controls.Add(mCharTextBox); Name = "DeviceMixByteCollectionEditor"; Size = new Size(mCharTextBox.Right, mCharTextBox.Height); - KeyDown += keyDown; + KeyDown += This_KeyDown; ResumeLayout(false); } - void keyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers != Keys.None) return; @@ -124,11 +124,11 @@ public int MixByteCollectionIndex } mMixByteCollectionIndex = value; - setIndexLabelText(); + SetIndexLabelText(); } } - void setIndexLabelText() + void SetIndexLabelText() { mMixByteCollectionIndexLabel.Text = mMixByteCollectionIndex.ToString("D" + mIndexCharCount) + ":"; } @@ -144,7 +144,7 @@ public int IndexCharCount if (mIndexCharCount == value) return; mIndexCharCount = value; - setIndexLabelText(); + SetIndexLabelText(); int oldCharBoxLeft = mCharTextBox.Left; mCharTextBox.Left = mMixByteCollectionIndexLabel.Right + 3; @@ -160,12 +160,7 @@ public IMixByteCollection DeviceMixByteCollection } set { - if (value == null) - { - throw new ArgumentNullException(nameof(value), "DeviceMixByteCollection may not be set to null"); - } - - mDeviceMixByteCollection = value; + mDeviceMixByteCollection = value ?? throw new ArgumentNullException(nameof(value), "DeviceMixByteCollection may not be set to null"); mCharTextBox.MixByteCollectionValue = mDeviceMixByteCollection; mCharTextBox.Select(0, 0); } diff --git a/MixEmul/Components/DeviceStatusControl.cs b/MixEmul/Components/DeviceStatusControl.cs index 11896a0..88ca784 100644 --- a/MixEmul/Components/DeviceStatusControl.cs +++ b/MixEmul/Components/DeviceStatusControl.cs @@ -44,7 +44,7 @@ public DeviceStatusControl(MixDevice device) mIndexLabel.TabIndex = 0; mIndexLabel.Text = "00:"; mIndexLabel.TextAlign = ContentAlignment.MiddleRight; - mIndexLabel.DoubleClick += control_DoubleClick; + mIndexLabel.DoubleClick += Control_DoubleClick; mStatusLabel.BorderStyle = BorderStyle.FixedSingle; mStatusLabel.Location = new Point(20, 0); @@ -53,7 +53,7 @@ public DeviceStatusControl(MixDevice device) mStatusLabel.TabIndex = 1; mStatusLabel.Text = ""; mStatusLabel.TextAlign = ContentAlignment.MiddleCenter; - mStatusLabel.DoubleClick += control_DoubleClick; + mStatusLabel.DoubleClick += Control_DoubleClick; mInputMenuItem.Index = 0; mInputMenuItem.Text = "Input device"; @@ -67,7 +67,7 @@ public DeviceStatusControl(MixDevice device) mResetMenuItem.DefaultItem = true; mResetMenuItem.Index = 3; mResetMenuItem.Text = "Reset"; - mResetMenuItem.Click += mResetMenuItem_Click; + mResetMenuItem.Click += MResetMenuItem_Click; mContextMenu.MenuItems.AddRange(new MenuItem[] { mInputMenuItem, mOutputMenuItem, mContextSeparator, mResetMenuItem }); ContextMenu = mContextMenu; @@ -81,9 +81,9 @@ public DeviceStatusControl(MixDevice device) UpdateLayout(); } - void control_DoubleClick(object sender, EventArgs e) => OnDoubleClick(e); + void Control_DoubleClick(object sender, EventArgs e) => OnDoubleClick(e); - void mResetMenuItem_Click(object sender, EventArgs e) + void MResetMenuItem_Click(object sender, EventArgs e) { if (mDevice != null) { diff --git a/MixEmul/Components/DeviceWordEditor.cs b/MixEmul/Components/DeviceWordEditor.cs index 7d7d59a..f53b3f6 100644 --- a/MixEmul/Components/DeviceWordEditor.cs +++ b/MixEmul/Components/DeviceWordEditor.cs @@ -32,7 +32,7 @@ public DeviceWordEditor(IFullWord deviceWord) mFullWordEditor = new FullWordEditor(mDeviceWord); mWordIndexLabel = new Label(); - initializeComponent(); + InitializeComponent(); } public Control EditorControl => this; @@ -47,9 +47,9 @@ public DeviceWordEditor(IFullWord deviceWord) protected virtual void OnValueChanged(WordEditorValueChangedEventArgs args) => ValueChanged?.Invoke(this, args); - void mFullWordEditor_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) => OnValueChanged(args); + void MFullWordEditor_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) => OnValueChanged(args); - void initializeComponent() + void InitializeComponent() { SuspendLayout(); @@ -64,18 +64,18 @@ void initializeComponent() mFullWordEditor.Location = new Point(mWordIndexLabel.Right, 2); mFullWordEditor.Name = "mFullWordEditor"; mFullWordEditor.TabIndex = 1; - mFullWordEditor.ValueChanged += mFullWordEditor_ValueChanged; - mFullWordEditor.NavigationKeyDown += keyDown; + mFullWordEditor.ValueChanged += MFullWordEditor_ValueChanged; + mFullWordEditor.NavigationKeyDown += This_KeyDown; Controls.Add(mWordIndexLabel); Controls.Add(mFullWordEditor); Name = "DeviceWordEditor"; Size = new Size(mFullWordEditor.Right + 2, mFullWordEditor.Height + 3); - KeyDown += keyDown; + KeyDown += This_KeyDown; ResumeLayout(false); } - void keyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { @@ -125,12 +125,7 @@ public IFullWord DeviceWord } set { - if (value == null) - { - throw new ArgumentNullException(nameof(value), "DeviceWord may not be set to null"); - } - - mDeviceWord = value; + mDeviceWord = value ?? throw new ArgumentNullException(nameof(value), "DeviceWord may not be set to null"); mFullWordEditor.WordValue = mDeviceWord; } } diff --git a/MixEmul/Components/DevicesControl.cs b/MixEmul/Components/DevicesControl.cs index 88d6c8f..9aea626 100644 --- a/MixEmul/Components/DevicesControl.cs +++ b/MixEmul/Components/DevicesControl.cs @@ -30,26 +30,28 @@ public DevicesControl(MixLib.Devices devices, LayoutStructure layout) { mStructure = layout; - mNoDevicesLabel = new Label(); - mNoDevicesLabel.Location = new Point(0, 0); - mNoDevicesLabel.Name = "mNoDevicesLabel"; - mNoDevicesLabel.Size = new Size(120, 16); - mNoDevicesLabel.TabIndex = 0; - mNoDevicesLabel.Text = "No devices connected"; - mNoDevicesLabel.TextAlign = ContentAlignment.MiddleCenter; + mNoDevicesLabel = new Label + { + Location = new Point(0, 0), + Name = "mNoDevicesLabel", + Size = new Size(120, 16), + TabIndex = 0, + Text = "No devices connected", + TextAlign = ContentAlignment.MiddleCenter + }; - Name = "DevicesControl"; + Name = "DevicesControl"; Devices = devices; } - void addDeviceControl(int index) + void AddDeviceControl(int index) { - var orientation = getOrientation(); + var orientation = GetOrientation(); Breaks breaks = mStructure != null && index > 0 ? mStructure[index] : Breaks.None; - var horizontalSpacing = getHorizontalSpacing(); - var verticalSpacing = getVerticalSpacing(); + var horizontalSpacing = GetHorizontalSpacing(); + var verticalSpacing = GetVerticalSpacing(); if (index == 0) { @@ -121,7 +123,7 @@ void addDeviceControl(int index) Controls.Add(control); } - void addDeviceControls() + void AddDeviceControls() { SuspendLayout(); Controls.Clear(); @@ -132,17 +134,17 @@ void addDeviceControls() } else { - for (int i = 0; i < mDeviceControls.Length; i++) addDeviceControl(i); + for (int i = 0; i < mDeviceControls.Length; i++) AddDeviceControl(i); } ResumeLayout(false); } - int getHorizontalSpacing() => mStructure == null ? 0 : mStructure.HorizontalSpacing; + int GetHorizontalSpacing() => mStructure == null ? 0 : mStructure.HorizontalSpacing; - Orientations getOrientation() => mStructure == null ? Orientations.Horizontal : mStructure.Orientation; + Orientations GetOrientation() => mStructure == null ? Orientations.Horizontal : mStructure.Orientation; - int getVerticalSpacing() => mStructure == null ? 0 : mStructure.VerticalSpacing; + int GetVerticalSpacing() => mStructure == null ? 0 : mStructure.VerticalSpacing; public new void Update() { @@ -173,15 +175,17 @@ public MixLib.Devices Devices DeviceStatusControl control; foreach (MixDevice device in mDevices) { - control = new DeviceStatusControl(device); - control.ToolTip = mToolTip; - control.DoubleClick += DevicesControl_DoubleClick; + control = new DeviceStatusControl(device) + { + ToolTip = mToolTip + }; + control.DoubleClick += DevicesControl_DoubleClick; mDeviceControls[device.Id] = control; } } - addDeviceControls(); + AddDeviceControls(); } } } @@ -199,7 +203,7 @@ public LayoutStructure Structure if (value != null) { mStructure = value; - addDeviceControls(); + AddDeviceControls(); } } } diff --git a/MixEmul/Components/EditorList.cs b/MixEmul/Components/EditorList.cs index 350360a..a6411bc 100644 Binary files a/MixEmul/Components/EditorList.cs and b/MixEmul/Components/EditorList.cs differ diff --git a/MixEmul/Components/FullWordEditor.cs b/MixEmul/Components/FullWordEditor.cs index eba0210..f8973cc 100644 --- a/MixEmul/Components/FullWordEditor.cs +++ b/MixEmul/Components/FullWordEditor.cs @@ -34,7 +34,7 @@ public FullWordEditor(IFullWord fullWord) mWordValueEditor = new WordValueEditor(mFullWord); mWordCharTextBox = new MixByteCollectionCharTextBox(mFullWord); mEqualsLabel = new Label(); - initializeComponent(); + InitializeComponent(); } public Control EditorControl => this; @@ -48,15 +48,15 @@ public bool Focus(FieldTypes? field, int? index) => protected virtual void OnValueChanged(WordEditorValueChangedEventArgs args) => ValueChanged?.Invoke(this, args); - void initializeComponent() + void InitializeComponent() { SuspendLayout(); mWordValueEditor.Location = new Point(0, 0); mWordValueEditor.Name = "mWordValueEditor"; mWordValueEditor.TabIndex = 2; - mWordValueEditor.ValueChanged += mWordValueEditor_ValueChanged; - mWordValueEditor.NavigationKeyDown += keyDown; + mWordValueEditor.ValueChanged += MWordValueEditor_ValueChanged; + mWordValueEditor.NavigationKeyDown += This_KeyDown; mEqualsLabel.Location = new Point(mWordValueEditor.Right, mWordValueEditor.Top + 2); mEqualsLabel.Name = "mFirstEqualsLabel"; @@ -68,19 +68,19 @@ void initializeComponent() mWordCharTextBox.Name = "mWordCharTextBox"; mWordCharTextBox.Size = new Size(45, mWordValueEditor.Height); mWordCharTextBox.TabIndex = 4; - mWordCharTextBox.ValueChanged += mWordCharTextBox_ValueChanged; - mWordCharTextBox.NavigationKeyDown += keyDown; + mWordCharTextBox.ValueChanged += MWordCharTextBox_ValueChanged; + mWordCharTextBox.NavigationKeyDown += This_KeyDown; Controls.Add(mWordValueEditor); Controls.Add(mEqualsLabel); Controls.Add(mWordCharTextBox); Name = "FullWordEditor"; Size = new Size(mWordCharTextBox.Right, mWordCharTextBox.Height); - KeyDown += keyDown; + KeyDown += This_KeyDown; ResumeLayout(false); } - void keyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers != Keys.None) return; @@ -128,13 +128,13 @@ void keyDown(object sender, KeyEventArgs e) } } - void mWordCharTextBox_ValueChanged(IMixByteCollectionEditor sender, MixByteCollectionEditorValueChangedEventArgs args) + void MWordCharTextBox_ValueChanged(IMixByteCollectionEditor sender, MixByteCollectionEditorValueChangedEventArgs args) { mWordValueEditor.Update(); OnValueChanged(new WordEditorValueChangedEventArgs((Word)args.OldValue, (Word)args.NewValue)); } - void mWordValueEditor_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) + void MWordValueEditor_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) { mWordCharTextBox.Update(); OnValueChanged(args); @@ -161,12 +161,7 @@ public IFullWord FullWord } set { - if (value == null) - { - throw new ArgumentNullException(nameof(value), "FullWord may not be set to null"); - } - - mFullWord = value; + mFullWord = value ?? throw new ArgumentNullException(nameof(value), "FullWord may not be set to null"); mWordValueEditor.WordValue = mFullWord; mWordCharTextBox.MixByteCollectionValue = mFullWord; } diff --git a/MixEmul/Components/InstructionInstanceTextBox.cs b/MixEmul/Components/InstructionInstanceTextBox.cs index 6fce792..5f139ac 100644 --- a/MixEmul/Components/InstructionInstanceTextBox.cs +++ b/MixEmul/Components/InstructionInstanceTextBox.cs @@ -67,16 +67,16 @@ public InstructionInstanceTextBox(IFullWord instructionWord) UpdateLayout(); DetectUrls = false; - TextChanged += this_TextChanged; - KeyPress += this_KeyPress; - KeyDown += this_KeyDown; - LostFocus += this_LostFocus; - Enter += this_Enter; - ReadOnlyChanged += this_ReadOnlyChanged; + TextChanged += This_TextChanged; + KeyPress += This_KeyPress; + KeyDown += This_KeyDown; + LostFocus += This_LostFocus; + Enter += This_Enter; + ReadOnlyChanged += This_ReadOnlyChanged; - mShowAddressMenuItem = new MenuItem("Show address", showAddressMenuItem_Click); + mShowAddressMenuItem = new MenuItem("Show address", ShowAddressMenuItem_Click); - mShowIndexedAddressMenuItem = new MenuItem("Show indexed address", showIndexedAddressMenuItem_Click); + mShowIndexedAddressMenuItem = new MenuItem("Show indexed address", ShowIndexedAddressMenuItem_Click); mContextMenu = new ContextMenu(); mContextMenu.MenuItems.Add(mShowAddressMenuItem); @@ -107,14 +107,14 @@ public InstructionInstanceTextBox(IFullWord instructionWord) protected void OnAddressSelected(AddressSelectedEventArgs args) => AddressSelected?.Invoke(this, args); - void this_Enter(object sender, EventArgs e) => checkContentsEditable(); + void This_Enter(object sender, EventArgs e) => CheckContentsEditable(); - void showIndexedAddressMenuItem_Click(object sender, EventArgs e) => - OnAddressSelected(new AddressSelectedEventArgs(IndexedAddressCalculatorCallback(getAddress(), mInstructionWord[MixInstruction.IndexByte]))); + void ShowIndexedAddressMenuItem_Click(object sender, EventArgs e) => + OnAddressSelected(new AddressSelectedEventArgs(IndexedAddressCalculatorCallback(GetAddress(), mInstructionWord[MixInstruction.IndexByte]))); - void showAddressMenuItem_Click(object sender, EventArgs e) => OnAddressSelected(new AddressSelectedEventArgs(getAddress())); + void ShowAddressMenuItem_Click(object sender, EventArgs e) => OnAddressSelected(new AddressSelectedEventArgs(GetAddress())); - void addTextElement(string element, bool markAsError) + void AddTextElement(string element, bool markAsError) { if (element != "") { @@ -125,7 +125,7 @@ void addTextElement(string element, bool markAsError) } } - string getAssemblyErrorsCaption(ParsedSourceLine line, AssemblyFindingCollection findings) + string GetAssemblyErrorsCaption(ParsedSourceLine line, AssemblyFindingCollection findings) { string caption = ""; int findingNumber = 1; @@ -139,7 +139,7 @@ string getAssemblyErrorsCaption(ParsedSourceLine line, AssemblyFindingCollection switch (finding.LineSection) { case LineSection.OpField: - markAssemblyError(finding.StartCharIndex, finding.Length); + MarkAssemblyError(finding.StartCharIndex, finding.Length); fieldLabel = "mnemonic"; break; @@ -147,11 +147,11 @@ string getAssemblyErrorsCaption(ParsedSourceLine line, AssemblyFindingCollection case LineSection.AddressField: if (finding.Length != 0) { - markAssemblyError((line.OpField.Length + finding.StartCharIndex) + 1, finding.Length); + MarkAssemblyError((line.OpField.Length + finding.StartCharIndex) + 1, finding.Length); } else { - markAssemblyError(line.OpField.Length + 1, line.AddressField.Length); + MarkAssemblyError(line.OpField.Length + 1, line.AddressField.Length); } fieldLabel = "address"; @@ -162,7 +162,7 @@ string getAssemblyErrorsCaption(ParsedSourceLine line, AssemblyFindingCollection continue; case LineSection.EntireLine: - markAssemblyError(0, TextLength); + MarkAssemblyError(0, TextLength); fieldLabel = "instruction"; break; @@ -189,13 +189,11 @@ string getAssemblyErrorsCaption(ParsedSourceLine line, AssemblyFindingCollection : string.Concat("Instruction errors:", Environment.NewLine, caption); } - bool assembleInstruction(bool markErrors) + bool AssembleInstruction(bool markErrors) { - AssemblyFindingCollection findings; - ParsedSourceLine line; mEditMode = false; - var instance = Assembler.Assemble(Text, MemoryAddress, out line, Symbols, out findings); + var instance = Assembler.Assemble(Text, MemoryAddress, out ParsedSourceLine line, Symbols, out AssemblyFindingCollection findings); if (instance != null && !(instance is MixInstruction.Instance)) { @@ -214,7 +212,7 @@ bool assembleInstruction(bool markErrors) base.Text = line.OpField + " " + line.AddressField; - mCaption = getAssemblyErrorsCaption(line, findings); + mCaption = GetAssemblyErrorsCaption(line, findings); mToolTip?.SetToolTip(this, mCaption); Select(selectionStart, selectionLength); @@ -235,12 +233,12 @@ bool assembleInstruction(bool markErrors) return true; } - bool checkContentsEditable() + bool CheckContentsEditable() { if (!ReadOnly && (mNoInstructionRendered || mInstructionWord.IsEmpty)) { base.Text = ""; - setEditMode(); + SetEditMode(); return false; } @@ -248,7 +246,7 @@ bool checkContentsEditable() return true; } - bool itemInErrors(InstanceValidationError[] errors, InstanceValidationError.Sources item) + bool ItemInErrors(InstanceValidationError[] errors, InstanceValidationError.Sources item) { if (errors != null) { @@ -261,7 +259,7 @@ bool itemInErrors(InstanceValidationError[] errors, InstanceValidationError.Sour return false; } - void markAssemblyError(int startCharIndex, int length) + void MarkAssemblyError(int startCharIndex, int length) { int selectionStart = SelectionStart; int selectionLength = SelectionLength; @@ -274,7 +272,7 @@ void markAssemblyError(int startCharIndex, int length) } } - void setEditMode() + void SetEditMode() { SuspendLayout(); @@ -302,11 +300,11 @@ void setEditMode() mEditMode = true; } - void showNonInstruction(string text) + void ShowNonInstruction(string text) { mNoInstructionRendered = true; - if (!Focused || checkContentsEditable()) + if (!Focused || CheckContentsEditable()) { SuspendLayout(); base.Text = text; @@ -321,17 +319,17 @@ void showNonInstruction(string text) } } - void this_KeyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { - if (mEditMode) assembleInstruction(true); + if (mEditMode) AssembleInstruction(true); e.Handled = true; } } - void this_KeyPress(object sender, KeyPressEventArgs e) + void This_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Escape) { @@ -341,23 +339,23 @@ void this_KeyPress(object sender, KeyPressEventArgs e) } } - void this_LostFocus(object sender, EventArgs e) + void This_LostFocus(object sender, EventArgs e) { - if (!mEditMode || !assembleInstruction(false)) + if (!mEditMode || !AssembleInstruction(false)) { mEditMode = false; Update(); } } - void this_ReadOnlyChanged(object sender, EventArgs e) + void This_ReadOnlyChanged(object sender, EventArgs e) { - if (Focused) checkContentsEditable(); + if (Focused) CheckContentsEditable(); } - void this_TextChanged(object sender, EventArgs e) + void This_TextChanged(object sender, EventArgs e) { - if (!mUpdating && !mEditMode) setEditMode(); + if (!mUpdating && !mEditMode) SetEditMode(); } public new string Text @@ -369,11 +367,11 @@ void this_TextChanged(object sender, EventArgs e) set { base.Text = value; - if (Focused) checkContentsEditable(); + if (Focused) CheckContentsEditable(); } } - int getAddress() + int GetAddress() { MixByte[] addressBytes = new MixByte[MixInstruction.AddressByteCount]; @@ -392,9 +390,9 @@ int getAddress() return address; } - void handleNoInstructionSet() + void HandleNoInstructionSet() { - showNonInstruction("No instructionset loaded"); + ShowNonInstruction("No instructionset loaded"); ContextMenu = null; mUpdating = false; @@ -402,9 +400,9 @@ void handleNoInstructionSet() mLastRenderedSign = Word.Signs.Positive; } - void handleNoInstruction(string caption) + void HandleNoInstruction(string caption) { - showNonInstruction("No instruction"); + ShowNonInstruction("No instruction"); mCaption = caption; mToolTip?.SetToolTip(this, caption); @@ -416,7 +414,7 @@ void handleNoInstruction(string caption) public new void Update() { var memoryFullWord = mInstructionWord as IMemoryFullWord; - string sourceLine = memoryFullWord != null ? memoryFullWord.SourceLine : null; + string sourceLine = memoryFullWord?.SourceLine; if (mEditMode || (mLastRenderedMagnitude == mInstructionWord.MagnitudeLongValue && mLastRenderedSign == mInstructionWord.Sign @@ -442,7 +440,7 @@ void handleNoInstruction(string caption) if (instruction == null) { - handleNoInstruction(sourceCaption); + HandleNoInstruction(sourceCaption); return; } @@ -454,14 +452,14 @@ void handleNoInstruction(string caption) base.Text = ""; ForeColor = mLastRenderedSourceLine != null ? mLoadedInstructionTextColor : mRenderedTextColor; - addTextElement(text.Mnemonic + " ", false); - addTextElement(text.Address, itemInErrors(errors, InstanceValidationError.Sources.Address)); - addTextElement(text.Index, itemInErrors(errors, InstanceValidationError.Sources.Index)); - addTextElement(text.Field, itemInErrors(errors, InstanceValidationError.Sources.FieldSpec)); + AddTextElement(text.Mnemonic + " ", false); + AddTextElement(text.Address, ItemInErrors(errors, InstanceValidationError.Sources.Address)); + AddTextElement(text.Index, ItemInErrors(errors, InstanceValidationError.Sources.Index)); + AddTextElement(text.Field, ItemInErrors(errors, InstanceValidationError.Sources.FieldSpec)); if (TextLength > 0) Select(TextLength, 0); - var caption = getAddressErrorsCaption(errors); + var caption = GetAddressErrorsCaption(errors); if (sourceCaption != null) { @@ -471,7 +469,7 @@ void handleNoInstruction(string caption) mCaption = caption; mToolTip?.SetToolTip(this, caption); - var address = getAddress(); + var address = GetAddress(); mShowAddressMenuItem.Enabled = address >= MemoryMinIndex && address <= MemoryMaxIndex; mShowIndexedAddressMenuItem.Enabled = IndexedAddressCalculatorCallback?.Invoke(address, mInstructionWord[MixInstruction.IndexByte]) != int.MinValue; ContextMenu = mContextMenu; @@ -483,7 +481,7 @@ void handleNoInstruction(string caption) mUpdating = false; } - string getAddressErrorsCaption(InstanceValidationError[] errors) + string GetAddressErrorsCaption(InstanceValidationError[] errors) { if (errors == null) return null; @@ -545,7 +543,7 @@ public IFullWord InstructionWord Update(); - if (Focused) checkContentsEditable(); + if (Focused) CheckContentsEditable(); } } } diff --git a/MixEmul/Components/LinkedItemsSelectorControl.cs b/MixEmul/Components/LinkedItemsSelectorControl.cs index c71afd6..72658d8 100644 --- a/MixEmul/Components/LinkedItemsSelectorControl.cs +++ b/MixEmul/Components/LinkedItemsSelectorControl.cs @@ -21,12 +21,12 @@ public class LinkedItemsSelectorControl : UserControl where T : class, IEquat public LinkedItemsSelectorControl() { - initializeComponent(); + InitializeComponent(); } protected void OnItemSelected(ItemSelectedEventArgs e) => ItemSelected?.Invoke(this, e); - void initializeComponent() + void InitializeComponent() { mNavigateForwards = new Button(); mNavigateBackwards = new Button(); @@ -41,7 +41,7 @@ void initializeComponent() mNavigateBackwards.Name = "mNavigateBackwards"; mNavigateBackwards.Size = new Size(21, 21); mNavigateBackwards.TabIndex = 0; - mNavigateBackwards.Click += mNavigateBackwards_Click; + mNavigateBackwards.Click += MNavigateBackwards_Click; // // mNavigateForwards // @@ -52,7 +52,7 @@ void initializeComponent() mNavigateForwards.Name = "mNavigateForwards"; mNavigateForwards.Size = mNavigateBackwards.Size; mNavigateForwards.TabIndex = 1; - mNavigateForwards.Click += mNavigateForwards_Click; + mNavigateForwards.Click += MNavigateForwards_Click; // // LinkedItemsSelectorControl // @@ -75,15 +75,15 @@ public void AddItem(T currentItem, T newItem) { if (currentItem.Equals(newItem)) return; - addItem(currentItem); - addItem(newItem); + AddItem(currentItem); + AddItem(newItem); - pruneToMaxItemCount(); + PruneToMaxItemCount(); - setEnabledState(); + SetEnabledState(); } - void pruneToMaxItemCount() + void PruneToMaxItemCount() { while (mItemCount > maxItemCount) { @@ -93,7 +93,7 @@ void pruneToMaxItemCount() } } - void removeItem(LinkedItem item) + void RemoveItem(LinkedItem item) { if (item.Next != null) { @@ -110,7 +110,7 @@ void removeItem(LinkedItem item) mItemCount--; } - void addItem(T item) + void AddItem(T item) { if (item == null) return; @@ -145,13 +145,13 @@ void addItem(T item) } } - void setEnabledState() + void SetEnabledState() { mNavigateBackwards.Enabled = mCurrentItem != null && mCurrentItem.Previous != null; mNavigateForwards.Enabled = mCurrentItem != null && mCurrentItem.Next != null; } - void mNavigateBackwards_Click(object sender, EventArgs e) + void MNavigateBackwards_Click(object sender, EventArgs e) { if (mGetCurrentItem != null) { @@ -159,7 +159,7 @@ void mNavigateBackwards_Click(object sender, EventArgs e) if (item != null && !mCurrentItem.Item.Equals(item) && !mCurrentItem.Previous.Item.Equals(item)) { - mCurrentItem = insertItem(mCurrentItem, item); + mCurrentItem = InsertItem(mCurrentItem, item); } } @@ -167,16 +167,17 @@ void mNavigateBackwards_Click(object sender, EventArgs e) OnItemSelected(new ItemSelectedEventArgs(mCurrentItem.Item)); - setEnabledState(); + SetEnabledState(); } - LinkedItem insertItem(LinkedItem insertBefore, T item) + LinkedItem InsertItem(LinkedItem insertBefore, T item) { if (insertBefore == null || item == null) return null; - var insertee = new LinkedItem(item); - - insertee.Previous = insertBefore.Previous; + var insertee = new LinkedItem(item) + { + Previous = insertBefore.Previous + }; if (insertee.Previous != null) { insertee.Previous.Next = insertee; @@ -195,7 +196,7 @@ LinkedItem insertItem(LinkedItem insertBefore, T item) return insertee; } - void mNavigateForwards_Click(object sender, EventArgs e) + void MNavigateForwards_Click(object sender, EventArgs e) { if (mGetCurrentItem != null) { @@ -203,7 +204,7 @@ void mNavigateForwards_Click(object sender, EventArgs e) if (item != null && !mCurrentItem.Item.Equals(item) && !mCurrentItem.Next.Item.Equals(item)) { - mCurrentItem = insertItem(mCurrentItem.Next, item); + mCurrentItem = InsertItem(mCurrentItem.Next, item); } } @@ -211,7 +212,7 @@ void mNavigateForwards_Click(object sender, EventArgs e) OnItemSelected(new ItemSelectedEventArgs(mCurrentItem.Item)); - setEnabledState(); + SetEnabledState(); } public void Clear() @@ -219,7 +220,7 @@ public void Clear() mFirstItem = mCurrentItem = null; mItemCount = 0; - setEnabledState(); + SetEnabledState(); } } diff --git a/MixEmul/Components/LogListView.cs b/MixEmul/Components/LogListView.cs index 0f14f09..a485da6 100644 --- a/MixEmul/Components/LogListView.cs +++ b/MixEmul/Components/LogListView.cs @@ -53,15 +53,15 @@ public LogListView() mListView.TabIndex = 0; mListView.View = View.Details; mListView.BorderStyle = BorderStyle.FixedSingle; - mListView.DoubleClick += doubleClick; - mListView.KeyPress += mListView_KeyPress; + mListView.DoubleClick += This_DoubleClick; + mListView.KeyPress += MListView_KeyPress; mClearButton.Anchor = AnchorStyles.Right | AnchorStyles.Top; mClearButton.Name = "mClearButton"; mClearButton.TabIndex = 1; mClearButton.Text = "&Clear"; mClearButton.Location = new Point(Width - mClearButton.Width, 0); - mClearButton.Click += mClearButton_Click; + mClearButton.Click += MClearButton_Click; mListView.Size = new Size(mClearButton.Width - 8, Size.Height); @@ -76,20 +76,20 @@ public void AddLogLine(LogLine line) => protected virtual void OnAddressSelected(AddressSelectedEventArgs args) => AddressSelected?.Invoke(this, args); - void doubleClick(object sender, EventArgs args) => addressSelected(); + void This_DoubleClick(object sender, EventArgs args) => HandleAddressSelected(); - void mClearButton_Click(object sender, EventArgs e) => mListView.Items.Clear(); + void MClearButton_Click(object sender, EventArgs e) => mListView.Items.Clear(); - void mListView_KeyPress(object sender, KeyPressEventArgs e) + void MListView_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { e.Handled = true; - addressSelected(); + HandleAddressSelected(); } } - void addressSelected() + void HandleAddressSelected() { int selectedAddress = SelectedAddress; if (selectedAddress != noAddress) OnAddressSelected(new AddressSelectedEventArgs(selectedAddress)); diff --git a/MixEmul/Components/LongValueTextBox.cs b/MixEmul/Components/LongValueTextBox.cs index eae926d..53c5c76 100644 --- a/MixEmul/Components/LongValueTextBox.cs +++ b/MixEmul/Components/LongValueTextBox.cs @@ -54,16 +54,16 @@ public LongValueTextBox(bool supportsSign, long minValue, long maxValue, Word.Si UpdateLayout(); - KeyDown += this_KeyDown; - KeyPress += this_KeyPress; - Leave += this_Leave; - TextChanged += this_TextChanged; + KeyDown += This_KeyDown; + KeyPress += This_KeyPress; + Leave += This_Leave; + TextChanged += This_TextChanged; Enter += LongValueTextBox_Enter; - setMinValue(minValue); - setMaxValue(maxValue); + SetMinValue(minValue); + SetMaxValue(maxValue); - checkAndUpdateValue(sign, magnitude); - checkAndUpdateMaxLength(); + CheckAndUpdateValue(sign, magnitude); + CheckAndUpdateMaxLength(); mUpdating = false; mEditMode = false; @@ -74,11 +74,11 @@ public LongValueTextBox(bool supportsSign, long minValue, long maxValue, Word.Si mLastValidText = mMagnitude.ToString(); } - void checkAndUpdateValue(Word.Signs newSign, long newMagnitude) => checkAndUpdateValue(newSign, newMagnitude, false); + void CheckAndUpdateValue(Word.Signs newSign, long newMagnitude) => CheckAndUpdateValue(newSign, newMagnitude, false); protected virtual void OnValueChanged(ValueChangedEventArgs args) => ValueChanged?.Invoke(this, args); - void this_Leave(object sender, EventArgs e) => checkAndUpdateValue(Text); + void This_Leave(object sender, EventArgs e) => CheckAndUpdateValue(Text); void LongValueTextBox_Enter(object sender, EventArgs e) { @@ -88,7 +88,7 @@ void LongValueTextBox_Enter(object sender, EventArgs e) } } - void this_KeyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.A) { @@ -125,12 +125,12 @@ void this_KeyDown(object sender, KeyEventArgs e) } } - void checkAndUpdateMaxLength() + void CheckAndUpdateMaxLength() { MaxLength = Math.Max(mMinValue.ToString().Length, mMaxValue.ToString().Length); } - void checkAndUpdateValue(string newValue) + void CheckAndUpdateValue(string newValue) { try { @@ -157,15 +157,15 @@ void checkAndUpdateValue(string newValue) magnitude = long.Parse(newValue.Substring(offset)); } - checkAndUpdateValue(sign, magnitude); + CheckAndUpdateValue(sign, magnitude); } catch (FormatException) { - checkAndUpdateValue(mLastValidText); + CheckAndUpdateValue(mLastValidText); } } - void checkAndUpdateValue(Word.Signs newSign, long newMagnitude, bool suppressEvent) + void CheckAndUpdateValue(Word.Signs newSign, long newMagnitude, bool suppressEvent) { mEditMode = false; var newValue = newSign.ApplyTo(newMagnitude); @@ -229,7 +229,7 @@ void checkAndUpdateValue(Word.Signs newSign, long newMagnitude, bool suppressEve } } - void setMaxValue(long value) + void SetMaxValue(long value) { mMaxValue = value; @@ -244,7 +244,7 @@ void setMaxValue(long value) } } - void setMinValue(long value) + void SetMinValue(long value) { mMinValue = value; if (mMinValue > mMaxValue) @@ -255,7 +255,7 @@ void setMinValue(long value) SupportSign = mMinValue < 0L; } - void this_KeyPress(object sender, KeyPressEventArgs e) + void This_KeyPress(object sender, KeyPressEventArgs e) { char keyChar = e.KeyChar; @@ -263,23 +263,23 @@ void this_KeyPress(object sender, KeyPressEventArgs e) { case Keys.Enter: e.Handled = true; - checkAndUpdateValue(Text); + CheckAndUpdateValue(Text); return; case Keys.Escape: e.Handled = true; - checkAndUpdateValue(mSign, mMagnitude); + CheckAndUpdateValue(mSign, mMagnitude); return; } - if (keyChar == '-' || (keyChar == '+' && Text.Length > 0 && Text[0] == '-')) changeSign(); + if (keyChar == '-' || (keyChar == '+' && Text.Length > 0 && Text[0] == '-')) ChangeSign(); e.Handled = !char.IsNumber(keyChar) && !char.IsControl(keyChar); } - void changeSign() + void ChangeSign() { int selectionStart = SelectionStart; int selectionLength = SelectionLength; @@ -320,11 +320,11 @@ public Word.Signs Sign } set { - if (mSign != value) checkAndUpdateValue(value, mMagnitude, true); + if (mSign != value) CheckAndUpdateValue(value, mMagnitude, true); } } - void this_TextChanged(object sender, EventArgs e) + void This_TextChanged(object sender, EventArgs e) { if (mUpdating) return; @@ -394,7 +394,7 @@ public long LongValue value = -value; } - if (sign != mSign || value != mMagnitude) checkAndUpdateValue(sign, value, true); + if (sign != mSign || value != mMagnitude) CheckAndUpdateValue(sign, value, true); } } @@ -408,7 +408,7 @@ public long Magnitude { value = value.GetMagnitude(); - if (mMagnitude != value) checkAndUpdateValue(mSign, value, true); + if (mMagnitude != value) CheckAndUpdateValue(mSign, value, true); } } @@ -422,9 +422,9 @@ public long MaxValue { if (mMaxValue != value) { - setMaxValue(value); - checkAndUpdateValue(mSign, mMagnitude); - checkAndUpdateMaxLength(); + SetMaxValue(value); + CheckAndUpdateValue(mSign, mMagnitude); + CheckAndUpdateMaxLength(); } } } @@ -439,9 +439,9 @@ public long MinValue { if (mMinValue != value) { - setMinValue(value); - checkAndUpdateValue(mSign, mMagnitude); - checkAndUpdateMaxLength(); + SetMinValue(value); + CheckAndUpdateValue(mSign, mMagnitude); + CheckAndUpdateMaxLength(); } } } @@ -457,7 +457,7 @@ public bool SupportNegativeZero if (mSupportNegativeZero != value) { mSupportNegativeZero = value; - checkAndUpdateValue(mSign, mMagnitude); + CheckAndUpdateValue(mSign, mMagnitude); } } } @@ -470,7 +470,7 @@ public override string Text } set { - checkAndUpdateValue(value); + CheckAndUpdateValue(value); } } diff --git a/MixEmul/Components/MemoryEditor.cs b/MixEmul/Components/MemoryEditor.cs index 37377b7..f4cff4b 100644 --- a/MixEmul/Components/MemoryEditor.cs +++ b/MixEmul/Components/MemoryEditor.cs @@ -54,20 +54,22 @@ public MemoryEditor(IMemory memory) mBreakpoints = SortedList.Synchronized(new SortedList()); - mNoMemoryLabel = new Label(); - mNoMemoryLabel.Location = new Point(0, 0); - mNoMemoryLabel.Name = "mNoMemoryLabel"; - mNoMemoryLabel.Size = new Size(120, 16); - mNoMemoryLabel.TabIndex = 0; - mNoMemoryLabel.Text = "No memory connected"; - mNoMemoryLabel.TextAlign = ContentAlignment.MiddleCenter; - - Memory = memory; + mNoMemoryLabel = new Label + { + Location = new Point(0, 0), + Name = "mNoMemoryLabel", + Size = new Size(120, 16), + TabIndex = 0, + Text = "No memory connected", + TextAlign = ContentAlignment.MiddleCenter + }; + + Memory = memory; } public ICollection Breakpoints => mBreakpoints.Values; - long getMaxProfilingCount(GuiSettings.ProfilingInfoType infoType) => mProfilingMaxCounts[(int)infoType]; + long GetMaxProfilingCount(GuiSettings.ProfilingInfoType infoType) => mProfilingMaxCounts[(int)infoType]; public bool IsBreakpointSet(int address) => mBreakpoints.Contains(address); @@ -79,12 +81,12 @@ public MemoryEditor(IMemory memory) protected virtual void OnAddressSelected(AddressSelectedEventArgs args) => AddressSelected?.Invoke(this, args); - void addressSelected(object sender, AddressSelectedEventArgs args) => MakeAddressVisible(args.SelectedAddress); + void This_AddressSelected(object sender, AddressSelectedEventArgs args) => MakeAddressVisible(args.SelectedAddress); - void addressDoubleClick(object sender, EventArgs e) => + void AddressDoubleClick(object sender, EventArgs e) => OnAddressSelected(new AddressSelectedEventArgs(((MemoryWordEditor)sender).MemoryWord.Index)); - void MemoryEditor_SizeChanged(object sender, EventArgs e) => setUpDownButtonStates(navigationDirection.None); + void MemoryEditor_SizeChanged(object sender, EventArgs e) => SetUpDownButtonStates(NavigationDirection.None); public ToolTip ToolTip { @@ -106,25 +108,27 @@ public ToolTip ToolTip } } - IWordEditor createWordEditor(int address) + IWordEditor CreateWordEditor(int address) { - var editor = new MemoryWordEditor(address >= mMemory.MinWordIndex ? mMemory[address] : new MemoryFullWord(address)); - editor.GetMaxProfilingCount = getMaxProfilingCount; - editor.MemoryMinIndex = mMemory.MinWordIndex; - editor.MemoryMaxIndex = mMemory.MaxWordIndex; - editor.IndexedAddressCalculatorCallback = mIndexedAddressCalculatorCallback; - editor.BreakPointChecked = mBreakpoints.Contains(address); - editor.Marked = mMarkedAddress == address; - editor.ToolTip = mToolTip; - editor.Symbols = mSymbols; - editor.BreakpointCheckedChanged += breakPointCheckedChanged; - editor.AddressDoubleClick += addressDoubleClick; - editor.AddressSelected += addressSelected; + var editor = new MemoryWordEditor(address >= mMemory.MinWordIndex ? mMemory[address] : new MemoryFullWord(address)) + { + GetMaxProfilingCount = GetMaxProfilingCount, + MemoryMinIndex = mMemory.MinWordIndex, + MemoryMaxIndex = mMemory.MaxWordIndex, + IndexedAddressCalculatorCallback = mIndexedAddressCalculatorCallback, + BreakPointChecked = mBreakpoints.Contains(address), + Marked = mMarkedAddress == address, + ToolTip = mToolTip, + Symbols = mSymbols + }; + editor.BreakpointCheckedChanged += BreakPointCheckedChanged; + editor.AddressDoubleClick += AddressDoubleClick; + editor.AddressSelected += This_AddressSelected; return editor; } - void loadWordEditor(IWordEditor editor, int address) + void LoadWordEditor(IWordEditor editor, int address) { var memoryEditor = (MemoryWordEditor)editor; @@ -141,7 +145,7 @@ void loadWordEditor(IWordEditor editor, int address) memoryEditor.Marked = mMarkedAddress == address; } - void breakPointCheckedChanged(object sender, EventArgs e) + void BreakPointCheckedChanged(object sender, EventArgs e) { if (!mWordEditorList.IsReloading) { @@ -168,7 +172,7 @@ public void ClearBreakpoints() } } - void initializeComponent() + void InitializeComponent() { SuspendLayout(); Controls.Clear(); @@ -207,12 +211,12 @@ void initializeComponent() mFirstAddressTextBox.Size = new Size(32, 20); mFirstAddressTextBox.TabIndex = 1; mFirstAddressTextBox.ClearZero = false; - mFirstAddressTextBox.ValueChanged += mFirstAddressTextBox_ValueChanged; + mFirstAddressTextBox.ValueChanged += MFirstAddressTextBox_ValueChanged; mAddressHistorySelector.Location = new Point(mFirstAddressTextBox.Right + 4, 0); mAddressHistorySelector.Name = "mAddressHistorySelector"; mAddressHistorySelector.TabIndex = 2; - mAddressHistorySelector.ItemSelected += mAddressHistorySelector_ItemSelected; + mAddressHistorySelector.ItemSelected += MAddressHistorySelector_ItemSelected; mSetClipboardLabel.Location = new Point(mAddressHistorySelector.Right + 16, 0); mSetClipboardLabel.Name = "mSetClipboardLabel"; @@ -230,7 +234,7 @@ void initializeComponent() mExportButton.Size = new Size(62, 21); mExportButton.TabIndex = 5; mExportButton.Text = "&Export..."; - mExportButton.Click += mExportButton_Click; + mExportButton.Click += MExportButton_Click; mDownButton.Visible = mMemory is Memory; mDownButton.Enabled = false; @@ -241,7 +245,7 @@ void initializeComponent() mDownButton.Size = new Size(21, 21); mDownButton.Location = new Point(Width - mDownButton.Width, 0); mDownButton.TabIndex = 7; - mDownButton.Click += mDownButton_Click; + mDownButton.Click += MDownButton_Click; mUpButton.Visible = mMemory is Memory; mUpButton.Enabled = false; @@ -252,7 +256,7 @@ void initializeComponent() mUpButton.Size = new Size(21, 21); mUpButton.Location = new Point(mDownButton.Left - mUpButton.Width, 0); mUpButton.TabIndex = 6; - mUpButton.Click += mUpButton_Click; + mUpButton.Click += MUpButton_Click; mFirstAddressPanel.Controls.Add(mFirstAddressLabel); mFirstAddressPanel.Controls.Add(mFirstAddressTextBox); @@ -267,10 +271,12 @@ void initializeComponent() mFirstAddressPanel.TabIndex = 0; mFirstAddressPanel.Size = new Size(Width, mFirstAddressTextBox.Height + 2); - mWordEditorList = new WordEditorList(mMemory.MinWordIndex, mMemory.MaxWordIndex, createWordEditor, loadWordEditor); - mWordEditorList.Dock = DockStyle.Fill; - mWordEditorList.ReadOnly = mReadOnly; - mWordEditorList.FirstVisibleIndexChanged += mWordEditorList_FirstVisibleIndexChanged; + mWordEditorList = new WordEditorList(mMemory.MinWordIndex, mMemory.MaxWordIndex, CreateWordEditor, LoadWordEditor) + { + Dock = DockStyle.Fill, + ReadOnly = mReadOnly + }; + mWordEditorList.FirstVisibleIndexChanged += MWordEditorList_FirstVisibleIndexChanged; Controls.Add(mWordEditorList); Controls.Add(mFirstAddressPanel); @@ -280,11 +286,11 @@ void initializeComponent() mFirstAddressPanel.ResumeLayout(false); ResumeLayout(false); - setUpDownButtonStates(navigationDirection.None); + SetUpDownButtonStates(NavigationDirection.None); } } - void setUpButtonState(Memory memory) + void SetUpButtonState(Memory memory) { mPrevDataIndex = null; @@ -322,7 +328,7 @@ void setUpButtonState(Memory memory) mUpButton.Enabled = mPrevDataIndex.HasValue; } - void setDownButtonState(Memory memory) + void SetDownButtonState(Memory memory) { mNextDataIndex = null; @@ -348,20 +354,20 @@ void setDownButtonState(Memory memory) mDownButton.Enabled = mNextDataIndex.HasValue; } - void setUpDownButtonStates(navigationDirection direction) + void SetUpDownButtonStates(NavigationDirection direction) { var memory = mMemory as Memory; if (memory == null || mWordEditorList == null) return; - if (direction != navigationDirection.Up || (mPrevDataIndex.HasValue && mPrevDataIndex.Value >= mWordEditorList.FirstVisibleIndex)) + if (direction != NavigationDirection.Up || (mPrevDataIndex.HasValue && mPrevDataIndex.Value >= mWordEditorList.FirstVisibleIndex)) { - setUpButtonState(memory); + SetUpButtonState(memory); } - if (direction != navigationDirection.Down || (mNextDataIndex.HasValue && mNextDataIndex.Value <= mWordEditorList.FirstVisibleIndex + mWordEditorList.VisibleEditorCount)) + if (direction != NavigationDirection.Down || (mNextDataIndex.HasValue && mNextDataIndex.Value <= mWordEditorList.FirstVisibleIndex + mWordEditorList.VisibleEditorCount)) { - setDownButtonState(memory); + SetDownButtonState(memory); } } @@ -379,7 +385,7 @@ public EditorListViewInfo GetCurrentListViewInfo() return viewInfo; } - void mAddressHistorySelector_ItemSelected(object sender, ItemSelectedEventArgs e) + void MAddressHistorySelector_ItemSelected(object sender, ItemSelectedEventArgs e) { EditorListViewInfo viewInfo = e.SelectedItem; @@ -403,15 +409,15 @@ void mAddressHistorySelector_ItemSelected(object sender, ItemSelectedEventArgs sender, WordEditorList.FirstVisibleIndexChangedEventArgs args) + void MWordEditorList_FirstVisibleIndexChanged(EditorList sender, WordEditorList.FirstVisibleIndexChangedEventArgs args) { if (args.FirstVisibleIndex < mFirstAddressTextBox.LongValue) { - setUpDownButtonStates(navigationDirection.Up); + SetUpDownButtonStates(NavigationDirection.Up); } else if (args.FirstVisibleIndex > mFirstAddressTextBox.LongValue) { - setUpDownButtonStates(navigationDirection.Down); + SetUpDownButtonStates(NavigationDirection.Down); } mFirstAddressTextBox.LongValue = args.FirstVisibleIndex; @@ -440,7 +446,7 @@ public void MakeAddressVisible(int address, bool trackChange) } } - void mFirstAddressTextBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) + void MFirstAddressTextBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) { var oldViewInfo = new EditorListViewInfo { FirstVisibleIndex = mWordEditorList.FirstVisibleIndex }; int selectedEditorIndex = mWordEditorList.ActiveEditorIndex; @@ -496,7 +502,7 @@ public bool ResizeInProgress mProfilingMaxCounts[(int)GuiSettings.ProfilingInfoType.Execution] = mMemory.MaxProfilingExecutionCount; mProfilingMaxCounts[(int)GuiSettings.ProfilingInfoType.Tick] = mMemory.MaxProfilingTickCount; mWordEditorList.Update(); - setUpDownButtonStates(navigationDirection.None); + SetUpDownButtonStates(NavigationDirection.None); base.Update(); } @@ -575,16 +581,16 @@ public int MarkedAddress { if (mMarkedAddress != value) { - setAddressMarkIfVisible(false); + SetAddressMarkIfVisible(false); mMarkedAddress = value; - setAddressMarkIfVisible(true); + SetAddressMarkIfVisible(true); } } } - void setAddressMarkIfVisible(bool mark) + void SetAddressMarkIfVisible(bool mark) { int firstVisibleIndex = mWordEditorList.FirstVisibleIndex; @@ -605,7 +611,7 @@ public IMemory Memory if (mMemory == null && value != null) { mMemory = value; - initializeComponent(); + InitializeComponent(); mProfilingMaxCounts[(int)GuiSettings.ProfilingInfoType.Execution] = mMemory.MaxProfilingExecutionCount; mProfilingMaxCounts[(int)GuiSettings.ProfilingInfoType.Tick] = mMemory.MaxProfilingTickCount; } @@ -651,7 +657,7 @@ public SymbolCollection Symbols } } - void mUpButton_Click(object sender, EventArgs args) + void MUpButton_Click(object sender, EventArgs args) { if (mPrevDataIndex.HasValue) { @@ -659,7 +665,7 @@ void mUpButton_Click(object sender, EventArgs args) } } - void mDownButton_Click(object sender, EventArgs args) + void MDownButton_Click(object sender, EventArgs args) { if (mNextDataIndex.HasValue) { @@ -667,23 +673,27 @@ void mDownButton_Click(object sender, EventArgs args) } } - void mExportButton_Click(object sender, EventArgs args) + void MExportButton_Click(object sender, EventArgs args) { - var exportDialog = new MemoryExportDialog(); - exportDialog.MinMemoryIndex = mMemory.MinWordIndex; - exportDialog.MaxMemoryIndex = mMemory.MaxWordIndex; - exportDialog.FromAddress = mWordEditorList.FirstVisibleIndex; - exportDialog.ToAddress = mWordEditorList.FirstVisibleIndex + mWordEditorList.VisibleEditorCount - 1; - exportDialog.ProgramCounter = mMarkedAddress; + var exportDialog = new MemoryExportDialog + { + MinMemoryIndex = mMemory.MinWordIndex, + MaxMemoryIndex = mMemory.MaxWordIndex, + FromAddress = mWordEditorList.FirstVisibleIndex, + ToAddress = mWordEditorList.FirstVisibleIndex + mWordEditorList.VisibleEditorCount - 1, + ProgramCounter = mMarkedAddress + }; if (exportDialog.ShowDialog(this) != DialogResult.OK) return; if (mSaveExportFileDialog == null) { - mSaveExportFileDialog = new SaveFileDialog(); - mSaveExportFileDialog.DefaultExt = "mixdeck"; - mSaveExportFileDialog.Filter = "MixEmul card deck files|*.mixdeck|All files|*.*"; - mSaveExportFileDialog.Title = "Specify export file name"; + mSaveExportFileDialog = new SaveFileDialog + { + DefaultExt = "mixdeck", + Filter = "MixEmul card deck files|*.mixdeck|All files|*.*", + Title = "Specify export file name" + }; } if (mSaveExportFileDialog.ShowDialog(this) == DialogResult.OK) @@ -708,7 +718,7 @@ void mExportButton_Click(object sender, EventArgs args) } } - enum navigationDirection + enum NavigationDirection { None, Up, diff --git a/MixEmul/Components/MemoryExportDialog.Designer.cs b/MixEmul/Components/MemoryExportDialog.Designer.cs index 2b2da27..afc0762 100644 --- a/MixEmul/Components/MemoryExportDialog.Designer.cs +++ b/MixEmul/Components/MemoryExportDialog.Designer.cs @@ -53,7 +53,7 @@ private void InitializeComponent() this.mFromAddressUpDown.Name = "mFromAddressUpDown"; this.mFromAddressUpDown.Size = new System.Drawing.Size(59, 20); this.mFromAddressUpDown.TabIndex = 1; - this.mFromAddressUpDown.ValueChanged += new System.EventHandler(this.mFromAddressUpDown_ValueChanged); + this.mFromAddressUpDown.ValueChanged += new System.EventHandler(this.MFromAddressUpDown_ValueChanged); // // mToAddressLabel // @@ -70,7 +70,7 @@ private void InitializeComponent() this.mToAddressUpDown.Name = "mToAddressUpDown"; this.mToAddressUpDown.Size = new System.Drawing.Size(59, 20); this.mToAddressUpDown.TabIndex = 3; - this.mToAddressUpDown.ValueChanged += new System.EventHandler(this.mToAddressUpDown_ValueChanged); + this.mToAddressUpDown.ValueChanged += new System.EventHandler(this.MToAddressUpDown_ValueChanged); // // mProgramCounterLabel // diff --git a/MixEmul/Components/MemoryExportDialog.cs b/MixEmul/Components/MemoryExportDialog.cs index 3eb64db..e99d647 100644 --- a/MixEmul/Components/MemoryExportDialog.cs +++ b/MixEmul/Components/MemoryExportDialog.cs @@ -66,7 +66,7 @@ public int ProgramCounter } } - void mFromAddressUpDown_ValueChanged(object sender, EventArgs e) + void MFromAddressUpDown_ValueChanged(object sender, EventArgs e) { if (mToAddressUpDown.Value < mFromAddressUpDown.Value) { @@ -74,7 +74,7 @@ void mFromAddressUpDown_ValueChanged(object sender, EventArgs e) } } - void mToAddressUpDown_ValueChanged(object sender, EventArgs e) + void MToAddressUpDown_ValueChanged(object sender, EventArgs e) { if (mFromAddressUpDown.Value > mToAddressUpDown.Value) { diff --git a/MixEmul/Components/MemoryWordEditor.cs b/MixEmul/Components/MemoryWordEditor.cs index 6f96ae0..04e96b0 100644 --- a/MixEmul/Components/MemoryWordEditor.cs +++ b/MixEmul/Components/MemoryWordEditor.cs @@ -59,11 +59,11 @@ public MemoryWordEditor(IMemoryFullWord memoryWord) mColonLabel = new Label(); mColonLabel2 = new Label(); mProfileLabel = new Label(); - initializeComponent(); + InitializeComponent(); MemoryWord = memoryWord; - updateProfilingLayout(); + UpdateProfilingLayout(); } public Control EditorControl => this; @@ -75,12 +75,12 @@ public MemoryWordEditor(IMemoryFullWord memoryWord) public bool Focus(FieldTypes? field, int? index) => field == FieldTypes.Instruction ? mInstructionTextBox.FocusWithIndex(index) : mFullWordEditor.Focus(field, index); - Color getBlendedColor(double fraction) => - fraction < .5 ? interpolate(Color.Green, Color.Yellow, fraction * 2) : interpolate(Color.Yellow, Color.Red, fraction * 2 - 1); + Color GetBlendedColor(double fraction) => + fraction < .5 ? Interpolate(Color.Green, Color.Yellow, fraction * 2) : Interpolate(Color.Yellow, Color.Red, fraction * 2 - 1); - int roundForArgb(double d) => d < 0 ? 0 : (d > 255 ? 255 : (int)d); + int RoundForArgb(double d) => d < 0 ? 0 : (d > 255 ? 255 : (int)d); - double interpolate(double d1, double d2, double fraction) => d1 * (1 - fraction) + d2 * fraction; + double Interpolate(double d1, double d2, double fraction) => d1 * (1 - fraction) + d2 * fraction; void OnAddressSelected(AddressSelectedEventArgs args) => AddressSelected?.Invoke(this, args); @@ -90,13 +90,13 @@ Color getBlendedColor(double fraction) => protected virtual void OnValueChanged(WordEditorValueChangedEventArgs args) => ValueChanged?.Invoke(this, args); - void mInstructionTextBox_MouseWheel(object sender, MouseEventArgs e) => OnMouseWheel(e); + void MInstructionTextBox_MouseWheel(object sender, MouseEventArgs e) => OnMouseWheel(e); - void mInstructionTextBox_AddressSelected(object sender, AddressSelectedEventArgs args) => OnAddressSelected(args); + void MInstructionTextBox_AddressSelected(object sender, AddressSelectedEventArgs args) => OnAddressSelected(args); - void mAddressLabel_DoubleClick(object sender, EventArgs e) => OnAddressDoubleClick(e); + void MAddressLabel_DoubleClick(object sender, EventArgs e) => OnAddressDoubleClick(e); - void mBreakPointBox_CheckedChanged(object sender, EventArgs e) => OnBreakpointCheckedChanged(e); + void MBreakPointBox_CheckedChanged(object sender, EventArgs e) => OnBreakpointCheckedChanged(e); public GetMaxProfilingCountCallback GetMaxProfilingCount { @@ -109,12 +109,12 @@ public GetMaxProfilingCountCallback GetMaxProfilingCount if (mGetMaxProfilingCount != value) { mGetMaxProfilingCount = value; - updateProfilingCount(); + UpdateProfilingCount(); } } } - void initializeComponent() + void InitializeComponent() { mAddressPanel.SuspendLayout(); SuspendLayout(); @@ -123,7 +123,7 @@ void initializeComponent() mBreakPointBox.Name = "mBreakPointBox"; mBreakPointBox.Size = new Size(16, 17); mBreakPointBox.TabIndex = 0; - mBreakPointBox.CheckedChanged += mBreakPointBox_CheckedChanged; + mBreakPointBox.CheckedChanged += MBreakPointBox_CheckedChanged; mAddressLabel.Font = GuiSettings.GetFont(GuiSettings.FixedWidth); mAddressLabel.ForeColor = GuiSettings.GetColor(GuiSettings.AddressText); @@ -133,7 +133,7 @@ void initializeComponent() mAddressLabel.TabIndex = 1; mAddressLabel.Text = "0000"; mAddressLabel.TextAlign = ContentAlignment.MiddleCenter; - mAddressLabel.DoubleClick += mAddressLabel_DoubleClick; + mAddressLabel.DoubleClick += MAddressLabel_DoubleClick; mAddressPanel.Controls.Add(mBreakPointBox); mAddressPanel.Controls.Add(mAddressLabel); @@ -150,8 +150,8 @@ void initializeComponent() mFullWordEditor.Location = new Point(mColonLabel.Right, mAddressPanel.Top); mFullWordEditor.Name = "mFullWordEditor"; mFullWordEditor.TabIndex = 2; - mFullWordEditor.ValueChanged += mFullWordEditor_ValueChanged; - mFullWordEditor.NavigationKeyDown += keyDown; + mFullWordEditor.ValueChanged += MFullWordEditor_ValueChanged; + mFullWordEditor.NavigationKeyDown += This_KeyDown; mEqualsLabel.Location = new Point(mFullWordEditor.Right, mFullWordEditor.Top + 2); mEqualsLabel.Name = "mEqualsLabel"; @@ -167,10 +167,10 @@ void initializeComponent() mInstructionTextBox.Name = "mInstructionTextBox"; mInstructionTextBox.Size = new Size(128, 21); mInstructionTextBox.TabIndex = 0; - mInstructionTextBox.KeyDown += keyDown; - mInstructionTextBox.ValueChanged += mInstructionTextBox_ValueChanged; - mInstructionTextBox.AddressSelected += mInstructionTextBox_AddressSelected; - mInstructionTextBox.MouseWheel += mInstructionTextBox_MouseWheel; + mInstructionTextBox.KeyDown += This_KeyDown; + mInstructionTextBox.ValueChanged += MInstructionTextBox_ValueChanged; + mInstructionTextBox.AddressSelected += MInstructionTextBox_AddressSelected; + mInstructionTextBox.MouseWheel += MInstructionTextBox_MouseWheel; mInstructionPanel.Controls.Add(mInstructionTextBox); mInstructionPanel.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top; @@ -205,21 +205,21 @@ void initializeComponent() Controls.Add(mProfileLabel); Name = "MemoryWordEditor"; Size = new Size(mProfileLabel.Right + 2, mInstructionPanel.Height + 3); - KeyDown += keyDown; + KeyDown += This_KeyDown; mAddressPanel.ResumeLayout(false); ResumeLayout(false); } - Color interpolate(Color color1, Color color2, double fraction) + Color Interpolate(Color color1, Color color2, double fraction) { - var r = roundForArgb(interpolate(color1.R, color2.R, fraction)); - var g = roundForArgb(interpolate(color1.G, color2.G, fraction)); - var b = roundForArgb(interpolate(color1.B, color2.B, fraction)); + var r = RoundForArgb(Interpolate(color1.R, color2.R, fraction)); + var g = RoundForArgb(Interpolate(color1.G, color2.G, fraction)); + var b = RoundForArgb(Interpolate(color1.B, color2.B, fraction)); return Color.FromArgb(r, g, b); } - void updateProfilingCount() + void UpdateProfilingCount() { long count = GuiSettings.ShowProfilingInfo == GuiSettings.ProfilingInfoType.Tick ? mMemoryWord.ProfilingTickCount : mMemoryWord.ProfilingExecutionCount; long max; @@ -231,15 +231,15 @@ void updateProfilingCount() } else { - var backColor = getBlendedColor((double)count / max); + var backColor = GetBlendedColor((double)count / max); mProfileLabel.BackColor = backColor; mProfileLabel.ForeColor = 255 - (int)(backColor.R * 0.299 + backColor.G * 0.587 + backColor.B * 0.114) < 105 ? Color.Black : Color.White; } } - void updateProfilingLayout() + void UpdateProfilingLayout() { - if (ExecutionSettings.ProfilingEnabled) updateProfilingCount(); + if (ExecutionSettings.ProfilingEnabled) UpdateProfilingCount(); if (mProfileLabel.Enabled == ExecutionSettings.ProfilingEnabled) return; @@ -283,7 +283,7 @@ public int MemoryMaxIndex } } - void keyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers != Keys.None) return; @@ -335,13 +335,13 @@ void keyDown(object sender, KeyEventArgs e) } } - void mInstructionTextBox_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) + void MInstructionTextBox_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) { mFullWordEditor.Update(); OnValueChanged(args); } - void mFullWordEditor_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) + void MFullWordEditor_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) { mInstructionTextBox.Update(); OnValueChanged(args); @@ -351,7 +351,7 @@ void mFullWordEditor_ValueChanged(IWordEditor sender, WordEditorValueChangedEven { mFullWordEditor.Update(); mInstructionTextBox.Update(); - if (mProfileLabel.Enabled) updateProfilingCount(); + if (mProfileLabel.Enabled) UpdateProfilingCount(); base.Update(); } @@ -368,7 +368,7 @@ public void UpdateLayout() mFullWordEditor.UpdateLayout(); mInstructionTextBox.UpdateLayout(); - updateProfilingLayout(); + UpdateProfilingLayout(); } public bool BreakPointChecked @@ -419,12 +419,7 @@ public IMemoryFullWord MemoryWord } set { - if (value == null) - { - throw new ArgumentNullException(nameof(value), "MemoryWord may not be set to null"); - } - - mMemoryWord = value; + mMemoryWord = value ?? throw new ArgumentNullException(nameof(value), "MemoryWord may not be set to null"); var text = mMemoryWord.Index.ToString("D4"); if (mMemoryWord.Index == 0) { @@ -438,7 +433,7 @@ public IMemoryFullWord MemoryWord mInstructionTextBox.MemoryAddress = mMemoryWord.Index; mFullWordEditor.WordValue = mMemoryWord; mInstructionTextBox.InstructionWord = mMemoryWord; - if (mProfileLabel.Enabled) updateProfilingCount(); + if (mProfileLabel.Enabled) UpdateProfilingCount(); } } diff --git a/MixEmul/Components/MixByteCollectionCharTextBox.cs b/MixEmul/Components/MixByteCollectionCharTextBox.cs index 7223b54..1d9fe33 100644 --- a/MixEmul/Components/MixByteCollectionCharTextBox.cs +++ b/MixEmul/Components/MixByteCollectionCharTextBox.cs @@ -46,10 +46,10 @@ public MixByteCollectionCharTextBox(IMixByteCollection byteCollection) Location = new Point(40, 16); Size = new Size(48, 21); BorderStyle = BorderStyle.FixedSingle; - KeyDown += this_KeyDown; - KeyPress += this_KeyPress; - Leave += this_Leave; - TextChanged += this_TextChanged; + KeyDown += This_KeyDown; + KeyPress += This_KeyPress; + Leave += This_Leave; + TextChanged += This_TextChanged; // base.MaxLength = mByteCollection.MaxByteCount; ResumeLayout(false); @@ -71,9 +71,9 @@ public MixByteCollectionCharTextBox(IMixByteCollection byteCollection) protected void OnValueChanged(MixByteCollectionEditorValueChangedEventArgs args) => ValueChanged?.Invoke(this, args); - void this_Leave(object sender, EventArgs e) => updateValue(); + void This_Leave(object sender, EventArgs e) => UpdateValue(); - void this_KeyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.A) { @@ -114,7 +114,7 @@ void this_KeyDown(object sender, KeyEventArgs e) } } - void this_KeyPress(object sender, KeyPressEventArgs e) + void This_KeyPress(object sender, KeyPressEventArgs e) { char keyChar = e.KeyChar; if (mEditMode) @@ -123,7 +123,7 @@ void this_KeyPress(object sender, KeyPressEventArgs e) { case Keys.Enter: e.Handled = true; - updateValue(); + UpdateValue(); return; @@ -140,7 +140,7 @@ void this_KeyPress(object sender, KeyPressEventArgs e) e.Handled = (index < 0 || index == MixByte.MixChars.Length - 2) && !char.IsControl(keyChar); } - void this_TextChanged(object sender, EventArgs e) + void This_TextChanged(object sender, EventArgs e) { if (!mUpdating) { @@ -166,7 +166,7 @@ void this_TextChanged(object sender, EventArgs e) if (!UseEditMode) { - updateValue(); + UpdateValue(); } else if (!mEditMode) { @@ -185,7 +185,7 @@ void this_TextChanged(object sender, EventArgs e) } } - bool arraysEqual(MixByte[] one, MixByte[] two) + bool ArraysEqual(MixByte[] one, MixByte[] two) { if ((one == null && two != null) || (one != null && two == null)) return false; if (one == null && two == null) return true; @@ -203,7 +203,7 @@ bool arraysEqual(MixByte[] one, MixByte[] two) { var byteCollectionBytes = mByteCollection.ToArray(); - if (mEditMode || mLastRenderedBytes == null || !arraysEqual(mLastRenderedBytes, byteCollectionBytes)) + if (mEditMode || mLastRenderedBytes == null || !ArraysEqual(mLastRenderedBytes, byteCollectionBytes)) { mEditMode = false; mLastRenderedBytes = byteCollectionBytes; @@ -238,7 +238,7 @@ public void UpdateLayout() ResumeLayout(); } - void updateValue() + void UpdateValue() { int currentCharIndex = 0; var oldValue = (IMixByteCollection)mByteCollection.Clone(); diff --git a/MixEmul/Components/MixByteTextBox.cs b/MixEmul/Components/MixByteTextBox.cs index 6009e59..ec3e264 100644 --- a/MixEmul/Components/MixByteTextBox.cs +++ b/MixEmul/Components/MixByteTextBox.cs @@ -50,20 +50,20 @@ public MixByteTextBox(int index) UpdateLayout(); - Leave += this_Leave; - Enter += this_Enter; - KeyPress += this_KeyPress; - KeyDown += this_KeyDown; - TextChanged += this_TextChanged; + Leave += This_Leave; + Enter += This_Enter; + KeyPress += This_KeyPress; + KeyDown += This_KeyDown; + TextChanged += This_TextChanged; } protected virtual void OnValueChanged(ValueChangedEventArgs args) => ValueChanged?.Invoke(this, args); - void this_Enter(object sender, EventArgs e) => Select(0, TextLength); + void This_Enter(object sender, EventArgs e) => Select(0, TextLength); - void this_Leave(object sender, EventArgs e) => checkAndUpdateValue(Text); + void This_Leave(object sender, EventArgs e) => CheckAndUpdateValue(Text); - void checkAndUpdateValue(byte byteValue) + void CheckAndUpdateValue(byte byteValue) { mEditMode = false; @@ -88,7 +88,7 @@ void checkAndUpdateValue(byte byteValue) if (oldByteValue != mByteValue) OnValueChanged(new ValueChangedEventArgs(mByteValue, mByteValue)); } - void this_KeyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.A) { @@ -98,18 +98,18 @@ void this_KeyDown(object sender, KeyEventArgs e) } } - void checkAndUpdateValue(string newValue) + void CheckAndUpdateValue(string newValue) { try { - checkAndUpdateValue(newValue == "" ? (byte)0 : byte.Parse(newValue)); + CheckAndUpdateValue(newValue == "" ? (byte)0 : byte.Parse(newValue)); } catch (FormatException) { } } - void this_KeyPress(object sender, KeyPressEventArgs e) + void This_KeyPress(object sender, KeyPressEventArgs e) { char keyChar = e.KeyChar; @@ -117,13 +117,13 @@ void this_KeyPress(object sender, KeyPressEventArgs e) { case Keys.Enter: e.Handled = true; - checkAndUpdateValue(Text); + CheckAndUpdateValue(Text); return; case Keys.Escape: e.Handled = true; - checkAndUpdateValue(mByteValue); + CheckAndUpdateValue(mByteValue); return; } @@ -131,7 +131,7 @@ void this_KeyPress(object sender, KeyPressEventArgs e) e.Handled = !char.IsNumber(keyChar) && !char.IsControl(keyChar); } - void this_TextChanged(object sender, EventArgs e) + void This_TextChanged(object sender, EventArgs e) { if (!mUpdating) { @@ -195,7 +195,7 @@ public MixByte MixByteValue set { mByteValue = value; - checkAndUpdateValue(mByteValue); + CheckAndUpdateValue(mByteValue); } } @@ -207,7 +207,7 @@ public sealed override string Text } set { - checkAndUpdateValue(value); + CheckAndUpdateValue(value); } } diff --git a/MixEmul/Components/MixCharClipboardButtonControl.cs b/MixEmul/Components/MixCharClipboardButtonControl.cs index f34bb98..3a5f3bc 100644 Binary files a/MixEmul/Components/MixCharClipboardButtonControl.cs and b/MixEmul/Components/MixCharClipboardButtonControl.cs differ diff --git a/MixEmul/Components/PreferencesForm.cs b/MixEmul/Components/PreferencesForm.cs index 573a712..d3d729a 100644 --- a/MixEmul/Components/PreferencesForm.cs +++ b/MixEmul/Components/PreferencesForm.cs @@ -72,35 +72,35 @@ public PreferencesForm(Configuration configuration, Devices devices, string defa InitializeComponent(); mShowColorLabel.Font = GuiSettings.GetFont(GuiSettings.FixedWidth); - fillDeviceReloadIntervalSelectionBox(); + FillDeviceReloadIntervalSelectionBox(); mConfiguration = configuration; mDevices = devices; mDefaultDirectory = defaultDirectory; mDeviceReloadInterval = DeviceSettings.UnsetDeviceReloadInterval; - initializeLoaderCardTextBoxes(); + InitializeLoaderCardTextBoxes(); } - string getCurrentDeviceFilesDirectory() => mDeviceFilesDirectory ?? DeviceSettings.DefaultDeviceFilesDirectory; + string GetCurrentDeviceFilesDirectory() => mDeviceFilesDirectory ?? DeviceSettings.DefaultDeviceFilesDirectory; public void UpdateLayout() => mTickCountBox.UpdateLayout(); - void mColorSelectionBox_SelectionChangeCommited(object sender, EventArgs e) => - updateColorControls((colorComboBoxItem)mColorSelectionBox.SelectedItem); + void MColorSelectionBox_SelectionChangeCommited(object sender, EventArgs e) => + UpdateColorControls((ColorComboBoxItem)mColorSelectionBox.SelectedItem); - void mDeviceFileSelectionBox_SelectionChangeCommitted(object sender, EventArgs e) => - updateDeviceFileControls((deviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); + void MDeviceFileSelectionBox_SelectionChangeCommitted(object sender, EventArgs e) => + UpdateDeviceFileControls((DeviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); - void mTickCountSelectionBox_SelectionChangeCommitted(object sender, EventArgs e) => - updateTickCountControls((tickCountComboBoxItem)mTickCountSelectionBox.SelectedItem); + void MTickCountSelectionBox_SelectionChangeCommitted(object sender, EventArgs e) => + UpdateTickCountControls((TickCountComboBoxItem)mTickCountSelectionBox.SelectedItem); - void mTickCountSetButton_Click(object sender, EventArgs e) => setTickCountValue(); + void MTickCountSetButton_Click(object sender, EventArgs e) => SetTickCountValue(); - void mLoaderCardsDefaultButton_Click(object sender, EventArgs e) => loadDefaultLoaderCards(); + void MLoaderCardsDefaultButton_Click(object sender, EventArgs e) => LoadDefaultLoaderCards(); - void initializeLoaderCardTextBoxes() + void InitializeLoaderCardTextBoxes() { mLoaderCardTextBoxes = new MixByteCollectionCharTextBox[] { mLoaderCard1TextBox, mLoaderCard2TextBox, mLoaderCard3TextBox }; @@ -108,17 +108,17 @@ void initializeLoaderCardTextBoxes() { MixByteCollectionCharTextBox loaderCardTextBox = mLoaderCardTextBoxes[index]; loaderCardTextBox.MixByteCollectionValue = new MixByteCollection(CardReaderDevice.BytesPerRecord); - loaderCardTextBox.NavigationKeyDown += keyDown; - loaderCardTextBox.ValueChanged += loaderCardTextBox_ValueChanged; + loaderCardTextBox.NavigationKeyDown += This_KeyDown; + loaderCardTextBox.ValueChanged += LoaderCardTextBox_ValueChanged; } } - void loaderCardTextBox_ValueChanged(IMixByteCollectionEditor sender, MixByteCollectionEditorValueChangedEventArgs args) + void LoaderCardTextBox_ValueChanged(IMixByteCollectionEditor sender, MixByteCollectionEditorValueChangedEventArgs args) { mLoaderCardsDefaultButton.Enabled = true; } - void keyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (!(sender is MixByteCollectionCharTextBox) || e.Modifiers != Keys.None) return; @@ -154,25 +154,25 @@ void keyDown(object sender, KeyEventArgs e) } } - void fillDeviceReloadIntervalSelectionBox() + void FillDeviceReloadIntervalSelectionBox() { - mDeviceReloadIntervalComboBox.Items.Add(new deviceReloadIntervalComboBoxItem(250)); - mDeviceReloadIntervalComboBox.Items.Add(new deviceReloadIntervalComboBoxItem(500)); - mDeviceReloadIntervalComboBox.Items.Add(new deviceReloadIntervalComboBoxItem(750)); - mDeviceReloadIntervalComboBox.Items.Add(new deviceReloadIntervalComboBoxItem(1000)); - mDeviceReloadIntervalComboBox.Items.Add(new deviceReloadIntervalComboBoxItem(1500)); - mDeviceReloadIntervalComboBox.Items.Add(new deviceReloadIntervalComboBoxItem(2000)); + mDeviceReloadIntervalComboBox.Items.Add(new DeviceReloadIntervalComboBoxItem(250)); + mDeviceReloadIntervalComboBox.Items.Add(new DeviceReloadIntervalComboBoxItem(500)); + mDeviceReloadIntervalComboBox.Items.Add(new DeviceReloadIntervalComboBoxItem(750)); + mDeviceReloadIntervalComboBox.Items.Add(new DeviceReloadIntervalComboBoxItem(1000)); + mDeviceReloadIntervalComboBox.Items.Add(new DeviceReloadIntervalComboBoxItem(1500)); + mDeviceReloadIntervalComboBox.Items.Add(new DeviceReloadIntervalComboBoxItem(2000)); } - void fillColorSelectionBox() + void FillColorSelectionBox() { mColorSelectionBox.Items.Clear(); string[] knownColorNames = GuiSettings.KnownColorNames; - var list = new List(); + var list = new List(); foreach (string colorName in knownColorNames) { - var comboBoxItem = new colorComboBoxItem(colorName); + var comboBoxItem = new ColorComboBoxItem(colorName); if (mConfiguration.Colors.ContainsKey(colorName)) { comboBoxItem.Color = mConfiguration.Colors[colorName]; @@ -186,18 +186,18 @@ void fillColorSelectionBox() mColorSelectionBox.SelectedIndex = 0; } - updateColorControls((colorComboBoxItem)mColorSelectionBox.SelectedItem); + UpdateColorControls((ColorComboBoxItem)mColorSelectionBox.SelectedItem); } - void fillDeviceFileSelectionBox() + void FillDeviceFileSelectionBox() { mDeviceFileSelectionBox.Items.Clear(); - var list = new List(); + var list = new List(); foreach (MixDevice device in mDevices) { if (!(device is FileBasedDevice)) continue; - var item = new deviceFileComboBoxItem((FileBasedDevice)device); + var item = new DeviceFileComboBoxItem((FileBasedDevice)device); if (mConfiguration.DeviceFilePaths.ContainsKey(device.Id)) { @@ -214,19 +214,19 @@ void fillDeviceFileSelectionBox() mDeviceFileSelectionBox.SelectedIndex = 0; } - updateDeviceFileControls((deviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); + UpdateDeviceFileControls((DeviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); } - void fillTickCountSelectionBox() + void FillTickCountSelectionBox() { mTickCountSelectionBox.Items.Clear(); string[] knownTickCountNames = DeviceSettings.KnownTickCountNames; - var list = new List(); + var list = new List(); foreach (string tickCountName in knownTickCountNames) { - var item = new tickCountComboBoxItem(tickCountName); + var item = new TickCountComboBoxItem(tickCountName); if (mConfiguration.TickCounts.ContainsKey(tickCountName)) { @@ -243,10 +243,10 @@ void fillTickCountSelectionBox() mTickCountSelectionBox.SelectedIndex = 0; } - updateTickCountControls((tickCountComboBoxItem)mTickCountSelectionBox.SelectedItem); + UpdateTickCountControls((TickCountComboBoxItem)mTickCountSelectionBox.SelectedItem); } - public Control getFocusedControl() + public Control GetFocusedControl() { ContainerControl container = this; Control control = null; @@ -260,7 +260,7 @@ public Control getFocusedControl() return control; } - Color getMatchingColor(string name, bool wantBackground) + Color GetMatchingColor(string name, bool wantBackground) { string matchingColorName; if (wantBackground) @@ -293,7 +293,7 @@ Color getMatchingColor(string name, bool wantBackground) matchingColorName = wantBackground ? "EditorBackground" : "RenderedText"; } - foreach (colorComboBoxItem item in mColorSelectionBox.Items) + foreach (ColorComboBoxItem item in mColorSelectionBox.Items) { if (item.Name == matchingColorName) return item.Color; } @@ -392,7 +392,7 @@ void InitializeComponent() mColorSetButton.Size = new Size(40, 23); mColorSetButton.TabIndex = 2; mColorSetButton.Text = "&Set..."; - mColorSetButton.Click += mColorSetButton_Click; + mColorSetButton.Click += MColorSetButton_Click; // // mShowColorLabel // @@ -415,7 +415,7 @@ void InitializeComponent() mColorSelectionBox.Size = new Size(182, 21); mColorSelectionBox.Sorted = true; mColorSelectionBox.TabIndex = 0; - mColorSelectionBox.SelectionChangeCommitted += mColorSelectionBox_SelectionChangeCommited; + mColorSelectionBox.SelectionChangeCommitted += MColorSelectionBox_SelectionChangeCommited; // // mColorDefaultButton // @@ -425,7 +425,7 @@ void InitializeComponent() mColorDefaultButton.Size = new Size(56, 23); mColorDefaultButton.TabIndex = 3; mColorDefaultButton.Text = "Default"; - mColorDefaultButton.Click += mColorDefaultButton_Click; + mColorDefaultButton.Click += MColorDefaultButton_Click; // // mDeviceFilesGroup // @@ -473,7 +473,7 @@ void InitializeComponent() mDeviceDirectorySetButton.Size = new Size(40, 23); mDeviceDirectorySetButton.TabIndex = 2; mDeviceDirectorySetButton.Text = "S&et..."; - mDeviceDirectorySetButton.Click += mDeviceDirectorySetButton_Click; + mDeviceDirectorySetButton.Click += MDeviceDirectorySetButton_Click; // // mDeviceDirectoryDefaultButton // @@ -483,7 +483,7 @@ void InitializeComponent() mDeviceDirectoryDefaultButton.Size = new Size(56, 23); mDeviceDirectoryDefaultButton.TabIndex = 3; mDeviceDirectoryDefaultButton.Text = "Default"; - mDeviceDirectoryDefaultButton.Click += mDeviceDirectoryDefaultButton_Click; + mDeviceDirectoryDefaultButton.Click += MDeviceDirectoryDefaultButton_Click; // // mDeviceFileSelectionBox // @@ -493,7 +493,7 @@ void InitializeComponent() mDeviceFileSelectionBox.Size = new Size(88, 21); mDeviceFileSelectionBox.Sorted = true; mDeviceFileSelectionBox.TabIndex = 4; - mDeviceFileSelectionBox.SelectionChangeCommitted += mDeviceFileSelectionBox_SelectionChangeCommitted; + mDeviceFileSelectionBox.SelectionChangeCommitted += MDeviceFileSelectionBox_SelectionChangeCommitted; // // mDeviceFileBox // @@ -513,7 +513,7 @@ void InitializeComponent() mDeviceFileSetButton.Size = new Size(40, 23); mDeviceFileSetButton.TabIndex = 6; mDeviceFileSetButton.Text = "Se&t..."; - mDeviceFileSetButton.Click += mDeviceFileSetButton_Click; + mDeviceFileSetButton.Click += MDeviceFileSetButton_Click; // // mDeviceFileDefaultButton // @@ -523,7 +523,7 @@ void InitializeComponent() mDeviceFileDefaultButton.Size = new Size(56, 23); mDeviceFileDefaultButton.TabIndex = 7; mDeviceFileDefaultButton.Text = "Default"; - mDeviceFileDefaultButton.Click += mDeviceFileDefaultButton_Click; + mDeviceFileDefaultButton.Click += MDeviceFileDefaultButton_Click; // // mOkButton // @@ -534,7 +534,7 @@ void InitializeComponent() mOkButton.Size = new Size(75, 23); mOkButton.TabIndex = 8; mOkButton.Text = "&OK"; - mOkButton.Click += mOkButton_Click; + mOkButton.Click += MOkButton_Click; // // mCancelButton // @@ -569,7 +569,7 @@ void InitializeComponent() mTickCountDefaultButton.Size = new Size(56, 23); mTickCountDefaultButton.TabIndex = 3; mTickCountDefaultButton.Text = "Default"; - mTickCountDefaultButton.Click += mTickCountDefaultButton_Click; + mTickCountDefaultButton.Click += MTickCountDefaultButton_Click; // // mTickCountSetButton // @@ -579,7 +579,7 @@ void InitializeComponent() mTickCountSetButton.Size = new Size(48, 23); mTickCountSetButton.TabIndex = 2; mTickCountSetButton.Text = "&Apply"; - mTickCountSetButton.Click += mTickCountSetButton_Click; + mTickCountSetButton.Click += MTickCountSetButton_Click; // // mTickCountSelectionBox // @@ -591,7 +591,7 @@ void InitializeComponent() mTickCountSelectionBox.Size = new Size(182, 21); mTickCountSelectionBox.Sorted = true; mTickCountSelectionBox.TabIndex = 0; - mTickCountSelectionBox.SelectionChangeCommitted += mTickCountSelectionBox_SelectionChangeCommitted; + mTickCountSelectionBox.SelectionChangeCommitted += MTickCountSelectionBox_SelectionChangeCommitted; // // mDefaultsButton // @@ -601,7 +601,7 @@ void InitializeComponent() mDefaultsButton.Size = new Size(75, 23); mDefaultsButton.TabIndex = 7; mDefaultsButton.Text = "&Defaults"; - mDefaultsButton.Click += mDefaultsButton_Click; + mDefaultsButton.Click += MDefaultsButton_Click; // // mMiscGroupBox // @@ -625,7 +625,7 @@ void InitializeComponent() mDeviceReloadIntervalComboBox.Name = "mDeviceReloadIntervalComboBox"; mDeviceReloadIntervalComboBox.Size = new Size(73, 21); mDeviceReloadIntervalComboBox.TabIndex = 5; - mDeviceReloadIntervalComboBox.SelectedIndexChanged += mDeviceReloadIntervalComboBox_SelectedIndexChanged; + mDeviceReloadIntervalComboBox.SelectedIndexChanged += MDeviceReloadIntervalComboBox_SelectedIndexChanged; // // mDeviceReloadIntervalLabel // @@ -644,7 +644,7 @@ void InitializeComponent() mDeviceReloadIntervalDefaultButton.Size = new Size(56, 23); mDeviceReloadIntervalDefaultButton.TabIndex = 3; mDeviceReloadIntervalDefaultButton.Text = "Default"; - mDeviceReloadIntervalDefaultButton.Click += mDeviceReloadIntervalDefaultButton_Click; + mDeviceReloadIntervalDefaultButton.Click += MDeviceReloadIntervalDefaultButton_Click; // // mLoaderCardsGroupBox // @@ -667,7 +667,7 @@ void InitializeComponent() mLoaderCardsDefaultButton.Size = new Size(56, 23); mLoaderCardsDefaultButton.TabIndex = 4; mLoaderCardsDefaultButton.Text = "Default"; - mLoaderCardsDefaultButton.Click += mLoaderCardsDefaultButton_Click; + mLoaderCardsDefaultButton.Click += MLoaderCardsDefaultButton_Click; // // mLoaderCardsPanel // @@ -713,7 +713,7 @@ void InitializeComponent() mFloatingPointMemoryWordCountDefaultButton.Size = new Size(56, 23); mFloatingPointMemoryWordCountDefaultButton.TabIndex = 2; mFloatingPointMemoryWordCountDefaultButton.Text = "Default"; - mFloatingPointMemoryWordCountDefaultButton.Click += mFloatingPointMemoryWordCountDefaultButton_Click; + mFloatingPointMemoryWordCountDefaultButton.Click += MFloatingPointMemoryWordCountDefaultButton_Click; // // mFloatingPointMemoryWordCountBox // @@ -733,7 +733,7 @@ void InitializeComponent() mFloatingPointMemoryWordCountBox.SupportNegativeZero = false; mFloatingPointMemoryWordCountBox.TabIndex = 1; mFloatingPointMemoryWordCountBox.Text = "200"; - mFloatingPointMemoryWordCountBox.ValueChanged += mFloatingPointMemoryWordCountBox_ValueChanged; + mFloatingPointMemoryWordCountBox.ValueChanged += MFloatingPointMemoryWordCountBox_ValueChanged; // // mLoaderCard3TextBox // @@ -835,7 +835,7 @@ void InitializeComponent() mTickCountBox.SupportNegativeZero = false; mTickCountBox.TabIndex = 1; mTickCountBox.Text = "1"; - mTickCountBox.ValueChanged += mTickCountBox_ValueChanged; + mTickCountBox.ValueChanged += MTickCountBox_ValueChanged; // // mColorProfilingCountsCheckBox // @@ -872,8 +872,8 @@ void InitializeComponent() SizeGripStyle = SizeGripStyle.Hide; StartPosition = FormStartPosition.CenterParent; Text = "Preferences"; - VisibleChanged += this_VisibleChanged; - KeyPress += this_KeyPress; + VisibleChanged += This_VisibleChanged; + KeyPress += This_KeyPress; mColorsGroup.ResumeLayout(false); mColorsGroup.PerformLayout(); mDeviceFilesGroup.ResumeLayout(false); @@ -891,125 +891,131 @@ void InitializeComponent() } - void mColorDefaultButton_Click(object sender, EventArgs e) + void MColorDefaultButton_Click(object sender, EventArgs e) { - var selectedItem = (colorComboBoxItem)mColorSelectionBox.SelectedItem; + var selectedItem = (ColorComboBoxItem)mColorSelectionBox.SelectedItem; selectedItem.ResetDefault(); - updateColorControls(selectedItem); + UpdateColorControls(selectedItem); mColorSelectionBox.Focus(); } - void mColorSetButton_Click(object sender, EventArgs e) + void MColorSetButton_Click(object sender, EventArgs e) { if (mColorDialog == null) { - mColorDialog = new ColorDialog(); - mColorDialog.AnyColor = true; - mColorDialog.SolidColorOnly = true; - mColorDialog.AllowFullOpen = true; + mColorDialog = new ColorDialog + { + AnyColor = true, + SolidColorOnly = true, + AllowFullOpen = true + }; } - var selectedItem = (colorComboBoxItem)mColorSelectionBox.SelectedItem; + var selectedItem = (ColorComboBoxItem)mColorSelectionBox.SelectedItem; mColorDialog.CustomColors = new int[] { selectedItem.Color.B << 16 | selectedItem.Color.G << 8 | selectedItem.Color.R }; mColorDialog.Color = selectedItem.Color; if (mColorDialog.ShowDialog(this) == DialogResult.OK) { selectedItem.Color = mColorDialog.Color; - updateColorControls(selectedItem); + UpdateColorControls(selectedItem); } } - void mDefaultsButton_Click(object sender, EventArgs e) + void MDefaultsButton_Click(object sender, EventArgs e) { - foreach (colorComboBoxItem colorItem in mColorSelectionBox.Items) colorItem.ResetDefault(); + foreach (ColorComboBoxItem colorItem in mColorSelectionBox.Items) colorItem.ResetDefault(); mColorProfilingCountsCheckBox.Checked = true; - foreach (deviceFileComboBoxItem deviceFileItem in mDeviceFileSelectionBox.Items) deviceFileItem.ResetDefault(); + foreach (DeviceFileComboBoxItem deviceFileItem in mDeviceFileSelectionBox.Items) deviceFileItem.ResetDefault(); - foreach (tickCountComboBoxItem tickCountItem in mTickCountSelectionBox.Items) tickCountItem.ResetDefault(); + foreach (TickCountComboBoxItem tickCountItem in mTickCountSelectionBox.Items) tickCountItem.ResetDefault(); mDeviceFilesDirectory = null; mDeviceReloadInterval = DeviceSettings.UnsetDeviceReloadInterval; - updateColorControls((colorComboBoxItem)mColorSelectionBox.SelectedItem); - updateDeviceDirectoryControls(); - updateDeviceFileControls((deviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); - updateTickCountControls((tickCountComboBoxItem)mTickCountSelectionBox.SelectedItem); - updateDeviceReloadIntervalControls(); + UpdateColorControls((ColorComboBoxItem)mColorSelectionBox.SelectedItem); + UpdateDeviceDirectoryControls(); + UpdateDeviceFileControls((DeviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); + UpdateTickCountControls((TickCountComboBoxItem)mTickCountSelectionBox.SelectedItem); + UpdateDeviceReloadIntervalControls(); mFloatingPointMemoryWordCount = null; - updateFloatingPointControls(); + UpdateFloatingPointControls(); - loadDefaultLoaderCards(); + LoadDefaultLoaderCards(); } - void updateFloatingPointControls() + void UpdateFloatingPointControls() { mFloatingPointMemoryWordCountBox.LongValue = mFloatingPointMemoryWordCount ?? ModuleSettings.FloatingPointMemoryWordCountDefault; mFloatingPointMemoryWordCountDefaultButton.Enabled = mFloatingPointMemoryWordCount != null; } - void mDeviceDirectoryDefaultButton_Click(object sender, EventArgs e) + void MDeviceDirectoryDefaultButton_Click(object sender, EventArgs e) { mDeviceFilesDirectory = null; - updateDeviceDirectoryControls(); - updateDeviceFileControls((deviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); + UpdateDeviceDirectoryControls(); + UpdateDeviceFileControls((DeviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); mDeviceDirectoryBox.Focus(); } - void mDeviceDirectorySetButton_Click(object sender, EventArgs e) + void MDeviceDirectorySetButton_Click(object sender, EventArgs e) { if (mDeviceFilesFolderBrowserDialog == null) { - mDeviceFilesFolderBrowserDialog = new FolderBrowserDialog(); - mDeviceFilesFolderBrowserDialog.Description = "Please select the default directory for device files."; + mDeviceFilesFolderBrowserDialog = new FolderBrowserDialog + { + Description = "Please select the default directory for device files." + }; } - mDeviceFilesFolderBrowserDialog.SelectedPath = getCurrentDeviceFilesDirectory(); + mDeviceFilesFolderBrowserDialog.SelectedPath = GetCurrentDeviceFilesDirectory(); if (mDeviceFilesFolderBrowserDialog.ShowDialog(this) == DialogResult.OK) { mDeviceFilesDirectory = mDeviceFilesFolderBrowserDialog.SelectedPath; - updateDeviceDirectoryControls(); - updateDeviceFileControls((deviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); + UpdateDeviceDirectoryControls(); + UpdateDeviceFileControls((DeviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem); } } - void mDeviceFileDefaultButton_Click(object sender, EventArgs e) + void MDeviceFileDefaultButton_Click(object sender, EventArgs e) { - var selectedItem = (deviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem; + var selectedItem = (DeviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem; selectedItem.ResetDefault(); - updateDeviceFileControls(selectedItem); + UpdateDeviceFileControls(selectedItem); mDeviceFileSelectionBox.Focus(); } - void mDeviceFileSetButton_Click(object sender, EventArgs e) + void MDeviceFileSetButton_Click(object sender, EventArgs e) { if (mSelectDeviceFileDialog == null) { - mSelectDeviceFileDialog = new SaveFileDialog(); - mSelectDeviceFileDialog.CreatePrompt = true; - mSelectDeviceFileDialog.DefaultExt = "mixdev"; - mSelectDeviceFileDialog.Filter = "MIX device files|*.mixdev|All files|*.*"; - mSelectDeviceFileDialog.OverwritePrompt = false; + mSelectDeviceFileDialog = new SaveFileDialog + { + CreatePrompt = true, + DefaultExt = "mixdev", + Filter = "MIX device files|*.mixdev|All files|*.*", + OverwritePrompt = false + }; } - var selectedItem = (deviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem; - mSelectDeviceFileDialog.FileName = Path.Combine(getCurrentDeviceFilesDirectory(), selectedItem.FilePath); + var selectedItem = (DeviceFileComboBoxItem)mDeviceFileSelectionBox.SelectedItem; + mSelectDeviceFileDialog.FileName = Path.Combine(GetCurrentDeviceFilesDirectory(), selectedItem.FilePath); if (mSelectDeviceFileDialog.ShowDialog(this) == DialogResult.OK) { selectedItem.FilePath = mSelectDeviceFileDialog.FileName; - updateDeviceFileControls(selectedItem); + UpdateDeviceFileControls(selectedItem); } } - void mOkButton_Click(object sender, EventArgs e) + void MOkButton_Click(object sender, EventArgs e) { mConfiguration.Colors.Clear(); - foreach (colorComboBoxItem colorItem in mColorSelectionBox.Items) + foreach (ColorComboBoxItem colorItem in mColorSelectionBox.Items) { if (!colorItem.IsDefault) mConfiguration.Colors.Add(colorItem.Name, colorItem.Color); } @@ -1017,7 +1023,7 @@ void mOkButton_Click(object sender, EventArgs e) mConfiguration.ColorProfilingCounts = mColorProfilingCountsCheckBox.Checked; mConfiguration.DeviceFilePaths.Clear(); - foreach (deviceFileComboBoxItem deviceFileItem in mDeviceFileSelectionBox.Items) + foreach (DeviceFileComboBoxItem deviceFileItem in mDeviceFileSelectionBox.Items) { if (!deviceFileItem.IsDefault) { @@ -1026,7 +1032,7 @@ void mOkButton_Click(object sender, EventArgs e) } mConfiguration.TickCounts.Clear(); - foreach (tickCountComboBoxItem tickCountItem in mTickCountSelectionBox.Items) + foreach (TickCountComboBoxItem tickCountItem in mTickCountSelectionBox.Items) { if (!tickCountItem.IsDefault) { @@ -1053,51 +1059,51 @@ void mOkButton_Click(object sender, EventArgs e) } - void mTickCountBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) => setTickCountValue(); + void MTickCountBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) => SetTickCountValue(); - void mTickCountDefaultButton_Click(object sender, EventArgs e) + void MTickCountDefaultButton_Click(object sender, EventArgs e) { - var selectedItem = (tickCountComboBoxItem)mTickCountSelectionBox.SelectedItem; + var selectedItem = (TickCountComboBoxItem)mTickCountSelectionBox.SelectedItem; selectedItem.ResetDefault(); - updateTickCountControls(selectedItem); + UpdateTickCountControls(selectedItem); mTickCountSelectionBox.Focus(); } - void setTickCountValue() + void SetTickCountValue() { - var selectedItem = (tickCountComboBoxItem)mTickCountSelectionBox.SelectedItem; + var selectedItem = (TickCountComboBoxItem)mTickCountSelectionBox.SelectedItem; selectedItem.TickCount = (int)mTickCountBox.LongValue; - updateTickCountControls(selectedItem); + UpdateTickCountControls(selectedItem); } - void this_KeyPress(object sender, KeyPressEventArgs e) + void This_KeyPress(object sender, KeyPressEventArgs e) { - if (e.KeyChar == (char)Keys.Escape && !(getFocusedControl() is IEscapeConsumer)) + if (e.KeyChar == (char)Keys.Escape && !(GetFocusedControl() is IEscapeConsumer)) { DialogResult = DialogResult.Cancel; Hide(); } } - void this_VisibleChanged(object sender, EventArgs e) + void This_VisibleChanged(object sender, EventArgs e) { if (Visible) { - fillColorSelectionBox(); + FillColorSelectionBox(); mColorProfilingCountsCheckBox.Checked = mConfiguration.ColorProfilingCounts; mDeviceFilesDirectory = mConfiguration.DeviceFilesDirectory; - updateDeviceDirectoryControls(); - fillDeviceFileSelectionBox(); - fillTickCountSelectionBox(); + UpdateDeviceDirectoryControls(); + FillDeviceFileSelectionBox(); + FillTickCountSelectionBox(); mDeviceReloadInterval = mConfiguration.DeviceReloadInterval; - updateDeviceReloadIntervalControls(); + UpdateDeviceReloadIntervalControls(); mFloatingPointMemoryWordCount = mConfiguration.FloatingPointMemoryWordCount; - updateFloatingPointControls(); - loadLoaderCards(); + UpdateFloatingPointControls(); + LoadLoaderCards(); } } - void loadLoaderCards() + void LoadLoaderCards() { string[] loaderCards = mConfiguration.LoaderCards ?? CardDeckExporter.DefaultLoaderCards; @@ -1112,7 +1118,7 @@ void loadLoaderCards() mLoaderCardsDefaultButton.Enabled = mConfiguration.LoaderCards != null; } - void updateColorControls(colorComboBoxItem item) + void UpdateColorControls(ColorComboBoxItem item) { if (item == null) { @@ -1126,13 +1132,13 @@ void updateColorControls(colorComboBoxItem item) { if (item.IsBackground) { - mShowColorLabel.ForeColor = getMatchingColor(item.Name, false); + mShowColorLabel.ForeColor = GetMatchingColor(item.Name, false); mShowColorLabel.BackColor = item.Color; } else { mShowColorLabel.ForeColor = item.Color; - mShowColorLabel.BackColor = getMatchingColor(item.Name, true); + mShowColorLabel.BackColor = GetMatchingColor(item.Name, true); } mColorSetButton.Enabled = true; @@ -1140,23 +1146,23 @@ void updateColorControls(colorComboBoxItem item) } } - void updateDeviceReloadIntervalControls() + void UpdateDeviceReloadIntervalControls() { if (mDeviceReloadInterval == DeviceSettings.UnsetDeviceReloadInterval) { - selectDeviceReloadInterval(DeviceSettings.DefaultDeviceReloadInterval); + SelectDeviceReloadInterval(DeviceSettings.DefaultDeviceReloadInterval); mDeviceReloadIntervalDefaultButton.Enabled = false; } else { - selectDeviceReloadInterval(mDeviceReloadInterval); + SelectDeviceReloadInterval(mDeviceReloadInterval); mDeviceReloadIntervalDefaultButton.Enabled = true; } } - void selectDeviceReloadInterval(int interval) + void SelectDeviceReloadInterval(int interval) { - foreach (deviceReloadIntervalComboBoxItem item in mDeviceReloadIntervalComboBox.Items) + foreach (DeviceReloadIntervalComboBoxItem item in mDeviceReloadIntervalComboBox.Items) { if (item.MilliSeconds >= interval) { @@ -1166,7 +1172,7 @@ void selectDeviceReloadInterval(int interval) } } - void updateDeviceDirectoryControls() + void UpdateDeviceDirectoryControls() { if (mDeviceFilesDirectory == null) { @@ -1180,7 +1186,7 @@ void updateDeviceDirectoryControls() } } - void updateDeviceFileControls(deviceFileComboBoxItem item) + void UpdateDeviceFileControls(DeviceFileComboBoxItem item) { if (item == null) { @@ -1190,13 +1196,13 @@ void updateDeviceFileControls(deviceFileComboBoxItem item) } else { - mDeviceFileBox.Text = Path.Combine(getCurrentDeviceFilesDirectory(), item.FilePath); + mDeviceFileBox.Text = Path.Combine(GetCurrentDeviceFilesDirectory(), item.FilePath); mDeviceFileSetButton.Enabled = true; mDeviceFileDefaultButton.Enabled = !item.IsDefault; } } - void updateTickCountControls(tickCountComboBoxItem item) + void UpdateTickCountControls(TickCountComboBoxItem item) { if (item == null) { @@ -1212,19 +1218,19 @@ void updateTickCountControls(tickCountComboBoxItem item) } } - void mDeviceReloadIntervalDefaultButton_Click(object sender, EventArgs e) + void MDeviceReloadIntervalDefaultButton_Click(object sender, EventArgs e) { mDeviceReloadInterval = DeviceSettings.UnsetDeviceReloadInterval; - updateDeviceReloadIntervalControls(); + UpdateDeviceReloadIntervalControls(); } - void mDeviceReloadIntervalComboBox_SelectedIndexChanged(object sender, EventArgs e) + void MDeviceReloadIntervalComboBox_SelectedIndexChanged(object sender, EventArgs e) { - mDeviceReloadInterval = ((deviceReloadIntervalComboBoxItem)mDeviceReloadIntervalComboBox.SelectedItem).MilliSeconds; + mDeviceReloadInterval = ((DeviceReloadIntervalComboBoxItem)mDeviceReloadIntervalComboBox.SelectedItem).MilliSeconds; mDeviceReloadIntervalDefaultButton.Enabled = true; } - void loadDefaultLoaderCards() + void LoadDefaultLoaderCards() { string[] defaultLoaderCards = CardDeckExporter.DefaultLoaderCards; @@ -1237,32 +1243,32 @@ void loadDefaultLoaderCards() mLoaderCardsDefaultButton.Enabled = false; } - void mFloatingPointMemoryWordCountDefaultButton_Click(object sender, EventArgs e) + void MFloatingPointMemoryWordCountDefaultButton_Click(object sender, EventArgs e) { mFloatingPointMemoryWordCount = null; - updateFloatingPointControls(); + UpdateFloatingPointControls(); } - void mFloatingPointMemoryWordCountBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) + void MFloatingPointMemoryWordCountBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) { mFloatingPointMemoryWordCount = (int)mFloatingPointMemoryWordCountBox.LongValue; - updateFloatingPointControls(); + UpdateFloatingPointControls(); } /// /// Instances of this class are used to store the color settings /// - class colorComboBoxItem + class ColorComboBoxItem { string mDisplayName; public bool IsDefault { get; private set; } public string Name { get; private set; } Color mSetColor; - public colorComboBoxItem(string name) + public ColorComboBoxItem(string name) { Name = name; - mDisplayName = getDisplayName(name); + mDisplayName = GetDisplayName(name); IsDefault = true; } @@ -1270,7 +1276,7 @@ public colorComboBoxItem(string name) public override string ToString() => mDisplayName; - static string getDisplayName(string name) + static string GetDisplayName(string name) { var builder = new StringBuilder(name[0].ToString()); @@ -1312,12 +1318,12 @@ public Color Color /// /// Instances of this class are used to store the device file settings /// - class deviceFileComboBoxItem + class DeviceFileComboBoxItem { readonly FileBasedDevice mDevice; string mFilePath; - public deviceFileComboBoxItem(FileBasedDevice device) + public DeviceFileComboBoxItem(FileBasedDevice device) { mDevice = device; } @@ -1349,17 +1355,17 @@ public string FilePath /// /// Instances of this class are used to store the tick count settings /// - class tickCountComboBoxItem + class TickCountComboBoxItem { string mDisplayName; bool mIsDefault; readonly string mName; int mSetTickCount; - public tickCountComboBoxItem(string name) + public TickCountComboBoxItem(string name) { mName = name; - mDisplayName = getDisplayName(name); + mDisplayName = GetDisplayName(name); mIsDefault = true; } @@ -1369,7 +1375,7 @@ public tickCountComboBoxItem(string name) public override string ToString() => mDisplayName; - static string getDisplayName(string name) + static string GetDisplayName(string name) { var builder = new StringBuilder(name[0].ToString()); @@ -1408,11 +1414,11 @@ public int TickCount } } - class deviceReloadIntervalComboBoxItem + class DeviceReloadIntervalComboBoxItem { public int MilliSeconds { get; set; } - public deviceReloadIntervalComboBoxItem(int milliSeconds) + public DeviceReloadIntervalComboBoxItem(int milliSeconds) { MilliSeconds = milliSeconds; } diff --git a/MixEmul/Components/RegistersEditor.cs b/MixEmul/Components/RegistersEditor.cs index 83c222e..9c68826 100644 --- a/MixEmul/Components/RegistersEditor.cs +++ b/MixEmul/Components/RegistersEditor.cs @@ -60,18 +60,20 @@ public RegistersEditor(MixLib.Registers registers) mCompareLabel = new Label(); mOverflowLabel = new Label(); - mEditors = new List(); - mEditors.Add(mrAEditor = new WordValueEditor(mRegisters.rA)); - mEditors.Add(mrXEditor = new WordValueEditor(mRegisters.rX)); - mEditors.Add(mrI1Editor = new WordValueEditor(mRegisters.rI1)); - mEditors.Add(mrI2Editor = new WordValueEditor(mRegisters.rI2)); - mEditors.Add(mrI3Editor = new WordValueEditor(mRegisters.rI3)); - mEditors.Add(mrI4Editor = new WordValueEditor(mRegisters.rI4)); - mEditors.Add(mr5Editor = new WordValueEditor(mRegisters.rI5)); - mEditors.Add(mrI6Editor = new WordValueEditor(mRegisters.rI6)); - mEditors.Add(mrJEditor = new WordValueEditor(mRegisters.rJ, false)); - - mCompareButton = new Button(); + mEditors = new List + { + (mrAEditor = new WordValueEditor(mRegisters.RA)), + (mrXEditor = new WordValueEditor(mRegisters.RX)), + (mrI1Editor = new WordValueEditor(mRegisters.RI1)), + (mrI2Editor = new WordValueEditor(mRegisters.RI2)), + (mrI3Editor = new WordValueEditor(mRegisters.RI3)), + (mrI4Editor = new WordValueEditor(mRegisters.RI4)), + (mr5Editor = new WordValueEditor(mRegisters.RI5)), + (mrI6Editor = new WordValueEditor(mRegisters.RI6)), + (mrJEditor = new WordValueEditor(mRegisters.RJ, false)) + }; + + mCompareButton = new Button(); mOverflowBox = new CheckBox(); SuspendLayout(); @@ -143,56 +145,56 @@ public RegistersEditor(MixLib.Registers registers) mrAEditor.Name = "mrAEditor"; mrAEditor.TabIndex = 1; mrAEditor.TextBoxWidth = 80; - mrAEditor.NavigationKeyDown += keyDown; + mrAEditor.NavigationKeyDown += This_KeyDown; mrXEditor.Location = new Point(24, 24); mrXEditor.Name = "mrXEditor"; mrXEditor.TabIndex = 3; mrXEditor.TextBoxWidth = 80; - mrXEditor.NavigationKeyDown += keyDown; + mrXEditor.NavigationKeyDown += This_KeyDown; mrI1Editor.Location = new Point(24, 48); mrI1Editor.Name = "mr1Editor"; mrI1Editor.TabIndex = 5; mrI1Editor.TextBoxWidth = 40; - mrI1Editor.NavigationKeyDown += keyDown; + mrI1Editor.NavigationKeyDown += This_KeyDown; mrI2Editor.Location = new Point(24, 72); mrI2Editor.Name = "mr2Editor"; mrI2Editor.TabIndex = 7; mrI2Editor.TextBoxWidth = 40; - mrI2Editor.NavigationKeyDown += keyDown; + mrI2Editor.NavigationKeyDown += This_KeyDown; mrI3Editor.Location = new Point(24, 96); mrI3Editor.Name = "mr3Editor"; mrI3Editor.TabIndex = 9; mrI3Editor.TextBoxWidth = 40; - mrI3Editor.NavigationKeyDown += keyDown; + mrI3Editor.NavigationKeyDown += This_KeyDown; mrI4Editor.Location = new Point(24, 120); mrI4Editor.Name = "mr4Editor"; mrI4Editor.TabIndex = 11; mrI4Editor.TextBoxWidth = 40; - mrI4Editor.NavigationKeyDown += keyDown; + mrI4Editor.NavigationKeyDown += This_KeyDown; mr5Editor.Location = new Point(24, 144); mr5Editor.Name = "mr5Editor"; mr5Editor.TabIndex = 13; mr5Editor.TextBoxWidth = 40; - mr5Editor.NavigationKeyDown += keyDown; + mr5Editor.NavigationKeyDown += This_KeyDown; mrI6Editor.Location = new Point(24, 168); mrI6Editor.Name = "mr6Editor"; mrI6Editor.TabIndex = 15; mrI6Editor.TextBoxWidth = 40; - mrI6Editor.NavigationKeyDown += keyDown; + mrI6Editor.NavigationKeyDown += This_KeyDown; mrJEditor.Location = new Point(41, 192); mrJEditor.Name = "mrJEditor"; mrJEditor.ReadOnly = false; mrJEditor.TabIndex = 17; mrJEditor.TextBoxWidth = 40; - mrJEditor.NavigationKeyDown += keyDown; + mrJEditor.NavigationKeyDown += This_KeyDown; mOverflowLabel.Name = "mOverflowLabel"; mOverflowLabel.Size = new Size(56, 21); @@ -204,7 +206,7 @@ public RegistersEditor(MixLib.Registers registers) mOverflowBox.Size = new Size(16, 21); mOverflowBox.Location = new Point((mrAEditor.Left + mrAEditor.Width) - mOverflowBox.Width, mrI6Editor.Top); mOverflowBox.TabIndex = 19; - mOverflowBox.CheckedChanged += mOverflowBox_CheckedChanged; + mOverflowBox.CheckedChanged += MOverflowBox_CheckedChanged; mCompareLabel.Name = "mCompareLabel"; mCompareLabel.Size = new Size(56, 21); @@ -218,7 +220,7 @@ public RegistersEditor(MixLib.Registers registers) mCompareButton.Location = new Point((mrAEditor.Left + mrAEditor.Width) - mCompareButton.Width, mrJEditor.Top); mCompareButton.TabIndex = 21; mCompareButton.Text = "" + mRegisters.CompareIndicator.ToChar(); - mCompareButton.Click += mCompareButton_Click; + mCompareButton.Click += MCompareButton_Click; mOverflowLabel.Location = new Point(Math.Min(mCompareButton.Left, mOverflowBox.Left) - Math.Max(mCompareLabel.Width, mOverflowLabel.Width), mOverflowBox.Top); @@ -252,12 +254,12 @@ public RegistersEditor(MixLib.Registers registers) ResumeLayout(false); } - void mOverflowBox_CheckedChanged(object sender, EventArgs e) + void MOverflowBox_CheckedChanged(object sender, EventArgs e) { mRegisters.OverflowIndicator = mOverflowBox.Checked; } - void keyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { FieldTypes? editorField = null; int? index = null; @@ -280,7 +282,7 @@ void keyDown(object sender, KeyEventArgs e) } } - void mCompareButton_Click(object sender, EventArgs e) + void MCompareButton_Click(object sender, EventArgs e) { var compValue = mRegisters.CompareIndicator.Next(); mRegisters.CompareIndicator = compValue; @@ -336,15 +338,15 @@ public MixLib.Registers Registers if (value != null && mRegisters != value) { mRegisters = value; - mrAEditor.WordValue = mRegisters.rA; - mrXEditor.WordValue = mRegisters.rX; - mrI1Editor.WordValue = mRegisters.rI1; - mrI2Editor.WordValue = mRegisters.rI2; - mrI3Editor.WordValue = mRegisters.rI3; - mrI4Editor.WordValue = mRegisters.rI4; - mr5Editor.WordValue = mRegisters.rI5; - mrI6Editor.WordValue = mRegisters.rI6; - mrJEditor.WordValue = mRegisters.rJ; + mrAEditor.WordValue = mRegisters.RA; + mrXEditor.WordValue = mRegisters.RX; + mrI1Editor.WordValue = mRegisters.RI1; + mrI2Editor.WordValue = mRegisters.RI2; + mrI3Editor.WordValue = mRegisters.RI3; + mrI4Editor.WordValue = mRegisters.RI4; + mr5Editor.WordValue = mRegisters.RI5; + mrI6Editor.WordValue = mRegisters.RI6; + mrJEditor.WordValue = mRegisters.RJ; } } } diff --git a/MixEmul/Components/SearchDialog.Designer.cs b/MixEmul/Components/SearchDialog.Designer.cs index b1c6f4e..7689c11 100644 --- a/MixEmul/Components/SearchDialog.Designer.cs +++ b/MixEmul/Components/SearchDialog.Designer.cs @@ -66,7 +66,7 @@ private void InitializeComponent() this.mValueCheckBox.TabIndex = 0; this.mValueCheckBox.Text = "&Numeric value"; this.mValueCheckBox.UseVisualStyleBackColor = true; - this.mValueCheckBox.CheckedChanged += new System.EventHandler(this.fieldCheckedChanged); + this.mValueCheckBox.CheckedChanged += new System.EventHandler(this.FieldCheckedChanged); // // mCharsCheckBox // @@ -79,7 +79,7 @@ private void InitializeComponent() this.mCharsCheckBox.TabIndex = 1; this.mCharsCheckBox.Text = "&Characters"; this.mCharsCheckBox.UseVisualStyleBackColor = true; - this.mCharsCheckBox.CheckedChanged += new System.EventHandler(this.fieldCheckedChanged); + this.mCharsCheckBox.CheckedChanged += new System.EventHandler(this.FieldCheckedChanged); // // mInstructionCheckBox // @@ -92,7 +92,7 @@ private void InitializeComponent() this.mInstructionCheckBox.TabIndex = 2; this.mInstructionCheckBox.Text = "&Instruction"; this.mInstructionCheckBox.UseVisualStyleBackColor = true; - this.mInstructionCheckBox.CheckedChanged += new System.EventHandler(this.fieldCheckedChanged); + this.mInstructionCheckBox.CheckedChanged += new System.EventHandler(this.FieldCheckedChanged); // // mMatchWholeWordCheckBox // @@ -127,7 +127,7 @@ private void InitializeComponent() this.mFindButton.TabIndex = 4; this.mFindButton.Text = "&Find"; this.mFindButton.UseVisualStyleBackColor = true; - this.mFindButton.Click += new System.EventHandler(this.mFindButton_Click); + this.mFindButton.Click += new System.EventHandler(this.MFindButton_Click); // // mCancelButton // @@ -194,7 +194,7 @@ private void InitializeComponent() this.mSearchTextBox.Size = new System.Drawing.Size(103, 21); this.mSearchTextBox.TabIndex = 1; this.mSearchTextBox.UseEditMode = false; - this.mSearchTextBox.ValueChanged += new MixGui.Events.MixByteCollectionEditorValueChangedEventHandler(this.mSearchTextBox_ValueChanged); + this.mSearchTextBox.ValueChanged += new MixGui.Events.MixByteCollectionEditorValueChangedEventHandler(this.MSearchTextBox_ValueChanged); // // SearchDialog // diff --git a/MixEmul/Components/SearchDialog.cs b/MixEmul/Components/SearchDialog.cs index 9d6fc70..e23f3d6 100644 --- a/MixEmul/Components/SearchDialog.cs +++ b/MixEmul/Components/SearchDialog.cs @@ -15,10 +15,10 @@ public SearchDialog() mSearchTextBox.MixByteCollectionValue = new MixByteCollection(80); } - void fieldCheckedChanged(object sender, EventArgs e) => setFindButtonEnabledState(); + void FieldCheckedChanged(object sender, EventArgs e) => SetFindButtonEnabledState(); - void mSearchTextBox_ValueChanged(IMixByteCollectionEditor sender, MixByteCollectionEditorValueChangedEventArgs args) => - setFindButtonEnabledState(); + void MSearchTextBox_ValueChanged(IMixByteCollectionEditor sender, MixByteCollectionEditorValueChangedEventArgs args) => + SetFindButtonEnabledState(); public SearchParameters SearchParameters { @@ -33,17 +33,17 @@ public SearchParameters SearchParameters { mSearchParameters = value; - fillControls(); + FillControls(); } } } - void setFindButtonEnabledState() + void SetFindButtonEnabledState() { mFindButton.Enabled = mSearchTextBox.MixByteCollectionValue.ToString(true).Trim() != string.Empty && (mValueCheckBox.Checked || mCharsCheckBox.Checked || mInstructionCheckBox.Checked); } - void mFindButton_Click(object sender, EventArgs e) + void MFindButton_Click(object sender, EventArgs e) { if (mSearchParameters == null) { @@ -70,10 +70,10 @@ void mFindButton_Click(object sender, EventArgs e) void SearchDialog_VisibleChanged(object sender, EventArgs e) { - if (Visible) fillControls(); + if (Visible) FillControls(); } - void fillControls() + void FillControls() { if (mSearchParameters != null) { diff --git a/MixEmul/Components/SourceAndFindingsForm.cs b/MixEmul/Components/SourceAndFindingsForm.cs index 1c7944f..03e5dd2 100644 --- a/MixEmul/Components/SourceAndFindingsForm.cs +++ b/MixEmul/Components/SourceAndFindingsForm.cs @@ -26,7 +26,7 @@ public class SourceAndFindingsForm : Form public SourceAndFindingsForm() { InitializeComponent(); - mFindingListView.SelectionChanged += mFindingListView_SelectionChanged; + mFindingListView.SelectionChanged += MFindingListView_SelectionChanged; } public void UpdateLayout() => mSourceControl.UpdateLayout(); @@ -94,7 +94,7 @@ void InitializeComponent() mExportButton.Size = new System.Drawing.Size(62, 23); mExportButton.TabIndex = 2; mExportButton.Text = "&Export..."; - mExportButton.Click += mExportButton_Click; + mExportButton.Click += MExportButton_Click; // // mLoadButton // @@ -164,7 +164,7 @@ void InitializeComponent() } - void mFindingListView_SelectionChanged(AssemblyFindingListView sender, AssemblyFindingListView.SelectionChangedEventArgs args) + void MFindingListView_SelectionChanged(AssemblyFindingListView sender, AssemblyFindingListView.SelectionChangedEventArgs args) { mSourceControl.MarkedFinding = args.SelectedFinding; } @@ -174,13 +174,13 @@ public void SetInstructionsAndFindings(PreInstruction[] instructions, Instructio mSourceControl.Instructions = instructions; mSourceControl.Findings = findings; mFindingListView.Findings = findings; - setStatusBarText(findings); + SetStatusBarText(findings); mInstances = instances; mLoadButton.Enabled = !findings.ContainsErrors; mExportButton.Enabled = mLoadButton.Enabled; } - void setStatusBarText(AssemblyFindingCollection findings) + void SetStatusBarText(AssemblyFindingCollection findings) { var severityNames = Enum.GetNames(typeof(Severity)); int[] severityCounts = new int[severityNames.Length]; @@ -236,7 +236,7 @@ public ImageList SeverityImageList } } - void mExportButton_Click(object sender, EventArgs e) + void MExportButton_Click(object sender, EventArgs e) { if (mSaveExportFileDialog.ShowDialog(this) == DialogResult.OK) { diff --git a/MixEmul/Components/SourceCodeControl.cs b/MixEmul/Components/SourceCodeControl.cs index 8495ee9..946777a 100644 --- a/MixEmul/Components/SourceCodeControl.cs +++ b/MixEmul/Components/SourceCodeControl.cs @@ -24,7 +24,7 @@ public class SourceCodeControl : UserControl Color mAddressColor; Color mCommentColor; bool mFindingsColored; - List mInstructions; + List mInstructions; Color mLineNumberColor; int mLineNumberLength; Color mLineNumberSeparatorColor; @@ -52,12 +52,12 @@ public SourceCodeControl() UpdateLayout(); - mInstructions = new List(); + mInstructions = new List(); mLineNumberLength = 0; mFindingsColored = false; } - void addLine(ParsedSourceLine sourceLine) + void AddLine(ParsedSourceLine sourceLine) { int count = mInstructions.Count; if (mSourceBox.TextLength != 0) mSourceBox.AppendText(Environment.NewLine); @@ -65,7 +65,7 @@ void addLine(ParsedSourceLine sourceLine) var lineNumberText = (count + 1).ToString(); mSourceBox.AppendText(new string(' ', mLineNumberLength - lineNumberText.Length) + lineNumberText + lineNumberSeparator); - var processedLine = new processedSourceLine(sourceLine, mSourceBox.TextLength); + var processedLine = new ProcessedSourceLine(sourceLine, mSourceBox.TextLength); mInstructions.Add(processedLine); if (sourceLine.IsCommentLine) @@ -80,14 +80,14 @@ void addLine(ParsedSourceLine sourceLine) if (sourceLine.Comment.Length > 0) mSourceBox.AppendText(sourceLine.Comment); } - applySyntaxColoring(processedLine); + ApplySyntaxColoring(processedLine); } - void applyFindingColoring(AssemblyFinding finding, markOperation mark) + void ApplyFindingColoring(AssemblyFinding finding, MarkOperation mark) { if (finding != null && finding.LineNumber != int.MinValue && finding.LineNumber >= 0 && finding.LineNumber < mInstructions.Count) { - processedSourceLine processedLine = mInstructions[finding.LineNumber]; + ProcessedSourceLine processedLine = mInstructions[finding.LineNumber]; int lineTextIndex = processedLine.LineTextIndex; int length = 0; @@ -159,7 +159,7 @@ void applyFindingColoring(AssemblyFinding finding, markOperation mark) if (length != 0) { - if (mark == markOperation.Mark) + if (mark == MarkOperation.Mark) { Font font = mSourceBox.Font; @@ -167,7 +167,7 @@ void applyFindingColoring(AssemblyFinding finding, markOperation mark) mSourceBox.Focus(); mSourceBox.ScrollToCaret(); } - else if (mark == markOperation.Unmark) + else if (mark == MarkOperation.Unmark) { mSourceBox.SelectionFont = mSourceBox.Font; } @@ -178,15 +178,15 @@ void applyFindingColoring(AssemblyFinding finding, markOperation mark) } } - void applyFindingColoring(AssemblyFindingCollection findings, Severity severity) + void ApplyFindingColoring(AssemblyFindingCollection findings, Severity severity) { foreach (AssemblyFinding finding in findings) { - if (finding.Severity == severity) applyFindingColoring(finding, markOperation.None); + if (finding.Severity == severity) ApplyFindingColoring(finding, MarkOperation.None); } } - void applySyntaxColoring(processedSourceLine processedLine) + void ApplySyntaxColoring(ProcessedSourceLine processedLine) { mSourceBox.SelectionStart = (processedLine.LineTextIndex - lineNumberSeparator.Length) - mLineNumberLength; mSourceBox.SelectionLength = mLineNumberLength; @@ -243,18 +243,18 @@ public AssemblyFindingCollection Findings { set { - applyFindingColoring(mMarkedFinding, markOperation.Unmark); + ApplyFindingColoring(mMarkedFinding, MarkOperation.Unmark); mMarkedFinding = null; if (mFindingsColored) { - foreach (processedSourceLine line in mInstructions) applySyntaxColoring(line); + foreach (ProcessedSourceLine line in mInstructions) ApplySyntaxColoring(line); } - if (value.ContainsDebugs) applyFindingColoring(value, Severity.Debug); - if (value.ContainsInfos) applyFindingColoring(value, Severity.Info); - if (value.ContainsWarnings) applyFindingColoring(value, Severity.Warning); - if (value.ContainsErrors) applyFindingColoring(value, Severity.Error); + if (value.ContainsDebugs) ApplyFindingColoring(value, Severity.Debug); + if (value.ContainsInfos) ApplyFindingColoring(value, Severity.Info); + if (value.ContainsWarnings) ApplyFindingColoring(value, Severity.Warning); + if (value.ContainsErrors) ApplyFindingColoring(value, Severity.Error); mFindingsColored = true; } @@ -282,9 +282,8 @@ public PreInstruction[] Instructions foreach (PreInstruction instruction in value) { - if (instruction is ParsedSourceLine) + if (instruction is ParsedSourceLine parsedLine) { - var parsedLine = (ParsedSourceLine)instruction; parsedLines.Add(parsedLine.LineNumber, parsedLine); } } @@ -293,10 +292,10 @@ public PreInstruction[] Instructions { while (parsedLine.LineNumber > mInstructions.Count) { - addLine(new ParsedSourceLine(mInstructions.Count, "")); + AddLine(new ParsedSourceLine(mInstructions.Count, "")); } - addLine(parsedLine); + AddLine(parsedLine); } mSourceBox.SelectionStart = 0; @@ -313,27 +312,27 @@ public AssemblyFinding MarkedFinding } set { - applyFindingColoring(mMarkedFinding, markOperation.Unmark); + ApplyFindingColoring(mMarkedFinding, MarkOperation.Unmark); mMarkedFinding = value; - applyFindingColoring(mMarkedFinding, markOperation.Mark); + ApplyFindingColoring(mMarkedFinding, MarkOperation.Mark); } } - enum markOperation + enum MarkOperation { Unmark, None, Mark } - class processedSourceLine + class ProcessedSourceLine { public ParsedSourceLine SourceLine { get; private set; } public int LineTextIndex { get; private set; } - public processedSourceLine(ParsedSourceLine sourceLine, int lineTextIndex) + public ProcessedSourceLine(ParsedSourceLine sourceLine, int lineTextIndex) { SourceLine = sourceLine; LineTextIndex = lineTextIndex; diff --git a/MixEmul/Components/SymbolListView.Designer.cs b/MixEmul/Components/SymbolListView.Designer.cs index 04cb24b..147e97c 100644 --- a/MixEmul/Components/SymbolListView.Designer.cs +++ b/MixEmul/Components/SymbolListView.Designer.cs @@ -56,9 +56,9 @@ private void InitializeComponent() this.mListView.TabIndex = 4; this.mListView.UseCompatibleStateImageBehavior = false; this.mListView.View = System.Windows.Forms.View.Details; - this.mListView.DoubleClick += new System.EventHandler(this.mListView_DoubleClick); - this.mListView.SelectedIndexChanged += new System.EventHandler(this.mListView_SelectedIndexChanged); - this.mListView.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.mListView_KeyPress); + this.mListView.DoubleClick += new System.EventHandler(this.MListView_DoubleClick); + this.mListView.SelectedIndexChanged += new System.EventHandler(this.MListView_SelectedIndexChanged); + this.mListView.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MListView_KeyPress); // // mNameColumnHeader // @@ -90,7 +90,7 @@ private void InitializeComponent() this.mSetButton.TabIndex = 2; this.mSetButton.Text = "&Set"; this.mSetButton.UseVisualStyleBackColor = true; - this.mSetButton.Click += new System.EventHandler(this.mSetButton_Click); + this.mSetButton.Click += new System.EventHandler(this.MSetButton_Click); // // mUnsetButton // @@ -102,7 +102,7 @@ private void InitializeComponent() this.mUnsetButton.TabIndex = 3; this.mUnsetButton.Text = "U&nset"; this.mUnsetButton.UseVisualStyleBackColor = true; - this.mUnsetButton.Click += new System.EventHandler(this.mUnsetButton_Click); + this.mUnsetButton.Click += new System.EventHandler(this.MUnsetButton_Click); // // mSymbolValueTextBox // diff --git a/MixEmul/Components/SymbolListView.cs b/MixEmul/Components/SymbolListView.cs index 256b1d8..73b927d 100644 --- a/MixEmul/Components/SymbolListView.cs +++ b/MixEmul/Components/SymbolListView.cs @@ -28,22 +28,22 @@ public SymbolListView() mSymbolValueTextBox.MaxValue = ValueSymbol.MaxValue; mSymbolNameTextBox.MaxLength = ValueSymbol.MaxNameLength; - mSymbolNameTextBox.TextChanged += mSymbolNameTextBox_TextChanged; - mSymbolValueTextBox.TextChanged += mSymbolValueTextBox_TextChanged; - mListView.SelectedIndexChanged += mListView_SelectedIndexChanged; + mSymbolNameTextBox.TextChanged += MSymbolNameTextBox_TextChanged; + mSymbolValueTextBox.TextChanged += MSymbolValueTextBox_TextChanged; + mListView.SelectedIndexChanged += MListView_SelectedIndexChanged; } - void mSymbolValueTextBox_TextChanged(object sender, EventArgs e) => setEnabledStates(); + void MSymbolValueTextBox_TextChanged(object sender, EventArgs e) => SetEnabledStates(); - void mSymbolNameTextBox_TextChanged(object sender, EventArgs e) => setEnabledStates(); + void MSymbolNameTextBox_TextChanged(object sender, EventArgs e) => SetEnabledStates(); - void setEnabledStates() => setEnabledStates(true); + void SetEnabledStates() => SetEnabledStates(true); - void mListView_DoubleClick(object sender, EventArgs e) => valueSelected(); + void MListView_DoubleClick(object sender, EventArgs e) => ValueSelected(); protected virtual void OnAddressSelected(AddressSelectedEventArgs args) => AddressSelected?.Invoke(this, args); - void setEnabledStates(bool updateSelectedItem) + void SetEnabledStates(bool updateSelectedItem) { string symbolName = mSymbolNameTextBox.Text; mSetButton.Enabled = ValueSymbol.IsValueSymbolName(symbolName) && mSymbolValueTextBox.TextLength > 0; @@ -91,7 +91,7 @@ public SymbolCollection Symbols foreach (SymbolBase symbol in mSymbols) { - showSymbol(symbol); + ShowSymbol(symbol); } ResumeLayout(); @@ -110,14 +110,12 @@ public void AddSymbol(SymbolBase symbol) mSymbols.Add(symbol); - showSymbol(symbol); + ShowSymbol(symbol); } - void showSymbol(SymbolBase symbol) + void ShowSymbol(SymbolBase symbol) { - var valueSymbol = symbol as ValueSymbol; - - if (valueSymbol != null) + if (symbol is ValueSymbol valueSymbol) { var valueText = valueSymbol.Magnitude.ToString(); if (valueSymbol.Sign.IsNegative()) @@ -125,8 +123,10 @@ void showSymbol(SymbolBase symbol) valueText = '-' + valueText; } - var viewItem = new ListViewItem(new string[] { valueSymbol.Name, valueText }); - viewItem.Name = valueSymbol.Name; + var viewItem = new ListViewItem(new string[] { valueSymbol.Name, valueText }) + { + Name = valueSymbol.Name + }; mListView.Items.Add(viewItem); } } @@ -163,7 +163,7 @@ public long SelectedValue } } - void valueSelected() + void ValueSelected() { long selectedValue = SelectedValue; if (selectedValue >= MemoryMinIndex && selectedValue <= MemoryMaxIndex) @@ -172,16 +172,16 @@ void valueSelected() } } - void mListView_KeyPress(object sender, KeyPressEventArgs e) + void MListView_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { e.Handled = true; - valueSelected(); + ValueSelected(); } } - void mSetButton_Click(object sender, EventArgs e) + void MSetButton_Click(object sender, EventArgs e) { if (mSymbols == null) { @@ -217,13 +217,13 @@ void mSetButton_Click(object sender, EventArgs e) valueSymbol.SetValue(symbolSign, symbolMagnitude); mSymbols.Add(valueSymbol); - showSymbol(valueSymbol); + ShowSymbol(valueSymbol); } - setEnabledStates(); + SetEnabledStates(); } - void mUnsetButton_Click(object sender, EventArgs e) + void MUnsetButton_Click(object sender, EventArgs e) { if (mSymbols == null) return; @@ -231,10 +231,10 @@ void mUnsetButton_Click(object sender, EventArgs e) mSymbols.Remove(symbolName); mListView.Items.RemoveByKey(symbolName); - setEnabledStates(); + SetEnabledStates(); } - void mListView_SelectedIndexChanged(object sender, EventArgs e) + void MListView_SelectedIndexChanged(object sender, EventArgs e) { ListView.SelectedListViewItemCollection selectedItems = mListView.SelectedItems; @@ -260,7 +260,7 @@ void mListView_SelectedIndexChanged(object sender, EventArgs e) mSymbolValueTextBox.Magnitude = magnitude; mSymbolValueTextBox.Sign = sign; - setEnabledStates(false); + SetEnabledStates(false); } } } diff --git a/MixEmul/Components/TeletypeForm.cs b/MixEmul/Components/TeletypeForm.cs index 74ff42c..bd61ff9 100644 --- a/MixEmul/Components/TeletypeForm.cs +++ b/MixEmul/Components/TeletypeForm.cs @@ -29,11 +29,11 @@ public TeletypeForm(MixLib.Device.TeletypeDevice teleType) TeletypeDevice = teleType; } - void mClearButton_Click(object sender, EventArgs e) => ClearOutput(); + void MClearButton_Click(object sender, EventArgs e) => ClearOutput(); - void mSendButton_Click(object sender, EventArgs e) => sendInput(); + void MSendButton_Click(object sender, EventArgs e) => SendInput(); - void activated(object sender, EventArgs e) + void This_Activated(object sender, EventArgs e) { mOutputTextBox.Select(mOutputTextBox.TextLength, 0); mOutputTextBox.Focus(); @@ -73,7 +73,7 @@ public void AddOutputText(string textToAdd) } } - void formClosing(object sender, FormClosingEventArgs e) + void This_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; Visible = false; @@ -128,7 +128,7 @@ void InitializeComponent() mInputTextBox.Name = "mInputTextBox"; mInputTextBox.Size = new Size(512, 20); mInputTextBox.TabIndex = 3; - mInputTextBox.KeyPress += keyPress; + mInputTextBox.KeyPress += This_KeyPress; // // mStatusBar // @@ -155,7 +155,7 @@ void InitializeComponent() mClearButton.Size = new Size(75, 23); mClearButton.TabIndex = 1; mClearButton.Text = "&Clear"; - mClearButton.Click += mClearButton_Click; + mClearButton.Click += MClearButton_Click; // // mSendButton // @@ -165,7 +165,7 @@ void InitializeComponent() mSendButton.Size = new Size(75, 23); mSendButton.TabIndex = 4; mSendButton.Text = "&Send"; - mSendButton.Click += mSendButton_Click; + mSendButton.Click += MSendButton_Click; // // mOnTopCheckBox // @@ -175,7 +175,7 @@ void InitializeComponent() mOnTopCheckBox.Size = new Size(72, 24); mOnTopCheckBox.TabIndex = 6; mOnTopCheckBox.Text = "&On top"; - mOnTopCheckBox.CheckedChanged += mOnTopCheckBox_CheckedChanged; + mOnTopCheckBox.CheckedChanged += MOnTopCheckBox_CheckedChanged; // // mEchoInputCheckBox // @@ -205,21 +205,21 @@ void InitializeComponent() StartPosition = FormStartPosition.CenterParent; Text = "Teletype"; TopMost = true; - Activated += activated; - VisibleChanged += visibleChanged; - FormClosing += formClosing; + Activated += This_Activated; + VisibleChanged += This_VisibleChanged; + FormClosing += This_FormClosing; ((ISupportInitialize)(mStatusBarPanel)).EndInit(); ResumeLayout(false); PerformLayout(); } - void keyPress(object sender, KeyPressEventArgs args) + void This_KeyPress(object sender, KeyPressEventArgs args) { char keyChar = args.KeyChar; if (keyChar == (char)Keys.Enter) { - sendInput(); + SendInput(); args.Handled = true; } else @@ -239,16 +239,16 @@ public void ClearOutput() mOutputTextBox.Text = ""; } - void mOnTopCheckBox_CheckedChanged(object sender, EventArgs e) + void MOnTopCheckBox_CheckedChanged(object sender, EventArgs e) { TopMost = mOnTopCheckBox.Checked; } - void outputAdded(object sender, EventArgs e) + void OutputAdded(object sender, EventArgs e) { if (InvokeRequired) { - Invoke(new EventHandler(outputAdded)); + Invoke(new EventHandler(OutputAdded)); } else { @@ -277,7 +277,7 @@ void outputAdded(object sender, EventArgs e) } } - void sendInput() + void SendInput() { if (EchoInput) AddOutputText("> " + mInputTextBox.Text); @@ -303,7 +303,7 @@ public void UpdateLayout() mOutputTextBox.BackColor = GuiSettings.GetColor(GuiSettings.TeletypeOutputBackground); } - void visibleChanged(object sender, EventArgs e) + void This_VisibleChanged(object sender, EventArgs e) { if (!Visible) { @@ -345,7 +345,7 @@ public MixLib.Device.TeletypeDevice TeletypeDevice if (mTeletypeDevice != null) { - mTeletypeDevice.OutputAdded += outputAdded; + mTeletypeDevice.OutputAdded += OutputAdded; } } } diff --git a/MixEmul/Components/TextFileDeviceEditor.Designer.cs b/MixEmul/Components/TextFileDeviceEditor.Designer.cs index ff562c6..bd2f853 100644 --- a/MixEmul/Components/TextFileDeviceEditor.Designer.cs +++ b/MixEmul/Components/TextFileDeviceEditor.Designer.cs @@ -68,7 +68,7 @@ private void InitializeComponent() this.mReadOnlyCheckBox.Size = new System.Drawing.Size(15, 14); this.mReadOnlyCheckBox.TabIndex = 1; this.mReadOnlyCheckBox.UseVisualStyleBackColor = true; - this.mReadOnlyCheckBox.CheckedChanged += new System.EventHandler(this.mReadOnlyCheckBox_CheckedChanged); + this.mReadOnlyCheckBox.CheckedChanged += new System.EventHandler(this.MReadOnlyCheckBox_CheckedChanged); // // mReadOnlyLabel // @@ -88,7 +88,7 @@ private void InitializeComponent() this.mRevertButton.TabIndex = 10; this.mRevertButton.Text = "&Revert"; this.mRevertButton.UseVisualStyleBackColor = true; - this.mRevertButton.Click += new System.EventHandler(this.mRevertButton_Click); + this.mRevertButton.Click += new System.EventHandler(this.MRevertButton_Click); // // mSaveButton // @@ -99,17 +99,17 @@ private void InitializeComponent() this.mSaveButton.TabIndex = 10; this.mSaveButton.Text = "&Save"; this.mSaveButton.UseVisualStyleBackColor = true; - this.mSaveButton.Click += new System.EventHandler(this.mSaveButton_Click); + this.mSaveButton.Click += new System.EventHandler(this.MSaveButton_Click); // // mDeviceFileWatcher // this.mDeviceFileWatcher.EnableRaisingEvents = true; this.mDeviceFileWatcher.NotifyFilter = ((System.IO.NotifyFilters)((System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite))); this.mDeviceFileWatcher.SynchronizingObject = this; - this.mDeviceFileWatcher.Changed += new System.IO.FileSystemEventHandler(this.mDeviceFileWatcher_Event); - this.mDeviceFileWatcher.Created += new System.IO.FileSystemEventHandler(this.mDeviceFileWatcher_Event); - this.mDeviceFileWatcher.Deleted += new System.IO.FileSystemEventHandler(this.mDeviceFileWatcher_Event); - this.mDeviceFileWatcher.Renamed += new System.IO.RenamedEventHandler(this.mDeviceFileWatcher_Renamed); + this.mDeviceFileWatcher.Changed += new System.IO.FileSystemEventHandler(this.MDeviceFileWatcher_Event); + this.mDeviceFileWatcher.Created += new System.IO.FileSystemEventHandler(this.MDeviceFileWatcher_Event); + this.mDeviceFileWatcher.Deleted += new System.IO.FileSystemEventHandler(this.MDeviceFileWatcher_Event); + this.mDeviceFileWatcher.Renamed += new System.IO.RenamedEventHandler(this.MDeviceFileWatcher_Renamed); // // mMixByteCollectionEditorList // @@ -127,7 +127,7 @@ private void InitializeComponent() this.mMixByteCollectionEditorList.ResizeInProgress = false; this.mMixByteCollectionEditorList.Size = new System.Drawing.Size(278, 32); this.mMixByteCollectionEditorList.TabIndex = 9; - this.mMixByteCollectionEditorList.FirstVisibleIndexChanged += new MixGui.Components.EditorList.FirstVisibleIndexChangedHandler(this.mMixByteCollectionEditorList_FirstVisibleIndexChanged); + this.mMixByteCollectionEditorList.FirstVisibleIndexChanged += new MixGui.Components.EditorList.FirstVisibleIndexChangedHandler(this.MMixByteCollectionEditorList_FirstVisibleIndexChanged); // // mMixCharButtons // @@ -153,12 +153,12 @@ private void InitializeComponent() this.mFirstRecordTextBox.SupportNegativeZero = false; this.mFirstRecordTextBox.TabIndex = 6; this.mFirstRecordTextBox.Text = "0"; - this.mFirstRecordTextBox.ValueChanged += new MixGui.Components.LongValueTextBox.ValueChangedEventHandler(this.mFirstRecordTextBox_ValueChanged); + this.mFirstRecordTextBox.ValueChanged += new MixGui.Components.LongValueTextBox.ValueChangedEventHandler(this.MFirstRecordTextBox_ValueChanged); // // mIODelayTimer // this.mIODelayTimer.Interval = 500; - this.mIODelayTimer.Tick += new System.EventHandler(this.mIODelayTimer_Tick); + this.mIODelayTimer.Tick += new System.EventHandler(this.MIODelayTimer_Tick); // // mAppendButton // @@ -169,7 +169,7 @@ private void InitializeComponent() this.mAppendButton.TabIndex = 11; this.mAppendButton.Text = "A&ppend"; this.mAppendButton.UseVisualStyleBackColor = true; - this.mAppendButton.Click += new System.EventHandler(this.mAppendButton_Click); + this.mAppendButton.Click += new System.EventHandler(this.MAppendButton_Click); // // mTruncateButton // @@ -180,7 +180,7 @@ private void InitializeComponent() this.mTruncateButton.TabIndex = 11; this.mTruncateButton.Text = "&Truncate"; this.mTruncateButton.UseVisualStyleBackColor = true; - this.mTruncateButton.Click += new System.EventHandler(this.mTruncateButton_Click); + this.mTruncateButton.Click += new System.EventHandler(this.MTruncateButton_Click); // // TextFileDeviceEditor // diff --git a/MixEmul/Components/TextFileDeviceEditor.cs b/MixEmul/Components/TextFileDeviceEditor.cs index e1c3414..173c68a 100644 --- a/MixEmul/Components/TextFileDeviceEditor.cs +++ b/MixEmul/Components/TextFileDeviceEditor.cs @@ -58,7 +58,7 @@ public TextFileDeviceEditor() mReadBytes = new List(); mEditBytes = new List(); - setDeviceRecordCount(1); + SetDeviceRecordCount(1); mInitialized = false; mLoading = false; @@ -66,21 +66,21 @@ public TextFileDeviceEditor() public bool SupportsAppending => !mReadOnlyCheckBox.Checked; - bool loadRecords() => loadRecords(loadErrorHandlingMode.AbortOnError); + bool LoadRecords() => LoadRecords(LoadErrorHandlingMode.AbortOnError); public new void Update() => mMixByteCollectionEditorList.Update(); - public bool Save() => writeRecords(); + public bool Save() => WriteRecords(); - void mSaveButton_Click(object sender, EventArgs e) => writeRecords(); + void MSaveButton_Click(object sender, EventArgs e) => WriteRecords(); - void mRevertButton_Click(object sender, EventArgs e) => revert(); + void MRevertButton_Click(object sender, EventArgs e) => Revert(); - void mDeviceFileWatcher_Event(object sender, FileSystemEventArgs e) => handleFileWatcherEvent(); + void MDeviceFileWatcher_Event(object sender, FileSystemEventArgs e) => HandleFileWatcherEvent(); - void DeviceEditor_VisibleChanged(object sender, EventArgs e) => processVisibility(); + void DeviceEditor_VisibleChanged(object sender, EventArgs e) => ProcessVisibility(); - void mDeviceFileWatcher_Renamed(object sender, RenamedEventArgs e) => handleFileWatcherEvent(); + void MDeviceFileWatcher_Renamed(object sender, RenamedEventArgs e) => HandleFileWatcherEvent(); public void Initialize(int bytesPerRecord, OpenStreamCallback openStream, ReadMixByteCallback readBytes, WriteMixByteCallback writeBytes) { @@ -99,15 +99,15 @@ public void Initialize(int bytesPerRecord, OpenStreamCallback openStream, ReadMi mFirstRecordTextBox.MaxValue = DeviceRecordCount - 1; mMixByteCollectionEditorList.MaxIndex = (int)DeviceRecordCount - 1; - mMixByteCollectionEditorList.CreateEditor = createMixByteCollectionEditor; - mMixByteCollectionEditorList.LoadEditor = loadMixByteCollectionEditor; + mMixByteCollectionEditorList.CreateEditor = CreateMixByteCollectionEditor; + mMixByteCollectionEditorList.LoadEditor = LoadMixByteCollectionEditor; mChangesPending = false; mLoadRetryCount = 0; - processReadOnlySettings(); - processVisibility(); + ProcessReadOnlySettings(); + ProcessVisibility(); } public string RecordName @@ -124,7 +124,7 @@ public string RecordName } } - void processSupportsAppending() + void ProcessSupportsAppending() { bool supportsAppending = SupportsAppending; @@ -168,11 +168,11 @@ public bool ShowReadOnly mBottomButtonsGap += mReadOnlyGap; } - processReadOnlySettings(); + ProcessReadOnlySettings(); } } - void processReadOnlySettings() + void ProcessReadOnlySettings() { bool showBottomButtons = !mMixByteCollectionEditorList.ReadOnly || mShowReadOnly; @@ -185,10 +185,10 @@ void processReadOnlySettings() mMixByteCollectionEditorList.Height = showBottomButtons ? (Height - mMixByteCollectionEditorList.Top - mBottomButtonsGap) : (Height - mMixByteCollectionEditorList.Top); - processSupportsAppending(); + ProcessSupportsAppending(); } - void setDeviceRecordCount(int recordCount) + void SetDeviceRecordCount(int recordCount) { if (recordCount < 1) { @@ -199,7 +199,7 @@ void setDeviceRecordCount(int recordCount) mMixByteCollectionEditorList.MaxIndex = (int)DeviceRecordCount - 1; - adaptListToRecordCount(mEditBytes); + AdaptListToRecordCount(mEditBytes); mFirstRecordTextBox.MaxValue = DeviceRecordCount - 1; @@ -209,51 +209,53 @@ void setDeviceRecordCount(int recordCount) editor.IndexCharCount = mIndexCharCount; } - processSupportsAppending(); + ProcessSupportsAppending(); Update(); } - void adaptListToRecordCount(List list) + void AdaptListToRecordCount(List list) { while (list.Count < DeviceRecordCount) list.Add(new MixByteCollection(mDeviceBytesPerRecord)); while (list.Count > DeviceRecordCount) list.RemoveAt(list.Count - 1); } - IMixByteCollectionEditor createMixByteCollectionEditor(int index) + IMixByteCollectionEditor CreateMixByteCollectionEditor(int index) { - var editor = new DeviceMixByteCollectionEditor(index == int.MinValue ? new MixByteCollection(mDeviceBytesPerRecord) : mEditBytes[index]); - editor.MixByteCollectionIndex = index; - editor.IndexCharCount = mIndexCharCount; - editor.ValueChanged += editor_ValueChanged; + var editor = new DeviceMixByteCollectionEditor(index == int.MinValue ? new MixByteCollection(mDeviceBytesPerRecord) : mEditBytes[index]) + { + MixByteCollectionIndex = index, + IndexCharCount = mIndexCharCount + }; + editor.ValueChanged += Editor_ValueChanged; return editor; } - void processVisibility() + void ProcessVisibility() { if (Visible) { mDeviceFileWatcher.EnableRaisingEvents |= Device != null; - loadRecords(); + LoadRecords(); } else { - if (changesPending) writeRecords(); + if (ChangesPending) WriteRecords(); mDeviceFileWatcher.EnableRaisingEvents &= Device == null; } } - void editor_ValueChanged(IMixByteCollectionEditor sender, MixGui.Events.MixByteCollectionEditorValueChangedEventArgs args) + void Editor_ValueChanged(IMixByteCollectionEditor sender, MixGui.Events.MixByteCollectionEditorValueChangedEventArgs args) { - changesPending = true; + ChangesPending = true; } - void loadMixByteCollectionEditor(IMixByteCollectionEditor editor, int index) + void LoadMixByteCollectionEditor(IMixByteCollectionEditor editor, int index) { var deviceEditor = (DeviceMixByteCollectionEditor)editor; deviceEditor.DeviceMixByteCollection = index >= 0 ? mEditBytes[index] : new MixByteCollection(mDeviceBytesPerRecord); @@ -268,24 +270,24 @@ public bool SetDevice(FileBasedDevice device) FileBasedDevice oldDevice = Device; Device = device; - initDeviceFileWatcher(); + InitDeviceFileWatcher(); - var success = loadRecords(loadErrorHandlingMode.AbortOnError); + var success = LoadRecords(LoadErrorHandlingMode.AbortOnError); if (!success) { Device = oldDevice; - initDeviceFileWatcher(); + InitDeviceFileWatcher(); } else { - processSupportsAppending(); + ProcessSupportsAppending(); } return success; } - void initDeviceFileWatcher() + void InitDeviceFileWatcher() { if (Device != null) { @@ -295,7 +297,7 @@ void initDeviceFileWatcher() } } - bool changesPending + bool ChangesPending { get { @@ -310,7 +312,7 @@ bool changesPending } } - bool loadRecords(loadErrorHandlingMode errorHandlingMode) + bool LoadRecords(LoadErrorHandlingMode errorHandlingMode) { if (!Visible) return true; if (Device == null) return false; @@ -354,9 +356,9 @@ bool loadRecords(loadErrorHandlingMode errorHandlingMode) mEditBytes.Add((IMixByteCollection)item.Clone()); } - setDeviceRecordCount(mReadBytes.Count); + SetDeviceRecordCount(mReadBytes.Count); - changesPending = false; + ChangesPending = false; mLastLoadTime = DateTime.Now; mLoadRetryCount = 0; @@ -365,9 +367,9 @@ bool loadRecords(loadErrorHandlingMode errorHandlingMode) } catch (Exception ex) { - if (errorHandlingMode == loadErrorHandlingMode.RetryOnError || (mLoadRetryCount > 0 && mLoadRetryCount <= maxLoadRetryCount)) + if (errorHandlingMode == LoadErrorHandlingMode.RetryOnError || (mLoadRetryCount > 0 && mLoadRetryCount <= maxLoadRetryCount)) { - mDelayedIOOperation = loadRecords; + mDelayedIOOperation = LoadRecords; mLoadRetryCount++; mIODelayTimer.Start(); @@ -397,7 +399,7 @@ bool loadRecords(loadErrorHandlingMode errorHandlingMode) return true; } - public bool writeRecords() + public bool WriteRecords() { if (!mChangesPending) return true; if (mReadOnlyCheckBox.Checked) return false; @@ -424,7 +426,7 @@ public bool writeRecords() foreach (IMixByteCollection item in mEditBytes) mReadBytes.Add((IMixByteCollection)item.Clone()); - changesPending = false; + ChangesPending = false; } catch (Exception ex) { @@ -444,9 +446,9 @@ public bool writeRecords() public void UpdateSettings() { - initDeviceFileWatcher(); + InitDeviceFileWatcher(); - if (Visible) loadRecords(); + if (Visible) LoadRecords(); mIODelayTimer.Interval = DeviceSettings.DeviceReloadInterval; } @@ -459,34 +461,34 @@ public void UpdateLayout() mMixByteCollectionEditorList.BackColor = GuiSettings.GetColor(GuiSettings.EditorBackground); } - void mReadOnlyCheckBox_CheckedChanged(object sender, EventArgs e) + void MReadOnlyCheckBox_CheckedChanged(object sender, EventArgs e) { mMixByteCollectionEditorList.ReadOnly = mReadOnlyCheckBox.Checked; - if (mReadOnlyCheckBox.Checked && mRevertButton.Enabled) revert(); + if (mReadOnlyCheckBox.Checked && mRevertButton.Enabled) Revert(); - processReadOnlySettings(); + ProcessReadOnlySettings(); } - void mFirstRecordTextBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) + void MFirstRecordTextBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) { mMixByteCollectionEditorList.FirstVisibleIndex = (int)args.NewValue; } - void mMixByteCollectionEditorList_FirstVisibleIndexChanged(EditorList sender, MixByteCollectionEditorList.FirstVisibleIndexChangedEventArgs args) + void MMixByteCollectionEditorList_FirstVisibleIndexChanged(EditorList sender, MixByteCollectionEditorList.FirstVisibleIndexChangedEventArgs args) { mFirstRecordTextBox.LongValue = mMixByteCollectionEditorList.FirstVisibleIndex; } - void revert() + void Revert() { mEditBytes.Clear(); foreach (IMixByteCollection item in mReadBytes) mEditBytes.Add((IMixByteCollection)item.Clone()); - setDeviceRecordCount(mReadBytes.Count); + SetDeviceRecordCount(mReadBytes.Count); - changesPending = false; + ChangesPending = false; Update(); } @@ -515,46 +517,46 @@ public bool ResizeInProgress } } - void handleFileWatcherEvent() + void HandleFileWatcherEvent() { if (mLoading || mIODelayTimer.Enabled) return; if ((DateTime.Now - mLastLoadTime).TotalMilliseconds > mIODelayTimer.Interval) { - loadRecords(loadErrorHandlingMode.RetryOnError); + LoadRecords(LoadErrorHandlingMode.RetryOnError); } else { - mDelayedIOOperation = loadRecords; + mDelayedIOOperation = LoadRecords; mIODelayTimer.Start(); } } - void mIODelayTimer_Tick(object sender, EventArgs e) + void MIODelayTimer_Tick(object sender, EventArgs e) { mIODelayTimer.Stop(); mDelayedIOOperation(); } - enum loadErrorHandlingMode + enum LoadErrorHandlingMode { AbortOnError, RetryOnError } - void mAppendButton_Click(object sender, EventArgs e) + void MAppendButton_Click(object sender, EventArgs e) { - setDeviceRecordCount((int)DeviceRecordCount + 1); + SetDeviceRecordCount((int)DeviceRecordCount + 1); - changesPending = true; + ChangesPending = true; } - void mTruncateButton_Click(object sender, EventArgs e) + void MTruncateButton_Click(object sender, EventArgs e) { - setDeviceRecordCount((int)DeviceRecordCount - 1); + SetDeviceRecordCount((int)DeviceRecordCount - 1); - changesPending = true; + ChangesPending = true; } public void DeleteDeviceFile() @@ -575,7 +577,7 @@ public void DeleteDeviceFile() return; } - loadRecords(); + LoadRecords(); } } @@ -597,7 +599,7 @@ internal void LoadDeviceFile(string filePath) return; } - loadRecords(); + LoadRecords(); } } } diff --git a/MixEmul/Components/ToolStripCycleButton.cs b/MixEmul/Components/ToolStripCycleButton.cs index be0304f..c0681ca 100644 --- a/MixEmul/Components/ToolStripCycleButton.cs +++ b/MixEmul/Components/ToolStripCycleButton.cs @@ -42,11 +42,13 @@ void ToolStripCycleButton_Paint(object sender, PaintEventArgs e) { if (string.IsNullOrEmpty(Text)) { - var stringFormat = new StringFormat(); - stringFormat.Alignment = StringAlignment.Center; - stringFormat.LineAlignment = StringAlignment.Center; + var stringFormat = new StringFormat + { + Alignment = StringAlignment.Center, + LineAlignment = StringAlignment.Center + }; - e.Graphics.DrawString(mCurrentStep == null ? "" : mCurrentStep.Text, Control.Font, new SolidBrush(Control.ForeColor), 1, 1); + e.Graphics.DrawString(mCurrentStep == null ? "" : mCurrentStep.Text, Control.Font, new SolidBrush(Control.ForeColor), 1, 1); } } @@ -54,7 +56,7 @@ void Control_Click(object sender, EventArgs e) { if (mCurrentStep == null || mCurrentStep.NextStep == null) return; - setCurrentStep(mCurrentStep.NextStep); + SetCurrentStep(mCurrentStep.NextStep); } void Control_SizeChanged(object sender, EventArgs e) @@ -112,14 +114,14 @@ public void AddStep(Step step) mSteps.Add(step); - if (mCurrentStep == null) setCurrentStep(step); + if (mCurrentStep == null) SetCurrentStep(step); } public object Value { get { - return mCurrentStep == null ? null : mCurrentStep.Value; + return mCurrentStep?.Value; } set { @@ -132,11 +134,11 @@ public object Value throw new ArgumentException(string.Format("no step with Value {0} exists", value)); } - setCurrentStep(step); + SetCurrentStep(step); } } - void setCurrentStep(Step step) + void SetCurrentStep(Step step) { if (mCurrentStep == step) return; diff --git a/MixEmul/Components/WordEditor.cs b/MixEmul/Components/WordEditor.cs index fe044d3..aa18131 100644 --- a/MixEmul/Components/WordEditor.cs +++ b/MixEmul/Components/WordEditor.cs @@ -53,20 +53,22 @@ public WordEditor(int byteCount, bool includeSign) mLastRenderedMagnitude = unrendered; mLastRenderedSign = Word.Signs.Positive; - mSignButton = new Button(); - mSignButton.Location = new Point(0, 0); - mSignButton.Name = "SignButton"; - mSignButton.Size = new Size(18, 21); - mSignButton.TabIndex = 0; - mSignButton.TabStop = false; - mSignButton.Text = "" + mWord.Sign.ToChar(); - mSignButton.FlatStyle = FlatStyle.Flat; - mSignButton.Enabled = !ReadOnly; - mSignButton.Click += mSignButton_Click; - mSignButton.KeyPress += editor_keyPress; - mSignButton.KeyDown += keyDown; - - initializeComponent(); + mSignButton = new Button + { + Location = new Point(0, 0), + Name = "SignButton", + Size = new Size(18, 21), + TabIndex = 0, + TabStop = false, + Text = "" + mWord.Sign.ToChar(), + FlatStyle = FlatStyle.Flat, + Enabled = !ReadOnly + }; + mSignButton.Click += MSignButton_Click; + mSignButton.KeyPress += Editor_KeyPress; + mSignButton.KeyDown += This_KeyDown; + + InitializeComponent(); } public int? CaretIndex => null; @@ -78,7 +80,7 @@ public bool Focus(FieldTypes? field, int? index) => protected virtual void OnValueChanged(WordEditorValueChangedEventArgs args) => ValueChanged?.Invoke(this, args); - void byteValueChanged(MixByteTextBox textBox, MixByteTextBox.ValueChangedEventArgs args) + void ByteValueChanged(MixByteTextBox textBox, MixByteTextBox.ValueChangedEventArgs args) { var oldValue = new Word(mWord.Magnitude, mWord.Sign); mWord[textBox.Index] = args.NewValue; @@ -90,21 +92,21 @@ void byteValueChanged(MixByteTextBox textBox, MixByteTextBox.ValueChangedEventAr } - void editor_Click(object sender, EventArgs e) + void Editor_Click(object sender, EventArgs e) { var box = (MixByteTextBox)sender; if (box.SelectionLength == 0) box.Select(0, 2); } - void editor_keyPress(object sender, KeyPressEventArgs e) + void Editor_KeyPress(object sender, KeyPressEventArgs e) { char keyChar = e.KeyChar; - if (IncludeSign && (keyChar == '-' || (keyChar == '+' && mWord.Sign.IsNegative()))) negateSign(); + if (IncludeSign && (keyChar == '-' || (keyChar == '+' && mWord.Sign.IsNegative()))) NegateSign(); } - void editor_Leave(object sender, EventArgs e) + void Editor_Leave(object sender, EventArgs e) { var box = (MixByteTextBox)sender; mFocusByte = box.Index; @@ -112,7 +114,7 @@ void editor_Leave(object sender, EventArgs e) mFocusByteSelLength = box.SelectionLength; } - void initializeComponent() + void InitializeComponent() { mFocusByte = 0; mFocusByteSelStart = 0; @@ -131,17 +133,19 @@ void initializeComponent() mByteTextBoxes = new MixByteTextBox[ByteCount]; for (int i = 0; i < ByteCount; i++) { - var box = new MixByteTextBox(i); - box.Location = new Point(width, 0); - box.Name = "MixByteEditor" + i; - box.MixByteValue = mWord[i]; - box.ReadOnly = ReadOnly; - box.TabIndex = tabIndex; - box.ValueChanged += byteValueChanged; - box.Click += editor_Click; - box.Leave += editor_Leave; - box.KeyPress += editor_keyPress; - box.KeyDown += keyDown; + var box = new MixByteTextBox(i) + { + Location = new Point(width, 0), + Name = "MixByteEditor" + i, + MixByteValue = mWord[i], + ReadOnly = ReadOnly, + TabIndex = tabIndex + }; + box.ValueChanged += ByteValueChanged; + box.Click += Editor_Click; + box.Leave += Editor_Leave; + box.KeyPress += Editor_KeyPress; + box.KeyDown += This_KeyDown; mByteTextBoxes[i] = box; @@ -157,7 +161,7 @@ void initializeComponent() Update(); } - void keyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers != Keys.None) return; @@ -225,9 +229,9 @@ void keyDown(object sender, KeyEventArgs e) } } - void mSignButton_Click(object sender, EventArgs e) + void MSignButton_Click(object sender, EventArgs e) { - negateSign(); + NegateSign(); if (mByteTextBoxes.Length > 0) { mByteTextBoxes[mFocusByte].Focus(); @@ -236,7 +240,7 @@ void mSignButton_Click(object sender, EventArgs e) } } - void negateSign() + void NegateSign() { Word.Signs sign = mWord.Sign; mWord.InvertSign(); @@ -249,13 +253,13 @@ void negateSign() OnValueChanged(new WordEditorValueChangedEventArgs(oldValue, newValue)); } - void reinitializeComponent() + void ReinitializeComponent() { Controls.Clear(); foreach (MixByteTextBox box in mByteTextBoxes) box.Dispose(); - initializeComponent(); + InitializeComponent(); } public new void Update() @@ -291,7 +295,7 @@ public int ByteCount if (ByteCount != value) { mWord = new Word(value); - reinitializeComponent(); + ReinitializeComponent(); } } } @@ -307,7 +311,7 @@ public bool IncludeSign if (mIncludeSign != value) { mIncludeSign = value; - reinitializeComponent(); + ReinitializeComponent(); } } } @@ -350,7 +354,7 @@ public IWord WordValue } else { - reinitializeComponent(); + ReinitializeComponent(); } } } diff --git a/MixEmul/Components/WordValueEditor.cs b/MixEmul/Components/WordValueEditor.cs index a1c8a51..682caf5 100644 --- a/MixEmul/Components/WordValueEditor.cs +++ b/MixEmul/Components/WordValueEditor.cs @@ -55,8 +55,8 @@ public WordValueEditor(int byteCount, bool includeSign) mWordEditor.ReadOnly = mReadOnly; mWordEditor.TabIndex = 0; mWordEditor.TabStop = true; - mWordEditor.ValueChanged += wordEditor_ValueChanged; - mWordEditor.NavigationKeyDown += keyDown; + mWordEditor.ValueChanged += WordEditor_ValueChanged; + mWordEditor.NavigationKeyDown += This_KeyDown; mEqualsLabel.Name = "EqualsLabel"; mEqualsLabel.TabIndex = 1; @@ -70,17 +70,17 @@ public WordValueEditor(int byteCount, bool includeSign) mLongValueTextBox.TabIndex = 2; mLongValueTextBox.TabStop = true; mLongValueTextBox.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top; - mLongValueTextBox.ValueChanged += textBox_ValueChanged; - mLongValueTextBox.NavigationKeyDown += keyDown; + mLongValueTextBox.ValueChanged += TextBox_ValueChanged; + mLongValueTextBox.NavigationKeyDown += This_KeyDown; SuspendLayout(); Controls.Add(mWordEditor); Controls.Add(mEqualsLabel); Controls.Add(mLongValueTextBox); Name = "WordValueEditor"; - KeyDown += keyDown; + KeyDown += This_KeyDown; - sizeComponent(); + SizeComponent(); } public Control EditorControl => this; @@ -99,7 +99,7 @@ protected override void Dispose(bool disposing) { } - void keyDown(object sender, KeyEventArgs e) + void This_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers != Keys.None) return; @@ -147,7 +147,7 @@ void keyDown(object sender, KeyEventArgs e) } } - void sizeComponent() + void SizeComponent() { SuspendLayout(); @@ -163,7 +163,7 @@ void sizeComponent() ResumeLayout(false); } - void textBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) + void TextBox_ValueChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) { IWord wordValue = mWordEditor.WordValue; IWord oldValue = new Word(wordValue.Magnitude, wordValue.Sign); @@ -188,7 +188,7 @@ public void UpdateLayout() mLongValueTextBox.UpdateLayout(); } - void wordEditor_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) + void WordEditor_ValueChanged(IWordEditor sender, WordEditorValueChangedEventArgs args) { mLongValueTextBox.Magnitude = mWordEditor.WordValue.MagnitudeLongValue; mLongValueTextBox.Sign = mWordEditor.WordValue.Sign; @@ -206,7 +206,7 @@ public int ByteCount if (ByteCount != value) { mWordEditor.ByteCount = value; - sizeComponent(); + SizeComponent(); } } } @@ -223,7 +223,7 @@ public bool IncludeSign { mIncludeSign = value; mWordEditor.IncludeSign = mIncludeSign; - sizeComponent(); + SizeComponent(); } } } @@ -256,7 +256,7 @@ public int TextBoxWidth if (mTextBoxWidth != value) { mTextBoxWidth = value; - sizeComponent(); + SizeComponent(); } } } @@ -278,7 +278,7 @@ public IWord WordValue } else { - sizeComponent(); + SizeComponent(); } } } diff --git a/MixEmul/MixForm.cs b/MixEmul/MixForm.cs index 187c981..4a197f9 100644 --- a/MixEmul/MixForm.cs +++ b/MixEmul/MixForm.cs @@ -39,7 +39,7 @@ public partial class MixForm : Form bool mUpdating; ImageList mSeverityImageList; SourceAndFindingsForm mSourceAndFindingsForm; - steppingState mSteppingState; + SteppingState mSteppingState; TeletypeForm mTeletype; MenuStrip mMainMenuStrip; ToolStripMenuItem mFileToolStripMenuItem; @@ -133,18 +133,20 @@ public MixForm() mMix.StepPerformed += mMix_StepPerformed; mMix.LogLineAdded += mMix_LogLineAdded; - mPCBox = new LongValueTextBox(); - mPCBox.BackColor = Color.White; - mPCBox.BorderStyle = BorderStyle.FixedSingle; - mPCBox.ForeColor = Color.Black; - mPCBox.LongValue = mMix.ProgramCounter; - mPCBox.ClearZero = false; - setPCBoxBounds(); + mPCBox = new LongValueTextBox + { + BackColor = Color.White, + BorderStyle = BorderStyle.FixedSingle, + ForeColor = Color.Black, + LongValue = mMix.ProgramCounter, + ClearZero = false + }; + SetPCBoxBounds(); mPCBox.Name = "mPCBox"; mPCBox.Size = new Size(40, 25); mPCBox.TabIndex = 1; mPCBox.Text = "0"; - mPCBox.ValueChanged += pcChanged; + mPCBox.ValueChanged += PcChanged; mControlToolStrip.Items.Insert(1, new LongValueToolStripTextBox(mPCBox)); mRegistersEditor.Registers = mMix.Registers; @@ -152,7 +154,7 @@ public MixForm() mMainMemoryEditor.ToolTip = mToolTip; mMainMemoryEditor.Memory = mMix.FullMemory; mMainMemoryEditor.MarkedAddress = mMix.ProgramCounter; - mMainMemoryEditor.IndexedAddressCalculatorCallback = calculateIndexedAddress; + mMainMemoryEditor.IndexedAddressCalculatorCallback = CalculateIndexedAddress; mProfilingEnabledMenuItem.Checked = ExecutionSettings.ProfilingEnabled; mProfilingShowTickCountsMenuItem.Enabled = ExecutionSettings.ProfilingEnabled; @@ -196,7 +198,7 @@ public MixForm() } CardDeckExporter.LoaderCards = mConfiguration.LoaderCards; - updateDeviceConfig(); + UpdateDeviceConfig(); mDeviceEditor = new DeviceEditorForm(mMix.Devices); mDeviceEditor.VisibleChanged += mDeviceEditor_VisibleChanged; @@ -219,14 +221,14 @@ public MixForm() mMix.Devices.Teletype.InputRequired += mMix_InputRequired; mMix.BreakpointManager = mMainMemoryEditor; - loadControlProgram(); - applyFloatingPointSettings(); + LoadControlProgram(); + ApplyFloatingPointSettings(); mOpenProgramFileDialog = null; mSourceAndFindingsForm = null; mReadOnly = false; mRunning = false; - mSteppingState = steppingState.Idle; + mSteppingState = SteppingState.Idle; var symbols = new SymbolCollection(); mSymbolListView.Symbols = symbols; @@ -257,48 +259,45 @@ public MixForm() LocationChanged += this_LocationChanged; } - MemoryEditor activeMemoryEditor => mMemoryEditors[mMemoryTabControl.SelectedIndex]; + MemoryEditor ActiveMemoryEditor => mMemoryEditors[mMemoryTabControl.SelectedIndex]; - void findNext() => activeMemoryEditor.FindMatch(mSearchOptions); + void FindNext() => ActiveMemoryEditor.FindMatch(mSearchOptions); - int calculateIndexedAddress(int address, int index) => + int CalculateIndexedAddress(int address, int index) => InstructionHelpers.GetValidIndexedAddress(mMix, address, index, false); - void setPCBoxBounds() + void SetPCBoxBounds() { mPCBox.MinValue = mMix.Memory.MinWordIndex; mPCBox.MaxValue = mMix.Memory.MaxWordIndex; } - void applyFloatingPointSettings() + void ApplyFloatingPointSettings() { mMix.SetFloatingPointModuleEnabled(ModuleSettings.FloatingPointEnabled); if (ModuleSettings.FloatingPointEnabled) { - loadModuleProgram(mMix.FloatingPointModule, ModuleSettings.FloatingPointProgramFile, "floating point"); + LoadModuleProgram(mMix.FloatingPointModule, ModuleSettings.FloatingPointProgramFile, "floating point"); } } - void loadControlProgram() + void LoadControlProgram() { string controlProgramFileName = ModuleSettings.ControlProgramFile; if (string.IsNullOrEmpty(controlProgramFileName) || !File.Exists(controlProgramFileName)) return; - loadModuleProgram(mMix, controlProgramFileName, "control"); + LoadModuleProgram(mMix, controlProgramFileName, "control"); mMix.FullMemory.ClearSourceLines(); } - SymbolCollection loadModuleProgram(ModuleBase module, string fileName, string programName) + SymbolCollection LoadModuleProgram(ModuleBase module, string fileName, string programName) { try { - PreInstruction[] instructions; - AssemblyFindingCollection findings; - SymbolCollection symbols; - var instances = Assembler.Assemble(File.ReadAllLines(fileName), out instructions, out symbols, out findings); + var instances = Assembler.Assemble(File.ReadAllLines(fileName), out PreInstruction[] instructions, out SymbolCollection symbols, out AssemblyFindingCollection findings); if (instances != null) { if (!module.LoadInstructionInstances(instances, symbols)) @@ -330,7 +329,7 @@ SymbolCollection loadModuleProgram(ModuleBase module, string fileName, string pr return null; } - bool disableTeletypeOnTop() + bool DisableTeletypeOnTop() { if (mTeletype != null && mTeletype.Visible && mTeletype.TopMost) { @@ -352,7 +351,7 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } - static void handleException(Exception exception) + static void HandleException(Exception exception) { Exception handlingException = null; var path = Path.Combine(Environment.CurrentDirectory, "exception.log"); @@ -380,7 +379,6 @@ static void handleException(Exception exception) writer.WriteLine(); writer.Close(); - writer.Dispose(); } catch (Exception ex) { @@ -403,7 +401,7 @@ static void handleException(Exception exception) Application.Exit(); } - void implementPCChange(int address) + void ImplementPCChange(int address) { if (mMainMemoryEditor.IsAddressVisible(mMix.ProgramCounter)) { @@ -1267,21 +1265,19 @@ void InitializeComponent() } - void loadProgram(string filePath) + void LoadProgram(string filePath) { if (filePath == null) return; - PreInstruction[] instructions; - AssemblyFindingCollection findings; - SymbolCollection symbols; - - var instances = Assembler.Assemble(File.ReadAllLines(filePath), out instructions, out symbols, out findings); + var instances = Assembler.Assemble(File.ReadAllLines(filePath), out PreInstruction[] instructions, out SymbolCollection symbols, out AssemblyFindingCollection findings); if (instructions != null && findings != null) { if (mSourceAndFindingsForm == null) { - mSourceAndFindingsForm = new SourceAndFindingsForm(); - mSourceAndFindingsForm.SeverityImageList = mSeverityImageList; + mSourceAndFindingsForm = new SourceAndFindingsForm + { + SeverityImageList = mSeverityImageList + }; } mSourceAndFindingsForm.SetInstructionsAndFindings(instructions, instances, findings); @@ -1308,11 +1304,11 @@ static void Main() } - void switchRunningState() + void SwitchRunningState() { - if (mSteppingState == steppingState.Idle) + if (mSteppingState == SteppingState.Idle) { - setSteppingState(steppingState.Stepping); + SetSteppingState(SteppingState.Stepping); mRunning = true; mMix.StartRun(); } @@ -1323,18 +1319,18 @@ void switchRunningState() } } - void pcChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) + void PcChanged(LongValueTextBox source, LongValueTextBox.ValueChangedEventArgs args) { - if (!mUpdating) implementPCChange((int)args.NewValue); + if (!mUpdating) ImplementPCChange((int)args.NewValue); } - void setSteppingState(steppingState state) + void SetSteppingState(SteppingState state) { if (mSteppingState != state) { mSteppingState = state; - if (mSteppingState == steppingState.Idle) + if (mSteppingState == SteppingState.Idle) { ReadOnly = false; mRunToolStripButton.Text = "R&un"; @@ -1349,7 +1345,7 @@ void setSteppingState(steppingState state) } } - void switchTeletypeVisibility() + void SwitchTeletypeVisibility() { if (mTeletype.Visible) { @@ -1365,7 +1361,7 @@ void switchTeletypeVisibility() { mUpdating = true; var pcVisible = mMainMemoryEditor.IsAddressVisible((int)mPCBox.LongValue); - setPCBoxBounds(); + SetPCBoxBounds(); mPCBox.LongValue = mMix.ProgramCounter; mMainMemoryEditor.MarkedAddress = mMix.ProgramCounter; if (mFloatingPointMemoryEditor != null) @@ -1417,7 +1413,7 @@ void switchTeletypeVisibility() mUpdating = false; } - void updateDeviceConfig() + void UpdateDeviceConfig() { DeviceSettings.DeviceFilesDirectory = mConfiguration.DeviceFilesDirectory; DeviceSettings.TickCounts = mConfiguration.TickCounts; @@ -1489,13 +1485,13 @@ public bool ReadOnly } } - enum steppingState + enum SteppingState { Idle, Stepping } - void implementFloatingPointPCChange(int address) + void ImplementFloatingPointPCChange(int address) { if (mFloatingPointMemoryEditor != null && mFloatingPointMemoryEditor.IsAddressVisible(mMix.FloatingPointModule.ProgramCounter)) { diff --git a/MixEmul/MixForm.handlers.cs b/MixEmul/MixForm.handlers.cs index e86b2d6..edabede 100644 --- a/MixEmul/MixForm.handlers.cs +++ b/MixEmul/MixForm.handlers.cs @@ -16,19 +16,19 @@ public partial class MixForm { void mExitMenuItem_Click(object sender, EventArgs e) => Close(); - static void application_ThreadException(object sender, ThreadExceptionEventArgs e) => handleException(e.Exception); + static void application_ThreadException(object sender, ThreadExceptionEventArgs e) => HandleException(e.Exception); static void currentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) => - handleException((Exception)e.ExceptionObject); + HandleException((Exception)e.ExceptionObject); - void mRunItem_Click(object sender, EventArgs e) => switchRunningState(); + void mRunItem_Click(object sender, EventArgs e) => SwitchRunningState(); void mShowPCButton_Click(object sender, EventArgs e) => mMainMemoryEditor.MakeAddressVisible(mMix.ProgramCounter); - void mTeletypeItem_Click(object sender, EventArgs e) => switchTeletypeVisibility(); + void mTeletypeItem_Click(object sender, EventArgs e) => SwitchTeletypeVisibility(); void mFloatingPointMemoryEditor_AddressSelected(object sender, AddressSelectedEventArgs args) => - implementFloatingPointPCChange(args.SelectedAddress); + ImplementFloatingPointPCChange(args.SelectedAddress); void mDevicesControl_DeviceDoubleClick(object sender, DeviceEventArgs e) { @@ -48,7 +48,7 @@ void mModeCycleButton_ValueChanged(object sender, EventArgs e) { int pc = mMix.ProgramCounter; mMix.Mode = (ModuleBase.RunMode)mModeCycleButton.Value; - setPCBoxBounds(); + SetPCBoxBounds(); if (pc != mMix.ProgramCounter) { @@ -75,7 +75,7 @@ void mAboutMenuItem_Click(object sender, EventArgs e) mAboutForm = new AboutForm(); } - var teletypeWasOnTop = disableTeletypeOnTop(); + var teletypeWasOnTop = DisableTeletypeOnTop(); mAboutForm.ShowDialog(this); @@ -94,12 +94,12 @@ void listViews_addressSelected(object sender, AddressSelectedEventArgs args) { mMemoryTabControl.SelectedIndex = mLogListView.SelectedModule == mMix.FloatingPointModule.ModuleName ? floatingPointMemoryEditorIndex : mainMemoryEditorIndex; } - activeMemoryEditor.MakeAddressVisible(args.SelectedAddress); + ActiveMemoryEditor.MakeAddressVisible(args.SelectedAddress); } void mMemoryEditor_addressSelected(object sender, AddressSelectedEventArgs args) { - if (!mReadOnly) implementPCChange(args.SelectedAddress); + if (!mReadOnly) ImplementPCChange(args.SelectedAddress); } void mMix_InputRequired(object sender, EventArgs e) @@ -115,7 +115,7 @@ void mMix_InputRequired(object sender, EventArgs e) if (!mTeletype.Visible) { - switchTeletypeVisibility(); + SwitchTeletypeVisibility(); } mTeletype.Activate(); @@ -158,14 +158,14 @@ void mMix_StepPerformed(object sender, EventArgs e) else { mRunning = false; - setSteppingState(steppingState.Idle); + SetSteppingState(SteppingState.Idle); } } } void mOpenProgramMenuItem_Click(object sender, EventArgs e) { - var teletypeWasOnTop = disableTeletypeOnTop(); + var teletypeWasOnTop = DisableTeletypeOnTop(); if (mOpenProgramFileDialog == null) { @@ -180,7 +180,7 @@ void mOpenProgramMenuItem_Click(object sender, EventArgs e) mLogListView.AddLogLine(new LogLine("Assembler", Severity.Info, "Parsing source", "File: " + mOpenProgramFileDialog.FileName)); try { - loadProgram(mOpenProgramFileDialog.FileName); + LoadProgram(mOpenProgramFileDialog.FileName); } catch (Exception ex) { @@ -199,13 +199,13 @@ void mPreferencesMenuItem_Click(object sender, EventArgs e) mPreferencesForm = new PreferencesForm(mConfiguration, mMix.Devices, mDefaultDirectory); } - var teletypeWasOnTop = disableTeletypeOnTop(); + var teletypeWasOnTop = DisableTeletypeOnTop(); if (mPreferencesForm.ShowDialog(this) == DialogResult.OK) { GuiSettings.ColorProfilingCounts = mConfiguration.ColorProfilingCounts; UpdateLayout(); - updateDeviceConfig(); + UpdateDeviceConfig(); mDeviceEditor.UpdateSettings(); CardDeckExporter.LoaderCards = mConfiguration.LoaderCards; } @@ -222,10 +222,10 @@ void mResetItem_Click(object sender, EventArgs e) mSymbolListView.Reset(); mMainMemoryEditor.ClearBreakpoints(); mMainMemoryEditor.Symbols = null; - loadControlProgram(); + LoadControlProgram(); mMix.FloatingPointModule.FullMemory.Reset(); - applyFloatingPointSettings(); + ApplyFloatingPointSettings(); if (mFloatingPointMemoryEditor != null) { mFloatingPointMemoryEditor.ClearBreakpoints(); @@ -245,7 +245,7 @@ void mResetTicksButton_Click(object sender, EventArgs e) void mStepItem_Click(object sender, EventArgs e) { - setSteppingState(steppingState.Stepping); + SetSteppingState(SteppingState.Stepping); mMix.StartStep(); } @@ -340,10 +340,10 @@ void mDeviceEditorItem_Click(object sender, EventArgs e) void mGoItem_Click(object sender, EventArgs e) { - if (mSteppingState == steppingState.Idle) + if (mSteppingState == SteppingState.Idle) { mMix.PrepareLoader(); - switchRunningState(); + SwitchRunningState(); } } @@ -362,7 +362,7 @@ void mMemoryTabControl_Selecting(object sender, TabControlCancelEventArgs e) mFloatingPointMemoryEditor.Anchor = mMainMemoryEditor.Anchor; mFloatingPointMemoryEditor.MarkedAddress = mMix.FloatingPointModule.ProgramCounter; mFloatingPointMemoryEditor.FirstVisibleAddress = mFloatingPointMemoryEditor.MarkedAddress; - mFloatingPointMemoryEditor.IndexedAddressCalculatorCallback = calculateIndexedAddress; + mFloatingPointMemoryEditor.IndexedAddressCalculatorCallback = CalculateIndexedAddress; mFloatingPointMemoryEditor.Location = mMainMemoryEditor.Location; mFloatingPointMemoryEditor.Size = mFloatingPointMemoryTab.Size; mFloatingPointMemoryEditor.Name = "mFloatingPointMemoryEditor"; @@ -383,7 +383,7 @@ void mMemoryTabControl_Selecting(object sender, TabControlCancelEventArgs e) void mMemoryTabControl_SelectedIndexChanged(object sender, EventArgs e) { - MemoryEditor editor = activeMemoryEditor; + MemoryEditor editor = ActiveMemoryEditor; mSymbolListView.Symbols = editor.Symbols; mSymbolListView.MemoryMinIndex = editor.Memory.MinWordIndex; mSymbolListView.MemoryMaxIndex = editor.Memory.MaxWordIndex; @@ -400,7 +400,7 @@ void mFindMenuItem_Click(object sender, EventArgs e) { mSearchOptions = mSearchDialog.SearchParameters; - findNext(); + FindNext(); } } @@ -412,7 +412,7 @@ void mFindNextMenuItem_Click(object sender, EventArgs e) return; } - findNext(); + FindNext(); } void mProfilingEnabledMenuItem_CheckedChanged(object sender, EventArgs e) diff --git a/MixEmul/Settings/Configuration.cs b/MixEmul/Settings/Configuration.cs index 03a22ab..1e61fcf 100644 --- a/MixEmul/Settings/Configuration.cs +++ b/MixEmul/Settings/Configuration.cs @@ -49,7 +49,7 @@ public Configuration() DeviceReloadInterval = DeviceSettings.UnsetDeviceReloadInterval; FloatingPointMemoryWordCount = null; ColorProfilingCounts = true; - fillEmptyMembers(); + FillEmptyMembers(); } protected Configuration(SerializationInfo info, StreamingContext context) @@ -57,7 +57,7 @@ protected Configuration(SerializationInfo info, StreamingContext context) mSerializationInfo = info; } - void fillEmptyMembers() + void FillEmptyMembers() { if (Colors == null) { @@ -284,7 +284,7 @@ public void OnDeserialization(object sender) } catch (SystemException) { } - fillEmptyMembers(); + FillEmptyMembers(); } } } diff --git a/MixEmul/Settings/GuiSettings.cs b/MixEmul/Settings/GuiSettings.cs index 6800237..886a8d8 100644 --- a/MixEmul/Settings/GuiSettings.cs +++ b/MixEmul/Settings/GuiSettings.cs @@ -40,35 +40,39 @@ public static class GuiSettings static GuiSettings() { - mDefaultColors = new Dictionary(); - mDefaultColors.Add(ErrorText, Color.Red); - mDefaultColors.Add(WarningText, Color.DarkOrange); - mDefaultColors.Add(InfoText, Color.DarkGreen); - mDefaultColors.Add(DebugText, Color.DarkBlue); - mDefaultColors.Add(RenderedText, Color.Black); - mDefaultColors.Add(EditingText, Color.Blue); - mDefaultColors.Add(ImmutableText, Color.DarkGray); - mDefaultColors.Add(EditorBackground, Color.White); - mDefaultColors.Add(LoadedInstructionText, Color.Black); - mDefaultColors.Add(LoadedInstructionBackground, Color.FromArgb(255, 255, 255, 204)); - mDefaultColors.Add(AddressText, Color.Black); - mDefaultColors.Add(ProgramCounterAddressBackground, Color.Yellow); - mDefaultColors.Add(DeviceIdle, Color.LawnGreen); - mDefaultColors.Add(DeviceBusy, Color.Yellow); - mDefaultColors.Add(LocationFieldText, Color.Black); - mDefaultColors.Add(OpFieldText, Color.Blue); - mDefaultColors.Add(AddressFieldText, Color.Black); - mDefaultColors.Add(CommentFieldText, Color.DarkGreen); - mDefaultColors.Add(LineNumberText, Color.DarkSeaGreen); - mDefaultColors.Add(LineNumberSeparator, Color.DarkGray); - mDefaultColors.Add(TeletypeInputText, Color.Black); - mDefaultColors.Add(TeletypeInputBackground, Color.White); - mDefaultColors.Add(TeletypeOutputText, Color.White); - mDefaultColors.Add(TeletypeOutputBackground, Color.Black); - Colors = new Dictionary(); - mDefaultFonts = new Dictionary(); - mDefaultFonts.Add(FixedWidth, new Font("Courier New", 9f, FontStyle.Regular, GraphicsUnit.Point, 0)); - ColorProfilingCounts = true; + mDefaultColors = new Dictionary + { + { ErrorText, Color.Red }, + { WarningText, Color.DarkOrange }, + { InfoText, Color.DarkGreen }, + { DebugText, Color.DarkBlue }, + { RenderedText, Color.Black }, + { EditingText, Color.Blue }, + { ImmutableText, Color.DarkGray }, + { EditorBackground, Color.White }, + { LoadedInstructionText, Color.Black }, + { LoadedInstructionBackground, Color.FromArgb(255, 255, 255, 204) }, + { AddressText, Color.Black }, + { ProgramCounterAddressBackground, Color.Yellow }, + { DeviceIdle, Color.LawnGreen }, + { DeviceBusy, Color.Yellow }, + { LocationFieldText, Color.Black }, + { OpFieldText, Color.Blue }, + { AddressFieldText, Color.Black }, + { CommentFieldText, Color.DarkGreen }, + { LineNumberText, Color.DarkSeaGreen }, + { LineNumberSeparator, Color.DarkGray }, + { TeletypeInputText, Color.Black }, + { TeletypeInputBackground, Color.White }, + { TeletypeOutputText, Color.White }, + { TeletypeOutputBackground, Color.Black } + }; + Colors = new Dictionary(); + mDefaultFonts = new Dictionary + { + { FixedWidth, new Font("Courier New", 9f, FontStyle.Regular, GraphicsUnit.Point, 0) } + }; + ColorProfilingCounts = true; } public static bool IsKnownColor(string name) => mDefaultColors.ContainsKey(name); diff --git a/MixEmul/Utils/CardDeckExporter.cs b/MixEmul/Utils/CardDeckExporter.cs index fd2445f..03c70f4 100644 --- a/MixEmul/Utils/CardDeckExporter.cs +++ b/MixEmul/Utils/CardDeckExporter.cs @@ -19,9 +19,9 @@ public static class CardDeckExporter const int maxWordsPerCard = 7; - static string getTransLine(int programCounter) => "TRANS0" + getAddressText(programCounter); + static string GetTransLine(int programCounter) => "TRANS0" + GetAddressText(programCounter); - static char getNegativeDigit(char digit) => MixByte.MixChars[MixByte.MixChars.IndexOf(digit) - 30]; + static char GetNegativeDigit(char digit) => MixByte.MixChars[MixByte.MixChars.IndexOf(digit) - 30]; public static string[] LoaderCards { @@ -35,7 +35,7 @@ public static string[] LoaderCards } } - static StreamWriter prepareWriter(string filePath) + static StreamWriter PrepareWriter(string filePath) { var writer = new StreamWriter(filePath, false, Encoding.ASCII); @@ -52,7 +52,7 @@ public static void ExportFullWords(string filePath, IList wordsToWrit { var words = new List(); - var writer = prepareWriter(filePath); + var writer = PrepareWriter(filePath); foreach (IFullWord word in wordsToWrite) { @@ -60,15 +60,15 @@ public static void ExportFullWords(string filePath, IList wordsToWrit if (words.Count == maxWordsPerCard) { - writer.WriteLine(getInformationLine(firstWordLocation, words)); + writer.WriteLine(GetInformationLine(firstWordLocation, words)); words.Clear(); firstWordLocation += maxWordsPerCard; } } - if (words.Count > 0) writer.WriteLine(getInformationLine(firstWordLocation, words)); + if (words.Count > 0) writer.WriteLine(GetInformationLine(firstWordLocation, words)); - writer.WriteLine(getTransLine(programCounter)); + writer.WriteLine(GetTransLine(programCounter)); writer.Close(); } @@ -80,7 +80,7 @@ public static void ExportInstructions(string filePath, InstructionInstanceBase[] LoaderInstruction.Instance loaderInstance; MixInstruction.Instance mixInstance; - var writer = prepareWriter(filePath); + var writer = PrepareWriter(filePath); foreach (InstructionInstanceBase instance in instances) { @@ -93,7 +93,7 @@ public static void ExportInstructions(string filePath, InstructionInstanceBase[] case LoaderInstruction.Operations.SetLocationCounter: if (words.Count > 0) { - writer.WriteLine(getInformationLine(firstWordLocation, words)); + writer.WriteLine(GetInformationLine(firstWordLocation, words)); } words.Clear(); @@ -110,10 +110,10 @@ public static void ExportInstructions(string filePath, InstructionInstanceBase[] case LoaderInstruction.Operations.SetProgramCounter: if (words.Count > 0) { - writer.WriteLine(getInformationLine(firstWordLocation, words)); + writer.WriteLine(GetInformationLine(firstWordLocation, words)); } - writer.WriteLine(getTransLine((int)loaderInstance.Value.LongValue)); + writer.WriteLine(GetTransLine((int)loaderInstance.Value.LongValue)); writer.Close(); return; } @@ -128,31 +128,31 @@ public static void ExportInstructions(string filePath, InstructionInstanceBase[] if (words.Count == maxWordsPerCard) { - writer.WriteLine(getInformationLine(firstWordLocation, words)); + writer.WriteLine(GetInformationLine(firstWordLocation, words)); words.Clear(); firstWordLocation = locationCounter; } } } - static string getAddressText(int address) + static string GetAddressText(int address) { if (address < 0) { address = -address; var addressText = address.ToString("0000"); - return addressText.Substring(0, 3) + getNegativeDigit(addressText[3]); + return addressText.Substring(0, 3) + GetNegativeDigit(addressText[3]); } return address.ToString("0000"); } - static string getInformationLine(int firstWordLocation, List words) + static string GetInformationLine(int firstWordLocation, List words) { var lineBuilder = new StringBuilder("INFO "); lineBuilder.Append(words.Count.ToString()); - lineBuilder.Append(getAddressText(firstWordLocation)); + lineBuilder.Append(GetAddressText(firstWordLocation)); string numberText; @@ -167,7 +167,7 @@ static string getInformationLine(int firstWordLocation, List words) else { lineBuilder.Append(numberText.Substring(0, 9)); - lineBuilder.Append(getNegativeDigit(numberText[9])); + lineBuilder.Append(GetNegativeDigit(numberText[9])); } } diff --git a/MixLib/Device/CardReaderDevice.cs b/MixLib/Device/CardReaderDevice.cs index ed13a81..8de9c49 100644 --- a/MixLib/Device/CardReaderDevice.cs +++ b/MixLib/Device/CardReaderDevice.cs @@ -36,20 +36,22 @@ public sealed override void UpdateSettings() { DeviceStep nextStep = new NoOpStep(DeviceSettings.GetTickCount(DeviceSettings.CardReaderInitialization), initializationDescription); FirstInputDeviceStep = nextStep; - nextStep.NextStep = new openStreamStep(); + nextStep.NextStep = new OpenStreamStep(); nextStep = nextStep.NextStep; nextStep.NextStep = new TextReadStep(recordWordCount); nextStep = nextStep.NextStep; nextStep.NextStep = new CloseStreamStep(); nextStep = nextStep.NextStep; - nextStep.NextStep = new WriteToMemoryStep(false, recordWordCount); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new WriteToMemoryStep(false, recordWordCount) + { + NextStep = null + }; FirstOutputDeviceStep = null; FirstIocDeviceStep = null; } - class openStreamStep : StreamStep + class OpenStreamStep : StreamStep { public override string StatusDescription => openingDescription; diff --git a/MixLib/Device/CardWriterDevice.cs b/MixLib/Device/CardWriterDevice.cs index 251ce0f..47ac8c6 100644 --- a/MixLib/Device/CardWriterDevice.cs +++ b/MixLib/Device/CardWriterDevice.cs @@ -40,17 +40,19 @@ public sealed override void UpdateSettings() FirstOutputDeviceStep = nextStep; nextStep.NextStep = new ReadFromMemoryStep(false, recordWordCount); nextStep = nextStep.NextStep; - nextStep.NextStep = new openStreamStep(); + nextStep.NextStep = new OpenStreamStep(); nextStep = nextStep.NextStep; nextStep.NextStep = new TextWriteStep(recordWordCount); nextStep = nextStep.NextStep; - nextStep.NextStep = new CloseStreamStep(); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new CloseStreamStep + { + NextStep = null + }; FirstIocDeviceStep = null; } - class openStreamStep : StreamStep + class OpenStreamStep : StreamStep { public override StreamStep.Instance CreateStreamInstance(StreamStatus streamStatus) => new Instance(streamStatus); diff --git a/MixLib/Device/DiskDevice.cs b/MixLib/Device/DiskDevice.cs index 745d89a..6a8be79 100644 --- a/MixLib/Device/DiskDevice.cs +++ b/MixLib/Device/DiskDevice.cs @@ -41,35 +41,41 @@ public sealed override void UpdateSettings() DeviceStep nextStep = new NoOpStep(tickCount, initializationDescription); FirstInputDeviceStep = nextStep; - nextStep.NextStep = new openStreamStep(); + nextStep.NextStep = new OpenStreamStep(); nextStep = nextStep.NextStep; - nextStep.NextStep = new seekStep(); + nextStep.NextStep = new SeekStep(); nextStep = nextStep.NextStep; nextStep.NextStep = new BinaryReadStep(WordsPerSector); nextStep = nextStep.NextStep; nextStep.NextStep = new CloseStreamStep(); nextStep = nextStep.NextStep; - nextStep.NextStep = new WriteToMemoryStep(true, WordsPerSector); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new WriteToMemoryStep(true, WordsPerSector) + { + NextStep = null + }; - nextStep = new NoOpStep(tickCount, initializationDescription); + nextStep = new NoOpStep(tickCount, initializationDescription); FirstOutputDeviceStep = nextStep; nextStep.NextStep = new ReadFromMemoryStep(true, WordsPerSector); nextStep = nextStep.NextStep; - nextStep.NextStep = new openStreamStep(); + nextStep.NextStep = new OpenStreamStep(); nextStep = nextStep.NextStep; - nextStep.NextStep = new seekStep(); + nextStep.NextStep = new SeekStep(); nextStep = nextStep.NextStep; nextStep.NextStep = new BinaryWriteStep(WordsPerSector); nextStep = nextStep.NextStep; - nextStep.NextStep = new CloseStreamStep(); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new CloseStreamStep + { + NextStep = null + }; - nextStep = new NoOpStep(tickCount, initializationDescription); + nextStep = new NoOpStep(tickCount, initializationDescription); FirstIocDeviceStep = nextStep; - nextStep.NextStep = new seekStep(); - nextStep.NextStep.NextStep = null; - } + nextStep.NextStep = new SeekStep + { + NextStep = null + }; + } public new static FileStream OpenStream(string fileName, FileMode fileMode, FileAccess fileAccess, FileShare fileShare) { @@ -87,7 +93,7 @@ public sealed override void UpdateSettings() return stream; } - class openStreamStep : StreamStep + class OpenStreamStep : StreamStep { public override string StatusDescription => openingDescription; @@ -120,7 +126,7 @@ public override bool Tick() } } - class seekStep : StreamStep + class SeekStep : StreamStep { public override string StatusDescription => seekingDescription; diff --git a/MixLib/Device/FileBasedDevice.cs b/MixLib/Device/FileBasedDevice.cs index 020e715..b6f88fd 100644 --- a/MixLib/Device/FileBasedDevice.cs +++ b/MixLib/Device/FileBasedDevice.cs @@ -21,7 +21,7 @@ protected FileBasedDevice(int id, string fileNamePrefix) : base(id) mFileNamePrefix = fileNamePrefix; mFilePath = null; StreamStatus = new StreamStatus(); - StreamStatus.ReportingEvent += streamStatus_Reporting; + StreamStatus.ReportingEvent += StreamStatus_Reporting; } public string DefaultFileName => mFileNamePrefix + Id + "." + FileNameExtension; @@ -31,7 +31,7 @@ public static FileStream OpenStream(string fileName, FileMode fileMode, FileAcce public void CloseStream() => StreamStatus.CloseStream(); - void streamStatus_Reporting(object sender, ReportingEventArgs args) => OnReportingEvent(args); + void StreamStatus_Reporting(object sender, ReportingEventArgs args) => OnReportingEvent(args); protected override DeviceStep.Instance GetCurrentStepInstance() => CurrentStep is StreamStep ? ((StreamStep)CurrentStep).CreateStreamInstance(StreamStatus) diff --git a/MixLib/Device/MixDevice.cs b/MixLib/Device/MixDevice.cs index 4f133cd..21484b6 100644 --- a/MixLib/Device/MixDevice.cs +++ b/MixLib/Device/MixDevice.cs @@ -44,7 +44,7 @@ protected MixDevice(int id) protected virtual void OnReportingEvent(ReportingEventArgs args) => ReportingEvent?.Invoke(this, args); - void stepInstance_Reporting(object sender, ReportingEventArgs args) => OnReportingEvent(args); + void StepInstance_Reporting(object sender, ReportingEventArgs args) => OnReportingEvent(args); public virtual void Reset() { @@ -89,7 +89,7 @@ public void Tick() { mCurrentStepInstance = GetCurrentStepInstance(); mCurrentStepInstance.Operands = mCurrentOperands; - mCurrentStepInstance.ReportingEvent += stepInstance_Reporting; + mCurrentStepInstance.ReportingEvent += StepInstance_Reporting; } // Current step still busy? If so, we're done here @@ -109,7 +109,7 @@ public void Tick() // Move on to next I/O step var currentStepInstance = GetCurrentStepInstance(); currentStepInstance.Operands = mCurrentOperands; - currentStepInstance.ReportingEvent += stepInstance_Reporting; + currentStepInstance.ReportingEvent += StepInstance_Reporting; currentStepInstance.InputFromPreviousStep = mCurrentStepInstance.OutputForNextStep; mCurrentStepInstance = currentStepInstance; } diff --git a/MixLib/Device/PaperTapeDevice.cs b/MixLib/Device/PaperTapeDevice.cs index c4b394a..1285fb4 100644 --- a/MixLib/Device/PaperTapeDevice.cs +++ b/MixLib/Device/PaperTapeDevice.cs @@ -39,24 +39,28 @@ public sealed override void UpdateSettings() DeviceStep nextStep = new NoOpStep(tickCount, initializationDescription); FirstInputDeviceStep = nextStep; - nextStep.NextStep = new openStreamStep(); + nextStep.NextStep = new OpenStreamStep(); nextStep = nextStep.NextStep; nextStep.NextStep = new TextReadStep(recordWordCount); nextStep = nextStep.NextStep; nextStep.NextStep = new CloseStreamStep(); nextStep = nextStep.NextStep; - nextStep.NextStep = new WriteToMemoryStep(false, recordWordCount); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new WriteToMemoryStep(false, recordWordCount) + { + NextStep = null + }; FirstOutputDeviceStep = null; nextStep = new NoOpStep(tickCount, initializationDescription); FirstIocDeviceStep = nextStep; - nextStep.NextStep = new rewindStep(); - nextStep.NextStep.NextStep = null; - } + nextStep.NextStep = new RewindStep + { + NextStep = null + }; + } - class openStreamStep : StreamStep + class OpenStreamStep : StreamStep { public override string StatusDescription => openingDescription; @@ -82,7 +86,7 @@ public override bool Tick() } } - class rewindStep : StreamStep + class RewindStep : StreamStep { public override string StatusDescription => rewindingDescription; diff --git a/MixLib/Device/PrinterDevice.cs b/MixLib/Device/PrinterDevice.cs index 0596988..9cf4a9a 100644 --- a/MixLib/Device/PrinterDevice.cs +++ b/MixLib/Device/PrinterDevice.cs @@ -46,24 +46,28 @@ public sealed override void UpdateSettings() FirstOutputDeviceStep = nextStep; nextStep.NextStep = new ReadFromMemoryStep(false, recordWordCount); nextStep = nextStep.NextStep; - nextStep.NextStep = new openStreamStep(); + nextStep.NextStep = new OpenStreamStep(); nextStep = nextStep.NextStep; nextStep.NextStep = new TextWriteStep(recordWordCount); nextStep = nextStep.NextStep; - nextStep.NextStep = new CloseStreamStep(); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new CloseStreamStep + { + NextStep = null + }; - nextStep = new NoOpStep(tickCount, initializationDescription); + nextStep = new NoOpStep(tickCount, initializationDescription); FirstIocDeviceStep = nextStep; - nextStep.NextStep = new openStreamStep(); + nextStep.NextStep = new OpenStreamStep(); nextStep = nextStep.NextStep; - nextStep.NextStep = new pageForwardStep(); + nextStep.NextStep = new PageForwardStep(); nextStep = nextStep.NextStep; - nextStep.NextStep = new CloseStreamStep(); - nextStep.NextStep.NextStep = null; - } + nextStep.NextStep = new CloseStreamStep + { + NextStep = null + }; + } - class openStreamStep : StreamStep + class OpenStreamStep : StreamStep { public override string StatusDescription => openingDescription; @@ -96,7 +100,7 @@ public override bool Tick() } } - class pageForwardStep : StreamStep + class PageForwardStep : StreamStep { public override string StatusDescription => nextPageDescription; diff --git a/MixLib/Device/Settings/DeviceSettings.cs b/MixLib/Device/Settings/DeviceSettings.cs index c50bb5c..ba37ad9 100644 --- a/MixLib/Device/Settings/DeviceSettings.cs +++ b/MixLib/Device/Settings/DeviceSettings.cs @@ -27,19 +27,21 @@ public static class DeviceSettings static DeviceSettings() { - mDefaultTickCounts = new Dictionary(); - mDefaultTickCounts.Add(CardReaderInitialization, 100); - mDefaultTickCounts.Add(CardWriterInitialization, 100); - mDefaultTickCounts.Add(DiskInitialization, 50); - mDefaultTickCounts.Add(DiskSectorSeek, 20); - mDefaultTickCounts.Add(PaperTapeInitialization, 100); - mDefaultTickCounts.Add(PaperTapeRecordWind, 5); - mDefaultTickCounts.Add(PrinterInitialization, 50); - mDefaultTickCounts.Add(TapeInitialization, 100); - mDefaultTickCounts.Add(TapeRecordWind, 10); - mDefaultTickCounts.Add(TeletypeInitialization, 25); + mDefaultTickCounts = new Dictionary + { + { CardReaderInitialization, 100 }, + { CardWriterInitialization, 100 }, + { DiskInitialization, 50 }, + { DiskSectorSeek, 20 }, + { PaperTapeInitialization, 100 }, + { PaperTapeRecordWind, 5 }, + { PrinterInitialization, 50 }, + { TapeInitialization, 100 }, + { TapeRecordWind, 10 }, + { TeletypeInitialization, 25 } + }; - TickCounts = new Dictionary(); + TickCounts = new Dictionary(); mDeviceReloadInterval = UnsetDeviceReloadInterval; } diff --git a/MixLib/Device/Step/BinaryReadStep.cs b/MixLib/Device/Step/BinaryReadStep.cs index 11c3621..0f735ec 100644 --- a/MixLib/Device/Step/BinaryReadStep.cs +++ b/MixLib/Device/Step/BinaryReadStep.cs @@ -52,11 +52,12 @@ public static IFullWord[] ReadWords(Stream stream, int wordCount) for (int i = 0; i < wordCount; i++) { - currentWord = new FullWord(); - - currentWord.Sign = readBytes[byteIndex++].ToSign(); + currentWord = new FullWord + { + Sign = readBytes[byteIndex++].ToSign() + }; - for (int j = 0; j < FullWord.ByteCount; j++) + for (int j = 0; j < FullWord.ByteCount; j++) { currentWord[j] = readBytes[byteIndex++]; } diff --git a/MixLib/Device/StreamStatus.cs b/MixLib/Device/StreamStatus.cs index 5fd37de..d09c6b8 100644 --- a/MixLib/Device/StreamStatus.cs +++ b/MixLib/Device/StreamStatus.cs @@ -19,7 +19,7 @@ public StreamStatus() Reset(); } - void onReportingEvent(ReportingEventArgs args) => ReportingEvent?.Invoke(this, args); + void OnReportingEvent(ReportingEventArgs args) => ReportingEvent?.Invoke(this, args); public void CloseStream() { @@ -45,7 +45,7 @@ public void UpdatePosition() } catch (Exception exception) { - onReportingEvent(new ReportingEventArgs(Severity.Error, "exception while getting position in file " + FileName + ":" + exception.Message)); + OnReportingEvent(new ReportingEventArgs(Severity.Error, "exception while getting position in file " + FileName + ":" + exception.Message)); } } @@ -83,7 +83,7 @@ public long Position } catch (Exception exception) { - onReportingEvent(new ReportingEventArgs(Severity.Error, "exception while opening file " + FileName + ":" + exception.Message)); + OnReportingEvent(new ReportingEventArgs(Severity.Error, "exception while opening file " + FileName + ":" + exception.Message)); } } } @@ -96,17 +96,12 @@ public System.IO.Stream Stream } set { - if (value == null) - { - throw new ArgumentNullException(nameof(value), "stream may not be set to null"); - } - - if (mStream != null) + if (mStream != null) { throw new InvalidOperationException("can't replace open stream. Open stream must first be closed."); } - mStream = value; + mStream = value ?? throw new ArgumentNullException(nameof(value), "stream may not be set to null"); if (PositionSet) { diff --git a/MixLib/Device/TapeDevice.cs b/MixLib/Device/TapeDevice.cs index fb868e5..62133f3 100644 --- a/MixLib/Device/TapeDevice.cs +++ b/MixLib/Device/TapeDevice.cs @@ -44,33 +44,39 @@ public sealed override void UpdateSettings() DeviceStep nextStep = new NoOpStep(tickCount, initializationDescription); FirstInputDeviceStep = nextStep; - nextStep.NextStep = new openStreamStep(); + nextStep.NextStep = new OpenStreamStep(); nextStep = nextStep.NextStep; nextStep.NextStep = new BinaryReadStep(WordsPerRecord); nextStep = nextStep.NextStep; nextStep.NextStep = new CloseStreamStep(); nextStep = nextStep.NextStep; - nextStep.NextStep = new WriteToMemoryStep(true, WordsPerRecord); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new WriteToMemoryStep(true, WordsPerRecord) + { + NextStep = null + }; - nextStep = new NoOpStep(tickCount, initializationDescription); + nextStep = new NoOpStep(tickCount, initializationDescription); FirstOutputDeviceStep = nextStep; nextStep.NextStep = new ReadFromMemoryStep(true, WordsPerRecord); nextStep = nextStep.NextStep; - nextStep.NextStep = new openStreamStep(); + nextStep.NextStep = new OpenStreamStep(); nextStep = nextStep.NextStep; nextStep.NextStep = new BinaryWriteStep(WordsPerRecord); nextStep = nextStep.NextStep; - nextStep.NextStep = new CloseStreamStep(); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new CloseStreamStep + { + NextStep = null + }; - nextStep = new NoOpStep(tickCount, initializationDescription); + nextStep = new NoOpStep(tickCount, initializationDescription); FirstIocDeviceStep = nextStep; - nextStep.NextStep = new seekStep(); - nextStep.NextStep.NextStep = null; - } + nextStep.NextStep = new SeekStep + { + NextStep = null + }; + } - class openStreamStep : StreamStep + class OpenStreamStep : StreamStep { public override string StatusDescription => openingDescription; @@ -100,7 +106,7 @@ public override bool Tick() } } - class seekStep : StreamStep + class SeekStep : StreamStep { public override string StatusDescription => windingDescription; @@ -120,7 +126,7 @@ public override bool Tick() { if (mTicksLeft == unset) { - if (!StreamStatus.PositionSet) initiateStreamPosition(); + if (!StreamStatus.PositionSet) InitiateStreamPosition(); mTicksLeft = (Operands.MValue == 0 ? (StreamStatus.Position / ((FullWord.ByteCount + 1) * WordsPerRecord)) : Math.Abs(Operands.MValue)) * DeviceSettings.GetTickCount(DeviceSettings.TapeRecordWind); } @@ -146,7 +152,7 @@ public override bool Tick() return true; } - private void initiateStreamPosition() + private void InitiateStreamPosition() { try { diff --git a/MixLib/Device/TeletypeDevice.cs b/MixLib/Device/TeletypeDevice.cs index eb09561..4ed7e47 100644 --- a/MixLib/Device/TeletypeDevice.cs +++ b/MixLib/Device/TeletypeDevice.cs @@ -40,24 +40,24 @@ public TeletypeDevice(int id) : base(id) public string GetOutputLine() => mOutputBuffer.Count <= 0 ? null : (string)mOutputBuffer.Dequeue(); - void inputRequired(object sender, EventArgs e) => InputRequired?.Invoke(this, e); + void This_InputRequired(object sender, EventArgs e) => InputRequired?.Invoke(this, e); - void outputAdded(object sender, EventArgs e) => OutputAdded?.Invoke(this, e); + void This_OutputAdded(object sender, EventArgs e) => OutputAdded?.Invoke(this, e); protected override DeviceStep.Instance GetCurrentStepInstance() { - if (CurrentStep is readLineStep) + if (CurrentStep is ReadLineStep) { - var instance = (readLineStep.Instance)((readLineStep)CurrentStep).CreateInstance(); - instance.InputRequired += inputRequired; + var instance = (ReadLineStep.Instance)((ReadLineStep)CurrentStep).CreateInstance(); + instance.InputRequired += This_InputRequired; return instance; } - if (CurrentStep is writeLineStep) + if (CurrentStep is WriteLineStep) { - var instance = (writeLineStep.Instance)((writeLineStep)CurrentStep).CreateInstance(); - instance.OutputAdded += outputAdded; + var instance = (WriteLineStep.Instance)((WriteLineStep)CurrentStep).CreateInstance(); + instance.OutputAdded += This_OutputAdded; return instance; } @@ -74,26 +74,30 @@ public sealed override void UpdateSettings() DeviceStep nextStep = new NoOpStep(tickCount, initializationDescription); FirstInputDeviceStep = nextStep; - nextStep.NextStep = new readLineStep(mInputBuffer); + nextStep.NextStep = new ReadLineStep(mInputBuffer); nextStep = nextStep.NextStep; - nextStep.NextStep = new WriteToMemoryStep(false, recordWordCount); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new WriteToMemoryStep(false, recordWordCount) + { + NextStep = null + }; - nextStep = new NoOpStep(tickCount, initializationDescription); + nextStep = new NoOpStep(tickCount, initializationDescription); FirstOutputDeviceStep = nextStep; nextStep.NextStep = new ReadFromMemoryStep(false, recordWordCount); nextStep = nextStep.NextStep; - nextStep.NextStep = new writeLineStep(mOutputBuffer); - nextStep.NextStep.NextStep = null; + nextStep.NextStep = new WriteLineStep(mOutputBuffer) + { + NextStep = null + }; FirstIocDeviceStep = null; } - class readLineStep : DeviceStep + class ReadLineStep : DeviceStep { Queue mInputBuffer; - public readLineStep(Queue inputBuffer) + public ReadLineStep(Queue inputBuffer) { mInputBuffer = inputBuffer; } @@ -147,11 +151,11 @@ public override bool Tick() } } - class writeLineStep : DeviceStep + class WriteLineStep : DeviceStep { Queue mOutputBuffer; - public writeLineStep(Queue outputBuffer) + public WriteLineStep(Queue outputBuffer) { mOutputBuffer = outputBuffer; } diff --git a/MixLib/Devices.cs b/MixLib/Devices.cs index f13d3ad..cf9d758 100644 --- a/MixLib/Devices.cs +++ b/MixLib/Devices.cs @@ -39,7 +39,7 @@ public Devices() foreach (MixDevice device in mDevices) { - device.ReportingEvent += device_Reporting; + device.ReportingEvent += Device_Reporting; } } @@ -51,7 +51,7 @@ public Devices() protected virtual void OnDeviceReportingEvent(DeviceReportingEventArgs args) => DeviceReportingEvent?.Invoke(this, args); - void device_Reporting(object sender, ReportingEventArgs args) => + void Device_Reporting(object sender, ReportingEventArgs args) => OnDeviceReportingEvent(new DeviceReportingEventArgs((MixDevice)sender, args.Severity, args.Message)); public void Reset() diff --git a/MixLib/Instruction/AddressTransferInstructions.cs b/MixLib/Instruction/AddressTransferInstructions.cs index 584ce27..b111d8e 100644 --- a/MixLib/Instruction/AddressTransferInstructions.cs +++ b/MixLib/Instruction/AddressTransferInstructions.cs @@ -14,9 +14,9 @@ public static class AddressTransferInstructions /// Method for performing DECx instructions /// public static bool Decrease(ModuleBase module, MixInstruction.Instance instance) => - doIncrease(module, instance, instance.MixInstruction.Opcode - opcodeBase, true); + DoIncrease(module, instance, instance.MixInstruction.Opcode - opcodeBase, true); - static bool doEnter(ModuleBase module, MixInstruction.Instance instance, int registerIndex, bool negateSign) + static bool DoEnter(ModuleBase module, MixInstruction.Instance instance, int registerIndex, bool negateSign) { var indexedAddress = module.Registers.GetIndexedAddress(instance.AddressValue, instance.Index); Register register = module.Registers[registerIndex]; @@ -36,7 +36,7 @@ static bool doEnter(ModuleBase module, MixInstruction.Instance instance, int reg return true; } - static bool doIncrease(ModuleBase module, MixInstruction.Instance instance, int registerIndex, bool negateSign) + static bool DoIncrease(ModuleBase module, MixInstruction.Instance instance, int registerIndex, bool negateSign) { var indexedAddress = module.Registers.GetIndexedAddress(instance.AddressValue, instance.Index); Register register = module.Registers[registerIndex]; @@ -76,18 +76,18 @@ static bool doIncrease(ModuleBase module, MixInstruction.Instance instance, int /// Method for performing ENTx instructions /// public static bool Enter(ModuleBase module, MixInstruction.Instance instance) => - doEnter(module, instance, instance.MixInstruction.Opcode - opcodeBase, false); + DoEnter(module, instance, instance.MixInstruction.Opcode - opcodeBase, false); /// /// Method for performing ENNx instructions /// public static bool EnterNegative(ModuleBase module, MixInstruction.Instance instance) => - doEnter(module, instance, instance.MixInstruction.Opcode - opcodeBase, true); + DoEnter(module, instance, instance.MixInstruction.Opcode - opcodeBase, true); /// /// Method for performing INCx instructions /// public static bool Increase(ModuleBase module, MixInstruction.Instance instance) => - doIncrease(module, instance, instance.MixInstruction.Opcode - opcodeBase, false); + DoIncrease(module, instance, instance.MixInstruction.Opcode - opcodeBase, false); } } diff --git a/MixLib/Instruction/ArithmaticInstructions.cs b/MixLib/Instruction/ArithmaticInstructions.cs index be30be7..1c2bf06 100644 --- a/MixLib/Instruction/ArithmaticInstructions.cs +++ b/MixLib/Instruction/ArithmaticInstructions.cs @@ -18,7 +18,7 @@ public static bool AddSubstract(ModuleBase module, MixInstruction.Instance insta var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index); if (indexedAddress == int.MinValue) return false; - Register rA = module.Registers.rA; + Register rA = module.Registers.RA; long rALongValue = rA.LongValue; long memoryWordValue = WordField.LoadFromFullWord(instance.FieldSpec, module.Memory[indexedAddress]).LongValue; @@ -61,8 +61,8 @@ public static bool Divide(ModuleBase module, MixInstruction.Instance instance) return true; } - Register rA = module.Registers.rA; - Register rX = module.Registers.rX; + Register rA = module.Registers.RA; + Register rX = module.Registers.RX; long rAValue = rA.LongValue; long rXValue = rX.LongValue; @@ -95,8 +95,8 @@ public static bool Multiply(ModuleBase module, MixInstruction.Instance instance) var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index); if (indexedAddress == int.MinValue) return false; - Register rA = module.Registers.rA; - Register rX = module.Registers.rX; + Register rA = module.Registers.RA; + Register rX = module.Registers.RX; long rAValue = rA.LongValue; long memoryWordValue = WordField.LoadFromFullWord(instance.FieldSpec, module.Memory[indexedAddress]).LongValue; diff --git a/MixLib/Instruction/FloatingPointInstructions.cs b/MixLib/Instruction/FloatingPointInstructions.cs index cf9769d..0e2b3a3 100644 --- a/MixLib/Instruction/FloatingPointInstructions.cs +++ b/MixLib/Instruction/FloatingPointInstructions.cs @@ -14,7 +14,7 @@ public static class FloatingPointInstructions const int fcmpOpcode = 56; public const string FcmpMnemonic = "FCMP"; - static executionStatus mExecutionStatus; + static ExecutionStatus mExecutionStatus; static int[] mPrenormOpcodes = { faddOpcode, fsubOpcode, fmulOpcode, fdivOpcode }; public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance instance) @@ -41,12 +41,12 @@ public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance in if (mExecutionStatus == null) { - mExecutionStatus = new executionStatus(module.Mode, module.ProgramCounter, instance.Instruction.Mnemonic); + mExecutionStatus = new ExecutionStatus(module.Mode, module.ProgramCounter, instance.Instruction.Mnemonic); } - if (mExecutionStatus.CurrentStep == executionStatus.Step.Initialize) + if (mExecutionStatus.CurrentStep == ExecutionStatus.Step.Initialize) { - mExecutionStatus.rAValue = module.Registers.rA.FullWordValue; + mExecutionStatus.RAValue = module.Registers.RA.FullWordValue; bool prenormInstruction = Array.IndexOf(mPrenormOpcodes, instance.MixInstruction.Opcode) != -1; bool fcmpInstruction = !prenormInstruction && instance.MixInstruction.Opcode == fcmpOpcode; @@ -77,9 +77,9 @@ public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance in if (prenormInstruction) { - mExecutionStatus.CurrentStep = executionStatus.Step.PrenormRA; + mExecutionStatus.CurrentStep = ExecutionStatus.Step.PrenormRA; - if (floatingPointModule.PreparePrenorm(mExecutionStatus.rAValue)) + if (floatingPointModule.PreparePrenorm(mExecutionStatus.RAValue)) { module.ReportBreakpointReached(); return false; @@ -87,11 +87,11 @@ public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance in } else { - mExecutionStatus.CurrentStep = executionStatus.Step.ExecuteInstruction; + mExecutionStatus.CurrentStep = ExecutionStatus.Step.ExecuteInstruction; if (fcmpInstruction - ? floatingPointModule.PrepareCall(mExecutionStatus.Mnemonic, mExecutionStatus.rAValue, mExecutionStatus.ParameterValue) - : floatingPointModule.PrepareCall(mExecutionStatus.Mnemonic, mExecutionStatus.rAValue)) + ? floatingPointModule.PrepareCall(mExecutionStatus.Mnemonic, mExecutionStatus.RAValue, mExecutionStatus.ParameterValue) + : floatingPointModule.PrepareCall(mExecutionStatus.Mnemonic, mExecutionStatus.RAValue)) { module.ReportBreakpointReached(); return false; @@ -107,9 +107,9 @@ public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance in switch (mExecutionStatus.CurrentStep) { - case executionStatus.Step.PrenormRA: - mExecutionStatus.rAValue = floatingPointModule.Registers.rA.FullWordValue; - mExecutionStatus.CurrentStep = executionStatus.Step.PrenormParameter; + case ExecutionStatus.Step.PrenormRA: + mExecutionStatus.RAValue = floatingPointModule.Registers.RA.FullWordValue; + mExecutionStatus.CurrentStep = ExecutionStatus.Step.PrenormParameter; if (floatingPointModule.PreparePrenorm(mExecutionStatus.ParameterValue)) { @@ -119,11 +119,11 @@ public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance in break; - case executionStatus.Step.PrenormParameter: - mExecutionStatus.ParameterValue = floatingPointModule.Registers.rA.FullWordValue; - mExecutionStatus.CurrentStep = executionStatus.Step.ExecuteInstruction; + case ExecutionStatus.Step.PrenormParameter: + mExecutionStatus.ParameterValue = floatingPointModule.Registers.RA.FullWordValue; + mExecutionStatus.CurrentStep = ExecutionStatus.Step.ExecuteInstruction; - if (floatingPointModule.PrepareCall(mExecutionStatus.Mnemonic, mExecutionStatus.rAValue, mExecutionStatus.ParameterValue)) + if (floatingPointModule.PrepareCall(mExecutionStatus.Mnemonic, mExecutionStatus.RAValue, mExecutionStatus.ParameterValue)) { module.ReportBreakpointReached(); return false; @@ -131,8 +131,8 @@ public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance in break; - case executionStatus.Step.ExecuteInstruction: - mExecutionStatus.rAValue = floatingPointModule.Registers.rA.FullWordValue; + case ExecutionStatus.Step.ExecuteInstruction: + mExecutionStatus.RAValue = floatingPointModule.Registers.RA.FullWordValue; Registers.CompValues comparatorValue = floatingPointModule.Registers.CompareIndicator; module.Registers.LoadFromMemory(floatingPointModule.FullMemory, ModuleSettings.FloatingPointMemoryWordCount); module.Registers.OverflowIndicator = mExecutionStatus.OverflowDetected; @@ -143,8 +143,8 @@ public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance in } else { - module.Registers.rA.Magnitude = mExecutionStatus.rAValue.Magnitude; - module.Registers.rA.Sign = mExecutionStatus.rAValue.Sign; + module.Registers.RA.Magnitude = mExecutionStatus.RAValue.Magnitude; + module.Registers.RA.Sign = mExecutionStatus.RAValue.Sign; } module.Mode = ModuleBase.RunMode.Normal; @@ -174,17 +174,17 @@ public static bool DoFloatingPoint(ModuleBase module, MixInstruction.Instance in return false; } - class executionStatus + class ExecutionStatus { public ModuleBase.RunMode Mode { get; private set; } public string Mnemonic { get; private set; } public int ProgramCounter { get; private set; } public Step CurrentStep { get; set; } public IFullWord ParameterValue { get; set; } - public IFullWord rAValue { get; set; } + public IFullWord RAValue { get; set; } public bool OverflowDetected { get; set; } - public executionStatus(ModuleBase.RunMode mode, int programCounter, string mnemonic) + public ExecutionStatus(ModuleBase.RunMode mode, int programCounter, string mnemonic) { Mode = mode; ProgramCounter = programCounter; diff --git a/MixLib/Instruction/IOInstructions.cs b/MixLib/Instruction/IOInstructions.cs index 0ece092..686a2c1 100644 --- a/MixLib/Instruction/IOInstructions.cs +++ b/MixLib/Instruction/IOInstructions.cs @@ -36,7 +36,7 @@ public static bool Input(ModuleBase module, MixInstruction.Instance instance) if (device.Busy) return false; - var field = WordField.LoadFromRegister(new FieldSpec(4, 5), module.Registers.rX); + var field = WordField.LoadFromRegister(new FieldSpec(4, 5), module.Registers.RX); device.StartInput(module.Memory, mValue, (int)field.LongValue, module is Mix && ((Mix)module).Mode == ModuleBase.RunMode.Control ? new InterruptQueueCallback(((Mix)module).QueueInterrupt) : null); return true; @@ -82,7 +82,7 @@ public static bool IOControl(ModuleBase module, MixInstruction.Instance instance if (device.Busy) return false; - var field = WordField.LoadFromRegister(new FieldSpec(4, 5), module.Registers.rX); + var field = WordField.LoadFromRegister(new FieldSpec(4, 5), module.Registers.RX); device.StartIoc(indexedAddress, (int)field.LongValue, module is Mix && ((Mix)module).Mode == ModuleBase.RunMode.Control ? new InterruptQueueCallback(((Mix)module).QueueInterrupt) : null); return true; @@ -163,7 +163,7 @@ public static bool Output(ModuleBase module, MixInstruction.Instance instance) if (device.Busy) return false; - var field = WordField.LoadFromRegister(new FieldSpec(4, 5), module.Registers.rX); + var field = WordField.LoadFromRegister(new FieldSpec(4, 5), module.Registers.RX); device.StartOutput(module.Memory, mValue, (int)field.LongValue, module is Mix && ((Mix)module).Mode == ModuleBase.RunMode.Control ? new InterruptQueueCallback(((Mix)module).QueueInterrupt) : null); return true; diff --git a/MixLib/Instruction/InstructionText.cs b/MixLib/Instruction/InstructionText.cs index c4c99a6..fa21654 100644 --- a/MixLib/Instruction/InstructionText.cs +++ b/MixLib/Instruction/InstructionText.cs @@ -17,14 +17,17 @@ public InstructionText(MixInstruction.Instance instance) public string Mnemonic => mInstance.MixInstruction.Mnemonic; - string getFieldText() + string FieldText { - FieldSpec fieldSpec = mInstance.FieldSpec; - if (mInstance.MixInstruction.MetaFieldSpec.FieldIsRange && fieldSpec.IsValid) + get { - return (fieldSpec.LowBound + ":" + fieldSpec.HighBound); + FieldSpec fieldSpec = mInstance.FieldSpec; + if (mInstance.MixInstruction.MetaFieldSpec.FieldIsRange && fieldSpec.IsValid) + { + return (fieldSpec.LowBound + ":" + fieldSpec.HighBound); + } + return fieldSpec.MixByteValue.ByteValue.ToString(); } - return fieldSpec.MixByteValue.ByteValue.ToString(); } public string Address @@ -51,12 +54,12 @@ public string Field case MetaFieldSpec.Presences.Optional: if (mInstance.FieldSpec != mInstance.MixInstruction.MetaFieldSpec.DefaultFieldSpec) { - str = getFieldText(); + str = FieldText; } break; case MetaFieldSpec.Presences.Mandatory: - str = getFieldText(); + str = FieldText; break; } diff --git a/MixLib/Instruction/JumpInstructions.cs b/MixLib/Instruction/JumpInstructions.cs index ff1bce3..6c4036a 100644 --- a/MixLib/Instruction/JumpInstructions.cs +++ b/MixLib/Instruction/JumpInstructions.cs @@ -29,11 +29,11 @@ public static class JumpInstructions const byte regJumpEvenField = 6; const byte regJumpOddField = 7; - static void doJump(ModuleBase module, int indexedAddress, bool saveJ) + static void DoJump(ModuleBase module, int indexedAddress, bool saveJ) { if (!saveJ) { - module.Registers.rJ.LongValue = module.ProgramCounter + 1; + module.Registers.RJ.LongValue = module.ProgramCounter + 1; } module.ProgramCounter = indexedAddress; @@ -44,7 +44,7 @@ static void doJump(ModuleBase module, int indexedAddress, bool saveJ) /// public static void Jump(ModuleBase module, int indexedAddress) { - doJump(module, indexedAddress, false); + DoJump(module, indexedAddress, false); } /// @@ -62,7 +62,7 @@ public static bool NonRegJump(ModuleBase module, MixInstruction.Instance instanc return false; case jsjField: - doJump(module, indexedAddress, true); + DoJump(module, indexedAddress, true); return false; case jovField: diff --git a/MixLib/Instruction/LoadInstructions.cs b/MixLib/Instruction/LoadInstructions.cs index 6aa9806..a8e55c2 100644 --- a/MixLib/Instruction/LoadInstructions.cs +++ b/MixLib/Instruction/LoadInstructions.cs @@ -11,7 +11,7 @@ public static class LoadInstructions const byte loadOpcodeBase = 8; const byte loadNegOpcodeBase = 16; - static bool doLoad(ModuleBase module, MixInstruction.Instance instance, int registerIndex, bool negateSign) + static bool DoLoad(ModuleBase module, MixInstruction.Instance instance, int registerIndex, bool negateSign) { var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index); if (indexedAddress == int.MinValue) return false; @@ -32,7 +32,7 @@ public static bool Load(ModuleBase module, MixInstruction.Instance instance) { int registerIndex = instance.MixInstruction.Opcode - loadOpcodeBase; - return doLoad(module, instance, registerIndex, false); + return DoLoad(module, instance, registerIndex, false); } /// @@ -42,7 +42,7 @@ public static bool LoadNegative(ModuleBase module, MixInstruction.Instance insta { int registerIndex = instance.MixInstruction.Opcode - loadNegOpcodeBase; - return doLoad(module, instance, registerIndex, true); + return DoLoad(module, instance, registerIndex, true); } } } diff --git a/MixLib/Instruction/MiscInstructions.cs b/MixLib/Instruction/MiscInstructions.cs index 2dd307b..51a8c0c 100644 --- a/MixLib/Instruction/MiscInstructions.cs +++ b/MixLib/Instruction/MiscInstructions.cs @@ -23,9 +23,9 @@ public static class MiscInstructions /// public static bool ConvertToChar(ModuleBase module, MixInstruction.Instance instance) { - Register rA = module.Registers.rA; + Register rA = module.Registers.RA; long magnitudeLongValue = rA.MagnitudeLongValue; - Register rX = module.Registers.rX; + Register rX = module.Registers.RX; for (int i = rX.ByteCount - 1; i >= 0; i--) { @@ -48,7 +48,7 @@ public static bool ConvertToChar(ModuleBase module, MixInstruction.Instance inst public static bool ConvertToNumeric(ModuleBase module, MixInstruction.Instance instance) { decimal num = 0M; - Register rA = module.Registers.rA; + Register rA = module.Registers.RA; for (int i = 0; i < rA.ByteCount; i++) { @@ -56,7 +56,7 @@ public static bool ConvertToNumeric(ModuleBase module, MixInstruction.Instance i num += rA[i] % 10; } - Register rX = module.Registers.rX; + Register rX = module.Registers.RX; for (int j = 0; j < rX.ByteCount; j++) { @@ -103,12 +103,11 @@ public static bool Halt(ModuleBase module, MixInstruction.Instance instance) /// public static bool Move(ModuleBase module, MixInstruction.Instance instance) { - moveStatus status; - mMoveStatuses.TryGetValue(module.ModuleName, out status); + mMoveStatuses.TryGetValue(module.ModuleName, out moveStatus status); - // if we have a move status, check if it applies to this instruction - if (status != null && status.ProgramCounter != module.ProgramCounter) + // if we have a move status, check if it applies to this instruction + if (status != null && status.ProgramCounter != module.ProgramCounter) { status = null; mMoveStatuses.Remove(module.ModuleName); @@ -154,7 +153,7 @@ public static bool Move(ModuleBase module, MixInstruction.Instance instance) // ... during the other, the value of rI1 is increased case moveStatus.WordStates.Moved: - Register rI1 = module.Registers.rI1; + Register rI1 = module.Registers.RI1; rI1.LongValue++; status.NextWord(); diff --git a/MixLib/Instruction/MixInstruction.cs b/MixLib/Instruction/MixInstruction.cs index 22e4108..1e06c97 100644 --- a/MixLib/Instruction/MixInstruction.cs +++ b/MixLib/Instruction/MixInstruction.cs @@ -49,7 +49,6 @@ public MixInstruction(byte opcode, string mnemonic, MetaFieldSpec metaFieldSpec, MixInstruction(byte opcode, FieldSpec fieldSpec, MetaFieldSpec metaFieldSpec, string mnemonic, int tickCount, Executor executor, Validator validator) : base(mnemonic) { - if (executor == null) throw new ArgumentNullException(nameof(executor)); // if the MetaFieldSpec Presence is Forbidden then an instruction fieldspec must be specified. Likewise, if an instruction fieldspec is provided, the MetaFieldSpec Presence must be Forbidden. if ((fieldSpec == null && metaFieldSpec.Presence == Instruction.MetaFieldSpec.Presences.Forbidden) || (metaFieldSpec.Presence != Instruction.MetaFieldSpec.Presences.Forbidden && fieldSpec != null)) @@ -61,7 +60,7 @@ public MixInstruction(byte opcode, string mnemonic, MetaFieldSpec metaFieldSpec, FieldSpec = fieldSpec; MetaFieldSpec = metaFieldSpec; TickCount = tickCount; - mExecutor = executor; + mExecutor = executor ?? throw new ArgumentNullException(nameof(executor)); mValidator = validator; } @@ -90,9 +89,9 @@ public Instance(MixInstruction instruction, IFullWord instructionWord) InstructionWord = instructionWord; } - public int AddressValue => addressValue(InstructionWord); + public int AddressValue => AddressValueFromWord(InstructionWord); - public int AddressMagnitude => addressMagnitude(InstructionWord); + public int AddressMagnitude => AddressMagnitudeFromWord(InstructionWord); public Word.Signs AddressSign => InstructionWord.Sign; @@ -108,9 +107,9 @@ public Instance(MixInstruction instruction, IFullWord instructionWord) public override string ToString() => new InstructionText(this).InstanceText; - int addressMagnitude(IWord word) => (int)Word.BytesToLong(Word.Signs.Positive, new MixByte[] { word[0], word[1] }); + int AddressMagnitudeFromWord(IWord word) => (int)Word.BytesToLong(Word.Signs.Positive, new MixByte[] { word[0], word[1] }); - int addressValue(IWord word) => (int)Word.BytesToLong(word.Sign, new MixByte[] { word[0], word[1] }); + int AddressValueFromWord(IWord word) => (int)Word.BytesToLong(word.Sign, new MixByte[] { word[0], word[1] }); public bool Execute(ModuleBase module) { diff --git a/MixLib/Instruction/ShiftInstructions.cs b/MixLib/Instruction/ShiftInstructions.cs index 3227689..2b9dd37 100644 --- a/MixLib/Instruction/ShiftInstructions.cs +++ b/MixLib/Instruction/ShiftInstructions.cs @@ -29,14 +29,14 @@ public static bool ShiftA(ModuleBase module, MixInstruction.Instance instance) return false; } - Register rA = module.Registers.rA; + Register rA = module.Registers.RA; int shiftCount = indexedAddress % rA.ByteCount; if (shiftCount != 0) { switch (instance.MixInstruction.FieldSpec.MixByteValue.ByteValue) { case slaField: - shiftWordLeft(rA, shiftCount); + ShiftWordLeft(rA, shiftCount); for (int i = rA.ByteCount - shiftCount; i < rA.ByteCount; i++) { @@ -46,7 +46,7 @@ public static bool ShiftA(ModuleBase module, MixInstruction.Instance instance) break; case sraField: - shiftWordRight(rA, shiftCount); + ShiftWordRight(rA, shiftCount); for (int j = shiftCount - 1; j >= 0; j--) { @@ -71,8 +71,8 @@ public static bool ShiftAX(ModuleBase module, MixInstruction.Instance instance) return false; } - Register rA = module.Registers.rA; - Register rX = module.Registers.rX; + Register rA = module.Registers.RA; + Register rX = module.Registers.RX; int shiftCount = indexedAddress % (FullWordRegister.RegisterByteCount * 2); if (shiftCount == 0) return true; @@ -82,7 +82,7 @@ public static bool ShiftAX(ModuleBase module, MixInstruction.Instance instance) case slaxField: if (shiftCount < FullWordRegister.RegisterByteCount) { - shiftRegistersLeft((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); + ShiftRegistersLeft((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); } else { @@ -112,7 +112,7 @@ public static bool ShiftAX(ModuleBase module, MixInstruction.Instance instance) case sraxField: if (shiftCount < FullWordRegister.RegisterByteCount) { - shiftRegistersRight((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); + ShiftRegistersRight((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); } else { @@ -146,7 +146,7 @@ public static bool ShiftAX(ModuleBase module, MixInstruction.Instance instance) shiftedBytes[i] = rA[i]; } - shiftRegistersLeft((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); + ShiftRegistersLeft((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); for (int i = 0; i < shiftCount; i++) { @@ -196,7 +196,7 @@ public static bool ShiftAX(ModuleBase module, MixInstruction.Instance instance) shiftBytes[i] = rX[(rX.ByteCount - shiftCount) + i]; } - shiftRegistersRight((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); + ShiftRegistersRight((FullWordRegister)rA, (FullWordRegister)rX, shiftCount); for (int i = 0; i < shiftCount; i++) { @@ -251,8 +251,8 @@ public static bool ShiftAXBinary(ModuleBase module, MixInstruction.Instance inst return false; } - Register rA = module.Registers.rA; - Register rX = module.Registers.rX; + Register rA = module.Registers.RA; + Register rX = module.Registers.RX; int registerBitCount = FullWordRegister.RegisterByteCount * MixByte.BitCount; int shiftCount = indexedAddress % (registerBitCount * 2); @@ -280,31 +280,31 @@ public static bool ShiftAXBinary(ModuleBase module, MixInstruction.Instance inst return true; } - static void shiftRegistersLeft(FullWordRegister left, FullWordRegister right, int shiftCount) + static void ShiftRegistersLeft(FullWordRegister left, FullWordRegister right, int shiftCount) { - shiftWordLeft(left, shiftCount); + ShiftWordLeft(left, shiftCount); for (int i = 0; i < shiftCount; i++) { left[(FullWordRegister.RegisterByteCount - shiftCount) + i] = right[i]; } - shiftWordLeft(right, shiftCount); + ShiftWordLeft(right, shiftCount); } - static void shiftRegistersRight(FullWordRegister left, FullWordRegister right, int shiftCount) + static void ShiftRegistersRight(FullWordRegister left, FullWordRegister right, int shiftCount) { - shiftWordRight(right, shiftCount); + ShiftWordRight(right, shiftCount); for (int i = shiftCount - 1; i >= 0; i--) { right[i] = left[(FullWordRegister.RegisterByteCount - shiftCount) + i]; } - shiftWordRight(left, shiftCount); + ShiftWordRight(left, shiftCount); } - static void shiftWordLeft(Word word, int shiftCount) + static void ShiftWordLeft(Word word, int shiftCount) { for (int i = shiftCount; i < word.ByteCount; i++) { @@ -312,7 +312,7 @@ static void shiftWordLeft(Word word, int shiftCount) } } - static void shiftWordRight(Word word, int shiftCount) + static void ShiftWordRight(Word word, int shiftCount) { for (int i = (word.ByteCount - shiftCount) - 1; i >= 0; i--) { diff --git a/MixLib/Instruction/StoreInstructions.cs b/MixLib/Instruction/StoreInstructions.cs index 8f97539..780bb4d 100644 --- a/MixLib/Instruction/StoreInstructions.cs +++ b/MixLib/Instruction/StoreInstructions.cs @@ -23,7 +23,7 @@ public static bool StoreRegister(ModuleBase module, MixInstruction.Instance inst if (instance.MixInstruction.Opcode == storeJOpcode) { - sourceRegister = module.Registers.rJ; + sourceRegister = module.Registers.RJ; } else { diff --git a/MixLib/InstructionSet.cs b/MixLib/InstructionSet.cs index 20f83cb..046fb3d 100644 --- a/MixLib/InstructionSet.cs +++ b/MixLib/InstructionSet.cs @@ -24,239 +24,239 @@ public InstructionSet() MixInstruction.Executor executor = LoadInstructions.Load; MixInstruction.Validator validator = InstructionHelpers.ValidateIndexAndFieldSpec; - addInstruction("LDA", 8, fullWordMetaSpec, 2, executor, validator); - addInstruction("LD1", 9, indexMetaSpec, 2, executor, validator); - addInstruction("LD2", 10, indexMetaSpec, 2, executor, validator); - addInstruction("LD3", 11, indexMetaSpec, 2, executor, validator); - addInstruction("LD4", 12, indexMetaSpec, 2, executor, validator); - addInstruction("LD5", 13, indexMetaSpec, 2, executor, validator); - addInstruction("LD6", 14, indexMetaSpec, 2, executor, validator); - addInstruction("LDX", 15, fullWordMetaSpec, 2, executor, validator); + AddInstruction("LDA", 8, fullWordMetaSpec, 2, executor, validator); + AddInstruction("LD1", 9, indexMetaSpec, 2, executor, validator); + AddInstruction("LD2", 10, indexMetaSpec, 2, executor, validator); + AddInstruction("LD3", 11, indexMetaSpec, 2, executor, validator); + AddInstruction("LD4", 12, indexMetaSpec, 2, executor, validator); + AddInstruction("LD5", 13, indexMetaSpec, 2, executor, validator); + AddInstruction("LD6", 14, indexMetaSpec, 2, executor, validator); + AddInstruction("LDX", 15, fullWordMetaSpec, 2, executor, validator); executor = LoadInstructions.LoadNegative; - addInstruction("LDAN", 16, fullWordMetaSpec, 2, executor, validator); - addInstruction("LD1N", 17, indexMetaSpec, 2, executor, validator); - addInstruction("LD2N", 18, indexMetaSpec, 2, executor, validator); - addInstruction("LD3N", 19, indexMetaSpec, 2, executor, validator); - addInstruction("LD4N", 20, indexMetaSpec, 2, executor, validator); - addInstruction("LD5N", 21, indexMetaSpec, 2, executor, validator); - addInstruction("LD6N", 22, indexMetaSpec, 2, executor, validator); - addInstruction("LDXN", 23, fullWordMetaSpec, 2, executor, validator); + AddInstruction("LDAN", 16, fullWordMetaSpec, 2, executor, validator); + AddInstruction("LD1N", 17, indexMetaSpec, 2, executor, validator); + AddInstruction("LD2N", 18, indexMetaSpec, 2, executor, validator); + AddInstruction("LD3N", 19, indexMetaSpec, 2, executor, validator); + AddInstruction("LD4N", 20, indexMetaSpec, 2, executor, validator); + AddInstruction("LD5N", 21, indexMetaSpec, 2, executor, validator); + AddInstruction("LD6N", 22, indexMetaSpec, 2, executor, validator); + AddInstruction("LDXN", 23, fullWordMetaSpec, 2, executor, validator); executor = StoreInstructions.StoreRegister; - addInstruction("STA", 24, fullWordMetaSpec, 2, executor, validator); - addInstruction("ST1", 25, indexMetaSpec, 2, executor, validator); - addInstruction("ST2", 26, indexMetaSpec, 2, executor, validator); - addInstruction("ST3", 27, indexMetaSpec, 2, executor, validator); - addInstruction("ST4", 28, indexMetaSpec, 2, executor, validator); - addInstruction("ST5", 29, indexMetaSpec, 2, executor, validator); - addInstruction("ST6", 30, indexMetaSpec, 2, executor, validator); - addInstruction("STX", 31, fullWordMetaSpec, 2, executor, validator); - addInstruction("STJ", 32, new MetaFieldSpec(true, AddressRegister.DefaultFieldSpec), 2, executor, validator); + AddInstruction("STA", 24, fullWordMetaSpec, 2, executor, validator); + AddInstruction("ST1", 25, indexMetaSpec, 2, executor, validator); + AddInstruction("ST2", 26, indexMetaSpec, 2, executor, validator); + AddInstruction("ST3", 27, indexMetaSpec, 2, executor, validator); + AddInstruction("ST4", 28, indexMetaSpec, 2, executor, validator); + AddInstruction("ST5", 29, indexMetaSpec, 2, executor, validator); + AddInstruction("ST6", 30, indexMetaSpec, 2, executor, validator); + AddInstruction("STX", 31, fullWordMetaSpec, 2, executor, validator); + AddInstruction("STJ", 32, new MetaFieldSpec(true, AddressRegister.DefaultFieldSpec), 2, executor, validator); executor = StoreInstructions.StoreZero; - addInstruction("STZ", 33, new MetaFieldSpec(true, Memory.DefaultFieldSpec), 2, executor, validator); + AddInstruction("STZ", 33, new MetaFieldSpec(true, Memory.DefaultFieldSpec), 2, executor, validator); executor = ArithmaticInstructions.AddSubstract; - addInstruction("ADD", 1, fullWordMetaSpec, 2, executor, validator); - addInstruction("SUB", 2, fullWordMetaSpec, 2, executor, validator); + AddInstruction("ADD", 1, fullWordMetaSpec, 2, executor, validator); + AddInstruction("SUB", 2, fullWordMetaSpec, 2, executor, validator); executor = ArithmaticInstructions.Multiply; - addInstruction("MUL", 3, fullWordMetaSpec, 10, executor, validator); + AddInstruction("MUL", 3, fullWordMetaSpec, 10, executor, validator); executor = ArithmaticInstructions.Divide; - addInstruction("DIV", 4, fullWordMetaSpec, 12, executor, validator); + AddInstruction("DIV", 4, fullWordMetaSpec, 12, executor, validator); executor = ComparisonInstructions.Compare; - addInstruction("CMPA", 56, fullWordMetaSpec, 2, executor, validator); - addInstruction("CMP1", 57, indexMetaSpec, 2, executor, validator); - addInstruction("CMP2", 58, indexMetaSpec, 2, executor, validator); - addInstruction("CMP3", 59, indexMetaSpec, 2, executor, validator); - addInstruction("CMP4", 60, indexMetaSpec, 2, executor, validator); - addInstruction("CMP5", 61, indexMetaSpec, 2, executor, validator); - addInstruction("CMP6", 62, indexMetaSpec, 2, executor, validator); - addInstruction("CMPX", 63, fullWordMetaSpec, 2, executor, validator); + AddInstruction("CMPA", 56, fullWordMetaSpec, 2, executor, validator); + AddInstruction("CMP1", 57, indexMetaSpec, 2, executor, validator); + AddInstruction("CMP2", 58, indexMetaSpec, 2, executor, validator); + AddInstruction("CMP3", 59, indexMetaSpec, 2, executor, validator); + AddInstruction("CMP4", 60, indexMetaSpec, 2, executor, validator); + AddInstruction("CMP5", 61, indexMetaSpec, 2, executor, validator); + AddInstruction("CMP6", 62, indexMetaSpec, 2, executor, validator); + AddInstruction("CMPX", 63, fullWordMetaSpec, 2, executor, validator); executor = AddressTransferInstructions.Increase; validator = InstructionHelpers.ValidateIndex; - addInstruction("INCA", 48, rangeSpecs[0], 1, executor, validator); - addInstruction("INC1", 49, rangeSpecs[0], 1, executor, validator); - addInstruction("INC2", 50, rangeSpecs[0], 1, executor, validator); - addInstruction("INC3", 51, rangeSpecs[0], 1, executor, validator); - addInstruction("INC4", 52, rangeSpecs[0], 1, executor, validator); - addInstruction("INC5", 53, rangeSpecs[0], 1, executor, validator); - addInstruction("INC6", 54, rangeSpecs[0], 1, executor, validator); - addInstruction("INCX", 55, rangeSpecs[0], 1, executor, validator); + AddInstruction("INCA", 48, rangeSpecs[0], 1, executor, validator); + AddInstruction("INC1", 49, rangeSpecs[0], 1, executor, validator); + AddInstruction("INC2", 50, rangeSpecs[0], 1, executor, validator); + AddInstruction("INC3", 51, rangeSpecs[0], 1, executor, validator); + AddInstruction("INC4", 52, rangeSpecs[0], 1, executor, validator); + AddInstruction("INC5", 53, rangeSpecs[0], 1, executor, validator); + AddInstruction("INC6", 54, rangeSpecs[0], 1, executor, validator); + AddInstruction("INCX", 55, rangeSpecs[0], 1, executor, validator); executor = AddressTransferInstructions.Decrease; - addInstruction("DECA", 48, rangeSpecs[1], 1, executor, validator); - addInstruction("DEC1", 49, rangeSpecs[1], 1, executor, validator); - addInstruction("DEC2", 50, rangeSpecs[1], 1, executor, validator); - addInstruction("DEC3", 51, rangeSpecs[1], 1, executor, validator); - addInstruction("DEC4", 52, rangeSpecs[1], 1, executor, validator); - addInstruction("DEC5", 53, rangeSpecs[1], 1, executor, validator); - addInstruction("DEC6", 54, rangeSpecs[1], 1, executor, validator); - addInstruction("DECX", 55, rangeSpecs[1], 1, executor, validator); + AddInstruction("DECA", 48, rangeSpecs[1], 1, executor, validator); + AddInstruction("DEC1", 49, rangeSpecs[1], 1, executor, validator); + AddInstruction("DEC2", 50, rangeSpecs[1], 1, executor, validator); + AddInstruction("DEC3", 51, rangeSpecs[1], 1, executor, validator); + AddInstruction("DEC4", 52, rangeSpecs[1], 1, executor, validator); + AddInstruction("DEC5", 53, rangeSpecs[1], 1, executor, validator); + AddInstruction("DEC6", 54, rangeSpecs[1], 1, executor, validator); + AddInstruction("DECX", 55, rangeSpecs[1], 1, executor, validator); executor = AddressTransferInstructions.Enter; - addInstruction("ENTA", 48, rangeSpecs[2], 1, executor, validator); - addInstruction("ENT1", 49, rangeSpecs[2], 1, executor, validator); - addInstruction("ENT2", 50, rangeSpecs[2], 1, executor, validator); - addInstruction("ENT3", 51, rangeSpecs[2], 1, executor, validator); - addInstruction("ENT4", 52, rangeSpecs[2], 1, executor, validator); - addInstruction("ENT5", 53, rangeSpecs[2], 1, executor, validator); - addInstruction("ENT6", 54, rangeSpecs[2], 1, executor, validator); - addInstruction("ENTX", 55, rangeSpecs[2], 1, executor, validator); + AddInstruction("ENTA", 48, rangeSpecs[2], 1, executor, validator); + AddInstruction("ENT1", 49, rangeSpecs[2], 1, executor, validator); + AddInstruction("ENT2", 50, rangeSpecs[2], 1, executor, validator); + AddInstruction("ENT3", 51, rangeSpecs[2], 1, executor, validator); + AddInstruction("ENT4", 52, rangeSpecs[2], 1, executor, validator); + AddInstruction("ENT5", 53, rangeSpecs[2], 1, executor, validator); + AddInstruction("ENT6", 54, rangeSpecs[2], 1, executor, validator); + AddInstruction("ENTX", 55, rangeSpecs[2], 1, executor, validator); executor = AddressTransferInstructions.EnterNegative; - addInstruction("ENNA", 48, rangeSpecs[3], 1, executor, validator); - addInstruction("ENN1", 49, rangeSpecs[3], 1, executor, validator); - addInstruction("ENN2", 50, rangeSpecs[3], 1, executor, validator); - addInstruction("ENN3", 51, rangeSpecs[3], 1, executor, validator); - addInstruction("ENN4", 52, rangeSpecs[3], 1, executor, validator); - addInstruction("ENN5", 53, rangeSpecs[3], 1, executor, validator); - addInstruction("ENN6", 54, rangeSpecs[3], 1, executor, validator); - addInstruction("ENNX", 55, rangeSpecs[3], 1, executor, validator); + AddInstruction("ENNA", 48, rangeSpecs[3], 1, executor, validator); + AddInstruction("ENN1", 49, rangeSpecs[3], 1, executor, validator); + AddInstruction("ENN2", 50, rangeSpecs[3], 1, executor, validator); + AddInstruction("ENN3", 51, rangeSpecs[3], 1, executor, validator); + AddInstruction("ENN4", 52, rangeSpecs[3], 1, executor, validator); + AddInstruction("ENN5", 53, rangeSpecs[3], 1, executor, validator); + AddInstruction("ENN6", 54, rangeSpecs[3], 1, executor, validator); + AddInstruction("ENNX", 55, rangeSpecs[3], 1, executor, validator); executor = JumpInstructions.NonRegJump; - addInstruction("JMP", 39, rangeSpecs[0], 1, executor, validator); - addInstruction("JSJ", 39, rangeSpecs[1], 1, executor, validator); - addInstruction("JOV", 39, rangeSpecs[2], 1, executor, validator); - addInstruction("JNOV", 39, rangeSpecs[3], 1, executor, validator); - addInstruction("JL", 39, rangeSpecs[4], 1, executor, validator); - addInstruction("JE", 39, rangeSpecs[5], 1, executor, validator); - addInstruction("JG", 39, rangeSpecs[6], 1, executor, validator); - addInstruction("JGE", 39, rangeSpecs[7], 1, executor, validator); - addInstruction("JNE", 39, new FieldSpec(8), 1, executor, validator); - addInstruction("JLE", 39, new FieldSpec(9), 1, executor, validator); + AddInstruction("JMP", 39, rangeSpecs[0], 1, executor, validator); + AddInstruction("JSJ", 39, rangeSpecs[1], 1, executor, validator); + AddInstruction("JOV", 39, rangeSpecs[2], 1, executor, validator); + AddInstruction("JNOV", 39, rangeSpecs[3], 1, executor, validator); + AddInstruction("JL", 39, rangeSpecs[4], 1, executor, validator); + AddInstruction("JE", 39, rangeSpecs[5], 1, executor, validator); + AddInstruction("JG", 39, rangeSpecs[6], 1, executor, validator); + AddInstruction("JGE", 39, rangeSpecs[7], 1, executor, validator); + AddInstruction("JNE", 39, new FieldSpec(8), 1, executor, validator); + AddInstruction("JLE", 39, new FieldSpec(9), 1, executor, validator); executor = JumpInstructions.RegJump; - addInstruction("JAN", 40, rangeSpecs[0], 1, executor, validator); - addInstruction("JAZ", 40, rangeSpecs[1], 1, executor, validator); - addInstruction("JAP", 40, rangeSpecs[2], 1, executor, validator); - addInstruction("JANN", 40, rangeSpecs[3], 1, executor, validator); - addInstruction("JANZ", 40, rangeSpecs[4], 1, executor, validator); - addInstruction("JANP", 40, rangeSpecs[5], 1, executor, validator); - addInstruction("JAE", 40, rangeSpecs[6], 1, executor, validator); - addInstruction("JAO", 40, rangeSpecs[7], 1, executor, validator); - - addInstruction("J1N", 41, rangeSpecs[0], 1, executor, validator); - addInstruction("J1Z", 41, rangeSpecs[1], 1, executor, validator); - addInstruction("J1P", 41, rangeSpecs[2], 1, executor, validator); - addInstruction("J1NN", 41, rangeSpecs[3], 1, executor, validator); - addInstruction("J1NZ", 41, rangeSpecs[4], 1, executor, validator); - addInstruction("J1NP", 41, rangeSpecs[5], 1, executor, validator); - - addInstruction("J2N", 42, rangeSpecs[0], 1, executor, validator); - addInstruction("J2Z", 42, rangeSpecs[1], 1, executor, validator); - addInstruction("J2P", 42, rangeSpecs[2], 1, executor, validator); - addInstruction("J2NN", 42, rangeSpecs[3], 1, executor, validator); - addInstruction("J2NZ", 42, rangeSpecs[4], 1, executor, validator); - addInstruction("J2NP", 42, rangeSpecs[5], 1, executor, validator); - - addInstruction("J3N", 43, rangeSpecs[0], 1, executor, validator); - addInstruction("J3Z", 43, rangeSpecs[1], 1, executor, validator); - addInstruction("J3P", 43, rangeSpecs[2], 1, executor, validator); - addInstruction("J3NN", 43, rangeSpecs[3], 1, executor, validator); - addInstruction("J3NZ", 43, rangeSpecs[4], 1, executor, validator); - addInstruction("J3NP", 43, rangeSpecs[5], 1, executor, validator); - - addInstruction("J4N", 44, rangeSpecs[0], 1, executor, validator); - addInstruction("J4Z", 44, rangeSpecs[1], 1, executor, validator); - addInstruction("J4P", 44, rangeSpecs[2], 1, executor, validator); - addInstruction("J4NN", 44, rangeSpecs[3], 1, executor, validator); - addInstruction("J4NZ", 44, rangeSpecs[4], 1, executor, validator); - addInstruction("J4NP", 44, rangeSpecs[5], 1, executor, validator); - - addInstruction("J5N", 45, rangeSpecs[0], 1, executor, validator); - addInstruction("J5Z", 45, rangeSpecs[1], 1, executor, validator); - addInstruction("J5P", 45, rangeSpecs[2], 1, executor, validator); - addInstruction("J5NN", 45, rangeSpecs[3], 1, executor, validator); - addInstruction("J5NZ", 45, rangeSpecs[4], 1, executor, validator); - addInstruction("J5NP", 45, rangeSpecs[5], 1, executor, validator); - - addInstruction("J6N", 46, rangeSpecs[0], 1, executor, validator); - addInstruction("J6Z", 46, rangeSpecs[1], 1, executor, validator); - addInstruction("J6P", 46, rangeSpecs[2], 1, executor, validator); - addInstruction("J6NN", 46, rangeSpecs[3], 1, executor, validator); - addInstruction("J6NZ", 46, rangeSpecs[4], 1, executor, validator); - addInstruction("J6NP", 46, rangeSpecs[5], 1, executor, validator); - - addInstruction("JXN", 47, rangeSpecs[0], 1, executor, validator); - addInstruction("JXZ", 47, rangeSpecs[1], 1, executor, validator); - addInstruction("JXP", 47, rangeSpecs[2], 1, executor, validator); - addInstruction("JXNN", 47, rangeSpecs[3], 1, executor, validator); - addInstruction("JXNZ", 47, rangeSpecs[4], 1, executor, validator); - addInstruction("JXNP", 47, rangeSpecs[5], 1, executor, validator); - addInstruction("JXE", 47, rangeSpecs[6], 1, executor, validator); - addInstruction("JXO", 47, rangeSpecs[7], 1, executor, validator); + AddInstruction("JAN", 40, rangeSpecs[0], 1, executor, validator); + AddInstruction("JAZ", 40, rangeSpecs[1], 1, executor, validator); + AddInstruction("JAP", 40, rangeSpecs[2], 1, executor, validator); + AddInstruction("JANN", 40, rangeSpecs[3], 1, executor, validator); + AddInstruction("JANZ", 40, rangeSpecs[4], 1, executor, validator); + AddInstruction("JANP", 40, rangeSpecs[5], 1, executor, validator); + AddInstruction("JAE", 40, rangeSpecs[6], 1, executor, validator); + AddInstruction("JAO", 40, rangeSpecs[7], 1, executor, validator); + + AddInstruction("J1N", 41, rangeSpecs[0], 1, executor, validator); + AddInstruction("J1Z", 41, rangeSpecs[1], 1, executor, validator); + AddInstruction("J1P", 41, rangeSpecs[2], 1, executor, validator); + AddInstruction("J1NN", 41, rangeSpecs[3], 1, executor, validator); + AddInstruction("J1NZ", 41, rangeSpecs[4], 1, executor, validator); + AddInstruction("J1NP", 41, rangeSpecs[5], 1, executor, validator); + + AddInstruction("J2N", 42, rangeSpecs[0], 1, executor, validator); + AddInstruction("J2Z", 42, rangeSpecs[1], 1, executor, validator); + AddInstruction("J2P", 42, rangeSpecs[2], 1, executor, validator); + AddInstruction("J2NN", 42, rangeSpecs[3], 1, executor, validator); + AddInstruction("J2NZ", 42, rangeSpecs[4], 1, executor, validator); + AddInstruction("J2NP", 42, rangeSpecs[5], 1, executor, validator); + + AddInstruction("J3N", 43, rangeSpecs[0], 1, executor, validator); + AddInstruction("J3Z", 43, rangeSpecs[1], 1, executor, validator); + AddInstruction("J3P", 43, rangeSpecs[2], 1, executor, validator); + AddInstruction("J3NN", 43, rangeSpecs[3], 1, executor, validator); + AddInstruction("J3NZ", 43, rangeSpecs[4], 1, executor, validator); + AddInstruction("J3NP", 43, rangeSpecs[5], 1, executor, validator); + + AddInstruction("J4N", 44, rangeSpecs[0], 1, executor, validator); + AddInstruction("J4Z", 44, rangeSpecs[1], 1, executor, validator); + AddInstruction("J4P", 44, rangeSpecs[2], 1, executor, validator); + AddInstruction("J4NN", 44, rangeSpecs[3], 1, executor, validator); + AddInstruction("J4NZ", 44, rangeSpecs[4], 1, executor, validator); + AddInstruction("J4NP", 44, rangeSpecs[5], 1, executor, validator); + + AddInstruction("J5N", 45, rangeSpecs[0], 1, executor, validator); + AddInstruction("J5Z", 45, rangeSpecs[1], 1, executor, validator); + AddInstruction("J5P", 45, rangeSpecs[2], 1, executor, validator); + AddInstruction("J5NN", 45, rangeSpecs[3], 1, executor, validator); + AddInstruction("J5NZ", 45, rangeSpecs[4], 1, executor, validator); + AddInstruction("J5NP", 45, rangeSpecs[5], 1, executor, validator); + + AddInstruction("J6N", 46, rangeSpecs[0], 1, executor, validator); + AddInstruction("J6Z", 46, rangeSpecs[1], 1, executor, validator); + AddInstruction("J6P", 46, rangeSpecs[2], 1, executor, validator); + AddInstruction("J6NN", 46, rangeSpecs[3], 1, executor, validator); + AddInstruction("J6NZ", 46, rangeSpecs[4], 1, executor, validator); + AddInstruction("J6NP", 46, rangeSpecs[5], 1, executor, validator); + + AddInstruction("JXN", 47, rangeSpecs[0], 1, executor, validator); + AddInstruction("JXZ", 47, rangeSpecs[1], 1, executor, validator); + AddInstruction("JXP", 47, rangeSpecs[2], 1, executor, validator); + AddInstruction("JXNN", 47, rangeSpecs[3], 1, executor, validator); + AddInstruction("JXNZ", 47, rangeSpecs[4], 1, executor, validator); + AddInstruction("JXNP", 47, rangeSpecs[5], 1, executor, validator); + AddInstruction("JXE", 47, rangeSpecs[6], 1, executor, validator); + AddInstruction("JXO", 47, rangeSpecs[7], 1, executor, validator); executor = FloatingPointInstructions.DoFloatingPoint; - addInstruction("FADD", 1, rangeSpecs[6], 4, executor, validator); - addInstruction("FSUB", 2, rangeSpecs[6], 4, executor, validator); - addInstruction("FMUL", 3, rangeSpecs[6], 9, executor, validator); - addInstruction("FDIV", 4, rangeSpecs[6], 11, executor, validator); - addInstruction("FLOT", 5, rangeSpecs[6], 3, executor, validator); - addInstruction("FIX", 5, rangeSpecs[7], 3, executor, validator); - addInstruction(FloatingPointInstructions.FcmpMnemonic, 56, rangeSpecs[6], 4, executor, validator); + AddInstruction("FADD", 1, rangeSpecs[6], 4, executor, validator); + AddInstruction("FSUB", 2, rangeSpecs[6], 4, executor, validator); + AddInstruction("FMUL", 3, rangeSpecs[6], 9, executor, validator); + AddInstruction("FDIV", 4, rangeSpecs[6], 11, executor, validator); + AddInstruction("FLOT", 5, rangeSpecs[6], 3, executor, validator); + AddInstruction("FIX", 5, rangeSpecs[7], 3, executor, validator); + AddInstruction(FloatingPointInstructions.FcmpMnemonic, 56, rangeSpecs[6], 4, executor, validator); executor = MiscInstructions.Move; - addInstruction("MOVE", 7, new MetaFieldSpec(false, rangeSpecs[1]), 1, executor, validator); + AddInstruction("MOVE", 7, new MetaFieldSpec(false, rangeSpecs[1]), 1, executor, validator); var ioMetaSpec = new MetaFieldSpec(MetaFieldSpec.Presences.Mandatory, false); executor = IOInstructions.JumpIfBusy; validator = IOInstructions.InstanceValid; - addInstruction("JBUS", 34, ioMetaSpec, 1, executor, validator); + AddInstruction("JBUS", 34, ioMetaSpec, 1, executor, validator); executor = IOInstructions.IOControl; - addInstruction("IOC", 35, ioMetaSpec, 1, executor, validator); + AddInstruction("IOC", 35, ioMetaSpec, 1, executor, validator); executor = IOInstructions.Input; - addInstruction("IN", IOInstructions.INOpCode, ioMetaSpec, 1, executor, validator); + AddInstruction("IN", IOInstructions.INOpCode, ioMetaSpec, 1, executor, validator); executor = IOInstructions.Output; - addInstruction("OUT", 37, ioMetaSpec, 1, executor, validator); + AddInstruction("OUT", 37, ioMetaSpec, 1, executor, validator); executor = IOInstructions.JumpIfReady; - addInstruction("JRED", 38, ioMetaSpec, 1, executor, validator); + AddInstruction("JRED", 38, ioMetaSpec, 1, executor, validator); executor = ShiftInstructions.ShiftA; - addInstruction("SLA", 6, rangeSpecs[0], 2, executor, null); - addInstruction("SRA", 6, rangeSpecs[1], 2, executor, null); + AddInstruction("SLA", 6, rangeSpecs[0], 2, executor, null); + AddInstruction("SRA", 6, rangeSpecs[1], 2, executor, null); executor = ShiftInstructions.ShiftAX; - addInstruction("SLAX", 6, rangeSpecs[2], 2, executor, null); - addInstruction("SRAX", 6, rangeSpecs[3], 2, executor, null); - addInstruction("SLC", 6, rangeSpecs[4], 2, executor, null); - addInstruction("SRC", 6, rangeSpecs[5], 2, executor, null); + AddInstruction("SLAX", 6, rangeSpecs[2], 2, executor, null); + AddInstruction("SRAX", 6, rangeSpecs[3], 2, executor, null); + AddInstruction("SLC", 6, rangeSpecs[4], 2, executor, null); + AddInstruction("SRC", 6, rangeSpecs[5], 2, executor, null); executor = ShiftInstructions.ShiftAXBinary; - addInstruction("SLB", 6, rangeSpecs[6], 2, executor, null); - addInstruction("SRB", 6, rangeSpecs[7], 2, executor, null); + AddInstruction("SLB", 6, rangeSpecs[6], 2, executor, null); + AddInstruction("SRB", 6, rangeSpecs[7], 2, executor, null); executor = MiscInstructions.Noop; - addInstruction("NOP", 0, new MetaFieldSpec(false, rangeSpecs[0]), 1, executor, null); + AddInstruction("NOP", 0, new MetaFieldSpec(false, rangeSpecs[0]), 1, executor, null); executor = MiscInstructions.ConvertToNumeric; - addInstruction("NUM", 5, rangeSpecs[0], 10, executor, null); + AddInstruction("NUM", 5, rangeSpecs[0], 10, executor, null); executor = MiscInstructions.ConvertToChar; - addInstruction("CHAR", 5, rangeSpecs[1], 10, executor, null); + AddInstruction("CHAR", 5, rangeSpecs[1], 10, executor, null); executor = MiscInstructions.Halt; - addInstruction("HLT", 5, rangeSpecs[2], 10, executor, null); + AddInstruction("HLT", 5, rangeSpecs[2], 10, executor, null); executor = MiscInstructions.ForceInterrupt; - addInstruction("INT", 5, new FieldSpec(9), 2, executor, null); + AddInstruction("INT", 5, new FieldSpec(9), 2, executor, null); } - void addInstruction(string mnemonic, byte opcode, MetaFieldSpec metaFieldSpec, int tickCount, MixInstruction.Executor executor, MixInstruction.Validator validator) => - addInstruction(mnemonic, new MixInstruction(opcode, mnemonic, metaFieldSpec, tickCount, executor, validator)); + void AddInstruction(string mnemonic, byte opcode, MetaFieldSpec metaFieldSpec, int tickCount, MixInstruction.Executor executor, MixInstruction.Validator validator) => + AddInstruction(mnemonic, new MixInstruction(opcode, mnemonic, metaFieldSpec, tickCount, executor, validator)); - void addInstruction(string mnemonic, byte opcode, FieldSpec fieldSpec, int tickCount, MixInstruction.Executor executor, MixInstruction.Validator validator) => - addInstruction(mnemonic, new MixInstruction(opcode, fieldSpec, mnemonic, tickCount, executor, validator)); + void AddInstruction(string mnemonic, byte opcode, FieldSpec fieldSpec, int tickCount, MixInstruction.Executor executor, MixInstruction.Validator validator) => + AddInstruction(mnemonic, new MixInstruction(opcode, fieldSpec, mnemonic, tickCount, executor, validator)); - void addInstruction(string mnemonic, MixInstruction instruction) + void AddInstruction(string mnemonic, MixInstruction instruction) { mMnemonicInstructionMap.Add(mnemonic, instruction); var list = mOpcodeInstructionMap.GetOrCreate(instruction.Opcode); @@ -285,11 +285,10 @@ public static InstructionSet Instance public MixInstruction GetInstruction(byte opcode, FieldSpec fieldSpec) { - List instructions; - if (!mOpcodeInstructionMap.TryGetValue(opcode, out instructions)) return null; + if (!mOpcodeInstructionMap.TryGetValue(opcode, out List instructions)) return null; - int startIndex = 0; + int startIndex = 0; MixInstruction defaultInstruction = null; if (instructions[0].FieldSpec == null) diff --git a/MixLib/LoaderInstructions.cs b/MixLib/LoaderInstructions.cs index 6757a77..874d654 100644 --- a/MixLib/LoaderInstructions.cs +++ b/MixLib/LoaderInstructions.cs @@ -9,15 +9,15 @@ public class LoaderInstructions public LoaderInstructions() { - addInstruction("ORIG", LoaderInstruction.Operations.SetLocationCounter, false); - addInstruction("CON", LoaderInstruction.Operations.SetMemoryWord, false); - addInstruction("ALF", LoaderInstruction.Operations.SetMemoryWord, true); - addInstruction("END", LoaderInstruction.Operations.SetProgramCounter, false); + AddInstruction("ORIG", LoaderInstruction.Operations.SetLocationCounter, false); + AddInstruction("CON", LoaderInstruction.Operations.SetMemoryWord, false); + AddInstruction("ALF", LoaderInstruction.Operations.SetMemoryWord, true); + AddInstruction("END", LoaderInstruction.Operations.SetProgramCounter, false); } public LoaderInstruction this[string mnemonic] => mInstructions.ContainsKey(mnemonic) ? mInstructions[mnemonic] : null; - void addInstruction(string mnemonic, LoaderInstruction.Operations operation, bool alphanumeric) => + void AddInstruction(string mnemonic, LoaderInstruction.Operations operation, bool alphanumeric) => mInstructions.Add(mnemonic, new LoaderInstruction(mnemonic, operation, alphanumeric)); } } diff --git a/MixLib/Mix.cs b/MixLib/Mix.cs index d1b08b1..87329eb 100644 --- a/MixLib/Mix.cs +++ b/MixLib/Mix.cs @@ -52,14 +52,14 @@ public Mix() mMemory = new MemoryView(mFullMemory); - mDevices.DeviceReportingEvent += deviceReporting; + mDevices.DeviceReportingEvent += DeviceReporting; mLog = Queue.Synchronized(new Queue()); ProgramCounter = 0; TickCounter = 0L; mStatus = RunStatus.Idle; mMode = RunMode.Normal; - setMemoryBounds(); + SetMemoryBounds(); mCurrentInstructionAddress = int.MinValue; mCurrentInstructionMnemonic = null; @@ -70,10 +70,12 @@ public Mix() mStartStep = new AutoResetEvent(false); mRunDetached = false; - var thread = new Thread(stepRunEntryPoint); - thread.IsBackground = true; - thread.Name = "Run thread"; - thread.Start(); + var thread = new Thread(StepRunEntryPoint) + { + IsBackground = true, + Name = "Run thread" + }; + thread.Start(); } public override Devices Devices => mDevices; @@ -100,10 +102,10 @@ public Mix() public void RequestStop() => RequestStop(true); - void deviceReporting(object sender, DeviceReportingEventArgs args) => + void DeviceReporting(object sender, DeviceReportingEventArgs args) => AddLogLine(new LogLine(ModuleName, args.Severity, "Device message", string.Concat(new object[] { "Device ", args.ReportingDevice.Id, ": ", args.Message }))); - void setMemoryBounds() + void SetMemoryBounds() { mMemory.IndexOffset = 0; mMemory.MinWordIndex = Mode == RunMode.Control ? mFullMemory.MinWordIndex : 0; @@ -195,7 +197,7 @@ public void StartStep() mStartStep.Set(); } - void stepRunEntryPoint() + void StepRunEntryPoint() { var stepStartTime = new DateTime(); bool suspendRun = true; @@ -224,7 +226,7 @@ void stepRunEntryPoint() } } - void increaseTickCounter() + void IncreaseTickCounter() { TickCounter++; if (TickCounter % 1000 == 0) @@ -245,25 +247,27 @@ public void PrepareLoader() { var instruction = InstructionSet.Instance.GetInstruction(IOInstructions.INOpCode, new FieldSpec(Devices.CardReaderUnitCode)); - var instructionWord = new FullWord(); - instructionWord[MixInstruction.OpcodeByte] = IOInstructions.INOpCode; - instructionWord[MixInstruction.FieldSpecByte] = Devices.CardReaderUnitCode; + var instructionWord = new FullWord + { + [MixInstruction.OpcodeByte] = IOInstructions.INOpCode, + [MixInstruction.FieldSpecByte] = Devices.CardReaderUnitCode + }; var instance = instruction.CreateInstance(instructionWord); int ticksLeft = instruction.TickCount; - while (ticksLeft-- > 0) increaseTickCounter(); + while (ticksLeft-- > 0) IncreaseTickCounter(); instance.Execute(this); - while (mDevices[Devices.CardReaderUnitCode].Busy) increaseTickCounter(); + while (mDevices[Devices.CardReaderUnitCode].Busy) IncreaseTickCounter(); ProgramCounter = 0; - increaseTickCounter(); + IncreaseTickCounter(); - mRegisters.rJ.LongValue = 0; + mRegisters.RJ.LongValue = 0; - increaseTickCounter(); + IncreaseTickCounter(); } public void SignalInterruptExecuted() @@ -293,7 +297,7 @@ public void Tick() } } - increaseTickCounter(); + IncreaseTickCounter(); if (Status == RunStatus.Halted) { @@ -311,7 +315,7 @@ public void Tick() if (instruction == null) { ReportInvalidInstruction("Opcode (and field) do not encode an instruction"); - if (Mode == RunMode.Module) resetMode(); + if (Mode == RunMode.Module) ResetMode(); return; } @@ -321,7 +325,7 @@ public void Tick() if (errors != null) { ReportInvalidInstruction(errors); - if (Mode == RunMode.Module) resetMode(); + if (Mode == RunMode.Module) ResetMode(); return; } @@ -331,7 +335,7 @@ public void Tick() mCurrentInstructionAddress = ProgramCounter; mCurrentInstructionTicksLeft = instruction.TickCount; mCurrentInstructionMnemonic = instruction.Mnemonic; - if (Mode == RunMode.Module) resetMode(); + if (Mode == RunMode.Module) ResetMode(); } if (Mode != RunMode.Module && mCurrentInstructionTicksLeft > 0) @@ -376,10 +380,7 @@ public void Tick() } } - void resetMode() - { - Mode = ProgramCounter < 0 ? RunMode.Control : RunMode.Normal; - } + void ResetMode() => Mode = ProgramCounter < 0 ? RunMode.Control : RunMode.Normal; public bool RunDetached { @@ -411,7 +412,7 @@ public override RunMode Mode { mMode = value; - setMemoryBounds(); + SetMemoryBounds(); } } } diff --git a/MixLib/Modules/FloatingPointModule.cs b/MixLib/Modules/FloatingPointModule.cs index 6ebf771..9f4c48b 100644 --- a/MixLib/Modules/FloatingPointModule.cs +++ b/MixLib/Modules/FloatingPointModule.cs @@ -85,7 +85,7 @@ public override void Reset() Status = RunStatus.Idle; } - int? getSymbolAddress(string name) + int? GetSymbolAddress(string name) { if (Symbols == null) return null; @@ -109,21 +109,21 @@ public override bool LoadInstructionInstances(InstructionInstanceBase[] instance if (!base.LoadInstructionInstances(instances, symbols)) return false; Symbols = symbols; - mAccAddress = getSymbolAddress(accSymbol); - mPrenormAddress = getSymbolAddress(prenormSymbol); - mExitAddress = getSymbolAddress(exitSymbol); - mUnexpectedOverflowAddress = getSymbolAddress(unexpectedOverflowSymbol); - mExponentOverflowAddress = getSymbolAddress(exponentOverflowSymbol); - mExponentUnderflowAddress = getSymbolAddress(exponentUnderflowSymbol); - mFixOverflowAddress = getSymbolAddress(fixOverflowSymbol); - mDivisionByZeroAddress = getSymbolAddress(divisionByZeroSymbol); + mAccAddress = GetSymbolAddress(accSymbol); + mPrenormAddress = GetSymbolAddress(prenormSymbol); + mExitAddress = GetSymbolAddress(exitSymbol); + mUnexpectedOverflowAddress = GetSymbolAddress(unexpectedOverflowSymbol); + mExponentOverflowAddress = GetSymbolAddress(exponentOverflowSymbol); + mExponentUnderflowAddress = GetSymbolAddress(exponentUnderflowSymbol); + mFixOverflowAddress = GetSymbolAddress(fixOverflowSymbol); + mDivisionByZeroAddress = GetSymbolAddress(divisionByZeroSymbol); - validateAddresses(Severity.Warning); + ValidateAddresses(Severity.Warning); return true; } - bool validateAddress(Severity severity, string name, int address) + bool ValidateAddress(Severity severity, string name, int address) { if (address < 0 || address >= ModuleSettings.FloatingPointMemoryWordCount) { @@ -134,7 +134,7 @@ bool validateAddress(Severity severity, string name, int address) return true; } - bool validateAddresses(Severity severity) + bool ValidateAddresses(Severity severity) { if (mAccAddress == null || mPrenormAddress == null || mExitAddress == null) { @@ -142,26 +142,26 @@ bool validateAddresses(Severity severity) return false; } - return validateAddress(severity, accSymbol, mAccAddress.Value) && validateAddress(severity, prenormSymbol, mPrenormAddress.Value) && validateAddress(severity, exitSymbol, mExitAddress.Value); + return ValidateAddress(severity, accSymbol, mAccAddress.Value) && ValidateAddress(severity, prenormSymbol, mPrenormAddress.Value) && ValidateAddress(severity, exitSymbol, mExitAddress.Value); } public bool ValidateCall(string mnemonic) { - if (!validateAddresses(Severity.Error)) return false; + if (!ValidateAddresses(Severity.Error)) return false; - long? instructionValue = getSymbolAddress(mnemonic); + long? instructionValue = GetSymbolAddress(mnemonic); if (instructionValue == null) { AddLogLine(new LogLine(moduleName, Severity.Error, "Symbol unset", string.Format("Symbol for mnemonic {0} unset", mnemonic))); return false; } - return validateAddress(Severity.Error, mnemonic, (int)instructionValue.Value); + return ValidateAddress(Severity.Error, mnemonic, (int)instructionValue.Value); } public bool PreparePrenorm(IFullWord rAValue) { - Registers.rA.LongValue = rAValue.LongValue; + Registers.RA.LongValue = rAValue.LongValue; ProgramCounter = mPrenormAddress.Value; if (IsBreakpointSet(ProgramCounter)) @@ -173,9 +173,9 @@ public bool PreparePrenorm(IFullWord rAValue) return false; } - bool prepareCall(string mnemonic) + bool PrepareCall(string mnemonic) { - ProgramCounter = getSymbolAddress(mnemonic).Value; + ProgramCounter = GetSymbolAddress(mnemonic).Value; if (IsBreakpointSet(ProgramCounter)) { @@ -188,18 +188,18 @@ bool prepareCall(string mnemonic) public bool PrepareCall(string mnemonic, IFullWord rAValue) { - Registers.rA.LongValue = rAValue.LongValue; + Registers.RA.LongValue = rAValue.LongValue; - return prepareCall(mnemonic); + return PrepareCall(mnemonic); } public bool PrepareCall(string mnemonic, IFullWord rAValue, IFullWord paramValue) { Memory[mAccAddress.Value].LongValue = rAValue.LongValue; - Registers.rA.LongValue = paramValue.LongValue; + Registers.RA.LongValue = paramValue.LongValue; - return prepareCall(mnemonic); + return PrepareCall(mnemonic); } public override RunMode Mode diff --git a/MixLib/Modules/ModuleBase.cs b/MixLib/Modules/ModuleBase.cs index 9f7ade9..cd33f42 100644 --- a/MixLib/Modules/ModuleBase.cs +++ b/MixLib/Modules/ModuleBase.cs @@ -20,7 +20,7 @@ public abstract class ModuleBase protected bool IsBreakpointSet(int address) => BreakpointManager != null && BreakpointManager.IsBreakpointSet(address); - void reportLoadError(int locationCounter, string message) => + void ReportLoadError(int locationCounter, string message) => AddLogLine(new LogLine(ModuleName, Severity.Error, locationCounter, "Loader error", message)); public abstract void ResetProfilingCounts(); @@ -56,7 +56,7 @@ public int ProgramCounter } } - int loadInstructionInstance(LoaderInstruction.Instance instance, int locationCounter) + int LoadInstructionInstance(LoaderInstruction.Instance instance, int locationCounter) { FullMemory[locationCounter].SourceLine = instance.SourceLine; @@ -66,7 +66,7 @@ int loadInstructionInstance(LoaderInstruction.Instance instance, int locationCou var desiredLC = (int)instance.Value.LongValue; if (desiredLC >= FullMemory.MinWordIndex && desiredLC <= FullMemory.MaxWordIndex) return desiredLC; - reportLoadError(locationCounter, string.Format("Attempt to set location counter to invalid value {0}", desiredLC)); + ReportLoadError(locationCounter, string.Format("Attempt to set location counter to invalid value {0}", desiredLC)); return locationCounter; @@ -90,7 +90,7 @@ int loadInstructionInstance(LoaderInstruction.Instance instance, int locationCou return locationCounter; } - reportLoadError(locationCounter, string.Format("Attempt to set program counter to invalid value {0}", desiredPC)); + ReportLoadError(locationCounter, string.Format("Attempt to set program counter to invalid value {0}", desiredPC)); return locationCounter; } @@ -98,10 +98,10 @@ int loadInstructionInstance(LoaderInstruction.Instance instance, int locationCou return locationCounter; } - int loadInstructionInstance(MixInstruction.Instance instance, int locationCounter) + int LoadInstructionInstance(MixInstruction.Instance instance, int locationCounter) { var validationErrors = instance.Validate(); - if (validationErrors != null) reportLoadInstanceErrors(locationCounter, validationErrors); + if (validationErrors != null) ReportLoadInstanceErrors(locationCounter, validationErrors); FullMemory[locationCounter].MagnitudeLongValue = instance.InstructionWord.MagnitudeLongValue; FullMemory[locationCounter].Sign = instance.InstructionWord.Sign; @@ -121,16 +121,16 @@ public virtual bool LoadInstructionInstances(InstructionInstanceBase[] instances { if (instance is MixInstruction.Instance) { - locationCounter = loadInstructionInstance((MixInstruction.Instance)instance, locationCounter); + locationCounter = LoadInstructionInstance((MixInstruction.Instance)instance, locationCounter); } else if (instance is LoaderInstruction.Instance) { - locationCounter = loadInstructionInstance((LoaderInstruction.Instance)instance, locationCounter); + locationCounter = LoadInstructionInstance((LoaderInstruction.Instance)instance, locationCounter); } if (locationCounter > FullMemory.MaxWordIndex) { - reportLoadError(FullMemory.MaxWordIndex, "Location counter overflow; loading aborted"); + ReportLoadError(FullMemory.MaxWordIndex, "Location counter overflow; loading aborted"); Status = RunStatus.Idle; return false; @@ -154,7 +154,7 @@ protected void ReportInvalidInstruction(string message) Status = RunStatus.InvalidInstruction; } - void reportLoadInstanceErrors(int counter, InstanceValidationError[] errors) + void ReportLoadInstanceErrors(int counter, InstanceValidationError[] errors) { foreach (InstanceValidationError error in errors) { diff --git a/MixLib/Registers.cs b/MixLib/Registers.cs index a0fe263..76f633d 100644 --- a/MixLib/Registers.cs +++ b/MixLib/Registers.cs @@ -37,23 +37,23 @@ public Registers() public Register this[Offset offset] => this[(int)offset]; - public Register rI1 => mRegisters[(int)Offset.rI1]; + public Register RI1 => mRegisters[(int)Offset.rI1]; - public Register rI2 => mRegisters[(int)Offset.rI2]; + public Register RI2 => mRegisters[(int)Offset.rI2]; - public Register rI3 => mRegisters[(int)Offset.rI3]; + public Register RI3 => mRegisters[(int)Offset.rI3]; - public Register rI4 => mRegisters[(int)Offset.rI4]; + public Register RI4 => mRegisters[(int)Offset.rI4]; - public Register rI5 => mRegisters[(int)Offset.rI5]; + public Register RI5 => mRegisters[(int)Offset.rI5]; - public Register rI6 => mRegisters[(int)Offset.rI6]; + public Register RI6 => mRegisters[(int)Offset.rI6]; - public Register rA => mRegisters[(int)Offset.rA]; + public Register RA => mRegisters[(int)Offset.rA]; - public Register rJ => mrJ; + public Register RJ => mrJ; - public Register rX => mRegisters[(int)Offset.rX]; + public Register RX => mRegisters[(int)Offset.rX]; public int GetIndexedAddress(int mValue, int index) { @@ -91,23 +91,23 @@ public void SaveToMemory(IMemory memory, int firstAddress, int addressValue) composedWord[addressByteIndex] = (addressValue >> MixByte.BitCount) & MixByte.MaxValue; composedWord[addressByteIndex + 1] = addressValue & MixByte.MaxValue; - flagValues flags = flagValues.None; + FlagValues flags = FlagValues.None; if (OverflowIndicator) { - flags |= flagValues.Overflow; + flags |= FlagValues.Overflow; } if (CompareIndicator == CompValues.Greater) { - flags |= flagValues.Greater; + flags |= FlagValues.Greater; } else if (CompareIndicator == CompValues.Less) { - flags |= flagValues.Less; + flags |= FlagValues.Less; } composedWord[flagsByteIndex] = (byte)flags; - composedWord[rJByteIndex] = rJ[0]; - composedWord[rJByteIndex + 1] = rJ[1]; + composedWord[rJByteIndex] = RJ[0]; + composedWord[rJByteIndex + 1] = RJ[1]; } public int LoadFromMemory(IMemory memory, int firstAddress) @@ -127,13 +127,13 @@ public int LoadFromMemory(IMemory memory, int firstAddress) addressValue = addressValue.GetMagnitude(); } - var flags = (flagValues)(byte)composedWord[flagsByteIndex]; - OverflowIndicator = (flags & flagValues.Overflow) == flagValues.Overflow; - if ((flags & flagValues.Greater) == flagValues.Greater) + var flags = (FlagValues)(byte)composedWord[flagsByteIndex]; + OverflowIndicator = (flags & FlagValues.Overflow) == FlagValues.Overflow; + if ((flags & FlagValues.Greater) == FlagValues.Greater) { CompareIndicator = CompValues.Greater; } - else if ((flags & flagValues.Less) == flagValues.Less) + else if ((flags & FlagValues.Less) == FlagValues.Less) { CompareIndicator = CompValues.Less; } @@ -142,8 +142,8 @@ public int LoadFromMemory(IMemory memory, int firstAddress) CompareIndicator = CompValues.Equal; } - rJ[0] = composedWord[rJByteIndex]; - rJ[1] = composedWord[rJByteIndex + 1]; + RJ[0] = composedWord[rJByteIndex]; + RJ[1] = composedWord[rJByteIndex + 1]; return addressValue; } @@ -182,7 +182,7 @@ public enum Offset } [Flags] - enum flagValues : byte + enum FlagValues : byte { None = 0, Less = 1, diff --git a/MixLib/Type/MemoryView.cs b/MixLib/Type/MemoryView.cs index 392d810..6132047 100644 --- a/MixLib/Type/MemoryView.cs +++ b/MixLib/Type/MemoryView.cs @@ -20,7 +20,7 @@ public MemoryView(IMemory sourceMemory, int minIndex, int maxIndex, int indexOff { SourceMemory = sourceMemory; - validateParameters(minIndex, maxIndex, indexOffset); + ValidateParameters(minIndex, maxIndex, indexOffset); mMinIndex = minIndex; mMaxIndex = maxIndex; @@ -39,7 +39,7 @@ public MemoryView(IMemory sourceMemory, int minIndex, int maxIndex, int indexOff public void ClearRealWordSourceLine(int index) => SourceMemory.ClearRealWordSourceLine(index + mIndexOffset); - void validateParameters(int minIndex, int maxIndex, int offset) + void ValidateParameters(int minIndex, int maxIndex, int offset) { if (minIndex + offset < SourceMemory.MinWordIndex) { @@ -116,7 +116,7 @@ public int MinWordIndex } set { - validateParameters(value, mMaxIndex, mIndexOffset); + ValidateParameters(value, mMaxIndex, mIndexOffset); mMinIndex = value; } @@ -130,7 +130,7 @@ public int MaxWordIndex } set { - validateParameters(mMinIndex, value, mIndexOffset); + ValidateParameters(mMinIndex, value, mIndexOffset); mMaxIndex = value; } @@ -144,7 +144,7 @@ public int IndexOffset } set { - validateParameters(mMinIndex, mMaxIndex, value); + ValidateParameters(mMinIndex, mMaxIndex, value); mIndexOffset = value; } diff --git a/MixLib/Type/SymbolCollection.cs b/MixLib/Type/SymbolCollection.cs index b65e585..c41b8fe 100644 --- a/MixLib/Type/SymbolCollection.cs +++ b/MixLib/Type/SymbolCollection.cs @@ -16,15 +16,15 @@ public sealed class SymbolCollection : IEnumerable, IEnumerable public bool Contains(string value) => mList.ContainsKey(value); - IEnumerator getEnumerator() => mList.Values.GetEnumerator(); + IEnumerator GetEnumerator() => mList.Values.GetEnumerator(); public void Remove(SymbolBase value) => Remove(value.Name); public void Remove(string name) => mList.Remove(name); - IEnumerator IEnumerable.GetEnumerator() => getEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => getEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public void Add(SymbolBase value) { diff --git a/MixLib/Type/VirtualMemoryFullWord.cs b/MixLib/Type/VirtualMemoryFullWord.cs index 12891a6..5f7199d 100644 --- a/MixLib/Type/VirtualMemoryFullWord.cs +++ b/MixLib/Type/VirtualMemoryFullWord.cs @@ -47,38 +47,38 @@ public VirtualMemoryFullWord(IMemory memory, int index) public int ByteCount => FullWord.ByteCount; - FullWord activeWord => realWordFetched ? mRealWord : mDefaultWord; + FullWord ActiveWord => RealWordFetched ? mRealWord : mDefaultWord; public long MaxMagnitude => mDefaultWord.MaxMagnitude; - public long ProfilingTickCount => realWordFetched ? mRealWord.ProfilingTickCount : 0; + public long ProfilingTickCount => RealWordFetched ? mRealWord.ProfilingTickCount : 0; - public long ProfilingExecutionCount => realWordFetched ? mRealWord.ProfilingExecutionCount : 0; + public long ProfilingExecutionCount => RealWordFetched ? mRealWord.ProfilingExecutionCount : 0; - public IEnumerator GetEnumerator() => activeWord.GetEnumerator(); + public IEnumerator GetEnumerator() => ActiveWord.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)activeWord).GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)ActiveWord).GetEnumerator(); - public int MaxByteCount => activeWord.MaxByteCount; + public int MaxByteCount => ActiveWord.MaxByteCount; - public bool IsEmpty => !realWordFetched || mRealWord.IsEmpty; + public bool IsEmpty => !RealWordFetched || mRealWord.IsEmpty; - public MixByte[] ToArray() => activeWord.ToArray(); + public MixByte[] ToArray() => ActiveWord.ToArray(); - public object Clone() => activeWord.Clone(); + public object Clone() => ActiveWord.Clone(); public string ToString(bool asChars) => - realWordFetched ? mRealWord.ToString(asChars) : (asChars ? mDefaultCharString : mDefaultNonCharString); + RealWordFetched ? mRealWord.ToString(asChars) : (asChars ? mDefaultCharString : mDefaultNonCharString); - void fetchRealWordIfNotFetched() + void FetchRealWordIfNotFetched() { lock (mSyncRoot) { - if (mRealWord == null) fetchRealWord(); + if (mRealWord == null) FetchRealWord(); } } - bool realWordFetched + bool RealWordFetched { get { @@ -89,12 +89,12 @@ bool realWordFetched } } - void fetchRealWord() + void FetchRealWord() { mRealWord = mMemory.GetRealWord(Index); } - bool fetchRealWordConditionally(Func condition) + bool FetchRealWordConditionally(Func condition) { lock (mSyncRoot) { @@ -102,7 +102,7 @@ bool fetchRealWordConditionally(Func condition) { if (!condition()) return false; - fetchRealWord(); + FetchRealWord(); } } @@ -113,11 +113,11 @@ public string SourceLine { get { - return realWordFetched ? mRealWord.SourceLine : null; + return RealWordFetched ? mRealWord.SourceLine : null; } set { - if (fetchRealWordConditionally(() => value != null)) + if (FetchRealWordConditionally(() => value != null)) { mRealWord.SourceLine = value; } @@ -126,12 +126,12 @@ public string SourceLine public void Load(string text) { - if (fetchRealWordConditionally(() => text != mDefaultCharString)) mRealWord.Load(text); + if (FetchRealWordConditionally(() => text != mDefaultCharString)) mRealWord.Load(text); } public void InvertSign() { - fetchRealWordIfNotFetched(); + FetchRealWordIfNotFetched(); mRealWord.InvertSign(); } @@ -139,11 +139,11 @@ public MixByte this[int index] { get { - return activeWord[index]; + return ActiveWord[index]; } set { - if (fetchRealWordConditionally(() => mDefaultWord[index].ByteValue != value.ByteValue)) + if (FetchRealWordConditionally(() => mDefaultWord[index].ByteValue != value.ByteValue)) { mRealWord[index] = value; } @@ -154,11 +154,11 @@ public long LongValue { get { - return activeWord.LongValue; + return ActiveWord.LongValue; } set { - if (fetchRealWordConditionally(() => value != mDefaultLongValue)) + if (FetchRealWordConditionally(() => value != mDefaultLongValue)) { mRealWord.LongValue = value; } @@ -169,11 +169,11 @@ public MixByte[] Magnitude { get { - return activeWord.Magnitude; + return ActiveWord.Magnitude; } set { - if (fetchRealWordConditionally(() => + if (FetchRealWordConditionally(() => { bool valueDifferent = false; int thisStartIndex = 0; @@ -222,11 +222,11 @@ public long MagnitudeLongValue { get { - return activeWord.MagnitudeLongValue; + return ActiveWord.MagnitudeLongValue; } set { - if (fetchRealWordConditionally(() => value != mDefaultLongValue)) + if (FetchRealWordConditionally(() => value != mDefaultLongValue)) { mRealWord.MagnitudeLongValue = value; } @@ -237,11 +237,11 @@ public Word.Signs Sign { get { - return activeWord.Sign; + return ActiveWord.Sign; } set { - if (fetchRealWordConditionally(() => value != mDefaultWord.Sign)) + if (FetchRealWordConditionally(() => value != mDefaultWord.Sign)) { mRealWord.Sign = value; } @@ -302,14 +302,14 @@ public override int GetHashCode() public void IncreaseProfilingTickCount(int ticks) { - fetchRealWordIfNotFetched(); + FetchRealWordIfNotFetched(); mRealWord.IncreaseProfilingTickCount(ticks); } public void IncreaseProfilingExecutionCount() { - fetchRealWordIfNotFetched(); + FetchRealWordIfNotFetched(); mRealWord.IncreaseProfilingExecutionCount(); } diff --git a/MixLib/Type/Word.cs b/MixLib/Type/Word.cs index cb0d57a..e8ce59a 100644 --- a/MixLib/Type/Word.cs +++ b/MixLib/Type/Word.cs @@ -186,7 +186,7 @@ public long LongValue { if (value == LongValue) return; - setMagnitudeLongValue(value); + SetMagnitudeLongValue(value); mSign = value.GetSign(); } finally @@ -198,7 +198,7 @@ public long LongValue } } - long setMagnitudeLongValue(long magnitude) + long SetMagnitudeLongValue(long magnitude) { long oldValue = MagnitudeLongValue; @@ -302,7 +302,7 @@ public long MagnitudeLongValue try { - if (setMagnitudeLongValue(value) == value.GetMagnitude()) return; + if (SetMagnitudeLongValue(value) == value.GetMagnitude()) return; } finally { diff --git a/MixLib/Utils/CollectionHelper.cs b/MixLib/Utils/CollectionHelper.cs index 73351d5..9c9bc58 100644 --- a/MixLib/Utils/CollectionHelper.cs +++ b/MixLib/Utils/CollectionHelper.cs @@ -6,14 +6,13 @@ public static class CollectionHelper { public static TValue GetOrCreate(this IDictionary dictionary, TKey key) where TValue : new() { - TValue value; - if (!dictionary.TryGetValue(key, out value)) - { - value = new TValue(); - dictionary[key] = value; - } + if (!dictionary.TryGetValue(key, out TValue value)) + { + value = new TValue(); + dictionary[key] = value; + } - return value; + return value; } } }