1 /* MS-DOS specific Lisp utilities. Coded by Manabu Higashida, 1991.
2 Major changes May-July 1993 Morten Welinder (only 10% original code left)
3 Copyright (C) 1991, 1993, 1996, 1997 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 /* The entire file is within this conditional */
33 #include "termhooks.h"
35 #include "blockinput.h"
43 #ifndef __DJGPP_MINOR__
44 # define __tb _go32_info_block.linear_address_of_transfer_buffer;
47 DEFUN ("int86", Fint86
, Sint86
, 2, 2, 0,
48 "Call specific MSDOS interrupt number INTERRUPT with REGISTERS.\n\
49 Return the updated REGISTER vector.\n\
51 INTERRUPT should be an integer in the range 0 to 255.\n\
52 REGISTERS should be a vector produced by `make-register' and\n\
53 `set-register-value'.")
54 (interrupt
, registers
)
55 Lisp_Object interrupt
, registers
;
59 union REGS inregs
, outregs
;
62 CHECK_NUMBER (interrupt
, 0);
63 no
= (unsigned long) XINT (interrupt
);
64 CHECK_VECTOR (registers
, 1);
65 if (no
< 0 || no
> 0xff || XVECTOR (registers
)-> size
!= 8)
67 for (i
= 0; i
< 8; i
++)
68 CHECK_NUMBER (XVECTOR (registers
)->contents
[i
], 1);
70 inregs
.x
.ax
= (unsigned long) XFASTINT (XVECTOR (registers
)->contents
[0]);
71 inregs
.x
.bx
= (unsigned long) XFASTINT (XVECTOR (registers
)->contents
[1]);
72 inregs
.x
.cx
= (unsigned long) XFASTINT (XVECTOR (registers
)->contents
[2]);
73 inregs
.x
.dx
= (unsigned long) XFASTINT (XVECTOR (registers
)->contents
[3]);
74 inregs
.x
.si
= (unsigned long) XFASTINT (XVECTOR (registers
)->contents
[4]);
75 inregs
.x
.di
= (unsigned long) XFASTINT (XVECTOR (registers
)->contents
[5]);
76 inregs
.x
.cflag
= (unsigned long) XFASTINT (XVECTOR (registers
)->contents
[6]);
77 inregs
.x
.flags
= (unsigned long) XFASTINT (XVECTOR (registers
)->contents
[7]);
79 int86 (no
, &inregs
, &outregs
);
81 XVECTOR (registers
)->contents
[0] = make_number (outregs
.x
.ax
);
82 XVECTOR (registers
)->contents
[1] = make_number (outregs
.x
.bx
);
83 XVECTOR (registers
)->contents
[2] = make_number (outregs
.x
.cx
);
84 XVECTOR (registers
)->contents
[3] = make_number (outregs
.x
.dx
);
85 XVECTOR (registers
)->contents
[4] = make_number (outregs
.x
.si
);
86 XVECTOR (registers
)->contents
[5] = make_number (outregs
.x
.di
);
87 XVECTOR (registers
)->contents
[6] = make_number (outregs
.x
.cflag
);
88 XVECTOR (registers
)->contents
[7] = make_number (outregs
.x
.flags
);
93 DEFUN ("msdos-memget", Fdos_memget
, Sdos_memget
, 2, 2, 0,
94 "Read DOS memory at offset ADDRESS into VECTOR.\n\
95 Return the updated VECTOR.")
97 Lisp_Object address
, vector
;
104 CHECK_NUMBER (address
, 0);
105 offs
= (unsigned long) XINT (address
);
106 CHECK_VECTOR (vector
, 1);
107 len
= XVECTOR (vector
)-> size
;
108 if (len
< 1 || len
> 2048 || address
< 0 || address
> 0xfffff - len
)
111 dosmemget (offs
, len
, buf
);
113 for (i
= 0; i
< len
; i
++)
114 XVECTOR (vector
)->contents
[i
] = make_number (buf
[i
]);
119 DEFUN ("msdos-memput", Fdos_memput
, Sdos_memput
, 2, 2, 0,
120 "Write DOS memory at offset ADDRESS from VECTOR.")
122 Lisp_Object address
, vector
;
129 CHECK_NUMBER (address
, 0);
130 offs
= (unsigned long) XINT (address
);
131 CHECK_VECTOR (vector
, 1);
132 len
= XVECTOR (vector
)-> size
;
133 if (len
< 1 || len
> 2048 || address
< 0 || address
> 0xfffff - len
)
137 for (i
= 0; i
< len
; i
++)
139 CHECK_NUMBER (XVECTOR (vector
)->contents
[i
], 1);
140 buf
[i
] = (unsigned char) XFASTINT (XVECTOR (vector
)->contents
[i
]) & 0xFF;
143 dosmemput (buf
, len
, offs
);
147 DEFUN ("msdos-set-keyboard", Fmsdos_set_keyboard
, Smsdos_set_keyboard
, 1, 2, 0,
148 "Set keyboard layout according to COUNTRY-CODE.\n\
149 If the optional argument ALLKEYS is non-nil, the keyboard is mapped for\n\
150 all keys; otherwise it is only used when the ALT key is pressed.\n\
151 The current keyboard layout is available in dos-keyboard-code.")
152 (country_code
, allkeys
)
153 Lisp_Object country_code
;
155 CHECK_NUMBER (country_code
, 0);
156 if (!dos_set_keyboard (XINT (country_code
), !NILP (allkeys
)))
161 #ifndef HAVE_X_WINDOWS
162 /* Later we might want to control the mouse interface with this function,
163 e.g., with respect to non-80 column screen modes. */
165 DEFUN ("msdos-mouse-p", Fmsdos_mouse_p
, Smsdos_mouse_p
, 0, 0, 0, "\
166 Report whether a mouse is present.")
175 /* Function to translate colour names to integers. See lisp/term/pc-win.el
176 for its definition. */
178 Lisp_Object Qmsdos_color_translate
;
182 DEFUN ("msdos-mouse-init", Fmsdos_mouse_init
, Smsdos_mouse_init
, 0, 0, "",
183 "Initialize and enable mouse if available.")
195 DEFUN ("msdos-mouse-enable", Fmsdos_mouse_enable
, Smsdos_mouse_enable
, 0, 0, "",
196 "Enable mouse if available.")
204 return have_mouse
? Qt
: Qnil
;
207 DEFUN ("msdos-mouse-disable", Fmsdos_mouse_disable
, Smsdos_mouse_disable
, 0, 0, "",
208 "Disable mouse if available.")
212 if (have_mouse
) have_mouse
= -1;
216 DEFUN ("insert-startup-screen", Finsert_startup_screen
, Sinsert_startup_screen
, 0, 0, "", "\
217 Insert copy of screen contents prior to starting emacs.\n\
218 Return nil if startup screen is not available.")
225 if (!dos_get_saved_screen (&s
, &rows
, &cols
))
228 for (i
= 0; i
< rows
; i
++)
230 for (j
= 0; j
< cols
; j
++)
242 int dos_country_code
;
244 int dos_timezone_offset
;
245 int dos_decimal_point
;
246 int dos_keyboard_layout
;
247 unsigned char dos_country_info
[DOS_COUNTRY_INFO
];
248 static unsigned char usa_country_info
[DOS_COUNTRY_INFO
] = {
249 0, 0, /* date format */
250 '$', 0, 0, 0, 0, /* currency string */
251 ',', 0, /* thousands separator */
252 '.', 0, /* decimal separator */
253 '/', 0, /* date separator */
254 ':', 0, /* time separator */
255 0, /* currency format */
256 2, /* digits after decimal in currency */
258 0, 0, 0, 0, /* address of case map routine, GPF if used */
259 ' ', 0, /* data-list separator (?) */
260 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* reserved */
267 Lisp_Object Vdos_version
;
268 Lisp_Object Vdos_display_scancodes
;
270 #ifndef HAVE_X_WINDOWS
271 static unsigned dos_windows_version
;
272 Lisp_Object Vdos_windows_version
;
274 char parent_vm_title
[50]; /* Ralf Brown says 30 is enough */
275 int w95_set_virtual_machine_title (const char *);
278 restore_parent_vm_title (void)
280 if (NILP (Vdos_windows_version
))
282 if ((dos_windows_version
& 0xff) >= 4 && parent_vm_title
[0])
283 w95_set_virtual_machine_title (parent_vm_title
);
286 #endif /* !HAVE_X_WINDOWS */
292 _go32_dpmi_registers dpmiregs
;
293 unsigned long xbuf
= _go32_info_block
.linear_address_of_transfer_buffer
;
295 #ifndef SYSTEM_MALLOC
296 get_lim_data (); /* why the hell isn't this called elsewhere? */
300 intdos (®s
, ®s
);
301 Vdos_version
= Fcons (make_number (regs
.h
.al
), make_number (regs
.h
.ah
));
303 /* Obtain the country code via DPMI, use DJGPP transfer buffer. */
304 dpmiregs
.x
.ax
= 0x3800;
305 dpmiregs
.x
.ds
= xbuf
>> 4;
307 dpmiregs
.x
.ss
= dpmiregs
.x
.sp
= dpmiregs
.x
.flags
= 0;
308 _go32_dpmi_simulate_int (0x21, &dpmiregs
);
309 if (dpmiregs
.x
.flags
& 1)
311 dos_country_code
= 1; /* assume USA if 213800 failed */
312 memcpy (dos_country_info
, usa_country_info
, DOS_COUNTRY_INFO
);
316 dos_country_code
= dpmiregs
.x
.bx
;
317 dosmemget (xbuf
, DOS_COUNTRY_INFO
, dos_country_info
);
320 dos_set_keyboard (dos_country_code
, 0);
323 intdos (®s
, ®s
);
325 /* Estimate code page from country code */
326 switch (dos_country_code
)
328 case 45: /* Denmark */
329 case 47: /* Norway */
337 dos_codepage
= regs
.x
.bx
& 0xffff;
339 #ifndef HAVE_X_WINDOWS
340 parent_vm_title
[0] = '\0';
342 /* If we are running from DOS box on MS-Windows, get Windows version. */
343 dpmiregs
.x
.ax
= 0x1600; /* enhanced mode installation check */
344 dpmiregs
.x
.ss
= dpmiregs
.x
.sp
= dpmiregs
.x
.flags
= 0;
345 _go32_dpmi_simulate_int (0x2f, &dpmiregs
);
346 /* We only support Windows-specific features when we run on Windows 9X
347 or on Windows 3.X/enhanced mode.
349 Int 2Fh/AX=1600h returns:
351 AL = 00: no Windows at all;
352 AL = 01: Windows/386 2.x;
353 AL = 80h: Windows 3.x in mode other than enhanced;
354 AL = FFh: Windows/386 2.x
356 We also check AH > 0 (Windows 3.1 or later), in case AL tricks us. */
357 if (dpmiregs
.h
.al
> 2 && dpmiregs
.h
.al
!= 0x80 && dpmiregs
.h
.al
!= 0xff
358 && (dpmiregs
.h
.al
> 3 || dpmiregs
.h
.ah
> 0))
360 dos_windows_version
= dpmiregs
.x
.ax
;
361 Vdos_windows_version
=
362 Fcons (make_number (dpmiregs
.h
.al
), make_number (dpmiregs
.h
.ah
));
364 /* Save the current title of this virtual machine, so we can restore
365 it before exiting. Otherwise, Windows 95 will continue to use
366 the title we set even after we are history, stupido... */
367 if (dpmiregs
.h
.al
>= 4)
369 dpmiregs
.x
.ax
= 0x168e;
370 dpmiregs
.x
.dx
= 3; /* get VM title */
371 dpmiregs
.x
.cx
= sizeof(parent_vm_title
) - 1;
372 dpmiregs
.x
.es
= __tb
>> 4;
373 dpmiregs
.x
.di
= __tb
& 15;
374 dpmiregs
.x
.sp
= dpmiregs
.x
.ss
= dpmiregs
.x
.flags
= 0;
375 _go32_dpmi_simulate_int (0x2f, &dpmiregs
);
376 if (dpmiregs
.x
.ax
== 1)
377 dosmemget (__tb
, sizeof(parent_vm_title
), parent_vm_title
);
382 dos_windows_version
= 0;
383 Vdos_windows_version
= Qnil
;
385 #endif /* !HAVE_X_WINDOWS */
389 /* Without this, we never see hidden files.
390 Don't OR it with the previous value, so the value recorded at dump
391 time, possibly with `preserve-case' flags set, won't get through. */
392 __opendir_flags
= __OPENDIR_FIND_HIDDEN
;
394 #if __DJGPP_MINOR__ == 0
395 /* Under LFN, preserve the case of files as recorded in the directory
396 (in DJGPP 2.01 and later this is automagically done by the library). */
397 if (!NILP (Fmsdos_long_file_names ()))
398 __opendir_flags
|= __OPENDIR_PRESERVE_CASE
;
399 #endif /* __DJGPP_MINOR__ == 0 */
400 #endif /* __DJGPP__ >= 2 */
403 #ifndef HAVE_X_WINDOWS
404 /* Support for features that are available when we run in a DOS box
407 ms_windows_version (void)
409 return dos_windows_version
;
412 /* Set the title of the current virtual machine, to appear on
413 the caption bar of that machine's window. */
416 w95_set_virtual_machine_title (const char *title_string
)
418 /* Only Windows 9X (version 4 and higher) support this function. */
419 if (!NILP (Vdos_windows_version
)
420 && (dos_windows_version
& 0xff) >= 4)
422 _go32_dpmi_registers regs
;
423 dosmemput (title_string
, strlen (title_string
) + 1, __tb
);
426 regs
.x
.es
= __tb
>> 4;
427 regs
.x
.di
= __tb
& 15;
428 regs
.x
.sp
= regs
.x
.ss
= regs
.x
.flags
= 0;
429 _go32_dpmi_simulate_int (0x2f, ®s
);
430 return regs
.x
.ax
== 1;
435 /* Change the title of frame F to NAME.
436 If NAME is nil, use the frame name as the title.
438 If Emacs is not run from a DOS box on Windows 9X, this only
439 sets the name in the frame struct, but has no other effects. */
442 x_set_title (f
, name
)
446 /* Don't change the title if it's already NAME. */
447 if (EQ (name
, f
->title
))
450 update_mode_lines
= 1;
457 if (FRAME_MSDOS_P (f
))
460 w95_set_virtual_machine_title (XSTRING (name
)->data
);
464 #endif /* !HAVE_X_WINDOWS */
469 #ifndef HAVE_X_WINDOWS
470 restore_parent_vm_title ();
472 /* Make sure the termscript file is committed, in case we are
473 crashing and some vital info was written there. */
477 fsync (fileno (termscript
));
487 defsubr (&Sdos_memget
);
488 defsubr (&Sdos_memput
);
489 defsubr (&Smsdos_mouse_init
);
490 defsubr (&Smsdos_mouse_enable
);
491 defsubr (&Smsdos_set_keyboard
);
492 defsubr (&Sinsert_startup_screen
);
493 defsubr (&Smsdos_mouse_disable
);
494 #ifndef HAVE_X_WINDOWS
495 defsubr (&Smsdos_mouse_p
);
496 Qmsdos_color_translate
= intern ("msdos-color-translate");
497 staticpro (&Qmsdos_color_translate
);
500 DEFVAR_INT ("dos-country-code", &dos_country_code
,
501 "The country code returned by Dos when Emacs was started.\n\
502 Usually this is the international telephone prefix.");
504 DEFVAR_INT ("dos-codepage", &dos_codepage
,
505 "The codepage active when Emacs was started.\n\
506 The following are known:\n\
508 850 Multilingual (Latin I)\n\
509 852 Slavic (Latin II)\n\
513 863 Canada (French)\n\
514 865 Norway/Denmark");
516 DEFVAR_INT ("dos-timezone-offset", &dos_timezone_offset
,
517 "The current timezone offset to UTC in minutes.
518 Implicitly modified when the TZ variable is changed.");
520 DEFVAR_LISP ("dos-version", &Vdos_version
,
521 "The (MAJOR . MINOR) Dos version (subject to modification with setver).");
523 #ifndef HAVE_X_WINDOWS
524 DEFVAR_LISP ("dos-windows-version", &Vdos_windows_version
,
525 "The (MAJOR . MINOR) Windows version for DOS session on MS-Windows.");
528 DEFVAR_LISP ("dos-display-scancodes", &Vdos_display_scancodes
,
529 "*When non-nil, the keyboard scan-codes are displayed at the bottom right\n\
530 corner of the display (typically at the end of the mode line).\n\
531 The output format is: scan code:char code*modifiers.");
532 Vdos_display_scancodes
= Qnil
;
534 DEFVAR_INT ("dos-hyper-key", &dos_hyper_key
,
535 "*If set to 1, use right ALT key as hyper key.\n\
536 If set to 2, use right CTRL key as hyper key.");
539 DEFVAR_INT ("dos-super-key", &dos_super_key
,
540 "*If set to 1, use right ALT key as super key.\n\
541 If set to 2, use right CTRL key as super key.");
544 DEFVAR_INT ("dos-keypad-mode", &dos_keypad_mode
,
545 "*Controls what key code is returned by a key in the numeric keypad.\n\
546 The `numlock ON' action is only taken if no modifier keys are pressed.\n\
547 The value is an integer constructed by adding the following bits together:\n\
549 0x00 Digit key returns digit (if numlock ON)\n\
550 0x01 Digit key returns kp-digit (if numlock ON)\n\
551 0x02 Digit key returns M-digit (if numlock ON)\n\
552 0x03 Digit key returns edit key (if numlock ON)\n\
554 0x00 Grey key returns char (if numlock ON)\n\
555 0x04 Grey key returns kp-key (if numlock ON)\n\
557 0x00 Digit key returns digit (if numlock OFF)\n\
558 0x10 Digit key returns kp-digit (if numlock OFF)\n\
559 0x20 Digit key returns M-digit (if numlock OFF)\n\
560 0x30 Digit key returns edit key (if numlock OFF)\n\
562 0x00 Grey key returns char (if numlock OFF)\n\
563 0x40 Grey key returns kp-key (if numlock OFF)\n\
565 0x200 ALT-0..ALT-9 in top-row produces shifted codes.");
566 dos_keypad_mode
= 0x75;
568 DEFVAR_INT ("dos-keyboard-layout", &dos_keyboard_layout
,
569 "Contains the country code for the current keyboard layout.\n\
570 Use msdos-set-keyboard to select another keyboard layout.");
571 dos_keyboard_layout
= 1; /* US */
573 DEFVAR_INT ("dos-decimal-point", &dos_decimal_point
,
574 "If non-zero, it contains the character to be returned when the\n\
575 decimal point key in the numeric keypad is pressed when Num Lock is on.\n\
576 If zero, the decimal point key returns the country code specific value.");
577 dos_decimal_point
= 0;