Ver Mensaje Individual
  #20  
Antiguo 23-03-2008
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Bueno, siguiendo con mi respuesta anterior:
Código Delphi [-]
type
  TBuffer = array[$0000..$FFFF] of Byte;

// Insertamos la linea de datos en un buffer
function Insertar(Str: String; var Buffer: TBuffer): String;
var
  i,j,k: Integer;
begin
  Result:= EmptyStr;
  Str:= Trim(Str);
  if Copy(Str,1,1) = ':' then
    if TryStrToInt('$' + Copy(Str,2,2),i) then
      if Length(Str) = ((2*i) + 11) then
        if TryStrToInt('$' + Copy(Str,4,4),j) then
          if TryStrToInt('$' + Copy(Str,8,2),k) then
            if k = 0 then
            begin
              Str:= Copy(Str,10,2*i);
              for k:= j to (j + i - 1) do
              begin
                Buffer[k]:= StrToInt('$' + Copy(Str,1,2));
                Delete(Str,1,2);
              end;
            end;
end;


// Aqui leemos el archivo y mostramos la informacion en un memo
var
  i,j: Integer;
  Str: String;
  Buffer: TBuffer;
begin
  Memo1.Clear;
  with TStringList.Create do
  try
    LoadFromFile('d:\test.hex');
    // Llenamos todo el buffer con ceros
    FillChar(Buffer,Sizeof(Buffer),#0);
    // Leemos el archivo linea a linea e insertamos los datos en el buffer
    for i:= 0 to Count - 1 do
      Insertar(Strings[i],Buffer);
    Str:= EmptyStr;
    j:= Sizeof(Buffer) - 1;
    // Buscamos el ultimo dato que no es un cero
    while (Buffer[j] = 0) and (j > 0) do
      dec(j);
    // Mostramos el contenido del buffer en un memo
    for i:= 0 to j do
    begin
      Str:= Str + #32 + IntToHex(Buffer[i],2);
      // 16 bytes por linea
      if ((i+1) mod 16 = 0) then
      begin
        Memo1.Lines.Add(Str);
        Str:= EmptyStr;
      end;
    end;
  finally
    Free;
  end;
end;

Solo quedaría añadir algunas cosillas, como la comprobación de la "suma de comprobación".

Última edición por seoane fecha: 23-03-2008 a las 17:05:05.
Responder Con Cita