Assembly language Writing DOS memory-resident program (5)

Source: Internet
Author: User
Tags control characters string format
Five keyboard input Expansion program
Based on the basic resident program in the previous section, you can build different applications. Next, write a resident program that takes the user's typing character and replaces it with a series of characters. This reduces the number of keystrokes that users have.
First, review the format of the resident program in the previous section, as follows:
CSEG segment
Assume Cs:cseg,ds:cseg
Org 100h
Start
JMP Initialize
Old_keyboard_io DD?
; Section 1
NEW_KEYBOARD_IO proc Far
STi
; Section 2
Pushf
Assume ds:nothing
Call Old_keyboard_io
Nop
Iret
New_keyboard_io ENDP
; Section 3
Initialize:
Assume Cs:cseg,ds:cseg
MOV Bx,cs
MOV ds,bx
MOV al,16h
MOV ah,35h
int 21h
mov word ptr old_keyboard_io,bx
mov word ptr old_keyboard_io[2],es
; End Section 3
MOV Dx,offset new_keyboard_io
MOV al,16h
MOV ah,25h
int 21h
MOV Dx,offset Initialize
int 27h
Cseg ends
End Start
As long as you new_keyboard_io this program, you can turn the above programs into many different keyboard applications. Before you start designing, you must solve some problems.
First of all, you must decide which keys can be used to expand. If you make an average English letter or a number of characters as an extended character, you may have some problems. If you are expanding the control character, there should be no problem, but DOS treats some control characters as a special feature. Like CONTROL_H,IBM. The PC itself has a set of unique and added characters (extended character), such as: function keys (F1 to F10), and the ALT key and other combinations of characters produced. These additional characters are usually used in the document editing program, These characters are more suitable for use as extension characters. This set of characters is made up of two yards, and the front one is always 0, so dos can be easily distinguished. And using these characters as extended characters will not have much impact on the use of DOS. The following is the second code size for the extended character group:
1 2 paoudo_null 3 4 5
6 7 8 9 10
Shift_tab alt_q alt_w alt_e alt_r alt_t alt_y Alt_u 2 alt_i (27) Alt_o (26) 8 Alt_a
alt_s alt_d alt_f Alt_g alt_h
Alt_j Notoginseng Alt_k alt_l 39 40
Alt_z alt_x
Alt_c Alt_v 48 49 50
51 52 53 54 55
F1 F2
F3 F4 F5 F6 F7
F8 F9 F10 69 70
UpArrow PgUp Leftarrow
RightArrow-DownArrow
Bayi PgDn to Insert the shift_f1 shift_f2
Shift_f3 shift_f4 shift_f5 Shift_f6 shift_f7
Shift_f8 shift_f9 shift_f10 control_f1 control_f2
Control_f3 control_f4 control_f5 Control_f6 control_f7
Control_f8 102 Control_f9 CONTROL_F10 alt_f1
ALT_F3 ALT_F4 108 Alt_f5 109 Alt_f6
Alt_f8 112 ALT_F9 113 ALT_F10 114 CONTROL_PRTSC
116 Control_rarrow 117 Control_end 118 CONTROL_PGDN 119 Control_home
121 Alt_2 122 Alt_3 123 Alt_4 124 alt_5
126 alt_7 127 alt_8 128 Alt_9 129 ALT_0 130 Alt_hyphan
131 Alt_space 132 Control_pgup
Next, you need to decide what string to extend the extension to. For example, what does the extended string end up with? One possible option is: Enter (carriage RETURN,ASCII Code 0DH). This choice is logical, Because the general instructions can be the end of the Enter. However, if you select the return key to the end of the extension string, it is difficult to represent the expansion string for many rows. Another option is to use $ as the end of the curried string. However, because some DOS system calls end with $ as characters, so if you use $ , you cannot have $ in the curried string.
The C language uses 0 of the ASCII code as the end of the string, and this form of string is called the ASCII string (the end of ASCII 0). Using the ASCII string format, you can represent all visible and invisible characters, because it is not possible to enter characters with ASCII code 0 from the keyboard.
In the following example, the F1 key (extension code 59) is defined as the dir instruction. You can also define the F1 as the following instruction:
MASM MACRO;
LINK MACRO;
Exe2bin MACRO. EXE macro.com;
In the instructions above, each line ends with the ENTER key.
The last thing to do is to solve the problem of returning the extended character to Dos. Typically, DOS takes a character from the keyboard input queue whenever a key is typed on the keyboard. Therefore, it must try to deceive DOS, let it accept a series of characters.
DOS to check the state of the keyboard to judge, whether there is a character input, the keyboard input function on the ROM BIOS sets the ZF (Zero Flag) to 1 without entering characters, otherwise the ZF is set to 0. If you can control this function, repeatedly deceive DOS there are currently characters to enter, The pre-string is then passed back to DOS, so DOS can accept any number of characters.
5.1 Basic expansion procedures
The above empty New_keyboard_io program can be replaced by the following program instead.
NEW_KEYBOARD_IO proc Far
STi
CMP ah,0; A Read request?
Je ksread
CMP ah,1; A status request?
Je ksstat
Assume ds:nothing; Let original routine
JMP old_keyboard_io;D o remaining subfunction
Ksread:
Call Keyread; Get Next char to return
Iret
Ksstat:
Call Keystat; GetStatus
RET 2; It ' s important!!
New_keyboard_io ENDP
In the New_keyboard_io program above, both the 0H (read character) and 1H (get keyboard status) are handled by themselves. This program is simple, but there is a key point. When we handle the function of getting the keyboard state, Because the original keyboard interrupt handler uses ZF to return to the keyboard state, this feature must also be retained in the package, and if the Iret is returned, then the set ZF will be recovered from the stack because the CPU status flag is removed from the heap.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.