Skip to content

Commit

Permalink
Split hSpriteIndexOrTextID into hSpriteIndex and hTextID
Browse files Browse the repository at this point in the history
Also identify `wPPUpCountAndMaxPP`
  • Loading branch information
Rangi42 committed Sep 10, 2024
1 parent 1f6e2bf commit 66d3adb
Show file tree
Hide file tree
Showing 72 changed files with 180 additions and 181 deletions.
2 changes: 1 addition & 1 deletion data/text/text_2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ _WillBeTradedText::
done

_TextIDErrorText::
text_decimal hSpriteIndexOrTextID, 1, 2
text_decimal hTextID, 1, 2
text " ERROR."
done

Expand Down
2 changes: 1 addition & 1 deletion engine/battle/battle_transitions.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BattleTransition:
; Determine which OAM block is being used by the enemy trainer sprite (if there
; is one).
ld hl, wSpritePlayerStateData1ImageIndex
ldh a, [hSpriteIndexOrTextID] ; enemy trainer sprite index (0 if wild battle)
ldh a, [hSpriteIndex] ; enemy trainer sprite index (0 if wild battle)
ld c, a
ld b, 0
ld de, $10
Expand Down
2 changes: 1 addition & 1 deletion engine/battle/wild_encounters.asm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ TryDoWildEncounter:
.lastRepelStep
ld [wRepelRemainingSteps], a
ld a, TEXT_REPEL_WORE_OFF
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call EnableAutoTextBoxDrawing
call DisplayTextID
.CantEncounter2
Expand Down
4 changes: 2 additions & 2 deletions engine/events/card_key.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PrintCardKeyText:
call GetCoordsInFrontOfPlayer
push de
tx_pre_id CardKeySuccessText
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call PrintPredefTextID
pop de
srl d
Expand All @@ -55,7 +55,7 @@ PrintCardKeyText:
jp PlaySound
.noCardKey
tx_pre_id CardKeyFailText
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
jp PrintPredefTextID

INCLUDE "data/events/card_key_maps.asm"
Expand Down
2 changes: 1 addition & 1 deletion engine/events/hidden_objects/safari_game.asm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SafariZoneGameOver:
cp SFX_SAFARI_ZONE_PA
jr nz, .waitForMusicToPlay
ld a, TEXT_SAFARI_GAME_OVER
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call DisplayTextID
xor a
ld [wPlayerMovingDirection], a
Expand Down
4 changes: 2 additions & 2 deletions engine/events/pick_up_item.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PickUpItem:
call EnableAutoTextBoxDrawing

ldh a, [hSpriteIndexOrTextID]
ldh a, [hSpriteIndex]
ld b, a
ld hl, wMissableObjectList
.missableObjectsListLoop
Expand All @@ -18,7 +18,7 @@ PickUpItem:
ldh [hMissableObjectIndex], a

ld hl, wMapSpriteExtraData
ldh a, [hSpriteIndexOrTextID]
ldh a, [hSpriteIndex]
dec a
add a
ld d, 0
Expand Down
4 changes: 2 additions & 2 deletions engine/events/poison.asm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ApplyOutOfBattlePoisonDamage:
ld [wJoyIgnore], a
call EnableAutoTextBoxDrawing
ld a, TEXT_MON_FAINTED
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call DisplayTextID
pop de
pop hl
Expand Down Expand Up @@ -100,7 +100,7 @@ ApplyOutOfBattlePoisonDamage:
jr nz, .noBlackOut
call EnableAutoTextBoxDrawing
ld a, TEXT_BLACKED_OUT
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call DisplayTextID
ld hl, wStatusFlags4
set BIT_BATTLE_OVER_OR_BLACKOUT, [hl]
Expand Down
20 changes: 8 additions & 12 deletions engine/events/prize_menu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,13 @@ WhichPrizeTextPtr:
text_end

