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