home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / PASCAL / PAVT199 / PAVTIO.PAS < prev    next >
Pascal/Delphi Source File  |  1994-03-05  |  8KB  |  197 lines

  1. (*******************************************************************)
  2. (*  Avatar level 1 Console driver.  Unit for providing a program   *)
  3. (*  with proper Avatar levels 0, 0+, and 1 emulations.             *)
  4. (*  Copyright (c) 1991 - 93 Gregory P. Smith                       *)
  5. (*  All Rights Reserved                                            *)
  6. (*-----------------------------------------------------------------*)
  7. (*  Last Update:   March  4, 1994     v 1.53                       *)
  8. (*====================================******************************)
  9. (* PAvatar Hook I/O interface         *)
  10. (**************************************)
  11.  
  12. Unit PAvtIO;
  13. {$I PAVTVER.INC -- Checks compiler version and defines }
  14. {$F-,O-  This unit shouldn't be overlayed }
  15.  
  16. INTERFACE
  17.  
  18. Uses Dos, Crt;
  19.  
  20. {-- public type declarations ---------------------------------------}
  21. type
  22.   AvatarInterpProc = Procedure (ch:char);     { interpreter procedure type }
  23.   ReplyProc = Procedure (S:String);                           { Query Hook }
  24.   WriteATHookT = Procedure (x,y,a:byte;ch:char);   { for writing to screen }
  25.   GotoXYHookT = Procedure (x,y:byte);                  { for moving cursor }
  26.   ScrollHookT = Procedure (dir,x1,y1,x2,y2,n,a:byte);          { Scrolling }
  27.               { dir: 1=up,2=down,3=left,4=right. n=# 2 scroll,a=new attrib }
  28.   FillHookT = Procedure (x1,y1,x2,y2,a:byte;ch:char);    { filling an area }
  29.   GetCharHookT = Procedure (x,y:byte;var a:byte;var c:char); { screen data }
  30.   HighHookT = Procedure (x1,y1,x2,y2,a:byte);   { for highlighting an area }
  31.   PauseHookT = Procedure (tenths:word);         { 10ths of second to pause }
  32.   CursorHookT = Procedure (style:byte);             { set the cursor style }
  33. {$IFDEF TTY_HOOK}
  34.   TTYChHookT = Function (ch:char;a:byte): boolean; { called from TTY procs }
  35. {$ENDIF}
  36.   TerminalType = (TermTTY,    { TTY: no terminal emulation }
  37.                   TermANSI,   { ANSI: extended ANSI terminal }
  38.                   TermAVT0,   { AVT/0+: extended level 0+ emulation }
  39.                   TermAVT1    { AVT/1: full level 1 emulation }
  40.    {$IFDEF VT52} ,TermVT52    { VT-52: Standard VT-52 emulation } {$ENDIF}
  41.   {$IFDEF VT102} ,TermVT102   { VT-102: Standard VT-102 emulation } {$ENDIF}
  42.                  );
  43.  
  44. {-- public constants ----------------------------------------------}
  45. const
  46. {-- runtime -------------}
  47.   CurrentTerm : TerminalType = TermAVT1; { Current Terminal }
  48.   ScrnLines   : byte = 25;       { lines on a terminal screen }
  49.   ScrnColumns : byte = 80;       { columns on a terminal screen }
  50.   Sound_Stat  : byte = 03;       { Sound: bit0=bell,bit1=Sound }
  51. {$IFDEF VT52}
  52.   VT52On      : boolean = False; { Use VT-52 codes }
  53. {$ENDIF}
  54. {$IFDEF VT102}
  55.   VT102On     : boolean = False; { Use VT-102 style implementations }
  56. {$ENDIF}
  57.   IgnoreNULL  : boolean = False; { TTY ignore the #0 character? (VT52) }
  58.   ANSI_BBS    : boolean = True;  { Use BBS Style ANSI? }
  59.   ANSI_MUSIC  : boolean = True;  { Allow "ANSI" music? }
  60.   Dest_BS     : boolean = True;  { Destructive backspace? (AVT/1 default) }
  61.   Fallback    : boolean = False; { ANSI fallback enabled }
  62.  
  63.   In_DV       : boolean = False; { Are we in DESQview? }
  64. {$IFDEF VT102}
  65.   CRtoCRLF    : boolean = False; { CR/LF sent when CR is pressed? }
  66. {$ENDIF}
  67.   QueryReply : string[80] =      { AVT/1 ^V^Q^Q response }
  68.                'AVT1, PAvatar 1.55 Copr. 1991-93 Gregory P. Smith'+^M;
  69. {-- compiletime ---------}
  70.   Esc = ^[;
  71.   DLE = ^P;
  72.   FS = #28;
  73.   GS = #29;
  74.   RS = #30;
  75.   US = #31;
  76.   SP = #32;  { space }
  77.   None = 0;          {  \               }
  78.   ZigZag = 1;        {   > Wrap Types   }  { for ORing with WCFLf }
  79.   ClockWise = 2;     {  /               }
  80.   NoWrap = 3;        { /                }
  81.   NormCursor = 4;    { \                }
  82.   BigCursor = 8;     {  > Cursor Styles }
  83.   HiddenCursor = 12; { /                }
  84. {$IFNDEF DPMI}
  85.   Seg0040 = $0040;   { BIOS data segment }
  86. {$ENDIF}
  87.  
  88. {-- public variables ----------------------------------------------}
  89. var
  90.   AVTInterp   : AvatarInterpProc; { Next interpretation stage      }
  91.   Query_Hook  : ReplyProc;    { processes Query Replys             }
  92.   WriteATh    : WriteATHookT; { \                                  }
  93.   GotoXYh     : GotoXYHookT;  {  \                                 }
  94.   Scrollh     : ScrollHookT;  {   > Hooks for screen manipulation  }
  95.   FillAreah   : FillHookT;    {  /                                 }
  96.   GetATh      : GetCharHookT; { /                                  }
  97.   HighAreah   : HighHookT;    {/                                   }
  98.   Pauseh      : PauseHookT;   { for system pause calls             }
  99.   Cursorh     : CursorHookT;  { for setting the cursor style       }
  100.   FlushInputh : Procedure;    { flush keyboard and local buffers   }
  101. {$IFDEF TTY_HOOK}
  102.   TTYCharH    : TTYChHookT;   { called before AvtTTY               }
  103. {$ENDIF}
  104.   Def_Cursor  : word;         { contains default cursor shape      }
  105.  
  106. {-- public procedures ---------------------------------------------}
  107.  
  108. PROCEDURE DESQview_Init;               { initialize the In_DV flag }
  109. FUNCTION  DESQview_Version: word; { return DESQview version number }
  110. PROCEDURE IdlePause;              { give up Multitasker time slice }
  111. FUNCTION  ReadKey: char;      { DESQview aware ReadKey replacement }
  112. PROCEDURE DV_Sound(freq,dur:word);   { Create sound under DESQview }
  113. PROCEDURE DelayTicks(t:word);            { Delay for t timer ticks }
  114.  
  115. IMPLEMENTATION
  116.  
  117. {-- Null Hook Definitions -----------------------------------------}
  118.  
  119. {$F+ compatible with TP 5.5 }
  120. Procedure NullReply(s:string); begin end;
  121. Procedure NullWriteAT(x,y,a:byte;c:char); begin end;
  122. Procedure NullGotoXY(x,y:byte); begin end;
  123. Procedure NullScroll(d,x,y,x1,y1,n,a:byte); begin end;
  124. Procedure NullFill(x,y,x1,y1,a:byte;c:char); begin end;
  125. Procedure NullGetChar(x,y:byte;var a:byte;var c:char); begin end;
  126. Procedure NullHigh(x,y,x1,y1,a:byte); begin end;
  127. Procedure NullPause(t:word); begin end;
  128. Procedure NullCursor(s:byte); begin end;
  129.  
  130. Procedure StdFlush;
  131. begin
  132.   MemW[Seg0040:$001A] := MemW[Seg0040:$001C]   { Zero KB buffer }
  133. end;
  134.  
  135. {$IFDEF TTY_HOOK}
  136. Function NullTTY(ch:char;a:byte): boolean;
  137. begin
  138.   NullTTY := True;
  139. end;
  140. {$ENDIF}
  141. {$F-}
  142.  
  143. Procedure Nullify_Hooks;
  144. begin
  145.   Query_Hook  := NullReply;
  146.   WriteATh    := NullWriteAT;
  147.   GotoXYh     := NullGotoXY;
  148.   Scrollh     := NullScroll;
  149.   FillAreah   := NullFill;
  150.   GetATh      := NullGetChar;
  151.   HighAreah   := NullHigh;
  152.   Pauseh      := NullPause;
  153.   Cursorh     := NullCursor;
  154.   FlushInputh := StdFlush;
  155. {$IFDEF TTY_HOOK}
  156.   TTYCharH    := NullTTY;
  157. {$ENDIF}
  158. {$IFDEF VER55}
  159.   Inline($B4/$03/$cd/$10/$89/$0e/def_cursor);   { get default cursor shape }
  160. {$ELSE}
  161.   asm
  162.    mov ah,03
  163.    int 10h
  164.    mov def_cursor,cx
  165.   end;
  166. {$ENDIF}
  167. end;
  168.  
  169. {$I PAVTDESQ.INC -- DESQview awareness module }
  170.  
  171. { Similar to the Crt unit's Delay procedure but will delay for approximately
  172.   t timer ticks (approx 55ms). }
  173. Procedure DelayTicks(t:word);
  174. const               { clock rate is 1,193,180/65536 times a second }
  175.   dticks = 1573040;    { number of ticks every 24 hours }
  176. var
  177.   systimerp : ^longint;
  178.   elapsed,
  179.   start : longint;
  180. begin
  181.   systimerp := Ptr(Seg0040, $006C);
  182.   start := systimerp^;
  183.   elapsed := 0;
  184.   repeat
  185.     if systimerp^ < start then
  186.      elapsed := dticks - (start - systimerp^)  { 24hr wrap around }
  187.     else elapsed := systimerp^ - start;
  188.     IdlePause;  { give up timeslice during a delay }
  189.   until elapsed >= t;
  190. end;
  191.  
  192. {-- Initialization Code ------------------------------------------}
  193.  
  194. BEGIN
  195.   Nullify_Hooks;
  196. END.
  197.