Skip to content

Commit 44de7d9

Browse files
committed
Turbo C - BGIOBJ Mode
1 parent 2dabca2 commit 44de7d9

File tree

4 files changed

+253
-23
lines changed

4 files changed

+253
-23
lines changed

objlib.pas

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ procedure Write_SegmentData(var F : File; SegmentIndex: byte; EnumeratedDataOffs
2626
function GetFileSize(filename : string) : longword;
2727
Procedure Write_FileContents(var F : File;filename : string;segIdx: byte; dataOffset: word);
2828
procedure Write_ModEnd(var F : File);
29-
3029
procedure Write_PubDefRecords(var F : File; BaseGroupIndex: byte; BaseSegmentIndex: byte;var rdata;rcount : word);
30+
3131
Function CreateTPObj(infile,outfile,publicname : string) : word;
3232
Function CreateTPObj(infile,outfile,publicname,publicsizename : string) : word;
3333

34+
Function CreateTCObj(infile,outfile,publicname,segname,classname : string;UseFswitch : Boolean) : word;
35+
Function CreateTCObj(infile,outfile,publicname,publicsizename,segname,classname : string;UseFswitch : Boolean) : word;
36+
3437
implementation
3538

3639
type
@@ -331,10 +334,10 @@ procedure Write_LeData(var F : File;SegmentIndex : Byte;EnumeratedDataOffset : w
331334
var
332335
recordPtr: PByte;
333336
begin
334-
GetMem(recordPtr, dataLength + 3);
337+
GetMem(recordPtr, dataLength + 3); // +3 is for Segmentindex (1) and EnumeratedDataOffset(2)
335338
recordPtr^ := SegmentIndex;
336-
(recordPtr + 1)^ := EnumeratedDataOffset and $FF;
337-
(recordPtr + 2)^ := EnumeratedDataOffset shr 8;
339+
(recordPtr + 1)^ := EnumeratedDataOffset and $FF; // LO(EnumeratedDataOffset);
340+
(recordPtr + 2)^ := EnumeratedDataOffset shr 8; // HI(EnumeratedDataOffset);
338341
Move(pbyte(databytes)^, (recordPtr + 3)^, dataLength);
339342

340343
Write_Id_Length_Data(F, $A0,recordPtr^,datalength+3);
@@ -464,5 +467,80 @@ procedure ChangePubDefStr(index : byte;var data; PublicName : string; PublicOffs
464467
result:=IORESULT;
465468
end;
466469

470+
// Turbo C's BGIOBJ /F switch inserts another LName that is the same as the public name
471+
// eg default is _TEXT CODE, if public name is _IMAGE, LName section becomes IMAGE_TEXT CODE
472+
// /F switch has not used when segname is provided
473+
// segname overwrites _TEXT and classname overwrites CODE
474+
function CreateTCLNames(infile,publicname,segname,classname : string;UseFswitch : boolean) : string;
475+
var
476+
LNames,defaultSegName,defaultClassName : string;
477+
begin
478+
defaultSegName:='_TEXT';
479+
defaultClassName:='CODE';
480+
481+
if segname<>'' then defaultSegName:=segname;
482+
if classname<>'' then defaultClassName:=classname;
483+
484+
if useFswitch and (segname='') then
485+
begin
486+
defaultSegname:=publicname+'_TEXT';
487+
if pos('_',defaultSegname)=1 then Delete(DefaultSegname,1,1);
488+
end;
489+
LNames:='#'+defaultSegName+'#'+defaultClassName+'#';
490+
result:=LNames;
491+
end;
492+
493+
Function CreateTCObj(infile,outfile,publicname,segname,classname : string;UseFswitch : Boolean) : word;
494+
var
495+
size : word;
496+
F : File;
497+
LNames : string;
498+
begin
499+
size:=WORD(GetFileSize(infile));
500+
{$I-}
501+
assign(F,outfile);
502+
rewrite(F,1);
503+
504+
Write_THeadr(F,#$3a#$3a);
505+
LNames:=CreateTCLNames(infile,publicname,segname,classname,UseFSwitch);
506+
Write_LNames(F,LNames);
507+
Write_SegDef(F,$68,size,2,3,1); //borland TC uses $68 = 2,3,1 - if Overlayindex is not 1 - does not work
508+
Write_PubDef(F,0,1,publicname,0,0);
509+
Write_FileContents(F,infile,1,0);
510+
Write_ModEnd(F);
511+
close(F);
512+
{$I+}
513+
result:=IORESULT;
514+
end;
515+
516+
Function CreateTCObj(infile,outfile,publicname,publicsizename,segname,classname : string;UseFswitch : Boolean) : word;
517+
var
518+
size : word;
519+
F : File;
520+
data : array[1..2] of TPubDefStrRec;
521+
LNames : string;
522+
begin
523+
size:=WORD(GetFileSize(infile));
524+
{$I-}
525+
assign(F,outfile);
526+
rewrite(F,1);
527+
Write_THeadr(F,#$3a#$3a);
528+
LNames:=CreateTCLNames(infile,publicname,segname,classname,UseFSwitch);
529+
Write_LNames(F,LNames);
530+
531+
Write_SegDef(F,$68,size+2,2,3,1); //+2 is the addtional bytes we will need to include the size information
532+
533+
ChangePubDefStr(1,data,publicname,0,0);
534+
ChangePubDefStr(2,data,publicsizename,size,0);
535+
Write_PubDefRecords(F,0,1,data,2);
536+
537+
Write_FileContentsAndSize(F,infile,1,0);
538+
Write_ModEnd(F);
539+
close(F);
540+
{$I+}
541+
result:=IORESULT;
542+
end;
543+
544+
467545
begin
468546
end.

rtbinobj.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
uses ObjLib;
55

66
Const
7-
ProgramName = 'RtBinObj v1.1 - Released April 23 - 2023 By RetroNick';
7+
ProgramName = 'RtBinObj v1.2 - Released April 24 - 2023 By RetroNick';
88

99
procedure Usage;
1010
begin

rtbinobjform.lfm

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
object Form1: TForm1
2-
Left = 599
3-
Height = 214
4-
Top = 460
5-
Width = 556
6-
Caption = 'RtBinObj v1.1'
7-
ClientHeight = 214
8-
ClientWidth = 556
2+
Left = 673
3+
Height = 269
4+
Top = 583
5+
Width = 605
6+
Caption = 'RtBinObj v1.2 By RetroNick - Released April 24 - 2023'
7+
ClientHeight = 269
8+
ClientWidth = 605
99
Color = clForm
1010
LCLVersion = '2.0.10.0'
1111
object InFileButton: TButton
@@ -50,7 +50,7 @@ object Form1: TForm1
5050
Left = 0
5151
Height = 32
5252
Top = 0
53-
Width = 556
53+
Width = 605
5454
Alignment = taCenter
5555
Anchors = [akTop, akLeft, akRight]
5656
AutoSize = False
@@ -63,18 +63,18 @@ object Form1: TForm1
6363
OptimalFill = True
6464
end
6565
object SaveAsButton: TButton
66-
Left = 432
66+
Left = 496
6767
Height = 25
68-
Top = 144
68+
Top = 216
6969
Width = 75
7070
Caption = 'Save As'
7171
OnClick = SaveAsButtonClick
72-
TabOrder = 4
72+
TabOrder = 8
7373
end
7474
object PublicSizeLabel: TLabel
7575
Left = 8
7676
Height = 15
77-
Top = 124
77+
Top = 128
7878
Width = 91
7979
Caption = 'Public Size Name'
8080
ParentColor = False
@@ -88,6 +88,79 @@ object Form1: TForm1
8888
ParentFont = False
8989
TabOrder = 3
9090
end
91+
object SegmentNameLabel: TLabel
92+
Left = 16
93+
Height = 15
94+
Top = 160
95+
Width = 82
96+
Caption = 'Segment Name'
97+
ParentColor = False
98+
end
99+
object EditSegmentName: TEdit
100+
Left = 120
101+
Height = 23
102+
Top = 152
103+
Width = 160
104+
Enabled = False
105+
MaxLength = 20
106+
ParentFont = False
107+
TabOrder = 4
108+
end
109+
object ClassNameLabel: TLabel
110+
Left = 36
111+
Height = 15
112+
Top = 192
113+
Width = 62
114+
Caption = 'Class Name'
115+
ParentColor = False
116+
end
117+
object EditClassName: TEdit
118+
Left = 120
119+
Height = 23
120+
Top = 184
121+
Width = 160
122+
Enabled = False
123+
MaxLength = 20
124+
ParentFont = False
125+
TabOrder = 5
126+
end
127+
object ObjModeRadioGroup: TRadioGroup
128+
Left = 416
129+
Height = 105
130+
Top = 56
131+
Width = 168
132+
AutoFill = True
133+
Caption = 'OBJ Mode'
134+
ChildSizing.LeftRightSpacing = 6
135+
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
136+
ChildSizing.EnlargeVertical = crsHomogenousChildResize
137+
ChildSizing.ShrinkHorizontal = crsScaleChilds
138+
ChildSizing.ShrinkVertical = crsScaleChilds
139+
ChildSizing.Layout = cclLeftToRightThenTopToBottom
140+
ChildSizing.ControlsPerLine = 1
141+
ClientHeight = 85
142+
ClientWidth = 164
143+
ItemIndex = 0
144+
Items.Strings = (
145+
'Turbo Pascal - BINOBJ'
146+
'Turbo C - BGIOBJ'
147+
)
148+
OnClick = ObjModeRadioGroupClick
149+
TabOrder = 7
150+
end
151+
object FarCallCheckBox: TCheckBox
152+
Left = 36
153+
Height = 19
154+
Hint = 'Segment Name must be blank'
155+
Top = 222
156+
Width = 96
157+
BidiMode = bdRightToLeft
158+
Caption = ' far calls '
159+
Enabled = False
160+
OnChange = FarCallCheckBoxChange
161+
ParentBidiMode = False
162+
TabOrder = 6
163+
end
91164
object OpenDialog: TOpenDialog
92165
Left = 440
93166
end

rtbinobjform.pas

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,40 @@
55
interface
66

77
uses
8-
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,LazFileUtils,objlib;
8+
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
9+
LazFileUtils, objlib;
910

1011
type
1112

1213
{ TForm1 }
1314

1415
TForm1 = class(TForm)
16+
FarCallCheckBox: TCheckBox;
1517
EditPublicSizeName: TEdit;
18+
EditSegmentName: TEdit;
19+
EditClassName: TEdit;
1620
OpenDialog: TOpenDialog;
1721
PublicSizeLabel: TLabel;
22+
ObjModeRadioGroup: TRadioGroup;
23+
SegmentNameLabel: TLabel;
1824
SaveAsButton: TButton;
1925
EditFileName: TEdit;
2026
InfoLabel: TLabel;
2127
EditPublicName: TEdit;
2228
InFileButton: TButton;
2329
PublicLabel: TLabel;
2430
SaveDialog: TSaveDialog;
31+
ClassNameLabel: TLabel;
32+
procedure FarCallCheckBoxChange(Sender: TObject);
2533
procedure InFileButtonClick(Sender: TObject);
34+
procedure ObjModeRadioGroupClick(Sender: TObject);
2635
procedure SaveAsButtonClick(Sender: TObject);
2736
private
2837
function ValidFields : boolean;
38+
procedure CreateTPOBJFile;
39+
procedure CreateTCOBJFile;
2940
procedure CreateOBJFile;
41+
3042
public
3143

3244
end;
@@ -49,9 +61,51 @@ procedure TForm1.InFileButtonClick(Sender: TObject);
4961
begin
5062
InfoLabel.Caption:='';
5163
EditFileName.Text:=OpenDialog.FileName;
52-
sname:=UpperCase(ExtractFileName(ExtractFileNameWithoutExt(OpenDialog.FileName)));
53-
EditPublicName.Text:=sname;
54-
EditPublicSizeName.Text:=sname+'SIZE';
64+
if ObjModeRadioGroup.ItemIndex = 0 then
65+
begin
66+
sname:=UpperCase(ExtractFileName(ExtractFileNameWithoutExt(OpenDialog.FileName)));
67+
EditPublicName.Text:=sname;
68+
EditPublicSizeName.Text:=sname+'SIZE';
69+
end
70+
else
71+
begin
72+
sname:=LowerCase(ExtractFileName(ExtractFileNameWithoutExt(OpenDialog.FileName)));
73+
EditPublicName.Text:='_'+sname;
74+
EditPublicSizeName.Text:='_'+sname+'size';
75+
end;
76+
end;
77+
end;
78+
79+
procedure TForm1.FarCallCheckBoxChange(Sender: TObject);
80+
begin
81+
if FarCallCheckBox.Checked then
82+
begin
83+
EditSegmentName.Text:='';
84+
EditSegmentName.Enabled:=false;
85+
EditClassName.Text:='';
86+
EditClassName.Enabled:=false;
87+
end
88+
else
89+
begin
90+
EditSegmentName.Enabled:=true;
91+
EditClassName.Enabled:=true;
92+
end;
93+
end;
94+
95+
procedure TForm1.ObjModeRadioGroupClick(Sender: TObject);
96+
begin
97+
if ObjModeRadioGroup.ItemIndex = 0 then
98+
begin
99+
EditSegmentName.Enabled:=false;
100+
EditClassName.Enabled:=false;
101+
FarCallCheckbox.Enabled:=false;
102+
end
103+
else if ObjModeRadioGroup.ItemIndex = 1 then
104+
begin
105+
EditSegmentName.Enabled:=true;
106+
EditClassName.Enabled:=true;
107+
FarCallCheckbox.Enabled:=true;
108+
FarCallCheckbox.Checked:=false;
55109
end;
56110
end;
57111

@@ -77,11 +131,10 @@ function TForm1.ValidFields: boolean;
77131
end;
78132
end;
79133

80-
procedure TForm1.CreateOBJFile;
134+
procedure TForm1.CreateTPOBJFile;
81135
var
82136
error : word;
83137
begin
84-
if SaveDialog.Execute = false then exit;
85138
if EditPublicSizeName.Text<>'' then
86139
error:=CreateTPObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text)
87140
else
@@ -97,5 +150,31 @@ procedure TForm1.CreateOBJFile;
97150
end;
98151
end;
99152

153+
procedure TForm1.CreateTCOBJFile;
154+
var
155+
error : word;
156+
begin
157+
if EditPublicSizeName.Text<>'' then
158+
error:=CreateTCObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text,EditSegmentName.Text,EditClassName.Text,FarCallCheckBox.Checked)
159+
else
160+
error:=CreateTCObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditSegmentName.Text,EditClassName.Text,FarCallCheckBox.Checked);
161+
162+
163+
if error=0 then
164+
begin
165+
InfoLabel.Caption:='New Obj successfully created and saved!';
166+
end
167+
else
168+
begin
169+
InfoLabel.Caption:='Ouch it looks like we had booboo #'+IntToStr(error);
170+
end;
171+
end;
172+
173+
procedure TForm1.CreateOBJFile;
174+
begin
175+
if SaveDialog.Execute = false then exit;
176+
if ObjModeRadioGroup.ItemIndex = 0 then CreateTPObjFile else CreateTCObjFile;
177+
end;
178+
100179
end.
101180

0 commit comments

Comments
 (0)