home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / Pascal / ANSIDRVR.ZIP / DEMOCOM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-05-03  |  4.6 KB  |  254 lines

  1. {
  2. Turbo Pascal ANSI Drivers
  3. Version 1.12
  4. Copyright (c) 1990 by Not So Serious Software
  5.  
  6. Original concept by Ian Silver
  7. Design and implementation by Kevin Dean
  8.  
  9. Kevin Dean
  10. Fairview Mall P.O. Box 55074
  11. 1800 Sheppard Avenue East
  12. Willowdale, Ontario
  13. CANADA    M2J 5B9
  14. CompuServe ID: 76336,3114
  15. }
  16.  
  17.  
  18. { This program demonstrates simple text I/O using the ANSICOM communications unit }
  19. program DemoCOM;
  20.  
  21.  
  22. uses
  23.   ANSI, ANSICOM;
  24.  
  25.  
  26. var
  27.   Result : integer;
  28.   Name : string[20];
  29.   BoxColor, DataColor, BkgndColor : byte;
  30.  
  31.  
  32. {***}
  33. procedure UpdateCursorPos;
  34.  
  35. var
  36.   CurX, CurY, OldAttr : byte;
  37.  
  38. begin
  39. CurX := WhereX;
  40. CurY := WhereY;
  41. OldAttr := TextAttr;
  42.  
  43. TextAttr := DataColor;
  44. GotoXY(50, 13);
  45. Write('(', CurX : 2, ',', CurY : 2, ')');
  46.  
  47. TextAttr := OldAttr;
  48. GotoXY(CurX, CurY)
  49. end;
  50.  
  51.  
  52. {***}
  53. procedure DrawBox;
  54.  
  55. var
  56.   I : byte;
  57.  
  58. begin
  59. TextAttr := BoxColor;
  60.  
  61. GotoXY(23, 9);
  62. UpdateCursorPos;
  63. Write('╔');
  64.  
  65. for I := 24 to 57 do
  66.   begin
  67.   UpdateCursorPos;
  68.   Write('═')
  69.   end;
  70.  
  71. UpdateCursorPos;
  72. Write('╗');
  73.  
  74. for I := 10 to 15 do
  75.   begin
  76.   GotoXY(58, I);
  77.   UpdateCursorPos;
  78.   Write('║')
  79.   end;
  80.  
  81. GotoXY(58, 16);
  82. UpdateCursorPos;
  83. Write('╝');
  84.  
  85. for I := 57 downto 24 do
  86.   begin
  87.   GotoXY(I, 16);
  88.   UpdateCursorPos;
  89.   Write('═')
  90.   end;
  91.  
  92. GotoXY(23, 16);
  93. UpdateCursorPos;
  94. Write('╚');
  95.  
  96. for I := 15 downto 10 do
  97.   begin
  98.   GotoXY(23, I);
  99.   UpdateCursorPos;
  100.   Write('║')
  101.   end
  102. end;
  103.  
  104.  
  105. {***}
  106. procedure RunDemo;
  107.  
  108. begin
  109. Randomize;
  110.  
  111. repeat
  112.   BoxColor := Random(256);
  113.  
  114.   DrawBox;
  115.  
  116.   DataColor := Random(256);
  117.   BkgndColor := Random(256);
  118.  
  119.   TextAttr := BkgndColor;
  120.   GotoXY(24, 10);
  121.   UpdateCursorPos;
  122.   Write(' Your name:                       ');
  123.   UpdateCursorPos;
  124.  
  125.   TextAttr := DataColor;
  126.   GotoXY(36, 10);
  127.   UpdateCursorPos;
  128.   Write(Name);
  129.   UpdateCursorPos;
  130.  
  131.   TextAttr := BkgndColor;
  132.   GotoXY(24, 11);
  133.   UpdateCursorPos;
  134.   Write(' Box color:       Data color:     ');
  135.   UpdateCursorPos;
  136.  
  137.   TextAttr := DataColor;
  138.   GotoXY(36, 11);
  139.   UpdateCursorPos;
  140.   Write(BoxColor : 3);
  141.   UpdateCursorPos;
  142.   GotoXY(54, 11);
  143.   UpdateCursorPos;
  144.   Write(DataColor : 3);
  145.   UpdateCursorPos;
  146.  
  147.   TextAttr := BkgndColor;
  148.   GotoXY(24, 12);
  149.   UpdateCursorPos;
  150.   Write(' Background color:                ');
  151.   UpdateCursorPos;
  152.  
  153.   TextAttr := DataColor;
  154.   GotoXY(43, 12);
  155.   UpdateCursorPos;
  156.   Write(BkgndColor : 3);
  157.   UpdateCursorPos;
  158.  
  159.   TextAttr := BkgndColor;
  160.   GotoXY(24, 13);
  161.   UpdateCursorPos;
  162.   Write(' Current cursor position:         ');
  163.   UpdateCursorPos;
  164.  
  165.   TextAttr := BkgndColor;
  166.   GotoXY(24, 14);
  167.   UpdateCursorPos;
  168.   Write('                                  ');
  169.   UpdateCursorPos;
  170.  
  171.   TextAttr := BkgndColor;
  172.   GotoXY(24, 15);
  173.   UpdateCursorPos;
  174.   Write(' Press any key to end demo.       ');
  175.   UpdateCursorPos;
  176.  
  177.   Delay(250)
  178. until KeyPressed
  179. end;
  180.  
  181.  
  182. {$F+}
  183.  
  184. {***}
  185. { Modem error handler - MUST BE COMPILED AS A FAR PROCEDURE }
  186. procedure ModemError(var Error : word);
  187.  
  188. var
  189.   ConF : text;
  190.  
  191. begin
  192. { Console is taken over by the communications routines so have to reopen it }
  193. Assign(ConF, 'CON');
  194. Rewrite(ConF);
  195.  
  196. if Error and ReceiveOverrun <> 0 then
  197.   WriteLn(ConF, 'Error : Receive overrun');
  198.  
  199. if Error and TransmitOverrun <> 0 then
  200.   WriteLn(ConF, 'Error : Transmit overrun');
  201.  
  202. if Error and ParityError <> 0 then
  203.   WriteLn(ConF, 'Error : Parity error');
  204.  
  205. if Error and FramingError <> 0 then
  206.   WriteLn(ConF, 'Error : Framing error');
  207.  
  208. if Error and BreakDetect <> 0 then
  209.   WriteLn(ConF, 'Error : Break detect');
  210.  
  211. if Error and CommTimeOut <> 0 then
  212.   WriteLn(ConF, 'Error : Modem time out');
  213.  
  214. if Error and NoCarrier <> 0 then
  215.   WriteLn(ConF, 'Error : No carrier');
  216.  
  217. if Error and CtrlBreak <> 0 then
  218.   WriteLn(ConF, 'Error : Ctrl-Break');
  219.  
  220. if Error and NotOnline <> 0 then
  221.   WriteLn(ConF, 'Error : Not on-line');
  222.  
  223. Close(ConF);
  224.  
  225. Disconnect;
  226. ReleaseCOM;
  227. halt(1)
  228. end;
  229.  
  230. {$F-}
  231.  
  232.  
  233. {***}
  234. begin
  235. Result := InitCOM(4, 9600, 8, 'N', 1, Init, SyncTransmit, @ModemError);
  236.  
  237. { It is very important to make an explicit call to either GotoXY or ClrScr at }
  238. { the start of your program.  If you do not do so, the internal cursor        }
  239. { position management will be unpredictable.                                  }
  240. ClrScr;
  241.  
  242. WriteLn('This program demonstrates simple I/O using the ANSI and ANSI');
  243. WriteLn('communications units.  Among the features demonstrated are screen');
  244. WriteLn('control, cursor control, text attribute control, input and output,');
  245. WriteLn('and the delay counter.');
  246. WriteLn;
  247. Write('What is your name (maximum 20 characters)? ');
  248. ReadLn(Name);
  249.  
  250. RunDemo;
  251.  
  252. { ALWAYS MAKE SURE THAT YOU RELEASE THE COMMUNICATIONS PORT BEFORE EXITING }
  253. ReleaseCOM
  254. end.