www.digitalmars.com         C & C++   DMDScript  

c++.dos - Relearning DOS. Good reference?

reply scottm obsessionaudio.com writes:
It's been years since I used DOS. I'm about to buy a PC104 board that has a 586
and runs a DOS variant (General Software DOS-ROM), and I have a lot of C++ code
I need to get running on it.

Can anyone suggest a GOOD primer on coding under DOS? I'm fine with C++, and I
understand the basic concepts behind interrupts, and I can stumble along in
inline assembler (but not .asm files). I remember nothing about memory extenders
(which I don't know if I'll need), mixed model programming, etc. 

Here are the specific areas I'm worried about:

The code
1) needs 32 bit ints, but no indicvidual objects I reference get anywhere near
64K. But I will probably end up with over 64K of data, aggregate.  I vaguely
remember that affects whether I use real or protected mode, but I don't remember
how it all works. 

2) needs to handle 3-4 serial ports, can't be allowed to miss any characters,
and can't poll. There's not a lot of traffic, but what there is, has to be
handled without fail. I need to use interrupts. As I remember, DOS doesn't
handle that case for you. I've run across assembler code, that handles hooking
the interrupts and buffering the I/O, in assembler. I have no idea how to mix
this .asm file with C++.

2) I'm planning to use Waterloo TCP and UDP. I think those demand large model.
That worries me, becauwse the assembler I scrounged for the serial ports starts
IDEAL
MODEL	compact
and I vaguely remember that mixed model programming was tricky. 

3) The code might someday need more than 4 serial ports. If I'm doing serial
ports with interrupts, I ought to be able to keep adding ports as long as I have
IRQs available. But IRQs will become a problem eventually. However, the board
I'm using also has a USB port. If I could make that work under DOS, I could
probably attach all the serial ports I would ever need off of that... but I
don't see much discussion of controlling a USB port under DOS. Is it possible?
Where would I find code?

Ironically, I don't think I need any of DOS's services, per se. I don't need to
allocate memory, do any file I/O (not even console/keyboard), and I don't even
need the time of day clock, though it might be nice to have. I need TCP, UDP,
serial access via interrupts, access to I/O ports, access to a few other
interrupts, and pretty much nothing else. DOS is just there to launch my
application at power-on. I'm hoping that simplifies things....

I know I can just bang around for awhile and figure all this out by trial and
error, but once I get the hardware I'd like to get things running in days, not
months. So if anyone can suggest a good cookbook or reference, that'd be great.

Or even better, if anyone *Happens* to have C++ code that hooks interrupts, uses
Waterloo TCP and does serial I/O, and doesn't mind sharing... :-)

Thanks for any help.
Apr 15 2006
next sibling parent reply Jan Knepper <jan smartsoft.us> writes:
scottm obsessionaudio.com wrote:
 It's been years since I used DOS. I'm about to buy a PC104 board that has a 586
 and runs a DOS variant (General Software DOS-ROM), and I have a lot of C++ code
 I need to get running on it.
 
 Can anyone suggest a GOOD primer on coding under DOS? I'm fine with C++, and I
 understand the basic concepts behind interrupts, and I can stumble along in
 inline assembler (but not .asm files). I remember nothing about memory
extenders
 (which I don't know if I'll need), mixed model programming, etc. 

DMC comes with DOSX extender... www.dosextender.com Which works like a charm. The libraries should be available for DOSX as well.
 Here are the specific areas I'm worried about:
 
 The code
 1) needs 32 bit ints, but no indicvidual objects I reference get anywhere near
 64K. But I will probably end up with over 64K of data, aggregate.  I vaguely
 remember that affects whether I use real or protected mode, but I don't
remember
 how it all works. 

Use DOSX as your memory model... 4 GB Flat...
 2) needs to handle 3-4 serial ports, can't be allowed to miss any characters,
 and can't poll. There's not a lot of traffic, but what there is, has to be
 handled without fail. I need to use interrupts. As I remember, DOS doesn't
 handle that case for you. I've run across assembler code, that handles hooking
 the interrupts and buffering the I/O, in assembler. I have no idea how to mix
 this .asm file with C++.

You should be able to handle this with DOSX...
 3) I'm planning to use Waterloo TCP and UDP. I think those demand large model.
 That worries me, becauwse the assembler I scrounged for the serial ports starts
 IDEAL
 MODEL	compact
 and I vaguely remember that mixed model programming was tricky. 

I would look for other code for the serial ports in that case. You should be able to write that in C/C++ in DOSX.
 4) The code might someday need more than 4 serial ports. If I'm doing serial
 ports with interrupts, I ought to be able to keep adding ports as long as I
