Пример #1
0
 public I2CMemTool(RegisterMap _regMap, DMDongle _dongle, IRegOperation _myRegOp)
 {
     InitializeComponent();
     this.regMap   = _regMap;
     this.myDongle = _dongle;
     this.myRegOp  = _myRegOp;
 }
Пример #2
0
 /// <summary>
 /// Private function used to write data into the sensor's registers
 /// </summary>
 /// <param name="register">The register to write to</param>
 /// <param name="value">The value to write into the register</param>
 private void WriteRegister(RegisterMap register, Byte value)
 {
     lock (_socket.LockI2c)
     {
         _accel.Write(new[] { (Byte)register, value });
     }
 }
Пример #3
0
 /// <summary>
 /// Private function used to write data into the sensor's registers
 /// </summary>
 /// <param name="register">The register to write to</param>
 /// <param name="value">The value to write into the register</param>
 private void WriteRegister(RegisterMap register, Byte value)
 {
     lock (Hardware.LockI2C)
     {
         _accel.Write(new[] { (Byte)register, value });
     }
 }
Пример #4
0
 public InputMux(RegisterMap _regMap, IRegOperation _myRegOp)
 {
     this.myRegOp = _myRegOp;
     this.regMap  = _regMap;
     InitializeComponent();
     InitGUI();
 }
Пример #5
0
        public MDRegisterView(DataTable _dt, DataTable _dtCustomer, RegisterMap _regmap, DMDongle _dongle)
        {
            InitializeComponent();

            dt_reg      = _dt;
            dt_Customer = _dtCustomer;
            regMap      = _regmap;
            dongle      = _dongle;
            CollectCurrentRegList(_dt);
            BindingDVG(dt_reg);

            if (_dt.TableName == "Customer")
            {
                this.rightClickMenu.Items.Add("&Read");
                this.rightClickMenu.Items.Add("&Write");
                this.rightClickMenu.Items.Add("&Delete from this tab");
                this.rightClickMenu.Items.Add("&Sort");
            }
            else
            {
                this.rightClickMenu.Items.Add("&Read");
                this.rightClickMenu.Items.Add("&Write");
                this.rightClickMenu.Items.Add("&Add to customer tab");
            }
            this.rightClickMenu.ItemClicked += new ToolStripItemClickedEventHandler(rightClickMenu_ItemClicked);
        }
Пример #6
0
    public List <RegisterMap> ListRegisterMap(int pIdGame, int pIdPlayer)
    {
        List <RegisterMap> list_register = new List <RegisterMap>();

        string        conn = "URI=file:" + Application.streamingAssetsPath + "/AdvScrabble.db";  //Path to database.
        IDbConnection dbconn;

        dbconn = (IDbConnection) new SqliteConnection(conn);
        dbconn.Open();         //Open connection to the database.
        IDbCommand dbcmd    = dbconn.CreateCommand();
        string     sqlQuery = String.Format("SELECT * FROM map_register where id_game = \"{0}\" and id_player = \"{1}\"", pIdGame, pIdPlayer);

        dbcmd.CommandText = sqlQuery;
        IDataReader reader = dbcmd.ExecuteReader();

        while (reader.Read())
        {
            RegisterMap r = new RegisterMap();
            r.Id_register_map = reader.GetInt32(2);
            r.Map             = this.GetMap(pIdGame, reader.GetInt32(3), -2);
            r.Score_map       = reader.GetInt32(4);
            r.ListRegLevel    = this.ListRegisterLevel(pIdGame, pIdPlayer, r.Id_register_map);
            list_register.Add(r);
        }
        reader.Close();
        reader = null;
        dbcmd.Dispose();
        dbcmd = null;
        dbconn.Close();
        dbconn = null;

        return(list_register);
    }
        /// <summary>
        /// Parses an instruction and generates the binary code for it.
        /// </summary>
        /// <param name="address">The address of the instruction being parsed in the .text segment.</param>
        /// <param name="args">An array containing the arguments of the instruction.</param>
        /// <returns>One or more 32-bit integers representing this instruction. If this interface is implemented
        /// for a pseudo-instruction, this may return more than one instruction value.</returns>
        public override IEnumerable <int> GenerateCodeForInstruction(int nextTextAddress, string[] args)
        {
            if (args.Length != 2)
            {
                throw new ArgumentException("Invalid number of arguments provided. Expected 2, received " + args.Length + '.');
            }

            int rs2 = RegisterMap.GetNumericFloatingPointRegisterValue(args[0]);

            var retList = new List <int>();
            ParameterizedInstructionArg arg = ParameterizedInstructionArg.ParameterizeArgument(args[1]);
            int instruction = 0;
            int upperOffset = (arg.Offset & 0xFE0);
            int lowerOffset = (arg.Offset & 0x1F);

            instruction |= (upperOffset << 25);
            instruction |= (rs2 << 20);
            instruction |= (arg.Register << 15);

            const int FUNC_CODE = 2;

            instruction |= (FUNC_CODE << 12);

            instruction |= (lowerOffset << 7);
            instruction |= 0x27;
            retList.Add(instruction);

            return(retList);
        }
Пример #8
0
        public MDRegisterViewTab(DataTable _dt, DataTable _dtCustomer, RegisterMap _regmap, DMDongle _dongle)
        {
            InitializeComponent();

            dt_reg = _dt;
            if (dt_reg.TableName == "Customer")
            {
                dt_reg.RowChanged   += new DataRowChangeEventHandler(dt_reg_RowChanged);
                dt_reg.TableCleared += new DataTableClearEventHandler(dt_reg_TableCleared);
            }

            // fix the two panel size
            this.splitContainer1.Panel1MinSize = 260;
            this.splitContainer1.Panel2MinSize = this.Width - 260;

            // Add MDRegisterView control
            mdRegView = new MDRegisterView(dt_reg, _dtCustomer, _regmap, _dongle);
            this.splitContainer1.Panel2.Controls.Add(mdRegView);
            mdRegView.Dock = DockStyle.Left;

            // create data table for search dgv
            dtSearch.Columns.Clear();
            dtSearch.Columns.Add("Items");
            CollectDisplayNames(dt_reg);
            UpdateSearchedItems(this.tbSearch.Text);
            this.dgvSearch.DataSource = dtSearch;

            // Added Row Selected Change Event
            mdRegView.RowSelectedChangeEvent += new MDRegisterView.RowSelectedChangeEventHandler(mdRegView_RowSelectedChangeEvent);
        }
