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 >
Wrap
C/C++ Source or Header
|
1995-04-16
|
5KB
|
260 lines
/* saver_dissolve.c - dissolve current screen */
#include <stdio.h>
#include <modes.h>
#include <types.h>
#include <wind.h>
#include <time.h>
#include "saver.h"
int orgwin;
int win;
int twin;
int gotosleep = FALSE;
int sigcode = 0; /* storage to keep received signal(s) */
int sighandler(); /* this will use a signal handler function */
char pal[768];
extern char *_gs_scadd();
extern int errno;
main()
{
int evID; /* event ID */
sigmask(1); /* mask signals */
intercept(sighandler); /* install signal handler */
if ((evID = _ev_link(EV_NAME)) == -1)
exit(1);
DWSet(STDOUT, 0xFF, 0, 0, 1, 1, 0, 0, 0);
CurOff(STDOUT);
BackWin(STDOUT);
if (_gs_currscr(STDOUT,&orgwin) == -1)
exit(0);
copy_window(orgwin);
sigmask(0); /* unmask signals */
_ev_set(evID, 0, 0x8000); /* wake up everybody */
/* we unlink from the event since we are through with it */
_ev_unlink(evID);
while(!sigcode)
{
if (gotosleep)
sleep(0);
else
dissolve();
}
}
copy_window(devnum)
int devnum;
{
SCINFO sc;
char devname[32];
int devpath;
char *scrn, *this_scrn;
int i;
int lines_to_copy, bytes_to_copy;
int bytes_per_scanline, total_scan_lines;
int max_x_pixel_coord, bits_per_pixel;
int max_colors, pixels_per_byte;
if (devnum == 0)
sprintf(devname,"/term");
else
sprintf(devname,"/w%d",devnum);
/* get info on the parent device screen */
_gs_scinfo(STDOUT,&sc);
if ((devpath = open(devname,1)) == -1)
exit (errno);
if (_gs_palette(devpath,0,pal,256) == -1)
exit (errno);
close (devpath);
/* Now, let's get the information... */
scrn = sc.sd_address;
pixels_per_byte = sc.sd_bitsperpixel; /* this can be most useful. */
bytes_per_scanline = sc.sd_phy_width;
total_scan_lines = sc.sd_max_y;
max_x_pixel_coord = sc.sd_max_x;
max_colors = 1 << sc.sd_bitsperpixel;
_ss_select(STDOUT, devnum); /* now select it! */
if (max_colors == 16)
{
DWEnd(STDOUT);
DWSet(STDOUT, 0, 0, 0, 80, 26, 0, 0, 0);
}
else
{
DWEnd(STDOUT);
DWSet(STDOUT, 3, 0, 0, 40, 26, 0, 0, 0);
}
CurOff(STDOUT);
BColor(STDOUT, 0);
this_scrn = _gs_scadd(STDOUT);
lines_to_copy = (total_scan_lines > 208) ? 208 : total_scan_lines;
bytes_to_copy = (sc.sd_phy_width > 320) ? 320 : sc.sd_phy_width;
/* warning BIG-TIME CHEAT!!! */
for (i = 0; i <= lines_to_copy; i++)
{
memcpy(&this_scrn[i * 320],&scrn[i * bytes_per_scanline],bytes_to_copy);
}
_ss_palette(STDOUT,0,pal,256);
_gs_wdev(STDOUT, &win); /* get our window device number */
_ss_select(STDOUT, win); /* now select it! */
ScaleSw(STDOUT,1);
srand(time(0));
/* reset the draw pointer */
SetDPtr(STDOUT,0,0);
}
dissolve()
{
RPoint(STDOUT,rand() % 640,rand() % 208);
tsleep(2);
}
sighandler(signal)
int signal;
{
switch(signal) {
case SLEEP_SIG:
gotosleep = TRUE;
break;
case WAKE_SIG:
gotosleep = FALSE;
break;
case QUIT_SIG:
default:
gotosleep = FALSE;
sigcode=signal;
if (_gs_currscr(STDOUT,&twin) == -1)
exit(0);
if (twin == win) {
_ss_select(STDOUT, orgwin);
}
}
}
/*
* A very random generator, period approx 6.8064e16.
*
* Uses algorithm M, "Art of Computer Programming", Vol 2. 1969, D.E.Knuth.
*
* Two generators are used to derive the high and low parts of sequence X, and
* another for sequence Y. These were derived by Michael Mauldin.
*
* Usage: initialize by calling srand(seed), then rand() returns a random
* number from 0..2147483647. srand(0) uses the current time as the seed.
*
* Author: Michael Mauldin, June 14, 1983. adapted to OS-9/68000 C-Library by
* Christian Engel, Sat Oct 17 01:39:27 1987
*/
/*
** time () called with NULL argument and <stdio.h> included
** randint (non ANSI) commented
** AM 20/12/90
*/
#ifndef NULL
#include <stdio.h>
#endif
/*
* Rand 1, period length 444674
*/
#define MUL1 1156
#define OFF1 312342
#define MOD1 1334025
#define RAND1 (seed1=((seed1*MUL1+OFF1)%MOD1))
#define Y RAND1
/*
* Rand 2, period length 690709
*/
#define MUL2 1366
#define OFF2 827291
#define MOD2 1519572
#define RAND2 (seed2=((seed2*MUL2+OFF2)%MOD2))
/*
* Rand 3, period length 221605
*/
#define MUL3 1156
#define OFF3 198273
#define MOD3 1329657
#define RAND3 (seed3=((seed3*MUL3+OFF3)%MOD3))
/*
* RAND2 generates 19 random bits, RAND3 generates 17. The X sequence is made
* up off both, and thus has 31 random bits.
*/
#define X ((RAND2<<13 ^ RAND3>>3) & 017777777777)
#define AUXLEN 97
static int seed1 = 872978, seed2 = 518652, seed3 = 226543;
static int auxtab[AUXLEN];
/*
* s r a n d
*/
srand(seed)
int seed;
{
register int i;
if (seed == 0)
seed = time(NULL);
/*
* Set the three random number seeds
*/
seed1 = (seed1 + seed) % MOD1;
seed2 = (seed2 + seed) % MOD2;
seed3 = (seed3 + seed) % MOD3;
for (i = AUXLEN; i--;)
auxtab[i] = X;
}
/*
* r a n d
*/
int rand()
{
register int j, result;
j = AUXLEN * Y / MOD1; /* j random from 0..AUXLEN-1 */
result = auxtab[j];
auxtab[j] = X;
return(result);
}