Recommended Posts

Hey, I was wondering how one would go about recieving multiple keypresses from the keyboard at once in Turbo C++ 3.1 (An older DOS compiler). I'm making a 2-player ASCII animated game where there a guys in the center that block your bullets and then there is player 1 at the bottom and player 2 at the top, and they have to shoot and kill each other. I want to have each player be able to shoot and move at the same time while the other player does the same. I have everything finished but that.

Share this post

Link to post

Share on other sites

If it's a real DOS game, you need to insert a handler into the keyboard interrupt (9) and extract the keypressed yourself.Basically you get the presses and releases sent; a pressed key has the 0x80 flag set. I gotta lookup exactly in my old (Turbo Pascal) code.

Do NOT forget to reset the interrupt handler once you're done with your game. Might not matter much when running from Windows but will matter in DOS.

Ok, found something: It's not my code, just found it from the net. It implements a nice handler. Shouldn't be too hard to replace with Turbo C functions.

var oldkbdint, oldtimint, oldbrkint: pointer;

procedure sti;inline($fb); { STI: set interrupt flag }

procedure cli;inline($fa); { CLI: clear interrupt flag -- not used }

procedure calloldint(sub: pointer);

{ calls old interrupt routine so that your programs don't deprive the computer of any vital functions -- kudos to Stephen O'Brien and "Turbo Pascal 6.0: The Complete Reference" for including thisinline code on page 407 }

procedure newkbdint; interrupt; { new keyboard handler }begin keydown[port[$60] mod 128] := (port[$60] < 128); { key is down if value of 60h is less than 128 -- record current status }if port[$60] < 128 then wasdown[port[$60]] := true; { update WASDOWN if the key is currently depressed } calloldint(oldkbdint); { call old interrupt } mem[$0040:$001a] := mem[$0040:$001c]; { Clear keyboard buffer: the buffer is a ring buffer, where the com- puter keeps track of the location of the next character in the buffer end the final character in the buffer. To clear the buffer, set the two equal to each other. } sti end;