home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / r_la4_01 / attrf2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-29  |  1.8 KB  |  62 lines

  1. /* ATTRF2.C - From page 361 of "Microsoft C Programming for     */
  2. /* the IBM" by Robert Lafore. The program uses bit fields to    */
  3. /* change attributes. Type 'x' to exit.                         */
  4. /****************************************************************/
  5.  
  6. #define ROMAX 25
  7. #define COMAX 80
  8. #define TRUE 1
  9.  
  10. main()
  11. {
  12. struct {
  13.    unsigned int foregnd : 3;        /*bits 0,1,2 */
  14.    unsigned int intense : 1;        /*bit 3*/
  15.    unsigned int backgnd : 3;        /*bits 4, 5, 6*/
  16.    unsigned int blinker : 1;        /*bit 7*/
  17. } attr;
  18. char ch;
  19.  
  20.    printf("\nType 'n' for normal,\n");
  21.    printf("     'u' for underlined,\n");
  22.    printf("     'i' for intensified,\n");
  23.    printf("     'b' for blinking,\n");
  24.    printf("     'r' for reverse video,\n");
  25.    while((ch = getch()) != 'x') {
  26.       switch(ch) {
  27.          case 'n':                     /*set to normal*/
  28.             attr.foregnd = 7;
  29.             attr.backgnd = 0;
  30.             break;
  31.          case 'u':                     /*set to underline*/
  32.             attr.foregnd = 1;
  33.             break;
  34.          case 'i':                     /*toggle intensity*/
  35.             attr.intense = (attr.intense == 1) ? 0 : 1;
  36.             break;
  37.          case 'b':                     /*toggle blinking*/
  38.             attr.blinker = (attr.blinker == 1) ? 0 : 1;
  39.             break;
  40.          case 'r':                     /*set to reverse video*/
  41.             attr.foregnd = 0;
  42.             attr.backgnd = 7;
  43.             break;
  44.       }
  45.       fill(ch, attr);
  46.    }
  47. }
  48.  
  49. /* fill() */      /*fills screen with char 'ch', attribute 'attr' */
  50. fill(ch, attr)
  51. char ch, attr;
  52. {
  53. int far *farptr;
  54. int col, row;
  55.  
  56.    farptr = (int far *) 0xB0000000;
  57.    for(row = 0; row < ROMAX; row++)
  58.       for(col = 0; col < COMAX; col++)
  59.          *(farptr + row*COMAX + col) = ch | attr << 8;
  60. }
  61.  
  62.