home *** CD-ROM | disk | FTP | other *** search
- /*
- * DISPTTY.C
- * Purpose: demonstrate using int386 function
- * Copyright (C) MicroWay, Inc., 1989
- *
- */
-
- #include <stdio.h>
- #include <dos.h>
-
- #define VIDEO_IO 0x10 /* interrupt # for ROM BIOS video services */
- #define BRIGHT 1<<3 /* intense attribute for screen chars */
- #define BLINKON 1<<7 /* blinking attribute on */
- #define BLINKOFF 0x7f /* blinking attribute off */
- #define DEFAULT 0xff /* leave old attributes as they were */
-
- void display_tty(); /* forward reference */
-
- main ()
- {
- printf ("A horse that can count to 10 is a remarkable ");
- fflush(stdout); /* force C to flush output buffer */
- display_tty (BRIGHT,DEFAULT,"horse");
- printf("\n");
- printf("not a remarkable ");
- fflush(stdout); /* force C to flush output buffer */
- display_tty (BRIGHT,DEFAULT,"mathematician.");
- printf(" - Dr. Samuel Johnson\n");
-
- }
-
- /* ************************************************************
- * display_tty
- * This function displays a string of characters on the screen
- * with a given attribute, and advances the cursor. Since there
- * is no single ROM BIOS video service that does both, it
- * combines the functionality of two of them:
- * Service 9, Write Character and Attribute
- * Service 2, Set Cursor Position
- * The three parameters are:
- * The attribute(s) to be added
- * The attribute(s) to be deleted
- * Pointer to a null-terminated string of characters
- * The coding of the attribute byte:
- * Bit
- * 7 6 5 4 3 2 1 0
- * 1 . . . . . . . Blinking of foreground character
- * . 1 . . . . . . Red component of background color
- * . . 1 . . . . . Green component of background color
- * . . . 1 . . . . Blue component of background color
- * . . . . 1 . . . Intensity of foreground color
- * . . . . . 1 . . Red component of foreground color
- * . . . . . . 1 . Green component of foreground color
- * . . . . . . . 1 Blue component of foreground color
- *
- * The current attribute byte is ANDed with the attribute(s)
- * to be removed and OR'd with the new attribute(s) to be added.
- */
-
- void display_tty(add_attr, del_attr, string)
- int add_attr; /* new attribute(s) to be added */
- int del_attr; /* attribute(s) to be removed */
- char *string; /* character(s) to be displayed */
-
- {
- unsigned char current_attr;
- unsigned char active_page;
- unsigned char row, col;
- unsigned char maxcol;
- union REGS inregs, outregs;
- int intnum;
-
- intnum = VIDEO_IO;
-
- inregs.b.ah = 15; /* get current video mode */
- int386 (&intnum, &inregs, &outregs);
- active_page = outregs.b.bh;
- maxcol = outregs.b.ah;
-
- inregs.b.ah = 8; /* get current attribute */
- int386 (&intnum, &inregs, &outregs);
- current_attr = outregs.b.ah;
-
- inregs.b.ah = 3; /* read cursor position */
- inregs.b.bh = active_page;
- int386 (&intnum, &inregs, &outregs);
- row = outregs.b.dh;
- col = outregs.b.dl;
-
- inregs.w.cx = 1; /* only one char, attr at a time */
- inregs.b.bl = (char) current_attr & del_attr | add_attr;
-
- while ( *string ) {
- inregs.b.ah = 9; /* output char, attr */
- inregs.b.al = *string++;
- int386 (&intnum, &inregs, &outregs);
-
- if (++col >= maxcol) {
- col = 0;
- if (++row == 25) {
- row = 0;
- }
- }
-
- inregs.b.ah = 2; /* advance cursor */
- inregs.b.dh = row;
- inregs.b.dl = col;
- int386 (&intnum, &inregs, &outregs);
- }
-
- } /* end of display_tty */
-
-