aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
authorwilliam341 <[email protected]>2017-06-19 12:16:31 -0700
committerGitHub <[email protected]>2017-06-19 12:16:31 -0700
commit09e2268bc220b299ef2c1b8779c4df0b5ef4df3c (patch)
tree4ebdeea150ea168678d6b08c8d1d20d246ee6ac2 /ShiftOS_TheReturn
parentc22370d643008e55121c0ddeaca0b81d755573ff (diff)
parentdf37f3c366fe5884b17fa0b66d154536f8df93d2 (diff)
downloadshiftos_thereturn-09e2268bc220b299ef2c1b8779c4df0b5ef4df3c.tar.gz
shiftos_thereturn-09e2268bc220b299ef2c1b8779c4df0b5ef4df3c.tar.bz2
shiftos_thereturn-09e2268bc220b299ef2c1b8779c4df0b5ef4df3c.zip
Merge pull request #4 from shiftos-game/master
pulling
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/BFInterpreter.cs67
-rw-r--r--ShiftOS_TheReturn/SaveSystem.cs2
2 files changed, 38 insertions, 31 deletions
diff --git a/ShiftOS_TheReturn/BFInterpreter.cs b/ShiftOS_TheReturn/BFInterpreter.cs
index f2463a4..1ff5358 100644
--- a/ShiftOS_TheReturn/BFInterpreter.cs
+++ b/ShiftOS_TheReturn/BFInterpreter.cs
@@ -53,7 +53,9 @@ namespace ShiftOS.Engine
private Stream str;
public IBFListener lst = null;
-
+
+ private static byte[] newline = Encoding.UTF8.GetBytes(Environment.NewLine);
+
public BFInterpreter(Stream io, IBFListener listener = null, string program = "")
{
lck = new object();
@@ -62,22 +64,21 @@ namespace ShiftOS.Engine
Reset();
lst = listener;
}
- public void Execute()
+ public void Execute(string program, int offset = 0)
{
+ int c = 0;
lock (lck)
- for (int iptr = 0; iptr < prg.Length; iptr++)
+ while (c < program.Length)
{
- if (lst != null)
- lst.IPtrMoved(iptr);
- switch (prg[iptr])
+ switch (program[c++])
{
- case '>':
- ptr++;
+ case '<':
+ ptr--;
if (lst != null)
lst.PointerMoved(ptr);
break;
- case '<':
- ptr--;
+ case '>':
+ ptr++;
if (lst != null)
lst.PointerMoved(ptr);
break;
@@ -92,39 +93,45 @@ namespace ShiftOS.Engine
lst.MemChanged(ptr, mem[ptr]);
break;
case '.':
- str.WriteByte(mem[ptr]);
+ if (mem[ptr] == 10)
+ str.Write(newline, 0, newline.Length); // normalise newline
+ else
+ str.WriteByte(mem[ptr]);
break;
case ',':
mem[ptr] = (byte)str.ReadByte();
+ if (mem[ptr] == 13)
+ mem[ptr] = 10; // normalise newline
if (lst != null)
lst.MemChanged(ptr, mem[ptr]);
break;
case '[':
- if (mem[ptr] == 0)
- while (prg[iptr] != ']')
- {
- iptr++;
- if (lst != null)
- lst.IPtrMoved(iptr);
- }
+ 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 ']':
- if (mem[ptr] != 0)
- while (prg[iptr] != '[')
- {
- iptr--;
- if (lst != null)
- lst.IPtrMoved(iptr);
- }
- break;
+ throw new Exception("Unbalanced brackets");
}
+ if (lst != null)
+ lst.IPtrMoved(offset + c);
}
}
- public void Execute(string program)
+ public void Execute()
{
- lock (lck)
- prg = program;
- Execute();
+ Execute(prg);
}
public void Reset()
{
diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs
index 8cd4d9b..8cfea4a 100644
--- a/ShiftOS_TheReturn/SaveSystem.cs
+++ b/ShiftOS_TheReturn/SaveSystem.cs
@@ -107,7 +107,7 @@ namespace ShiftOS.Engine
SkinEngine.Init();
Random rnd = new Random();
int loadingJoke1 = rnd.Next(10);
- int loadingJoke2 = rnd.Next(10);
+ int loadingJoke2 = rnd.Next(11);
TerminalBackend.OpenTerminal();