Exemplo n.º 1
0
 public static void TestHexRange()
 {
     for (var c = '\0'; c < 255; ++c)
     {
         if (validHexChars.Contains(char.ToUpper(c)))
         {
             Assert.Equal(Convert.ToInt32(c.ToString(), 16), ByteUtil.ByteParseHex1(c));
         }
         else
         {
             Assert.Throws <InvalidDataException>(() => ByteUtil.ByteParseHex1(c));
         }
     }
 }
Exemplo n.º 2
0
        // note: performance-intensive function. be really careful when adding stuff here.
        public RomByte DecodeRomByte(string line)
        {
            var input = PrepLine(line);

            var newByte = new RomByte();

            var flagTxt     = input[0];
            var otherFlags1 = Fake64Encoding.DecodeHackyBase64(input[1]);

            newByte.DataBank     = ByteUtil.ByteParseHex2(input[2], input[3]);
            newByte.DirectPage   = (int)ByteUtil.ByteParseHex4(input[4], input[5], input[6], input[7]);
            newByte.Arch         = (Data.Architecture)(ByteUtil.ByteParseHex1(input[8]) & 0x3);
            newByte.BaseAddr     = (int)ByteUtil.ByteParseHex6(input[9], input[10], input[11], input[12], input[13], input[14]);
            newByte.IndirectAddr = (int)ByteUtil.ByteParseHex6(input[15], input[16], input[17], input[18], input[19], input[20]);
            newByte.TypeConstant = (Data.ConstantType)(ByteUtil.ByteParseHex1(input[21]));

#if EXTRA_DEBUG_CHECKS
            Debug.Assert(Fake64Encoding.EncodeHackyBase64(otherFlags1) == o1_str);
#endif

            newByte.XFlag = ((otherFlags1 >> 2) & 0x1) != 0;
            newByte.MFlag = ((otherFlags1 >> 3) & 0x1) != 0;
            newByte.Point = (Data.InOutPoint)((otherFlags1 >> 4) & 0xF);

            var found = false;
            foreach (var e in FlagEncodeTable)
            {
                if (e.C != flagTxt)
                {
                    continue;
                }

                newByte.TypeFlag = e.F;
                found            = true;
                break;
            }
            if (!found)
            {
                throw new InvalidDataException("Unknown FlagType");
            }

            return(newByte);
        }
Exemplo n.º 3
0
 public static void TestHex1()
 {
     Assert.Equal(0xF, ByteUtil.ByteParseHex1('F'));
 }