MindBlow tweaks

* MindBlow now lets you reset memory before you start a new
program, and kill one that is still executing
* The MindBlow site now uses the correct button theme
This commit is contained in:
RogueAI42 2017-06-19 17:03:51 +10:00
parent 45c587b3a6
commit b453978afc
4 changed files with 187 additions and 137 deletions

View file

@ -30,16 +30,18 @@
{
this.tabs = new System.Windows.Forms.TabControl();
this.console = new System.Windows.Forms.TabPage();
this.program = new System.Windows.Forms.TabPage();
this.monitor = new System.Windows.Forms.TabPage();
this.consoleout = new System.Windows.Forms.TextBox();
this.programinput = new System.Windows.Forms.TextBox();
this.load = new System.Windows.Forms.Button();
this.save = new System.Windows.Forms.Button();
this.memptr = new System.Windows.Forms.Label();
this.instptr = new System.Windows.Forms.Label();
this.memlist = new System.Windows.Forms.ListBox();
this.program = new System.Windows.Forms.TabPage();
this.run = new System.Windows.Forms.Button();
this.save = new System.Windows.Forms.Button();
this.load = new System.Windows.Forms.Button();
this.programinput = new System.Windows.Forms.TextBox();
this.monitor = new System.Windows.Forms.TabPage();
this.memlist = new System.Windows.Forms.ListBox();
this.instptr = new System.Windows.Forms.Label();
this.memptr = new System.Windows.Forms.Label();
this.stop = new System.Windows.Forms.Button();
this.reset = new System.Windows.Forms.Button();
this.tabs.SuspendLayout();
this.console.SuspendLayout();
this.program.SuspendLayout();
@ -70,8 +72,19 @@
this.console.Text = "Console";
this.console.UseVisualStyleBackColor = true;
//
// consoleout
//
this.consoleout.Dock = System.Windows.Forms.DockStyle.Fill;
this.consoleout.Location = new System.Drawing.Point(3, 3);
this.consoleout.Multiline = true;
this.consoleout.Name = "consoleout";
this.consoleout.ReadOnly = true;
this.consoleout.Size = new System.Drawing.Size(378, 237);
this.consoleout.TabIndex = 0;
//
// program
//
this.program.Controls.Add(this.stop);
this.program.Controls.Add(this.run);
this.program.Controls.Add(this.save);
this.program.Controls.Add(this.load);
@ -84,27 +97,35 @@
this.program.Text = "Program";
this.program.UseVisualStyleBackColor = true;
//
// monitor
// run
//
this.monitor.Controls.Add(this.memlist);
this.monitor.Controls.Add(this.instptr);
this.monitor.Controls.Add(this.memptr);
this.monitor.Location = new System.Drawing.Point(4, 22);
this.monitor.Name = "monitor";
this.monitor.Size = new System.Drawing.Size(384, 243);
this.monitor.TabIndex = 2;
this.monitor.Text = "Monitor";
this.monitor.UseVisualStyleBackColor = true;
this.run.Location = new System.Drawing.Point(196, 217);
this.run.Name = "run";
this.run.Size = new System.Drawing.Size(101, 23);
this.run.TabIndex = 3;
this.run.Text = "Run";
this.run.UseVisualStyleBackColor = true;
this.run.Click += new System.EventHandler(this.run_Click);
//
// consoleout
// save
//
this.consoleout.Dock = System.Windows.Forms.DockStyle.Fill;
this.consoleout.Location = new System.Drawing.Point(3, 3);
this.consoleout.Multiline = true;
this.consoleout.Name = "consoleout";
this.consoleout.ReadOnly = true;
this.consoleout.Size = new System.Drawing.Size(378, 237);
this.consoleout.TabIndex = 0;
this.save.Location = new System.Drawing.Point(102, 217);
this.save.Name = "save";
this.save.Size = new System.Drawing.Size(88, 23);
this.save.TabIndex = 2;
this.save.Text = "Save";
this.save.UseVisualStyleBackColor = true;
this.save.Click += new System.EventHandler(this.save_Click);
//
// load
//
this.load.Location = new System.Drawing.Point(6, 217);
this.load.Name = "load";
this.load.Size = new System.Drawing.Size(90, 23);
this.load.TabIndex = 1;
this.load.Text = "Load";
this.load.UseVisualStyleBackColor = true;
this.load.Click += new System.EventHandler(this.load_Click);
//
// programinput
//
@ -114,43 +135,18 @@
this.programinput.Size = new System.Drawing.Size(378, 218);
this.programinput.TabIndex = 0;
//
// load
// monitor
//
this.load.Location = new System.Drawing.Point(6, 217);
this.load.Name = "load";
this.load.Size = new System.Drawing.Size(115, 23);
this.load.TabIndex = 1;
this.load.Text = "Load";
this.load.UseVisualStyleBackColor = true;
this.load.Click += new System.EventHandler(this.load_Click);
//
// save
//
this.save.Location = new System.Drawing.Point(127, 217);
this.save.Name = "save";
this.save.Size = new System.Drawing.Size(114, 23);
this.save.TabIndex = 2;
this.save.Text = "Save";
this.save.UseVisualStyleBackColor = true;
this.save.Click += new System.EventHandler(this.save_Click);
//
// memptr
//
this.memptr.AutoSize = true;
this.memptr.Location = new System.Drawing.Point(8, 8);
this.memptr.Name = "memptr";
this.memptr.Size = new System.Drawing.Size(56, 13);
this.memptr.TabIndex = 0;
this.memptr.Text = "Memory: 0";
//
// instptr
//
this.instptr.AutoSize = true;
this.instptr.Location = new System.Drawing.Point(8, 21);
this.instptr.Name = "instptr";
this.instptr.Size = new System.Drawing.Size(68, 13);
this.instptr.TabIndex = 1;
this.instptr.Text = "Instruction: 0";
this.monitor.Controls.Add(this.reset);
this.monitor.Controls.Add(this.memlist);
this.monitor.Controls.Add(this.instptr);
this.monitor.Controls.Add(this.memptr);
this.monitor.Location = new System.Drawing.Point(4, 22);
this.monitor.Name = "monitor";
this.monitor.Size = new System.Drawing.Size(384, 243);
this.monitor.TabIndex = 2;
this.monitor.Text = "Monitor";
this.monitor.UseVisualStyleBackColor = true;
//
// memlist
//
@ -162,15 +158,44 @@
this.memlist.Size = new System.Drawing.Size(370, 199);
this.memlist.TabIndex = 2;
//
// run
// instptr
//
this.run.Location = new System.Drawing.Point(247, 217);
this.run.Name = "run";
this.run.Size = new System.Drawing.Size(131, 23);
this.run.TabIndex = 3;
this.run.Text = "Run";
this.run.UseVisualStyleBackColor = true;
this.run.Click += new System.EventHandler(this.run_Click);
this.instptr.AutoSize = true;
this.instptr.Location = new System.Drawing.Point(8, 21);
this.instptr.Name = "instptr";
this.instptr.Size = new System.Drawing.Size(68, 13);
this.instptr.TabIndex = 1;
this.instptr.Text = "Instruction: 0";
//
// memptr
//
this.memptr.AutoSize = true;
this.memptr.Location = new System.Drawing.Point(8, 8);
this.memptr.Name = "memptr";
this.memptr.Size = new System.Drawing.Size(56, 13);
this.memptr.TabIndex = 0;
this.memptr.Text = "Memory: 0";
//
// stop
//
this.stop.Location = new System.Drawing.Point(303, 217);
this.stop.Name = "stop";
this.stop.Size = new System.Drawing.Size(75, 23);
this.stop.TabIndex = 4;
this.stop.Text = "Stop";
this.stop.UseVisualStyleBackColor = true;
this.stop.Click += new System.EventHandler(this.stop_Click);
//
// reset
//
this.reset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.reset.Location = new System.Drawing.Point(306, 8);
this.reset.Name = "reset";
this.reset.Size = new System.Drawing.Size(75, 23);
this.reset.TabIndex = 3;
this.reset.Text = "Reset";
this.reset.UseVisualStyleBackColor = true;
this.reset.Click += new System.EventHandler(this.reset_Click);
//
// MindBlow
//
@ -205,5 +230,7 @@
private System.Windows.Forms.Label memptr;
private System.Windows.Forms.ListBox memlist;
private System.Windows.Forms.Button run;
private System.Windows.Forms.Button stop;
private System.Windows.Forms.Button reset;
}
}

