Commit | Line | Data |
---|---|---|
9da6e765 | 1 | /* MS-DOS specific C utilities. |
1d28946c | 2 | Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. |
1b94449f RS |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
6 | GNU Emacs is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
edfc0d45 | 8 | the Free Software Foundation; either version 2, or (at your option) |
1b94449f RS |
9 | any later version. |
10 | ||
11 | GNU Emacs is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Emacs; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
9da6e765 | 20 | /* Contributed by Morten Welinder */ |
f32d4091 | 21 | /* New display, keyboard, and mouse control by Kim F. Storm */ |
9da6e765 | 22 | |
1b94449f RS |
23 | /* Note: some of the stuff here was taken from end of sysdep.c in demacs. */ |
24 | ||
48984716 | 25 | #include <config.h> |
1b94449f RS |
26 | |
27 | #ifdef MSDOS | |
28 | #include "lisp.h" | |
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | #include <sys/param.h> | |
32 | #include <sys/time.h> | |
33 | #include <dos.h> | |
34 | #include "dosfns.h" | |
35 | #include "msdos.h" | |
36 | #include "systime.h" | |
37 | #include "termhooks.h" | |
87485d6f MW |
38 | #include "dispextern.h" |
39 | #include "termopts.h" | |
1b94449f | 40 | #include "frame.h" |
87485d6f | 41 | #include "window.h" |
1b94449f RS |
42 | #include <go32.h> |
43 | #include <pc.h> | |
44 | #include <ctype.h> | |
45 | /* #include <process.h> */ | |
46 | /* Damn that local process.h! Instead we can define P_WAIT ourselves. */ | |
47 | #define P_WAIT 1 | |
48 | ||
aee81730 RS |
49 | |
50 | static unsigned long | |
51 | event_timestamp () | |
52 | { | |
53 | struct time t; | |
54 | unsigned long s; | |
f32d4091 | 55 | |
aee81730 RS |
56 | gettime (&t); |
57 | s = t.ti_min; | |
58 | s *= 60; | |
59 | s += t.ti_sec; | |
60 | s *= 1000; | |
61 | s += t.ti_hund * 10; | |
f32d4091 | 62 | |
aee81730 RS |
63 | return s; |
64 | } | |
65 | ||
f32d4091 KS |
66 | \f |
67 | /* ------------------------ Mouse control --------------------------- | |
68 | * | |
69 | * Coordinates are in screen positions and zero based. | |
70 | * Mouse buttons are numbered from left to right and also zero based. | |
71 | */ | |
1b94449f | 72 | |
f32d4091 KS |
73 | int have_mouse; /* 0: no, 1: enabled, -1: disabled */ |
74 | static int mouse_visible; | |
1b94449f | 75 | |
f32d4091 KS |
76 | static int mouse_last_x; |
77 | static int mouse_last_y; | |
1b94449f | 78 | |
f32d4091 KS |
79 | static int mouse_button_translate[NUM_MOUSE_BUTTONS]; |
80 | static int mouse_button_count; | |
1b94449f | 81 | |
f32d4091 KS |
82 | void |
83 | mouse_on () | |
1b94449f | 84 | { |
1b94449f | 85 | union REGS regs; |
1b94449f | 86 | |
f32d4091 | 87 | if (have_mouse > 0 && !mouse_visible) |
1b94449f | 88 | { |
f32d4091 KS |
89 | if (termscript) |
90 | fprintf (termscript, "<M_ON>"); | |
91 | regs.x.ax = 0x0001; | |
92 | int86 (0x33, ®s, ®s); | |
93 | mouse_visible = 1; | |
1b94449f | 94 | } |
1b94449f RS |
95 | } |
96 | ||
f32d4091 KS |
97 | void |
98 | mouse_off () | |
1b94449f | 99 | { |
f32d4091 | 100 | union REGS regs; |
1b94449f | 101 | |
f32d4091 | 102 | if (have_mouse > 0 && mouse_visible) |
1b94449f | 103 | { |
f32d4091 KS |
104 | if (termscript) |
105 | fprintf (termscript, "<M_OFF>"); | |
106 | regs.x.ax = 0x0002; | |
107 | int86 (0x33, ®s, ®s); | |
108 | mouse_visible = 0; | |
1b94449f | 109 | } |
1b94449f RS |
110 | } |
111 | ||
f32d4091 KS |
112 | void |
113 | mouse_moveto (x, y) | |
114 | int x, y; | |
1b94449f | 115 | { |
f32d4091 | 116 | union REGS regs; |
1b94449f | 117 | |
f32d4091 KS |
118 | if (termscript) |
119 | fprintf (termscript, "<M_XY=%dx%d>", x, y); | |
120 | regs.x.ax = 0x0004; | |
121 | mouse_last_x = regs.x.cx = x * 8; | |
122 | mouse_last_y = regs.x.dx = y * 8; | |
123 | int86 (0x33, ®s, ®s); | |
1b94449f RS |
124 | } |
125 | ||
f32d4091 KS |
126 | static int |
127 | mouse_pressed (b, xp, yp) | |
128 | int b, *xp, *yp; | |
1b94449f | 129 | { |
f32d4091 | 130 | union REGS regs; |
1b94449f | 131 | |
f32d4091 KS |
132 | if (b >= mouse_button_count) |
133 | return 0; | |
134 | regs.x.ax = 0x0005; | |
135 | regs.x.bx = mouse_button_translate[b]; | |
136 | int86 (0x33, ®s, ®s); | |
137 | if (regs.x.bx) | |
138 | *xp = regs.x.cx / 8, *yp = regs.x.dx / 8; | |
139 | return (regs.x.bx != 0); | |
1b94449f RS |
140 | } |
141 | ||
f32d4091 KS |
142 | static int |
143 | mouse_released (b, xp, yp) | |
144 | int b, *xp, *yp; | |
1b94449f RS |
145 | { |
146 | union REGS regs; | |
147 | ||
f32d4091 KS |
148 | if (b >= mouse_button_count) |
149 | return 0; | |
150 | regs.x.ax = 0x0006; | |
151 | regs.x.bx = mouse_button_translate[b]; | |
152 | int86 (0x33, ®s, ®s); | |
153 | if (regs.x.bx) | |
154 | *xp = regs.x.cx / 8, *yp = regs.x.dx / 8; | |
155 | return (regs.x.bx != 0); | |
1b94449f RS |
156 | } |
157 | ||
f32d4091 KS |
158 | static void |
159 | mouse_get_xy (int *x, int *y) | |
1b94449f | 160 | { |
f32d4091 | 161 | union REGS regs; |
1b94449f | 162 | |
f32d4091 KS |
163 | regs.x.ax = 0x0003; |
164 | int86 (0x33, ®s, ®s); | |
165 | *x = regs.x.cx / 8; | |
166 | *y = regs.x.dx / 8; | |
1b94449f RS |
167 | } |
168 | ||
f32d4091 KS |
169 | void |
170 | mouse_get_pos (f, insist, bar_window, part, x, y, time) | |
171 | FRAME_PTR *f; | |
172 | int insist; | |
173 | Lisp_Object *bar_window, *x, *y; | |
174 | enum scroll_bar_part *part; | |
175 | unsigned long *time; | |
176 | { | |
177 | int ix, iy; | |
178 | union REGS regs; | |
179 | ||
180 | regs.x.ax = 0x0003; | |
181 | int86 (0x33, ®s, ®s); | |
182 | *f = selected_frame; | |
183 | *bar_window = Qnil; | |
184 | mouse_get_xy (&ix, &iy); | |
185 | selected_frame->mouse_moved = 0; | |
186 | *x = make_number (ix); | |
187 | *y = make_number (iy); | |
188 | *time = event_timestamp (); | |
189 | } | |
1b94449f | 190 | |
f32d4091 KS |
191 | static void |
192 | mouse_check_moved () | |
1b94449f | 193 | { |
aee81730 | 194 | int x, y; |
1b94449f | 195 | |
f32d4091 KS |
196 | mouse_get_xy (&x, &y); |
197 | selected_frame->mouse_moved |= (x != mouse_last_x || y != mouse_last_y); | |
198 | mouse_last_x = x; | |
199 | mouse_last_y = y; | |
200 | } | |
1b94449f | 201 | |
f32d4091 KS |
202 | void |
203 | mouse_init () | |
204 | { | |
205 | union REGS regs; | |
647c32eb | 206 | |
f32d4091 KS |
207 | if (termscript) |
208 | fprintf (termscript, "<M_INIT>"); | |
1b94449f | 209 | |
f32d4091 KS |
210 | regs.x.ax = 0x0021; |
211 | int86 (0x33, ®s, ®s); | |
091d0bdf | 212 | |
f32d4091 KS |
213 | regs.x.ax = 0x0007; |
214 | regs.x.cx = 0; | |
215 | regs.x.dx = 8 * (ScreenCols () - 1); | |
216 | int86 (0x33, ®s, ®s); | |
1b94449f | 217 | |
f32d4091 KS |
218 | regs.x.ax = 0x0008; |
219 | regs.x.cx = 0; | |
220 | regs.x.dx = 8 * (ScreenRows () - 1); | |
221 | int86 (0x33, ®s, ®s); | |
1b94449f | 222 | |
f32d4091 KS |
223 | mouse_moveto (0, 0); |
224 | mouse_visible = 0; | |
225 | } | |
3eb1dbb6 | 226 | \f |
f32d4091 KS |
227 | /* ------------------------- Screen control ---------------------- |
228 | * | |
229 | */ | |
aee81730 | 230 | |
f32d4091 | 231 | static int internal_terminal = 0; |
aee81730 | 232 | |
f32d4091 KS |
233 | #ifndef HAVE_X_WINDOWS |
234 | extern unsigned char ScreenAttrib; | |
235 | static int screen_face; | |
236 | static int highlight; | |
aee81730 | 237 | |
f32d4091 KS |
238 | static int screen_size_X; |
239 | static int screen_size_Y; | |
240 | static int screen_size; | |
1b94449f | 241 | |
f32d4091 KS |
242 | static int current_pos_X; |
243 | static int current_pos_Y; | |
244 | static int new_pos_X; | |
245 | static int new_pos_Y; | |
1b94449f | 246 | |
f32d4091 KS |
247 | static void *startup_screen_buffer; |
248 | static int startup_screen_size_X; | |
249 | static int startup_screen_size_Y; | |
250 | static int startup_pos_X; | |
251 | static int startup_pos_Y; | |
c9adab25 | 252 | static unsigned char startup_screen_attrib; |
1b94449f | 253 | |
f32d4091 | 254 | static int term_setup_done; |
1b94449f | 255 | |
f32d4091 | 256 | /* Similar to the_only_frame. */ |
f6816f88 | 257 | struct x_output the_only_x_display; |
1b94449f | 258 | |
f32d4091 KS |
259 | /* This is never dereferenced. */ |
260 | Display *x_current_display; | |
1b94449f | 261 | |
1b94449f | 262 | |
f32d4091 KS |
263 | #define SCREEN_SET_CURSOR() \ |
264 | if (current_pos_X != new_pos_X || current_pos_Y != new_pos_Y) \ | |
265 | ScreenSetCursor (current_pos_Y = new_pos_Y, current_pos_X = new_pos_X) | |
aee81730 | 266 | |
f32d4091 KS |
267 | static |
268 | dos_direct_output (y, x, buf, len) | |
269 | int y; | |
270 | int x; | |
271 | char *buf; | |
272 | int len; | |
1b94449f | 273 | { |
f32d4091 | 274 | int t = (int) ScreenPrimary + 2 * (x + y * screen_size_X); |
aee81730 | 275 | |
f32d4091 KS |
276 | while (--len >= 0) { |
277 | dosmemput (buf++, 1, t); | |
278 | t += 2; | |
279 | } | |
1b94449f | 280 | } |
aee81730 | 281 | #endif |
1b94449f | 282 | |
1b94449f RS |
283 | /* Flash the screen as a substitute for BEEPs. */ |
284 | ||
f32d4091 | 285 | #if (__DJGPP__ < 2) |
49a09c76 | 286 | static void |
fcea9cd4 | 287 | do_visible_bell (xorattr) |
1b94449f RS |
288 | unsigned char xorattr; |
289 | { | |
49a09c76 | 290 | asm volatile |
ca986694 | 291 | (" movb $1,%%dl |
1b94449f | 292 | visible_bell_0: |
ca986694 | 293 | movl _ScreenPrimary,%%eax |
49a09c76 | 294 | call dosmemsetup |
ca986694 RS |
295 | movl %%eax,%%ebx |
296 | movl %1,%%ecx | |
297 | movb %0,%%al | |
298 | incl %%ebx | |
1b94449f | 299 | visible_bell_1: |
ca986694 RS |
300 | xorb %%al,%%gs:(%%ebx) |
301 | addl $2,%%ebx | |
302 | decl %%ecx | |
49a09c76 | 303 | jne visible_bell_1 |
ca986694 | 304 | decb %%dl |
49a09c76 | 305 | jne visible_bell_3 |
1b94449f | 306 | visible_bell_2: |
ca986694 RS |
307 | movzwl %%ax,%%eax |
308 | movzwl %%ax,%%eax | |
309 | movzwl %%ax,%%eax | |
310 | movzwl %%ax,%%eax | |
311 | decw %%cx | |
49a09c76 RS |
312 | jne visible_bell_2 |
313 | jmp visible_bell_0 | |
ca986694 RS |
314 | visible_bell_3:" |
315 | : /* no output */ | |
f32d4091 | 316 | : "m" (xorattr), "g" (screen_size) |
ca986694 | 317 | : "%eax", "%ebx", /* "%gs",*/ "%ecx", "%edx"); |
1b94449f RS |
318 | } |
319 | ||
f32d4091 KS |
320 | static void |
321 | ScreenVisualBell (void) | |
322 | { | |
323 | /* This creates an xor-mask that will swap the default fore- and | |
324 | background colors. */ | |
325 | do_visible_bell (((the_only_x_display.foreground_pixel | |
326 | ^ the_only_x_display.background_pixel) | |
327 | * 0x11) & 0x7f); | |
328 | } | |
329 | #endif | |
330 | ||
331 | #ifndef HAVE_X_WINDOWS | |
332 | ||
333 | /* | |
334 | * If we write a character in the position where the mouse is, | |
335 | * the mouse cursor may need to be refreshed. | |
336 | */ | |
09e2ac30 RS |
337 | |
338 | static void | |
f32d4091 | 339 | mouse_off_maybe () |
09e2ac30 | 340 | { |
f32d4091 KS |
341 | int x, y; |
342 | ||
343 | if (!mouse_visible) | |
344 | return; | |
345 | ||
346 | mouse_get_xy (&x, &y); | |
347 | if (y != new_pos_Y || x < new_pos_X) | |
348 | return; | |
349 | ||
350 | mouse_off (); | |
351 | } | |
352 | ||
353 | static | |
354 | IT_ring_bell () | |
355 | { | |
356 | if (visible_bell) | |
aee81730 | 357 | { |
f32d4091 KS |
358 | mouse_off (); |
359 | ScreenVisualBell (); | |
aee81730 | 360 | } |
f32d4091 | 361 | else |
3635be47 RS |
362 | { |
363 | union REGS inregs, outregs; | |
364 | inregs.h.ah = 2; | |
365 | inregs.h.dl = 7; | |
366 | intdos (&inregs, &outregs); | |
367 | } | |
09e2ac30 RS |
368 | } |
369 | ||
f32d4091 KS |
370 | static void |
371 | IT_set_face (int face) | |
372 | { | |
373 | struct face *fp; | |
374 | extern struct face *intern_face (/* FRAME_PTR, struct face * */); | |
375 | ||
376 | if (face == 1 || (face == 0 && highlight)) | |
377 | fp = FRAME_MODE_LINE_FACE (foo); | |
378 | else if (face <= 0 || face >= FRAME_N_COMPUTED_FACES (foo)) | |
379 | fp = FRAME_DEFAULT_FACE (foo); | |
380 | else | |
381 | fp = intern_face (selected_frame, FRAME_COMPUTED_FACES (foo)[face]); | |
382 | if (termscript) | |
383 | fprintf (termscript, "<FACE:%d:%d>", FACE_FOREGROUND (fp), FACE_BACKGROUND (fp)); | |
384 | screen_face = face; | |
385 | ScreenAttrib = (FACE_BACKGROUND (fp) << 4) | FACE_FOREGROUND (fp); | |
386 | } | |
387 | ||
388 | static | |
389 | IT_write_glyphs (GLYPH *str, int len) | |
390 | { | |
391 | int newface; | |
392 | int ch, l = len; | |
393 | unsigned char *buf, *bp; | |
87485d6f | 394 | |
f32d4091 | 395 | if (len == 0) return; |
aee81730 | 396 | |
f32d4091 | 397 | buf = bp = alloca (len * 2); |
aee81730 | 398 | |
f32d4091 | 399 | while (--l >= 0) |
aee81730 | 400 | { |
f32d4091 KS |
401 | newface = FAST_GLYPH_FACE (*str); |
402 | if (newface != screen_face) | |
403 | IT_set_face (newface); | |
404 | ch = FAST_GLYPH_CHAR (*str); | |
405 | *bp++ = (unsigned char)ch; | |
406 | *bp++ = ScreenAttrib; | |
407 | ||
408 | if (termscript) | |
409 | fputc (ch, termscript); | |
410 | str++; | |
aee81730 RS |
411 | } |
412 | ||
f32d4091 KS |
413 | mouse_off_maybe (); |
414 | dosmemput (buf, 2 * len, | |
415 | (int)ScreenPrimary + 2 * (new_pos_X + screen_size_X * new_pos_Y)); | |
416 | new_pos_X += len; | |
417 | } | |
aee81730 | 418 | |
f32d4091 KS |
419 | static |
420 | IT_clear_end_of_line (first_unused) | |
421 | { | |
422 | char *spaces, *sp; | |
423 | int i, j; | |
424 | ||
425 | IT_set_face (0); | |
426 | if (termscript) | |
427 | fprintf (termscript, "<CLR:EOL>"); | |
428 | i = (j = screen_size_X - new_pos_X) * 2; | |
429 | spaces = sp = alloca (i); | |
aee81730 | 430 | |
f32d4091 | 431 | while (--j >= 0) |
aee81730 | 432 | { |
f32d4091 KS |
433 | *sp++ = ' '; |
434 | *sp++ = ScreenAttrib; | |
aee81730 RS |
435 | } |
436 | ||
f32d4091 KS |
437 | mouse_off_maybe (); |
438 | dosmemput (spaces, i, | |
439 | (int)ScreenPrimary + 2 * (new_pos_X + screen_size_X * new_pos_Y)); | |
aee81730 RS |
440 | } |
441 | ||
f32d4091 KS |
442 | static |
443 | IT_clear_screen (void) | |
444 | { | |
445 | if (termscript) | |
446 | fprintf (termscript, "<CLR:SCR>"); | |
447 | IT_set_face (0); | |
448 | mouse_off (); | |
449 | ScreenClear (); | |
450 | new_pos_X = new_pos_Y = 0; | |
451 | } | |
452 | ||
453 | static | |
454 | IT_clear_to_end (void) | |
455 | { | |
456 | if (termscript) | |
457 | fprintf (termscript, "<CLR:EOS>"); | |
458 | ||
459 | while (new_pos_Y < screen_size_Y) { | |
460 | new_pos_X = 0; | |
461 | IT_clear_end_of_line (0); | |
462 | new_pos_Y++; | |
463 | } | |
464 | } | |
465 | ||
466 | static | |
467 | IT_cursor_to (int y, int x) | |
468 | { | |
469 | if (termscript) | |
470 | fprintf (termscript, "\n<XY=%dx%d>", x, y); | |
471 | new_pos_X = x; | |
472 | new_pos_Y = y; | |
473 | } | |
474 | ||
475 | static | |
476 | IT_reassert_line_highlight (new, vpos) | |
477 | int new, vpos; | |
478 | { | |
479 | highlight = new; | |
480 | IT_set_face (0); /* To possibly clear the highlighting. */ | |
481 | } | |
482 | ||
483 | static | |
484 | IT_change_line_highlight (new_highlight, vpos, first_unused_hpos) | |
1b94449f | 485 | { |
f32d4091 KS |
486 | highlight = new_highlight; |
487 | IT_set_face (0); /* To possibly clear the highlighting. */ | |
488 | IT_cursor_to (vpos, 0); | |
489 | IT_clear_end_of_line (first_unused_hpos); | |
490 | } | |
491 | ||
492 | static | |
493 | IT_update_begin () | |
494 | { | |
495 | highlight = 0; | |
496 | IT_set_face (0); /* To possibly clear the highlighting. */ | |
497 | screen_face = -1; | |
498 | } | |
499 | ||
500 | static | |
501 | IT_update_end () | |
502 | { | |
503 | } | |
1b94449f | 504 | |
f32d4091 KS |
505 | /* This was more or less copied from xterm.c */ |
506 | static void | |
507 | IT_set_menu_bar_lines (window, n) | |
508 | Lisp_Object window; | |
509 | int n; | |
510 | { | |
511 | struct window *w = XWINDOW (window); | |
512 | ||
9a166e40 | 513 | XSETFASTINT (w->last_modified, 0); |
f32d4091 KS |
514 | XSETFASTINT (w->top, XFASTINT (w->top) + n); |
515 | XSETFASTINT (w->height, XFASTINT (w->height) - n); | |
516 | ||
517 | /* Handle just the top child in a vertical split. */ | |
518 | if (!NILP (w->vchild)) | |
519 | IT_set_menu_bar_lines (w->vchild, n); | |
520 | ||
521 | /* Adjust all children in a horizontal split. */ | |
522 | for (window = w->hchild; !NILP (window); window = w->next) | |
1b94449f | 523 | { |
f32d4091 KS |
524 | w = XWINDOW (window); |
525 | IT_set_menu_bar_lines (window, n); | |
aee81730 | 526 | } |
f32d4091 KS |
527 | } |
528 | ||
529 | /* | |
530 | * IT_set_terminal_modes is called when emacs is started, | |
531 | * resumed, and whenever the screen is redrawn! | |
532 | */ | |
533 | ||
534 | static | |
535 | IT_set_terminal_modes (void) | |
536 | { | |
537 | char *colors; | |
538 | FRAME_PTR f; | |
539 | struct face *fp; | |
aee81730 | 540 | |
aee81730 | 541 | if (termscript) |
f32d4091 KS |
542 | fprintf (termscript, "\n<SET_TERM>"); |
543 | highlight = 0; | |
544 | ||
545 | screen_size_X = ScreenCols (); | |
546 | screen_size_Y = ScreenRows (); | |
547 | screen_size = screen_size_X * screen_size_Y; | |
aee81730 | 548 | |
f32d4091 KS |
549 | new_pos_X = new_pos_Y = 0; |
550 | current_pos_X = current_pos_Y = -1; | |
551 | ||
552 | if (term_setup_done) | |
553 | return; | |
554 | term_setup_done = 1; | |
aee81730 | 555 | |
f32d4091 KS |
556 | startup_screen_size_X = screen_size_X; |
557 | startup_screen_size_Y = screen_size_Y; | |
c9adab25 | 558 | startup_screen_attrib = ScreenAttrib; |
f32d4091 KS |
559 | |
560 | ScreenGetCursor (&startup_pos_Y, &startup_pos_X); | |
561 | ScreenRetrieve (startup_screen_buffer = xmalloc (screen_size * 2)); | |
562 | ||
563 | if (termscript) | |
c9adab25 KH |
564 | fprintf (termscript, "<SCREEN SAVED (dimensions=%dx%d)>\n", |
565 | screen_size_X, screen_size_Y); | |
f32d4091 KS |
566 | } |
567 | ||
568 | /* | |
569 | * IT_reset_terminal_modes is called when emacs is | |
570 | * suspended or killed. | |
571 | */ | |
572 | ||
573 | static | |
574 | IT_reset_terminal_modes (void) | |
575 | { | |
c9adab25 KH |
576 | int display_row_start = (int) ScreenPrimary; |
577 | int saved_row_len = startup_screen_size_X * 2; | |
578 | int update_row_len = ScreenCols () * 2; | |
579 | int current_rows = ScreenRows (); | |
580 | int to_next_row = update_row_len; | |
581 | unsigned char *saved_row = startup_screen_buffer; | |
582 | int cursor_pos_X = ScreenCols () - 1; | |
583 | int cursor_pos_Y = ScreenRows () - 1; | |
584 | ||
f32d4091 | 585 | if (termscript) |
5063b150 | 586 | fprintf (termscript, "\n<RESET_TERM>"); |
f32d4091 KS |
587 | |
588 | highlight = 0; | |
589 | ||
590 | if (!term_setup_done) | |
591 | return; | |
592 | ||
c9adab25 KH |
593 | mouse_off (); |
594 | ||
595 | /* We have a situation here. | |
596 | We cannot just do ScreenUpdate(startup_screen_buffer) because | |
597 | the luser could have changed screen dimensions inside Emacs | |
598 | and failed (or didn't want) to restore them before killing | |
599 | Emacs. ScreenUpdate() uses the *current* screen dimensions and | |
600 | thus will happily use memory outside what was allocated for | |
601 | `startup_screen_buffer'. | |
602 | Thus we only restore as much as the current screen dimensions | |
603 | can hold, and clear the rest (if the saved screen is smaller than | |
604 | the current) with the color attribute saved at startup. The cursor | |
605 | is also restored within the visible dimensions. */ | |
606 | ||
607 | ScreenAttrib = startup_screen_attrib; | |
608 | ScreenClear (); | |
609 | ||
610 | if (update_row_len > saved_row_len) | |
611 | update_row_len = saved_row_len; | |
612 | if (current_rows > startup_screen_size_Y) | |
613 | current_rows = startup_screen_size_Y; | |
f32d4091 KS |
614 | |
615 | if (termscript) | |
c9adab25 KH |
616 | fprintf (termscript, "<SCREEN RESTORED (dimensions=%dx%d)>\n", |
617 | update_row_len / 2, current_rows); | |
618 | ||
619 | while (current_rows--) | |
620 | { | |
621 | dosmemput (saved_row, update_row_len, display_row_start); | |
622 | saved_row += saved_row_len; | |
623 | display_row_start += to_next_row; | |
624 | } | |
625 | if (startup_pos_X < cursor_pos_X) | |
626 | cursor_pos_X = startup_pos_X; | |
627 | if (startup_pos_Y < cursor_pos_Y) | |
628 | cursor_pos_Y = startup_pos_Y; | |
629 | ||
630 | ScreenSetCursor (cursor_pos_Y, cursor_pos_X); | |
631 | xfree (startup_screen_buffer); | |
f32d4091 KS |
632 | |
633 | term_setup_done = 0; | |
634 | } | |
635 | ||
636 | static | |
637 | IT_set_terminal_window (void) | |
638 | { | |
639 | } | |
640 | ||
641 | void | |
642 | IT_set_frame_parameters (frame, alist) | |
643 | FRAME_PTR frame; | |
644 | Lisp_Object alist; | |
645 | { | |
646 | Lisp_Object tail; | |
647 | int redraw; | |
648 | extern unsigned long load_color (); | |
649 | FRAME_PTR f = (FRAME_PTR) &the_only_frame; | |
650 | ||
651 | redraw = 0; | |
652 | for (tail = alist; CONSP (tail); tail = Fcdr (tail)) | |
653 | { | |
654 | Lisp_Object elt, prop, val; | |
655 | ||
656 | elt = Fcar (tail); | |
657 | prop = Fcar (elt); | |
658 | val = Fcdr (elt); | |
659 | CHECK_SYMBOL (prop, 1); | |
660 | ||
661 | if (EQ (prop, intern ("foreground-color"))) | |
662 | { | |
663 | unsigned long new_color = load_color (f, val); | |
664 | if (new_color != ~0) | |
665 | { | |
666 | FRAME_FOREGROUND_PIXEL (f) = new_color; | |
667 | redraw = 1; | |
668 | } | |
669 | } | |
670 | else if (EQ (prop, intern ("background-color"))) | |
671 | { | |
672 | unsigned long new_color = load_color (f, val); | |
673 | if (new_color != ~0) | |
674 | { | |
675 | FRAME_BACKGROUND_PIXEL (f) = new_color & ~8; | |
676 | redraw = 1; | |
677 | } | |
678 | } | |
679 | else if (EQ (prop, intern ("menu-bar-lines"))) | |
680 | { | |
681 | int new; | |
682 | int old = FRAME_MENU_BAR_LINES (the_only_frame); | |
683 | ||
684 | if (INTEGERP (val)) | |
685 | new = XINT (val); | |
686 | else | |
687 | new = 0; | |
688 | FRAME_MENU_BAR_LINES (f) = new; | |
689 | IT_set_menu_bar_lines (the_only_frame.root_window, new - old); | |
690 | } | |
691 | } | |
692 | ||
693 | if (redraw) | |
694 | { | |
695 | recompute_basic_faces (f); | |
696 | Fredraw_frame (Fselected_frame ()); | |
697 | } | |
698 | } | |
699 | ||
700 | #endif /* !HAVE_X_WINDOWS */ | |
701 | ||
702 | ||
703 | /* Do we need the internal terminal? */ | |
704 | void | |
705 | internal_terminal_init () | |
706 | { | |
707 | char *term = getenv ("TERM"); | |
708 | char *colors; | |
709 | ||
710 | #ifdef HAVE_X_WINDOWS | |
711 | if (!inhibit_window_system) | |
712 | return; | |
713 | #endif | |
714 | ||
715 | internal_terminal | |
716 | = (!noninteractive) && term && !strcmp (term, "internal"); | |
717 | ||
718 | if (getenv ("EMACSTEST")) | |
5063b150 | 719 | termscript = fopen (getenv ("EMACSTEST"), "wt"); |
f32d4091 KS |
720 | |
721 | #ifndef HAVE_X_WINDOWS | |
722 | if (!internal_terminal || inhibit_window_system) | |
723 | { | |
724 | the_only_frame.output_method = output_termcap; | |
725 | return; | |
726 | } | |
727 | ||
728 | Vwindow_system = intern ("pc"); | |
729 | Vwindow_system_version = make_number (1); | |
730 | ||
731 | bzero (&the_only_x_display, sizeof the_only_x_display); | |
732 | the_only_x_display.background_pixel = 7; /* White */ | |
733 | the_only_x_display.foreground_pixel = 0; /* Black */ | |
5063b150 | 734 | colors = getenv ("EMACSCOLORS"); |
f32d4091 KS |
735 | if (colors && strlen (colors) >= 2) |
736 | { | |
737 | the_only_x_display.foreground_pixel = colors[0] & 0x07; | |
738 | the_only_x_display.background_pixel = colors[1] & 0x07; | |
739 | } | |
740 | the_only_x_display.line_height = 1; | |
f6816f88 | 741 | the_only_frame.output_data.x = &the_only_x_display; |
f32d4091 | 742 | the_only_frame.output_method = output_msdos_raw; |
64ec6a02 | 743 | the_only_x_display.font = (XFontStruct *)1; /* must *not* be zero */ |
f32d4091 KS |
744 | |
745 | init_frame_faces ((FRAME_PTR) &the_only_frame); | |
746 | ||
747 | ring_bell_hook = IT_ring_bell; | |
748 | write_glyphs_hook = IT_write_glyphs; | |
749 | cursor_to_hook = raw_cursor_to_hook = IT_cursor_to; | |
750 | clear_to_end_hook = IT_clear_to_end; | |
751 | clear_end_of_line_hook = IT_clear_end_of_line; | |
752 | clear_frame_hook = IT_clear_screen; | |
753 | change_line_highlight_hook = IT_change_line_highlight; | |
754 | update_begin_hook = IT_update_begin; | |
755 | update_end_hook = IT_update_end; | |
756 | reassert_line_highlight_hook = IT_reassert_line_highlight; | |
757 | ||
758 | /* These hooks are called by term.c without being checked. */ | |
759 | set_terminal_modes_hook = IT_set_terminal_modes; | |
760 | reset_terminal_modes_hook = IT_reset_terminal_modes; | |
761 | set_terminal_window_hook = IT_set_terminal_window; | |
762 | #endif | |
763 | } | |
764 | ||
765 | dos_get_saved_screen (screen, rows, cols) | |
766 | char **screen; | |
767 | int *rows; | |
768 | int *cols; | |
769 | { | |
770 | #ifndef HAVE_X_WINDOWS | |
771 | *screen = startup_screen_buffer; | |
772 | *cols = startup_screen_size_X; | |
773 | *rows = startup_screen_size_Y; | |
774 | return 1; | |
775 | #else | |
776 | return 0; | |
777 | #endif | |
778 | } | |
5063b150 | 779 | \f |
f32d4091 KS |
780 | /* ----------------------- Keyboard control ---------------------- |
781 | * | |
782 | * Keymaps reflect the following keyboard layout: | |
783 | * | |
784 | * 0 1 2 3 4 5 6 7 8 9 10 11 12 BS | |
785 | * TAB 15 16 17 18 19 20 21 22 23 24 25 26 (41) | |
786 | * CLOK 30 31 32 33 34 35 36 37 38 39 40 (41) RET | |
787 | * SH () 45 46 47 48 49 50 51 52 53 54 SHIFT | |
788 | * SPACE | |
789 | */ | |
790 | ||
791 | static int extended_kbd; /* 101 (102) keyboard present. */ | |
792 | ||
793 | struct dos_keyboard_map | |
794 | { | |
795 | char *unshifted; | |
796 | char *shifted; | |
797 | char *alt_gr; | |
798 | }; | |
799 | ||
800 | ||
801 | static struct dos_keyboard_map us_keyboard = { | |
802 | /* 0 1 2 3 4 5 */ | |
803 | /* 01234567890123456789012345678901234567890 12345678901234 */ | |
804 | "`1234567890-= qwertyuiop[] asdfghjkl;'\\ zxcvbnm,./ ", | |
805 | /* 0123456789012345678901234567890123456789 012345678901234 */ | |
806 | "~!@#$%^&*()_+ QWERTYUIOP{} ASDFGHJKL:\"| ZXCVBNM<>? ", | |
807 | 0 /* no Alt-Gr key */ | |
808 | }; | |
809 | ||
810 | static struct dos_keyboard_map fr_keyboard = { | |
811 | /* 0 1 2 3 4 5 */ | |
812 | /* 012 3456789012345678901234567890123456789012345678901234 */ | |
813 |