News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Input interrupts

Started by realcr, May 05, 2005, 11:27:55 AM

Previous topic - Next topic

realcr

Is there such a 16bit dos interrupt for reading a key, and if a key is not entered after some defined time the program continues?

realcr.

AeroASM

int 16h ah = 0h waits for a key, but does not have a timeout.

realcr

Tnx AeroASM.
However , do you know about the existence of such interrupts as I decribed?

realcr.

realcr

I am trying to write a PacMan program in DOS mode , however , It works like a Turns game , Since every time I press a button , I the PACMAN character moves , and then the enemy moves. I want it to work like a multithreaded program , but I only know how to do it using windows. I prefer to try to solve it without Windows Threads. How can I do that?

realcr.

AeroASM

Why do you need a timeout?

realcr

I have a pacman an a ghost that running after it. If i use ah=0 in interrupt 16h , I get something like a Turns game. If I use ah=1 the ghost is running all over and I can't press on anything.
It's like a loop that in each cycle me and the ghost should do one turn... Is there a better way to do that? Of course I will probably need a timeout for the ghost...
I can't find any good way of creating this program. I wish to know if there is another way than the loop I have written about.

realcr.

hutch--

realcr,

It sounds like you need to run a loop and poll for the keystroke each iteration of the loop. That was the normal way to do it in DOS. This allows you to schedule "events" that you process on a conditional basis within that loop while not just waiting for one event.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Tedd

You have to use int 16, func 1 (I think) which will tell you if there was a key pressed, but it doesn't wait.
Soooo, to do the timeout magic, you'll need a loop which checks for the keypress and exits if got key, or then checks the current time (in seconds) and exits if time has passed, otherwise loop again.

If you're using DOS then I think there is a function that does all this for you.
No snowflake in an avalanche feels responsible.

MichaelW

realcr,

Interrupt 16h, Functions 1 and 11h (extended keyboards) return immediately, with the keystroke scan and ASCII codes if a keystroke is available, but the functions do not remove the keystroke from the keyboard buffer (so the next call will return the same keystroke). Functions 0 and 10h do remove the keystroke from the keyboard buffer, but if no keystroke is available the functions will wait until one is available before returning. To avoid the wait the functions are normally used in pairs.

If you want the ghost to move independently of PACMAN, I can see no way to do it that does not involve a timer (that is, unless you don't care how fast the ghost moves). The BIOS provides an Event Wait function (Interrupt 15h, Function 83h) that will set a flag after a preprogrammed delay, but the function will not delay under Windows 2000/XP. For these versions of Windows, the only reasonable alternative I can see would be to poll the system timer tick count that the BIOS maintains in the DWORD at 40h:6Ch. The tick count is derived from system timer 0, which is normally programmed to generate 1193186 / 65536  (~ 18.2) ticks per second. You could coordinate everything from a main loop that would receive keystrokes and track the tick count, and call other procedures as necessary.
eschew obfuscation

realcr

Thank you for your help everyone.
I will try your suggestions about the timer and polling inside the loop.

realcr.