aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRogueAI42 <[email protected]>2017-06-19 17:30:55 +1000
committerRogueAI42 <[email protected]>2017-06-19 17:30:55 +1000
commit40b4c29b969f97004ec51c3c22b4b8263fadbef4 (patch)
tree47004bfe852f64fdffac626c673ab60b79679f35
parentb453978afc994eec4cd328f7b9348a1e263e097f (diff)
downloadshiftos_thereturn-40b4c29b969f97004ec51c3c22b4b8263fadbef4.tar.gz
shiftos_thereturn-40b4c29b969f97004ec51c3c22b4b8263fadbef4.tar.bz2
shiftos_thereturn-40b4c29b969f97004ec51c3c22b4b8263fadbef4.zip
Fixed keyboard input & instruction pointer display
-rw-r--r--ShiftOS.WinForms/Applications/MindBlow.cs8
-rw-r--r--ShiftOS_TheReturn/BFInterpreter.cs105
2 files changed, 61 insertions, 52 deletions
diff --git a/ShiftOS.WinForms/Applications/MindBlow.cs b/ShiftOS.WinForms/Applications/MindBlow.cs
index 15361c2..4fcda03 100644
--- a/ShiftOS.WinForms/Applications/MindBlow.cs
+++ b/ShiftOS.WinForms/Applications/MindBlow.cs
@@ -22,6 +22,7 @@ namespace ShiftOS.WinForms.Applications
{
private TextBox box;
private KeysConverter kc;
+ public KeyPressEventHandler handler;
public TextBoxStream(TextBox mybox)
{
kc = new KeysConverter();
@@ -55,7 +56,7 @@ namespace ShiftOS.WinForms.Applications
{
object lck = new object();
int ptr = offset;
- KeyPressEventHandler handler = (o, a) =>
+ handler = (o, a) =>
{
lock (lck)
{
@@ -98,6 +99,7 @@ namespace ShiftOS.WinForms.Applications
private static string[] DefaultMem;
private BFInterpreter Interpreter;
private Thread InterpreterThread;
+ private TextBoxStream consolestr;
private void DoLayout()
{
memlist.Left = 0;
@@ -121,7 +123,8 @@ namespace ShiftOS.WinForms.Applications
for (ushort i = 0; i < 30000; i++)
DefaultMem[i] = "0";
memlist.Items.AddRange(DefaultMem);
- Interpreter = new BFInterpreter(new TextBoxStream(consoleout), this);
+ consolestr = new TextBoxStream(consoleout);
+ Interpreter = new BFInterpreter(consolestr, this);
}
public void IPtrMoved(int newval)
@@ -212,6 +215,7 @@ namespace ShiftOS.WinForms.Applications
InterpreterThread.Abort();
}
catch { }
+ consoleout.KeyPress -= consolestr.handler;
}
private void reset_Click(object sender, EventArgs e)
diff --git a/ShiftOS_TheReturn/BFInterpreter.cs b/ShiftOS_TheReturn/BFInterpreter.cs
index 985e2ee..da4b44e 100644
--- a/ShiftOS_TheReturn/BFInterpreter.cs
+++ b/ShiftOS_TheReturn/BFInterpreter.cs
@@ -62,60 +62,65 @@ namespace ShiftOS.Engine
Reset();
lst = listener;
}
- public void Execute(string program)
+ public void Execute(string program, int offset = 0)
{
int c = 0;
lock (lck)
- while (c < program.Length)
- switch (program[c++])
+ while (c < program.Length)
{
- 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");
+ 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, offset + oldc);
+
+ }
+ break;
+ case ']':
+ throw new Exception("Unbalanced brackets");
+ }
+ if (lst != null)
+ lst.IPtrMoved(offset + c);
}
}
public void Execute()