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