Added register controls, updated converters

This commit is contained in:
Ferit Yiğit BALABAN
2021-10-29 14:09:14 +03:00
parent 94aad64809
commit a76058ab36
2 changed files with 57 additions and 1 deletions

2
MainForm.Designer.cs generated
View File

@@ -221,6 +221,7 @@ namespace processor
this.btnStart.TabIndex = 2;
this.btnStart.Text = "Start";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// btnStep
//
@@ -230,6 +231,7 @@ namespace processor
this.btnStep.TabIndex = 3;
this.btnStep.Text = "Step";
this.btnStep.UseVisualStyleBackColor = true;
this.btnStep.Click += new System.EventHandler(this.btnStep_Click);
//
// btnHalt
//

View File

@@ -4,10 +4,14 @@ using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using processor.Properties;
using static processor.Extensions;
namespace processor
@@ -59,6 +63,20 @@ namespace processor
/// <returns></returns>
private int ReadRam(int address) => CnvRespectfully(ramList.Items[address].ToString().Split(':', StringSplitOptions.TrimEntries)[1]);
/// <summary>
/// Reads the amount of memory cells supplied in "count", starts reading from "address". 0 for count only reads addressed memory, 1 reads addressed and next cell
/// </summary>
/// <param name="address"></param>
/// <param name="count"></param>
/// <returns></returns>
private int ReadRam(int address, int count = 0)
{
string append = string.Empty;
for (int i = 0; i <= count; i++)
append += ramList.Items[address + i].ToString().Split(':', StringSplitOptions.TrimEntries)[1];
return CnvRespectfully(append);
}
/// <summary>
/// Used by loader for writing hexadecimal/binary instructions
/// </summary>
@@ -74,6 +92,33 @@ namespace processor
private void WriteRam(int address, int value) => ramList.Items[address] = $"{CnvRespectfully(address)}: {CnvRespectfully(value)}";
#endregion
#region Registers
private int ReadRegister(int address) => CnvRespectfully(Controls.Find($"txtr{address:x}".ToLower(), true)[0].Text);
private void WriteRegister(int address, int value) => Controls.Find($"txtr{address:x}".ToLower(), true)[0].Text = CnvRespectfully(value);
private int ReadCounter() => CnvRespectfully(txtProgCounter.Text);
private void SetCounter(int value)
{
txtProgCounter.Text = CnvRespectfully(value);
SetInstRegister(ReadRam(ReadCounter(), 1));
}
private int[] ReadInstRegister()
{
int[] r = new int[4];
string[] a = radHex.Checked ? txtrInstReg.Text.Split1() : txtrInstReg.Text.Split4().ToArray();
for (int i = 0; i < 4; i++)
r[i] = CnvRespectfully(a[i]);
return r;
}
private void SetInstRegister(int value) => txtrInstReg.Text = CnvRespectfully4(value);
#endregion
/// <summary>
/// Converts integer to hexadecimal or binary representation in text according to selected view mode
/// </summary>
@@ -81,6 +126,10 @@ namespace processor
/// <returns></returns>
private string CnvRespectfully(int value) => radHex.Checked ? Convert.ToString(value, 16).PadLeft(2, '0').ToUpper() : Convert.ToString(value, 2).PadLeft(8, '0');
private string CnvRespectfully4(int value) => radHex.Checked ? Convert.ToString(value, 16).PadLeft(4, '0').ToUpper() : Convert.ToString(value, 2).PadLeft(8, '0');
private string CnvRespectfully(int value, int hexPad = 2, int binPad = 8) => radHex.Checked ? Convert.ToString(value, 16).PadLeft(hexPad, '0').ToUpper() : Convert.ToString(value, 2).PadLeft(binPad, '0');
/// <summary>
/// Converts hexadecimal or binary representation to integer according to selected view mode
/// </summary>
@@ -88,6 +137,8 @@ namespace processor
/// <returns></returns>
private int CnvRespectfully(string value) => radHex.Checked ? Convert.ToInt32(value, 16) : Convert.ToInt32(value, 2);
private string AppendOperand(int x, int y) => radHex.Checked ? CnvRespectfully((x * 16) + y, 2, 8) : CnvRespectfully(5, 2, 4) + CnvRespectfully(3, 2, 4);
/// <summary>
/// Parses and loads instructions to ramList
/// </summary>
@@ -126,7 +177,10 @@ namespace processor
private void btnStart_Click(object sender, EventArgs e)
{
}
private void btnStep_Click(object sender, EventArgs e)
{
}
}
}