1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.termcap.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.termcap.c,v 1.10 1999/11/16 10:26:38 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.termcap.c,v 1.4 2005/05/22 03:37:05 y0netan1 Exp $ */
10 #include "config.h" /* for ROWNO and COLNO */
11 #include "def.flag.h" /* for flags.nonull */
14 static char tbuf[512];
15 static char *HO, *CL, *CE, *tcUP, *CM, *ND, *XD, *tcBC, *SO, *SE, *TI, *TE;
18 static char tcPC = '\0';
19 char *CD; /* tested in pri.c: docorner() */
20 int CO, LI; /* used in pri.c and whatis.c */
28 tptr = (char *) alloc(1024);
31 if(!(term = getenv("TERM")))
32 error("Can't get TERM.");
33 if(tgetent(tptr, term) < 1)
34 error("Unknown terminal type: %s.", term);
35 if (tgetflag(__DECONST(char *, "NP")) ||
36 tgetflag(__DECONST(char *, "nx")))
38 if(pc = tgetstr(__DECONST(char *, "pc"), &tbufptr))
40 if(!(tcBC = tgetstr(__DECONST(char *, "bc"), &tbufptr))) {
41 if(!tgetflag(__DECONST(char *, "bs")))
42 error("Terminal must backspace.");
47 HO = tgetstr(__DECONST(char *, "ho"), &tbufptr);
48 CO = tgetnum(__DECONST(char *, "co"));
49 LI = tgetnum(__DECONST(char *, "li"));
50 if(CO < COLNO || LI < ROWNO+2)
52 if(!(CL = tgetstr(__DECONST(char *, "cl"), &tbufptr)))
53 error("Hack needs CL.");
54 ND = tgetstr(__DECONST(char *, "nd"), &tbufptr);
55 if(tgetflag(__DECONST(char *, "os")))
56 error("Hack can't have OS.");
57 CE = tgetstr(__DECONST(char *, "ce"), &tbufptr);
58 tcUP = tgetstr(__DECONST(char *, "up"), &tbufptr);
59 /* It seems that xd is no longer supported, and we should use
60 a linefeed instead; unfortunately this requires resetting
61 CRMOD, and many output routines will have to be modified
62 slightly. Let's leave that till the next release. */
63 XD = tgetstr(__DECONST(char *, "xd"), &tbufptr);
64 /* not: XD = tgetstr("do", &tbufptr); */
65 if(!(CM = tgetstr(__DECONST(char *, "cm"), &tbufptr))) {
67 error("Hack needs CM or UP or HO.");
68 printf("Playing hack on terminals without cm is suspect...\n");
71 SO = tgetstr(__DECONST(char *, "so"), &tbufptr);
72 SE = tgetstr(__DECONST(char *, "se"), &tbufptr);
73 SG = tgetnum(__DECONST(char *, "sg"));
74 if(!SO || !SE || (SG > 0)) SO = SE = 0;
75 CD = tgetstr(__DECONST(char *, "cd"), &tbufptr);
76 set_whole_screen(); /* uses LI and CD */
77 if(tbufptr-tbuf > sizeof(tbuf)) error("TERMCAP entry too big...\n");
93 /* Cursor movements */
94 extern xchar curx, cury;
97 int x, y; /* not xchar: perhaps xchar is unsigned and
98 curx-x would be unsigned as well */
101 if (y == cury && x == curx)
103 if(!ND && (curx != x || x <= 3)) { /* Extremely primitive */
104 cmov(x, y); /* bunker!wtm */
107 if(abs(cury-y) <= 3 && abs(curx-x) <= 3)
109 else if((x <= 3 && abs(cury-y)<= 3) || (!CM && x<abs(curx-x))) {
110 (void) putchar('\r');
123 while (cury > y) { /* Go up. */
132 } /* else impossible("..."); */
133 } else if (cury < y) {
149 if (curx < x) { /* Go to the right. */
150 if(!ND) cmov(x, y); else /* bah */
151 /* should instead print what is there already */
156 } else if (curx > x) {
157 while (curx > x) { /* Go to the left. */
167 xputs(tgoto(CM, x-1, y-1));
173 (void) fputc(c, stdout);
183 else { /* no-CE fix - free after Harold Rynes */
184 /* this looks terrible, especially on a slow terminal
185 but is better than nothing */
186 int cx = curx, cy = cury;
188 while(curx < COLNO) {
206 xputs(tgoto(CM, 0, 0));
208 curs(1, 1); /* using tcUP ... */
230 (void) putchar('\007'); /* curx does not change */
231 (void) fflush(stdout);
234 static short tmspc10[] = { /* from termcap */
235 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 3, 2, 1
240 /* delay 50 ms - could also use a 'nap'-system call */
241 /* BUG: if the padding character is visible, as it is on the 5620
242 then this looks terrible. */
244 tputs("50", 1, xputc);
246 /* cbosgd!cbcephus!pds for SYS V R2 */
247 /* is this terminfo, or what? */
248 /* tputs("$<50>", 1, xputc); */
250 (void) fflush(stdout);
253 else if(ospeed > 0 || ospeed < SIZE(tmspc10)) if(CM) {
254 /* delay by sending cm(here) an appropriate number of times */
255 int cmlen = strlen(tgoto(CM, curx-1, cury-1));
256 int i = 500 + tmspc10[ospeed]/2;
260 i -= cmlen*tmspc10[ospeed];
266 cl_eos() /* free after Robert Viduya */
267 { /* must only be called with curx = 1 */
272 int cx = curx, cy = cury;
273 while(cury <= LI-2) {