2014-12-03 120 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