have
 IRQs available. But IRQs will become a problem eventually. However, the board
 I'm using also has a USB port. If I could make that work under DOS, I could
 probably attach all the serial ports I would ever need off of that... but I
 don't see much discussion of controlling a USB port under DOS. Is it possible?
 Where would I find code?

No Idea... with all these requirements why are you running DOS? and not a BSD or Linux?
 Ironically, I don't think I need any of DOS's services, per se. I don't need to
 allocate memory, do any file I/O (not even console/keyboard), and I don't even
 need the time of day clock, though it might be nice to have. I need TCP, UDP,
 serial access via interrupts, access to I/O ports, access to a few other
 interrupts, and pretty much nothing else. DOS is just there to launch my
 application at power-on. I'm hoping that simplifies things....
 
 I know I can just bang around for awhile and figure all this out by trial and
 error, but once I get the hardware I'd like to get things running in days, not
 months. So if anyone can suggest a good cookbook or reference, that'd be great.
 
 Or even better, if anyone *Happens* to have C++ code that hooks interrupts,
uses
 Waterloo TCP and does serial I/O, and doesn't mind sharing... :-)

Seems like you are writing a communications Black-Box... In current day and age I would use FreeBSD for that... or any of the other BSD's or in the worst case Linux... Jan -- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org
Apr 15 2006
parent Cesar Rabak <crabak acm.org> writes:
Jan Knepper escreveu:
 scottm obsessionaudio.com wrote:

 4) The code might someday need more than 4 serial ports. If I'm doing 
 serial
 ports with interrupts, I ought to be able to keep adding ports as long 
 as I have
 IRQs available. But IRQs will become a problem eventually. However, 
 the board
 I'm using also has a USB port. If I could make that work under DOS, I 
 could
 probably attach all the serial ports I would ever need off of that... 
 but I
 don't see much discussion of controlling a USB port under DOS. Is it 
 possible?
 Where would I find code?

No Idea... with all these requirements why are you running DOS? and not a BSD or Linux?

 
 Seems like you are writing a communications Black-Box... In current day 
 and age I would use FreeBSD for that... or any of the other BSD's or in 
 the worst case Linux...
 

factor (which I believe it is not, one project we did some years ago used a NS 486 chip which had no real [16 bit] mode and some mappings were different from ordinary PCs), porting BSD or Linux may be a lot of work if no distro already had been assembled and compiled for the board. just .019999
Apr 24 2006
prev sibling parent reply Cesar Rabak <crabak acm.org> writes:
scottm obsessionaudio.com escreveu:
 It's been years since I used DOS. I'm about to buy a PC104 board that has a 586
 and runs a DOS variant (General Software DOS-ROM), and I have a lot of C++ code
 I need to get running on it.

OK.
 
 Can anyone suggest a GOOD primer on coding under DOS? I'm fine with C++, and I
 understand the basic concepts behind interrupts, and I can stumble along in
 inline assembler (but not .asm files). I remember nothing about memory
extenders
 (which I don't know if I'll need), mixed model programming, etc. 

Although I see your concerns are correct and legitimate, I suggest you first peruse the manual will come with the PC104 board. As it is supposed you'll develop for it, it _should_ come with stuff to allow to develop in this specific flavor of DOS.
 
 Here are the specific areas I'm worried about:
 
 The code
 1) needs 32 bit ints, but no indicvidual objects I reference get anywhere near
 64K. But I will probably end up with over 64K of data, aggregate.  I vaguely
 remember that affects whether I use real or protected mode, but I don't
remember
 how it all works. 

Is this DOS version 16 o 32 bits?
 
 2) needs to handle 3-4 serial ports, can't be allowed to miss any characters,
 and can't poll. There's not a lot of traffic, but what there is, has to be
 handled without fail. I need to use interrupts. As I remember, DOS doesn't
 handle that case for you. I've run across assembler code, that handles hooking
 the interrupts and buffering the I/O, in assembler. I have no idea how to mix
 this .asm file with C++.

First, and most important check if the development environment supported by the vendor doesn't come with some libraries that do the dirty work for you. Even if in source code (and in assembly) it'll spare you a lot of work, and nowadays should be no a big addon as this is more or less expected to be a requirement of your end app.
 
 2) I'm planning to use Waterloo TCP and UDP. I think those demand large model.
 That worries me, becauwse the assembler I scrounged for the serial ports starts
 IDEAL
 MODEL	compact
 and I vaguely remember that mixed model programming was tricky. 

