public void TestSUB()
        {
            SignalBus signals = new SignalBus();
            Operation op      = new SUB(null, signals, null);

            signals.Reset();
            op.Step0();
            Assert.IsTrue(signals.MI);
            Assert.IsTrue(signals.CO);

            signals.Reset();
            op.Step1();
            Assert.IsTrue(signals.RO);
            Assert.IsTrue(signals.II);
            Assert.IsTrue(signals.CE);

            signals.Reset();
            op.Step2();
            Assert.IsTrue(signals.IO);
            Assert.IsTrue(signals.MI);

            signals.Reset();
            op.Step3();
            Assert.IsTrue(signals.RO);
            Assert.IsTrue(signals.BI);

            signals.Reset();
            op.Step4();
            Assert.IsTrue(signals.EO);
            Assert.IsTrue(signals.AI);
            Assert.IsTrue(signals.SU);
            Assert.IsTrue(signals.FI);
        }
Example #2
0
 public Instructions()
 {
     instructions["ST"]   = new ST();
     instructions["LD"]   = new LD();
     instructions["ADD"]  = new ADD();
     instructions["SUB"]  = new SUB();
     instructions["JMP"]  = new JMP();
     instructions["JN"]   = new JN();
     instructions["JP"]   = new JP();
     instructions["JZ"]   = new JZ();
     instructions["JNZ"]  = new JNZ();
     instructions["HALT"] = new HALT();
     //Second architecture functions.
     instructions["LD2"] = new LD2();
     instructions["LD3"] = new LD3();
     instructions["ST2"] = new ST2();
     instructions["ST3"] = new ST3();
     instructions["POS"] = new POS();
     instructions["PXL"] = new PXL();
     instructions["RND"] = new RND();
     instructions["CLR"] = new CLR();
     instructions["COS"] = new COS();
     instructions["SIN"] = new SIN();
     instructions["IN"]  = new IN();
 }
