home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turbo Toolbox
/
Turbo_Toolbox.iso
/
1990
/
05
/
praxis
/
tsr.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1990-02-13
|
4KB
|
149 lines
(* ------------------------------------------------------ *)
(* TSR.PAS *)
(* ------------------------------------------------------ *)
{$R-,S-,I-,V-,B-,N-}
UNIT TSR;
INTERFACE USES Dos;
PROCEDURE SaveInt16;
PROCEDURE Int16;
FUNCTION AlreadyLoaded(ID : BYTE) : BOOLEAN;
FUNCTION Segment(ID : BYTE) : WORD;
FUNCTION PopUpInstalled(PopUp : Pointer;
HotKey, HeapParas : WORD) : BOOLEAN;
PROCEDURE MakeResident(ID : BYTE);
PROCEDURE ReleaseBlock(Segment : WORD);
PROCEDURE RemoveTSR;
IMPLEMENTATION
VAR
SaveSP,
SaveSS,
PopUpSS,
PopUpSP,
HotKey_ :WORD;
TempInt16,
SaveInt1B,
PopUp_ :Pointer;
InUse :BOOLEAN;
ProgramID :BYTE;
{$L TSR.OBJ}
PROCEDURE SaveInt16; EXTERNAL;
PROCEDURE Int16; EXTERNAL;
FUNCTION AlreadyLoaded(ID : BYTE) : BOOLEAN;
VAR
Regs : Registers;
IDMask : LongInt;
BEGIN
WITH Regs DO BEGIN
AH := $F0;
BX := 0;
CX := 0;
Intr ($16, Regs);
IDMask := LongInt(CX) SHL 16 + BX;
END;
AlreadyLoaded := IDMask AND
(LongInt(1) SHL Pred(ID)) <> 0;
END;
FUNCTION Segment(ID : BYTE) : WORD;
VAR
Regs : Registers;
BEGIN
WITH Regs DO BEGIN
AH := $F1;
AL := ID;
BX := 0;
Intr ($16, Regs);
Segment := BX;
END
END;
FUNCTION PopUpInstalled(PopUp :Pointer;
HotKey, HeapParas : WORD) : BOOLEAN;
CONST
Reserved = $1000;
VAR
MaxParas : WORD;
NextFree : ^WORD;
FUNCTION ParasNeeded : WORD;
{ ermittelt den Speicherbedarf des aktuellen Programms }
{ für Code-, Daten- und Stack-Segment sowie des }
{ Environment-Bereichs in Paragraphen }
VAR
EnvironSeg, EnvironSize : WORD;
BEGIN
EnvironSeg := WORD(Ptr(PrefixSeg, $002C)^);
EnvironSize := WORD(Ptr(EnvironSeg - 1, $0003)^);
ParasNeeded := Succ(Seg(HeapOrg^) -
- PrefixSeg + EnvironSize);
END;
BEGIN
PopUpInstalled := FALSE; { Mißerfolg bei Rückkehr! }
MaxParas := WORD(Ptr(PrefixSeg - 1, $0003)^);
NextFree := Ptr(PrefixSeg, $0002);
IF ParasNeeded + HeapParas + Reserved > MaxParas THEN
Exit; { zu wenig Speicher! }
FreePtr := Ptr(Seg(HeapOrg^) + HeapParas - $1000, 0);
NextFree^ := Seg(HeapOrg^) + HeapParas;
Release(HeapOrg); { gesamten Heap freimachen! }
PopUp_ := PopUp; { Installationsparameter sichen }
HotKey_ := HotKey;
PopUpInstalled := TRUE;{ Installation war erfolgreich! }
END;
PROCEDURE MakeResident(ID : BYTE);
VAR
SavePtr :^Pointer;
BEGIN
ProgramID := ID; { Identify-Maske sichern }
SavePtr := @SaveInt16;
SetIntVec ($00, SaveInt00); { Vektoren restaurieren }
SetIntVec ($1B, SaveInt1B);
SetIntVec ($23, SaveInt23);
SetIntVec ($24, SaveInt24);
GetIntVec ($16, SavePtr^); { Int16-Vektor holen... }
SetIntVec ($16, @Int16);
InUse := FALSE;
Keep(0); { Programm resident machen }
END;
PROCEDURE ReleaseBlock(Segment : WORD);
VAR
Regs : Registers;
BEGIN
WITH Regs DO BEGIN
ES := Segment;
AH := $49; { DOS-Funktion "Free Allocated Memory" }
MsDos(Regs);
END;
END;
PROCEDURE RemoveTSR;
VAR
P : ^Pointer;
BEGIN
P := @SaveInt16;
TempInt16 := P^;
IF MemW[PrefixSeg:$2C] <> 0 THEN
{ Umgebungsbereich freigeben }
ReleaseBlock(MemW[PrefixSeg:$2C]);
ReleaseBlock(PrefixSeg);
{ Programmspeicher freigeben }
END;
BEGIN
PopUpSS := SSeg; { die Stapelwerte merken }
PopUpSP := SPtr + 4; { Sprung berücksichtigen! }
GetIntVec ($1B, SaveInt1B); { Ctrl-Break-Vektor sichern }
END.
(* ------------------------------------------------------ *)
(* Ende von TSR.PAS *)