Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsuki105 committed May 9, 2020
1 parent 955162d commit 924bede
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 23 deletions.
20 changes: 20 additions & 0 deletions docs/oam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# OAM

OAM: Object Attribute Memory(スプライト属性テーブル)

\$FE00-\$FE9F(160バイト)に配置されるスプライトのプロパティを定義しているテーブル

1エントリ4バイトなのでOAMには160/4 = 40スプライト分のプロパティを格納できる

各エントリは

- 0byte: スプライトのY座標(px)
- 1byte: スプライトのX座標(px)
- 2byte: タイル番号
- 3byte: スプライトの属性

を定義している

## 参考

[VRAM Sprite Attribute Table (OAM)](https://gbdev.io/pandocs/#vram-sprite-attribute-table-oam)
7 changes: 7 additions & 0 deletions docs/sprite.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ NPCは基本ランダムウォークだが、たまに動きが一定つまり
## スプライトの移動

TODO

## Emotion Bubble

!マークなどの感情を表す吹き出しのこと

`engine/overworld/emotion_bubbles.asm`で詳細に定義されている

3 changes: 2 additions & 1 deletion docs/term.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
bg map | 背景マップ | $9800-$9BFF or $9C00-$9FFFのこと
coords | 座標 | ここでは16*16のマス目単位の座標を指す?
dialog box | ダイアログボックス | 会話時に出てくるテキストボックス
null | null | null
oam block | OAMブロック | 2*2のOAMタイルの塊 1OAMブロック=16\*16pxはポケモン赤のスプライトの基本的な大きさ
null | null | null
2 changes: 1 addition & 1 deletion engine/overworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cut2.asm | null
daycare_exp.asm | 育て屋のポケモンの経験値をインクリメントする処理
doors.asm | ドアタイルから強制的に下に歩かせる処理
elevator.asm | エレベータを揺らす処理
emotion_bubbles.asm | null
emotion_bubbles.asm | !マークなどの感情を表す吹き出しを表示させる処理
field_move_messages.asm | null
healing_machine.asm | null
hidden_items.asm | null
Expand Down
40 changes: 34 additions & 6 deletions engine/overworld/emotion_bubbles.asm
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
; **EmotionBubble**
; !マークなどの感情を表す吹き出しを表示させる処理
;
; INPUT: [wWhichEmotionBubble] = 対象のEmotion Bubble番号
EmotionBubble:
; hl = 対象のEmotionBubbleの画像データのポインタ
ld a, [wWhichEmotionBubble]
ld c, a
ld b, 0
ld hl, EmotionBubblesPointerTable
; 各エントリ2バイトなので2回Add
add hl, bc
add hl, bc

; de = 画像データ
ld e, [hl]
inc hl
ld d, [hl]

; EmotionBubbleのタイルデータをVRAMに転送
ld hl, vChars1 + $780
lb bc, BANK(EmotionBubbles), $04
call CopyVideoData

; スプライト表示を無効化
ld a, [wUpdateSpritesEnabled]
push af
ld a, $ff
ld [wUpdateSpritesEnabled], a

ld a, [wd736]
bit 6, a ; are the last 4 OAM entries reserved for a shadow or fishing rod?
bit 6, a
; 段差から降りている最中/釣り中のときはde, hlのポインタを変える
ld hl, wOAMBuffer + 4 * 35 + $3 ; $8f
ld de, wOAMBuffer + 4 * 39 + $3 ; $9f
jr z, .next
; それ以外のとき
ld hl, wOAMBuffer + 4 * 31 + $3 ; $7f
ld de, wOAMBuffer + 4 * 35 + $3 ; $8f

; Copy OAM data 16 bytes forward to make room for emotion bubble OAM data at the
; start of the OAM buffer.
; OAMのデータを16バイトほど前のアドレスのメモリに移動して、OAMBufferの開始地点にEmotion BuffleのOAMデータのためのスペースを確保
; INPUT:
; - de = コピー先
; - hl = コピー元
.next
ld bc, $90
ld bc, $90 ; 160 => OAMデータの長さ
.loop
ld a, [hl]
ld [de], a
Expand All @@ -38,36 +55,47 @@ EmotionBubble:
jr nz, .loop

; get the screen coordinates of the sprite the bubble is to be displayed above
; Emotion Bubbleを表示する対象のスプライトのcoordsを得る
; hl = 対象のスプライトの$c1x4
ld hl, wSpriteStateData1 + 4
ld a, [wEmotionBubbleSpriteIndex]
swap a
ld c, a
ld b, 0
add hl, bc

; b = スプライトのY座標
; c = スプライトのX座標 + 8
ld a, [hli]
ld b, a
inc hl
inc hl ; hl = $c1x6
ld a, [hl]
add $8
ld c, a

; OAMにEmotion bubbleのOAMデータを書き込む
ld de, EmotionBubblesOAM
xor a
call WriteOAMBlock
ld c, 60
call DelayFrames

pop af

; Emotion Bubbleを表示させる
ld [wUpdateSpritesEnabled], a
call DelayFrame
jp UpdateSprites

; EmotionBubbleの画像データのポインタのリスト
EmotionBubblesPointerTable:
dw EmotionBubbles
dw EmotionBubbles + $40
dw EmotionBubbles + $80

; EmotionBubbleのOAMデータ
EmotionBubblesOAM:
db $F8,$00,$F9,$00
db $F8,$00,$F9,$00 ; (Y座標, X座標, タイル番号, 属性)
db $FA,$00,$FB,$00

EmotionBubbles:
Expand Down
21 changes: 14 additions & 7 deletions home.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3997,15 +3997,21 @@ StringCmp::
jr nz, StringCmp
ret

; **WriteOAMBlock**
; OAMBufferにOAM blockのデータを書き込む
; OAM block: 2*2のOAMタイルの塊
;
; INPUT:
; a = oam block index (each block is 4 oam entries)
; b = Y coordinate of upper left corner of sprite
; c = X coordinate of upper left corner of sprite
; de = base address of 4 tile number and attribute pairs
; - a = OAM blockのインデックス
; - b = OAM blockの左上角のYcoord
; - c = OAM blockの左上角のXcoord
; - de = OAM blockの4つのタイル番号と属性のペアの開始アドレス
WriteOAMBlock::
; hl = 対象のOAM blockのwOAMBufferでの開始アドレス
ld h, wOAMBuffer / $100
swap a ; multiply by 16
swap a ; *= 16 => 各OAM blockは16バイトなので
ld l, a

call .writeOneEntry ; upper left
push bc
ld a, 8
Expand All @@ -4019,8 +4025,9 @@ WriteOAMBlock::
call .writeOneEntry ; lower left
ld a, 8
add c
ld c, a
; lower right
ld c, a
; lower right
; INPUT: [hl] = OAMエントリ
.writeOneEntry
ld [hl], b ; Y coordinate
inc hl
Expand Down
8 changes: 4 additions & 4 deletions vram.asm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
vChars0 EQU $8000
vChars1 EQU $8800
vChars0 EQU $8000 ; タイルアセットを配置する領域1
vChars1 EQU $8800 ; タイルアセットを配置する領域2
vChars2 EQU $9000
vBGMap0 EQU $9800
vBGMap1 EQU $9c00
vBGMap0 EQU $9800 ; BGマップ1
vBGMap1 EQU $9c00 ; BGマップ2

; Battle/Menu
vSprites EQU vChars0
Expand Down
10 changes: 6 additions & 4 deletions wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1201,11 +1201,13 @@ wSlotMachineRerollCounter:: ; cd4f
; The remaining number of times wheel 3 will roll down a symbol until a match is
; found, when winning is enabled. It's initialized to 4 each bet.

wEmotionBubbleSpriteIndex:: ; cd4f
; the index of the sprite the emotion bubble is to be displayed above
; cd4f
; Emotion Bubbleを表示する対象のスプライトのオフセット
wEmotionBubbleSpriteIndex::
ds 1

wWhichEmotionBubble:: ; cd50
; cd50
wWhichEmotionBubble::

wSlotMachineBet:: ; cd50
; how many coins the player bet on the slot machine (1 to 3)
Expand Down Expand Up @@ -3157,7 +3159,7 @@ wBeatLorelei:: ; d734
; - bit 0: プレイヤーがドアに立っているか確認し、そうであるなら下に1歩歩かせる
; - bit 1: 1ならプレイヤーは今、ドアから下に向かって歩いている状態である
; - bit 2: standing on a warp
; - bit 6: jumping down a ledge / fishing animation
; - bit 6: 段差をジャンプしているモーション中 / 釣りのモーション中に立つフラグ
; - bit 7: player sprite spinning due to spin tiles (Rocket hideout / Viridian Gym)
wd736::
ds 1
Expand Down

0 comments on commit 924bede

Please sign in to comment.