home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap10 / scrrest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-06  |  1.2 KB  |  49 lines

  1. /* scrrest.c  --  demonstrates read() by restoring */
  2. /*                text screen from any file.       */
  3.  
  4. #include <stdio.h>        /* for stderr              */
  5. #include <fcntl.h>        /* for O_RDONLY | O_BINARY */
  6.  
  7. #define SCRCHARS  (25 * 80)
  8. int Buf[SCRCHARS];
  9.  
  10. main(argc, argv)
  11. int argc;
  12. char *argv[];
  13. {
  14.     int *cp, *ep;
  15.     int far *sp;
  16.     int fd_in, bytes;
  17.  
  18.     if (argc != 2)
  19.         {
  20.         fprintf(stderr, "usage: scrrest file.scr\n");
  21.         exit(0);
  22.         }
  23.     if ((fd_in = open(argv[1], O_RDONLY | O_BINARY)) < 0)
  24.         {
  25.         fprintf(stderr, "\"%s\": Can't open to read.\n", argv[1]);
  26.         exit(1);
  27.         }
  28.     /* Read it. */
  29.     bytes = read(fd_in, Buf, SCRCHARS * 2);
  30.     if (bytes < 0)
  31.         {
  32.         fprintf(stderr, "\"%s\": Error Reading.\n", argv[1]);
  33.         exit(1);
  34.         }
  35.     if (bytes == 0)
  36.         {
  37.         fprintf(stderr, "\"%s\": Empty File.\n", argv[1]);
  38.         exit(1);
  39.         }
  40.     /* Copy the buffer to screen memory. */
  41.     ep = &Buf[bytes / 2];
  42.     cp = Buf;
  43.  
  44.     /* use 0xB800000 for EGA or VGA */
  45.     sp = (int far *)(0xB0000000);
  46.     for (; cp < ep; ++cp, ++sp)
  47.         *sp = *cp;
  48. }
  49.