home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 11screen / st.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.0 KB  |  123 lines

  1. /*
  2.  *    st -- screen test using cpblk function
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <conio.h>
  8. #include <ctype.h>
  9. #include <dos.h>
  10. #include <local\std.h>
  11. #include <local\video.h>
  12.  
  13. #define CG_SEG        0xB800
  14. #define MONO_SEG    0xB000
  15. #define NBYTES        0x1000
  16. #define PAGESIZ        (NBYTES / 2)
  17. #define PG0_OS        0
  18. #define PG1_OS        PG0_OS + NBYTES
  19. #define ESC        27
  20. #define MAXSCAN        14
  21.  
  22. main(argc, argv)
  23. int argc;
  24. char *argv[];
  25. {
  26.     int i;
  27.     int k;                /* user command character */
  28.     int ca;                /* character/attribute word */
  29.     int ch;                /* character value read */
  30.     int row, col;            /* cursor position upon entry */
  31.     int c_start, c_end;        /* cursor scan lines */
  32.     unsigned char attr;        /* saved video attribute */
  33.     unsigned dseg;            /* destination buffer segment */
  34.     unsigned os;            /* page offset in bytes */
  35.     static unsigned sbuf[NBYTES];    /* screen buffer */
  36.     unsigned *bp;            /* screen element pointer */
  37.     unsigned sseg;            /* source segment */
  38.     int special;            /* use special copy routine */
  39.     int apg, vpg;            /* active and visual display pages */
  40.  
  41.     /* segment register values */
  42.     struct SREGS segregs;
  43.  
  44.     extern void swap_int(int *, int *);
  45.  
  46.     static char pgm[] = { "st" };    /* program name */
  47.  
  48.     /* save user's current video state */
  49.     getstate();
  50.     readcur(&row, &col, Vpage);
  51.     putcur(row - 1, 0, Vpage);
  52.     readca(&ch, &attr, Vpage);
  53.     getctype(&c_start, &c_end, Vpage);
  54.     setctype(MAXSCAN, c_end);
  55.     clrscrn(attr);
  56.     putcur(1, 1, Vpage);
  57.  
  58.     /* initialize destination segment */
  59.     special = 1;
  60.     fputs("ScreenTest (ST): ", stderr);
  61.     if (Vmode == CGA_C80 || Vmode == CGA_M80) {
  62.         dseg = CG_SEG;
  63.         fprintf(stderr, "Using CGA mode %d", Vmode);
  64.     }
  65.     else if (Vmode == MDA_M80) {
  66.         dseg = MONO_SEG;
  67.         fprintf(stderr, "Using MDA (mode %d)", Vmode);
  68.         special = 0;
  69.     } else
  70.         fprintf(stderr, "%s: Requires 80-column text mode\n", pgm);
  71.  
  72.     /* process command-line arguments */
  73.     if (argc > 2) {
  74.         fprintf(stderr, "Usage: %s [x]\n", pgm);
  75.         exit(2);
  76.     }
  77.     else if (argc == 2)
  78.         special = 0;    /* bypass special block move */
  79.  
  80.     /* get data segment value */
  81.     segread(&segregs);
  82.     sseg = segregs.ds;
  83.  
  84.     /* set up "active" and "visual" display pages */
  85.     apg = 1;    /* page being written to */
  86.     vpg = 0;    /* page being viewed */
  87.  
  88.     /* display buffers on the user's command */
  89.     fprintf(stderr, " -- Type printable text; Esc=exit");
  90.     while ((k = getkey()) != ESC) {
  91.         if (isascii(k) && isprint(k)) {
  92.             /* fill the buffer */
  93.             ca = ((k % 0xEF) << 8) | k;
  94.             for (bp = sbuf; bp - sbuf < PAGESIZ; ++bp)
  95.                 *bp = ca;
  96.             if (Vmode == MDA_M80)
  97.                 os = 0;
  98.             else
  99.                 os = (apg == 0) ? PG0_OS : PG1_OS;
  100.             if (special)
  101.                 cpblk(sbuf, sseg, os, dseg);
  102.             else
  103.                 movedata(sseg, sbuf, dseg, os, NBYTES);
  104.             if (Vmode != MDA_M80) {
  105.                 swap_int(&apg, &vpg);
  106.                 setpage(vpg);
  107.             }
  108.         }
  109.         else {
  110.             clrscrn(attr);
  111.             putcur(0, 0, Vpage);
  112.             writestr(" Type printable text; Esc = exit ", vpg);
  113.         }
  114.     }
  115.  
  116.     /* restore user's video conditions and return to DOS */
  117.     setpage(Vpage);
  118.     clrscrn(attr);
  119.     putcur(0, 0, Vpage);
  120.     setctype(c_start, c_end);
  121.     exit(0);
  122. }
  123.