⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsrkey.asm

📁 一个关于内存驻留的汇编源代码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;***************************
PAGE    55,132          ;Format .LST listing at 55 lines by 132 columns.
TITLE   TSRKEY Version 0.4 Jan 20 1991 Robert Curtis Davis
SUBTTL  Introduction
;******************************************************************************
;
;       TSRKEY.ASM      Version 0.4     Jan 20 91
;       A part of the TBONES software package.
;
;       Copyright (C) 1990, 1991 by Robert Curtis Davis,
;	All Rights Reserved.
;
;	DESCRIPTION:
;	ASM Program template for Terminate-and-Stay-Resident (TSR) programs
;		that are activated by a specified HotKey..
;
;	PURPOSE:
;       Provides a skeletal framework program useful as a starting point
;       in the design of your own HotKey TSRs.
;
;                   E-mail address:
;			  Internet: sonny@trantor.harris-atd.com
;
;                          US Mail:
;                                   430 Bahama Drive
;                                   Indialantic, FL 32903
;
;***************************************************************************
;
; Special thanks to David Kirschbaum, whose Toad Hall Tweaks significantly
; improved TBONES' code:
;
;v0.11	Toad Hall Tweak, 25 Nov 90
; - Idiosyncracy: I like my constant labels all-upper-case
;   and my variable labels lower-case.
; - Load AX with words, not byte-by-byte
; - Load ES directly with environ seg, no need to pass thru AX.
; - Save ES directly to variable, no need to pass thru AX.
; - Let compiler do basic arithmetic (figuring paras of memory to save).
; - Use processes just to be neat.  (That FAR NewInt09 is important!)
; - INS is a reserved word for TASM v1.0. Changed to INSRT.
;**************************************************************************
SUBTTL  Code Segment (Resident)
PAGE
;**************************************************************************
;
CodeSeg		segment
                assume  cs:CodeSeg,ds:CodeSeg
BeginDump       EQU     $       ;This, from Roy Silvernail, makes
                                ;TASM v.1.0 happy below.
;
		org	2CH		;0.11
envseg		label	word		;0.11
;
		org	100h		;ORG for all COM programs.
;
Entry           PROC    NEAR            ;v0.11
		jmp	TSRinit		;Jump over resident portion and
					;initialize things and make code
					;between Entry: and TSRinit: resident.
;  
; Old Keyboard Interrupt Vector (Int 09h handler address) is stored 
; here during TSR initialization:
oldint09        dd      ?
;
Entry           ENDP                    ;v0.11

; For this HotKey TSR Template, specify Keyboard Interrupt 09h as the Hook:
HOOK09            equ     09h   ;Hooked Interrupt number.
;
bellgate	db	0	;Gate closed (=1) when in Bell routine.
				;Gate open (=0) when not in Bell routine.
;
; EQUs defining Key Flag weights in the Key Flag Byte:
RSHIFT		equ	00000001B		;Right Shift Key Flag weight.
LSHIFT		equ	00000010B		;Left Shift  Key Flag weight.
CTRL		equ	00000100B		;Ctrl        Key Flag weight.
ALT		equ	00001000B		;Alt         Key Flag weight.
;SCROLL          equ     00010000B               ;Scroll Lock Key Flag weight.
;NUM             equ     00100000B               ;Num Lock    Key Flag weight.
;CAPS            equ     01000000B               ;Caps Lock   Key Flag weight.
INSRT		equ	10000000B		;Ins         Key Flag weight.
;*************************************************************************
;       Mask to mask out Num, Caps, and Scroll Lock bits from key flag byte.
LockKeyMask     EQU     10001111B
;
;       Your HotKey is specified here:
;       (This sample HotKey is set for Ctrl-Alt-K)
;
; Specify TSR's HotKey Shift Keys:
KEYFLAGBYTE	equ	CTRL+ALT		;HotKey Flags
;
; Specify TSR's HotKey Scan Code:
HOTKEY          equ     25h                     ;'K' key.
;
;*************************************************************************
SUBTTL User-supplied TSR Routine
PAGE
;*************************************************************************
ROUTINE         PROC    NEAR
;*************************************************************************
;	Code for your HotKey-triggered TSR routine  GOES HERE:
;	( Here, a dummy routine has been placed which simply rings the
;	  terminal Bell whenever the TSR is triggered. )
;
;	Announce this dummy TSR's trigger by a Bell signal:
;
Enter:
                mov     al,07h          ;al = ASCII Bell.
                mov     bh,0            ;Video page.
                mov     cx,1            ;No. of bytes to write.
                mov     ah,0Eh          ;BIOS Int10,OEh=TTY Screen.
                Int     10h             ;Write ASCII Bell to screen.
;
Exit:
                ret                     ;Return from TSR routine.
;
ROUTINE         endp
;
;	End of your HotKeyed TSR routine.
;***************************************************************************
SUBTTL Hooked Interrupts
PAGE
;***************************************************************************
;
NewInt09	PROC	FAR		;v0.01
;
; The following three instructions often are said to "simulate an interrupt"
; that calls the PRIOR interrupt handler routine and then the prior interrupt
; handler's IRET instruction pops the flags and returns here to the point
; after the following CALL instruction.
;    The reason for "simulating the interrupt" here is to give prior (and
; presumably more time-critical) handlers a shot at processing this interrupt
; before we process with this TSR's code.
;
		pushf			;Push flags as a true interrupt would.
                cli                     ;Be sure interrupts are disabled.
		call	CS:oldint09	;Call FAR PTR address of old interrupt
;					;     handler routine.
;
;
                push    ax      ;Prepare to check for Hotkey.
                push    bx      ;Save all registers (DS is already pushed).
                push    cx
                push    dx
                push    si
                push    di
                push    bp
                push    ds
                push    es
;
                push    CS              ;Set up data segment
                pop     DS              ;register to point to code segment.
;
                ASSUME  DS:CodeSeg      ;v0.01
;
;       Determine if the current Keyboard Interrupt (Int09h) occurred
;       because this TSR's HotKey was pressed:
                in      al,60h          ;Get current Key Scan Code.
                cmp     al,HOTKEY       ;Is it HotKey's Scan Code?
                jne     Exit09          ;Exit if not.
                mov     ah,02h          ;Int16h,Fcn02h:GetKEYFLAGBYTE.
                Int     16h             ;Return Key Flag Byte in al.
                and     al,LockKeyMask  ;Mask out Num, Caps, Scroll Lock bits.
                cmp     al,KEYFLAGBYTE  ;Are the HotKey Flags active ?
                jne     Exit09          ;Exit if not.
;
;       At this point, Hotkey is known to have been pressed. First, purge
;       the DOS Keyboard type-ahead buffer of the hot key(s) so they won't
;       be passed on to DOS:
;
ClrKbdBuf:      ;Clear Keyboard buffer:
                mov     ah,01h          ;Get Keyboard buffer status
                int     16h             ;via BIOS Interrupt 16h.
                jz      BufClr          ;Jump if buffer empty.
                mov     ah,00h          ;Get key from buffer (to purge it)
                int     16h             ;via BIOS Interrupt 16h.
                jmp     ClrKbdBuf       ;Loop back to purge another key.
BufClr:
;
; We shall allow other interrupts to occur during our TSR ROUTINE.
; If we didn't allow other interrupts (through the STI instruction),
; we could lock out time-critical interrupts from access to the CPU during
; our TSR routine. However, by allowing interrupts during our routine, we 
; have an increased responsibility to make sure critical portions of our

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -