Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to index page
Thread view  Board view
Pablo

31.05.2010, 08:22
 

Help me with C++ (Developers)

Hello
I am trying to re-writing my program Explorer PC (graphical file manager for DOS).Before it was written in Turbo Assembler but now I am using Turbo C++.
My problem is that need making to ensure to me that several variables remain together in the executable file (.exe) or when running are located together in the same segment.
For example:
int a; SEG=0 OFFSET=0
int b; SEG=0 OFFSET=2
int c; SEG=0 OFFSET=4
In assembler I can control this but in C++ is possible?
Thanks

RayeR

Homepage

CZ,
31.05.2010, 10:13

@ Pablo
 

Help me with C++

AFAIK C should place all global variables into one segment one by one so you only need to get pointer to the first variable and data segment. But there may be some problem with aligning where some dummy bytes are placed between Byte variables - e.g.
int a; - 0x1100
Byte b; - 0x1102
int c; - 0x1104 (instead of 0x1103)

Aligning may be turned off by some compiler option but you are not sure if another compiler can disable it. May be better use some kind of attribute packed and put all vars into a packed structue. Then you will be safe that any extra bytes was added.

---
DOS gives me freedom to unlimited HW access.

Pablo

07.06.2010, 01:28

@ RayeR
 

Help me with C++

>... May be better use some kind of attribute
> packed and put all vars into a packed structue. Then you will be safe that
> any extra bytes was added.
ok, this is the solution, but when compiling:
Line 1 ... Struct x{
Line 2 ... int a;
Line 3 ... int b;
Line 4 ... int c:
Line 5 ... } y;
Line 6 ... asm mov ax,seg y

it keep the following error to me: Error ... Line 6 Expression syntax

As I can obtain the segment and offset of a variable with structure ?

RayeR

Homepage

CZ,
08.06.2010, 13:12

@ Pablo
 

Help me with C++

It's not defined in ANSI C how to get full address of some variable. You can get only relative pointer in data segment by "&" operator. It depends on your compiler. E.g. DJGPP defines _my_ds() symbol (selector to your data segment) which completes full address. I think that borland has something similar.

---
DOS gives me freedom to unlimited HW access.

Pablo

21.06.2010, 01:41

@ RayeR
 

Help me with C++

> It's not defined in ANSI C how to get full address of some variable. You
> can get only relative pointer in data segment by "&" operator. It depends
> on your compiler. E.g. DJGPP defines _my_ds() symbol (selector to your data
> segment) which completes full address. I think that borland has something
> similar.
Definitively the programming in C++ is not mine. That sad that there is not an intermediate level between C++ and Assembler. C++ is good but it reaches very extra kilobytes that can will be useful with Assembler. I wanted to program in C++ to make but my code clear source, but now I believe that there is nothing no better than to put commentaries to a code source.

Laaca

Homepage

Czech republic,
21.06.2010, 10:18

@ Pablo
 

Help me with C++

> Definitively the programming in C++ is not mine. That sad that there is not
> an intermediate level between C++ and Assembler.

It is, look for "Sphinx C--" programming language.

---
DOS-u-akbar!

rr

Homepage E-mail

Berlin, Germany,
21.06.2010, 20:57

@ Laaca
 

Help me with C++

> > Definitively the programming in C++ is not mine. That sad that there is
> not
> > an intermediate level between C++ and Assembler.
>
> It is, look for "Sphinx C--" programming language.

