From b453978afc994eec4cd328f7b9348a1e263e097f Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Mon, 19 Jun 2017 17:03:51 +1000 Subject: 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 --- ShiftOS_TheReturn/BFInterpreter.cs | 110 ++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 57 deletions(-) (limited to 'ShiftOS_TheReturn') 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() { -- cgit v1.2.3 From 40b4c29b969f97004ec51c3c22b4b8263fadbef4 Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Mon, 19 Jun 2017 17:30:55 +1000 Subject: Fixed keyboard input & instruction pointer display --- ShiftOS.WinForms/Applications/MindBlow.cs | 8 ++- ShiftOS_TheReturn/BFInterpreter.cs | 105 ++++++++++++++++-------------- 2 files changed, 61 insertions(+), 52 deletions(-) (limited to 'ShiftOS_TheReturn') 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() -- cgit v1.2.3 From 1c9d527ba084dfca2548eb739536f7fbe7a2f086 Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Mon, 19 Jun 2017 17:43:53 +1000 Subject: 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 --- ShiftOS_TheReturn/BFInterpreter.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'ShiftOS_TheReturn') 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 ']': -- cgit v1.2.3 From 49b31c7e847cc7aa9365880f9f92e0498f1450bd Mon Sep 17 00:00:00 2001 From: RogueAI42 Date: Mon, 19 Jun 2017 20:14:36 +1000 Subject: extra loading joke --- ShiftOS.WinForms/Resources/strings_en.txt | 1 + ShiftOS_TheReturn/SaveSystem.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'ShiftOS_TheReturn') diff --git a/ShiftOS.WinForms/Resources/strings_en.txt b/ShiftOS.WinForms/Resources/strings_en.txt index 9e17f11..55402ab 100644 --- a/ShiftOS.WinForms/Resources/strings_en.txt +++ b/ShiftOS.WinForms/Resources/strings_en.txt @@ -235,6 +235,7 @@ "{LOADINGMSG2_7}": "[systemd] There's no antidote...", "{LOADINGMSG2_8}": "[systemd] Can I at least have a muffin?", "{LOADINGMSG2_9}": "[systemd] System initiated, but I still want a cake.", + "{LOADINGMSG2_10}": "[sysvinit] Your init system has been upgraded.", //Format editor "{FORMATEDITOR_COMMAND_LOWER}": "command", 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(); -- cgit v1.2.3