home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Party 1994: Try This At Home
/
disk_image.bin
/
source
/
gallery
/
subdirs.exe
/
TEXTURE
/
BIN2INC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-07-10
|
2KB
|
95 lines
{$V-}
uses dos;
var I : File;
O : Text;
NI,xNI,nNI,NO : string;
d,nm,e : string;
data : array[0..9] of byte;
InFileSize, LIM, k : longint;
count : integer;
function ToHex( var V; len : byte ) : string;
const Hex : string = '0123456789abcdef';
type BArray = array[1..16] of byte;
var s : string;
i,k : integer;
b : byte;
begin
s[1] := '0'; k := 2;
for i := len downto 1 do begin
b := BArray(V)[i];
s[k] := Hex[(b div 16)+1]; inc(k);
s[k] := Hex[(b mod 16)+1]; inc(k);
end;
s[k] := 'h';
s[0] := chr(k);
ToHex := s;
end;
begin
writeln('BIN2INC. Binary to include file converter // A.R-M. 7/93');
writeln;
if paramcount<1 then begin
write('Binary input file name [.BIN]: '); readln(NI);
end else NI := ParamStr(1);
FSplit( NI, d,nNI,e );
if e='' then e := '.BIN';
xNI := nNI+e;
NI := d+xNI;
if paramcount<2 then begin
write('.INC output file name [',nNI,'.INC]: '); readln(NO);
end else NO := ParamStr(2);
FSplit( NO, d,nm,e );
if nm='' then nm := nNI;
if e='' then e := '.INC';
NO := d+nm+e;
assign(I,NI); reset(I,1);
assign(O,NO); rewrite(O);
writeln(O,'; data file created from "',xNI,'" by BIN2INC, ARM 7/93');
writeln(O);
InFileSize := FileSize(I);
if InFileSize>10 then begin
write(O,' DT ');
count := 0;
LIM := InFileSize div 10;
for k := 1 to LIM do begin
blockread(I, data, 10);
write(O, ToHex(data,10));
inc (count);
if count=8 then begin
writeln(O);
if k<LIM then write(O,' DT ');
count := 0
end else
if k<LIM then write(O,',');
end;
end;
if count<>0 then writeln(O);
LIM := InFileSize mod 10;
if LIM>0 then begin
write(O,' DB ');
count := InFileSize mod 10;
blockread(I, data, count);
for k := 1 to count-1 do write(O, ToHex(data[k-1],1),',');
writeln(O,toHex(data[k-1],1));
end;
writeln(O);
close(O);
close(I);
writeln('"',nm+e,'" successfully created.');
end.