function writeline(ADDR,RECLEN,RECTYPE:integer;
var buf:buffer):string;
var i:integer;
CHKSUM:byte;
begin
CHKSUM:=0;
result:=':'+inttohex(RECLEN,2)+
inttohex(ADDR,4)+inttohex(RECTYPE,2);
CHKSUM:=RECLEN+lo(ADDR)+hi(ADDR);
for i:=0 to RECLEN-1 do begin
result:=result+inttohex(buf[ADDR+i],2);
CHKSUM:=CHKSUM+buf[ADDR+i];
end;
result:=result+inttohex(256-CHKSUM,2);
end;
function write_eof:string;
begin
result:=':00'+'0000'+'01'+'FF'; // :00000001FF
end;
To test the above routine use this example
procedure TForm1.Button2Click(Sender: TObject);
var Fname,line:string;
Fp : textfile;
ErrorCode,StartAddr,ByteCnt:integer;
A_Line,EOF_HEX:string;
begin
StartAddr:=$0000; // start address
ByteCnt:=3; // 3 bytes
SetLength(HexBufOut,ByteCnt);
HexBufOut[0]:=$01;
HexBufOut[1]:=$02;
HexBufOut[2]:=$03;
Fname:='test1.hex';
AssignFile(Fp,Fname); { File selected in dialog }
Rewrite(Fp);
// write 16 bytes in HexBuf
A_Line:=writeline(StartAddr,ByteCnt,$00,HexBufOut);
EOF_HEX:=':00'+'0000'+'01'+'FF';// write end of HEX file
writeln(Fp,A_Line);
writeln(Fp,EOF_HEX);
closefile(Fp);
end;
Wyszukiwarka
Podobne podstrony:
READ HEX File FormatFile Formats And Extensionsdef file formatDiffering file formatsFile Formatfile formats recovered by photorecdb tech file formatAuxiliary File FormatPOS File Formatfun160 file reg read write enfile8885Fadal Format 2 (AC) B807 12file D Download Polki Wirtualna Polska8Fadal Format 2 [MM] MW60 89Fadal Format 2 [PEP] M116 89 1SGH Flasher Dumper v 07 dif formatwięcej podobnych podstron