forked from AnttiTakala/SSH2DOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vidio.c
1363 lines (1103 loc) · 37.5 KB
/
vidio.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) 1988 Jerry Joplin
*
* Portions copyright (c) 1981, 1988
* Trustees of Columbia University in the City of New York
*
* Permission is granted to any individual or institution
* to use, copy, or redistribute this program and
* documentation as long as it is not sold for profit and
* as long as the Columbia copyright notice is retained.
*
*
* Modified by Nagy Daniel - OpenWatcom
* - added ChrDelete function
* - added LineRight function
* - removed unnecessary things (sorry, need memory)
* - added scrollback support
*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <stdarg.h>
#include <dos.h>
#include <i86.h>
#include "config.h"
#include "common.h"
#if defined (MEMWATCH)
#include "memwatch.h"
#endif
#define SCROLLBUFSIZE 32768 /* size of scrollback buffer (short)*/
#if defined (__386__)
#undef MK_FP
static char *MK_FP (unsigned short seg, unsigned short ofs)
{
return (char *) ((seg << 4) + ofs);
}
#endif
static char peekb(unsigned short segment, unsigned short offset)
{
char *p;
p = MK_FP(segment, offset);
return(*p);
}
static short peekw(unsigned segment, unsigned offset)
{
short *p;
p = (short *)MK_FP(segment, offset);
return(*p);
}
#define BLINK 0x80 /* Blink video attribute */
#define NORMAL 0x7 /* Normal video attribute */
#define BOLD 0x8 /* Bold video attribute */
#define UNDERLINED 0xA /* Underlined video attribute */
#define REVERSE 0x70 /* Reverse video attribute */
#define SCREEN 0x10 /* BIOS video interrupt number */
#define RETRACE 0x3da /* Video Retrace port address for CGA */
#define ASCII 0 /* ASCII character set */
#define UK 1 /* UK character set */
#define SPECIAL 2 /* Special character set, graphics chars */
/****************************************************************************/
/* Global Data */
unsigned short statusline = 1; /* status line */
unsigned short vidmode = 0; /* Screen video mode */
unsigned short origvmode = 0; /* Original video mode */
unsigned columns; /* Columns on logical terminal screen */
unsigned lines; /* Lines on logical terminal screen */
int cursx; /* X cursor position */
int cursy; /* Y cursor position */
unsigned char scrolltop; /* Top row of scrolling region */
unsigned char curattr; /* Video attribute of displayable chars */
char vidpages; /* number of video pages in current mode */
/****************************************************************************/
/* External variables */
extern Config GlobalConfig;
extern unsigned short Configuration;
extern unsigned originmode; /* Origin mode, relative or absolute */
extern unsigned insertmode; /* Insert mode, off or on */
extern unsigned autowrap; /* Automatic wrap mode, off or on */
extern unsigned cursorvisible; /* Cursor visibility, on or hidden */
extern unsigned reversebackground; /* Reverse background attribute, on or off */
extern unsigned screenwid; /* Absolute screen width */
/***************************************************************************/
/* Local static data */
static unsigned char retracemode = 0; /* Flag indicating No Video refresh wait */
static unsigned isvga = 0; /* Is VGA */
static unsigned char screentop; /* Absolute top of screen */
static unsigned char screenbot; /* Absolute bottom of screen */
static unsigned char scrollbot; /* Bottom row of scrolling region */
static unsigned char CharCounter; /* for Brailab adapter support */
static unsigned scroff; /* Screen memory offset */
static unsigned scrseg; /* Screen memory segment */
static char *screen; /* Pointer to video screen */
static unsigned char video_state; /* State of video, reversed or normal */
static unsigned char scbattr; /* Video attribute of empty video cell */
static unsigned char baseattr; /* Base attribute for video attributes */
static unsigned char extrattr; /* Extra attribute for video attributes */
static unsigned char vesa; /* is VESA available? */
static char actpage; /* actual video page */
static char *scrollbuf; /* scrollback buffer */
static unsigned char att_reverse; /* Reverse attribute bits */
static unsigned char att_normal; /* Normal attribute bits */
static unsigned char att_low_mask = 0x6; /* Low attribute mask */
static unsigned char att_underline = 0x1; /* Underlined attribute bit */
static unsigned char att_intensity = 0x8; /* Bold attribute bit */
static unsigned char att_blink = 0x80; /* Blinking attribute bit */
static char tabs[132]; /* active tab stops */
static char deftabs[132]; /* default tab stops, 9,17,26 .... */
static int G0 = ASCII; /* Character set G0 */
static int G1 = ASCII; /* Character set G1 */
static int *GL = &G0; /* Pointer to current mapped character set */
static char special_chars[32] = { /* Special characters */
32, 4, 176, 9, 12, 13, 10, 248, 241, 18, 11, 217, 191, 218, 192,
197,
196, 196, 196, 196, 196, 195, 180, 193, 194, 179, 243, 242, 227,
216, 156, 7
};
static char defpalette[48] = { /* Default color palette */
0x00, 0x00, 0x00,
0x00, 0x00, 0xAA,
0x00, 0xAA, 0x00,
0x00, 0xAA, 0xAA,
0xAA, 0x00, 0x00,
0xAA, 0x00, 0xAA,
0xAA, 0x55, 0x00,
0xAA, 0xAA, 0xAA,
0x55, 0x55, 0x55,
0x55, 0x55, 0xFF,
0x55, 0xFF, 0x55,
0x55, 0xFF, 0xFF,
0xFF, 0x55, 0x55,
0xFF, 0x55, 0xFF,
0xFF, 0xFF, 0x55,
0xFF, 0xFF, 0xFF
};
static char paletteregs[17] = { /* Palette register list */
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x00
};
static struct SaveCursorStruct { /* Structure to save cursor description */
int cursx; /* X cursor position, column */
int cursy; /* Y cursor position, row */
int *GL; /* pointer to mapped character set */
int G0; /* character set G0 */
int G1; /* character set G1 */
int mode; /* origin mode */
} save = {
1, 1, &G0, ASCII, ASCII, 0};
/****************************************************************************/
/****************************************************************************/
/* I N T E R R U P T 1 0 -- Call on the BIOS video software interrupt */
static union REGS interrupt10(unsigned short ax, unsigned short bx,
unsigned short cx, unsigned short dx)
{
union REGS r;
r.w.cx = cx; /* Load contents of register parameters */
r.w.dx = dx;
r.w.bx = bx;
r.w.ax = ax;
#if defined (__386__)
int386(0x10, &r, &r); /* Issue Video interrupt */
#else
int86(0x10, &r, &r); /* Issue Video interrupt */
#endif
return(r);
}
/* B R K A T T R -- Break an attribute into its video components */
static void BrkAtt(unsigned char attribute)
{
extrattr = 0; /* Clear extra attributes */
baseattr = attribute; /* Start specified base attribute */
if(vidmode == 0x7) { /* If a Monochrome monitor */
if(attribute & att_low_mask) { /* Any Low mask attributes on? */
baseattr |= att_normal; /* if yes then set normal bits on */
} else { /* else check other attributes */
if(attribute & att_underline) { /* Underline attribute ? */
extrattr |= att_underline; /* yes then set underline bit */
if(attribute & 0x70) /* Reverse video ? */
baseattr &= ~att_underline; /* If yes then clear underline */
else /* monochrome can't do both */
baseattr |= att_normal; /* Else set normal bits on */
}
}
}
if(baseattr & att_intensity) /* If bold attribute is on */
extrattr |= att_intensity; /* then set intensity bit */
if(baseattr & att_blink) /* If blink attribute is on */
extrattr |= att_blink; /* then set blink bit */
/* Turn off blink,bold in base attribute */
baseattr &= ~(att_intensity + att_blink);
}
/* A D D A T R -- Build video attribute from base and extra attributes */
static unsigned char AddAtt(void)
{
if(extrattr & att_underline) /* If underline is requested */
baseattr &= ~att_low_mask; /* Clear low mask */
return (baseattr | extrattr); /* return the or'ed attributes */
}
/* S T A R T S C R E E N -- Updates 'screen' pointer to 'row' and 'col' pos. */
void StartScreen(register int row, register int col)
{
scroff = ((row * columns) + col) * 2; /* Calculate offset from beginning of */
/* screen memory */
/* Construct a far pointer to video memory */
screen = MK_FP(scrseg, scroff);
}
/* V T P R I N T F -- print a formatted string to the video screen */
static int vtprintf(int row, int col, int reverse, char *strformat, ...)
{
unsigned attr, nchars;
va_list argptr;
char str[132];
char *sptr = str;
if(reverse) { /* If reversed attribute specified */
attr = att_reverse;
} else { /* Else use normal attribute */
attr = att_normal;
}
va_start(argptr, strformat); /* Start variable length argument list */
StartScreen(row, col); /* Start a screen update */
nchars = vsprintf(str, strformat, argptr); /* Format the string */
while (*sptr != '\0') { /* Move the formatted string */
*screen++ = *sptr++; /* to video memory */
*screen++ = attr;
}
va_end(argptr); /* End the va_start */
return (nchars); /* Return number of characters written */
}
/* V E S A C H E C K -- Check if VESA BIOS is available */
void VESACheck(void)
{
union REGS r;
struct SREGS s;
#if defined (__386__)
short sel, seg;
static struct rminfo {
long EDI;
long ESI;
long EBP;
long reserved_by_system;
long EBX;
long EDX;
long ECX;
long EAX;
short flags;
short ES,DS,FS,GS,IP,CS,SP,SS;
} RMI;
#else
char *vesainfo;
#endif
/* Save original video mode */
origvmode = peekb(0x40, 0x49);
if(Configuration & NOVESA){
vesa = 0;
return;
}
#if defined (__386__)
/* allocate conventional mem for transfer buffer */
memset(&s, 0, sizeof(s));
r.w.ax = 0x0100;
r.w.bx = 256 >> 4; /* number of paragraphs needed */
int386(0x31, &r, &r);
seg = r.w.ax;
sel = r.w.dx;
/* simulate real mode interrupt */
memset(&RMI, 0, sizeof(RMI));
RMI.EAX = 0x4F00;
RMI.ES = seg;
RMI.EDI = 0;
r.w.ax = 0x0300;
r.h.bl = 0x10;
r.h.bh = 0;
r.w.cx = 0;
s.ds = 0;
s.es = FP_SEG(&RMI);
r.x.edi = FP_OFF(&RMI);
int386x(0x31, &r, &r, &s);
r.x.ebx = RMI.EAX;
r.w.ax = 0x0101;
r.w.dx = sel;
int386(0x31, &r, &r);
if(r.h.bl == 0x4F)
#else
if((vesainfo = (char *)malloc(256)) == NULL)
fatal("Memory allocation error. %s: %d", __FILE__, __LINE__);
s.es = FP_SEG(vesainfo);
r.x.di = FP_OFF(vesainfo);
r.x.ax = 0x4F00;
int86x(0x10, &r, &r, &s); /* Get VESA info first */
free(vesainfo);
if(r.h.al == 0x4F)
#endif
vesa = 1;
else
vesa = 0;
}
/* Add a line to the scrollback buffer */
void SbkAddline(void)
{
char *p;
/* shift all up a line */
memcpy(scrollbuf, scrollbuf + 2 * columns,
vidpages * 2 * columns * lines - 2 * columns);
/* add line to bottom */
p = MK_FP(scrseg, statusline * 2 * columns);
memcpy(scrollbuf + vidpages * 2 * columns * lines - 2 * columns,
p, 2 * columns);
}
/*
* Set video page
* Scrollback is tricky. We keep the scrollback buffer in memory.
* Page 0 is always the page where things happen. The scrollback
* area is mapped to page 1. So if scrollback happens, screen content
* from memory is copied to page 1 then we switch to page 1.
* Page -1 and 'vidpages' is immediate jump to the happening page.
*/
void SbkSetPage(signed char page)
{
char *p;
short n;
if(page == -1) /* jump to the page where things happen? */
page = vidpages;
if(page == actpage) /* don't bother if we already at the requested page */
return;
if(page == vidpages) /* jump to happening page */
interrupt10(0x0500, 0, 0, 0);
else { /* else scroll back */
n = peekw(0x40, 0x4c);
p = MK_FP(scrseg, n);
memcpy(p, scrollbuf + page * 2 * columns * lines, 2 * columns * lines);
interrupt10(0x0501, 0, 0, 0);
}
actpage = page;
}
/* Scroll back a page */
void SbkBack(void)
{
if(actpage)
SbkSetPage(actpage - 1);
}
/* Scroll forward a page */
void SbkForward(void)
{
if(actpage < vidpages)
SbkSetPage(actpage + 1);
}
/****************************************************************************/
/****************************************************************************/
/* S E T M O D E -- Set video mode */
void SetMode(void)
{
if(vesa && vidmode) /* switch only if VESA is supported and
mode is given at command line */
interrupt10(0x4F02, vidmode, 0, 0);
}
/****************************************************************************/
/****************************************************************************/
/* V I D P A R A M -- Get Video Size & Type parameters */
void VidParam(void)
{
union REGS r;
struct SREGS s;
#if defined (__386__)
char *p;
short sel, seg;
static struct rminfo {
long EDI;
long ESI;
long EBP;
long reserved_by_system;
long EBX;
long EDX;
long ECX;
long EAX;
short flags;
short ES,DS,FS,GS,IP,CS,SP,SS;
} RMI;
#endif
char bptr;
if(vesa){
r = interrupt10(0x4F03, 0, 0, 0);
vidmode = r.w.bx; /* Save the video mode */
} else {
// vidmode = peekb(0x40, 0x49);
r = interrupt10(0x0F00, 0, 0, 0);
vidmode = (unsigned short)r.h.al; /* Save the video mode */
}
columns = peekw(0x40, 0x4A); /* Save the number of columns */
/* First determine if snow is a problem and set segment */
if(vidmode != 7){ /* Assume video adapter is snowy if */
retracemode = 1; /* it is not a MonoChrome */
scrseg = 0xb800;
} else
scrseg = 0xb000;
/* First query Video BIOS to see if */
/* VGA is present, no "snow" problem on VGA */
r = interrupt10(0x1A00, 0, 0, 0);
if(r.h.al == 0x1A){ /* If VGA is detected */
retracemode = 0; /* No snow protection needed */
isvga = 1;
#if defined (__386__)
/* allocate conventional mem for transfer buffer */
memset(&s, 0, sizeof(s));
r.w.ax = 0x0100;
r.w.bx = 4; /* number of paragraphs needed */
int386(0x31, &r, &r);
seg = r.w.ax;
sel = r.w.dx;
/* simulate real mode interrupt */
memset(&RMI, 0, sizeof(RMI));
RMI.EAX = 0x1009; /* Read all palette registers */
RMI.ES = seg;
RMI.EDX = 0;
r.w.ax = 0x0300;
r.h.bl = 0x10;
r.h.bh = 0;
r.w.cx = 0;
s.ds = 0;
s.es = FP_SEG(&RMI);
r.x.edi = FP_OFF(&RMI);
int386x(0x31, &r, &r, &s);
p = MK_FP(seg, 0);
memcpy(paletteregs, p, 17);
r.w.ax = 0x0101;
r.w.dx = sel;
int386(0x31, &r, &r);
#else
r.x.ax = 0x1009; /* Read all palette registers */
s.es = FP_SEG(paletteregs);
r.x.dx = FP_OFF(paletteregs);
int86x(0x10, &r, &r, &s); /* Issue BIOS video interrupt */
#endif
} else { /* Else look for an EGA */
r = interrupt10(0x1200, 0xFF00, 0x000C, 0);
if(r.h.cl < 0xC) { /* If EGA is detected */
bptr = peekb(0x40, 0x87); /* Check BIOS data to see if the */
if((bptr & 0x8) == 0) /* EGA is the active adapter */
retracemode = 0; /* No snow protection required */
}
}
/* Determine the default screen attributes */
r = interrupt10(0x0800, 0, 0, 0); /* Get video attribute at cursor pos */
scbattr = r.h.ah; /* Save this attribute */
if(isvga)
lines = peekb(0x40, 0x84) + 1; /* Check BIOS data to see # of rows on screen */
else
lines = 25; /* Lines = 25, (sorry no 43,50 lines) */
}
/* V I D I N I T -- Initialize the video system */
void VidInit(char *username, char *remotehost)
{
screenbot = lines - statusline;
/* Bottom of screen is 24 if statusline */
screentop = 1; /* Top of screen is line 1 */
att_normal = scbattr;
BrkAtt(scbattr); /* Break the attribute into base,extra */
/* Reverse the foreground and background */
baseattr = (baseattr >> 4 | baseattr << 4);
att_reverse = AddAtt(); /* Put the attributes back together */
/* in order to get reverse attribute */
/* Clear screen to established attribute */
interrupt10(0x0600, scbattr << 8, 0, (lines << 8) | (columns - 1));
if(statusline){
/* Clear the top line setting it to reverse */
interrupt10(0x0600, att_reverse << 8, 0, columns - 1);
vtprintf(0, 0, 1, "%s@%s", username, remotehost);
/* Display the mode line in reverse */
}
if((scrollbuf = (char *)malloc(SCROLLBUFSIZE)) == NULL)
fatal("Memory allocation error. %s: %d", __FILE__, __LINE__);
memset(scrollbuf, 0, SCROLLBUFSIZE);
vidpages = SCROLLBUFSIZE / (2 * columns * lines);;
actpage = vidpages;
}
/* V I D U N I N I T -- free buffers */
void VidUninit(void)
{
free(scrollbuf);
if(origvmode != vidmode)
interrupt10(origvmode & 0xff, 0, 0, 0);
}
/* S E T V A T T R -- Set the video attribute */
void SetVattr(unsigned char attr)
{
video_state = 0; /* Reset the video state */
BrkAtt(scbattr); /* Break apart the default screen attribute */
switch (attr) { /* See what video attribute is requested */
case BLINK: /* Blinking characters */
extrattr = att_blink;
break;
case REVERSE: /* Reversed video characters */
video_state = 1;
baseattr = (baseattr >> 4 | baseattr << 4);
break;
case UNDERLINED: /* Underlined characters */
if(vidmode == 0x7) /* Monochrome can underline */
extrattr = att_underline;
else { /* others can't use reverse video */
video_state = 1;
baseattr = (baseattr >> 4 | baseattr << 4);
}
break;
case BOLD: /* High intensity, bold, characters */
extrattr = att_intensity;
break;
case NORMAL: /* Normal characters */
default:
extrattr = 0;
break;
}
curattr = AddAtt(); /* Put the video attributes back together */
}
/* A D D V A T T R -- Add an attribute bit to the current video attribute */
void AddVattr(unsigned char attr)
{
BrkAtt(curattr); /* Break apart the current video attribute */
switch (attr) { /* See what attribute wants to be added */
case BLINK: /* Blinking attribute */
extrattr |= att_blink;
break;
case BOLD: /* High intensity, bold, attribute */
extrattr |= att_intensity;
break;
case REVERSE: /* Reversed attribute */
if(video_state == 0) {
video_state = 1;
baseattr = (baseattr >> 4 | baseattr << 4);
}
break;
case UNDERLINED: /* Underlined characters */
if(vidmode == 0x7) /* Monochrom can underline */
extrattr = att_underline;
/* others cant use reversed video */
else if(video_state == 0) {
video_state = 1;
baseattr = (baseattr >> 4 | baseattr << 4);
}
break;
default:
break;
}
curattr = AddAtt(); /* Put the video attributes back together */
}
/* S U B V A T T R -- Remove attribute bit to the current video attribute */
void SubVattr(unsigned char attr)
{
BrkAtt(curattr); /* Break apart the current video attribute */
switch (attr) { /* See what video attribute to remove */
case BLINK: /* Remove the blinking attribute */
extrattr &= ~att_blink;
break;
case BOLD: /* Remove the high intensity, bold */
extrattr &= ~att_intensity;
break;
case REVERSE: /* Remove reversed attribute */
if(video_state == 1) {
video_state = 0;
baseattr = (baseattr >> 4 | baseattr << 4);
}
break;
case UNDERLINED: /* Remove underlined attribute */
if(vidmode == 0x7) /* Monochrome could have underlined */
extrattr &= ~att_underline;
/* others couldn't remove reverse attribute */
else if(video_state == 1) {
video_state = 0;
baseattr = (baseattr >> 4 | baseattr << 4);
}
break;
default:
break;
}
curattr = AddAtt(); /* Put the video attributes back together */
}
/* P O S C U R S -- Position the cursor on the physical screen */
static void PosCurs(void)
{
register int col = cursx;
register int row = cursy;
if(!statusline) row--;/* up a line if no statusline */
if(col > columns) /* Check validity of requested column */
col = columns; /* put cursor on the right bound */
if(row > lines) /* Check validity of requested row */
row = lines; /* put cursor on the bottom */
if(cursorvisible) /* Only position the cursor if its visible */
interrupt10(0x0200, 0, 0, (row << 8) | --col);
}
/* L I N E R I G H T -- Scroll line to right from cursor */
void LineRight(void)
{
unsigned char c[2], attr[2];
int row, ws;
row=cursy;
if(!statusline) row--;
StartScreen(row, cursx - 1); /* Start direct video memory access */
c[0] = *screen; /* Save character at current position */
attr[0] = *(screen + 1); /* Save attribute at current position */
*screen = ' '; /* clear inserted character */
ws = 1;
for (row = cursx; row < columns; row++) {
c[ws] = *(screen + 2); /* Save character at next position */
attr[ws] = *(screen + 3); /* Save attribute at next position */
ws ^= 1; /* Flop save char,attribute array index */
*(screen + 2) = c[ws]; /* Write saved character and attribute */
*(screen + 3) = attr[ws];
screen += 2; /* Increment to next character position */
}
}
/* S E T C U R S -- Set absolute cursor position on the logical screen */
void SetCurs(register int col, register int row)
{
if(col == 0) /* If called with X coordinate = zero */
col = cursx; /* then default to current coordinate */
if(row == 0) /* If called with Y coordinate = zero */
row = cursy; /* then default to current coordinate */
if(originmode) { /* If origin mode is relative */
row += (scrolltop - 1); /* adjust the row */
if(row < scrolltop || row > scrollbot)
return; /* Can not position cursor out of scroll */
/* region in relative cursor mode */
}
/* Can only position the cursor if it lies */
/* within the logical screen limits */
if(col > screenwid)
col = screenwid;
if(row > screenbot)
row = screenbot;
cursx = col; /* Set the X cursor coordinate, column */
cursy = row; /* Set the Y cursor coordinate, row */
PosCurs(); /* Request the physical positioning */
}
/* S E T S C R O L L -- Establish the scrolling boundaries */
void SetScroll(register int top, register int bottom)
{
if(top == 0) /* If the top scroll boundary is 0 */
top = 1; /* interpret this as the top screen row */
if(bottom == 0) /* If the bottom scroll boundary is 0 */
bottom = screenbot; /* interpret this as bottom screen row */
/* Set scrolling region if valid coords */
if(top > 0 && top <= screenbot && bottom >= top
&& bottom <= screenbot) {
scrolltop = top; /* save top boundary */
scrollbot = bottom; /* save bottom boundary */
SetCurs(1, 1); /* this also homes the cursor */
}
}
/* I N D E X D O W N -- Scroll the screen down */
void IndexDown(void)
{
register unsigned attr;
register unsigned top;
register unsigned bottom;
top=scrolltop;
bottom=scrollbot;
if(!statusline){
top--; /* up a line if no statusline */
bottom--;
}
attr = scbattr << 8; /* Get the attribute for new line */
/* Call the BIOS to scroll the region */
interrupt10(0x0701, attr, top << 8,
(bottom << 8) | (columns - 1));
PosCurs(); /* Position the cursor */
}
/* I N D E X U P -- Scroll the screen up */
void IndexUp(void)
{
register unsigned attr;
register unsigned top;
register unsigned bottom;
top=scrolltop;
bottom=scrollbot;
if(!statusline){
top--; /* up a line if no statusline */
bottom--;
}
attr = scbattr << 8; /* Get the attribute for new line */
/* Call the BIOS to scroll the region */
interrupt10(0x0601, attr, top << 8,
(bottom << 8) | (columns - 1));
PosCurs(); /* Position the cursor */
}
/* S C R O L L D O W N -- Move up a row scrolling if necessary */
void ScrollDown(void)
{
if(cursy == scrolltop) /* If on the top of the scrolling region */
IndexDown(); /* scroll the rest of the region down */
else { /* Else */
--cursy; /* just decrement cursor Y position */
PosCurs(); /* and request the reposition */
}
}
/* S C R O L L U P -- Move down a row scrolling if necessary */
void ScrollUp(void)
{
if(cursy == scrollbot) /* If on the bottom of the scrolling region */
IndexUp(); /* scroll the rest of the region down */
else { /* Else */
++cursy; /* just increment the cursor Y position */
PosCurs(); /* and request the reposition */
}
}
/* W R I T E O N E C H A R -- writes on character to video memory */
void WriteOneChar(unsigned char c, register int row, register int col)
{
if(!statusline)
row--; /* up a row if no status line */
if(Configuration & BIOS){
interrupt10(0x0200, 0, 0, (row << 8) | col);
interrupt10((0x09 << 8) | c, curattr, 1, 0);
} else {
StartScreen(row, col);
*screen++ = c; /* write character into screen memory */
*screen = curattr; /* write attribute into screen memory */
}
}
/* C H R W R I T E -- Write a character to a row and column of the screen */
void ChrWrite(unsigned char chr)
{
if(GlobalConfig.brailab){ /* Brailab PC adapter is on */
fputc((int)chr, GlobalConfig.brailab);
switch(chr){
case '.': /* delimiters */
case ',':
case ';':
case ':':
case '?':
case '!':
CharCounter = 0;
fflush(GlobalConfig.brailab);
break;
default: /* non-delimiters */
CharCounter++; /* increment counter */
if(CharCounter >= 160){
fputc((int)':', GlobalConfig.brailab);
CharCounter = 0;
fflush(GlobalConfig.brailab);
}
break;
}
}
if(*GL == ASCII) /* Check character set being used */
; /* if regular ASCII then char is OK */
else if(*GL == SPECIAL) { /* if using the special character */
if(chr > 94 && chr < 128) /* then translate graphics characters */
chr = special_chars[chr - 95];
} else if(*GL == UK) { /* If using the UK character set */
if(chr == '#') /* then watch for the number sign */
chr = ''; /* translating it to British pound */
}
/* NOTE: Inserting a character using this technique is *very* slow */
/* for snowy CGA systems */
if(insertmode) LineRight(); /* If insert mode, scoot rest of line over */
if(cursx > screenwid) { /* If trying to go beyond the screen width */
if(autowrap) { /* when autowrap is on */
ScrollUp(); /* scroll the screen up */
SetCurs(1, 0); /* set cursor to column 1 of next line */
} else
cursx = screenwid; /* else put the cursor on right margin */
}
WriteOneChar(chr, cursy, cursx - 1);
++cursx; /* Increment the cursor X position */
PosCurs(); /* Move the cursor to the new position */
}
/* C H R D E L E T E -- Erase a character at current position, shift
line to left */
void ChrDelete(void)
{
int row;
row = cursy;
if(!statusline) row--;
StartScreen(row, cursx - 1); /* Start direct video memory access */
for (row = cursx; row < columns; row++, screen += 2) {
*(screen) = *(screen + 2);
*(screen + 1) = *(screen + 3);
}
*screen = 0; /* last pos is empty */
}
/* S E T R E L C U R S -- Set relative curs pos on the logical screen */
void SetRelCurs(register int col, register int row)
{
if(col == 0) /* If called with X coordinate = zero */
col = cursx; /* then default to current X coordinate */
else{ /* Else */
col = cursx + col; /* add col value to X cursor position */
if(col < 0) /* correct it if negative */
col = 1;
else if(col > screenwid) /* or too large */
col = screenwid;
}
if(row == 0) /* If called with Y coordinate = zero */
row = cursy; /* then default to current Y coordinate */
else{ /* Else */
row = cursy + row; /* add row value to Y cursor position */
if(row < 0) /* correct it if negative */
row = 1;
else if(row > screenbot) /* or too large */
row = screenbot;
}
if(originmode) { /* If origin mode is relative */
row += (scrolltop - 1); /* adjust the row */
if(row < scrolltop || row > scrollbot)
return; /* Can not position cursor out of scroll */
}
/* region in relative cursor mode */
/* Can only position the cursor if it lies */
/* within the logical screen limits */
if(col > 0 && col <= screenwid && row > 0 && row <= screenbot) {
cursy = row; /* Set the X cursor coordinate, column */
cursx = col; /* Set the Y cursor coordinate, row */
PosCurs(); /* Request the physical positioning */
}
}
/* C L E A R B O X -- Clear a window on the screen with the specified attr */