0
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?

アセンブリでGameBoyのコードを書く環境を導入

0
Posted at

GameBoyエミュレータ導入

curl -L https://github.com/LIJI32/SameBoy/archive/refs/heads/master.tar.gz -o sameboy.tar.gz
tar xzf sameboy.tar.gz

make sdl CONF=release

./build/bin/SDL/sameboy

ビルドに必要

必要に応じて入れる

sudo apt install libpng-dev

RGBDS導入

curl -L https://github.com/gbdev/rgbds/releases/download/v0.8.0/rgbds-0.8.0-linux-x86_64.tar.xz -o rgbds.tar.xz
mkdir rgbds

tar xf rgbds.tar.xz -C rgbds
cd rgbds
sudo cp rgbasm rgblink rgbfix rgbgfx /usr/local/bin/
rgbasm -o hello.o hello.asm && \
rgblink -o hello.gb hello.o && \
rgbfix -v -p 0xFF hello.gb && \
../SameBoy-master/build/bin/SDL/sameboy hello.gb

動かしてみる

筆者には8080やz80の知識がまだ無く、書けないので一旦動作確認の為にGPTで縞を表示するコードを書きました。
縞になっていないのでゲームボーイの仕様を理解してから自分で書いてみます。
截图 2026-09-02 21-59-18

hello.asm
SECTION "Entry", ROM0[$0100]
    jp start

SECTION "Main", ROM0[$0150]

start:
    di
    ld sp, $FFFE

wait_vblank:
    ld a, [$FF44]
    cp 144
    jr c, wait_vblank

    xor a
    ld [$FF40], a

    ; VRAM $8000-$97FF clear (6144 bytes)
    ld hl, $8000
    ld bc, 6144
    xor a
vram_clear:
    ld [hl+], a
    dec bc
    ld a, b
    or c
    jr nz, vram_clear

    ; Tile 0: top 8 rows white, bottom 8 rows black
    ld hl, $8000
    xor a
    REPT 8
    ld [hl+], a
    ENDR
    ld a, $FF
    REPT 8
    ld [hl+], a
    ENDR

    ; Tile map $9800-$9BFF = tile 0
    ld hl, $9800
    ld bc, 1024
    xor a
fill_map:
    ld [hl+], a
    dec bc
    ld a, b
    or c
    jr nz, fill_map

    ; LCD on
    ld a, %10010001
    ld [$FF40], a

forever:
    jr forever
0
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
0
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?