View file

@ -59,8 +59,11 @@ namespace ShiftOS.WinForms.Applications
{
lock (lck)
{
buffer[ptr] = (byte)a.KeyChar;
ptr++;
if (ptr < offset + count)
{
buffer[ptr] = (byte)a.KeyChar;
ptr++;
}
}
};
Desktop.InvokeOnWorkerThread(() => box.KeyPress += handler);
@ -94,7 +97,7 @@ namespace ShiftOS.WinForms.Applications
}
private static string[] DefaultMem;
private BFInterpreter Interpreter;
private Thread InterpreterThread;
private void DoLayout()
{
memlist.Left = 0;
@ -104,9 +107,11 @@ namespace ShiftOS.WinForms.Applications
program.Left = 0;
programinput.Width = program.Width;
programinput.Height = program.Height - load.Height;
load.Top = save.Top = run.Top = programinput.Height;
load.Width = save.Width = run.Width = save.Left = program.Width / 3;
load.Top = save.Top = run.Top = stop.Top = programinput.Height;
load.Width = save.Width = run.Width = stop.Width = save.Left = program.Width / 4;
load.Left = 0;
run.Left = save.Left * 2;
stop.Left = save.Left * 3;
}
public MindBlow()
@ -168,18 +173,20 @@ namespace ShiftOS.WinForms.Applications
private void run_Click(object sender, EventArgs e)
{
new Thread(() =>
InterpreterThread = new Thread(() =>
{
try
{
Interpreter.Reset();
Interpreter.Execute(programinput.Text);
}
catch (ThreadAbortException) { } // ignore
catch (Exception ex)
{
Desktop.InvokeOnWorkerThread(() => Infobox.Show("Program Error", "An error occurred while executing your program: " + ex.GetType().ToString()));
}
}).Start();
});
InterpreterThread.Start();
}
private void tabs_Selected(object sender, TabControlEventArgs e)
@ -196,5 +203,24 @@ namespace ShiftOS.WinForms.Applications
{
AppearanceManager.SetupDialog(new FileDialog(new string[] { ".bf" }, FileOpenerStyle.Save, new Action<string>((file) => Objects.ShiftFS.Utils.WriteAllText(file, programinput.Text))));
}
private void stop_Click(object sender, EventArgs e)
{
if (InterpreterThread != null)
try
{
InterpreterThread.Abort();
}
catch { }
}
private void reset_Click(object sender, EventArgs e)
{
if (InterpreterThread != null)
if (InterpreterThread.IsAlive)
Infobox.Show("Cannot Reset", "The program is still running.");
else
Interpreter.Reset();
}
}
}