Again, check if there isn't a suitable stack and library for your board.
 
 3) The code might someday need more than 4 serial ports. If I'm doing serial
 ports with interrupts, I ought to be able to keep adding ports as long as I
have
 IRQs available. But IRQs will become a problem eventually. However, the board
 I'm using also has a USB port. If I could make that work under DOS, I could
 probably attach all the serial ports I would ever need off of that... but I
 don't see much discussion of controlling a USB port under DOS. Is it possible?
 Where would I find code?

Yes, it is doable, but the specifics may need to get support from your vendor, except if you intend to do lots of hacking.
 
 Ironically, I don't think I need any of DOS's services, per se. I don't need to
 allocate memory, do any file I/O (not even console/keyboard), and I don't even
 need the time of day clock, though it might be nice to have. I need TCP, UDP,
 serial access via interrupts, access to I/O ports, access to a few other
 interrupts, and pretty much nothing else. DOS is just there to launch my
 application at power-on. I'm hoping that simplifies things....

Most of these embedded DOS versions come with ways of customizing it so you don't use more than you need, although YMMV.
 
 I know I can just bang around for awhile and figure all this out by trial and
 error, but once I get the hardware I'd like to get things running in days, not
 months. So if anyone can suggest a good cookbook or reference, that'd be great.
 
 Or even better, if anyone *Happens* to have C++ code that hooks interrupts,
uses
 Waterloo TCP and does serial I/O, and doesn't mind sharing... :-)

In the past the Simtel site used to have lots of stuff like this. Some reminiscent sites: http://www.opus.co.tt/dave/indexall.htm http://a2.pluto.it/a2754.htm http://www.filegate.net/pdncee/ http://www.faqs.org/faqs/C++-faq/libraries/part2/ (but see the other parts as well :-) HTH
 
 Thanks for any help.
 
 

Apr 24 2006
parent reply scottm obsessionaudio.com writes:
In article <e2jd1j$dlu$1 digitaldaemon.com>, Cesar Rabak says...
scottm obsessionaudio.com escreveu:
 It's been years since I used DOS. I'm about to buy a PC104 board that has a 586
 and runs a DOS variant (General Software DOS-ROM), and I have a lot of C++ code
 I need to get running on it.

OK.
 
 Can anyone suggest a GOOD primer on coding under DOS? I'm fine with C++, and I
 understand the basic concepts behind interrupts, and I can stumble along in
 inline assembler (but not .asm files). I remember nothing about memory
extenders
 (which I don't know if I'll need), mixed model programming, etc. 

Although I see your concerns are correct and legitimate, I suggest you first peruse the manual will come with the PC104 board.

Limited info there.
As it is supposed you'll develop for it, it _should_ come with stuff to 
allow to develop in this specific flavor of DOS.

Is this DOS version 16 o 32 bits?

I'm looking at General DOS or FreeDOs. These are both 16 bit. I expect to easily fit in 640K (even with waterloo TCP/UDP linked in) but I do want "int" to be 32 bits and "unsigned long long" to be 64. I just now ran into this - I got my code to compile under DM, but when I added -ml to the command line I got slapped about my use of unsigned long long. Hrm. Basically, I want the modern conveniences of C++ as I know it, but stil be able to code to bare metal so I can have interrupts and the I/O instructions. I ruled out ?unix early, as it was demanding I do a device driver to get at interrupts and in/out instructions, and I just can't be bothered. I want to own the machine, not negotiate for it.
In the past the Simtel site used to have lots of stuff like this. Some 
reminiscent sites:

http://www.opus.co.tt/dave/indexall.htm
http://a2.pluto.it/a2754.htm
http://www.filegate.net/pdncee/
http://www.faqs.org/faqs/C++-faq/libraries/part2/ (but see the other 
parts as well :-)

Thanks!
Apr 26 2006
next sibling parent reply scottm obsessionaudio.com writes:
I bet this screams "memory model problem", but I'm new to this compiler, so bear
with me.

Here's the command line:

\digitalMars\bin\dmc -5 -ml -I.\wat2001a\include controllerv4.cpp
\wat2001a\lib\wattcpsm.lib

I get a whole lot of: 

C:\digitalMars\bin\..\lib\SDC.lib(far)
Error 36: LOCATION Not Within FRAME at Relative 00015H  from
Segment _TEXT
FRAME  = Frame of TARGET 00000H
TARGET = External Symbol _farfree 192DAH
FIXUPP Type = Near JMP or CALL

--- errorlevel 431

