Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed bugs found while testing, added input for a label (symlink) to …

…be used as an opcode
  • Loading branch information...
commit 957e41d1a8248282c86d570768ff01af5ec3d33e 1 parent 0b130b2
@danpalmer authored
View
BIN  .DS_Store
Binary file not shown
View
BIN  Assembly Simulator.suo
Binary file not shown
View
3  Assembly Simulator/Assembly Simulator.csproj
@@ -160,6 +160,7 @@
<None Include="Assembly Simulator_TemporaryKey.pfx" />
<EmbeddedResource Include="InstructionList.dat">
</EmbeddedResource>
+ <None Include="Properties\app.manifest" />
<None Include="README.txt" />
</ItemGroup>
<ItemGroup>
@@ -194,7 +195,7 @@
-->
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_UpdateFileVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.DayStamp" BuildVersion_UpdateAssemblyVersion="True" />
+ <UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.DayStamp" BuildVersion_UpdateFileVersion="True" />
</VisualStudio>
</ProjectExtensions>
</Project>
View
24 Assembly Simulator/CPU.cs 100644 → 100755
@@ -234,12 +234,13 @@ private void ST(string label, int intOperand, string operand)
}
}
- error(null, "Could not find symbolic link in array, "
+ // Code should never reach this location
+ error(null, "Could not find the label in array, "
+ "please contact the publisher of this program for assistance");
}
else
{
- parent.setValueForRAMIndex(Convert.ToInt32(operand), accumulator);
+ parent.setValueForRAMIndex(Convert.ToInt32(hexToInt(operand)), accumulator);
Debug.WriteLine("Stored accumulator in memory location");
}
}
@@ -299,7 +300,7 @@ private void GETINT(string label, int operand)
int y = Convert.ToInt32(x);
// Validation done here because the input window is for letters and numbers
- if (y > 127 || y < -127)
+ if (y > 255 || y < 0)
error(null, "Integer is not within the correct bounds");
else
{
@@ -370,10 +371,19 @@ private void DEFB(string label, int operand)
// Jump to operand label
private void JP(string label, string operand)
{
- if (operand == "" || operand == null) {
- // Change the next instruction to be executed by getting the label to jump to
- this.programCounter = (parent.programInstructionIndexForLabel(operand) -1).ToString();
- }
+ if (operand != "" && operand != null)
+ {
+ // Change the next instruction to be executed by getting the label to jump to
+ this.programCounter = (parent.programInstructionIndexForLabel(operand) - 1).ToString();
+ if (this.programCounter == (-2).ToString())
+ {
+ error("Bad Jump Instruction", "The label you tried to jump to does not exist.");
+ }
+ }
+ else
+ {
+ error("Bad Jump Instruction", "The Jump instruction requires an operand of the label to jump to.");
+ }
}
// Jump to operand label if greater: z=0 and ns=0
View
2  Assembly Simulator/EnhancedTextBox.cs 100644 → 100755
@@ -87,7 +87,7 @@ private void errorFlash()
base.ForeColor = Color.White;
// Create a timer set to call endErrorFlash in 0.1s and start it
Timer timer = new Timer();
- timer.Interval = 100;
+ timer.Interval = 2000;
timer.Tick += new System.EventHandler(this.endErrorFlash);
timer.Start();
}
View
21 Assembly Simulator/InstructionList.dat
@@ -7,6 +7,7 @@
</detail>
<OPCODE>LD</OPCODE>
<colour>1</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Store</name>
@@ -14,6 +15,7 @@
</detail>
<OPCODE>ST</OPCODE>
<colour>1</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Define Byte</name>
@@ -21,6 +23,7 @@
</detail>
<OPCODE>DEFB</OPCODE>
<colour>1</colour>
+ <allowlabel>no</allowlabel>
</instruction>
<!-- MATHS FUNCTIONS -->
<instruction>
@@ -29,6 +32,7 @@
</detail>
<OPCODE>ADD</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Subtract</name>
@@ -36,6 +40,7 @@
</detail>
<OPCODE>SUB</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Multiply</name>
@@ -45,6 +50,7 @@
</detail>
<OPCODE>MUL</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Divide</name>
@@ -52,6 +58,7 @@
</detail>
<OPCODE>DIV</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>And</name>
@@ -59,6 +66,7 @@
</detail>
<OPCODE>AND</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Or</name>
@@ -68,6 +76,7 @@
</detail>
<OPCODE>OR</OPCODE>
<colour>2</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<!-- COMPARISON FUNCTIONS -->
<instruction>
@@ -76,6 +85,7 @@
</detail>
<OPCODE>CMP</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump</name>
@@ -85,6 +95,7 @@
</detail>
<OPCODE>JP</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Equal</name>
@@ -92,6 +103,7 @@
</detail>
<OPCODE>JE</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Greater</name>
@@ -99,6 +111,7 @@
</detail>
<OPCODE>JG</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Less</name>
@@ -106,6 +119,7 @@
</detail>
<OPCODE>JL</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Greater than or Equal</name>
@@ -113,6 +127,7 @@
</detail>
<OPCODE>JGE</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Less or Equal</name>
@@ -120,6 +135,7 @@
</detail>
<OPCODE>JLE</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<instruction>
<name>Jump if Not Equal</name>
@@ -127,6 +143,7 @@
</detail>
<OPCODE>JNE</OPCODE>
<colour>3</colour>
+ <allowlabel>yes</allowlabel>
</instruction>
<!-- OTHER STUFF -->
<instruction>
@@ -135,6 +152,7 @@
</detail>
<OPCODE>GETCHAR</OPCODE>
<colour>4</colour>
+ <allowlabel>no</allowlabel>
</instruction>
<instruction>
<name>Get Integer</name>
@@ -142,6 +160,7 @@
</detail>
<OPCODE>GETINT</OPCODE>
<colour>4</colour>
+ <allowlabel>no</allowlabel>
</instruction>
<instruction>
<name>Put Character</name>
@@ -149,6 +168,7 @@
</detail>
<OPCODE>PUTCHAR</OPCODE>
<colour>4</colour>
+ <allowlabel>no</allowlabel>
</instruction>
<instruction>
<name>Put Integer</name>
@@ -156,5 +176,6 @@
</detail>
<OPCODE>PUTINT</OPCODE>
<colour>4</colour>
+ <allowlabel>no</allowlabel>
</instruction>
</List>
View
1  Assembly Simulator/InstructionView.Designer.cs
@@ -95,6 +95,7 @@ private void InitializeComponent()
this.textBoxOPERAND.ReadOnly = true;
this.textBoxOPERAND.Size = new System.Drawing.Size(68, 20);
this.textBoxOPERAND.TabIndex = 12;
+ this.textBoxOPERAND.Enter += new System.EventHandler(this.textBoxOPERAND_Click);
//
// labelDetail
//
View
24 Assembly Simulator/InstructionView.cs
@@ -13,9 +13,10 @@ namespace Assembly_Simulator
public partial class InstructionView : UserControl
{
private Main parent;
+ private bool validatedInput;
// Initialisation Code
- public InstructionView(string name, string detail, string OPCODE, int colour, Main p)
+ public InstructionView(string name, string detail, string OPCODE, int colour, string vI, Main p)
{
InitializeComponent();
labelName.Text = name;
@@ -44,7 +45,14 @@ public InstructionView(string name, string detail, string OPCODE, int colour, Ma
changeColour(Color.FromName("GradientInactiveCaption"));
break;
}
-
+
+ if (vI == "yes")
+ {
+ validatedInput = true;
+ } else {
+ validatedInput = false;
+ }
+
parent = p;
// Set other values
@@ -107,9 +115,15 @@ private void addInstruction_Click(object sender, EventArgs e)
// TODO: get this to work with tabbing in to the box rather than clicking on it.
private void textBoxOPERAND_Click(object sender, EventArgs e)
{
- Control c = (Control)sender;
- ((TextBox)sender).Text = parent.getValidatedInput(c);
- this.addInstruction.Select();
+ if (validatedInput) {
+ Control c = (Control)sender;
+ ((TextBox)sender).Text = parent.getValidatedInput(c, true);
+ this.addInstruction.Select();
+ } else {
+ Control c = (Control)sender;
+ ((TextBox)sender).Text = parent.getValidatedInput(c, false);
+ this.addInstruction.Select();
+ }
}
}
}
View
25 Assembly Simulator/Main.cs
@@ -39,7 +39,7 @@ public Main()
string[,] opcodes = parser.GetInstructions();
- for (int i = 0; i < (opcodes.Length / 4); i++)
+ for (int i = 0; i < (opcodes.Length / 5); i++)
{
InstructionView newInstruction
= new InstructionView(
@@ -47,6 +47,7 @@ InstructionView newInstruction
opcodes[i, 1],
opcodes[i, 2],
Convert.ToInt32(opcodes[i, 3]),
+ opcodes[i, 4],
this);
instructionFlowPanel.Controls.Add(newInstruction);
}
@@ -328,7 +329,7 @@ private void newButton_Click(object sender, EventArgs e)
RAM_OutOfDate = true;
processor.reset("all");
updateProcessorValues();
- mainFormTabs.SelectTab(tabExecute);
+ mainFormTabs.SelectTab(tabWrite);
updateCPUDiagramValues();
}
}
@@ -644,8 +645,17 @@ private void saveButton_Click(object sender, EventArgs e)
{
StreamWriter s;
s = File.CreateText(save.FileName);
+ bool error = false;
foreach (ProgramInstruction i in instructions)
{
+ if (i.label.Length > 20)
+ {
+ i.label = i.label.Substring(0, 20);
+ if (!error)
+ {
+ MessageBox.Show("One or more of your labels has exceeded the maximum length of 20 characters. To continue saving it has been shortened automatically.", "Error Saving File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ }
+ }
s.WriteLine(i.saveableInstruction());
}
s.Close();
@@ -719,10 +729,14 @@ private DialogResult new_program()
#endregion
- internal string getValidatedInput(Control control)
+ internal string getValidatedInput(Control control, bool allowLabel)
{
ValidationWindow v = new ValidationWindow();
TextBox x = (TextBox)control;
+ if (allowLabel)
+ {
+ v.allowLabel();
+ }
this.TopMost = true;
if (v.ShowDialog(this) == DialogResult.OK)
@@ -737,6 +751,11 @@ internal string getValidatedInput(Control control)
this.TopMost = false;
return v.rah.Text.Insert(0, "#");
}
+ if (v.textboxLabel.Text != "")
+ {
+ this.TopMost = false;
+ return v.textboxLabel.Text;
+ }
else
{
// Fail
View
31 Assembly Simulator/ValidationWindow.Designer.cs 100644 → 100755
@@ -41,6 +41,8 @@ private void InitializeComponent()
this.rab = new Assembly_Simulator.EnhancedTextBox();
this.evb = new Assembly_Simulator.EnhancedTextBox();
this.button1 = new System.Windows.Forms.Button();
+ this.textboxLabel = new Assembly_Simulator.EnhancedTextBox();
+ this.labelLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
@@ -92,7 +94,7 @@ private void InitializeComponent()
//
this.buttonOK.BackColor = System.Drawing.SystemColors.Menu;
this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
- this.buttonOK.Location = new System.Drawing.Point(336, 98);
+ this.buttonOK.Location = new System.Drawing.Point(336, 135);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 3;
@@ -155,7 +157,7 @@ private void InitializeComponent()
//
// button1
//
- this.button1.Location = new System.Drawing.Point(255, 99);
+ this.button1.Location = new System.Drawing.Point(255, 135);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 11;
@@ -163,14 +165,35 @@ private void InitializeComponent()
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
+ // textboxLabel
+ //
+ this.textboxLabel.Location = new System.Drawing.Point(99, 105);
+ this.textboxLabel.Name = "textboxLabel";
+ this.textboxLabel.Size = new System.Drawing.Size(100, 21);
+ this.textboxLabel.TabIndex = 12;
+ this.textboxLabel.Visible = false;
+ this.textboxLabel.TextChanged += new System.EventHandler(this.textboxLabel_TextChanged);
+ //
+ // labelLabel
+ //
+ this.labelLabel.AutoSize = true;
+ this.labelLabel.Location = new System.Drawing.Point(52, 108);
+ this.labelLabel.Name = "labelLabel";
+ this.labelLabel.Size = new System.Drawing.Size(41, 15);
+ this.labelLabel.TabIndex = 13;
+ this.labelLabel.Text = "Label:";
+ this.labelLabel.Visible = false;
+ //
// ValidationWindow
//
this.AcceptButton = this.buttonOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.GradientActiveCaption;
- this.ClientSize = new System.Drawing.Size(439, 134);
+ this.ClientSize = new System.Drawing.Size(439, 175);
this.ControlBox = false;
+ this.Controls.Add(this.labelLabel);
+ this.Controls.Add(this.textboxLabel);
this.Controls.Add(this.button1);
this.Controls.Add(this.rad);
this.Controls.Add(this.evd);
@@ -214,5 +237,7 @@ private void InitializeComponent()
private EnhancedTextBox evd;
private EnhancedTextBox rad;
private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Label labelLabel;
+ public EnhancedTextBox textboxLabel;
}
}
View
17 Assembly Simulator/ValidationWindow.cs 100644 → 100755
@@ -111,5 +111,22 @@ private void button1_Click(object sender, EventArgs e)
this.DialogResult = DialogResult.Cancel;
this.Close();
}
+
+ public void allowLabel()
+ {
+ this.labelLabel.Visible = true;
+ this.textboxLabel.Visible = true;
+ }
+
+ private void textboxLabel_TextChanged(object sender, EventArgs e)
+ {
+ // Clear other boxes
+ evh.Clear();
+ evd.Clear();
+ evb.Clear();
+ rah.Clear();
+ rad.Clear();
+ rab.Clear();
+ }
}
}
View
0  Assembly Simulator/ValidationWindow.resx 100644 → 100755
File mode changed
View
6 Assembly Simulator/XMLInstructionParser.cs
@@ -33,7 +33,7 @@ public XMLInstructionParser(string path)
}
reader.Close();
- string[,] instructionArray = new string[index, 4];
+ string[,] instructionArray = new string[index, 5];
index = 0;
// This has been changed to use the Instructions.dat file embedded in the application file
reader = XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("Assembly_Simulator." + pathToXML));
@@ -58,6 +58,10 @@ public XMLInstructionParser(string path)
instructionArray[index, 3] =
reader.ReadElementContentAsString("colour", reader.NamespaceURI);
+ reader.ReadToFollowing("allowlabel");
+ instructionArray[index, 4] =
+ reader.ReadElementContentAsString("allowlabel", reader.NamespaceURI);
+
index++;
}
View
107 TextMateProject.tmproj
@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>currentDocument</key>
- <string>Assembly Simulator/CPU.cs</string>
+ <string>Assembly Simulator/InstructionList.dat</string>
<key>documents</key>
<array>
<dict>
@@ -18,7 +18,7 @@
</dict>
</array>
<key>fileHierarchyDrawerWidth</key>
- <integer>200</integer>
+ <integer>149</integer>
<key>metaData</key>
<dict>
<key>Assembly Simulator/CPU.cs</key>
@@ -26,28 +26,114 @@
<key>caret</key>
<dict>
<key>column</key>
- <integer>40</integer>
+ <integer>13</integer>
<key>line</key>
- <integer>372</integer>
+ <integer>224</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
- <integer>353</integer>
+ <integer>205</integer>
+ </dict>
+ <key>Assembly Simulator/EnhancedTextBox.cs</key>
+ <dict>
+ <key>caret</key>
+ <dict>
+ <key>column</key>
+ <integer>80</integer>
+ <key>line</key>
+ <integer>26</integer>
+ </dict>
+ <key>firstVisibleColumn</key>
+ <integer>0</integer>
+ <key>firstVisibleLine</key>
+ <integer>57</integer>
+ </dict>
+ <key>Assembly Simulator/InstructionList.dat</key>
+ <dict>
+ <key>caret</key>
+ <dict>
+ <key>column</key>
+ <integer>13</integer>
+ <key>line</key>
+ <integer>22</integer>
+ </dict>
+ <key>firstVisibleColumn</key>
+ <integer>0</integer>
+ <key>firstVisibleLine</key>
+ <integer>0</integer>
+ </dict>
+ <key>Assembly Simulator/InstructionView.cs</key>
+ <dict>
+ <key>caret</key>
+ <dict>
+ <key>column</key>
+ <integer>71</integer>
+ <key>line</key>
+ <integer>123</integer>
+ </dict>
+ <key>firstVisibleColumn</key>
+ <integer>0</integer>
+ <key>firstVisibleLine</key>
+ <integer>0</integer>
</dict>
<key>Assembly Simulator/Main.cs</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
+ <integer>39</integer>
+ <key>line</key>
+ <integer>647</integer>
+ </dict>
+ <key>firstVisibleColumn</key>
+ <integer>0</integer>
+ <key>firstVisibleLine</key>
+ <integer>622</integer>
+ </dict>
+ <key>Assembly Simulator/ValidationWindow.cs</key>
+ <dict>
+ <key>caret</key>
+ <dict>
+ <key>column</key>
<integer>0</integer>
<key>line</key>
- <integer>209</integer>
+ <integer>0</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
- <integer>19</integer>
+ <integer>0</integer>
+ </dict>
+ <key>Assembly Simulator/XMLInstructionParser.cs</key>
+ <dict>
+ <key>caret</key>
+ <dict>
+ <key>column</key>
+ <integer>74</integer>
+ <key>line</key>
+ <integer>62</integer>
+ </dict>
+ <key>columnSelection</key>
+ <false/>
+ <key>firstVisibleColumn</key>
+ <integer>0</integer>
+ <key>firstVisibleLine</key>
+ <integer>23</integer>
+ <key>selectFrom</key>
+ <dict>
+ <key>column</key>
+ <integer>4</integer>
+ <key>line</key>
+ <integer>60</integer>
+ </dict>
+ <key>selectTo</key>
+ <dict>
+ <key>column</key>
+ <integer>74</integer>
+ <key>line</key>
+ <integer>62</integer>
+ </dict>
</dict>
<key>README</key>
<dict>
@@ -67,7 +153,12 @@
<key>openDocuments</key>
<array>
<string>Assembly Simulator/Main.cs</string>
+ <string>Assembly Simulator/InstructionList.dat</string>
<string>Assembly Simulator/CPU.cs</string>
+ <string>Assembly Simulator/InstructionView.cs</string>
+ <string>Assembly Simulator/XMLInstructionParser.cs</string>
+ <string>Assembly Simulator/ValidationWindow.cs</string>
+ <string>Assembly Simulator/EnhancedTextBox.cs</string>
<string>README</string>
</array>
<key>showFileHierarchyDrawer</key>
@@ -93,6 +184,6 @@
</dict>
</dict>
<key>windowFrame</key>
- <string>{{193, 4}, {1033, 874}}</string>
+ <string>{{0, 4}, {1440, 874}}</string>
</dict>
</plist>

0 comments on commit 957e41d

Please sign in to comment.
Something went wrong with that request. Please try again.