cleanup, add manual page
[unix-history] / usr / src / games / worm / worm.c
index cea6da7..1cd46d1 100644 (file)
@@ -1,5 +1,29 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
 
 
-static char sccsid[] = "       worm.c  4.1     82/10/24        ";
+#ifndef lint
+static char sccsid[] = "@(#)worm.c     5.5 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * Worm.  Written by Michael Toy
 
 /*
  * Worm.  Written by Michael Toy
@@ -17,7 +41,10 @@ static char sccsid[] = "     worm.c  4.1     82/10/24        ";
 #define RUNLEN 8
 #define when break;case
 #define otherwise break;default
 #define RUNLEN 8
 #define when break;case
 #define otherwise break;default
-#define CNTRL(p) ('p'-'A'+1)
+#define CNTRL(p) (p-'A'+1)
+#ifndef baudrate
+# define       baudrate()      _tty.sg_ospeed
+#endif
 
 WINDOW *tv;
 WINDOW *stw;
 
 WINDOW *tv;
 WINDOW *stw;
@@ -29,6 +56,7 @@ struct body {
 } *head, *tail, goody;
 int growing = 0;
 int running = 0;
 } *head, *tail, goody;
 int growing = 0;
 int running = 0;
+int slow = 0;
 int score = 0;
 int start_len = LENGTH;
 char lastch;
 int score = 0;
 int start_len = LENGTH;
 char lastch;
@@ -55,6 +83,7 @@ char **argv;
        initscr();
        crmode();
        noecho();
        initscr();
        crmode();
        noecho();
+       slow = (baudrate() <= B1200);
        clear();
        stw = newwin(1, COLS-1, 0, 0);
        tv = newwin(LINES-1, COLS-1, 1, 0);
        clear();
        stw = newwin(1, COLS-1, 0, 0);
        tv = newwin(LINES-1, COLS-1, 1, 0);
@@ -104,7 +133,6 @@ life()
        }
        tail = np;
        tail->prev = NULL;
        }
        tail = np;
        tail->prev = NULL;
-       wrefresh(tv);
 }
 
 display(pos, chr)
 }
 
 display(pos, chr)
@@ -173,9 +201,9 @@ char ch;
                when 'K': y--; running = RUNLEN/2; ch = tolower(ch);
                when 'L': x++; running = RUNLEN; ch = tolower(ch);
                when '\f': setup(); return;
                when 'K': y--; running = RUNLEN/2; ch = tolower(ch);
                when 'L': x++; running = RUNLEN; ch = tolower(ch);
                when '\f': setup(); return;
-               when CNTRL(Z): suspend(); return;
-               when CNTRL(C): crash(); return;
-               when CNTRL(D): crash(); return;
+               when CNTRL('Z'): suspend(); return;
+               when CNTRL('C'): crash(); return;
+               when CNTRL('D'): crash(); return;
                otherwise: if (! running) alarm(1);
                           return;
        }
                otherwise: if (! running) alarm(1);
                           return;
        }
@@ -210,8 +238,10 @@ char ch;
        nh->x = x;
        display(nh, HEAD);
        head = nh;
        nh->x = x;
        display(nh, HEAD);
        head = nh;
-       wrefresh(tv);
-       if (! running) alarm(1);
+       if (!(slow && running))
+               wrefresh(tv);
+       if (!running)
+               alarm(1);
 }
 
 crash()
 }
 
 crash()