summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/battle_anims/anim_commands.asm66
-rw-r--r--engine/battle_anims/bg_effects.asm12
-rw-r--r--engine/battle_anims/core.asm53
-rw-r--r--engine/battle_anims/helpers.asm7
-rw-r--r--engine/gfx/sprites.asm22
5 files changed, 89 insertions, 71 deletions
diff --git a/engine/battle_anims/anim_commands.asm b/engine/battle_anims/anim_commands.asm
index f6c6b06a6..135ec31ea 100644
--- a/engine/battle_anims/anim_commands.asm
+++ b/engine/battle_anims/anim_commands.asm
@@ -112,10 +112,10 @@ RunBattleAnimScript:
cp ROLLOUT
jr nz, .not_rollout
- ld a, $2e
- ld b, 5
- ld de, 4
- ld hl, wActiveBGEffects
+ ld a, ANIM_BG_2E
+ ld b, NUM_BG_EFFECTS
+ ld de, BG_EFFECT_STRUCT_LENGTH
+ ld hl, wBGEffect1Function
.find
cp [hl]
jr z, .done
@@ -128,10 +128,10 @@ RunBattleAnimScript:
.done
ld a, [wBattleAnimFlags]
- bit 0, a
+ bit BATTLEANIM_STOP_F, a
jr z, .playframe
- call BattleAnim_ClearCGB_OAMFlags
+ call BattleAnim_ClearOAM
ret
BattleAnimClearHud:
@@ -232,16 +232,17 @@ Unreferenced_Functioncc220:
call BattleAnimDelayFrame
ret
-BattleAnim_ClearCGB_OAMFlags:
+BattleAnim_ClearOAM:
ld a, [wBattleAnimFlags]
- bit 3, a
+ bit BATTLEANIM_KEEPSPRITES_F, a
jr z, .delete
+ ; Instead of deleting the sprites, make them all use palette 0 (monochrome)
ld hl, wVirtualOAMSprite00Attributes
ld c, NUM_SPRITE_OAM_STRUCTS
.loop
ld a, [hl]
- and $f0
+ and ~PALETTE_MASK & ~VRAM_BANK_1
ld [hli], a
rept SPRITEOAMSTRUCT_LENGTH + -1
inc hl
@@ -267,12 +268,12 @@ RunBattleAnimCommand:
ret
.CheckTimer:
- ld a, [wBattleAnimDuration]
+ ld a, [wBattleAnimDelay]
and a
jr z, .done
dec a
- ld [wBattleAnimDuration], a
+ ld [wBattleAnimDelay], a
and a
ret
@@ -289,17 +290,17 @@ RunBattleAnimCommand:
; Return from a subroutine.
ld hl, wBattleAnimFlags
- bit 1, [hl]
+ bit BATTLEANIM_IN_SUBROUTINE_F, [hl]
jr nz, .do_anim
- set 0, [hl]
+ set BATTLEANIM_STOP_F, [hl]
ret
.not_done_with_anim
- cp $d0
+ cp anim_obj_command
jr nc, .do_anim
- ld [wBattleAnimDuration], a
+ ld [wBattleAnimDelay], a
ret
.do_anim
@@ -310,7 +311,7 @@ RunBattleAnimCommand:
.DoCommand:
; Execute battle animation command in [wBattleAnimByte].
ld a, [wBattleAnimByte]
- sub $d0
+ sub anim_obj_command
ld e, a
ld d, 0
@@ -361,7 +362,7 @@ BattleAnimCommands::
dw BattleAnimCmd_BGP
dw BattleAnimCmd_OBP0
dw BattleAnimCmd_OBP1
- dw BattleAnimCmd_ClearSprites
+ dw BattleAnimCmd_KeepSprites
dw BattleAnimCmd_F5
dw BattleAnimCmd_F6
dw BattleAnimCmd_F7
@@ -382,7 +383,7 @@ BattleAnimCmd_ED:
BattleAnimCmd_Ret:
ld hl, wBattleAnimFlags
- res 1, [hl]
+ res BATTLEANIM_IN_SUBROUTINE_F, [hl]
ld hl, wBattleAnimParent
ld e, [hl]
inc hl
@@ -413,7 +414,7 @@ BattleAnimCmd_Call:
inc hl
ld [hl], d
ld hl, wBattleAnimFlags
- set 1, [hl]
+ set BATTLEANIM_IN_SUBROUTINE_F, [hl]
ret
BattleAnimCmd_Jump:
@@ -430,12 +431,12 @@ BattleAnimCmd_Jump:
BattleAnimCmd_Loop:
call GetBattleAnimByte
ld hl, wBattleAnimFlags
- bit 2, [hl]
+ bit BATTLEANIM_IN_LOOP_F, [hl]
jr nz, .continue_loop
and a
jr z, .perpetual
dec a
- set 2, [hl]
+ set BATTLEANIM_IN_LOOP_F, [hl]
ld [wBattleAnimLoops], a
.continue_loop
ld hl, wBattleAnimLoops
@@ -456,7 +457,7 @@ BattleAnimCmd_Loop:
.return_from_loop
ld hl, wBattleAnimFlags
- res 2, [hl]
+ res BATTLEANIM_IN_LOOP_F, [hl]
ld hl, wBattleAnimAddress
ld e, [hl]
inc hl
@@ -643,10 +644,13 @@ BattleAnimCmd_ResetObp0:
ret
BattleAnimCmd_ClearObjs:
+; BUG: This function only clears the first 6+(2/3) objects
+
ld hl, wActiveAnimObjects
ld a, $a0
+ ; ld a, wActiveAnimObjectsEnd - wActiveAnimObjects
.loop
- ld [hl], $0
+ ld [hl], 0
inc hl
dec a
jr nz, .loop
@@ -693,7 +697,7 @@ endr
BattleAnimCmd_IncObj:
call GetBattleAnimByte
- ld e, 10
+ ld e, NUM_ANIM_OBJECTS
ld bc, wActiveAnimObjects
.loop
ld hl, BATTLEANIMSTRUCT_INDEX
@@ -718,8 +722,8 @@ BattleAnimCmd_IncObj:
BattleAnimCmd_IncBGEffect:
call GetBattleAnimByte
- ld e, 5
- ld bc, wActiveBGEffects
+ ld e, NUM_BG_EFFECTS
+ ld bc, wBGEffect1Function
.loop
ld hl, $0
add hl, bc
@@ -743,7 +747,7 @@ BattleAnimCmd_IncBGEffect:
BattleAnimCmd_SetObj:
call GetBattleAnimByte
- ld e, 10
+ ld e, NUM_ANIM_OBJECTS
ld bc, wActiveAnimObjects
.loop
ld hl, BATTLEANIMSTRUCT_INDEX
@@ -1152,9 +1156,9 @@ BattleAnimCmd_OAMOff:
ldh [hOAMUpdate], a
ret
-BattleAnimCmd_ClearSprites:
+BattleAnimCmd_KeepSprites:
ld hl, wBattleAnimFlags
- set 3, [hl]
+ set BATTLEANIM_KEEPSPRITES_F, [hl]
ret
BattleAnimCmd_F5:
@@ -1430,10 +1434,10 @@ BattleAnim_SetOBPals:
ret
BattleAnim_UpdateOAM_All:
- ld a, $0
+ ld a, 0
ld [wBattleAnimOAMPointerLo], a
ld hl, wActiveAnimObjects
- ld e, 10
+ ld e, NUM_ANIM_OBJECTS
.loop
ld a, [hl]
and a
diff --git a/engine/battle_anims/bg_effects.asm b/engine/battle_anims/bg_effects.asm
index 0f2e716ca..00eb9a4ce 100644
--- a/engine/battle_anims/bg_effects.asm
+++ b/engine/battle_anims/bg_effects.asm
@@ -10,7 +10,7 @@
ExecuteBGEffects:
ld hl, wActiveBGEffects
- ld e, 5
+ ld e, NUM_BG_EFFECTS
.loop
ld a, [hl]
and a
@@ -23,7 +23,7 @@ ExecuteBGEffects:
pop de
pop hl
.next
- ld bc, 4
+ ld bc, BG_EFFECT_STRUCT_LENGTH
add hl, bc
dec e
jr nz, .loop
@@ -31,12 +31,12 @@ ExecuteBGEffects:
QueueBGEffect:
ld hl, wActiveBGEffects
- ld e, 5
+ ld e, NUM_BG_EFFECTS
.loop
ld a, [hl]
and a
jr z, .load
- ld bc, 4
+ ld bc, BG_EFFECT_STRUCT_LENGTH
add hl, bc
dec e
jr nz, .loop
@@ -416,7 +416,7 @@ BattleBGEffect_BattlerObj_1Row:
.zero
call BGEffect_CheckFlyDigStatus
jr z, .not_flying_digging
- ld hl, wNumActiveBattleAnims
+ ld hl, wLastAnimObjectIndex
inc [hl]
call EndBattleBGEffect
ret
@@ -483,7 +483,7 @@ BattleBGEffect_BattlerObj_2Row:
.zero
call BGEffect_CheckFlyDigStatus
jr z, .not_flying_digging
- ld hl, wNumActiveBattleAnims
+ ld hl, wLastAnimObjectIndex
inc [hl]
call EndBattleBGEffect
ret
diff --git a/engine/battle_anims/core.asm b/engine/battle_anims/core.asm
index 65e16c792..171816f38 100644
--- a/engine/battle_anims/core.asm
+++ b/engine/battle_anims/core.asm
@@ -1,6 +1,6 @@
QueueBattleAnimation:
ld hl, wActiveAnimObjects
- ld e, 10
+ ld e, NUM_ANIM_OBJECTS
.loop
ld a, [hl]
and a
@@ -15,7 +15,7 @@ QueueBattleAnimation:
.done
ld c, l
ld b, h
- ld hl, wNumActiveBattleAnims
+ ld hl, wLastAnimObjectIndex
inc [hl]
call InitBattleAnimation
ret
@@ -38,7 +38,7 @@ endr
ld d, h
ld hl, BATTLEANIMSTRUCT_INDEX
add hl, bc
- ld a, [wNumActiveBattleAnims]
+ ld a, [wLastAnimObjectIndex]
ld [hli], a ; Index
ld a, [de]
inc de
@@ -80,32 +80,36 @@ endr
BattleAnimOAMUpdate:
call InitBattleAnimBuffer
call GetBattleAnimFrame
- cp -3
+ cp dowait_command
jp z, .done
- cp -4
+ cp delanim_command
jp z, .delete
+
push af
ld hl, wBattleAnimTempOAMFlags
- ld a, [wBattleAnimTempAddSubFlags]
+ ld a, [wBattleAnimTempFrameOAMFlags]
xor [hl]
- and $e0
+ and PRIORITY | Y_FLIP | X_FLIP
ld [hl], a
pop af
+
push bc
call GetBattleAnimOAMPointer
ld a, [wBattleAnimTempTileID]
- add [hl]
+ add [hl] ; tile offset
ld [wBattleAnimTempTileID], a
inc hl
- ld a, [hli]
+ ld a, [hli] ; oam data length
ld c, a
- ld a, [hli]
+ ld a, [hli] ; oam data pointer
ld h, [hl]
ld l, a
ld a, [wBattleAnimOAMPointerLo]
ld e, a
ld d, HIGH(wVirtualOAM)
+
.loop
+ ; Y Coord
ld a, [wBattleAnimTempYCoord]
ld b, a
ld a, [wBattleAnimTempYOffset]
@@ -114,16 +118,17 @@ BattleAnimOAMUpdate:
push hl
ld a, [hl]
ld hl, wBattleAnimTempOAMFlags
- bit 6, [hl]
+ bit OAM_Y_FLIP, [hl]
jr z, .no_yflip
add $8
xor $ff
inc a
-
.no_yflip
pop hl
add b
ld [de], a
+
+ ; X Coord
inc hl
inc de
ld a, [wBattleAnimTempXCoord]
@@ -134,43 +139,47 @@ BattleAnimOAMUpdate:
push hl
ld a, [hl]
ld hl, wBattleAnimTempOAMFlags
- bit 5, [hl]
+ bit OAM_X_FLIP, [hl]
jr z, .no_xflip
add $8
xor $ff
inc a
-
.no_xflip
pop hl
add b
ld [de], a
+
+ ; Tile ID
inc hl
inc de
ld a, [wBattleAnimTempTileID]
add BATTLEANIM_BASE_TILE
add [hl]
ld [de], a
+
+ ; Attributes
inc hl
inc de
ld a, [wBattleAnimTempOAMFlags]
ld b, a
ld a, [hl]
xor b
- and $e0
+ and PRIORITY | Y_FLIP | X_FLIP
ld b, a
ld a, [hl]
- and $10
+ and OBP_NUM
or b
ld b, a
ld a, [wBattleAnimTempPalette]
- and $f
+ and (PRIORITY | Y_FLIP | X_FLIP | OBP_NUM) ^ $ff
or b
ld [de], a
+
inc hl
inc de
ld a, e
ld [wBattleAnimOAMPointerLo], a
- cp $a0
+ cp LOW(wVirtualOAMEnd)
jr nc, .exit_set_carry
dec c
jr nz, .loop
@@ -193,10 +202,11 @@ InitBattleAnimBuffer:
ld hl, BATTLEANIMSTRUCT_01
add hl, bc
ld a, [hl]
- and %10000000
+
+ and PRIORITY
ld [wBattleAnimTempOAMFlags], a
xor a
- ld [wBattleAnimTempAddSubFlags], a
+ ld [wBattleAnimTempFrameOAMFlags], a
ld hl, BATTLEANIMSTRUCT_PALETTE
add hl, bc
ld a, [hl]
@@ -217,15 +227,18 @@ InitBattleAnimBuffer:
ld [wBattleAnimTempXOffset], a
ld a, [hli]
ld [wBattleAnimTempYOffset], a
+
ldh a, [hBattleTurn]
and a
ret z
+
ld hl, BATTLEANIMSTRUCT_01
add hl, bc
ld a, [hl]
ld [wBattleAnimTempOAMFlags], a
bit 0, [hl]
ret z
+
ld hl, BATTLEANIMSTRUCT_XCOORD
add hl, bc
ld a, [hli]
diff --git a/engine/battle_anims/helpers.asm b/engine/battle_anims/helpers.asm
index 4a7f2950c..64d43f032 100644
--- a/engine/battle_anims/helpers.asm
+++ b/engine/battle_anims/helpers.asm
@@ -37,16 +37,16 @@ GetBattleAnimFrame:
push af
ld a, [hl]
push hl
- and $3f
+ and (Y_FLIP << 1 | X_FLIP << 1) ^ $ff
ld hl, BATTLEANIMSTRUCT_DURATION
add hl, bc
ld [hl], a
pop hl
.okay
ld a, [hl]
- and $c0
+ and Y_FLIP << 1 | X_FLIP << 1 ; The << 1 is compensated in the "frame" macro
srl a
- ld [wBattleAnimTempAddSubFlags], a
+ ld [wBattleAnimTempFrameOAMFlags], a
pop af
ret
@@ -55,6 +55,7 @@ GetBattleAnimFrame:
ld hl, BATTLEANIMSTRUCT_DURATION
add hl, bc
ld [hl], a
+
ld hl, BATTLEANIMSTRUCT_FRAME
add hl, bc
dec [hl]
diff --git a/engine/gfx/sprites.asm b/engine/gfx/sprites.asm
index 76519eb62..79cd71671 100644
--- a/engine/gfx/sprites.asm
+++ b/engine/gfx/sprites.asm
@@ -315,8 +315,8 @@ UpdateAnimFrame:
AddOrSubtractY:
push hl
ld a, [hl]
- ld hl, wCurSpriteAddSubFlags
- bit 6, [hl]
+ ld hl, wCurSpriteOAMFlags
+ bit OAM_Y_FLIP, [hl]
jr z, .ok
; 8 - a
add $8
@@ -330,8 +330,8 @@ AddOrSubtractY:
AddOrSubtractX:
push hl
ld a, [hl]
- ld hl, wCurSpriteAddSubFlags
- bit 5, [hl] ; x flip
+ ld hl, wCurSpriteOAMFlags
+ bit OAM_X_FLIP, [hl]
jr z, .ok
; 8 - a
add $8
@@ -343,20 +343,20 @@ AddOrSubtractX:
ret
GetSpriteOAMAttr:
- ld a, [wCurSpriteAddSubFlags]
+ ld a, [wCurSpriteOAMFlags]
ld b, a
ld a, [hl]
xor b
- and $e0
+ and PRIORITY | Y_FLIP | X_FLIP
ld b, a
ld a, [hl]
- and $1f
+ and (PRIORITY | Y_FLIP | X_FLIP) ^ $ff
or b
ret
InitSpriteAnimBuffer:
xor a
- ld [wCurSpriteAddSubFlags], a
+ ld [wCurSpriteOAMFlags], a
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld a, [hli]
@@ -436,7 +436,7 @@ GetSpriteAnimFrame:
push af
ld a, [hl]
push hl
- and $3f
+ and (Y_FLIP << 1 | X_FLIP << 1) ^ $ff
ld hl, SPRITEANIMSTRUCT_DURATIONOFFSET
add hl, bc
add [hl]
@@ -446,9 +446,9 @@ GetSpriteAnimFrame:
pop hl
.okay
ld a, [hl]
- and $c0
+ and Y_FLIP << 1 | X_FLIP << 1 ; The << 1 is compensated in the "frame" macro
srl a
- ld [wCurSpriteAddSubFlags], a
+ ld [wCurSpriteOAMFlags], a
pop af
ret