Handling keyboard and mouse using DOS and BIOS interrupt calls

I need to create a Matrix like a screensaver using (mostly) 16-bit assembly language and we need to be able to trigger the keyboard and mouse using interrupts. I got a mouse interrupt, but the keyboard doesn't seem to work. What's wrong?

.model small
.486    
.stack 100h

.data 

seed DWORD 12345678h
X DW 0
Y dW 0
V db 0
.code

MyInt proc
    CLI

    mov ah,0
    mov al, V
    int 10h

    mov ax, 4C00h
    int 21h

    STI
    iret
MyInt endp

getRand PROC
    call LongRandom
    mov dx,0
    mov cx,80 
    div cx
    mov si,dx
    mov ax,si
    add si,ax
    ret
getRand endp

Move proc
    mov bx,si
    add bx,3680

shft:
    mov ax, es:[bx]
    add bx,160
    mov es:[bx],ax
    sub bx,320
    cmp bx,si
    jge shft
    ret
MOve endp

LongRandom proc 
    mov eax,343FDh
    mul seed
    XOR edx,edx
    add eax, 269EC3h
    mov seed, eax
    ret
LongRandom ENDP

Busywait proc
    mov ecx, 07FFFFFFh
L2: dec ecx
    cmp ecx,1
    jge L2
    ret
Busywait endp

Create proc 
    call Longrandom
    push ax
    mov dx,0
    mov cx,5
    div cx
    pop ax
    cmp dx,4
    jne T2

    cmp al,38h
    je T4
    jmp T5
T4: mov ah,00000101b
    mov es:[si],ax
    jmp T3
T5: mov ah,00001010b
    mov es:[si],ax
    jmp T3
T2: mov dx,20h
    mov es:[si],dx
T3: ret
create endp

main proc
    mov ax, @data
    mov ds, ax

    mov ah,0Fh
    int 10h
    mov V,al

    mov ax, 0B800h
    mov es, ax

    ; Here is the bulk of my interrupts.

    mov ah,0
    mov al,3
    int 10h

    push ds
    mov ax,@code
    mov ds,ax

    mov ah,25
    mov al,9
    mov dx, offset myInt
    int 21h
    pop ds

    mov ax,3
    int 33h
    mov X, cx
    mov Y, dx

    ; This is the end of the interrupts (I believe).

L1: cmp x,cx
    jne exit
    cmp y,dx
    jne exit
    cmp bx,0
    jne exit
    push bx
    push cx
    push dx

    call getRand
    call Move
    call Busywait
    call create

    pop dx
    pop cx
    pop bx
    mov ax,3
    int 33h

    jmp L1

exit:
    mov ah,0
    mov al, V
    int 10h

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

      

Here's my attempt at adding an interrupt to the loop L1

:

    pop dx
    pop cx
    pop bx
    mov ax,3
    int 33h
    mov al,9
    ; mov dx, offset myInt ?
    int 21h

      

Should this fix the problem?

+3


source to share





All Articles