Board index » delphi » Detecting Protected/Real mode

Detecting Protected/Real mode

Heya. I'm using Borland Pascal 7.0, and I am looking for some reliable method
for a program to detect, whether it is running/compiled for Protected mode or
Real mode. If there is a syntax which uses compiler directive, that is a
definet plus, but as long as it is reliable (i.e. it doesn't change depending
on system/prototype hardware) it would be great.

Thanks :)

Minoru Toda

 

Re:Detecting Protected/Real mode


Quote
>for a program to detect, whether it is running/compiled for Protected mode
>or Real mode. If there is a syntax which uses compiler directive, that is a

{$IFDEF DPMI}
WriteLn('Running in PM');
{$ELSE}
WriteLn('Running in RM');
{$ENDIF}

Regarding your previous question (upgrading program later on), you could try
using .DLLs.  You should however define the interface in advance (without
the code to support it).   Ie. define LoadJPG/SaveJPG procedures now (simple
begin;end) and when you have the time, add the actual  procedure into the
.DLL.

Robert

Re:Detecting Protected/Real mode


Minoru Toda used chalk and slate for
Quote
>Heya. I'm using Borland Pascal 7.0, and I am looking for some reliable method
>for a program to detect, whether it is running/compiled for Protected mode or
>Real mode. If there is a syntax which uses compiler directive, that is a
>definet plus, but as long as it is reliable (i.e. it doesn't change depending
>on system/prototype hardware) it would be great.

As long as you are not compiling for windows as well:

{$IFDEF DPMI}
const DPMIvar : boolean = true;
{$ELSE}
const DPMIvar : boolean = false;
{$ENDIF}
--
Pedt

Never curse the Crocodile's mother before crossing the river

Re:Detecting Protected/Real mode


In article <ncMl8MA32OR3Y...@pedt.demon.co.uk>,
Pedt Scragg  <signp...@pedt.demon.co.uk> wrote:

Quote
>Minoru Toda used chalk and slate for
>>Heya. I'm using Borland Pascal 7.0, and I am looking for some reliable method
>>for a program to detect, whether it is running/compiled for Protected mode or
>>Real mode. If there is a syntax which uses compiler directive, that is a
>>definet plus, but as long as it is reliable (i.e. it doesn't change depending
>>on system/prototype hardware) it would be great.

>As long as you are not compiling for windows as well:

>{$IFDEF DPMI}
>const DPMIvar : boolean = true;
>{$ELSE}
>const DPMIvar : boolean = false;
>{$ENDIF}

Do not make them typed constants, instead use normal constants:

{$IFDEF DPMI}
const DPMIvar = true;
{$ELSE}
const DPMIvar = false;
{$ENDIF}

In that way the compiler can optimize them

Osmo

Re:Detecting Protected/Real mode


JRS:  In article <ncMl8MA32OR3Y...@pedt.demon.co.uk> of Fri, 21 May 1999
06:23:03 in news:comp.lang.pascal.borland, Pedt Scragg

Quote
<newsmas...@pedt.demon.co.uk> wrote:
>Minoru Toda used chalk and slate for
>>Heya. I'm using Borland Pascal 7.0, and I am looking for some reliable method
>>for a program to detect, whether it is running/compiled for Protected mode or
>>Real mode. If there is a syntax which uses compiler directive, that is a
>>definet plus, but as long as it is reliable (i.e. it doesn't change depending
>>on system/prototype hardware) it would be great.

>As long as you are not compiling for windows as well:

>{$IFDEF DPMI}
>const DPMIvar : boolean = true;
>{$ELSE}
>const DPMIvar : boolean = false;
>{$ENDIF}

const DPMIvar : boolean = {$IFDEF DPMI} true {$ELSE} false {$ENDIF} ;

is IMHO better (unless you are paid by the line).

Precede it, for safety, with

{$IFDEF WINDOWS} **fail**  {$ENDIF}

Perhaps you should also consider what else the program might be compiled
with, perhaps in future, and include some IFDEFs on VER##.  I find it
useful to test some programs with Delphi 3 "DCC32 -cc", for example - it
gives useful warnings, though it is not a true superset of BP7 - whether
or not you expect to run that way.

I now often add {$I version.pas} to programs, to include
        http://www.merlyn.demon.co.uk/programs/version.pas

--
 ? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
  Web <URL: http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
  PAS, EXE in <URL: http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
  Do not Mail News to me.    Before a reply, quote with ">" or "> " (SoRFC1036)

Re:Detecting Protected/Real mode


JRS:  In article <7i3spn$...@kruuna.Helsinki.FI> of Fri, 21 May 1999
18:06:31 in news:comp.lang.pascal.borland, Osmo Ronkanen

Quote
<ronka...@cc.helsinki.fi> wrote:
>In article <ncMl8MA32OR3Y...@pedt.demon.co.uk>,
>Pedt Scragg  <signp...@pedt.demon.co.uk> wrote:
>>Minoru Toda used chalk and slate for
>>>Heya. I'm using Borland Pascal 7.0, and I am looking for some reliable method
>>>for a program to detect, whether it is running/compiled for Protected mode or
>>>Real mode. If there is a syntax which uses compiler directive, that is a
>>>definet plus, but as long as it is reliable (i.e. it doesn't change depending
>>>on system/prototype hardware) it would be great.

>>As long as you are not compiling for windows as well:

>>{$IFDEF DPMI}
>>const DPMIvar : boolean = true;
>>{$ELSE}
>>const DPMIvar : boolean = false;
>>{$ENDIF}

>Do not make them typed constants, instead use normal constants:

>{$IFDEF DPMI}
>const DPMIvar = true;
>{$ELSE}
>const DPMIvar = false;
>{$ENDIF}

>In that way the compiler can optimize them

Yes, I missed saying that.

IIRC, that also means that one can write, rather than
     {$IFDEF DPMI} <DPMI code> {$ELSE} <non-DPMI code> {$ENDIF} ,
     if DPMIvar then <DPMI code> else <non-DPMI code> end ;
which will optimise to the same, but which has the advantage that the
compiler will check both branches for compilability, whichever option
one is currently using.  This helps one to keep the two branches
compatible when, for example, adding functionality.

--
 ? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
  Web <URL: http://www.merlyn.demon.co.uk/> - TP/BP/&c. FAQqish topics & links.
  Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
  <A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.

Other Threads