mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-10-14 01:49:05 +03:00
Enable specifying joystick device
Before this, value of joy_device config parameter (-devjoy in command line) was ignored. After this, this parameter will take an integer value and will be used as the device_index argument of SDL_JoystickOpen(). This also removes obsolete doc/README.joystick.
This commit is contained in:
+1
-1
@@ -223,7 +223,7 @@
|
||||
-Ms? : Sequencer device (?:device number)
|
||||
-M0 : disable midi
|
||||
|
||||
-devjoy name : joystick のデバイス名を name にします
|
||||
-devjoy n : n 番目の joystick のデバイスを使用します。
|
||||
|
||||
-version : バージョン情報を表示します。
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
Joystick の使い方について
|
||||
|
||||
現在 linux の kernel 2.2.x 以降の Joystick インターフェイスに対応して
|
||||
います。対応環境をおもちの方は configure --enable-joy としてコンパイル
|
||||
コンパイルして下さい。
|
||||
|
||||
Joystick のデバイス名はデフォルトでは /dev/js0 で、実行時に -devjoy
|
||||
オプションで指定するか、.xsys35rc ファイルで joy_device のエントリー
|
||||
に加えて下さい。
|
||||
|
||||
他環境での動作報告、パッチなどお待ちしています。宛先は以下の両方に
|
||||
お願いします。
|
||||
|
||||
chikama (masaki-c@is.aist-nara.ac.jp)
|
||||
linux 版の作者の村田さん(fmurata@p1.tcnet.ne.jp)
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "portab.h"
|
||||
|
||||
extern void joy_set_devicename(char *);
|
||||
extern void joy_set_deviceindex(int);
|
||||
extern int joy_open(void);
|
||||
extern void joy_close(void);
|
||||
extern int joy_getinfo(void);
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
#include "joystick.h"
|
||||
#include "portab.h"
|
||||
|
||||
void joy_set_devicename(char *name) {
|
||||
void joy_set_deviceindex(int index) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+23
-29
@@ -31,30 +31,35 @@
|
||||
#include "joystick.h"
|
||||
#include "sdl_core.h"
|
||||
|
||||
static int joy_axes, joy_buttons;
|
||||
static char *dev_joy = NULL;
|
||||
static boolean joy_enable=TRUE;
|
||||
static int device_index = -1;
|
||||
static SDL_Joystick *js;
|
||||
|
||||
void joy_set_devicename(char *name) {
|
||||
if( dev_joy ) free(dev_joy);
|
||||
dev_joy=strdup(name);
|
||||
static boolean joy_open_index(int index) {
|
||||
js = SDL_JoystickOpen(index);
|
||||
if (!js)
|
||||
return FALSE;
|
||||
|
||||
const char *name = SDL_JoystickName(js);
|
||||
int axes = SDL_JoystickNumAxes(js);
|
||||
int buttons = SDL_JoystickNumButtons(js);
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
printf("SDL joystick '%s' %d axes %d buttons\n", name, axes, buttons);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void joy_set_deviceindex(int index) {
|
||||
device_index = index;
|
||||
}
|
||||
|
||||
int joy_open(void) {
|
||||
int i;
|
||||
const char *name;
|
||||
for( i=0 ; i<SDL_NumJoysticks() ; i++ ) {
|
||||
if( (js=SDL_JoystickOpen(i)) ) {
|
||||
name=SDL_JoystickName(js);
|
||||
joy_axes = SDL_JoystickNumAxes(js);
|
||||
joy_buttons = SDL_JoystickNumButtons(js);
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
printf("SDL joystick '%s' axes %d buttons %d\n",name,joy_axes,joy_buttons);
|
||||
return 1;
|
||||
if (device_index >= 0) {
|
||||
return joy_open_index(device_index) ? 1 : -1;
|
||||
} else {
|
||||
for (int i = 0; i < SDL_NumJoysticks(); i++) {
|
||||
if (joy_open_index(i))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
joy_enable=FALSE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -62,19 +67,8 @@ void joy_close(void) {
|
||||
SDL_JoystickClose(js);
|
||||
}
|
||||
|
||||
#if 0
|
||||
boolean joy_getinfo(int *data) {
|
||||
int rt = FALSE;
|
||||
if( joy_enable ) {
|
||||
*data=sdl_getjoyinfo();
|
||||
rt=TRUE;
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
#endif
|
||||
|
||||
int joy_getinfo(void) {
|
||||
if (joy_enable) {
|
||||
if (js) {
|
||||
return sdl_getjoyinfo();
|
||||
}
|
||||
return 0;
|
||||
|
||||
+2
-2
@@ -58,10 +58,10 @@
|
||||
# ------------------------------------------------------------
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# joystick device のデバイス名
|
||||
# joystick device のデバイス番号 (0-)
|
||||
#
|
||||
|
||||
#joy_device: /dev/js0
|
||||
#joy_device: 0
|
||||
|
||||
# ------------------------------------------------------------
|
||||
|
||||
|
||||
+3
-4
@@ -128,8 +128,7 @@ static void sys35_usage(boolean verbose) {
|
||||
#endif
|
||||
puts(" -M0 : Disable MIDI output");
|
||||
|
||||
puts(" -devjoy device : set joystic device name to 'device'");
|
||||
puts(" if 'device' is set to 'none', don't use the device");
|
||||
puts(" -devjoy device : joystick device index (0-)");
|
||||
|
||||
puts(" -ttfont_mincho: set TrueType font for mincho");
|
||||
puts(" -ttfont_gothic: set TrueType font for mincho");
|
||||
@@ -306,7 +305,7 @@ static void sys35_ParseOption(int *argc, char **argv) {
|
||||
midi_set_output_device(argv[i][2] | subdev);
|
||||
} else if (0 == strcmp(argv[i], "-devjoy")) {
|
||||
if (argv[i + 1] != NULL) {
|
||||
joy_set_devicename(argv[i + 1]);
|
||||
joy_set_deviceindex(atoi(argv[i + 1]));
|
||||
}
|
||||
} else if (0 == strcmp(argv[i], "-fullscreen")) {
|
||||
fs_on = TRUE;
|
||||
@@ -377,7 +376,7 @@ static void check_profile() {
|
||||
/* joystick device name の設定 */
|
||||
param = get_profile("joy_device");
|
||||
if (param) {
|
||||
joy_set_devicename(param);
|
||||
joy_set_deviceindex(atoi(param));
|
||||
}
|
||||
/* Raw MIDI device name の設定 */
|
||||
param = get_profile("midi_device");
|
||||
|
||||
Reference in New Issue
Block a user