DEVICE Functions

Functions for interfacing with external devices such as game controllers, mice, and Wii controllers.

Gamepad Support

DEVICE(GAMEPAD channel, funct)

Returns data from a USB PS3 or PS4 controller.

funct is a 1 or 2 letter code indicating the information to return as follows: LX the position of the analog left joystick x axis LY the position of the analog left joystick y axis RX the position of the analog right joystick x axis RY the position of the analog right joystick y axis GX the reading from the X axis gyro (where supported) GY the reading from the Y axis gyro (where supported) GZ the reading from the Z axis gyro (where supported) AX the reading from the X axis accelerometer (where supported) AY the reading from the Y axis accelerometer (where supported) AZ the reading from the Z axis accelerometer (where supported) L the position of the analog left button R the position of the analog right button B a bitmap of the state of all the buttons. A bit will be set to 1 if the button is pressed.

T        the ID code of the controller

The button bitmap is as follows: BIT 0 Button R/R1 BIT 1 Button start/options BIT 2 Button home BIT 3 Button select/share BIT 4 Button L/L1 BIT 5 Button down cursor BIT 6 Button right cursor BIT 7 Button up cursor BIT 8 Button left cursor BIT 9 Right shoulder button 2/R2 BIT 10 Button x/triangle BIT 11 Button a/circle BIT 12 Button y/square BIT 13 Button b/cross BIT 14 Left should button 2/L2 BIT 15 Touchpad

Mouse Support

DEVICE(MOUSE channel, funct)

Returns data from a mouse connected via channel.

A PS2 mouse is always allocated channel 2. Normally a USB mouse is also allocated to channel 2 but this can vary. See MM.INFO(USB n) for more information.

Wii Controller Support

DEVICE(WII [CLASSIC] funct)

Returns data from a Wii Classic controller.

funct is a 1 or 2 letter code indicating the information to return as follows: LX the position of the analog left joystick x axis LY the position of the analog left joystick y axis RX the position of the analog right joystick x axis RY the position of the analog right joystick y axis L the position of the analog left button R the position of the analog right button B a bitmap of the state of all the buttons. A bit will be set to 1 if the button is pressed.

T        the ID code of the controller - should be hex &HA4200101

The button bitmap is as follows: BIT 0 Button R BIT 1 Button start BIT 2 Button home BIT 3 Button select BIT 4 Button L BIT 5 Button down cursor BIT 6 Button right cursor BIT 7 Button up cursor BIT 8 Button left cursor BIT 9 Button ZR BIT 10 Button x BIT 11 Button a BIT 12 Button y BIT 13 Button b BIT 14 Button ZL

DEVICE(WII NUNCHUCK funct)

Returns data from a Wii Nunchuck controller.

funct is a 1 or 2 letter code indicating the information to return as follows: AX the x axis acceleration AY the y axis acceleration AZ the z axis acceleration JX the position of the joystick x axis JY the position of joystick y axis C the state of the C button Z the state of the Z button T the ID code of the controller - should be hex &HA4200000

Device Utilities

FIELD$( string1, nbr, string2 [, string3] )

Returns a particular field in a string with the fields separated by delimiters.

Note that a space character cannot be used as a delimeter.

nbr is the field to return (the first is nbr 1). string1 is the string to search and string2 is a string holding the delimiters (more than one can be used). The space character may not be used as a delimiter.

string3 is optional and if specified will include characters that are used to quote text in string1 (ie, quoted text will not be searched for a delimiter).

For example: S$ = "foo, boo, zoo, doo" r$ = FIELD$(s$, 2, ",") will result in r$ = "boo". While: s$ = "foo, 'boo, zoo', doo" r$ = FIELD$(s$, 2, ",", "'") will result in r$ = "boo, zoo".

FLAG(n%)

Returns the value (0 or 1) of the bit n% (0-63) in the system flag register.

See also MM.FLAGS and the FLAG and FLAGS commands

FORMAT$( nbr [, fmt$] )

Will return a string representing nbr formatted according to the specifications in the string fmt$.

The format specification starts with a % character and ends with a letter.

Anything outside of this construct is copied to the output as is.

The structure of a format specification is: % [flags] [width] [.precision] type Where flags can be: - Left justify the value within a given field width 0 Use 0 for the pad character instead of space + Forces the + sign to be shown for positive numbers space Causes a positive value to display a space for the sign. Negative values still show the – sign width is the minimum number of characters to output, less than this the number will be padded, more than this the width will be expanded.

precision specifies the number of fraction digits to generate with an e, or f type or the maximum number of significant digits to generate with a g type and defaults to 4 digits. If specified, the precision must be preceded by a dot (.).

GETSCANLINE

This will report on the line that is currently being drawn on the VGA monitor in the range of 0 to 525. This is irrespective of the current MODE.

Using this to time updates to the screen can avoid timing effects caused by updates while the screen is being updated.

The first visible line will return a value of 0. Any line number above 479 is in the frame blanking period.