forked from MidnightCommander/mc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslvideo.c
1594 lines (1422 loc) · 43 KB
/
slvideo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef __WIN32__
# include <windows.h>
#endif
#ifdef __GO32__
# undef msdos
#endif
#if defined (msdos)
# include <conio.h>
# include <bios.h>
# include <mem.h>
#endif
#if defined (__WATCOMC__)
# include <graph.h>
# define int86 int386 /* simplify code writing */
#endif
#if defined (__GO32__)
# include <pc.h>
# define GO32_VIDEO
#endif
#if defined (__os2__) && !defined (EMX_VIDEO)
# define INCL_BASE
# define INCL_NOPM
# define INCL_VIO
# define INCL_KBD
# include <os2.h>
#else
# if defined (__EMX__) /* EMX video does both DOS & OS/2 */
# ifndef EMX_VIDEO
# define EMX_VIDEO
# endif
# include <sys/video.h>
# endif
#endif
#include <dos.h>
#include "_slang.h"
#ifdef GO32_VIDEO
# define HAS_SAVE_SCREEN
#endif
/* ------------------------- global variables ------------------------- */
#ifdef WIN32
extern HANDLE hStdout, hStdin;
extern CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
#endif
int SLtt_Term_Cannot_Insert;
int SLtt_Term_Cannot_Scroll;
int SLtt_Ignore_Beep = 3;
int SLtt_Use_Ansi_Colors;
int SLtt_Screen_Rows = 25;
int SLtt_Screen_Cols = 80;
/* ------------------------- local variables -------------------------- */
static int Attribute_Byte;
static int Scroll_r1 = 0, Scroll_r2 = 25;
static int Cursor_Row = 1, Cursor_Col = 1;
static int Current_Color;
static int IsColor = 1;
static int Blink_Killed; /* high intensity background enabled */
#define JMAX_COLORS 256
#define JNORMAL_COLOR 0
#define JNO_COLOR -1
static unsigned char Color_Map [JMAX_COLORS] =
{
0x7, 0x70, 0x70, 0x70, 0x70, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7
};
#define JMAX_COLOR_NAMES 16
static char *Color_Names [JMAX_COLOR_NAMES] =
{
"black", "blue", "green", "cyan",
"red", "magenta", "brown", "lightgray",
"gray", "brightblue", "brightgreen", "brightcyan",
"brightred", "brightmagenta", "yellow", "white"
};
/*
* set_color_from_attribute (int attribute);
* define the correspondence of color to attribute
*/
#define set_color_from_attribute(a)\
SLtt_set_color (\
JNORMAL_COLOR, NULL,\
Color_Names[(a) & 0xf],\
Color_Names[(a) >> 4])
/* this is how to make a space character */
#define mkSpaceChar() (((Attribute_Byte) << 8) | 0x20)
/* buffer to hold a line of character/attribute pairs */
#define MAXCOLS 256
static unsigned char Line_Buffer [MAXCOLS*2];
/*----------------------------------------------------------------------*\
* define various ways and means of writing to the screen
\*----------------------------------------------------------------------*/
#if defined (__GO32__) || defined (__WATCOMC__)
# if !defined (GO32_VIDEO)
# define HAS_LINEAR_SCREEN
# endif
#else /* __GO32__ or __WATCOMC__ */
# if defined (msdos)
# define USE_ASM
# endif
#endif /* __GO32__ or __WATCOMC__ */
/* define for direct to memory screen writes */
#if defined (USE_ASM) || defined (HAS_LINEAR_SCREEN)
static unsigned char *Video_Base;
# define mkScreenPointer(row,col) ((unsigned short *)\
(Video_Base +\
2 * (SLtt_Screen_Cols * (row)\
+ (col))))
# if defined (USE_ASM)
int SLtt_Msdos_Cheap_Video = 0;
static int Video_Status_Port;
# define MONO_STATUS 0x3BA
# define CGA_STATUS 0x3DA
# define CGA_SETMODE 0x3D8
# define SNOW_CHECK \
if (SLtt_Msdos_Cheap_Video)\
{ while ((inp (CGA_STATUS) & 0x08)); while (!(inp (CGA_STATUS) & 0x08)); }
# endif /* USE_ASM */
#endif /* USE_ASM or HAS_LINEAR_SCREEN */
/* -------------------------------------------------------------------- */
#if defined (__WATCOMC__)
# define ScreenPrimary (0xb800 << 4)
# define ScreenSize (SLtt_Screen_Cols * SLtt_Screen_Rows)
# define ScreenSetCursor (x,y) _settextposition (x+1,y+1)
void ScreenGetCursor (int *x, int *y)
{
struct rccoord rc = _gettextposition ();
*x = rc.row - 1;
*y = rc.col - 1;
}
void ScreenRetrieve (unsigned char *dest)
{
memcpy (dest, (unsigned char *) ScreenPrimary, 2 * ScreenSize);
}
void ScreenUpdate (unsigned char *src)
{
memcpy ((unsigned char *) ScreenPrimary, src, 2 * ScreenSize);
}
#endif /* __WATCOMC__ */
#ifdef HAS_SAVE_SCREEN
static void *Saved_Screen_Buffer;
static int Saved_Cursor_Row;
static void save_screen (void)
{
int row, col;
if (Saved_Screen_Buffer != NULL)
{
SLFREE (Saved_Screen_Buffer);
Saved_Screen_Buffer = NULL;
}
#ifdef GO32_VIDEO
Saved_Screen_Buffer = SLMALLOC (sizeof (short) *
ScreenCols () * ScreenRows ());
if (Saved_Screen_Buffer == NULL)
return;
ScreenRetrieve (Saved_Screen_Buffer);
ScreenGetCursor (&row, &col);
Saved_Cursor_Row = row;
#endif
}
static void restore_screen (void)
{
if (Saved_Screen_Buffer == NULL) return;
#ifdef GO32_VIDEO
ScreenUpdate (Saved_Screen_Buffer);
SLtt_goto_rc (Saved_Cursor_Row, 0);
#endif
}
#endif /* HAS_SAVE_SCREEN */
/*----------------------------------------------------------------------*\
* Function: void SLtt_write_string (char *str);
*
* put string STR to 'stdout'
\*----------------------------------------------------------------------*/
void SLtt_write_string (char *str)
{
#ifdef WIN32
int bytes;
(void) WriteConsole(hStdout, str, strlen(str), &bytes, NULL);
#else
fputs (str, stdout);
#endif
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_set_scroll_region (int r1, int r2);
*
* define a scroll region of top_row to bottom_row
\*----------------------------------------------------------------------*/
void SLtt_set_scroll_region (int top_row, int bottom_row)
{
Scroll_r1 = top_row;
Scroll_r2 = bottom_row;
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_reset_scroll_region (void);
*
* reset the scrol region to be the entire screen,
* ie, SLtt_set_scroll_region (0, SLtt_Screen_Rows);
\*----------------------------------------------------------------------*/
void SLtt_reset_scroll_region (void)
{
Scroll_r1 = 0;
Scroll_r2 = SLtt_Screen_Rows;
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_goto_rc (int row, int col);
*
* move the terminal cursor to x,y position COL, ROW and record the
* position in Cursor_Row, Cursor_Col
\*----------------------------------------------------------------------*/
void SLtt_goto_rc (int row, int col)
{
#ifdef WIN32
COORD newPosition;
newPosition.X = col;
newPosition.Y = row;
#endif
#if !defined (USE_ASM)
if (row > SLtt_Screen_Rows) row = SLtt_Screen_Rows;
if (col > SLtt_Screen_Cols) col = SLtt_Screen_Cols;
# if defined (EMX_VIDEO)
v_gotoxy (col, Scroll_r1 + row);
# else /* EMX_VIDEO_ */
# if defined (__os2__)
VioSetCurPos (Scroll_r1 + row, col, 0);
# elif defined(WIN32)
(void) SetConsoleCursorPosition(hStdout, newPosition);
# else /* __os2__ */
# if defined (__GO32__) || defined (__WATCOMC__)
ScreenSetCursor(Scroll_r1 + row, col);
# endif /* __GO32__ or __WATCOMC__ */
# endif /* __os2__ */
# endif /* EMX_VIDEO_ */
Cursor_Row = row;
Cursor_Col = col;
#else /* USE_ASM */
/* if (r > SLtt_Screen_Rows - 1) r = SLtt_Screen_Rows - 1; */
asm mov ax, row
asm mov bx, SLtt_Screen_Rows
asm dec bx
asm cmp ax, bx
asm jle L1
asm mov ax, bx
L1:
/* if (c > SLtt_Screen_Cols - 1) c = SLtt_Screen_Cols - 1; */
asm mov cx, SLtt_Screen_Cols
asm dec cx
asm mov bx, col
asm cmp bx, cx
asm jle L2
asm mov bx, cx
L2:
asm mov Cursor_Row, ax
asm mov Cursor_Col, bx
asm add ax, Scroll_r1
asm xor dx, dx
asm mov dh, al
asm mov dl, bl
asm xor bx, bx
asm mov ax, 0x200
asm int 0x10
#endif /* USE_ASM */
}
/*----------------------------------------------------------------------*\
* Function: static void slvid_getxy (void);
*
* retrieve the cursor position into Cursor_Row, Cursor_Col
\*----------------------------------------------------------------------*/
static void slvid_getxy (void)
{
#if !defined (USE_ASM)
# if defined (EMX_VIDEO)
v_getxy (&Cursor_Col, &Cursor_Row);
# else /* EMX_VIDEO */
# if defined (__os2__)
VioGetCurPos ((USHORT*) &Cursor_Row, (USHORT*) &Cursor_Col, 0);
# elif defined(WIN32)
CONSOLE_SCREEN_BUFFER_INFO screenInfo;
if (GetConsoleScreenBufferInfo(hStdout, &screenInfo) == TRUE)
{
Cursor_Row = screenInfo.dwCursorPosition.Y;
Cursor_Col = screenInfo.dwCursorPosition.X;
}
# else /* __os2__ */
# if defined (__GO32__) || defined (__WATCOMC__)
ScreenGetCursor (&Cursor_Row, &Cursor_Col);
# endif /* __GO32__ or __WATCOMC__ */
# endif /* __os2__ */
# endif /* EMX_VIDEO */
#else /* USE_ASM */
asm mov ah, 3
asm mov bh, 0
asm int 10h
asm xor ax, ax
asm mov al, dh
asm mov Cursor_Row, ax
asm xor ax, ax
asm mov al, dl
asm mov Cursor_Col, ax
#endif /* USE_ASM */
}
/*----------------------------------------------------------------------*\
* static void slvid_deleol (int x);
*
* write space characters from column X of row Cursor_Row through to
* SLtt_Screen_Cols using the current Attribute_Byte
\*----------------------------------------------------------------------*/
#if defined (GO32_VIDEO)
static void slvid_deleol (int x)
{
while (x < SLtt_Screen_Cols)
ScreenPutChar (32, Attribute_Byte, x++, Cursor_Row);
}
#endif
#if defined (EMX_VIDEO)
static void slvid_deleol (int x)
{
unsigned char *p, *pmax;
int w = mkSpaceChar ();
int count = SLtt_Screen_Cols - x;
p = Line_Buffer;
pmax = p + 2 * count;
while (p < pmax)
{
*p++ = (unsigned char) w;
*p++ = (unsigned char) (w >> 8);
}
v_putline (Line_Buffer, x, Cursor_Row, count);
}
#endif /* EMX_VIDEO */
/*----------------------------------------------------------------------*\
* Function: void SLtt_begin_insert (void);
*
* insert a single space, moving everything right 1 character to make room
\*----------------------------------------------------------------------*/
void SLtt_begin_insert (void)
{
#if !defined (GO32_VIDEO)
# if defined (HAS_LINEAR_SCREEN) || defined (USE_ASM)
unsigned short *p;
# if defined (HAS_LINEAR_SCREEN)
unsigned short *pmin;
# endif
# endif
int n;
slvid_getxy ();
n = SLtt_Screen_Cols - Cursor_Col;
/* Msdos_Insert_Mode = 1; */
# ifndef WIN32
# if defined (EMX_VIDEO)
v_getline (Line_Buffer, Cursor_Col, Cursor_Row, n);
v_putline (Line_Buffer, Cursor_Col+1, Cursor_Row, n - 1);
# else /* EMX_VIDEO */
# if defined (__os2__)
n = 2 * (n - 1);
VioReadCellStr ((PCH)Line_Buffer, (USHORT*) &n, Cursor_Row, Cursor_Col, 0);
VioWrtCellStr ((PCH)Line_Buffer, n, Cursor_Row, Cursor_Col + 1, 0);
# else /* __os2__ */
p = mkScreenPointer (Cursor_Row, SLtt_Screen_Cols - 1);
# if defined (HAS_LINEAR_SCREEN)
/* pmin = p - (n-1); */
pmin = mkScreenPointer (Cursor_Row, Cursor_Col);
while (p-- > pmin) *(p + 1) = *p;
# else
SNOW_CHECK;
asm mov ax, ds
asm mov bx, di
asm mov dx, si
asm mov cx, n
asm les di, p
asm lds si, p
asm sub si, 2
asm std
asm rep movsw
asm mov ds, ax
asm mov di, bx
asm mov si, dx
# endif /* HAS_LINEAR_SCREEN */
# endif /* __os2__ */
# endif /* EMX_VIDEO */
# endif /* WIN32 */
#endif /* not GO32_VIDEO */
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_end_insert (void);
*
* any cleanup after insert a blank column
\*----------------------------------------------------------------------*/
void SLtt_end_insert (void)
{
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_delete_char (void);
*
* delete a single character, moving everything left 1 column to take
* up the room
\*----------------------------------------------------------------------*/
void SLtt_delete_char (void)
{
#if !defined (GO32_VIDEO)
# if defined (HAS_LINEAR_SCREEN) || defined (USE_ASM)
unsigned short *p;
# if defined (HAS_LINEAR_SCREEN)
register unsigned short *p1;
# endif
# endif
int n;
slvid_getxy ();
n = SLtt_Screen_Cols - Cursor_Col - 1;
# ifndef WIN32
# if defined (EMX_VIDEO)
v_getline (Line_Buffer, Cursor_Col+1, Cursor_Row, n);
v_putline (Line_Buffer, Cursor_Col, Cursor_Row, n);
# else /* EMX_VIDEO */
# if defined (__os2__)
n *= 2;
VioReadCellStr ((PCH)Line_Buffer, (USHORT*)&n, Cursor_Row, Cursor_Col + 1, 0);
VioWrtCellStr ((PCH)Line_Buffer, n, Cursor_Row, Cursor_Col, 0);
return;
# else /* __os2__ */
p = mkScreenPointer (Cursor_Row, Cursor_Col);
# if defined (HAS_LINEAR_SCREEN)
while (n--)
{
p1 = p + 1;
*p = *p1;
p++;
}
# else /* HAS_LINEAR_SCREEN */
SNOW_CHECK;
asm mov ax, ds
asm mov bx, si
asm mov dx, di
asm mov cx, n
asm les di, p
asm lds si, p
asm add si, 2
asm cld
asm rep movsw
asm mov ds, ax
asm mov si, bx
asm mov di, dx
# endif /* HAS_LINEAR_SCREEN */
# endif /* __os2__ */
# endif /* EMX_VIDEO */
# endif /* WIN32 */
#endif /* not GO32_VIDEO */
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_erase_line (void);
*
* This function is *only* called on exit.
* It sets attribute byte to Black & White
\*----------------------------------------------------------------------*/
void SLtt_erase_line (void)
{
#ifndef WIN32
# if defined (GO32_VIDEO) || defined (EMX_VIDEO)
Attribute_Byte = 0x07;
slvid_deleol (0);
# else /* GO32_VIDEO or EMX_VIDEO */
# if defined (__os2__)
USHORT w;
Attribute_Byte = 0x07;
w = mkSpaceChar ();
VioWrtNCell ((BYTE*)&w, SLtt_Screen_Cols, Cursor_Row, 0, 0);
# else /* __os2__ */
unsigned short w;
unsigned short *p = mkScreenPointer (Cursor_Row, 0);
# if defined (HAS_LINEAR_SCREEN)
register unsigned short *pmax = p + SLtt_Screen_Cols;
Attribute_Byte = 0x07;
w = mkSpaceChar ();
while (p < pmax) *p++ = w;
# else /* HAS_LINEAR_SCREEN */
Attribute_Byte = 0x07;
w = mkSpaceChar ();
SNOW_CHECK;
asm mov dx, di
asm mov ax, w
asm mov cx, SLtt_Screen_Cols
asm les di, p
asm cld
asm rep stosw
asm mov di, dx
# endif /* HAS_LINEAR_SCREEN */
# endif /* __os2__ */
# endif /* GO32_VIDEO or EMX_VIDEO */
Current_Color = JNO_COLOR; /* since we messed with attribute byte */
#endif /* WIN32 */
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_delete_nlines (int nlines);
*
* delete NLINES by scrolling up the region <Scroll_r1, Scroll_r2>
\*----------------------------------------------------------------------*/
void SLtt_delete_nlines (int nlines)
{
SLtt_normal_video ();
#ifndef WIN32
# if defined (EMX_VIDEO)
v_attrib (Attribute_Byte);
v_scroll (0, Scroll_r1, SLtt_Screen_Cols-1, Scroll_r2, nlines, V_SCROLL_UP);
# else /* EMX_VIDEO */
# if defined (__os2__)
{
Line_Buffer[0] = ' '; Line_Buffer[1] = Attribute_Byte;
VioScrollUp (Scroll_r1, 0, Scroll_r2, SLtt_Screen_Cols-1,
nlines, (PCH) Line_Buffer, 0);
}
# else /* __os2__ */
# if defined (USE_ASM)
/* This has the effect of pulling all lines below it up */
asm mov ax, nlines
asm mov ah, 6 /* int 6h */
asm xor cx, cx
asm mov ch, byte ptr Scroll_r1
asm mov dx, SLtt_Screen_Cols
asm dec dx
asm mov dh, byte ptr Scroll_r2
asm mov bh, byte ptr Attribute_Byte
asm int 10h
# else /* USE_ASM */
{
union REGS r;
# if defined (__WATCOMC__)
r.x.eax = nlines;
r.x.ecx = 0;
# else
r.x.ax = nlines;
r.x.cx = 0;
# endif
r.h.ah = 6;
r.h.ch = Scroll_r1;
r.h.dl = SLtt_Screen_Cols - 1;
r.h.dh = Scroll_r2;
r.h.bh = Attribute_Byte;
int86 (0x10, &r, &r);
}
# endif /* USE_ASM */
# endif /* __os2__ */
# endif /* EMX_VIDEO */
#endif /* WIN32 */
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_reverse_index (int nlines);
*
* scroll down the region <Scroll_r1, Scroll_r2> by NLINES
\*----------------------------------------------------------------------*/
void SLtt_reverse_index (int nlines)
{
SLtt_normal_video ();
#ifndef WIN32
# if defined (EMX_VIDEO)
v_attrib (Attribute_Byte);
v_scroll (0, Scroll_r1, SLtt_Screen_Cols-1, Scroll_r2, nlines,
V_SCROLL_DOWN);
# else /* EMX_VIDEO */
# if defined (__os2__)
{
Line_Buffer[0] = ' '; Line_Buffer[1] = Attribute_Byte;
VioScrollDn (Scroll_r1, 0, Scroll_r2, SLtt_Screen_Cols-1,
nlines, (PCH) Line_Buffer, 0);
}
# else /* __os2__ */
# if defined (USE_ASM)
asm xor cx, cx
asm mov ch, byte ptr Scroll_r1
asm mov dx, SLtt_Screen_Cols
asm dec dx
asm mov dh, byte ptr Scroll_r2
asm mov bh, byte ptr Attribute_Byte
asm mov ah, 7
asm mov al, byte ptr nlines
asm int 10h
# else /* USE_ASM */
{
union REGS r;
r.h.al = nlines;
# if defined (__WATCOMC__)
r.x.ecx = 0;
# else
r.x.cx = 0;
# endif
r.h.ah = 7;
r.h.ch = Scroll_r1;
r.h.dl = SLtt_Screen_Cols - 1;
r.h.dh = Scroll_r2;
r.h.bh = Attribute_Byte;
int86 (0x10, &r, &r);
}
# endif /* USE_ASM */
# endif /* __os2__ */
# endif /* EMX_VIDEO */
#endif /* WIN32 */
}
/*----------------------------------------------------------------------*\
* Function: static void slvid_invert_region (int top_row, int bot_row);
*
* invert the display in the region, top_row <= row < bot_row
\*----------------------------------------------------------------------*/
static void slvid_invert_region (int top_row, int bot_row)
{
#ifndef WIN32
# if defined (EMX_VIDEO)
int row, col;
for (row = top_row; row < bot_row; row++)
{
v_getline (Line_Buffer, 0, row, SLtt_Screen_Cols);
for (col = 1; col < SLtt_Screen_Cols * 2; col += 2)
Line_Buffer [col] ^= 0xff;
v_putline (Line_Buffer, 0, row, SLtt_Screen_Cols);
}
# else /* EMX_VIDEO */
# ifdef __os2__
int row, col;
USHORT length = SLtt_Screen_Cols * 2;
for (row = top_row; row < bot_row; row++)
{
VioReadCellStr ((PCH)Line_Buffer, &length, row, 0, 0);
for (col = 1; col < length; col += 2)
Line_Buffer [col] ^= 0xff;
VioWrtCellStr ((PCH)Line_Buffer, length, row, 0, 0);
}
# else /* __os2__ */
# if defined (__GO32__) || defined (__WATCOMC__)
unsigned char buf [2 * 180 * 80]; /* 180 cols x 80 rows */
unsigned char *b, *bmax;
b = buf + 1 + 2 * SLtt_Screen_Cols * top_row;
bmax = buf + 1 + 2 * SLtt_Screen_Cols * bot_row;
ScreenRetrieve (buf);
while (b < bmax)
{
*b ^= 0xFF;
b += 2;
}
ScreenUpdate (buf);
# else /* __GO32__ or __WATCOMC__ */
register unsigned short ch, sh;
register unsigned short *pmin = mkScreenPointer (top_row, 0);
register unsigned short *pmax = mkScreenPointer (bot_row, 0);
while (pmin < pmax)
{
sh = *pmin;
ch = sh;
ch = ch ^ 0xFF00;
*pmin = (ch & 0xFF00) | (sh & 0x00FF);
pmin++;
}
# endif /* __GO32__ or __WATCOMC__ */
# endif /* __os2__ */
# endif /* EMX_VIDEO */
#endif /* WIN32 */
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_beep (void);
*
* signal error by a "bell" condition, the type of signal is governed
* by the value of SLtt_Ignore_Beep:
*
* 0 silent bell
* 1 audible bell
* 2 visual bell
* 4 special visual bell (only flash the bottom status line)
*
* these may be combined:
* eg, 3 = audible visual bell.
* but if both the visual bell and the "special" visual bell are specified,
* only the special bell is used.
\*----------------------------------------------------------------------*/
void SLtt_beep (void)
{
int audible; /* audible bell */
int special = 0; /* first row to invert */
int visual = 0; /* final row to invert */
if (!SLtt_Ignore_Beep) return;
audible = (SLtt_Ignore_Beep & 1);
if ( (SLtt_Ignore_Beep & 4) )
{
special = SLtt_Screen_Rows - 1;
visual = special--; /* only invert bottom status line */
}
else if ( (SLtt_Ignore_Beep & 2) )
{
visual = SLtt_Screen_Rows;
}
if (visual) slvid_invert_region (special, visual);
#if defined (EMX_VIDEO)
if (audible) /*sound (1500)*/; _sleep2 (100); if (audible) /* nosound () */;
#else
# ifdef __os2__
if (audible) DosBeep (1500, 100); else DosSleep (100);
# elif defined(WIN32)
# else
if (audible) sound (1500); delay (100); if (audible) nosound ();
# endif
#endif
if (visual) slvid_invert_region (special, visual);
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_del_eol (void);
*
* delete from the current cursor position to the end of the row
\*----------------------------------------------------------------------*/
void SLtt_del_eol (void)
{
#ifndef WIN32
# if defined (GO32_VIDEO) || defined (EMX_VIDEO)
if (Current_Color != JNO_COLOR) SLtt_normal_video ();
slvid_deleol (Cursor_Col);
# else /* GO32_VIDEO or EMX_VIDEO */
# ifdef __os2__
USHORT w;
if (Current_Color != JNO_COLOR) SLtt_normal_video ();
w = mkSpaceChar ();
VioWrtNCell ((BYTE*)&w, (SLtt_Screen_Cols - Cursor_Col),
Cursor_Row, Cursor_Col, 0);
# else /* __os2__ */
unsigned short *p = mkScreenPointer (Cursor_Row, Cursor_Col);
int n = SLtt_Screen_Cols - Cursor_Col;
unsigned short w;
# if defined (HAS_LINEAR_SCREEN)
unsigned short *pmax = p + n;
if (Current_Color != JNO_COLOR) SLtt_normal_video ();
w = mkSpaceChar ();
while (p < pmax) *p++ = w;
# else /* HAS_LINEAR_SCREEN */
if (Current_Color != JNO_COLOR) SLtt_normal_video ();
w = mkSpaceChar ();
SNOW_CHECK;
asm mov dx, di
asm les di, p
asm mov ax, w
asm mov cx, n
asm cld
asm rep stosw
asm mov di, dx
# endif /* HAS_LINEAR_SCREEN */
# endif /* __os2__ */
# endif /* GO32_VIDEO or EMX_VIDEO */
#endif /* WIN32 */
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_reverse_video (int color);
*
* set Attribute_Byte corresponding to COLOR.
* Use Current_Color to remember the color which was set.
* convert from the COLOR number to the attribute value.
\*----------------------------------------------------------------------*/
void SLtt_reverse_video (int color)
{
Attribute_Byte = Color_Map [color];
Current_Color = color;
}
/*----------------------------------------------------------------------*\
* Function: void SLtt_normal_video (void);
*
* reset the attributes for normal video
\*----------------------------------------------------------------------*/
void SLtt_normal_video (void)
{
SLtt_reverse_video (JNORMAL_COLOR);
}
#if defined (USE_ASM)
/*----------------------------------------------------------------------*\
* Function: static unsigned short *video_write (register unsigned char *pp,
* register unsigned char *p,
* register unsigned short *pos)
*
* write out (P - PP) characters from the array pointed to by PP
* at position (POS, Cursor_Row) in the current Attribute_Byte
*
* increment POS to reflect the number of characters sent and
* return the it as a pointer
\*----------------------------------------------------------------------*/
static unsigned short *video_write (register unsigned char *pp,
register unsigned char *p,
register unsigned short *pos)
{
int n = (int) (p - pp); /* num of characters of PP to write */
asm push si
asm push ds
asm push di
/* set up register for BOTH fast and slow */
asm mov bx, SLtt_Msdos_Cheap_Video
/* These are the registers needed for both fast AND slow */
asm mov ah, byte ptr Attribute_Byte
asm mov cx, n
asm lds si, dword ptr pp
asm les di, dword ptr pos
asm cld
asm cmp bx, 0 /* cheap video test */
asm je L_fast
asm mov bx, ax
asm mov dx, CGA_STATUS
asm jg L_slow_blank
/* slow video */
asm cli
/* wait for retrace */
L_slow:
asm in al, dx
asm test al, 1
asm jnz L_slow
L_slow1:
asm in al, dx
asm test al, 1
asm jz L_slow1
/* move a character out */
asm mov ah, bh
asm lodsb
asm stosw
asm loop L_slow
asm sti
asm jmp done
/* -------------- slow video, vertical retace and pump --------------*/
L_slow_blank:
L_slow_blank_loop:
asm in al, dx
asm test al, 8
asm jnz L_slow_blank_loop
L_slow_blank1:
asm in al, dx
asm test al, 8
asm jz L_slow_blank1
/* write line */
asm mov ah, bh
L_slow_blank2:
asm lodsb
asm stosw
asm loop L_slow_blank2
asm jmp done
/*-------------- Fast video --------------*/
L_fast:
asm lodsb
asm stosw
asm loop L_fast
done:
asm pop di
asm pop ds
asm pop si
return (pos + n);
}
#endif /* USE_ASM */
/*----------------------------------------------------------------------*\
* Function: static void write_attributes (unsigned short *src,
* int count);