-
Notifications
You must be signed in to change notification settings - Fork 5
/
BIN2PAS.PAS
58 lines (54 loc) · 1.43 KB
/
BIN2PAS.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: 2021
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program BIN2PAS;
Var
Source:File {$IFDEF FPC}of Byte{$ENDIF};
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('BIN2PAS : Cette commande permet de convertir un ficiher binaire en tableau de Pascal.');
WriteLn;
WriteLn('Syntaxe : BIN2PAS fichier fichier.pas');
End
Else
If ParamCount=2Then Begin
Assign(Source,ParamStr(1));
Reset(Source);
Assign(Target,ParamStr(2));
Rewrite(Target);
Position:=0;
WriteLn(Target,'Const samples:Array[0..',FileSize(Source)-1,'] of Byte=(');
Write(Target,' ');
While Not EOF(Source)do Begin
BlockRead(Source,Tampon,1,ByteReaded);
Write(Target,'$',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.