; ISR hook example ; This code hooks the keyboard hardware interrupt and inserts a new ISR. ; The new ISR blinks the LEDs (port 301h )only when a key is pressed with ; the NUM LOCK active on the keyboard. It uses INT 21h TSR servicing and ; only runs in MS-DOS (not Windows), so it works only when the DOS window ; is selected. .MODEL TINY .CODE ORG 100H .STARTUP ; We need the following code to be in memory but it needs only run when the ; interrupt is activated by the IRQ1 (in this case) JMP INSTALL NEW_09H_ISR PROC FAR ; Save all PUSHF PUSH AX PUSH ES PUSH DI PUSH DX ; Point ES:DI to the keyboard flag byte, which sits at 0040:0017 in DOS MOV AX, 40H MOV ES, AX MOV DI, 17h MOV AL, ES: [DI] TEST AL, 00100000B ;NUM LOCK STATE? JZ LAST ; Do nothing unless NUM LOCK is on ; Here's where we go do the voodoo that we do. MOV DX,303H MOV AL,80H OUT DX,AL MOV DX,301H MOV AL,00H OUT DX,AL MOV CX,005FH DLY1:PUSH CX MOV CX,0FFFFH DLY2: LOOP DLY2 POP CX LOOP DLY1 MOV AL,0ffH OUT DX,AL ; OK, now clean up and go service the keyboard like normal LAST: POP DX POP DI POP ES POP AX POPF ; IRET JMP CS:OLD_09H_VECTOR IRET NEW_09H_ISR ENDP ;************************************************************************* OLD_09H_VECTOR DD ? INSTALL PROC ; Get interrupt vector for interrupt #09 (IRQ1 used a lot for keyboard hooks) MOV AH, 35H MOV AL, 09H INT 21H ; Returns INT vector in ES:BX ; Save old vector for INT 09 servicing MOV WORD PTR OLD_09H_VECTOR, BX MOV WORD PTR OLD_09H_VECTOR + 2, ES ; Install new interrupt vector MOV AX, CS MOV DS, AX MOV AH, 25H MOV AL, 09H MOV DX, OFFSET NEW_09H_ISR INT 21H ; To make it "terminate and stay resident" (TSR)...you need to compute and save the ; space taken up by the NEW_09H_VECTOR (above). This "INSTALL" procedure can go ; away once it is run. MOV AX, 3100H MOV DX, OFFSET INSTALL MOV CL, 04 SHR DX, CL INC DX INT 21H INSTALL ENDP END