kcpmtk/ihex.pas

95 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2023-10-03 10:07:21 +00:00
const
2023-10-03 19:28:45 +00:00
IRecEOF : String[11] = ':00000001FF';
2023-10-03 23:19:22 +00:00
IRecDat : Byte = 0;
2023-10-03 10:07:21 +00:00
type
2023-10-03 19:28:45 +00:00
LnStr = String[64];
2023-10-03 10:07:21 +00:00
{irec stores an individual record.}
irec = record
Addr : Integer;
2023-10-03 19:28:45 +00:00
Data : array [1..32] of Byte;
Count : Byte;
MaxCount : Byte;
2023-10-03 23:19:22 +00:00
RType : Byte;
2023-10-03 19:28:45 +00:00
end;
2023-10-03 23:19:22 +00:00
function IsWhSp(c: Char): Boolean;
var
res : Boolean;
2023-10-03 19:28:45 +00:00
begin
2023-10-03 23:19:22 +00:00
res := False;
2023-10-03 19:28:45 +00:00
2023-10-03 23:19:22 +00:00
case c of
' ' : res := True;
#$0A : res := True;
#$0D : res := True;
end;
IsWhSp := res;
end;
2023-10-03 19:28:45 +00:00
function RdDumpLn(Line : LnStr): irec;
var
lrec : irec;
begin
lrec.Addr := ReadWord(Line);
2023-10-03 23:19:22 +00:00
lrec.RType := IRecDat;
lrec.Count := 0;
Delete(Line, 1, 4);
while (Line <> '') do
2023-10-03 19:28:45 +00:00
begin
2023-10-03 23:19:22 +00:00
if IsWhSp(Line[1]) then Delete(Line, 1, 1);
if Line <> '' then
begin
lrec.Count := lrec.Count + 1;
lrec.Data[lrec.Count] := ReadByte(Line);
Delete(Line, 1, 2);
end;
2023-10-03 19:28:45 +00:00
end;
RdDumpLn := lrec;
end;
function IRecCS(rec : irec) : Byte;
var
2023-10-03 23:19:22 +00:00
cksm : Integer;
I : Integer;
2023-10-03 19:28:45 +00:00
begin
2023-10-03 23:19:22 +00:00
cksm := rec.Addr + rec.Count + rec.RType;
for I := 1 to rec.Count do cksm := cksm + rec.Data[I];
cksm := cksm and $00FF;
2023-10-03 19:28:45 +00:00
2023-10-03 23:19:22 +00:00
IRecCS := not Byte(cksm) + 1;
2023-10-03 19:28:45 +00:00
end;
2023-10-03 23:19:22 +00:00
procedure PrnRec(rec : irec);
2023-10-03 19:28:45 +00:00
var
I : Byte;
begin
Write(':');
Write(WriteByte(rec.Count));
Write(WriteWord(rec.Addr));
2023-10-03 23:19:22 +00:00
Write(WriteByte(rec.RType));
2023-10-03 19:28:45 +00:00
for I := 1 to rec.Count do
Write(WriteByte(rec.Data[I]));
2023-10-03 10:07:21 +00:00
2023-10-03 19:28:45 +00:00
Writeln(WriteByte(IRecCS(rec)));
end;
2023-10-03 23:19:22 +00:00
procedure WrRec(rec : irec; var outf : Text);
var
I : Byte;
begin
Write(outf, ':');
Write(outf, WriteByte(rec.Count));
Write(outf, WriteWord(rec.Addr));
Write(outf, WriteByte(rec.RType));
for I := 1 to rec.Count do
Write(outf, WriteByte(rec.Data[I]));
Writeln(outf, WriteByte(IRecCS(rec)));
end;