Пример #9
0
            /// <summary>
            /// Takes an argument (e.g. 4(x9)) and parameterizes it into the offset component
            /// and its numeric register ID.
            /// </summary>
            /// <param name="trimmedArgToken">The token to parameterize, with whitespace trimmed on both left/right sides.</param>
            /// <returns>A parameterized register/offset structure.</returns>
            public static ParameterizedInstructionArg ParameterizeArgument(string trimmedArgToken)
            {
                string[] parameterizedArgs = trimmedArgToken.Split(new[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries).Apply((str) => str.Trim()).ToArray();

                // we should expect one or two arguments.
                if (parameterizedArgs.Length != 1 && parameterizedArgs.Length != 2)
                {
                    throw new ArgumentException(trimmedArgToken + " was not in a valid format.");
                }

                ParameterizedInstructionArg retVal = default(ParameterizedInstructionArg);

                // if we have one argument, assume its the register name, and that the offset is 0.
                if (parameterizedArgs.Length == 1)
                {
                    int registerId = RegisterMap.GetNumericRegisterValue(parameterizedArgs[0]);
                    retVal = new ParameterizedInstructionArg(0, registerId);
                }
                else
                {
                    bool isValidOffset = IntExtensions.TryParseEx(parameterizedArgs[0], out short offsetVal) && ((offsetVal & 0xF000) == 0);
                    if (!isValidOffset)
                    {
                        throw new ArgumentException(parameterizedArgs[0] + " is not a valid 12-bit offset.");
                    }

                    int registerId = RegisterMap.GetNumericRegisterValue(parameterizedArgs[1]);
                    retVal = new ParameterizedInstructionArg(offsetVal, registerId);
                }

                return(retVal);
            }
Пример #10
0
        private void MenuItemFile_Open_Excel_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "Please select regmap excel file...";
            ofd.Filter = "xlsx(*.xlsx)|*.xlsx|xls(*.xls)|*.xls|All Files(*.*)|*.*";
            //ofd.RestoreDirectory = true;
            ofd.ReadOnlyChecked = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                DS_Excel = ImportExcel(ofd.FileName);
                if (DS_Excel == null)
                {
                    return;
                }

                DataSet = new MDDataSet(DS_Excel);
                regMap  = DataSet.RegMap;
                // Init tabs with created data tables
                CreateTabs(DataSet.DS_Display);
            }
            else
            {
                return;
            }
        }
        /// <summary>
        /// Parses an instruction and generates the binary code for it.
        /// </summary>
        /// <param name="address">The address of the instruction being parsed in the .text segment.</param>
        /// <param name="args">An array containing the arguments of the instruction.</param>
        /// <returns>One or more 32-bit integers representing this instruction. If this interface is implemented
        /// for a pseudo-instruction, this may return more than one instruction value.</returns>
        public override IEnumerable <int> GenerateCodeForInstruction(int address, string[] args)
        {
            // we expect three arguments. if not, throw an ArgumentException
            if (args.Length != 3)
            {
                throw new ArgumentException("Invalid number of arguments provided. Expected 3, received " + args.Length + '.');
            }

            IEnumerable <int> returnVal = null;
            int instruction             = 0;
            int rdReg  = RegisterMap.GetNumericRegisterValue(args[0]);
            int rs1Reg = RegisterMap.GetNumericRegisterValue(args[1]);
            int rs2Reg = 0;

            try
            {
                rs2Reg = RegisterMap.GetNumericRegisterValue(args[2]);

                List <int> instructionList = new List <int>();
                instruction |= 0x2000000;
                instruction |= (rs2Reg << 20);
                instruction |= (rs1Reg << 15);
                instruction |= (0x6 << 12);
                instruction |= (rdReg << 7);
                instruction |= 0x33;
                instructionList.Add(instruction);
                returnVal = instructionList;
            }
            catch (ArgumentException)
            {
                throw;
            }

            return(returnVal);
        }
Пример #12
0
 public void Setup()
 {
     _factory = new MockRepository(MockBehavior.Strict);
     _clipboard = MockObjectFactory.CreateClipboardDevice(_factory);
     _rawMap = new RegisterMap(_clipboard.Object);
     _map = _rawMap;
 }
