home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / spxdos.exe / SCREEN.C < prev    next >
Text File  |  1995-01-27  |  6KB  |  312 lines

  1. /****************************************************************************
  2. **    File:    Screen.C    
  3. **
  4. **    Desc:    Sample SPX chat program.    
  5. **
  6. **            This Sample code demonstrates how to set up and use SPX
  7. **            communications to communicate between 2 nodes.
  8. **        
  9. **        
  10. **        
  11. **
  12. **        DISCLAIMER  
  13. **  
  14. **    Novell, Inc. makes no representations or warranties with respect to
  15. **    any NetWare software, and specifically disclaims any express or
  16. **    implied warranties of merchantability, title, or fitness for a
  17. **    particular purpose.  
  18. **
  19. **    Distribution of any NetWare software is forbidden without the
  20. **    express written consent of Novell, Inc.  Further, Novell reserves
  21. **    the right to discontinue distribution of any NetWare software.
  22. **    
  23. **    Novell is not responsible for lost profits or revenue, loss of use
  24. **    of the software, loss of data, costs of re-creating lost data, the
  25. **    cost of any substitute equipment or program, or claims by any party
  26. **    other than you.  Novell strongly recommends a backup be made before
  27. **    any software is installed.   Technical support for this software
  28. **    may be provided at the discretion of Novell.
  29. **
  30. **    Programmers:
  31. **
  32. **        Ini    Who                        Firm
  33. **        -----------------------------------------------------------------------
  34. **        TDOC  Technical Documentation Team
  35. **        KLB    Karl Bunnell                Novell Developer Support.
  36. **
  37. **    History:
  38. **
  39. **        When        Who    What
  40. **        -----------------------------------------------------------------------
  41. **        10-25-88    TDOC    First code.
  42. **        01-27-95 KLB   Ported this example to the NetWare Client SDK
  43. */
  44.  
  45. /****************************************************************************
  46. **    Include headers, macros, function prototypes, etc.
  47. */
  48.  
  49.     /*------------------------------------------------------------------------
  50.     **    ANSI
  51.     */
  52.     #include <stdio.h>
  53.     #include <dos.h>
  54.  
  55.  
  56.     /*------------------------------------------------------------------------
  57.     **    NetWare
  58.     */
  59.     #include <nwcalls.h>
  60.     #include "chat.h"
  61.  
  62.     /*------------------------------------------------------------------------
  63.     **    GLOBALS
  64.     */
  65.  
  66.  
  67.     void     ClearEndOfLine();
  68.     void     ClearReceiveBox();
  69.     void     ClearScreen();
  70.     void     ClearSendBox();
  71.     void     CursorOff();
  72.     void     CursorOn(); 
  73.     void     DisplayHeadings();
  74.     void     DrawBorder();
  75.     void     DrawScreen();
  76.     void     Error();
  77.     void     ScrollUp();
  78.     void     SetCursor();
  79.     void     Update();
  80.     void     WriteChar();
  81.  
  82.     extern int  sendRow,
  83.                 sendCol,
  84.                 receiveRow,
  85.                 receiveCol;
  86.  
  87.     union    REGS  regs;
  88.  
  89.  
  90. void DrawScreen()
  91. {
  92.     ClearScreen();
  93.     DrawBorder();
  94.     DisplayHeadings();
  95. }
  96.  
  97.  
  98. void DrawBorder()
  99. {
  100.     int        row,
  101.             col;
  102.  
  103.     CursorOff();
  104.  
  105.     for (row = TOP; row <= BOTTOM; row++)
  106.     {
  107.         for (col = LEFT_SIDE; col <= RIGHT_SIDE; col++)
  108.         {
  109.             SetCursor(row,col);
  110.                 
  111.          /* Check for top, bottom, or middle */
  112.             if (row == TOP)
  113.             {
  114.                 if (col == LEFT_SIDE) 
  115.                     WriteChar(UPPER_LEFT);                            
  116.                 else if (col == RIGHT_SIDE)
  117.                     WriteChar(UPPER_RIGHT);
  118.                 else
  119.                     WriteChar(HORIZONTAL);
  120.             }
  121.             else if (row == BOTTOM)
  122.             {
  123.                 if (col == LEFT_SIDE)
  124.                     WriteChar(LOWER_LEFT);
  125.                 else if (col == RIGHT_SIDE)
  126.                     WriteChar(LOWER_RIGHT);
  127.                 else
  128.                     WriteChar(HORIZONTAL);
  129.             }
  130.             else if (row == MID_SCREEN)
  131.             {
  132.                 if (col == LEFT_SIDE)
  133.                     WriteChar(L_INTERSECT);
  134.                 else if (col == RIGHT_SIDE)
  135.                     WriteChar(R_INTERSECT);                        
  136.                 else 
  137.                     WriteChar(HORIZONTAL);                            
  138.             }
  139.  
  140.           /* Check for sides */
  141.             else if ( (col == LEFT_SIDE) || (col == RIGHT_SIDE) )
  142.                 WriteChar(VERTICAL);                            
  143.         }            
  144.     }
  145.     CursorOn();
  146. }
  147.  
  148.  
  149. void DisplayHeadings()
  150. {
  151.     CursorOff();
  152.  
  153.     SetCursor(1,2);
  154.     printf("RECEIVING");
  155.  
  156.     SetCursor(11,2);
  157.     printf("SENDING");
  158.  
  159.     SetCursor(22,6);
  160.     printf("ENTER = Return   BACKSPACE = Delete   TAB = Clear box   ESCAPE = Quit");
  161.  
  162.     SetCursor(13,2);
  163.     CursorOn();
  164. }
  165.  
  166.  
  167. void Update(string)
  168. char    *string;
  169. {
  170.     int        cursorRow, cursorCol;
  171.  
  172.     CursorOff();
  173.     SetCursor (24,1);
  174.     printf ("System Message: %s",string);
  175.     GetCursor (&cursorRow, &cursorCol);
  176.     ClearEndOfLine (24, cursorCol);
  177.     SetCursor (sendRow,sendCol);
  178.     CursorOn();
  179. }
  180.  
  181. void Error(text)
  182. char    *text;
  183. {
  184.     ClearScreen();
  185.     printf("%s",text);
  186.     Exit();
  187. }
  188.  
  189.  
  190. void ClearScreen()
  191. {
  192.     ScrollUp(0,0,24,0,79);
  193. }
  194.  
  195.  
  196. void ClearSendBox()
  197. {
  198.     int lines = 7,
  199.         topRow = 13,
  200.         bottomRow = 19,
  201.         leftCol = 1,
  202.         rightCol = 78;
  203.     
  204.     ScrollUp(lines,topRow,bottomRow,leftCol,rightCol);
  205.  
  206.     sendRow = TOP_SEND_ROW;
  207.     sendCol = FIRST_TEXT_COL;
  208.     SetCursor(sendRow,sendCol);
  209. }
  210.  
  211.  
  212. void ClearReceiveBox()
  213. {
  214.     int lines = 7, topRow = 3, bottomRow = 9, leftCol = 1, rightCol = 78;
  215.     
  216.     ScrollUp (lines, topRow, bottomRow, leftCol, rightCol);
  217.     CursorOff();
  218.  
  219.     receiveRow = TOP_RECEIVE_ROW;
  220.     receiveCol = FIRST_TEXT_COL;
  221.     SetCursor(sendRow, sendCol);
  222.     CursorOn();
  223. }
  224.  
  225.  
  226. void ClearEndOfLine (line, cursor)
  227. int        line, cursor;
  228. {
  229.      ScrollUp (1, line, line, cursor, 79);
  230. }
  231.  
  232.  
  233. void WriteChar(ch)
  234. char    ch;
  235. {
  236.     regs.h.ah = 0x09;
  237.     regs.h.al = ch;
  238.     regs.h.bl = 0x07;
  239.     regs.h.bh = 0;
  240.     regs.h.ch = 0;
  241.     regs.h.cl = 1;
  242.  
  243.     int86(VIDEO, ®s, ®s);
  244. }
  245.  
  246.  
  247. void ScrollUp (lines, topRow, bottomRow, leftCol, rightCol)
  248. int    lines, topRow, bottomRow, leftCol, rightCol;
  249. {
  250.     regs.h.ah = SCROLL_UP;
  251.     regs.h.al = lines;
  252.     regs.h.ch = topRow;
  253.     regs.h.cl = leftCol;
  254.     regs.h.dh = bottomRow;
  255.     regs.h.dl = rightCol;
  256.     regs.h.bh = 0x07;
  257.  
  258.     int86(VIDEO, ®s, ®s);
  259. }
  260.  
  261.  
  262. void SetCursor(r,c)
  263. int register    c,
  264.                 r;
  265. {
  266.     union REGS regs;
  267.  
  268.     regs.h.ah = SET_CURSOR;
  269.     regs.h.dl = c;
  270.     regs.h.dh = r;
  271.     regs.h.bh = 0;
  272.  
  273.     int86(VIDEO, ®s, ®s);
  274. }
  275.  
  276. void CursorOn() 
  277. {
  278.     int        start = 12; /* top line of cursor    */
  279.     int        end = 13;   /* bottom line of cursor */
  280.  
  281.     regs.h.ch = start;
  282.     regs.h.cl = end;
  283.     regs.h.ah = CURSOR_SIZE;
  284.  
  285.     int86(VIDEO, ®s, ®s);
  286. }
  287.  
  288.  
  289. void CursorOff()
  290. {
  291.     regs.h.ch = STOPBIT;
  292.     regs.h.ah = CURSOR_SIZE;
  293.     int86(VIDEO, ®s, ®s);
  294. }
  295.  
  296.  
  297. GetCursor (cursorRow, cursorCol)
  298. int     *cursorRow, *cursorCol;
  299. {
  300.     union REGS regs;
  301.  
  302.     regs.h.ah = 3;
  303.     regs.h.bh = 0;
  304.      int86(VIDEO, ®s, ®s);
  305.  
  306.     *cursorCol = regs.h.dl;
  307.     *cursorRow = regs.h.dh;
  308. }
  309.  
  310.  
  311.  
  312.