Small tweaks and performance improvements

Reimplemented CnvRespectfully()
Updated code to ram loader
This commit is contained in:
Ferit Yiğit BALABAN
2021-10-29 01:54:29 +03:00
parent a2914002ba
commit 05cbaee652
+31 -16
View File
@@ -52,9 +52,14 @@ namespace processor
} }
#region RAM #region RAM
private void ReadRam(int address, string value) /// <summary>
/// Returns data as integers hold in addressed memory cell
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
private int ReadRam(int address)
{ {
} }
private void WriteRam(int address, string hexValue) private void WriteRam(int address, string hexValue)
@@ -63,11 +68,19 @@ namespace processor
} }
#endregion #endregion
private string CnvRespectfully(string value) /// <summary>
{ /// Converts integer to hexadecimal or binary representation in text according to selected view mode
if (radHex.Checked is true) return value.Hex2Int().ToHex2(); /// </summary>
else throw new NotImplementedException(); /// <param name="value"></param>
} /// <returns></returns>
private string CnvRespectfully(int value) => radHex.Checked ? Convert.ToString(value, 16).PadLeft(2, '0') : Convert.ToString(value, 2).PadLeft(8, '0');
/// <summary>
/// Converts hexadecimal or binary representation to integer according to selected view mode
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private int CnvRespectfully(string value) => radHex.Checked ? Convert.ToInt32(value, 16) : Convert.ToInt32(value, 2);
/// <summary> /// <summary>
/// Parses and loads instructions to ramList /// Parses and loads instructions to ramList
@@ -76,7 +89,7 @@ namespace processor
/// <param name="e"></param> /// <param name="e"></param>
private void btnLoad_Click(object sender, EventArgs e) private void btnLoad_Click(object sender, EventArgs e)
{ {
List<string> instructionList = new List<string>(); List<string> instructionList = new();
if (!string.IsNullOrWhiteSpace(txtCode.Text)) if (!string.IsNullOrWhiteSpace(txtCode.Text))
{ {
@@ -88,16 +101,13 @@ namespace processor
if (radHex.Checked is true) if (radHex.Checked is true)
{ {
instructionList = (from x in instructionList select RemoveLeading(x)).ToList(); instructionList = (from x in instructionList select RemoveLeading(x)).ToList();
List<string> inst = new(); int j = 0;
for (int i = 0; i < instructionList.Count; i++) for (int i = 0; i < instructionList.Count; i++)
{ {
IEnumerable<string> enm = instructionList[i].Split2(); string[] enm = instructionList[i].Split2().ToArray();
inst.Add(enm.ElementAt(0)); WriteRam(j, enm[0]);
inst.Add(enm.ElementAt(1)); // i am quite sure that there is a much better approach but it's 1 am and i'm tired af WriteRam(j+1, enm[1]);
} j += 2;
for (int i = 0; i < inst.Count; i++)
{
WriteRam(i, inst[i]);
} }
} }
else else
@@ -107,5 +117,10 @@ namespace processor
} }
private void btnClear_Click(object sender, EventArgs e) => InitializeRamList(); private void btnClear_Click(object sender, EventArgs e) => InitializeRamList();
private void btnStart_Click(object sender, EventArgs e)
{
}
} }
} }