Skip to content

Commit

Permalink
Ensure OAM is fully initialized at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
tbsp committed Mar 1, 2022
1 parent 77a2fdd commit 5a5b143
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/header.asm
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,41 @@ Reset::
ld a, WY_START
ldh [rWY], a

; Initialize variables
xor a
; Position sprite to overlap (R)
ld de, SpriteAnimationPath
ld hl, wShadowOAM
ld a, SPRITE_Y_COORD
ld [hli], a
ld a, [de]
ld [hli], a
ld a, SPRITE_TILE_ID
ld [hli], a
ld a, e
ldh [hSpriteLowByte], a

; Clear remaining wShadowOAM
ld a, c ; zero from MemcpySmall
ld c, OAM_COUNT * sizeof_OAM_ATTRS - 3
rst MemsetSmall

; Take advantate of trailing A==0 to initialize a few vars
ldh [hSCYCache], a
ldh [hFrameCounterLogo], a

; Set object palette for effect
dec a ; $FF
ldh [rOBP0], a

; Initialize aditional variables
ld a, SPLIT_LINE+1
ldh [hResumeLY], a
ld a, LOW(SplitAnimationPath)
ldh [hSplitLowByte], a

; Ensure OAM is initialized before sprites are enabled
ld a, HIGH(wShadowOAM)
call hOAMDMA

; Enable window/objects safely
: ldh a, [rSTAT]
and STATF_BUSY
Expand All @@ -110,27 +136,6 @@ Reset::
ld c, 6
call LCDMemsetSmallFromB

; Position sprite to overlap (R)
ld de, SpriteAnimationPath
ld hl, wShadowOAM
ld a, SPRITE_Y_COORD
ld [hli], a
ld a, [de]
ld [hli], a
ld a, SPRITE_TILE_ID
ld [hli], a
ld a, e
ldh [hSpriteLowByte], a

; Clear remaining wShadowOAM
ld a, c ; zero from MemcpySmall
ld c, OAM_COUNT * sizeof_OAM_ATTRS - 3
rst MemsetSmall

; Set object palette for effect
dec a ; $FF
ldh [rOBP0], a

; Animate!
ld b, SPLIT_LINE
ld h, d
Expand Down

0 comments on commit 5a5b143

Please sign in to comment.