home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / GRAPHICS / ssaver.lzh / SRC / saver_mw.c < prev    next >
C/C++ Source or Header  |  1995-11-02  |  3KB  |  145 lines

  1. /* saver_mw.c                                     */
  2. /* A screen-saver program for use with SSaver,    */
  3. /* by Boisy G. Pitre                              */
  4. /* This program works on a 256-color screen       */
  5.  
  6. #include <stdio.h>
  7. #include <modes.h>
  8. #include <types.h>
  9. #include "saver.h"
  10.  
  11. int orgwin, win, twin;
  12.  
  13. int sighandler();            /* this will use a signal handler function */
  14. int sigcode = 0;            /* storage to keep received signal(s) */
  15. int gotosleep = FALSE;
  16.  
  17. int max_pixels, max_lines;
  18. int dx, dy;
  19. int x, y;
  20. int pid;
  21.  
  22. extern char object_microware;
  23. extern int  errno;
  24.  
  25. main()
  26. {
  27.     int evID;                    /* event ID */
  28.  
  29.     sigmask(1);                    /* mask signals */
  30.  
  31.     intercept(sighandler);        /* install signal handler */
  32.  
  33.     if ((evID = _ev_link(EV_NAME)) == -1)
  34.         exit(1);
  35.  
  36.     DWSet(STDOUT, 3, 0, 0, 40, 26, 0, 0, 0);
  37.  
  38.     if (_gs_currscr(STDOUT,&orgwin) == -1)
  39.         exit(0);
  40.  
  41.     CurOff(STDOUT);
  42.     BColor(STDOUT, 0);
  43.     _gs_wdev(STDOUT, &win);        /* get our window device number */
  44.     _ss_select(STDOUT, win);    /* now select it! */
  45.  
  46.     init_saver();
  47.  
  48.     sigmask(0);                    /* unmask signals */
  49.     _ev_set(evID, 0, 0x8000);    /* wake up everybody */
  50.  
  51.     /* we unlink from the event since we are through with it */
  52.     _ev_unlink(evID);
  53.  
  54.     while(! sigcode)
  55.     {
  56.         if (gotosleep)
  57.             sleep(0);
  58.         else
  59.             draw_logo();
  60.     }
  61.  
  62.     cleanup();
  63. }
  64.  
  65. init_saver()
  66. {
  67.     char *buf = &object_microware;
  68.  
  69.     /* graphics scaling off */
  70.     ScaleSw(STDOUT,0);
  71.  
  72.     _gs_scsz(STDOUT,&max_pixels,&max_lines);
  73.  
  74.     max_pixels <<= 3;    /* max_pixels is how many pixels wide the screen is */
  75.     max_lines  <<= 3;    /* max_lines is how many pixels deep the screen is */
  76.  
  77.     pid = getpid();        /* get process-id for unique kwgroup */
  78.  
  79.     KilBuf(STDOUT,pid,0);    /* make sure our group is free */
  80.  
  81.     /* load our graphics data */
  82.     GPLoad(STDOUT, pid, 1, 3, 208, 28, 208 * 28);
  83.     write(STDOUT, buf + 7, 5824);
  84.  
  85.     /* start location & direction of our logo */
  86.     x = 50;
  87.     y = 20;
  88.     dx = 2;
  89.     dy = 1;
  90.  
  91. }
  92.     
  93. draw_logo()
  94. {
  95.     /* put logo on screen */
  96.     PutBlk(STDOUT,pid,1,x,y);
  97.  
  98.     /* move logo according to directionals */
  99.     x += dx;
  100.     y += dy;
  101.     
  102.     /* now, boundary check... */
  103.     if (x <= 1) {
  104.         dx = -dx;                /* bounce */
  105.     }
  106.     if (x >= (max_pixels - 208)) {
  107.         dx = -dx;    /* bounce */
  108.     }
  109.     if (y <= 1) {
  110.         dy = -dy;                /* bounce */
  111.     }
  112.     if (y >= (max_lines - 28)) {
  113.         dy =- dy;    /* bounce */
  114.     }
  115.  
  116.     tsleep(5);    /* rest -- let user enjoy the view */
  117. }
  118.  
  119. cleanup()
  120. {    
  121.     KilBuf(STDOUT,pid,0);    /* release our graphics buffer before exiting */
  122. }
  123.  
  124. sighandler(signal)
  125. int signal;
  126. {
  127.     switch(signal) {
  128.     case SLEEP_SIG:
  129.         gotosleep = TRUE;
  130.         break;
  131.     case WAKE_SIG:
  132.         gotosleep = FALSE;
  133.         break;
  134.     case QUIT_SIG:
  135.     default:        
  136.         gotosleep = FALSE;
  137.         sigcode = signal;
  138.         if (_gs_currscr(STDOUT,&twin) == -1)
  139.             exit(0);
  140.         if (twin == win) {
  141.             _ss_select(STDOUT, orgwin);
  142.         }
  143.     }
  144. }
  145.