-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtbinobjform.pas
464 lines (409 loc) · 12.8 KB
/
rtbinobjform.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
unit rtbinobjform;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
LazFileUtils, objlib,hunklib,bsavelib,cofflib;
Const
ProgramName = 'RtBinObj v1.8 By RetroNick - Released December 24 - 2023';
type
{ TForm1 }
TForm1 = class(TForm)
FarCallCheckBox: TCheckBox;
EditPublicSizeName: TEdit;
EditSegmentName: TEdit;
EditClassName: TEdit;
OpenDialog: TOpenDialog;
PublicSizeLabel: TLabel;
ObjModeRadioGroup: TRadioGroup;
AmigaMemRadioGroup: TRadioGroup;
SegmentNameLabel: TLabel;
SaveAsButton: TButton;
EditFileName: TEdit;
InfoLabel: TLabel;
EditPublicName: TEdit;
InFileButton: TButton;
PublicLabel: TLabel;
SaveDialog: TSaveDialog;
ClassNameLabel: TLabel;
procedure AmigaMemRadioGroupClick(Sender: TObject);
procedure FarCallCheckBoxChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
procedure InFileButtonClick(Sender: TObject);
procedure ObjModeRadioGroupClick(Sender: TObject);
procedure SaveAsButtonClick(Sender: TObject);
private
MemLoad : Longword;
function ValidFields : boolean;
procedure SetPublicNames;
procedure CreateTPOBJFile;
procedure CreateTMTOBJFile;
procedure CreateTCOBJFile;
procedure CreateOBJFile;
procedure CreateOWDOS32OBJFile;
procedure CreateOWDos16OBJFile;
procedure CreateAmigaHunkFile;
procedure CreateBSaveFile;
procedure CreateCOFFFile;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.SetPublicNames;
var
sname : string;
begin
if ObjModeRadioGroup.ItemIndex = 0 then //TP
begin
sname:=UpperCase(ExtractFileName(ExtractFileNameWithoutExt(OpenDialog.FileName)));
EditPublicName.Text:=sname;
EditPublicSizeName.Text:=sname+'SIZE';
end
else if ObjModeRadioGroup.ItemIndex = 7 then //TMT
begin
sname:=UpperCase(ExtractFileName(ExtractFileNameWithoutExt(OpenDialog.FileName)));
EditPublicName.Text:=sname;
EditPublicSizeName.Text:='';
end
else
begin
sname:=LowerCase(ExtractFileName(ExtractFileNameWithoutExt(OpenDialog.FileName)));
EditPublicName.Text:='_'+sname;
EditPublicSizeName.Text:='_'+sname+'size';
end;
end;
procedure TForm1.InFileButtonClick(Sender: TObject);
begin
// OpenDialog.Filter := 'Windows BMP|*.bmp|PNG|*.png|PC Paintbrush |*.pcx|DP-Amiga IFF LBM|*.lbm|DP-Amiga IFF BBM Brush|*.bbm|GIF|*.gif|RM RAW Files|*.raw|All Files|*.*';
if OpenDialog.Execute then
begin
InfoLabel.Caption:='';
EditFileName.Text:=OpenDialog.FileName;
SetPublicNames;
end;
end;
procedure TForm1.FarCallCheckBoxChange(Sender: TObject);
begin
if FarCallCheckBox.Checked then
begin
EditSegmentName.Text:='';
EditSegmentName.Enabled:=false;
EditClassName.Text:='';
EditClassName.Enabled:=false;
end
else
begin
EditSegmentName.Enabled:=true;
EditClassName.Enabled:=true;
end;
end;
procedure TForm1.AmigaMemRadioGroupClick(Sender: TObject);
begin
case AmigaMemRadioGroup.ItemIndex of 0:begin
MemLoad:=ANY_MEM;
EditSegmentName.Text:='ANYMEM';
end;
1:begin
MemLoad:=CHIP_MEM;
EditSegmentName.Text:='CHIPMEM';
end;
2:begin
MemLoad:=FAST_MEM;
EditSegmentName.Text:='FASTMEM';
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Caption:=ProgramName;
end;
procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String);
begin
if High(Filenames) > 0 then
begin
ShowMessage('Drag only one file!');
exit;
end;
if FileExists(FileNames[0]) then
begin
OpenDialog.FileName:=FileNames[0];
EditFileName.Caption:=FileNames[0];
SetPublicNames;
end
else
begin
ShowMessage('Invalid File/Directory!');
exit;
end;
end;
procedure TForm1.ObjModeRadioGroupClick(Sender: TObject);
begin
if ObjModeRadioGroup.ItemIndex = 0 then
begin
EditPublicName.Enabled:=true;
EditPublicSizeName.Enabled:=true;
EditSegmentName.Enabled:=false;
EditClassName.Enabled:=false;
SegmentNameLabel.Caption:='Segment Name';
AmigaMemRadioGroup.Enabled:=false;
FarCallCheckbox.Enabled:=false;
FarCallCheckbox.checked:=false;
end
else if ObjModeRadioGroup.ItemIndex = 1 then
begin
EditPublicName.Enabled:=true;
EditPublicSizeName.Enabled:=true;
EditSegmentName.Enabled:=true;
EditClassName.Enabled:=true;
SegmentNameLabel.Caption:='Segment Name';
AmigaMemRadioGroup.Enabled:=false;
FarCallCheckbox.Enabled:=true;
FarCallCheckbox.Checked:=false;
end
else if ObjModeRadioGroup.ItemIndex = 2 then
begin
EditPublicName.Enabled:=true;
EditPublicSizeName.Enabled:=true;
EditSegmentName.Enabled:=true;
EditClassName.Enabled:=true;
SegmentNameLabel.Caption:='Segment Name';
AmigaMemRadioGroup.Enabled:=false;
FarCallCheckbox.Enabled:=true;
FarCallCheckbox.Checked:=false;
end
else if ObjModeRadioGroup.ItemIndex = 3 then
begin
EditPublicName.Enabled:=true;
EditPublicSizeName.Enabled:=true;
EditSegmentName.Enabled:=true;
EditClassName.Enabled:=true;
SegmentNameLabel.Caption:='Segment Name';
AmigaMemRadioGroup.Enabled:=false;
FarCallCheckbox.Enabled:=false;
FarCallCheckbox.Checked:=false;
end
else if ObjModeRadioGroup.ItemIndex = 4 then
begin
EditPublicName.Enabled:=true;
EditPublicSizeName.Enabled:=true;
EditSegmentName.Enabled:=true;
EditClassName.Enabled:=false;
SegmentNameLabel.Caption:=' Hunk Name';
AmigaMemRadioGroup.Enabled:=true;
FarCallCheckbox.Enabled:=false;
FarCallCheckbox.Checked:=false;
end
else if ObjModeRadioGroup.ItemIndex = 5 then
begin
EditPublicName.Enabled:=false;
EditPublicSizeName.Enabled:=false;
EditSegmentName.Enabled:=false;
EditClassName.Enabled:=false;
SegmentNameLabel.Caption:='Segment Name';
AmigaMemRadioGroup.Enabled:=false;
FarCallCheckbox.Enabled:=false;
FarCallCheckbox.Checked:=false;
end
else if ObjModeRadioGroup.ItemIndex = 6 then
begin
EditPublicName.Enabled:=true;
EditPublicSizeName.Enabled:=true;
EditSegmentName.Enabled:=false;
EditClassName.Enabled:=false;
SegmentNameLabel.Caption:='Segment Name';
AmigaMemRadioGroup.Enabled:=false;
FarCallCheckbox.Enabled:=false;
FarCallCheckbox.Checked:=false;
end
else if ObjModeRadioGroup.ItemIndex = 7 then
begin
EditPublicName.Enabled:=true;
EditPublicSizeName.Enabled:=false;
EditSegmentName.Enabled:=false;
EditClassName.Enabled:=false;
SegmentNameLabel.Caption:='Segment Name';
AmigaMemRadioGroup.Enabled:=false;
FarCallCheckbox.Enabled:=false;
FarCallCheckbox.Checked:=false;
end;
end;
procedure TForm1.SaveAsButtonClick(Sender: TObject);
begin
if ValidFields then CreateObjFile;
end;
function TForm1.ValidFields: boolean;
begin
result:=false;
if EditFileName.Text = '' then
begin
ShowMessage('No File Selected');
end
else if (EditPublicName.Text = '') and (ObjModeRadioGroup.ItemIndex <> 5) then
begin
ShowMessage('Public Name cannot be empty');
end
else if (EditSegmentName.Text = '') and (ObjModeRadioGroup.ItemIndex = 4) then
begin
ShowMessage('Hunk Name cannot be empty');
end
else
begin
result:=true;
end;
end;
procedure TForm1.CreateTPOBJFile;
var
error : word;
begin
if EditPublicSizeName.Text<>'' then
error:=CreateTPObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text)
else
error:=CreateTPObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text);
if error=0 then
begin
InfoLabel.Caption:='New Obj successfully created and saved!';
end
else
begin
InfoLabel.Caption:='Ouch it looks like we had booboo #'+IntToStr(error);
end;
end;
procedure TForm1.CreateTMTOBJFile;
var
error : word;
begin
InfoLabel.Caption:='We are In correct area';
if EditPublicSizeName.Text<>'' then
error:=CreateTMTObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text)
else
error:=CreateTMTObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text);
if error=0 then
begin
InfoLabel.Caption:='New Obj successfully created and saved!';
end
else
begin
InfoLabel.Caption:='Ouch it looks like we had booboo #'+IntToStr(error);
end;
end;
procedure TForm1.CreateTCOBJFile;
var
error : word;
begin
if EditPublicSizeName.Text<>'' then
error:=CreateTCObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text,EditSegmentName.Text,EditClassName.Text,FarCallCheckBox.Checked)
else
error:=CreateTCObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditSegmentName.Text,EditClassName.Text,FarCallCheckBox.Checked);
if error=0 then
begin
InfoLabel.Caption:='New Obj successfully created and saved!';
end
else
begin
InfoLabel.Caption:='Ouch it looks like we had booboo #'+IntToStr(error);
end;
end;
procedure TForm1.CreateOWDOS32OBJFile;
var
error : word;
begin
if EditPublicSizeName.Text<>'' then
error:=CreateOWObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text,EditSegmentName.Text,EditClassName.Text,FarCallCheckBox.Checked)
else
error:=CreateOWObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditSegmentName.Text,EditClassName.Text,FarCallCheckBox.Checked);
if error=0 then
begin
InfoLabel.Caption:='New Obj successfully created and saved!';
end
else
begin
InfoLabel.Caption:='Ouch it looks like we had booboo #'+IntToStr(error);
end;
end;
procedure TForm1.CreateOWDos16OBJFile;
var
error : word;
begin
//not a bug we are using the same format as Turbo C for the 16 bit - it works
if EditPublicSizeName.Text<>'' then
error:=CreateTCObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text,EditSegmentName.Text,EditClassName.Text,FarCallCheckBox.Checked)
else
error:=CreateTCObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditSegmentName.Text,EditClassName.Text,FarCallCheckBox.Checked);
if error=0 then
begin
InfoLabel.Caption:='New Obj successfully created and saved!';
end
else
begin
InfoLabel.Caption:='Ouch it looks like we had booboo #'+IntToStr(error);
end;
end;
procedure TForm1.CreateAmigaHunkFile;
var
IncludeFileSize : boolean;
error: word;
begin
if EditPublicSizeName.Text<>'' then IncludeFileSize:=true else IncludeFileSize:=false;
error:=CreateHunkObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text,EditSegmentName.Text,IncludeFileSize,MemLoad);
if error=0 then
begin
InfoLabel.Caption:='New Hunk successfully created and saved!';
end
else
begin
InfoLabel.Caption:='Ouch it looks like we had booboo #'+IntToStr(error);
end;
end;
procedure TForm1.CreateCOFFFile;
var
IncludeFileSize : boolean;
error: word;
begin
if EditPublicSizeName.Text<>'' then IncludeFileSize:=true else IncludeFileSize:=false;
error:=CreateCOFF(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text,IncludeFileSize);
if error=0 then
begin
InfoLabel.Caption:='New COFF successfully created and saved!';
end
else
begin
InfoLabel.Caption:='Ouch it looks like we had booboo #'+IntToStr(error);
end;
end;
procedure TForm1.CreateBSaveFile;
var
error: word;
begin
if NOT ValidBSaveSource(OpenDialog.Filename) then
begin
ShowMessage('Source File too big!');
exit;
end;
error:=CreateBSaveObj(OpenDialog.Filename,SaveDialog.FileName);
if error=0 then
begin
InfoLabel.Caption:='New BSave Object successfully created and saved!';
end
else
begin
InfoLabel.Caption:='Ouch it looks like we had booboo #'+IntToStr(error);
end;
end;
procedure TForm1.CreateOBJFile;
begin
if SaveDialog.Execute = false then exit;
case ObjModeRadioGroup.ItemIndex of 0:CreateTPObjFile;
1:CreateTCObjFile;
2:CreateOWDOS16OBJFile;
3:CreateOWDOS32OBJFile;
4:CreateAmigaHunkFile;
5:CreateBSaveFile;
6:CreateCOFFFile;
7:CreateTMTObjFile;
end;
end;
end.