GetPrizeMenuId:
; determine which one among the three
; prize-texts has been selected
; using the text ID (stored in [hSpriteIndexOrTextID])
; load the three prizes at wd13d-wd13f
; load the three prices at wd141-wd146
; display the three prizes' names
; (distinguishing between Pokemon names
; and Items (specifically TMs) names)
ldh a, [hSpriteIndexOrTextID]
sub 3 ; prize-texts' id are 3, 4 and 5
ld [wWhichPrizeWindow], a ; prize-texts' id (relative, i.e. 0, 1 or 2)
; determine which one among the three prize texts has been selected using the text ID (stored in [hTextID])
; load the three prizes at wPrize1-wPrice3
; load the three prices at wPrize1Price-wPrize3Price
; display the three prizes' names, distinguishing between Pokemon names and item names (specifically TMs)
ldh a, [hTextID]
sub 3 ; prize texts' IDs are 3-5
ld [wWhichPrizeWindow], a ; prize texts' relative ID (i.e. 0-2)
add a
add a
ld d, 0
Expand All @@ -88,7 +84,7 @@ GetPrizeMenuId:
ld bc, 6
call CopyData
ld a, [wWhichPrizeWindow]
cp 2 ;is TM_menu?
cp 2 ; is TM_menu?
jr nz, .putMonName
ld a, [wPrize1]
ld [wd11e], a
Expand Down
7 changes: 4 additions & 3 deletions engine/items/item_effects.asm
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,11 @@ ItemUseSurfboard:
jp PrintText
.tryToStopSurfing
xor a
ldh [hSpriteIndexOrTextID], a
ldh [hSpriteIndex], a
ld d, 16 ; talking range in pixels (normal range)
call IsSpriteInFrontOfPlayer2
res 7, [hl]
ldh a, [hSpriteIndexOrTextID]
ldh a, [hSpriteIndex]
and a ; is there a sprite in the way?
jr nz, .cannotStopSurfing
ld hl, TilePairCollisionsWater
Expand Down Expand Up @@ -2512,9 +2512,10 @@ GetMaxPP:
and %11000000 ; get PP Up count
pop bc
or b ; place normal max PP in 6 lower bits of a
assert wMoveData + MOVE_PP + 1 == wPPUpCountAndMaxPP
ld h, d
ld l, e
inc hl ; hl = wcd73
inc hl ; hl = wPPUpCountAndMaxPP
ld [hl], a
xor a ; add the bonus for the existing PP Up count
ld [wUsingPPUp], a
Expand Down
2 changes: 1 addition & 1 deletion engine/menus/display_text_id_init.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DisplayTextIDInit::
ld a, [wAutoTextBoxDrawingControl]
bit 0, a
jr nz, .skipDrawingTextBoxBorder
ldh a, [hSpriteIndexOrTextID] ; text ID (or sprite ID)
ldh a, [hTextID]
and a
jr nz, .notStartMenu
; if text ID is 0 (i.e. the start menu)
Expand Down
6 changes: 3 additions & 3 deletions engine/overworld/push_boulder.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ TryPushingBoulder::
bit BIT_BOULDER_DUST, a
ret nz
xor a
ldh [hSpriteIndexOrTextID], a
ldh [hSpriteIndex], a
call IsSpriteInFrontOfPlayer
ldh a, [hSpriteIndexOrTextID]
ldh a, [hSpriteIndex]
ld [wBoulderSpriteIndex], a
and a
jp z, ResetBoulderPushFlags
ld hl, wSpritePlayerStateData1MovementStatus
ld d, $0
ldh a, [hSpriteIndexOrTextID]
ldh a, [hSpriteIndex]
swap a
ld e, a
add hl, de
Expand Down
20 changes: 10 additions & 10 deletions home/overworld.asm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ OverworldLoopLessDelay::
jr z, .startButtonNotPressed
; if START is pressed
xor a ; TEXT_START_MENU
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
jp .displayDialogue
.startButtonNotPressed
bit BIT_A_BUTTON, a
Expand All @@ -92,7 +92,7 @@ OverworldLoopLessDelay::
and a
jp z, OverworldLoop ; jump if a hidden object or bookshelf was found, but not if a card key door was found
call IsSpriteOrSignInFrontOfPlayer
ldh a, [hSpriteIndexOrTextID]
ldh a, [hTextID]
and a
jp z, OverworldLoop
.displayDialogue
Expand Down Expand Up @@ -1072,11 +1072,11 @@ LoadEastWestConnectionsTileMap::
ret

