Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/DEVICE_RAID' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottPiersall committed Dec 16, 2021
2 parents 69e4ff5 + 759c74f commit dbab1c1
Show file tree
Hide file tree
Showing 22 changed files with 1,067 additions and 158 deletions.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file added .vs/SICVM/v16/.suo
Binary file not shown.
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\C:\\Users\\dylan\\Source\\Repos\\SICVM",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
16 changes: 9 additions & 7 deletions SIC Simulator/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Assembler(string filePath)
StreamReader file = new StreamReader(filePath);
int memory_address = 0, line_counter = 0;
String output = "ASSEMBLY ERROR\n"; // error message header
String line, tmpLine;
String line;
pass_one();
if (_process == PROCESS.ERROR)
{
Expand Down Expand Up @@ -192,15 +192,17 @@ void pass_one()
{
while ((line = file.ReadLine()) != null)
{
tmpLine = line;
tmpLine = tmpLine.Trim();
//If there is a comment, remove it
line = line.Split('#')[0];

line_counter++;

if (String.IsNullOrEmpty(tmpLine) || tmpLine[0] == 35)
if (String.IsNullOrEmpty(line.Trim()))
{ // skip comments and blank lines
continue;
}


line = Regex.Replace(line, @"\s+(?=([^']*'[^']*')*[^']*$)", "\t"); // clean line for assembler

if (_process == PROCESS.END)
Expand Down Expand Up @@ -313,7 +315,7 @@ void pass_one()
}
else if (instruction_line.OpCode.Equals("WORD"))
{
if (Int32.TryParse(instruction_line.Operand, out len))
if (Int32.TryParse(instruction_line.Operand, out len) && (len >= -(1<<23)) && (len < (1<<23)))
{
memory_address += 3;
}
Expand All @@ -330,7 +332,7 @@ void pass_one()
}
else if (instruction_line.OpCode.Equals("RESW"))
{
if (Int32.TryParse(instruction_line.Operand, out len))
if (Int32.TryParse(instruction_line.Operand, out len) && len > 0)
{
memory_address += 3 * len;
}
Expand Down Expand Up @@ -371,7 +373,7 @@ void pass_one()
}
else if (instruction_line.OpCode.Equals("RESB"))
{
if (Int32.TryParse(instruction_line.Operand, out len))
if (Int32.TryParse(instruction_line.Operand, out len) && len > 0)
{
memory_address += len;
}
Expand Down
9 changes: 3 additions & 6 deletions SIC Simulator/Extensions/integer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ static class integerExtensions
public static string To24BITBinary(this int a)
{
string res = string.Empty;
if (a >= 0)
res = Convert.ToString(a, 2);
else
{
// Number is Negative... We have two push two's complement in 24 bits more elegantly
}
uint b = (uint)a;
b &= 0xFFFFFF; //only read 3 bytes
res = Convert.ToString(b, 2);
return res.PadLeft(24, '0'); ;
}
}
Expand Down
44 changes: 31 additions & 13 deletions SIC Simulator/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 98 additions & 3 deletions SIC Simulator/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using SIC_Simulator.Extensions;
using static System.Windows.Forms.ListViewItem;
using System.Diagnostics;
using System.Drawing;
using System.Media;


Expand Down Expand Up @@ -163,14 +164,20 @@ private async Task DeviceRefreshAsync()
{ // update the sub list views with data found in the device array
try
{
this.lvDevices.Items[i].SubItems[1].Text = this.SICVirtualMachine.Devices[i].GetWriteBufferASCIIByteString;
// this.lvDevices.Items[i].SubItems[1].Text = this.SICVirtualMachine.Devices[i].GetWriteBufferASCIIByteString;
this.lvDevices.Items[i].SubItems[1].Text = this.SICVirtualMachine.Devices[i].GetASCIIStringWrites();
this.lvDevices.Items[i].SubItems[2].Text = this.SICVirtualMachine.Devices[i].GetHEXStringWrites();

}catch(NullReferenceException)
{
this.lvDevices.Items[i].SubItems[1].Text = "";
}


}
}


/// <summary>
/// Refreshes Memory Display on background thread. Calls are marshalled to UI thread
/// </summary>
Expand Down Expand Up @@ -411,6 +418,13 @@ private async Task RegRefreshAsync()
txtPC_Hex.Text = SICVirtualMachine.PC.ToString("X6");
txtSW_Hex.Text = SICVirtualMachine.SW.ToString("X6");

//remove leading characters in case value is negative
txtX_Hex.Text = txtX_Hex.Text.Substring(txtX_Hex.Text.Length - 6);
txtA_Hex.Text = txtA_Hex.Text.Substring(txtA_Hex.Text.Length - 6);
txtL_Hex.Text = txtL_Hex.Text.Substring(txtL_Hex.Text.Length - 6);
txtPC_Hex.Text = txtPC_Hex.Text.Substring(txtPC_Hex.Text.Length - 6);
txtSW_Hex.Text = txtSW_Hex.Text.Substring(txtSW_Hex.Text.Length - 6);

txtX_Dec.Text = SICVirtualMachine.X.ToString();
txtA_Dec.Text = SICVirtualMachine.A.ToString();
txtL_Dec.Text = SICVirtualMachine.L.ToString();
Expand Down Expand Up @@ -727,6 +741,7 @@ private void Form1_Load(object sender, EventArgs e)
{ //seed lsit view for devices with 64 items
ListViewItem lvItem = new ListViewItem(String.Format("{0,2:D2}", i));
lvItem.SubItems.Add("");
lvItem.SubItems.Add("");
this.lvDevices.Items.Add(lvItem);
}
lvDevices.View = View.Details;
Expand Down Expand Up @@ -893,14 +908,94 @@ private void loadObjectFileToolStripMenuItem_Click(object sender, EventArgs e)

}

