home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk12 / bigben / bigben.c next >
Encoding:
C/C++ Source or Header  |  1989-11-20  |  3.0 KB  |  179 lines

  1. /*
  2.  * This example uses a few of the many VIO calls.
  3.  * 
  4.  * This example puts the time on the screen in large numbers.
  5.  *
  6.  * Created by Microsoft Corp. 1986
  7.  */
  8.  
  9. #include <os2def.h>
  10. #define INCL_DOSPROCESS
  11. #define INCL_DOSDATETIME
  12. #include <bsedos.h>
  13. #define INCL_SUB
  14. #include <bsesub.h>
  15. #include <stdio.h>
  16.  
  17. #define    CHAR_WIDTH    8
  18. #define    CHAR_HEIGHT    7
  19.  
  20. #define    CLOCK_ROW    10    /* row to start the clock */
  21. #define    TOTAL_COLMS    80    /* screen size in colms */
  22. #define    TOTAL_ROWS    24    /* screen size in rows */
  23.  
  24.     
  25. char    BigChars[10][CHAR_HEIGHT][CHAR_WIDTH] = {
  26.  
  27. {
  28.     "   00  ",
  29.     "  0  0 ",
  30.     " 0    0",
  31.     " 0    0",
  32.     " 0    0",
  33.     "  0  0 ",
  34.     "   00  "
  35. },
  36. {
  37.     "   1   ",
  38.     "   1   ",
  39.     "   1   ",
  40.     "   1   ",
  41.     "   1   ",
  42.     "   1   ",
  43.     "   1   "
  44. }, 
  45. {
  46.     "  2222 ",
  47.     " 2    2",
  48.     "      2",
  49.     "     2 ",
  50.     "   2   ",
  51.     "  2    ",
  52.     " 222222" 
  53. },
  54. {
  55.     " 33333 ",
  56.     "      3",
  57.     "      3",
  58.     "   333 ",
  59.     "      3",
  60.     "      3",
  61.     " 33333 " 
  62. },
  63. {
  64.     "    44 ",
  65.     "   4 4 ",
  66.     "  4  4 ",
  67.     " 4   4 ",
  68.     " 444444",
  69.     "     4 ",
  70.     "     4 " 
  71. },
  72. {
  73.     " 555555",
  74.     " 5     ",
  75.     " 55555 ",
  76.     "      5",
  77.     "      5",
  78.     " 5    5",
  79.     "  5555 " 
  80. },
  81. {
  82.     "    6  ",
  83.     "   6   ",
  84.     "  6    ",
  85.     "  6666 ",
  86.     " 6    6",
  87.     " 6    6",
  88.     "  6666 " 
  89. },
  90. {
  91.     " 777777",
  92.     "      7",
  93.     "     7 ",
  94.     "    7  ",
  95.     "   7   ",
  96.     "  7    ",
  97.     " 7     "
  98. },
  99. {
  100.     "  8888 ",
  101.     " 8    8",
  102.     " 8    8",
  103.     "  8888 ",
  104.     " 8    8",
  105.     " 8    8",
  106.     "  8888 "
  107. },
  108. {
  109.     "  9999 ",
  110.     " 9    9",
  111.     " 9    9",
  112.     "  9999 ",
  113.     "    9  ",
  114.     "   9   ",
  115.     "  9    "
  116. }
  117. };
  118.  
  119.  
  120. main(argc, argv)
  121.     int    argc;
  122.     char    *argv[];
  123. {
  124.     unsigned    rc;    /* return code */
  125.     DATETIME Now;     /* time struct for DosGetDateTime */
  126.  
  127.     /* clear the screen */
  128.  
  129.     VioWrtNCell( " \07", TOTAL_ROWS * TOTAL_COLMS, 0, 0, 0 );
  130.  
  131.     /* paint separators between hours and minutes, and minutes and seconds*/
  132.  
  133.     VioWrtNCell( "|\07", 1, (CLOCK_ROW + 2), 27, 0 );
  134.     VioWrtNCell( "|\07", 1, (CLOCK_ROW + 5), 27, 0 );
  135.     VioWrtNCell( "|\07", 1, (CLOCK_ROW + 2), 52, 0 );
  136.     VioWrtNCell( "|\07", 1, (CLOCK_ROW + 5), 52, 0 );
  137.      
  138.     for (;;) {
  139.  
  140.         /* get the system time */
  141.  
  142.         if (rc = DosGetDateTime( &Now))  {
  143.  
  144.         printf("DosGetDateTime failed, error: %d\n", rc);
  145.         DosExit(EXIT_PROCESS, 0);
  146.         }
  147.  
  148.         /* write the digits out to the screen */
  149.  
  150.         LoadNumber(Now.hours / 10, 5, CLOCK_ROW);
  151.         LoadNumber(Now.hours % 10, 15, CLOCK_ROW);
  152.         LoadNumber(Now.minutes / 10, 30, CLOCK_ROW);
  153.         LoadNumber(Now.minutes % 10, 40, CLOCK_ROW);
  154.         LoadNumber(Now.seconds / 10, 55, CLOCK_ROW);
  155.         LoadNumber(Now.seconds % 10, 65, CLOCK_ROW);
  156.  
  157.         DosSleep(900L);
  158.     }
  159. }
  160.  
  161.  
  162. /* display the digit at the given coordinates */
  163.  
  164. LoadNumber( dig, x, y )
  165.     unsigned    dig;
  166.     unsigned    x;
  167.     unsigned    y;
  168. {
  169.     int    i;
  170.  
  171.     /* write a list of char strings to make up a display number */
  172.  
  173.     for (i=0; (i < CHAR_HEIGHT); i++) 
  174.  
  175.         /* write a character string starting from the coordinates */
  176.  
  177.         VioWrtCharStr( BigChars[dig][i], CHAR_WIDTH, y++, x, 0);
  178.