📄 tsrbones.asm
字号:
;************************
PAGE 55,132 ;Format .LST listing at 55 lines by 132 columns.
TITLE TSRBONES Version 0.1 Jan 20 91 Robert Curtis Davis
SUBTTL Introduction
;**************************************************************************
;
; TSRBONES.ASM Version 0.1 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 WHEN DOS IS NOT
; BUSY (the InDOS Flag AND the DOS Critical Error Flag are zero)
; flag), OR WHEN DOS IS AT "BUSY IDLE" (when INT28h is called),
; AND WHEN NO HARDWARE INTERRUPT IRQ0-IRQ7 IS BEING HANDLED.
; This avoids problems of interfering with hardware interrupt
; handling and with DOS non-reentrancy; and allows DOS function
; calls above 0Ch to be used in the TSR routine. The TSR's code
; prevents multiple installations. Also checks DOS version and
; requires DOS Version 2 or later before installation is
; permitted.
;
; PURPOSE:
; Provides a skeletal framework program as a starting point in the
; design of your own HotKey TSRs which use DOS function calls, and
; for which a single installation is desired.
;
; E-mail address:
; Internet: sonny@trantor.harris-atd.com
;
; US Mail address:
; 430 Bahama Drive
; Indialantic, FL 32903
;
;**************************************************************************
;
; Special thanks to Roy Silvernail, whose persistent hacking (in the best
; sense of that word) and E-mail exchanges over the holiday season in
; December 1990, rooted out TBONES incompatibilities with Borland's TASM v.1.0.
;
;**************************************************************************
;
; Special thanks to Anto Prijosoesilo and Richard Brittain for E-mail
; exchanges which helped solve detailed problems with the implementation of
; the "Pseudo-Environment" idea.
;
;**************************************************************************
;
; Special thanks to David Kirschbaum, whose Toad Hall Tweaks significantly
; improved an early version of the TBONES Assembly Language code:
;
;v0.01 Toad Hall Tweak, 25 Nov 90
;**************************************************************************
SUBTTL Code Segment
PAGE
;**************************************************************************
;
CodeSeg segment
assume cs:CodeSeg,ds:CodeSeg
BeginDump EQU $ ;Roy Silvernail - Keep TASM 1.0 happy
;when computing # resident paragraphs.
;
org 2CH ;v0.01 ORG in PSP to pick up the
envseg label word ;v0.01 Environment Segment.
;
org 100h ;ORG for all COM programs.
;
Entry PROC NEAR ;v0.01
jmp TSRinit ;Jump over resident portion and
;initialize things and make code
;between Entry: and TSRinit: resident.
;
; Old Interrupt Vectors are stored here during TSR initialization:
oldint09 dd ? ;Keyboard Hardware Interrupt.
oldint13 dd ? ;Disk BIOS Interrupt.
oldint16 dd ? ;Keyboard BIOS Interrupt.
oldint28 dd ? ;DOS Idle Interrupt.
;
; For this HotKey TSR Template, specify Keyboard Interrupt 09h as the Hook:
HOOK09 equ 09h ;Hooked Interrupt 09h.
; Int 13h is used to set a flag to prevent TSR trigger while disk active:
HOOK13 equ 13h ;Hooked Interrupt 13h.
; Int 16h is hooked solely to provide way to check for prior TSR installation.
HOOK16 equ 16h ;Hooked Interrupt 16h.
; We also have to hook Interrupt 28h to check for "DOS idle":
HOOK28 equ 28h ;Hooked Interrupt 28h.
;
bellgate db 0 ;Gate closed (=1) when in Bell routine.
;Gate open (=0) when not in Bell routine.
; Below:
; EQUates related to the Intel 8259A Programmable Interrupt Controller (PIC)
; chip. Hardware Interrupts IRQ0 through IRQ7 are controlled by the PIC.
;
; To really understand the nitty-gritty details of this stuff,
; you have to study the Intel Specification data for the 8259A PIC chip.
; These EQUates are used in this TSR to examine the PIC chip's In Service
; Register (ISR) to be sure that the TSR is not interrupting one of
; the hardware interrupt service routines. The reason for not wanting to
; interrupt these hardware interrupt service routines is that they are
; often time-critical and can be compromised by intruding on them with
; our TSR (for example, a hardware COM port interrupt-driven comm
; program might lose bytes on a modem transfer if we bull our way in and
; steal the CPU away from the comm program's service routine):
PICPORT EQU 20h ;I/O Port for the 8259A PIC chip.
ISRREQ EQU 00001011B ;This is a byte defining the
;Operation Control Word 3 (OCW3) to
;output on port 20h to make the PIC
;chip's In Service Register available
;for reading by the CPU on the
;next IN 20h command.
;
; 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.
;
LockKeyMask equ 10001111B ;For masking out Scroll, Caps,
;and Num Lock bits in KeyFlags.
;
; Pointer to "DOS busy" (InDOS) flag (loaded during TSR initialization):
indosptr dd ?
;
; Pointer to "Critical Error" (CritErr) flag (loaded at TSR initialization):
criterrptr dd ?
;
; Pointer to "Print Screen" busy (PrtScrn) flag
prtscrn dd 00500000h
;
; hotkeyflag used to signal HotKey pressed to "DOS idle" Interrupt 28h:
hotkeyflag db 0 ;hotkeyflag initially zero.
;
; diskflag used to prevent TSR trigger during time-critical Disk operations:
diskflag db 0 ;diskflag initially zero.
;*************************************************************************
; Your HotKey is specified here:
; (This sample HotKey is set for Ctrl-Alt-B)
;
; Specify TSR's HotKey Shift Keys:
KEYFLAGBYTE equ CTRL+ALT ;HotKey Flags
;
; Specify TSR's HotKey Scan Code:
HOTKEY equ 30h ;'B' (for Bones) key
;
;*************************************************************************
; Specify TSR's signature words:
TSRsigA equ 'TS' ;'TSRBONES' Signature
TSRsigB equ 'RB'
TSRsigC equ 'ON'
TSRsigD equ 'ES'
;*************************************************************************
Entry ENDP ;v0.01
;
;*************************************************************************
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
; 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 BusyExit09 ;Exit if not,
mov bellgate,1 ;Else, close gate and proceed.
;
CLI ;DISABLE INTERRUPTS
; Now we will check to be sure that no time-critical hardware interrupt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -