Remade btnLoad preinitialization & Added code loader
This commit is contained in:
+24
-16
@@ -133,26 +133,21 @@ namespace processor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void btnLoad_Click(object sender, EventArgs e)
|
private void btnLoad_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
List<string> instructionList = new();
|
if (string.IsNullOrWhiteSpace(txtCode.Text)) return;
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(txtCode.Text))
|
// Next line reads content from txtCode, splits it into lines using '\n' as delimiter and casts the IEnumerable to List
|
||||||
{
|
List<string> inputLines = txtCode.Text.Split((char)10, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList();
|
||||||
List<string> inputLines = txtCode.Text.Trim().Split((char)10, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList();
|
// Removes comments from lines, drops empty lines and sets instructionList to this new collection
|
||||||
inputLines = (from x in inputLines select RemoveComment(x)).ToList(); // removes comments from lines
|
List<string> instructionList = (from x in inputLines where !string.IsNullOrEmpty(RemoveComment(x)) select RemoveComment(x)).ToList();
|
||||||
instructionList = (from x in inputLines where string.IsNullOrEmpty(x) is false select x).ToList(); // drops empty elements
|
|
||||||
}
|
List<string> funcCode, ramCode;
|
||||||
|
funcCode = (from x in instructionList where x.StartsWith("0x") select x).ToList();
|
||||||
|
ramCode = (from x in instructionList where x.StartsWith("1x") select x).ToList();
|
||||||
|
|
||||||
if (radHex.Checked is true)
|
if (radHex.Checked is true)
|
||||||
{
|
{
|
||||||
instructionList = (from x in instructionList select RemoveLeading(x)).ToList();
|
LoadHexCode(funcCode);
|
||||||
int j = 0;
|
LoadHexCode(ramCode);
|
||||||
for (int i = 0; i < instructionList.Count; i++)
|
|
||||||
{
|
|
||||||
string[] enm = instructionList[i].Split2().ToArray();
|
|
||||||
LoadProgram(j, enm[0]);
|
|
||||||
LoadProgram(j+1, enm[1]);
|
|
||||||
j += 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -160,6 +155,19 @@ namespace processor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LoadHexCode(List<string> codes)
|
||||||
|
{
|
||||||
|
codes = (from x in codes select RemoveLeading(x)).ToList();
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < codes.Count; i++)
|
||||||
|
{
|
||||||
|
string[] enm = codes[i].Split2().ToArray();
|
||||||
|
LoadProgram(j, enm[0]);
|
||||||
|
LoadProgram(j+1, enm[1]);
|
||||||
|
j += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
private void btnStart_Click(object sender, EventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user