public static bool ParseTextLine(string line, ModificationData modData)
        {
            // caution: very performance-sensitive function, please take care when making modifications
            // string.IndexOf() is super-slow too.
            // Input lines must follow this strict format and be this exact formatting and column indices.
            // 028cde rep #$30               A:0004 X:0000 Y:0004 S:1fdd D:0000 DB:02 nvmxdiZC V:133 H: 654 F:36
            if (line.Length < 80)
            {
                return(false);
            }

            // TODO: add error treatment / validation here.

            modData.SnesAddress = (int)ByteUtil.ByteParseHex(line, 0, 6);
            modData.DirectPage  = (int)ByteUtil.ByteParseHex(line, CachedIdx.D, 4);
            modData.DataBank    = (int)ByteUtil.ByteParseHex(line, CachedIdx.Db, 2);

            // 'X' = unchecked in bsnesplus debugger UI = (8bit), 'x' or '.' = checked (16bit)
            modData.XFlagSet = line[CachedIdx.FX] == 'X';

            // 'M' = unchecked in bsnesplus debugger UI = (8bit), 'm' or '.' = checked (16bit)
            modData.MFlagSet = line[CachedIdx.FM] == 'M';

            return(true);
        }
Ejemplo n.º 2
0
        public static void TestHexM()
        {
            Assert.Equal((uint)0xF029, ByteUtil.ByteParseHex("F029", 0, 4));
            Assert.Equal((uint)0xF02, ByteUtil.ByteParseHex("F02", 0, 3));
            Assert.Equal((uint)0xF0, ByteUtil.ByteParseHex("F0", 0, 2));
            Assert.Equal((uint)0xF, ByteUtil.ByteParseHex("F", 0, 1));

            Assert.Equal((uint)0xF, ByteUtil.ByteParseHex(" F", 1, 1));
            Assert.Equal((uint)0xF2, ByteUtil.ByteParseHex(" F2 ", 1, 2));
            Assert.Equal((uint)0xF029, ByteUtil.ByteParseHex(" F0297", 1, 4));
            Assert.Equal((uint)0xF02979A, ByteUtil.ByteParseHex(" F02979A", 1, 7));
            Assert.Equal(0xF02979A9, ByteUtil.ByteParseHex(" F02979A9", 1, 8));

            Assert.Throws <ArgumentException>(() => ByteUtil.ByteParseHex("F02988554324AC", 0, 9));
            Assert.Throws <ArgumentException>(() => ByteUtil.ByteParseHex("F029", 0, 0));
        }
        public bool ParseTextLine(string line, ModificationData modData)
        {
            // caution: very performance-sensitive function, please take care when making modifications
            // string.IndexOf() is super-slow too.
            // Input lines must follow this strict format and be this exact formatting and column indices.
            // 028cde rep #$30               A:0004 X:0000 Y:0004 S:1fdd D:0000 DB:02 nvmxdiZC V:133 H: 654 F:36
            if (line.Length < 80)
            {
                return(false);
            }

            // performance: we could just parse the whitespace, but,
            // tracelogs have a huge amount of lines. so we parse the first line,
            // then save the offsets for all other lines in the same file.
            if (TextImportFormatCached.LastLineLength != line.Length)
            {
                TextImportFormatCached.RecomputeCachedIndicesBasedOn(line);
            }

            // TODO: add error treatment / validation here.

            modData.SnesAddress = (int)ByteUtil.ByteParseHex(line, 0, 6);
            modData.DirectPage  = (int)ByteUtil.ByteParseHex(line, TextImportFormatCached.D, 4);
            modData.DataBank    = (int)ByteUtil.ByteParseHex(line, TextImportFormatCached.Db, 2);

            // 'X' (if emulation mode) or 'B' (if native mode) = unchecked in bsnesplus debugger UI = (8bit)
            // 'x' or '.' = checked (16bit)
            modData.XFlagSet = line[TextImportFormatCached.Fx] == 'X' || line[TextImportFormatCached.Fx] == 'B';

            // 'M' (if emulation mode) or '1' (if native mode) = unchecked in bsnesplus debugger UI = (8bit)
            // 'm' or '.' = checked (16bit)
            modData.MFlagSet = line[TextImportFormatCached.Fm] == 'M' || line[TextImportFormatCached.Fm] == '1';

            // TODO: we could capture native vs emulation mode here and mark that.

            return(true);
        }