www.retrosoftware.co.uk
http://www.retrosoftware.co.uk/forum/

How many simultaneous key presses is it possible to read?
http://www.retrosoftware.co.uk/forum/viewtopic.php?f=73&t=911
Page 1 of 1

Author:  jbnbeeb [ Mon Aug 04, 2014 2:58 pm ]
Post subject:  How many simultaneous key presses is it possible to read?

..And how? (I couldn't fit the "and how on" the subject line :)

I can see how it's possible to read two keys via INKEY / OS routines.

In my biplane dogfight game, I want to be able to have two players, each of whose controls are left,right, accelerate, decelerate and fire. I can envisage scenarios whereby both players are simultaneously wanting to rotate, accelerate and fire.. so 3 simultaneous keypresses each = 6 simultaneous keypresses!

My questions are:
a) Is it possible to read more than two simultaneous key presses
b) How?

Or alternatively, am I doing it wrong and do games sample keyboard over time serially (though still giving the impression of gathering the keypresses simultaneously)?

Thanks,
jbnbeeb.

Author:  tricky [ Mon Aug 04, 2014 6:45 pm ]
Post subject:  Re: How many simultaneous key presses is it possible to read

In theory, I think it is 16, but finding that many that you can get your fingers around while avoiding "aliasing" (three keys seem like 4) is hard.
Jeltron did up,down,left,right,fire,power-up for each of two players in relative comfort, so you should be fine.
IIRC, In BASIC, you need to use negative INKEY values.
In assembler, there is a routine on my carnival disk that check for as many as you like, you could hack that. I think there is a basic program that you can run on a beeb to visualise which keys are pressed to visually check for aliasing. When you press "K" to redefine the keys on Carnival, it runs a basic program that asks you to press all three keys to "OK" the selection and then rejects them if it sees 4 - sneaky eh (and unnecessary!).
You can't really test this on an emulator, as the PC usually only guarantees two simultaneous with a third that you can "roll-over" to.
I'm sure you can work it out from there, I can dig you the code out later if you can't find it or can't understand my obfuscated code ;)

Author:  tricky [ Mon Aug 04, 2014 6:46 pm ]
Post subject:  Re: How many simultaneous key presses is it possible to read

Or you could try this post I made a while ago (I thought this sounded familiar)!
http://www.retrosoftware.co.uk/forum/viewtopic.php?f=73&t=888

Author:  jbnbeeb [ Tue Aug 05, 2014 1:35 pm ]
Post subject:  Re: How many simultaneous key presses is it possible to read

Hi, thanks for the pointers Tricky . It's not so much that your code is obfuscated as it is that the code is very optimised and my poor brain can struggle to piece it all together :oops:

I've taken a look at the Carnivale code for keys as well as the Basic example. Have yet to actually have a go at putting it in to my game. I see you're changing bits in the VIA. Thus far, I've only been brave enough to do it for the "interrupt at bottom of screen" timer in my routines.

You write disable the keyboard to read the keys. Do you then have to write enable [can't see code to do that in Carnivale]

Also, what does the keys_not_prev value do?

I wonder if this relates to an idea I need to implement properly - basically I don't want to act upon the key press for a finite period of time.. i.e. once player presses Accelerate and keeps his finger on that key, I don't want to increase the speed of the plane every time the keys routine is run. I want to ignore the key press for a number of frames before acting on the keypress again.

Author:  tricky [ Tue Aug 05, 2014 1:56 pm ]
Post subject:  Re: How many simultaneous key presses is it possible to read

The not previous is so that only keys pressed this frame are counted eh fire button without auto fire.
Movement just use what is down.
I think there is a smaller example in the redefine keys code on the carnival disk.
The disable keyboard is jut me setting the keyboard bit to 0, which seems like disable to me.
To be safe, you need to disable interrupts, set the via to communicate with the keyboard (disable keyboard)!, then set the read/write lines to write the "address" of the key you want and the read the state from the most significant bit.you can just check the minus/plus bit oak I usually shift it out and in to a byte with all the other keys.
You shouldn't need to restore the via as anything using it should do its setup first; unless you have kicked the is out and don't use it for anything else like sound

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/