Skip to content

Commit 591ed49

Browse files
committed
public size name added
1 parent f103346 commit 591ed49

File tree

4 files changed

+105
-12
lines changed

4 files changed

+105
-12
lines changed

objlib.pas

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ procedure Write_ModEnd(var F : File);
2929

3030
procedure Write_PubDefRecords(var F : File; BaseGroupIndex: byte; BaseSegmentIndex: byte;var rdata;rcount : word);
3131
Function CreateTPObj(infile,outfile,publicname : string) : word;
32+
Function CreateTPObj(infile,outfile,publicname,publicsizename : string) : word;
3233

3334
implementation
3435

@@ -357,9 +358,11 @@ function GetFileSize(filename : string) : longword;
357358
F : File;
358359
begin
359360
Assign(F,filename);
361+
{$I-}
360362
Reset(F,1);
361-
result:=FileSize(F);
363+
result:=WORD(FileSize(F));
362364
close(F);
365+
{$I+}
363366
end;
364367

365368
Procedure Write_FileContents(var F : File;filename : string;segIdx: byte; dataOffset: word);
@@ -370,7 +373,7 @@ function GetFileSize(filename : string) : longword;
370373
begin
371374
Assign(FC,filename);
372375
Reset(FC,1);
373-
size:=FileSize(FC);
376+
size:=WORD(FileSize(FC));
374377
GetMem(data,size);
375378
if data<>NIL then
376379
begin
@@ -381,13 +384,37 @@ function GetFileSize(filename : string) : longword;
381384
close(FC);
382385
end;
383386

387+
Procedure Write_FileContentsAndSize(var F : File;filename : string;segIdx: byte; dataOffset: word);
388+
var
389+
size : word;
390+
FC : File;
391+
data : PByte;
392+
begin
393+
Assign(FC,filename);
394+
Reset(FC,1);
395+
size:=WORD(FileSize(FC));
396+
GetMem(data,size+2);
397+
if data<>NIL then
398+
begin
399+
Blockread(FC,data^,size);
400+
(data + size)^:=LO(size);
401+
(data + size+1)^:=HI(size);
402+
403+
Write_SegmentData(F,SegIdx,dataOffset,data,size+2);
404+
FreeMem(data,size+2);
405+
end;
406+
close(FC);
407+
end;
408+
409+
410+
384411
// create Turbo Pascal Compatile BINOBJ output exactly to the byte level
385412
Function CreateTPObj(infile,outfile,publicname : string) : word;
386413
var
387414
size : word;
388415
F : File;
389416
begin
390-
size:=GetFileSize(infile);
417+
size:=WORD(GetFileSize(infile));
391418
{$I-}
392419
assign(F,outfile);
393420
rewrite(F,1);
@@ -402,5 +429,40 @@ function GetFileSize(filename : string) : longword;
402429
result:=IORESULT;
403430
end;
404431

