;Capture key press without stopping the flow of the program.
;Captures 'a' and 'b' keys.
IDEAL
MODEL small
STACK 100h
DATASEG
message  db 'a key pressed',13,10,'$'
message1 db 'b key pressed',13,10,'$'
CODESEG
start:
        mov ax, @data
        mov ds, ax
WaitForData:
        mov ah, 1         ;sets the keyboard to capture key press
        Int 16h
        ; Here we can put code that runs while we wait for a key press,
        ; for example, clock running, snake moving etc. 
        jz WaitForData
        mov ah, 0         ;gets the scan code of the key pressed into ah
        int 16h
        cmp ah, 1eh       ;1eh is the scan code for A
        je  aPressed
        cmp ah, 30h       ;30h is the scan code for B
        je  bPressed
        jne WaitForData
aPressed:
        mov dx, offset message
        mov ah, 9
        int 21h
        jmp exit
bPressed:
        mov dx, offset message1
        mov ah, 9
        int 21h        
exit:
        mov ax, 4C00h
        int 21h
END start