I am having trouble figuring out how to implement a keyboard and mouse interrupt for my matrix program to make my never ending matrix program terminate once any key on the keyboard has been pressed and/or when the mouse has been moved, as well as when any buttons on the mouse is pressed.
Here is my Matrix code:
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
Here is the Keyboard interrupt code that my professor gave me:
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
Here is the Mouse Interrupt Code that my professor also gave me:
.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
So I basically have to combine both the Keyboard and Mouse interrupt code into one so when anyone who runs my program can terminate it by either pressing a key on the keyboard, move the mouse, or click the buttons on the mouse (left click, right click, and middle button).
For the keyboard termination part, I believe my professor told us that we just had to paste our code into the "Loop2: ;Matrix code goes here loop Loop2" section of the code, but I am pretty sure I just misheard him. I believe he meant to say we have to paste our code into that loop AND check for keyboard key inputs, but I know its not the way I know how to check for input (mov ah 7h/1h, int 21h) so I am confused at that part.
As for the Mouse interrupt part, it seems as though my professor gave me everything I need and I just have to paste my code into the ";Matrix code goes here" sections of my Mouse Interrupt code. If this is incorrect please let me know and if possible explain to me and if possible with examples what I will need to make the Mouse Interrupt work.
I am trying to help a little bit:
The terminate function: "AH=4Ch int 21h" is only usefull for to terminate the main-program and for to return to DOS or for to return to a parent program, when the parent is the caller of the child program. But within a interrupt service routine(ISR) it makes no sense.
;-------------------
For to use the mouseinterrupt 33h we have to start a mousedriver like the cutemouse driver before. http://cutemouse.sourceforge.net/
The cutemouse drive supports protocols of serial COM-ports and PS/2 mice. (For USB we need to enable the USB lagacy in the mainboard bios. This redirect the USB data from the mouse into the keyboard controller, so the USB mouse can be used similar like a PS2-mouse.)