From 08a006c9c3d0efae2b6b2a2a38d416048eb11f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Fri, 29 Oct 2021 02:04:57 +0300 Subject: [PATCH] RAM manipulation methods extended --- MainForm.cs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/MainForm.cs b/MainForm.cs index 5600b8f..c793d5a 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -57,15 +57,21 @@ namespace processor /// /// /// - private int ReadRam(int address) - { - - } + private int ReadRam(int address) => CnvRespectfully(ramList.Items[address].ToString().Split(':', StringSplitOptions.TrimEntries)[1]); - private void WriteRam(int address, string hexValue) - { - ramList.Items[address] = string.Format("{0}: {1}", CnvRespectfully(address.ToString()), hexValue); - } + /// + /// Used by loader for writing hexadecimal/binary instructions + /// + /// + /// + private void LoadProgram(int address, string value) => ramList.Items[address] = $"{CnvRespectfully(address)}: {value}"; + + /// + /// Write data to addressed memory cell + /// + /// + /// + private void WriteRam(int address, int value) => ramList.Items[address] = $"{CnvRespectfully(address)}: {CnvRespectfully(value)}"; #endregion /// @@ -73,7 +79,7 @@ namespace processor /// /// /// - private string CnvRespectfully(int value) => radHex.Checked ? Convert.ToString(value, 16).PadLeft(2, '0') : Convert.ToString(value, 2).PadLeft(8, '0'); + private string CnvRespectfully(int value) => radHex.Checked ? Convert.ToString(value, 16).PadLeft(2, '0').ToUpper() : Convert.ToString(value, 2).PadLeft(8, '0'); /// /// Converts hexadecimal or binary representation to integer according to selected view mode @@ -105,8 +111,8 @@ namespace processor for (int i = 0; i < instructionList.Count; i++) { string[] enm = instructionList[i].Split2().ToArray(); - WriteRam(j, enm[0]); - WriteRam(j+1, enm[1]); + LoadProgram(j, enm[0]); + LoadProgram(j+1, enm[1]); j += 2; } }