; function to check if there is a sign or sprite in front of the player
; if so, it is stored in [hSpriteIndexOrTextID]
; if not, [hSpriteIndexOrTextID] is set to 0
; if so, it is stored in [hTextID]
; if not, [hTextID] is set to 0
IsSpriteOrSignInFrontOfPlayer::
xor a
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
ld a, [wNumSigns]
and a
jr z, .extendRangeOverCounter
Expand Down Expand Up @@ -1106,7 +1106,7 @@ IsSpriteOrSignInFrontOfPlayer::
dec c
add hl, bc
ld a, [hl]
ldh [hSpriteIndexOrTextID], a ; store sign text ID
ldh [hTextID], a ; store sign text ID
pop bc
pop hl
ret
Expand All @@ -1127,7 +1127,7 @@ IsSpriteOrSignInFrontOfPlayer::
jr nz, .counterTilesLoop

; part of the above function, but sometimes its called on its own, when signs are irrelevant
; the caller must zero [hSpriteIndexOrTextID]
; the caller must zero [hTextID]
IsSpriteInFrontOfPlayer::
ld d, $10 ; talking range in pixels (normal range)
IsSpriteInFrontOfPlayer2::
Expand Down Expand Up @@ -1212,7 +1212,7 @@ IsSpriteInFrontOfPlayer2::
ld l, a ; hl = x#SPRITESTATEDATA1_MOVEMENTSTATUS
set 7, [hl] ; set flag to make the sprite face the player
ld a, e
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
ret

; function to check if the player will jump down a ledge and check if the tile ahead is passable (when not surfing)
Expand All @@ -1231,9 +1231,9 @@ CollisionCheckOnLand::
and d ; check if a sprite is in the direction the player is trying to go
jr nz, .collision
xor a
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call IsSpriteInFrontOfPlayer ; check for sprite collisions again? when does the above check fail to detect a sprite collision?
ldh a, [hSpriteIndexOrTextID]
ldh a, [hTextID]
and a ; was there a sprite collision?
jr nz, .collision
; if no sprite collision
Expand Down
2 changes: 1 addition & 1 deletion home/predef_text.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PrintPredefTextID::
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
ld hl, TextPredefs
call SetMapTextPointer
ld hl, wTextPredefFlag
Expand Down
4 changes: 2 additions & 2 deletions home/text.asm
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ NullChar:: ; unused
pop hl
; A "<NULL>" character in a printed string
; displays an error message with the current value
; of hSpriteIndexOrTextID in decimal format.
; of hTextID in decimal format.
; This is a debugging leftover.
ld de, TextIDErrorText
dec de
ret

TextIDErrorText:: ; "[hSpriteIndexOrTextID] ERROR."
TextIDErrorText:: ; "[hTextID] ERROR."
text_far _TextIDErrorText
text_end

Expand Down
9 changes: 5 additions & 4 deletions home/text_script.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
; this function is used to display sign messages, sprite dialog, etc.
; INPUT: [hSpriteIndexOrTextID] = sprite ID or text ID
; INPUT: [hSpriteIndex] = sprite ID or [hTextID] = text ID
DisplayTextID::
assert hSpriteIndex == hTextID ; these are at the same memory location
ldh a, [hLoadedROMBank]
push af
farcall DisplayTextIDInit ; initialization
Expand All @@ -18,7 +19,7 @@ DisplayTextID::
ld h, [hl]
ld l, a ; hl = map text pointer
ld d, $00
ldh a, [hSpriteIndexOrTextID] ; text ID
ldh a, [hTextID]
ld [wSpriteIndex], a

dict TEXT_START_MENU, DisplayStartMenu
Expand All @@ -29,7 +30,7 @@ DisplayTextID::

ld a, [wNumSprites]
ld e, a
ldh a, [hSpriteIndexOrTextID] ; sprite ID
ldh a, [hSpriteIndex] ; sprite ID
cp e
jr z, .spriteHandling
jr nc, .skipSpriteHandling
Expand All @@ -42,7 +43,7 @@ DisplayTextID::
pop bc
pop de
ld hl, wMapSpriteData ; NPC text entries
ldh a, [hSpriteIndexOrTextID]
ldh a, [hSpriteIndex]
dec a
add a
add l
Expand Down
4 changes: 2 additions & 2 deletions home/trainers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ StoreTrainerHeaderPointer::
ret

