Use hardware timer to simulate interrupt moderation.
[dragonfly.git] / games / mille / init.c
bloba4a0bd42e5954a873c4368a82af84fe9b0a65348
1 /*
2 * Copyright (c) 1982, 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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
33 * @(#)init.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/mille/init.c,v 1.5 1999/12/12 06:17:24 billf Exp $
35 * $DragonFly: src/games/mille/init.c,v 1.3 2006/08/27 17:17:23 pavalos Exp $
38 # include "mille.h"
41 * @(#)init.c 1.1 (Berkeley) 4/1/82
44 void
45 init(void)
48 PLAY *pp;
49 int i, j;
50 CARD card;
52 bzero(Numseen, sizeof Numseen);
53 Numgos = 0;
55 for (i = 0; i < 2; i++) {
56 pp = &Player[i];
57 pp->hand[0] = C_INIT;
58 for (j = 0; j < NUM_SAFE; j++) {
59 pp->safety[j] = S_UNKNOWN;
60 pp->coups[j] = FALSE;
62 for (j = 1; j < HAND_SZ; j++) {
63 pp->hand[j] = *--Topcard;
64 if (i == COMP) {
65 account(card = *Topcard);
66 if (issafety(card))
67 pp->safety[card - S_CONV] = S_IN_HAND;
70 pp->mileage = 0;
71 pp->hand_tot = 0;
72 pp->safescore = 0;
73 pp->coupscore = 0;
74 pp->can_go = FALSE;
75 pp->speed = C_INIT;
76 pp->battle = C_INIT;
77 pp->new_speed = FALSE;
78 pp->new_battle = FALSE;
79 for (j = 0; j < NUM_MILES; j++)
80 pp->nummiles[j] = 0;
82 if (Order)
83 sort(Player[PLAYER].hand);
84 Discard = C_INIT;
85 Finished = FALSE;
86 End = 700;
89 void
90 shuffle(void)
93 int i, r;
94 CARD temp;
96 for (i = 0; i < DECK_SZ; i++) {
97 r = roll(1, DECK_SZ) - 1;
98 if (r < 0 || r > DECK_SZ - 1) {
99 fprintf(stderr, "shuffle: card no. error: %d\n", r);
100 die(1);
102 temp = Deck[r];
103 Deck[r] = Deck[i];
104 Deck[i] = temp;
106 Topcard = &Deck[DECK_SZ];
109 void
110 newboard(void)
113 int i;
114 PLAY *pp;
115 static int first = TRUE;
117 if (first) {
118 werase(Board);
119 werase(Score);
120 mvaddstr(5, 0, "--HAND--");
121 mvaddch(6, 0, 'P');
122 mvaddch(7, 0, '1');
123 mvaddch(8, 0, '2');
124 mvaddch(9, 0, '3');
125 mvaddch(10, 0, '4');
126 mvaddch(11, 0, '5');
127 mvaddch(12, 0, '6');
128 mvaddstr(13, 0, "--BATTLE--");
129 mvaddstr(15, 0, "--SPEED--");
130 mvaddstr(5, 20, "--DECK--");
131 mvaddstr(7, 20, "--DISCARD--");
132 mvaddstr(13, 20, "--BATTLE--");
133 mvaddstr(15, 20, "--SPEED--");
134 mvwaddstr(Miles, 0, 0, "--MILEAGE--");
135 mvwaddstr(Miles, 0, 41, "--MILEAGE--");
136 Sh_discard = -1;
137 for (pp = Player; pp <= &Player[COMP]; pp++) {
138 for (i = 0; i < HAND_SZ; i++)
139 pp->sh_hand[i] = -1;
140 pp->sh_battle = -1;
141 pp->sh_speed = -1;
142 pp->sh_mileage = -1;
144 first = FALSE;
146 else {
147 for (i = 0; i < 5; i++) {
148 move(i, 0);
149 clrtoeol();
151 wmove(Miles, 1, 0);
152 wclrtobot(Miles);
153 wmove(Board, MOVE_Y + 1, MOVE_X);
154 wclrtoeol(Board);
155 wmove(Board, MOVE_Y + 2, MOVE_X);
156 wclrtoeol(Board);
158 Sh_discard = -1;
159 for (pp = Player; pp <= &Player[COMP]; pp++) {
160 for (i = 0; i < NUM_SAFE; i++)
161 pp->sh_safety[i] = FALSE;
162 for (i = 0; i < NUM_MILES; i++)
163 pp->sh_nummiles[i] = 0;
164 pp->sh_safescore = -1;
166 newscore();
169 void
170 newscore(void)
173 int i, new;
174 PLAY *pp;
175 static int was_full = -1;
176 static int last_win = -1;
178 if (was_full < 0)
179 was_full = (Window != W_FULL);
180 stdscr = Score;
181 move(0, 22);
182 new = FALSE;
183 if (inch() != 'Y') {
184 erase();
185 mvaddstr(0, 22, "You Comp Value");
186 mvaddstr(1, 2, "Milestones Played");
187 mvaddstr(2, 8, "Each Safety");
188 mvaddstr(3, 5, "All 4 Safeties");
189 mvaddstr(4, 3, "Each Coup Fourre");
190 mvaddstr(2, 37, "100");
191 mvaddstr(3, 37, "300");
192 mvaddstr(4, 37, "300");
193 new = TRUE;
195 else if ((Window == W_FULL || Finished) ^ was_full) {
196 move(5, 1);
197 clrtobot();
198 new = TRUE;
200 else if (Window != last_win)
201 new = TRUE;
202 if (new) {
203 for (i = 0; i < SCORE_Y; i++)
204 mvaddch(i, 0, '|');
205 move(SCORE_Y - 1, 1);
206 for (i = 0; i < SCORE_X; i++)
207 addch('_');
208 for (pp = Player; pp <= &Player[COMP]; pp++) {
209 pp->sh_hand_tot = -1;
210 pp->sh_total = -1;
211 pp->sh_games = -1;
212 pp->sh_safescore = -1;
215 Player[PLAYER].was_finished = !Finished;
216 Player[COMP].was_finished = !Finished;
217 if (Window == W_FULL || Finished) {
218 if (!was_full || new) {
219 mvaddstr(5, 5, "Trip Completed");
220 mvaddstr(6, 10, "Safe Trip");
221 mvaddstr(7, 5, "Delayed Action");
222 mvaddstr(8, 10, "Extension");
223 mvaddstr(9, 11, "Shut-Out");
224 mvaddstr(10, 21, "---- ---- -----");
225 mvaddstr(11, 9, "Hand Total");
226 mvaddstr(12, 20, "----- -----");
227 mvaddstr(13, 6, "Overall Total");
228 mvaddstr(14, 15, "Games");
229 mvaddstr(5, 37, "400");
230 mvaddstr(6, 37, "300");
231 mvaddstr(7, 37, "300");
232 mvaddstr(8, 37, "200");
233 mvaddstr(9, 37, "500");
236 else
237 if (was_full || new) {
238 mvaddstr(5, 21, "---- ---- -----");
239 mvaddstr(6, 9, "Hand Total");
240 mvaddstr(7, 20, "----- -----");
241 mvaddstr(8, 6, "Overall Total");
242 mvaddstr(9, 15, "Games");
243 mvaddstr(11, 2, "p: pick");
244 mvaddstr(12, 2, "u: use #");
245 mvaddstr(13, 2, "d: discard #");
246 mvaddstr(14, 2, "w: toggle window");
247 mvaddstr(11, 21, "q: quit");
248 if (!Order)
249 mvaddstr(12, 21, "o: order hand");
250 else
251 mvaddstr(12, 21, "o: stop ordering");
252 mvaddstr(13, 21, "s: save");
253 mvaddstr(14, 21, "r: reprint");
255 stdscr = Board;
256 was_full = (Window == W_FULL || Finished);
257 last_win = Window;