Take care of one BSOD in NtGdiDdCreateDirectDrawObject, it is not correct fix, it...
[reactos.git] / rosapps / mc / slang / slvideo.c
1 /* Copyright (c) 1992, 1995 John E. Davis
2 * All rights reserved.
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Perl Artistic License.
6 */
7
8 #include "config.h"
9
10 #include <stdio.h>
11 #include <string.h>
12
13 #include <stdlib.h>
14
15 #ifdef __WIN32__
16 # include <windows.h>
17 #endif
18
19 #ifdef __GO32__
20 # undef msdos
21 #endif
22
23 #if defined (msdos)
24 # include <conio.h>
25 # include <bios.h>
26 # include <mem.h>
27 #endif
28 #if defined (__WATCOMC__)
29 # include <graph.h>
30 # define int86 int386 /* simplify code writing */
31 #endif
32
33 #if defined (__GO32__)
34 # include <pc.h>
35 # define GO32_VIDEO
36 #endif
37
38 #if defined (__os2__) && !defined (EMX_VIDEO)
39 # define INCL_BASE
40 # define INCL_NOPM
41 # define INCL_VIO
42 # define INCL_KBD
43 # include <os2.h>
44 #else
45 # if defined (__EMX__) /* EMX video does both DOS & OS/2 */
46 # ifndef EMX_VIDEO
47 # define EMX_VIDEO
48 # endif
49 # include <sys/video.h>
50 # endif
51 #endif
52
53 #include <dos.h>
54 #include "slang.h"
55
56 #ifdef GO32_VIDEO
57 # define HAS_SAVE_SCREEN
58 #endif
59
60 /* ------------------------- global variables ------------------------- */
61
62 #ifdef WIN32
63 extern HANDLE hStdout, hStdin;
64 extern CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
65 #endif
66
67
68 int SLtt_Term_Cannot_Insert;
69 int SLtt_Term_Cannot_Scroll;
70 int SLtt_Ignore_Beep = 3;
71 int SLtt_Use_Ansi_Colors;
72
73 int SLtt_Screen_Rows = 25;
74 int SLtt_Screen_Cols = 80;
75
76 /* ------------------------- local variables -------------------------- */
77 static int Attribute_Byte;
78 static int Scroll_r1 = 0, Scroll_r2 = 25;
79 static int Cursor_Row = 1, Cursor_Col = 1;
80 static int Current_Color;
81 static int IsColor = 1;
82 static int Blink_Killed; /* high intensity background enabled */
83
84 #define JMAX_COLORS 256
85 #define JNORMAL_COLOR 0
86 #define JNO_COLOR -1
87
88 static unsigned char Color_Map [JMAX_COLORS] =
89 {
90 0x7, 0x70, 0x70, 0x70, 0x70, 0x7, 0x7, 0x7,
91 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
92 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
93 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
94 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
95 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
96 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
97 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
98 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
99 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
100 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
101 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
102 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
103 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
104 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
105 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
106 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
107 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
108 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
109 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
110 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
111 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
112 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
113 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
114 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
115 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
116 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
117 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
118 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
119 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
120 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
121 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7
122 };
123
124
125 #define JMAX_COLOR_NAMES 16
126 static char *Color_Names [JMAX_COLOR_NAMES] =
127 {
128 "black", "blue", "green", "cyan",
129 "red", "magenta", "brown", "lightgray",
130 "gray", "brightblue", "brightgreen", "brightcyan",
131 "brightred", "brightmagenta", "yellow", "white"
132 };
133
134 /*
135 * set_color_from_attribute (int attribute);
136 * define the correspondence of color to attribute
137 */
138 #define set_color_from_attribute(a)\
139 SLtt_set_color (\
140 JNORMAL_COLOR, NULL,\
141 Color_Names[(a) & 0xf],\
142 Color_Names[(a) >> 4])
143 /* this is how to make a space character */
144 #define mkSpaceChar() (((Attribute_Byte) << 8) | 0x20)
145
146 /* buffer to hold a line of character/attribute pairs */
147 #define MAXCOLS 256
148 static unsigned char Line_Buffer [MAXCOLS*2];
149
150 /*----------------------------------------------------------------------*\
151 * define various ways and means of writing to the screen
152 \*----------------------------------------------------------------------*/
153 #if defined (__GO32__) || defined (__WATCOMC__)
154 # if !defined (GO32_VIDEO)
155 # define HAS_LINEAR_SCREEN
156 # endif
157 #else /* __GO32__ or __WATCOMC__ */
158 # if defined (msdos)
159 # define USE_ASM
160 # endif
161 #endif /* __GO32__ or __WATCOMC__ */
162
163 /* define for direct to memory screen writes */
164 #if defined (USE_ASM) || defined (HAS_LINEAR_SCREEN)
165 static unsigned char *Video_Base;
166 # define mkScreenPointer(row,col) ((unsigned short *)\
167 (Video_Base +\
168 2 * (SLtt_Screen_Cols * (row)\
169 + (col))))
170 # if defined (USE_ASM)
171 int SLtt_Msdos_Cheap_Video = 0;
172 static int Video_Status_Port;
173
174 # define MONO_STATUS 0x3BA
175 # define CGA_STATUS 0x3DA
176 # define CGA_SETMODE 0x3D8
177
178 # define SNOW_CHECK \
179 if (SLtt_Msdos_Cheap_Video)\
180 { while ((inp (CGA_STATUS) & 0x08)); while (!(inp (CGA_STATUS) & 0x08)); }
181 # endif /* USE_ASM */
182 #endif /* USE_ASM or HAS_LINEAR_SCREEN */
183
184
185 /* -------------------------------------------------------------------- */
186 #if defined (__WATCOMC__)
187 # define ScreenPrimary (0xb800 << 4)
188 # define ScreenSize (SLtt_Screen_Cols * SLtt_Screen_Rows)
189 # define ScreenSetCursor (x,y) _settextposition (x+1,y+1)
190 void ScreenGetCursor (int *x, int *y)
191 {
192 struct rccoord rc = _gettextposition ();
193 *x = rc.row - 1;
194 *y = rc.col - 1;
195 }
196 void ScreenRetrieve (unsigned char *dest)
197 {
198 memcpy (dest, (unsigned char *) ScreenPrimary, 2 * ScreenSize);
199 }
200 void ScreenUpdate (unsigned char *src)
201 {
202 memcpy ((unsigned char *) ScreenPrimary, src, 2 * ScreenSize);
203 }
204 #endif /* __WATCOMC__ */
205
206 #ifdef HAS_SAVE_SCREEN
207 static void *Saved_Screen_Buffer;
208 static int Saved_Cursor_Row;
209
210 static void save_screen (void)
211 {
212 int row, col;
213
214 if (Saved_Screen_Buffer != NULL)
215 {
216 SLFREE (Saved_Screen_Buffer);
217 Saved_Screen_Buffer = NULL;
218 }
219 #ifdef GO32_VIDEO
220 Saved_Screen_Buffer = SLMALLOC (sizeof (short) *
221 ScreenCols () * ScreenRows ());
222
223 if (Saved_Screen_Buffer == NULL)
224 return;
225
226 ScreenRetrieve (Saved_Screen_Buffer);
227 ScreenGetCursor (&row, &col);
228 Saved_Cursor_Row = row;
229 #endif
230
231 }
232
233 static void restore_screen (void)
234 {
235 if (Saved_Screen_Buffer == NULL) return;
236 #ifdef GO32_VIDEO
237 ScreenUpdate (Saved_Screen_Buffer);
238 SLtt_goto_rc (Saved_Cursor_Row, 0);
239 #endif
240
241 }
242 #endif /* HAS_SAVE_SCREEN */
243 /*----------------------------------------------------------------------*\
244 * Function: void SLtt_write_string (char *str);
245 *
246 * put string STR to 'stdout'
247 \*----------------------------------------------------------------------*/
248 void SLtt_write_string (char *str)
249 {
250 #ifdef WIN32
251 unsigned long bytes;
252
253 (void) WriteConsole(hStdout, str, strlen(str), &bytes, NULL);
254 #else
255 fputs (str, stdout);
256 #endif
257 }
258
259 /*----------------------------------------------------------------------*\
260 * Function: void SLtt_set_scroll_region (int r1, int r2);
261 *
262 * define a scroll region of top_row to bottom_row
263 \*----------------------------------------------------------------------*/
264 void SLtt_set_scroll_region (int top_row, int bottom_row)
265 {
266 Scroll_r1 = top_row;
267 Scroll_r2 = bottom_row;
268 }
269
270 /*----------------------------------------------------------------------*\
271 * Function: void SLtt_reset_scroll_region (void);
272 *
273 * reset the scrol region to be the entire screen,
274 * ie, SLtt_set_scroll_region (0, SLtt_Screen_Rows);
275 \*----------------------------------------------------------------------*/
276 void SLtt_reset_scroll_region (void)
277 {
278 Scroll_r1 = 0;
279 Scroll_r2 = SLtt_Screen_Rows;
280 }
281
282 /*----------------------------------------------------------------------*\
283 * Function: void SLtt_goto_rc (int row, int col);
284 *
285 * move the terminal cursor to x,y position COL, ROW and record the
286 * position in Cursor_Row, Cursor_Col
287 \*----------------------------------------------------------------------*/
288 void SLtt_goto_rc (int row, int col)
289 {
290 #ifdef WIN32
291 COORD newPosition;
292 newPosition.X = col;
293 newPosition.Y = row;
294 #endif
295
296 #if !defined (USE_ASM)
297 if (row > SLtt_Screen_Rows) row = SLtt_Screen_Rows;
298 if (col > SLtt_Screen_Cols) col = SLtt_Screen_Cols;
299 # if defined (EMX_VIDEO)
300 v_gotoxy (col, Scroll_r1 + row);
301 # else /* EMX_VIDEO_ */
302 # if defined (__os2__)
303 VioSetCurPos (Scroll_r1 + row, col, 0);
304 # elif defined(WIN32)
305 (void) SetConsoleCursorPosition(hStdout, newPosition);
306 # else /* __os2__ */
307 # if defined (__GO32__) || defined (__WATCOMC__)
308 ScreenSetCursor(Scroll_r1 + row, col);
309 # endif /* __GO32__ or __WATCOMC__ */
310 # endif /* __os2__ */
311 # endif /* EMX_VIDEO_ */
312 Cursor_Row = row;
313 Cursor_Col = col;
314 #else /* USE_ASM */
315 /* if (r > SLtt_Screen_Rows - 1) r = SLtt_Screen_Rows - 1; */
316 asm mov ax, row
317 asm mov bx, SLtt_Screen_Rows
318 asm dec bx
319 asm cmp ax, bx
320 asm jle L1
321 asm mov ax, bx
322 L1:
323 /* if (c > SLtt_Screen_Cols - 1) c = SLtt_Screen_Cols - 1; */
324 asm mov cx, SLtt_Screen_Cols
325 asm dec cx
326 asm mov bx, col
327 asm cmp bx, cx
328 asm jle L2
329 asm mov bx, cx
330 L2:
331 asm mov Cursor_Row, ax
332 asm mov Cursor_Col, bx
333 asm add ax, Scroll_r1
334 asm xor dx, dx
335 asm mov dh, al
336 asm mov dl, bl
337 asm xor bx, bx
338 asm mov ax, 0x200
339 asm int 0x10
340 #endif /* USE_ASM */
341 }
342
343 /*----------------------------------------------------------------------*\
344 * Function: static void slvid_getxy (void);
345 *
346 * retrieve the cursor position into Cursor_Row, Cursor_Col
347 \*----------------------------------------------------------------------*/
348 static void slvid_getxy (void)
349 {
350 #if !defined (USE_ASM)
351 # if defined (EMX_VIDEO)
352 v_getxy (&Cursor_Col, &Cursor_Row);
353 # else /* EMX_VIDEO */
354 # if defined (__os2__)
355 VioGetCurPos ((USHORT*) &Cursor_Row, (USHORT*) &Cursor_Col, 0);
356 # elif defined(WIN32)
357 CONSOLE_SCREEN_BUFFER_INFO screenInfo;
358 if (GetConsoleScreenBufferInfo(hStdout, &screenInfo) == TRUE)
359 {
360 Cursor_Row = screenInfo.dwCursorPosition.Y;
361 Cursor_Col = screenInfo.dwCursorPosition.X;
362 }
363 # else /* __os2__ */
364 # if defined (__GO32__) || defined (__WATCOMC__)
365 ScreenGetCursor (&Cursor_Row, &Cursor_Col);
366 # endif /* __GO32__ or __WATCOMC__ */
367 # endif /* __os2__ */
368 # endif /* EMX_VIDEO */
369 #else /* USE_ASM */
370 asm mov ah, 3
371 asm mov bh, 0
372 asm int 10h
373 asm xor ax, ax
374 asm mov al, dh
375 asm mov Cursor_Row, ax
376 asm xor ax, ax
377 asm mov al, dl
378 asm mov Cursor_Col, ax
379 #endif /* USE_ASM */
380 }
381
382 /*----------------------------------------------------------------------*\
383 * static void slvid_deleol (int x);
384 *
385 * write space characters from column X of row Cursor_Row through to
386 * SLtt_Screen_Cols using the current Attribute_Byte
387 \*----------------------------------------------------------------------*/
388 #if defined (GO32_VIDEO)
389 static void slvid_deleol (int x)
390 {
391 while (x < SLtt_Screen_Cols)
392 ScreenPutChar (32, Attribute_Byte, x++, Cursor_Row);
393 }
394 #endif
395 #if defined (EMX_VIDEO)
396 static void slvid_deleol (int x)
397 {
398 unsigned char *p, *pmax;
399 int w = mkSpaceChar ();
400 int count = SLtt_Screen_Cols - x;
401
402 p = Line_Buffer;
403 pmax = p + 2 * count;
404
405 while (p < pmax)
406 {
407 *p++ = (unsigned char) w;
408 *p++ = (unsigned char) (w >> 8);
409 }
410
411 v_putline (Line_Buffer, x, Cursor_Row, count);
412 }
413 #endif /* EMX_VIDEO */
414
415 /*----------------------------------------------------------------------*\
416 * Function: void SLtt_begin_insert (void);
417 *
418 * insert a single space, moving everything right 1 character to make room
419 \*----------------------------------------------------------------------*/
420 void SLtt_begin_insert (void)
421 {
422 #if !defined (GO32_VIDEO)
423 # if defined (HAS_LINEAR_SCREEN) || defined (USE_ASM)
424 unsigned short *p;
425 # if defined (HAS_LINEAR_SCREEN)
426 unsigned short *pmin;
427 # endif
428 # endif
429 int n;
430 slvid_getxy ();
431 n = SLtt_Screen_Cols - Cursor_Col;
432 /* Msdos_Insert_Mode = 1; */
433
434 # ifndef WIN32
435 # if defined (EMX_VIDEO)
436 v_getline (Line_Buffer, Cursor_Col, Cursor_Row, n);
437 v_putline (Line_Buffer, Cursor_Col+1, Cursor_Row, n - 1);
438 # else /* EMX_VIDEO */
439 # if defined (__os2__)
440 n = 2 * (n - 1);
441 VioReadCellStr ((PCH)Line_Buffer, (USHORT*) &n, Cursor_Row, Cursor_Col, 0);
442 VioWrtCellStr ((PCH)Line_Buffer, n, Cursor_Row, Cursor_Col + 1, 0);
443 # else /* __os2__ */
444 p = mkScreenPointer (Cursor_Row, SLtt_Screen_Cols - 1);
445
446 # if defined (HAS_LINEAR_SCREEN)
447 /* pmin = p - (n-1); */
448 pmin = mkScreenPointer (Cursor_Row, Cursor_Col);
449 while (p-- > pmin) *(p + 1) = *p;
450 # else
451 SNOW_CHECK;
452 asm mov ax, ds
453 asm mov bx, di
454 asm mov dx, si
455
456 asm mov cx, n
457 asm les di, p
458 asm lds si, p
459 asm sub si, 2
460 asm std
461 asm rep movsw
462
463 asm mov ds, ax
464 asm mov di, bx
465 asm mov si, dx
466 # endif /* HAS_LINEAR_SCREEN */
467 # endif /* __os2__ */
468 # endif /* EMX_VIDEO */
469
470 # endif /* WIN32 */
471
472 #endif /* not GO32_VIDEO */
473 }
474
475 /*----------------------------------------------------------------------*\
476 * Function: void SLtt_end_insert (void);
477 *
478 * any cleanup after insert a blank column
479 \*----------------------------------------------------------------------*/
480 void SLtt_end_insert (void)
481 {
482 }
483
484 /*----------------------------------------------------------------------*\
485 * Function: void SLtt_delete_char (void);
486 *
487 * delete a single character, moving everything left 1 column to take
488 * up the room
489 \*----------------------------------------------------------------------*/
490 void SLtt_delete_char (void)
491 {
492 #if !defined (GO32_VIDEO)
493 # if defined (HAS_LINEAR_SCREEN) || defined (USE_ASM)
494 unsigned short *p;
495 # if defined (HAS_LINEAR_SCREEN)
496 register unsigned short *p1;
497 # endif
498 # endif
499 int n;
500
501 slvid_getxy ();
502 n = SLtt_Screen_Cols - Cursor_Col - 1;
503
504 # ifndef WIN32
505
506 # if defined (EMX_VIDEO)
507 v_getline (Line_Buffer, Cursor_Col+1, Cursor_Row, n);
508 v_putline (Line_Buffer, Cursor_Col, Cursor_Row, n);
509 # else /* EMX_VIDEO */
510 # if defined (__os2__)
511 n *= 2;
512 VioReadCellStr ((PCH)Line_Buffer, (USHORT*)&n, Cursor_Row, Cursor_Col + 1, 0);
513 VioWrtCellStr ((PCH)Line_Buffer, n, Cursor_Row, Cursor_Col, 0);
514 return;
515 # else /* __os2__ */
516 p = mkScreenPointer (Cursor_Row, Cursor_Col);
517
518 # if defined (HAS_LINEAR_SCREEN)
519 while (n--)
520 {
521 p1 = p + 1;
522 *p = *p1;
523 p++;
524 }
525 # else /* HAS_LINEAR_SCREEN */
526 SNOW_CHECK;
527 asm mov ax, ds
528 asm mov bx, si
529 asm mov dx, di
530
531 asm mov cx, n
532 asm les di, p
533 asm lds si, p
534 asm add si, 2
535 asm cld
536 asm rep movsw
537
538 asm mov ds, ax
539 asm mov si, bx
540 asm mov di, dx
541 # endif /* HAS_LINEAR_SCREEN */
542 # endif /* __os2__ */
543 # endif /* EMX_VIDEO */
544
545 # endif /* WIN32 */
546
547 #endif /* not GO32_VIDEO */
548 }
549
550 /*----------------------------------------------------------------------*\
551 * Function: void SLtt_erase_line (void);
552 *
553 * This function is *only* called on exit.
554 * It sets attribute byte to Black & White
555 \*----------------------------------------------------------------------*/
556 void SLtt_erase_line (void)
557 {
558
559 #ifndef WIN32
560
561 # if defined (GO32_VIDEO) || defined (EMX_VIDEO)
562 Attribute_Byte = 0x07;
563 slvid_deleol (0);
564 # else /* GO32_VIDEO or EMX_VIDEO */
565 # if defined (__os2__)
566 USHORT w;
567 Attribute_Byte = 0x07;
568 w = mkSpaceChar ();
569 VioWrtNCell ((BYTE*)&w, SLtt_Screen_Cols, Cursor_Row, 0, 0);
570 # else /* __os2__ */
571 unsigned short w;
572 unsigned short *p = mkScreenPointer (Cursor_Row, 0);
573 # if defined (HAS_LINEAR_SCREEN)
574 register unsigned short *pmax = p + SLtt_Screen_Cols;
575
576 Attribute_Byte = 0x07;
577 w = mkSpaceChar ();
578 while (p < pmax) *p++ = w;
579 # else /* HAS_LINEAR_SCREEN */
580 Attribute_Byte = 0x07;
581 w = mkSpaceChar ();
582 SNOW_CHECK;
583 asm mov dx, di
584 asm mov ax, w
585 asm mov cx, SLtt_Screen_Cols
586 asm les di, p
587 asm cld
588 asm rep stosw
589 asm mov di, dx
590 # endif /* HAS_LINEAR_SCREEN */
591 # endif /* __os2__ */
592 # endif /* GO32_VIDEO or EMX_VIDEO */
593 Current_Color = JNO_COLOR; /* since we messed with attribute byte */
594
595 #endif /* WIN32 */
596
597 }
598
599 /*----------------------------------------------------------------------*\
600 * Function: void SLtt_delete_nlines (int nlines);
601 *
602 * delete NLINES by scrolling up the region <Scroll_r1, Scroll_r2>
603 \*----------------------------------------------------------------------*/
604 void SLtt_delete_nlines (int nlines)
605 {
606 SLtt_normal_video ();
607
608 #ifndef WIN32
609
610 # if defined (EMX_VIDEO)
611 v_attrib (Attribute_Byte);
612 v_scroll (0, Scroll_r1, SLtt_Screen_Cols-1, Scroll_r2, nlines, V_SCROLL_UP);
613 # else /* EMX_VIDEO */
614 # if defined (__os2__)
615 {
616 Line_Buffer[0] = ' '; Line_Buffer[1] = Attribute_Byte;
617 VioScrollUp (Scroll_r1, 0, Scroll_r2, SLtt_Screen_Cols-1,
618 nlines, (PCH) Line_Buffer, 0);
619 }
620 # else /* __os2__ */
621 # if defined (USE_ASM)
622 /* This has the effect of pulling all lines below it up */
623 asm mov ax, nlines
624 asm mov ah, 6 /* int 6h */
625 asm xor cx, cx
626 asm mov ch, byte ptr Scroll_r1
627 asm mov dx, SLtt_Screen_Cols
628 asm dec dx
629 asm mov dh, byte ptr Scroll_r2
630 asm mov bh, byte ptr Attribute_Byte
631 asm int 10h
632 # else /* USE_ASM */
633 {
634 union REGS r;
635 # if defined (__WATCOMC__)
636 r.x.eax = nlines;
637 r.x.ecx = 0;
638 # else
639 r.x.ax = nlines;
640 r.x.cx = 0;
641 # endif
642 r.h.ah = 6;
643 r.h.ch = Scroll_r1;
644 r.h.dl = SLtt_Screen_Cols - 1;
645 r.h.dh = Scroll_r2;
646 r.h.bh = Attribute_Byte;
647 int86 (0x10, &r, &r);
648 }
649 # endif /* USE_ASM */
650 # endif /* __os2__ */
651 # endif /* EMX_VIDEO */
652
653 #endif /* WIN32 */
654
655 }
656
657 /*----------------------------------------------------------------------*\
658 * Function: void SLtt_reverse_index (int nlines);
659 *
660 * scroll down the region <Scroll_r1, Scroll_r2> by NLINES
661 \*----------------------------------------------------------------------*/
662 void SLtt_reverse_index (int nlines)
663 {
664 SLtt_normal_video ();
665
666 #ifndef WIN32
667
668 # if defined (EMX_VIDEO)
669 v_attrib (Attribute_Byte);
670 v_scroll (0, Scroll_r1, SLtt_Screen_Cols-1, Scroll_r2, nlines,
671 V_SCROLL_DOWN);
672 # else /* EMX_VIDEO */
673 # if defined (__os2__)
674 {
675 Line_Buffer[0] = ' '; Line_Buffer[1] = Attribute_Byte;
676 VioScrollDn (Scroll_r1, 0, Scroll_r2, SLtt_Screen_Cols-1,
677 nlines, (PCH) Line_Buffer, 0);
678 }
679 # else /* __os2__ */
680 # if defined (USE_ASM)
681 asm xor cx, cx
682 asm mov ch, byte ptr Scroll_r1
683 asm mov dx, SLtt_Screen_Cols
684 asm dec dx
685 asm mov dh, byte ptr Scroll_r2
686 asm mov bh, byte ptr Attribute_Byte
687 asm mov ah, 7
688 asm mov al, byte ptr nlines
689 asm int 10h
690 # else /* USE_ASM */
691 {
692 union REGS r;
693 r.h.al = nlines;
694 # if defined (__WATCOMC__)
695 r.x.ecx = 0;
696 # else
697 r.x.cx = 0;
698 # endif
699 r.h.ah = 7;
700 r.h.ch = Scroll_r1;
701 r.h.dl = SLtt_Screen_Cols - 1;
702 r.h.dh = Scroll_r2;
703 r.h.bh = Attribute_Byte;
704 int86 (0x10, &r, &r);
705 }
706 # endif /* USE_ASM */
707 # endif /* __os2__ */
708 # endif /* EMX_VIDEO */
709
710 #endif /* WIN32 */
711
712 }
713
714 /*----------------------------------------------------------------------*\
715 * Function: static void slvid_invert_region (int top_row, int bot_row);
716 *
717 * invert the display in the region, top_row <= row < bot_row
718 \*----------------------------------------------------------------------*/
719 static void slvid_invert_region (int top_row, int bot_row)
720 {
721
722 #ifndef WIN32
723
724 # if defined (EMX_VIDEO)
725 int row, col;
726
727 for (row = top_row; row < bot_row; row++)
728 {
729 v_getline (Line_Buffer, 0, row, SLtt_Screen_Cols);
730 for (col = 1; col < SLtt_Screen_Cols * 2; col += 2)
731 Line_Buffer [col] ^= 0xff;
732 v_putline (Line_Buffer, 0, row, SLtt_Screen_Cols);
733 }
734 # else /* EMX_VIDEO */
735 # ifdef __os2__
736 int row, col;
737 USHORT length = SLtt_Screen_Cols * 2;
738
739 for (row = top_row; row < bot_row; row++)
740 {
741 VioReadCellStr ((PCH)Line_Buffer, &length, row, 0, 0);
742 for (col = 1; col < length; col += 2)
743 Line_Buffer [col] ^= 0xff;
744 VioWrtCellStr ((PCH)Line_Buffer, length, row, 0, 0);
745 }
746 # else /* __os2__ */
747 # if defined (__GO32__) || defined (__WATCOMC__)
748 unsigned char buf [2 * 180 * 80]; /* 180 cols x 80 rows */
749 unsigned char *b, *bmax;
750
751 b = buf + 1 + 2 * SLtt_Screen_Cols * top_row;
752 bmax = buf + 1 + 2 * SLtt_Screen_Cols * bot_row;
753 ScreenRetrieve (buf);
754 while (b < bmax)
755 {
756 *b ^= 0xFF;
757 b += 2;
758 }
759 ScreenUpdate (buf);
760 # else /* __GO32__ or __WATCOMC__ */
761 register unsigned short ch, sh;
762 register unsigned short *pmin = mkScreenPointer (top_row, 0);
763 register unsigned short *pmax = mkScreenPointer (bot_row, 0);
764
765 while (pmin < pmax)
766 {
767 sh = *pmin;
768 ch = sh;
769 ch = ch ^ 0xFF00;
770 *pmin = (ch & 0xFF00) | (sh & 0x00FF);
771 pmin++;
772 }
773 # endif /* __GO32__ or __WATCOMC__ */
774 # endif /* __os2__ */
775 # endif /* EMX_VIDEO */
776
777 #endif /* WIN32 */
778
779 }
780
781 /*----------------------------------------------------------------------*\
782 * Function: void SLtt_beep (void);
783 *
784 * signal error by a "bell" condition, the type of signal is governed
785 * by the value of SLtt_Ignore_Beep:
786 *
787 * 0 silent bell
788 * 1 audible bell
789 * 2 visual bell
790 * 4 special visual bell (only flash the bottom status line)
791 *
792 * these may be combined:
793 * eg, 3 = audible visual bell.
794 * but if both the visual bell and the "special" visual bell are specified,
795 * only the special bell is used.
796 \*----------------------------------------------------------------------*/
797 void SLtt_beep (void)
798 {
799 int audible; /* audible bell */
800 int special = 0; /* first row to invert */
801 int visual = 0; /* final row to invert */
802 if (!SLtt_Ignore_Beep) return;
803
804 audible = (SLtt_Ignore_Beep & 1);
805 if ( (SLtt_Ignore_Beep & 4) )
806 {
807 special = SLtt_Screen_Rows - 1;
808 visual = special--; /* only invert bottom status line */
809 }
810 else if ( (SLtt_Ignore_Beep & 2) )
811 {
812 visual = SLtt_Screen_Rows;
813 }
814
815 if (visual) slvid_invert_region (special, visual);
816 #if defined (EMX_VIDEO)
817 if (audible) /*sound (1500)*/; _sleep2 (100); if (audible) /* nosound () */;
818 #else
819 # ifdef __os2__
820 if (audible) DosBeep (1500, 100); else DosSleep (100);
821
822 # elif defined(WIN32)
823
824 # else
825 if (audible) sound (1500); delay (100); if (audible) nosound ();
826 # endif
827 #endif
828 if (visual) slvid_invert_region (special, visual);
829 }
830
831 /*----------------------------------------------------------------------*\
832 * Function: void SLtt_del_eol (void);
833 *
834 * delete from the current cursor position to the end of the row
835 \*----------------------------------------------------------------------*/
836 void SLtt_del_eol (void)
837 {
838
839 #ifndef WIN32
840
841 # if defined (GO32_VIDEO) || defined (EMX_VIDEO)
842 if (Current_Color != JNO_COLOR) SLtt_normal_video ();
843 slvid_deleol (Cursor_Col);
844 # else /* GO32_VIDEO or EMX_VIDEO */
845 # ifdef __os2__
846 USHORT w;
847 if (Current_Color != JNO_COLOR) SLtt_normal_video ();
848 w = mkSpaceChar ();
849 VioWrtNCell ((BYTE*)&w, (SLtt_Screen_Cols - Cursor_Col),
850 Cursor_Row, Cursor_Col, 0);
851 # else /* __os2__ */
852 unsigned short *p = mkScreenPointer (Cursor_Row, Cursor_Col);
853 int n = SLtt_Screen_Cols - Cursor_Col;
854 unsigned short w;
855 # if defined (HAS_LINEAR_SCREEN)
856 unsigned short *pmax = p + n;
857
858 if (Current_Color != JNO_COLOR) SLtt_normal_video ();
859 w = mkSpaceChar ();
860 while (p < pmax) *p++ = w;
861 # else /* HAS_LINEAR_SCREEN */
862 if (Current_Color != JNO_COLOR) SLtt_normal_video ();
863 w = mkSpaceChar ();
864 SNOW_CHECK;
865 asm mov dx, di
866 asm les di, p
867 asm mov ax, w
868 asm mov cx, n
869 asm cld
870 asm rep stosw
871
872 asm mov di, dx
873 # endif /* HAS_LINEAR_SCREEN */
874 # endif /* __os2__ */
875 # endif /* GO32_VIDEO or EMX_VIDEO */
876
877 #endif /* WIN32 */
878
879 }
880
881 /*----------------------------------------------------------------------*\
882 * Function: void SLtt_reverse_video (int color);
883 *
884 * set Attribute_Byte corresponding to COLOR.
885 * Use Current_Color to remember the color which was set.
886 * convert from the COLOR number to the attribute value.
887 \*----------------------------------------------------------------------*/
888 void SLtt_reverse_video (int color)
889 {
890 Attribute_Byte = Color_Map [color];
891 Current_Color = color;
892 }
893
894 /*----------------------------------------------------------------------*\
895 * Function: void SLtt_normal_video (void);
896 *
897 * reset the attributes for normal video
898 \*----------------------------------------------------------------------*/
899 void SLtt_normal_video (void)
900 {
901 SLtt_reverse_video (JNORMAL_COLOR);
902 }
903
904 #if defined (USE_ASM)
905 /*----------------------------------------------------------------------*\
906 * Function: static unsigned short *video_write (register unsigned char *pp,
907 * register unsigned char *p,
908 * register unsigned short *pos)
909 *
910 * write out (P - PP) characters from the array pointed to by PP
911 * at position (POS, Cursor_Row) in the current Attribute_Byte
912 *
913 * increment POS to reflect the number of characters sent and
914 * return the it as a pointer
915 \*----------------------------------------------------------------------*/
916 static unsigned short *video_write (register unsigned char *pp,
917 register unsigned char *p,
918 register unsigned short *pos)
919 {
920 int n = (int) (p - pp); /* num of characters of PP to write */
921
922 asm push si
923 asm push ds
924 asm push di
925
926 /* set up register for BOTH fast and slow */
927 asm mov bx, SLtt_Msdos_Cheap_Video
928
929 /* These are the registers needed for both fast AND slow */
930 asm mov ah, byte ptr Attribute_Byte
931 asm mov cx, n
932 asm lds si, dword ptr pp
933 asm les di, dword ptr pos
934 asm cld
935
936 asm cmp bx, 0 /* cheap video test */
937 asm je L_fast
938 asm mov bx, ax
939 asm mov dx, CGA_STATUS
940 asm jg L_slow_blank
941
942 /* slow video */
943 asm cli
944
945 /* wait for retrace */
946 L_slow:
947 asm in al, dx
948 asm test al, 1
949 asm jnz L_slow
950
951 L_slow1:
952 asm in al, dx
953 asm test al, 1
954 asm jz L_slow1
955
956 /* move a character out */
957 asm mov ah, bh
958 asm lodsb
959 asm stosw
960 asm loop L_slow
961
962 asm sti
963 asm jmp done
964
965 /* -------------- slow video, vertical retace and pump --------------*/
966 L_slow_blank:
967 L_slow_blank_loop:
968 asm in al, dx
969 asm test al, 8
970 asm jnz L_slow_blank_loop
971
972 L_slow_blank1:
973 asm in al, dx
974 asm test al, 8
975 asm jz L_slow_blank1
976 /* write line */
977 asm mov ah, bh
978 L_slow_blank2:
979 asm lodsb
980 asm stosw
981 asm loop L_slow_blank2
982
983 asm jmp done
984 /*-------------- Fast video --------------*/
985
986 L_fast:
987 asm lodsb
988 asm stosw
989 asm loop L_fast
990 done:
991 asm pop di
992 asm pop ds
993 asm pop si
994 return (pos + n);
995 }
996 #endif /* USE_ASM */
997
998 /*----------------------------------------------------------------------*\
999 * Function: static void write_attributes (unsigned short *src,
1000 * int count);
1001 *
1002 * Copy COUNT character/color pairs from the array pointed to by
1003 * SRC to the screen at position (0,Cursor_Row).
1004 * NB: SRC contains character/color pairs -- the color must be converted to
1005 * an ansi attribute.
1006 *
1007 * Write out
1008 * 1) a combination of string/attributes
1009 * 2) each string of continuous colour
1010 *
1011 * approach 2) is used for assembler output, while 1) is used when a higher
1012 * level API is available or direct to memory writing is possible: emx video
1013 * routines, os/2, go32, watcom.
1014 \*----------------------------------------------------------------------*/
1015 static void write_attributes (unsigned short *src, int count)
1016 {
1017 register unsigned char *p = Line_Buffer;
1018 register unsigned short pair;
1019 #ifdef WIN32
1020 register unsigned char * org_src = (unsigned char*)src;
1021 COORD coord;
1022 DWORD bytes;
1023 #endif
1024 #if !defined (USE_ASM)
1025 # if defined (HAS_LINEAR_SCREEN)
1026 register unsigned short *pos = mkScreenPointer (Cursor_Row, 0);
1027 # endif
1028 int n = count;
1029
1030 /* write into a character/attribute pair */
1031 while (n-- > 0)
1032 {
1033 pair = *(src++); /* character/color pair */
1034 SLtt_reverse_video (pair >> 8); /* color change */
1035 # if defined (HAS_LINEAR_SCREEN)
1036 *(pos++) = ((unsigned short) Attribute_Byte << 8) | pair & 0xff;
1037 # else
1038 # if defined(EMX_VIDEO) || !defined(WIN32)
1039 *(p++) = pair & 0xff; /* character byte */
1040 *(p++) = Attribute_Byte; /* attribute byte */
1041 # else
1042 /* WIN32 for now... */
1043 *(p++) = pair & 0xff;
1044 # endif
1045 # endif
1046 }
1047
1048 # if !defined (HAS_LINEAR_SCREEN)
1049 # if defined (EMX_VIDEO)
1050 v_putline (Line_Buffer, Cursor_Col, Cursor_Row, count);
1051 # else /* EMX_VIDEO */
1052 # if defined (__os2__)
1053 VioWrtCellStr ((PCH)Line_Buffer, (USHORT)(2 * count),
1054 (USHORT)Cursor_Row, (USHORT)Cursor_Col, 0);
1055 # elif defined(WIN32)
1056 /* do color attributes later */
1057 p = Line_Buffer;
1058 coord.X = Cursor_Col;
1059 coord.Y = Cursor_Row;
1060 WriteConsoleOutputCharacter(hStdout, (char*)p, count, coord, &bytes);
1061
1062 /* write color attributes */
1063 p = Line_Buffer;
1064 n = count;
1065 src = (unsigned short*)org_src; /* restart the src pointer */
1066
1067 /* write into attributes only */
1068 while (n-- > 0)
1069 {
1070 pair = *(src++); /* character/color pair */
1071 SLtt_reverse_video (pair >> 8); /* color change */
1072 *(p++) = Attribute_Byte; /* attribute byte */
1073 *(p++) = 0; /* what's this for? */
1074 }
1075
1076 WriteConsoleOutputAttribute(hStdout, (WORD*)Line_Buffer, count, coord, &bytes);
1077 # else /* __os2__ */
1078 /* ScreenUpdateLine (void *virtual_screen_line, int row); */
1079 p = Line_Buffer;
1080 n = Cursor_Col;
1081 while (count-- > 0)
1082 {
1083 ScreenPutChar ((int)p[0], (int)p[1], n++, Cursor_Row);
1084 p += 2;
1085 }
1086 # endif /* EMX_VIDEO */
1087 # endif /* __os2__ */
1088 # endif /* HAS_LINEAR_SCREEN */
1089 #else /* not USE_ASM */
1090 unsigned char ch, color;
1091 register unsigned short *pos = mkScreenPointer (Cursor_Row, 0);
1092
1093 while (count--)
1094 {
1095 pair = *(src++); /* character/color pair */
1096 ch = pair & 0xff; /* character value */
1097 color = pair >> 8; /* color value */
1098 if (color != Current_Color) /* need a new color */
1099 {
1100 if (p != Line_Buffer)
1101 {
1102 pos = video_write (Line_Buffer, p, pos);
1103 p = Line_Buffer;
1104 }
1105 SLtt_reverse_video (color); /* change color */
1106 }
1107 *(p++) = ch;
1108 }
1109 pos = video_write (Line_Buffer, p, pos);
1110 #endif /* not USE_ASM */
1111 }
1112
1113 /*----------------------------------------------------------------------*\
1114 * Function: void SLtt_smart_puts (unsigned short *new_string,
1115 * unsigned short *old_string,
1116 * int len, int row);
1117 *
1118 * puts NEW_STRING, which has length LEN, at row ROW. NEW_STRING contains
1119 * characters/colors packed in the form value = ((color << 8) | (ch));
1120 *
1121 * the puts tries to avoid overwriting the same characters/colors
1122 *
1123 * OLD_STRING is not used, maintained for compatibility with other systems
1124 \*----------------------------------------------------------------------*/
1125 void SLtt_smart_puts (unsigned short *new_string,
1126 unsigned short *old_string,
1127 int len, int row)
1128 {
1129 (void) old_string;
1130 Cursor_Row = row;
1131 Cursor_Col = 0;
1132 write_attributes (new_string, len);
1133 }
1134
1135 /*----------------------------------------------------------------------*\
1136 * Function: void SLtt_reset_video (void);
1137 \*----------------------------------------------------------------------*/
1138 void SLtt_reset_video (void)
1139 {
1140 SLtt_goto_rc (SLtt_Screen_Rows - 1, 0);
1141 #ifdef HAS_SAVE_SCREEN
1142 restore_screen ();
1143 #endif
1144 Attribute_Byte = 0x07;
1145 Current_Color = JNO_COLOR;
1146 SLtt_del_eol ();
1147 }
1148
1149 #if 0
1150 void wide_width (void)
1151 {
1152 }
1153
1154 void narrow_width (void)
1155 {
1156 }
1157 #endif
1158
1159 /*----------------------------------------------------------------------*\
1160 * Function: void SLtt_cls (void);
1161 \*----------------------------------------------------------------------*/
1162 void SLtt_cls (void)
1163 {
1164 #ifdef WIN32
1165 DWORD bytes;
1166 COORD coord;
1167 char ch;
1168 #endif
1169 SLtt_normal_video ();
1170 #if defined (__GO32__) || defined (__WATCOMC__) || defined (EMX_VIDEO)
1171 SLtt_reset_scroll_region ();
1172 SLtt_goto_rc (0, 0);
1173 SLtt_delete_nlines (SLtt_Screen_Rows);
1174 #else /* __GO32__ or __WATCOMC__ or EMX_VIDEO */
1175 # ifdef __os2__
1176 {
1177 Line_Buffer [0] = ' '; Line_Buffer [1] = Attribute_Byte;
1178 VioScrollUp (0, 0, -1, -1, -1, (PCH)Line_Buffer, 0);
1179 }
1180 # elif defined(WIN32)
1181 /* clear the WIN32 screen in one shot */
1182 coord.X = 0;
1183 coord.Y = 0;
1184
1185 ch = ' ';
1186
1187 (void) FillConsoleOutputCharacter(hStdout,
1188 ch,
1189 csbiInfo.dwMaximumWindowSize.Y * csbiInfo.dwMaximumWindowSize.X,
1190 coord,
1191 &bytes);
1192
1193 /* now set screen to the current attribute */
1194 ch = Attribute_Byte;
1195 (void) FillConsoleOutputAttribute(hStdout,
1196 ch,
1197 csbiInfo.dwMaximumWindowSize.Y * csbiInfo.dwMaximumWindowSize.X,
1198 coord,
1199 &bytes);
1200 # else /* __os2__ */
1201 asm mov dx, SLtt_Screen_Cols
1202 asm dec dx
1203 asm mov ax, SLtt_Screen_Rows
1204 asm dec ax
1205 asm mov dh, al
1206 asm xor cx, cx
1207 asm xor ax, ax
1208 asm mov ah, 7
1209 asm mov bh, byte ptr Attribute_Byte
1210 asm int 10h
1211 # endif /* __os2__ */
1212 #endif /* __GO32__ or __WATCOMC__ or EMX_VIDEO */
1213 }
1214
1215 /*----------------------------------------------------------------------*\
1216 * Function: void SLtt_putchar (char ch);
1217 *
1218 * put CH on the screen in the current position.
1219 * this function is called assuming that cursor is in correct position
1220 \*----------------------------------------------------------------------*/
1221
1222 void SLtt_putchar (char ch)
1223 {
1224 #if !defined (GO32_VIDEO) && !defined (EMX_VIDEO)
1225 unsigned short p, *pp;
1226 # if defined(WIN32)
1227 DWORD bytes;
1228 # endif
1229 #endif
1230
1231 if (Current_Color) SLtt_normal_video ();
1232 slvid_getxy (); /* get current position */
1233 switch (ch)
1234 {
1235 case 7: /* ^G - break */
1236 SLtt_beep (); break;
1237 case 8: /* ^H - backspace */
1238 SLtt_goto_rc (Cursor_Row, Cursor_Col - 1); break;
1239 case 13: /* ^M - carriage return */
1240 SLtt_goto_rc (Cursor_Row, 0); break;
1241 default: /* write character to screen */
1242 #if defined (EMX_VIDEO)
1243 v_putn (ch, 1);
1244 #else /* EMX_VIDEO */
1245 # ifdef __os2__
1246 VioWrtCharStrAtt (&ch, 1, Cursor_Row, Cursor_Col,
1247 (BYTE*)&Attribute_Byte, 0);
1248 # elif defined(WIN32)
1249 WriteConsole(hStdout, &ch, 1, &bytes, NULL);
1250 # else /* __os2__ */
1251 # ifdef GO32_VIDEO
1252 ScreenPutChar ((int) ch, Attribute_Byte, Cursor_Col, Cursor_Row);
1253 # else /* GO32_VIDEO */
1254 pp = mkScreenPointer (Cursor_Row, Cursor_Col);
1255 p = (Attribute_Byte << 8) | (unsigned char) ch;
1256
1257 # ifdef USE_ASM
1258 SNOW_CHECK;
1259 # endif
1260 *pp = p;
1261 # endif /* GO32_VIDEO */
1262 # endif /* __os2__ */
1263 #endif /* EMX_VIDEO */
1264 SLtt_goto_rc (Cursor_Row, Cursor_Col + 1);
1265 }
1266 }
1267
1268 /*----------------------------------------------------------------------*\
1269 * Function: void SLtt_set_color (int obj, char *what, char *fg, char *bg);
1270 *
1271 * set foreground and background colors of OBJ to the attributes which
1272 * correspond to the names FG and BG, respectively.
1273 *
1274 * WHAT is the name corresponding to the object OBJ, but is not used in
1275 * this routine.
1276 \*----------------------------------------------------------------------*/
1277 void SLtt_set_color (int obj, char *what, char *fg, char *bg)
1278 {
1279 int i, b = -1, f = -1;
1280 #ifdef WIN32
1281 int newcolor;
1282 #endif
1283
1284 (void) what;
1285
1286 if ( !IsColor || (obj < 0) || (obj >= JMAX_COLORS))
1287 return;
1288
1289 for (i = 0; i < JMAX_COLOR_NAMES; i++ )
1290 {
1291 if (!strcmp (fg, Color_Names [i]))
1292 {
1293 f = i;
1294 break;
1295 }
1296 }
1297
1298 for (i = 0; i < JMAX_COLOR_NAMES; i++)
1299 {
1300 if (!strcmp (bg, Color_Names [i]))
1301 {
1302 if (Blink_Killed) b = i; else b = i & 0x7;
1303 break;
1304 }
1305 }
1306 if ((f == -1) || (b == -1) || (f == b)) return;
1307 #if 1
1308 Color_Map [obj] = (b << 4) | f;
1309 #else
1310
1311 /*
1312 0 1 2 3
1313 "black", "blue", "green", "cyan",
1314 4 5 6 7
1315 "red", "magenta", "brown", "lightgray",
1316 8 9 10 11
1317 "gray", "brightblue", "brightgreen", "brightcyan",
1318 12 13 14 15
1319 "brightred", "brightmagenta", "yellow", "white"
1320 */
1321
1322 /* these aren't all right yet */
1323 switch (f)
1324 {
1325 case 0: newcolor = 0; break;
1326 case 1: newcolor = FOREGROUND_BLUE; break;
1327 case 2: newcolor = FOREGROUND_GREEN; break;
1328 case 3: newcolor = FOREGROUND_GREEN | FOREGROUND_BLUE; break;
1329
1330 case 4: newcolor = FOREGROUND_RED; break;
1331 case 5: newcolor = FOREGROUND_RED | FOREGROUND_BLUE; break;
1332 case 6: newcolor = FOREGROUND_GREEN | FOREGROUND_RED; break;
1333 case 7: newcolor = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
1334
1335 case 8: newcolor = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN; break;
1336 case 9: newcolor = FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
1337 case 10: newcolor = FOREGROUND_GREEN | FOREGROUND_INTENSITY; break;
1338 case 11: newcolor = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
1339
1340 case 12: newcolor = FOREGROUND_RED | FOREGROUND_INTENSITY; break;
1341 case 13: newcolor = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
1342 case 14: newcolor = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
1343 case 15: newcolor = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
1344 }
1345 // switch
1346
1347 /*
1348 0 1 2 3
1349 "black", "blue", "green", "cyan",
1350 4 5 6 7
1351 "red", "magenta", "brown", "lightgray",
1352 8 9 10 11
1353 "gray", "brightblue", "brightgreen", "brightcyan",
1354 12 13 14 15
1355 "brightred", "brightmagenta", "yellow", "white"
1356 */
1357
1358 switch (b)
1359 {
1360 case 0: newcolor |= 0; break;
1361 case 1: newcolor |= BACKGROUND_BLUE; break;
1362 case 2: newcolor |= BACKGROUND_GREEN; break;
1363 case 3: newcolor |= BACKGROUND_GREEN | BACKGROUND_BLUE; break;
1364
1365 case 4: newcolor |= BACKGROUND_RED; break;
1366 case 5: newcolor |= BACKGROUND_RED | BACKGROUND_BLUE; break;
1367 case 6: newcolor |= BACKGROUND_GREEN | BACKGROUND_RED; break;
1368 case 7: newcolor |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
1369
1370 case 8: newcolor |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
1371 case 9: newcolor |= BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
1372 case 10: newcolor |= BACKGROUND_GREEN | BACKGROUND_INTENSITY; break;
1373 case 11: newcolor |= BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
1374
1375 case 12: newcolor |= BACKGROUND_RED | BACKGROUND_INTENSITY; break;
1376 case 13: newcolor |= BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
1377 case 14: newcolor |= BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
1378 case 15: newcolor |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; break;
1379 }
1380 // switch
1381
1382 Color_Map [obj] = newcolor;
1383
1384 #endif
1385 /* if we're setting the normal color, and the attribute byte hasn't
1386 been set yet, set it to the new color */
1387 if ((obj == 0) && (Attribute_Byte == 0))
1388 SLtt_reverse_video (0);
1389 }
1390
1391 /*----------------------------------------------------------------------*\
1392 * Function: void SLtt_get_terminfo (void)
1393 \*----------------------------------------------------------------------*/
1394 void SLtt_get_terminfo (void)
1395 {
1396 #ifdef WIN32
1397 SLtt_Screen_Rows = csbiInfo.dwMaximumWindowSize.Y;
1398 SLtt_Screen_Cols = csbiInfo.dwMaximumWindowSize.X;
1399 #endif
1400 #ifdef GO32_VIDEO
1401 SLtt_Screen_Rows = ScreenRows ();
1402 SLtt_Screen_Cols = ScreenCols ();
1403 #endif
1404 }
1405
1406 /*----------------------------------------------------------------------*\
1407 * Function: void SLtt_init_video (void);
1408 \*----------------------------------------------------------------------*/
1409 void SLtt_init_video (void)
1410 {
1411 #if defined (EMX_VIDEO)
1412 int OldCol, OldRow;
1413 #endif
1414
1415 #ifdef HAS_SAVE_SCREEN
1416 save_screen ();
1417 #endif
1418
1419 Cursor_Row = Cursor_Col = 0;
1420
1421 #if defined (EMX_VIDEO)
1422
1423 v_init ();
1424 if ( v_hardware () != V_MONOCHROME ) IsColor = 1; else IsColor = 0;
1425
1426 v_getxy(&OldCol,&OldRow);
1427
1428 v_gotoxy (0, 0);
1429 if (IsColor)
1430 {
1431 if (_osmode == OS2_MODE)
1432 {
1433 # if 0
1434 /* Enable high-intensity background colors */
1435 VIOINTENSITY RequestBlock;
1436 RequestBlock.cb = sizeof (RequestBlock);
1437 RequestBlock.type = 2; RequestBlock.fs = 1;
1438 VioSetState (&RequestBlock, 0); /* nop if !fullscreen */
1439 # endif
1440 Blink_Killed = 1;
1441 }
1442 else
1443 {
1444 Blink_Killed = 1; /* seems to work */
1445 }
1446 }
1447
1448 if (!Attribute_Byte)
1449 {
1450 /* find the attribute currently under the cursor */
1451 v_getline (Line_Buffer, OldCol, OldRow, 1);
1452 Attribute_Byte = Line_Buffer[1];
1453 set_color_from_attribute (Attribute_Byte);
1454 }
1455
1456 v_attrib (Attribute_Byte);
1457 /* SLtt_Term_Cannot_Insert = 1; */
1458 #else /* EMX_VIDEO */
1459 # ifdef __os2__
1460 IsColor = 1; /* is it really? */
1461 {
1462 /* Enable high-intensity background colors */
1463 VIOINTENSITY RequestBlock;
1464 RequestBlock.cb = sizeof (RequestBlock);
1465 RequestBlock.type = 2; RequestBlock.fs = 1;
1466 VioSetState (&RequestBlock, 0); /* nop if !fullscreen */
1467 Blink_Killed = 1;
1468 }
1469
1470 if (!Attribute_Byte)
1471 {
1472 /* find the attribute currently under the cursor */
1473 USHORT Length = 2, Row, Col;
1474 VioGetCurPos (&Row, &Col, 0);
1475 VioReadCellStr ((PCH)Line_Buffer, &Length, Row, Col, 0);
1476 Attribute_Byte = Line_Buffer[1];
1477 set_color_from_attribute (Attribute_Byte);
1478 }
1479 # elif defined(WIN32)
1480 /* initialize the WIN32 console */
1481 IsColor = 1; /* yes, the WIN32 console can do color (on a color monitor) */
1482 # else
1483 # if defined (__GO32__) || defined (__WATCOMC__)
1484 # ifdef GO32_VIDEO
1485 SLtt_Term_Cannot_Insert = 1;
1486 # else
1487 Video_Base = (unsigned char *) ScreenPrimary;
1488 # endif
1489 if (!Attribute_Byte) Attribute_Byte = 0x17;
1490 IsColor = 1; /* is it really? */
1491
1492 if (IsColor)
1493 {
1494 union REGS r;
1495 # ifdef __WATCOMC__
1496 r.x.eax = 0x1003; r.x.ebx = 0;
1497 # else
1498 r.x.ax = 0x1003; r.x.bx = 0;
1499 # endif
1500 int86 (0x10, &r, &r);
1501 Blink_Killed = 1;
1502 }
1503 # else /* (__GO32__ or __WATCOMC__ */
1504 {
1505 unsigned char *p = (unsigned char far *) 0x00400049L;
1506 if (*p == 7)
1507 {
1508 Video_Status_Port = MONO_STATUS;
1509 Video_Base = (unsigned char *) MK_FP (0xb000,0000);
1510 IsColor = 0;
1511 }
1512 else
1513 {
1514 Video_Status_Port = CGA_STATUS;
1515 Video_Base = (unsigned char *) MK_FP (0xb800,0000);
1516 IsColor = 1;
1517 }
1518 }
1519
1520 /* test for video adapter type. Of primary interest is whether there is
1521 * snow or not. Assume snow if the card is color and not EGA or greater.
1522 */
1523
1524 /* Use Ralf Brown test for EGA or greater */
1525 asm mov ah, 0x12
1526 asm mov bl, 0x10
1527 asm mov bh, 0xFF
1528 asm int 10h
1529 asm cmp bh, 0xFF
1530 asm je L1
1531
1532 /* (V)EGA */
1533 asm xor bx, bx
1534 asm mov SLtt_Msdos_Cheap_Video, bx
1535 asm mov ax, Attribute_Byte
1536 asm cmp ax, bx
1537 asm jne L2
1538 asm mov ax, 0x17
1539 asm mov Attribute_Byte, ax
1540 asm jmp L2
1541
1542 L1:
1543 /* Not (V)EGA */
1544 asm mov ah, 0x0F
1545 asm int 10h
1546 asm cmp al, 7
1547 asm je L3
1548 asm mov ax, 1
1549 asm mov SLtt_Msdos_Cheap_Video, ax
1550 L3:
1551 asm mov ax, Attribute_Byte
1552 asm cmp ax, 0
1553 asm jne L2
1554 asm mov ax, 0x07
1555 asm mov Attribute_Byte, ax
1556 L2:
1557 /* toggle the blink bit so we can use hi intensity background */
1558 if (IsColor && !SLtt_Msdos_Cheap_Video)
1559 {
1560 asm mov ax, 0x1003
1561 asm mov bx, 0
1562 asm int 0x10
1563 Blink_Killed = 1;
1564 }
1565 # endif /* __GO32__ or __WATCOMC__ */
1566 # endif /* __os2__ */
1567 #endif /* EMX_VIDEO */
1568 SLtt_set_scroll_region (0, SLtt_Screen_Rows);
1569 SLtt_Use_Ansi_Colors = IsColor;
1570 }
1571
1572 /*----------------------------------------------------------------------*\
1573 * Function: int SLtt_flush_output (void);
1574 \*----------------------------------------------------------------------*/
1575 int SLtt_flush_output (void)
1576 {
1577 fflush (stdout);
1578 return -1;
1579 }
1580
1581 int SLtt_set_cursor_visibility (int show)
1582 {
1583 (void) show;
1584 return -1;
1585 }
1586
1587 void SLtt_set_mono (int obj_unused, char *unused, SLtt_Char_Type c_unused)
1588 {
1589 (void) obj_unused;
1590 (void) unused;
1591 (void) c_unused;
1592 }
1593
1594 /* /////////////////////// end of file (c source) ///////////////////// */