View file

@ -65,6 +65,7 @@ namespace ShiftOS.WinForms.ShiftnetSites
public void OnSkinLoad()
{
Tools.ControlManager.SetupControls(this);
}
public void OnUpgrade()

View file

@ -62,69 +62,65 @@ namespace ShiftOS.Engine
Reset();
lst = listener;
}
public void Execute()
{
lock (lck)
for (int iptr = 0; iptr < prg.Length; iptr++)
{
if (lst != null)
lst.IPtrMoved(iptr);
switch (prg[iptr])
{
case '>':
ptr++;
if (lst != null)
lst.PointerMoved(ptr);
break;
case '<':
ptr--;
if (lst != null)
lst.PointerMoved(ptr);
break;
case '+':
mem[ptr]++;
if (lst != null)
lst.MemChanged(ptr, mem[ptr]);
break;
case '-':
mem[ptr]--;
if (lst != null)
lst.MemChanged(ptr, mem[ptr]);
break;
case '.':
str.WriteByte(mem[ptr]);
break;
case ',':
mem[ptr] = (byte)str.ReadByte();
if (lst != null)
lst.MemChanged(ptr, mem[ptr]);
break;
case '[':
if (mem[ptr] == 0)
while (prg[iptr] != ']')
{
iptr++;
if (lst != null)
lst.IPtrMoved(iptr);
}
break;
case ']':
if (mem[ptr] != 0)
while (prg[iptr] != '[')
{
iptr--;
if (lst != null)
lst.IPtrMoved(iptr);
}
break;
}
}
}
public void Execute(string program)
{
int c = 0;
lock (lck)
prg = program;
Execute();
while (c < program.Length)
switch (program[c++])
{
case '<':
ptr--;
if (lst != null)
lst.PointerMoved(ptr);
break;
case '>':
ptr++;
if (lst != null)
lst.PointerMoved(ptr);
break;
case '+':
mem[ptr]++;
if (lst != null)
lst.MemChanged(ptr, mem[ptr]);
break;
case '-':
mem[ptr]--;
if (lst != null)
lst.MemChanged(ptr, mem[ptr]);
break;
case '.':
str.WriteByte(mem[ptr]);
break;
case ',':
mem[ptr] = (byte)str.ReadByte();
if (lst != null)
lst.MemChanged(ptr, mem[ptr]);
break;
case '[':
int b;
int oldc = c;
for (b = 1; b != 0 && c < program.Length; c++)
{
if (program[c] == '[')
b++;
else if (program[c] == ']')
b--;
}
if (b == 0)
{
string block = program.Substring(oldc, c - oldc - 1);
while (mem[ptr] != 0)
Execute(block);
}
break;
case ']':
throw new Exception("Unbalanced brackets");
}
}
public void Execute()
{
Execute(prg);
}
public void Reset()
{