diff options
| author | RogueAI42 <[email protected]> | 2017-06-17 19:16:50 +1000 |
|---|---|---|
| committer | RogueAI42 <[email protected]> | 2017-06-17 19:16:50 +1000 |
| commit | dbf794c9849c0046cf2e93a878c6d8d9101d2fc8 (patch) | |
| tree | d5ff20daf283fff179f0ddb79b07edafd59c613a /ShiftOS.WinForms/Applications | |
| parent | 77cb4a9a14de07023e86a9a5cda7171fcb4ec8ec (diff) | |
| download | shiftos_thereturn-dbf794c9849c0046cf2e93a878c6d8d9101d2fc8.tar.gz shiftos_thereturn-dbf794c9849c0046cf2e93a878c6d8d9101d2fc8.tar.bz2 shiftos_thereturn-dbf794c9849c0046cf2e93a878c6d8d9101d2fc8.zip | |
MindBlow: Brainfuck IDE for ShiftOS
For 50,000 Codepoints you can write and run Brainfuck programs in
a dedicated IDE. Check out the site on "shiftnet/mindblow".
The IDE seems to be working perfectly. The site has some theming
issues.
Diffstat (limited to 'ShiftOS.WinForms/Applications')
| -rw-r--r-- | ShiftOS.WinForms/Applications/MindBlow.Designer.cs | 209 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Applications/MindBlow.cs | 183 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Applications/MindBlow.resx | 120 |
3 files changed, 512 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/Applications/MindBlow.Designer.cs b/ShiftOS.WinForms/Applications/MindBlow.Designer.cs new file mode 100644 index 0000000..da269f6 --- /dev/null +++ b/ShiftOS.WinForms/Applications/MindBlow.Designer.cs @@ -0,0 +1,209 @@ +namespace ShiftOS.WinForms.Applications +{ + partial class MindBlow + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.tabs = new System.Windows.Forms.TabControl(); + this.console = new System.Windows.Forms.TabPage(); + this.program = new System.Windows.Forms.TabPage(); + this.monitor = new System.Windows.Forms.TabPage(); + this.consoleout = new System.Windows.Forms.TextBox(); + this.programinput = new System.Windows.Forms.TextBox(); + this.load = new System.Windows.Forms.Button(); + this.save = new System.Windows.Forms.Button(); + this.memptr = new System.Windows.Forms.Label(); + this.instptr = new System.Windows.Forms.Label(); + this.memlist = new System.Windows.Forms.ListBox(); + this.run = new System.Windows.Forms.Button(); + this.tabs.SuspendLayout(); + this.console.SuspendLayout(); + this.program.SuspendLayout(); + this.monitor.SuspendLayout(); + this.SuspendLayout(); + // + // tabs + // + this.tabs.Controls.Add(this.console); + this.tabs.Controls.Add(this.program); + this.tabs.Controls.Add(this.monitor); + this.tabs.Dock = System.Windows.Forms.DockStyle.Fill; + this.tabs.Location = new System.Drawing.Point(0, 0); + this.tabs.Name = "tabs"; + this.tabs.SelectedIndex = 0; + this.tabs.Size = new System.Drawing.Size(392, 269); + this.tabs.TabIndex = 0; + this.tabs.Selected += new System.Windows.Forms.TabControlEventHandler(this.tabs_Selected); + // + // console + // + this.console.Controls.Add(this.consoleout); + this.console.Location = new System.Drawing.Point(4, 22); + this.console.Name = "console"; + this.console.Padding = new System.Windows.Forms.Padding(3); + this.console.Size = new System.Drawing.Size(384, 243); + this.console.TabIndex = 0; + this.console.Text = "Console"; + this.console.UseVisualStyleBackColor = true; + // + // program + // + this.program.Controls.Add(this.run); + this.program.Controls.Add(this.save); + this.program.Controls.Add(this.load); + this.program.Controls.Add(this.programinput); + this.program.Location = new System.Drawing.Point(4, 22); + this.program.Name = "program"; + this.program.Padding = new System.Windows.Forms.Padding(3); + this.program.Size = new System.Drawing.Size(384, 243); + this.program.TabIndex = 1; + this.program.Text = "Program"; + this.program.UseVisualStyleBackColor = true; + // + // monitor + // + this.monitor.Controls.Add(this.memlist); + this.monitor.Controls.Add(this.instptr); + this.monitor.Controls.Add(this.memptr); + this.monitor.Location = new System.Drawing.Point(4, 22); + this.monitor.Name = "monitor"; + this.monitor.Size = new System.Drawing.Size(384, 243); + this.monitor.TabIndex = 2; + this.monitor.Text = "Monitor"; + this.monitor.UseVisualStyleBackColor = true; + // + // consoleout + // + this.consoleout.Dock = System.Windows.Forms.DockStyle.Fill; + this.consoleout.Location = new System.Drawing.Point(3, 3); + this.consoleout.Multiline = true; + this.consoleout.Name = "consoleout"; + this.consoleout.ReadOnly = true; + this.consoleout.Size = new System.Drawing.Size(378, 237); + this.consoleout.TabIndex = 0; + // + // programinput + // + this.programinput.Location = new System.Drawing.Point(3, 0); + this.programinput.Multiline = true; + this.programinput.Name = "programinput"; + this.programinput.Size = new System.Drawing.Size(378, 218); + this.programinput.TabIndex = 0; + // + // load + // + this.load.Location = new System.Drawing.Point(6, 217); + this.load.Name = "load"; + this.load.Size = new System.Drawing.Size(115, 23); + this.load.TabIndex = 1; + this.load.Text = "Load"; + this.load.UseVisualStyleBackColor = true; + this.load.Click += new System.EventHandler(this.load_Click); + // + // save + // + this.save.Location = new System.Drawing.Point(127, 217); + this.save.Name = "save"; + this.save.Size = new System.Drawing.Size(114, 23); + this.save.TabIndex = 2; + this.save.Text = "Save"; + this.save.UseVisualStyleBackColor = true; + this.save.Click += new System.EventHandler(this.save_Click); + // + // memptr + // + this.memptr.AutoSize = true; + this.memptr.Location = new System.Drawing.Point(8, 8); + this.memptr.Name = "memptr"; + this.memptr.Size = new System.Drawing.Size(56, 13); + this.memptr.TabIndex = 0; + this.memptr.Text = "Memory: 0"; + // + // instptr + // + this.instptr.AutoSize = true; + this.instptr.Location = new System.Drawing.Point(8, 21); + this.instptr.Name = "instptr"; + this.instptr.Size = new System.Drawing.Size(68, 13); + this.instptr.TabIndex = 1; + this.instptr.Text = "Instruction: 0"; + // + // memlist + // + this.memlist.FormattingEnabled = true; + this.memlist.Location = new System.Drawing.Point(11, 37); + this.memlist.Name = "memlist"; + this.memlist.ScrollAlwaysVisible = true; + this.memlist.SelectionMode = System.Windows.Forms.SelectionMode.None; + this.memlist.Size = new System.Drawing.Size(370, 199); + this.memlist.TabIndex = 2; + // + // run + // + this.run.Location = new System.Drawing.Point(247, 217); + this.run.Name = "run"; + this.run.Size = new System.Drawing.Size(131, 23); + this.run.TabIndex = 3; + this.run.Text = "Run"; + this.run.UseVisualStyleBackColor = true; + this.run.Click += new System.EventHandler(this.run_Click); + // + // MindBlow + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.tabs); + this.Name = "MindBlow"; + this.Size = new System.Drawing.Size(392, 269); + this.Resize += new System.EventHandler(this.MindBlow_Resize); + this.tabs.ResumeLayout(false); + this.console.ResumeLayout(false); + this.console.PerformLayout(); + this.program.ResumeLayout(false); + this.program.PerformLayout(); + this.monitor.ResumeLayout(false); + this.monitor.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TabControl tabs; + private System.Windows.Forms.TabPage console; + private System.Windows.Forms.TabPage program; + private System.Windows.Forms.TabPage monitor; + private System.Windows.Forms.TextBox consoleout; + private System.Windows.Forms.TextBox programinput; + private System.Windows.Forms.Button load; + private System.Windows.Forms.Button save; + private System.Windows.Forms.Label instptr; + private System.Windows.Forms.Label memptr; + private System.Windows.Forms.ListBox memlist; + private System.Windows.Forms.Button run; + } +} diff --git a/ShiftOS.WinForms/Applications/MindBlow.cs b/ShiftOS.WinForms/Applications/MindBlow.cs new file mode 100644 index 0000000..22f5011 --- /dev/null +++ b/ShiftOS.WinForms/Applications/MindBlow.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; +using System.IO; +using System.Threading; + +namespace ShiftOS.WinForms.Applications +{ + [WinOpen("mindblow")] + [Launcher("MindBlow", false, null, "Utilities")] + [RequiresUpgrade("mindblow")] + public partial class MindBlow : UserControl, IShiftOSWindow, IBFListener + { + private class TextBoxStream : Stream + { + private TextBox box; + private KeysConverter kc; + public TextBoxStream(TextBox mybox) + { + kc = new KeysConverter(); + box = mybox; + } + public override bool CanRead => true; + + public override bool CanSeek => false; + + public override bool CanWrite => true; + + public override long Length => box.Text.Length; + + public override long Position { get => Length; set => throw new NotImplementedException(); } + + public override void Flush() + { + } + + public override int Read(byte[] buffer, int offset, int count) + { + object lck = new object(); + int ptr = offset; + KeyPressEventHandler handler = (o, a) => + { + lock (lck) + { + buffer[ptr] = (byte)a.KeyChar; + ptr++; + } + }; + Desktop.InvokeOnWorkerThread(() => box.KeyPress += handler); + while (true) + { + lock (lck) + if (ptr >= offset + count) + break; + } + Desktop.InvokeOnWorkerThread(() => box.KeyPress -= handler); + return count; + } + + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotImplementedException(); + } + + public override void SetLength(long value) + { + throw new NotImplementedException(); + } + + public override void Write(byte[] buffer, int offset, int count) + { + string output = ""; + foreach (byte b in buffer.Skip(offset).Take(count)) + output += Convert.ToChar(b); + Desktop.InvokeOnWorkerThread(() => box.Text += output); + } + } + private static string[] DefaultMem; + private BFInterpreter Interpreter; + + private void DoLayout() + { + memlist.Left = 0; + memlist.Width = monitor.Width; + memlist.Height = monitor.Height - memlist.Top; + program.Top = 0; + program.Left = 0; + programinput.Width = program.Width; + programinput.Height = program.Height - load.Height; + load.Top = save.Top = run.Top = programinput.Height; + load.Width = save.Width = run.Width = save.Left = program.Width / 3; + run.Left = save.Left * 2; + } + + public MindBlow() + { + InitializeComponent(); + DefaultMem = new string[30000]; + for (ushort i = 0; i < 30000; i++) + DefaultMem[i] = "0"; + memlist.Items.AddRange(DefaultMem); + Interpreter = new BFInterpreter(new TextBoxStream(consoleout), this); + } + + public void IPtrMoved(int newval) + { + Desktop.InvokeOnWorkerThread(() => instptr.Text = "Instruction: " + newval.ToString()); + } + + public void MemChanged(ushort pos, byte newval) + { + Desktop.InvokeOnWorkerThread(() => memlist.Items[pos] = newval.ToString()); + } + + public void MemReset() + { + Desktop.InvokeOnWorkerThread(() => + { + memlist.Items.Clear(); + memlist.Items.AddRange(DefaultMem); + }); + } + + public void OnLoad() + { + DoLayout(); + } + + public void OnSkinLoad() + { + } + + public bool OnUnload() + { + return true; + } + + public void OnUpgrade() + { + } + + public void PointerMoved(ushort newval) + { + Desktop.InvokeOnWorkerThread(() => memptr.Text = "Memory: " + newval.ToString()); + } + + private void MindBlow_Resize(object sender, EventArgs e) + { + DoLayout(); + } + + private void run_Click(object sender, EventArgs e) + { + new Thread(() => + { + Interpreter.Reset(); + Interpreter.Execute(programinput.Text); + }).Start(); + } + + private void tabs_Selected(object sender, TabControlEventArgs e) + { + DoLayout(); + } + + private void load_Click(object sender, EventArgs e) + { + AppearanceManager.SetupDialog(new FileDialog(new string[] { ".bf" }, FileOpenerStyle.Open, new Action<string>((file) => programinput.Text = Objects.ShiftFS.Utils.ReadAllText(file)))); + } + + private void save_Click(object sender, EventArgs e) + { + AppearanceManager.SetupDialog(new FileDialog(new string[] { ".bf" }, FileOpenerStyle.Save, new Action<string>((file) => Objects.ShiftFS.Utils.WriteAllText(file, programinput.Text)))); + } + } +} diff --git a/ShiftOS.WinForms/Applications/MindBlow.resx b/ShiftOS.WinForms/Applications/MindBlow.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/MindBlow.resx @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root>
\ No newline at end of file |
