From ef6844bbfa2181dff53d52987762fcf077aa349c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 30 Oct 2021 06:06:11 +0300 Subject: [PATCH] Commented hex. load implementation --- src/MainForm.cs | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index d055119..032975b 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -73,7 +73,7 @@ namespace processor /// /// /// - private void LoadProgram(int address, string value) => ramList.Items[address] = $"{CnvRespectfully(address, 2, 8)}: {value}"; + private void LoadCode(int address, string value) => ramList.Items[address] = $"{CnvRespectfully(address, 2, 8)}: {value}"; /// /// Write data to addressed memory cell @@ -140,21 +140,23 @@ namespace processor // 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(); - 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) { - LoadHexCode(funcCode); - LoadHexCode(ramCode); + // This loads CPU instructions to RAM, starting from address 0x00 and going up to 0xFF + LoadHexCode((from x in instructionList where x.StartsWith("0x") select x).ToList()); + // This executes RAM write instructions, ultimately overwriting RAM with data + ExecuteRamWrite((from x in instructionList where x.StartsWith("1x") select x).ToList()); } else { - + } } + /// + /// Loads hexadecimal CPU instructions to RAM + /// + /// private void LoadHexCode(List codes) { codes = (from x in codes select RemoveLeading(x)).ToList(); @@ -162,12 +164,34 @@ namespace processor for (int i = 0; i < codes.Count; i++) { string[] enm = codes[i].Split2().ToArray(); - LoadProgram(j, enm[0]); - LoadProgram(j+1, enm[1]); + LoadCode(j, enm[0]); + LoadCode(j+1, enm[1]); j += 2; } } + /// + /// Writes data to RAM without using CPU instructions + /// + /// + private void ExecuteRamWrite(List codes) + { + foreach (string code in codes) // code is a 2 byte hexadecimal instruction: 1A34 + { + string[] ia = code.Split2().ToArray(); + WriteRam(CnvRespectfully(ia[0]), CnvRespectfully(ia[1])); + } + } + + /// + /// Loads binary CPU instructions to RAM + /// + /// + private void LoadBinCode(List codes) + { + throw new NotImplementedException(); + } + private void btnClear_Click(object sender, EventArgs e) => InitializeRamList(); private void btnStart_Click(object sender, EventArgs e)