[AD] Joystick driver for BeOS |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hi to all.
Here's a joystick driver for BeOS, plus a fix which adds the BeOS os_type
variable; these diffs are taken from the current CVS Allegro version, so don't
worry, you can apply them without modifications (bjoyapi.cpp is a new file by
the way).
Can someone tell me why the X DGA video memory is cleared by default under
Linux? It takes some seconds to complete, and it's a bit annoying. Wouldn't it
be better if it's deactivated by default? Just a suggestion.
Thanks!
--
Angelo Mottola
a.mottola@xxxxxxxxxx
71a72,75
> int be_joy_init(void);
> void be_joy_exit(void);
> int be_joy_poll(void);
>
42c42
< //AL_VAR(JOYSTICK_DRIVER, joystick_beos);
---
> AL_VAR(JOYSTICK_DRIVER, joystick_beos);
78c78
< /* { JOYSTICK_BEOS, &joystick_beos, TRUE }, */
---
> { JOYSTICK_BEOS, &joystick_beos, TRUE },
56a57,61
> # BeOS graphics drivers:
> #
> # BFS - Fullscreen
> # BFSS - Fullscreen safe
> #
202c207,212
<
---
> #
> # BeOS digital sound drivers:
> #
> # 0 - none
> # BDIG - BeOS digital sound system
> #
401a412,417
> joytype =
>
>
>
> # BeOS only: joystick device port name (as reported on system joystick prefs)
> joystick_device =
95a96
> #define OSTYPE_BEOS AL_ID('B','E','O','S')
11c11
< * Stuff for BeOS.
---
> * Joystick driver for BeOS.
13c13
< * By Jason Wilkins.
---
> * By Angelo Mottola.
19a20
> #include "allegro/aintbeos.h"
23c24
< #endif
---
> #endif
25c26,39
< //JOYSTICK_DRIVER joystick_beos;
---
> JOYSTICK_DRIVER joystick_beos =
> {
> JOYSTICK_BEOS, // int id;
> empty_string, // AL_CONST char *name;
> empty_string, // AL_CONST char *desc;
> "BeOS joystick", // AL_CONST char *ascii_name;
> be_joy_init, // AL_METHOD(int, init, (void));
> be_joy_exit, // AL_METHOD(void, exit, (void));
> be_joy_poll, // AL_METHOD(int, poll, (void));
> NULL, // AL_METHOD(int, save_data, (void));
> NULL, // AL_METHOD(int, load_data, (void));
> NULL, // AL_METHOD(AL_CONST char *, calibrate_name, (int n));
> NULL // AL_METHOD(int, calibrate, (int n));
> };
/* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
* /\____/
* \_/__/
*
* Joystick driver routines for BeOS.
*
* By Angelo Mottola.
*
* See readme.txt for copyright information.
*/
#include "bealleg.h"
#include "allegro/aintern.h"
#include "allegro/aintbeos.h"
#ifndef ALLEGRO_BEOS
#error something is wrong with the makefile
#endif
static BJoystick *be_joy = NULL;
static int32 num_devices, num_axes, num_hats, num_buttons;
static int16 *axis_value = NULL;
static int8 *hat_value = NULL;
/* be_joy_init:
* Initializes BeOS joystick driver.
*/
extern "C" int be_joy_init(void)
{
const char *device_config;
char device_name[B_OS_NAME_LENGTH + 1];
static char desc[30];
static char name_x[10];
static char name_y[10];
static char name_stick[] = "stick";
static char name_hat[] = "hat";
static char name_throttle[] = "throttle";
static char name_hat_lr[] = "left/right";
static char name_hat_ud[] = "up/down";
static char *name_b[] =
{"B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8"};
int32 i, j, stick;
BString *temp;
char *name;
temp = new BString;
be_joy = new BJoystick;
num_devices = be_joy->CountDevices();
/* no joysticks available */
if (num_devices == 0) {
goto cleanup;
}
/* Scans if the joystick_device config variable is set */
device_config = get_config_string("joystick", "joystick_device", "");
/* Let's try to open selected device */
if ((device_config[0] == '\0') || (be_joy->Open(device_config) < 0)) {
/* ok, let's try to open first available device */
if (be_joy->GetDeviceName(0, device_name) != B_OK) {
goto cleanup;
}
if (be_joy->Open(device_name) == B_ERROR) {
goto cleanup;
}
}
be_joy->GetControllerName(temp);
name = temp->LockBuffer(0);
strncpy(desc, name, 29);
temp->UnlockBuffer();
joystick_beos.desc = desc;
num_axes = be_joy->CountAxes();
num_hats = be_joy->CountHats();
num_buttons = be_joy->CountButtons();
if (num_axes) {
axis_value = (int16 *)malloc(sizeof(int16) * num_axes);
hat_value = (int8 *)malloc(sizeof(int8) * num_axes);
}
num_joysticks = be_joy->CountSticks();
for (i = 0; i < num_joysticks; i++) {
joy[i].flags = JOYFLAG_DIGITAL | JOYFLAG_ANALOGUE;
stick = 0;
if (num_axes >= 2) {
joy[i].stick[0].flags = JOYFLAG_DIGITAL | JOYFLAG_ANALOGUE | JOYFLAG_SIGNED;
joy[i].stick[0].num_axis = 2;
joy[i].stick[0].name = name_stick;
be_joy->GetAxisNameAt(0, temp);
name = temp->LockBuffer(0);
strncpy(name_x, name, 9);
temp->UnlockBuffer();
joy[i].stick[0].axis[0].name = name_x;
be_joy->GetAxisNameAt(1, temp);
name = temp->LockBuffer(0);
strncpy(name_y, name, 9);
temp->UnlockBuffer();
joy[i].stick[0].axis[1].name = name_y;
stick++;
for (j = 2; j < num_axes; j++) {
joy[i].stick[stick].flags = JOYFLAG_DIGITAL | JOYFLAG_ANALOGUE | JOYFLAG_UNSIGNED;
joy[i].stick[stick].num_axis = 1;
joy[i].stick[stick].axis[0].name = "";
joy[i].stick[stick].name = name_throttle;
stick++;
}
for (j = 0; j < num_hats; j++) {
joy[i].stick[stick].flags = JOYFLAG_DIGITAL | JOYFLAG_SIGNED;
joy[i].stick[stick].num_axis = 2;
joy[i].stick[stick].axis[0].name = name_hat_lr;
joy[i].stick[stick].axis[1].name = name_hat_ud;
joy[i].stick[stick].name = name_hat;
stick++;
}
}
joy[i].num_sticks = stick;
joy[i].num_buttons = num_buttons;
for (j = 0; j < num_buttons; j++)
joy[i].button[j].name = name_b[j];
}
delete temp;
be_joy_poll();
return 0;
cleanup: {
delete temp;
delete be_joy;
return -1;
}
}
/* be_joy_exit:
* Closes joystick driver.
*/
extern "C" void be_joy_exit(void)
{
if (be_joy) {
delete be_joy;
be_joy = NULL;
}
if (axis_value) {
free(axis_value);
axis_value = NULL;
}
if (hat_value) {
free(hat_value);
hat_value = NULL;
}
}
/* be_joy_poll:
* Polls joysticks status.
*/
extern "C" int be_joy_poll(void)
{
int32 i, j, k;
int32 axis, hat, stick, buttons;
be_joy->Update();
for (i = 0; i < num_joysticks; i++) {
axis = hat = stick = 0;
be_joy->GetAxisValues(axis_value, i);
for (j = 0; j < joy[i].num_sticks; j++) {
for (k = 0; k < joy[i].stick[j].num_axis; k++) {
axis_value[axis] /= 256;
if (joy[i].stick[j].flags & JOYFLAG_SIGNED)
joy[i].stick[j].axis[k].pos = axis_value[axis];
else
joy[i].stick[j].axis[k].pos = axis_value[axis] + 128;
joy[i].stick[j].axis[k].d1 = (axis_value[axis] < -64 ? 1 : 0);
joy[i].stick[j].axis[k].d2 = (axis_value[axis] > 64 ? 1 : 0);
axis++;
}
stick++;
if (axis >= num_axes) break;
}
for (j = 0; j < num_hats; j++) {
switch (hat_value[hat]) {
case 0: /* centered */
joy[i].stick[stick].axis[0].pos = 0;
joy[i].stick[stick].axis[0].d1 = 0;
joy[i].stick[stick].axis[0].d2 = 0;
joy[i].stick[stick].axis[1].pos = 0;
joy[i].stick[stick].axis[1].d1 = 0;
joy[i].stick[stick].axis[1].d2 = 0;
break;
case 1: /* up */
joy[i].stick[stick].axis[0].pos = 0;
joy[i].stick[stick].axis[0].d1 = 0;
joy[i].stick[stick].axis[0].d2 = 0;
joy[i].stick[stick].axis[1].pos = 128;
joy[i].stick[stick].axis[1].d1 = 0;
joy[i].stick[stick].axis[1].d2 = 1;
case 2: /* up and right */
joy[i].stick[stick].axis[0].pos = 128;
joy[i].stick[stick].axis[0].d1 = 0;
joy[i].stick[stick].axis[0].d2 = 1;
joy[i].stick[stick].axis[1].pos = 128;
joy[i].stick[stick].axis[1].d1 = 0;
joy[i].stick[stick].axis[1].d2 = 1;
case 3: /* right */
joy[i].stick[stick].axis[0].pos = 128;
joy[i].stick[stick].axis[0].d1 = 0;
joy[i].stick[stick].axis[0].d2 = 1;
joy[i].stick[stick].axis[1].pos = 0;
joy[i].stick[stick].axis[1].d1 = 0;
joy[i].stick[stick].axis[1].d2 = 0;
case 4: /* down and right */
joy[i].stick[stick].axis[0].pos = 128;
joy[i].stick[stick].axis[0].d1 = 0;
joy[i].stick[stick].axis[0].d2 = 1;
joy[i].stick[stick].axis[1].pos = -128;
joy[i].stick[stick].axis[1].d1 = 1;
joy[i].stick[stick].axis[1].d2 = 0;
case 5: /* down */
joy[i].stick[stick].axis[0].pos = 0;
joy[i].stick[stick].axis[0].d1 = 0;
joy[i].stick[stick].axis[0].d2 = 0;
joy[i].stick[stick].axis[1].pos = -128;
joy[i].stick[stick].axis[1].d1 = 1;
joy[i].stick[stick].axis[1].d2 = 0;
case 6: /* down and left */
joy[i].stick[stick].axis[0].pos = -128;
joy[i].stick[stick].axis[0].d1 = 1;
joy[i].stick[stick].axis[0].d2 = 0;
joy[i].stick[stick].axis[1].pos = -128;
joy[i].stick[stick].axis[1].d1 = 1;
joy[i].stick[stick].axis[1].d2 = 0;
case 7: /* left */
joy[i].stick[stick].axis[0].pos = -128;
joy[i].stick[stick].axis[0].d1 = 1;
joy[i].stick[stick].axis[0].d2 = 0;
joy[i].stick[stick].axis[1].pos = 0;
joy[i].stick[stick].axis[1].d1 = 0;
joy[i].stick[stick].axis[1].d2 = 0;
case 8: /* up and left */
joy[i].stick[stick].axis[0].pos = -128;
joy[i].stick[stick].axis[0].d1 = 1;
joy[i].stick[stick].axis[0].d2 = 0;
joy[i].stick[stick].axis[1].pos = 128;
joy[i].stick[stick].axis[1].d1 = 0;
joy[i].stick[stick].axis[1].d2 = 1;
}
hat++;
stick++;
}
buttons = be_joy->ButtonValues(i);
for (j = 0; j < num_buttons; j++) {
joy[i].button[j].b = buttons & 1;
buttons >>= 1;
}
}
}
165a166,167
> os_type = OSTYPE_BEOS;
>
45c45
< LFLAGS = -lbe -lgame -g
---
> LFLAGS = -lbe -lgame -ldevice -g
54c54
< LFLAGS = -lbe -lgame -pg
---
> LFLAGS = -lbe -lgame -ldevice -pg
63c63
< LFLAGS = -lbe -lgame -s
---
> LFLAGS = -lbe -lgame -ldevice -s
65c65
< LFLAGS = -lbe -lgame
---
> LFLAGS = -lbe -lgame -ldevice
191a192
> src/beos/bjoyapi.cpp \
22,24c22,24
< Status: It compiles for Intel R4,
< the keyboard and system drivers
< are almost 100 percent.
---
> Status: It compiles for Intel R4 & R5. Port is almost complete, but it
> needs beta testing; still missing a windowed graphics driver and a midi
> driver.
32c32,35
< BeOS Intel R4 comes with everything you need.
---
> BeOS Intel R4 and R5 Pro Edition come with everything you need. If you
> have BeOS Intel R5 Personal Edition, you require the development tools;
> these can be found on the Be homepage at http://www.be.com.
>
40d42
<