Exemple #1
0
        public void Address(object sender, Tryte address)
        {
            int addr = address.ToInt();

            if (addr < 0)
            {
                throw new IndexOutOfRangeException();
            }
            else if (addr < TRIBBLE_SIZE)
            {
                trortRegister = null;
                tryteRegister.ReadWriteEnabled(this, Trit.Neu);
                tryteRegister = _TryteRegisters[addr];
                tryteRegister.ReadWriteEnabled(this, rwEnabledState);
            }
            else if (addr < TRIBBLE_SIZE * 2)
            {
                tryteRegister = null;
                trortRegister.ReadWriteEnabled(this, Trit.Neu);
                trortRegister = _TrortRegisters[addr];
                trortRegister.ReadWriteEnabled(this, rwEnabledState);
            }
        }
Exemple #2
0
        public TernaryString Trim(Tryte @char)
        {
            int startIndex = 0;

            for (; startIndex < _Chars.Count; startIndex++)
            {
                if (_Chars[startIndex] != @char)
                {
                    break;
                }
            }

            int endIndex = _Chars.Count;

            for (; endIndex > 0; endIndex--)
            {
                if (_Chars[endIndex] != @char)
                {
                    break;
                }
            }

            return(Substring(startIndex, endIndex - startIndex));
        }
Exemple #3
0
 static void Greater(Tryte t1, Tryte t2)
 {
     Console.WriteLine($"Greater: {t1 > t2}");
 }
Exemple #4
0
        static void Mod(Tryte t1, Tryte t2)
        {
            Tryte mod = t1 % t2;

            Console.WriteLine($"Mod: [{mod.ToString("s")}] {mod}");
        }
Exemple #5
0
        static void Div(Tryte t1, Tryte t2)
        {
            Tryte div = t1 / t2;

            Console.WriteLine($"Div: [{div.ToString("s")}] {div}");
        }
Exemple #6
0
        static void Multi(Tryte t1, Tryte t2)
        {
            Tryte multi = t1 * t2;

            Console.WriteLine($"Multi: [{multi.ToString("s")}] {multi}");
        }
Exemple #7
0
 static void DisplayPrev(Tryte t, int offset)
 {
     Console.SetCursorPosition(offset, Console.CursorTop - 1);
     Console.WriteLine($"{t.ToString("s")} {t}");
 }
Exemple #8
0
 public TernaryFolder(TernaryString fullName, Tryte attr) : base(fullName, attr)
 {
 }
Exemple #9
0
 protected void InvokeOutput(object sender, Tryte output)
 {
     BusValue = output;
     BusOutput?.Invoke(this, output);
 }
Exemple #10
0
        public TernaryString Substring(Tryte index, Tryte length)
        {
            int len = length.ToInt();

            return(new TernaryString(_Chars.Skip(index.ToInt()).Take(len)));
        }
Exemple #11
0
 public TernaryString Substring(Tryte index)
 {
     return(new TernaryString(_Chars.Skip(index.ToInt())));
 }
Exemple #12
0
 public bool Contains(Tryte @char)
 {
     return(_Chars.Any(c => c == @char));
 }
Exemple #13
0
 public int LastIndexOf(Tryte @char)
 {
     return(_Chars.LastIndexOf(@char));
 }
Exemple #14
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++;
                        }
                    }
                }
            }
        }
Exemple #15
0
 public void Main(string[] args)
 {
     Tryte t = new Tryte();
 }
Exemple #16
0
 static void Lesser(Tryte t1, Tryte t2)
 {
     Console.WriteLine($"Lesser: {t1 < t2}");
 }
Exemple #17
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();
            }
        }
Exemple #18
0
 public void BBusInput(object sender, Tryte tryte)
 {
     muxerBusB.AInput(this, tryte);
     inverterBusB.BusInput(this, tryte);
 }