; Ask the user to press A. If it is pressed, print a message.
; Wait on an endless loop for a key press. If another key is
; pressed for the first time, message: 'Wrong key, buddy'. If
; another key is pressed again, message: Wrong again, buddy.

IDEAL
MODEL small
STACK 100h
DATASEG
msg1    db 'Waiting for you to press A$'
msg2    db 'Wrong key, buddy$'
msg3    db 'Wrong again, buddy$'
msg     db 'A was pressed$'
savekey db 0  

; --------------------------
; Your variables here
; --------------------------
CODESEG
start:
	mov ax, @data
	mov ds, ax
	mov dx, offset msg1     ; instruction to the user
    mov ah,9
    int 21h 
    ; new line
	mov ah, 2 
	mov dl, 10
	int 21h
	mov dl, 13
	int 21h
wait1:
    mov ah, 1
    int 16h
    jz wait1                ; no input yet (nothing pressed)
    mov ah,0
    int 16h                 ; ah gets the scan code and al gets the ascii code.
    cmp ah,1Eh
    je  endit               ; A pressed
    cmp [savekey],0
    je  firsttime
    mov dx, offset msg3
    mov ah,9
    int 21h
    ; new line
	mov ah, 2 
	mov dl, 10
	int 21h
	mov dl, 13
	int 21h
    jmp wait1
firsttime:
    mov dx, offset msg2
    mov ah,9
    int 21h
    inc [savekey]
    ; new line
	mov ah, 2 
	mov dl, 10
	int 21h
	mov dl, 13
	int 21h
    jmp wait1
endit:

    mov dx, offset msg
    mov ah,9
    int 21h
exit:
	mov ax, 4c00h
	int 21h
END start


