-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhunkster.pas
135 lines (111 loc) · 2.9 KB
/
hunkster.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
program hunkster;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, CustApp,
hunklib;
type
{ THunkster }
THunkster = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
end;
{ THunsker }
procedure THunkster.DoRun;
var
MemLoad,Size : Longword;
IncludeFileSize : boolean;
HunkName : String;
infile,outfile : string;
outF : File;
DataName,DataSizeName : String;
begin
CaseSensitiveOptions:=false;
// parse parameters
if HasOption('h', 'help') or (ParamCount < 2) then begin
WriteHelp;
Terminate;
Exit;
end;
infile:=paramstr(1);
outfile:=paramstr(2);
MemLoad:=ANY_MEM;
IncludeFileSize:=False;
Dataname:='_'+ExtractFileName(infile);
DataSizeName:=DataName+'_size';
HunkName:='ANY';
if UpperCase(GetOptionValue('m')) = 'CHIP' then
begin
MemLoad:=CHIP_MEM;
Hunkname:='CHIP';
end;
if UpperCase(GetOptionValue('m')) = 'FAST' then
begin
MemLoad:=FAST_MEM;
Hunkname:='FAST';
end;
if GetOptionValue('dn')<>'' then
begin
DataName:=GetOptionValue('dn');
//writeln('Dataname:',DataName);
end;
if GetOptionValue('ds')<>'' then DataSizeName:=GetOptionValue('ds');
if GetOptionValue('hn') <>'' then Hunkname:=GetOptionValue('hn');
if HasOption('i','includesize') then IncludeFileSize:=true;
//using System.Assign because of name collision with class
System.Assign(outF,outFile);
System.Rewrite(outF,1);
write('Writing HunkUnit..');
WriteHunkUnit(outF);
write('HunkName..',HunkName,'..');
WriteHunkName(outF,HunkName);
write('HunkData..');
size:=WriteHunkData(outF,MemLoad,inFile,IncludeFileSize);
write('HunkExt..');
WriteHunkExt(outF,DataName);
if IncludeFileSize then
begin
write('HunkExt..',DataSizeName,'..');
WriteHunkExtSize(outF,DataSizeName,size);
end;
writeln('HunkEnd');
WriteHunkEnd(outF);
System.close(outF);
// stop program loop
Terminate;
end;
constructor THunkster.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor THunkster.Destroy;
begin
inherited Destroy;
end;
procedure THunkster.WriteHelp;
begin
{ add your help code here }
writeln('Hunkster v1.0 for Windows/Linux By RetroNick');
writeln('Usage: Hunkster infile outhunkfile');
writeln(' Optional -DN (DataName Value)');
writeln(' -DS (DataNameSize Value)');
writeln(' -I (IncludeSize');
writeln(' -HN (HunkName Value');
writeln(' -M (Load to Memory {Chip,Fast,Any}');
writeln('eg. Hunkster image.xgf image.o -DN _image -M chip')
end;
var
Application: THunkster;
begin
Application:=THunkster.Create(nil);
Application.Title:='TheHunkster';
Application.Run;
Application.Free;
end.