I'm compiling on a windows box, for a DOS16 target, and I undef'd __NT__ in
order to get this far. I've tried -ms and -mc, and -mXd; same result. What am I
missing?
Apr 26 2006
next sibling parent Cesar Rabak <crabak acm.org> writes:
scottm obsessionaudio.com escreveu:
 I bet this screams "memory model problem", but I'm new to this compiler, so
bear
 with me.
 
 Here's the command line:
 
 \digitalMars\bin\dmc -5 -ml -I.\wat2001a\include controllerv4.cpp
 \wat2001a\lib\wattcpsm.lib
 
 I get a whole lot of: 
 
 C:\digitalMars\bin\..\lib\SDC.lib(far)
 Error 36: LOCATION Not Within FRAME at Relative 00015H  from
 Segment _TEXT
 FRAME  = Frame of TARGET 00000H
 TARGET = External Symbol _farfree 192DAH
 FIXUPP Type = Near JMP or CALL
 
 --- errorlevel 431
 
 I'm compiling on a windows box, for a DOS16 target, and I undef'd __NT__ in
 order to get this far. I've tried -ms and -mc, and -mXd; same result. What am I
 missing?
 

wattcpsm.lib?
Apr 26 2006
prev sibling next sibling parent reply scottm obsessionaudio.com writes:
In article <e2p0f3$2f5m$1 digitaldaemon.com>, scottm obsessionaudio.com says...

I bet this screams "memory model problem"...
Here's the command line:

\digitalMars\bin\dmc -5 -ml -I.\wat2001a\include controllerv4.cpp
\wat2001a\lib\wattcpsm.lib

OK. It looks like the problem is that "sm" means "small model"; my code can't use small. I've tried to rebuild wattcp for large model using dmc. It looks pretty hopeless; apparently wattcp was written to assume a Borland compiler (I'm looking at wat2001a) and there are dozens of errors under dmc. Has anyone used waterloo TCP/UDP in a Digital Mars project? Having paid $55 for the blasted waterloo documentation (to find out it doesn't have build instructions), I'm hoping I don't have to restart the hunt for a different TCP library (or different compiler).
Apr 26 2006
next sibling parent Cesar Rabak <crabak acm.org> writes:
scottm obsessionaudio.com escreveu:
 In article <e2p0f3$2f5m$1 digitaldaemon.com>, scottm obsessionaudio.com says...
 
 
I bet this screams "memory model problem"...
Here's the command line:

\digitalMars\bin\dmc -5 -ml -I.\wat2001a\include controllerv4.cpp
\wat2001a\lib\wattcpsm.lib

OK. It looks like the problem is that "sm" means "small model"; my code can't use small. I've tried to rebuild wattcp for large model using dmc. It looks pretty hopeless; apparently wattcp was written to assume a Borland compiler (I'm looking at wat2001a) and there are dozens of errors under dmc. Has anyone used waterloo TCP/UDP in a Digital Mars project? Having paid $55 for the blasted waterloo documentation (to find out it doesn't have build instructions), I'm hoping I don't have to restart the hunt for a different TCP library (or different compiler).

The DMC comes with an utility called 'bcc', and a 'make' one. Does the Borland makefile compiles using these tools? HTH -- Cesar Rabak
Apr 27 2006
prev sibling parent "tjulian" <tjulian removethis.oldi.com> writes:
scottm obsessionaudio.com wrote:

 Has anyone used waterloo TCP/UDP in a Digital Mars project?

I went through the exercise of porting wattcp to DMC. There were many issues, but everything works. The one problem is that this is still DOS16 code. There is now available a Wattcp32 package that includes DMC support. It is compilable for DOS16 (16bit int) and for Extended DOS (32bit int with DOS Extender). I recommend downloading this package and starting there since it is being actively maintained. -- TimJ
Apr 28 2006
prev sibling parent Walter Bright <newshound digitalmars.com> writes:
Framing errors happen when code tries to make a 'near' reference to 
something that's in another segment.
Apr 29 2006
prev sibling parent Walter Bright <newshound digitalmars.com> writes:
scottm obsessionaudio.com wrote:
 I'm looking at General DOS or FreeDOs. These are both 16 bit. I expect to
easily
 fit in 640K (even with waterloo TCP/UDP linked in) but I do want "int" to be 32
 bits and "unsigned long long" to be 64.
 
 I just now ran into this - I got my code to compile under DM, but when I added
 -ml to the command line I got slapped about my use of unsigned long long. Hrm.

64 bit integers aren't supported for 16 bit code. Can I suggest using DOS in 32 bit mode (the -mx memory model)?
Apr 29 2006