432+
procedure ChangePubDefStr(index : byte;var data; PublicName : string; PublicOffset : word; typeindex : byte);
433+
var
434+
DataA : array[1..255] of TPubDefStrRec absolute data;
435+
begin
436+
dataA[index].StringLength:=length(publicname);
437+
dataA[index].PubLicName:=publicname;
438+
dataA[index].PublicOffset:=publicoffset;
439+
dataA[index].TypeIndex:=typeindex;
440+
end;
441+
442+
Function CreateTPObj(infile,outfile,publicname,publicsizename : string) : word;
443+
var
444+
size : word;
445+
F : File;
446+
data : array[1..2] of TPubDefStrRec;
447+
begin
448+
size:=WORD(GetFileSize(infile));
449+
{$I-}
450+
assign(F,outfile);
451+
rewrite(F,1);
452+
Write_THeadr(F,#$3a#$3a);
453+
Write_LNames(F,'#CODE##');
454+
Write_SegDef(F,$28,size+2,2,1,1); //+2 is the addtional bytes we will need to include the size information
455+
456+
ChangePubDefStr(1,data,publicname,0,0);
457+
ChangePubDefStr(2,data,publicsizename,size,0);
458+
Write_PubDefRecords(F,0,1,data,2);
459+
460+
Write_FileContentsAndSize(F,infile,1,0);
461+
Write_ModEnd(F);
462+
close(F);
463+
{$I+}
464+
result:=IORESULT;
465+
end;
466+
405467
begin
406468
end.

rtbinobj.pas

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
// Turbo Pascal
1+
// Turbo Pascal BINOBJ clone for Windows\Linux - output is exactly the same
22

33
Program RtBinToObj;
44
uses ObjLib;
55

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

99
procedure Usage;
1010
begin
1111
writeln(programname);
12-
writeln('Usage: RtBinObj <source[.BIN]> <destination[.OBJ] <public name>');
12+
writeln('Usage: RtBinObj <source[.BIN]> <destination[.OBJ] <public name> <public size name>');
13+
writeln(' <public size name> is optional');
14+
writeln;
15+
writeln('eg. RtBinObj image.xgf image.obj myimagename');
16+
writeln(' RtBinObj image.xgf image.obj myimagename myimagesize');
17+
1318
end;
1419

1520
procedure convert;
1621
var
1722
error : word;
1823
begin
1924
writeln(programName);
20-
error:=CreateTPObj(ParamStr(1),ParamStr(2),ParamStr(3));
25+
case ParamCount of 3:error:=CreateTPObj(ParamStr(1),ParamStr(2),ParamStr(3));
26+
4:error:=CreateTPObj(ParamStr(1),ParamStr(2),ParamStr(3),ParamStr(4));
27+
end;
2128
if error = 0 then writeln('Converted Successfully') else writeln('Looks like we have an error# ',error);
2229
end;
2330

2431
begin
25-
if ParamCount=3 then convert else Usage;
32+
if (ParamCount=3) or (ParamCount=4) then convert else Usage;
2633
end.
2734

rtbinobjform.lfm

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
object Form1: TForm1
2-
Left = 552
2+
Left = 599
33
Height = 214
4-
Top = 428
4+
Top = 460
55
Width = 556
6-
Caption = 'RtBinObj v1.0'
6+
Caption = 'RtBinObj v1.1'
77
ClientHeight = 214
88
ClientWidth = 556
99
Color = clForm
@@ -69,6 +69,23 @@ object Form1: TForm1
6969
Width = 75
7070
Caption = 'Save As'
7171
OnClick = SaveAsButtonClick
72+
TabOrder = 4
73+
end
74+
object PublicSizeLabel: TLabel
75+
Left = 8
76+
Height = 15
77+
Top = 124
78+
Width = 91
79+
Caption = 'Public Size Name'
80+
ParentColor = False
81+
end
82+
object EditPublicSizeName: TEdit
83+
Left = 120
84+
Height = 23
85+
Top = 120
86+
Width = 160
87+
MaxLength = 20
88+
ParentFont = False
7289
TabOrder = 3
7390
end
7491
object OpenDialog: TOpenDialog

rtbinobjform.pas

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ interface
1212
{ TForm1 }
1313

1414
TForm1 = class(TForm)
15+
EditPublicSizeName: TEdit;
1516
OpenDialog: TOpenDialog;
17+
PublicSizeLabel: TLabel;
1618
SaveAsButton: TButton;
1719
EditFileName: TEdit;
1820
InfoLabel: TLabel;
@@ -49,6 +51,7 @@ procedure TForm1.InFileButtonClick(Sender: TObject);
4951
EditFileName.Text:=OpenDialog.FileName;
5052
sname:=UpperCase(ExtractFileName(ExtractFileNameWithoutExt(OpenDialog.FileName)));
5153
EditPublicName.Text:=sname;
54+
EditPublicSizeName.Text:=sname+'SIZE';
5255
end;
5356
end;
5457

@@ -79,7 +82,11 @@ procedure TForm1.CreateOBJFile;
7982
error : word;
8083
begin
8184
if SaveDialog.Execute = false then exit;
82-
error:=CreateTPObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text);
85+
if EditPublicSizeName.Text<>'' then
86+
error:=CreateTPObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text,EditPublicSizeName.Text)
87+
else
88+
error:=CreateTPObj(OpenDialog.Filename,SaveDialog.FileName,EditPublicName.Text);
89+
8390
if error=0 then
8491
begin
8592
InfoLabel.Caption:='New Obj successfully created and saved!';

0 commit comments

Comments
 (0)