Example #3
0
        public static void AssociateOpcodes()
        {
            instructions[0] = new NOP();
            instructions[1] = new PRNT();

            instructions[16] = new PUSH();
            instructions[17] = new POP();
            instructions[18] = new SAVE();
            instructions[19] = new CPY();
            instructions[20] = new RNDM();
            instructions[21] = new EMPTY();

            instructions[128] = new ADD();
            instructions[129] = new SUB();
            instructions[130] = new MUL();
            instructions[131] = new DIV();

            instructions[132] = new SUB2();
            instructions[133] = new DIV2();

            instructions[134] = new NEG();
            instructions[135] = new ABS();

            instructions[144] = new INC();
            instructions[145] = new DEC();

            instructions[64] = new JMP();
            instructions[65] = new JGZ();
            instructions[66] = new JLZ();
            instructions[67] = new JEZ();
            instructions[68] = new JNZ();
            instructions[69] = new CALL();
            instructions[70] = new RET();
            instructions[71] = new LDLOC();
            instructions[72] = new STLOC();
            instructions[73] = new LDARG();
            instructions[74] = new STARG();

            instructions[0b10100100] = new CMP();
Example #4
0
        //------------------------------------------methods---------------------------------------------------------

        public E3D_model(string path)
        {
            if (!File.Exists(path))
            {
                Debug.LogError("ERROR: E3D file not found!");
                return;
            }

            FileStream file = File.OpenRead(path);

            ObjectName = Path.GetFileNameWithoutExtension(path);
            if (!(parser.GetString(file, 4) == "E3D0"))
            {
                Debug.LogError("ERROR: Unknown main chunk");
                return;
            }
            int MainChunkSize = parser.GetInt(file);

            while (file.Position < MainChunkSize - 8)
            {
                string chunk_name = parser.GetString(file, 4);
                if (chunk_name == "SUB0")//loading submodel data
                {
                    int size = parser.GetInt(file);
                    size = (size - 8) / 256;
                    for (int i = 0; i < size; i++)
                    {
                        SUB SUB0 = new SUB
                        {
                            nextSubmodel        = parser.GetInt(file),
                            firstSubmodel       = parser.GetInt(file),
                            submodelType        = parser.GetInt(file),
                            nameNumber          = parser.GetInt(file),
                            animationType       = parser.GetInt(file),
                            submodelFlags       = parser.GetInt(file),
                            viewMatrixNumber    = parser.GetInt(file),
                            vertexSize          = parser.GetInt(file),
                            firstVertexPosition = parser.GetInt(file),
                            materialNumber      = parser.GetInt(file)
                        };
                        parser.Skip(file, 4);  //skip - submodelLigntOnBrightnessThreshold
                        parser.Skip(file, 4);  //skip - submodelLightOnThreshold
                        parser.Skip(file, 16); //skip - RGBAcolorAmbient
                        parser.Skip(file, 16); //skip - RGBAdiffuseColor
                        parser.Skip(file, 16); //skip - RGBAspecularColor
                        parser.Skip(file, 16); //skip - RGBAselfillumColor
                        SUB0.lineSize    = parser.GetFloat(file);
                        SUB0.maxDistance = parser.GetFloat(file);
                        SUB0.minDistance = parser.GetFloat(file);
                        parser.Skip(file, 32);//skip - lightParameters
                        parser.Skip(file, 100);


                        submodel_data.Add(SUB0);
                    }
                }
                if (chunk_name == "SUB1") //currently unused
                {
                    int size = parser.GetInt(file);
                    for (int i = 0; i < size - 8; i++)
                    {
                        file.ReadByte();
                    }
                }
                if (chunk_name == "VNT0") //loading mesh data
                {
                    int size = parser.GetInt(file);
                    size = (size - 8) / 32;
                    for (int i = 0; i < size; i++)
                    {
                        VNT0.position.Add(new Vector3(parser.GetFloat(file), parser.GetFloat(file), parser.GetFloat(file)));
                        VNT0.normal.Add(new Vector3(parser.GetFloat(file), parser.GetFloat(file), parser.GetFloat(file)));
                        float U = parser.GetFloat(file);
                        float V = parser.GetFloat(file);
                        VNT0.uv.Add(new Vector2(U, -V));
                    }
                }
                if (chunk_name == "TEX0") //loading material names
                {
                    int  size         = parser.GetInt(file) - 8;
                    long counterStart = file.Position;       //początek czytanego fragmentu pliku
                    long counterEnd   = counterStart + size; //koniec czytanego fragmentu pliku
                    while (file.Position < counterEnd)
                    {
                        TEX _TEX0 = new TEX
                        {
                            materialName = parser.GetName(file)
                        };
                        TEX0.Add(_TEX0);
                    }
                }
                if (chunk_name == "NAM0") //loading submodel names
                {
                    int  size         = parser.GetInt(file) - 8;
                    long counterStart = file.Position;       //początek czytanego fragmentu pliku
                    long counterEnd   = counterStart + size; //koniec czytanego fragmentu pliku
                    while (file.Position < counterEnd)
                    {
                        NAM _NAM0 = new NAM
                        {
                            submodelName = parser.GetName(file)
                        };
                        NAM0.Add(_NAM0);
                    }
                }
                if (chunk_name == "TRA0") //loading transform matrix
                {
                    int size = parser.GetInt(file);
                    size = (size - 8) / 64;
                    for (int i = 0; i < size; i++)
                    {
                        TRA _TRA0 = new TRA
                        {
                            transformMatrix = parser.GetTransformMatrix(file)
                        };
                        TRA0.Add(_TRA0);
                    }
                }
                if (chunk_name == "TRA1")//unused
                {
                    Debug.LogWarning("Unsuported chunk detected! TRA1 is currently not supported");
                    int size = parser.GetInt(file);
                    for (int i = 0; i < size - 8; i++)
                    {
                        file.ReadByte();
                    }
                }
            }
        }
Example #5
0
        public static Instruccion DescodificarInstruccion(byte codigo, ushort pos)
        {
            Instruccion instruccion       = null;
            ArgMemoria  argumentoMemoria  = Argumento.ConvertirEnArgumento((Main.ObtenerMemoria.ObtenerDireccion((ushort)(pos + 1)).Contenido * 256 + Main.ObtenerMemoria.ObtenerDireccion((ushort)(pos + 2)).Contenido).ToString("X4"), true) as ArgMemoria;
            ArgRegistro argumentoRegistro = Argumento.ConvertirEnArgumento(Main.ObtenerNombreRegistro(codigo % 4), false) as ArgRegistro;
            ArgLiteral  argumentoLiteral  = Argumento.ConvertirEnArgumento(Main.ObtenerMemoria.ObtenerDireccion((ushort)(pos + 1)).Contenido.ToString(), false) as ArgLiteral;

            switch (codigo / 8)
            {
            case 0:
                instruccion = new LD(argumentoRegistro);
                break;

            case 1:
                instruccion = new ST(argumentoRegistro);
                break;

            case 4:
            case 5:
                instruccion = new LDM(argumentoMemoria, argumentoRegistro);
                break;

            case 6:
            case 7:
                instruccion = new STM(argumentoRegistro, argumentoMemoria);
                break;

            case 2:
            case 3:
                instruccion = new LDI(argumentoLiteral, argumentoRegistro);
                break;

            case 8:
                instruccion = new ADD(argumentoRegistro);
                break;

            case 9:
                instruccion = new SUB(argumentoRegistro);
                break;

            case 10:
                instruccion = new CMP(argumentoRegistro);
                break;


            case 11:
                instruccion = new INC();
                break;

            case 12:
                instruccion = new ADI(argumentoLiteral);
                break;

            case 13:
                instruccion = new SUI(argumentoLiteral);
                break;

            case 14:
            case 15:
                instruccion = new CMI(argumentoLiteral);
                break;


            case 16:
                instruccion = new ANA(argumentoRegistro);
                break;

            case 17:
                instruccion = new ORA(argumentoRegistro);
                break;

            case 18:
                instruccion = new XRA(argumentoRegistro);
                break;


            case 19:
                instruccion = new CMA();
                break;

            case 20:
                instruccion = new ANI(argumentoLiteral);
                break;

            case 21:
                instruccion = new ORI(argumentoLiteral);
                break;

            case 22:
            case 23:
                instruccion = new XRI(argumentoLiteral);
                break;

            case 24:
            case 25:
                instruccion = new JMP(argumentoMemoria);
                break;

            case 26:
                instruccion = new BEQ(argumentoMemoria);
                break;

            case 27:
                instruccion = new BC(argumentoMemoria);
                break;

            case 28:
            case 29:
                instruccion = new LF();
                break;

            case 30:
                instruccion = new IN(argumentoMemoria, argumentoRegistro);
                break;

            case 31:
                instruccion = new OUT(argumentoRegistro, argumentoMemoria);
                break;
            }
            return(instruccion);
        }
Example #6
0
        public static string GetExtensionFromBuffer(byte[] buffer)
        {
            //Archives
            if (AFS.IsValid(buffer))
            {
                return("AFS");
            }
            if (GZ.IsValid(buffer))
            {
                return("GZ");
            }
            if (IDX.IsValid(buffer))
            {
                return("IDX");
            }
            if (IPAC.IsValid(buffer))
            {
                return("IPAC");
            }
            if (PKF.IsValid(buffer))
            {
                return("PKF");
            }
            if (PKS.IsValid(buffer))
            {
                return("PKS");
            }
            //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension
            if (TAD.IsValid(buffer))
            {
                return("TAD");
            }

            //Textures/Images
            if (TEXN.IsValid(buffer))
            {
                return("TEXN");
            }
            if (PVRT.IsValid(buffer))
            {
                return("PVRT");
            }
            if (DDS.IsValid(buffer))
            {
                return("DDS");
            }

            //Models
            if (MT5.IsValid(buffer))
            {
                return("MT5");
            }
            if (MT7.IsValid(buffer))
            {
                return("MT7");
            }

            //Subtitles
            if (SUB.IsValid(buffer))
            {
                return("SUB");
            }

            return("UNKNOWN");
        }
Example #7
0
        /// <summary>
        /// Trys to find the fitting file type for the given file with the file signature.
        /// </summary>
        public static Type GetFileTypeFromSignature(Stream stream)
        {
            byte[] buffer = new byte[8];
            stream.Read(buffer, 0, buffer.Length);

            //Archives
            if (AFS.IsValid(buffer))
            {
                return(typeof(AFS));
            }
            if (GZ.IsValid(buffer))
            {
                return(typeof(GZ));
            }
            if (IDX.IsValid(buffer))
            {
                return(typeof(IDX));
            }
            if (IPAC.IsValid(buffer))
            {
                return(typeof(IPAC));
            }
            if (PKF.IsValid(buffer))
            {
                return(typeof(PKF));
            }
            if (PKS.IsValid(buffer))
            {
                return(typeof(PKS));
            }
            //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension
            if (TAD.IsValid(buffer))
            {
                return(typeof(TAD));
            }

            //Textures/Images
            if (TEXN.IsValid(buffer))
            {
                return(typeof(TEXN));
            }
            if (PVRT.IsValid(buffer))
            {
                return(typeof(PVRT));
            }
            if (DDS.IsValid(buffer))
            {
                return(typeof(DDS));
            }

            //Models
            if (MT5.IsValid(buffer))
            {
                return(typeof(MT5));
            }
            if (MT7.IsValid(buffer))
            {
                return(typeof(MT7));
            }

            //Subtitles
            if (SUB.IsValid(buffer))
            {
                return(typeof(SUB));
            }

            return(null);
        }
Example #8
0
        /// <summary>
        /// Create a single component from XML data
        /// </summary>
        /// <param name="node">XML node containing component data</param>
        /// <returns>Created Component</returns>
        private static ComponentBase CreateComponent(XmlNode node)
        {
            ComponentBase component;

            switch (node.LocalName)
            {
                #region Basic
            case "Coil":
                Coil coil = new Coil();
                coil.Mode = node.Attributes["Mode"].Value.ToEnum <Coil.CoilMode>();
                coil.Type = node.Attributes["Type"].Value.ToEnum <Coil.CoilType>();
                component = coil;
                break;

            case "Contact":
                Contact contact = new Contact();
                contact.IsClosed   = node.Attributes["IsClosed"].Value.ToBool();
                contact.IsInverted = node.Attributes["IsInverted"].Value.ToBool();
                contact.Type       = node.Attributes["Type"].Value.ToEnum <Contact.ContactType>();
                component          = contact;
                break;

            case "SC": component = new SC(); break;

            case "OSF": component = new OSF(); break;

            case "OSR": component = new OSR(); break;
                #endregion Basic

                #region Compare Components
            case "EQU": component = new EQU(); break;

            case "GEQ": component = new GEQ(); break;

            case "GRT": component = new GRT(); break;

            case "LEG": component = new LEG(); break;

            case "LES": component = new LES(); break;

            case "NEQ": component = new NEQ(); break;
                #endregion Compare Components

                #region Counter Components
            case "CTC": component = new CTC(); break;

            case "CTD": component = new CTD(); break;

            case "CTU": component = new CTU(); break;

            case "RES": component = new RES(); break;
                #endregion Counter Components

                #region Math Components
            case "ADD": component = new ADD(); break;

            case "DIV": component = new DIV(); break;

            case "MUL": component = new MUL(); break;

            case "SUB": component = new SUB(); break;

            case "MOV": component = new MOV(); break;
                #endregion Math Components

                #region Analog Components
            case "ADC":
                ADC adc = new ADC();
                adc.Destination = node.Attributes["Destination"].Value;
                component       = adc;
                break;

            case "PWM":
                PWM pwm = new PWM();
                pwm.DudyCycle = node.Attributes["DudyCycle"].Value;
                component     = pwm;
                break;
                #endregion Analog Components

                #region Function Components
            case "ELF":
                ELF elf = new ELF();
                elf.Name  = node.Attributes["Name"].Value;
                elf.Code  = node.InnerText;
                component = elf;
                break;
                #endregion Function Components

            default:
                throw new ArgumentException("Unknow Component", "node");
            }

            component.Comment = node.Attributes["Comment"].Value;

            #region Extra Processing based on Components Base Class
            if (component is NameableComponent)
            {
                (component as NameableComponent).Name = node.Attributes["Name"].Value;
            }

            if (component is CompareComponent)
            {
                (component as CompareComponent).VarA = node.Attributes["VarA"].Value;
                (component as CompareComponent).VarB = node.Attributes["VarB"].Value;
            }
            else if (component is CounterComponent)
            {
                (component as CounterComponent).Limit = node.Attributes["Limit"].Value;
            }
            else if (component is MathComponent)
            {
                (component as MathComponent).Destination = node.Attributes["Destination"].Value;
                (component as MathComponent).VarA        = node.Attributes["VarA"].Value;
                (component as MathComponent).VarB        = node.Attributes["VarB"].Value;
            }
            #endregion Extra Processing based on Components Base Class

            return(component);
        }
Example #9
0
        public void Math()
        {
            #region Startup
            var  TestTable = new LadderDataTable();
            Node PowerRail = new Node();

            ADD add = new ADD();
            add.LeftLide    = PowerRail;
            add.Destination = "Dest";
            add.VarA        = "VarA";
            add.VarB        = "VarB";
            add.DataTable   = TestTable;

            DIV div = new DIV();
            div.LeftLide    = PowerRail;
            div.Destination = "Dest";
            div.VarA        = "VarA";
            div.VarB        = "VarB";
            div.DataTable   = TestTable;

            MOV mov = new MOV();
            mov.LeftLide    = PowerRail;
            mov.Destination = "Dest";
            mov.VarA        = "VarA";
            mov.DataTable   = TestTable;

            MUL mul = new MUL();
            mul.LeftLide    = PowerRail;
            mul.Destination = "Dest";
            mul.VarA        = "VarA";
            mul.VarB        = "VarB";
            mul.DataTable   = TestTable;

            SUB sub = new SUB();
            sub.LeftLide    = PowerRail;
            sub.Destination = "Dest";
            sub.VarA        = "VarA";
            sub.VarB        = "VarB";
            sub.DataTable   = TestTable;
            #endregion Startup

            #region ADD
            Trace.WriteLine("ADD", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "ADD");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            add.ValueA = 1;
            add.ValueB = 2;
            Trace.Unindent();

            Trace.WriteLine("Input False", "ADD");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            add.Execute();
            Assert.IsFalse(add.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "ADD");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            add.Execute();
            Assert.IsTrue(add.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)3);

            Trace.Unindent();
            Trace.Unindent();
            #endregion ADD

            #region DIV
            Trace.WriteLine("DIV", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "DIV");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            div.ValueA = 10;
            div.ValueB = 2;
            Trace.Unindent();

            Trace.WriteLine("Input False", "DIV");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            div.Execute();
            Assert.IsFalse(div.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "DIV");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            div.Execute();
            Assert.IsTrue(div.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)5);

            Trace.Unindent();
            Trace.Unindent();
            #endregion DIV

            #region MOV
            Trace.WriteLine("MOV", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "MOV");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            mov.ValueA = 10;
            Trace.Unindent();

            Trace.WriteLine("Input False", "MOV");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            mov.Execute();
            Assert.IsFalse(mov.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "MOV");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            mov.Execute();
            Assert.IsTrue(mov.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)10);

            Trace.Unindent();
            Trace.Unindent();
            #endregion MOV

            #region MUL
            Trace.WriteLine("MUL", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "MUL");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            mul.ValueA = 3;
            mul.ValueB = 6;
            Trace.Unindent();

            Trace.WriteLine("Input False", "MUL");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            mul.Execute();
            Assert.IsFalse(mul.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "MUL");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            mul.Execute();
            Assert.IsTrue(mul.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)18);

            Trace.Unindent();
            Trace.Unindent();
            #endregion MUL

            #region SUB
            Trace.WriteLine("SUB", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "SUB");
            Trace.Indent();
            TestTable.SetValue("Dest", (short)0);
            sub.ValueA = 4;
            sub.ValueB = 6;
            Trace.Unindent();

            Trace.WriteLine("Input False", "SUB");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            sub.Execute();
            Assert.IsFalse(sub.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)0);
            Trace.Unindent();

            Trace.WriteLine("Input True", "SUB");
            Trace.Indent();

            PowerRail.LogicLevel = true;
            sub.Execute();
            Assert.IsTrue(sub.InternalState);
            Assert.AreEqual(TestTable.GetValue("Dest"), (short)-2);

            Trace.Unindent();
            Trace.Unindent();
            #endregion SUB
        }