home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c329 / 2.img / EXAMPLES / DISPTTY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-23  |  3.6 KB  |  113 lines

  1. /*
  2.  * DISPTTY.C
  3.  * Purpose: demonstrate using int386 function
  4.  * Copyright (C) MicroWay, Inc., 1989
  5.  *
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <dos.h>
  10.  
  11. #define VIDEO_IO 0x10 /* interrupt # for ROM BIOS video services */
  12. #define BRIGHT 1<<3   /* intense attribute for screen chars */
  13. #define BLINKON 1<<7  /* blinking attribute on */
  14. #define BLINKOFF 0x7f /* blinking attribute off */
  15. #define DEFAULT 0xff  /* leave old attributes as they were */
  16.  
  17. void display_tty();   /* forward reference */
  18.  
  19. main ()
  20. {
  21.     printf ("A horse that can count to 10 is a remarkable ");
  22.     fflush(stdout); /* force C to flush output buffer */
  23.     display_tty (BRIGHT,DEFAULT,"horse");
  24.     printf("\n");
  25.     printf("not a remarkable ");
  26.     fflush(stdout); /* force C to flush output buffer */
  27.     display_tty (BRIGHT,DEFAULT,"mathematician.");
  28.     printf(" - Dr. Samuel Johnson\n");
  29.  
  30. }
  31.  
  32. /* ************************************************************
  33.  * display_tty
  34.  * This function displays a string of characters on the screen
  35.  * with a given attribute, and advances the cursor. Since there
  36.  * is no single ROM BIOS video service that does both, it
  37.  * combines the functionality of two of them:
  38.  *      Service 9, Write Character and Attribute
  39.  *      Service 2, Set Cursor Position
  40.  * The three parameters are:
  41.  *      The attribute(s) to be added
  42.  *      The attribute(s) to be deleted
  43.  *      Pointer to a null-terminated string of characters
  44.  * The coding of the attribute byte:
  45.  *       Bit
  46.  *      7 6 5 4 3 2 1 0
  47.  *      1 . . . . . . .     Blinking of foreground character
  48.  *      . 1 . . . . . .     Red component of background color
  49.  *      . . 1 . . . . .     Green component of background color
  50.  *      . . . 1 . . . .     Blue component of background color
  51.  *      . . . . 1 . . .     Intensity of foreground color
  52.  *      . . . . . 1 . .     Red component of foreground color
  53.  *      . . . . . . 1 .     Green component of foreground color
  54.  *      . . . . . . . 1     Blue component of foreground color
  55.  *
  56.  * The current attribute byte is ANDed with the attribute(s)
  57.  * to be removed and OR'd with the new attribute(s) to be added.
  58.  */
  59.  
  60. void display_tty(add_attr, del_attr, string)
  61. int     add_attr;   /* new attribute(s) to be added */
  62. int     del_attr;   /* attribute(s) to be removed */
  63. char    *string;    /* character(s) to be displayed */
  64.  
  65. {
  66.     unsigned char   current_attr;
  67.     unsigned char   active_page;
  68.     unsigned char   row, col;
  69.     unsigned char   maxcol;
  70.     union   REGS    inregs, outregs;
  71.     int     intnum;
  72.  
  73.     intnum = VIDEO_IO;
  74.  
  75.     inregs.b.ah = 15;     /* get current video mode */
  76.     int386 (&intnum, &inregs, &outregs);
  77.     active_page = outregs.b.bh;
  78.     maxcol = outregs.b.ah;
  79.  
  80.     inregs.b.ah = 8;      /* get current attribute */
  81.     int386 (&intnum, &inregs, &outregs);
  82.     current_attr = outregs.b.ah;
  83.  
  84.     inregs.b.ah = 3;      /* read cursor position */
  85.     inregs.b.bh = active_page;
  86.     int386 (&intnum, &inregs, &outregs);
  87.     row = outregs.b.dh;
  88.     col = outregs.b.dl;
  89.  
  90.     inregs.w.cx = 1; /* only one char, attr at a time */
  91.     inregs.b.bl = (char) current_attr & del_attr | add_attr;
  92.  
  93.     while ( *string ) {
  94.         inregs.b.ah = 9;  /* output char, attr */
  95.         inregs.b.al = *string++;
  96.         int386 (&intnum, &inregs, &outregs);
  97.  
  98.         if (++col >= maxcol) {
  99.             col = 0;
  100.             if (++row == 25) {
  101.                 row = 0;
  102.             }
  103.         }
  104.  
  105.         inregs.b.ah = 2;  /* advance cursor */
  106.         inregs.b.dh = row;
  107.         inregs.b.dl = col;
  108.         int386 (&intnum, &inregs, &outregs);
  109.     }
  110.  
  111. }       /* end of display_tty */
  112.  
  113.