home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 5
/
ctrom5b.zip
/
ctrom5b
/
PROGRAM
/
PASCAL
/
PAVT199
/
DHOOKS.NEW
< prev
next >
Wrap
Text File
|
1992-04-09
|
6KB
|
233 lines
{ Include file for the demo programs in PAvatar. }
{ These are the video and user hook routines }
{ if the compiler directive AVT0 is set then it }
{ will compile to be compatible with the PAvt0 }
{ unit. Otherwise PAvt1 is assumed. }
type
ScreenWord = record
chr : char;
attr : byte;
end;
ScreenPtr = ^Screen;
Screen = Array[1..25,1..80] of ScreenWord;
var
ScrPtr : ScreenPtr; { for direct screen writes }
{$IFDEF VER55}
Function DV_Get_Video_Buffer(vseg:word): word;
begin
if DESQview_version = 0 then DV_Get_Video_Buffer := vseg
else
InLine(
$b4/$fe/ { MOV AH,0FEH DV's get video buffer function }
$cd/$10/ { INT 10H Returns ES:DI of alt buffer }
$8c/$c0); { MOV AX,ES Return video buffer }
end; { DV_Get_Video_Buffer }
{$ELSE}
Function DV_Get_Video_Buffer(vseg:word): word; assembler;
asm { Modified by Scott Samet April 1st, 1992 }
CALL DESQview_version { Returns AX=0 if not in DV }
MOV ES,vseg { Put current segment into ES }
TEST AX,AX { In DV? }
JZ @DVGVB_X { Jump if not }
MOV AH,0FEH { DV's get video buffer function }
INT 10H { Returns ES:DI of alt buffer }
@DVGVB_X:
MOV AX,ES { Return video buffer }
end; { DV_Get_Video_Buffer }
{$ENDIF}
Procedure SetScrPtr;
var
sg : word;
begin
if LastMode = 7 then sg := $B000
else sg := $B800;
sg := DV_Get_Video_Buffer(sg);
ScrPtr := Ptr(sg,$0000);
end;
(* Hooks *)
procedure FillWord(var x; count:integer; w:word);
begin
Inline(
$c4/$be/x/
$8b/$86/w/
$8b/$8e/count/
$fc/
$f2/$ab);
(* LES DI,x { load target address }
MOV AX,w { load word to fill in }
MOV CX,count { number of words to move }
CLD { clear direction flag }
REPNZ STOSW { copy the data } *)
end;
procedure MoveW(var Source, Dest; count:integer); assembler;
asm
MOV DX,DS { Save DS }
LES DI,Dest { Load destination ptr }
LDS SI,Source { load source ptr }
MOV CX,Count { load # of words to move }
CLD
CMP SI,DI { are they overlapping? }
JNB @move { no, do foward }
MOV BX,CX { yes, do backward }
SHL BX,1 { count to bytes }
DEC BX { prep for addition }
DEC BX
ADD SI,BX { set them to end of area to move }
ADD DI,BX
STD { other direction }
@move:
REP MOVSW { move 'em }
MOV DS,DX { restore DS }
end;
procedure GetXY(var x,y:byte);
begin
x := WhereX;
y := WhereY;
end;
{$F+}
procedure SetXY(x,y:byte);
begin
GotoXY(x,y);
end;
procedure WriteAT(x,y,a:byte;ch:char);
begin
with ScrPtr^[y,x] do
begin
attr := a;
chr := ch;
end;
end;
procedure FillArea(x1,y1,x2,y2,a:byte;ch:char);
var
sw : screenword;
w : byte;
begin
if x1 > x2 then x1 := x2;
if y1 > y2 then y1 := y2;
sw.chr := ch;
sw.attr := a;
w := succ(x2-x1);
for y1 := y1 to y2 do
FillWord(ScrPtr^[y1,x1],w,word(sw));
end;
procedure Scroll(dir,x1,y1,x2,y2,n,a:byte);
var
t : byte;
begin
if x1 > x2 then x1 := x2;
if y1 > y2 then y1 := y2;
if n = 0 then
begin
FillArea(x1,y1,x2,y2,a,' ');
exit;
end;
case dir of
1 : begin { up }
if n > succ(y2-y1) then n := succ(y2-y1);
for t := y1+n to y2 do
MoveW(ScrPtr^[t,x1], ScrPtr^[t-n,x1], succ(x2-x1)); { move a line }
FillArea(x1,succ(y2-n),x2,y2,a,' ');
end;
2 : begin { down }
if n > succ(y2-y1) then n := succ(y2-y1);
for t := y2-n downto y1 do
MoveW(ScrPtr^[t,x1], ScrPtr^[t+n,x1], succ(x2-x1)); { move a line }
FillArea(x1,y1,x2,pred(y1+n),a,' ');
end;
3 : begin { left }
if n > succ(x2-x1) then n := succ(x2-x1);
for t := y1 to y2 do
MoveW(ScrPtr^[t,x1+n], ScrPtr^[t,x1], succ(x2-(x1+n)));
FillArea(succ(x2-n),y1,x2,y2,a,' ');
end;
4 : begin { right }
if n > succ(x2-x1) then n := succ(x2-x1);
for t := y1 to y2 do
MoveW(ScrPtr^[t,x1], ScrPtr^[t,x1+n], succ(x2-(x1+n)));
FillArea(x1,y1,pred(x1+n),y2,a,' ');
end;
end; { case dir }
end;
procedure GetScrChar(x,y:byte;var a:byte;var c:char);
begin
with ScrPtr^[y,x] do
begin
a := attr;
c := chr;
end;
end;
procedure HighArea(x1,y1,x2,y2,a:byte);
var
i,j,m : byte;
c : char;
begin
if x1 > x2 then x1 := x2;
if y1 > y2 then y1 := y2;
for i := x1 to x2 do
for j := y1 to y2 do
begin
GetScrChar(i,j,m,c);
WriteAT(i,j,a,c);
end;
end;
procedure Pause(tens:word);
begin
for tens := tens downto 1 do
begin
delay(100); { note that delay usually isn't accurate }
if KeyPressed then tens := 1; { abort the pause }
end;
end;
Procedure ShapeCursor(typ:byte);
procedure SetCursor(shape:word);
begin
Inline($b4/$01/ { MOV AH, 01 }
$8b/$8e/shape/ { MOV CX, shape }
$cd/$10); { INT 10h }
end;
begin
case typ of
NormCursor : SetCursor(Def_Cursor);
BigCursor : if lo(Def_Cursor) > 7 then SetCursor($000e)
else SetCursor($0007);
HiddenCursor : SetCursor($0100);
end;
end;
{$F-}
(* End Hook Definitions *)
procedure SetHooks;
begin
{ Query_Hook := <defualt null hook for this application> }
Pauseh := Pause;
HighAreah := HighArea;
GetATh := GetScrChar;
FillAreah := FillArea;
Scrollh := Scroll;
GotoXYh := SetXY;
WriteATh := WriteAT;
{ FlushInputh := <Defualt Zero keyboard buffer hook is fine> }
Cursorh := ShapeCursor;
end;