home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / win_os2.swg / 0002_OS2CHECK.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  4KB  |  143 lines

  1. {
  2. Author : GREGORY P. SMITH
  3.  
  4. > Is there any way to detect OS/2 (in a Dos box) sessions and Windows
  5. > Sessions? I'd like to throw in support For these multitaskers so I can
  6. > run an idlekey Program.
  7.  
  8. Actual code is always the best example For me..  Look at this Unit (and use
  9. it, I think you'll like it).  Check With someone else if you want to
  10. specifically detect winslows.  This Unit will, however, give up time to any
  11. multitasker.
  12. }
  13.  
  14. (* Public Domain Unit by Gregory P. Smith, No Rights Reserved *)
  15. (* ...  This also means no guarantees  ... *)
  16.  
  17. Unit OS_Test; { DESQview, OS/2, & 386 v86 machine Interfaces }
  18.  
  19. {$X+,S-,R-,F-,O-,D-,G-} { extended syntax, nothing else }
  20.  
  21. Interface
  22.  
  23. Const
  24.   In_DV  : Boolean = False; { are we in DESQview? }
  25.   In_VM  : Boolean = False; { are we in a 386+ virtual machine? }
  26.   In_OS2 : Boolean = False; { are we in OS/2? }
  27.  
  28. Function  OS2_GetVersion: Word; { Get OS/2 version # }
  29. Function  DV_GetVersion: Word; { update In_DV and get version # }
  30. Function  DV_Get_Video_Buffer(vseg:Word): Word; { get the alt video buffer }
  31. Procedure DV_Pause; { give up time slice }
  32. Procedure MT_Pause; Inline($cd/$28); { give up time in most multitaskers }
  33. Procedure KillTime; { Release time in any situation }
  34. Procedure DV_begin_Critical; { don't slice away }
  35.   Inline($b8/$1b/$10/$cd/$15);
  36. Procedure DV_end_Critical; { allow slicing again }
  37.   Inline($b8/$1c/$10/$cd/$15);
  38. Procedure DV_Sound(freq,dur:Integer); { Create a Sound in the Bkg }
  39.  
  40. Implementation
  41.  
  42. Function OS2_GetVersion: Word; Assembler;
  43. Asm
  44.   MOV    AH, 30h  { Dos Get Version Call }
  45.   INT    21h      { AL = major version * 10, AH = minor version }
  46.   MOV    BH, AH   { save minor version }
  47.   xor    AH, AH
  48.   MOV    CL, 10
  49.   div    CL       { divide by 10 to get the major version }
  50.   MOV    AH, BH   { restore minor version }
  51.   XCHG   AH, AL   { AH = major, AL = minor }
  52. end;
  53.  
  54. Function DV_GetVersion: Word; Assembler;
  55. Asm
  56.   MOV    CX,'DE'     { CX+DX to 'DESQ' (invalid date) }
  57.   MOV    DX,'SQ'
  58.   MOV    AX,02B01H   { Dos' set date funct. }
  59.   INT    21H         { call Dos }
  60.   CMP    AL,0FFH     { Was it invalid? }
  61.   JE     @No_dv      { yep, no dv }
  62.   MOV    AX,BX       { AH=major AL=minor }
  63.   MOV    In_DV,1     { Set In_DV flag }
  64.   JMP    @DvGv_x     { other routines }
  65.  @No_dv:
  66.   xor    AX,AX       { Return 0 or no DV }
  67.  @DvGv_x:
  68. end; { DV_GetVersion }
  69.  
  70. Function DV_Get_Video_Buffer(vseg:Word): Word; Assembler;
  71. Asm                      { Modified by Scott Samet April 1992 }
  72.   CALL   DV_GetVersion   { Returns AX=0 if not in DV }
  73.   MOV    ES,vseg         { Put current segment into ES }
  74.   TEST   AX,AX           { In DV? }
  75.   JZ     @DVGVB_X        { Jump if not }
  76.   MOV    AH,0FEH         { DV's get video buffer Function }
  77.   INT    10H             { Returns ES:DI of alt buffer }
  78.  @DVGVB_X:
  79.   MOV    AX,ES           { Return video buffer }
  80. end; { DV_Get_Video_Buffer }
  81.  
  82. Procedure DV_Pause;
  83. begin
  84.   if In_DV then
  85.   Asm
  86.     MOV AX, 1000h    { pause Function }
  87.     INT 15h
  88.   end;
  89. end; { DV_Pause }
  90.  
  91. Procedure KillTime;
  92. begin
  93.   if In_VM then
  94.   Asm
  95.     MOV AX, 1680h    { give up VM time slice }
  96.     INT 2Fh
  97.   end
  98.   else
  99.   if In_DV then
  100.   Asm
  101.     MOV AX, 1000h    { DV pause call }
  102.     INT 15h
  103.   end
  104.   else
  105.     MT_Pause;      { Dos Idle call }
  106. end;
  107.  
  108. (* Procedure DV_begin_Critical; Assembler;
  109. Asm
  110.   MOV AX,$101B       { DV begin critical Function }
  111.   INT 15h
  112. end; { DV_begin_Critical }
  113.  
  114. Procedure DV_end_Critical; Assembler;
  115. Asm
  116.   MOV AX,$101C       { DV end critical Function }
  117.   INT 15h
  118. end; { DV_end_Critical }  *)
  119.  
  120. Procedure DV_Sound(freq,dur:Integer); Assembler; { Sound a tone }
  121. Asm
  122.   MOV   AX,1019H
  123.   MOV   BX,freq  { frequency above 20 Hz }
  124.   MOV   CX,dur   { duration in clock ticks }
  125.   INT   15H
  126. end;
  127.  
  128. { ** -- initalization -- ** }
  129.  
  130. begin
  131.   DV_GetVersion; { discard answer.  Just update In_DV }
  132.   Asm
  133.     MOV AX, 1680h
  134.     INT 2Fh          { Gives up time slice in most 386+ virtual machines }
  135.     not AL           { AL = 00h if supported, remains 80h if not }
  136.     MOV CL, 7
  137.     SHR AL, CL       { move bit 7 to bit 0 For a Boolean }
  138.     MOV In_VM, AL    { update the flag }
  139.   end;
  140.   In_OS2 := (OS2_GetVersion >= $0100); { version 1.0 or greater }
  141. end.
  142.  
  143.