Keyboard version of gamepad_001 -help
Oldbitcollector (Jeff)
Posts: 8,091
I'm attempting to write a gamepad_001 object that will spit out the correct bits when a key is pressed, but I've run into a little snag. For some reason it doesn't seem to work fast enough to do the job. It works, but movement is jerky.
Would someone who understands the gamepad_001 code take a look at this and tell me why it doesn't seem to move fast enough? I've tried both comboKeyboard & keyboard with the same results.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with the Protoboard? - Propeller Cookbook
Got an SD card? - PropDOS
A Living Propeller FAQ - The Propeller Wiki
(Got the Knowledge? Got a Moment? Add something today!)
Would someone who understands the gamepad_001 code take a look at this and tell me why it doesn't seem to move fast enough? I've tried both comboKeyboard & keyboard with the same results.
' Keyboard gamepad_001 driver ' AUTHOR: Jeff Ledger OBJ key : "Keyboard" ' Keyboard Driver PUB start : okay key.start(26, 27) PUB stop PUB read : joy_bits | keystroke ' NES bit encodings -- Provided as reference ' NES_RIGHT = %00000001 ' NES_LEFT = %00000010 ' NES_DOWN = %00000100 ' NES_UP = %00001000 ' NES_START = %00010000 ' NES_SELECT = %00100000 ' NES_B = %01000000 ' NES_A = %10000000 joy_bits := %00000000 keystroke := key.key if keystroke == 122 'Keyboard(Z) = A joy_bits := %10000000 if keystroke == 120 'Keyboard(X) = B joy_bits := %01000000 if keystroke == 115 'Keyboard(S) = Select joy_bits := %00100000 if keystroke == 32 'Keyboard(SPACE) = Start joy_bits := %00010000 if keystroke == 193 'Right Arrow on Keyboard joy_bits := %00000001 if keystroke == 192 'Left Arrow on Keyboard joy_bits := %00000010 if keystroke == 195 'Down Arrow on Keyboard joy_bits := %00000100 if keystroke == 194 'Up Arrow on Keyboard joy_bits := %00001000 PUB button(WhichOne) {{ Return value: true or false }} if WhichOne == read return true else return false
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with the Protoboard? - Propeller Cookbook
Got an SD card? - PropDOS
A Living Propeller FAQ - The Propeller Wiki
(Got the Knowledge? Got a Moment? Add something today!)
Comments
I think the main problem would be that the keyboard sends "keys" with a low repetition rate only. When you "poll" it too fast there will be just no key in the buffer, and KEY.KEY will return zero.
You should use KEY.KEYSTATE(k) to make it behave more like a gamepad.
BTW: Do you know LOOKUP and LOOKDOWN?
You've got me back in the book with LOOKUP/LOOKDOWN, not sure how I'd apply it to something like this, but
it does look like it would save a serious amount of code. Thanks!
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with the Protoboard? - Propeller Cookbook
Got an SD card? - PropDOS
A Living Propeller FAQ - The Propeller Wiki
(Got the Knowledge? Got a Moment? Add something today!)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
will make a real short piece of code... But this is not the program you want
JOYACTIVE is a CON set to 1 if you have one connected, otherwise it'll skip the reading and writing to pins 3-6 ( joypad controller pins )
I've even left in the F9, F10 code that I use to toggle PAL / NTSC on the fly, ( if your using any of my drivers or the original parallax drivers. PS, tvparams[noparse][[/noparse]6] is hx PAL is whatever you have NTSC set to plus 2, tvparams is mode PAL=1 NTSC=0 )
Well, maybe I overdid it now...
believe me I had thought of that, but for board compatibility, you would also have to have the entries in the correct bit order, it would therefore not be joypad & nespad compatible, unless you had those values in the CON comment section too along with the direction bits, so again, it might look tidy there, but it'd make a larger CON section, hence, I use my rolled out version. [noparse];)[/noparse]
Baggers.
There are lots of reasons to be more explicite, to make tables, etc.
Works perfectly! Seemed like something that would have already been in obex.
Too Simple?
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with the Protoboard? - Propeller Cookbook
Got an SD card? - PropDOS
A Living Propeller FAQ - The Propeller Wiki
(Got the Knowledge? Got a Moment? Add something today!)