home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / OS2UNIT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-08-05  |  4KB  |  132 lines

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