📄 tsrkey.asm
字号:
; own code is not re-entered. (The "bellgate" stuff below is an example
; of a measure necessary to keep us from re-entering our own TSR's code).
; What we really want to do by allowing interrupts is to make the CPU avail-
; able to OTHER critical interrupt service routines WITHOUT swarming all over
; ourselves through multiple detections of our own HotKey.
; This "gate" technique is a good one to keep in
; mind whenever you have a code region in an interrupt handler
; that needs to be protected from re-entry:
;
cmp bellgate,0 ;Is it clear to re-enter Hotkey code?
jne Exit09 ;Exit if not,
mov bellgate,1 ;Else, close gate and proceed.
;
STI ;Allow other interrupts in our TSR.
;
call ROUTINE ;All is clear!, so call routine.
;
mov CS:bellgate,0 ;Open gate allowing new HotKey detect.
;
Exit09:
pop es ;Restore all registers
pop ds
ASSUME DS:NOTHING ;v0.01
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop ax
;
;
; Return from this TSR's Keyboard Interrupt 09h handler routine:
iret
;
NewInt09 ENDP ;v0.01
;
;*************************************************************************
;
; -END OF TSR's RESIDENT CODE-
; Only the code above will remain locked in memory
; after the initialization performed below.
;*************************************************************************
SUBTTL TSR Initialization Code (Nonresident). The "BOOSTER".
PAGE
;*************************************************************************
; BEGINNING OF TSR's INITIALIZATION CODE:
; The following code is protected in RAM *ONLY* during initialization
; of the TSR that occurs when the TSR name is first entered
; at the DOS command level. All the following code is abandonned
; unprotected in RAM after the Terminate-and-Stay-Resident
; call to Function 31h of DOS Interrupt 21h below. This
; is allowed to happen because the code's work is complete at
; that point. The code will be overwritten as the memory which
; it temporarily occupied is needed by DOS for other purposes.
; I have seen this following section of code colorfully called
; the TSR "Booster". And this is quite appropriate since the code
; sits here, strapped to the very end of the code. It is of use
; only during the initialization of the TSR, when it is used to
; put the TSR into "orbit" (residency), and after which it is
; "jettisoned" by the DOS TSR call, Int 21h, Fcn 31h.
;
TSRinit PROC NEAR ;v0.11
EndDump EQU $ ;From Roy Silvernail. Keeps TASM v.1.0 happy.
;
; TSRKEY requires DOS Version 2 or later. Be sure DOS Version 1 not used:
;
; Get DOS Version Number:
mov ah,30h ;Fcn 30h = Get DOS Version
int 21h ;DOS Version = al.ah
;
; If this is DOS v.1.x, this TSR cannot work, so go print message
; and exit without installing:
cmp al,1 ;Is this DOS Version 1.x?
ja DOSverOK ;If not, DOS version is OK.
;
DOSver1:
;If here, DOS Version 1.x is being run and TSR won't work, so bail out:
;
mov dx,OFFSET BailOutMsg ;TBONES needs DOS 2.x or later.
mov ah,09h ;Say we're sorry, but NO GO
int 21h ;via DOS.
pop bx ;Clear stack.
int 20h ;Terminate without installing
;in only way DOS 1.x knows.
;
BailOutMsg:
db 0Dh,0Ah
db 'Sorry. TSRBONES needs DOS v.2+. You have v.1.x'
db 0Dh,0Ah,'$'
;
DOSverOK:
; If here, DOS version is 2.0 or later. TSR can work, so proceed.
;
; To conserve RAM usage, release from memory the copy of the DOS
; Environment passed to this TSR (this assumes, of course, that
; your Interrupt handler routine will not need to reference this
; de-allocated Environment):
;
mov ES,envseg ;ES=PSP's environment seg v0.11
mov ah,49h ;DOS Fcn 49h = Release Memory
int 21h ;Release it via DOS interrupt.
;
; In order to make the TSR's command name show under the "owner" column in
; the "MAPMEM" command of Kim Kokkonen's excellent TSR Mark/Release
; package, allocate a tiny 1-paragraph "Pseudo-Environment" here which
; contains nothing but the TSR name. This costs only 16 bytes in
; TSR resident code.
;
; Allocate the memory needed by the tiny 'Pseudo-Environment":
mov bx,1 ;Allocate one parag. (16bytes)
mov ah,48h ;and return allocation
int 21h ;segment in ax via DOS call.
;
mov ES,ax ;Pseudo-Env. Segment to ES.
mov si,OFFSET PseudoEnv ;si=source string OFFSET.
mov di,0 ;di=destination string OFFSET.
mov cx,ENVLNGTH ;cx=Bytes in Pseudo-Env.string.
cld ;Forward string move direction.
rep movsb ;Move Pseudo-Env. string @ DS:si to ES:di
;
; Set PSP's Environment segment pointer to point to tiny Pseudo-Environment.
mov envseg,ES
;
;*****************************************************************************
; Hook Interrupt 09h vector:
;
; Get Old Interrupt Vector:
mov ax,3500H+HOOK09 ;Get Hooked interrupt vec v0.11
int 21h ;Int.Vector in ES:BX via DOS.
;
; Save Old Interrupt Vector:
mov Word Ptr oldint09,bx ;Save Offset of Old Interrupt.
mov word ptr oldint09+2,ES ;save segment v0.11
;
; Install New Interrupt Vector to this TSR's "NewInt09:" Label:
mov ax,2500H+HOOK09 ;Set Hooked int vector v0.11
mov dx,offset NewInt09 ;dx=Offset of New Int Handler.
int 21h ;Set New Int via DOS.
;
; Announce the TSR's Installation:
mov dx,Offset InstallMsg ;DX points to message.
mov ah,09h ;DOS Fcn. 09h=Display String.
int 21h ;Display String via DOS.
;
; Lock resident code in memory via Terminate-and-Stay-Resident (TSR) DOS call:
;
;v0.11 DX requires size of resident code (in 16-byte paragraphs)
; This awkward construct is required to keep
; DOS Function 31h happy. Notice how we first compute
; the length of the TSR code in bytes [i.e., end of
; the TSR code (TSRinit) minus start of the TSR code
; (0, our CodeSeg)], round it up to the next whole paragraph ( + 0Fh),
; and then divide by 16 (SHR 4) to get the number of resident paragraphs:
;
; Roy Silvernail discovered that the EndDump and BeginDump constants
; kept his TASM 1.0 assembler happy on the following statement:
mov dx,(EndDump-BeginDump+0FH)/16 ;v0.11
;
mov ah,31h ;DOS FCN 31h=TSR Call.
int 21h ;Go Resident via DOS TSR call.
;
PseudoEnv: DB ' ',0,0,1,0,'TSRKEY',0
ENVLNGTH EQU $-PseudoEnv
;
InstallMsg:
db 0Dh,0Ah
db 'YOUR HOT KEY TSR IS NOW INSTALLED.'
db 0Dh,0Ah
db 'HotKey => Ctrl-Alt-K'
db 0Dh,0Ah
db 0Dh,0Ah
db 'TSRKEY Version 0.4'
db 0Dh,0Ah
db 'Copyright (C) 1990, 1991 by Robert Curtis Davis'
db 0Dh,0Ah,'$'
;
TSRinit ENDP ;v0.11
CodeSeg ends
end Entry
;
;******************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -