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 >
Wrap
C/C++ Source or Header
|
1995-11-02
|
3KB
|
145 lines
/* saver_mw.c */
/* A screen-saver program for use with SSaver, */
/* by Boisy G. Pitre */
/* This program works on a 256-color screen */
#include <stdio.h>
#include <modes.h>
#include <types.h>
#include "saver.h"
int orgwin, win, twin;
int sighandler(); /* this will use a signal handler function */
int sigcode = 0; /* storage to keep received signal(s) */
int gotosleep = FALSE;
int max_pixels, max_lines;
int dx, dy;
int x, y;
int pid;
extern char object_microware;
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, 3, 0, 0, 40, 26, 0, 0, 0);
if (_gs_currscr(STDOUT,&orgwin) == -1)
exit(0);
CurOff(STDOUT);
BColor(STDOUT, 0);
_gs_wdev(STDOUT, &win); /* get our window device number */
_ss_select(STDOUT, win); /* now select it! */
init_saver();
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
draw_logo();
}
cleanup();
}
init_saver()
{
char *buf = &object_microware;
/* graphics scaling off */
ScaleSw(STDOUT,0);
_gs_scsz(STDOUT,&max_pixels,&max_lines);
max_pixels <<= 3; /* max_pixels is how many pixels wide the screen is */
max_lines <<= 3; /* max_lines is how many pixels deep the screen is */
pid = getpid(); /* get process-id for unique kwgroup */
KilBuf(STDOUT,pid,0); /* make sure our group is free */
/* load our graphics data */
GPLoad(STDOUT, pid, 1, 3, 208, 28, 208 * 28);
write(STDOUT, buf + 7, 5824);
/* start location & direction of our logo */
x = 50;
y = 20;
dx = 2;
dy = 1;
}
draw_logo()
{
/* put logo on screen */
PutBlk(STDOUT,pid,1,x,y);
/* move logo according to directionals */
x += dx;
y += dy;
/* now, boundary check... */
if (x <= 1) {
dx = -dx; /* bounce */
}
if (x >= (max_pixels - 208)) {
dx = -dx; /* bounce */
}
if (y <= 1) {
dy = -dy; /* bounce */
}
if (y >= (max_lines - 28)) {
dy =- dy; /* bounce */
}
tsleep(5); /* rest -- let user enjoy the view */
}
cleanup()
{
KilBuf(STDOUT,pid,0); /* release our graphics buffer before exiting */
}
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);
}
}
}