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