News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Reading the Status Register of the Parallel Port (solved)

Started by popcalent, June 02, 2021, 08:08:13 PM

Previous topic - Next topic

FORTRANS

Hi,

Quote from: popcalent on June 04, 2021, 01:34:49 AM
By the way, is there a way to read the keyboard and, if there's nothing there, just continue instead of waiting for a key to be pressed?

   INT 16H is the BIOS keyboard functions.  Functions 0 and 10H
return a key when one is available.  Functions 1 and 11H check
the status of the keyboard buffer.

INT 16,01   Check Keyboard Status

   Checks the input buffer to see if there is a key waiting.
If a key is available, the codes are returned in AX, but not
removed from the buffer.  If no key available, the Zero Flag
is set.

INPUT  AH = 1

OUTPUT Zero Flag = 1, Buffer is empty
       Zero Flag = 0, AH = Scancode, AL = Character or 0


Cheers,

Steve N.

P.S.
minerio got to be first.  I'm just a slow typist.
SRN


popcalent

I'm trying to use INT16H to check if the keyboard buffer is empty or not, if it's empty, then go back to beginning of loop, if it's not do whatever... But I can't get it to work... This is my code:

0 MAIN_LOOP:
1    MOV AH, 1
2    INT 16H
3    JZ  READ_KB
4    ;DO STUFF THAT NEEDS TO BE DONE EVERY ITERATION
5    JMP MAIN_LOOP

6 READ_KB:
7    MOV AH, 0 ;READ KB BUFFER
8    INT 16H
9    ;DO STUFF ACCORDING TO THE KEY THAT WAS PRESSED
10   JMP MAIN_LOOP


The program never goes to line 4, whether I press a key or not. Then it stops at line 8 waiting for me to press a key. I understand that lines 7, and 8 are necessary because lines 1 and 2 do not remove a keystroke from the buffer. If I remove lines 7,and 8. The loop iterates really fast and the program ends after a second (it doesn't crash). What am I doing wrong?

FORTRANS


Hi,

   The zero flag is set if the buffer is empty.  So you
would jump to the none ready code with JZ.  You
would jump to character available code with JNZ.

Regards,

Steve N.

popcalent

Thanks, FORTRANS.

I knew ZF=1 means no keystroke, and vice versa. And, I checked, and rechecked, and double checked, but, for some reason, this escaped me!