Пример #13
0
 public void Execute(string[] args)
 {
     try
     {
         int    regIdx  = -1;
         string regName = args[0];
         if (RegisterMap.IsNamedIntegerRegister(regName))
         {
             regIdx = RegisterMap.GetNumericRegisterValue(regName);
             m_Terminal.PrintString("\t" + regName + " = " + m_Registers.UserIntRegisters[regIdx].Value + '\n');
         }
         else if (RegisterMap.IsNamedFloatingPointRegister(regName))
         {
             regIdx = RegisterMap.GetNumericFloatingPointRegisterValue(regName);
             m_Terminal.PrintString("\t" + regName + " = " + m_Registers.UserFloatingPointRegisters[regIdx].Value + '\n');
         }
         else
         {
             throw new ParseException(regName + " is not a valid integer register name.");
         }
     }
     catch (Exception ex)
     {
         m_Terminal.PrintString(ex.Message + '\n');
     }
 }
        /// <summary>
        /// Parses an instruction and generates the binary code for it.
        /// </summary>
        /// <param name="address">The address of the instruction being parsed in the .text segment.</param>
        /// <param name="args">An array containing the arguments of the instruction.</param>
        /// <returns>One or more 32-bit integers representing this instruction. If this interface is implemented
        /// for a pseudo-instruction, this may return more than one instruction value.</returns>
        public override IEnumerable <int> GenerateCodeForInstruction(int address, string[] args)
        {
            // we expect two arguments. if not, throw an ArgumentException
            if (args.Length != 2)
            {
                throw new ArgumentException("Invalid number of arguments provided. Expected 2, received " + args.Length + '.');
            }

            string rs1          = args[0].Trim();
            string immediateStr = args[1].Trim();

            int immediate = 0;

            if (!IntExtensions.TryParseEx(immediateStr, out immediate))
            {
                throw new ArgumentException("auipc - argument 2 was non-integer immediate value.");
            }

            int rs1Reg = RegisterMap.GetNumericRegisterValue(rs1);

            // shift this such that
            int bitShiftedImm = immediate << 12;

            int instruction = 0;

            instruction |= bitShiftedImm;
            instruction |= (rs1Reg << 7);
            instruction |= 0x17;
            var inList = new List <int>();

            inList.Add(instruction);
            return(inList);
        }
Пример #15
0
        public NoiseGateForm(RegisterMap _regMap, IRegOperation _myRegOp)
        {
            InitializeComponent();
            regMap  = _regMap;
            myRegOp = _myRegOp;

            InitDVG();
        }
Пример #16
0
 protected RegisterMapTest()
 {
     _factory = new MockRepository(MockBehavior.Strict);
     _clipboard = MockObjectFactory.CreateClipboardDevice(_factory);
     _fileName = null;
     _rawMap = VimUtil.CreateRegisterMap(_clipboard.Object, () => _fileName);
     _map = _rawMap;
 }
Пример #17
0
 public void UpdateRegMap(RegisterMap _regmap)
 {
     this.regMap = _regmap;
     if (eqCurveCtrl != null)
     {
         eqCurveCtrl.UpdateRegMap(_regmap);
     }
 }
Пример #18
0
 public OutputMuxForm(RegisterMap _regMap, IRegOperation _myRegOp, int modeIndex)
 {
     InitializeComponent();
     this.regMap = _regMap;
     myRegOp     = _myRegOp;
     mode        = modeIndex;
     InitGUI(modeIndex);
 }
Пример #19
0
 private void InitGUI(IRegOperation _myRegOp, int _filterCount, RegisterMap _regmap, byte[] _regAddr)
 {
     eqCurveCtrl = new EQCurveCtrl(_myRegOp, _filterCount, _regmap, _regAddr);
     this.Controls.Add(eqCurveCtrl);
     eqCurveCtrl.Location = new Point(12, 12);
     //this.eqCurveCtrl.InitSetting(filterCount);
     this.eqCurveCtrl.dgv_filterSetting.CellValueChanged += filterSetting_CellValueChanged;
 }
Пример #20
0
 protected RegisterMapTest()
 {
     _factory   = new MockRepository(MockBehavior.Strict);
     _clipboard = MockObjectFactory.CreateClipboardDevice(_factory);
     _fileName  = null;
     _rawMap    = VimUtil.CreateRegisterMap(_clipboard.Object, () => _fileName);
     _map       = _rawMap;
 }
Пример #21
0
 public ParameterEQCtrl(IRegOperation _myRegOp, int count, RegisterMap _regmap, byte[] _regAddr)
 {
     InitializeComponent();
     myRegOp     = _myRegOp;
     filterCount = count;
     regMap      = _regmap;
     regAddr     = _regAddr;
     InitGUI(_myRegOp, filterCount, _regmap, _regAddr);
 }
Пример #22
0
        /// <summary>
        /// Private function used to read data from the sensor's registers
        /// </summary>
        /// <param name="register">The register to read from</param>
        /// <returns>A byte value containing the data read from the sensor's register</returns>
        private Byte ReadRegister(RegisterMap register)
        {
            var data    = new Byte[1];
            var actions = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new [] { (Byte)register }), I2CDevice.CreateReadTransaction(data) };

            Hardware.I2CBus.Execute(_config, actions, 10);

            return(data[0]);
        }
Пример #23
0
        public string Solve(string[] input)
        {
            var registers = new RegisterMap(new[] { 'a', 'b', 'c', 'd' });
            var parser    = new InstructionParser(registers);
            var interpret = new Interpreter(registers);

            interpret.Execute(input.Select(i => parser.Parse(i)).ToArray());
            return(interpret.Registers[0].ToString());
        }
Пример #24
0
        public void ParseMap(string map)
        {
            string[]    lines  = map.Replace("\r\n", "\n").Split(new char[] { '\n' });
            RadioButton sender = null;

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Equals(_rowSeparator))
                {
                    _uxNotes.Text = "";
                    for (int j = i + 1; j < lines.Length; j++)
                    {
                        _uxNotes.Text = _uxNotes.Text + lines[j] + "\n";
                    }
                    break;
                }

                string[] strArray2 = lines[i].TrimEnd(new char[] { '\r' }).Split(new char[] { '\t' });

                RadioButton button2 = new RadioButton
                {
                    Name = "rb" + strArray2[0]
                };
                if (i == 0)
                {
                    button2.Checked = true;
                    sender          = button2;
                }

                RegisterSTB rstb = new RegisterSTB();
                rstb.Address      = Convert.ToInt32(strArray2[0], 16);
                rstb.Name         = strArray2[1];
                rstb.Description  = strArray2[2];
                rstb.Comment      = strArray2[5].Replace('|', ' ');
                rstb.BitFieldName = strArray2[6].Split(new char[] { ',' });
                Array.Reverse(rstb.BitFieldName);
                rstb.Type.Value = (RegisterOptions)Convert.ToInt32(strArray2[4]);
                rstb.Type.Rw    = strArray2[3];
                RegisterMap.Add(rstb.Address, rstb);

                button2.Font            = new Font(FontName, (float)RadioButtonFontSize, FontStyle.Regular);
                button2.Text            = string.Format("{0} {1}", strArray2[0], rstb.Name);
                button2.ForeColor       = Color.Black;
                button2.AutoSize        = true;
                button2.CheckedChanged += new EventHandler(rbo_CheckedChanged);
                _uxRbPanel.Controls.Add(button2);
            }
            ButtonExportRegisters           = new Button();
            ButtonExportRegisters.Text      = "Export All Records";
            ButtonExportRegisters.AutoSize  = true;
            ButtonExportRegisters.BackColor = Color.Gray;
            ButtonExportRegisters.ForeColor = Color.Black;
            _uxRbPanel.Controls.Add(ButtonExportRegisters);
            rbo_CheckedChanged(sender, null);
        }
