@DATABASE Joypad
$VER: PureBasic - Joypad library (05.03.2000) © Fantaisie Software
@NODE MAIN "Joypad"

  @{b}PureBasic - Joypad library@{ub}

    The PureBasic provide a full access to joypads plugged
    in the ports 0,1,2 or 3. It supports standard joysticks
    (1 buttons) and CD32 like joypads (7 buttons).
    The lowlevel.library is used to be OS friendly so be sure
    to include it in your final package as it's only part of
    Rom3.1. The lowlevel.library is provided in the extra
    drawer of the PureBasic package.

  @{b}Commands summary:@{ub}

    @{" InitJoypad       " LINK InitJoypad}
    @{" JoypadButtons    " LINK JoypadButtons}
    @{" JoypadMovement   " LINK JoypadMovement}
    @{" PressedRawKey    " LINK PressedRawKey}

  @{b}Example:@{ub}

    @{" Joypad example   " LINK "PureBasic:Examples/Sources/Joypad.pb/Main"}

@ENDNODE


@NODE InitJoypad

    @{b}SYNTAX@{ub}
  Result.l = InitJoypad()

    @{b}FUNCTION@{ub}
  Init all the joypad environment for later  use. This command try to
  open the lowlevel.library, so if it fails it's probably this library
  which is not found. You must call this function before any other
  commands of this library.

@ENDNODE


@NODE JoypadMovement

    @{b}SYNTAX@{ub}
  Movement.w = JoypadMovemnt(Port)

    @{b}FUNCTION@{ub}
  Return the actual joypad movement (on axis X and Y) plugged in the
  specified port. Here is the list for the returned value:

    0: No activity
    1: Up
    2: Up-Right
    3: Right
    4: Down-Right
    5: Down
    6: Down-Left
    7: Left
    8: Up-Left


  Note about the ports:

    Port 0: On the Amiga. Used traditionnaly by the mouse
    Port 1: On the Amiga. Near the first port, used by a joystick
    Port 2: Need an external adaptater
    Port 3: Need an external adaptater

@ENDNODE


@NODE JoypadButtons

    @{b}SYNTAX@{ub}
  PressedButtons.l = JoypadButtons(Port)

    @{b}FUNCTION@{ub}
  Returns a long typed value with a mask of currently pressed buttons.
  Any number of buttons can be pressed at the same time.

  To know which button is actually pressed, you must use the following
  constants (self-explanatory) which are declared in the AmigaOS_Small
  resident file (loaded automatically at the start of PureBasic):

  #PB_JOYPAD_BUTTON1
  #PB_JOYPAD_BUTTON2
  #PB_JOYPAD_BUTTON3
  #PB_JOYPAD_BUTTON4
  #PB_JOYPAD_BUTTON5
  #PB_JOYPAD_BUTTON6
  #PB_JOYPAD_BUTTON7

  And you have to perform some tests like:

    If PressedButtons & #PB_JOYPAD_BUTTON1
      PrintN("Button 1 is pushed !")
      B1 = 1
    EndIf

    If PressedButtons & #PB_JOYPAD_BUTTON7
      PrintN("Button 7 is pushed !")
      B7 = 1
    EndIf


    If B1=1 And B7=1
      PrintN("Buttons 1 & 7 are pushed at the same time !")
    EndIf

@ENDNODE


@NODE PressedRawKey

    @{b}SYNTAX@{ub}
  Key = PressedRawKey()

    @{b}STATEMENT@{ub}
  Return the raw code of the key which is actually pushed or NULL
  if no key are pushed. Rawkey code are the same on any Amiga,
  indepedantly of the used keyboard. Rawkey are not ASCII values.

@ENDNODE
