125993Smckusick /* 225993Smckusick * Copyright (c) 1980 Regents of the University of California. 334205Sbostic * All rights reserved. 434205Sbostic * 534205Sbostic * Redistribution and use in source and binary forms are permitted 634205Sbostic * provided that this notice is preserved and that due credit is given 734205Sbostic * to the University of California at Berkeley. The name of the University 834205Sbostic * may not be used to endorse or promote products derived from this 934205Sbostic * software without specific prior written permission. This software 1034205Sbostic * is provided ``as is'' without express or implied warranty. 1125993Smckusick */ 1225993Smckusick 1311683Smckusick #ifndef lint 1425993Smckusick char copyright[] = 1525993Smckusick "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 1625993Smckusick All rights reserved.\n"; 1734205Sbostic #endif /* not lint */ 1811683Smckusick 1925993Smckusick #ifndef lint 20*34591Sbostic static char sccsid[] = "@(#)main.c 5.3 (Berkeley) 06/01/88"; 2134205Sbostic #endif /* not lint */ 2225993Smckusick 2311683Smckusick # include "trek.h" 2412738Slayer # include <stdio.h> 2512738Slayer # include <sgtty.h> 2612738Slayer # define PRIO 00 /* default priority */ 2711683Smckusick 2812738Slayer int Mother = 51 + (51 << 8); 2911683Smckusick 3011683Smckusick /* 3111683Smckusick ** #### ##### # #### ##### #### ##### # # 3211683Smckusick ** # # # # # # # # # # # # 3311683Smckusick ** ### # ##### #### # #### ### ### 3411683Smckusick ** # # # # # # # # # # # # 3511683Smckusick ** #### # # # # # # # # ##### # # 3611683Smckusick ** 3711683Smckusick ** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help 3811683Smckusick ** from Jeff Poskanzer and Pete Rubinstein. 3911683Smckusick ** 4011683Smckusick ** I also want to thank everyone here at Berkeley who 4111683Smckusick ** where crazy enough to play the undebugged game. I want to 4211683Smckusick ** particularly thank Nick Whyte, who made considerable 4311683Smckusick ** suggestions regarding the content of the game. Why, I'll 4411683Smckusick ** never forget the time he suggested the name for the 4511683Smckusick ** "capture" command. 4611683Smckusick ** 4711683Smckusick ** Please send comments, questions, and suggestions about this 4811683Smckusick ** game to: 4911683Smckusick ** Eric P. Allman 5011683Smckusick ** Project INGRES 5111683Smckusick ** Electronics Research Laboratory 5211683Smckusick ** Cory Hall 5311683Smckusick ** University of California 5411683Smckusick ** Berkeley, California 94720 5511683Smckusick ** 5611683Smckusick ** If you make ANY changes in the game, I sure would like to 5711683Smckusick ** know about them. It is sort of an ongoing project for me, 5811683Smckusick ** and I very much want to put in any bug fixes and improvements 5911683Smckusick ** that you might come up with. 6011683Smckusick ** 6111683Smckusick ** FORTRASH version by Kay R. Fisher (DEC) "and countless others". 6211683Smckusick ** That was adapted from the "original BASIC program" (ha!) by 6311683Smckusick ** Mike Mayfield (Centerline Engineering). 6411683Smckusick ** 6511683Smckusick ** Additional inspiration taken from FORTRAN version by 6611683Smckusick ** David Matuszek and Paul Reynolds which runs on the CDC 6711683Smckusick ** 7600 at Lawrence Berkeley Lab, maintained there by 6811683Smckusick ** Andy Davidson. This version is also available at LLL 6911683Smckusick ** and at LMSC. In all fairness, this version was the 7011683Smckusick ** major inspiration for this version of the game (trans- 7111683Smckusick ** lation: I ripped off a whole lot of code). 7211683Smckusick ** 7311683Smckusick ** Minor other input from the "Battelle Version 7A" by Joe Miller 7411683Smckusick ** (Graphics Systems Group, Battelle-Columbus Labs) and 7511683Smckusick ** Ross Pavlac (Systems Programmer, Battelle Memorial 7611683Smckusick ** Institute). That version was written in December '74 7711683Smckusick ** and extensively modified June '75. It was adapted 7811683Smckusick ** from the FTN version by Ron Williams of CDC Sunnyvale, 7911683Smckusick ** which was adapted from the Basic version distributed 8011683Smckusick ** by DEC. It also had "neat stuff swiped" from T. T. 8111683Smckusick ** Terry and Jim Korp (University of Texas), Hicks (Penn 8211683Smckusick ** U.), and Rick Maus (Georgia Tech). Unfortunately, it 8311683Smckusick ** was not as readable as it could have been and so the 8411683Smckusick ** translation effort was severely hampered. None the 8511683Smckusick ** less, I got the idea of inhabited starsystems from this 8611683Smckusick ** version. 8711683Smckusick ** 8811683Smckusick ** Permission is given for use, copying, and modification of 8911683Smckusick ** all or part of this program and related documentation, 9011683Smckusick ** provided that all reference to the authors are maintained. 9111683Smckusick ** 9211683Smckusick ** 9311683Smckusick ********************************************************************** 9411683Smckusick ** 9511683Smckusick ** NOTES TO THE MAINTAINER: 9611683Smckusick ** 9711683Smckusick ** There is a compilation option xTRACE which must be set for any 9811683Smckusick ** trace information to be generated. It is probably defined in 9911683Smckusick ** the version that you get. It can be removed, however, if you 10011683Smckusick ** have trouble finding room in core. 10111683Smckusick ** 10211683Smckusick ** Many things in trek are not as clear as they might be, but are 10311683Smckusick ** done to reduce space. I compile with the -f and -O flags. I 10411683Smckusick ** am constrained to running with non-seperated I/D space, since 10512738Slayer ** we don't have doubleing point hardware here; even if we did, I 10611683Smckusick ** would like trek to be available to the large number of people 10711683Smckusick ** who either have an 11/40 or do not have FP hardware. I also 10811683Smckusick ** found it desirable to make the code run reentrant, so this 10911683Smckusick ** added even more space constraints. 11011683Smckusick ** 11111683Smckusick ** I use the portable C library to do my I/O. This is done be- 11211683Smckusick ** cause I wanted the game easily transportable to other C 11312738Slayer ** implementations, and because I was too lazy to do the doubleing 11411683Smckusick ** point input myself. Little did I know. The portable C library 11511683Smckusick ** released by Bell Labs has more bugs than you would believe, so 11611683Smckusick ** I ended up rewriting the whole blessed thing. Trek excercises 11711683Smckusick ** many of the bugs in it, as well as bugs in some of the section 11811683Smckusick ** III UNIX routines. We have fixed them here. One main problem 11911683Smckusick ** was a bug in alloc() that caused it to always ask for a large 12011683Smckusick ** hunk of memory, which worked fine unless you were almost out, 12111683Smckusick ** which I inevitably was. If you want the code for all of this 12211683Smckusick ** stuff, it is also available through me. 12311683Smckusick ** 12411683Smckusick *********************************************************************** 12511683Smckusick */ 12611683Smckusick 12711683Smckusick main(argc, argv) 12811683Smckusick int argc; 12911683Smckusick char **argv; 13011683Smckusick { 13112738Slayer long vect; 13212738Slayer /* extern FILE *f_log; */ 13311683Smckusick register char opencode; 13411683Smckusick int prio; 13511683Smckusick register int ac; 13611683Smckusick register char **av; 13712738Slayer struct sgttyb argp; 13812738Slayer int been_here = 0; 13911683Smckusick 14011683Smckusick av = argv; 14111683Smckusick ac = argc; 14211683Smckusick av++; 14312738Slayer time(&vect); 14412738Slayer srand(vect); 14511683Smckusick opencode = 'w'; 14611683Smckusick prio = PRIO; 14712738Slayer if (gtty(1, &argp) == 0) 14811683Smckusick { 14912738Slayer if ((argp.sg_ispeed ) < B1200) 15011683Smckusick Etc.fast++; 15111683Smckusick } 15211683Smckusick while (ac > 1 && av[0][0] == '-') 15311683Smckusick { 15411683Smckusick switch (av[0][1]) 15511683Smckusick { 15611683Smckusick case 'a': /* append to log file */ 15711683Smckusick opencode = 'a'; 15811683Smckusick break; 15911683Smckusick 16011683Smckusick case 'f': /* set fast mode */ 16111683Smckusick Etc.fast++; 16211683Smckusick break; 16311683Smckusick 16411683Smckusick case 's': /* set slow mode */ 16511683Smckusick Etc.fast = 0; 16611683Smckusick break; 16711683Smckusick 16811683Smckusick # ifdef xTRACE 16911683Smckusick case 't': /* trace */ 17011683Smckusick if (getuid() != Mother) 17111683Smckusick goto badflag; 17211683Smckusick Trace++; 17311683Smckusick break; 17411683Smckusick # endif 17511683Smckusick 17611683Smckusick case 'p': /* set priority */ 17711683Smckusick if (getuid() != Mother) 17811683Smckusick goto badflag; 17911683Smckusick if (scanf(-1, &av[0][2], "%d", &prio) > 0) 18011683Smckusick break; 18111683Smckusick 18211683Smckusick default: 18311683Smckusick badflag: 18411683Smckusick printf("Invalid option: %s\n", av[0]); 18511683Smckusick 18611683Smckusick } 18711683Smckusick ac--; 18811683Smckusick av++; 18911683Smckusick } 19011683Smckusick if (ac > 2) 19111683Smckusick syserr(0, "arg count"); 19212738Slayer /* 19311683Smckusick if (ac > 1) 19412738Slayer f_log = fopen(av[0], opencode); 19512738Slayer */ 19611683Smckusick 197*34591Sbostic printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n"); 19811683Smckusick 19911683Smckusick setexit(); 20012738Slayer if ( been_here == 1 ) 20111683Smckusick { 20212738Slayer if ( !getynpar("Another game") ) 20312738Slayer exit(0); 20412738Slayer } 20512738Slayer been_here = 1; 20612738Slayer do 20712738Slayer { 20811683Smckusick setup(); 20911683Smckusick play(); 21012738Slayer } while (getynpar("Another game")); 21112738Slayer 21212738Slayer fflush(stdout); 21311683Smckusick } 214