Esempio n. 1
0
        public char[] EncodeLine(Parser.Line l)
        {
            var vals = new List <byte>();

            switch (l.Type)
            {
            case Parser.LineType.Header:
                return(null);    // no definition

            case Parser.LineType.Data:
                vals.Add((byte)l.Data.Count());
                vals.Add((byte)(l.Address >> 8));
                vals.Add((byte)(l.Address & 0xff));
                vals.Add(CODE_DATA);
                vals = vals.Concat(l.Data).ToList();
                break;

            case Parser.LineType.Offset:
                vals.Add(0x02); // byte count
                vals.Add(0x00); // address H
                vals.Add(0x00); // address L
                if ((l.Address & 0xFFF00000) != 0)
                {               // xxxx0000H
                    vals.Add(CODE_EX_LIN_ADDR);
                    vals.Add((byte)(l.Address >> 24));
                    vals.Add((byte)(l.Address >> 16));
                }
                else
                {       // 000xxxx0H
                    vals.Add(CODE_EX_SEG_ADDR);
                    vals.Add((byte)(l.Address >> 12));
                    vals.Add((byte)(l.Address >> 4));
                }
                break;

            case Parser.LineType.Termination:
                vals.Add(0x00);     // byte count
                vals.Add(0x00);     // address H
                vals.Add(0x00);     // address L
                vals.Add(CODE_EOF);
                break;

            default:
                throw new NotImplementedException();
            }
            vals.Add(genChecksum(vals));

            return(genCharArray(vals));
        }
Esempio n. 2
0
        public Parser.Line DecodeLine(char[] a)
        {
            var l    = new Parser.Line();
            var vals = genByteArray(a);
            var type = vals[0]; // "Sx"
            var len  = vals[1];

            l.Valid = (vals.Length == len + 2) && evalChecksum(vals);
            switch (type)
            {
            case CODE_HEADER:
                l.Type    = Parser.LineType.Header;
                l.Address = (vals[2] << 8) | vals[3];
                l.Data    = new byte[len - (2 + 1)]; // address(2)+checksum(1)
                Array.Copy(vals, 4, l.Data, 0, l.Data.Length);
                break;

            case CODE_DATA16:
            case CODE_TERMINATE16:
                l.Type    = (type == CODE_DATA16) ? Parser.LineType.Data : Parser.LineType.Termination;
                l.Address = (vals[2] << 8) | vals[3];
                l.Data    = new byte[len - (2 + 1)];  // address(2)+checksum(1)
                Array.Copy(vals, 4, l.Data, 0, l.Data.Length);
                break;

            case CODE_DATA24:
            case CODE_TERMINATE24:
                l.Type    = (type == CODE_DATA24) ? Parser.LineType.Data : Parser.LineType.Termination;
                l.Address = (vals[2] << 16) | (vals[3] << 8) | vals[4];
                l.Data    = new byte[len - (3 + 1)];  // address(3)+checksum(1)
                Array.Copy(vals, 5, l.Data, 0, l.Data.Length);
                break;

            case CODE_DATA32:
            case CODE_TERMINATE32:
                l.Type    = (type == CODE_DATA32)? Parser.LineType.Data: Parser.LineType.Termination;
                l.Address = (vals[2] << 24) | (vals[3] << 16) | (vals[4] << 8) | vals[5];
                l.Data    = new byte[len - (4 + 1)];  // address(4)+checksum(1)
                Array.Copy(vals, 6, l.Data, 0, l.Data.Length);
                break;

            case CODE_COUNT16:
            case CODE_COUNT24:
                throw new NotImplementedException();
            }
            return(l);
        }
Esempio n. 3
0
        public char[] EncodeLine(Parser.Line l)
        {
            var vals = new List <byte>();
            var len  = (byte)(l.Data.Count() + 4);

            switch (l.Type)
            {
            case Parser.LineType.Header:
                vals.Add(CODE_HEADER);
                vals.Add(len);
                vals.Add(0x00);
                vals.Add(0x00);
                break;

            case Parser.LineType.Data:
                vals.Add(CODE_DATA24);
                vals.Add(len);
                vals.Add((byte)(l.Address >> 16));
                vals.Add((byte)(l.Address >> 8));
                vals.Add((byte)(l.Address & 0xff));
                break;

            case Parser.LineType.Offset:
                return(null);    // no definition

            case Parser.LineType.Termination:
                vals.Add(CODE_TERMINATE24);
                vals.Add(len);
                vals.Add(0x00);
                vals.Add(0x00);
                vals.Add(0x00);
                break;

            default:
                throw new NotImplementedException();
            }
            vals = vals.Concat(l.Data).ToList();
            vals.Add(genChecksum(vals));

            return(genCharArray(vals));
        }
Esempio n. 4
0
        public Parser.Line DecodeLine(char[] a)
        {
            var l    = new Parser.Line();
            var vals = genByteArray(a);
            var len  = vals[0];

            l.Valid = (vals.Length == len + 5) && evalChecksum(vals);
            var addr = (vals[1] << 8) | vals[2];

            switch (vals[3])
            {
            case CODE_DATA:
                l.Type    = Parser.LineType.Data;
                l.Address = addr;
                l.Data    = new byte[len];
                Array.Copy(vals, 4, l.Data, 0, len);
                break;

            case CODE_EOF:
                l.Type = Parser.LineType.Termination;
                break;

            case CODE_EX_SEG_ADDR:
                l.Type = Parser.LineType.Offset;
                if (len != 2)
                {
                    l.Valid = false;
                }
                else
                {
                    l.Address = (vals[4] << 12) | (vals[5] << 4);
                }
                break;

            case CODE_ST_SEG_ADDR:
                if (len != 4)
                {
                    l.Valid = false;
                }
                else
                {
                    _regCS = ((uint)vals[4] << 8) | ((uint)vals[5] << 0);
                    _regIP = ((uint)vals[6] << 8) | ((uint)vals[7] << 0);
                }
                break;

            case CODE_EX_LIN_ADDR:
                l.Type = Parser.LineType.Offset;
                if (len != 2)
                {
                    l.Valid = false;
                }
                else
                {
                    l.Address = (vals[4] << 24) | (vals[5] << 16);
                }
                break;

            case CODE_ST_LIN_ADDR:
                if (len != 2)
                {
                    l.Valid = false;
                }
                else
                {
                    _regEIP = ((uint)vals[4] << 24) | ((uint)vals[5] << 16) | ((uint)vals[6] << 8) | ((uint)vals[7] << 0);
                }
                break;
            }

            return(l);
        }