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?

専用ツール不要!NASMと機械語直書きで挑むゲームボーイ開発入門

Last updated at Posted at 2025-10-08

目的

任天堂ゲームボーイ上で動くプログラムを作成します。
普通はゲームボーイ用のコンパイラやアセンブラを使いますが、NASMを使い「無理やり」機械語をバイナリとして生成します。

ゲームボーイのCPUはZ80と8080を基に拡張したような感じになっています。

test.as
db 0xC3,0x50,0x01       ; JP Start

; Nintendoロゴ 48バイト
db 0xCE,0xED,0x66,0x66,0xCC,0x0D,0x00,0x0B
db 0x03,0x73,0x00,0x83,0x00,0x0C,0x00,0x0D
db 0x00,0x08,0x11,0x1F,0x88,0x89,0x00,0x0E
db 0xDC,0xCC,0x6E,0xE6,0xDD,0xDD,0xD9,0x99
db 0xBB,0xBB,0x67,0x63,0x6E,0x0E,0xEC,0xCC
db 0xDD,0xDC,0x99,0x9F,0xBB,0xB9,0x33,0x3E

times 0x0150-($-$$) db 0

; Start
; LCD OFF
db 0x3E,0x00           ; LD A,0
db 0xE0,0x40           ; LDH (0xFF40),A

; 0x8000, タイルパターンの開始アドレス
db 0x21,0x00,0x80      ; LD HL,0x8000

%rep 16                ; 16回繰り返す
db 0x36,0x55           ; LD (HL),0x55
db 0x23                ; INC HL
%endrep

; 背景マップ 0x98000x9BFF  0番タイルを埋める
db 0x21,0x00,0x98      ; LD HL,0x9800

; LCD ON
db 0x3E,0x91
db 0xE0,0x40

MainLoop:
db 0x18,0xFE           ; JR MainLoop (-2)

; 32KB 0埋め
times 32768-($-$$) db 0

検証結果

test@test-ThinkPad-X280:~/test$ nasm -f bin -o test.gb test.asm
test@test-ThinkPad-X280:~/test$ sameboy test.gb

エミュレータ上で縦縞が表示されました。
image.png

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?