I like(d) C-- very much, but unfortunately the project is dead. :-( Last version is 0.239 beta 26 from April 2007. And Mikhail Sheker refused to release C--'s source code.

---
Forum admin

Pablo

22.06.2010, 05:56

@ rr
 

Help me with C++

sphinx is interesting but needs to him a modern IDE like visual BASIC 2010, autoident, autotabs, guide lines, who helps the fast programming, clear and structured. this it is an example:
[image]

Rugxulo

Homepage

Usono,
22.06.2010, 08:46

@ Pablo
 

Help me with C++

> sphinx is interesting but needs to him a modern IDE like visual BASIC 2010,
> autoident, autotabs, guide lines, who helps the fast programming, clear and
> structured. this it is an example:

Hardly a necessary feature, IMHO. But I do think several editors support this (maybe not the connecting lines, but at least similar via folding), e.g. Scintilla, VIM, GNU Emacs, etc.

Laaca

Homepage

Czech republic,
22.06.2010, 11:22

@ Rugxulo
 

Help me with C++

> > sphinx is interesting but needs to him a modern IDE like visual BASIC
> 2010,
> > autoident, autotabs, guide lines, who helps the fast programming, clear
> and
> > structured.


SETEDIT is your friend ;-)
http://setedit.sourceforge.net/#download

---
DOS-u-akbar!

Pablo

22.06.2010, 12:33

@ Rugxulo
 

MasmEd Code Editor

I locate several IDE's like Setedit, VIM, WinAsm and others in DOS and Windows ... very good, but the one that has some features to edit a DOS assembly code with the Visual Basic look, is MasmEd Code Editor 1.2.0.0. So far I believe that it is my favorite, although it does not have the capacity to detect possible errors.
[image]

rr

Homepage E-mail

Berlin, Germany,
22.06.2010, 16:04

@ Pablo
 

MasmEd Code Editor

> I locate several IDE's like Setedit, VIM, WinAsm and others in DOS and
> Windows ... very good, but the one that has some features to edit a DOS
> assembly code with the Visual Basic look, is MasmEd Code Editor 1.2.0.0.

MasmEd's home: http://radasm.cherrytree.at/masmed/

---
Forum admin

Khusraw

E-mail

Bucharest, Romania,
21.06.2010, 10:45

@ Pablo
 

Help me with C++

You can also try BAssPasC.

---
Glory to God for all things

Arjay

22.06.2010, 13:18
(edited by Arjay, 22.06.2010, 13:29)

@ RayeR
 

Help me with C++ / Segment of pointer in Turbo C

> It's not defined in ANSI C how to get full address of some variable. You
> can get only relative pointer in data segment by "&" operator. It depends
> on your compiler. E.g. DJGPP defines _my_ds() symbol (selector to your data
> segment) which completes full address. I think that borland has something
> similar.

On this particular subject a good discussion entitled: "Segment of pointer in Turbo C".

marcov

06.06.2010, 19:49

@ Pablo
 

Help me with C++

> I am trying to re-writing my program Explorer PC (graphical file manager
> for DOS).Before it was written in Turbo Assembler but now I am using Turbo
> C++.
> My problem is that need making to ensure to me that several variables
> remain together in the executable file (.exe) or when running are located
> together in the same segment.
> For example:
> int a; SEG=0 OFFSET=0
> int b; SEG=0 OFFSET=2
> int c; SEG=0 OFFSET=4
> In assembler I can control this but in C++ is possible?

Something that I have seen in FreeBSD headers was something like this:

struct {
int ___prefix_a;
int ___prefix_b;
int ___prefix_c;
#define a __prefix_a
#define b __prefix_b
#define c __prefix_c
} a;

IOW make a record with dummy names, and then use #defines to access them.

Costs a bit of error message clarity though (and C/C++ doesn't have that much of that already)

Arjay

22.06.2010, 14:19
(edited by Arjay, 22.06.2010, 16:10)

@ Pablo
 

Help me with C++ 2 alternatives with Turbo C (malloc/bgiobj)

> My problem is that need making to ensure to me that several variables
> remain together in the executable file (.exe) or when running are located
> together in the same segment.
> For example:
> int a; SEG=0 OFFSET=0
> int b; SEG=0 OFFSET=2
> int c; SEG=0 OFFSET=4
> In assembler I can control this but in C++ is possible?
> Thanks
In addition to using struct/TC alternatives which have already been covered. There are at least 2 other alternatives using TC that sprung to mind:

1) Don't hard-code in your resources (e.g. like you did with the ASM version) and instead use malloc - this has the advantage your resources can easily be changed by others particularly if you pack them in as a common data format, e.g. On an unreleased DOS game I wrote all the code to use the Windows .FNT/.FON file format and various graphics formats. There are however now a lot of free graphics libraries out there that you could easily incorporate. Certainly storing resources such as text non-hardcoded always helps translators.

