diff options
author | luckytyphlosion <alan.rj.huang@gmail.com> | 2015-10-24 17:35:57 -0400 |
---|---|---|
committer | luckytyphlosion <alan.rj.huang@gmail.com> | 2015-10-24 17:35:57 -0400 |
commit | 3a5d7ec05db9ce1156863983a0427396d6f6f49b (patch) | |
tree | b85979ed890027d54edcd4deca8be46dbf10cbf7 /engine/overworld | |
parent | bb97b63af1fbeca208cb30a41f8195b4408821dc (diff) |
data/facing.asm, titlescreen functions, oam/sprite related functions, other misc functions
Also rename pcm-related functions.
Diffstat (limited to 'engine/overworld')
-rw-r--r-- | engine/overworld/oam.asm | 161 |
1 files changed, 94 insertions, 67 deletions
diff --git a/engine/overworld/oam.asm b/engine/overworld/oam.asm index ff85eb3e..e81375a3 100644 --- a/engine/overworld/oam.asm +++ b/engine/overworld/oam.asm @@ -1,12 +1,14 @@ -PrepareOAMData: +PrepareOAMData: ; 499b (1:499b) ; Determine OAM data for currently visible ; sprites and write it to wOAMBuffer. +; Yellow code has been changed to use registers more efficiently +; as well as tweaking the code to show gbc palettes ld a, [wUpdateSpritesEnabled] dec a jr z, .updateEnabled - cp 0 - 1 + cp $ff ret nz ld [wUpdateSpritesEnabled], a jp HideSprites @@ -17,10 +19,10 @@ PrepareOAMData: .spriteLoop ld [hSpriteOffset2], a - - ld d, wSpriteStateData1 / $100 - ld a, [hSpriteOffset2] + ld e, a + ld d, wSpriteStateData1 / $100 + ld a, [de] ; c1x0 and a jp z, .nextSprite @@ -40,16 +42,22 @@ PrepareOAMData: jr c, .usefacing ; unchanging - and $f - add $10 ; skip to the second half of the table which doesn't account for facing direction + ld a, $0 jr .next .usefacing and $f .next +; read the entry from the table + ld c, a + ld b, 0 + ld hl, SpriteFacingAndAnimationTable + add hl, bc + add hl, bc + ld a, [hli] + ld h, [hl] ld l, a - ; get sprite priority push de inc d @@ -61,65 +69,46 @@ PrepareOAMData: ld [hSpritePriority], a ; temp store sprite priority pop de -; read the entry from the table - ld h, 0 - ld bc, SpriteFacingAndAnimationTable - add hl, hl - add hl, hl - add hl, bc - ld a, [hli] - ld c, a - ld a, [hli] - ld b, a - ld a, [hli] - ld h, [hl] - ld l, a call GetSpriteScreenXY ld a, [hOAMBufferOffset] + add [hl] + cp $a0 + jr z, .hidden + jr nc, .asm_4a41 +.hidden + call Func_4a7b + ld [wd5cd], a + ld a, [hOAMBufferOffset] + ld e, a ld d, wOAMBuffer / $100 .tileLoop + ld a, [hli] + ld c, a +.loop ld a, [hSpriteScreenY] ; temp for sprite Y position add $10 ; Y=16 is top of screen (Y=0 is invisible) add [hl] ; add Y offset from table ld [de], a ; write new sprite OAM Y position inc hl + inc e ld a, [hSpriteScreenX] ; temp for sprite X position add $8 ; X=8 is left of screen (X=0 is invisible) add [hl] ; add X offset from table + ld [de], a + inc hl inc e - ld [de], a ; write new sprite OAM X position - inc e - ld a, [bc] ; read pattern number offset (accommodates orientation (offset 0,4 or 8) and animation (offset 0 or $80)) - inc bc - push bc + ld a, [wd5cd] + add [hl] + cp $80 + jr c, .asm_4a1c ld b, a - - ld a, [wd5cd] ; temp copy of c1x2 - swap a ; high nybble determines sprite used (0 is always player sprite, next are some npcs) - and $f - - ; Sprites $a and $b have one face (and therefore 4 tiles instead of 12). - ; As a result, sprite $b's tile offset is less than normal. - cp $b - jr nz, .notFourTileSprite - ld a, $a * 12 + 4 - jr .next2 - -.notFourTileSprite - ; a *= 12 - sla a - sla a - ld c, a - sla a - add c - -.next2 - add b ; add the tile offset from the table (based on frame and facing direction) - pop bc + ld a, [$fffc] + add b +.asm_4a1c ld [de], a ; tile id inc hl inc e @@ -129,15 +118,19 @@ PrepareOAMData: ld a, [hSpritePriority] or [hl] .skipPriority - inc hl + and $f0 + bit 4, a ; OBP0 or OBP1 + jr z, .spriteusesOBP0 + or %100 ; palettes 4-7 are OBP1 +.spriteusesOBP0 ld [de], a + inc hl inc e - bit 0, a ; OAMFLAG_ENDOFDATA - jr z, .tileLoop + dec c + jr nz, .loop ld a, e ld [hOAMBufferOffset], a - .nextSprite ld a, [hSpriteOffset2] add $10 @@ -145,28 +138,33 @@ PrepareOAMData: jp nz, .spriteLoop ; Clear unused OAM. - ld a, [hOAMBufferOffset] - ld l, a - ld h, wOAMBuffer / $100 - ld de, $4 - ld b, $a0 +.asm_4a41 ld a, [wd736] bit 6, a ; jumping down ledge or fishing animation? - ld a, $a0 + ld c, $a0 jr z, .clear ; Don't clear the last 4 entries because they are used for the shadow in the ; jumping down ledge animation and the rod in the fishing animation. - ld a, $90 + ld c, $90 .clear - cp l - ret z + ld a, [hOAMBufferOffset] + cp c + ret nc + ld l, a + ld h, wOAMBuffer / $100 + ld a, c + ld de, $4 ; entry size + ld b, $a0 +.clearLoop ld [hl], b add hl, de - jr .clear + cp l + jr nz, .clearLoop + ret -GetSpriteScreenXY: ; 4bd1 (1:4bd1) +GetSpriteScreenXY: ; 4a5f (1:4a5f) inc e inc e ld a, [de] ; c1x4 @@ -188,6 +186,32 @@ GetSpriteScreenXY: ; 4bd1 (1:4bd1) ld [de], a ; c1xb (x) ret +Func_4a7b: ; 4a7b (1:4a7b) + push bc + ld a, [wd5cd] ; temp copy of c1x2 + swap a ; high nybble determines sprite used (0 is always player sprite, next are some npcs) + and $f + + ; Sprites $a and $b have one face (and therefore 4 tiles instead of 12). + ; As a result, sprite $b's tile offset is less than normal. + cp $b + jr nz, .notFourTileSprite + ld a, $a * 12 + 4 ; $7c + jr .done + +.notFourTileSprite + ; a *= 12 + add a + add a + ld c, a + add a + add c +.done + pop bc + ret + +INCLUDE "engine/oam_dma.asm" + _IsTilePassable:: ; 4aaa (1:4aaa) ld hl,W_TILESETCOLLISIONPTR ; pointer to list of passable tiles ld a,[hli] @@ -198,8 +222,11 @@ _IsTilePassable:: ; 4aaa (1:4aaa) cp a,$ff jr z,.tileNotPassable cp c - ret z - jr .loop + jr nz,.loop + xor a + ret .tileNotPassable scf - ret
\ No newline at end of file + ret + +INCLUDE "data/collision.asm" ; probably
\ No newline at end of file |