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