【原创】DOS下TSR程序的汇编演示代码1--自动按键程序

来源:互联网 发布:天宝gps数据处理软件 编辑:程序博客网 时间:2024/05/16 16:20
我喜欢在DOS下用QE.EXE来阅读文本文件,自已按键手痛。于是写了个自动向键盘缓冲区放UP和DOWN键值的程序。; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<; 文件名: AutoKey.asm; 功  能: 自动向键盘缓冲区填充RIGHT 或 DOWN 键值 来移动光标;           Ctrl + Tab         停止填充;           Ctrl + →         填充RIGHT 键值;           Ctrl + ↓         填充DOWN  键值;           Ctrl + ↑          提高填充速度;           Ctrl + ←         降低填充速度;; 作  者: 黄志斌 2003年2月 广西河池;; 申  明: 可以自由转载,应保存完整性.且不能用于商业用途;; 说  明:;         1. 第一次运行时常驻内存,再次运行则撤出内存;         2. 适用于QE.EXE 和 TC.EXE, 不适于 EDIT.COM;         3. 改进方向:;              A 在屏幕右上角显示当前速度;              B 填充RIGHT 键值时能自动换行; 开发环境: IBM PC 486, MSDOS7.0(mswin95), MASM生成; Log; -----------------------------------------------------------------------; 2003.02.24    Created, but the result is exception!; 2003.02.25    OK!<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<cseg segment;============================== org 100h assume es: cseg, ss: cseg assume cs: cseg, ds: csegUP      EQU     48hLeft    EQU     4bhRIGHT   EQU     4dhDOWN    EQU     50hCtrl    EQU     04hAlt     EQU     08hEndKey  EQU     4fhTab     EQU     0FhAddKey  EQU     0dhDecKey  EQU     0chRightDelay    equ     10DownDelay     equ     100;-----------------------------start:  jmp @Init        ;====================        Old1cAddr label dword        Old1cOff  dw    ?        Old1cSeg  dw    ?        Old09Addr label dword        Old09Off  dw    ?        Old09Seg  dw    ?        mcb_evb   dw    ?       ; mcb: Memmory Control Block        mcb_psp   dw    ?        show      dw    1        count     dw    0        FillKey   db    0        time      dw    0        AutoKey   label   word                  db      00        KeyCode   db      RIGHT        VarLen    equ   $ - Old1cAddr;---------------new09h  proc    far        sti        push    ax        push    bx        push    ds        mov     ax, 0040h        mov     ds, ax        mov     bh, ds:[017h]        push    cs        pop     ds        test    bh, Ctrl        jz      @old09        in      al, 60h        cmp     al, Tab ;EndKey        jne     @right        mov     FillKey, 0        mov     KeyCode, 0        jmp     @Old09@right:        cmp     al, RIGHT        jnz     @down        mov     byte ptr KeyCode, RIGHT        mov     time, RightDelay        jmp     @AutoON@down:        cmp     al, DOWN        jnz     @up        mov     byte ptr KeyCode, DOWN        mov     time, DownDelay        jmp     @AutoON@up:        cmp     al, UP        jnz     @left        cmp     word ptr time, 1        je      @Old09        dec     time        jmp     @ClrCount  ;jmp     @Old09@left:        cmp     al, LEFT        jnz     @Old09        cmp     word ptr time, 0ffffh        je      @Old09        inc     time        ;jmp     @ClrCount@AutoON:        mov     FillKey, 1@ClrCount:        mov     count, 0@Old09:        pop     ds        pop     bx        pop     ax        jmp     cs:Old09Addrnew09h  endpnew1ch  proc    far        cmp     byte ptr cs:FillKey, 1        jne     @Old1c        push    ds        push    cs        pop     ds        inc     count        mov     ax, time        cmp     ax, count        jne     n1c        mov     count, 0        push    ax        push    bx        mov     ax, 0040h        mov     ds, ax        cli        mov     bx, word ptr ds:[001ch]        mov     ax, cs: AutoKey        mov     [bx], ax        inc     bx        inc     bx        cmp     bx, 003eh        jnz     @NoTail        mov     bx, 001eh@NoTail:        mov     ax, bx        mov     bx, 001ch        mov     [bx], ax        sti        pop     bx        pop     axn1c:        pop     ds@Old1c:        jmp cs:Old1cAddrnew1ch  endp@Init:        mov ax, 3509h           ; Get current 1ch interrupt vector        int 21h        cmp bx, offset new09h   ; Has been Intalled?        jnz @install            ; No install        mov  dx, offset strMsgUninstall        mov  ah, 09h        int  21h        mov  bx, 1ch * 04h      ; Restore old 1ch interrupt vector        xor  ax, ax             ; to System interrupt vector talbe        mov  ds, ax        mov  ax, es:[Old1cOff]        mov  ds:[bx], ax        mov  ax, es:[Old1cSeg]        mov  ds:[bx+2], ax        mov  bx, 09h * 04h      ; Restore old 09h interrupt vector        mov  ax, es:[Old09Off]  ; to System interrupt vector talbe        ;xor  ax, ax                    ;mov  ds, ax            ; ds must equal 0        mov  ds:[bx], ax                mov  ax, es:[Old09Seg]        mov  ds:[bx+2], ax        mov  bx, 1              ; Release evirenment parameter block        mov  ax, es:[mcb_evb]        mov  ds, ax        mov  word ptr ds:[bx], 0        mov  ax, es:[mcb_psp]    ; Release TSR        mov  ds, ax        mov  word ptr ds:[bx], 0        mov  ax, 4c00h        int  21h@install:        ;mov    ax, 3509h         ; Get current 1ch interrupt vector        ;int    21h        mov     Old09Seg, es       ; Store current 09h interrupt vector        mov     Old09Off, bx        mov     dx, offset new09h  ; Set new 09h interrupt vector        mov     ax, 2509h        int     21h        mov     ax, 351ch          ; Get current 1ch interrupt vector        int     21h        mov     Old1cSeg, es       ; Store current 1ch interrupt vector        mov     Old1cOff, bx        mov     dx, offset new1ch  ; Set new 1ch interrupt vector        mov     ax, 251ch        int     21h        mov     dx, offset strMsgInstall        mov     ah, 09h        int     21h        ; Store the address of evirenment parameter block        mov     ax, cs        dec     ax        mov     [mcb_psp], ax      ;mov  cs:[mcb_psp], ax        mov     bx, 2ch        mov     ax, [bx]           ;mov  ax, cs:[bx]        dec     ax        mov     cs:[mcb_evb], ax        mov     dx, offset @Init        add     dx, VarLen + 2        mov     cl, 04h        shr     dx, cl        mov     ax, 3100h        int     21h        ;====================        strMsgInstall   db 07h, "AutoKey installed!$"        strMsgUninstall db 07h, "AutoKey uninstalled!$"cseg ends        end start