-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtbinobj.pas
261 lines (223 loc) · 6.74 KB
/
rtbinobj.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// Turbo Pascal BINOBJ clone for Windows\Linux - output is exactly the same
Program RtBinToObj;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, CustAPP,
objlib,hunklib,bsavelib,cofflib;
Const
ProgramName = 'RtBinObj v1.8 - Released December 24 - 2023 By RetroNick';
CompTP = 0;
CompTC = 1;
CompOW16 = 2;
CompOW32 = 3;
CompAmigaHunk = 4;
CompBSAVE = 5;
CompCOFF = 6;
CompTMT = 7;
type
{ RtBinObj }
TRTBinObj = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
end;
function GetCompModeName(Compiler : integer) : string;
begin
result:='';
case Compiler of CompTP:result:='Turbo Pascal BINOBJ Mode';
CompTC:result:='Turbo C BGIOBJ Mode';
CompOW16:result:='Open Watcom DOS 16bit Mode';
CompOW32:result:='Open Watcom DOS 32bit Mode';
CompAmigaHunk:result:='Amiga Hunk Mode';
CompBSAVE:result:='QuickBasic\GWBASIC BSAVE Mode';
CompCOFF:result:='COFF 32bit Mode';
CompTMT:result:='TMT Pascal Obj Mode';
end;
end;
procedure TRTBinObj.DoRun;
var
infile,outfile : string;
publicName : String;
publicsizename : string;
segmentname : string;
clname : string;
HunkName : string;
useFswitch : boolean;
CompilerMode : integer;
MemLoad : longword;
error : word;
begin
MemLoad:=ANY_MEM; //amiga option
CaseSensitiveOptions:=false;
HunkName:='ANY_MEM';
// parse parameters
if HasOption('h', 'help') or (ParamCount < 3) then begin
WriteHelp;
Terminate;
Exit;
end;
error:=0;
useFSwitch:=false;
CompilerMode:=CompTP;
infile:=paramstr(1);
outfile:=paramstr(2);
publicname:=paramstr(3);
publicsizename:='';
segmentname:='';
clname:='';
Case UpperCase(GetOptionValue('o')) of 'TC':CompilerMode:=CompTC;
'OW16':CompilerMode:=CompOW16;
'OW32':CompilerMode:=CompOW32;
'HUNK':CompilerMode:=CompAmigaHunk;
'BSAVE':CompilerMode:=CompBSAVE;
'COFF':CompilerMode:=CompCOFF;
'TMT':CompilerMode:=CompTMT;
end;
if HasOption('f','usefswitch') and (CompilerMode in [CompTC,CompOW16]) then usefswitch:=true;
if GetOptionValue('ps') <> '' then
begin
publicsizename:=GetOptionValue('ps');
end;
if (GetOptionValue('sn')<>'') and (CompilerMode in [CompTC,CompOW16,CompOW32]) then
begin
segmentname:=GetOptionValue('sn');
end;
if (GetOptionValue('cn')<>'') and (CompilerMode in [CompTC,CompOW16,CompOW32]) then
begin
clname:=GetOptionValue('cn');
end;
if (GetOptionValue('ml')<>'') and (CompilerMode = CompAmigaHunk) then
begin
if UpperCase(GetOptionValue('ml')) = 'CHIP' then
begin
MemLoad:=CHIP_MEM;
HunkName:='CHIP_MEM';
end;
if UpperCase(GetOptionValue('ml')) = 'FAST' then
begin
MemLoad:=FAST_MEM;
HunkName:='FAST_MEM';
end;
end;
if (GetOptionValue('hn')<>'') and (CompilerMode = CompAmigaHunk ) then
begin
hunkname:=GetOptionValue('hn');
end;
if CompilerMode = CompTP then
begin
if publicsizename<>'' then
begin
error:=CreateTPObj(infile,outfile,publicname,publicsizename);
end
else
begin
error:=CreateTPObj(infile,outfile,publicname);
end;
end
else if CompilerMode in [CompTC,CompOW16] then
begin
if publicsizename<>'' then
begin
error:=CreateTCObj(infile,outfile,publicname,publicsizename,segmentname,clname,UseFswitch);
end
else
begin
error:=CreateTCObj(infile,outfile,publicname,segmentname,clname,UseFswitch);
end;
end
else if CompilerMode = CompOW32 then
begin
if publicsizename<>'' then
begin
error:=CreateOWObj(infile,outfile,publicname,publicsizename,segmentname,clname,UseFswitch);
end
else
begin
error:=CreateOWObj(infile,outfile,publicname,segmentname,clname,UseFswitch);
end;
end
else if CompilerMode = CompAmigaHunk then
begin
if publicsizename<>'' then
begin
error:=CreateHunkObj(infile,outfile,publicname,publicsizename,hunkname,True,MemLoad);
end
else
begin
error:=CreateHunkObj(infile,outfile,publicname,publicsizename,hunkname,False,MemLoad);
end;
end
else if CompilerMode = CompBSAVE then
begin
if NOT ValidBSaveSource(infile) then
begin
writeln('Source File too big!');
Terminate;
end
else
begin
error:=CreateBSaveObj(infile,outfile);
end;
end
else if CompilerMode = CompCOFF then
begin
if publicsizename<>'' then
begin
error:=CreateCOFF(infile,outfile,publicname,publicsizename,True);
end
else
begin
error:=CreateCOFF(infile,outfile,publicname,publicsizename,FALSE);
end;
end
else if CompilerMode = CompTMT then
begin
error:=CreateTMTObj(infile,outfile,publicname);
end;
if error = 0 then writeln('Converted Successfully using ',GetCompModeName(CompilerMode)) else writeln('Looks like we have an error# ',error);
// stop program loop
Terminate;
end;
constructor TRTBinObj.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor TRTBinObj.Destroy;
begin
inherited Destroy;
end;
procedure TRTBinObj.WriteHelp;
begin
{ add your help code here }
writeln(programname);
writeln('Usage: RtBinObj infile outfile public_name');
writeln(' Optional -PS public size name');
writeln(' -O OBJ Mode {TP,TC,TMT,OW16,OW32,HUNK,BSAVE,COFF}');
writeln(' -SN segment name');
writeln(' -CN class name');
writeln(' -HN hunk name (Amiga 68k)');
writeln(' -F use far call');
writeln(' -ML Memory Load {ANY,CHIP,FAST');
writeln;
writeln('eg. RtBinObj image.xgf image.obj image -PS imagesize');
writeln('eg. RtBinObj image.xgf image.obj _image -PS _imagesize -O TC'); //turbo c BGIBIN mode
writeln('eg. RtBinObj image.xgf image.obj _image -PS _imagesize -F -O TC');
writeln('eg. RtBinObj image.xgf image.obj _image -PS _imagesize -SN segname -CN classname -O TC');
writeln('eg. RtBinObj image.xgf image.obj _image -PS _imagesize -HN hunkname -O HUNK'); //Amiga
writeln('eg. RtBinObj image.xgf image.bsv -O BSAVE'); //QuickBasic/GWBASIC
end;
var
Application: TRTBinObj;
begin
Application:=TRTBinObj.Create(nil);
Application.Title:='TRtBinObj';
Application.Run;
Application.Free;
end.