-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathos_msdos.c
3081 lines (2764 loc) · 75.2 KB
/
os_msdos.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
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* os_msdos.c
*
* MSDOS system-dependent routines.
* A cheap plastic imitation of the amiga dependent code.
* A lot in this file was made by Juergen Weigert (jw).
*
* DJGPP changes by Gert van Antwerpen
* Faster text screens by John Lange (jlange@zilker.net)
* Windows clipboard functionality added by David Kotchan (dk)
*
* Some functions are also used for Win16 (MS-Windows 3.1).
*/
#include "vim.h"
/* cproto fails on missing include files */
#ifndef PROTO
# include <conio.h>
#endif
/*
* MS-DOS only code, not used for Win16.
*/
#ifndef WIN16
#ifndef PROTO
# include <bios.h>
# ifdef DJGPP
# include <dpmi.h>
# include <signal.h>
# include <sys/movedata.h>
# include <crt0.h>
# ifdef FEAT_CLIPBOARD
# include <sys/segments.h>
# endif
# else
# include <alloc.h>
# endif
#endif
#if defined(DJGPP) || defined(PROTO)
# define _cdecl /* DJGPP doesn't have this */
#endif
static int cbrk_pressed = FALSE; /* set by ctrl-break interrupt */
static int ctrlc_pressed = FALSE; /* set when ctrl-C or ctrl-break detected */
static int delayed_redraw = FALSE; /* set when ctrl-C detected */
static int bioskey_read = _NKEYBRD_READ; /* bioskey() argument: read key */
static int bioskey_ready = _NKEYBRD_READY; /* bioskey() argument: key ready? */
#ifdef FEAT_MOUSE
static int mouse_avail = FALSE; /* mouse present */
static int mouse_active; /* mouse enabled */
static int mouse_hidden; /* mouse not shown */
static int mouse_click = -1; /* mouse status */
static int mouse_last_click = -1; /* previous status at click */
static int mouse_x = -1; /* mouse x coordinate */
static int mouse_y = -1; /* mouse y coordinate */
static long mouse_click_time = 0; /* biostime() of last click */
static int mouse_click_count = 0; /* count for multi-clicks */
static int mouse_click_x = 0; /* x of previous mouse click */
static int mouse_click_y = 0; /* y of previous mouse click */
static linenr_T mouse_topline = 0; /* w_topline at previous mouse click */
#ifdef FEAT_DIFF
static int mouse_topfill = 0; /* w_topfill at previous mouse click */
#endif
static int mouse_x_div = 8; /* column = x coord / mouse_x_div */
static int mouse_y_div = 8; /* line = y coord / mouse_y_div */
#endif
#define BIOSTICK 55 /* biostime() increases one tick about
every 55 msec */
static int orig_attr = 0x0700; /* video attributes when starting */
static int S_iLeft = 0; /* Scroll window; these are 1 offset */
static int S_iTop = 0;
static int S_iRight = 0;
static int S_iBottom = 0;
/*
* Need to remember the values, because we set horizontal and vertical
* edges separately.
*/
static void
mywindow(int iLeft, int iTop, int iRight, int iBottom)
{
S_iLeft = iLeft;
S_iTop = iTop;
S_iRight = iRight;
S_iBottom = iBottom;
window(iLeft, iTop, iRight, iBottom);
}
#ifdef DJGPP
/*
* For DJGPP, use our own functions for fast text screens. JML 1/18/98
*/
unsigned long S_ulScreenBase = 0xb8000;
unsigned short S_uiAttribute = 0;
int S_iCurrentRow = 0; /* These are 0 offset */
int S_iCurrentColumn = 0;
short S_selVideo; /* Selector for DJGPP direct video transfers */
/*
* Use burst writes to improve mch_write speed - VJN 01/10/99
*/
unsigned short S_linebuffer[8000]; /* <VN> enough for 160x50 */
unsigned short S_blankbuffer[256]; /* <VN> max length of console line */
unsigned short *S_linebufferpos = S_linebuffer;
int S_iBufferRow;
int S_iBufferColumn;
static void
myflush(void)
{
if (S_linebufferpos != S_linebuffer)
{
_dosmemputw(S_linebuffer, (S_linebufferpos - S_linebuffer),
S_ulScreenBase
+ S_iBufferRow * (Columns << 1) + (S_iBufferColumn << 1));
S_linebufferpos = S_linebuffer;
}
}
static void
mygotoxy(int x, int y)
{
S_iCurrentRow = y - 1;
S_iCurrentColumn = x - 1;
}
/*
* Set the system cursor to our cursor position.
*/
static void
set_sys_cursor(void)
{
if (term_console && full_screen)
{
myflush();
gotoxy(S_iCurrentColumn + 1, S_iCurrentRow + 1);
}
}
static void
setblankbuffer(unsigned short uiValue)
{
int i;
static unsigned short olduiValue = 0;
if (olduiValue != uiValue)
{
/* Load blank line buffer with spaces */
for (i = 0; i < Columns; ++i)
S_blankbuffer[i] = uiValue;
olduiValue = uiValue;
}
}
static void
myclreol(void)
{
/* Clear to end of line */
setblankbuffer(S_uiAttribute | ' ');
_dosmemputw(S_blankbuffer, S_iRight - S_iCurrentColumn, S_ulScreenBase
+ (S_iCurrentRow) * (Columns << 1)
+ (S_iCurrentColumn << 1));
}
static void
myclrscr(void)
{
/* Clear whole screen */
short iColumn;
int endpoint = (Rows * Columns) << 1;
setblankbuffer(S_uiAttribute | ' ');
for (iColumn = 0; iColumn < endpoint; iColumn += (Columns << 1))
_dosmemputw(S_blankbuffer, Columns, S_ulScreenBase + iColumn);
}
static void
mydelline(void)
{
short iRow, iColumn;
iColumn = (S_iLeft - 1) << 1;
/* Copy the lines underneath */
for (iRow = S_iCurrentRow; iRow < S_iBottom - 1; iRow++)
movedata(S_selVideo, (((iRow + 1) * Columns) << 1) + iColumn,
S_selVideo, ((iRow * Columns) << 1) + iColumn,
(S_iRight - S_iLeft + 1) << 1);
/* Clear the new row */
setblankbuffer(S_uiAttribute | ' ');
_dosmemputw(S_blankbuffer, (S_iRight - S_iLeft) + 1, S_ulScreenBase
+ (S_iBottom - 1) * (Columns << 1) + iColumn);
}
static void
myinsline(void)
{
short iRow, iColumn;
iColumn = (S_iLeft - 1) << 1;
/* Copy the lines underneath */
for (iRow = S_iBottom - 1; iRow >= S_iTop; iRow--)
movedata(S_selVideo, (((iRow - 1) * Columns) << 1) + iColumn,
S_selVideo, ((iRow * Columns) << 1) + iColumn,
(S_iRight - S_iLeft + 1) << 1);
/* Clear the new row */
setblankbuffer(S_uiAttribute | ' ');
_dosmemputw(S_blankbuffer, (S_iRight - S_iLeft) + 1, S_ulScreenBase
+ (S_iTop - 1) * (Columns << 1) + iColumn);
}
/*
* Scroll the screen one line up, clear the last line.
*/
static void
myscroll(void)
{
short iRow, iColumn;
iColumn = (S_iLeft - 1) << 1;
/* Copy the screen */
for (iRow = S_iTop; iRow < S_iBottom; iRow++)
movedata(S_selVideo, ((iRow * Columns) << 1) + iColumn,
S_selVideo, (((iRow - 1) * Columns) << 1) + iColumn,
(S_iRight - S_iLeft + 1) << 1);
/* Clear the bottom row */
setblankbuffer(S_uiAttribute | ' ');
_dosmemputw(S_blankbuffer, (S_iRight - S_iLeft) + 1, S_ulScreenBase
+ (S_iBottom - 1) * (Columns << 1) + iColumn);
}
static int
myputch(int iChar)
{
unsigned short uiValue;
if (iChar == '\n')
{
myflush();
if (S_iCurrentRow >= S_iBottom - S_iTop)
myscroll();
else
{
S_iCurrentColumn = S_iLeft - 1;
S_iCurrentRow++;
}
}
else if (iChar == '\r')
{
myflush();
S_iCurrentColumn = S_iLeft - 1;
}
else if (iChar == '\b')
{
myflush();
if (S_iCurrentColumn >= S_iLeft)
S_iCurrentColumn--;
}
else if (iChar == 7)
{
sound(440); /* short beep */
delay(200);
nosound();
}
else
{
uiValue = S_uiAttribute | (unsigned char)iChar;
/*
* Normal char - are we starting to buffer?
*/
if (S_linebufferpos == S_linebuffer)
{
S_iBufferColumn = S_iCurrentColumn;
S_iBufferRow = S_iCurrentRow;
}
*S_linebufferpos++ = uiValue;
S_iCurrentColumn++;
if (S_iCurrentColumn >= S_iRight && S_iCurrentRow >= S_iBottom - S_iTop)
{
myflush();
myscroll();
S_iCurrentColumn = S_iLeft - 1;
S_iCurrentRow++;
}
}
return 0;
}
static void
mytextinit(struct text_info *pTextinfo)
{
S_selVideo = __dpmi_segment_to_descriptor(S_ulScreenBase >> 4);
S_uiAttribute = pTextinfo->normattr << 8;
}
static void
get_screenbase(void)
{
static union REGS regs;
/* old Hercules grafic card has different base address (Macewicz) */
regs.h.ah = 0x0f;
(void)int86(0x10, ®s, ®s); /* int 10 0f */
if (regs.h.al == 0x07) /* video mode 7 -- hercules mono */
S_ulScreenBase = 0xb0000;
else
S_ulScreenBase = 0xb8000;
}
static void
mytextattr(int iAttribute)
{
S_uiAttribute = (unsigned short)iAttribute << 8;
}
static void
mynormvideo(void)
{
mytextattr(orig_attr);
}
static void
mytextcolor(int iTextColor)
{
S_uiAttribute = (unsigned short)((S_uiAttribute & 0xf000)
| (unsigned short)iTextColor << 8);
}
static void
mytextbackground(int iBkgColor)
{
S_uiAttribute = (unsigned short)((S_uiAttribute & 0x0f00)
| (unsigned short)(iBkgColor << 12));
}
/*
* Getdigits: Get a number from a string and skip over it.
* Note: the argument is a pointer to a char_u pointer!
*/
static long
mygetdigits(pp)
char_u **pp;
{
char_u *p;
long retval = 0;
p = *pp;
if (*p == '-') /* skip negative sign */
++p;
while (VIM_ISDIGIT(*p))
{
retval = (retval * 10) + (*p - '0');
++p;
}
if (**pp == '-') /* process negative sign */
retval = -retval;
*pp = p;
return retval;
}
#else
# define mygotoxy gotoxy
# define myputch putch
# define myscroll scroll
# define mynormvideo normvideo
# define mytextattr textattr
# define mytextcolor textcolor
# define mytextbackground textbackground
# define mygetdigits getdigits
# define myclreol clreol
# define myclrscr clrscr
# define myinsline insline
# define mydelline delline
#endif
static const struct
{
char_u scancode;
char_u metakey;
} altkey_table[] =
{
{0x1e, 0xe1}, /* a */
{0x30, 0xe2}, /* b */
{0x2e, 0xe3}, /* c */
{0x20, 0xe4}, /* d */
{0x12, 0xe5}, /* e */
{0x21, 0xe6}, /* f */
{0x22, 0xe7}, /* g */
{0x23, 0xe8}, /* h */
{0x17, 0xe9}, /* i */
{0x24, 0xea}, /* j */
{0x25, 0xeb}, /* k */
{0x26, 0xec}, /* l */
{0x32, 0xed}, /* m */
{0x31, 0xee}, /* n */
{0x18, 0xef}, /* o */
{0x19, 0xf0}, /* p */
{0x10, 0xf1}, /* q */
{0x13, 0xf2}, /* r */
{0x1f, 0xf3}, /* s */
{0x14, 0xf4}, /* t */
{0x16, 0xf5}, /* u */
{0x2f, 0xf6}, /* v */
{0x11, 0xf7}, /* w */
{0x2d, 0xf8}, /* x */
{0x15, 0xf9}, /* y */
{0x2c, 0xfa}, /* z */
{0x78, 0xb1}, /* 1 */
{0x79, 0xb2}, /* 2 */
{0x7a, 0xb3}, /* 3 */
{0x7b, 0xb4}, /* 4 */
{0x7c, 0xb5}, /* 5 */
{0x7d, 0xb6}, /* 6 */
{0x7e, 0xb7}, /* 7 */
{0x7f, 0xb8}, /* 8 */
{0x80, 0xb9}, /* 9 */
{0x81, 0xb0}, /* 0 */
};
/*
* Translate extended keycodes into meta-chars where applicable
*/
static int
translate_altkeys(int rawkey)
{
int i, c;
if ((rawkey & 0xff) == 0)
{
c = (rawkey >> 8);
for (i = sizeof(altkey_table) / sizeof(altkey_table[0]); --i >= 0; )
{
if (c == altkey_table[i].scancode)
return (int)altkey_table[i].metakey;
}
}
return rawkey;
}
/*
* Set normal fg/bg color, based on T_ME. Called when t_me has been set.
*/
void
mch_set_normal_colors()
{
char_u *p;
int n;
cterm_normal_fg_color = (orig_attr & 0xf) + 1;
cterm_normal_bg_color = ((orig_attr >> 4) & 0xf) + 1;
if (T_ME[0] == ESC && T_ME[1] == '|')
{
p = T_ME + 2;
n = getdigits(&p);
if (*p == 'm' && n > 0)
{
cterm_normal_fg_color = (n & 0xf) + 1;
cterm_normal_bg_color = ((n >> 4) & 0xf) + 1;
}
}
}
#if defined(MCH_CURSOR_SHAPE) || defined(PROTO)
/*
* Save/restore the shape of the cursor.
* call with FALSE to save, TRUE to restore
*/
static void
mch_restore_cursor_shape(int restore)
{
static union REGS regs;
static int saved = FALSE;
if (restore)
{
if (saved)
regs.h.ah = 0x01; /* Set Cursor */
else
return;
}
else
{
regs.h.ah = 0x03; /* Get Cursor */
regs.h.bh = 0x00; /* Page */
saved = TRUE;
}
(void)int86(0x10, ®s, ®s);
}
/*
* Set the shape of the cursor.
* 'thickness' can be from 0 (thin) to 7 (block)
*/
static void
mch_set_cursor_shape(int thickness)
{
union REGS regs;
regs.h.ch = 7 - thickness; /* Starting Line */
regs.h.cl = 7; /* Ending Line */
regs.h.ah = 0x01; /* Set Cursor */
(void)int86(0x10, ®s, ®s);
}
void
mch_update_cursor(void)
{
int idx;
int thickness;
/*
* How the cursor is drawn depends on the current mode.
*/
idx = get_shape_idx(FALSE);
if (shape_table[idx].shape == SHAPE_BLOCK)
thickness = 7;
else
thickness = (7 * shape_table[idx].percentage + 90) / 100;
mch_set_cursor_shape(thickness);
}
#endif
/*
* Return amount of memory currently available in Kbyte.
*/
long_u
mch_avail_mem(int special)
{
#ifdef DJGPP
return _go32_dpmi_remaining_virtual_memory() >> 10;
#else
return coreleft() >> 10;
#endif
}
#ifdef FEAT_MOUSE
/*
* Set area where mouse can be moved to: The whole screen.
* Rows and Columns must be valid when calling!
*/
static void
mouse_area(void)
{
union REGS regs;
if (mouse_avail)
{
regs.x.cx = 0; /* mouse visible between cx and dx */
regs.x.dx = Columns * mouse_x_div - 1;
regs.x.ax = 7;
(void)int86(0x33, ®s, ®s);
regs.x.cx = 0; /* mouse visible between cx and dx */
regs.x.dx = Rows * mouse_y_div - 1;
regs.x.ax = 8;
(void)int86(0x33, ®s, ®s);
}
}
static void
show_mouse(int on)
{
static int was_on = FALSE;
union REGS regs;
if (mouse_avail)
{
if (!mouse_active || mouse_hidden)
on = FALSE;
/*
* Careful: Each switch on must be compensated by exactly one switch
* off
*/
if ((on && !was_on) || (!on && was_on))
{
was_on = on;
regs.x.ax = on ? 1 : 2;
int86(0x33, ®s, ®s); /* show mouse */
if (on)
mouse_area();
}
}
}
#endif
/*
* Version of kbhit() and getch() that use direct console I/O.
* This avoids trouble with CTRL-P and the like, and should work over a telnet
* connection (it works for Xvi).
*/
static int cons_key = -1;
/*
* Try to get one character directly from the console.
* If there is a key, it is stored in cons_key.
* Only call when cons_key is -1!
*/
static void
cons_getkey(void)
{
union REGS regs;
/* call DOS function 6: Direct console I/O */
regs.h.ah = 0x06;
regs.h.dl = 0xff;
(void)intdos(®s, ®s);
if ((regs.x.flags & 0x40) == 0) /* zero flag not set? */
cons_key = (regs.h.al & 0xff);
}
/*
* Return TRUE if a character is available.
*/
static int
cons_kbhit(void)
{
if (cons_key < 0)
cons_getkey();
return (cons_key >= 0);
}
/*
* Return a character from the console.
* Should only be called when vim_kbhit() returns TRUE.
*/
static int
cons_getch(void)
{
int c = -1;
if (cons_key < 0)
cons_getkey();
c = cons_key;
cons_key = -1;
return c;
}
#ifdef DJGPP
/*
* DJGPP provides a kbhit() function that goes to the BIOS instead of DOS.
* This doesn't work for terminals connected to a serial port.
* Redefine kbhit() here to make it work.
*/
static int
vim_kbhit(void)
{
union REGS regs;
regs.h.ah = 0x0b;
(void)intdos(®s, ®s);
return regs.h.al;
}
#ifdef kbhit
# undef kbhit /* might have been defined in conio.h */
#endif
#define kbhit() vim_kbhit()
#endif
/*
* Simulate WaitForChar() by slowly polling with bioskey(1) or kbhit().
*
* If Vim should work over the serial line after a 'ctty com1' we must use
* kbhit() and getch(). (jw)
* Usually kbhit() is not used, because then CTRL-C and CTRL-P
* will be caught by DOS (mool).
*
* return TRUE if a character is available, FALSE otherwise
*/
#define FOREVER 1999999999L
static int
WaitForChar(long msec)
{
long starttime = 0;
if (msec != 0)
starttime = biostime(0, 0L);
for (;;)
{
#ifdef FEAT_MOUSE
long clicktime;
static int old_status = 0;
union REGS regs;
int x, y;
if (mouse_avail && mouse_active && mouse_click < 0)
{
regs.x.ax = 3;
int86(0x33, ®s, ®s); /* check mouse status */
/* only recognize button-down and button-up event */
x = regs.x.cx / mouse_x_div;
y = regs.x.dx / mouse_y_div;
if ((old_status == 0) != (regs.x.bx == 0))
{
if (old_status) /* button up */
mouse_click = MOUSE_RELEASE;
else /* button down */
{
/*
* Translate MSDOS mouse events to Vim mouse events.
* TODO: should handle middle mouse button, by pressing
* left and right at the same time.
*/
if (regs.x.bx & MSDOS_MOUSE_LEFT)
mouse_click = MOUSE_LEFT;
else if (regs.x.bx & MSDOS_MOUSE_RIGHT)
mouse_click = MOUSE_RIGHT;
else if (regs.x.bx & MSDOS_MOUSE_MIDDLE)
mouse_click = MOUSE_MIDDLE;
/*
* Find out if this is a multi-click
*/
clicktime = biostime(0, 0L);
if (mouse_click_x == x && mouse_click_y == y
&& mouse_topline == curwin->w_topline
#ifdef FEAT_DIFF
&& mouse_topfill == curwin->w_topfill
#endif
&& mouse_click_count != 4
&& mouse_click == mouse_last_click
&& clicktime < mouse_click_time
+ p_mouset / BIOSTICK)
++mouse_click_count;
else
mouse_click_count = 1;
mouse_click_time = clicktime;
mouse_last_click = mouse_click;
mouse_click_x = x;
mouse_click_y = y;
mouse_topline = curwin->w_topline;
#ifdef FEAT_DIFF
mouse_topfill = curwin->w_topfill;
#endif
SET_NUM_MOUSE_CLICKS(mouse_click, mouse_click_count);
}
}
else if (old_status && (x != mouse_x || y != mouse_y))
mouse_click = MOUSE_DRAG;
old_status = regs.x.bx;
if (mouse_hidden && mouse_x >= 0 && (mouse_x != x || mouse_y != y))
{
mouse_hidden = FALSE;
show_mouse(TRUE);
}
mouse_x = x;
mouse_y = y;
}
#endif
if ((p_consk ? cons_kbhit()
: p_biosk ? bioskey(bioskey_ready) : kbhit())
|| cbrk_pressed
#ifdef FEAT_MOUSE
|| mouse_click >= 0
#endif
)
return TRUE;
/*
* Use biostime() to wait until our time is done.
* We busy-wait here. Unfortunately, delay() and usleep() have been
* reported to give problems with the original Windows 95. This is
* fixed in service pack 1, but not everybody installed that.
* The DJGPP implementation of usleep() uses a busy-wait loop too.
*/
if (msec == 0 || (msec != FOREVER
&& biostime(0, 0L) > starttime + msec / BIOSTICK))
break;
#ifdef DJGPP
/* Yield the CPU to the next process. */
__dpmi_yield();
#endif
}
return FALSE;
}
/*
* don't do anything for about "msec" msec
*/
void
mch_delay(
long msec,
int ignoreinput)
{
long starttime;
if (ignoreinput)
{
/*
* We busy-wait here. Unfortunately, delay() and usleep() have been
* reported to give problems with the original Windows 95. This is
* fixed in service pack 1, but not everybody installed that.
*/
starttime = biostime(0, 0L);
while (biostime(0, 0L) < starttime + msec / BIOSTICK)
;
}
else
WaitForChar(msec);
}
/*
* mch_write(): write the output buffer to the screen
*/
void
mch_write(
char_u *s,
int len)
{
char_u *p;
int row, col;
if (term_console && full_screen)
while (len--)
{
/* translate ESC | sequences into bios calls */
if (p_wd) /* testing: wait a bit for each char */
WaitForChar(p_wd);
if (s[0] == '\n')
#ifdef DJGPP
{
myflush();
S_iCurrentColumn = S_iLeft - 1;
}
#else
myputch('\r');
#endif
else if (s[0] == ESC && len > 1 && s[1] == '|')
{
switch (s[2])
{
#ifdef DJGPP
case 'B': ScreenVisualBell();
goto got3;
#endif
case 'J':
#ifdef DJGPP
myflush();
#endif
myclrscr();
goto got3;
case 'K':
#ifdef DJGPP
myflush();
#endif
myclreol();
goto got3;
case 'L':
#ifdef DJGPP
myflush();
#endif
myinsline();
goto got3;
case 'M':
#ifdef DJGPP
myflush();
#endif
mydelline();
got3: s += 3;
len -= 2;
continue;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': p = s + 2;
row = mygetdigits(&p); /* no check for length! */
if (p > s + len)
break;
if (*p == ';')
{
++p;
col = mygetdigits(&p); /* no check for length! */
if (p > s + len)
break;
if (*p == 'H' || *p == 'r' || *p == 'V')
{
#ifdef DJGPP
myflush();
#endif
if (*p == 'H') /* set cursor position */
mygotoxy(col, row);
else if (*p == 'V')
mywindow(row, S_iTop, col, S_iBottom);
else /* set scroll region */
mywindow(S_iLeft, row, S_iRight, col);
len -= p - s;
s = p + 1;
continue;
}
}
else if (*p == 'm' || *p == 'f' || *p == 'b')
{
if (*p == 'm') /* set color */
{
if (row == 0)
mynormvideo();/* reset color */
else
mytextattr(row);
}
else if (*p == 'f') /* set foreground color */
mytextcolor(row);
else /* set background color */
mytextbackground(row);
len -= p - s;
s = p + 1;
continue;
}
}
}
myputch(*s++);
}
else
{
write(1, s, (unsigned)len);
}
}
/*
* mch_inchar(): low level input function.
* Get a characters from the keyboard.
* If time == 0 do not wait for characters.
* If time == n wait a short time for characters.
* If time == -1 wait forever for characters.
*
* return the number of characters obtained
*/
int
mch_inchar(
char_u *buf,
int maxlen,
long time,
int tb_change_cnt)
{
int len = 0;
int c;
int tmp_c;
static int nextchar = 0; /* may keep character when maxlen == 1 */
/*
* if we got a ctrl-C when we were busy, there will be a "^C" somewhere
* on the screen, so we need to redisplay it.
*/
if (delayed_redraw)
{
delayed_redraw = FALSE;