1 /*
2 	swmain	 -	SW mainline
3 
4 	Copyright (C) 1984-2003 David L. Clark.
5 	This program is free software; you can redistribute it and/or modify it under
6 	the terms of the GNU General Public License as published by the Free Software
7 	Foundation; either version 2 of the License, or (at your option) any later
8 	version. This program is distributed in the hope that it will be useful,
9 	but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 	or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 	more details. You should have received a copy of the GNU General Public
12 	License along with this program; if not, write to the Free Software Foundation,
13 	Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
14 
15 			Author: Dave Clark
16 
17 	Modification History:
18 			84-02-02	Development
19 			84-06-12	PC-jr Speed-up
20 			85-10-31	Atari
21 			87-03-09	Microsoft compiler.
22 			87-03-12	Wounded airplanes.
23 			87-04-06	Computer plane avoiding oxen.
24 			96-12-26	Speed up game a bit
25 			2003-01-27	GNU General Public License
26 */
27 #include	"sw.h"
28 
29 
30 
31 int	playmode;			/* Mode of play 		    */
32 GAMES	*currgame;			/* Game parameters and current game */
33 OBJECTS *targets[MAX_TARG+MAX_OXEN];	/* Status of targets array	    */
34 int	numtarg[2];			/* Number of active targets by color*/
35 int	savemode;			/* Saved PC display mode	    */
36 int	tickmode;			/* Tick action to be performed	    */
37 int	counttick, countmove;		/* Performance counters 	    */
38 int	movetick, movemax;		/* Move timing			    */
39 
40 int	gamenum;			/* Current game number		    */
41 int	gmaxspeed, gminspeed;		/* Speed range based on game number */
42 int	targrnge;			/* Target range based on game number*/
43 
44 MULTIO	multiost;			/* Multiple player I/O buffer	    */
45 #ifdef	IBMPC				/* Auxiliary display area	    */
46 char	auxdisp[0x2000];
47 #endif
48 #ifdef	ATARI
49 char	auxdisp[0x4000];
50 #endif
51 
52 int	multkey;			/* Keystroke to be passed	    */
53 MULTIO	*multbuff = &multiost;
54 
55 #ifdef	IBMPC
56 unsigned multaddr = 0x3F2;		/* Multiple user diskette adapter   */
57 #endif					/*   address			    */
58 #ifdef	ATARI
59 unsigned multaddr = 0;			/* Multiple user controller number  */
60 #endif
61 
62 int	multtick;			/* Multiple user tick delay	    */
63 BOOL	hires;				/* High res flag		    */
64 BOOL	disppos;			/* Display position flag	    */
65 BOOL	titleflg;			/* Title flag			    */
66 int	dispdbg;			/* Debug value to display	    */
67 BOOL	soundflg;			/* Sound flag			    */
68 BOOL	repflag;			/* Report statistics flag	    */
69 BOOL	joystick;			/* Joystick being used		    */
70 BOOL	ibmkeybd;			/* IBM-like keyboard being used     */
71 BOOL	inplay; 			/* Game is in play		    */
72 BOOL	printflg = 0;			/* Print screen requested	    */
73 int	koveride;			/* Keyboard override index number   */
74 int	missok; 			/* Missiles supported		    */
75 
76 int	displx, disprx; 		/* Display left and right	    */
77 int	dispdx; 			/* Display shift		    */
78 BOOL	dispinit;			/* Inialized display flag	    */
79 
80 OBJECTS *drawlist;			/* Onscreen object list 	    */
81 OBJECTS *nobjects;			/* Objects list.		    */
82 OBJECTS oobjects[MAX_PLYR];		/* Original plane object description*/
83 OBJECTS *objbot, *objtop,		/* Top and bottom of object list    */
84 	*objfree,			/* Free list			    */
85 	*deltop, *delbot;		/* Newly deallocated objects	    */
86 OBJECTS topobj, botobj; 		/* Top and Bottom of obj. x list    */
87 
88 OBJECTS *compnear[MAX_PLYR];		/* Planes near computer planes	    */
89 int	lcompter[MAX_PLYR] = {		/* Computer plane territory	    */
90 	0, 1155, 0,    2089
91 };
92 int	rcompter[MAX_PLYR] = {		/* Computer plane territory	    */
93 	0, 2088, 1154, 10000
94 };
95 
96 OBJECTS *objsmax	=	0;	/* Maximum object allocated	    */
97 int	endsts[MAX_PLYR];		/* End of game status and move count*/
98 int	endcount;
99 int	player; 			/* Pointer to player's object       */
100 int	currobx;			/* Current object index 	    */
101 BOOL	plyrplane;			/* Current object is player flag    */
102 BOOL	compplane;			/* Current object is a comp plane   */
103 OLDWDISP wdisp[MAX_OBJS];		/* World display status 	    */
104 BOOL	goingsun;			/* Going to the sun flag	    */
105 BOOL	forcdisp;			/* Force display of ground	    */
106 char	*histin, *histout;		/* History input and output files   */
107 unsigned explseed;			/* random seed for explosion	    */
108 
109 int	keydelay = -1;			/* Number of displays per keystroke */
110 int	dispcnt;			/* Displays to delay keyboard	    */
111 int	endstat;			/* End of game status for curr. move*/
112 int	maxcrash;			/* Maximum number of crashes	    */
113 int	shothole;			/* Number of shot holes to display  */
114 int	splatbird;			/* Number of slatted bird symbols   */
115 int	splatox;			/* Display splatted ox		    */
116 int	oxsplatted;			/* An ox has been splatted	    */
117 
118 int	sintab[ANGLES] = {		/* sine table of pi/8 increments    */
119 	0,	98,	181,	237,	/*   multiplied by 256		    */
120 	256,	237,	181,	98,
121 	0,	-98,	-181,	-237,
122 	-256,	-237,	-181,	-98
123 	};
124 
125 jmp_buf envrestart;			/* Restart environment for restart  */
126 					/*  long jump.			    */
127 
128 extern	int	 swkeyint();		/* Keyboard interrupt server	    */
129 
130 #ifdef	IBMPC				/* System type			    */
131 extern	int	 _systype;
132 #endif
133 #ifdef	ATARI
134 	int	_systype;
135 #endif
136 
137 
138 main( argc, argv )
139 int	argc;
140 char	*argv[];
141 {
142 char	*malloc();
143 
144 	nobjects = (OBJECTS *)malloc( 100 * sizeof( OBJECTS ) );
145 	_systype = PCDOS;
146 
147 	swinit( argc, argv );
148 	setjmp( envrestart );
149 	FOREVER {
150 
151 		/*----- DLC 96/12/27 ------
152 		while ( movetick < 2  );
153 		movetick = 0;
154 		-------------------------*/
155 		while ( movetick < movemax );
156 		intsoff();
157 		movetick -= movemax;
158 		intson();
159 
160 		swmove();
161 		swgetjoy();
162 		swdisp();
163 		swgetjoy();
164 		swcollsn();
165 		swgetjoy();
166 		intsoff();
167 		if ( printflg ) {
168 			printflg = FALSE;
169 			_intreset( koveride );
170 			intson();
171 			swprint();
172 			intsoff();
173 			koveride = _intsetup( KEYINT, swkeyint,
174 					      csseg(), dsseg() );
175 		}
176 		intson();
177 		swsound();
178 	}
179 }
180 