summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAroymart <andrewrmartinek@gmail.com>2020-12-06 20:55:10 -0500
committerGitHub <noreply@github.com>2020-12-06 20:55:10 -0500
commitdb90dae74cc91f53e9ec815531572bdd295efacc (patch)
tree7f5038ab342e9160a25e17a0e55d1b96efd2d920
parent66a5ec1006d54e0e48d544bc0514fba169d47954 (diff)
parent93df19eba83c7f18cb7a0960045ad269391b8bbe (diff)
Merge pull request #70 from anmart/master
Uncover Sprite system from MapDataPointers
-rw-r--r--src/constants/sprite_constants.asm39
-rw-r--r--src/engine/bank03.asm12
-rw-r--r--src/engine/bank04.asm210
-rw-r--r--src/engine/bank07.asm6
-rw-r--r--src/engine/bank20.asm24
-rw-r--r--src/engine/home.asm140
-rw-r--r--src/macros/wram.asm30
-rw-r--r--src/wram.asm12
8 files changed, 303 insertions, 170 deletions
diff --git a/src/constants/sprite_constants.asm b/src/constants/sprite_constants.asm
index dc051d9..8447934 100644
--- a/src/constants/sprite_constants.asm
+++ b/src/constants/sprite_constants.asm
@@ -3,20 +3,33 @@ SPRITE_ANIM_BUFFER_CAPACITY EQU 16 ; sprites
; sprite_anim_struct constants
const_def
- const SPRITE_ANIM_FIELD_00
- const SPRITE_ANIM_FIELD_01
+ const SPRITE_ANIM_ENABLED
+ const SPRITE_ANIM_ATTRIBUTES
const SPRITE_ANIM_COORD_X
const SPRITE_ANIM_COORD_Y
const SPRITE_ANIM_TILE_ID
- const SPRITE_ANIM_FIELD_05
- const SPRITE_ANIM_FIELD_06
- const SPRITE_ANIM_FIELD_07
- const SPRITE_ANIM_FIELD_08
- const SPRITE_ANIM_FIELD_09
- const SPRITE_ANIM_FIELD_0A
- const SPRITE_ANIM_FIELD_0B
- const SPRITE_ANIM_FIELD_0C
- const SPRITE_ANIM_FIELD_0D
- const SPRITE_ANIM_MOVEMENT_COUNTER
- const SPRITE_ANIM_FIELD_0F
+ const SPRITE_ANIM_ID
+ const SPRITE_ANIM_BANK
+ const SPRITE_ANIM_POINTER
+const_value = const_value+1 ; pointer
+ const SPRITE_ANIM_FRAME_OFFSET_POINTER
+const_value = const_value+1 ; pointer
+ const SPRITE_ANIM_FRAME_BANK
+ const SPRITE_ANIM_FRAME_DATA_POINTER
+const_value = const_value+1 ; pointer
+ const SPRITE_ANIM_COUNTER
+ const SPRITE_ANIM_FLAGS
SPRITE_ANIM_LENGTH EQU const_value
+
+; SPRITE_ANIM_FLAGS values
+ const_def
+ const SPRITE_ANIM_FLAG_X_SUBTRACT
+ const SPRITE_ANIM_FLAG_Y_SUBTRACT
+ const SPRITE_ANIM_FLAG_SPEED
+ const SPRITE_ANIM_FLAG_3
+ const SPRITE_ANIM_FLAG_4
+ const SPRITE_ANIM_FLAG_5
+ const SPRITE_ANIM_FLAG_6
+ const SPRITE_ANIM_FLAG_SKIP_DRAW
+
+SPRITE_FRAME_OFFSET_SIZE EQU 4
diff --git a/src/engine/bank03.asm b/src/engine/bank03.asm
index 1f1e690..4925b76 100644
--- a/src/engine/bank03.asm
+++ b/src/engine/bank03.asm
@@ -681,7 +681,7 @@ Func_c58b: ; c58b (3:458b)
call GetPermissionOfMapPosition
and $10
push af
- ld c, SPRITE_ANIM_FIELD_0F
+ ld c, SPRITE_ANIM_FLAGS
call GetSpriteAnimBufferProperty
pop af
ld a, [hl]
@@ -747,7 +747,7 @@ UpdatePlayerSprite: ; c5e9 (3:45e9)
ld b, a
ld a, [wPlayerDirection]
add b
- farcall Func_12ab5
+ farcall StartNewSpriteAnimation
pop bc
ret
@@ -790,10 +790,10 @@ AttemptPlayerMovement: ; c619 (3:4619)
ld [wPlayerCurrentlyMoving], a
ld a, $10
ld [wd338], a
- ld c, SPRITE_ANIM_FIELD_0F
+ ld c, SPRITE_ANIM_FLAGS
call GetSpriteAnimBufferProperty
set 2, [hl]
- ld c, SPRITE_ANIM_MOVEMENT_COUNTER
+ ld c, SPRITE_ANIM_COUNTER
call GetSpriteAnimBufferProperty
ld a, $4
ld [hl], a
@@ -920,10 +920,10 @@ Func_c6dc: ; c6dc (3:46dc)
Func_c6f7: ; c6f7 (3:46f7)
ld a, [wPlayerSpriteIndex]
ld [wWhichSprite], a
- ld c, SPRITE_ANIM_FIELD_0F
+ ld c, SPRITE_ANIM_FLAGS
call GetSpriteAnimBufferProperty
res 2, [hl]
- ld c, SPRITE_ANIM_MOVEMENT_COUNTER
+ ld c, SPRITE_ANIM_COUNTER
call GetSpriteAnimBufferProperty
ld a, $ff
ld [hl], a
diff --git a/src/engine/bank04.asm b/src/engine/bank04.asm
index 13df81b..6564bfc 100644
--- a/src/engine/bank04.asm
+++ b/src/engine/bank04.asm
@@ -509,7 +509,7 @@ Func_10fbc: ; 10fbc (4:4fbc)
ld b, $37
.asm_10fd8
ld a, b
- farcall Func_12ab5
+ farcall StartNewSpriteAnimation
ret
Func_10fde: ; 10fde (4:4fde)
@@ -529,12 +529,12 @@ Func_10fde: ; 10fde (4:4fde)
.asm_10ffe
ld a, b
ld [wd33c], a
- call Func_12ab5
+ call StartNewSpriteAnimation
ld a, $3e
farcall GetEventFlagValue
or a
jr nz, .asm_11015
- ld c, SPRITE_ANIM_FIELD_0F
+ ld c, SPRITE_ANIM_FLAGS
call GetSpriteAnimBufferProperty
set 7, [hl]
.asm_11015
@@ -545,7 +545,7 @@ Func_11016: ; 11016 (4:5016)
ld [wWhichSprite], a
ld a, [wd33c]
inc a
- call Func_12ab5
+ call StartNewSpriteAnimation
ret
Func_11024: ; 11024 (4:5024)
@@ -553,7 +553,7 @@ Func_11024: ; 11024 (4:5024)
call PlaySFX
ld a, [wPlayerSpriteIndex]
ld [wWhichSprite], a
- ld c, SPRITE_ANIM_FIELD_0F
+ ld c, SPRITE_ANIM_FLAGS
call GetSpriteAnimBufferProperty
set 2, [hl]
ld hl, Unknown_1229f
@@ -1244,7 +1244,7 @@ CreateSpriteAndAnimBufferEntry: ; 1299f (4:699f)
push bc
push hl
call Func_12c05
- ld [wd5d3], a
+ ld [wCurrSpriteTileID], a
xor a
ld [wWhichSprite], a
call GetFirstSpriteAnimBufferProperty
@@ -1284,13 +1284,13 @@ FillNewSpriteAnimBufferEntry: ; 129d9 (4:69d9)
dec c
jr nz, .clearSpriteAnimBufferEntryLoop
pop hl
- ld bc, SPRITE_ANIM_FIELD_05 - 1
+ ld bc, SPRITE_ANIM_ID - 1
add hl, bc
- ld a, [wd5d3]
+ ld a, [wCurrSpriteTileID]
ld [hli], a
ld a, $ff
ld [hl], a
- ld bc, SPRITE_ANIM_MOVEMENT_COUNTER - SPRITE_ANIM_FIELD_05
+ ld bc, SPRITE_ANIM_COUNTER - SPRITE_ANIM_ID
add hl, bc
ld a, $ff
ld [hl], a
@@ -1301,41 +1301,145 @@ FillNewSpriteAnimBufferEntry: ; 129d9 (4:69d9)
INCROM $129fa, $12a21
-Func_12a21: ; 12a21 (4:6a21)
- INCROM $12a21, $12ab5
+HandleAllSpriteAnimations: ; 12a21 (4:6a21)
+ push af
+ ld a, [wd5d7] ; skip animating this frame if enabled
+ or a
+ jr z, .continue
+ pop af
+ ret
+.continue
+ pop af
+ push af
+ push bc
+ push de
+ push hl
+ call ZeroObjectPositions
+ xor a
+ ld [wWhichSprite], a
+ call GetFirstSpriteAnimBufferProperty
+.spriteLoop
+ ld a, [hl]
+ or a
+ jr z, .nextSprite ; skip if SPRITE_ANIM_ENABLED is 0
+ call TryHandleSpriteAnimationFrame
+ call LoadSpriteDataForAnimationFrame
+.nextSprite
+ ld bc, SPRITE_ANIM_LENGTH
+ add hl, bc
+ ld a, [wWhichSprite]
+ inc a
+ ld [wWhichSprite], a
+ cp SPRITE_ANIM_BUFFER_CAPACITY
+ jr nz, .spriteLoop
+ ld hl, wVBlankOAMCopyToggle
+ inc [hl]
+ pop hl
+ pop de
+ pop bc
+ pop af
+ ret
-Func_12ab5: ; 12ab5 (4:6ab5)
+LoadSpriteDataForAnimationFrame: ; 12a5b (4:6a5b)
+ push hl
+ push bc
+ inc hl
+ ld a, [hli]
+ ld [wCurrSpriteAttributes], a
+ ld a, [hli]
+ ld [wCurrSpriteXPos], a
+ ld a, [hli]
+ ld [wCurrSpriteYPos], a
+ ld a, [hl]
+ ld [wCurrSpriteTileID], a
+ ld bc, SPRITE_ANIM_FLAGS - SPRITE_ANIM_TILE_ID
+ add hl, bc
+ ld a, [hl]
+ and 1 << SPRITE_ANIM_FLAG_SKIP_DRAW
+ jr nz, .quit
+ ld bc, SPRITE_ANIM_FRAME_BANK - SPRITE_ANIM_FLAGS
+ add hl, bc
+ ld a, [hli]
+ ld [wd5d6], a
+ or a
+ jr z, .quit
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call DrawSpriteAnimationFrame
+.quit
+ pop bc
+ pop hl
+ ret
+
+; decrements the given sprite's movement counter (2x if SPRITE_ANIM_FLAG_SPEED is set)
+; moves to the next animation frame if necessary
+TryHandleSpriteAnimationFrame: ; 12a8b (4:6a8b)
+ push hl
+ push bc
+ push de
+ push hl
+ ld d, 1
+ ld bc, SPRITE_ANIM_FLAGS
+ add hl, bc
+ bit SPRITE_ANIM_FLAG_SPEED, [hl]
+ jr z, .skipSpeedIncrease
+ inc d
+.skipSpeedIncrease
+ pop hl
+ ld bc, SPRITE_ANIM_COUNTER
+ add hl, bc
+ ld a, [hl]
+ cp $ff
+ jr z, .exit
+ sub d
+ ld [hl], a
+ jr z, .doNextAnimationFrame
+ jr nc, .exit
+.doNextAnimationFrame
+ ld bc, SPRITE_ANIM_ENABLED - SPRITE_ANIM_COUNTER
+ add hl, bc
+ call HandleAnimationFrame
+.exit
+ pop de
+ pop bc
+ pop hl
+ ret
+
+StartNewSpriteAnimation: ; 12ab5 (4:6ab5)
push hl
push af
- ld c, SPRITE_ANIM_FIELD_05
+ ld c, SPRITE_ANIM_ID
call GetSpriteAnimBufferProperty
pop af
cp [hl]
pop hl
ret z
push hl
- call Func_12ae2
- call Func_12b13
+ call LoadSpriteAnimPointers
+ call HandleAnimationFrame
pop hl
ret
; 0x12ac9
INCROM $12ac9, $12ae2
-Func_12ae2: ; 12ae2 (4:6ae2)
+; Given an animation ID, fills the current sprite's Animation Pointer and Frame Offset Pointer
+; a - Animation ID for current sprite
+LoadSpriteAnimPointers: ; 12ae2 (4:6ae2)
push bc
push af
call GetFirstSpriteAnimBufferProperty
pop af
push hl
- ld bc, $0005
+ ld bc, SPRITE_ANIM_ID
add hl, bc
ld [hli], a
push hl
- ld l, $6
+ ld l, 6 ; 4th entry in MapDataPointers
farcall GetMapDataPointer
- farcall Func_80229
- pop hl
+ farcall LoadGraphicsPointerFromHL
+ pop hl ; hl is animation bank
ld a, [wTempPointerBank]
ld [hli], a
ld a, [wTempPointer]
@@ -1354,60 +1458,63 @@ Func_12ae2: ; 12ae2 (4:6ae2)
pop bc
ret
-Func_12b13: ; 12b13 (4:6b13)
+; hl - beginning of current sprite_anim_buffer
+; Handles a full animation frame using all values in animation structure
+; (frame data offset, anim counter, X Mov, Y Mov)
+HandleAnimationFrame: ; 12b13 (4:6b13)
push bc
push de
push hl
-.asm_12b16
+.tryHandlingFrame
push hl
- ld bc, $0006
+ ld bc, SPRITE_ANIM_BANK
add hl, bc
ld a, [hli]
ld [wTempPointerBank], a
inc hl
inc hl
- ld a, [hl]
+ ld a, [hl] ; SPRITE_ANIM_FRAME_OFFSET_POINTER
ld [wTempPointer], a
- add $4
+ add SPRITE_FRAME_OFFSET_SIZE ; advance FRAME_OFFSET_POINTER by 1 frame, 4 bytes
ld [hli], a
ld a, [hl]
ld [wTempPointer + 1], a
- adc $0
+ adc 0
ld [hl], a
ld de, wd23e
- ld bc, $0004
+ ld bc, SPRITE_FRAME_OFFSET_SIZE
call CopyBankedDataToDE
- pop hl
+ pop hl ; beginning of current sprite_anim_buffer
ld de, wd23e
ld a, [de]
- call Func_12b6a
+ call GetAnimFramePointerFromOffset
inc de
ld a, [de]
- call Func_12b89
- jr c, .asm_12b16
+ call SetAimationCounterAndLoop
+ jr c, .tryHandlingFrame
inc de
- ld bc, $0002
+ ld bc, SPRITE_ANIM_COORD_X
add hl, bc
push hl
- ld bc, $000d
+ ld bc, SPRITE_ANIM_FLAGS - SPRITE_ANIM_COORD_X
add hl, bc
ld b, [hl]
pop hl
ld a, [de]
- bit 0, b
- jr z, .asm_12b5a
+ bit SPRITE_ANIM_FLAG_X_SUBTRACT, b
+ jr z, .addXOffset
cpl
inc a
-.asm_12b5a
+.addXOffset
add [hl]
ld [hli], a
inc de
ld a, [de]
- bit 1, b
- jr z, .asm_12b64
+ bit SPRITE_ANIM_FLAG_Y_SUBTRACT, b
+ jr z, .addYOffset
cpl
inc a
-.asm_12b64
+.addYOffset
add [hl]
ld [hl], a
pop hl
@@ -1415,13 +1522,16 @@ Func_12b13: ; 12b13 (4:6b13)
pop bc
ret
-Func_12b6a: ; 12b6a (4:6b6a)
+; Calls GetAnimationFramePointer after setting up wTempPointerBank and wd4ca
+; a - frame offset from Animation Data
+; hl - beginning of Sprite Anim Buffer
+GetAnimFramePointerFromOffset: ; 12b6a (4:6b6a)
ld [wd4ca], a
push hl
push bc
push de
push hl
- ld bc, $0006
+ ld bc, SPRITE_ANIM_BANK
add hl, bc
ld a, [hli]
ld [wTempPointerBank], a
@@ -1430,34 +1540,36 @@ Func_12b6a: ; 12b6a (4:6b6a)
ld a, [hli]
ld [wTempPointer + 1], a
pop hl
- call Func_3d72
+ call GetAnimationFramePointer ; calls with the original map data script pointer/bank
pop de
pop bc
pop hl
ret
-Func_12b89: ; 12b89 (4:6b89)
+; Sets the animation counter for the current sprite. If the value is zero, loop the animation
+; a - new animation counter
+SetAimationCounterAndLoop: ; 12b89 (4:6b89)
push hl
push bc
- ld bc, $000e
+ ld bc, SPRITE_ANIM_COUNTER
add hl, bc
ld [hl], a
or a
- jr nz, .asm_12ba4
- ld bc, $fff9
+ jr nz, .exit
+ ld bc, SPRITE_ANIM_POINTER - SPRITE_ANIM_COUNTER
add hl, bc
ld a, [hli]
- add $3
+ add 3 ; skip base bank/pointer at beginning of data structure
ld c, a
ld a, [hli]
- adc $0
+ adc 0
ld b, a
ld a, c
ld [hli], a
ld a, b
ld [hl], a
scf
-.asm_12ba4
+.exit
pop bc
pop hl
ret
diff --git a/src/engine/bank07.asm b/src/engine/bank07.asm
index 45cc8b1..9b109be 100644
--- a/src/engine/bank07.asm
+++ b/src/engine/bank07.asm
@@ -319,7 +319,7 @@ Func_1c58e: ; 1c58e (7:458e)
add [hl]
inc hl
.asm_1c5ae
- farcall Func_12ab5
+ farcall StartNewSpriteAnimation
.quit
pop af
ld [wWhichSprite], a
@@ -654,7 +654,7 @@ Func_1c94a:
call Func_1c980
pop af
- farcall Func_12ab5
+ farcall StartNewSpriteAnimation
or a
jr .return
@@ -667,7 +667,7 @@ Func_1c980: ; 1c980 (7:4980)
push hl
push bc
ld a, [wAnimationQueue]
- ld c, SPRITE_ANIM_FIELD_01
+ ld c, SPRITE_ANIM_ATTRIBUTES
call GetSpriteAnimBufferProperty_SpriteInA
call Func_1c9a2
diff --git a/src/engine/bank20.asm b/src/engine/bank20.asm
index b656f90..867ee77 100644
--- a/src/engine/bank20.asm
+++ b/src/engine/bank20.asm
@@ -276,6 +276,8 @@ Func_801f1: ; 801f1 (20:41f1)
pop hl
ret
+; l - map data offset (0,2,4,6,8 for banks 0,1,2,3,4)
+; a - map index (inside of the given bank)
GetMapDataPointer: ; 8020f (20:420f)
push bc
push af
@@ -296,13 +298,14 @@ GetMapDataPointer: ; 8020f (20:420f)
pop bc
ret
-Func_80229: ; 80229 (20:4229)
+; Loads a pointer from [hl] to wTempPointer. Adds the graphics bank offset ($20)
+LoadGraphicsPointerFromHL: ; 80229 (20:4229)
ld a, [hli]
ld [wTempPointer], a
ld a, [hli]
ld [wTempPointer + 1], a
ld a, [hli]
- add $20
+ add BANK(MapDataPointers)
ld [wTempPointerBank], a
ret
; 0x80238
@@ -313,7 +316,7 @@ Func_8025b: ; 8025b (20:425b)
push hl
ld l, $4
call GetMapDataPointer
- call Func_80229
+ call LoadGraphicsPointerFromHL
ld a, [hl]
push af
ld [wd4c8], a
@@ -390,7 +393,7 @@ Func_803b9: ; 803b9 (20:43b9)
ld l, $00
ld a, [wd131]
call GetMapDataPointer
- call Func_80229
+ call LoadGraphicsPointerFromHL
ld a, [hl]
ld [$d239], a
ret
@@ -515,15 +518,19 @@ Func_80baa: ; 80baa (20:4baa)
INCROM $80c21, $80e5a
-Unknown_80e5a: ; 80e5a (20:4e5a)
- INCROM $80e5a, $80e5d
+SpriteNullAnimationPointer: ; 80e5a (20:4e5a)
+ dw SpriteNullAnimationFrame
+
+SpriteNullAnimationFrame:
+ db 0
; might be closer to "screen specific data" than map data
+; data in each section is 4 bytes long.
MapDataPointers: ; 80e5d (20:4e5d)
dw MapDataPointers_80e67
dw MapDataPointers_8100f
dw MapDataPointers_8116b
- dw MapDataPointers_81333
+ dw SpriteAnimationPointers
dw MapDataPointers_81697
MapDataPointers_80e67: ; 80e67 (20:4e67)
@@ -535,7 +542,8 @@ MapDataPointers_8100f: ; 8100f (20:500f)
MapDataPointers_8116b: ; 8116b (20:516b)
INCROM $8116b, $81333
-MapDataPointers_81333: ; 81333 (20:5333)
+; pointer low, pointer high, bank (minus $20), unknown
+SpriteAnimationPointers: ; 81333 (20:5333)
INCROM $81333, $81697
MapDataPointers_81697: ; 81697 (20:5697)
diff --git a/src/engine/home.asm b/src/engine/home.asm
index 78e0bf1..03e8ca4 100644
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -11522,141 +11522,145 @@ Func_3ca4: ; 3ca4 (0:3ca4)
Func_3cb4: ; 3cb4 (0:3cb4)
ldh a, [hBankROM]
push af
- ld a, BANK(Func_12a21)
+ ld a, BANK(HandleAllSpriteAnimations)
call BankswitchROM
- call Func_12a21
+ call HandleAllSpriteAnimations
pop af
call BankswitchROM
ret
; 0x3cc4
-; refresh sprites?
-Func_3cc4: ; 3cc4 (0:3cc4)
+; hl - pointer to animation frame
+; wd5d6 - bank of animation frame
+DrawSpriteAnimationFrame: ; 3cc4 (0:3cc4)
ldh a, [hBankROM]
push af
ld a, [wd5d6]
call BankswitchROM
- ld a, [wd5d1]
+ ld a, [wCurrSpriteXPos]
cp $f0
- ld a, $00
- jr c, .asm_3cd7
+ ld a, 0
+ jr c, .notNearRight
dec a
-.asm_3cd7
- ld [wd5d4], a
- ld a, [wd5d2]
+.notNearRight
+ ld [wCurrSpriteRightEdgeCheck], a
+ ld a, [wCurrSpriteYPos]
cp $f0
- ld a, $00
- jr c, .asm_3ce4
+ ld a, 0
+ jr c, .setBottomEdgeCheck
dec a
-.asm_3ce4
- ld [wd5d5], a
+.setBottomEdgeCheck
+ ld [wCurrSpriteBottomEdgeCheck], a
ld a, [hli]
or a
jp z, .done
ld c, a
-.asm_3ced
+.loop
push bc
push hl
- ld b, $00
+ ld b, 0
bit 7, [hl]
- jr z, .asm_3cf6
+ jr z, .beginY
dec b
-.asm_3cf6
- ld a, [wd5d0]
- bit 6, a
- jr z, .asm_3d10
+.beginY
+ ld a, [wCurrSpriteAttributes]
+ bit OAM_Y_FLIP, a
+ jr z, .unflippedY
ld a, [hl]
- add $08
+ add 8 ; size of a tile
ld c, a
- ld a, $00
+ ld a, 0
adc b
ld b, a
- ld a, [wd5d2]
+ ld a, [wCurrSpriteYPos]
sub c
ld e, a
- ld a, [wd5d5]
+ ld a, [wCurrSpriteBottomEdgeCheck]
sbc b
- jr .asm_3d19
-.asm_3d10
- ld a, [wd5d2]
+ jr .finishYPosition
+.unflippedY
+ ld a, [wCurrSpriteYPos]
add [hl]
ld e, a
- ld a, [wd5d5]
+ ld a, [wCurrSpriteBottomEdgeCheck]
adc b
-.asm_3d19
+.finishYPosition
or a
- jr nz, .asm_3d64
+ jr nz, .endCurrentIteration
inc hl
- ld b, $00
+ ld b, 0
bit 7, [hl]
- jr z, .asm_3d24
+ jr z, .beginX
dec b
-.asm_3d24
- ld a, [wd5d0]
- bit 5, a
- jr z, .asm_3d3e
+.beginX
+ ld a, [wCurrSpriteAttributes]
+ bit OAM_X_FLIP, a
+ jr z, .unflippedX
ld a, [hl]
- add $08
+ add 8 ; size of a tile
ld c, a
- ld a, $00
+ ld a, 0
adc b
ld b, a
- ld a, [wd5d1]
+ ld a, [wCurrSpriteXPos]
sub c
ld d, a
- ld a, [wd5d4]
+ ld a, [wCurrSpriteRightEdgeCheck]
sbc b
- jr .asm_3d47
-.asm_3d3e
- ld a, [wd5d1]
+ jr .finishXPosition
+.unflippedX
+ ld a, [wCurrSpriteXPos]
add [hl]
ld d, a
- ld a, [wd5d4]
+ ld a, [wCurrSpriteRightEdgeCheck]
adc b
-.asm_3d47
+.finishXPosition
or a
- jr nz, .asm_3d64
+ jr nz, .endCurrentIteration
inc hl
- ld a, [wd5d3]
+ ld a, [wCurrSpriteTileID]
add [hl]
ld c, a
inc hl
- ld a, [wd5d0]
+ ld a, [wCurrSpriteAttributes]
add [hl]
- and $17
+ and OAM_PALETTE | (1 << OAM_OBP_NUM)
ld b, a
- ld a, [wd5d0]
+ ld a, [wCurrSpriteAttributes]
xor [hl]
- and $e0
+ and (1 << OAM_X_FLIP) | (1 << OAM_Y_FLIP) | (1 << OAM_PRIORITY)
or b
ld b, a
inc hl
call SetOneObjectAttributes
-.asm_3d64
+.endCurrentIteration
pop hl
- ld bc, $4
+ ld bc, 4 ; size of info for one sub tile
add hl, bc
pop bc
dec c
- jr nz, .asm_3ced
+ jr nz, .loop
.done
pop af
call BankswitchROM
ret
-; 0x3d72
-Func_3d72: ; 3d72 (0:3d72)
+; Loads a pointer to the current animation frame into SPRITE_ANIM_FRAME_DATA_POINTER using
+; the current frame's offset
+; [wd4ca] - current frame offset
+; wTempPointer* - Pointer to current Animation
+GetAnimationFramePointer: ; 3d72 (0:3d72)
ldh a, [hBankROM]
push af
push hl
push hl
ld a, [wd4ca]
cp $ff
- jr nz, .asm_3d84
- ld de, Unknown_80e5a
+ jr nz, .useLoadedOffset
+ ld de, SpriteNullAnimationPointer
xor a
- jr .asm_3da1
-.asm_3d84
+ jr .loadPointer
+.useLoadedOffset
ld a, [wTempPointer]
ld l, a
ld a, [wTempPointer + 1]
@@ -11672,13 +11676,13 @@ Func_3d72: ; 3d72 (0:3d72)
ld e, a
inc hl
ld a, [hl]
- adc $0
+ adc 0
ld d, a
pop af
-.asm_3da1
- add BANK(Unknown_80e5a)
+.loadPointer
+ add BANK(SpriteNullAnimationPointer)
pop hl
- ld bc, $000b
+ ld bc, SPRITE_ANIM_FRAME_BANK
add hl, bc
ld [hli], a
call BankswitchROM
@@ -11694,7 +11698,7 @@ Func_3d72: ; 3d72 (0:3d72)
GetFirstSpriteAnimBufferProperty: ; 3db7 (0:3db7)
push bc
- ld c, SPRITE_ANIM_FIELD_00
+ ld c, SPRITE_ANIM_ENABLED
call GetSpriteAnimBufferProperty
pop bc
ret
@@ -11729,7 +11733,7 @@ GetSpriteAnimBufferProperty_SpriteInA:
Func_3ddb: ; 3ddb (0:3ddb)
push hl
push bc
- ld c, SPRITE_ANIM_FIELD_0F
+ ld c, SPRITE_ANIM_FLAGS
call GetSpriteAnimBufferProperty_SpriteInA
res 2, [hl]
pop bc
@@ -11740,7 +11744,7 @@ Func_3ddb: ; 3ddb (0:3ddb)
Func_3de7: ; 3de7 (0:3de7)
push hl
push bc
- ld c, SPRITE_ANIM_FIELD_0F
+ ld c, SPRITE_ANIM_FLAGS
call GetSpriteAnimBufferProperty_SpriteInA
set 2, [hl]
pop bc
diff --git a/src/macros/wram.asm b/src/macros/wram.asm
index c8b9a88..8545972 100644
--- a/src/macros/wram.asm
+++ b/src/macros/wram.asm
@@ -46,24 +46,20 @@ text_header: MACRO
\1RomBank:: ds 1
ENDM
-; TODO: Figure out what the rest are for
sprite_anim_struct: MACRO
-\1Field0x00:: ds 1
-\1Field0x01:: ds 1 ; movement handling / palette
-\1CoordX:: ds 1
-\1CoordY:: ds 1
-\1TileID:: ds 1
-\1Field0x05:: ds 1
-\1Field0x06:: ds 1
-\1Field0x07:: ds 1
-\1Field0x08:: ds 1
-\1Field0x09:: ds 1
-\1Field0x0a:: ds 1
-\1Field0x0b:: ds 1
-\1Field0x0c:: ds 1
-\1Field0x0d:: ds 1
-\1MovementCounter:: ds 1
-\1Field0x0f:: ds 1
+\1Enabled:: ds 1
+\1Attributes:: ds 1
+\1CoordX:: ds 1
+\1CoordY:: ds 1
+\1TileID:: ds 1
+\1ID:: ds 1
+\1Bank:: ds 1
+\1Pointer:: ds 2
+\1FrameOffsetPointer:: ds 2
+\1FrameBank:: ds 1
+\1FrameDataPointer:: ds 2
+\1Counter:: ds 1
+\1Flags:: ds 1
ENDM
loaded_npc_struct: MACRO
diff --git a/src/wram.asm b/src/wram.asm
index a54a8d2..15a6e1a 100644
--- a/src/wram.asm
+++ b/src/wram.asm
@@ -2390,22 +2390,22 @@ wSpriteAnimBuffer:: ; d4d0
sprite_anim_struct wSprite15
sprite_anim_struct wSprite16
-wd5d0:: ; d5d0
+wCurrSpriteAttributes:: ; d5d0
ds $1
-wd5d1:: ; d5d1
+wCurrSpriteXPos:: ; d5d1
ds $1
-wd5d2:: ; d5d2
+wCurrSpriteYPos:: ; d5d2
ds $1
-wd5d3:: ; d5d3
+wCurrSpriteTileID:: ; d5d3
ds $1
-wd5d4:: ; d5d4
+wCurrSpriteRightEdgeCheck:: ; d5d4
ds $1
-wd5d5:: ; d5d5
+wCurrSpriteBottomEdgeCheck:: ; d5d5
ds $1
wd5d6:: ; d5d6