/// <summary>
 /// Compute the operand from the line
 /// </summary>
 /// <param name="item">the current line</param>
 /// <returns>error index</returns>
 private int ResolveOperand(String[] item)
 {
     short adress = 0;
     int modifier = 0;
     try
     {
         adress = (short)Int16.Parse(item[2], System.Globalization.NumberStyles.HexNumber);
     }
     catch
     {
         int val = 0;
         if (labels.TryGetValue(item[2], out val))
         {
             sWord adr = new sWord();
             if (val >= 0x1000)
             {
                 adress = (short)(val - 0x1000 + 0x400);
             }
             else
             {
                 if (val >= 0x400 && val <= 0x7FF)
                 {
                     adr = new sWord((short)val);
                     adress = (short)(adr.getVal(0, 7) + 0x300);
                 }
                 else
                 {
                     adress = (short)val;
                 }
             }
         }
         else if (fixedValue.registers.TryGetValue(item[2], out val))
         {
             adress = (short)val;
         }
         else if(Int32.TryParse(item[2], out modifier))
         {
             adress = (short)(bank_index + modifier);
         }
         else
         {
             return -2;
         }
     }
     return (short)testModifier((int)adress, item);
 }
 public int fFixed_switch(int adr)
 {
     tEr = PB.isErasable();
     tId = (short)PB.getId();
     tFEB = PB.getFEB();
     sWord s = new sWord((short)adr);
     if (s.getVal(10, 11) == 0)
     {
         if ((short)s.getVal(8, 9) == 0)
         { PB = RegBank; }
         else
         {
             PB = new BANK(true, (short)s.getVal(8, 9), 0, AGC_File);
         }
         adr = s.getVal(0, 7);
         e_mem = true;
     }
     else
     {
         PB = new BANK(false, (short)s.getVal(10, 11), 0, AGC_File);
         adr = s.getVal(0, 9);
         e_mem = false;
     }
     return adr;
 }
 private void extraCodes(sWord S)
 {
     int val = 0;
     if (fFixed)
     { val = fFixed_switch(S.getInt()); }
     else { val = S.getInt(); }
     switch (RegBank.get_word(11))
     {
         case 0:
             val = S.getVal(0, 8);
             switch(PC)
             {
                 case 0:
                     Console.WriteLine("READ {0:X4}", val+index);
                     break;
                 case 1:
                     Console.WriteLine("WRITE {0:X4}", val+index);
                     write_chan(val, RegBank.get_word(0));
                     break;
                 case 2:
                     Console.WriteLine("RAND {0:X4}", val+index);
                     break;
                 case 3:
                     Console.WriteLine("WAND {0:X4}", val+index);
                     break;
                 case 4:
                     Console.WriteLine("ROR {0:X4}", val+index);
                     break;
                 case 5:
                     Console.WriteLine("WOR {0:X4}", val+index);
                     break;
                 case 6:
                     Console.WriteLine("RXOR {0:X4}", val+index);
                     break;
                 case 7:
                     Console.WriteLine("WXOR {0:X4}", val+index);
                     break;
             }
             index = 0;
             extra = false;
             break;
         case 1:
             if(QC==0)
             {
                 Console.WriteLine("DV {0:X4}", val + index);
             }
             else
             {
                 Console.WriteLine("BZF {0:X4}", val + index);
             }
             index = 0;
             extra = false;
             break;
         case 2:
             switch(QC)
             {
                 case 1:
                     Console.WriteLine("MSU {0:X4}", val + index);
                     break;
                 case 2:
                     if (val == 7)
                     {
                         Console.WriteLine("ZQ");
                     }
                     else
                     {
                         Console.WriteLine("QXCH {0:X4}", val + index);
                     }
                     break;
                 case 3:
                     Console.WriteLine("AUG {0:X4}", val + index);
                     break;
                 case 4:
                     Console.WriteLine("DIM {0:X4}", val + index);
                     break;
             }
             index = 0;
             extra = false;
             break;
         case 3:
             if (val == 0)
             {
                 Console.WriteLine("DCOM");
             }
             else
             {
                 Console.WriteLine("DCA {0:X4}", val + index);
             }
             index = 0;
             extra = false;
             break;
         case 4:
             Console.WriteLine("DCS {0:X4}", val + index);
             index = 0;
             extra = false;
             break;
         case 5:
             Console.WriteLine("INDEX {0:X4}", val + index);
             index = PB.get_word((short)(val + index));
             extra = true;
             break;
         case 6:
             if(QC==0)
             { Console.WriteLine("SU {0:X4}", val + index); }
             else { Console.WriteLine("BZMF {0:X4}", val + index); }
             index = 0;
             extra = false;
             break;
         case 7:
             if (val == 0)
             {
                 Console.WriteLine("SQUARE");
             }
             else
             {
                 Console.WriteLine("MP {0:X4}", val + index);
             }
             index = 0;
             extra = false;
             break;
     }
 }
        //Execution
        /// <summary>
        /// <para>edit adress registry (FB/EB/FEB/S) based on the bits 12-1 of the current instruction</para>
        /// <para>detect usage of FB/EB register</para>
        /// <para>if not needed, will set them accordingly to the bank to load</para>
        /// </summary>
        /// <param name="adress">byte[] : 16b adress word</param>
        /// <returns>bool : type (true : erasable, false : fixed)</returns>
        public bool build_adress_reg(sWord adress)
        {
            short S = 0;

            bool erasable = false;
            if (extra && adress.getVal(12, 14) == 0)//IO Code detection
            {
                S = adress.getVal(0, 8);
                PC = adress.getVal(9, 11);
                erasable = true;
                fFixed = false;
            }
            else if (adress.getVal(10,11) == 0)
            {
                if ((adress.getVal(9, 9) != 1) | (adress.getVal(8,8) != 1))
                {
                    S = adress.getVal(0, 11);
                    fFixed = true;
                }
                else
                {
                    S = (short)(adress.getVal(0, 7));
                    fFixed = false;
                }
                erasable = true;
            }
            else if (adress.getVal(10,11) == 2 | adress.getVal(10,11)==3)
            {
                    S = adress.getVal(0, 10);
                    erasable = false;
                    fFixed = true;
            }
            else
            {
                S = (short)(adress.getVal(0, 9));
                erasable = false;
                fFixed = false;
            }
            RegBank.set_hex(12, S); //set S reg to operand value
            return erasable;
        }