home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo3.zoo / demo / misc / overlayd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  3.4 KB  |  134 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: overlayd.c,v 4.1 88/06/22 14:37:59 bianchi Exp $
  9.     $Source: /tmp/mgrsrc/demo/misc/RCS/overlayd.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/misc/RCS/overlayd.c,v $$Revision: 4.1 $";
  12.  
  13. /*    overlayd        (S A Uhler)
  14.  *
  15.  *    turn off overlay plane anytime /dev/console gets scrunged (cgfour only)
  16.  */
  17.  
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20. #include <sys/ioctl.h>
  21. #include <sys/file.h>
  22. #include <sys/mman.h>
  23. #include <stdio.h>
  24.  
  25. #define CONSOLE     "/dev/console"
  26. #define DISPLAY    "/dev/fb"
  27. #define BITS    (1152*900)    /* bits in a plane */
  28. #define SLEEP    5        /* polling interval */
  29.  
  30. #define INIT    0    /* ok to init frame buffer */
  31. #define OK    1    /* frame buffer ok, do it */
  32. #define BAD    2    /* couldn't get fb, punt */
  33.  
  34.  
  35. main(argc,argv)
  36. int argc;
  37. char **argv;
  38.    {
  39.    struct stat statb;
  40.    int fd;
  41.    long mod_time;
  42.    long now;
  43.  
  44.    switch (fork()) {
  45.    default:    /* parent */
  46.       exit(0);
  47.    case -1:    /* fork() error */
  48.       perror( *argv );
  49.       exit(1);
  50.    case 0:     /* child */
  51.  
  52.       /* fix environment */
  53.  
  54.       fd = open("/dev/tty");
  55.       ioctl(fd,TIOCNOTTY,0);
  56.       close(fd);
  57.       close(0); close(1); close(2);
  58.       chdir("/");
  59.  
  60.       overlay(DISPLAY,0);
  61.       stat(CONSOLE,&statb);
  62.       mod_time = statb.st_mtime;
  63.  
  64.       while(1) {
  65.          stat(CONSOLE,&statb);
  66.          sleep(SLEEP);
  67.          if (mod_time < statb.st_mtime) {
  68.             mod_time = statb.st_mtime;
  69.             overlay(DISPLAY,0);
  70.             }
  71.          }
  72.       }
  73.    }
  74.  
  75. static int state = INIT;
  76.  
  77. overlay(name,how)
  78. char *name;
  79. int how;
  80.    {
  81.    int fd;
  82.    char  *malloc();
  83.    static int *addr = (int * ) 0;    /* starting address of frame buffer */
  84.    register int *start,*end;    /* range of addresses to change */
  85.    int size,temp,pagesize;
  86.    static int bits = BITS;
  87.  
  88.    /* open the SUN screen */
  89.  
  90.    switch(state) {
  91.       case BAD:
  92.          return(-1);
  93.          break;
  94.       case INIT:                /* first call, get fb */
  95.          state = BAD;
  96.          if ((fd = open(name,O_RDWR)) <0) {
  97.             perror(name);
  98.             return(-1);
  99.             }
  100.  
  101.          /* malloc space for frame buffer  -- overlay and enable planes */
  102.  
  103.          pagesize = getpagesize();
  104.          size = bits >> 2;    /* bitplane size in bytes  * 2 */
  105.          size = (size+pagesize-1) &~ (pagesize-1);    /* round to next page */
  106.  
  107.          if ((temp = (int) malloc(size+pagesize)) == 0) {
  108.             perror("malloc");
  109.             return(-1);
  110.             }
  111.    
  112.          /* align space on a page boundary */
  113.    
  114.          addr = (int *)(((unsigned int)temp+pagesize-1) & ~(pagesize-1));
  115.    
  116.          /* map the frame buffer into malloc'd space */
  117.    
  118.          if (mmap(addr,size,PROT_WRITE,MAP_SHARED,fd,0) < 0) {
  119.             perror("mmap");
  120.             free(temp);
  121.             return(-1);
  122.             }
  123.          state = OK;
  124.          /* no break */
  125.       case OK:         /* write data to plane */
  126.  
  127.          start = addr + 128*1024/4;        /* start of enable plane */
  128.          end =   start +(bits>>5);        /* end of enable plane */
  129.  
  130.          while(start < end)
  131.             *start++ = how;
  132.       }
  133.    }
  134.