]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - warp/term.h
games: remove trailing whitespace in *.c and *.h
[bsdgames-darwin.git] / warp / term.h
1 /* Header: term.h,v 7.0.1.2 86/12/12 17:05:15 lwall Exp */
2
3 /* Log: term.h,v
4 * Revision 7.0.1.2 86/12/12 17:05:15 lwall
5 * Baseline for net release.
6 *
7 * Revision 7.0.1.1 86/10/16 10:53:33 lwall
8 * Added Damage. Fixed random bugs.
9 *
10 * Revision 7.0 86/10/08 15:14:07 lwall
11 * Split into separate files. Added amoebas and pirates.
12 *
13 */
14
15 #ifndef TERM_H
16 #define TERM_H
17
18 #include "util.h"
19
20 /* Compat with old termios. */
21 #ifndef ECHO
22 #define ECHO 8
23 #endif
24
25 /* warp will still work without the following, but may get ahead at low speed */
26 #ifdef TIOCOUTQ /* chars left in output queue */
27 #define output_pending() (ioctl(1, TIOCOUTQ, &iocount),iocount)
28 #endif
29
30 /* If some of the following look something like curses calls, it is because
31 * warp used to use curses but doesn't now. Warp was neither as efficient nor
32 * as portable with curses, and since the program had to cheat on curses all
33 * over the place anyway, we ripped it out.
34 */
35 #define setimage(of,to) (mvaddch(of->posy+1,of->posx*2,of->image=(to)))
36
37 #define mvaddch(y,x,ch) move((y),(x),(ch))
38 /* #define addch(ch) (tmpchr=(ch), write(1,&tmpchr,1), real_x++) */
39 #define mvaddc(y,x,ch) move((y),(x),(ch))
40 #define addc(ch) (write(1,&(ch),1), real_x++)
41 #define addspace() (write(1," ",1), real_x++)
42 #define mvaddstr(y,x,s) (move((y),(x),0), tmpstr = (s), \
43 tmplen = strlen(tmpstr), write(1, tmpstr, tmplen), real_x += tmplen)
44
45 EXT size_t tmplen;
46 EXT const char *tmpstr;
47 /* EXT char tmpchr; */
48
49 /* The following macros are like the pseudo-curses macros above, but do
50 * certain amount of controlled output buffering.
51 *
52 * NOTE: a beg_qwrite()..end_qwrite() sequence must NOT contain a cursor
53 * movement (move), because the move() routine uses beg_qwrite()..end_qwrite()
54 * itself.
55 */
56
57 #define beg_qwrite() (maxcmstring = cmbuffer)
58 #ifdef vax
59 #define qwrite() asm("movc3 _gfillen,_filler,*_maxcmstring"); maxcmstring += gfillen
60 #else
61 #define qwrite() (movc3(gfillen,filler,maxcmstring), maxcmstring += gfillen)
62 #endif
63 #define qaddc(ch) (*maxcmstring++ = (ch), real_x++)
64 #define qaddch(ch) (*maxcmstring++ = (ch), real_x++)
65 #define qaddspace() (*maxcmstring++ = ' ', real_x++)
66 #define end_qwrite() (write(1,cmbuffer,maxcmstring-cmbuffer))
67
68 /* setting a ??size to infinity forces cursor addressing in that direction */
69
70 EXT int CMsize;
71 EXT int BCsize INIT(1);
72 EXT int DOsize INIT(1000);
73 EXT int UPsize INIT(1000);
74 EXT int NDsize INIT(1000);
75
76 EXT int charsperhalfsec;
77
78 EXT int real_y INIT(-100);
79 EXT int real_x INIT(-100);
80
81 #ifdef DOINIT
82 char filler[] = {0,'\b',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
83 #else
84 EXT char filler[];
85 #endif
86
87 EXT char *bsptr INIT(filler+1);
88
89 EXT char term[12];
90
91 EXT char gfillen INIT(25);
92
93 EXT char *maxcmstring;
94 EXT char cmbuffer[512];
95
96 #define BREAKCH '\0'
97
98 EXT char INTRCH INIT('\03');
99
100 #ifdef PUSHBACK
101 EXT char circlebuf[PUSHSIZE];
102 EXT int nextin INIT(0);
103 EXT int nextout INIT(0);
104 # ifdef PENDING
105 # ifdef FIONREAD
106 EXT long iocount INIT(0);
107 # ifndef lint
108 # define input_pending() (nextin!=nextout || \
109 (ioctl(0, FIONREAD, &iocount),(int)iocount))
110 # else
111 # define input_pending() bizarre
112 # endif /* lint */
113 # else /* FIONREAD */
114 int circfill();
115 # ifdef RDCHK
116 # ifndef lint
117 # define input_pending() rdchk(0)
118 # else /* lint */
119 # define input_pending() bizarre
120 # endif /* lint */
121 # else /* RDCHK */
122 # ifndef O_NDELAY /* assert O_NDELAY */
123 ??? PENDING is not defined correctly in warp.h
124 # endif
125 EXT int devtty INIT(0);
126 # ifndef lint
127 # define input_pending() (nextin!=nextout || circfill())
128 # else
129 # define input_pending() bizarre
130 # endif /* lint */
131 # endif /* RDCHK */
132 # endif /* FIONREAD */
133 # else /* PENDING */
134 # ??? warp will not work without PENDING
135 # ifndef lint
136 # define input_pending() (nextin!=nextout)
137 # else
138 # define input_pending() bizarre
139 # endif /* lint */
140 # endif /* PENDING */
141 #else /* PUSHBACK */
142 # ifdef PENDING
143 # ifdef FIONREAD /* must have FIONREAD or O_NDELAY for input_pending() */
144 # define read_tty(addr,size) read(0,addr,size)
145 # ifndef lint
146 # define input_pending() (ioctl(0, FIONREAD, &iocount), \
147 (int)iocount)
148 # else
149 # define input_pending() bizarre
150 # endif /* lint */
151 EXT long iocount INIT(0);
152 # else /* FIONREAD */
153 # ifdef RDCHK /* actually, they can have rdchk() too */
154 # define read_tty(addr,size) read(0,addr,size)
155 # ifndef lint
156 # define input_pending() rdchk(0)
157 # else /* lint */
158 # define input_pending() bizarre
159 # endif /* lint */
160 # else /* RDCHK */
161 # ifndef O_NDELAY /* assert O_NDELAY */
162 ??? PENDING is not defined correctly in warp.h
163 # endif
164 EXT int devtty INIT(0);
165 EXT bool is_input INIT(false);
166 EXT char pending_ch INIT(0);
167 # ifndef lint
168 # define input_pending() (is_input || \
169 (is_input=read(devtty,&pending_ch,1)))
170 # else
171 # define input_pending() bizarre
172 # endif /* lint */
173 # endif /* RDCHK */
174 # endif /* FIONREAD */
175 # else /* PENDING */
176 ??? warp will not work without PENDING
177 # define read_tty(addr,size) read(0,addr,size)
178 # define input_pending() (false)
179 # endif /* PENDING */
180 #endif /* PUSHBACK */
181
182 /* stuff wanted by terminal mode diddling routines */
183
184 #ifdef TERMIOS
185 EXT struct termios _tty, _oldtty;
186 #elif defined(TERMIO)
187 typedef int speed_t;
188 EXT struct termio _tty, _oldtty;
189 #define tcsetattr(fd, how, ti) ioctl(fd, how, ti)
190 #define tcgetattr(fd, ti) ioctl(fd, TCGETA, ti)
191 #define cfgetospeed(ti) ((ti)->c_cflag & CBAUD)
192 #else
193 typedef int speed_t;
194 EXT struct sgttyb _tty;
195 EXT int _res_flg INIT(0);
196 #endif
197
198 EXT int _tty_ch INIT(2);
199 EXT bool bizarre INIT(false); /* do we need to restore terminal? */
200
201 /* terminal mode diddling routines */
202
203 #if defined(TERMIO) || defined(TERMIOS)
204
205 #define raw() ((bizarre=1),_tty.c_lflag &=~ISIG,_tty.c_cc[VMIN] = 1,tcsetattr(_tty_ch,TCSAFLUSH,&_tty))
206 #define noraw() ((bizarre=1),_tty.c_lflag |= ISIG,_tty.c_cc[VEOF] = CEOF,tcsetattr(_tty_ch,TCSAFLUSH,&_tty))
207 #define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,tcsetattr(_tty_ch,TCSAFLUSH,&_tty))
208 #define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,tcsetattr(_tty_ch,TCSAFLUSH,&_tty))
209 #define echo() ((bizarre=1),_tty.c_lflag |= ECHO, tcsetattr(_tty_ch, TCSANOW, &_tty))
210 #define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, tcsetattr(_tty_ch, TCSANOW, &_tty))
211 #define nl() ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,tcsetattr(_tty_ch, TCSANOW, &_tty))
212 #define nonl() ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,tcsetattr(_tty_ch, TCSANOW, &_tty))
213 #define savetty() (tcgetattr(_tty_ch, &_oldtty),tcgetattr(_tty_ch, &_tty))
214 #define resetty() ((bizarre=0),tcsetattr(_tty_ch, TCSAFLUSH, &_oldtty))
215 #define unflush_output()
216
217 #else
218
219 #define raw() ((bizarre=1),_tty.sg_flags|=RAW, stty(_tty_ch,&_tty))
220 #define noraw() ((bizarre=1),_tty.sg_flags&=~RAW,stty(_tty_ch,&_tty))
221 #define crmode() ((bizarre=1),_tty.sg_flags |= CBREAK, stty(_tty_ch,&_tty))
222 #define nocrmode() ((bizarre=1),_tty.sg_flags &= ~CBREAK,stty(_tty_ch,&_tty))
223 #define echo() ((bizarre=1),_tty.sg_flags |= ECHO, stty(_tty_ch, &_tty))
224 #define noecho() ((bizarre=1),_tty.sg_flags &= ~ECHO, stty(_tty_ch, &_tty))
225 #define nl() ((bizarre=1),_tty.sg_flags |= CRMOD,stty(_tty_ch, &_tty))
226 #define nonl() ((bizarre=1),_tty.sg_flags &= ~CRMOD, stty(_tty_ch, &_tty))
227 #define savetty() (gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
228 #define resetty() ((bizarre=0),_tty.sg_flags = _res_flg, stty(_tty_ch, &_tty))
229 #endif /* TERMIO */
230
231 #ifdef TIOCSTI
232 #ifdef lint
233 #define forceme(c) ioctl(_tty_ch,TIOCSTI,Null(long*)) /* ghad! */
234 #else
235 #define forceme(c) ioctl(_tty_ch,TIOCSTI,c) /* pass character in " " */
236 #endif /* lint */
237 #else
238 #define forceme(c)
239 #endif
240
241 /* termcap stuff */
242
243 /*
244 * NOTE: if you don't have termlib you'll have to define these strings,
245 * the tputs routine, and the tgoto routine.
246 * The tgoto routine simply produces a cursor addressing string for a given
247 * x and y. The 1st argument is a generic string to be interpreted.
248 * If you are hardwiring it you might just ignore the 1st argument.
249 * The tputs routine interprets any leading number as a padding factor, possibly
250 * scaled by the number of lines (2nd argument), puts out the string (1st arg)
251 * and the padding using the routine specified as the 3rd argument.
252 */
253
254 #ifdef HAVETERMLIB
255 EXT char *BC INIT(NULL); /* backspace character */
256 EXT char *UP INIT(NULL); /* move cursor up one line */
257 EXT char *myUP;
258 EXT char *ND INIT(NULL); /* non-destructive cursor right */
259 EXT char *myND;
260 EXT char *DO INIT(NULL); /* move cursor down one line */
261 EXT char *myDO;
262 EXT char *CR INIT(NULL); /* get to left margin, somehow */
263 EXT char *VB INIT(NULL); /* visible bell */
264 EXT char *CL INIT(NULL); /* home and clear screen */
265 EXT char *CE INIT(NULL); /* clear to end of line */
266 EXT char *CM INIT(NULL); /* cursor motion -- PWP */
267 EXT char *HO INIT(NULL); /* home cursor -- PWP */
268 EXT char *CD INIT(NULL); /* clear to end of display -- PWP */
269 EXT char *SO INIT(NULL); /* begin standout mode */
270 EXT char *SE INIT(NULL); /* end standout mode */
271 EXT int SG INIT(0); /* blanks left by SO and SE */
272 EXT char *US INIT(NULL); /* start underline mode */
273 EXT char *UE INIT(NULL); /* end underline mode */
274 EXT char *UC INIT(NULL); /* underline a character, if that's how it's done */
275 EXT int UG INIT(0); /* blanks left by US and UE */
276 EXT bool AM INIT(false); /* does terminal have automatic margins? */
277 EXT bool XN INIT(false); /* does it eat 1st newline after automatic wrap? */
278 EXT char PC INIT(0); /* pad character for use by tputs() */
279 EXT short ospeed INIT(0); /* terminal output speed, for use by tputs() */
280 EXT int LINES INIT(0), COLS INIT(0); /* size of screen */
281 EXT int just_a_sec INIT(960); /* 1 sec at current baud rate */
282 /* (number of nulls) */
283 EXT char ERASECH; /* rubout character */
284 EXT char KILLCH; /* line delete character */
285
286 /* define a few handy macros */
287
288 #define clear() (do_tc(CL,LINES),real_y=real_x=0)
289 #define erase_eol() do_tc(CE,1)
290 #define backspace() (do_tc(BC,0),real_x--)
291 #define clear_rest() do_tc(CD,LINES)
292 #define underline() do_tc(US,1)
293 #define un_underline() do_tc(UE,1)
294 #define underchar() do_tc(UC,0)
295 #define standout() do_tc(SO,1)
296 #define un_standout() do_tc(SE,1)
297 #define up_line() do_tc(UP,1)
298 #define dingaling() do_tc(VB,1)
299 #else
300 ???????? /* up to you */
301 #endif
302
303 void term_init(void);
304 void term_set(char *);
305 #ifdef PUSHBACK
306 void pushchar(int);
307 void mac_init(char *);
308 void mac_line(char *, char *, size_t);
309 #endif
310 void page(const char *filename, size_t);
311 void move(int, int, int);
312 void do_tc(const char *, int);
313 int comp_tc(char *, const char *, int);
314 void helper(void);
315 void rewrite(void);
316 int cmstore(int);
317 void eat_typeahead(void);
318 void settle_down(void);
319 #ifndef read_tty
320 int read_tty(char *, ssize_t);
321 #endif
322 int read_nd(char *, size_t);
323 void getcmd(char *);
324 void pushstring(char *);
325
326 #endif