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.2 2003/06/17 04:25:24 dillon 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, *UP, *CM, *ND, *XD, *BC, *SO, *SE, *TI, *TE;
18 static char PC = '\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("NP") || tgetflag("nx"))
37 if(pc = tgetstr("pc", &tbufptr))
39 if(!(BC = tgetstr("bc", &tbufptr))) {
41 error("Terminal must backspace.");
46 HO = tgetstr("ho", &tbufptr);
49 if(CO < COLNO || LI < ROWNO+2)
51 if(!(CL = tgetstr("cl", &tbufptr)))
52 error("Hack needs CL.");
53 ND = tgetstr("nd", &tbufptr);
55 error("Hack can't have OS.");
56 CE = tgetstr("ce", &tbufptr);
57 UP = tgetstr("up", &tbufptr);
58 /* It seems that xd is no longer supported, and we should use
59 a linefeed instead; unfortunately this requires resetting
60 CRMOD, and many output routines will have to be modified
61 slightly. Let's leave that till the next release. */
62 XD = tgetstr("xd", &tbufptr);
63 /* not: XD = tgetstr("do", &tbufptr); */
64 if(!(CM = tgetstr("cm", &tbufptr))) {
66 error("Hack needs CM or UP or HO.");
67 printf("Playing hack on terminals without cm is suspect...\n");
70 SO = tgetstr("so", &tbufptr);
71 SE = tgetstr("se", &tbufptr);
72 SG = tgetnum("sg"); /* -1: not fnd; else # of spaces left by so */
73 if(!SO || !SE || (SG > 0)) SO = SE = 0;
74 CD = tgetstr("cd", &tbufptr);
75 set_whole_screen(); /* uses LI and CD */
76 if(tbufptr-tbuf > sizeof(tbuf)) error("TERMCAP entry too big...\n");
92 /* Cursor movements */
93 extern xchar curx, cury;
96 int x, y; /* not xchar: perhaps xchar is unsigned and
97 curx-x would be unsigned as well */
100 if (y == cury && x == curx)
102 if(!ND && (curx != x || x <= 3)) { /* Extremely primitive */
103 cmov(x, y); /* bunker!wtm */
106 if(abs(cury-y) <= 3 && abs(curx-x) <= 3)
108 else if((x <= 3 && abs(cury-y)<= 3) || (!CM && x<abs(curx-x))) {
109 (void) putchar('\r');
122 while (cury > y) { /* Go up. */
131 } /* else impossible("..."); */
132 } else if (cury < y) {
148 if (curx < x) { /* Go to the right. */
149 if(!ND) cmov(x, y); else /* bah */
150 /* should instead print what is there already */
155 } else if (curx > x) {
156 while (curx > x) { /* Go to the left. */
166 xputs(tgoto(CM, x-1, y-1));
172 (void) fputc(c, stdout);
182 else { /* no-CE fix - free after Harold Rynes */
183 /* this looks terrible, especially on a slow terminal
184 but is better than nothing */
185 int cx = curx, cy = cury;
187 while(curx < COLNO) {
205 xputs(tgoto(CM, 0, 0));
207 curs(1, 1); /* using UP ... */
229 (void) putchar('\007'); /* curx does not change */
230 (void) fflush(stdout);
233 static short tmspc10[] = { /* from termcap */
234 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 3, 2, 1
239 /* delay 50 ms - could also use a 'nap'-system call */
240 /* BUG: if the padding character is visible, as it is on the 5620
241 then this looks terrible. */
243 tputs("50", 1, xputc);
245 /* cbosgd!cbcephus!pds for SYS V R2 */
246 /* is this terminfo, or what? */
247 /* tputs("$<50>", 1, xputc); */
249 (void) fflush(stdout);
252 else if(ospeed > 0 || ospeed < SIZE(tmspc10)) if(CM) {
253 /* delay by sending cm(here) an appropriate number of times */
254 int cmlen = strlen(tgoto(CM, curx-1, cury-1));
255 int i = 500 + tmspc10[ospeed]/2;
259 i -= cmlen*tmspc10[ospeed];
265 cl_eos() /* free after Robert Viduya */
266 { /* must only be called with curx = 1 */
271 int cx = curx, cy = cury;
272 while(cury <= LI-2) {