How can I delete the keyboard buffer in assembly?

Viewed 42

I have this code that prints "hi" when I press 'h' on the keyboard, but when I press it non-stop for a few seconds, It still prints "hi" in a delay. I'm pretty sure it happens because when I press on 'h', it "spam" the keyboard buffer and I think I need to reset or delete the keyboard buffer every time I'm entering the proc "key" to make it work. is there any interrupt I can use for this? Here's the code:

IDEAL
MODEL small
STACK 100h


DATASEG

timeEnter dw ?
mil db ?
count db ?
hi dw ? 
message db 'hi',10,13,'$'


CODESEG


proc delaytime
push bp
mov bp, sp

push ax
push bx
push cx
push si
push dx
push di

    mov bl, [bp+4] ;offset time enter
    mov [mil],0
    mov [count],0

    mov ah, 2Ch
    int 21h
    mov [mil], dl
    jmp L1
L2:
    inc [count]
    mov [mil], dl
L1:
    mov ah, 2Ch
    int 21h
    cmp dl, [mil]
    je L1
    cmp [count],bl
    jne L2


pop di
pop dx
pop si 
pop cx
pop bx
pop ax
pop bp
ret 2
endp delaytime

proc key
push bp
mov bp,sp
push ax
push bx
push cx
push si
push dx
push di



    mov [hi],0
    mov ah, 01
    int 16h
    
    jz L3
    
    mov ah, 00h
    int 16h ;al=ascii charachter
    
    cmp al, 68h
    jne L3
    mov [hi],1
    
    
    
    
    
L3:



pop di
pop dx
pop si 
pop cx
pop bx
pop ax
pop bp
ret 
endp key

















start :
    mov ax, @data
    mov ds, ax
    
L:
    ; Graphic mode
    mov ax, 13h
    int 10h
    
    call key
    cmp [hi],1
    jne L4
    
    ;print
    mov dl, 15   ;J
    mov dh, 2    ;I
    mov bh, 0     ;Display page 0
    mov ah, 02h   ;SetCursor
    int 10h
    mov dx, offset message
    mov ah, 09h   ;DispayString
    int 21h 



L4: 

    mov [timeEnter],3
    push [timeEnter]
    call delaytime


    
    ;text mode 
    mov ah, 0
    mov al, 2
    int 10h

    jmp L
    
exit :
mov ax, 4c00h
int 21h
END start
0 Answers
Related