View Full Version : Programming for a Gameport
10-27-2002, 08:54 PM
Yet another crazy idea from team 810. this time, instead of the serial port, we need help with the gameport. my friend found out how to hook up two joy sticks to the gameport, and has some crazy idea for a program. i can't say what it is, for that will ruin the surprise.
basically, what i need is a simple way (prefereablly just a console app) that can read the gameport. something similar to the serial white paper (the author's name escapes me at the moment) would help a lot. we do know how to make it work if we were to use two serial ports, but we're not sure if that's possible (i think it is, but i can't be sure).
so, if anyone has any information on how to use the gameport in a C++ program, or how to set up a joystick on a serial port (i'm not sure how you would read back analog values), i'd be very thankful.
10-28-2002, 12:46 AM
OK, you've got a few options. Let me know which one appeals to you and I'll write another paper (the serial one was mine).
Option 1: DirectX. Advantages: Industry standard. Can support more axes/buttons than the next method. Disadvantages: a lot of overhead for setting up DirectInput, only works under Windows
Option 2: Assembly!!!!!! Yup, you can do it straight from assembly. Advantages: none of the DirectX stuff, can be used w/o windows. Disadvantages: it's assembly. 'nuf said.
In all honesty, assembly isn't really that bad, especially if you have someone tell you exactly what to write in your code--it's the method I'd recomend for a simple project like this.
However, as I said before DirectInput is the industry standard nowadays, so if you want to learn it for the pure sake of learning some introductory DirectX, I'd be happy to write a paper on that too.
As for doing it through a serial port, it just isn't going to happen. A joystick uses a different pin for each axis/set of buttons, but a serial port has only one pin for data.
My Linux box just died a slow, painful death with lots of pretty colors, so I'm off to remedy that (and maybe sleep?), but let me know which you'd prefer.
(I could have the assembly one done in about 20 mins. The DirectInput might take a few days)
10-28-2002, 07:10 PM
assembly or directx?
i was kind of hoping there'd be a nice happy thing like the serial port (the readfile thing). i finally understand that now :).
i'm mostly a C++/PBASIC programmer, but i guess i could learn either assembly or directx (isn't that a library extension onto C++ or something like that?). one thing though, i believe like the dashboard program i made, it will be creating a text file that is read into a flash program. that means there needs to be enough resources to let the flash program work (which there should be either way if we use a good computer, but i believe we'll be using this at school, and well, the school computers pretty much suck :p). if you can write something up in assembly in 20 minutes, then it never hurts to try. if you can find the directx stuff it'd be interesting to try, but don't kill yourself trying to do it. and thanks for the help ;).
10-28-2002, 08:26 PM
i second that motion that school computers suck. Board of Ed in NYC stinks all together and needs to start chippin and gettin us robotics schools something decent to work with other then the old 486's / penitium 100's and pros etc. how does a 486 make it in the year 2002 must create thread on this. cya
10-28-2002, 08:31 PM
I believe that a program using assembly will not work in any NT based operating system(2000 and XP). I could be wrong, though.
10-28-2002, 09:33 PM
Well, I tried the assembly stuff I had lying around and it worked fine under DOS but gave a BSOD under Windows. I know I've asked this before, but what compiler are you using? If it's VC++, I think I have a fairly painless solution for you. Otherwise, things could get difficult. Also, do you normally use the Win32 SDK (with Windows, WndProc, etc)? If not, this could get very interesting very fast.
If you want to see some DirectInput code, it's included in RoboEmu 1.03(?) and higher in order to allow binding to real joysticks.
10-28-2002, 10:43 PM
OK, I finally figured this out w/o DirectX or assembly! Here's the code you need:
//no driver installed
//invalid parameter passed
//joystick ID is invalid
//joystick is not pluged in
At this point, the joyInfo1 struct contains everything you could ever want. Here's a quick rundown of the important fields:
dwXpos: the x pos
dwYpos: the y pos
dwZpos: the z pos
dwButtons: All 32 buttons
In order to access an individual button, use the JOY_BUTTON1, JOY_BUTTON2, etc as a bit mask. I.e:
bool button1=(joyInfo1.dwButtons & JOY_BUTTON1 > 0 ? 1 : 0)
In order to use this stuff, you'll have to tell your compiler to link in the winmm.lib library.
Calibration comes from the Gaming Options control panel, but you'll probably want to check the values yourself just to make sure.
Finally, to access joystick #2, replace JOYSTICKID1 with JOYSTICKID2 in the joyGetPosEx function.
Anyway, I hope this helps. Let me know if something goes wrong or if you want some more detail/additional options. Alternatively, check out the MSDN library entry for JOYINFOEX.
10-30-2002, 08:37 PM
Anybody had a chance to try this yet? If it works on other peoples' systems, I'll write up a formal white paper, but I want to make sure it's going to work first. Anyway, let me know if you have questions or want more info.
11-01-2002, 11:56 AM
I haven't had a chance to try it yet because I'm in the middle of installing gentoo on my computer, but i should be able to give it a whirl sometime this weekend. If it works i'll tell you, but i'll need a bit of time to try it out. thanks for the help.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.