From 893817eb3a49c142b4c78632d086d7e463279751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 30 Oct 2021 05:49:22 +0300 Subject: [PATCH] Remade btnLoad preinitialization & Added code loader --- src/MainForm.cs | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index f6fcffc..d055119 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -133,26 +133,21 @@ namespace processor /// private void btnLoad_Click(object sender, EventArgs e) { - List instructionList = new(); + if (string.IsNullOrWhiteSpace(txtCode.Text)) return; + + // Next line reads content from txtCode, splits it into lines using '\n' as delimiter and casts the IEnumerable to List + List inputLines = txtCode.Text.Split((char)10, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList(); + // Removes comments from lines, drops empty lines and sets instructionList to this new collection + List instructionList = (from x in inputLines where !string.IsNullOrEmpty(RemoveComment(x)) select RemoveComment(x)).ToList(); - if (!string.IsNullOrWhiteSpace(txtCode.Text)) - { - List inputLines = txtCode.Text.Trim().Split((char)10, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList(); - inputLines = (from x in inputLines select RemoveComment(x)).ToList(); // removes comments from lines - instructionList = (from x in inputLines where string.IsNullOrEmpty(x) is false select x).ToList(); // drops empty elements - } + List 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) { - instructionList = (from x in instructionList select RemoveLeading(x)).ToList(); - int j = 0; - 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; - } + LoadHexCode(funcCode); + LoadHexCode(ramCode); } else { @@ -160,6 +155,19 @@ namespace processor } } + private void LoadHexCode(List 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 btnStart_Click(object sender, EventArgs e)