community.borland.com

Article #15341: Creating Protected Mode Apps with Borland Pascal

 Technical Information Database

TI341D.txt - Creating Protected Mode Apps with Borland Pascal

Category   :Turbo Pascal
Platform   :DOS
Product    :

Description:

o Benefits of Protected Mode Programming

     Borland Pascal with Objects allows you to create DOS
protected mode applications.
     This means that your programs no longer have to be
constricted by the long-standing 640 k memory limitation. This
barrier has now disappeared entirely with our protected mode
target that allows you to create programs that use up to 16meg of
code and data.
     You only need to throw a single switch inside the IDE
(integrated development environment) in order to produce a
protected mode application. In most circumstances there is no
need to change your code at all.
     Consider the following program, which reports on the
available memory:

     program MemSize;

     begin
       WriteLn(MemAvail);
     end.

If compiled in real mode,  this program will probably report that
you have between 300,000 and 600,000 bytes of memory available.
If you open the Compile menu, select Target, and switch from Real
Mode to Protected Mode code generation, then this program will
report a figure near the total amount of RAM available on your
current system.
     If you use the command line compiler, called BPC.EXE, then
it is only necessary to add "/cp" to the command line in order to
compile a protected mode app. For instance, to compile the
program listed above in real mode, one would type:

     bpc MemSize

To recompile this same application in protected mode, one would
type:

     bpc/cp MemSize

As an unofficial test case, these two programs were run on a
system with 12 megs of memory available. In the first case
MemSize reported 574,144 bytes of memory available, but when
compiled in protected mode, it reported 9,118,992 bytes of memory
available. This is a difference of over 8 million bytes.


o Differences between Real and Protected Mode programming

     Although most Pascal programs written under TP60 will
recompile unchanged as protected mode apps, developers should be
aware of the way memory is addressed in protected mode. Real mode
DOS addresses typically include a segment and offset which
reference an actual location in memory. But under Intel's
protected mode memory scheme, the segment portion of an address
is replaced with something called a selector.
     Selectors are not real memory addresses but rather indexes
into a descriptor table. This table is maintained by the
operating system and cannot normally be accessed directly by a
programmer. This means that programs which directly reference
real mode memory addresses will have to be adjusted before they
will run correctly in protected mode.
     Fortunately, Intel has provided programmers with a DOS
Protected Mode Interface (DPMI) specification, which forms a
gateway between protected mode and real mode. Borland's new
protected mode DOS extender is DPMI compliant, so this interface
is available to experienced programmers who want to address real
mode memory directly. As a result, Borland Pascal protected mode
apps have almost unlimited access to real mode.
     Your protected mode applications will also run inside a
Windows DOS box. This is possible because Windows itself runs in
protected mode and is somewhat DPMI compliant.
     There are no royalties involved in using this new DOS
extender technology, but BP.EXE, the new Pascal IDE, requires at
least a 286 machine with two megs of memory to run. If you can
meet these requirements then the world of protected mode
programming is now available to you at the flip of a switch.
     For more information as to the internals of the DOS extender
technology, Borland has made available the Open Architecture
Handbook which goes in to some detail about this new and exciting
area of programming.


Reference:
 

3/30/99 3:10:14 PM
 

Last Modified: 01-SEP-99