home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / pascal / 7472 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  5.0 KB

  1. Path: sparky!uunet!pipex!unipalm!uknet!comlab.ox.ac.uk!oxuniv!speedy
  2. From: speedy@vax.oxford.ac.uk
  3. Newsgroups: comp.lang.pascal
  4. Subject: TVISION and Interrupts. Is it safe?
  5. Message-ID: <1992Dec14.210207.10760@vax.oxford.ac.uk>
  6. Date: 14 Dec 92 21:02:07 GMT
  7. Organization: Oxford University VAX 6620
  8. Lines: 255
  9.  
  10. Interrupts and Turbo Vision
  11. ===========================
  12.  
  13. See source below...
  14.  
  15.  
  16. Is this sort of thing safe. It certainly used to work in 
  17. Turbo Pascal 6 - but does not now seem to work in BP7. It 
  18. actually seems to work on a 486 but not on a 286 or 386 which 
  19. makes me think that there must be some sort of re-entry. 
  20. In certain circumstances it seems to utterly lock up the 
  21. computer (big red button time :-( ) Does turbo vision re-enable
  22. interrupts? Or is it just not a safe thing to do with 
  23. TVISION? In the instance were I am using it - overlays
  24. are being used in some parts of the program - however
  25. Objects,Drivers,Views,App and DOS are not overlaid.
  26. Initwaitbox is called in the main applications constructor.
  27.  
  28. Thank you for any help!
  29.  
  30.  
  31.  
  32. unit WaitBox; 
  33.  
  34.       {*********************************************************************}
  35.       {   Source File: WAITBOX.pas                                          }
  36.       {   Description: Implements a wait box with moving dot on the screen  }
  37.       {   Date       : Sat Dec 12 14:44:07 1992                             }
  38.       {   Copyright  : (C) N.Waltham 1992                        }
  39.       {*********************************************************************}
  40.  
  41. {$O-} {$F+} {$S-}
  42.  
  43. interface
  44.  
  45. function WaitOn(aTitle : String) : integer;
  46. function WaitOff : integer;
  47. procedure InitWaitBox;
  48.  
  49.  
  50. implementation
  51.  
  52. Uses
  53.  Objects,Drivers,Views,App,Dos;
  54.  
  55.  
  56.  
  57. type
  58.  PWaitView  = ^TWaitView;
  59.  TWaitView  = Object(TView)
  60.  
  61.               TickPosn    :  Integer;
  62.               TextPos     :  TPoint;
  63.               TextIs      :  String[20];
  64.               TickStart   :  TPoint;
  65.  
  66.               constructor init(var Bounds :  TRect);
  67.               procedure   TickOn;
  68.               procedure   Draw; virtual;
  69.  
  70.               end;
  71.  
  72.  
  73.  PWaitWindow = ^TWaitWindow;
  74.  TWaitWindow = Object(TWindow)
  75.  
  76.                WaitView   :  PWaitView;
  77.  
  78.                constructor init(var Bounds : TRect; aTitle : TTitleStr);
  79.                procedure   TickOn;
  80.  
  81.                end;
  82.  
  83. var
  84.  Temp_Stack : array [0..16384] of byte;
  85.  Wait_Box   : PWaitWindow;
  86.  OldTimer   : pointer;
  87.  OldExit    : pointer;
  88.  TickCount  : longint;
  89.  old_ss     : word;
  90.  old_sp     : word;
  91.  
  92.  
  93. procedure GrabTimer; forward;
  94. procedure ReleaseTimer; forward;
  95. procedure ProcessTimer(Flags, CS,
  96.           IP, AX, BX,CX, DX, SI, DI, DS, ES, BP: Word); interrupt; forward;
  97. procedure ExitWaitBox; far; forward;
  98. procedure TickOn; forward;
  99.  
  100. procedure intoff; inline($FA); {CLI}
  101. procedure inton; inline($FB); {STI}
  102.  
  103.  
  104. {----------Objects-----------------}
  105.  
  106. constructor TWaitView.Init;
  107.  
  108.  
  109. var
  110.  R       : TRect;
  111.  
  112. begin
  113. TView.Init(Bounds);
  114. GetExtent(R);
  115. TickPosn:=0;
  116. TickStart.X:=((R.B.X-R.A.X) DIV 2 -3);
  117. TickStart.Y:=R.B.Y-2;
  118. TextIs:='Please Wait';
  119. TextPos.Y:=R.A.Y+1;
  120. TextPos.X:=((R.B.X-R.A.X) DIV 2) - (byte(TextIs[0]) DIV 2)
  121. end;
  122.  
  123. procedure TWaitView.Draw;
  124.  
  125. begin
  126. Owner^.Lock;
  127. TView.Draw;
  128. WriteStr(TextPos.X,TextPos.Y,TextIs,1);
  129. WriteChar(TickStart.X,TickStart.Y,'-',3,6);
  130. WriteChar(TickStart.X+TickPosn,TickStart.Y,'*',3,1);
  131. Owner^.UnLock;
  132. end;
  133.  
  134. procedure TWaitView.TickOn;
  135.  
  136. begin
  137.  Inc(TickPosn);
  138.  If TickPosn=6 then TickPosn:=0;
  139.  DrawView;
  140. end;
  141.  
  142.  
  143. constructor TWaitWindow.Init;
  144.  
  145. var
  146.  R : TRect;
  147.  
  148. begin
  149.  TWindow.Init(Bounds,aTitle,wnNoNumber);
  150.  Options:=(Options or ofCentered) AND NOT (ofSelectable);
  151.  Flags:=0;
  152.  GetExtent(R);
  153.  R.Grow(-1,-1);
  154.  WaitView:=New(PWaitView,Init(R));
  155.  Insert(WaitView);
  156. end;
  157.  
  158. procedure TWaitWindow.TickOn;
  159.  
  160. begin
  161.  WaitView^.TickOn;
  162. end;
  163.  
  164. procedure GrabTimer;
  165.  
  166. begin
  167.  GetIntVec($1C,OldTimer);
  168.  SetIntVec($1C,@ProcessTimer);
  169. end;
  170.  
  171. procedure ReleaseTimer;
  172.  
  173. begin
  174.  SetIntVec($1C,OldTimer);
  175. end;
  176.  
  177. procedure ProcessTimer;
  178.  
  179. begin
  180. asm {----Switch to temporary Stack so no unexpeceted stack overflows----}
  181.  pushf {Push extra set of flags onto stack to iret comes back here}
  182.  call dword ptr ds:[OldTimer];
  183.  cli
  184.  mov word ptr ds:[old_ss],ss;
  185.  mov word ptr ds:[old_sp],sp;
  186.  mov ax,ds;
  187.  mov ss,ax;
  188.  mov sp,offset temp_stack+16384;
  189. end;
  190. TickOn;
  191. asm {Restore original stack & jump to next hook}
  192.  mov ss,ds:[old_ss];
  193.  mov sp,ds:[old_sp];
  194.  end;
  195. end;
  196.  
  197. procedure TickOn;
  198.  
  199. begin
  200. If Wait_Box=nil then exit;
  201. Inc(TickCount);
  202. If TickCount=2 then
  203.  begin
  204.  TickCount:=0;
  205.  Wait_Box^.TickOn;
  206.  end;
  207. end;
  208.  
  209. procedure ExitWaitBox;
  210.  
  211. begin
  212.  ReleaseTimer;
  213.  ExitProc:=OldExit;
  214. end;
  215.  
  216. function WaitOn;
  217.  
  218. var
  219.  R : TRect;
  220.  TWait : PWaitWindow;
  221.  
  222. begin
  223. intoff;
  224. If Wait_Box<>nil then
  225.  begin
  226.  WaitOn:=-1;
  227.  Exit;
  228.  end;
  229. R.Assign(1,5,14+byte(aTitle[0]),11);
  230. TWait:=New(PWaitWindow,Init(R,aTitle));
  231. DeskTop^.Insert(Twait);
  232. Wait_Box:=TWait;
  233. inton;
  234. end;
  235.  
  236. function Waitoff;
  237.  
  238. var
  239.  TWait : PWaitWindow;
  240.  
  241.  
  242. begin
  243. intoff;
  244. TWait:=Wait_Box;
  245. Wait_Box:=nil;
  246. DeskTop^.Delete(TWait);
  247. Dispose(TWait,Done);
  248. Waitoff:=0;
  249. inton;
  250. end;
  251.  
  252. procedure InitWaitBox;
  253.  
  254. begin
  255.  {exit;}
  256.  Wait_Box:=nil;
  257.  TickCount:=0;
  258.  OldExit:=ExitProc;
  259.  ExitProc:=@ExitWaitBox;
  260.  GrabTimer;
  261. end;
  262.  
  263.  
  264. end.
  265.