aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
authorRogueAI42 <[email protected]>2017-06-19 17:03:51 +1000
committerRogueAI42 <[email protected]>2017-06-19 17:03:51 +1000
commitb453978afc994eec4cd328f7b9348a1e263e097f (patch)
tree583536eac945c1c9cff4a587a2cb13780227809a /ShiftOS_TheReturn
parent45c587b3a656135fec9c91566fa5f817ddfc600e (diff)
downloadshiftos_thereturn-b453978afc994eec4cd328f7b9348a1e263e097f.tar.gz
shiftos_thereturn-b453978afc994eec4cd328f7b9348a1e263e097f.tar.bz2
shiftos_thereturn-b453978afc994eec4cd328f7b9348a1e263e097f.zip
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
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/BFInterpreter.cs110
1 files changed, 53 insertions, 57 deletions
diff --git a/ShiftOS_TheReturn/BFInterpreter.cs b/ShiftOS_TheReturn/BFInterpreter.cs
index f2463a4..985e2ee 100644
--- a/ShiftOS_TheReturn/BFInterpreter.cs
+++ b/ShiftOS_TheReturn/BFInterpreter.cs
@@ -62,69 +62,65 @@ namespace ShiftOS.Engine
Reset();
lst = listener;
}
- public void Execute()
+ public void Execute(string program)
{
+ int c = 0;
lock (lck)
- for (int iptr = 0; iptr < prg.Length; iptr++)
+ while (c < program.Length)
+ switch (program[c++])
{
- 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;
- }
+ 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(string program)
+ public void Execute()
{
- lock (lck)
- prg = program;
- Execute();
+ Execute(prg);
}
public void Reset()
{