2) Use BGIOBJ as it is known as with Turbo C (or BINOBJ as it has also been known, e.g. with Turbo Pascal). For example:

bgiobj mydata.bin mydata.obj mydata

Once a file has been converted with BGIOBJ/BINOBJ you can then include the .OBJ file at link time and use as data or code (with caution!) as appropriate.

Note: Some versions (e.g. TC3 version) support a /F parameter:
"/F selects 'far' version (please read the documentation before using /F)."

Amusingly as I just discovered if you look up BGIOBJ in a physical Turbo C manual, it just refers to UTIL.DOC which can normally be found in C:\TC\DOC - having just re-referenced it for you I was reminded that it only talks about BGI files which we don't care about (certainly I never have). However don't be fooled you can use the utility for other purposes. Anyway, I have just noted UTIL.DOC basically explains that /F instructs BGIOBJ to use a different segment name other than _TEXT in the form of filename_TEXT - the UTIL.DOC documentation takes up a lot of space to explain this though :)


Some Borland compiler examples
Ok, firstly lets imagine we have a text file called HW.TXT which you've guessed it contains:

Hello World!

as above we use bgiobj or binobj to convert it (the parameters are the same):

bgiobj hw.txt hw hw
or
binobj hw.txt hw hw

The above will result in hw.obj - below are some examples of Borland linking:


Borland/Turbo C linking examples
With Borland C products linking an obj file in is very straight forward, e.g:

\tc\bin\bcc myproject.c hw.obj
or
\tc\bin\tcc myproject.c hw.obj

Note: Borland store BGIOBJ by default under C:\TC\BGI directory not C:\TC\BIN


Turbo Pascal example 1/2
Linking in OBJ data at compile with Turbo Pascal is however a bit more complex but can still be done. Firstly here is a basic example of how to fool TP's linker into letting us get away with including non-code object data:
{$F+}  {force far calls}

{$L hw.obj}

procedure hw; external;  {fool TP as $L is supposed to be for code only}

Begin
  Halt; {Halt as we do NOT want to run the following reference which is DATA}
  HW;   {We need to include a reference to it otherwise TP won't include it}
End.


Turbo Pascal example 2
In this example we print out the text that was linked into our EXE from HW.OBJ after fooling TP's linker as already shown above. Note: this time however we use a move to overcome Borland's checking for "invalid variables".

{$F+}  {force far calls}

{$L hw.obj}

procedure hw; external;  {fool TP as $L is supposed to be for code only}

Var
  MyMessage:array[1..12] of char; {Our example text is 12 bytes long}

Begin
  Writeln;
  Move(Mem[Seg(HW):Ofs(HW)], MyMessage, SizeOf(MyMessage)); {What invalid variable? :}
  Writeln('My Message = ', MyMessage);
  Halt; {Halt as we do NOT want to run the following reference which is DATA}
  HW;   {We need to include a reference otherwise TP won't include it}
End.



Note: There are many ways of doing things like the above to add data/code during (or after) linking with Borland's products. e.g. After linking you can use Ben Castricum's UNP (e.g. unp412.zip) has the "m" (MarkEXE) option to "insert a file into an EXE's header" which is another basic way of getting resources into EXE files.

Back to index page
Thread view  Board view
22049 Postings in 2034 Threads, 396 registered users, 295 users online (0 registered, 295 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum