From 5a5b143bbc41cbfd77abc7f6ed7d4c93fc345f81 Mon Sep 17 00:00:00 2001 From: Dave VanEe Date: Tue, 1 Mar 2022 07:10:18 -0800 Subject: [PATCH] Ensure OAM is fully initialized at startup --- src/header.asm | 51 +++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/header.asm b/src/header.asm index 88c8436..944989d 100644 --- a/src/header.asm +++ b/src/header.asm @@ -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 @@ -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