Board index » delphi » Am I in protected mode?

Am I in protected mode?

How can my BP7 program detect wether it was compiled real or
protected mode?

Ken Pemberton
sac...@is.co.za

 

Re:Am I in protected mode?


In article <4mph4s$...@hermes.is.co.za> in comp.lang.pascal.borland,

Quote
sac...@is.co.za wrote:
>How can my BP7 program detect wether it was compiled real or
>protected mode?

Const
RealMode = {$IFDEF MSDOS} true {$ELSE} false {$ENDIF} ;
Fenestrated = {$IFDEF WINDOWS} true {$ELSE} false {$ENDIF} ;
...
Writeln('Compiled in ',
  {$IFDEF MSDOS}   'MSDOS'   {$ENDIF}
  {$IFDEF DPMI}    'DPMI'    {$ENDIF}
  {$IFDEF WINDOWS} 'WINDOWS' {$ENDIF}
  ' mode.') ;
--
John Stockton, Surrey, UK.  J...@merlyn.demon.co.uk  Turnpike v1.12  MIME

Re:Am I in protected mode?


Quote
In article <4mph4s$...@hermes.is.co.za>,  <sac...@is.co.za> wrote:
>How can my BP7 program detect wether it was compiled real or
>protected mode?

>Ken Pemberton
>sac...@is.co.za

function DetectPM:boolean; assembler;
asm
        db 0fh,01h,0e0h
        test    ax,0001
        mov     al,0
        je      @@noPM
        mov     al,1
@@NoPM:
end;

function InRealMode:boolean; assembler;
asm
        mov     ax,1686h
        int     2fh
end;

begin
 if InRealMode then writeln('In Real Mode') else writeln('In Protected Mode');
 if DetectPM then writeln('In Protected Mode') else writeln('In Real Mode');
end.

This tells you what the current mode of the machine is, not necessarily
if the program was compiled in PM/RM.  You can use {$ifdef DPMI} to
tell if the program is being compiled under PM or RM.

--TCA of NewOrder

Re:Am I in protected mode?


Quote
sac...@is.co.za wrote:
>How can my BP7 program detect wether it was compiled real or
>protected mode?

{$IFDEF dpmi}
writeln ('DPMI version');
{$endif}
http://www.webworldinc.com/joejared/
ftp://webworldinc.com/joejared/
--- Fidoknot v1.0
* Origin: Yorba Linda, CA (joeja...@webworldinc.com) BP8.0 please... Not everyone uses Windoze.

Re:Am I in protected mode?


Quote
In article <4mph4s$...@hermes.is.co.za>,  <sac...@is.co.za> wrote:
>How can my BP7 program detect wether it was compiled real or
>protected mode?

Use {$IFDEF DPMI} and/or {$IFDEF MSDOS}

Quote

>Ken Pemberton
>sac...@is.co.za

Osmo

Re:Am I in protected mode?


In article <4mtsne$...@hume.nmia.com>,

Quote
Mark Iuzzolino <iuzzo...@plato.nmia.com> wrote:

...

Quote
>begin
> if InRealMode then writeln('In Real Mode') else writeln('In Protected Mode');
> if DetectPM then writeln('In Protected Mode') else writeln('In Real Mode');
>end.

>This tells you what the current mode of the machine is, not necessarily
>if the program was compiled in PM/RM.  You can use {$ifdef DPMI} to
>tell if the program is being compiled under PM or RM.

{$ifdef DPMI} tells the mode of the target program, not of the compiler.
That is same as the mode of the processor unless one has done some
tricks.

Quote

>--TCA of NewOrder

Osmo

Re:Am I in protected mode?


Quote
sac...@is.co.za wrote:

: How can my BP7 program detect wether it was compiled real or
: protected mode?

  It depends on whether you want to know it at compile-  or at run-time. If
you want to know it at compile time use the conditional compiler directives:

  {$IFDEF DPMI}
       dpmi code
  {$ELSE}
       real-mode code
  {$ENDIF}

  If you want to know it at runtime, it is much more difficult since
nowadays all DOS based computers use some kind of memory manager (EMM386 for
instance) which enters protected mode. But this small code fragment checks
whether you are in protected mode, or not.

      mov       cr0,eax
      test      ax,1
      jne       @@ProtectedMode
@@RealMode:

@@ProtectedMode:

  If your code should work on computers based on 80286 you can use "smsw ax"
instead of mov cr0,eax.

  Another solution could be to call the DPMI install-check routine, or check
whether RTM is resident. I don't know how to do this exactly, but you could
debug your protected mode program stub, and get the info from there.

   I hope this helps,

--
                                 Balazs Scheidler

*-----------------------------------------------------------------------*
|Author of Turbo Vision Resource WorkShop, the new 3.0 version is able  |
|to generate C++ & Pascal source code, and supports custom controls.    |
|v3.0 is at:  ftp://ftp.coast.net/SimTel/msdos/turbovis/tvrw30db.zip    |
*--------------------------------------------*bAzSi*--------------------*
| email: ba...@tas.vein.hu, ba...@hal2000.vein.hu                       |
*-----------------------------------------------------------------------*

Other Threads