From: Jos v.d.V. <jo...@us...> - 2006-05-27 15:13:48
|
Update of /cvsroot/win32forth/win32forth/src/lib In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv16558/src/lib Added Files: Joystick.f Log Message: Jos: Added joystick support. --- NEW FILE: Joystick.f --- Anew -joystick.f INTERNAL WinLibrary WINMM.DLL EXTERNAL Needs ExtStruct.f :struct joycapsa WORD wMid; /* manufacturer ID */ WORD wPid; /* product ID */ MAXPNAMELEN Field: szPname /* product name (NULL terminated string) */ UINT wXmin; /* minimum x position value */ UINT wXmax; /* maximum x position value */ UINT wYmin; /* minimum y position value */ UINT wYmax; /* maximum y position value */ UINT wZmin; /* minimum z position value */ UINT wZmax; /* maximum z position value */ UINT wNumButtons; /* number of buttons */ UINT wPeriodMin; /* minimum message period when captured */ UINT wPeriodMax; /* maximum message period when captured */ UINT wRmin; /* minimum r position value */ UINT wRmax; /* maximum r position value */ UINT wUmin; /* minimum u (5th axis) position value */ UINT wUmax; /* maximum u (5th axis) position value */ UINT wVmin; /* minimum v (6th axis) position value */ UINT wVmax; /* maximum v (6th axis) position value */ UINT wCaps; /* joystick capabilites */ UINT wMaxAxes; /* maximum number of axes supported */ UINT wNumAxes; /* number of axes in use */ UINT wMaxButtons; /* maximum number of buttons supported */ maxpnamelen Field: szRegKey /* registry key */ max_joystickoemvxdname Field: szOEMVxD /* OEM VxD in use */ ;struct sizeof joycapsa mkstruct: *lpjoycapsa :struct joyinfo UINT wXpos /* x position */ UINT wYpos /* y position */ UINT wZpos /* z position */ UINT wButtons /* button states */ ;struct sizeof joyinfo mkstruct: *lpjoyinfo :struct joyinfoex DWORD dwSize; /* size of structure */ DWORD dwFlags; /* flags to indicate what to return */ DWORD dwXpos; /* x position */ DWORD dwYpos; /* y position */ DWORD dwZpos; /* z position */ DWORD dwRpos; /* rudder/4th axis position */ DWORD dwUpos; /* 5th axis position */ DWORD dwVpos; /* 6th axis position */ DWORD dwButtons; /* button states */ DWORD dwButtonNumber; /* current button number pressed */ DWORD dwPOV; /* point of view state */ DWORD dwReserved1; /* reserved for communication between winmm & driver */ DWORD dwReserved2; /* reserved for future expansion */ ;struct sizeof joyinfoex mkstruct: *lpjoyinfoex : GetJoystickInfo ( id -- x y z buttons ) *lpjoyinfo [ sizeof joyinfo ] literal erase *lpjoyinfo swap Call joyGetPos drop struct, *lpjoyinfo joyinfo wXpos @ struct, *lpjoyinfo joyinfo wYpos @ struct, *lpjoyinfo joyinfo wZpos @ struct, *lpjoyinfo joyinfo wButtons @ ; 4 constant MaxJoysticks : FindFirstJoyStick ( - *lpjoycapsa ID ) \ ID should be <= MaxJoysticks *lpjoycapsa [ sizeof JOYCAPSA ] literal 2dup erase swap MaxJoysticks 0 do 2dup i Call joyGetDevCaps 0= if nip I leave then loop ; \s Test and demo: : JoystickTest ( - ) \ Move the joystick and press some buttons FindFirstJoyStick nip dup MaxJoysticks < if begin cr dup GetJoystickInfo dup>r . . . . 20 ms r> 1 = until \ the fire button has been pressed drop ." The fire button has been pressed." else cr ." No joystick found." then ; JoystickTest \s |