Пример #25
0
        /// <summary>
        /// Private function used to read data from the sensor's registers
        /// </summary>
        /// <param name="register">The register to read from</param>
        /// <returns>A byte value containing the data read from the sensor's register</returns>
        private Byte ReadRegister(RegisterMap register)
        {
            var data = new Byte[1];

            lock (Hardware.LockI2C)
            {
                _accel.WriteRead(new[] { (Byte)register }, data);
            }

            return(data[0]);
        }
Пример #26
0
 public void NormalizeLineEndings()
 {
     Create("cat", "dog");
     RegisterMap.GetRegister('c').UpdateValue("fish\ntree\n", OperationKind.LineWise);
     _vimBuffer.ProcessNotation("<C-R>c");
     Assert.Equal(
         new[] { "fish", "tree", "cat", "dog" },
         _textBuffer.GetLines());
     for (int i = 0; i < 3; i++)
     {
         Assert.Equal(Environment.NewLine, _textBuffer.GetLine(i).GetLineBreakText());
     }
 }
        /// <summary>
        /// Parses an instruction and generates the binary code for it.
        /// </summary>
        /// <param name="address">The address of the instruction being parsed in the .text segment.</param>
        /// <param name="args">An array containing the arguments of the instruction.</param>
        /// <returns>One or more 32-bit integers representing this instruction. If this interface is implemented
        /// for a pseudo-instruction, this may return more than one instruction value.</returns>
        public override IEnumerable <int> GenerateCodeForInstruction(int address, string[] args)
        {
            // we expect three arguments. if not, throw an ArgumentException
            if (args.Length != 3)
            {
                throw new ArgumentException("Invalid number of arguments provided. Expected 3, received " + args.Length + '.');
            }

            string rd  = args[0].Trim();
            string rs1 = args[1].Trim();
            string rs2 = args[2].Trim();

            IEnumerable <int> returnVal = null;
            int instruction             = 0;
            int rdReg  = RegisterMap.GetNumericRegisterValue(rd);
            int rs1Reg = RegisterMap.GetNumericRegisterValue(rs1);
            int rs2Reg = 0;

            try
            {
                rs2Reg = RegisterMap.GetNumericRegisterValue(rs2);

                List <int> instructionList = new List <int>();
                instruction |= (rs2Reg << 20);
                instruction |= (rs1Reg << 15);
                instruction |= (0x7 << 12);
                instruction |= (rdReg << 7);
                instruction |= 0x33;
                instructionList.Add(instruction);
                returnVal = instructionList;
            }
            catch (ArgumentException)
            {
                // try to parse the string as a number; maybe the user meant andi?
                short immediate = 0;
                bool  isShort   = IntExtensions.TryParseEx(rs2, out immediate);
                if (isShort)
                {
                    var immediateParser = new AndiProcessor();
                    returnVal = immediateParser.GenerateCodeForInstruction(address, args);
                }
                else
                {
                    // otherwise, this is garbage; rethrow the value.
                    throw;
                }
            }

            return(returnVal);
        }
Пример #28
0
        /// <summary>
        /// Parses an instruction and generates the binary code for it.
        /// </summary>
        /// <param name="address">The address of the instruction being parsed in the .text segment.</param>
        /// <param name="args">An array containing the arguments of the instruction.</param>
        /// <returns>One or more 32-bit integers representing this instruction. If this interface is implemented
        /// for a pseudo-instruction, this may return more than one instruction value.</returns>
        public override IEnumerable <int> GenerateCodeForInstruction(int address, string[] args)
        {
            // we expect three arguments. if not, throw an ArgumentException
            if (args.Length != 3)
            {
                throw new ArgumentException("Invalid number of arguments provided. Expected 3, received " + args.Length + '.');
            }

            IEnumerable <int> returnVal = null;
            int  rdReg            = RegisterMap.GetNumericRegisterValue(args[0]);
            int  rs1Reg           = RegisterMap.GetNumericRegisterValue(args[1]);
            int  shiftAmt         = 0;
            bool isValidImmediate = IntExtensions.TryParseEx(args[2], out shiftAmt);

            // ensure our shift amount is 5 bits or less.
            isValidImmediate = isValidImmediate && ((shiftAmt & 0xFFFFFFE0) == 0);
            var instructionList = new List <int>();

            if (isValidImmediate)
            {
                int instruction = 0;
                instruction |= (0x1 << 30);
                instruction |= (shiftAmt << 20);
                instruction |= (rs1Reg << 15);
                instruction |= (0x5 << 12);
                instruction |= (rdReg << 7);
                instruction |= 0x13;
                instructionList.Add(instruction);
                returnVal = instructionList;
            }
            else
            {
                // otherwise, emit three instructions. load the upper 20 bits of the immediate into the destination register,
                // bitwise-or it with the remaining 12 bits, and then shift the target register by the destination register.
                var luiProc = new LuiProcessor();
                instructionList.AddRange(luiProc.GenerateCodeForInstruction(address, new string[] { args[0], (shiftAmt >> 12).ToString() }));

                int orImmVal = shiftAmt & 0xFFF;
                var oriProc  = new OriProcessor();
                instructionList.AddRange(oriProc.GenerateCodeForInstruction(address, new string[] { args[0], orImmVal.ToString() }));

                var sraProc = new SraProcessor();
                instructionList.AddRange(sraProc.GenerateCodeForInstruction(address, new string[] { args[0], args[1], args[0] }));
            }

            return(returnVal);
        }
