| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Timeslices |
Hello Timo!
24 Dec 95 04:49, Timo Sirainen wrote to All:
TS> repeat
TS> if keypressed then
TS> begin
TS> c:=readkey;
TS> {...}
TS> end else
TS> begin
TS> give_timeslice; { Any way to do this in OS/2 prog? }
TS> end;
TS> until quit;
{
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.
>---
This is the original. In my implementation, I tweaked the code a little to
make it return 3.0 if os/2 is 2.30.
-= Francois =-
Thunus{at}innet.lu
http://www.innet.net/~pub00071
Microsoft: Where do you want to wait today?
--- GoldED 2.50+
* Origin: Xara Sto Pragma ! Gasperich - Luxembourg -> (FidoNet 2:270/25.2)SEEN-BY: 270/101 620/243 711/401 409 410 413 430 808 809 934 955 712/407 515 SEEN-BY: 712/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™.