port gamepad API

Still haven't tested it. Preliminary thoughts?
i see a couple of problems here. what happens if the user plugs in 3 joysticks sequentially, now the state is -
joystick1 - index 1; joystick2 - index2; joystick3 - index3 ; numjoysticks - 3

 and then he remove joystick1 and joystick2 and then adds joystick1 again - now  the state is -
joystick1 - index1, joystick3 - index3 numjoysticks - 2

.. the for loop never inits joystick3