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