Keyboard input/Obtain a Y or N response: Difference between revisions

Content added Content deleted
No edit summary
(Add 8080 assembly)
Line 10: Line 10:
The response should be obtained as soon as   '''Y'''   or   '''N'''   are pressed, and there should be no need to press an   enter   key.
The response should be obtained as soon as   '''Y'''   or   '''N'''   are pressed, and there should be no need to press an   enter   key.
<br><br>
<br><br>

=={{header|8080 Assembly}}==

This program uses CP/M to read the keyboard.

<lang 8080asm>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$'</lang>


=={{header|8th}}==
=={{header|8th}}==