ref: 323895af6dada7e1949ff79855970f75ad4b65b2
parent: 04a6c306dce136873fd33d27aa3d5b90d9eeba5a
author: YamaArashi <shadow962@live.com>
date: Thu Jul 23 16:48:35 EDT 2015
fixed hram aliases and named wram var
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -139,6 +139,12 @@
FLAG_SET EQU 1
FLAG_TEST EQU 2
+; special text IDs
+TEXT_MON_FAINTED EQU $d0
+TEXT_BLACKED_OUT EQU $d1
+TEXT_REPEL_WORE_OFF EQU $d2
+TEXT_SAFARI_GAME_OVER EQU $d3
+
; serial
ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK EQU $01
--- a/engine/battle/common_text.asm
+++ b/engine/battle/common_text.asm
@@ -104,10 +104,10 @@
ld [H_MULTIPLICAND], a
ld hl, wEnemyMonHP
ld a, [hli]
- ld [wcce3], a
+ ld [wLastSwitchInEnemyMonHP], a
ld [H_MULTIPLICAND + 1], a
ld a, [hl]
- ld [wcce4], a
+ ld [wLastSwitchInEnemyMonHP + 1], a
ld [H_MULTIPLICAND + 2], a
ld a, 25
ld [H_MULTIPLIER], a
@@ -120,7 +120,7 @@
srl a
rr b
ld a, b
- ld b, $4
+ ld b, 4
ld [H_DIVISOR], a ; enemy mon max HP divided by 4
call Divide
ld a, [H_QUOTIENT + 3] ; a = (enemy mon current HP * 25) / (enemy max HP / 4); this approximates the current percentage of max HP
@@ -174,19 +174,19 @@
push de
push bc
ld hl, wEnemyMonHP + 1
- ld de, wcce4
+ ld de, wLastSwitchInEnemyMonHP + 1
ld b, [hl]
dec hl
ld a, [de]
sub b
- ld [$ff98], a
+ ld [H_MULTIPLICAND + 2], a
dec de
ld b, [hl]
ld a, [de]
sbc b
- ld [$ff97], a
- ld a, $19
- ld [H_POWEROFTEN], a
+ ld [H_MULTIPLICAND + 1], a
+ ld a, 25
+ ld [H_MULTIPLIER], a
call Multiply
ld hl, wEnemyMonMaxHP
ld a, [hli]
@@ -196,22 +196,27 @@
srl a
rr b
ld a, b
- ld b, $4
- ld [H_POWEROFTEN], a
+ ld b, 4
+ ld [H_DIVISOR], a
call Divide
pop bc
pop de
- ld a, [$ff98]
- ld hl, EnoughText
+ ld a, [H_QUOTIENT + 3] ; a = ((LastSwitchInEnemyMonHP - CurrentEnemyMonHP) / 25) / (EnemyMonMaxHP / 4)
+; Assuming that the enemy mon hasn't gained HP since the last switch in,
+; a approximates the percentage that the enemy mon's total HP has decreased
+; since the last switch in.
+; If the enemy mon has gained HP, then a is garbage due to wrap-around and
+; can fall in any of the ranges below.
+ ld hl, EnoughText ; HP stayed the same
and a
ret z
- ld hl, ComeBackText
- cp $1e
+ ld hl, ComeBackText ; HP went down 1% - 29%
+ cp 30
ret c
- ld hl, OKExclamationText
- cp $46
+ ld hl, OKExclamationText ; HP went down 30% - 69%
+ cp 70
ret c
- ld hl, GoodText
+ ld hl, GoodText ; HP went down 70% or more
ret
EnoughText: ; 58f25 (16:4f25)
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -175,7 +175,7 @@
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ld a, $31
- ld [$ffe1], a
+ ld [hStartTileID], a
coord hl, 1, 5
predef CopyUncompressedPicToTilemap
xor a
@@ -1429,9 +1429,9 @@
call LoadEnemyMonData
ld hl,wEnemyMonHP
ld a,[hli]
- ld [wcce3],a
+ ld [wLastSwitchInEnemyMonHP],a
ld a,[hl]
- ld [wcce4],a
+ ld [wLastSwitchInEnemyMonHP + 1],a
ld a,1
ld [wCurrentMenuItem],a
ld a,[wd11d]
@@ -1497,8 +1497,8 @@
call GetMonHeader
ld de,vFrontPic
call LoadMonFrontSprite
- ld a,$CF
- ld [$FFE1],a
+ ld a,-$31
+ ld [hStartTileID],a
coord hl, 15, 6
predef AnimateSendingOutMon
ld a,[wEnemyMonSpecies2]
@@ -1802,7 +1802,7 @@
call DrawPlayerHUDAndHPBar
predef LoadMonBackPic
xor a
- ld [$ffe1], a
+ ld [hStartTileID], a
ld hl, wBattleAndStartSavedMenuItem
ld [hli], a
ld [hl], a
@@ -1839,23 +1839,23 @@
; show 2 stages of the player mon getting smaller before disappearing
AnimateRetreatingPlayerMon: ; 3ccfa (f:4cfa)
coord hl, 1, 5
- ld bc, $707
+ lb bc, 7, 7
call ClearScreenArea
coord hl, 3, 7
- ld bc, $505
+ lb bc, 5, 5
xor a
ld [wDownscaledMonSize], a
- ld [H_DOWNARROWBLINKCNT1], a
+ ld [hBaseTileID], a
predef CopyDownscaledMonTiles
ld c, 4
call DelayFrames
call .clearScreenArea
coord hl, 4, 9
- ld bc, $303
- ld a, $1
+ lb bc, 3, 3
+ ld a, 1
ld [wDownscaledMonSize], a
xor a
- ld [H_DOWNARROWBLINKCNT1], a
+ ld [hBaseTileID], a
predef CopyDownscaledMonTiles
call Delay3
call .clearScreenArea
@@ -1863,7 +1863,7 @@
Coorda 5, 11
.clearScreenArea
coord hl, 1, 5
- ld bc, $707
+ lb bc, 7, 7
jp ClearScreenArea
; reads player's current mon's HP into wBattleMonHP
@@ -6449,7 +6449,7 @@
xor a
ld [$0], a
ld a, $31
- ld [$ffe1], a
+ ld [hStartTileID], a
coord hl, 1, 5
predef_jump CopyUncompressedPicToTilemap
@@ -6862,7 +6862,7 @@
call _LoadTrainerPic
xor a
ld [wEnemyMonSpecies2], a
- ld [$ffe1], a
+ ld [hStartTileID], a
dec a
ld [wAICount], a
coord hl, 12, 0
@@ -6918,7 +6918,7 @@
.spriteLoaded
xor a
ld [W_TRAINERCLASS], a
- ld [$ffe1], a
+ ld [hStartTileID], a
coord hl, 12, 0
predef CopyUncompressedPicToTilemap
@@ -6995,38 +6995,38 @@
ld h, a
ld a, [wPredefRegisters + 1]
ld l, a
- ld a, [$ffe1]
- ld [H_DOWNARROWBLINKCNT1], a
+ ld a, [hStartTileID]
+ ld [hBaseTileID], a
ld b, $4c
ld a, [W_ISINBATTLE]
and a
- jr z, .asm_3f0bc
+ jr z, .notInBattle
add b
ld [hl], a
call Delay3
- ld bc, -41
+ ld bc, -(SCREEN_WIDTH * 2 + 1)
add hl, bc
- ld a, $1
+ ld a, 1
ld [wDownscaledMonSize], a
- ld bc, $303
+ lb bc, 3, 3
predef CopyDownscaledMonTiles
ld c, 4
call DelayFrames
- ld bc, -41
+ ld bc, -(SCREEN_WIDTH * 2 + 1)
add hl, bc
xor a
ld [wDownscaledMonSize], a
- ld bc, $505
+ lb bc, 5, 5
predef CopyDownscaledMonTiles
ld c, 5
call DelayFrames
- ld bc, -41
- jr .asm_3f0bf
-.asm_3f0bc
- ld bc, -123
-.asm_3f0bf
+ ld bc, -(SCREEN_WIDTH * 2 + 1)
+ jr .next
+.notInBattle
+ ld bc, -(SCREEN_WIDTH * 6 + 3)
+.next
add hl, bc
- ld a, [H_DOWNARROWBLINKCNT1]
+ ld a, [hBaseTileID]
add $31
jr CopyUncompressedPicToHL
@@ -7035,52 +7035,52 @@
ld h, a
ld a, [wPredefRegisters + 1]
ld l, a
- ld a, [$ffe1]
+ ld a, [hStartTileID]
CopyUncompressedPicToHL: ; 3f0d0 (f:70d0)
- ld bc, $707
+ lb bc, 7, 7
ld de, SCREEN_WIDTH
push af
ld a, [W_SPRITEFLIPPED]
and a
- jr nz, .asm_3f0ed
+ jr nz, .flipped
pop af
-.asm_3f0de
+.loop
push bc
push hl
-.asm_3f0e0
+.innerLoop
ld [hl], a
add hl, de
inc a
dec c
- jr nz, .asm_3f0e0
+ jr nz, .innerLoop
pop hl
inc hl
pop bc
dec b
- jr nz, .asm_3f0de
+ jr nz, .loop
ret
-.asm_3f0ed
+.flipped
push bc
- ld b, $0
+ ld b, 0
dec c
add hl, bc
pop bc
pop af
-.asm_3f0f4
+.flippedLoop
push bc
push hl
-.asm_3f0f6
+.flippedInnerLoop
ld [hl], a
add hl, de
inc a
dec c
- jr nz, .asm_3f0f6
+ jr nz, .flippedInnerLoop
pop hl
dec hl
pop bc
dec b
- jr nz, .asm_3f0f4
+ jr nz, .flippedLoop
ret
LoadMonBackPic: ; 3f103 (f:7103)
--- a/engine/battle/wild_encounters.asm
+++ b/engine/battle/wild_encounters.asm
@@ -18,11 +18,11 @@
jr z, .CantEncounter
ld a, [wRepelRemainingSteps]
and a
- jr z, .asm_1389e
+ jr z, .next
dec a
jr z, .lastRepelStep
ld [wRepelRemainingSteps], a
-.asm_1389e
+.next
; determine if wild pokemon can appear in the half-block we're standing in
; is the bottom right tile (9,9) of the half-block we're standing in a grass/water tile?
coord hl, 9, 9
@@ -71,7 +71,7 @@
; since the bottom right tile of a "left shore" half-block is $14 but the bottom left tile is not,
; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters.
.gotWildEncounterType
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hli]
ld [W_CURENEMYLVL], a
@@ -89,8 +89,8 @@
jr .willEncounter
.lastRepelStep
ld [wRepelRemainingSteps], a
- ld a, 210
- ld [H_DOWNARROWBLINKCNT2], a
+ ld a, TEXT_REPEL_WORE_OFF
+ ld [hSpriteIndexOrTextID], a
call EnableAutoTextBoxDrawing
call DisplayTextID
.CantEncounter2
--- a/engine/hidden_object_functions17.asm
+++ b/engine/hidden_object_functions17.asm
@@ -71,7 +71,7 @@
ld de, vChars1 + $310
call LoadMonFrontSprite
ld a, $80
- ld [$ffe1], a
+ ld [hStartTileID], a
coord hl, 10, 11
predef AnimateSendingOutMon
call WaitForTextScrollButtonPress
--- a/engine/hidden_object_functions7.asm
+++ b/engine/hidden_object_functions7.asm
@@ -73,19 +73,19 @@
ld a, [wc02a]
cp $b9
jr nz, .asm_1e9c2
- ld a, $d3
- ld [H_DOWNARROWBLINKCNT2], a
+ ld a, TEXT_SAFARI_GAME_OVER
+ ld [hSpriteIndexOrTextID], a
call DisplayTextID
xor a
ld [wPlayerMovingDirection], a
ld a, SAFARI_ZONE_ENTRANCE
- ld [H_DOWNARROWBLINKCNT1], a
+ ld [hWarpDestinationMap], a
ld a, $3
ld [wDestinationWarpID], a
ld a, $5
ld [W_SAFARIZONEENTRANCECURSCRIPT], a
SetEvent EVENT_SAFARI_GAME_OVER
- ld a, $1
+ ld a, 1
ld [wSafariZoneGameOver], a
ret
--- a/engine/oak_speech.asm
+++ b/engine/oak_speech.asm
@@ -229,5 +229,5 @@
coord hl, 6, 4
.next
xor a
- ld [$FFE1],a
+ ld [hStartTileID],a
predef_jump CopyUncompressedPicToTilemap
--- a/engine/overworld/card_key.asm
+++ b/engine/overworld/card_key.asm
@@ -28,7 +28,7 @@
call GetCoordsInFrontOfPlayer
push de
tx_pre_id CardKeySuccessText
- ld [H_DOWNARROWBLINKCNT2], a
+ ld [hSpriteIndexOrTextID], a
call PrintPredefTextID
pop de
srl d
@@ -55,7 +55,7 @@
jp PlaySound
.noCardKey
tx_pre_id CardKeyFailText
- ld [H_DOWNARROWBLINKCNT2], a
+ ld [hSpriteIndexOrTextID], a
jp PrintPredefTextID
SilphCoMapList: ; 526e3 (14:66e3)
--- a/home.asm
+++ b/home.asm
@@ -301,7 +301,7 @@
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
xor a
- ld [$ffe1], a
+ ld [hStartTileID], a
call CopyUncompressedPicToHL
xor a
ld [W_SPRITEFLIPPED], a
@@ -1071,13 +1071,13 @@
ld [wSpriteIndex],a
and a
jp z,DisplayStartMenu
- cp a,$d3
+ cp a,TEXT_SAFARI_GAME_OVER
jp z,DisplaySafariGameOverText
- cp a,$d0
+ cp a,TEXT_MON_FAINTED
jp z,DisplayPokemonFaintedText
- cp a,$d1
+ cp a,TEXT_BLACKED_OUT
jp z,DisplayPlayerBlackedOutText
- cp a,$d2
+ cp a,TEXT_REPEL_WORE_OFF
jp z,DisplayRepelWoreOffText
ld a,[W_NUMSPRITES]
ld e,a
@@ -2825,7 +2825,7 @@
ld a, [de]
cp $ff
jr z, .endOfList
- ld [H_DOWNARROWBLINKCNT1], a ; store byte value to be written
+ ld [hRLEByteValue], a ; store byte value to be written
inc de
ld a, [de]
ld b, $0
@@ -2833,7 +2833,7 @@
ld a, [wRLEByteCount]
add c
ld [wRLEByteCount], a ; update total number of written bytes
- ld a, [H_DOWNARROWBLINKCNT1]
+ ld a, [hRLEByteValue]
call FillMemory ; write a c-times to output
inc de
jr .listLoop
@@ -3906,7 +3906,7 @@
push af ; save existing values on stack
xor a
ld [H_DOWNARROWBLINKCNT1],a ; blinking down arrow timing value 1
- ld a,$06
+ ld a,6
ld [H_DOWNARROWBLINKCNT2],a ; blinking down arrow timing value 2
.loop1
xor a
@@ -4631,7 +4631,7 @@
ret
PrintPredefTextID:: ; 3ef5 (0:3ef5)
- ld [H_DOWNARROWBLINKCNT2], a
+ ld [hSpriteIndexOrTextID], a
ld hl, TextPredefs
call SetMapTextPointer
ld hl, wTextPredefFlag
--- a/hram.asm
+++ b/hram.asm
@@ -4,6 +4,7 @@
; presses the reset sequence (A+B+SEL+START).
; Soft reset when 0 is reached.
+; base tile ID to which offsets are added
hBaseTileID EQU $FF8B
; 3-byte BCD number
@@ -23,6 +24,8 @@
hSlideAmount EQU $FF8B
+hRLEByteValue EQU $FF8B
+
H_SPRITEWIDTH EQU $FF8B ; in tiles
H_SPRITEINTERLACECOUNTER EQU $FF8B
H_SPRITEHEIGHT EQU $FF8C ; in tiles
@@ -260,6 +263,9 @@
hVendingMachineItem EQU $FFDB
hVendingMachinePrice EQU $FFDC ; 3-byte BCD number
+
+; the first tile ID in a sequence of tile IDs that increase by 1 each step
+hStartTileID EQU $FFE1
hNewPartyLength EQU $FFE4
--- a/wram.asm
+++ b/wram.asm
@@ -479,8 +479,11 @@
wEnemyMoveListIndex:: ; cce2
ds 1
-wcce3:: ds 1 ; used in battle-related text functions
-wcce4:: ds 1 ; used in battle-related text functions
+wLastSwitchInEnemyMonHP:: ; cce3
+; The enemy mon's HP when it was switched in or when the current player mon
+; was switched in, which was more recent.
+; It's used to determine the message to print when switching out the player mon.
+ ds 2
wTotalPayDayMoney:: ; cce5
; total amount of money made using Pay Day during the current battle