[net.micro.amiga] How To Space Out

ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) (07/02/86)

[ Line eating bugs go out on strike!  Massive sanity prevails! ]

	This is a crock.  This is only a crock.  If this had been a real
program, you would probably have written it yourself.

	I hacked this up this afternoon and thought it looked sorta neat.
I suspect it will acutally hold your attention for at least five seconds.
Trust me, it looks good.

	Yes, I know, it's heavily uncommented.  If you'd like an explanation
of what I'm doing, mail me and I'll try to confuse you more :-).

					Have phun,
					Schwab

################# Do **NOT** cut here  #####################################
################# Cut here instead :-) #####################################
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	stars.readme
#	stars.c
#	rnd.s
# This archive created: Tue Jul  1 02:58:30 1986
# By:	Leo 'Bols Ewhac' Schwab ()
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'stars.readme'
then
	echo shar: "will not over-write existing file 'stars.readme'"
else
cat << \SHAR_EOF > 'stars.readme'
	How to make this beastie:

	This has been written for the Manx C compiler and assembler.
Conversion to Lettuce C should be trivial, although I haven't tried it.
The following commands make the program (look, ma, no 32-bit ints!):

1> cc stars.c
1> as rnd.s
1> ln stars.o rnd.o -lc -o stars

--------
	Usage:

SYNOPSIS
	stars {magic} {warpfactor}

DESCRIPTION
	MAGIC is a magic number that controls the field of view.  The
smaller the number, the wider the field of view.  Default is 256.
Anything below 50 looks kinda ridiculous.

	WARPFACTOR is the speed at which stars come at you.  Default speed
is three.
--------

	I hope you enjoy spacing out on this :-)!

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 ________                ___
           \            /___--__                Leo L. Schwab
  ___  ___ /\               ---##\              ihnp4!ptsfa!well!ewhac
      /   X  \_____    |  __ _---))                      ..or..
     /   /_\--    -----+==____\ // \  _         well ---\
___ (   o---+------------------O/   \/ \        dual ----> !unicom!ewhac
     \     /                ___ \_  (`o )       hplabs -/       ("AE-wack")
 ____ \___/                          \_/
              Recumbent Bikes:                  "Work FOR?  I don't work FOR
            The _O_n_l_y Way To Fly!                anybody!  I'm just having fun."
SHAR_EOF
fi
if test -f 'stars.c'
then
	echo shar: "will not over-write existing file 'stars.c'"
else
cat << \SHAR_EOF > 'stars.c'
/*  :ts=8
 * stars.c:  An attmept to fight boredom (yet again).
 * by Leo L. Schwab   8606.30
 */

#include <exec/types.h>
#include <intuition/intuition.h>

#define NSTARS		64

extern void *OpenLibrary(), *OpenScreen(), *OpenWindow(), *GetMsg();
extern short rnd();

long *IntuitionBase, *GfxBase;

struct NewScreen scrdef = {
	0, 0, 320, 200,
	4,		/*  # planes  */
	-1, -1,
	NULL,
	CUSTOMSCREEN,
	NULL, NULL, NULL, NULL
};

struct NewWindow windef = {
	0, 0, 320, 200,
	-1, -1,
	CLOSEWINDOW,
	WINDOWCLOSE,
	NULL, NULL, NULL, NULL, NULL,
	0, 0, 0, 0,
	CUSTOMSCREEN
};

struct Window *win;
struct Screen *scr;
struct RastPort *rp;
short x[NSTARS], y[NSTARS], z[NSTARS];
short xo[NSTARS], yo[NSTARS];


main (ac, av)
char *av[];
int ac;
{
	long xs, ys;
	long *msg;
	short magic;
	register short i, inc;

	if (ac > 1)
		magic = atoi (av[1]);
	else
		magic = 256;

	if (ac > 2)
		inc = atoi (av[2]);
	else
		inc = 3;

	openstuff ();
	rnd (-5286);
	SetRast (rp, 0L);
	for (xs=0; xs<16; xs++)
		SetRGB4 (&(scr -> ViewPort), xs, xs, xs, xs);

	for (i=0; i<NSTARS; i++)
		mkpoint (i);

	FOREVER {
		for (i=0; i<NSTARS; i++) {
			if ((z[i] -= inc) <= 0)
				mkpoint (i);
			xs = x[i] * magic / z[i] + 160;
			ys = y[i] * magic / z[i] + 100;
			SetAPen (rp, 0L);
			WritePixel (rp, (long) xo[i], (long) yo[i]);
			if (xs < 0 || xs > 319 || ys < 0 || ys > 199)
				mkpoint (i);
			else {
				SetAPen (rp, (long) (256-z[i] >> 4));
				WritePixel (rp, xs, ys);
				xo[i] = xs;  yo[i] = ys;
			}
		}
		if (msg = GetMsg (win -> UserPort)) {
			ReplyMsg (msg);
			break;
		}
	}

	closestuff ();
}

mkpoint (i)
register short i;
{
	x[i] = rnd (256) - 128;
	y[i] = rnd (150) - 75;
	z[i] = 255;
}

openstuff ()
{
	if (!(IntuitionBase = OpenLibrary ("intuition.library", 0L))) {
		printf ("Intuition open failed.\n");
		die ();
	}

	if (!(GfxBase = OpenLibrary ("graphics.library", 0L))) {
		printf ("graphics open failed.\n");
		die ();
	}

	if (!(scr = OpenScreen (&scrdef))) {
		printf ("Can't open screen.\n");
		die ();
	}

	windef.Screen = scr;
	if (!(win = OpenWindow (&windef))) {
		printf ("Window painted shut.\n");
		die ();
	}
	rp = &(scr -> RastPort);
}

closestuff ()
{
	if (win)		CloseWindow  (win);
	if (scr)		CloseScreen  (scr);
	if (GfxBase)		CloseLibrary (GfxBase);
	if (IntuitionBase)	CloseLibrary (IntuitionBase);
}

die ()
{
	closestuff ();
	exit (-1);
}
SHAR_EOF
fi
if test -f 'rnd.s'
then
	echo shar: "will not over-write existing file 'rnd.s'"
else
cat << \SHAR_EOF > 'rnd.s'
*\
*  :ts=8
* Yet Another random number generator.  By Leo Schwab.
* Based on an idea posted on the USENET (Thanks, Sam Dicker!)
* For the Manx assembler.
*
* Calling convention:
*  short rnd (range);
*  short range;
*
* 8606.30
*/

		public    _rnd

_rnd		lea	rndseed,a0	Get address of seed
		move.w	4(sp),d1	Get range argument
		tst.w	d1
		ble.s	setseed		Go reset seed


		move.l	(a0),d0		Get seed
		ADD.L   D0,D0
		BHI.S   over
		EORI.L  #$1D872B41,D0
over
		move.l	d0,(a0)		Save new seed
		andi.l	#$ffff,d0	Coerce into word
		divu	d1,d0		Divide by range
		swap	d0		 and get remainder (modulus)
		rts

setseed		neg.w	d1		Probably don't need this
		move.l	d1,(a0)
		rts

		dseg
rndseed		dc.l	0
		cseg
SHAR_EOF
fi
exit 0
#	End of shell archive