home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / GRAPHICS / kwsaver.lzh / kwsaver_mm1s.c < prev    next >
C/C++ Source or Header  |  1994-05-05  |  3KB  |  99 lines

  1. /* kwsaver_mm1s.c                                 */
  2. /* A screen-saver program for use with KWSaver,   */
  3. /* by Joel Mathew Hegberg.                        */
  4. /* This program works only with 16-color screens, */
  5. /* since that's what the raw graphics data is     */
  6. /* formatted for.  If used on a 256-color screen, */
  7. /* only a black screen is shown.                  */
  8.  
  9. /* NOTE: This program uses a K-Windows graphic buffer, which */
  10. /*       must be killed before exiting (or else the memory   */
  11. /*       used by the buffer will not be returned to the      */
  12. /*       system), so a signal trap (handler) is implemented  */
  13. /*       to detect when it's time to exit.                   */
  14.  
  15. #include <stdio.h>
  16. #include "kwsaver_mm1s.h"    /* contains our graphics data */
  17.  
  18. #define PATH 1
  19.  
  20. extern int sighandler();    /* this will use a signal handler function */
  21.  
  22. int sigcode=0;                /* storage to keep received signal(s) */
  23.  
  24. main()
  25. {
  26.     int x,y,dx,dy,pid,max_pixels,max_lines,temp;
  27.     
  28.     intercept(sighandler);        /* install signal handler */
  29.     
  30.     temp=Get_Num_Colors(PATH);    /* Is this a 16-color screen? */
  31.     if (temp!=16)                /* if not 16-color, just show black screen */
  32.     {
  33.         do_nothing();
  34.         exit(0);
  35.     }
  36.     _gs_scsz(PATH,&max_pixels,&max_lines);
  37.     max_pixels*=8;    /* max_pixels is how many pixels wide the screen is */
  38.     max_lines*=8;    /* max_lines is how many pixels deep the screen is */
  39.     pid=getpid();    /* get process-id for unique kwgroup */
  40.     loadbuff(PATH,pid,1,16,17,smallmm1_icon); /* load our graphics data */
  41.     x=50; y=20; dx=2; dy=1;    /* start location & direction of our logo */
  42.     ScaleSw(PATH,0);        /* graphics scaling off */
  43.     
  44.     while(!sigcode)    /* loop until signal has been received */
  45.     {
  46.         PutBlk(PATH,pid,1,x,y);    /* put logo on screen */
  47.         tsleep(5);    /* rest -- let user enjoy the view */
  48.         x+=dx; y+=dy;    /* move logo according to directionals */
  49.         
  50.         /* now, boundary check... */
  51.         if (x<=1) dx=-dx;                /* bounce */
  52.         if (x>=(max_pixels-34)) dx=-dx;    /* bounce */
  53.         if (y<=1) dy=-dy;                /* bounce */
  54.         if (y>=(max_lines-19)) dy=-dy;    /* bounce */
  55.     }
  56.     
  57.     KilBuf(PATH,pid,1);    /* release our graphics buffer before exiting */
  58. }
  59.  
  60. do_nothing()
  61. {
  62.     sleep(0);    /* sleep until a signal is received */
  63. }
  64.  
  65. /* loadbuff loads in graphics data into a K-Windows buffer */
  66. loadbuff(pth,grp,buf,xsiz,ysiz,data)
  67. int pth,grp,buf,xsiz,ysiz;
  68. char *data;
  69. {
  70.     char chr;
  71.     
  72.     write(pth,"\x1b\x2b",2);
  73.     chr=(char)grp;
  74.     write(pth,&chr,1);
  75.     chr=(char)buf;
  76.     write(pth,&chr,1);
  77.     write(pth,"\x08",1);
  78.     chr=(char)((xsiz*2)/256);
  79.     write(pth,&chr,1);
  80.     chr=(char)((xsiz*2)&255);
  81.     write(pth,&chr,1);
  82.     chr=(char)(ysiz/256);
  83.     write(pth,&chr,1);
  84.     chr=(char)(ysiz&255);
  85.     write(pth,&chr,1);
  86.     chr=(char)((xsiz*ysiz)/256);
  87.     write(pth,&chr,1);
  88.     chr=(char)((xsiz*ysiz)&255);
  89.     write(pth,&chr,1);
  90.     write(pth,data,xsiz*ysiz);
  91. }
  92.  
  93. sighandler(signal)
  94. int signal;
  95. {
  96.     sigcode=signal;
  97. }
  98.  
  99.