Keyboard input/Flush the keyboard buffer: Difference between revisions
Content deleted Content added
Added solution for Action! |
Puppydrum64 (talk | contribs) |
||
Line 16:
''The program must not wait for users to type anything.''
<br><br>
=={{header|6502 Assembly}}==
{{works with|http://skilldrick.github.io/easy6502/ Easy6502}}
On the Easy6502 and 6502asm simulators, the zero page memory address 0xFF is a memory-mapped port that reflects the [[ASCII]] code of last key you pressed on your keyboard.
Writing a value of 0 (or almost any ASCII control code that you can't type on your keyboard) to it effectively flushes the keyboard buffer. This prevents an input loop from thinking your finger is still on that key even after you stopped pressing it.
<lang 6502asm>lda #$00
sta $FF</lang>
=={{header|8086 Assembly}}==
{{works with|MS-DOS}}
Depending on the value of <code>AL</code>, you can have this system call "slide" into another related system call immediately after flushing the keyboard buffer. After flushing the keyboard buffer, <code>AL</code> will be copied into <code>AH</code> and then <code>int 21h</code> will be called again. Make sure that any other parameters needed by the interrupt you "slide into" are loaded before flushing, as you won't get a chance to do so between the flush and the second system call!
<lang asm>mov ax,0C00h▼
The valid values of <code>AL</code> for this interrupt are:
* 0x01: Read a character from standard input with echo
* 0x06: Direct console output
* 0x07: Direct character input, no echo
* 0x08: Character input without echo
* 0x0A: Buffered input (for text strings).
If you just want to flush the keyboard buffer without doing anything else, load a zero (or any value that isn't one of the above) into <code>AL</code>.
<lang asm>mov ax,0C00h ;equivalent of "mov ah,0Ch mov al,0"
int 21h</lang>
int 21h ;flush the keyboard buffer then immediately ask the user to type in a sentence and hit Enter when done.</lang>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
|