boot - Multiple changes to try to make cdboot work with more bioses
[dragonfly.git] / games / trek / main.c
blob5a4cb4565769529866d1b2f5f3fc65c919decb21
1 /*-
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved.
30 * @(#)main.c 8.1 (Berkeley) 5/31/93
31 * $FreeBSD: src/games/trek/main.c,v 1.7.2.1 2001/03/05 12:11:14 kris Exp $
32 * $DragonFly: src/games/trek/main.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
35 #include "trek.h"
36 #include "getpar.h"
38 #define PRIO 00 /* default priority */
40 unsigned int Mother = 51 + (51 << 8);
43 ** #### ##### # #### ##### #### ##### # #
44 ** # # # # # # # # # # # #
45 ** ### # ##### #### # #### ### ###
46 ** # # # # # # # # # # # #
47 ** #### # # # # # # # # ##### # #
49 ** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
50 ** from Jeff Poskanzer and Pete Rubinstein.
52 ** I also want to thank everyone here at Berkeley who
53 ** where crazy enough to play the undebugged game. I want to
54 ** particularly thank Nick Whyte, who made considerable
55 ** suggestions regarding the content of the game. Why, I'll
56 ** never forget the time he suggested the name for the
57 ** "capture" command.
59 ** Please send comments, questions, and suggestions about this
60 ** game to:
61 ** Eric P. Allman
62 ** Project INGRES
63 ** Electronics Research Laboratory
64 ** Cory Hall
65 ** University of California
66 ** Berkeley, California 94720
68 ** If you make ANY changes in the game, I sure would like to
69 ** know about them. It is sort of an ongoing project for me,
70 ** and I very much want to put in any bug fixes and improvements
71 ** that you might come up with.
73 ** FORTRASH version by Kay R. Fisher (DEC) "and countless others".
74 ** That was adapted from the "original BASIC program" (ha!) by
75 ** Mike Mayfield (Centerline Engineering).
77 ** Additional inspiration taken from FORTRAN version by
78 ** David Matuszek and Paul Reynolds which runs on the CDC
79 ** 7600 at Lawrence Berkeley Lab, maintained there by
80 ** Andy Davidson. This version is also available at LLL
81 ** and at LMSC. In all fairness, this version was the
82 ** major inspiration for this version of the game (trans-
83 ** lation: I ripped off a whole lot of code).
85 ** Minor other input from the "Battelle Version 7A" by Joe Miller
86 ** (Graphics Systems Group, Battelle-Columbus Labs) and
87 ** Ross Pavlac (Systems Programmer, Battelle Memorial
88 ** Institute). That version was written in December '74
89 ** and extensively modified June '75. It was adapted
90 ** from the FTN version by Ron Williams of CDC Sunnyvale,
91 ** which was adapted from the Basic version distributed
92 ** by DEC. It also had "neat stuff swiped" from T. T.
93 ** Terry and Jim Korp (University of Texas), Hicks (Penn
94 ** U.), and Rick Maus (Georgia Tech). Unfortunately, it
95 ** was not as readable as it could have been and so the
96 ** translation effort was severely hampered. None the
97 ** less, I got the idea of inhabited starsystems from this
98 ** version.
100 ** Permission is given for use, copying, and modification of
101 ** all or part of this program and related documentation,
102 ** provided that all reference to the authors are maintained.
105 **********************************************************************
107 ** NOTES TO THE MAINTAINER:
109 ** There is a compilation option xTRACE which must be set for any
110 ** trace information to be generated. It is probably defined in
111 ** the version that you get. It can be removed, however, if you
112 ** have trouble finding room in core.
114 ** Many things in trek are not as clear as they might be, but are
115 ** done to reduce space. I compile with the -f and -O flags. I
116 ** am constrained to running with non-separated I/D space, since
117 ** we don't have doubleing point hardware here; even if we did, I
118 ** would like trek to be available to the large number of people
119 ** who either have an 11/40 or do not have FP hardware. I also
120 ** found it desirable to make the code run reentrant, so this
121 ** added even more space constraints.
123 ** I use the portable C library to do my I/O. This is done be-
124 ** cause I wanted the game easily transportable to other C
125 ** implementations, and because I was too lazy to do the doubleing
126 ** point input myself. Little did I know. The portable C library
127 ** released by Bell Labs has more bugs than you would believe, so
128 ** I ended up rewriting the whole blessed thing. Trek exercises
129 ** many of the bugs in it, as well as bugs in some of the section
130 ** III UNIX routines. We have fixed them here. One main problem
131 ** was a bug in alloc() that caused it to always ask for a large
132 ** hunk of memory, which worked fine unless you were almost out,
133 ** which I inevitably was. If you want the code for all of this
134 ** stuff, it is also available through me.
136 ***********************************************************************
139 jmp_buf env;
142 main(int argc, char **argv)
144 #if 0
145 extern FILE *f_log;
146 #endif
147 char opencode;
148 int prio;
149 int ac;
150 char **av;
152 /* Revoke setgid privileges */
153 setgid(getgid());
155 av = argv;
156 ac = argc;
157 av++;
158 srandomdev();
159 opencode = 'w';
160 prio = PRIO;
162 while (ac > 1 && av[0][0] == '-') {
163 switch (av[0][1]) {
164 case 'a': /* append to log file */
165 opencode = 'a';
166 break;
168 #ifdef xTRACE
169 case 't': /* trace */
170 if (getuid() != Mother)
171 goto badflag;
172 Trace++;
173 break;
174 #endif
176 case 'p': /* set priority */
177 if (getuid() != Mother)
178 goto badflag;
179 prio = atoi(av[0] + 2);
180 break;
182 default:
183 badflag:
184 printf("Invalid option: %s\n", av[0]);
187 ac--;
188 av++;
190 if (ac > 2)
191 syserr(0, "arg count");
192 #if 0
193 if (ac > 1)
194 f_log = fopen(av[0], opencode);
195 #endif
197 printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n");
199 if (setjmp(env)) {
200 if ( !getynpar("Another game") )
201 exit(0);
203 do {
204 setup();
205 play();
206 } while (getynpar("Another game"));
208 fflush(stdout);
209 return (0);