private void loadSICSourceFD_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
private void resetSICDevicesToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult Result;

Result = MessageBox.Show("This will clear all SIC Devices. Are you sure you want to proceed?", "Confirm", MessageBoxButtons.YesNo);

if (Result == DialogResult.Yes)
{
for (int i = 0; i < SIC_CPU.NumDevices; i++)
{
this.SICVirtualMachine.Devices[i].reset();
}
this.RefreshCPUDisplays();
}
}

private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
private void lvDevices_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Right) { return; }
ListViewHitTestInfo ht = lvDevices.HitTest(e.X, e.Y);
ContextMenu ct = new ContextMenu();
int deviceNum = ht.Item.Index;
if (ht.Location == ListViewHitTestLocations.Label)
{
MenuItem title = new MenuItem("Device " + deviceNum);
title.Enabled = false;
ct.MenuItems.Add(title);

MenuItem resetDeviceMenuOption = new MenuItem("Reset Device");
resetDeviceMenuOption.Click += resetDevice;
ct.MenuItems.Add(resetDeviceMenuOption);

MenuItem addStringMenuOption = new MenuItem("Write String to Device");
addStringMenuOption.Click += addString;
ct.MenuItems.Add(addStringMenuOption);

MenuItem setHexMenuOption = new MenuItem("Set Device Contents");
setHexMenuOption.Click += setHex;
ct.MenuItems.Add(setHexMenuOption);

ct.Show(lvDevices, new Point(e.X, e.Y));
}
//local methods for menu items
void resetDevice(object s, EventArgs ev)
{
DialogResult Result;

Result = MessageBox.Show("This will clear SIC Device " + deviceNum +
"\nAre you sure you want to proceed?", "Confirm", MessageBoxButtons.YesNo);

if (Result == DialogResult.Yes)
{
this.SICVirtualMachine.Devices[deviceNum].reset();
this.RefreshCPUDisplays();
}
}
void addString(object s, EventArgs ev)
{
dlgWriteStringToDevice strToDevice = new dlgWriteStringToDevice();

DialogResult result = strToDevice.ShowDialog();

if (result == DialogResult.Cancel)
{
return;
}

this.SICVirtualMachine.Devices[deviceNum].WriteString(strToDevice.result);

this.RefreshCPUDisplays();
}


void setHex(object s, EventArgs ev)
{
dlgSetDeviceContent devContent = new dlgSetDeviceContent(this.SICVirtualMachine.Devices[deviceNum].GetHEXStringWrites());
DialogResult Result = devContent.ShowDialog();

if (Result == DialogResult.Cancel)
{
return;
}

this.SICVirtualMachine.Devices[deviceNum].WriteBuffer = devContent.result;
this.SICVirtualMachine.Devices[deviceNum].status = devContent.result.Count > 0 ? 2 : 1;

this.RefreshCPUDisplays();
}
}
}
}
Loading

0 comments on commit dbab1c1

Please sign in to comment.