home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
MM1
/
GRAPHICS
/
kwsaver25.lzh
/
programmer.lzh
/
kwsaver_mm1s.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-05
|
3KB
|
99 lines
/* kwsaver_mm1s.c */
/* A screen-saver program for use with KWSaver, */
/* by Joel Mathew Hegberg. */
/* This program works only with 16-color screens, */
/* since that's what the raw graphics data is */
/* formatted for. If used on a 256-color screen, */
/* only a black screen is shown. */
/* NOTE: This program uses a K-Windows graphic buffer, which */
/* must be killed before exiting (or else the memory */
/* used by the buffer will not be returned to the */
/* system), so a signal trap (handler) is implemented */
/* to detect when it's time to exit. */
#include <stdio.h>
#include "kwsaver_mm1s.h" /* contains our graphics data */
#define PATH 1
extern int sighandler(); /* this will use a signal handler function */
int sigcode=0; /* storage to keep received signal(s) */
main()
{
int x,y,dx,dy,pid,max_pixels,max_lines,temp;
intercept(sighandler); /* install signal handler */
temp=Get_Num_Colors(PATH); /* Is this a 16-color screen? */
if (temp!=16) /* if not 16-color, just show black screen */
{
do_nothing();
exit(0);
}
_gs_scsz(PATH,&max_pixels,&max_lines);
max_pixels*=8; /* max_pixels is how many pixels wide the screen is */
max_lines*=8; /* max_lines is how many pixels deep the screen is */
pid=getpid(); /* get process-id for unique kwgroup */
loadbuff(PATH,pid,1,16,17,smallmm1_icon); /* load our graphics data */
x=50; y=20; dx=2; dy=1; /* start location & direction of our logo */
ScaleSw(PATH,0); /* graphics scaling off */
while(!sigcode) /* loop until signal has been received */
{
PutBlk(PATH,pid,1,x,y); /* put logo on screen */
tsleep(5); /* rest -- let user enjoy the view */
x+=dx; y+=dy; /* move logo according to directionals */
/* now, boundary check... */
if (x<=1) dx=-dx; /* bounce */
if (x>=(max_pixels-34)) dx=-dx; /* bounce */
if (y<=1) dy=-dy; /* bounce */
if (y>=(max_lines-19)) dy=-dy; /* bounce */
}
KilBuf(PATH,pid,1); /* release our graphics buffer before exiting */
}
do_nothing()
{
sleep(0); /* sleep until a signal is received */
}
/* loadbuff loads in graphics data into a K-Windows buffer */
loadbuff(pth,grp,buf,xsiz,ysiz,data)
int pth,grp,buf,xsiz,ysiz;
char *data;
{
char chr;
write(pth,"\x1b\x2b",2);
chr=(char)grp;
write(pth,&chr,1);
chr=(char)buf;
write(pth,&chr,1);
write(pth,"\x08",1);
chr=(char)((xsiz*2)/256);
write(pth,&chr,1);
chr=(char)((xsiz*2)&255);
write(pth,&chr,1);
chr=(char)(ysiz/256);
write(pth,&chr,1);
chr=(char)(ysiz&255);
write(pth,&chr,1);
chr=(char)((xsiz*ysiz)/256);
write(pth,&chr,1);
chr=(char)((xsiz*ysiz)&255);
write(pth,&chr,1);
write(pth,data,xsiz*ysiz);
}
sighandler(signal)
int signal;
{
sigcode=signal;
}