2018-06-24 07:09:41 -07:00
|
|
|
ClearSpriteAnims:
|
2020-10-30 12:39:08 -07:00
|
|
|
ld hl, wSpriteAnimData
|
|
|
|
ld bc, wSpriteAnimDataEnd - wSpriteAnimData
|
2015-11-12 21:49:27 -08:00
|
|
|
.loop
|
2020-06-17 07:39:17 -07:00
|
|
|
ld [hl], 0
|
2015-11-12 21:49:27 -08:00
|
|
|
inc hl
|
|
|
|
dec bc
|
|
|
|
ld a, c
|
|
|
|
or b
|
|
|
|
jr nz, .loop
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PlaySpriteAnimationsAndDelayFrame:
|
2015-11-28 12:13:40 -08:00
|
|
|
call PlaySpriteAnimations
|
2015-11-12 21:49:27 -08:00
|
|
|
call DelayFrame
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PlaySpriteAnimations:
|
2015-11-12 21:49:27 -08:00
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
2015-11-04 17:20:14 -08:00
|
|
|
push af
|
|
|
|
|
2022-07-09 14:18:22 -07:00
|
|
|
ld a, LOW(wShadowOAM)
|
2018-09-09 12:09:51 -07:00
|
|
|
ld [wCurSpriteOAMAddr], a
|
2015-12-01 12:35:28 -08:00
|
|
|
call DoNextFrameForAllSprites
|
2015-11-12 21:49:27 -08:00
|
|
|
|
2015-11-04 17:20:14 -08:00
|
|
|
pop af
|
2015-11-12 21:49:27 -08:00
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
DoNextFrameForAllSprites:
|
2015-11-28 12:13:40 -08:00
|
|
|
ld hl, wSpriteAnimationStructs
|
2018-01-02 17:35:57 -08:00
|
|
|
ld e, NUM_SPRITE_ANIM_STRUCTS
|
2015-11-04 17:20:14 -08:00
|
|
|
|
|
|
|
.loop
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr z, .next ; This struct is deinitialized.
|
|
|
|
ld c, l
|
|
|
|
ld b, h
|
|
|
|
push hl
|
|
|
|
push de
|
2023-09-24 06:06:19 -07:00
|
|
|
call DoSpriteAnimFrame ; Uses a massive dw
|
2015-12-05 12:38:25 -08:00
|
|
|
call UpdateAnimFrame
|
2015-11-12 21:49:27 -08:00
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
jr c, .done
|
|
|
|
|
|
|
|
.next
|
2018-01-02 17:35:57 -08:00
|
|
|
ld bc, SPRITEANIMSTRUCT_LENGTH
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
dec e
|
2015-11-04 17:20:14 -08:00
|
|
|
jr nz, .loop
|
|
|
|
|
2024-02-10 15:34:46 -08:00
|
|
|
ld a, [wStateFlags]
|
2024-02-26 13:09:32 -08:00
|
|
|
bit DONT_CLEAR_SHADOW_OAM_IN_SPRITE_ANIMS_F, a
|
2023-08-22 03:42:53 -07:00
|
|
|
ret nz
|
|
|
|
|
|
|
|
; Clear (wShadowOAM + [wCurSpriteOAMAddr] --> wShadowOAMEnd)
|
2018-09-09 12:09:51 -07:00
|
|
|
ld a, [wCurSpriteOAMAddr]
|
2015-11-12 21:49:27 -08:00
|
|
|
ld l, a
|
2022-07-09 14:18:22 -07:00
|
|
|
ld h, HIGH(wShadowOAM)
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2023-08-22 03:42:53 -07:00
|
|
|
.loop2
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, l
|
2022-07-09 14:18:22 -07:00
|
|
|
cp LOW(wShadowOAMEnd)
|
2015-11-12 21:49:27 -08:00
|
|
|
jr nc, .done
|
|
|
|
xor a
|
|
|
|
ld [hli], a
|
|
|
|
jr .loop2
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
.done
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
DoNextFrameForFirst16Sprites:
|
2015-11-13 15:59:49 -08:00
|
|
|
ld hl, wSpriteAnimationStructs
|
2018-01-02 17:35:57 -08:00
|
|
|
ld e, NUM_SPRITE_ANIM_STRUCTS
|
2015-11-12 21:49:27 -08:00
|
|
|
|
|
|
|
.loop
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr z, .next
|
|
|
|
ld c, l
|
|
|
|
ld b, h
|
|
|
|
push hl
|
|
|
|
push de
|
2023-09-24 06:06:19 -07:00
|
|
|
call DoSpriteAnimFrame ; Uses a massive dw
|
2015-12-05 12:38:25 -08:00
|
|
|
call UpdateAnimFrame
|
2015-11-12 21:49:27 -08:00
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
jr c, .done
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
.next
|
2018-01-02 17:35:57 -08:00
|
|
|
ld bc, SPRITEANIMSTRUCT_LENGTH
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
dec e
|
|
|
|
jr nz, .loop
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2018-09-09 12:09:51 -07:00
|
|
|
ld a, [wCurSpriteOAMAddr]
|
2015-11-12 21:49:27 -08:00
|
|
|
ld l, a
|
2022-07-09 14:18:22 -07:00
|
|
|
ld h, HIGH(wShadowOAMSprite16)
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2022-07-09 14:18:22 -07:00
|
|
|
.loop2 ; Clear (wShadowOAM + [wCurSpriteOAMAddr] --> Sprites + $40)
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, l
|
2022-07-09 14:18:22 -07:00
|
|
|
cp LOW(wShadowOAMSprite16)
|
2015-11-12 21:49:27 -08:00
|
|
|
jr nc, .done
|
|
|
|
xor a
|
|
|
|
ld [hli], a
|
|
|
|
jr .loop2
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
.done
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2020-02-11 04:42:36 -08:00
|
|
|
_InitSpriteAnimStruct::
|
2015-12-04 05:46:11 -08:00
|
|
|
; Initialize animation a at pixel x=e, y=d
|
2015-11-28 12:13:40 -08:00
|
|
|
; Find if there's any room in the wSpriteAnimationStructs array, which is 10x16
|
2015-11-12 21:49:27 -08:00
|
|
|
push de
|
2015-11-04 17:20:14 -08:00
|
|
|
push af
|
2015-11-28 12:13:40 -08:00
|
|
|
ld hl, wSpriteAnimationStructs
|
2018-01-02 17:35:57 -08:00
|
|
|
ld e, NUM_SPRITE_ANIM_STRUCTS
|
2015-11-12 21:49:27 -08:00
|
|
|
.loop
|
2015-11-04 17:20:14 -08:00
|
|
|
ld a, [hl]
|
2015-11-12 21:49:27 -08:00
|
|
|
and a
|
|
|
|
jr z, .found
|
2018-01-02 17:35:57 -08:00
|
|
|
ld bc, SPRITEANIMSTRUCT_LENGTH
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
dec e
|
2015-11-04 17:20:14 -08:00
|
|
|
jr nz, .loop
|
2015-11-12 21:49:27 -08:00
|
|
|
; We've reached the end. There is no more room here.
|
|
|
|
; Return carry.
|
|
|
|
pop af
|
|
|
|
pop de
|
|
|
|
scf
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
.found
|
|
|
|
; Back up the structure address to bc.
|
|
|
|
ld c, l
|
|
|
|
ld b, h
|
2020-08-04 11:26:26 -07:00
|
|
|
|
|
|
|
; Increment [wSpriteAnimCount], skipping a 0 value.
|
2015-12-10 19:26:31 -08:00
|
|
|
ld hl, wSpriteAnimCount
|
2015-11-12 21:49:27 -08:00
|
|
|
inc [hl]
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
2020-08-04 11:26:26 -07:00
|
|
|
jr nz, .nonzero
|
2015-11-12 21:49:27 -08:00
|
|
|
inc [hl]
|
2020-08-04 11:26:26 -07:00
|
|
|
.nonzero
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2023-09-24 06:06:19 -07:00
|
|
|
; Get row a of SpriteAnimObjects, copy the pointer into de
|
2015-11-12 21:49:27 -08:00
|
|
|
pop af
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2023-09-24 06:06:19 -07:00
|
|
|
ld hl, SpriteAnimObjects
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, de
|
2016-05-10 09:31:49 -07:00
|
|
|
add hl, de
|
|
|
|
add hl, de
|
2015-11-12 21:49:27 -08:00
|
|
|
ld e, l
|
|
|
|
ld d, h
|
|
|
|
; Set hl to the first field (field 0) in the current structure.
|
2015-12-04 05:46:11 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_INDEX
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
; Load the index.
|
2015-12-10 19:26:31 -08:00
|
|
|
ld a, [wSpriteAnimCount]
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_INDEX
|
2015-11-12 21:49:27 -08:00
|
|
|
; Copy the table entry to the next two fields.
|
|
|
|
ld a, [de]
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_FRAMESET_ID
|
2015-11-12 21:49:27 -08:00
|
|
|
inc de
|
|
|
|
ld a, [de]
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_ANIM_SEQ_ID
|
2015-11-12 21:49:27 -08:00
|
|
|
inc de
|
2020-10-30 12:39:08 -07:00
|
|
|
; Look up the third field in the wSpriteAnimDict mapping.
|
|
|
|
; Take the mapped value and load it in.
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [de]
|
2015-12-04 05:46:11 -08:00
|
|
|
call GetSpriteAnimVTile
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_TILE_ID
|
2015-11-12 21:49:27 -08:00
|
|
|
pop de
|
2015-12-04 05:46:11 -08:00
|
|
|
; Set hl to field 4 (X coordinate). Kinda pointless, because we're presumably already here.
|
|
|
|
ld hl, SPRITEANIMSTRUCT_XCOORD
|
2015-11-04 17:20:14 -08:00
|
|
|
add hl, bc
|
2015-11-12 21:49:27 -08:00
|
|
|
; Load the original value of de into here.
|
|
|
|
ld a, e
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_XCOORD
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, d
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_YCOORD
|
2015-11-12 21:49:27 -08:00
|
|
|
; load 0 into the next four fields
|
|
|
|
xor a
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_XOFFSET
|
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_YOFFSET
|
2015-11-12 21:49:27 -08:00
|
|
|
xor a
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_DURATION
|
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_DURATIONOFFSET
|
2015-11-12 21:49:27 -08:00
|
|
|
; load -1 into the next field
|
|
|
|
dec a
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_FRAME
|
2015-11-12 21:49:27 -08:00
|
|
|
; load 0 into the last five fields
|
|
|
|
xor a
|
2020-08-22 07:22:37 -07:00
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_JUMPTABLE_INDEX
|
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_VAR1
|
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_VAR2
|
|
|
|
ld [hli], a ; SPRITEANIMSTRUCT_VAR3
|
|
|
|
ld [hl], a ; SPRITEANIMSTRUCT_VAR4
|
2015-12-04 05:46:11 -08:00
|
|
|
; back up the address of the first field to wSpriteAnimAddrBackup
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, c
|
2015-12-04 05:46:11 -08:00
|
|
|
ld [wSpriteAnimAddrBackup], a
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, b
|
2015-12-04 05:46:11 -08:00
|
|
|
ld [wSpriteAnimAddrBackup + 1], a
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
DeinitializeSprite:
|
2015-11-12 21:49:27 -08:00
|
|
|
; Clear the index field of the struct in bc.
|
2015-12-02 10:24:18 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_INDEX
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
2020-06-17 07:39:17 -07:00
|
|
|
ld [hl], 0
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
DeinitializeAllSprites:
|
2015-11-28 12:13:40 -08:00
|
|
|
; Clear the index field of every struct in the wSpriteAnimationStructs array.
|
|
|
|
ld hl, wSpriteAnimationStructs
|
2018-01-02 17:35:57 -08:00
|
|
|
ld bc, SPRITEANIMSTRUCT_LENGTH
|
|
|
|
ld e, NUM_SPRITE_ANIM_STRUCTS
|
2015-11-12 21:49:27 -08:00
|
|
|
xor a
|
|
|
|
.loop
|
|
|
|
ld [hl], a
|
|
|
|
add hl, bc
|
|
|
|
dec e
|
|
|
|
jr nz, .loop
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
UpdateAnimFrame:
|
2015-12-04 05:46:11 -08:00
|
|
|
call InitSpriteAnimBuffer ; init WRAM
|
2015-12-05 12:38:25 -08:00
|
|
|
call GetSpriteAnimFrame ; read from a memory array
|
2022-06-22 18:07:46 -07:00
|
|
|
cp oamwait_command
|
2015-11-12 21:49:27 -08:00
|
|
|
jr z, .done
|
2022-06-22 18:07:46 -07:00
|
|
|
cp oamdelete_command
|
2015-12-02 10:24:18 -08:00
|
|
|
jr z, .delete
|
2015-12-05 12:38:25 -08:00
|
|
|
call GetFrameOAMPointer
|
2018-09-09 12:09:51 -07:00
|
|
|
; add byte to [wCurAnimVTile]
|
|
|
|
ld a, [wCurAnimVTile]
|
2015-11-12 21:49:27 -08:00
|
|
|
add [hl]
|
2018-09-09 12:09:51 -07:00
|
|
|
ld [wCurAnimVTile], a
|
2015-11-12 21:49:27 -08:00
|
|
|
inc hl
|
2015-12-02 10:24:18 -08:00
|
|
|
; load pointer into hl
|
2015-11-04 17:20:14 -08:00
|
|
|
ld a, [hli]
|
2015-11-12 21:49:27 -08:00
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
push bc
|
2018-09-09 12:09:51 -07:00
|
|
|
ld a, [wCurSpriteOAMAddr]
|
2015-11-04 17:20:14 -08:00
|
|
|
ld e, a
|
2022-07-09 14:18:22 -07:00
|
|
|
ld d, HIGH(wShadowOAM)
|
2015-11-04 17:20:14 -08:00
|
|
|
ld a, [hli]
|
2015-12-02 10:24:18 -08:00
|
|
|
ld c, a ; number of objects
|
2015-11-12 21:49:27 -08:00
|
|
|
.loop
|
2015-12-02 10:24:18 -08:00
|
|
|
; first byte: y (px)
|
2018-09-09 12:09:51 -07:00
|
|
|
; [de] = [wCurAnimYCoord] + [wCurAnimYOffset] + [wGlobalAnimYOffset] + AddOrSubtractY([hl])
|
|
|
|
ld a, [wCurAnimYCoord]
|
2015-11-12 21:49:27 -08:00
|
|
|
ld b, a
|
2018-09-09 12:09:51 -07:00
|
|
|
ld a, [wCurAnimYOffset]
|
2015-11-12 21:49:27 -08:00
|
|
|
add b
|
|
|
|
ld b, a
|
2015-12-02 14:59:05 -08:00
|
|
|
ld a, [wGlobalAnimYOffset]
|
2015-11-12 21:49:27 -08:00
|
|
|
add b
|
|
|
|
ld b, a
|
2015-12-04 05:46:11 -08:00
|
|
|
call AddOrSubtractY
|
2015-11-12 21:49:27 -08:00
|
|
|
add b
|
|
|
|
ld [de], a
|
|
|
|
inc hl
|
|
|
|
inc de
|
2015-12-02 10:24:18 -08:00
|
|
|
; second byte: x (px)
|
2018-09-09 12:09:51 -07:00
|
|
|
; [de] = [wCurAnimXCoord] + [wCurAnimXOffset] + [wGlobalAnimXOffset] + AddOrSubtractX([hl])
|
|
|
|
ld a, [wCurAnimXCoord]
|
2015-11-12 21:49:27 -08:00
|
|
|
ld b, a
|
2018-09-09 12:09:51 -07:00
|
|
|
ld a, [wCurAnimXOffset]
|
2015-11-12 21:49:27 -08:00
|
|
|
add b
|
|
|
|
ld b, a
|
2015-12-02 14:59:05 -08:00
|
|
|
ld a, [wGlobalAnimXOffset]
|
2015-11-12 21:49:27 -08:00
|
|
|
add b
|
|
|
|
ld b, a
|
2015-12-04 05:46:11 -08:00
|
|
|
call AddOrSubtractX
|
2015-11-12 21:49:27 -08:00
|
|
|
add b
|
|
|
|
ld [de], a
|
|
|
|
inc hl
|
|
|
|
inc de
|
2015-12-02 10:24:18 -08:00
|
|
|
; third byte: vtile
|
2018-09-09 12:09:51 -07:00
|
|
|
; [de] = [wCurAnimVTile] + [hl]
|
|
|
|
ld a, [wCurAnimVTile]
|
2015-11-12 21:49:27 -08:00
|
|
|
add [hl]
|
|
|
|
ld [de], a
|
|
|
|
inc hl
|
|
|
|
inc de
|
2015-12-02 10:24:18 -08:00
|
|
|
; fourth byte: attributes
|
2015-12-05 12:38:25 -08:00
|
|
|
; [de] = GetSpriteOAMAttr([hl])
|
|
|
|
call GetSpriteOAMAttr
|
2015-11-12 21:49:27 -08:00
|
|
|
ld [de], a
|
|
|
|
inc hl
|
|
|
|
inc de
|
|
|
|
ld a, e
|
2018-09-09 12:09:51 -07:00
|
|
|
ld [wCurSpriteOAMAddr], a
|
2022-07-09 14:18:22 -07:00
|
|
|
cp LOW(wShadowOAMEnd)
|
2015-12-02 10:24:18 -08:00
|
|
|
jr nc, .reached_the_end
|
2015-11-12 21:49:27 -08:00
|
|
|
dec c
|
|
|
|
jr nz, .loop
|
|
|
|
pop bc
|
|
|
|
jr .done
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2015-12-02 10:24:18 -08:00
|
|
|
.delete
|
2022-06-22 18:07:46 -07:00
|
|
|
; Removes the object from the screen, as opposed to `oamend` which just stops all motion
|
2015-12-04 05:46:11 -08:00
|
|
|
call DeinitializeSprite
|
2015-11-12 21:49:27 -08:00
|
|
|
.done
|
2015-11-04 17:20:14 -08:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2015-12-02 10:24:18 -08:00
|
|
|
.reached_the_end
|
2015-11-12 21:49:27 -08:00
|
|
|
pop bc
|
2015-11-04 17:20:14 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
AddOrSubtractY:
|
2015-11-12 21:49:27 -08:00
|
|
|
push hl
|
2015-11-04 17:20:14 -08:00
|
|
|
ld a, [hl]
|
2019-02-16 10:08:34 -08:00
|
|
|
ld hl, wCurSpriteOAMFlags
|
|
|
|
bit OAM_Y_FLIP, [hl]
|
2015-11-12 21:49:27 -08:00
|
|
|
jr z, .ok
|
2020-04-18 14:31:51 -07:00
|
|
|
; -8 - a
|
2020-06-17 07:39:17 -07:00
|
|
|
add 8
|
2015-11-12 21:49:27 -08:00
|
|
|
xor $ff
|
|
|
|
inc a
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
.ok
|
|
|
|
pop hl
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
AddOrSubtractX:
|
2015-11-04 17:20:14 -08:00
|
|
|
push hl
|
|
|
|
ld a, [hl]
|
2019-02-16 10:08:34 -08:00
|
|
|
ld hl, wCurSpriteOAMFlags
|
|
|
|
bit OAM_X_FLIP, [hl]
|
2015-11-12 21:49:27 -08:00
|
|
|
jr z, .ok
|
2020-04-18 14:31:51 -07:00
|
|
|
; -8 - a
|
2020-06-17 07:39:17 -07:00
|
|
|
add 8
|
2015-11-12 21:49:27 -08:00
|
|
|
xor $ff
|
|
|
|
inc a
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
.ok
|
|
|
|
pop hl
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetSpriteOAMAttr:
|
2019-02-16 10:08:34 -08:00
|
|
|
ld a, [wCurSpriteOAMFlags]
|
2015-11-12 21:49:27 -08:00
|
|
|
ld b, a
|
|
|
|
ld a, [hl]
|
|
|
|
xor b
|
2019-02-16 10:08:34 -08:00
|
|
|
and PRIORITY | Y_FLIP | X_FLIP
|
2015-11-12 21:49:27 -08:00
|
|
|
ld b, a
|
|
|
|
ld a, [hl]
|
2021-11-23 17:37:18 -08:00
|
|
|
and ~(PRIORITY | Y_FLIP | X_FLIP)
|
2015-11-12 21:49:27 -08:00
|
|
|
or b
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
InitSpriteAnimBuffer:
|
2015-11-04 17:20:14 -08:00
|
|
|
xor a
|
2019-02-16 10:08:34 -08:00
|
|
|
ld [wCurSpriteOAMFlags], a
|
2015-12-02 10:24:18 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_TILE_ID
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hli]
|
2018-09-09 12:09:51 -07:00
|
|
|
ld [wCurAnimVTile], a
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [hli]
|
2018-09-09 12:09:51 -07:00
|
|
|
ld [wCurAnimXCoord], a
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [hli]
|
2018-09-09 12:09:51 -07:00
|
|
|
ld [wCurAnimYCoord], a
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [hli]
|
2018-09-09 12:09:51 -07:00
|
|
|
ld [wCurAnimXOffset], a
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [hli]
|
2018-09-09 12:09:51 -07:00
|
|
|
ld [wCurAnimYOffset], a
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetSpriteAnimVTile:
|
2020-10-30 12:39:08 -07:00
|
|
|
; a = wSpriteAnimDict[a] if a in wSpriteAnimDict else vtile offset $00
|
2015-11-04 17:20:14 -08:00
|
|
|
push hl
|
|
|
|
push bc
|
2015-11-19 15:07:20 -08:00
|
|
|
ld hl, wSpriteAnimDict
|
2015-11-04 17:20:14 -08:00
|
|
|
ld b, a
|
2020-10-30 12:39:08 -07:00
|
|
|
ld c, NUM_SPRITEANIMDICT_ENTRIES
|
2015-11-04 17:20:14 -08:00
|
|
|
.loop
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [hli]
|
2015-11-04 17:20:14 -08:00
|
|
|
cp b
|
2015-11-12 21:49:27 -08:00
|
|
|
jr z, .ok
|
2015-11-04 17:20:14 -08:00
|
|
|
inc hl
|
|
|
|
dec c
|
|
|
|
jr nz, .loop
|
2015-11-12 21:49:27 -08:00
|
|
|
xor a
|
|
|
|
jr .done
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
.ok
|
|
|
|
ld a, [hl]
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
.done
|
2015-11-04 17:20:14 -08:00
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
_ReinitSpriteAnimFrame::
|
2015-12-05 12:38:25 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_FRAMESET_ID
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], a
|
2015-12-02 14:59:05 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_DURATION
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
2015-12-02 14:59:05 -08:00
|
|
|
ld [hl], 0
|
|
|
|
ld hl, SPRITEANIMSTRUCT_FRAME
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
2015-12-02 14:59:05 -08:00
|
|
|
ld [hl], -1
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetSpriteAnimFrame:
|
2015-11-04 17:20:14 -08:00
|
|
|
.loop
|
2015-12-01 12:35:28 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_DURATION
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-11-04 17:20:14 -08:00
|
|
|
and a
|
2020-10-30 14:32:09 -07:00
|
|
|
jr z, .next_frame
|
2015-11-12 21:49:27 -08:00
|
|
|
dec [hl]
|
2020-10-30 14:32:09 -07:00
|
|
|
call .GetPointer
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [hli]
|
|
|
|
push af
|
2015-12-01 12:35:28 -08:00
|
|
|
jr .okay
|
2015-11-12 21:49:27 -08:00
|
|
|
|
2015-12-02 10:24:18 -08:00
|
|
|
.next_frame
|
2015-12-01 12:35:28 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_FRAME
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
inc [hl]
|
2020-10-30 14:32:09 -07:00
|
|
|
call .GetPointer
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [hli]
|
2022-06-22 18:07:46 -07:00
|
|
|
cp oamrestart_command
|
2015-12-05 12:38:25 -08:00
|
|
|
jr z, .restart
|
2022-06-22 18:07:46 -07:00
|
|
|
cp oamend_command
|
2015-12-05 12:38:25 -08:00
|
|
|
jr z, .repeat_last
|
2015-12-01 12:35:28 -08:00
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
push af
|
|
|
|
ld a, [hl]
|
2015-11-04 17:20:14 -08:00
|
|
|
push hl
|
2021-11-23 17:37:18 -08:00
|
|
|
and ~(Y_FLIP << 1 | X_FLIP << 1)
|
2015-12-04 05:46:11 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_DURATIONOFFSET
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
add [hl]
|
2015-12-01 12:35:28 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_DURATION
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], a
|
2015-11-04 17:20:14 -08:00
|
|
|
pop hl
|
2015-12-01 12:35:28 -08:00
|
|
|
.okay
|
2015-11-12 21:49:27 -08:00
|
|
|
ld a, [hl]
|
2022-06-22 18:07:46 -07:00
|
|
|
and Y_FLIP << 1 | X_FLIP << 1 ; The << 1 is compensated in the "oamframe" macro
|
2015-11-12 21:49:27 -08:00
|
|
|
srl a
|
2019-02-16 10:08:34 -08:00
|
|
|
ld [wCurSpriteOAMFlags], a
|
2015-11-12 21:49:27 -08:00
|
|
|
pop af
|
2015-11-04 17:20:14 -08:00
|
|
|
ret
|
|
|
|
|
2015-12-05 12:38:25 -08:00
|
|
|
.repeat_last
|
2015-11-12 21:49:27 -08:00
|
|
|
xor a
|
2015-12-01 12:35:28 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_DURATION
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], a
|
2015-12-01 12:35:28 -08:00
|
|
|
|
|
|
|
ld hl, SPRITEANIMSTRUCT_FRAME
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
dec [hl]
|
2015-12-26 18:59:03 -08:00
|
|
|
dec [hl]
|
2015-11-12 21:49:27 -08:00
|
|
|
jr .loop
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2015-12-05 12:38:25 -08:00
|
|
|
.restart
|
2015-11-12 21:49:27 -08:00
|
|
|
xor a
|
2015-12-01 12:35:28 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_DURATION
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], a
|
2015-12-01 12:35:28 -08:00
|
|
|
|
2015-11-12 21:49:27 -08:00
|
|
|
dec a
|
2015-12-01 12:35:28 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_FRAME
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], a
|
|
|
|
jr .loop
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.GetPointer:
|
2015-12-05 12:38:25 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_FRAMESET_ID
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
ld e, [hl]
|
|
|
|
ld d, 0
|
2015-12-05 12:38:25 -08:00
|
|
|
ld hl, SpriteAnimFrameData
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, de
|
2015-12-26 18:59:03 -08:00
|
|
|
add hl, de
|
2015-11-12 21:49:27 -08:00
|
|
|
ld e, [hl]
|
|
|
|
inc hl
|
|
|
|
ld d, [hl]
|
2015-12-01 12:35:28 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_FRAME
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, bc
|
|
|
|
ld l, [hl]
|
|
|
|
ld h, 0
|
|
|
|
add hl, hl
|
|
|
|
add hl, de
|
|
|
|
ret
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetFrameOAMPointer:
|
2015-11-12 21:49:27 -08:00
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2015-12-05 12:38:25 -08:00
|
|
|
ld hl, SpriteAnimOAMData
|
2015-11-12 21:49:27 -08:00
|
|
|
add hl, de
|
2016-05-10 09:31:49 -07:00
|
|
|
add hl, de
|
|
|
|
add hl, de
|
2015-11-12 21:49:27 -08:00
|
|
|
ret
|
2015-11-04 17:20:14 -08:00
|
|
|
|
2023-09-24 06:06:19 -07:00
|
|
|
INCLUDE "data/sprite_anims/objects.asm"
|
2015-11-12 21:49:27 -08:00
|
|
|
|
2023-09-24 06:06:19 -07:00
|
|
|
INCLUDE "engine/sprite_anims/functions.asm"
|
2017-12-11 19:44:25 -08:00
|
|
|
|
2017-12-26 15:45:04 -08:00
|
|
|
INCLUDE "data/sprite_anims/framesets.asm"
|
2017-12-11 19:44:25 -08:00
|
|
|
|
2017-12-26 15:45:04 -08:00
|
|
|
INCLUDE "data/sprite_anims/oam.asm"
|
2017-12-11 19:44:25 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Sprites_Cosine:
|
2018-01-09 13:39:36 -08:00
|
|
|
; a = d * cos(a * pi/32)
|
2018-02-03 18:11:55 -08:00
|
|
|
add %010000 ; cos(x) = sin(x + pi/2)
|
|
|
|
; fallthrough
|
2018-06-24 07:09:41 -07:00
|
|
|
Sprites_Sine:
|
2018-01-09 13:39:36 -08:00
|
|
|
; a = d * sin(a * pi/32)
|
2018-02-03 18:11:55 -08:00
|
|
|
calc_sine_wave
|
2015-11-19 15:07:20 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
AnimateEndOfExpBar:
|
2015-11-28 12:13:40 -08:00
|
|
|
ld de, EndOfExpBarGFX
|
2017-12-28 04:32:33 -08:00
|
|
|
ld hl, vTiles0 tile $00
|
2015-11-28 12:13:40 -08:00
|
|
|
lb bc, BANK(EndOfExpBarGFX), 1
|
2015-11-19 15:07:20 -08:00
|
|
|
call Request2bpp
|
2015-12-05 12:38:25 -08:00
|
|
|
ld c, 8
|
|
|
|
ld d, 0
|
2015-11-28 12:13:40 -08:00
|
|
|
.loop
|
2015-11-19 15:07:20 -08:00
|
|
|
push bc
|
2015-11-28 12:13:40 -08:00
|
|
|
call .AnimateFrame
|
2015-11-19 15:07:20 -08:00
|
|
|
call DelayFrame
|
|
|
|
pop bc
|
|
|
|
inc d
|
2015-12-26 18:59:03 -08:00
|
|
|
inc d
|
2015-11-19 15:07:20 -08:00
|
|
|
dec c
|
2015-11-28 12:13:40 -08:00
|
|
|
jr nz, .loop
|
2015-11-19 15:07:20 -08:00
|
|
|
call ClearSprites
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.AnimateFrame:
|
2022-07-09 14:18:22 -07:00
|
|
|
ld hl, wShadowOAMSprite00
|
2018-01-10 10:47:57 -08:00
|
|
|
ld c, 8 ; number of animated circles
|
2015-11-28 12:13:40 -08:00
|
|
|
.anim_loop
|
2015-11-19 15:07:20 -08:00
|
|
|
ld a, c
|
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
dec c
|
|
|
|
ld a, c
|
2015-12-05 12:38:25 -08:00
|
|
|
; multiply by 8
|
2015-11-19 15:07:20 -08:00
|
|
|
sla a
|
|
|
|
sla a
|
|
|
|
sla a
|
|
|
|
push af
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2015-11-19 15:07:20 -08:00
|
|
|
push de
|
|
|
|
push hl
|
2015-12-04 11:33:29 -08:00
|
|
|
call Sprites_Sine
|
2015-11-19 15:07:20 -08:00
|
|
|
pop hl
|
|
|
|
pop de
|
2018-01-10 10:47:57 -08:00
|
|
|
add 13 * TILE_WIDTH
|
|
|
|
ld [hli], a ; y
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2015-11-19 15:07:20 -08:00
|
|
|
pop af
|
|
|
|
push de
|
|
|
|
push hl
|
2015-12-04 11:33:29 -08:00
|
|
|
call Sprites_Cosine
|
2015-11-19 15:07:20 -08:00
|
|
|
pop hl
|
|
|
|
pop de
|
2018-01-10 10:47:57 -08:00
|
|
|
add 10 * TILE_WIDTH + 4
|
|
|
|
ld [hli], a ; x
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2015-11-19 15:07:20 -08:00
|
|
|
ld a, $0
|
2018-01-10 10:47:57 -08:00
|
|
|
ld [hli], a ; tile id
|
2018-01-01 01:40:30 -08:00
|
|
|
ld a, PAL_BATTLE_OB_BLUE
|
2018-01-10 10:47:57 -08:00
|
|
|
ld [hli], a ; attributes
|
2015-11-28 12:13:40 -08:00
|
|
|
jr .anim_loop
|
2015-11-19 15:07:20 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
EndOfExpBarGFX:
|
2015-11-28 12:13:40 -08:00
|
|
|
INCBIN "gfx/battle/expbarend.2bpp"
|
2015-11-19 15:07:20 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ClearSpriteAnims2:
|
2015-11-19 15:07:20 -08:00
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
push af
|
2020-10-30 12:39:08 -07:00
|
|
|
ld hl, wSpriteAnimData
|
|
|
|
ld bc, wSpriteAnimDataEnd - wSpriteAnimData
|
2015-11-19 15:07:20 -08:00
|
|
|
.loop
|
2018-01-01 01:40:30 -08:00
|
|
|
ld [hl], 0
|
2015-11-19 15:07:20 -08:00
|
|
|
inc hl
|
|
|
|
dec bc
|
|
|
|
ld a, c
|
|
|
|
or b
|
|
|
|
jr nz, .loop
|
|
|
|
pop af
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|