1999-10-05 03:26:59 +04:00
|
|
|
/* $NetBSD: subs.c,v 1.13 1999/10/04 23:26:59 lukem Exp $ */
|
1995-03-21 18:03:38 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-03-21 18:03:38 +03:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-03-21 18:03:38 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)subs.c 8.1 (Berkeley) 5/31/93";
|
|
|
|
#else
|
1999-10-05 03:26:59 +04:00
|
|
|
__RCSID("$NetBSD: subs.c,v 1.13 1999/10/04 23:26:59 lukem Exp $");
|
1995-03-21 18:03:38 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include "back.h"
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
int buffnum;
|
|
|
|
char outbuff[BUFSIZ];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-02-10 15:29:47 +03:00
|
|
|
static const char plred[] = "Player is red, computer is white.";
|
|
|
|
static const char plwhite[] = "Player is white, computer is red.";
|
|
|
|
static const char nocomp[] = "(No computer play.)";
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-02-10 15:29:47 +03:00
|
|
|
const char *const descr[] = {
|
1993-03-21 12:45:37 +03:00
|
|
|
"Usage: backgammon [-] [n r w b pr pw pb t3a]\n",
|
|
|
|
"\t-\tgets this list\n\tn\tdon't ask for rules or instructions",
|
|
|
|
"\tr\tplayer is red (implies n)\n\tw\tplayer is white (implies n)",
|
|
|
|
"\tb\ttwo players, red and white (implies n)",
|
|
|
|
"\tpr\tprint the board before red's turn",
|
|
|
|
"\tpw\tprint the board before white's turn",
|
|
|
|
"\tpb\tprint the board before both player's turn",
|
|
|
|
"\tterm\tterminal is a term",
|
|
|
|
"\tsfile\trecover saved game from file",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
errexit(s)
|
|
|
|
const char *s;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
write(2, "\n", 1);
|
|
|
|
perror(s);
|
|
|
|
getout(0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1999-10-05 03:26:59 +04:00
|
|
|
int
|
1997-10-10 12:59:32 +04:00
|
|
|
addbuf(c)
|
|
|
|
int c;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
buffnum++;
|
1997-10-10 12:59:32 +04:00
|
|
|
if (buffnum == BUFSIZ) {
|
|
|
|
if (write(1, outbuff, BUFSIZ) != BUFSIZ)
|
|
|
|
errexit("addbuf (write):");
|
1993-03-21 12:45:37 +03:00
|
|
|
buffnum = 0;
|
|
|
|
}
|
|
|
|
outbuff[buffnum] = c;
|
1999-10-05 03:26:59 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
buflush()
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
if (buffnum < 0)
|
|
|
|
return;
|
|
|
|
buffnum++;
|
1997-10-10 12:59:32 +04:00
|
|
|
if (write(1, outbuff, buffnum) != buffnum)
|
|
|
|
errexit("buflush (write):");
|
1993-03-21 12:45:37 +03:00
|
|
|
buffnum = -1;
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
int
|
|
|
|
readc()
|
|
|
|
{
|
|
|
|
char c;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
if (tflag) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cline();
|
|
|
|
newpos();
|
|
|
|
}
|
|
|
|
buflush();
|
1997-10-10 12:59:32 +04:00
|
|
|
if (read(0, &c, 1) != 1)
|
|
|
|
errexit("readc");
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef WHY_IS_THIS_HARDWIRED_IN_HERE
|
|
|
|
if (c == '\177')
|
1997-10-10 12:59:32 +04:00
|
|
|
getout(0);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
if (c == '\033' || c == '\015')
|
|
|
|
return ('\n');
|
|
|
|
if (cflag)
|
|
|
|
return (c);
|
|
|
|
if (c == '\014')
|
|
|
|
return ('R');
|
|
|
|
if (c >= 'a' && c <= 'z')
|
|
|
|
return (c & 0137);
|
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
writec(c)
|
|
|
|
char c;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
if (tflag)
|
1997-10-10 12:59:32 +04:00
|
|
|
fancyc(c);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
addbuf(c);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
writel(l)
|
1999-02-10 15:29:47 +03:00
|
|
|
const char *l;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
1999-02-10 15:29:47 +03:00
|
|
|
const char *s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (trace == NULL)
|
1997-10-10 12:59:32 +04:00
|
|
|
trace = fopen("bgtrace", "w");
|
|
|
|
|
|
|
|
fprintf(trace, "writel: \"");
|
1993-03-21 12:45:37 +03:00
|
|
|
for (s = l; *s; s++) {
|
|
|
|
if (*s < ' ' || *s == '\177')
|
1997-10-10 12:59:32 +04:00
|
|
|
fprintf(trace, "^%c", (*s) ^ 0100);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
putc(*s, trace);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
fprintf(trace, "\"\n");
|
|
|
|
fflush(trace);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
while (*l)
|
1997-10-10 12:59:32 +04:00
|
|
|
writec(*l++);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
proll()
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
if (d0)
|
|
|
|
swap;
|
|
|
|
if (cturn == 1)
|
1997-10-10 12:59:32 +04:00
|
|
|
writel("Red's roll: ");
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
writel("White's roll: ");
|
|
|
|
writec(D0 + '0');
|
|
|
|
writec('\040');
|
|
|
|
writec(D1 + '0');
|
1993-03-21 12:45:37 +03:00
|
|
|
if (tflag)
|
|
|
|
cline();
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
wrint(n)
|
|
|
|
int n;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
int i, j, t;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
for (i = 4; i > 0; i--) {
|
1993-03-21 12:45:37 +03:00
|
|
|
t = 1;
|
1997-10-10 12:59:32 +04:00
|
|
|
for (j = 0; j < i; j++)
|
1993-03-21 12:45:37 +03:00
|
|
|
t *= 10;
|
1997-10-10 12:59:32 +04:00
|
|
|
if (n > t - 1)
|
|
|
|
writec((n / t) % 10 + '0');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
writec(n % 10 + '0');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
gwrite()
|
|
|
|
{
|
|
|
|
int r, c;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
r = c = 0;
|
|
|
|
if (tflag) {
|
1993-03-21 12:45:37 +03:00
|
|
|
r = curr;
|
|
|
|
c = curc;
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(16, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
if (gvalue > 1) {
|
|
|
|
writel("Game value: ");
|
|
|
|
wrint(gvalue);
|
|
|
|
writel(". ");
|
1993-03-21 12:45:37 +03:00
|
|
|
if (dlast == -1)
|
1997-10-10 12:59:32 +04:00
|
|
|
writel(color[0]);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
writel(color[1]);
|
|
|
|
writel(" doubled last.");
|
|
|
|
} else {
|
|
|
|
switch (pnum) {
|
|
|
|
case -1: /* player is red */
|
|
|
|
writel(plred);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-10-10 12:59:32 +04:00
|
|
|
case 0: /* player is both colors */
|
|
|
|
writel(nocomp);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-10-10 12:59:32 +04:00
|
|
|
case 1: /* player is white */
|
|
|
|
writel(plwhite);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
if (rscore || wscore) {
|
|
|
|
writel(" ");
|
1993-03-21 12:45:37 +03:00
|
|
|
wrscore();
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
if (tflag) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cline();
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(r, c);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
int
|
|
|
|
quit()
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
if (tflag) {
|
|
|
|
curmove(20, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
clend();
|
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
writec('\n');
|
|
|
|
writel("Are you sure you want to quit?");
|
|
|
|
if (yorn(0)) {
|
|
|
|
if (rfl) {
|
|
|
|
writel("Would you like to save this game?");
|
1993-03-21 12:45:37 +03:00
|
|
|
if (yorn(0))
|
|
|
|
save(0);
|
|
|
|
}
|
|
|
|
cturn = 0;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
int
|
|
|
|
yorn(special)
|
|
|
|
char special; /* special response */
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
char c;
|
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
i = 1;
|
1997-10-10 12:59:32 +04:00
|
|
|
while ((c = readc()) != 'Y' && c != 'N') {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (special && c == special)
|
|
|
|
return (2);
|
1997-10-10 12:59:32 +04:00
|
|
|
if (i) {
|
|
|
|
if (special) {
|
|
|
|
writel(" (Y, N, or ");
|
|
|
|
writec(special);
|
|
|
|
writec(')');
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
writel(" (Y or N)");
|
1993-03-21 12:45:37 +03:00
|
|
|
i = 0;
|
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
writec('\007');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
if (c == 'Y')
|
1997-10-10 12:59:32 +04:00
|
|
|
writel(" Yes.\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1997-10-10 12:59:32 +04:00
|
|
|
writel(" No.\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
if (tflag)
|
|
|
|
buflush();
|
|
|
|
return (c == 'Y');
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
wrhit(i)
|
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
writel("Blot hit on ");
|
|
|
|
wrint(i);
|
|
|
|
writec('.');
|
|
|
|
writec('\n');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
nexturn()
|
|
|
|
{
|
|
|
|
int c;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
cturn = -cturn;
|
1997-10-10 12:59:32 +04:00
|
|
|
c = cturn / abs(cturn);
|
1993-03-21 12:45:37 +03:00
|
|
|
home = bar;
|
1997-10-10 12:59:32 +04:00
|
|
|
bar = 25 - bar;
|
1993-03-21 12:45:37 +03:00
|
|
|
offptr += c;
|
|
|
|
offopp -= c;
|
|
|
|
inptr += c;
|
|
|
|
inopp -= c;
|
|
|
|
Colorptr += c;
|
|
|
|
colorptr += c;
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
getarg(arg)
|
|
|
|
char ***arg;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-10 12:59:32 +04:00
|
|
|
char **s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* process arguments here. dashes are ignored, nbrw are ignored if
|
|
|
|
* the game is being recovered */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
s = *arg;
|
1998-09-15 17:43:34 +04:00
|
|
|
while (*s && s[0][0] == '-') {
|
1997-10-10 12:59:32 +04:00
|
|
|
switch (s[0][1]) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* don't ask if rules or instructions needed */
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'n':
|
|
|
|
if (rflag)
|
|
|
|
break;
|
|
|
|
aflag = 0;
|
|
|
|
args[acnt++] = 'n';
|
|
|
|
break;
|
|
|
|
|
1998-09-11 17:06:30 +04:00
|
|
|
/* player is both red and white */
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'b':
|
|
|
|
if (rflag)
|
|
|
|
break;
|
|
|
|
pnum = 0;
|
|
|
|
aflag = 0;
|
|
|
|
args[acnt++] = 'b';
|
|
|
|
break;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* player is red */
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'r':
|
|
|
|
if (rflag)
|
|
|
|
break;
|
|
|
|
pnum = -1;
|
|
|
|
aflag = 0;
|
|
|
|
args[acnt++] = 'r';
|
|
|
|
break;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* player is white */
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'w':
|
|
|
|
if (rflag)
|
|
|
|
break;
|
|
|
|
pnum = 1;
|
|
|
|
aflag = 0;
|
|
|
|
args[acnt++] = 'w';
|
|
|
|
break;
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
/* print board after move according to following
|
|
|
|
* character */
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'p':
|
|
|
|
if (s[0][2] != 'r' && s[0][2] != 'w' && s[0][2] != 'b')
|
|
|
|
break;
|
|
|
|
args[acnt++] = 'p';
|
|
|
|
args[acnt++] = s[0][2];
|
|
|
|
if (s[0][2] == 'r')
|
|
|
|
bflag = 1;
|
|
|
|
if (s[0][2] == 'w')
|
|
|
|
bflag = -1;
|
|
|
|
if (s[0][2] == 'b')
|
|
|
|
bflag = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
if (s[0][2] == '\0') { /* get terminal caps */
|
|
|
|
s++;
|
1997-10-10 12:59:32 +04:00
|
|
|
tflag = getcaps(*s);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
tflag = getcaps(&s[0][2]);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
s++;
|
|
|
|
/* recover file */
|
1999-07-27 00:50:44 +04:00
|
|
|
if (s[0] == NULL) {
|
|
|
|
writel("No save file named\n");
|
|
|
|
getout(0);
|
|
|
|
} else
|
|
|
|
recover(s[0]);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
if (s[0] != 0)
|
|
|
|
recover(s[0]);
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
init()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
for (i = 0; i < 26;)
|
|
|
|
board[i++] = 0;
|
|
|
|
board[1] = 2;
|
|
|
|
board[6] = board[13] = -5;
|
|
|
|
board[8] = -3;
|
|
|
|
board[12] = board[19] = 5;
|
|
|
|
board[17] = 3;
|
|
|
|
board[24] = -2;
|
|
|
|
off[0] = off[1] = -15;
|
|
|
|
in[0] = in[1] = 5;
|
|
|
|
gvalue = 1;
|
|
|
|
dlast = 0;
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
wrscore()
|
|
|
|
{
|
|
|
|
writel("Score: ");
|
|
|
|
writel(color[1]);
|
|
|
|
writec(' ');
|
|
|
|
wrint(rscore);
|
|
|
|
writel(", ");
|
|
|
|
writel(color[0]);
|
|
|
|
writec(' ');
|
|
|
|
wrint(wscore);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
fixtty(t)
|
|
|
|
struct termios *t;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
if (tflag)
|
|
|
|
newpos();
|
|
|
|
buflush();
|
1997-10-10 12:59:32 +04:00
|
|
|
if (tcsetattr(0, TCSADRAIN, t) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
errexit("fixtty");
|
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
getout(dummy)
|
1999-09-09 01:45:25 +04:00
|
|
|
int dummy __attribute__((__unused__));
|
1997-10-10 12:59:32 +04:00
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
/* go to bottom of screen */
|
1997-10-10 12:59:32 +04:00
|
|
|
if (tflag) {
|
|
|
|
curmove(23, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
cline();
|
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
writec('\n');
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* fix terminal status */
|
1997-10-10 12:59:32 +04:00
|
|
|
fixtty(&old);
|
1995-04-24 16:21:37 +04:00
|
|
|
exit(0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-10 12:59:32 +04:00
|
|
|
void
|
|
|
|
roll()
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
int row;
|
|
|
|
int col;
|
|
|
|
|
|
|
|
row = col = 0;
|
|
|
|
if (iroll) {
|
|
|
|
if (tflag) {
|
1993-03-21 12:45:37 +03:00
|
|
|
row = curr;
|
|
|
|
col = curc;
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(17, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
writec('\n');
|
|
|
|
writel("ROLL: ");
|
1993-03-21 12:45:37 +03:00
|
|
|
c = readc();
|
1997-10-10 12:59:32 +04:00
|
|
|
if (c != '\n') {
|
1993-03-21 12:45:37 +03:00
|
|
|
while (c < '1' || c > '6')
|
|
|
|
c = readc();
|
1997-10-10 12:59:32 +04:00
|
|
|
D0 = c - '0';
|
|
|
|
writec(' ');
|
|
|
|
writec(c);
|
1993-03-21 12:45:37 +03:00
|
|
|
c = readc();
|
|
|
|
while (c < '1' || c > '6')
|
|
|
|
c = readc();
|
1997-10-10 12:59:32 +04:00
|
|
|
D1 = c - '0';
|
|
|
|
writec(' ');
|
|
|
|
writec(c);
|
|
|
|
if (tflag) {
|
|
|
|
curmove(17, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
cline();
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(row, col);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
writec('\n');
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
if (tflag) {
|
|
|
|
curmove(17, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
cline();
|
1997-10-10 12:59:32 +04:00
|
|
|
curmove(row, col);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1997-10-10 12:59:32 +04:00
|
|
|
writec('\n');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-10 12:59:32 +04:00
|
|
|
D0 = rnum(6) + 1;
|
|
|
|
D1 = rnum(6) + 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
d0 = 0;
|
|
|
|
}
|