First steps towards system programming under MS-DOS 7/The PC keyboard
Chapter 1 Let's get acquainted with keyboard
For all DOS-like operating systems the main input means is keyboard. Each keystroke invokes execution of at least one preloaded (resident) software module. Sometimes this execution doesn't reveal itself at all, but more frequently it brings about an appearance of the corresponding character on the screen. Several keys (the "hot" keys) may be charged with more complex missions. Resident software modules which define key's missions are loaded in memory by either
- BIOS (Basic Input-Output system);
- DOS loader from IO.SYS file (active during loading only);
- the CON device (console) driver from DOS's core;
- command interpreter (usually COMMAND.COM).
This chapter does not describe other "hot" key functions which may be assigned by other TSR (TSR = terminate and stay resident) utilities or file managers: Norton Commander, Volkov Commander, etc. Being loaded later, TSRs intercept some original keyboard functions — as most file managers do — or substitute with partial (not exact) emulation. Command line presented by file managers is NOT the same as original DOS's command line: a large part of original keyboard functions is intercepted and made inactive.
The following text describes functions of the most common "enhanced" keyboard, which usually has from 101 to 108 keys. Evolution of key's functions is shown just as they are activated while loading MS-DOS 7. The assumed final stage of this evolution is that implemented by command interpreter COMMAND.COM.
1.01 Keyboard functions of PC's BIOS.Edit
When switched on, computer starts under control of its BIOS system. BIOS loads the INT 09 handler (8.01-09) and thus becomes able to sense keyboard controller calls sent via the IRQ 1 line. Every keystroke is sensed, but only a few keys and key combinations invoke a certain response. Common BIOS versions assign special mission to the following keys and key combinations :
|Ctrl-Alt-Delete – initiates a "warm" reboot.|
|Delete||–||launches BIOS Setup procedure which enables to set BIOS' parameters.[Note 1][Note 2] This function is deactivated after about 2 seconds, so you have to keep the "Delete" key pressed just when computer starts.|
|Pause/Break (or Ctrl-Break) – causes temporary stop until any other key is pressed, thus giving an opportunity to read screen messages.|
|Shift-PrtScr – sends current screen to printer via LPT1 port. The printer must be ready and must be able to respond properly (this does not work with a USB-connected printer, or those "designed for Windows").|
There is no uniform standard for BIOS' keyboard functions, so they may somewhat differ. For example, the 8th BIOS version from American Megatrends provides supplementary PC's loading menu, invoked with the F8 key. Nevertheless some BIOS' keyboard functions have become de-facto standard, in particular, these of the DELETE key [Note 2] and of the CTRL-ALT-DELETE key combination.
Keyboard functions set by BIOS may be deactivated later, just as any software implemented function. In particular, the Shift-PrtScr keystroke combination is often deactivated by embedded software of the video card. Other BIOS' functions may fail because of INT 09 interception, or because of software crash, affecting data in interrupt table (from 0000:0000h to 0000:0400h) or in BIOS memory area (A.01-1). Therefore the most important reboot function in some PCs is hardware duplicated by a RESET button.
- ^ BIOS Setup program may make active some other keys, that depends on the BIOS version. These keys enable to change some parameter settings, including the one preventing BIOS' logo display. Without BIOS' logo you will be able to see current BIOS’ messages.
- ^ a b Some (largely obsolete) BIOS versions launch BIOS Setup procedure with F1, F2, F10, ESC keys or with F3-F2, Ctrl-Alt-S, Ctrl-Alt-Ins, Ctrl-Alt-Esc key combinations.
- Some models of "enhanced" keyboard, developed in 1990s, have a supplementary TURBO key. TURBO-F11 key combination toggles keyboard lock ON/OFF, and TURBO-F12 key combination toggles beeper sound lock ON/OFF. Most modern keyboards have no TURBO key.
- For power supply control via keyboard many keyboard models are equipped with three special keys: POWER, SLEEP and WAKE UP. These keys are intended to be served by BIOS, but their functions are intercepted, in particular, by Windows XP and by Windows Vista.
1.02 Keyboard functions of the DOS loaderEdit
At some moment during PC's loading the BIOS' logo is replaced by the logo of the operating system. This logo change signifies termination of BIOS's loading mission. Since that moment control is transferred to operating system's loader.
Both Windows-95/98 and MS-DOS 7 operating systems have the same primary loader, contained as a part inside the IO.SYS file. The loader begins its mission with reading parameters stored in MSDOS.SYS file (5.01-01). Then according to these parameters the DOS loader activates for a time some more "hot" keys and key combinations :
|F5||–||turns subsequent loading into Safe Mode with WINDOWS' GUI (graphic user's interface) and default settings, ignoring commands in configuration files (CONFIG.SYS and AUTOEXEC.BAT).|
|SHIFT-F5||–||turns subsequent loading into "command line only" mode with all drivers, but without WINDOWS' GUI. This is in fact loading of MS-DOS 7.|
|F6||–||turns subsequent loading into Safe Mode (just as F5) plus adds network support.|
|F8||–||invokes display of WINDOWS' standard boot menu and stops further process until user makes his choice. In MS-DOS 8 the CTRL key duplicates the function of F8 key.|
|SHIFT-F8||–||turns execution of configuration files into step-by-step mode; this enables to skip some operations according to the user's choice.|
The listed key functions in MSDOS 7 and MSDOS 8 differ from those implemented in previous DOS versions. Activation of the mentioned "hot" keys may be affected by parameters (BOOTDELAY, BOOTKEYS, BOOTMULTI), specified in configuration file MSDOS.SYS (5.01-01). Of course, loading of WINDOWS' GUI can't be performed, when MS-DOS 7 is used as a stand-alone operating system, and the GUI software isn't physically accessible.
For the time of displaying boot menu the DOS loader activates cursor keys (up, down), the ENTER key and numeric keys (0–9) in the common part of keyboard. NUMLOCK key is activated too; when NUMLOCK is set ON, numeric (rightmost) keypad may be used to choose menu items by number. After the choice is made, all menu keys are deactivated. If the chosen menu item doesn't imply anything else, then the DOS loader begins interpretation of commands from CONFIG.SYS configuration file (example in 9.01-01).
During step-by-step confirmation the choice may be made by Y (yes), N (no), ENTER (= yes) and A keys (A = yes for all following lines). Normal (non-step-by-step) execution doesn't produce any effect on the screen, because at that time Window's logo is displayed. However, the logo display may be suppressed by setting the "Logo=0" parameter in the MSDOS.SYS file (5.01-01). Then on the screen you will see rapidly scrolling messages from the drivers being loaded. In order to be able to examine these messages carefully, you may suspend loading process with a PAUSE/BREAK keystroke or with CTRL-S keystroke combination. Then after any other keystroke the loading process will be resumed.
Having interpreted all the lines in CONFIG.SYS configuration file, the DOS loader deactivates all its "hot" keys and transfers control to command interpreter COMMAND.COM.
- In version 7.00 of MS-DOS, the DOS loader activates the F4 key in order to start previous DOS version loading. Since version 7.10, this option has been abolished.
1.03 Keyboard functions during batch file execution.Edit
Control over the PC is given to the main command interpreter when DOS configuration procedure is not finished yet. The first mission of COMMAND.COM is interpretation of commands in lines of the last configuration file AUTOEXEC.BAT (example in 9.01-02). During interpretation COMMAND.COM is quite self-sufficient, but at the same time the user's role is not diminished to zero. If Window's logo display is turned off, then user can monitor current messages. Besides that, command interpreter keeps active some "hot" keys, which enable user to suspend or to stop interpretation of batch command file.
Both suspension and stoppage of execution initiate a complex succession of calls (see 8.01-95 for details), involving resident modules of DOS's core as well as those installed by PC's BIOS. Therefore exact action of some "hot" keys may depend on BIOS version. Nevertheless the activated "hot" keys are the same in all AT-compatible computers.
The Break/Pause key provides a temporary stop, enables to read messages, but gives no opportunity to terminate execution of batch file: any following keystroke resumes execution. The user can terminate batch file execution with "hot" keystroke combinations CTRL-C, CTRL-BREAK and ALT-03 (the latter digits "03" must be typed via the rightmost numeric keypad). Action of these keystroke combinations depends on the way the command interpreter has been launched. When COMMAND.COM starts permanently with
/P parameter (6.04), the mentioned keystroke combinations stop execution and display an offer
"Terminate batch job? Y/N"
thus providing an explicit choice. But if COMMAND.COM starts with
/C parameter (6.04) for execution of a single job (as inside TSR shells), then CTRL-C, CTRL-BREAK and ALT-03 keystroke combinations terminate batch file interpretation at once, giving no chance to resume.
The CTRL-S keystroke combination provides a temporary stop, but (unlike the BREAK key) always enables to have a choice. You may resume execution by pressing any other key, except CTRL-C, CTRL-BREAK, ALT-03 and CTRL-2. Action of CTRL-C, CTRL-BREAK and ALT-03 depends on the way COMMAND.COM has been launched just as it was described above. CTRL-2 acts similarly, but only when execution has been suspended already by CTRL-S. Normal batch interpretation will not be affected by CTRL-2 keystroke combination.
Keyboard functions, breaking interpretation of a batch file, can be disabled by
CTTY NUL command (see 3.07) in a line of the same batch file. But this trick may be justified in special circumstances only (example in 9.03-02).
Having finished interpretation of commands from AUTOEXEC.BAT file, command interpreter COMMAND.COM by default must transfer control to the Windows' GUI loader — the WIN.COM file. But this will not happen if
- the WIN.COM file isn't found (for example, on a bootable diskette);
- the SHIFT-F5 key combination has been pressed at start (1.02);
- in Windows' boot menu the "command line only" option has been chosen;
- in MSDOS.SYS file (5.01-01) the "
BootGUI=0" parameter is specified;
SINGLEparameter is given to the DOS command.[note 1 to 4.08]
In any of the listed cases, MS-DOS 7 is loaded instead of the Windows operating system, command interpreter COMMAND.COM begins to accept commands from keyboard, displays its prompt on the screen, and since that moment works with keyboard in a quite different way.
1.04 Keyboard input of commands and textual lines.Edit
When COMMAND.COM presents its command line, it accepts input via the CON device driver. The latter enables to type characters, digits and special symbols according to keyboard layout table resident in memory. Symbols may be entered either by corresponding keys or by ASCII decimal symbol's numbers. The latter should be typed via numeric keypad while the ALT key is kept pressed. Each next character appends the current command line and increments by 1 current position pointers for the current line and for the internal memory buffer, where the previous line is automatically stored.
The selection of symbols, typed with literal keys, depends on the state of SHIFT and CAPSLOCK keys. Pressing CAPSLOCK toggles keyboard into upper case letters selection and back. Pressing SHIFT turns keyboard into upper case selection for a while until SHIFT key isn't released. Besides that, DOS presents some limited opportunities of editing current command line (1.05).
All mentioned features are equally true for typing textual lines. Transition from command line input to textual line input is initiated by an explicit request to the CON device driver, for example, with command
COPY CON Filename.txt
where FILENAME.TXT is an arbitrary name of a file to store the text.
The COPY command is not a separate utility; it is an internal command of the interpreter COMMAND.COM (3.06). Textual line input also can be implemented by other utilities, which are able to address the CON device driver in the same way.
Differences between textual input and command line input evince in what happens with the typed line when user confirms that typing the line is finished with the ENTER keystroke or with equivalent CTRL-M keystroke combination. Text lines are written into an internal buffer, replace there the previous line, and then a new line is opened for input. The end of each textual line is marked with bytes 0Dh 0Ah, and in this form it is appended to previous lines in memory area, devoted for text storage. The COMMAND.COM interpreter enables to send this text into a specified file or into a selected channel (see 3.06 for details). Return from textual input back to command line input can be performed with keystroke combinations F6-ENTER, CTRL-Z-ENTER or ALT-26-ENTER. In the latter combination the digits must be typed via the rightmost numeric keypad.
When the ENTER keystroke signifies entering of a command line, this line is also written into an internal line buffer, just as textual line, but the following events occur otherwise. In buffer the line is parsed in order to extract the command name and to discriminate whether it is an internal command or a separate utility. While parsing MS-DOS 7 regards upper case letters and lower case letters as identical. Separate utilities are searched for (2.02-02), read from their media and prepared for execution. When execution terminates, control is returned back to command interpreter. The latter displays its prompt in a new line and begins to wait for the next command line input. If the main object of the parsed line is a name of a command file, then command interpreter begins to read commands from this file and interprets them line-by-line. When execution of the last command line terminates, command interpreter returns to waiting for command line input from keyboard.
Specific contents of a command line, of course, depend on the command interpreter it is addressed to, and this is a subject of a separate consideration which begins in chapter 2 of this book and is continued along the chapters that follow.
1.05 Functional keys for line editing.Edit
The most "hot" input key, no doubt, is the ENTER key. But there are several other "hot" keys, charged with editing and control functions, which have a long history in former computer generations. Both interactive command interpreters in DOS — COMMAND.COM and DEBUG.EXE — inherit these functions. Some of them seem rudimentary, but some are still widely used.
BACKSPACE key (left arrow) decrements by 1 current position pointer for the current line and in internal memory buffer as well. Contents of internal memory buffer remain intact, but the last character in the current line looks lost; in fact this character is prepared to be overwritten with the following keystroke. Left arrow among cursor keys, left arrow in the numeric keypad, CTRL-H and ALT-08 keystroke combinations do just the same.
CTRL-2, CTRL-C, CTRL-BREAK and ALT-03 – all these key combinations erase contents of the current line and open an empty line to be typed anew. All previous textual input becomes lost.
CTRL-ENTER, CTRL-J, and ALT-10 key combinations wrap current input line and give an opportunity to continue it in the next lower row. This enables to see the whole line (up to 128 characters long by default) within the screen which is usually 80 characters wide. The wrapped command line is always accepted just as if it were continuous.
CTRL-G and ALT-07 key combinations insert code 07h "Beep". It does nothing in textual and command lines, but having been sent to the screen, produces a vile sound signal instead.
CTRL-P and ALT-16 key combinations toggle data output from screen to printer and back. This is dangerous when printer is not ready, or is not connected, or is connected not to the default port (LPT1). In any such case INT 24 (8.02-84) is called for with its "Abort, Retry?" offer, but the "Abort" choice doesn't reset the output state (this seems to be a bug). In order to get back to normal command line you have to press CTRL-P once more, otherwise the offer is repeated indefinitely.
DEL (DELETE) key increments by 1 the pointer in internal memory buffer. This looks as though the previous line in the buffer has been shifted one position to the left. If then copying into the current line is performed, one character from the preceding line becomes skipped. Formerly this function was known as "SKIP1".
ESC, CTRL-ESC, CTRL-[ and ALT-27 key combinations cancel the current line and open a new one. Formerly this function was known as "VOID". Contents of internal memory buffer remain intact. The cancelled command line is marked on the screen with a backslash "\", but the backslash itself doesn't cause the "VOID" action: you are free to type it in an ordinary way.
F1 keystroke appends current line with one character, copied from the same position in the previous line which is kept stored in internal memory buffer. Formerly this function was known as "COPY1". Right arrow key in numeric keypad and right arrow cursor key do just the same.
F2 keystroke causes a pause, waiting for one character input. If the inputted character isn't present in the rest part of previous line in internal memory buffer, the F2 keystroke is aborted; but if the character is present, a number of characters preceding the inputted one are copied from internal buffer, appending the current line. Formerly this function was known as "COPYUP".
F3 keystroke fills line's empty space with characters from internal memory buffer, thus copying the previous command line. If current line contains several symbols already, then only the rest part of characters from internal memory buffer will be appended to existing part of the current line. Formerly this function was known as "COPYALL".
F4 keystroke affects internal memory buffer only. When pressed, F4 causes a pause, waiting for one character input. If the inputted character isn't present in rest part of internal memory buffer, the F4 keystroke is aborted; but if the character is present, preceding characters in memory buffer are deleted. This looks as though the contents of internal buffer became shifted to the left until the inputted character gets the same position as the cursor in the current line. The F4 function, formerly known as SKIPUP, enables to skip a part of preceding line from being copied into the current line by F1 or by F3 keystroke.
F5 keystroke copies current line into internal memory buffer, closes the copied line on the screen with "@" symbol, and opens a next (empty) command line which is to be typed anew. The described action isn't caused by symbol "@" itself, so the latter may be used in an ordinary way.
F7 and ALT-00 insert code 00h, marked by symbol pair ^@. Code 00h interrupts parsing of command line: all characters after 00h will be ignored. But 00h doesn't interrupt text input: code 00h itself and all the following characters remain in the saved text.
INS (INSERT) keystroke toggles a bit (see A.02-3, 0040:0017) which controls incrementation of current position pointer in internal memory buffer. If you have copied a part of previous line, then stop incrementation, type in some new characters, and then copy the rest part of previous line, the result will look as if the new characters were inserted between adjacent characters of the previous line. To restore normal incrementation you have to press the INS key once more.
CTRL-I, ALT-09 and TAB keys insert code of horizontal tabulation 09h which is expanded by the displaying procedure into 8 empty spaces. When text is saved into a file, tabulation symbol is not expanded. Some text editing programs can expand the 09h code into other number of spaces.
The listed original key functions are often intercepted by TSR (terminate and stay resident) programs which can be loaded later. TSR shells (Norton Commander, Volkov Commander, etc.) usually intercept INS, DEL, F1 – F7 and several other keys, make them inactive or active in another way (see 6.25 for examples). Nevertheless original command line editing functions always remain active for input of textual lines and in DEBUG's (6.05) interactive sessions as well.
1.06 Keyboard layouts and character sets.Edit
By default MS-DOS 7 employs American English (US') set of characters, represented by codepage 437, but gives an opportunity to replace it according to national demands. Implementation of this opportunity involves several operations for changing both keyboard and display settings. Microsoft proposes the following sequence of operations :
- change limitations for names and some other setting by loading data from COUNTRY.SYS file (5.02-01, an example in 9.01-01);
- prepare a memory place for additional codepage(s) by loading DISPLAY.SYS driver (5.02-02, an example in 9.01-01);
- launch MODE.COM utility in order to load codepages and to make one of them active (6.18, an example in 9.01-02);
- launch KEYB.COM driver in order to load alternative keyboard layouts (see 5.02-04, an example in 9.01-02);
- load NLSFUNC.EXE driver (5.02-03) in order to enable switching between prepared codepages and national data sets.
National codepages inside WINDOWS-95 OS release are packed into four data files : EGA.CPI, EGA2.CPI, EGA3.CPI, ISO.CPI. Each national codepage contains 256 characters in two character sets : american english set (characters 32–127) and a national one (characters beyond the 128th). Therefore switching between any national language and english language doesn't require swapping of codepages, it can be performed within any single national codepage. This is quite enough for all that limited variety of tasks which are solved nowadays with MS-DOS 7. Because of this reason swapping of codepages has come out of use.
Switching between different character sets (inside one codepage) is done with "hot" keys, arranged by KEYB.COM (5.02-04) or by any other keyboard driver (for example, KEYRUS.COM, see 5.02-05). In particular, KEYB.COM activates CTRL-rightSHIFT key combination for switching to a national character set and CTRL-leftSHIFT key combination to switch back to common english character set. KEYRUS.COM enables to activate various key combinations, including the mentioned ones.
Microsoft supplies keyboard layout tables packed in special keyboard data files KEYBOARD.SYS, KEYBRD2.SYS, KEYBRD3.SYS. Among these the KEYBOARD.SYS is the only keyboard data file supporting typewriter form of keyboard layout. Details concerning the choice of a proper keyboard layout for a particular country (and of a proper code page too) are shown in appendix A.02-2. An implementation example of Microsoft's proprietary national adaptation is shown in articles 9.01-01 and 9.01-02. Though Microsoft's keyboard files and codepages include national data for the most part of the globe, they are no more supported by Microsoft and are not opened for updating. Because of this at least 5 other keyboard drivers have been developed for DOS up to now. Only one of those alternatives is described in this book — the KEYRUS.COM driver (5.02-05). Contrary to most other keyboard drivers, KEYRUS.COM is an open project, supplied with means for creating new keyboard layouts and for making corrections in codepages. Unfortunately, format of Microsoft's keyboard data files and codepages can't be accepted by KEYRUS.COM. Examples of national adaptation with KEYRUS.COM are shown in articles 9.04-01 and 9.09-01.