2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Python】GBDKで作成したROMをPyBoyで動作させるメモ

Last updated at Posted at 2020-06-20

GBDKで作成したROMをPyBoyで動作させるメモです。
今回の実装は以下リポジトリで公開しています。
https://github.com/Kazuhito00/pyboy-gbdk-examples

PyBoyとは

Pythonで記述されたゲームボーイのエミュレータです。
ただのエミュレータではなく、強化学習のプラットフォームも目指して開発しているようです。
https://github.com/Baekalfen/PyBoy

GBDKとは

GameBoy Developers Kitの略で、C言語またはアセンブリ言語でゲームボーイのソフトが開発できるフリーウェアです。
http://gbdk.sourceforge.net/

Installation

GBDK

  1. GBDK本体を以下リンクよりダウンロード
    https://sourceforge.net/projects/gbdk/files/gbdk/
    本サンプルではWindows版(gbdk-2.95-win32.zip)を使用。
  2. 「C:\gbdk」などの任意のフォルダに解凍
  3. Windowsのシステム環境変数に「C:\gbdk\bin」を追加
    ※「C:\gbdk」以外に解凍した場合は、解答場所に合わせてパスを変更要

PyBoy

  1. SDL2をインストール

     Ubuntu: sudo apt install libsdl2-dev

     Fedora: sudo dnf install SDL2-devel

     macOS: brew install sdl2

     Windows: (New-Object Net.WebClient).DownloadFile('https://www.libsdl.org/release/SDL2-devel-2.0.10-VC.zip', 'SDL2-devel-2.0.10-VC.zip')

      : Expand-Archive -Force 'SDL2-devel-2.0.10-VC.zip' C:\SDL2\

      : setx PYSDL2_DLL_PATH C:\SDL2\SDL2-2.0.10\lib\x64

      : setx PATH "%PATH%;C:\SDL2\SDL2-2.0.10\lib\x64"
  2. PyBoyをpipインストール

    python3 -m pip install --upgrade pip

    python3 -m pip install pyboy

※詳しくは公式のInstallationを参照

Hello World

printf()でハロワが出来ます。

hello_world.c
# include <stdio.h>
# include <gb/gb.h>
# include <gb/console.h>

int main(void)
{
    gotoxy(0, 0);  // 描画座標指定
    printf("Hello World\n");
}

GBDKのLCCと言うコンパイラでコンパイル。

c:\gbdk\bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -c -o hello_world.o hello_world.c
c:\gbdk\bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wl-yt2 -Wl-yo4 -Wl-ya4 -o hello_world.gb hello_world.o

PyBoyで起動

from pyboy import PyBoy

# PyBoy起動
color_palette = [0xd6e895, 0xacc04c, 0x527d3e, 0x264a2e]  # ゲームボーイっぽい色パレット指定
pyboy = PyBoy('hello_world.gb', color_palette=color_palette)

while not pyboy.tick():
    pass

以下のようなウィンドウが出れば成功。
2020-06-20 (7).png

以上。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?