JOY(4)
JOY(4) โ joystick device driver ๐๐ฎ
okay bestie, sit down, grab a snack, because this is the Kernel Interfaces Manual page for the joystick device driver and it's genuinely iconic. yes, actual physical joysticks. retro. crunchy. main character energy. let's go โจ
๐ธ NAME ๐ธ
joy โ the joystick device driver ๐น๏ธ
โจ SYNOPSIS โจ
so to compile this driver into the kernel, you put these lines in your kernel configuration file:
device joy
or, if you'd rather load it as a module at boot time (honestly? valid), you drop this line into loader.conf(5):
joy_load="YES"
and in /boot/device.hints you write exactly this, no cap:
hint.joy.0.at="isa"
hint.joy.0.port="0x201"
hint.joy.1.at="isa"
hint.joy.1.port="0x201"
also you're gonna want this header, it's literally the whole vibe:
#include <sys/joystick.h>
๐ DESCRIPTION ๐
The joystick device driver lets applications read the status of the PC joystick. that's it. that's the job. slay.
heads up bestie: this device may be opened by only one process at a time. it's giving exclusive relationship. no sharing. ๐ซถ
You read the joystick status from a structure via a read() call. the structure lives in the header file and looks like this:
struct joystick {
int x; /* x position */
int y; /* y position */
int b1; /* button 1 status */
int b2; /* button 2 status */
};
Positions are typically in the range 0-2000. periodt.
๐ง One line perl example:
not me giving you a whole perl one-liner, but here she is, verbatim, she's a legend:
perl -e 'open(JOY,"/dev/joy0")||die;while(1)
{sysread(JOY,$x,16);@j=unpack("iiii",$x);print "@j\n";sleep(1);}'
๐ ioctl calls
Several ioctl() calls are also available, bestie. They take an argument of type int *.
JOY_SETTIMEOUT int *limitโ sets the time limit (in microseconds) for reading the joystick status. โ ๏ธ if you set this value too small it may prevent getting correct values for the positions โ and when that happens the positions get set to-2147483648. yes, really, that number. but honestly it can be useful if all you care about is the buttons status. buttons stay booked and busy ๐JOY_GETTIMEOUT int *limitโ gets the time limit (in microseconds) used for reading the joystick status.JOY_SET_X_OFFSET int *offsetโ sets the value that gets added to the X position when reading the joystick status.JOY_SET_Y_OFFSET int *offsetโ sets the value that gets added to the Y position when reading the joystick status.JOY_GET_X_OFFSET int *offsetโ gets the value which is added to the X position when reading the joystick status.JOY_GET_Y_OFFSET int *offsetโ gets the value which is added to the Y position when reading the joystick status.
๐ฆ TECHNICAL SPECIFICATIONS ๐ฆ
the pinout of the DB-15 connector is as follows, and yes we're doing all fifteen pins, no skipping, that would be rude to pin 8 and pin 15:
1โ XY1 (+5v)2โ Switch 13โ X1 (potentiometer #1)4โ Switch 1 (GND)5โ Switch 2 (GND)6โ Y1 (potentiometer #2)7โ Switch 28โ N.C.9โ XY2 (+5v)10โ Switch 411โ X2 (potentiometer #3)12โ Switch 3&4 (GND)13โ Y2 (potentiometer #4)14โ Switch 315โ N.C.
Pots are normally 0-150k variable resistors (0-100k sometimes), and according to the IBM technical reference, the time is given by:
Time = 24.2e-6s + 0.011e-6s * R/Ohms
math girlies rise ๐
๐ FILES ๐
/dev/joy?โ joystick device files
โญ HISTORY โญ
The joy driver appeared in FreeBSD 2.0.5. ancient. legendary. still here.
๐ AUTHORS ๐
Jean-Marc Zucconi <jmz@cabri.obs-besancon.fr> โ thank you for your service, king ๐ซถ
and that's the whole page bestie!! this one came from the Debian crew and it's dated January 23, 1995 โ yeah, 1995, we love a vintage moment ๐๐ go plug in a joystick and read some bytes, you've got this. bye!! ๐โจ
๐ฆ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms