# HG changeset patch # User Yoshiki Yazawa # Date 1294231299 -32400 # Node ID b16b82dbfe87bf7594d6740526c64d52b1dfe180 # Parent 05cc06e88a57675dec5b591400d8e2177e1dd45e massive cleanup diff -r 05cc06e88a57 -r b16b82dbfe87 Makefile --- a/Makefile Fri Dec 24 15:28:04 2010 +0900 +++ b/Makefile Wed Jan 05 21:41:39 2011 +0900 @@ -1,18 +1,15 @@ -# $Id: Makefile,v 1.1 2002/12/21 01:13:27 tosy Exp $ - -TARGET = rcctl +APPS = rcctl SRCS = rcctl.c cdcnv.c -OBJS = rcctl.o cdcnv.o +OBJS = ${SRCS:.c=.o} CC = gcc -# for debug build -CFLAGS = -O -Wall -g -DVERBOSE -DDEBUG -I/usr/include/libusb-1.0 -# for release build -#CFLAGS = -O -Wall +CFLAGS = -O -Wall -g -I/usr/include/libusb-1.0 LDFLAGS = -lhid -lusb -all: $(OBJS) - $(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) +all: $(APPS) + +rcctl: $(OBJS) + $(CC) -o $@ $^ $(LDFLAGS) clean: rm -f *.o $(TARGET) diff -r 05cc06e88a57 -r b16b82dbfe87 cdcnv.c --- a/cdcnv.c Fri Dec 24 15:28:04 2010 +0900 +++ b/cdcnv.c Wed Jan 05 21:41:39 2011 +0900 @@ -1,18 +1,21 @@ /* cdcnv.c --------------------------------------------- $Id: cdcnv.c,v 1.1 2002/12/21 01:13:27 tosy Exp $ - (以前の履歴は rcctl.c 参照) - v0.30 97.12.13 コード変換部(cdcnv.c)分離 - v0.31 98.03.07 Mac21対応 - v0.31a 98.03.11 Syncom対応(要rc_send修正) - v0.31b 98.03.15 ALISA3(L)対応 - v0.32 98.11.29 鉄人,Σ,NET7000対応 - v0.40 02.12.15 B-kara,HyperJOY対応,Σバグ修正 + (篁ュ絮ユ眼 rcctl.c ) + v0.30 97.12.13 潟若紊(cdcnv.c) + v0.31 98.03.07 Mac21絲上 + v0.31a 98.03.11 Syncom絲上(荀rc_send篆罩) + v0.31b 98.03.15 ALISA3(L)絲上 + v0.32 98.11.29 篋,裡,NET7000絲上 + v0.40 02.12.15 B-kara,HyperJOY絲上,裡遺信罩 + v0.50 11.01.06 linux吾眼 (yaz) ------------------------------------------------------*/ #include #include -#if defined(__FreeBSD__)||defined(linux) +#include "debug.h" + +#if defined(__FreeBSD__) || defined(linux) #define stricmp(s, c) strcasecmp(s, c) #endif @@ -25,16 +28,16 @@ #define M_BT 5 /* BeMax'S(T) */ #define M_PR 6 /* Prologue21 */ #define M_DA 7 /* DAM */ -#define M_SY 8 /* Syncom/孫悟空 */ +#define M_SY 8 /* Syncom/絖腥 */ #define M_N7 9 /* NET7000 */ #define M_BK 10 /* B-kara */ #define M_MA 11 /* Mac21 */ #define M_A3 12 /* ALISA3(A) */ #define M_AL 13 /* ALISA3(L) */ #define M_AZ 14 /* ALISA3(Z) */ -#define M_TS 15 /* 東映システム */ -#define M_SI 16 /* Σシステム */ -#define M_TJ 17 /* カラオケの鉄人 */ +#define M_TS 15 /* 掩激鴻 */ +#define M_SI 16 /* 裡激鴻 */ +#define M_TJ 17 /* 宴篋 */ #define K_SE 3 #define K_KU 4 @@ -80,10 +83,10 @@ {0x30, 0x00, 0xff, 0x41, 0x08, 0x09, 0x4c, 0x45, 0x44, /* TOEI sys */ 0x13, 0x0f, 0x4f, 0x4e, 0x07, 0x47, 0x46, 0x03, 0x43, 0x42, 0x53, 0x52 }, - {0x10, 0x55, 0xaa, 0x3e, 0x08, 0x09, 0x5c, -1, -1, /* Σ System */ + {0x10, 0x55, 0xaa, 0x3e, 0x08, 0x09, 0x5c, -1, -1, /* 裡 System */ 0x13, 0x0f, 0x4f, 0x4e, 0x07, 0x47, 0x46, 0x03, 0x43, 0x42, 0x53, 0x52 }, - {0x40, 0xae, 0x51, 0xdc, 0x03, 0x02, 0x96, -1, 0xdd, /* 鉄人 */ + {0x40, 0xae, 0x51, 0xdc, 0x03, 0x02, 0x96, -1, 0xdd, /* 篋 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0xda, 0xdb } }; @@ -101,17 +104,15 @@ int maker, i, c, n, *q; char *tmp = NULL; -#ifdef DEBUG - fprintf(stderr, "mak=%s cod=%s\n", mak, cod); -#endif + debug(1, "mak=%s cod=%s\n", mak, cod); tmp = strchr(mks, *mak & 0xdf); if(!tmp) return -1; + maker = (int)(tmp - mks); -#ifdef DEBUG - fprintf(stderr, "maker=%d\n", maker); -#endif + debug(1, "maker=%d\n", maker); + q = buf; *q++ = 0x80; /* wake-up code */ @@ -119,7 +120,7 @@ *q++ = cvt[maker][1]; *q++ = cvt[maker][2]; - /* 統合機種等でのメーカー名指定 */ + /* 腟怨罘腮膈с<若弱絎 */ if ((c = *++mak) != 0) { if ((maker == M_A3)&&('0' <= c)&&(c <= '4')) cvt[maker][K_SE] = 0x12 + (c - '0'); @@ -161,7 +162,7 @@ } } - /* 曲コード変換 */ + /* 蚊潟若紊 */ while((c = *cod++) != '\0') { if (('0' <= c)&&(c <= '9')) *q = cvt[maker][c - '0' + K_NM]; @@ -181,10 +182,10 @@ return -2; } - /* 送信直前処理 */ + /* 篆∞翫 */ switch(maker) { case M_X2: - /* X2000: 曲コードの末尾 2 桁の直前にも SET を送信 */ + /* X2000: 蚊潟若絨 2 罅翫 SET 篆 */ q -= 2; q[3] = cvt[maker][K_SE]; q[2] = q[1]; @@ -194,7 +195,7 @@ break; case M_GI: - /* GIGA: 曲コードが 6 桁以下の場合は最後に'0'を埋める */ + /* GIGA: 蚊潟若 6 罅篁ヤ翫緇'0' */ while(q < &buf[10]) *q++ = cvt[maker][K_NM]; break; @@ -214,27 +215,27 @@ buf[5] = buf[9]; buf[6] = buf[10]; buf[7] = buf[11]; - break; /* q=&buf[8] にしないとバグのような… */ + break; /* q=&buf[8] 違 */ case M_SI: - /* Σシステム: コード長 10 バイト(,,)固定 */ + /* 裡激鴻: 潟若 10 ゃ(,,)阪 */ case M_DA: - /* DAM: コード長 9 バイト(0x08,,)固定 */ + /* DAM: 潟若 9 ゃ(0x08,,)阪 */ case M_BK: - /* B-kara: コード長 9 バイト(0xf0,,)固定 */ - n = (maker == M_SI)? 12: 11; /* 数字の最終桁を buf[n] とした値 */ + /* B-kara: 潟若 9 ゃ(0xf0,,)阪 */ + n = (maker == M_SI)? 12: 11; /* 医腟罅 buf[n] */ for( i=0; i<7; i++ ) { c = *(q-1); if ((i == 1)&&((c == cvt[maker][K_NM+10])||(c == cvt[maker][K_NM+11]))) - /* 曲コード中の'A','B'以降の桁数が1桁なら'0'を挿入 */ + /* 蚊潟若筝'A','B'篁ラ罅違1罅'0'水 */ buf[n-i] = cvt[maker][K_NM + 0]; else if ((i == 2)&&(c!=cvt[maker][K_NM+10])&&(c!=cvt[maker][K_NM+11])) - /* 曲コードの末尾 3 文字めが'A','B'でなければ'-'を設定 */ + /* 蚊潟若絨 3 絖'A','B'с'-'荐絎 */ buf[n-i] = (maker == M_BK)? 0x3d: ((maker == M_SI)? 0x51: 0x3c); else if (q > &buf[n-6]) buf[n-i] = *--q; else - /* 桁数の足らない部分には'0'を設定 */ + /* 罅違莇潟'0'荐絎 */ buf[n-i] = cvt[maker][K_NM + 0]; } q = &buf[n+1]; @@ -243,7 +244,7 @@ break; } } - /* 制御コードの処理 */ + /* 九勝潟若 */ else { *q = -1; if (!stricmp(cod, "SE")) @@ -266,6 +267,6 @@ if ((maker == M_BK)||((maker == M_UK)&&('2' == *mak))) *q++ = 0xf7; - buf[1] |= q-buf-2; /* 実送信バイト数(PIC 制御用)を埋め込み */ + buf[1] |= q-buf-2; /* 絎篆<ゃ(PIC 九勝)莨若 */ return q-buf; } diff -r 05cc06e88a57 -r b16b82dbfe87 debug.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debug.h Wed Jan 05 21:41:39 2011 +0900 @@ -0,0 +1,14 @@ +#ifndef __RCCTL_DEBUG_H__ +#define __RCCTL_DEBUG_H__ + +extern int debug; + +/* print debug message if specified level is greater enough */ +#define debug(level, fmt, ...) \ + do { \ + if(debug >= level) { \ + fprintf(stderr, "%s: %s():%4d: " fmt, __FILE__, __FUNCTION__, (int) __LINE__, ## __VA_ARGS__); \ + } \ + } while(0); + +#endif diff -r 05cc06e88a57 -r b16b82dbfe87 rcctl.c --- a/rcctl.c Fri Dec 24 15:28:04 2010 +0900 +++ b/rcctl.c Wed Jan 05 21:41:39 2011 +0900 @@ -1,24 +1,25 @@ /* rcctl.c --------------------------------------------- $Id: rcctl.c,v 1.1 2002/12/21 01:13:28 tosy Exp $ - v0.10 97.08.15 初期版(コミケット52) - v0.11 97.08.27 通信タイミング修正 - v0.12 97.09.12 U-kara-2サポート - v0.12a 97.09.15 返り値設定 + v0.10 97.08.15 (潟宴52) + v0.11 97.08.27 篆<帥ゃ潟遺信罩 + v0.12 97.09.12 U-kara-2泣若 + v0.12a 97.09.15 菴よ┃絎 v0.12b 97.09.20 Bug fix (JOY:[SP]) - v0.20 97.10.01 FreeBSD版 + v0.20 97.10.01 FreeBSD v0.20a 97.10.18 Bug fix (X2k:[SP],[ST]) - v0.21 97.12.10 ALISA-3シーケンス修正 - v0.30 97.12.13 コード変換部(cdcnv.c)分離 - v0.40 02.12.16 USB版対応 - 【cdcnv.c の履歴も参照のこと】 + v0.21 97.12.10 ALISA-3激若宴潟剛信罩 + v0.30 97.12.13 潟若紊(cdcnv.c) + v0.40 02.12.16 USB絲上 + v0.50 11.01.06 linux絨吾眼 (yaz) + cdcnv.c 絮ユ眼с ------------------------------------------------------*/ #define __LINUX__ #include #include -#include -#include -#include +//#include +//#include +//#include #define HID_MAX_USAGES 16 typedef unsigned int __u32; @@ -35,14 +36,16 @@ #include #include +#include "debug.h" #ifndef S_VERS -#define S_VERS "0.41" +#define S_VERS "0.50" #endif /* globals */ HIDInterface *hidif; extern int errno; +int debug = 0; /* prototypes */ int cdcnv(int buf[], char *mak, char *cod); @@ -52,15 +55,11 @@ { hid_return ret; -// unsigned int report_id; -// unsigned int report_type; -// unsigned int size; - /* vendor id and product id of okecon */ HIDInterfaceMatcher matcher = { 0x0bfe, 0x2022, NULL, NULL, 0 }; /* see include/debug.h for possible values */ - hid_set_debug(HID_DEBUG_ALL); + hid_set_debug(debug); hid_set_debug_stream(stderr); /* passed directly to libusb */ hid_set_usb_debug(0); @@ -83,51 +82,6 @@ return 1; } - - -#if 0 - /* read feature */ - ret = hid_get_feature_report(hidif, path, depth, buffer, size); - if(ret != HID_RET_SUCCESS) { - fprintf(stderr, "hid_get_feature_report failed with return code %d\n", ret); - return 1; - } - - /* parse */ - - /* prepare buffers */ - hid_get_report_size(hidif, report_id, report_type, &size); - if(size != 8) { - fprintf(stderr, "%s is not 'OKCon/USB'?\n", UDEV); - return 1; - }; - - -// BSD - /* read header */ - if ((rd = hid_get_report_desc(fd)) == 0) { - fprintf(stderr, "Failed on USB_GET_REPORT_DESC.\n"); - return 1; - } - - /* parse */ - hd = hid_start_parse(rd, 1< \n", cmd); + printf("options: -d \n"); + exit(0); +} -int main(int ac, char *av[]) +int main(int argc, char **argv) { int i, u, buf[16]; unsigned char sbuf[8]; hid_return ret; + int opt; - if (ac < 3) { - printf("'Oke-Con' controller, version " S_VERS ".\n"); - printf("Copyright (C) 1997-2002 by Tosy / W341IG.\n"); - printf("Usage: rcctl \n"); - return 255; + if(argc < 3) { + usage(argv[0]); } - if ((u = cdcnv(buf, av[1], av[2])) < 0) { - fprintf(stderr, "%s: %s\n", av[0], cverrstr[~u]); + while ((opt=getopt(argc, argv, "d:h")) != -1) { + switch (opt) { + case 'd': + debug = atoi(optarg); + break; + case 'h': + default: + usage(argv[0]); + break; + } + } + argc -= optind; + argv += optind; + + if ((u = cdcnv(buf, *argv, *(argv+1))) < 0) { + fprintf(stderr, "%s: %s\n", *argv, cverrstr[~u]); return 1; } - printf("cdcnv %d\n", u); - -#ifdef VERBOSE - printf("Initializing....\n"); -#endif + debug(1, "cdcnv %d\n", u); + debug(1, "Initializing....\n"); if (init_usb()) return 255; -#ifdef VERBOSE - printf(" done.\n"); -#endif + debug(1, " done.\n"); -#ifdef VERBOSE for(i=0; i