さんだすメモ

さメモ

技術ブログでは、ない・・・

GCコンのプロトコルについて

コントローラーを作ろうと思って色々調べたところ、GCコンのプロトコルについて新しくわかったことがあるので、その周辺をまとめました。間違いなどありましたら指摘してくださると助かります。

参考にしたサイト

コマンドは以下のサイトを参照した上で調べました。論理値の定義など、必要なことがほとんど載っています。

  1. Nintendo Gamecube Controller Protocol

  2. GameCube to Nintendo 64 Controller Converter

  3. Yet Another Gamecube Documentation

リクエストとコマンド

普通のGCコントローラーのDOL-003を使ってテストしました。

0x00: Identify

コントローラーは2バイトのデバイスIDと1バイトのステータスを返します。GCコンのIDは0x0900です。3.を参考にしつつ調べると、ステータスの8ビットの意味は次の表のようだとかんがえまs。

bit(s) description
7 bit 7, byte 0 of joy-channel = ERRSTAT? (0)
6 bit 6, byte 0 of joy-channel = ERRLATCH? (0)
5 is-not-calibrated
4 unused? (0)
3 is-rumbling
2-0 joy-channel mode of analog values

5ビット目はコントローラーのニュートラルポジションがセットされたかどうかを示します。そして、ホストが一度0x41または0x42のコマンドを送ると、5ビット目は0になります。 As described below, this is same as bit 5, byte 7 of joy-channel. So I assumed bit 7 and bit 6 are same as that of byte 0 of joy-channel (I couldn't test them).

0x40, byte B, byte C: request joy-channel, make rumble or not

The controller returns 8 bytes of joy-channel. The meanings are as follows, along with 1., 3..

bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
byte 0 ERRSTAT (0) ERRLATCH (0) is-not-calibrated Start Y X B A
byte 1 unused? (1) L R Z D-Up D-Down D-Right D-Left

And analog values follow.

bit 7-0
byte 2 Joystick X value (8 bit)
byte 3 Joystick Y value (8 bit)
byte 4-7 depends on the mode of analog values

joy-channel mode of analog values depends on byte B. The meanings are as follows. Only lower 3 bits of byte B are used.

bit 2 bit 1 bit 0 C-Stick X, Y L, R
0 0 0 8 bits 4 bits
0 0 1 4 bits 8 bits
0 1 0 4 bits 4 bits
0 1 1 8 bits 8 bits
1 0 0 8 bits 0 bits
X X X 8 bits 4 bits

The values are put in byte 4-7 in this order, and if there are extra frames, they are filled by 0.

Bit 0 of byte C shows whether to make the controller rumble or not. Other bits seem to be unused but I think they should be set to 0.

0x41: get original positions of the analog values

The controller returns 10 bytes. Byte 0-1 are the button state that is almost same format as above one. In special case that the host send 0x41 while Z button is pushed, ERRLATCH is set to 1 (I don't know why). Byte 2-7 are original positions of the analog values. Joystick X, Y, C-Stick X, Y, L, R are placed in this order, and the size of values are always 8 bits. Byte 8-9 are set to 0 in all case I tried. Note that if the controller haven't set original positions, it sets them and returns.

0x42 (, 0x00, 0x00): set original positions of the analog values

The controller sets orginal values. When the controller recieved 1 byte of 0x42, it returns nothing. On the other hand when recieved 3 bytes of 0x42, 0x00, 0x00, it returns 10 bytes of original positions (This is the same behavior as recieving 0x41 for the first time).

最後に

コントローラーを作るときに何が必須の条件になるのかを調べる余裕はありませんでしたが、実際の受け答えがわかれば設計がスムーズにできると思います。これが役に立てば幸いです。