2014-12-03 71 views
0

我有麻烦搞清楚如何实现我的矩阵程序的键盘和鼠标的中断,使我永不落幕的矩阵程序终止后键盘上的任意键被按下和/或当鼠标已移动,以及按下鼠标上的任何按钮时。汇编语言8086键盘和鼠标中断

这里是我的矩阵代码:

title lab9 (lab9.asm) 

.model small 
.stack 100h 
.data 

    seed dw 1234h 
.code 
main proc 
mov ax, @data 
mov ds, ax 



    mov ax, 0B800h 
    mov es, ax 

    mov bx, 0 
    mov ax, 0 

    Loo1: 
     add bx, 120 
     call row 
     call busyWait 
     mov si, 0 
     jmp Loo1 
     loop Loo1 

    mov ax,4C00h 
    int 21h 

main endp 
row proc  

     push cx 
     mov cx, 10 

     R: 
     call printMsg 
     add bx, 160 

     loop R 

     pop cx 


     ret 
row endp 



printMsg proc 

    call randomCh 
    mov ah, [si] 
    mov es:[bx], ax 
    inc si 

    ret 
printMsg endp 

randomCh proc 
    mov ax, 343Fh 
    mul seed 
    xor dx, dx 
    add ax, 269h 
    mov seed, ax  

    ret 
randomCh endp 


busyWait proc 
     push cx 
     mov cx, 100h 
    L1: 


    loop L1 
    pop cx 

    ret 
busyWait endp  

My_int proc 
mov ax, 4C00h 
int 21h 
iret 
My_int endp 

end 

这里是键盘中断代码我的教授给我:

mov ax, @data 
mov ds, ax 
;Install interrupt handler 
push ds 
mov ax, @code 
mov ds, ax 
mov ah, 25h 
mov al, 9 
mov dx, offset My_Int 
int 21h 
pop ds 

Loop2; 

;MATRIX CODE GOES HERE 

jmp Loop2 

;mov ax, 4c00h 
;Int 21h 
main endp 

My_int proc 
mov ax, 4c00h 
int 21h 
iret 
My_Int endp 
end main 

这里是鼠标中断代码,我的教授也给我:

.model smal 
.stack 100h 
.data 
oX dw 0 
oY dw 0 
.code 
main proc 

    mov ax, @data 
    mov ds, ax 

    moov ax, 3 
    int 33h 
    mov oX, CX 
    mov oY, DX 

L1: 

cmp oX ,CX ; (While oX == cx, && oY == dx && button == 0) <-- I believe the "button variable is 
      ; the BX register    
jne exit 
cmp oY, DX 
jne exit 
cmp bx, 0 
jne exit 

;Matrix code goes here probably with the "Loop2: ;Matrix goes here loop Loop2 section from the 
;keyboard interrupt section 

mov ax, 3 
int 33h 
jmp L1 

exit: 
mov ax, 4C00H 
int 21h 
main endp 
end main 

所以我基本都既键盘和鼠标中断代码合并成一个,所以当谁运行我的程序任何人都可以通过按下键盘上的一个键终止它,移动鼠标,或单击鼠标上的按键(左击,右键单击和中键)。对于键盘端接部分,我相信我的教授告诉我们,我们只需将代码粘贴到代码的“Loop2:;矩阵代码到此循环Loop2”部分,但我确信我只是误听了他。我相信他的意思是说,我们有我们的代码粘贴到循环并为您的键盘按键输入,但我知道它不是我知道如何检查输入(MOV啊7H/1H,INT 21H)的方式 所以我在那部分混淆。

至于鼠标中断部分,它好像我的教授给了我一切,我需要,我只需要我的代码粘贴到“矩阵码到这里”我的鼠标中断代码段。如果这是不正确的,请让我知道,如果可能的话向我解释,如果可能的话用例子说明我需要做鼠标中断的工作。

回答

0

我想一点点帮助:

My_int proc 
; mov ax, 4c00h ; This is the functions number for to terminate the program. 
; int 21h  ; Both instructions are not needed here and it is a very wrong 
       ; place for it, because all of the following instructions can 
       ; not be execute after terminating the program. 

; It make more sense to push all of the register that we use here to the stack. 
push ax 

; But before we want to return from the interrupt with iret, we have to send 
; an End of Interrupt signal(EOI) to the programmable interupt controller(PIC). 
mov al, 20h 
out 20h, al 

; And here we can pop all the register that we have pushed before. 
pop ax 

iret 
My_Int endp 
end main 

的终止函数:“AH = 4CH INT 21H”是终止主程序只有用并返回到DOS或以当父母是子程序的调用者时,返回父母程序。但是在中断服务例程(ISR)中,这没有任何意义。

; -------------------

对于使用mouseinterrupt 33H我们之前开始像cutemouse司机mousedriver。 http://cutemouse.sourceforge.net/

cutemouse驱动器支持串行COM端口和PS/2鼠标的协议。 (适用于USB,我们需要能够在主板的BIOS的USB lagacy,这从鼠标到键盘控制器重定向USB数据,所以USB鼠标可以使用类似的像一个PS2鼠标。)

+0

真的吗?这很奇怪,因为我的教授告诉我,我只需将我的代码粘贴到他给我们的代码的选定区域。 – AlternateRealm 2014-12-03 16:37:56