Arduino（マイコン）からモールス信号を送信する（C++）

発光信号を送りたくなったので、Arduinoからモールス信号を送信するコードを書きました。

# モールス信号とは
長音（ツー）と短音（トン）の組み合わせで文字を送るアレです。
[モールス符号 - Wikipedia](https://ja.wikipedia.org/wiki/%E3%83%A2%E3%83%BC%E3%83%AB%E3%82%B9%E7%AC%A6%E5%8F%B7)
[モールス信号（復号）](https://tomari.org/main/java/morse_dec.html)

# モールス信号のお約束簡単まとめ
- 長音－（ツー）は短音・（トン）の3倍の長さ
- シンボル（トンツー）とシンボルの間は短いギャップを空ける
- 文字と文字の間はギャップを空ける
- 単語と単語の間は長めのギャップを空ける
- 送信完了したら`HH`（欧文）`ﾗﾀ`（和文）を送る（？）
- 和文と欧文は混ぜて使えない

# Arduino（C++）向けモールスコード表
ファイル構成
- MorseCode.hpp
- MorseCode.cpp

Arduinoに連想配列なんて気の利いたものはありませんので[^1]、配列でゴリゴリ作りこみます。
コード表は[モールス信号（復号）](https://tomari.org/main/java/morse_dec.html)を参考にしました。

[^1]: あるにはあって、便利そうなんですが、今回は容量の都合で諦めました。[Arduino 開発を支える地味なライブラリたち](https://qiita.com/hideakitai/items/0553446c20493bb079a2)

まず、モールス符号を表すchr型構造体を定義しました。
メンバはコードの長さlenとトンツーを入れるbool配列のsig[8]です[^2]。
sig[8]の各要素はヘッダでdefineしてるTON,TUU,NUL（未使用部分）です[^3]。
``` cpp: MorseCode.hpp
#define TUU true
#define TON false
#define NUL false
```

[^2]: 一番長いのがHHの8シンボルでしたので、配列サイズは8にしましたが、uint8_tにしてビット演算しても良いでしょうね。
[^3]: よくよく考えたら`#define`ではなくて、`const bool TUU = true;`でよかった…

コード表をchr型配列`const chr Code[]`にゴリゴリ書きます。
とても人間様の仕事ではなかったので、ちょっと工夫して書きました。（後日別記事作成予定）
直接呼び出す場合は次のようにしますが、あまり使わないと思います。
```cpp
MorseCode::chr a = MorseCode::Code[MorseCode::Oubun.A];
```
今回はとりあえず、コード表通りの順番で配列に入れましたが、ASCIIコード表に対応させてしまえば、以下のように呼び出せるように書けます。
```cpp
MorseCode::chr a = MorseCode::Code['a'];
```
この方が高速動作が期待できますが、次のようなデメリットがあります。
- 配列サイズが大きくなる
- ASCIIコード表にドンピシャ対応しない符号`HH`（訂正）とかの置き場所に困る
- モールス信号に変換できないASCIIコードの対応に困る

後日書き換えた時に、`Oubun.A = 'a';`と変えてしまえば古いコードも使えるかなと思って、回りくどい書き方をしてみました。

実際の使い方としては、`chr EncodeOubun(char moji);`関数または`chr EncodeWabun(char moji);`関数を使う想定です。
和文文字はShift JISでエンコードされた半角カナを使用してください。
```cpp
MorseCode::chr MorseChar = MorseCode::EncodeOubun('a');
```

# ソースコード
使い方サンプル（ビルトインLEDから`a`を発光信号で送る）
```cpp:main.cpp
#include <Arduino.h>
#include "MorseCode.hpp"

void SendTUU();
void SendTON();

void setup()
{
  // put your setup code here, to run once:
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  // put your main code here, to run repeatedly:
  MorseCode::chr MorseChar = MorseCode::EncodeOubun('a');
  for (int i = 0; i < MorseChar.len; i++)
  {
    if (MorseChar.sig[i] == TUU)
      SendTUU();
    else
      SendTON();
  }
  delay(500);
}
void SendTUU()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
}
void SendTON()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(300);
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
}
```
``` cpp: MorseCode.hpp
#ifndef MorseCode_H
#define MorseCode_H

#define TUU true
#define TON false
#define NUL false

/*
モールス信号のコード表です。
出典：https://tomari.org/main/java/morse_dec.html
*/
namespace MorseCode
{
    /// @brief モールス符号構造体
    struct chr
    {
        /// @brief シンボル長
        int len;
        /// @brief シンボル配列
        bool sig[8];
    };

    /// @brief 文字からモールス符号（欧文+数字）へエンコード
    ///（HH（訂正）は'\b'、エンコードできない文字は0幅符号）
    /// @param moji エンコードしたい文字
    /// @return モールス符号構造体
    chr EncodeOubun(char moji);

    /// @brief 文字からモールス符号（和文+数字）へエンコード
    ///（段落は'\n'、本文（ﾎﾚ）は'\f'、訂正・終了（ﾗﾀ）は'\b'、「ヰ」「ヱ」は未対応、エンコードできない文字は0幅符号）
    /// @param moji エンコードしたい文字（半角カナShift JIS）
    /// @return モールス符号構造体
    chr EncodeWabun(char moji);

    /// @brief 欧文
    struct StructOubun
    {
        const int A = 0;
        const int B = 1;
        const int C = 2;
        const int D = 3;
        const int E = 4;
        const int F = 5;
        const int G = 6;
        const int H = 7;
        const int I = 8;
        const int J = 9;
        const int K = 10;
        const int L = 11;
        const int M = 12;
        const int N = 13;
        const int O = 14;
        const int P = 15;
        const int Q = 16;
        const int R = 17;
        const int S = 18;
        const int T = 19;
        const int U = 20;
        const int V = 21;
        const int W = 22;
        const int X = 23;
        const int Y = 24;
        const int Z = 25;
        const int Dot = 26;
        const int Comma = 27;
        const int Colon = 28;
        const int Question = 29;
        const int SingleQuote = 30;
        const int Minus = 31;
        const int ParenL = 32;
        const int ParenR = 33;
        const int Slash = 34;
        const int Equal = 35;
        const int Plus = 36;
        const int DoubleQuote = 37;
        const int Cross = 38;
        const int At = 39;
        const int HH = 40;
    };
    /// @brief 欧文 使用例：Code[Oubun.A]
    const StructOubun Oubun;

    /// @brief 数字
    struct StructNumber
    {
        const int One = 41;
        const int Two = 42;
        const int Three = 43;
        const int Four = 44;
        const int Five = 45;
        const int Six = 46;
        const int Seven = 47;
        const int Eight = 48;
        const int Nine = 49;
        const int Zero = 50;
    };
    /// @brief 数字 使用例：Code[Number.One]
    const StructNumber Number;

    /// @brief 数字の略体
    struct StructNumberOmit
    {
        const int One = 51;
        const int Two = 52;
        const int Three = 53;
        const int Four = 54;
        const int Five = 55;
        const int Six = 56;
        const int Seven = 57;
        const int Eight = 58;
        const int Nine = 59;
        const int Zero = 60;
    };
    /// @brief 数字の略体 使用例：Code[NumberOmit.One]
    const StructNumberOmit NumberOmit;

    /// @brief 和文
    struct StructWabun
    {
        const int A = 61;
        const int I = 62;
        const int U = 63;
        const int E = 64;
        const int O = 65;
        const int Ka = 66;
        const int Ki = 67;
        const int Ku = 68;
        const int Ke = 69;
        const int Ko = 70;
        const int Sa = 71;
        const int Si = 72;
        const int Su = 73;
        const int Se = 74;
        const int So = 75;
        const int Ta = 76;
        const int Ti = 77;
        const int Tu = 78;
        const int Te = 79;
        const int To = 80;
        const int Na = 81;
        const int Ni = 82;
        const int Nu = 83;
        const int Ne = 84;
        const int No = 85;
        const int Ha = 86;
        const int Hi = 87;
        const int Hu = 88;
        const int He = 89;
        const int Ho = 90;
        const int Ma = 91;
        const int Mi = 92;
        const int Mu = 93;
        const int Me = 94;
        const int Mo = 95;
        const int Ya = 96;
        const int Yu = 97;
        const int Yo = 98;
        const int Ra = 99;
        const int Ri = 100;
        const int Ru = 101;
        const int Re = 102;
        const int Ro = 103;
        const int Wa = 104;
        const int Wi = 105;
        const int Wo = 106;
        const int We = 107;
        const int N = 108;
        const int Dakuten = 109;
        const int Handakuten = 110;
        const int Nobashibo = 111;
        const int Touten = 112;
        const int Danraku = 113;
        const int Kakkohiraku = 114;
        const int Kakkotojiru = 115;
        const int Hore = 116;
        const int Rata = 117;
    };
    /// @brief 和文　使用例：Code[Wabun.A]
    const StructWabun Wabun;

    /// @brief モールスコード表
    const chr Code[] = {
        // 欧文文字
        {2, {TON, TUU, NUL, NUL, NUL, NUL, NUL, NUL}}, // A
        {4, {TUU, TON, TON, TON, NUL, NUL, NUL, NUL}}, // B
        {4, {TUU, TON, TUU, TON, NUL, NUL, NUL, NUL}}, // C
        {3, {TUU, TON, TON, NUL, NUL, NUL, NUL, NUL}}, // D
        {1, {TON, NUL, NUL, NUL, NUL, NUL, NUL, NUL}}, // E
        {4, {TON, TON, TUU, TON, NUL, NUL, NUL, NUL}}, // F
        {3, {TUU, TUU, TON, NUL, NUL, NUL, NUL, NUL}}, // G
        {4, {TON, TON, TON, TON, NUL, NUL, NUL, NUL}}, // H
        {2, {TON, TON, NUL, NUL, NUL, NUL, NUL, NUL}}, // I
        {4, {TON, TUU, TUU, TUU, NUL, NUL, NUL, NUL}}, // J
        {3, {TUU, TON, TUU, NUL, NUL, NUL, NUL, NUL}}, // K
        {4, {TON, TUU, TON, TON, NUL, NUL, NUL, NUL}}, // L
        {2, {TUU, TUU, NUL, NUL, NUL, NUL, NUL, NUL}}, // M
        {2, {TUU, TON, NUL, NUL, NUL, NUL, NUL, NUL}}, // N
        {3, {TUU, TUU, TUU, NUL, NUL, NUL, NUL, NUL}}, // O
        {4, {TON, TUU, TUU, TON, NUL, NUL, NUL, NUL}}, // P
        {4, {TUU, TUU, TON, TUU, NUL, NUL, NUL, NUL}}, // Q
        {3, {TON, TUU, TON, NUL, NUL, NUL, NUL, NUL}}, // R
        {3, {TON, TON, TON, NUL, NUL, NUL, NUL, NUL}}, // S
        {1, {TUU, NUL, NUL, NUL, NUL, NUL, NUL, NUL}}, // T
        {3, {TON, TON, TUU, NUL, NUL, NUL, NUL, NUL}}, // U
        {4, {TON, TON, TON, TUU, NUL, NUL, NUL, NUL}}, // V
        {3, {TON, TUU, TUU, NUL, NUL, NUL, NUL, NUL}}, // W
        {4, {TUU, TON, TON, TUU, NUL, NUL, NUL, NUL}}, // X
        {4, {TUU, TON, TUU, TUU, NUL, NUL, NUL, NUL}}, // Y
        {4, {TUU, TUU, TON, TON, NUL, NUL, NUL, NUL}}, // Z
        {6, {TON, TUU, TON, TUU, TON, TUU, NUL, NUL}}, // .
        {6, {TUU, TUU, TON, TON, TUU, TUU, NUL, NUL}}, // ,
        {6, {TUU, TUU, TUU, TON, TON, TON, NUL, NUL}}, // :
        {6, {TON, TON, TUU, TUU, TON, TON, NUL, NUL}}, // ?
        {6, {TON, TUU, TUU, TUU, TUU, TON, NUL, NUL}}, // '
        {6, {TUU, TON, TON, TON, TON, TUU, NUL, NUL}}, // -
        {5, {TUU, TON, TUU, TUU, TON, NUL, NUL, NUL}}, // (
        {6, {TUU, TON, TUU, TUU, TON, TUU, NUL, NUL}}, // )
        {5, {TUU, TON, TON, TUU, TON, NUL, NUL, NUL}}, // /
        {5, {TUU, TON, TON, TON, TUU, NUL, NUL, NUL}}, // =
        {5, {TON, TUU, TON, TUU, TON, NUL, NUL, NUL}}, // +
        {6, {TON, TUU, TON, TON, TUU, TON, NUL, NUL}}, // "
        {4, {TUU, TON, TON, TUU, NUL, NUL, NUL, NUL}}, // *
        {6, {TON, TUU, TUU, TON, TUU, TON, NUL, NUL}}, // @
        {8, {TON, TON, TON, TON, TON, TON, TON, TON}}, // HH

        // 数字
        {5, {TON, TUU, TUU, TUU, TUU, NUL, NUL, NUL}}, // 1
        {5, {TON, TON, TUU, TUU, TUU, NUL, NUL, NUL}}, // 2
        {5, {TON, TON, TON, TUU, TUU, NUL, NUL, NUL}}, // 3
        {5, {TON, TON, TON, TON, TUU, NUL, NUL, NUL}}, // 4
        {5, {TON, TON, TON, TON, TON, NUL, NUL, NUL}}, // 5
        {5, {TUU, TON, TON, TON, TON, NUL, NUL, NUL}}, // 6
        {5, {TUU, TUU, TON, TON, TON, NUL, NUL, NUL}}, // 7
        {5, {TUU, TUU, TUU, TON, TON, NUL, NUL, NUL}}, // 8
        {5, {TUU, TUU, TUU, TUU, TON, NUL, NUL, NUL}}, // 9
        {5, {TUU, TUU, TUU, TUU, TUU, NUL, NUL, NUL}}, // 0

        // 数字の略体
        {2, {TON, TUU, NUL, NUL, NUL, NUL, NUL, NUL}}, // 1
        {3, {TON, TON, TUU, NUL, NUL, NUL, NUL, NUL}}, // 2
        {4, {TON, TON, TON, TUU, NUL, NUL, NUL, NUL}}, // 3
        {5, {TON, TON, TON, TON, TUU, NUL, NUL, NUL}}, // 4
        {5, {TON, TON, TON, TON, TON, NUL, NUL, NUL}}, // 5
        {5, {TUU, TON, TON, TON, TON, NUL, NUL, NUL}}, // 6
        {4, {TUU, TON, TON, TON, NUL, NUL, NUL, NUL}}, // 7
        {3, {TUU, TON, TON, NUL, NUL, NUL, NUL, NUL}}, // 8
        {2, {TUU, TON, NUL, NUL, NUL, NUL, NUL, NUL}}, // 9
        {1, {TUU, NUL, NUL, NUL, NUL, NUL, NUL, NUL}}, // 0

        // 和文
        {5, {TUU, TUU, TON, TUU, TUU, NUL, NUL, NUL}}, // ア
        {2, {TON, TUU, NUL, NUL, NUL, NUL, NUL, NUL}}, // イ
        {3, {TON, TON, TUU, NUL, NUL, NUL, NUL, NUL}}, // ウ
        {5, {TUU, TON, TUU, TUU, TUU, NUL, NUL, NUL}}, // エ
        {5, {TON, TUU, TON, TON, TON, NUL, NUL, NUL}}, // オ
        {4, {TON, TUU, TON, TON, NUL, NUL, NUL, NUL}}, // カ
        {5, {TUU, TON, TUU, TON, TON, NUL, NUL, NUL}}, // キ
        {4, {TON, TON, TON, TUU, NUL, NUL, NUL, NUL}}, // ク
        {4, {TUU, TON, TUU, TUU, NUL, NUL, NUL, NUL}}, // ケ
        {4, {TUU, TUU, TUU, TUU, NUL, NUL, NUL, NUL}}, // コ
        {5, {TUU, TON, TUU, TON, TUU, NUL, NUL, NUL}}, // サ
        {5, {TUU, TUU, TON, TUU, TON, NUL, NUL, NUL}}, // シ
        {5, {TUU, TUU, TUU, TON, TUU, NUL, NUL, NUL}}, // ス
        {5, {TON, TUU, TUU, TUU, TON, NUL, NUL, NUL}}, // セ
        {4, {TUU, TUU, TUU, TON, NUL, NUL, NUL, NUL}}, // ソ
        {2, {TUU, TON, NUL, NUL, NUL, NUL, NUL, NUL}}, // タ
        {4, {TON, TON, TUU, TON, NUL, NUL, NUL, NUL}}, // チ
        {4, {TON, TUU, TUU, TON, NUL, NUL, NUL, NUL}}, // ツ
        {5, {TON, TUU, TON, TUU, TUU, NUL, NUL, NUL}}, // テ
        {5, {TON, TON, TUU, TON, TON, NUL, NUL, NUL}}, // ト
        {3, {TON, TUU, TON, NUL, NUL, NUL, NUL, NUL}}, // ナ
        {4, {TUU, TON, TUU, TON, NUL, NUL, NUL, NUL}}, // ニ
        {4, {TON, TON, TON, TON, NUL, NUL, NUL, NUL}}, // ヌ
        {4, {TUU, TUU, TON, TUU, NUL, NUL, NUL, NUL}}, // ネ
        {4, {TON, TON, TUU, TUU, NUL, NUL, NUL, NUL}}, // ノ
        {4, {TUU, TON, TON, TON, NUL, NUL, NUL, NUL}}, // ハ
        {5, {TUU, TUU, TON, TON, TUU, NUL, NUL, NUL}}, // ヒ
        {4, {TUU, TUU, TON, TON, NUL, NUL, NUL, NUL}}, // フ
        {1, {TON, NUL, NUL, NUL, NUL, NUL, NUL, NUL}}, // ヘ
        {3, {TUU, TON, TON, NUL, NUL, NUL, NUL, NUL}}, // ホ
        {4, {TUU, TON, TON, TUU, NUL, NUL, NUL, NUL}}, // マ
        {5, {TON, TON, TUU, TON, TUU, NUL, NUL, NUL}}, // ミ
        {1, {TUU, NUL, NUL, NUL, NUL, NUL, NUL, NUL}}, // ム
        {5, {TUU, TON, TON, TON, TUU, NUL, NUL, NUL}}, // メ
        {5, {TUU, TON, TON, TUU, TON, NUL, NUL, NUL}}, // モ
        {3, {TON, TUU, TUU, NUL, NUL, NUL, NUL, NUL}}, // ヤ
        {5, {TUU, TON, TON, TUU, TUU, NUL, NUL, NUL}}, // ユ
        {2, {TUU, TUU, NUL, NUL, NUL, NUL, NUL, NUL}}, // ヨ
        {3, {TON, TON, TON, NUL, NUL, NUL, NUL, NUL}}, // ラ
        {3, {TUU, TUU, TON, NUL, NUL, NUL, NUL, NUL}}, // リ
        {5, {TUU, TON, TUU, TUU, TON, NUL, NUL, NUL}}, // ル
        {3, {TUU, TUU, TUU, NUL, NUL, NUL, NUL, NUL}}, // レ
        {4, {TON, TUU, TON, TUU, NUL, NUL, NUL, NUL}}, // ロ
        {3, {TUU, TON, TUU, NUL, NUL, NUL, NUL, NUL}}, // ワ
        {5, {TON, TUU, TON, TON, TUU, NUL, NUL, NUL}}, // ヰ
        {4, {TON, TUU, TUU, TUU, NUL, NUL, NUL, NUL}}, // ヲ
        {5, {TON, TUU, TUU, TON, TON, NUL, NUL, NUL}}, // ヱ
        {5, {TON, TUU, TON, TUU, TON, NUL, NUL, NUL}}, // ン
        {2, {TON, TON, NUL, NUL, NUL, NUL, NUL, NUL}}, // ゛
        {5, {TON, TON, TUU, TUU, TON, NUL, NUL, NUL}}, // ゜
        {5, {TON, TUU, TUU, TON, TUU, NUL, NUL, NUL}}, // ｌ
        {6, {TON, TUU, TON, TUU, TON, TUU, NUL, NUL}}, // 、
        {6, {TON, TUU, TON, TUU, TON, TON, NUL, NUL}}, // └
        {6, {TUU, TON, TUU, TUU, TON, TUU, NUL, NUL}}, // （
        {6, {TON, TUU, TON, TON, TUU, TON, NUL, NUL}}, // ）
        {6, {TUU, TON, TON, TUU, TUU, TUU, NUL, NUL}}, // ホレ
        {5, {TON, TON, TON, TUU, TON, NUL, NUL, NUL}}  // ラタ
    };
}

#endif
```

```cpp:MorseCode.cpp
// This source file have to be encoded by "Shift JIS".
#include "MorseCode.hpp"

using namespace MorseCode;
namespace MorseCode
{
    chr EncodeOubun(char moji)
    {
        switch (moji)
        {
        case 'A':
        case 'a':
            return Code[Oubun.A];
        case 'B':
        case 'b':
            return Code[Oubun.B];
        case 'C':
        case 'c':
            return Code[Oubun.C];
        case 'D':
        case 'd':
            return Code[Oubun.D];
        case 'E':
        case 'e':
            return Code[Oubun.E];
        case 'F':
        case 'f':
            return Code[Oubun.F];
        case 'G':
        case 'g':
            return Code[Oubun.G];
        case 'H':
        case 'h':
            return Code[Oubun.H];
        case 'I':
        case 'i':
            return Code[Oubun.I];
        case 'J':
        case 'j':
            return Code[Oubun.J];
        case 'K':
        case 'k':
            return Code[Oubun.K];
        case 'L':
        case 'l':
            return Code[Oubun.L];
        case 'M':
        case 'm':
            return Code[Oubun.M];
        case 'N':
        case 'n':
            return Code[Oubun.N];
        case 'O':
        case 'o':
            return Code[Oubun.O];
        case 'P':
        case 'p':
            return Code[Oubun.P];
        case 'Q':
        case 'q':
            return Code[Oubun.Q];
        case 'R':
        case 'r':
            return Code[Oubun.R];
        case 'S':
        case 's':
            return Code[Oubun.S];
        case 'T':
        case 't':
            return Code[Oubun.T];
        case 'U':
        case 'u':
            return Code[Oubun.U];
        case 'V':
        case 'v':
            return Code[Oubun.V];
        case 'W':
        case 'w':
            return Code[Oubun.W];
        case 'X':
        case 'x':
            return Code[Oubun.X];
        case 'Y':
        case 'y':
            return Code[Oubun.Y];
        case 'Z':
        case 'z':
            return Code[Oubun.Z];
        case '.':
            return Code[Oubun.Dot];
        case ',':
            return Code[Oubun.Comma];
        case ':':
            return Code[Oubun.Colon];
        case '?':
            return Code[Oubun.Question];
        case '\'':
            return Code[Oubun.SingleQuote];
        case '-':
            return Code[Oubun.Minus];
        case '(':
            return Code[Oubun.ParenL];
        case ')':
            return Code[Oubun.ParenR];
        case '/':
            return Code[Oubun.Slash];
        case '=':
            return Code[Oubun.Equal];
        case '+':
            return Code[Oubun.Plus];
        case '"':
            return Code[Oubun.DoubleQuote];
        case '*':
            return Code[Oubun.Cross];
        case '@':
            return Code[Oubun.At];
        case '\b':
            return Code[Oubun.HH];
        case '1':
            return Code[Number.One];
        case '2':
            return Code[Number.Two];
        case '3':
            return Code[Number.Three];
        case '4':
            return Code[Number.Four];
        case '5':
            return Code[Number.Five];
        case '6':
            return Code[Number.Six];
        case '7':
            return Code[Number.Seven];
        case '8':
            return Code[Number.Eight];
        case '9':
            return Code[Number.Nine];
        case '0':
            return Code[Number.Zero];
        default:
            return {0, {NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL}};
        }
    }
    chr EncodeWabun(char moji)
    {
        switch (moji)
        {
        case 'ｱ':
            return Code[Wabun.A];
        case 'ｲ':
            return Code[Wabun.I];
        case 'ｳ':
            return Code[Wabun.U];
        case 'ｴ':
            return Code[Wabun.E];
        case 'ｵ':
            return Code[Wabun.O];
        case 'ｶ':
            return Code[Wabun.Ka];
        case 'ｷ':
            return Code[Wabun.Ki];
        case 'ｸ':
            return Code[Wabun.Ku];
        case 'ｹ':
            return Code[Wabun.Ke];
        case 'ｺ':
            return Code[Wabun.Ko];
        case 'ｻ':
            return Code[Wabun.Sa];
        case 'ｼ':
            return Code[Wabun.Si];
        case 'ｽ':
            return Code[Wabun.Su];
        case 'ｾ':
            return Code[Wabun.Se];
        case 'ｿ':
            return Code[Wabun.So];
        case 'ﾀ':
            return Code[Wabun.Ta];
        case 'ﾁ':
            return Code[Wabun.Ti];
        case 'ﾂ':
            return Code[Wabun.Tu];
        case 'ﾃ':
            return Code[Wabun.Te];
        case 'ﾄ':
            return Code[Wabun.To];
        case 'ﾅ':
            return Code[Wabun.Na];
        case 'ﾆ':
            return Code[Wabun.Ni];
        case 'ﾇ':
            return Code[Wabun.Nu];
        case 'ﾈ':
            return Code[Wabun.Ne];
        case 'ﾉ':
            return Code[Wabun.No];
        case 'ﾊ':
            return Code[Wabun.Ha];
        case 'ﾋ':
            return Code[Wabun.Hi];
        case 'ﾌ':
            return Code[Wabun.Hu];
        case 'ﾍ':
            return Code[Wabun.He];
        case 'ﾎ':
            return Code[Wabun.Ho];
        case 'ﾏ':
            return Code[Wabun.Ma];
        case 'ﾐ':
            return Code[Wabun.Mi];
        case 'ﾑ':
            return Code[Wabun.Mu];
        case 'ﾒ':
            return Code[Wabun.Me];
        case 'ﾓ':
            return Code[Wabun.Mo];
        case 'ﾔ':
            return Code[Wabun.Ya];
        case 'ﾕ':
            return Code[Wabun.Yu];
        case 'ﾖ':
            return Code[Wabun.Yo];
        case 'ﾗ':
            return Code[Wabun.Ra];
        case 'ﾘ':
            return Code[Wabun.Ri];
        case 'ﾙ':
            return Code[Wabun.Ru];
        case 'ﾚ':
            return Code[Wabun.Re];
        case 'ﾛ':
            return Code[Wabun.Ro];
        case 'ﾜ':
            return Code[Wabun.Wa];
        case 'ｦ':
            return Code[Wabun.Wo];
        case 'ﾝ':
            return Code[Wabun.N];
        case 'ﾞ':
            return Code[Wabun.Dakuten];
        case 'ﾟ':
            return Code[Wabun.Handakuten];
        case 'ｰ':
            return Code[Wabun.Nobashibo]; // 長音
        case '､':
            return Code[Wabun.Touten];
        case '\n':
            return Code[Wabun.Danraku]; // └ 段落
        case '(':
            return Code[Wabun.Kakkohiraku];
        case ')':
            return Code[Wabun.Kakkotojiru];
        case '\f':
            return Code[Wabun.Hore]; // ﾎﾚ 本文
        case '\b':
            return Code[Wabun.Rata]; // ﾗﾀ 訂正・終了
        case '1':
            return Code[Number.One];
        case '2':
            return Code[Number.Two];
        case '3':
            return Code[Number.Three];
        case '4':
            return Code[Number.Four];
        case '5':
            return Code[Number.Five];
        case '6':
            return Code[Number.Six];
        case '7':
            return Code[Number.Seven];
        case '8':
            return Code[Number.Eight];
        case '9':
            return Code[Number.Nine];
        case '0':
            return Code[Number.Zero];
        default:
            return {0, {NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL}};
        }
    }
}
```