Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update blog article 303 #143

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/content/blog-metas/303.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"postDate": "2020-12-20T17:05:00+09:00",
"updateDate": "2023-11-09T23:17:00+09:00"
"updateDate": "2024-11-28T05:52:33.972Z"
}
68 changes: 7 additions & 61 deletions src/content/blogs/303.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ tags: [advent-calendar, electronic-dictionary, c-cpp]

[この表](https://brain.fandom.com/ja/wiki/Brain%E6%A9%9F%E7%A8%AE%E5%88%A5%E8%A7%A3%E8%AA%AC)で第 1 世代から第 4 世代に分類されている機種を対象とします。2021 年以降発売の[第 5 世代](https://brain.fandom.com/ja/wiki/%E7%AC%AC5%E4%B8%96%E4%BB%A3)に該当する機種用のアプリケーションは、この記事の方法では作成できません。

(2024 年 11 月追記)この記事は、[Brain Wiki](https://brain.fandom.com/ja/wiki/%E9%96%8B%E7%99%BA%E7%92%B0%E5%A2%83%E3%83%BBSDK) にも同等の内容(環境構築方法のみ)を転記しています。著者は既に OUCC を引退している OB なので、状況に変化があった場合は Brain Wiki 側を優先的に更新します。本記事の手順でうまくいかなかった場合などは Brain Wiki も併せてご確認ください。

## プログラム
この記事では、プログラミングよりも開発環境やコンパイル方法など、開発手順の解説に重点を置くため、簡単なプログラムを使用します。[`brain.cpp`](https://gist.github.com/watamario15/0ce68d7825062094c7282fdc7c762efe) をダウンロードしてください。なお、このプログラムは通常の Windows PC と Windows CE のどちらでも使用できるようにしてあるので、Brain を所持していない方でも Win32 アプリケーションを開発できる環境があれば試すことは可能です。

Expand All @@ -38,66 +40,9 @@ Visual Studio 2005/2008 の Professional 以上でも開発可能です。[こ
`index.din` 及び `AppMain.cfg` は空のテキストファイルを作成し、ファイル名を `index.din`, `AppMain.cfg`(もちろん元の拡張子 `.txt` は消す)に変更するだけで作成が可能です。UNIX 系の環境なら `touch` コマンドでも作成できます。ceOpener などの別ツールを導入済みなどで、 exe ファイルを直接実行する場合は以上の作業は不要です。どんな名前でもどこに置いても構いません。

## CeGCC
Linux, Cygwin, WSL, macOS 等の UNIX 環境で使用できる、最新の Windows CE 開発環境です。Windows XP のような古い Windows 環境が不要で、GCC 9.3.0 ベースなので C++17 を完全にサポートしているなど、現在では最も使いやすい環境です。ただし、個人の方が作成されたものだというのもあり、若干癖があります。

基本的に[公式サイト](https://max.kellermann.name/projects/cegcc/)に従います。Debian 系でない OS や AMD64 以外の CPU を搭載する PC の場合は、[こちら](https://brain.fandom.com/ja/wiki/CeGCC)に従ってください。

### 環境構築
`/etc/apt/sources.list` ファイルに、以下の 1 行を追加します。どちらに属するか分からない場合は、Debian の方で試したうえでエラーが出た場合に Ubuntu の記法を試してください。

Debian:
```
deb https://max.kellermann.name/debian cegcc_buster-default main
```

Ubuntu:
```
deb [trusted=yes] https://max.kellermann.name/debian cegcc_buster-default main
```

この作業にはテキストエディタを用いても構いませんが、今回はファイルの末尾に足すだけなので、以下のコマンドを実行すればよいです(1 行目は改行、2 行目は実際の追記)。

Debian:
```bash
sudo bash -c 'echo >> /etc/apt/sources.list'
sudo bash -c 'echo deb [trusted=yes] https://max.kellermann.name/debian cegcc_buster-default main >> /etc/apt/sources.list'
```

Ubuntu:
```bash
sudo bash -c 'echo >> /etc/apt/sources.list'
sudo bash -c 'echo deb [trusted=yes] https://max.kellermann.name/debian cegcc_buster-default main >> /etc/apt/sources.list'
```

その後、以下のコマンドを実行してインストールします。

```bash
sudo apt update
sudo apt install gcc-arm-mingw32ce
```
Linux, Cygwin, WSL, macOS 等の UNIX 環境で使用できる Windows CE 開発環境です。Windows XP のような古い Windows 環境が不要で、GCC 9.3.0 ベースなので C++17 を完全にサポートしているなど、現在では最も使いやすい環境です。ただし、個人の方が作成されたものだというのもあり、若干癖があります。

終わったら、以下のコマンドを入力します。

```bash
arm-mingw32ce-g++ -v
```

以下のような出力が得られれば環境構築は終了です。お疲れさまでした!コマンドが見つからないというエラーが出た場合は、正しくインストールできていないので今までの手順をもう一度確認してください。

```
Using built-in specs.
COLLECT_GCC=arm-mingw32ce-g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/arm-mingw32ce/9.3.0/lto-wrapper
Target: arm-mingw32ce
Configured with: ../../../configure --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-mingw32ce --disable-dependency-tracking --prefix=/usr --syscon
fdir=/etc --with-gcc --with-gnu-ld --with-gnu-as --enable-threads=win32 --disable-nls --enable-languages=c,c++ --disable-win32-registry --disable-multilib --dis
able-interwork --without-newlib --enable-checking --with-headers --disable-__cxa_atexit
Thread model: win32
gcc version 9.3.0 (GCC)
```

### ビルド
[`brain.cpp`](https://gist.github.com/watamario15/0ce68d7825062094c7282fdc7c762efe) を配置したディレクトリで、以下のコマンドを実行します。
まず、[こちら](https://brain.fandom.com/ja/wiki/CeGCC)を参考に導入します。その後、[`brain.cpp`](https://gist.github.com/watamario15/0ce68d7825062094c7282fdc7c762efe) を配置したディレクトリで、以下のコマンドを実行します。

```bash
arm-mingw32ce-g++ -Wall -Wextra -O3 -std=gnu++2a -march=armv5tej -mcpu=arm926ej-s -static -s -o AppMain.exe brain.cpp
Expand All @@ -113,9 +58,11 @@ CeGCC のヘッダファイルは通常版 Windows のものが流用されて
また、CeGCC の公式ビルドはデバッグ情報を取り除く strip 処理が行われていないため、開発したアプリケーションを Brain 上で動かすときに必要な C/C++ ランタイムを普通に静的リンクすると、極端に exe のサイズが大きくなります。これに対応するため、挙げたコマンドやスクリプトでは strip を表す `-s` オプションを付けてあります。

## eMbedded Visual C++ 4.0
知る人ぞ知る、2000 年頃の Windows CE 用 Microsoft 純正無料 IDE です。激古なので C++ の新しい機能は使えず、Windows 2000 と Windows XP でしかフル機能が使えないという難点がありますが、最新の CeGCC が発見されるまでは唯一の無料で使える開発環境でした。
知る人ぞ知る、2000 年頃の Windows CE 用 Microsoft 純正無料 IDE です。激古なので C++ の新しい機能は使えず、Windows 2000 と Windows XP でしかフル機能が使えないという難点がありますが、先述の CeGCC が発見されるまでは唯一の無料で使える開発環境でした。

### 環境構築
Arm 版の Windows 10/11 を使用している場合は、予め [winevdm](https://github.com/otya128/winevdm) と [ntvdm64.dll](https://github.com/otya128/ntvdm64.dll) をインストールしておく必要があります(DLL 側の Readme の手順に従う)。この方法では eVC4 のインストーラが Standard SDK のインストールまで一貫して行うようです。

まず、 [Microsoft Download Center](https://web.archive.org/web/20201130112637/https://www.microsoft.com/ja-jp/download/details.aspx?id=24809)([直リン](https://web.archive.org/web/20201008100955/https://download.microsoft.com/download/f/7/1/f711e5dd-fd65-421b-8da9-34707a73c310/JA_eVC4.exe))からダウンロードします。これは自動解凍式の圧縮ファイルになっているので、実行して適当な場所に解凍します。それで得られたファイルの `setup.exe` を実行し、手順に従ってインストールします。途中でプロダクトキーを聞かれますが、先ほどのダウンロードページの「インストール方法」欄に記載されているものを入力すれば大丈夫です。

次に、Windows 2000, XP の場合は [Service Pack 4](https://web.archive.org/web/20210120144550/https://www.microsoft.com/ja-jp/download/details.aspx?id=16683)([直リン](https://web.archive.org/web/20201008101356/https://download.microsoft.com/download/b/f/d/bfd2a609-ee3a-4ac3-931b-06030d251eef/evc4sp4JPN.exe))、Windows Vista 以降の場合は [Service Pack 3](https://web.archive.org/web/20180420090632/http://www.microsoft.com/ja-jp/download/details.aspx?id=4800)([直リン](https://web.archive.org/web/20180420090715/https://download.microsoft.com/download/3/9/e/39e7ef4d-8c26-482b-8133-5e07c7c5b208/evc4sp3JPN.exe))をダウンロードして、同様の手順でインストールします。
Expand Down Expand Up @@ -164,7 +111,6 @@ CeGCC のヘッダファイルは通常版 Windows のものが流用されて
## Pocket GCC
SHARP Brain 上でのセルフ開発が可能な GCC の Windows CE 移植版コンパイラです。eVC4 よりさらに機能は限られますが、PC がなくても使用できます。

### 準備
まず、[こちら](https://brain.fandom.com/ja/wiki/%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0)を参考に導入します。DOS窓Open の準備も必要です。

一通り終わったら、[`brain.cpp`](https://gist.github.com/watamario15/0ce68d7825062094c7282fdc7c762efe) を `win.cpp` に改名したものと [`WINBUILD.BAT`](https://raw.githubusercontent.com/watamario15/prime-calculator/master/PocketGCC%201.50/WINBUILD.BAT) を電子辞書内の同じフォルダに入れます。この際、`WINBUILD.BAT` の 2 行目と 3 行目を環境に合わせて編集しておきます。
Expand Down