1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#)twinkle2.c	6.1 (Berkeley) 04/24/86";
9 #endif not lint
10 
11 extern int	_putchar();
12 
13 main()
14 {
15 	reg char	*sp;
16 
17 	srand(getpid());		/* initialize random sequence */
18 
19 	if (isatty(0)) {
20 	       gettmode();
21 	       if ((sp = getenv("TERM")) != NULL)
22 		       setterm(sp);
23 		signal(SIGINT, die);
24 	}
25 	else {
26 		printf("Need a terminal on %d\n", _tty_ch);
27 		exit(1);
28 	}
29 	_puts(TI);
30 	_puts(VS);
31 
32 	noecho();
33 	nonl();
34 	tputs(CL, NLINES, _putchar);
35 	for (;;) {
36 		makeboard();		/* make the board setup */
37 		puton('*');		/* put on '*'s */
38 		puton(' ');		/* cover up with ' 's */
39 	}
40 }
41 
42 puton(ch)
43 char	ch;
44 {
45 	reg LOCS	*lp;
46 	reg int		r;
47 	reg LOCS	*end;
48 	LOCS		temp;
49 	static int	lasty, lastx;
50 
51 	end = &Layout[Numstars];
52 	for (lp = Layout; lp < end; lp++) {
53 		r = rand() % Numstars;
54 		temp = *lp;
55 		*lp = Layout[r];
56 		Layout[r] = temp;
57 	}
58 
59 	for (lp = Layout; lp < end; lp++)
60 			/* prevent scrolling */
61 		if (!AM || (lp->y < NLINES - 1 || lp->x < NCOLS - 1)) {
62 			mvcur(lasty, lastx, lp->y, lp->x);
63 			putchar(ch);
64 			lasty = lp->y;
65 			if ((lastx = lp->x + 1) >= NCOLS)
66 				if (AM) {
67 					lastx = 0;
68 					lasty++;
69 				}
70 				else
71 					lastx = NCOLS - 1;
72 		}
73 }
74