Identify some more uses of wBuffer1-6

This commit is contained in:
Rangi
2020-11-03 22:45:12 -05:00
parent c88c4a8340
commit 9f62d7911b
6 changed files with 110 additions and 75 deletions

View File

@@ -1,14 +1,14 @@
CheckForHiddenItems:
; Checks to see if there are hidden items on the screen that have not yet been found. If it finds one, returns carry.
call GetMapScriptsBank
ld [wBuffer1], a
; Get the coordinate of the bottom right corner of the screen, and load it in wBuffer3/wBuffer4.
ld [wCurMapScriptBank], a
; Get the coordinate of the bottom right corner of the screen, and load it in wBottomRightYCoord/wBottomRightXCoord.
ld a, [wXCoord]
add SCREEN_WIDTH / 4
ld [wBuffer4], a
ld [wBottomRightXCoord], a
ld a, [wYCoord]
add SCREEN_HEIGHT / 4
ld [wBuffer3], a
ld [wBottomRightYCoord], a
; Get the pointer for the first bg_event in the map...
ld hl, wCurMapBGEventsPointer
ld a, [hli]
@@ -20,14 +20,14 @@ CheckForHiddenItems:
jr z, .nobgeventitems
; For i = 1:wCurMapBGEventCount...
.loop
; Store the counter in wBuffer2, and store the bg_event pointer in the stack.
ld [wBuffer2], a
; Store the counter in wRemainingBGEventCount, and store the bg_event pointer in the stack.
ld [wRemainingBGEventCount], a
push hl
; Get the Y coordinate of the BG event.
call .GetFarByte
ld e, a
; Is the Y coordinate of the BG event on the screen? If not, go to the next BG event.
ld a, [wBuffer3]
ld a, [wBottomRightYCoord]
sub e
jr c, .next
cp SCREEN_HEIGHT / 2
@@ -35,7 +35,7 @@ CheckForHiddenItems:
; Is the X coordinate of the BG event on the screen? If not, go to the next BG event.
call .GetFarByte
ld d, a
ld a, [wBuffer4]
ld a, [wBottomRightXCoord]
sub d
jr c, .next
cp SCREEN_WIDTH / 2
@@ -45,9 +45,9 @@ CheckForHiddenItems:
cp BGEVENT_ITEM
jr nz, .next
; Has this item already been found? If not, set off the Itemfinder.
ld a, [wBuffer1]
ld a, [wCurMapScriptBank]
call GetFarHalfword
ld a, [wBuffer1]
ld a, [wCurMapScriptBank]
call GetFarHalfword
ld d, h
ld e, l
@@ -63,7 +63,7 @@ CheckForHiddenItems:
ld bc, BG_EVENT_SIZE
add hl, bc
; Restore the BG event counter and decrement it. If it hits zero, there are no hidden items in range.
ld a, [wBuffer2]
ld a, [wRemainingBGEventCount]
dec a
jr nz, .loop
@@ -77,7 +77,7 @@ CheckForHiddenItems:
ret
.GetFarByte:
ld a, [wBuffer1]
ld a, [wCurMapScriptBank]
call GetFarByte
inc hl
ret