IANAP, but I did find this white paper:
http://qin.laya.com/first/joystick.html
The code is in PBASIC, but you should be able to adapt it.
Hope this helps!
--Billfred
PS: Rabid acceleration sometimes just comes with the territory. You should've seen it when I hit the sticks on Ockham.