aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/BFInterpreter.cs
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 /ShiftOS_TheReturn/BFInterpreter.cs
parentb453978afc994eec4cd328f7b9348a1e263e097f (diff)
downloadshiftos_thereturn-40b4c29b969f97004ec51c3c22b4b8263fadbef4.tar.gz
shiftos_thereturn-40b4c29b969f97004ec51c3c22b4b8263fadbef4.tar.bz2
shiftos_thereturn-40b4c29b969f97004ec51c3c22b4b8263fadbef4.zip
Fixed keyboard input & instruction pointer display
Diffstat (limited to 'ShiftOS_TheReturn/BFInterpreter.cs')
-rw-r--r--ShiftOS_TheReturn/BFInterpreter.cs105
1 files changed, 55 insertions, 50 deletions
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()