Exemplo n.º 1
0
        static void Main(string[] args)
        {
            TryteALU alu = new TryteALU();

            alu.BusOutput += (s, t) =>
            {
                Console.WriteLine($"[{t.ToString("s")}] {t}");
            };

            while (true)
            {
                Action <Tryte, int> DisplayPrevTryte = (t, offset) =>
                {
                    Console.SetCursorPosition(offset, Console.CursorTop - 1);
                    Console.WriteLine($"{t.ToString("s")} {t}");
                };


                Console.Write("Trit S: ");
                if (!TritEx.TryParse(Console.ReadLine(), out Trit to))
                {
                    break;
                }

                Console.Write("Tryte A: ");
                if (!Tryte.TryParse(Console.ReadLine(), out Tryte ta))
                {
                    break;
                }

                DisplayPrevTryte(ta, 9);

                Console.Write("Tryte B: ");
                if (!Tryte.TryParse(Console.ReadLine(), out Tryte tb))
                {
                    break;
                }

                DisplayPrevTryte(tb, 9);


                Console.WriteLine();

                alu.ABusInput(null, ta);
                alu.BBusInput(null, tb);
                alu.FowleanControlInput(null, to);


                Console.WriteLine();
            }


            Console.WriteLine("\nPress any key to continue.");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void TryteTest()
        {
            tryteAdder.BusOutput += (s, sum) => {
                Console.WriteLine($"Sum: [{sum.ToString("s")}] {sum}");
            };

            tryteAdder.CarryOut += (s, carry) => {
                Console.WriteLine($"Sum Carry: {carry.ToSymbol()}");
            };


            tryteAdderForDiff.BusOutput += (s, sum) => {
                Console.WriteLine($"Diff: [{sum.ToString("s")}] {sum}");
            };

            tryteAdderForDiff.CarryOut += (s, carry) => {
                Console.WriteLine($"Diff Carry: {carry.ToSymbol()}");
            };

            tryteInverterBus.BusOutput += tryteAdderForDiff.BBusInput;



            while (true)
            {
                Console.Write("Tryte 1: ");
                if (!Tryte.TryParse(Console.ReadLine(), out Tryte t1))
                {
                    break;
                }

                DisplayPrev(t1, 9);

                Console.Write("Tryte 2: ");
                if (!Tryte.TryParse(Console.ReadLine(), out Tryte t2))
                {
                    break;
                }

                DisplayPrev(t2, 9);

                Console.WriteLine();

                Sum(t1, t2);
                Diff(t1, t2);
                //Multi(t1, t2);
                //Div(t1, t2);
                //Mod(t1, t2);
                //Greater(t1, t2);
                //Lesser(t1, t2);

                Console.WriteLine();
            }
        }
Exemplo n.º 3
0
        static void TrortMemoryTest()
        {
            STrortAddrTryteMemory trortAddrMemory = new STrortAddrTryteMemory();

            Func <Trort, string> t2s = (tryte) =>
            {
                return(String.Join("", tryte.LowerTryte.LowerTribble.Select(t => t.ToSymbol())) + ":" +
                       String.Join("", tryte.LowerTryte.UpperTribble.Select(t => t.ToSymbol())) + ":" +
                       String.Join("", tryte.UpperTryte.LowerTribble.Select(t => t.ToSymbol())) + ":" +
                       String.Join("", tryte.UpperTryte.UpperTribble.Select(t => t.ToSymbol())));
            };

            trortAddrMemory.BusOutput += (s, t) =>
            {
                Console.WriteLine($"     Address       Value");
                Console.WriteLine($"[{t2s(trortAddrMemory.Address)}]: {t.ToString()}");
            };

            while (true)
            {
                Console.Write("Address: ");
                if (!Trort.TryParse(Console.ReadLine(), out Trort addr))
                {
                    break;
                }

                Console.SetCursorPosition(9, Console.CursorTop - 1);
                Console.WriteLine($"      [{addr.ToString("s")}] {addr}");

                Console.Write("Action: ");
                if (!TritEx.TryParse(Console.ReadLine(), out Trit act))
                {
                    break;
                }

                Console.SetCursorPosition(8, Console.CursorTop - 1);
                Console.WriteLine($"       {act.ToSymbol()}              {(act == Trit.Pos ? "Write" : act == Trit.Neg ? "Read" : "Disable")}");

                if (act == Trit.Pos)
                {
                    Console.Write("Storage Value: ");
                    if (!Tryte.TryParse(Console.ReadLine(), out Tryte store))
                    {
                        break;
                    }

                    Console.SetCursorPosition(15, Console.CursorTop - 1);
                    Console.WriteLine($"[{store.ToString("S")}]       {store}");

                    trortAddrMemory.AddressInput(null, addr);
                    trortAddrMemory.BusInput(null, store);
                    trortAddrMemory.ReadWriteEnabled(null, act);
                    trortAddrMemory.ReadWriteEnabled(null, Trit.Neu);
                }
                else if (act == Trit.Neg)
                {
                    trortAddrMemory.AddressInput(null, addr);
                    trortAddrMemory.ReadWriteEnabled(null, act);
                    trortAddrMemory.ReadWriteEnabled(null, Trit.Neu);
                }

                Console.WriteLine();
            }
        }
Exemplo n.º 4
0
        static void AssembleRaw(string inputFile, string outputFile)
        {
            using (StreamReader reader = new StreamReader(inputFile))
            {
                string line = reader.ReadLine();
                bool   sym  = true;

                if (line.StartsWith("#num"))
                {
                    sym = false;
                }
                else if (!line.StartsWith("#sym"))
                {
                    Console.WriteLine("Invalid file format.");
                    return;
                }

                using (BinaryWriter writer = new BinaryWriter(File.Create(outputFile)))
                {
                    int lineNum = 1;
                    if (sym)
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            if (Tryte.TryParse(line, out Tryte tryte))
                            {
                                writer.Write((Int16)tryte.ToInt());
                            }
                            else
                            {
                                Console.WriteLine($"Format error on line {lineNum}.");
                                break;
                            }

                            lineNum++;
                        }
                    }
                    else
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            if (Int16.TryParse(line, out Int16 val))
                            {
                                if (val < Tryte.MIN_INT_VALUE || val > Tryte.MAX_INT_VALUE)
                                {
                                    Console.WriteLine($"Value out of range on line {lineNum}.");
                                    break;
                                }

                                writer.Write(val);
                            }
                            else
                            {
                                Console.WriteLine($"Format error on line {lineNum}.");
                                break;
                            }

                            lineNum++;
                        }
                    }
                }
            }
        }