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_dissolve.c < prev    next >
C/C++ Source or Header  |  1995-04-16  |  5KB  |  260 lines

  1. /* saver_dissolve.c - dissolve current screen */
  2.  
  3. #include <stdio.h>
  4. #include <modes.h>
  5. #include <types.h>
  6. #include <wind.h>
  7. #include <time.h>
  8.  
  9. #include "saver.h"
  10.  
  11. int  orgwin;
  12. int  win;
  13. int  twin;
  14.  
  15. int  gotosleep = FALSE;
  16. int  sigcode = 0;        /* storage to keep received signal(s) */
  17. int  sighandler();    /* this will use a signal handler function */
  18.     
  19. char pal[768];
  20.  
  21. extern char *_gs_scadd();
  22. extern int errno;
  23.  
  24. main()
  25. {
  26.     int evID;                    /* event ID */
  27.  
  28.     sigmask(1);                    /* mask signals */
  29.     
  30.     intercept(sighandler);        /* install signal handler */
  31.  
  32.     if ((evID = _ev_link(EV_NAME)) == -1)
  33.         exit(1);
  34.  
  35.     DWSet(STDOUT, 0xFF, 0, 0, 1, 1, 0, 0, 0);
  36.     CurOff(STDOUT);
  37.     BackWin(STDOUT);
  38.  
  39.     if (_gs_currscr(STDOUT,&orgwin) == -1)
  40.         exit(0);
  41.     
  42.     copy_window(orgwin);
  43.  
  44.     sigmask(0);                    /* unmask signals */
  45.     _ev_set(evID, 0, 0x8000);    /* wake up everybody */
  46.  
  47.     /* we unlink from the event since we are through with it */
  48.     _ev_unlink(evID);
  49.  
  50.     while(!sigcode)
  51.     {
  52.         if (gotosleep)
  53.             sleep(0);
  54.         else
  55.             dissolve();
  56.     }
  57. }
  58.  
  59. copy_window(devnum)
  60. int devnum;
  61. {
  62.     SCINFO sc;
  63.     char devname[32];
  64.     int  devpath;
  65.     char *scrn, *this_scrn;
  66.     int  i;
  67.     int  lines_to_copy, bytes_to_copy;
  68.     int  bytes_per_scanline, total_scan_lines;
  69.     int  max_x_pixel_coord, bits_per_pixel;
  70.     int  max_colors, pixels_per_byte;
  71.  
  72.     if (devnum == 0)
  73.         sprintf(devname,"/term");
  74.     else
  75.         sprintf(devname,"/w%d",devnum);
  76.  
  77.     /* get info on the parent device screen */
  78.     _gs_scinfo(STDOUT,&sc);
  79.  
  80.     if ((devpath = open(devname,1)) == -1)
  81.         exit (errno);
  82.  
  83.     if (_gs_palette(devpath,0,pal,256) == -1)
  84.         exit (errno);
  85.     
  86.     close (devpath);
  87.     
  88.     /* Now, let's get the information...           */
  89.     scrn = sc.sd_address;
  90.     pixels_per_byte = sc.sd_bitsperpixel;    /* this can be most useful. */
  91.     bytes_per_scanline = sc.sd_phy_width;
  92.     total_scan_lines = sc.sd_max_y;
  93.     max_x_pixel_coord = sc.sd_max_x;
  94.     max_colors = 1 << sc.sd_bitsperpixel;
  95.  
  96.     _ss_select(STDOUT, devnum);            /* now select it! */
  97.  
  98.     if (max_colors == 16)
  99.     {
  100.         DWEnd(STDOUT);
  101.         DWSet(STDOUT, 0, 0, 0, 80, 26, 0, 0, 0);
  102.     }
  103.     else
  104.     {
  105.         DWEnd(STDOUT);
  106.         DWSet(STDOUT, 3, 0, 0, 40, 26, 0, 0, 0);
  107.     }
  108.     CurOff(STDOUT);
  109.     BColor(STDOUT, 0);
  110.  
  111.     this_scrn = _gs_scadd(STDOUT);
  112.     lines_to_copy = (total_scan_lines > 208) ? 208 : total_scan_lines;
  113.     bytes_to_copy = (sc.sd_phy_width > 320) ? 320 : sc.sd_phy_width; 
  114.     
  115.     /* warning BIG-TIME CHEAT!!! */
  116.     for (i = 0; i <= lines_to_copy; i++)
  117.     {
  118.         memcpy(&this_scrn[i * 320],&scrn[i * bytes_per_scanline],bytes_to_copy);
  119.     }
  120.     _ss_palette(STDOUT,0,pal,256);
  121.     _gs_wdev(STDOUT, &win);            /* get our window device number */
  122.     _ss_select(STDOUT, win);        /* now select it! */
  123.  
  124.     ScaleSw(STDOUT,1);
  125.  
  126.     srand(time(0));
  127.  
  128.     /* reset the draw pointer */
  129.     SetDPtr(STDOUT,0,0);
  130. }
  131.  
  132. dissolve()
  133. {
  134.     RPoint(STDOUT,rand() % 640,rand() % 208);
  135.     tsleep(2);
  136. }
  137.  
  138. sighandler(signal)
  139. int signal;
  140. {
  141.     switch(signal) {
  142.     case SLEEP_SIG:
  143.         gotosleep = TRUE;
  144.         break;
  145.     case WAKE_SIG:
  146.         gotosleep = FALSE;
  147.         break;
  148.     case QUIT_SIG:
  149.     default:
  150.         gotosleep = FALSE;
  151.         sigcode=signal;
  152.         if (_gs_currscr(STDOUT,&twin) == -1)
  153.             exit(0);
  154.         if (twin == win) {
  155.             _ss_select(STDOUT, orgwin);
  156.         }
  157.     }
  158. }
  159.  
  160. /*
  161.  * A very random generator, period approx 6.8064e16.
  162.  * 
  163.  * Uses algorithm M, "Art of Computer Programming", Vol 2. 1969, D.E.Knuth.
  164.  * 
  165.  * Two generators are used to derive the high and low parts of sequence X, and
  166.  * another for sequence Y. These were derived by Michael Mauldin.
  167.  * 
  168.  * Usage:  initialize by calling srand(seed), then rand() returns a random
  169.  * number from 0..2147483647. srand(0) uses the current time as the seed.
  170.  * 
  171.  * Author: Michael Mauldin, June 14, 1983. adapted to OS-9/68000 C-Library by
  172.  * Christian Engel, Sat Oct 17 01:39:27 1987
  173.  */
  174.  
  175. /*
  176. ** time () called with NULL argument and <stdio.h> included
  177. ** randint (non ANSI) commented
  178. ** AM 20/12/90
  179. */
  180.  
  181. #ifndef NULL
  182. #include <stdio.h>
  183. #endif
  184.  
  185. /*
  186.  * Rand 1, period length 444674
  187.  */
  188. #define MUL1  1156
  189. #define OFF1  312342
  190. #define MOD1  1334025
  191. #define RAND1 (seed1=((seed1*MUL1+OFF1)%MOD1))
  192. #define Y     RAND1
  193.  
  194. /*
  195.  * Rand 2, period length 690709
  196.  */
  197. #define MUL2  1366
  198. #define OFF2  827291
  199. #define MOD2  1519572
  200. #define RAND2 (seed2=((seed2*MUL2+OFF2)%MOD2))
  201.  
  202. /*
  203.  * Rand 3, period length 221605
  204.  */
  205. #define MUL3  1156
  206. #define OFF3  198273
  207. #define MOD3  1329657
  208. #define RAND3 (seed3=((seed3*MUL3+OFF3)%MOD3))
  209.  
  210. /*
  211.  * RAND2 generates 19 random bits, RAND3 generates 17. The X sequence is made
  212.  * up off both, and thus has 31 random bits.
  213.  */
  214.  
  215. #define X ((RAND2<<13 ^ RAND3>>3) & 017777777777)
  216.  
  217. #define AUXLEN 97
  218.  
  219. static int seed1 = 872978, seed2 = 518652, seed3 = 226543;
  220. static int auxtab[AUXLEN];
  221.  
  222. /*
  223.  * s r a n d
  224.  */
  225. srand(seed)
  226. int seed;
  227. {
  228.   register int i;
  229.  
  230.   if (seed == 0)
  231.     seed = time(NULL);
  232.  
  233.   /*
  234.    * Set the three random number seeds
  235.    */
  236.   seed1 = (seed1 + seed) % MOD1;
  237.   seed2 = (seed2 + seed) % MOD2;
  238.   seed3 = (seed3 + seed) % MOD3;
  239.  
  240.   for (i = AUXLEN; i--;)
  241.     auxtab[i] = X;
  242. }
  243.  
  244. /*
  245.  * r a n d
  246.  */
  247. int rand()
  248. {
  249.   register int j, result;
  250.  
  251.   j = AUXLEN * Y / MOD1;    /* j random from 0..AUXLEN-1 */
  252.   result    = auxtab[j];
  253.   auxtab[j] = X;
  254.  
  255.   return(result);
  256. }
  257.  
  258.  
  259.  
  260.