

Task

Obtain a valid   Y   or   N   response from the keyboard.

The keyboard should be flushed, so that any outstanding key-presses are removed, preventing any existing   Y   or   N   key-press from being evaluated.

The response should be obtained as soon as   Y   or   N   are pressed, and there should be no need to press an   enter   key.




rawio:	equ	6	; Raw console input
puts:	equ	9	; String output
bdos:	equ	5	; CP/M entry point
	org	100h
	jmp	demo
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;;	Routine: read 'Y' or 'N' from the keyboard.
	;;;	Output: carry flag clear if Y pressed, set if N pressed.
yesno:	mvi	c,rawio	; Read input from console
	mvi	e,-1
	call	bdos
	ana	a	; Read keys as long as a key is pressed
	jnz	yesno	; (wait until keyboard is clear)
yread:	mvi	c,rawio	; Then, wait for a key to be pressed
	mvi	e,-1
	call	bdos	
	ana	a
	jz	yread
	ori	32	; Set bit 5 to make input letters lowercase
	cpi	'y'	; If the key is Y,
	rz		; then return (carry is clear here)
	cpi	'n'	; If the key is N,
	stc		; then set the carry flag and return
	rz
	jmp	yread	; If it wasn't Y or N, get another key
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;;	Demo code: use the routine to read Y or N, and then print
	;;;	'yes' or 'no'.
demo:	call	yesno	; Read Y or N
	mvi	c,puts	
	lxi	d,yes
	jnc	bdos	; If carry clear, print 'Yes'
	lxi	d,no
	jmp	bdos	; Otherwise, print 'No'
yes:	db	'Yes$'
no:	db	'No$'