我曾尝试编写汇编代码来挂起键盘和鼠标(我现在尝试使用键盘)。我几乎到处搜索(参考和文章以及这里的旧主题),几乎所有人都通过获取INT 9的地址来显示相同的代码并创建新的中断,然后调用它而不是原始中断(9)。那是我写的代码:
.model tiny
.stack 100h
.data
old_ISR dd ?
.code
main proc far
mov ah,35h ; get interrupt vector
mov al,09 ; for int 9
INT 21h
mov word ptr old_ISR,BX ; address of original int9 saved
mov word ptr old_ISR,ES ; in ES:BX
mov ah,25h ; set interrupt vector
mov al,09h ; for int 9
mov DX,offset ISR ;is pointing to my ISR
INT 21h
mov ax,3100h ; to make my program resident
mov dx,1 ; in the memory
int 21h
ISR proc
push ax
nop ; do nothing
pop ax
iret
ISR endp
在ISR中,我什么都不做,因为我的目标是使原来的int9不指向包含int9的中断向量表但是指向我的ISR然后扫描码将错过,这就是我想要的...不幸的是,对我来说,代码根本不能正常工作,我不知道为什么! 谢谢你的建议。
****************一些修改********************
.model tiny
.stack 100h
.data
old_ISR dd ?
.code
main proc far
mov ax;@data ;new modification
mov ds,ax ;new modification
mov ah,35h ; get interrupt vector
mov al,09 ; for int 9
INT 21h
mov word ptr old_ISR,BX ; address of original int9 saved
mov word ptr old_ISR,ES ; in ES:BX
mov ah,25h ; set interrupt vector
mov al,09h ; for int 9
mov DX,offset ISR ;is pointing to my ISR
INT 21h
mov ax,3100h ; to make my program resident
mov dx,1 ; in the memory
int 21h
main endp ; new modification
ISR proc
push ax
nop ; do nothing
pop ax
iret
ISR endp
end ; new modification
答案 0 :(得分:0)
对于MSDOS / DOSBOX:
cli
mov al,2 ; disable IRQ 1
out 21h,al
sti
;------------- Main loop
P1:
in al, 64h ; get status
test al, 1
jz short NOKEY
test al, 20h ; byte from PS2 mouse?
jnz short NOKEY
in al, 60h
dec al ; exit if escape key pressed
jz HOME
; placeholder for checking more keys using a table of keys
NOKEY:
jmp P1
;------------------------
HOME:
cli
xor al, al ; enable IRQ 1
out 21h, al
sti
mov ah, 1 ; clear keyboard buffer
int 16h
; placeholder for terminate program