-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBIN2CPP.PAS
59 lines (54 loc) · 1.41 KB
/
BIN2CPP.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{ @author: Sylvain Maltais ([email protected])
@created: 2023
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program BIN2CPP;
Var
Source:File;
Target:Text;
Tampon:Array[0..0]of Byte;
ByteReaded:Integer;
Position:Byte;
Function ByteHex2Str(value:Byte):String;
Const
matrix:Array[0..15]of Char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
Begin
ByteHex2Str:=matrix[(value shr 4) and $0F]+matrix[value and $F];
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')Then Begin
WriteLn('BIN2CPP : Cette commande permet de convertir un fichier binaire en tableau de C++.');
WriteLn;
WriteLn('Syntaxe : BIN2CPP fichier fichier.cpp');
End
Else
If ParamCount=2Then Begin
Assign(Source,ParamStr(1));
Reset(Source,1);
Assign(Target,ParamStr(2));
Rewrite(Target);
Position:=0;
WriteLn(Target,'const unsigned char samples[',FileSize(Source),'] = {');
Write(Target,' ');
While Not EOF(Source)do Begin
BlockRead(Source,Tampon,1,ByteReaded);
Write(Target,'0x',ByteHex2Str(Tampon[0]));
If Not EOF(Source)Then Begin
Write(Target,', ');
Inc(Position);
If Position=8Then BEgin
WriteLn(Target);
Write(Target,' ');
End;
Position:=Position and 7;
End;
End;
WriteLn(Target);
WriteLn(Target,'};');
Close(Target);
Close(Source);
End
Else
WriteLn('Parametre invalide !');
END.