1 /*   SCCS Id: @(#)video.c   3.4     2001/04/07			    */
2 /*   Copyright (c) NetHack PC Development Team 1993, 1994, 2001	    */
3 /*   NetHack may be freely redistributed.  See license for details. */
4 /*								    */
5 /*
6  * video.c - Hardware video support front-ends
7  *
8  *Edit History:
9  *     Initial Creation 	     M. Allison      1993/04/04
10  *     Add djgpp support	     K. Smolkowski   1993/04/26
11  *     Add txt/graphics mode support M. Allison      1993/10/30
12  *     Add graphics mode cursor sim. M. Allison      1994/02/19
13  *     Add hooks for decals on vga   M. Allison      2001/04/07
14  */
15 
16 #include "hack.h"
17 
18 #ifndef STUBVIDEO
19 #include "pcvideo.h"
20 #include "pctiles.h"
21 
22 #if defined(_MSC_VER)
23 # if _MSC_VER >= 700
24 #pragma warning(disable:4018)	/* signed/unsigned mismatch */
25 #pragma warning(disable:4127)	/* conditional expression is constant */
26 #pragma warning(disable:4131)	/* old style declarator */
27 #pragma warning(disable:4305)	/* prevents complaints with MK_FP */
28 #pragma warning(disable:4309)	/* initializing */
29 #pragma warning(disable:4759)	/* prevents complaints with MK_FP */
30 # endif
31 #endif
32 /*=========================================================================
33  * General PC Video routines.
34  *
35  * The following routines are the video interfacing functions.
36  * In general these make calls to more hardware specific
37  * routines in other source files.
38  *
39  * Assumptions (94/04/23):
40  *
41  *   - Supported defaults.nh file video options:
42  *
43  *          If OPTIONS=video:autodetect is defined in defaults.nh then
44  *          check for a VGA video adapter.  If one is detected, then
45  *          use the VGA code, otherwise resort to using the 'standard'
46  *          video BIOS routines.
47  *
48  *          If OPTIONS=video:vga is defined in defaults.nh, then use
49  *          the VGA code.
50  *
51  *          If OPTIONS=video:default is defined in defaults.nh use the
52  *          'standard' video BIOS routines (in the overlaid version),
53  *          or DJGPPFAST routines (under djgpp). This is equivalent to
54  *          having no OPTIONS=video:xxxx entry at all.
55  *
56  * Notes (94/04/23):
57  *
58  *   - The handler for defaults.nh file entry:
59  *
60  *           OPTIONS=video:xxxxx
61  *
62  *     has now been added.  The handler is in video.c and is called
63  *     from options.c.
64  *
65  *   - Handling of videocolors and videoshades are now done with
66  *     OPTIONS= statements.  The new syntax separates the colour
67  *     values with dashes ('-') rather than spaces (' ').
68  *
69  * To Do (94/04/23):
70  *
71  *
72  *=========================================================================
73  */
74 
75 
76 #ifdef OVLB
77 void
get_scr_size()78 get_scr_size()
79 {
80 #  ifdef SCREEN_VGA
81 	if (iflags.usevga) {
82 		vga_get_scr_size();
83 	} else
84 #  endif
85 		txt_get_scr_size();
86 }
87 #endif /*OVLB*/
88 
89 /*
90  * --------------------------------------------------------------
91  * The rest of this file is only compiled if NO_TERMS is defined.
92  * --------------------------------------------------------------
93  */
94 
95 #ifdef NO_TERMS
96 
97 #include <ctype.h>
98 #include "wintty.h"
99 
100 # ifdef __GO32__
101 #include <pc.h>
102 #include <unistd.h>
103 #if !(__DJGPP__ >= 2)
104 typedef long clock_t;
105 #endif
106 # endif
107 
108 # ifdef __BORLANDC__
109 #include <dos.h>		/* needed for delay() */
110 # endif
111 
112 # ifdef SCREEN_DJGPPFAST	/* parts of this block may be unecessary now */
113 #define get_cursor(x,y) ScreenGetCursor(y,x)
114 # endif
115 
116 # ifdef SCREEN_BIOS
117 void FDECL(get_cursor, (int *, int *));
118 # endif
119 
120 void FDECL(adjust_cursor_flags, (struct WinDesc *));
121 void FDECL(cmov, (int, int));
122 void FDECL(nocmov, (int, int));
123 STATIC_DCL void NDECL(init_ttycolor);
124 
125 # ifdef OVLB
126 int savevmode;		  /* store the original video mode in here */
127 int curcol,currow;	  /* graphics mode current cursor locations */
128 int g_attribute;	  /* Current attribute to use */
129 int monoflag;		  /* 0 = not monochrome, else monochrome */
130 int attrib_text_normal;   /* text mode normal attribute */
131 int attrib_gr_normal;	  /* graphics mode normal attribute */
132 int attrib_text_intense;  /* text mode intense attribute */
133 int attrib_gr_intense;	  /* graphics mode intense attribute */
134 boolean traditional = FALSE; /* traditonal TTY character mode */
135 boolean inmap = FALSE;	  /* in the map window */
136 #  ifdef TEXTCOLOR
137 char ttycolors[CLR_MAX];	/* also used/set in options.c */
138 #  endif /* TEXTCOLOR */
139 # else
140 extern int savevmode;
141 extern int curcol,currow;
142 extern int g_attribute;
143 extern int monoflag;
144 extern int attrib_text_normal;
145 extern int attrib_gr_normal;
146 extern int attrib_text_intense;
147 extern int attrib_gr_intense;
148 extern boolean traditonal;
149 extern boolean inmap;
150 #  ifdef TEXTCOLOR
151 extern char ttycolors[CLR_MAX];	/* also used/set in options.c */
152 #  endif /* TEXTCOLOR */
153 # endif /* OVLB */
154 
155 # ifdef OVLB
156 void
backsp()157 backsp()
158 {
159 	if (!iflags.grmode) {
160 		txt_backsp();
161 #  ifdef SCREEN_VGA
162 	} else if (iflags.usevga) {
163 		vga_backsp();
164 #  endif
165 	}
166 }
167 # endif /* OVLB */
168 
169 # ifdef OVL0
170 void
clear_screen()171 clear_screen()
172 {
173 	if (!iflags.grmode) {
174 		txt_clear_screen();
175 #  ifdef SCREEN_VGA
176 	} else if (iflags.usevga) {
177 		vga_clear_screen(BACKGROUND_VGA_COLOR);
178 #  endif
179 	}
180 }
181 
182 void
cl_end()183 cl_end()	/* clear to end of line */
184 {
185 	int col,row;
186 
187 	col = (int)ttyDisplay->curx;
188 	row = (int)ttyDisplay->cury;
189 	if (!iflags.grmode) {
190 		txt_cl_end(col,row);
191 #  ifdef SCREEN_VGA
192 	} else if (iflags.usevga) {
193 		vga_cl_end(col,row);
194 #  endif
195 	}
196 	tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1,
197 						(int)ttyDisplay->cury);
198 }
199 
200 void
cl_eos()201 cl_eos()	/* clear to end of screen */
202 {
203 	int cy = (int)ttyDisplay->cury+1;
204 
205 	if (!iflags.grmode) {
206 		txt_cl_eos();
207 #  ifdef SCREEN_VGA
208 	} else if (iflags.usevga) {
209 		vga_cl_eos(cy);
210 #  endif
211 	}
212 	tty_curs(BASE_WINDOW, (int)ttyDisplay->curx+1,
213 						(int)ttyDisplay->cury);
214 }
215 
216 void
cmov(col,row)217 cmov(col, row)
218 register int col, row;
219 {
220 	ttyDisplay->cury = (uchar)row;
221 	ttyDisplay->curx = (uchar)col;
222 	if (!iflags.grmode) {
223 		txt_gotoxy(col,row);
224 #  ifdef SCREEN_VGA
225 	} else if (iflags.usevga) {
226 		vga_gotoloc(col,row);
227 #  endif
228 	}
229 }
230 # endif /* OVL0 */
231 
232 # ifdef OVLB
233 int
has_color(int color)234 has_color(int color)
235 {
236 	++color;		/* prevents compiler warning (unref. param) */
237 #  ifdef TEXTCOLOR
238 	return	(monoflag) ? 0 : 1;
239 #  else
240 	return 0;
241 #  endif
242 }
243 # endif /* OVLB */
244 
245 # ifdef OVL0
246 void
home()247 home()
248 {
249 	tty_curs(BASE_WINDOW, 1, 0);
250 	ttyDisplay->curx = ttyDisplay->cury = (uchar)0;
251 	if (!iflags.grmode) {
252 		txt_gotoxy(0,0);
253 #  ifdef SCREEN_VGA
254 	} else if (iflags.usevga) {
255 		vga_gotoloc(0,0);
256 #  endif
257 	}
258 }
259 
260 void
nocmov(col,row)261 nocmov(col, row)
262 int col,row;
263 {
264 	if (!iflags.grmode) {
265 		txt_gotoxy(col,row);
266 #  ifdef SCREEN_VGA
267 	} else if (iflags.usevga) {
268 		vga_gotoloc(col,row);
269 #  endif
270 	}
271 }
272 
273 void
standoutbeg()274 standoutbeg()
275 {
276 	g_attribute = iflags.grmode ? attrib_gr_intense
277 				   : attrib_text_intense;
278 }
279 
280 void
standoutend()281 standoutend()
282 {
283 	g_attribute = iflags.grmode ? attrib_gr_normal
284 				   : attrib_text_normal;
285 }
286 # endif /* OVL0 */
287 
288 
289 # ifdef OVLB
290 void
term_end_attr(int attr)291 term_end_attr(int attr)
292 {
293 	switch(attr) {
294 		case ATR_ULINE:
295 		case ATR_BOLD:
296 		case ATR_BLINK:
297 		case ATR_INVERSE:
298 		default:
299 		g_attribute = iflags.grmode ? attrib_gr_normal
300 					   : attrib_text_normal;
301 	}
302 }
303 
304 void
term_end_color(void)305 term_end_color(void)
306 {
307 	g_attribute = iflags.grmode ? attrib_gr_normal
308 				   : attrib_text_normal;
309 }
310 
311 void
term_end_raw_bold(void)312 term_end_raw_bold(void)
313 {
314     standoutend();
315 }
316 
317 
318 void
term_start_attr(int attr)319 term_start_attr(int attr)
320 {
321     switch(attr){
322 
323 	case ATR_ULINE:
324 		if (monoflag) {
325 			g_attribute = ATTRIB_MONO_UNDERLINE;
326 		} else {
327 			g_attribute = iflags.grmode ? attrib_gr_intense
328 						   : attrib_text_intense;
329 		}
330 		break;
331 	case ATR_BOLD:
332 		g_attribute = iflags.grmode ? attrib_gr_intense
333 					   : attrib_text_intense;
334 		break;
335 	case ATR_BLINK:
336 		if (monoflag) {
337 			g_attribute = ATTRIB_MONO_BLINK;
338 		} else {
339 			g_attribute = iflags.grmode ? attrib_gr_intense
340 						   : attrib_text_intense;
341 		}
342 		break;
343 	case ATR_INVERSE:
344 		if (monoflag) {
345 			g_attribute = ATTRIB_MONO_REVERSE;
346 		} else {
347 			g_attribute = iflags.grmode ? attrib_gr_intense
348 						   : attrib_text_intense;
349 		}
350 		break;
351 	default:
352 		g_attribute = iflags.grmode ? attrib_gr_normal
353 					   : attrib_text_normal;
354 		break;
355     }
356 }
357 
358 
359 void
term_start_color(int color)360 term_start_color(int color)
361 {
362 #  ifdef TEXTCOLOR
363 	if (monoflag) {
364 			g_attribute = attrib_text_normal;
365 	} else {
366 		if (color >= 0 && color < CLR_MAX) {
367 			if (iflags.grmode)
368 				g_attribute = color;
369 			else
370 				g_attribute = ttycolors[color];
371 		}
372 	}
373 #  endif
374 }
375 
376 void
term_start_raw_bold(void)377 term_start_raw_bold(void)
378 {
379     standoutbeg();
380 }
381 # endif /* OVLB */
382 
383 # ifdef OVL0
384 void
tty_delay_output()385 tty_delay_output()
386 {
387 #ifdef TIMED_DELAY
388 	if (flags.nap) {
389 	    (void) fflush(stdout);
390 	    msleep(50);		/* sleep for 50 milliseconds */
391 	    return;
392 	}
393 #endif
394 }
395 
396 # endif /* OVL0 */
397 
398 # ifdef OVLB
399 void
tty_end_screen()400 tty_end_screen()
401 {
402 
403 	if (!iflags.grmode) {
404 		txt_clear_screen();
405 #  ifdef PC9800
406 		fputs("\033[>1l", stdout);
407 #  endif
408 #  ifdef SCREEN_VGA
409 	} else if (iflags.usevga) {
410 		vga_tty_end_screen();
411 #  endif
412 	}
413 }
414 
415 void
tty_nhbell()416 tty_nhbell()
417 {
418 	txt_nhbell();
419 }
420 
421 
422 void
tty_number_pad(state)423 tty_number_pad(state)
424 int state;
425 {
426 	++state;		/* prevents compiler warning (unref. param) */
427 }
428 
429 void
tty_startup(wid,hgt)430 tty_startup(wid, hgt)
431 int *wid, *hgt;
432 {
433 
434 	/* code to sense display adapter is required here - MJA */
435 
436 	attrib_text_normal  = ATTRIB_NORMAL;
437 	attrib_text_intense = ATTRIB_INTENSE;
438 
439 	/* These are defaults and may get overridden */
440 	attrib_gr_normal    = attrib_text_normal;
441 	attrib_gr_intense   = attrib_text_intense;
442 	g_attribute = attrib_text_normal;	/* Give it a starting value */
443 
444 #  ifdef SCREEN_VGA
445 	if (iflags.usevga) {
446 		vga_tty_startup(wid, hgt);
447 	} else
448 #  endif
449 	txt_startup(wid, hgt);
450 
451 	*wid = CO;
452 	*hgt = LI;
453 
454 #  ifdef CLIPPING
455 	if (CO < COLNO || LI < ROWNO+3) setclipped();
456 #  endif
457 
458 #  ifdef TEXTCOLOR
459 	init_ttycolor();
460 #  endif
461 
462 #  ifdef MONO_CHECK
463 	monoflag = txt_monoadapt_check();
464 #  else
465 	monoflag = 0;
466 #  endif
467 
468 }
469 
470 void
tty_start_screen()471 tty_start_screen()
472 {
473 #  ifdef PC9800
474 	fputs("\033[>1h", stdout);
475 #  endif
476 	if (iflags.num_pad) tty_number_pad(1);	/* make keypad send digits */
477 }
478 
479 void
gr_init()480 gr_init(){
481 	if (iflags.usevga)	{
482 # ifdef SCREEN_VGA
483 		vga_Init();
484 # endif
485 # ifdef SCREEN_VESA
486 	} else if (iflags.usevesa) {
487 		vesa_Init();
488 
489 # endif
490 # ifdef SCREEN_8514
491 	} else if (iflags.use8514) {
492 		v8514_Init();
493 # endif
494 	}
495 }
496 
497 void
gr_finish()498 gr_finish()
499 {
500 	if (iflags.grmode) {
501 	   if (iflags.usevga) {
502 # ifdef SCREEN_VGA
503 		vga_Finish();
504 # endif
505 # ifdef SCREEN_VESA
506 	   } else if (iflags.usevesa) {
507 		vesa_Finish();
508 # endif
509 # ifdef SCREEN_8514
510 	   } else if (iflags.use8514) {
511 		v8514_Finish();
512 # endif
513 	   }
514 	}
515 }
516 
517 # endif /* OVLB */
518 
519 /*
520  * Screen output routines (these are heavily used).
521  *
522  * These are the 3 routines used to place information on the screen
523  * in the NO_TERMS PC tty port of NetHack.  These are the routines
524  * that get called by routines in other NetHack source files (such
525  * as those in win/tty).
526  *
527  * xputs - Writes a c null terminated string at the current location.
528  *	   Depending on compile options, this could just be a series
529  *	   of repeated calls to xputc() for each character.
530  *
531  * xputc - Writes a single character at the current location. Since
532  *	   various places in the code assume that control characters
533  *	   can be used to control, we are forced to interpret some of
534  *	   the more common ones, in order to keep things looking correct.
535  *
536  * xputg - If using a graphics mode display mechanism (such as VGA, this
537  *	   routine is used to display a graphical representation of a
538  *	   NetHack glyph at the current location.  For more information on
539  *	   NetHack glyphs refer to the comments in include/display.h.
540  *
541  * NOTES:
542  *	   wintty.h uses macros to redefine common output functions
543  *	   such as puts, putc, putchar, so that they get steered into
544  *	   either xputs (for strings) or xputc (for single characters).
545  *	   References to puts, putc, and putchar in other source files
546  *	   (that include wintty.h) are actually using these routines.
547  */
548 
549 # ifdef OVL0
550 void
xputs(s)551 xputs(s)
552 const char *s;
553 {
554 	int col,row;
555 
556 	col = (int)ttyDisplay->curx;
557 	row = (int)ttyDisplay->cury;
558 
559 	if (!iflags.grmode) {
560 		txt_xputs(s,col,row);
561 #  ifdef SCREEN_VGA
562 	} else if (iflags.usevga) {
563 		vga_xputs(s,col,row);
564 #  endif
565 	}
566 }
567 
568 void
xputc(ch)569 xputc(ch)	/* write out character (and attribute) */
570 char ch;
571 {
572 	int i;
573 	char attribute;
574 
575 	i = iflags.grmode ? attrib_gr_normal
576 			 : attrib_text_normal;
577 
578 	attribute = (char)((g_attribute == 0) ? i : g_attribute);
579 	if (!iflags.grmode) {
580 		txt_xputc(ch,attribute);
581 #  ifdef SCREEN_VGA
582 	} else if (iflags.usevga) {
583 		vga_xputc(ch,attribute);
584 #  endif /*SCREEN_VGA*/
585 	}
586 }
587 
588 void
xputg(glyphnum,ch,special)589 xputg(glyphnum,ch,special)	/* write out a glyph picture at current location */
590 int glyphnum;
591 int ch;
592 unsigned special;
593 {
594 	if (!iflags.grmode || !iflags.tile_view) {
595 		xputc((char)ch);
596 #  ifdef SCREEN_VGA
597 	} else {
598 		vga_xputg(glyphnum, ch, special);
599 #  endif
600 	}
601 }
602 
603 #  ifdef POSITIONBAR
604 void
video_update_positionbar(posbar)605 video_update_positionbar(posbar)
606 char *posbar;
607 {
608 	if (!iflags.grmode)
609 		return;
610 #   ifdef SCREEN_VGA
611 	else
612 		vga_update_positionbar(posbar);
613 #   endif
614 }
615 #  endif
616 
617 void
adjust_cursor_flags(cw)618 adjust_cursor_flags(cw)
619 struct WinDesc *cw;
620 {
621 #  ifdef SIMULATE_CURSOR
622 #   if 0
623     if (cw->type == NHW_MAP) cursor_flag = 1;
624     else cursor_flag = 0;
625 #   else
626     if (cw->type == NHW_MAP) {
627 	inmap = 1;
628 	cursor_flag = 1;
629     } else {
630 	inmap = 0;
631 	cursor_flag = 1;
632     }
633 #   endif /* 0 */
634 #  endif /* SIMULATE_CURSOR */
635 }
636 
637 #  ifdef SIMULATE_CURSOR
638 
639 /* change the defaults in pcvideo.h, not here */
640 int cursor_type  = CURSOR_DEFAULT_STYLE;
641 int cursor_color = CURSOR_DEFAULT_COLOR;
642 int cursor_flag;
643 
644 /* The check for iflags.grmode is made BEFORE calling these. */
645 void
DrawCursor()646 DrawCursor()
647 {
648 #  ifdef SCREEN_VGA
649 	vga_DrawCursor();
650 #  endif
651 }
652 
653 void
HideCursor()654 HideCursor()
655 {
656 #  ifdef SCREEN_VGA
657 	vga_HideCursor();
658 #  endif
659 }
660 
661 #  endif /* SIMULATE_CURSOR */
662 # endif /* OVL0 */
663 
664 # ifdef TEXTCOLOR
665 /*
666  * CLR_BLACK		0
667  * CLR_RED		1
668  * CLR_GREEN		2
669  * CLR_BROWN		3	low-intensity yellow
670  * CLR_BLUE 		4
671  * CLR_MAGENTA		5
672  * CLR_CYAN 		6
673  * CLR_GRAY 		7	low-intensity white
674  * NO_COLOR		8
675  * CLR_ORANGE		9
676  * CLR_BRIGHT_GREEN 	10
677  * CLR_YELLOW		11
678  * CLR_BRIGHT_BLUE	12
679  * CLR_BRIGHT_MAGENTA	13
680  * CLR_BRIGHT_CYAN	14
681  * CLR_WHITE		15
682  * CLR_MAX		16
683  * BRIGHT		8
684  */
685 
686 #  ifdef VIDEOSHADES
687 /* assign_videoshades() is prototyped in extern.h */
688 /* assign_videocolors() is prototyped in extern.h */
689 /* assign_video()	is prototyped in extern.h */
690 
691 #   ifdef OVLB
692 int shadeflag;					/* shades are initialized */
693 int colorflag;					/* colors are initialized */
694 char *schoice[3] = {"dark","normal","light"};
695 char *shade[3];
696 #   else
697 extern int shadeflag;
698 extern int colorflag;
699 extern char *schoice[3];
700 extern char *shade[3];
701 #   endif /* OVLB */
702 
703 #  endif /* VIDEOSHADES */
704 
705 #  ifdef OVLB
706 STATIC_OVL void
init_ttycolor()707 init_ttycolor()
708 {
709 #   ifdef VIDEOSHADES
710 	if (!shadeflag) {
711 		ttycolors[CLR_BLACK] = M_BLACK;	/*  8 = dark gray */
712 		ttycolors[CLR_WHITE] = M_WHITE;	/* 15 = bright white */
713 		ttycolors[CLR_GRAY]  = M_GRAY;	/*  7 = normal white */
714 		shade[0] = schoice[0];
715 		shade[1] = schoice[1];
716 		shade[2] = schoice[2];
717 	}
718 #   else
719 	ttycolors[CLR_BLACK] = M_GRAY;		/*  mapped to white */
720 	ttycolors[CLR_WHITE] = M_GRAY;		/*  mapped to white */
721 	ttycolors[CLR_GRAY]  = M_GRAY;		/*  mapped to white */
722 #   endif
723 
724 #   ifdef VIDEOSHADES
725 	if (!colorflag) {
726 #   endif
727 		ttycolors[CLR_RED]	      = M_RED;
728 		ttycolors[CLR_GREEN]	      = M_GREEN;
729 		ttycolors[CLR_BROWN]	      = M_BROWN;
730 		ttycolors[CLR_BLUE] 	      = M_BLUE;
731 		ttycolors[CLR_MAGENTA]	      = M_MAGENTA;
732 		ttycolors[CLR_CYAN] 	      = M_CYAN;
733 		ttycolors[BRIGHT]	      = M_WHITE;
734 		ttycolors[CLR_ORANGE]	      = M_ORANGE;
735 		ttycolors[CLR_BRIGHT_GREEN]   = M_BRIGHTGREEN;
736 		ttycolors[CLR_YELLOW]	      = M_YELLOW;
737 		ttycolors[CLR_BRIGHT_BLUE]    = M_BRIGHTBLUE;
738 		ttycolors[CLR_BRIGHT_MAGENTA] = M_BRIGHTMAGENTA;
739 		ttycolors[CLR_BRIGHT_CYAN]    = M_BRIGHTCYAN;
740 #   ifdef VIDEOSHADES
741 	}
742 #   endif
743 }
744 #  endif /* OVLB */
745 
746 #  ifdef OVL1
747 	static int FDECL(convert_uchars,(char *, uchar *, int));
748 #   ifdef VIDEOSHADES
assign_videoshades(char * choiceptr)749 int assign_videoshades(char *choiceptr)
750 {
751 	char choices[120];
752 	char *cptr, *cvalue[3];
753 	int i,icolor = CLR_WHITE;
754 
755 	strcpy(choices,choiceptr);
756 	cvalue[0] = choices;
757 
758 	/* find the next ' ' or tab */
759 	cptr = index(cvalue[0], '-');
760 	if (!cptr) cptr = index(cvalue[0], ' ');
761 	if (!cptr) cptr = index(cvalue[0], '\t');
762 	if (!cptr) return 0;
763 	*cptr = '\0';
764 	/* skip  whitespace between '=' and value */
765 	do { ++cptr; } while (isspace(*cptr) || (*cptr == '-'));
766 	cvalue[1] = cptr;
767 
768 	cptr = index(cvalue[1], '-');
769 	if (!cptr) cptr = index(cvalue[0], ' ');
770 	if (!cptr) cptr = index(cvalue[0], '\t');
771 	if (!cptr) return 0;
772 	*cptr = '\0';
773 	do { ++cptr; } while (isspace(*cptr) || (*cptr == '-'));
774 	cvalue[2] = cptr;
775 
776 	for (i=0; i < 3; ++i) {
777 		switch(i) {
778 			case 0: icolor = CLR_BLACK;
779 				break;
780 			case 1: icolor = CLR_GRAY;
781 				break;
782 			case 2: icolor = CLR_WHITE;
783 				break;
784 		}
785 
786 		shadeflag = 1;
787 		if ((strncmpi(cvalue[i],"black",5) == 0) ||
788 		    (strncmpi(cvalue[i],"dark",4) == 0)) {
789 			shade[i] = schoice[0];
790 			ttycolors[icolor] = M_BLACK;	/* dark gray */
791 		} else if ((strncmpi(cvalue[i],"gray",4) == 0) ||
792 			   (strncmpi(cvalue[i],"grey",4) == 0) ||
793 			   (strncmpi(cvalue[i],"medium",6) == 0) ||
794 			   (strncmpi(cvalue[i],"normal",6) == 0)) {
795 			shade[i] = schoice[1];
796 			ttycolors[icolor] = M_GRAY;	/* regular gray */
797 		} else if ((strncmpi(cvalue[i],"white",5) == 0) ||
798 			   (strncmpi(cvalue[i],"light",5) == 0)) {
799 			shade[i] = schoice[2];
800 			ttycolors[icolor] = M_WHITE;  /* bright white */
801 		} else {
802 			shadeflag = 0;
803 			return 0;
804 		}
805 	}
806 	return 1;
807 }
808 
809 /*
810  * Process defaults.nh OPTIONS=videocolors:xxx
811  * Left to right assignments for:
812  *	red green brown blue magenta cyan orange br.green yellow
813  *	br.blue br.mag br.cyan
814  *
815  * Default Mapping (BIOS): 4-2-6-1-5-3-12-10-14-9-13-11
816  */
assign_videocolors(char * colorvals)817 int assign_videocolors(char *colorvals)
818 {
819 	int i,icolor;
820 	uchar *tmpcolor;
821 
822 	init_ttycolor();	/* in case defaults.nh entry wasn't complete */
823 	i = strlen(colorvals);
824 	tmpcolor = (uchar *)alloc(i);
825 	(void)convert_uchars(colorvals,tmpcolor,i);
826 	icolor = CLR_RED;
827 	for( i = 0; tmpcolor[i] != 0; ++i) {
828 		if (icolor < (CLR_WHITE)) {
829 			ttycolors[icolor++] = tmpcolor[i];
830 			if ((icolor > CLR_CYAN) && (icolor < CLR_ORANGE)) {
831 				 icolor = CLR_ORANGE;
832 			}
833 		}
834 	}
835 	colorflag = 1;
836 	free((genericptr_t)tmpcolor);
837 	return 1;
838 }
839 
840 static int
convert_uchars(bufp,list,size)841 convert_uchars(bufp,list,size)
842     char *bufp; 	/* current pointer */
843     uchar *list;	/* return list */
844     int size;
845 {
846     unsigned int num = 0;
847     int count = 0;
848 
849     while (1) {
850 	switch(*bufp) {
851 	    case ' ':  case '\0':
852 	    case '\t': case '-':
853 	    case '\n':
854 		if (num) {
855 		    list[count++] =  num;
856 		    num = 0;
857 		}
858 		if ((count==size) || !*bufp) return count;
859 		bufp++;
860 		break;
861 
862 	    case '0': case '1': case '2': case '3':
863 	    case '4': case '5': case '6': case '7':
864 	    case '8': case '9':
865 		num = num*10 + (*bufp-'0');
866 		bufp++;
867 		break;
868 		return count;
869 	}
870     }
871     /*NOTREACHED*/
872 }
873 
874 #   endif /* VIDEOSHADES */
875 #  endif /* OVL1 */
876 # endif /* TEXTCOLOR */
877 
878 /*
879  * Process defaults.nh OPTIONS=video:xxxx
880  *
881  *    where (current) legitimate values are:
882  *
883  *    autodetect (attempt to determine the adapter type)
884  *    default	 (force use of the default video method for environment)
885  *    vga	 (use vga adapter code)
886  */
887 # ifdef OVL1
888 int
assign_video(sopt)889 assign_video(sopt)
890 char *sopt;
891 {
892 
893 /*
894  * debug
895  *
896  *	printf("video is %s",sopt);
897  *	getch();
898  */
899 	iflags.grmode  = 0;
900 	iflags.hasvga  = 0;
901 	iflags.usevga  = 0;
902 
903 	if (strncmpi(sopt,"def",3) == 0) {              /* default */
904 		/* do nothing - default */
905 #  ifdef SCREEN_VGA
906 	} else if (strncmpi(sopt,"vga",3) == 0) {       /* vga */
907 		iflags.usevga  = 1;
908 		iflags.hasvga  = 1;
909 #  endif
910 #  ifdef SCREEN_VESA
911 	} else if (strncmpi(sopt,"vesa",4) == 0) {      /* vesa */
912 		iflags.hasvesa = 1;
913 		iflags.usevesa = 1;
914 #  endif
915 #  ifdef SCREEN_8514
916 	} else if (strncmpi(sopt,"8514",4) == 0) {      /* 8514/A */
917 		iflags.use8514 = 1;
918 		iflags.has8514 = 1;
919 #  endif
920 	} else if (strncmpi(sopt,"auto",4) == 0) {      /* autodetect */
921 #  ifdef SCREEN_VESA
922 		if (vesa_detect()) {
923 			iflags.hasvesa = 1;
924 		}
925 #  endif
926 #  ifdef SCREEN_8514
927 		if (v8514_detect()) {
928 			iflags.has8514 = 1;
929 		}
930 #  endif
931 #  ifdef SCREEN_VGA
932 		if (vga_detect()) {
933 			iflags.hasvga  = 1;
934 		}
935 #  endif
936 	/*
937 	 * Auto-detect Priorities (arbitrary for now):
938 	 *	VGA
939 	 */
940 		if (iflags.hasvga)	{
941 			iflags.usevga  = 1;
942 			/* VGA depends on BIOS to enable function keys*/
943 			iflags.BIOS = 1;
944 			iflags.rawio = 1;
945 		}
946 	} else {
947 		return 0;
948 	}
949 	return 1;
950 }
951 # endif /* OVL1 */
952 # ifdef OVL0
953 
tileview(enable)954 void tileview(enable)
955 boolean enable;
956 {
957 #ifdef SCREEN_VGA
958 	if (iflags.grmode) vga_traditional(enable ? FALSE : TRUE);
959 #endif
960 }
961 # endif /* OVL0 */
962 #endif /* NO_TERMS  */
963 #else	/* STUBVIDEO */
tileview(enable)964 void tileview(enable)
965 boolean enable;
966 {
967 }
968 #endif /* STUBVIDEO */
969 
970