162779Sbostic .\" Copyright (c) 1980, 1993 262779Sbostic .\" The Regents of the University of California. All rights reserved. 348164Sbostic .\" 448164Sbostic .\" %sccs.include.redist.roff% 548164Sbostic .\" 6*62780Sbostic .\" @(#)twinkle2.c 8.1 (Berkeley) 06/08/93 748164Sbostic .\" 827339Smckusick extern int _putchar(); 927337Smckusick 1027339Smckusick main() 1127339Smckusick { 1227337Smckusick reg char *sp; 1327337Smckusick 1427337Smckusick srand(getpid()); /* initialize random sequence */ 1527337Smckusick 1627337Smckusick if (isatty(0)) { 1727337Smckusick gettmode(); 1827339Smckusick if ((sp = getenv("TERM")) != NULL) 1927337Smckusick setterm(sp); 2027337Smckusick signal(SIGINT, die); 2127337Smckusick } 2227337Smckusick else { 2327337Smckusick printf("Need a terminal on %d\n", _tty_ch); 2427337Smckusick exit(1); 2527337Smckusick } 2627337Smckusick _puts(TI); 2727337Smckusick _puts(VS); 2827337Smckusick 2927337Smckusick noecho(); 3027337Smckusick nonl(); 3127337Smckusick tputs(CL, NLINES, _putchar); 3227337Smckusick for (;;) { 3327337Smckusick makeboard(); /* make the board setup */ 3427337Smckusick puton('*'); /* put on '*'s */ 3527337Smckusick puton(' '); /* cover up with ' 's */ 3627337Smckusick } 3727337Smckusick } 3827337Smckusick 3927337Smckusick puton(ch) 4027339Smckusick char ch; 4127339Smckusick { 4227337Smckusick reg LOCS *lp; 4327337Smckusick reg int r; 4427337Smckusick reg LOCS *end; 4527337Smckusick LOCS temp; 4627339Smckusick static int lasty, lastx; 4727337Smckusick 4827337Smckusick end = &Layout[Numstars]; 4927337Smckusick for (lp = Layout; lp < end; lp++) { 5027337Smckusick r = rand() % Numstars; 5127337Smckusick temp = *lp; 5227337Smckusick *lp = Layout[r]; 5327337Smckusick Layout[r] = temp; 5427337Smckusick } 5527337Smckusick 5627337Smckusick for (lp = Layout; lp < end; lp++) 5727337Smckusick /* prevent scrolling */ 5827337Smckusick if (!AM || (lp->y < NLINES - 1 || lp->x < NCOLS - 1)) { 5927337Smckusick mvcur(lasty, lastx, lp->y, lp->x); 6027337Smckusick putchar(ch); 6127337Smckusick lasty = lp->y; 6227337Smckusick if ((lastx = lp->x + 1) >= NCOLS) 6327337Smckusick if (AM) { 6427337Smckusick lastx = 0; 6527337Smckusick lasty++; 6627337Smckusick } 6727337Smckusick else 6827337Smckusick lastx = NCOLS - 1; 6927337Smckusick } 7027337Smckusick } 71