aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
authorRogueAI42 <[email protected]>2017-06-19 17:43:53 +1000
committerRogueAI42 <[email protected]>2017-06-19 17:48:02 +1000
commit1c9d527ba084dfca2548eb739536f7fbe7a2f086 (patch)
tree35403f1d8916c1f2eaa8770e9b1babeb66ab3876 /ShiftOS_TheReturn
parent40b4c29b969f97004ec51c3c22b4b8263fadbef4 (diff)
downloadshiftos_thereturn-1c9d527ba084dfca2548eb739536f7fbe7a2f086.tar.gz
shiftos_thereturn-1c9d527ba084dfca2548eb739536f7fbe7a2f086.tar.bz2
shiftos_thereturn-1c9d527ba084dfca2548eb739536f7fbe7a2f086.zip
Normalise newlines for BFInterpreter I/O
when the stream sends \r, the program will receive \n when the program sends \n, the stream will receive Environment.NewLine
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/BFInterpreter.cs12
1 files changed, 9 insertions, 3 deletions
diff --git a/ShiftOS_TheReturn/BFInterpreter.cs b/ShiftOS_TheReturn/BFInterpreter.cs
index da4b44e..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();
@@ -91,10 +93,15 @@ 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;
@@ -113,7 +120,6 @@ namespace ShiftOS.Engine
string block = program.Substring(oldc, c - oldc - 1);
while (mem[ptr] != 0)
Execute(block, offset + oldc);
-
}
break;
case ']':