TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Stefan van der Walt
from: Francois Thunus
date: 1996-03-02 08:59:00
subject: Time Slicing and Detecting OS/2

Hello Stefan!

24 Feb 96 17:43, Stefan van der Walt wrote to All:

 SvdW>   1) How to do time slicing in Pascal for OS/2 running in a DOS Session?
 SvdW>   2) How do I detect if OS/2 is running so that I can enable time
 SvdW>      slicing?


>----- Begin -----

{
Author : GREGORY P. SMITH

> Is there any way to detect OS/2 (in a Dos box) sessions and Windows
> Sessions? I'd like to throw in support For these multitaskers so I can
> run an idlekey Program.

Actual code is always the best example For me..  Look at this Unit (and use
it, I think you'll like it).  Check With someone else if you want to
specifically detect winslows.  This Unit will, however, give up time to any
multitasker.
}

(* Public Domain Unit by Gregory P. Smith, No Rights Reserved *)
(* ...  This also means no guarantees  ... *)

Unit MTcheck; { DESQview, OS/2, & 386 v86 machine Interfaces }

{$X+,S-,R-,F-,O-,D-,G-} { extended syntax, nothing else }

Interface

Const
  In_DV  : Boolean = False; { are we in DESQview? }
  In_VM  : Boolean = False; { are we in a 386+ virtual machine? }
  In_OS2 : Boolean = False; { are we in OS/2? }

Function  OS2_GetVersion: Word; { Get OS/2 version # }
Function  DV_GetVersion: Word; { update In_DV and get version # }
Function  DV_Get_Video_Buffer(vseg:Word): Word; { get the alt video buffer }
Procedure DV_Pause; { give up time slice }
Procedure MT_Pause; Inline($cd/$28); { give up time in most multitaskers }
Procedure KillTime; { Release time in any situation }
Procedure DV_begin_Critical; { don't slice away }
  Inline($b8/$1b/$10/$cd/$15);
Procedure DV_end_Critical; { allow slicing again }
  Inline($b8/$1c/$10/$cd/$15);
Procedure DV_Sound(freq,dur:Integer); { Create a Sound in the Bkg }

Implementation

Function OS2_GetVersion: Word; Assembler;
Asm
  MOV    AH, 30h  { Dos Get Version Call }
  INT    21h      { AL = major version * 10, AH = minor version }
  MOV    BH, AH   { save minor version }
  xor    AH, AH
  MOV    CL, 10
  div    CL       { divide by 10 to get the major version }
  MOV    AH, BH   { restore minor version }
  XCHG   AH, AL   { AH = major, AL = minor }
end;

Function DV_GetVersion: Word; Assembler;
Asm
  MOV    CX,'DE'     { CX+DX to 'DESQ' (invalid date) }
  MOV    DX,'SQ'
  MOV    AX,02B01H   { Dos' set date funct. }
  INT    21H         { call Dos }
  CMP    AL,0FFH     { Was it invalid? }
  JE     {at}No_dv      { yep, no dv }
  MOV    AX,BX       { AH=major AL=minor }
  MOV    In_DV,1     { Set In_DV flag }
  JMP    {at}DvGv_x     { other routines }
 {at}No_dv:
  xor    AX,AX       { Return 0 or no DV }
 {at}DvGv_x:
end; { DV_GetVersion }

Function DV_Get_Video_Buffer(vseg:Word): Word; Assembler;
Asm                      { Modified by Scott Samet April 1992 }
  CALL   DV_GetVersion   { Returns AX=0 if not in DV }
  MOV    ES,vseg         { Put current segment into ES }
  TEST   AX,AX           { In DV? }
  JZ     {at}DVGVB_X        { Jump if not }
  MOV    AH,0FEH         { DV's get video buffer Function }
  INT    10H             { Returns ES:DI of alt buffer }
 {at}DVGVB_X:
  MOV    AX,ES           { Return video buffer }
end; { DV_Get_Video_Buffer }

Procedure DV_Pause;
begin
  if In_DV then
  Asm
    MOV AX, 1000h    { pause Function }
    INT 15h
  end;
end; { DV_Pause }

Procedure KillTime;
begin
  if In_VM then
  Asm
    MOV AX, 1680h    { give up VM time slice }
    INT 2Fh
  end
  else
  if In_DV then
  Asm
    MOV AX, 1000h    { DV pause call }
    INT 15h
  end
  else
    MT_Pause;      { Dos Idle call }
end;

(* Procedure DV_begin_Critical; Assembler;
Asm
  MOV AX,$101B       { DV begin critical Function }
  INT 15h
end; { DV_begin_Critical }

Procedure DV_end_Critical; Assembler;
Asm
  MOV AX,$101C       { DV end critical Function }
  INT 15h
end; { DV_end_Critical }  *)

Procedure DV_Sound(freq,dur:Integer); Assembler; { Sound a tone }
Asm
  MOV   AX,1019H
  MOV   BX,freq  { frequency above 20 Hz }
  MOV   CX,dur   { duration in clock ticks }
  INT   15H
end;

{ ** -- initalization -- ** }

begin
  DV_GetVersion; { discard answer.  Just update In_DV }
  Asm
    MOV AX, 1680h
    INT 2Fh          { Gives up time slice in most 386+ virtual machines }
    not AL           { AL = 00h if supported, remains 80h if not }
    MOV CL, 7
    SHR AL, CL       { move bit 7 to bit 0 For a Boolean }
    MOV In_VM, AL    { update the flag }
  end;
  In_OS2 := (OS2_GetVersion >= $0100); { version 1.0 or greater }
end.

>-----  End  -----

sample code:

>----- Begin -----

uses mtcheck;
var in_mt: boolean;
begin
  in_mt:=(in_dv or in_os2 or in_vm);
  if in_dv then writeln ('Running under DESQview version
',hi(dv_getversion):2,'.',lo(dv_getversion):2)
  else
  if in_OS2 then
            begin
                 write('Running under OS/2 V');
                 if ((hi(os2_getversion)=2) AND(lo(os2_getversion)=30))
                  then writeln(' 3.0 Warp') else
                  writeln(hi(os2_getversion):2,'.',lo(os2_getversion):2));
            end
  else
  if in_VM then writeln ('Running in Virtual Dos Machine')
  else writeln('Running under Dos');
while true do
begin
 write ('hit a key to stop');
 if in_mt then killtime;
 if keypressed then halt;
end;
end.

>-----  End  -----

you may want to change the settings of the initial unit to allow overlay.

                             -= Francois =-
                             Thunus{at}innet.lu
                     http://www.innet.net/~pub00071
186,000 miles/sec: Not just a good idea, It's the LAW.

--- GoldED 2.50+
* Origin: Xara Sto Pragma ! Gasperich - Luxembourg -> (FidoNet 2:270/25.2)
SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 270/25 17 24/24 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.