Пример #29
0
    public void UpdateRegMap(int pIdGame, int pIdPlayer, RegisterMap r)
    {
        string conn = "URI=file:" + Application.streamingAssetsPath + "/AdvScrabble.db";         //Path to database.

        using (IDbConnection dbconn = new SqliteConnection(conn))
        {
            dbconn.Open();

            using (IDbCommand dbcmd = dbconn.CreateCommand())
            {
                string sqlQuery = String.Format("UPDATE map_register SET id_game = \"{0}\", id_player = \"{1}\", id_map_register = \"{2}\", id_map = \"{3}\", score_map = \"{4}\" WHERE id_game =\"{0}\" AND id_player = \"{1}\" AND  id_map_register = \"{2}\"", pIdGame, pIdPlayer, r.Id_register_map, r.Map.Id_map, r.Score_map);
                dbcmd.CommandText = sqlQuery;
                dbcmd.ExecuteScalar();
                dbconn.Close();
            }
        }
    }
Пример #30
0
        private void MenuItemFile_Open_proj_Click(object sender, EventArgs e)
        {
            OpenFileDialog openProj = new OpenFileDialog();

            openProj.Title  = "open an project file and update infomations to GUI...";
            openProj.Filter = "MDPROJ(.mdproj)|*.mdproj";
            //importFile.RestoreDirectory = true;
            if (openProj.ShowDialog() == DialogResult.OK)
            {
                currentProjPath = openProj.FileName;
                DeserializeMethod(currentProjPath);

                regMap = DataSet.RegMap;
                // Init tabs with created data tables
                CreateTabs(DataSet.DS_Display);
            }
        }
Пример #31
0
        public MDDataSet(DataSet _ds)
        {
            ds_excel = _ds;
            regMap   = CreateRegMap(_ds);

            if (crazyMode)
            {
                CreateBF_DT_Crazy(regMap);
            }
            else
            {
                CreateBF_DT(regMap);
            }

            CreateCustomerDT();
            Console.WriteLine(regMap.Count());
        }
Пример #32
0
        /// <summary>
        /// Parses an instruction and generates the binary code for it.
        /// </summary>
        /// <param name="address">The address of the instruction being parsed in the .text segment.</param>
        /// <param name="args">An array containing the arguments of the instruction.</param>
        /// <returns>One or more 32-bit integers representing this instruction. If this interface is implemented
        /// for a pseudo-instruction, this may return more than one instruction value.</returns>
        public override IEnumerable <int> GenerateCodeForInstruction(int address, string[] args)
        {
            if (args.Length != 3)
            {
                throw new ArgumentException("Invalid number of arguments provided. Expected 3, received " + args.Length + '.');
            }

            IEnumerable <int> returnVal = null;
            int instruction             = 0;
            int rdReg  = RegisterMap.GetNumericRegisterValue(args[0]);
            int rs1Reg = RegisterMap.GetNumericRegisterValue(args[1]);
            int rs2Reg = 0;

            try
            {
                rs2Reg = RegisterMap.GetNumericRegisterValue(args[2]);

                List <int> instructionList = new List <int>();
                instruction |= (rs2Reg << 20);
                instruction |= (rs1Reg << 15);

                // or opcode/funt3/funct7 = 0x33/0x6/0x0
                instruction |= (0x6 << 12);
                instruction |= (rdReg << 7);
                instruction |= 0x33;
                instructionList.Add(instruction);
                returnVal = instructionList;
            }
            catch (ArgumentException)
            {
                // try parsing as ori instruction
                int  immediate = 0;
                bool isShort   = IntExtensions.TryParseEx(args[2], out immediate);
                if (isShort)
                {
                    var immediateParser = new OriProcessor();
                    returnVal = immediateParser.GenerateCodeForInstruction(address, args);
                }
                else
                {
                    throw;
                }
            }

            return(returnVal);
        }