; executes the current map script from the function pointer array provided in de.
; a: map script index to execute (unless overridden by [wd733] bit 4)
; a: map script index to execute (unless overridden by [wStatusFlags7] BIT_USE_CUR_MAP_SCRIPT)
; hl: trainer header pointer
ExecuteCurMapScriptInTable::
push af
Expand Down Expand Up @@ -165,7 +165,7 @@ DisplayEnemyTrainerTextAndStartBattle::
ret nz ; return if the enemy trainer hasn't finished walking to the player's sprite
ld [wJoyIgnore], a
ld a, [wSpriteIndex]
ldh [hSpriteIndexOrTextID], a
ldh [hSpriteIndex], a
call DisplayTextID
; fall through

Expand Down
2 changes: 1 addition & 1 deletion home/uncompress.asm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ _UncompressSpriteData::
; bit 0 decides in which one the first chunk is placed
; fall through

; uncompresses a chunk from the sprite input data stream (pointed to at wd0da) into sSpriteBuffer1 or sSpriteBuffer2
; uncompresses a chunk from the sprite input data stream (pointed to by wSpriteInputPtr) into sSpriteBuffer1 or sSpriteBuffer2
; each chunk is a 1bpp sprite. A 2bpp sprite consist of two chunks which are merged afterwards
; note that this is an endless loop which is terminated during a call to MoveToNextBufferPosition by manipulating the stack
UncompressSpriteDataLoop::
Expand Down
2 changes: 1 addition & 1 deletion ram/hram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ hPreviousTileset::
hRLEByteValue::
db

hSpriteIndexOrTextID:: ; DisplayTextID's argument
hTextID:: ; DisplayTextID's argument
hPartyMonIndex::
db

Expand Down
1 change: 1 addition & 0 deletions ram/wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ wNameBuffer:: ds NAME_BUFFER_LENGTH
NEXTU
; data copied from Moves for one move
wMoveData:: ds MOVE_LENGTH
wPPUpCountAndMaxPP:: db

NEXTU
; amount of money made from one use of Pay Day
Expand Down
4 changes: 2 additions & 2 deletions scripts/AgathasRoom.asm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ AgathasRoomDefaultScript:
jr z, AgathaScriptWalkIntoRoom
.stopPlayerFromLeaving
ld a, TEXT_AGATHASROOM_AGATHA_DONT_RUN_AWAY
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call DisplayTextID
ld a, D_UP
ld [wSimulatedJoypadStatesEnd], a
Expand Down Expand Up @@ -111,7 +111,7 @@ AgathasRoomAgathaEndBattleScript:
cp $ff
jp z, ResetAgathaScript
ld a, TEXT_AGATHASROOM_AGATHA
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call DisplayTextID
ld a, SCRIPT_CHAMPIONSROOM_PLAYER_ENTERS
ld [wChampionsRoomCurScript], a
Expand Down
2 changes: 1 addition & 1 deletion scripts/BillsHouse.asm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ BillsHouseCleanupScript:

BillsHousePCScript:
ld a, TEXT_BILLSHOUSE_ACTIVATE_PC
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call DisplayTextID
ld a, SCRIPT_BILLSHOUSE_DEFAULT
ld [wBillsHouseCurScript], a
Expand Down
4 changes: 2 additions & 2 deletions scripts/BrunosRoom.asm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ BrunosRoomDefaultScript:
jr z, BrunoScriptWalkIntoRoom
.stopPlayerFromLeaving
ld a, TEXT_BRUNOSROOM_BRUNO_DONT_RUN_AWAY
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
call DisplayTextID ; "Don't run away!"
ld a, D_UP
ld [wSimulatedJoypadStatesEnd], a
Expand Down Expand Up @@ -111,7 +111,7 @@ BrunosRoomBrunoEndBattleScript:
cp $ff
jp z, ResetBrunoScript
ld a, TEXT_BRUNOSROOM_BRUNO
ldh [hSpriteIndexOrTextID], a
ldh [hTextID], a
jp DisplayTextID

BrunosRoom_TextPointers:
Expand Down
Loading

0 comments on commit 66d3adb

Please sign in to comment.