Commit | Line | Data |
---|---|---|
c8df485c KM |
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 | |
df5a607f | 8 | static char sccsid[] = "@(#)twinkle2.c 6.1 (Berkeley) %G%"; |
c8df485c KM |
9 | #endif not lint |
10 | ||
df5a607f | 11 | extern int _putchar(); |
c8df485c | 12 | |
df5a607f KM |
13 | main() |
14 | { | |
c8df485c | 15 | reg char *sp; |
c8df485c KM |
16 | |
17 | srand(getpid()); /* initialize random sequence */ | |
18 | ||
19 | if (isatty(0)) { | |
20 | gettmode(); | |
df5a607f | 21 | if ((sp = getenv("TERM")) != NULL) |
c8df485c KM |
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 | ||
c8df485c | 42 | puton(ch) |
df5a607f KM |
43 | char ch; |
44 | { | |
c8df485c KM |
45 | reg LOCS *lp; |
46 | reg int r; | |
47 | reg LOCS *end; | |
48 | LOCS temp; | |
df5a607f | 49 | static int lasty, lastx; |
c8df485c KM |
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 | } |