home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / pcpilot.zip / RULER.C < prev    next >
Text File  |  1990-01-13  |  2KB  |  97 lines

  1. /*
  2.     RULER.C - Display a ruler on the screen.
  3.               Original idea taken from Duane A. Bowen and his
  4.               @LAST TSR program.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <dos.h>
  9. #include <kbd.h>
  10.  
  11. void Ruler(void);
  12.  
  13. typedef int ROW[80];
  14. ROW far *Video;
  15. static int Buffer[25][80];
  16. extern int Row, Col;
  17. extern int HighlightClr;
  18.  
  19. static void InitBuf(void);
  20. static void PutRow(void);
  21. static void DrawRuler(void);
  22.  
  23. void Ruler()
  24. {
  25.     int dx, dy;
  26.  
  27.     ScrGetCur(&dx, &dy, 0);
  28.     Video = MK_FP (*(char far *)0x00400049 == 7 ? 0xb000 : 0xb800, 0);
  29.     InitBuf();
  30.  
  31.     for (;;)    {
  32.         DrawRuler();
  33.         Video[Row][Col] = Buffer[Row][Col];
  34.         switch (KbdGetC())    {
  35.             case UP:
  36.                 PutRow();
  37.                 if (--Row < 0) Row = 24;
  38.                 break;
  39.             case DN:
  40.                 PutRow();
  41.                 if (++Row > 24) Row = 0;
  42.                 break;
  43.             case RIGHT:
  44.                 if (++Col > 79) Col = 0;
  45.                 break;
  46.             case LEFT:
  47.                 if (--Col < 0) Col = 79;
  48.                 break;
  49.             case HOME:
  50.                 Col = 0;
  51.                 break;
  52.             case END:
  53.                 Col = 79;
  54.                 break;
  55.             case PGUP:
  56.                 PutRow();
  57.                 Row = 0;
  58.                 break;
  59.             case PGDN:
  60.                 PutRow();
  61.                 Row = 24;
  62.                 break;
  63.             case RET:
  64.             case ESC:
  65.                 PutRow();
  66.                 ScrSetCur(dx, dy, 0);
  67.                 return;
  68.         }
  69.     }
  70. }
  71.  
  72. static void DrawRuler()
  73. {
  74.     PutStr(0,Row, HighlightClr,
  75. "  Column = %2d, Row = %2d      %c %c %c %c,  <Esc> - Quit      Column = %2d, Row = %2d  ",
  76.     Col, Row, 27, 24, 25, 26, Col, Row);
  77. }
  78.  
  79. static void PutRow()
  80. {
  81.     register int c;
  82.  
  83.     for (c=0; c<=79; c++)
  84.         Video[Row][c] = Buffer[Row][c];
  85. }
  86.  
  87. static void InitBuf()
  88. {
  89.     int VideoSeg;
  90.  
  91.     VideoSeg = *(char far *)0x00400049 == 7 ? 0xb000 : 0xb800;
  92.  
  93.     movedata(VideoSeg, 0, FP_SEG((char far *)Buffer),
  94.              FP_OFF((char far *)Buffer), 4000);
  95. }
  96.  
  97.