pokecrystal/engine/battle_anims/anim_commands.asm

1482 lines
22 KiB
NASM
Raw Normal View History

; Battle animation command interpreter.
2018-06-24 14:09:41 +00:00
PlayBattleAnim:
ldh a, [rSVBK]
push af
2018-01-23 22:39:09 +00:00
ld a, BANK(wActiveAnimObjects)
ldh [rSVBK], a
call _PlayBattleAnim
pop af
ldh [rSVBK], a
ret
2018-06-24 14:09:41 +00:00
_PlayBattleAnim:
ld c, 6
.wait
call BattleAnimDelayFrame
dec c
jr nz, .wait
call BattleAnimAssignPals
call BattleAnimRequestPals
call BattleAnimDelayFrame
ld c, 1
ldh a, [rKEY1]
bit 7, a
jr nz, .asm_cc0ff
ld c, 3
.asm_cc0ff
2015-01-20 05:31:29 +00:00
ld hl, hVBlank
ld a, [hl]
push af
ld [hl], c
2015-11-09 21:41:09 +00:00
call BattleAnimRunScript
pop af
ldh [hVBlank], a
ld a, 1
ldh [hBGMapMode], a
call BattleAnimDelayFrame
call BattleAnimDelayFrame
call BattleAnimDelayFrame
call WaitSFX
ret
2018-06-24 14:09:41 +00:00
BattleAnimRunScript:
2018-01-23 22:39:09 +00:00
ld a, [wFXAnimID + 1]
and a
2015-11-09 21:41:09 +00:00
jr nz, .hi_byte
2017-12-24 17:47:30 +00:00
farcall CheckBattleScene
2015-11-09 21:41:09 +00:00
jr c, .disabled
call BattleAnimClearHud
2015-11-09 21:41:09 +00:00
call RunBattleAnimScript
call BattleAnimAssignPals
call BattleAnimRequestPals
xor a
ldh [hSCX], a
ldh [hSCY], a
call BattleAnimDelayFrame
call BattleAnimRestoreHuds
2015-11-09 21:41:09 +00:00
.disabled
2015-12-23 19:00:29 +00:00
ld a, [wNumHits]
and a
2015-11-09 21:41:09 +00:00
jr z, .done
ld l, a
ld h, 0
2015-11-09 21:41:09 +00:00
ld de, ANIM_MISS
add hl, de
ld a, l
2018-01-23 22:39:09 +00:00
ld [wFXAnimID], a
ld a, h
2018-01-23 22:39:09 +00:00
ld [wFXAnimID + 1], a
2015-11-09 21:41:09 +00:00
.hi_byte
call WaitSFX
2015-12-23 19:00:29 +00:00
call PlayHitSound
2015-11-09 21:41:09 +00:00
call RunBattleAnimScript
2015-11-09 21:41:09 +00:00
.done
2015-12-24 01:46:23 +00:00
call BattleAnim_RevertPals
ret
2018-06-24 14:09:41 +00:00
RunBattleAnimScript:
2015-12-24 01:46:23 +00:00
call ClearBattleAnims
.playframe
2015-12-23 22:10:50 +00:00
call RunBattleAnimCommand
call _ExecuteBGEffects
2015-12-23 22:10:50 +00:00
call BattleAnim_UpdateOAM_All
call PushLYOverrides
call BattleAnimRequestPals
; Speed up Rollout's animation.
2018-01-23 22:39:09 +00:00
ld a, [wFXAnimID + 1]
or a
2015-12-24 01:46:23 +00:00
jr nz, .not_rollout
2018-01-23 22:39:09 +00:00
ld a, [wFXAnimID]
cp ROLLOUT
2015-12-24 01:46:23 +00:00
jr nz, .not_rollout
ld a, ANIM_BG_2E
ld b, NUM_BG_EFFECTS
ld de, BG_EFFECT_STRUCT_LENGTH
ld hl, wBGEffect1Function
2015-12-24 01:46:23 +00:00
.find
cp [hl]
2015-12-24 01:46:23 +00:00
jr z, .done
add hl, de
dec b
2015-12-24 01:46:23 +00:00
jr nz, .find
2015-12-24 01:46:23 +00:00
.not_rollout
call BattleAnimDelayFrame
2015-12-24 01:46:23 +00:00
.done
2018-01-23 22:39:09 +00:00
ld a, [wBattleAnimFlags]
bit BATTLEANIM_STOP_F, a
jr z, .playframe
call BattleAnim_ClearOAM
ret
2018-06-24 14:09:41 +00:00
BattleAnimClearHud:
call BattleAnimDelayFrame
call WaitTop
call ClearActorHud
ld a, $1
ldh [hBGMapMode], a
call BattleAnimDelayFrame
call BattleAnimDelayFrame
call BattleAnimDelayFrame
call WaitTop
ret
2018-06-24 14:09:41 +00:00
BattleAnimRestoreHuds:
call BattleAnimDelayFrame
call WaitTop
ldh a, [rSVBK]
push af
2020-02-28 16:51:42 +00:00
ld a, BANK(wCurBattleMon) ; aka BANK(wTempMon), BANK(wPartyMon1), and several others
ldh [rSVBK], a
; this block should just be "call UpdateBattleHuds"
ld hl, UpdateBattleHuds
ld a, BANK(UpdatePlayerHUD)
rst FarCall
pop af
ldh [rSVBK], a
ld a, $1
ldh [hBGMapMode], a
call BattleAnimDelayFrame
call BattleAnimDelayFrame
call BattleAnimDelayFrame
call WaitTop
ret
2018-06-24 14:09:41 +00:00
BattleAnimRequestPals:
ldh a, [hCGB]
and a
ret z
ldh a, [rBGP]
ld b, a
2015-12-23 19:00:29 +00:00
ld a, [wBGP]
cp b
2015-12-24 01:46:23 +00:00
call nz, BattleAnim_SetBGPals
ldh a, [rOBP0]
ld b, a
2015-12-23 19:00:29 +00:00
ld a, [wOBP0]
cp b
2015-12-24 01:46:23 +00:00
call nz, BattleAnim_SetOBPals
ret
2018-06-24 14:09:41 +00:00
BattleAnimDelayFrame:
; Like DelayFrame but wastes battery life.
ld a, 1
2018-01-23 22:39:09 +00:00
ld [wVBlankOccurred], a
.wait
2018-01-23 22:39:09 +00:00
ld a, [wVBlankOccurred]
and a
jr nz, .wait
ret
2018-06-24 14:09:41 +00:00
ClearActorHud:
ldh a, [hBattleTurn]
and a
jr z, .player
hlcoord 1, 0
lb bc, 4, 10
call ClearBox
ret
.player
hlcoord 9, 7
lb bc, 5, 11
call ClearBox
ret
Functioncc220: ; unreferenced
xor a
ldh [hBGMapMode], a
2017-12-28 12:32:33 +00:00
ld a, LOW(vBGMap0 tile $28)
ldh [hBGMapAddress], a
2017-12-28 12:32:33 +00:00
ld a, HIGH(vBGMap0 tile $28)
ldh [hBGMapAddress + 1], a
2015-12-11 21:59:40 +00:00
call WaitBGMap2
ld a, $60
ldh [hWY], a
2017-12-28 12:32:33 +00:00
xor a ; LOW(vBGMap0)
ldh [hBGMapAddress], a
2017-12-28 12:32:33 +00:00
ld a, HIGH(vBGMap0)
ldh [hBGMapAddress + 1], a
call BattleAnimDelayFrame
ret
BattleAnim_ClearOAM:
2018-01-23 22:39:09 +00:00
ld a, [wBattleAnimFlags]
bit BATTLEANIM_KEEPSPRITES_F, a
2015-12-24 01:46:23 +00:00
jr z, .delete
2020-03-21 17:07:18 +00:00
; Instead of deleting the sprites, make them all use PAL_BATTLE_OB_ENEMY
2018-01-30 19:52:46 +00:00
ld hl, wVirtualOAMSprite00Attributes
2018-01-10 18:47:57 +00:00
ld c, NUM_SPRITE_OAM_STRUCTS
2015-11-09 21:41:09 +00:00
.loop
ld a, [hl]
2020-03-21 17:07:18 +00:00
and $ff ^ (PALETTE_MASK | VRAM_BANK_1) ; PAL_BATTLE_OB_ENEMY (0)
ld [hli], a
rept SPRITEOAMSTRUCT_LENGTH - 1
inc hl
2018-01-10 18:47:57 +00:00
endr
dec c
2015-11-09 21:41:09 +00:00
jr nz, .loop
ret
2015-12-24 01:46:23 +00:00
.delete
ld hl, wVirtualOAM
2018-01-30 19:55:20 +00:00
ld c, wVirtualOAMEnd - wVirtualOAM
xor a
2015-11-09 21:41:09 +00:00
.loop2
ld [hli], a
dec c
2015-11-09 21:41:09 +00:00
jr nz, .loop2
ret
2018-06-24 14:09:41 +00:00
RunBattleAnimCommand:
2015-11-09 21:41:09 +00:00
call .CheckTimer
ret nc
2015-11-09 21:41:09 +00:00
call .RunScript
ret
2018-06-24 14:09:41 +00:00
.CheckTimer:
ld a, [wBattleAnimDelay]
and a
2015-11-09 21:41:09 +00:00
jr z, .done
dec a
ld [wBattleAnimDelay], a
and a
ret
2015-11-09 21:41:09 +00:00
.done
scf
ret
2018-06-24 14:09:41 +00:00
.RunScript:
2015-11-09 21:41:09 +00:00
.loop
call GetBattleAnimByte
2018-07-15 09:56:57 +00:00
cp anim_ret_command
2015-11-09 21:41:09 +00:00
jr nz, .not_done_with_anim
; Return from a subroutine.
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimFlags
bit BATTLEANIM_IN_SUBROUTINE_F, [hl]
2015-11-09 21:41:09 +00:00
jr nz, .do_anim
set BATTLEANIM_STOP_F, [hl]
ret
2015-11-09 21:41:09 +00:00
.not_done_with_anim
cp anim_obj_command
2015-11-09 21:41:09 +00:00
jr nc, .do_anim
ld [wBattleAnimDelay], a
ret
2015-11-09 21:41:09 +00:00
.do_anim
call .DoCommand
2015-11-09 21:41:09 +00:00
jr .loop
2018-06-24 14:09:41 +00:00
.DoCommand:
2018-01-23 22:39:09 +00:00
; Execute battle animation command in [wBattleAnimByte].
ld a, [wBattleAnimByte]
sub anim_obj_command
ld e, a
ld d, 0
ld hl, BattleAnimCommands
add hl, de
2015-12-24 01:46:23 +00:00
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
2018-06-24 14:09:41 +00:00
BattleAnimCommands::
; entries correspond to anim_* constants (see macros/scripts/battle_anims.asm)
dw BattleAnimCmd_Obj
dw BattleAnimCmd_1GFX
dw BattleAnimCmd_2GFX
dw BattleAnimCmd_3GFX
dw BattleAnimCmd_4GFX
dw BattleAnimCmd_5GFX
dw BattleAnimCmd_IncObj
dw BattleAnimCmd_SetObj
dw BattleAnimCmd_IncBGEffect
dw BattleAnimCmd_BattlerGFX_1Row
dw BattleAnimCmd_BattlerGFX_2Row
dw BattleAnimCmd_CheckPokeball
dw BattleAnimCmd_Transform
dw BattleAnimCmd_RaiseSub
dw BattleAnimCmd_DropSub
dw BattleAnimCmd_ResetObp0
dw BattleAnimCmd_Sound
dw BattleAnimCmd_Cry
dw BattleAnimCmd_MinimizeOpp
dw BattleAnimCmd_OAMOn
dw BattleAnimCmd_OAMOff
dw BattleAnimCmd_ClearObjs
dw BattleAnimCmd_BeatUp
dw BattleAnimCmd_E7
dw BattleAnimCmd_UpdateActorPic
dw BattleAnimCmd_Minimize
dw BattleAnimCmd_EA ; dummy
dw BattleAnimCmd_EB ; dummy
dw BattleAnimCmd_EC ; dummy
dw BattleAnimCmd_ED ; dummy
2016-05-05 19:07:37 +00:00
dw BattleAnimCmd_IfParamAnd
dw BattleAnimCmd_JumpUntil
dw BattleAnimCmd_BGEffect
dw BattleAnimCmd_BGP
dw BattleAnimCmd_OBP0
dw BattleAnimCmd_OBP1
dw BattleAnimCmd_KeepSprites
dw BattleAnimCmd_F5
dw BattleAnimCmd_F6
dw BattleAnimCmd_F7
2016-05-05 19:07:37 +00:00
dw BattleAnimCmd_IfParamEqual
dw BattleAnimCmd_SetVar
dw BattleAnimCmd_IncVar
2016-05-05 19:07:37 +00:00
dw BattleAnimCmd_IfVarEqual
dw BattleAnimCmd_Jump
dw BattleAnimCmd_Loop
dw BattleAnimCmd_Call
dw BattleAnimCmd_Ret
BattleAnimCmd_EA:
BattleAnimCmd_EB:
BattleAnimCmd_EC:
2018-06-24 14:09:41 +00:00
BattleAnimCmd_ED:
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_Ret:
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimFlags
res BATTLEANIM_IN_SUBROUTINE_F, [hl]
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimParent
ld e, [hl]
inc hl
ld d, [hl]
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld [hl], e
inc hl
ld [hl], d
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_Call:
call GetBattleAnimByte
ld e, a
call GetBattleAnimByte
ld d, a
push de
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld e, [hl]
inc hl
ld d, [hl]
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimParent
ld [hl], e
inc hl
ld [hl], d
pop de
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld [hl], e
inc hl
ld [hl], d
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimFlags
set BATTLEANIM_IN_SUBROUTINE_F, [hl]
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_Jump:
call GetBattleAnimByte
ld e, a
call GetBattleAnimByte
ld d, a
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld [hl], e
inc hl
ld [hl], d
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_Loop:
call GetBattleAnimByte
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimFlags
bit BATTLEANIM_IN_LOOP_F, [hl]
2015-12-24 01:46:23 +00:00
jr nz, .continue_loop
and a
2015-12-24 01:46:23 +00:00
jr z, .perpetual
dec a
set BATTLEANIM_IN_LOOP_F, [hl]
2018-01-23 22:39:09 +00:00
ld [wBattleAnimLoops], a
2015-12-24 01:46:23 +00:00
.continue_loop
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimLoops
ld a, [hl]
and a
2015-12-24 01:46:23 +00:00
jr z, .return_from_loop
dec [hl]
2015-12-24 01:46:23 +00:00
.perpetual
call GetBattleAnimByte
ld e, a
call GetBattleAnimByte
ld d, a
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld [hl], e
inc hl
ld [hl], d
ret
2015-12-24 01:46:23 +00:00
.return_from_loop
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimFlags
res BATTLEANIM_IN_LOOP_F, [hl]
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld e, [hl]
inc hl
ld d, [hl]
inc de
2015-12-24 01:46:23 +00:00
inc de
ld [hl], d
dec hl
ld [hl], e
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_JumpUntil:
2015-12-24 01:46:23 +00:00
ld hl, wBattleAnimParam
ld a, [hl]
and a
2015-12-24 01:46:23 +00:00
jr z, .dont_jump
dec [hl]
call GetBattleAnimByte
ld e, a
call GetBattleAnimByte
ld d, a
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld [hl], e
inc hl
ld [hl], d
ret
2015-12-24 01:46:23 +00:00
.dont_jump
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld e, [hl]
inc hl
ld d, [hl]
inc de
2015-12-24 01:46:23 +00:00
inc de
ld [hl], d
dec hl
ld [hl], e
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_SetVar:
call GetBattleAnimByte
2018-01-23 22:39:09 +00:00
ld [wBattleAnimVar], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_IncVar:
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimVar
inc [hl]
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_IfVarEqual:
call GetBattleAnimByte
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimVar
cp [hl]
jr z, .jump
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld e, [hl]
inc hl
ld d, [hl]
inc de
2015-12-24 01:46:23 +00:00
inc de
ld [hl], d
dec hl
ld [hl], e
ret
.jump
call GetBattleAnimByte
ld e, a
call GetBattleAnimByte
ld d, a
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld [hl], e
inc hl
ld [hl], d
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_IfParamEqual:
call GetBattleAnimByte
2015-12-24 01:46:23 +00:00
ld hl, wBattleAnimParam
cp [hl]
jr z, .jump
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld e, [hl]
inc hl
ld d, [hl]
inc de
2015-12-24 01:46:23 +00:00
inc de
ld [hl], d
dec hl
ld [hl], e
ret
.jump
call GetBattleAnimByte
ld e, a
call GetBattleAnimByte
ld d, a
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld [hl], e
inc hl
ld [hl], d
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_IfParamAnd:
call GetBattleAnimByte
ld e, a
2015-12-24 01:46:23 +00:00
ld a, [wBattleAnimParam]
and e
jr nz, .jump
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld e, [hl]
inc hl
ld d, [hl]
inc de
2015-12-24 01:46:23 +00:00
inc de
ld [hl], d
dec hl
ld [hl], e
ret
2016-05-05 19:07:37 +00:00
.jump
call GetBattleAnimByte
ld e, a
call GetBattleAnimByte
ld d, a
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimAddress
ld [hl], e
inc hl
ld [hl], d
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_Obj:
2015-12-24 03:51:50 +00:00
; index, x, y, param
call GetBattleAnimByte
ld [wBattleObjectTempID], a
call GetBattleAnimByte
ld [wBattleObjectTempXCoord], a
call GetBattleAnimByte
ld [wBattleObjectTempYCoord], a
call GetBattleAnimByte
ld [wBattleObjectTempParam], a
call QueueBattleAnimation
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_BGEffect:
call GetBattleAnimByte
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp0], a
call GetBattleAnimByte
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp1], a
call GetBattleAnimByte
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp2], a
call GetBattleAnimByte
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp3], a
call _QueueBGEffect
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_BGP:
call GetBattleAnimByte
2015-12-23 19:00:29 +00:00
ld [wBGP], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_OBP0:
call GetBattleAnimByte
2015-12-23 19:00:29 +00:00
ld [wOBP0], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_OBP1:
call GetBattleAnimByte
2015-12-23 19:00:29 +00:00
ld [wOBP1], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_ResetObp0:
ldh a, [hSGB]
and a
ld a, $e0
jr z, .not_sgb
ld a, $f0
.not_sgb
2015-12-23 19:00:29 +00:00
ld [wOBP0], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_ClearObjs:
; BUG: This function only clears the first 6⅔ objects
2018-01-23 22:39:09 +00:00
ld hl, wActiveAnimObjects
ld a, $a0 ; should be NUM_ANIM_OBJECTS * BATTLEANIMSTRUCT_LENGTH
.loop
ld [hl], 0
inc hl
dec a
jr nz, .loop
ret
BattleAnimCmd_1GFX:
BattleAnimCmd_2GFX:
BattleAnimCmd_3GFX:
BattleAnimCmd_4GFX:
2018-06-24 14:09:41 +00:00
BattleAnimCmd_5GFX:
2018-01-23 22:39:09 +00:00
ld a, [wBattleAnimByte]
and $f
ld c, a
2015-12-23 19:00:29 +00:00
ld hl, wBattleAnimTileDict
xor a
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp0], a
2015-12-23 19:00:29 +00:00
.loop
2015-12-24 03:51:50 +00:00
ld a, [wBattleAnimTemp0]
cp (vTiles1 - vTiles0) / LEN_2BPP_TILE - BATTLEANIM_BASE_TILE
ret nc
call GetBattleAnimByte
ld [hli], a
2015-12-24 03:51:50 +00:00
ld a, [wBattleAnimTemp0]
ld [hli], a
push bc
push hl
ld l, a
ld h, $0
2015-07-21 02:18:18 +00:00
rept 4
add hl, hl
2015-07-21 02:18:18 +00:00
endr
ld de, vTiles0 tile BATTLEANIM_BASE_TILE
add hl, de
2018-01-23 22:39:09 +00:00
ld a, [wBattleAnimByte]
call LoadBattleAnimGFX
2015-12-24 03:51:50 +00:00
ld a, [wBattleAnimTemp0]
add c
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp0], a
pop hl
pop bc
dec c
2015-12-23 19:00:29 +00:00
jr nz, .loop
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_IncObj:
call GetBattleAnimByte
ld e, NUM_ANIM_OBJECTS
2018-01-23 22:39:09 +00:00
ld bc, wActiveAnimObjects
2015-12-23 22:10:50 +00:00
.loop
ld hl, BATTLEANIMSTRUCT_INDEX
add hl, bc
ld d, [hl]
2018-01-23 22:39:09 +00:00
ld a, [wBattleAnimByte]
cp d
2015-12-24 01:46:23 +00:00
jr z, .found
2015-12-23 22:10:50 +00:00
ld hl, BATTLEANIMSTRUCT_LENGTH
add hl, bc
ld c, l
ld b, h
dec e
2015-12-23 22:10:50 +00:00
jr nz, .loop
ret
2015-12-23 22:10:50 +00:00
2015-12-24 01:46:23 +00:00
.found
2015-12-23 22:10:50 +00:00
ld hl, BATTLEANIMSTRUCT_ANON_JT_INDEX
add hl, bc
inc [hl]
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_IncBGEffect:
call GetBattleAnimByte
ld e, NUM_BG_EFFECTS
ld bc, wBGEffect1Function
2015-12-24 01:46:23 +00:00
.loop
ld hl, $0
add hl, bc
ld d, [hl]
2018-01-23 22:39:09 +00:00
ld a, [wBattleAnimByte]
cp d
2015-12-24 01:46:23 +00:00
jr z, .found
ld hl, 4
add hl, bc
ld c, l
ld b, h
dec e
2015-12-24 01:46:23 +00:00
jr nz, .loop
ret
2015-12-24 01:46:23 +00:00
.found
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
inc [hl]
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_SetObj:
call GetBattleAnimByte
ld e, NUM_ANIM_OBJECTS
2018-01-23 22:39:09 +00:00
ld bc, wActiveAnimObjects
2015-12-24 01:46:23 +00:00
.loop
ld hl, BATTLEANIMSTRUCT_INDEX
add hl, bc
ld d, [hl]
2018-01-23 22:39:09 +00:00
ld a, [wBattleAnimByte]
cp d
2015-12-24 01:46:23 +00:00
jr z, .found
ld hl, BATTLEANIMSTRUCT_LENGTH
add hl, bc
ld c, l
ld b, h
dec e
2015-12-24 01:46:23 +00:00
jr nz, .loop
ret
2015-12-24 01:46:23 +00:00
.found
call GetBattleAnimByte
2015-12-24 01:46:23 +00:00
ld hl, BATTLEANIMSTRUCT_ANON_JT_INDEX
add hl, bc
ld [hl], a
ret
BattleAnimCmd_BattlerGFX_1Row:
2015-12-23 19:00:29 +00:00
ld hl, wBattleAnimTileDict
2015-12-24 01:46:23 +00:00
.loop
ld a, [hl]
and a
2015-12-24 01:46:23 +00:00
jr z, .okay
inc hl
2015-12-24 01:46:23 +00:00
inc hl
jr .loop
2015-12-24 01:46:23 +00:00
.okay
ld a, ANIM_GFX_PLAYERHEAD
ld [hli], a
ld a, ($80 - 6 - 7) - BATTLEANIM_BASE_TILE
ld [hli], a
ld a, ANIM_GFX_ENEMYFEET
ld [hli], a
ld a, ($80 - 6) - BATTLEANIM_BASE_TILE
ld [hl], a
ld hl, vTiles0 tile ($80 - 6 - 7)
ld de, vTiles2 tile $06 ; Enemy feet start tile
ld a, 7 tiles ; Enemy pic height
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp0], a
ld a, 7 ; Copy 7x1 tiles
call .LoadFeet
ld de, vTiles2 tile $31 ; Player head start tile
ld a, 6 tiles ; Player pic height
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp0], a
ld a, 6 ; Copy 6x1 tiles
call .LoadFeet
ret
.LoadFeet:
push af
push hl
push de
lb bc, BANK(@), 1
call Request2bpp
pop de
2015-12-24 03:51:50 +00:00
ld a, [wBattleAnimTemp0]
ld l, a
2015-12-24 01:46:23 +00:00
ld h, 0
add hl, de
ld e, l
ld d, h
pop hl
2015-12-24 01:46:23 +00:00
ld bc, 1 tiles
add hl, bc
pop af
dec a
jr nz, .LoadFeet
ret
BattleAnimCmd_BattlerGFX_2Row:
2015-12-23 19:00:29 +00:00
ld hl, wBattleAnimTileDict
2015-12-24 01:46:23 +00:00
.loop
ld a, [hl]
and a
2015-12-24 01:46:23 +00:00
jr z, .okay
inc hl
2015-12-24 01:46:23 +00:00
inc hl
jr .loop
2015-12-24 01:46:23 +00:00
.okay
ld a, ANIM_GFX_PLAYERHEAD
ld [hli], a
ld a, ($80 - 6 * 2 - 7 * 2) - BATTLEANIM_BASE_TILE
ld [hli], a
ld a, ANIM_GFX_ENEMYFEET
ld [hli], a
ld a, ($80 - 6 * 2) - BATTLEANIM_BASE_TILE
ld [hl], a
ld hl, vTiles0 tile ($80 - 6 * 2 - 7 * 2)
ld de, vTiles2 tile $05 ; Enemy feet start tile
ld a, 7 tiles ; Enemy pic height
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp0], a
ld a, 7 ; Copy 7x2 tiles
2015-12-24 01:46:23 +00:00
call .LoadHead
ld de, vTiles2 tile $31 ; Player head start tile
ld a, 6 tiles ; Player pic height
2015-12-24 03:51:50 +00:00
ld [wBattleAnimTemp0], a
ld a, 6 ; Copy 6x2 tiles
2015-12-24 01:46:23 +00:00
call .LoadHead
ret
2018-06-24 14:09:41 +00:00
.LoadHead:
push af
push hl
push de
lb bc, BANK(@), 2
call Request2bpp
pop de
2015-12-24 03:51:50 +00:00
ld a, [wBattleAnimTemp0]
ld l, a
2015-12-24 01:46:23 +00:00
ld h, 0
add hl, de
ld e, l
ld d, h
pop hl
2015-12-24 01:46:23 +00:00
ld bc, 2 tiles
add hl, bc
pop af
dec a
2015-12-24 01:46:23 +00:00
jr nz, .LoadHead
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_CheckPokeball:
2017-12-24 17:47:30 +00:00
callfar GetPokeBallWobble
ld a, c
2018-01-23 22:39:09 +00:00
ld [wBattleAnimVar], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_E7:
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_Transform:
ldh a, [rSVBK]
push af
2018-01-23 22:39:09 +00:00
ld a, BANK(wCurPartySpecies)
ldh [rSVBK], a
ld a, [wCurPartySpecies]
push af
ldh a, [hBattleTurn]
and a
jr z, .player
ld a, [wTempBattleMonSpecies]
ld [wCurPartySpecies], a
ld hl, wBattleMonDVs
predef GetUnownLetter
2017-12-28 12:32:33 +00:00
ld de, vTiles0 tile $00
predef GetMonFrontpic
jr .done
.player
ld a, [wTempEnemyMonSpecies]
ld [wCurPartySpecies], a
ld hl, wEnemyMonDVs
predef GetUnownLetter
2017-12-28 12:32:33 +00:00
ld de, vTiles0 tile $00
predef GetMonBackpic
.done
pop af
ld [wCurPartySpecies], a
pop af
ldh [rSVBK], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_UpdateActorPic:
2017-12-28 12:32:33 +00:00
ld de, vTiles0 tile $00
ldh a, [hBattleTurn]
and a
jr z, .player
2017-12-28 12:32:33 +00:00
ld hl, vTiles2 tile $00
ld b, 0
ld c, 7 * 7
call Request2bpp
ret
.player
2017-12-28 12:32:33 +00:00
ld hl, vTiles2 tile $31
ld b, 0
ld c, 6 * 6
call Request2bpp
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_RaiseSub:
ldh a, [rSVBK]
push af
ld a, 1 ; unnecessary bankswitch?
ldh [rSVBK], a
xor a ; BANK(sScratch)
call OpenSRAM
GetSubstitutePic: ; used only for BANK(GetSubstitutePic)
ld hl, sScratch
2016-03-27 16:47:28 +00:00
ld bc, (7 * 7) tiles
.loop
xor a
ld [hli], a
dec bc
ld a, c
or b
jr nz, .loop
ldh a, [hBattleTurn]
and a
jr z, .player
2015-12-24 01:46:23 +00:00
ld hl, MonsterSpriteGFX + 0 tiles
2016-03-27 16:47:28 +00:00
ld de, sScratch + (2 * 7 + 5) tiles
2015-12-24 01:46:23 +00:00
call .CopyTile
ld hl, MonsterSpriteGFX + 1 tiles
2016-03-27 16:47:28 +00:00
ld de, sScratch + (3 * 7 + 5) tiles
2015-12-24 01:46:23 +00:00
call .CopyTile
ld hl, MonsterSpriteGFX + 2 tiles
2016-03-27 16:47:28 +00:00
ld de, sScratch + (2 * 7 + 6) tiles
2015-12-24 01:46:23 +00:00
call .CopyTile
ld hl, MonsterSpriteGFX + 3 tiles
2016-03-27 16:47:28 +00:00
ld de, sScratch + (3 * 7 + 6) tiles
2015-12-24 01:46:23 +00:00
call .CopyTile
2017-12-28 12:32:33 +00:00
ld hl, vTiles2 tile $00
ld de, sScratch
lb bc, BANK(GetSubstitutePic), 7 * 7
call Request2bpp
jr .done
.player
2015-12-24 01:46:23 +00:00
ld hl, MonsterSpriteGFX + 4 tiles
2016-03-27 16:47:28 +00:00
ld de, sScratch + (2 * 6 + 4) tiles
2015-12-24 01:46:23 +00:00
call .CopyTile
ld hl, MonsterSpriteGFX + 5 tiles
2016-03-27 16:47:28 +00:00
ld de, sScratch + (3 * 6 + 4) tiles
2015-12-24 01:46:23 +00:00
call .CopyTile
ld hl, MonsterSpriteGFX + 6 tiles
2016-03-27 16:47:28 +00:00
ld de, sScratch + (2 * 6 + 5) tiles
2015-12-24 01:46:23 +00:00
call .CopyTile
ld hl, MonsterSpriteGFX + 7 tiles
2016-03-27 16:47:28 +00:00
ld de, sScratch + (3 * 6 + 5) tiles
2015-12-24 01:46:23 +00:00
call .CopyTile
2017-12-28 12:32:33 +00:00
ld hl, vTiles2 tile $31
ld de, sScratch
lb bc, BANK(GetSubstitutePic), 6 * 6
call Request2bpp
.done
call CloseSRAM
pop af
ldh [rSVBK], a
ret
2018-06-24 14:09:41 +00:00
.CopyTile:
2015-12-24 01:46:23 +00:00
ld bc, 1 tiles
ld a, BANK(MonsterSpriteGFX)
call FarCopyBytes
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_MinimizeOpp:
ldh a, [rSVBK]
push af
ld a, 1 ; unnecessary bankswitch?
ldh [rSVBK], a
xor a ; BANK(sScratch)
call OpenSRAM
call GetMinimizePic
call Request2bpp
call CloseSRAM
pop af
ldh [rSVBK], a
ret
2018-06-24 14:09:41 +00:00
GetMinimizePic:
ld hl, sScratch
ld bc, (7 * 7) tiles
.loop
xor a
ld [hli], a
dec bc
ld a, c
or b
jr nz, .loop
ldh a, [hBattleTurn]
and a
jr z, .player
2015-12-24 01:46:23 +00:00
ld de, sScratch + $1a tiles
call CopyMinimizePic
2017-12-28 12:32:33 +00:00
ld hl, vTiles2 tile $00
ld de, sScratch
2018-01-15 00:43:35 +00:00
lb bc, BANK(GetMinimizePic), 7 * 7
ret
.player
2015-08-21 06:00:59 +00:00
ld de, sScratch + $160
call CopyMinimizePic
2017-12-28 12:32:33 +00:00
ld hl, vTiles2 tile $31
ld de, sScratch
2018-01-15 00:43:35 +00:00
lb bc, BANK(GetMinimizePic), 6 * 6
ret
2018-06-24 14:09:41 +00:00
CopyMinimizePic:
ld hl, MinimizePic
ld bc, $10
ld a, BANK(MinimizePic)
call FarCopyBytes
ret
2018-06-24 14:09:41 +00:00
MinimizePic:
INCBIN "gfx/battle/minimize.2bpp"
2018-06-24 14:09:41 +00:00
BattleAnimCmd_Minimize:
ldh a, [rSVBK]
push af
ld a, 1 ; unnecessary bankswitch?
ldh [rSVBK], a
xor a ; BANK(sScratch)
call OpenSRAM
call GetMinimizePic
2017-12-28 12:32:33 +00:00
ld hl, vTiles0 tile $00
call Request2bpp
call CloseSRAM
pop af
ldh [rSVBK], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_DropSub:
ldh a, [rSVBK]
push af
2018-01-23 22:39:09 +00:00
ld a, BANK(wCurPartySpecies)
ldh [rSVBK], a
ld a, [wCurPartySpecies]
push af
ldh a, [hBattleTurn]
and a
jr z, .player
2017-12-24 17:47:30 +00:00
callfar DropEnemySub
jr .done
.player
2017-12-24 17:47:30 +00:00
callfar DropPlayerSub
.done
pop af
ld [wCurPartySpecies], a
pop af
ldh [rSVBK], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_BeatUp:
ldh a, [rSVBK]
push af
2018-01-23 22:39:09 +00:00
ld a, BANK(wCurPartySpecies)
ldh [rSVBK], a
ld a, [wCurPartySpecies]
push af
2015-12-24 01:46:23 +00:00
ld a, [wBattleAnimParam]
ld [wCurPartySpecies], a
ldh a, [hBattleTurn]
and a
jr z, .player
2018-01-23 22:39:09 +00:00
ld hl, wBattleMonDVs
predef GetUnownLetter
2017-12-28 12:32:33 +00:00
ld de, vTiles2 tile $00
predef GetMonFrontpic
jr .done
.player
2018-01-23 22:39:09 +00:00
ld hl, wEnemyMonDVs
predef GetUnownLetter
2017-12-28 12:32:33 +00:00
ld de, vTiles2 tile $31
predef GetMonBackpic
.done
pop af
ld [wCurPartySpecies], a
2015-12-28 15:57:04 +00:00
ld b, SCGB_BATTLE_COLORS
call GetSGBLayout
pop af
ldh [rSVBK], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_OAMOn:
xor a
ldh [hOAMUpdate], a
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_OAMOff:
ld a, $1
ldh [hOAMUpdate], a
ret
BattleAnimCmd_KeepSprites:
2018-01-23 22:39:09 +00:00
ld hl, wBattleAnimFlags
set BATTLEANIM_KEEPSPRITES_F, [hl]
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_F5:
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_F6:
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_F7:
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_Sound:
call GetBattleAnimByte
ld e, a
srl a
srl a
2015-12-23 22:10:50 +00:00
ld [wSFXDuration], a
call .GetCryTrack
2018-01-16 22:27:50 +00:00
maskbits NUM_NOISE_CHANS
ld [wCryTracks], a
ld e, a
ld d, 0
2015-12-23 22:10:50 +00:00
ld hl, .GetPanning
add hl, de
ld a, [hl]
2015-12-23 22:10:50 +00:00
ld [wStereoPanningMask], a
call GetBattleAnimByte
ld e, a
ld d, 0
2017-12-24 17:47:30 +00:00
callfar PlayStereoSFX
ret
2018-06-24 14:09:41 +00:00
.GetPanning:
db $f0, $0f, $f0, $0f
2018-06-24 14:09:41 +00:00
.GetCryTrack:
ldh a, [hBattleTurn]
and a
jr nz, .enemy
ld a, e
ret
.enemy
ld a, e
xor 1
ret
2018-06-24 14:09:41 +00:00
BattleAnimCmd_Cry:
call GetBattleAnimByte
2018-01-16 22:27:50 +00:00
maskbits NUM_NOISE_CHANS
ld e, a
ld d, 0
2015-12-23 19:00:29 +00:00
ld hl, .CryData
2015-07-21 02:18:18 +00:00
rept 4
add hl, de
2015-07-21 02:18:18 +00:00
endr
ldh a, [rSVBK]
push af
ld a, BANK(wEnemyMon) ; wBattleMon is in WRAM0, but wEnemyMon is in WRAMX
ldh [rSVBK], a
ldh a, [hBattleTurn]
and a
jr nz, .enemy
ld a, $f0
2018-01-23 22:39:09 +00:00
ld [wCryTracks], a
ld a, [wBattleMonSpecies]
2015-12-23 19:00:29 +00:00
jr .done_cry_tracks
.enemy
ld a, $0f
2018-01-23 22:39:09 +00:00
ld [wCryTracks], a
ld a, [wEnemyMonSpecies]
2015-12-23 19:00:29 +00:00
.done_cry_tracks
push hl
call LoadCry
pop hl
jr c, .done
ld a, [hli]
ld c, a
ld a, [hli]
ld b, a
push hl
2018-01-23 22:39:09 +00:00
ld hl, wCryPitch
ld a, [hli]
ld h, [hl]
ld l, a
add hl, bc
ld a, l
2018-01-23 22:39:09 +00:00
ld [wCryPitch], a
ld a, h
2018-01-23 22:39:09 +00:00
ld [wCryPitch + 1], a
pop hl
ld a, [hli]
ld c, a
ld b, [hl]
ld hl, wCryLength
ld a, [hli]
ld h, [hl]
ld l, a
add hl, bc
ld a, l
ld [wCryLength], a
ld a, h
2018-01-23 22:39:09 +00:00
ld [wCryLength + 1], a
ld a, 1
2015-12-23 22:10:50 +00:00
ld [wStereoPanningMask], a
callfar _PlayCry
.done
pop af
ldh [rSVBK], a
ret
2018-06-24 14:09:41 +00:00
.CryData:
; +pitch, +length
2015-12-23 19:00:29 +00:00
dw $0000, $00c0
dw $0000, $0040
dw $0000, $0000
dw $0000, $0000
2018-06-24 14:09:41 +00:00
PlayHitSound:
2015-12-23 19:00:29 +00:00
ld a, [wNumHits]
cp $1
2015-11-09 21:41:09 +00:00
jr z, .okay
cp $4
ret nz
2015-11-09 21:41:09 +00:00
.okay
2018-01-23 22:39:09 +00:00
ld a, [wTypeModifier]
and $7f
ret z
2018-03-09 21:09:03 +00:00
cp EFFECTIVE
ld de, SFX_DAMAGE
jr z, .play
ld de, SFX_SUPER_EFFECTIVE
jr nc, .play
ld de, SFX_NOT_VERY_EFFECTIVE
.play
call PlaySFX
ret
2018-06-24 14:09:41 +00:00
BattleAnimAssignPals:
ldh a, [hCGB]
and a
2015-11-09 21:41:09 +00:00
jr nz, .cgb
ldh a, [hSGB]
and a
2015-11-09 21:41:09 +00:00
ld a, %11100000
jr z, .sgb
ld a, %11110000
2015-11-09 21:41:09 +00:00
.sgb
2015-12-23 19:00:29 +00:00
ld [wOBP0], a
2015-11-09 21:41:09 +00:00
ld a, %11100100
2015-12-23 19:00:29 +00:00
ld [wBGP], a
ld [wOBP1], a
ret
2015-11-09 21:41:09 +00:00
.cgb
ld a, %11100100
2015-12-23 19:00:29 +00:00
ld [wBGP], a
ld [wOBP0], a
ld [wOBP1], a
call DmgToCgbBGPals
2015-11-09 21:41:09 +00:00
lb de, %11100100, %11100100
call DmgToCgbObjPals
ret
ClearBattleAnims::
2015-11-09 21:41:09 +00:00
; Clear animation block
2018-01-23 22:39:09 +00:00
ld hl, wLYOverrides
ld bc, wBattleAnimEnd - wLYOverrides
2015-11-09 21:41:09 +00:00
.loop
ld [hl], 0
inc hl
dec bc
ld a, c
or b
2015-11-09 21:41:09 +00:00
jr nz, .loop
2018-01-23 22:39:09 +00:00
ld hl, wFXAnimID
ld e, [hl]
inc hl
ld d, [hl]
2014-01-05 12:28:55 +00:00
ld hl, BattleAnimations
add hl, de
2015-12-24 01:46:23 +00:00
add hl, de
2015-11-09 21:41:09 +00:00
call GetBattleAnimPointer
call BattleAnimAssignPals
call BattleAnimDelayFrame
ret
2018-06-24 14:09:41 +00:00
BattleAnim_RevertPals:
call WaitTop
2015-11-09 21:41:09 +00:00
ld a, %11100100
2015-12-23 19:00:29 +00:00
ld [wBGP], a
ld [wOBP0], a
ld [wOBP1], a
call DmgToCgbBGPals
2015-11-09 21:41:09 +00:00
lb de, %11100100, %11100100
call DmgToCgbObjPals
xor a
ldh [hSCX], a
ldh [hSCY], a
call BattleAnimDelayFrame
ld a, $1
ldh [hBGMapMode], a
ret
2018-06-24 14:09:41 +00:00
BattleAnim_SetBGPals:
ldh [rBGP], a
ldh a, [hCGB]
and a
ret z
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ldh [rSVBK], a
2018-01-01 14:08:21 +00:00
ld hl, wBGPals2
ld de, wBGPals1
ldh a, [rBGP]
ld b, a
2017-12-11 01:50:08 +00:00
ld c, 7
call CopyPals
2018-01-01 14:08:21 +00:00
ld hl, wOBPals2
ld de, wOBPals1
ldh a, [rBGP]
ld b, a
2017-12-11 01:50:08 +00:00
ld c, 2
call CopyPals
pop af
ldh [rSVBK], a
ld a, $1
ldh [hCGBPalUpdate], a
ret
2018-06-24 14:09:41 +00:00
BattleAnim_SetOBPals:
ldh [rOBP0], a
ldh a, [hCGB]
and a
ret z
ldh a, [rSVBK]
push af
ld a, BANK(wOBPals1)
ldh [rSVBK], a
2018-01-01 14:08:21 +00:00
ld hl, wOBPals2 palette PAL_BATTLE_OB_GRAY
ld de, wOBPals1 palette PAL_BATTLE_OB_GRAY
ldh a, [rOBP0]
ld b, a
2017-12-11 01:50:08 +00:00
ld c, 2
call CopyPals
pop af
ldh [rSVBK], a
ld a, $1
ldh [hCGBPalUpdate], a
ret
2018-06-24 14:09:41 +00:00
BattleAnim_UpdateOAM_All:
ld a, 0
2015-12-24 01:46:23 +00:00
ld [wBattleAnimOAMPointerLo], a
2018-01-23 22:39:09 +00:00
ld hl, wActiveAnimObjects
ld e, NUM_ANIM_OBJECTS
.loop
ld a, [hl]
and a
jr z, .next
ld c, l
ld b, h
push hl
push de
2015-12-23 22:10:50 +00:00
call DoBattleAnimFrame
call BattleAnimOAMUpdate
pop de
pop hl
jr c, .done
.next
2015-12-23 22:10:50 +00:00
ld bc, BATTLEANIMSTRUCT_LENGTH
add hl, bc
dec e
jr nz, .loop
2015-12-24 01:46:23 +00:00
ld a, [wBattleAnimOAMPointerLo]
ld l, a
ld h, HIGH(wVirtualOAM)
.loop2
ld a, l
2018-01-30 19:55:20 +00:00
cp LOW(wVirtualOAMEnd)
jr nc, .done
xor a
ld [hli], a
jr .loop2
.done
ret