Update FSF's address in the preamble.
[bpt/emacs.git] / src / dosfns.c
CommitLineData
1b94449f
RS
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 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
edfc0d45 9the Free Software Foundation; either version 2, or (at your option)
1b94449f
RS
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
1b94449f
RS
21
22
48984716 23#include <config.h>
1b94449f
RS
24
25#ifdef MSDOS
26/* The entire file is within this conditional */
27
28#include <stdio.h>
29#include <dos.h>
30#include "lisp.h"
31#include "buffer.h"
32#include "termchar.h"
33#include "termhooks.h"
34#include "frame.h"
35#include "dosfns.h"
36#include "msdos.h"
5f08dc78 37#include <go32.h>
1b94449f 38
24ba360b
RS
39DEFUN ("mode25", Fmode25, Smode25, 0, 0, "", "\
40Changes the number of rows to 25.")
1b94449f
RS
41 ()
42{
43 union REGS regs;
44
24ba360b
RS
45#ifdef HAVE_X_WINDOWS
46 if (!inhibit_window_system)
47 return Qnil;
48#endif
ac3b0279 49 mouse_off ();
1b94449f
RS
50 regs.x.ax = 3;
51 int86 (0x10, &regs, &regs);
52 regs.x.ax = 0x1101;
53 regs.h.bl = 0;
54 int86 (0x10, &regs, &regs);
55 regs.x.ax = 0x1200;
56 regs.h.bl = 32;
57 int86 (0x10, &regs, &regs);
58 regs.x.ax = 3;
59 int86 (0x10, &regs, &regs);
24ba360b 60 Fset_frame_size (Fselected_frame (), ScreenCols (), ScreenRows ());
1b94449f
RS
61 Frecenter (Qnil);
62 Fredraw_display ();
24ba360b
RS
63 if (have_mouse) mouse_init ();
64 return Qnil;
1b94449f
RS
65}
66
24ba360b
RS
67DEFUN ("mode4350", Fmode4350, Smode4350, 0, 0, "", "\
68Changes the number of rows to 43 (EGA) or 50 (VGA).")
1b94449f
RS
69 ()
70{
71 union REGS regs;
72
24ba360b
RS
73#ifdef HAVE_X_WINDOWS
74 if (!inhibit_window_system)
75 return Qnil;
76#endif
ac3b0279 77 mouse_off ();
1b94449f
RS
78 regs.x.ax = 3;
79 int86 (0x10, &regs, &regs);
80 regs.x.ax = 0x1112;
81 regs.h.bl = 0;
82 int86 (0x10, &regs, &regs);
83 regs.x.ax = 0x1200;
84 regs.h.bl = 32;
85 int86 (0x10, &regs, &regs);
86 regs.x.ax = 0x0100;
87 regs.x.cx = 7;
88 int86 (0x10, &regs, &regs);
24ba360b 89 Fset_frame_size (Fselected_frame (), ScreenCols (), ScreenRows ());
1b94449f
RS
90 Frecenter (Qnil);
91 Fredraw_display ();
24ba360b
RS
92 if (have_mouse) mouse_init ();
93 return Qnil;
1b94449f
RS
94}
95
96DEFUN ("int86", Fint86, Sint86, 2, 2, 0,
97 "Call specific MSDOS interrupt number INTERRUPT with REGISTERS.\n\
98Return the updated REGISTER vector.\n\
99\n\
100INTERRUPT should be an integer in the range 0 to 255.\n\
101REGISTERS should be a vector produced by `make-register' and\n\
102`set-register-value'.")
e20104ba
EN
103 (interrupt, registers)
104 Lisp_Object interrupt, registers;
1b94449f
RS
105{
106 register int i;
107 int no;
108 union REGS inregs, outregs;
109 Lisp_Object val;
110
e20104ba
EN
111 CHECK_NUMBER (interrupt, 0);
112 no = (unsigned long) XINT (interrupt);
113 CHECK_VECTOR (registers, 1);
114 if (no < 0 || no > 0xff || XVECTOR (registers)-> size != 8)
1b94449f
RS
115 return Qnil;
116 for (i = 0; i < 8; i++)
e20104ba 117 CHECK_NUMBER (XVECTOR (registers)->contents[i], 1);
1b94449f 118
e20104ba
EN
119 inregs.x.ax = (unsigned long) XFASTINT (XVECTOR (registers)->contents[0]);
120 inregs.x.bx = (unsigned long) XFASTINT (XVECTOR (registers)->contents[1]);
121 inregs.x.cx = (unsigned long) XFASTINT (XVECTOR (registers)->contents[2]);
122 inregs.x.dx = (unsigned long) XFASTINT (XVECTOR (registers)->contents[3]);
123 inregs.x.si = (unsigned long) XFASTINT (XVECTOR (registers)->contents[4]);
124 inregs.x.di = (unsigned long) XFASTINT (XVECTOR (registers)->contents[5]);
125 inregs.x.cflag = (unsigned long) XFASTINT (XVECTOR (registers)->contents[6]);
126 inregs.x.flags = (unsigned long) XFASTINT (XVECTOR (registers)->contents[7]);
1b94449f
RS
127
128 int86 (no, &inregs, &outregs);
129
e20104ba
EN
130 XVECTOR (registers)->contents[0] = make_number (outregs.x.ax);
131 XVECTOR (registers)->contents[1] = make_number (outregs.x.bx);
132 XVECTOR (registers)->contents[2] = make_number (outregs.x.cx);
133 XVECTOR (registers)->contents[3] = make_number (outregs.x.dx);
134 XVECTOR (registers)->contents[4] = make_number (outregs.x.si);
135 XVECTOR (registers)->contents[5] = make_number (outregs.x.di);
136 XVECTOR (registers)->contents[6] = make_number (outregs.x.cflag);
137 XVECTOR (registers)->contents[7] = make_number (outregs.x.flags);
1b94449f 138
e20104ba 139 return registers;
1b94449f
RS
140}
141
5f08dc78
KS
142DEFUN ("msdos-memget", Fdos_memget, Sdos_memget, 2, 2, 0,
143 "Read DOS memory at offset ADDRESS into VECTOR.\n\
144Return the updated VECTOR.")
e20104ba
EN
145 (address, vector)
146 Lisp_Object address, vector;
5f08dc78
KS
147{
148 register int i;
149 int offs, len;
150 char *buf;
151 Lisp_Object val;
152
e20104ba
EN
153 CHECK_NUMBER (address, 0);
154 offs = (unsigned long) XINT (address);
155 CHECK_VECTOR (vector, 1);
156 len = XVECTOR (vector)-> size;
157 if (len < 1 || len > 2048 || address < 0 || address > 0xfffff - len)
5f08dc78
KS
158 return Qnil;
159 buf = alloca (len);
160 dosmemget (offs, len, buf);
161
162 for (i = 0; i < len; i++)
e20104ba 163 XVECTOR (vector)->contents[i] = make_number (buf[i]);
5f08dc78 164
e20104ba 165 return vector;
5f08dc78
KS
166}
167
168DEFUN ("msdos-memput", Fdos_memput, Sdos_memput, 2, 2, 0,
169 "Write DOS memory at offset ADDRESS from VECTOR.")
e20104ba
EN
170 (address, vector)
171 Lisp_Object address, vector;
5f08dc78
KS
172{
173 register int i;
174 int offs, len;
175 char *buf;
176 Lisp_Object val;
177
e20104ba
EN
178 CHECK_NUMBER (address, 0);
179 offs = (unsigned long) XINT (address);
180 CHECK_VECTOR (vector, 1);
181 len = XVECTOR (vector)-> size;
182 if (len < 1 || len > 2048 || address < 0 || address > 0xfffff - len)
5f08dc78
KS
183 return Qnil;
184 buf = alloca (len);
185
186 for (i = 0; i < len; i++)
187 {
e20104ba
EN
188 CHECK_NUMBER (XVECTOR (vector)->contents[i], 1);
189 buf[i] = (unsigned char) XFASTINT (XVECTOR (vector)->contents[i]) & 0xFF;
5f08dc78
KS
190 }
191
192 dosmemput (buf, len, offs);
193 return Qt;
194}
195
196DEFUN ("msdos-set-keyboard", Fmsdos_set_keyboard, Smsdos_set_keyboard, 1, 2, 0,
e20104ba 197 "Set keyboard layout according to COUNTRY-CODE.\n\
5f08dc78
KS
198If the optional argument ALLKEYS is non-nil, the keyboard is mapped for\n\
199all keys; otherwise it is only used when the ALT key is pressed.\n\
200The current keyboard layout is available in dos-keyboard-code.")
201 (country_code, allkeys)
202 Lisp_Object country_code;
203{
204 CHECK_NUMBER (country_code, 0);
205 if (!dos_set_keyboard (XINT (country_code), !NILP (allkeys)))
206 return Qnil;
207 return Qt;
208}
209
87485d6f
MW
210#ifndef HAVE_X_WINDOWS
211/* Later we might want to control the mouse interface with this function,
212 e.g., with respect to non-80 column screen modes. */
213
214DEFUN ("msdos-mouse-p", Fmsdos_mouse_p, Smsdos_mouse_p, 0, 0, 0, "\
215Report whether a mouse is present.")
216 ()
217{
218 if (have_mouse)
219 return Qt;
220 else
221 return Qnil;
222}
223
224DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
225 "Move the mouse pointer to the center of character cell (X,Y) in FRAME.\n\
226WARNING: If you use this under X windows,\n\
227you should call `unfocus-frame' afterwards.")
228 (frame, x, y)
229 Lisp_Object frame, x, y;
230{
231 mouse_moveto (XINT (x), XINT (y));
ac3b0279 232 return Qnil;
87485d6f
MW
233}
234
235/* Function to translate colour names to integers. See lisp/term/pc-win.el
236 for its definition. */
237
238Lisp_Object Qmsdos_color_translate;
239#endif
240
ac3b0279
RS
241
242DEFUN ("msdos-mouse-init", Fmsdos_mouse_init, Smsdos_mouse_init, 0, 0, "",
243 "Initialize and enable mouse if available.")
244 ()
245{
5f08dc78
KS
246 if (have_mouse)
247 {
248 have_mouse = 1;
249 mouse_init ();
250 return Qt;
251 }
ac3b0279
RS
252 return Qnil;
253}
254
255DEFUN ("msdos-mouse-enable", Fmsdos_mouse_enable, Smsdos_mouse_enable, 0, 0, "",
256 "Enable mouse if available.")
257 ()
258{
259 if (have_mouse)
260 {
5f08dc78
KS
261 have_mouse = 1;
262 mouse_on ();
ac3b0279
RS
263 }
264 return have_mouse ? Qt : Qnil;
265}
266
267DEFUN ("msdos-mouse-disable", Fmsdos_mouse_disable, Smsdos_mouse_disable, 0, 0, "",
268 "Disable mouse if available.")
269 ()
270{
271 mouse_off ();
272 if (have_mouse) have_mouse = -1;
273 return Qnil;
274}
275
5f08dc78
KS
276DEFUN ("insert-startup-screen", Finsert_startup_screen, Sinsert_startup_screen, 0, 0, "", "\
277Insert copy of screen contents prior to starting emacs.\n\
278Return nil if startup screen is not available.")
279 ()
280{
281 char *s;
282 int rows, cols;
283 int i, j;
284
285 if (!dos_get_saved_screen (&s, &rows, &cols))
286 return Qnil;
287
288 for (i = 0; i < rows; i++)
289 {
290 for (j = 0; j < cols; j++)
291 {
292 insert_char (*s, 1);
293 s += 2;
294 }
295 insert_char ('\n', 1);
296 }
297
298 return Qt;
299}
ac3b0279 300
87485d6f 301\f
5f08dc78 302/* country info */
1b94449f
RS
303int dos_country_code;
304int dos_codepage;
5f08dc78
KS
305int dos_timezone_offset;
306int dos_decimal_point;
307int dos_keyboard_layout;
308unsigned char dos_country_info[DOS_COUNTRY_INFO];
309
310int dos_hyper_key;
311int dos_super_key;
312int dos_keypad_mode;
1b94449f 313
5f08dc78
KS
314Lisp_Object Vdos_version;
315Lisp_Object Vdos_display_scancodes;
5f08dc78 316
1b94449f
RS
317void
318init_dosfns ()
319{
320 union REGS regs;
321 _go32_dpmi_seginfo info;
322 _go32_dpmi_registers dpmiregs;
323
87485d6f 324#ifndef SYSTEM_MALLOC
1b94449f 325 get_lim_data (); /* why the hell isn't this called elsewhere? */
87485d6f 326#endif
1b94449f
RS
327
328 regs.x.ax = 0x3000;
329 intdos (&regs, &regs);
330 Vdos_version = Fcons (make_number (regs.h.al), make_number (regs.h.ah));
331
332 /* Obtain the country code by calling Dos via Dpmi. Don't rely on GO32. */
5f08dc78 333 info.size = (sizeof(dos_country_info) + 15) / 16;
1b94449f
RS
334 if (_go32_dpmi_allocate_dos_memory (&info))
335 dos_country_code = 1;
336 else
337 {
338 dpmiregs.x.ax = 0x3800;
339 dpmiregs.x.ds = info.rm_segment;
340 dpmiregs.x.dx = 0;
341 dpmiregs.x.ss = dpmiregs.x.sp = 0;
342 _go32_dpmi_simulate_int (0x21, &dpmiregs);
343 dos_country_code = dpmiregs.x.bx;
5f08dc78 344 dosmemget (info.rm_segment * 16, DOS_COUNTRY_INFO, dos_country_info);
1b94449f
RS
345 _go32_dpmi_free_dos_memory (&info);
346 }
5f08dc78 347 dos_set_keyboard (dos_country_code, 0);
1b94449f
RS
348
349 regs.x.ax = 0x6601;
350 intdos (&regs, &regs);
351 if (regs.x.cflag)
352 /* Estimate code page from country code */
353 switch (dos_country_code)
354 {
355 case 45: /* Denmark */
356 case 47: /* Norway */
357 dos_codepage = 865;
358 break;
359 default:
360 /* US */
361 dos_codepage = 437;
362 }
363 else
364 dos_codepage = regs.x.bx & 0xffff;
365}
366\f
367/*
368 * Define everything
369 */
370syms_of_dosfns ()
371{
372 defsubr (&Smode25);
373 defsubr (&Smode4350);
374 defsubr (&Sint86);
5f08dc78
KS
375 defsubr (&Sdos_memget);
376 defsubr (&Sdos_memput);
ac3b0279
RS
377 defsubr (&Smsdos_mouse_init);
378 defsubr (&Smsdos_mouse_enable);
5f08dc78
KS
379 defsubr (&Smsdos_set_keyboard);
380 defsubr (&Sinsert_startup_screen);
ac3b0279 381 defsubr (&Smsdos_mouse_disable);
87485d6f
MW
382#ifndef HAVE_X_WINDOWS
383 defsubr (&Smsdos_mouse_p);
384 defsubr (&Sset_mouse_position);
385
386 Qmsdos_color_translate = intern ("msdos-color-translate");
387 staticpro (&Qmsdos_color_translate);
388#endif
1b94449f
RS
389
390 DEFVAR_INT ("dos-country-code", &dos_country_code,
391 "The country code returned by Dos when Emacs was started.\n\
392Usually this is the international telephone prefix.");
393
394 DEFVAR_INT ("dos-codepage", &dos_codepage,
5f08dc78 395 "The codepage active when Emacs was started.\n\
24ba360b
RS
396The following are known:\n\
397 437 United States\n\
398 850 Multilingual (Latin I)\n\
399 852 Slavic (Latin II)\n\
400 857 Turkish\n\
401 860 Portugal\n\
402 861 Iceland\n\
403 863 Canada (French)\n\
1b94449f
RS
404 865 Norway/Denmark");
405
5f08dc78
KS
406 DEFVAR_INT ("dos-timezone-offset", &dos_timezone_offset,
407 "The current timezone offset to UTC in minutes.
408Implicitly modified when the TZ variable is changed.");
409
1b94449f
RS
410 DEFVAR_LISP ("dos-version", &Vdos_version,
411 "The (MAJOR . MINOR) Dos version (subject to modification with setver).");
5f08dc78
KS
412
413 DEFVAR_LISP ("dos-display-scancodes", &Vdos_display_scancodes,
414 "*When non-nil, the keyboard scan-codes are displayed at the bottom right\n\
415corner of the display (typically at the end of the mode line).\n\
416The output format is: scan code:char code*modifiers.");
417 Vdos_display_scancodes = Qnil;
418
5f08dc78
KS
419 DEFVAR_INT ("dos-hyper-key", &dos_hyper_key,
420 "*If set to 1, use right ALT key as hyper key.\n\
421If set to 2, use right CTRL key as hyper key.");
422 dos_hyper_key = 0;
423
424 DEFVAR_INT ("dos-super-key", &dos_super_key,
425 "*If set to 1, use right ALT key as super key.\n\
426If set to 2, use right CTRL key as super key.");
427 dos_super_key = 0;
428
429 DEFVAR_INT ("dos-keypad-mode", &dos_keypad_mode,
430 "*Controls what key code is returned by a key in the numeric keypad.\n\
431The `numlock ON' action is only taken if no modifier keys are pressed.\n\
432The value is an integer constructed by adding the following bits together:\n\
433 \n\
434 0x00 Digit key returns digit (if numlock ON)\n\
435 0x01 Digit key returns kp-digit (if numlock ON)\n\
436 0x02 Digit key returns M-digit (if numlock ON)\n\
437 0x03 Digit key returns edit key (if numlock ON)\n\
438 \n\
439 0x00 Grey key returns char (if numlock ON)\n\
440 0x04 Grey key returns kp-key (if numlock ON)\n\
441 \n\
442 0x00 Digit key returns digit (if numlock OFF)\n\
443 0x10 Digit key returns kp-digit (if numlock OFF)\n\
444 0x20 Digit key returns M-digit (if numlock OFF)\n\
445 0x30 Digit key returns edit key (if numlock OFF)\n\
446 \n\
447 0x00 Grey key returns char (if numlock OFF)\n\
448 0x40 Grey key returns kp-key (if numlock OFF)\n\
449 \n\
450 0x200 ALT-0..ALT-9 in top-row produces shifted codes.");
b3d5621c 451 dos_keypad_mode = 0x75;
5f08dc78
KS
452
453 DEFVAR_INT ("dos-keyboard-layout", &dos_keyboard_layout,
454 "Contains the country code for the current keyboard layout.\n\
455Use msdos-set-keyboard to select another keyboard layout.");
456 dos_keyboard_layout = 1; /* US */
457
458 DEFVAR_INT ("dos-decimal-point", &dos_decimal_point,
459 "If non-zero, it contains the character to be returned when the\n\
460decimal point key in the numeric keypad is pressed when Num Lock is on.\n\
461If zero, the decimal point key returns the country code specific value.");
462 dos_decimal_point = 0;
1b94449f
RS
463}
464#endif /* MSDOS */