Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name the unnamed hram variables and one wram label #438

Merged
merged 11 commits into from
Nov 20, 2023
4 changes: 2 additions & 2 deletions engine/events/hidden_objects/bookshelves.asm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PrintBookshelfText::
pop af
call PrintPredefTextID
xor a
ldh [hFFDB], a
ldh [hWasBookShelfTextFound], a
ret
.nextBookshelfEntry1
inc hl
Expand All @@ -33,7 +33,7 @@ PrintBookshelfText::
jr .loop
.noMatch
ld a, $ff
ldh [hFFDB], a
ldh [hWasBookShelfTextFound], a
farjp PrintCardKeyText

INCLUDE "data/tilesets/bookshelf_tile_ids.asm"
4 changes: 2 additions & 2 deletions engine/gfx/sprite_oam.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PrepareOAMData::
inc e
inc e
ld a, [de] ; [x#SPRITESTATEDATA1_IMAGEINDEX]
ld [wd5cd], a
ld [wSpriteImageIndexTempCopy], a
cp $ff ; off-screen (don't draw)
jr nz, .visible

Expand Down Expand Up @@ -98,7 +98,7 @@ PrepareOAMData::
push bc
ld b, a

ld a, [wd5cd] ; temp copy of [x#SPRITESTATEDATA1_IMAGEINDEX]
ld a, [wSpriteImageIndexTempCopy] ; temp copy of [x#SPRITESTATEDATA1_IMAGEINDEX]
swap a ; high nybble determines sprite used (0 is always player sprite, next are some npcs)
and $f

Expand Down
38 changes: 19 additions & 19 deletions engine/overworld/sprite_collisions.asm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ DetectCollisionBetweenSprites:
and $f0
or c

ldh [hFF90], a ; store Y coordinate adjusted for direction of movement
ldh [hSpriteCollisionsTempYStore], a ; store Y coordinate adjusted for direction of movement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete comments when labels make them obsolete.

Suggested change
ldh [hSpriteCollisionsTempYStore], a ; store Y coordinate adjusted for direction of movement
ldh [hSpriteCollisionsTempYStore], a

Copy link
Contributor Author

@Vortyne Vortyne Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these y coord and x coord stores are used for 2 purposes

  • storing y or x coord adjusted for direction of movement
  • storing the distance between the two sprites' adjusted y or x values

so I figured these comments would help distinguish, since wSpriteCollisionsTempYCoordOrDistanceBetweenSpriteAdjustedYValue
would be a bit much...hence why I named it hSpriteCollisionsTempYStore initially, due to multiple purposes, all being dealing with Y or X values

Copy link
Contributor Author

@Vortyne Vortyne Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should make them into two?
hSpriteCollisionsTempYCoord::
hSpriteCollisionsDistanceBetweenAdjustedYValues:: db

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I posted some more label suggestions after reading the file more carefully. Thanks for your patience with all the feedback.


ld a, [hli] ; a = [i#SPRITESTATEDATA1_XSTEPVECTOR] (-1, 0, or 1)
call SetSpriteCollisionValues
Expand All @@ -93,7 +93,7 @@ DetectCollisionBetweenSprites:
and $f0
or c

ldh [hFF91], a ; store X coordinate adjusted for direction of movement
ldh [hSpriteCollisionsTempXStore], a ; store X coordinate adjusted for direction of movement

ld a, l
add 7
Expand All @@ -103,15 +103,15 @@ DetectCollisionBetweenSprites:
ld [hld], a ; zero [i#SPRITESTATEDATA1_0D] XXX what's this for?
ld [hld], a ; zero [i#SPRITESTATEDATA1_COLLISIONDATA]

ldh a, [hFF91]
ldh a, [hSpriteCollisionsTempXStore]
ld [hld], a ; [i#SPRITESTATEDATA1_XADJUSTED]
ldh a, [hFF90]
ldh a, [hSpriteCollisionsTempYStore]
ld [hl], a ; [i#SPRITESTATEDATA1_YADJUSTED]

xor a ; zero the loop counter

.loop
ldh [hFF8F], a ; store loop counter
ldh [hSpriteCollisionsLoopCounter], a ; store loop counter
swap a
ld e, a
ldh a, [hCurrentSpriteOffset]
Expand Down Expand Up @@ -155,7 +155,7 @@ DetectCollisionBetweenSprites:
cpl
inc a
.noCarry1
ldh [hFF90], a ; store the distance between the two sprites' adjusted Y values
ldh [hSpriteCollisionsTempYStore], a ; store the distance between the two sprites' adjusted Y values

; Use the carry flag set by the above subtraction to determine which sprite's
; Y coordinate is larger. This information is used later to set
Expand All @@ -177,11 +177,11 @@ DetectCollisionBetweenSprites:
ld b, 9

.next1
ldh a, [hFF90] ; a = distance between adjusted Y coordinates
ldh a, [hSpriteCollisionsTempYStore] ; a = distance between adjusted Y coordinates
sub b
ldh [hFF92], a ; store distance adjusted using sprite i's direction
ldh [hSpriteCollisionsAdjustedDistance], a ; store distance adjusted using sprite i's direction
ld a, b
ldh [hFF90], a ; store 7 or 9 depending on sprite i's delta Y
ldh [hSpriteCollisionsTempYStore], a ; store 7 or 9 depending on sprite i's delta Y
jr c, .checkXDistance

; If sprite j's delta Y is 0, then b = 7, else b = 9.
Expand All @@ -194,7 +194,7 @@ DetectCollisionBetweenSprites:
ld b, 9

.next2
ldh a, [hFF92] ; a = distance adjusted using sprite i's direction
ldh a, [hSpriteCollisionsAdjustedDistance] ; a = distance adjusted using sprite i's direction
sub b ; adjust distance using sprite j's direction
jr z, .checkXDistance
jr nc, .next ; go to next sprite if distance is still positive after both adjustments
Expand Down Expand Up @@ -226,7 +226,7 @@ DetectCollisionBetweenSprites:
cpl
inc a
.noCarry2
ldh [hFF91], a ; store the distance between the two sprites' adjusted X values
ldh [hSpriteCollisionsTempXStore], a ; store the distance between the two sprites' adjusted X values

; Use the carry flag set by the above subtraction to determine which sprite's
; X coordinate is larger. This information is used later to set
Expand All @@ -248,11 +248,11 @@ DetectCollisionBetweenSprites:
ld b, 9

.next3
ldh a, [hFF91] ; a = distance between adjusted X coordinates
ldh a, [hSpriteCollisionsTempXStore] ; a = distance between adjusted X coordinates
sub b
ldh [hFF92], a ; store distance adjusted using sprite i's direction
ldh [hSpriteCollisionsAdjustedDistance], a ; store distance adjusted using sprite i's direction
ld a, b
ldh [hFF91], a ; store 7 or 9 depending on sprite i's delta X
ldh [hSpriteCollisionsTempXStore], a ; store 7 or 9 depending on sprite i's delta X
jr c, .collision

; If sprite j's delta X is 0, then b = 7, else b = 9.
Expand All @@ -265,15 +265,15 @@ DetectCollisionBetweenSprites:
ld b, 9

.next4
ldh a, [hFF92] ; a = distance adjusted using sprite i's direction
ldh a, [hSpriteCollisionsAdjustedDistance] ; a = distance adjusted using sprite i's direction
sub b ; adjust distance using sprite j's direction
jr z, .collision
jr nc, .next ; go to next sprite if distance is still positive after both adjustments

.collision
ldh a, [hFF91] ; a = 7 or 9 depending on sprite i's delta X
ldh a, [hSpriteCollisionsTempXStore] ; a = 7 or 9 depending on sprite i's delta X
ld b, a
ldh a, [hFF90] ; a = 7 or 9 depending on sprite i's delta Y
ldh a, [hSpriteCollisionsTempYStore] ; a = 7 or 9 depending on sprite i's delta Y
inc l

; If delta X isn't 0 and delta Y is 0, then b = %0011, else b = %1100.
Expand All @@ -296,7 +296,7 @@ DetectCollisionBetweenSprites:
; to indicate which sprite the collision occurred with
inc l
inc l
ldh a, [hFF8F] ; a = loop counter
ldh a, [hSpriteCollisionsLoopCounter] ; a = loop counter
ld de, SpriteCollisionBitTable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data for SpriteCollisionBitTable should use a loop:

SpriteCollisionBitTable:
FOR n, 16
	bigdw 1 << n
ENDR

(The bigdw macro will need porting from pokecrystal.)

add a
add e
Expand All @@ -313,7 +313,7 @@ DetectCollisionBetweenSprites:
ld [hl], a

.next
ldh a, [hFF8F] ; a = loop counter
ldh a, [hSpriteCollisionsLoopCounter] ; a = loop counter
inc a
cp $10
jp nz, .loop
Expand Down
2 changes: 1 addition & 1 deletion home/hidden_objects.asm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CheckForHiddenObjectOrBookshelfOrCardKeyDoor::
jr .done
.hiddenObjectNotFound
farcall PrintBookshelfText
ldh a, [hFFDB]
ldh a, [hWasBookShelfTextFound]
and a
jr z, .done
.nothingFound
Expand Down
11 changes: 5 additions & 6 deletions ram/hram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ hSpriteScreenX:: db
hSpriteScreenY:: db

NEXTU
hFF8F:: db
hFF90:: db
hFF91:: db
hFF92:: db
hSpriteCollisionsLoopCounter:: db
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used as a 0-15 offset into SpriteCollisionBitTable for the sprite being collision-tested with the "current sprite" (whose corresponding offset is already named hCurrentSpriteOffset).

Suggested change
hSpriteCollisionsLoopCounter:: db
hCollidingSpriteOffset:: db

hSpriteCollisionsTempYStore:: db
hSpriteCollisionsTempXStore:: db
Vortyne marked this conversation as resolved.
Show resolved Hide resolved
hSpriteCollisionsAdjustedDistance:: db
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for both the Y and X distance, so:

Suggested change
hSpriteCollisionsAdjustedDistance:: db
hCollidingSpriteAdjustedDistance:: db

ENDU

hTilePlayerStandingOn:: db
Expand Down Expand Up @@ -330,8 +330,7 @@ hGymTrashCanRandNumMask::
db

NEXTU
hFFDB:: db
hFFDC:: db
hWasBookShelfTextFound:: db ; set to 0 if found, $FF if not found when attempting to interact with a hidden object
Rangi42 marked this conversation as resolved.
Show resolved Hide resolved
ENDU

ds 1
Expand Down
2 changes: 1 addition & 1 deletion ram/wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ wMissableObjectFlagsEnd::
ds 7

; temp copy of SPRITESTATEDATA1_IMAGEINDEX (used for sprite facing/anim)
wd5cd:: db
wSpriteImageIndexTempCopy:: db
Rangi42 marked this conversation as resolved.
Show resolved Hide resolved

; each entry consists of 2 bytes
; * the sprite ID (depending on the current map)
Expand Down