示例#1
0
        static void LoadHexProgram()
        {
            using (var hexStreamReader = new HexStreamReader("program.hex"))
            {
                RecordType recordType;
                var        extendedLinearAddress = 0;
                do
                {
                    // Consume the leading semicolon
                    hexStreamReader.Read();

                    // Retrieve the informations
                    var recordLength  = hexStreamReader.ReadHex(2);
                    var recordAddress = hexStreamReader.ReadHex(4);
                    recordType = (RecordType)hexStreamReader.ReadHex(2);
                    byte[] data = null;

                    switch (recordType)
                    {
                    case RecordType.Data:
                        data = new byte[recordLength];
                        for (var i = 0; i < recordLength; i++)
                        {
                            data[i] = (byte)hexStreamReader.ReadHex(2);
                        }
                        break;

                    case RecordType.ExtendedLinearAddress:
                        extendedLinearAddress = hexStreamReader.ReadHex(4);
                        break;

                    case RecordType.ExtendedSegmentAddress:
                        throw new NotImplementedException("Segment Addressing is not supported");
                    }

                    // Todo check the CRC
                    var crc = hexStreamReader.ReadHex(2);

                    // Consume the newline characters, can be \n or \r\n depending on the environment
                    foreach (var t in Environment.NewLine)
                    {
                        hexStreamReader.Read();
                    }

                    // Populate the memory
                    if (recordType == RecordType.Data)
                    {
                        var effectiveAddress = (extendedLinearAddress << 8) | (recordAddress);
                        Array.Copy(data, 0, memoryProgram, effectiveAddress, recordLength);
                    }
                } while (recordType != RecordType.EndOfFile);
            }
        }
示例#2
0
        static void LoadHexProgram()
        {
            using (var hexStreamReader = new HexStreamReader("program.hex"))
            {
                RecordType recordType;
                var extendedLinearAddress = 0;
                do
                {
                    // Consume the leading semicolon
                    hexStreamReader.Read();

                    // Retrieve the informations
                    var recordLength = hexStreamReader.ReadHex(2);
                    var recordAddress = hexStreamReader.ReadHex(4);
                    recordType = (RecordType)hexStreamReader.ReadHex(2);
                    byte[] data = null;

                    switch (recordType)
                    {
                        case RecordType.Data:
                            data = new byte[recordLength];
                            for (var i = 0; i < recordLength; i++)
                            {
                                data[i] = (byte)hexStreamReader.ReadHex(2);
                            }
                            break;
                        case RecordType.ExtendedLinearAddress:
                            extendedLinearAddress = hexStreamReader.ReadHex(4);
                            break;
                        case RecordType.ExtendedSegmentAddress:
                            throw new NotImplementedException("Segment Addressing is not supported");
                    }

                    // Todo check the CRC
                    var crc = hexStreamReader.ReadHex(2);

                    // Consume the newline characters, can be \n or \r\n depending on the environment
                    foreach (var t in Environment.NewLine)
                    {
                        hexStreamReader.Read();
                    }

                    // Populate the memory
                    if (recordType == RecordType.Data)
                    {
                        var effectiveAddress = (extendedLinearAddress << 8) | (recordAddress);
                        Array.Copy(data, 0, memoryProgram, effectiveAddress, recordLength);
                    }

                } while (recordType != RecordType.EndOfFile);
            }
        }