News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Joypad

Started by Farabi, October 10, 2008, 02:42:23 AM

Previous topic - Next topic

Farabi

How to get joypad input? I tried to use WinMM library but got no luck.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

MichaelW

I don't know what you may have tried, and I have no way to test this, but it might provide some useful information.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
    include \masm32\include\winmm.inc
    includelib \masm32\lib\winmm.lib
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      jix JOYINFOEX <>
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    mov jix.dwSize, SIZEOF JOYINFOEX
    invoke joyGetNumDevs
    .IF eax == 0
      print "no driver",13,10
    .ELSE
      push eax
      print "number of devices supported = "
      pop eax
      print ustr$(eax),13,10
      invoke joyGetPosEx, JOYSTICKID1, ADDR jix
      SWITCH eax
        CASE JOYERR_NOERROR
          print "JOYSTICKID1 present",13,10
        CASE MMSYSERR_NODRIVER
          print "JOYSTICKID1 no driver",13,10
        CASE MMSYSERR_INVALPARAM
          print "JOYSTICKID1 invalid parameter",13,10
        CASE MMSYSERR_BADDEVICEID
          print "JOYSTICKID1 bad device ID",13,10
        CASE JOYERR_UNPLUGGED
          print "JOYSTICKID1 not connected",13,10
        CASE JOYERR_PARMS
          print "JOYSTICKID1 bad device ID",13,10
        DEFAULT
          print "JOYSTICKID1 unexpected error",13,10
      ENDSW
      invoke joyGetPosEx, JOYSTICKID2, ADDR jix
      SWITCH eax
        CASE JOYERR_NOERROR
          print "JOYSTICKID2 present",13,10
        CASE MMSYSERR_NODRIVER
          print "JOYSTICKID2 no driver",13,10
        CASE MMSYSERR_INVALPARAM
          print "JOYSTICKID2 invalid parameter",13,10
        CASE MMSYSERR_BADDEVICEID
          print "JOYSTICKID2 bad device ID",13,10
        CASE JOYERR_UNPLUGGED
          print "JOYSTICKID2 not connected",13,10
        CASE JOYERR_PARMS
          print "JOYSTICKID2 bad device ID",13,10
        DEFAULT
          print "JOYSTICKID2 unexpected error",13,10
      ENDSW
    .ENDIF

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

Farabi

I've made it working before, but your example make it more cleare. Thanks.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

MichaelW

#3
If the app detected a joystick present, then you should be able to call joyGetPosEx from a loop to determine if it can detect button presses and motion. For example, assuming that JOYSTICKID1 is present:

    ;-----------------------------------------
    ; Save current button state and position.
    ;-----------------------------------------

    mov ebx, jix.dwButtons
    mov esi, jix.dwXpos
    mov edi, jix.dwYpos

    .WHILE 1

      invoke joyGetPosEx, JOYSTICKID1, ADDR jix

      ;------------------------------------------
      ; Display values only if they changed from
      ; the last loop, then save the new value.
      ;------------------------------------------

      .IF jix.dwButtons != ebx
        print "dwButtons : "
        print uhex$(jix.dwButtons),13,10
        mov ebx, jix.dwButtons
      .ENDIF

      .IF jix.dwXpos != esi
        print "dwXpos    : "
        print str$(jix.dwXpos),13,10
        mov esi, jix.dwXpos
      .ENDIF

      .IF jix.dwYpos != edi
        print "dwYpos    : "
        print str$(jix.dwYpos),13,10
        mov edi, jix.dwYpos
      .ENDIF

    .ENDW

eschew obfuscation