Пример #33
0
		public static string ConvertToGLSL (ByteArray agal)
		{
			agal.position = 0;

			int magic = agal.readByte ();
			if (magic != 0xA0) {
				throw new InvalidOperationException ("Magic value must be 0xA0, may not be AGAL");
			}

			int version = agal.readInt ();
			if (version != 1) {
				throw new InvalidOperationException ("Version must be 1");
			}

			int shaderTypeId = agal.readByte ();
			if (shaderTypeId != 0xA1) {
				throw new InvalidOperationException ("Shader type id must be 0xA1");
			}

			ProgramType programType = (agal.readByte () == 0) ? ProgramType.Vertex : ProgramType.Fragment;

			var map = new RegisterMap();
			var sb = new StringBuilder();
			while (agal.position < agal.length) {

				// fetch instruction info
				int opcode = agal.readInt();
				uint dest = (uint)agal.readInt();
				ulong source1 = ReadUInt64(agal);
				ulong source2 = ReadUInt64(agal);
				sb.Append("\t");
				sb.AppendFormat("// opcode:{0:X} dest:{1:X} source1:{2:X} source2:{3:X}\n", opcode,
				                dest, source1, source2);

				// parse registers
				var dr  = DestReg.Parse(dest,programType);
				var sr1 = SourceReg.Parse(source1,programType, dr.mask);
				var sr2 = SourceReg.Parse(source2,programType, dr.mask);

				// switch on opcode and emit GLSL 
				sb.Append("\t");
				switch (opcode)
				{
				case 0x17: // m33
					sb.AppendFormat("{0} = {1} * mat3({2}); // m33", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(false) ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Matrix44); // 33?
					break;
				case 0x18: // m44
					sb.AppendFormat("{0} = {1} * {2}; // m44", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(false) ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Matrix44);
					break;
				case 0x00: // mov
					sb.AppendFormat("{0} = {1}; // mov", dr.ToGLSL(), sr1.ToGLSL()); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;
			
				case 0x01: // add
					sb.AppendFormat("{0} = {1} + {2}; // add", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x02: // sub
					sb.AppendFormat("{0} = {1} - {2}; // sub", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x03: // mul
					sb.AppendFormat("{0} = {1} * {2}; // mul", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x04: // div
					sb.AppendFormat("{0} = {1} / {2}; // div", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x07: // max
					sb.AppendFormat("{0} = max({1}, {2}); // max", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x12: // dp3
					sr1.sourceMask = sr2.sourceMask = 7; // adjust dest mask for xyz input to dot product
					sb.AppendFormat("{0} = dot(vec3({1}), vec3({2})); // dp3", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
				
				case 0x13: // dp4
					sr1.sourceMask = sr2.sourceMask = 0xF; // adjust dest mask for xyzw input to dot product
					sb.AppendFormat("{0} = dot(vec4({1}), vec4({2})); // dp4", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x8: // frc
					sb.AppendFormat("{0} = fract({1}); // frc", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x16: // saturate
					sb.AppendFormat("{0} = clamp({1}, 0.0, 1.0); // saturate", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x0E: // normalize
					sb.AppendFormat("{0} = normalize({1}); // normalize", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x27: // kill /  discard
					sb.AppendFormat("// if ({0} > 0.0) discard;", sr1.ToGLSL() ); 
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x28: // tex
					SamplerReg sampler = SamplerReg.Parse(source2, programType);

					switch (sampler.d)
					{
					case 0: // 2d texture
						sr1.sourceMask = 0x3;
						sb.AppendFormat("{0} = texture2D({2}, {1}); // tex", dr.ToGLSL(), sr1.ToGLSL(), sampler.ToGLSL() ); 
						map.Add(sampler, RegisterUsage.Sampler2D);
						break;
					case 1: // cube texture
						sr1.sourceMask = 0x7;
						sb.AppendFormat("{0} = textureCube({2}, {1}); // tex", dr.ToGLSL(), sr1.ToGLSL(), sampler.ToGLSL() ); 
						map.Add(sampler, RegisterUsage.SamplerCube);
						break;
					}
					//sb.AppendFormat("{0} = vec4(0,1,0,1);", dr.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x29: // sge
					sr1.sourceMask = sr2.sourceMask = 0xF; // sge only supports vec4
					sb.AppendFormat("{0} = vec4(greaterThanEqual({1}, {2})){3}; // ste", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(), dr.GetWriteMask() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x2A: // slt
					sr1.sourceMask = sr2.sourceMask = 0xF; // slt only supports vec4
					sb.AppendFormat("{0} = vec4(lessThan({1}, {2})){3}; // slt", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(), dr.GetWriteMask() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
				
				case 0x2C: // seq
					sr1.sourceMask = sr2.sourceMask = 0xF; // seq only supports vec4
					sb.AppendFormat("{0} = vec4(equal({1}, {2})){3}; // seq", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(), dr.GetWriteMask() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
				
				case 0x2D: // sne
					sr1.sourceMask = sr2.sourceMask = 0xF; // sne only supports vec4
					sb.AppendFormat("{0} = vec4(notEqual({1}, {2})){3}; // sne", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(), dr.GetWriteMask() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				default:
					//sb.AppendFormat ("unsupported opcode" + opcode);
					throw new NotSupportedException("Opcode " + opcode);
				}

				sb.AppendLine();
			}


#if PLATFORM_MONOMAC
			var glslVersion = 120;
#elif PLATFORM_MONOTOUCH
			var glslVersion = 100; // Actually this is glsl 1.20 but in gles it's 1.0
#endif

			// combine parts into final progam
			var glsl = new StringBuilder();
			glsl.AppendFormat("// AGAL {0} shader\n", (programType == ProgramType.Vertex) ? "vertex" : "fragment");
			glsl.AppendFormat("#version {0}\n", glslVersion);
#if PLATFORM_MONOTOUCH
			// Required to set the default precision of vectors
			glsl.Append("precision mediump float;\n");
#endif
			glsl.Append (map.ToGLSL(false));
			glsl.AppendLine("void main() {");
			glsl.Append (map.ToGLSL(true));
			glsl.Append(sb.ToString());
			glsl.AppendLine("}");
			System.Console.WriteLine(glsl);
			return glsl.ToString();;
		}
Пример #34
0
		public static string ConvertToGLSL (ByteArray agal, textures.SamplerState[] outSamplers)
		{
			agal.position = 0;

			int magic = agal.readByte ();
			if (magic != 0xA0) {
				throw new InvalidOperationException ("Magic value must be 0xA0, may not be AGAL");
			}

			int version = agal.readInt ();
			if (version != 1) {
				throw new InvalidOperationException ("Version must be 1");
			}

			int shaderTypeId = agal.readByte ();
			if (shaderTypeId != 0xA1) {
				throw new InvalidOperationException ("Shader type id must be 0xA1");
			}

			ProgramType programType = (agal.readByte () == 0) ? ProgramType.Vertex : ProgramType.Fragment;

			var map = new RegisterMap();
			var sb = new StringBuilder();
			while (agal.position < agal.length) {

				// fetch instruction info
				int opcode = agal.readInt();
				uint dest = (uint)agal.readInt();
				ulong source1 = ReadUInt64(agal);
				ulong source2 = ReadUInt64(agal);
//				sb.Append("\t");
//				sb.AppendFormat("// opcode:{0:X} dest:{1:X} source1:{2:X} source2:{3:X}\n", opcode,
//				                dest, source1, source2);

				// parse registers
				var dr  = DestReg.Parse(dest,programType);
				var sr1 = SourceReg.Parse(source1,programType, dr.mask);
				var sr2 = SourceReg.Parse(source2,programType, dr.mask);

				// switch on opcode and emit GLSL 
				sb.Append("\t");
				switch (opcode)
				{
				case 0x00: // mov
					sb.AppendFormat("{0} = {1}; // mov", dr.ToGLSL(), sr1.ToGLSL()); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;
					
				case 0x01: // add
					sb.AppendFormat("{0} = {1} + {2}; // add", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
					
				case 0x02: // sub
					sb.AppendFormat("{0} = {1} - {2}; // sub", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
					
				case 0x03: // mul
					sb.AppendFormat("{0} = {1} * {2}; // mul", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
					
				case 0x04: // div
					sb.AppendFormat("{0} = {1} / {2}; // div", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x05: // rcp
					sb.AppendFormat("{0} = vec4(1) / {1}; // rcp (untested)", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x06: // min
					sb.AppendFormat("{0} = min({1}, {2}); // min", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
					
				case 0x07: // max
					sb.AppendFormat("{0} = max({1}, {2}); // max", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x08: // frc
					sb.AppendFormat("{0} = fract({1}); // frc", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;
					
				case 0x09: // sqrt
					sb.AppendFormat("{0} = sqrt({1}); // sqrt", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;
					
				case 0x0A: // rsq
					sb.AppendFormat("{0} = inversesqrt({1}); // rsq", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;
					
				case 0x0B: // pow
					sb.AppendFormat("{0} = pow({1}, {2}); // pow", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
				
				case 0x0C: // log
					sb.AppendFormat("{0} = log2({1}); // log", dr.ToGLSL(), sr1.ToGLSL()); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x0D: // exp
					sb.AppendFormat("{0} = exp2({1}); // exp", dr.ToGLSL(), sr1.ToGLSL()); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x0E: // normalize
					sb.AppendFormat("{0} = normalize({1}); // normalize", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x0F: // sin
					sb.AppendFormat("{0} = sin({1}); // sin", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x10: // cos
					sb.AppendFormat("{0} = cos({1}); // cos", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x11: // crs
					sr1.sourceMask = sr2.sourceMask = 7; // adjust source mask for xyz input to dot product
					sb.AppendFormat("{0} = cross(vec3({1}), vec3({2})); // crs", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x12: // dp3
					sr1.sourceMask = sr2.sourceMask = 7; // adjust source mask for xyz input to dot product
					sb.AppendFormat("{0} = dot(vec3({1}), vec3({2})); // dp3", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
					
				case 0x13: // dp4
					sr1.sourceMask = sr2.sourceMask = 0xF; // adjust source mask for xyzw input to dot product
					sb.AppendFormat("{0} = dot(vec4({1}), vec4({2})); // dp4", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x14: // abs
					sb.AppendFormat("{0} = abs({1}); // abs", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x15: // neg
					sb.AppendFormat("{0} = -{1}; // neg", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x16: // saturate
					sb.AppendFormat("{0} = clamp({1}, 0.0, 1.0); // saturate", dr.ToGLSL(), sr1.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x17: // m33
				{
					var existingUsage = map.GetUsage(sr2);
					if (existingUsage != RegisterUsage.Vector4)
					{
						sb.AppendFormat("{0} = {1} * mat3({2}); // m33", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(false) ); 
						map.Add(dr, RegisterUsage.Vector4);
						map.Add(sr1, RegisterUsage.Vector4);
						map.Add(sr2, RegisterUsage.Matrix44); // 33?
					}
					else
					{
                        // compose the matrix multiply from dot products
                        sr1.sourceMask = sr2.sourceMask = 7;
                        sb.AppendFormat("{0} = vec3(dot({1},{2}), dot({1},{3}), dot({1},{4})); // m33", dr.ToGLSL(), sr1.ToGLSL(true), 
                                        sr2.ToGLSL(true,0),
                                        sr2.ToGLSL(true,1), 
                                        sr2.ToGLSL(true,2) 
                                        ); 

                        map.Add(dr, RegisterUsage.Vector4);
						map.Add(sr1, RegisterUsage.Vector4);
						map.Add(sr2, RegisterUsage.Vector4, 0); 
						map.Add(sr2, RegisterUsage.Vector4, 1); 
						map.Add(sr2, RegisterUsage.Vector4, 2); 
					}
				}
					break;

				case 0x18: // m44
				{
					var existingUsage = map.GetUsage(sr2);
					if (existingUsage != RegisterUsage.Vector4)
					{
						sb.AppendFormat("{0} = {1} * {2}; // m44", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(false) ); 
						map.Add(dr, RegisterUsage.Vector4);
						map.Add(sr1, RegisterUsage.Vector4);
						map.Add(sr2, RegisterUsage.Matrix44);
					}
					else
					{
                        // compose the matrix multiply from dot products
                        sr1.sourceMask = sr2.sourceMask = 0xF;
                        sb.AppendFormat("{0} = vec4(dot({1},{2}), dot({1},{3}), dot({1},{4}, dot({1},{5})); // m44", dr.ToGLSL(), sr1.ToGLSL(true), 
                                        sr2.ToGLSL(true,0),
                                        sr2.ToGLSL(true,1), 
                                        sr2.ToGLSL(true,2), 
                                        sr2.ToGLSL(true,3) 
                                        ); 

                        map.Add(dr, RegisterUsage.Vector4);
						map.Add(sr1, RegisterUsage.Vector4);
						map.Add(sr2, RegisterUsage.Vector4, 0); 
						map.Add(sr2, RegisterUsage.Vector4, 1); 
						map.Add(sr2, RegisterUsage.Vector4, 2); 
						map.Add(sr2, RegisterUsage.Vector4, 3); 
					}
				}
					break;

				case 0x19: // m34
				{
					// prevent w from being written for a m34
					dr.mask &= 7;

					var existingUsage = map.GetUsage(sr2);
					if (existingUsage != RegisterUsage.Vector4)
					{
						sb.AppendFormat("{0} = {1} * {2}; // m34", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(false) ); 
						map.Add(dr, RegisterUsage.Vector4);
						map.Add(sr1, RegisterUsage.Vector4);
						map.Add(sr2, RegisterUsage.Matrix44);
					}
					else
					{
                        // compose the matrix multiply from dot products
                        sr1.sourceMask = sr2.sourceMask = 0xF;
                        sb.AppendFormat("{0} = vec3(dot({1},{2}), dot({1},{3}), dot({1},{4}); // m34", dr.ToGLSL(), sr1.ToGLSL(true), 
                                        sr2.ToGLSL(true,0),
                                        sr2.ToGLSL(true,1), 
                                        sr2.ToGLSL(true,2)
                                        ); 

                        map.Add(dr, RegisterUsage.Vector4);
						map.Add(sr1, RegisterUsage.Vector4);
						map.Add(sr2, RegisterUsage.Vector4, 0); 
						map.Add(sr2, RegisterUsage.Vector4, 1); 
						map.Add(sr2, RegisterUsage.Vector4, 2); 
					}
				}
					break;

				case 0x27: // kill /  discard
					sb.AppendFormat("if (any(lessThan({0}, vec4(0)))) discard;", sr1.ToGLSL() ); 
					map.Add(sr1, RegisterUsage.Vector4);
					break;

				case 0x28: // tex
					SamplerReg sampler = SamplerReg.Parse(source2, programType);

					switch (sampler.d)
					{
					case 0: // 2d texture
						sr1.sourceMask = 0x3;
						sb.AppendFormat("{0} = texture2D({2}, {1}); // tex", dr.ToGLSL(), sr1.ToGLSL(), sampler.ToGLSL() ); 
						map.Add(sampler, RegisterUsage.Sampler2D);
						break;
					case 1: // cube texture
						sr1.sourceMask = 0x7;
						sb.AppendFormat("{0} = textureCube({2}, {1}); // tex", dr.ToGLSL(), sr1.ToGLSL(), sampler.ToGLSL() ); 
						map.Add(sampler, RegisterUsage.SamplerCube);
						break;
					}
					//sb.AppendFormat("{0} = vec4(0,1,0,1);", dr.ToGLSL() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);

					if (outSamplers != null)
					{
						// add sampler state to output list for caller
						outSamplers[sampler.n] = sampler.ToSamplerState();
					}
					break;

				case 0x29: // sge
					sr1.sourceMask = sr2.sourceMask = 0xF; // sge only supports vec4
					sb.AppendFormat("{0} = vec4(greaterThanEqual({1}, {2})){3}; // ste", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(), dr.GetWriteMask() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				case 0x2A: // slt
					sr1.sourceMask = sr2.sourceMask = 0xF; // slt only supports vec4
					sb.AppendFormat("{0} = vec4(lessThan({1}, {2})){3}; // slt", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(), dr.GetWriteMask() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
				
				case 0x2C: // seq
					sr1.sourceMask = sr2.sourceMask = 0xF; // seq only supports vec4
					sb.AppendFormat("{0} = vec4(equal({1}, {2})){3}; // seq", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(), dr.GetWriteMask() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;
				
				case 0x2D: // sne
					sr1.sourceMask = sr2.sourceMask = 0xF; // sne only supports vec4
					sb.AppendFormat("{0} = vec4(notEqual({1}, {2})){3}; // sne", dr.ToGLSL(), sr1.ToGLSL(), sr2.ToGLSL(), dr.GetWriteMask() ); 
					map.Add(dr, RegisterUsage.Vector4);
					map.Add(sr1, RegisterUsage.Vector4);
					map.Add(sr2, RegisterUsage.Vector4);
					break;

				default:
					//sb.AppendFormat ("unsupported opcode" + opcode);
					throw new NotSupportedException("Opcode " + opcode);
				}

				sb.AppendLine();
			}


#if PLATFORM_MONOMAC
			var glslVersion = 120;
#elif PLATFORM_MONOTOUCH
			var glslVersion = 100; // Actually this is glsl 1.20 but in gles it's 1.0
#endif

			// combine parts into final progam
			var glsl = new StringBuilder();
			glsl.AppendFormat("// AGAL {0} shader\n", (programType == ProgramType.Vertex) ? "vertex" : "fragment");
			glsl.AppendFormat("#version {0}\n", glslVersion);
#if PLATFORM_MONOTOUCH
			// Required to set the default precision of vectors
			glsl.Append("precision mediump float;\n");
#endif
			glsl.Append (map.ToGLSL(false));
			if (programType == ProgramType.Vertex) {
				// this is needed for flipping render textures upside down
				glsl.AppendLine("uniform vec4 vcPositionScale;");
			}
			glsl.AppendLine("void main() {");
			glsl.Append (map.ToGLSL(true));
			glsl.Append(sb.ToString());

			if (programType == ProgramType.Vertex) {
				// this is needed for flipping render textures upside down
				glsl.AppendLine("gl_Position *= vcPositionScale;");
			}
			glsl.AppendLine("}");
			// System.Console.WriteLine(glsl);
			return glsl.ToString();;
		}
Пример #35
0
        private void WriteRegister(RegisterMap register, byte value)
        {
            var data = new[] { (byte)register, value };
            var write = I2CDevice.CreateWriteTransaction(data);
            var writeTransaction = new I2CDevice.I2CTransaction[] { write };

            lock (bus)
            {
                bus.Config = configuration;
                bus.Execute(writeTransaction, 10);
            }
        }