How do I get keyboard input without interrupts.

Started by www.:).com, November 29, 2010, 09:01:34 PM

Previous topic - Next topic

MichaelW

There is a 16-bit DOS example of reading the data port directly here:

http://www.masm32.com/board/index.php?topic=13604.msg106677#msg106677

But note that the port is read in an interrupt handler, because doing it that way is much more efficient (and reliable) than polling for keystrokes. See multikey.asm in the attachment.

In a Windows app you can do something similar with GetKeyboardState.
eschew obfuscation

www.:).com

Thanks, and as for what redskull said:
Quote from: redskull on November 30, 2010, 02:30:24 AM
Quote from: www.:).com on November 30, 2010, 02:14:04 AMok, but how would i do this without interrupts even if it is not the best way to to it?

You have yet to clarify what system you are writing for, and whether it's software or hardware interrupts you are opposed to.  To summarize:

1. If you are writing a 32-bit Windows program, you can't.
2. If you are writing a true 16-bit DOS program, you use the I/O port (reading port 60 will tell you the most recent keystroke)
3. If you are writing a 16-bit program to run in a DOS Box, then option two is not gaurenteed to work, but might.
4. If you are attempting to write your own 32-bit OS, then you should already know how to do it

-r
Im trying to do number 3 and i'm not so much opposed to interrupts it's just I never had luck with them - setting them up.

FORTRANS

Hi,

   Setting up the code to use interrupts is covered in many
old ASM books.  DOS function 35H "Get Interrupt Vector"
returns the current address of the interrupt handler.  DOS
function 25H "Set Interrupt Vector" allows you to use your
interrupt handler.

   You could also use BIOS int 16H function 1 to return the
status of the keyboard and function 0 to retrieve the
character.

Steve

BogdanOntanu

And I think that it is about time and required that you tell us what is the purpose of this program and why you want to do it in this strange ways.

Many DOS native things will not work in Win7 in a DOS box but some exploits are targeted on purpose for this hence please do explain your purpose / program.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

www.:).com

There is no specific program in mind, I was just wondering how to do it without interrupts, for learning purposes.

www.:).com

Quote from: FORTRANS on November 30, 2010, 03:20:38 PM
Hi,

   Setting up the code to use interrupts is covered in many
old ASM books.  DOS function 35H "Get Interrupt Vector"
returns the current address of the interrupt handler.  DOS
function 25H "Set Interrupt Vector" allows you to use your
interrupt handler.

   You could also use BIOS int 16H function 1 to return the
status of the keyboard and function 0 to retrieve the
character.

Steve
-As for interrupt 25h does the new interrupt vector replace the old one or just extend it?
-Is the interrupt vector a variable location or is it always in a specific location independent of BIOS and DOS?
-Do you happen to know what possible values are stored in registers for int 16h function 1 & 0 and what they indicate? If not ill just search google.

Magnum

You should consider devoting your time learning 32 bit code only.

You can keep your favorite 16 bit code and the .exes and .coms.

Andy
Have a great day,
                         Andy

Neil

Answers to your questions :-

1 - You must save the interrupt vector before replacing it & restore it on program termination.
2 - The bottom 1k of memory stores the interrupt vectors, 256 of them.
3 - Function 1 of Int 16H returns with the zero flag set to 1 if there is a character in the keyboard buffer & 0 if not.

Number 3 above can be done 'manually' by checking the Head & Tail pointers in the keyboard buffer.

BogdanOntanu

Quote from: www.:).com on November 30, 2010, 06:10:23 PM
There is no specific program in mind, I was just wondering how to do it without interrupts, for learning purposes.

This is the wrong way to do it.

Unless you write your own OS but even then you should use BIOS for 16 bits and then go to 32 bits and then eventually go to 64bits.

You do not seem to understand that there are 2 types of interupts:
a) Software interrupts that are in fact DOS or BIOS interfaces
b) Hardware interrupts or IRQ's that are in fact required by hardware.

"Learning" purposes is not good enough for going the wrong way.  Please consider a better answer next time ;)

Locked.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro