Load hex program code to ram
This commit is contained in:
+60
-1
@@ -8,6 +8,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using static processor.Extensions;
|
||||
|
||||
namespace processor
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
@@ -23,7 +25,64 @@ namespace processor
|
||||
{
|
||||
ramList.Items.Clear();
|
||||
for (int i = 0; i < 256; i++)
|
||||
ramList.Items.Add(string.Format("{0}: {1}", Convert.ToString(i, 2).PadLeft(8, '0'), "00000000"));
|
||||
ramList.Items.Add(string.Format("{0}: {1}", Convert.ToString(i, 16).PadLeft(2, '0'), "00"));
|
||||
}
|
||||
|
||||
#region RAM
|
||||
private void ReadRam(int address, string value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void WriteRam(int address, string hexValue)
|
||||
{
|
||||
ramList.Items[address] = string.Format("{0}: {1}", CnvRespectfully(address.ToString()), hexValue);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private string CnvRespectfully(string value)
|
||||
{
|
||||
if (radHex.Checked is true) return value.Hex2Int().ToHex2();
|
||||
else throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses and loads instructions to ramList
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void btnLoad_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<string> instructionList = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(txtCode.Text))
|
||||
{
|
||||
List<string> 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
|
||||
}
|
||||
|
||||
if (radHex.Checked is true)
|
||||
{
|
||||
instructionList = (from x in instructionList select RemoveLeading(x)).ToList();
|
||||
List<string> inst = new();
|
||||
for (int i = 0; i < instructionList.Count; i++)
|
||||
{
|
||||
IEnumerable<string> enm = instructionList[i].Split2();
|
||||
inst.Add(enm.ElementAt(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
|
||||
}
|
||||
for (int i = 0; i < inst.Count; i++)
|
||||
{
|
||||
WriteRam(i, inst[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void btnClear_Click(object sender, EventArgs e) => InitializeRamList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user