Skip to main content

Gamepads

Besides keyboard input, the Hybrix virtual machine also features two gamepad input devices. A gamepad has four buttons and a directional controller. The directional controller can be either a D-pad or an analog stick.

You can connect real gamepads to your computer and use them with Hybrix, as long as the device is compatible with the web browser's Gamepad API. Hybrix officially recommends the 8BitDo SN30 Pro gamepad. Another option is to connect a game controller from a popular console such as PlayStation, Xbox, or Nintendo Switch, which is often possible using Bluetooth or USB.

A typical gamepad device

A typical gamepad with a D-pad and two analog sticks (gray circles)

Keyboard mappings

Real gamepads get mapped to the IO::GAMEPADS[] array according to the order in which they were connected.

If there are less than 2 real gamepads connected, you can use keyboard mappings to simulate a "virtual" gamepad. The "CONFIGURE CONTROLLERS" panel provides three choices:

GamepadKeyset A (PC)Keyset A (Mac)Keyset BKeyset C
Button ASHIFTSHIFT (⇧)1N
Button BZZ2M
Button CXX3,
Button DCTRLOPTION (⌥)4.
UpUPUPWUP
DownDOWNDOWNADOWN
LeftLEFTLEFTSLEFT
RightRIGHTRIGHTDRIGHT

Keyset A is most convenient for a single person. Keyset B and Keyset C allow two people to play together using the keyboard.

Currently the individual keys are not configurable, but a settings page may be added in the future.

Directional controller

IO_GAMEPAD::X and IO_GAMEPAD::Y report the state of the directional controller. The value is approximately zero when the controller is in its center position; otherwise, it ranges from -1,023 to 1,023 with negative corresponding to left or up.

These values are typically measured imprecisely. Programs that need highly accurate input often implement a "calibration" screen. For digital controllers, it's recommended to consider the D-pad to be "pressed" if the value is less than -512 or greater than 512.

Many controllers have both a D-pad and an analog stick. In this case, Hybrix uses both inputs: IO_GAMEPAD::X and IO_GAMEPAD::Y will report the analog stick whenever the D-pad is not being pressed.

Framework API

For beginners, the Hybrix framework provides a simplified GAMEPAD module. You must call ENGINE::THINK() regularly to update its fields:

MODULE GAMEPAD
VAR LEFT: BOOL
VAR RIGHT: BOOL
VAR UP: BOOL
VAR DOWN: BOOL
VAR BUTTON_A: BOOL
VAR BUTTON_B: BOOL
VAR BUTTON_C: BOOL
VAR BUTTON_D: BOOL
END MODULE

I/O definitions

CLASS IO_HAND_CONTROLLER # SIZE 8
# 0 = DISABLED
# 1 = GAMEPAD
# 16 = MOUSE (X AND Y ARE ROLLING COUNTERS)
VAR KIND: BYTE

# +1 = A / MOUSE MAIN BUTTON
# +2 = B / MOUSE MIDDLE BUTTON
# +4 = C / MOUSE SECONDARY BUTTON
# +8 = D
VAR BUTTONS: BYTE

# GAMEPAD: (LEFT) -1023 .. +1023 (RIGHT)
VAR X: PAIR

# GAMEPAD: (UP) -1023 .. +1023 (DOWN)
VAR Y: PAIR

VAR RESERVED: PAIR
END CLASS

MODULE IO
. . .
INSET GAMEPAD_0: IO_HAND_CONTROLLER LOCATED AT $D0_0060
INSET GAMEPAD_1: IO_HAND_CONTROLLER LOCATED AT $D0_0068
INSET GAMEPADS: IO_HAND_CONTROLLER[INSET 2] LOCATED AT $D0_0060
. . .
END MODULE