home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / chat / screen.c < prev    next >
C/C++ Source or Header  |  1989-03-22  |  4KB  |  260 lines

  1. /******************************************************************************
  2.  *
  3.  *    Program Name:    TALK_TO.ME 
  4.  *
  5.  *    Filename:    SCREEN.C -- 10/25/88
  6.  *
  7.  *    Purpose:  Draws a user interface
  8.  *
  9.  ******************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <dos.h>
  13. #include "chat.h"
  14.  
  15. void     ClearEndOfLine();
  16. void     ClearReceiveBox();
  17. void     ClearScreen();
  18. void     ClearSendBox();
  19. void     CursorOff();
  20. void     CursorOn(); 
  21. void     DisplayHeadings();
  22. void     DrawBorder();
  23. void     DrawScreen();
  24. void     Error();
  25. void     ScrollUp();
  26. void     SetCursor();
  27. void     Update();
  28. void     WriteChar();
  29.  
  30. extern int  sendRow,
  31.             sendCol,
  32.             receiveRow,
  33.             receiveCol;
  34.  
  35. union    REGS  regs;
  36.  
  37.  
  38. void DrawScreen()
  39. {
  40.     ClearScreen();
  41.     DrawBorder();
  42.     DisplayHeadings();
  43. }
  44.  
  45.  
  46. void DrawBorder()
  47. {
  48.     int        row,
  49.             col;
  50.  
  51.     CursorOff();
  52.  
  53.     for (row = TOP; row <= BOTTOM; row++)
  54.     {
  55.         for (col = LEFT_SIDE; col <= RIGHT_SIDE; col++)
  56.         {
  57.             SetCursor(row,col);
  58.                 
  59.          /* Check for top, bottom, or middle */
  60.             if (row == TOP)
  61.             {
  62.                 if (col == LEFT_SIDE) 
  63.                     WriteChar(UPPER_LEFT);                            
  64.                 else if (col == RIGHT_SIDE)
  65.                     WriteChar(UPPER_RIGHT);
  66.                 else
  67.                     WriteChar(HORIZONTAL);
  68.             }
  69.             else if (row == BOTTOM)
  70.             {
  71.                 if (col == LEFT_SIDE)
  72.                     WriteChar(LOWER_LEFT);
  73.                 else if (col == RIGHT_SIDE)
  74.                     WriteChar(LOWER_RIGHT);
  75.                 else
  76.                     WriteChar(HORIZONTAL);
  77.             }
  78.             else if (row == MID_SCREEN)
  79.             {
  80.                 if (col == LEFT_SIDE)
  81.                     WriteChar(L_INTERSECT);
  82.                 else if (col == RIGHT_SIDE)
  83.                     WriteChar(R_INTERSECT);                        
  84.                 else 
  85.                     WriteChar(HORIZONTAL);                            
  86.             }
  87.  
  88.           /* Check for sides */
  89.             else if ( (col == LEFT_SIDE) || (col == RIGHT_SIDE) )
  90.                 WriteChar(VERTICAL);                            
  91.         }            
  92.     }
  93.     CursorOn();
  94. }
  95.  
  96.  
  97. void DisplayHeadings()
  98. {
  99.     CursorOff();
  100.  
  101.     SetCursor(1,2);
  102.     printf("RECEIVING");
  103.  
  104.     SetCursor(11,2);
  105.     printf("SENDING");
  106.  
  107.     SetCursor(22,6);
  108.     printf("ENTER = Return   BACKSPACE = Delete   TAB = Clear box   ESCAPE = Quit");
  109.  
  110.     SetCursor(13,2);
  111.     CursorOn();
  112. }
  113.  
  114.  
  115. void Update(string)
  116. char    *string;
  117. {
  118.     int        cursorRow, cursorCol;
  119.  
  120.     CursorOff();
  121.     SetCursor (24,1);
  122.     printf ("System Message: %s",string);
  123.     GetCursor (&cursorRow, &cursorCol);
  124.     ClearEndOfLine (24, cursorCol);
  125.     SetCursor (sendRow,sendCol);
  126.     CursorOn();
  127. }
  128.  
  129. void Error(text)
  130. char    *text;
  131. {
  132.     ClearScreen();
  133.     printf("%s",text);
  134.     Exit();
  135. }
  136.  
  137.  
  138. void ClearScreen()
  139. {
  140.     ScrollUp(0,0,24,0,79);
  141. }
  142.  
  143.  
  144. void ClearSendBox()
  145. {
  146.     int lines = 7,
  147.         topRow = 13,
  148.         bottomRow = 19,
  149.         leftCol = 1,
  150.         rightCol = 78;
  151.     
  152.     ScrollUp(lines,topRow,bottomRow,leftCol,rightCol);
  153.  
  154.     sendRow = TOP_SEND_ROW;
  155.     sendCol = FIRST_TEXT_COL;
  156.     SetCursor(sendRow,sendCol);
  157. }
  158.  
  159.  
  160. void ClearReceiveBox()
  161. {
  162.     int lines = 7, topRow = 3, bottomRow = 9, leftCol = 1, rightCol = 78;
  163.     
  164.     ScrollUp (lines, topRow, bottomRow, leftCol, rightCol);
  165.     CursorOff();
  166.  
  167.     receiveRow = TOP_RECEIVE_ROW;
  168.     receiveCol = FIRST_TEXT_COL;
  169.     SetCursor(sendRow, sendCol);
  170.     CursorOn();
  171. }
  172.  
  173.  
  174. void ClearEndOfLine (line, cursor)
  175. int        line, cursor;
  176. {
  177.      ScrollUp (1, line, line, cursor, 79);
  178. }
  179.  
  180.  
  181. void WriteChar(ch)
  182. char    ch;
  183. {
  184.     regs.h.ah = 0x09;
  185.     regs.h.al = ch;
  186.     regs.h.bl = 0x07;
  187.     regs.h.bh = 0;
  188.     regs.h.ch = 0;
  189.     regs.h.cl = 1;
  190.  
  191.     int86(VIDEO, ®s, ®s);
  192. }
  193.  
  194.  
  195. void ScrollUp (lines, topRow, bottomRow, leftCol, rightCol)
  196. int    lines, topRow, bottomRow, leftCol, rightCol;
  197. {
  198.     regs.h.ah = SCROLL_UP;
  199.     regs.h.al = lines;
  200.     regs.h.ch = topRow;
  201.     regs.h.cl = leftCol;
  202.     regs.h.dh = bottomRow;
  203.     regs.h.dl = rightCol;
  204.     regs.h.bh = 0x07;
  205.  
  206.     int86(VIDEO, ®s, ®s);
  207. }
  208.  
  209.  
  210. void SetCursor(r,c)
  211. int register    c,
  212.                 r;
  213. {
  214.     union REGS regs;
  215.  
  216.     regs.h.ah = SET_CURSOR;
  217.     regs.h.dl = c;
  218.     regs.h.dh = r;
  219.     regs.h.bh = 0;
  220.  
  221.     int86(VIDEO, ®s, ®s);
  222. }
  223.  
  224. void CursorOn() 
  225. {
  226.     int        start = 12; /* top line of cursor    */
  227.     int        end = 13;   /* bottom line of cursor */
  228.  
  229.     regs.h.ch = start;
  230.     regs.h.cl = end;
  231.     regs.h.ah = CURSOR_SIZE;
  232.  
  233.     int86(VIDEO, ®s, ®s);
  234. }
  235.  
  236.  
  237. void CursorOff()
  238. {
  239.     regs.h.ch = STOPBIT;
  240.     regs.h.ah = CURSOR_SIZE;
  241.     int86(VIDEO, ®s, ®s);
  242. }
  243.  
  244.  
  245. GetCursor (cursorRow, cursorCol)
  246. int     *cursorRow, *cursorCol;
  247. {
  248.     union REGS regs;
  249.  
  250.     regs.h.ah = 3;
  251.     regs.h.bh = 0;
  252.      int86(VIDEO, ®s, ®s);
  253.  
  254.     *cursorCol = regs.h.dl;
  255.     *cursorRow = regs.h.dh;
  256. }
  257.  
  258.  
  259.  
  260.