1 /* Header: term.h,v 7.0.1.2 86/12/12 17:05:15 lwall Exp */
4 * Revision 7.0.1.2 86/12/12 17:05:15 lwall
5 * Baseline for net release.
7 * Revision 7.0.1.1 86/10/16 10:53:33 lwall
8 * Added Damage. Fixed random bugs.
10 * Revision 7.0 86/10/08 15:14:07 lwall
11 * Split into separate files. Added amoebas and pirates.
20 /* Compat with old termios. */
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)
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.
35 #define setimage(of,to) (mvaddch(of->posy+1,of->posx*2,of->image=(to)))
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)
46 EXT
const char *tmpstr
;
47 /* EXT char tmpchr; */
49 /* The following macros are like the pseudo-curses macros above, but do
50 * certain amount of controlled output buffering.
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()
57 #define beg_qwrite() (maxcmstring = cmbuffer)
59 #define qwrite() asm("movc3 _gfillen,_filler,*_maxcmstring"); maxcmstring += gfillen
61 #define qwrite() (movc3(gfillen,filler,maxcmstring), maxcmstring += gfillen)
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))
68 /* setting a ??size to infinity forces cursor addressing in that direction */
71 EXT
int BCsize
INIT(1);
72 EXT
int DOsize
INIT(1000);
73 EXT
int UPsize
INIT(1000);
74 EXT
int NDsize
INIT(1000);
76 EXT
int charsperhalfsec
;
78 EXT
int real_y
INIT(-100);
79 EXT
int real_x
INIT(-100);
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};
87 EXT
char *bsptr
INIT(filler
+1);
91 EXT
char gfillen
INIT(25);
93 EXT
char *maxcmstring
;
94 EXT
char cmbuffer
[512];
98 EXT
char INTRCH
INIT('\03');
101 EXT
char circlebuf
[PUSHSIZE
];
102 EXT
int nextin
INIT(0);
103 EXT
int nextout
INIT(0);
106 EXT
long iocount
INIT(0);
108 # define input_pending() (nextin!=nextout || \
109 (ioctl(0, FIONREAD, &iocount),(int)iocount))
111 # define input_pending() bizarre
113 # else /* FIONREAD */
117 # define input_pending() rdchk(0)
119 # define input_pending() bizarre
122 # ifndef O_NDELAY /* assert O_NDELAY */
123 ??? PENDING is
not defined correctly in warp
.h
125 EXT
int devtty
INIT(0);
127 # define input_pending() (nextin!=nextout || circfill())
129 # define input_pending() bizarre
132 # endif /* FIONREAD */
134 # ??? warp will not work without PENDING
136 # define input_pending() (nextin!=nextout)
138 # define input_pending() bizarre
140 # endif /* PENDING */
143 # ifdef FIONREAD /* must have FIONREAD or O_NDELAY for input_pending() */
144 # define read_tty(addr,size) read(0,addr,size)
146 # define input_pending() (ioctl(0, FIONREAD, &iocount), \
149 # define input_pending() bizarre
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)
156 # define input_pending() rdchk(0)
158 # define input_pending() bizarre
161 # ifndef O_NDELAY /* assert O_NDELAY */
162 ??? PENDING is
not defined correctly in warp
.h
164 EXT
int devtty
INIT(0);
165 EXT
bool is_input
INIT(false);
166 EXT
char pending_ch
INIT(0);
168 # define input_pending() (is_input || \
169 (is_input=read(devtty,&pending_ch,1)))
171 # define input_pending() bizarre
174 # endif /* FIONREAD */
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 */
182 /* stuff wanted by terminal mode diddling routines */
185 EXT
struct termios _tty
, _oldtty
;
186 #elif defined(TERMIO)
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)
194 EXT
struct sgttyb _tty
;
195 EXT
int _res_flg
INIT(0);
198 EXT
int _tty_ch
INIT(2);
199 EXT
bool bizarre
INIT(false); /* do we need to restore terminal? */
201 /* terminal mode diddling routines */
203 #if defined(TERMIO) || defined(TERMIOS)
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()
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))
233 #define forceme(c) ioctl(_tty_ch,TIOCSTI,Null(long*)) /* ghad! */
235 #define forceme(c) ioctl(_tty_ch,TIOCSTI,c) /* pass character in " " */
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.
255 EXT
char *BC
INIT(NULL
); /* backspace character */
256 EXT
char *UP
INIT(NULL
); /* move cursor up one line */
258 EXT
char *ND
INIT(NULL
); /* non-destructive cursor right */
260 EXT
char *DO
INIT(NULL
); /* move cursor down one line */
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 */
286 /* define a few handy macros */
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)
300 ???????? /* up to you */
303 void term_init(void);
304 void term_set(char *);
307 void mac_init(char *);
308 void mac_line(char *, char *, size_t);
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);
317 void eat_typeahead(void);
318 void settle_down(void);
320 int read_tty(char *, ssize_t
);
322 int read_nd(char *, size_t);
324 void pushstring(char *);