Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request From: games-request@tekred.UUCP Newsgroups: mod.sources.games Subject: v01i002: rot - waterfall terminal display Message-ID: <1095@tekred.TEK.COM> Date: Fri, 17-Apr-87 16:25:24 EST Article-I.D.: tekred.1095 Posted: Fri Apr 17 16:25:24 1987 Date-Received: Sat, 18-Apr-87 19:01:50 EST Sender: billr@tekred.TEK.COM Lines: 456 Approved: billr@tekred.TEK.COM Submitted by: seismo!ut-sally!shell!neuro1!hyd-ptd!peter Mod.sources.games: Volume 1, Issue 2 Archive-name: rot [This was originally posted to net.bizarre back in July 1985. I have compiled and run this sucessfully on our 4.3bsd Vax and don't see any particular machine/os dependencies, other than requiring term{lib|cap}. -br ] #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh README <<'END_OF_README' XThis program cascades letters from the top of the terminal screen Xto the bottom in a waterfall effect. There was a note in the Xoriginal posting about this program not working on terminals that Xrequire padding (PC is read but not used). Also, this will be Xpretty slow at lower baudrates. X X-- XOriginal source from: X X Peter da Silva (ihnp4!shell!neuro1!{hyd-ptd,datafact,baylor}!peter) X XMakefile and README from: X X Bill Randle (billr@tekred.TEK.COM) END_OF_README if test 455 -ne `wc -c Makefile <<'END_OF_Makefile' X# Simple makefile for rot program X Xrot: rot.c X cc -O -o rot rot.c -ltermlib X Xtest: rot X rot rot.c <<'END_OF_rot.c' X#include X X/* -- Miscellaneous defines -- */ X#define FALSE 0 X#define TRUE 1 X#define MAXCOL 80 X#define MAXLI 24 X Xextern char *tgetstr(); X Xint lastx, lasty; Xstruct _c { X struct _c *c_next; X int c_line, c_column; X char c_mark; X} *clist; X X/* -- Global variables -- */ Xchar *tent; /* Pointer to tbuf */ Xchar *PC; /* Pad character */ Xchar *UP, *BC; /* Upline, backsapce character */ Xshort ospeed; /* Terminal output speed */ Xint tglen; X Xchar *cm, /* Cursor motion */ X *cl, /* Clear screen */ X *ti, /* Init terminal */ X *te; /* Reset terminal */ Xint li, /* lines on screen */ X co; /* columns ditto */ Xchar screen[MAXLI+1][MAXCOL]; Xchar newscreen[MAXLI+1][MAXCOL]; X Xmain(ac, av) Xint ac; Xchar **av; X{ X srand(getpid()); X tinit(getenv("TERM")); X if(av[1]) X while(*++av) X dropf(*av); X else X fdropf(stdin); X tend(); X} X Xat(x, y, c) Xint x, y; Xchar c; X{ X#ifdef DEBUG X _at(x, y); X#else X if(y==lasty) { X if(x!=lastx) { X if(xlastx && x-lastxlastx) { X putchar(newscreen[lasty][lastx]); X lastx++; X } X else X _at(x, y); X } X } else X _at(x, y); X#endif X c &= ~0200; X putchar(c); X if(c >= ' ' && c != '\177') X lastx++; X if(lastx>=co) { X lastx -= co; X lasty++; X } X} X X_at(x, y) Xint x, y; X{ X outs(tgoto(cm, x, y)); X lastx = x; X lasty = y; X} X Xtinit(name) Xchar *name; X{ X static char junkbuf[1024], *junkptr; X char tbuf[1024]; X int intr(); X X junkptr = junkbuf; X X tgetent(tbuf, name); X X PC = tgetstr("pc", &junkptr); X UP = tgetstr("up", &junkptr); X BC = tgetstr("bc", &junkptr); X cm = tgetstr("cm", &junkptr); X cl = tgetstr("cl", &junkptr); X ti = tgetstr("ti", &junkptr); X te = tgetstr("te", &junkptr); X li = min(tgetnum("li"), MAXLI); X co = min(tgetnum("co"), MAXCOL); X tglen = strlen(tgoto(co-1, li-1)); X} X Xtend() X{ X outs(te); X _at(0, li-1); X putchar('\n'); X fflush(stdout); X} X Xreadscreen(fp) XFILE *fp; X{ X int line, column, p; X char tmp[256]; X X for(line=0; line=co) { X column -= co; X line++; X } X newscreen[line][column] = X (tmp[p]+'@') & 127; X column++; X break; X } X else { X newscreen[line][column] = tmp[p]; X column++; X } X if(column >= co) { X column -= co; X line++; X } X if(line >= li) X break; X } X } X for(column=0; column=li || column<0 || column>=co || X (line>=li-2 && column >= co-1) || /* scroll potential */ X screen[line][column]==' ' || /* empty */ X screen[line][column] & 0200) /* already in list */ X return; X if(screen[line+1][column]!=' ' && X (column==co-1 ||screen[line+1][column+1]!=' ') && X (column==0 ||screen[line+1][column-1]!=' ')) X return; X X hold = (struct _c *) malloc(sizeof(struct _c)); X hold -> c_next = clist; X hold -> c_column = column; X hold -> c_line = line; X hold -> c_mark = 0; X screen[line][column] |= 0200; X clist = hold; X} X Xdrops() X{ X int l, c; X struct _c *hold; X for(hold = clist; hold; hold=hold->c_next) { X int line = hold->c_line, column=hold->c_column; X if(line>= li-2 && column>=co-1) { X newscreen[line][column] &= ~0200; X screen[line][column] &= ~0200; X hold->c_mark = 1; X continue; X } X drop(line+1, column); X drop(line, column+1); X drop(line-1, column); X drop(line, column-1); X if(newscreen[line+1][column]==' ') { X newscreen[line+1][column] = screen[line][column]; X newscreen[line][column] = ' '; X line++; X } else if(rand()&01000) { X if(column>0 && newscreen[line][column-1] == ' ' && X newscreen[line+1][column-1]==' ') { X newscreen[line][column-1] = X screen[line][column]; X newscreen[line][column] = ' '; X column--; X } X else if(column c_mark = 1; X } X } else { X if(column0 && newscreen[line][column-1] == ' ' && X newscreen[line+1][column-1]==' ') { X newscreen[line][column-1] = X screen[line][column]; X newscreen[line][column] = ' '; X column--; X } X else { X newscreen[line][column] &= ~0200; X screen[line][column] &= ~0200; X hold -> c_mark = 1; X } X } X hold -> c_column = column; X hold -> c_line = line; X fflush(stdout); X } X X while(clist && clist->c_mark) { X struct _c *p = clist; X clist = clist -> c_next; X free(p); X } X hold = clist; X while(hold && hold->c_next) X if(hold->c_next->c_mark) { X struct _c *p = hold->c_next; X hold->c_next = p->c_next; X free(p); X } else X hold=hold->c_next; X} X Xdroplet(line, column) Xint line, column; X{ X int ret; X while(column>=0 && screen[line][column]!=' ') X column--; X column++; X while(column=0 && !rubbish; column--) X rubbish += droplet(line, column); X } X } while(rubbish); X} X Xdropf(file) Xchar *file; X{ X FILE *fp; X X if(!(fp = fopen(file, "r"))) { X perror(file); X return -1; X } X fdropf(fp); X} X Xfdropf(fp) XFILE *fp; X{ X int i; X X while(!feof(fp)) { X readscreen(fp); X drawscreen(); X for(i=0; i<20; i++) X droplet((rand()>>4) % li, (rand()>>4) % co); X dropscreen(); X } X} X Xouts(s) Xchar *s; X{ X fputs(s, stdout); X} X Xmin(a, b) Xint a, b; X{ X if(a