Beispiel #1
0
        private async void UIElement_OnKeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key == VirtualKey.F5)
            {
                OutputRichTextBox.Document.SetText(TextSetOptions.Unhide, "");
                _position = 0;
                BrainfuckInputRichTextBox.Document.GetText(TextGetOptions.NoHidden, out string input);
                using (ICpu cpu = _brainfuck.CreateCpu(input))
                {
                    bool failed = false;
                    try
                    {
                        await cpu.Process();
                    }
                    catch (Exception ex)
                    {
                        var dialog = new MessageDialog("Error: " + ex.Message);
                        await dialog.ShowAsync();

                        failed = true;
                    }

                    MemoryDumpListBox.Items.Clear();
                    foreach (var v in cpu.Memory.Dump())
                    {
                        MemoryDumpListBox.Items.Add($"{v.ToString()} ({(char)v})");
                    }

                    if (!failed)
                    {
                        MemoryDumpListBox.SelectedIndex = (int)cpu.Memory.Address;
                    }
                }
            }
        }
Beispiel #2
0
        static async Task Main(string[] args)
        {
            var brainfuck = BrainfuckInterpreter.Create();

            ICpu cpu = brainfuck.CreateCpu("++++++++++[>+>+++>+++<<<-]>>++>++++++++++++>+[>+>+<<-]>+++++++++[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>+++[>+>+<<-]>++++++[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>+++++[>+>+<<-]>+++[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>+++++++[>+>+<<-]>[<<<.>>>-]>[<<<.>>>-]<<<<<.>>>++++++++++[>++++++<-]>+++++<<<...>>>+++++.-.+++++++.---.+++++++++++++++++.<<<.>>>------------.-------------.+++++++++++++++++++++.-------------------.+++++++++++.<<<.>>>-----------.+++++++++++++++.------------.---.");
            await cpu.Process();

            Console.ReadKey();
            // dump the memory in screen.
            int i = 0;

            foreach (var @byte in cpu.Memory.Dump())
            {
                Console.Write($"[{i}] {@byte}");
                if (i == cpu.Memory.Address)
                {
                    Console.Write("*");
                }

                Console.WriteLine();
                i++;
            }

            Console.WriteLine("Finished.");
            Console.ReadKey();
        }
 public Computer(ICpuFactory factory)
 {
     cpu = factory.ProduceCpu();
     cpu.Process();
 }