Difference between revisions of "Input"

From SizeCoding
Jump to: navigation, search
(Created page with "== Checking for ESCAPE == This is fairly easy: Monitor the keyboard scancode port for ESC which is #1, then deal with it: <syntaxhighlight lang=nasm> in al,60h...")
 
Line 8: Line 8:
 
         jnz    mainloop        ;fall through if 0, do jump somewhere else if otherwise
 
         jnz    mainloop        ;fall through if 0, do jump somewhere else if otherwise
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== Checking for '''any''' keypress ==
 +
 +
If you need to shave a byte, it might be possible in some environments to check for any keypress instead of just escape using less code:
 +
 +
<syntaxhighlight lang=nasm>
 +
        in      al,60h          ;read whatever is at keyboard port
 +
        das                    ;If non-zero, parity will be set
 +
        jp      mainloop        ;Jump if parity
 +
</syntaxhighlight>
 +
 +
An alternative if not running DOSBox:
 +
 +
<syntaxhighlight lang=nasm>
 +
        in      al,60h          ;read whatever is at keyboard port
 +
        aaa
 +
        jz      mainloop        ;Jump if zero
 +
</syntaxhighlight>
 +
 +
The above are somewhat flaky due to different hardware, VMs, and emulators not honoring flags correctly.

Revision as of 00:57, 7 August 2016

Checking for ESCAPE

This is fairly easy: Monitor the keyboard scancode port for ESC which is #1, then deal with it:

        in      al,60h          ;read whatever is at keyboard port; looking for ESC which is #1
        dec     ax              ;if ESC, AX now 0
        jnz     mainloop        ;fall through if 0, do jump somewhere else if otherwise

Checking for any keypress

If you need to shave a byte, it might be possible in some environments to check for any keypress instead of just escape using less code:

        in      al,60h          ;read whatever is at keyboard port
        das                     ;If non-zero, parity will be set
        jp      mainloop        ;Jump if parity

An alternative if not running DOSBox:

        in      al,60h          ;read whatever is at keyboard port
        aaa
        jz      mainloop        ;Jump if zero

The above are somewhat flaky due to different hardware, VMs, and emulators not honoring flags correctly.