shithub: pokered

Download patch

ref: 3870f5e10a1e17f35c78b176272df6b1f516f24e
parent: 1347023128e141dc4cfc71ee6bc689f909e96919
author: YamaArashi <shadow962@live.com>
date: Sat Feb 7 20:44:41 EST 2015

named misc functions

--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -82,4 +82,4 @@
 LINK_STATE_START_BATTLE  EQU $03 ; pre-battle initialisation
 LINK_STATE_BATTLING      EQU $04 ; in a link battle
 LINK_STATE_RESET         EQU $05 ; reset game (unused)
-LINK_STATE_TRADING       EQU $32 ; in a link trade
\ No newline at end of file
+LINK_STATE_TRADING       EQU $32 ; in a link trade
--- a/engine/battle/4_2.asm
+++ b/engine/battle/4_2.asm
@@ -60,7 +60,7 @@
 	ld [hli], a
 	ld [hl], a
 	ld [wListScrollOffset], a
-	ld hl, wd060
+	ld hl, wPlayerStatsToDouble
 	ld b, $18
 .loop
 	ld [hli], a
@@ -402,7 +402,7 @@
 	jr z, .rival
 	ld [wd0b5], a
 	ld a, TRAINER_NAME
-	ld [W_LISTTYPE], a
+	ld [wNameListType], a
 	ld a, BANK(TrainerNames)
 	ld [wPredefBank], a
 	call GetName
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -839,7 +839,7 @@
 	res AttackingMultipleTimes, [hl]
 	xor a
 	ld [wPlayerNumHits], a
-	ld hl, wd065 ; clear enemy statuses
+	ld hl, wEnemyStatsToDouble ; clear enemy statuses
 	ld [hli], a
 	ld [hli], a
 	ld [hli], a
@@ -1366,7 +1366,7 @@
 ; don't change wPartyGainExpFlags or wPartyFoughtCurrentEnemyFlags
 EnemySendOutFirstMon: ; 3c92a (f:492a)
 	xor a
-	ld hl,wd065 ; clear enemy statuses
+	ld hl,wEnemyStatsToDouble ; clear enemy statuses
 	ld [hli],a
 	ld [hli],a
 	ld [hli],a
@@ -1815,7 +1815,7 @@
 	ld hl, wPlayerUsedMove
 	ld [hli], a
 	ld [hl], a
-	ld hl, wd060
+	ld hl, wPlayerStatsToDouble
 	ld [hli], a
 	ld [hli], a
 	ld [hli], a
@@ -5671,7 +5671,7 @@
 	ld a, BANK(MoveNames)
 	ld [wPredefBank], a
 	ld a, MOVE_NAME
-	ld [W_LISTTYPE], a
+	ld [wNameListType], a
 	call GetName
 	ld de, wcd6d
 	call CopyStringToCF4B
@@ -6148,7 +6148,7 @@
 	ld a, BANK(MoveNames)
 	ld [wPredefBank], a
 	ld a, MOVE_NAME
-	ld [W_LISTTYPE], a
+	ld [wNameListType], a
 	call GetName
 	ld de, wcd6d
 	jp CopyStringToCF4B
@@ -6339,7 +6339,7 @@
 	ld [hWY], a
 	ld [rWY], a
 	ld [hTilesetType], a
-	ld hl, wd060
+	ld hl, wPlayerStatsToDouble
 	ld [hli], a
 	ld [hli], a
 	ld [hli], a
@@ -6423,10 +6423,11 @@
 	hlCoord 1, 5
 	predef_jump Func_3f0c6
 
-Func_3ed02: ; 3ed02 (f:6d02)
-	callab Func_39680
-	ld hl, Func_396a7
-	ld b, BANK(Func_396a7)
+; does nothing since no stats are ever selected (barring glitches)
+DoubleOrHalveSelectedStats: ; 3ed02 (f:6d02)
+	callab DoubleSelectedStats
+	ld hl, HalveSelectedStats
+	ld b, BANK(HalveSelectedStats)
 	jp Bankswitch
 
 ScrollTrainerPicAfterBattle: ; 3ed12 (f:6d12)
--- a/engine/battle/e.asm
+++ b/engine/battle/e.asm
@@ -1,24 +1,25 @@
-Func_39680: ; 39680 (e:5680)
-	ld a, [H_WHOSETURN] ; $fff3
+; does nothing since no stats are ever selected (barring glitches)
+DoubleSelectedStats: ; 39680 (e:5680)
+	ld a, [H_WHOSETURN]
 	and a
-	ld a, [wd060]
+	ld a, [wPlayerStatsToDouble]
 	ld hl, wBattleMonAttack + 1
-	jr z, .asm_39691
-	ld a, [wd065]
+	jr z, .notEnemyTurn
+	ld a, [wEnemyStatsToDouble]
 	ld hl, wEnemyMonAttack + 1
-.asm_39691
-	ld c, $4
+.notEnemyTurn
+	ld c, 4
 	ld b, a
-.asm_39694
+.loop
 	srl b
-	call c, Func_3969f
+	call c, .doubleStat
 	inc hl
 	inc hl
 	dec c
 	ret z
-	jr .asm_39694
+	jr .loop
 
-Func_3969f: ; 3969f (e:569f)
+.doubleStat
 	ld a, [hl]
 	add a
 	ld [hld], a
@@ -27,35 +28,36 @@
 	ld [hli], a
 	ret
 
-Func_396a7: ; 396a7 (e:56a7)
-	ld a, [H_WHOSETURN] ; $fff3
+; does nothing since no stats are ever selected (barring glitches)
+HalveSelectedStats: ; 396a7 (e:56a7)
+	ld a, [H_WHOSETURN]
 	and a
-	ld a, [wd061]
+	ld a, [wPlayerStatsToHalve]
 	ld hl, wBattleMonAttack
-	jr z, .asm_396b8
-	ld a, [wd066]
+	jr z, .notEnemyTurn
+	ld a, [wEnemyStatsToHalve]
 	ld hl, wEnemyMonAttack
-.asm_396b8
-	ld c, $4
+.notEnemyTurn
+	ld c, 4
 	ld b, a
-.asm_396bb
+.loop
 	srl b
-	call c, Func_396c6
+	call c, .halveStat
 	inc hl
 	inc hl
 	dec c
 	ret z
-	jr .asm_396bb
+	jr .loop
 
-Func_396c6: ; 396c6 (e:56c6)
+.halveStat
 	ld a, [hl]
 	srl a
 	ld [hli], a
 	rr [hl]
 	or [hl]
-	jr nz, .asm_396d1
-	ld [hl], $1
-.asm_396d1
+	jr nz, .nonzeroStat
+	ld [hl], 1
+.nonzeroStat
 	dec hl
 	ret
 
@@ -69,41 +71,42 @@
 	callab _LoadTrainerPic
 	hlCoord 19, 0
 	ld c, $0
-.asm_396e9
+.scrollLoop
 	inc c
 	ld a, c
-	cp $7
+	cp 7
 	ret z
 	ld d, $0
 	push bc
 	push hl
-.asm_396f2
-	call Func_39707
+.drawTrainerPicLoop
+	call DrawTrainerPicColumn
 	inc hl
-	ld a, $7
+	ld a, 7
 	add d
 	ld d, a
 	dec c
-	jr nz, .asm_396f2
-	ld c, $4
+	jr nz, .drawTrainerPicLoop
+	ld c, 4
 	call DelayFrames
 	pop hl
 	pop bc
 	dec hl
-	jr .asm_396e9
+	jr .scrollLoop
 
-Func_39707: ; 39707 (e:5707)
+; write one 7-tile column of the trainer pic to the tilemap
+DrawTrainerPicColumn: ; 39707 (e:5707)
 	push hl
 	push de
 	push bc
-	ld e, $7
-.asm_3970c
+	ld e, 7
+.loop
 	ld [hl], d
-	ld bc, $14
+	ld bc, SCREEN_WIDTH
 	add hl, bc
 	inc d
 	dec e
-	jr nz, .asm_3970c
+	jr nz, .loop
 	pop bc
 	pop de
 	pop hl
@@ -591,7 +594,7 @@
 	ld a, BANK(MoveNames)
 	ld [wPredefBank], a
 	ld a, MOVE_NAME
-	ld [W_LISTTYPE], a
+	ld [wNameListType], a
 	call GetName
 	ld hl, wcd6d
 .copyNameLoop
@@ -630,41 +633,42 @@
 	ld [de], a
 	ret
 
+; XXX this is called in a few places, but it doesn't appear to do anything useful
 Func_39bd5: ; 39bd5 (e:5bd5)
 	ld a, [wd11b]
 	cp $1
 	jr nz, .asm_39be6
-	ld hl, wEnemyPartyCount ; wEnemyPartyCount
-	ld de, wEnemyMonOT ; wd9ac OT names of other player
-	ld a, $6
+	ld hl, wEnemyPartyCount
+	ld de, wEnemyMonOT
+	ld a, ENEMYOT_NAME
 	jr .asm_39c18
 .asm_39be6
 	cp $4
 	jr nz, .calcAttackStat4
-	ld hl, wPartyCount ; wPartyCount
-	ld de, wPartyMonOT ; wd273
-	ld a, $5
+	ld hl, wPartyCount
+	ld de, wPartyMonOT
+	ld a, PLAYEROT_NAME
 	jr .asm_39c18
 .calcAttackStat4
 	cp $5
 	jr nz, .asm_39c02
 	ld hl, wStringBuffer2 + 11
-	ld de, MonsterNames ; $421e
-	ld a, $1
+	ld de, MonsterNames
+	ld a, MONSTER_NAME
 	jr .asm_39c18
 .asm_39c02
 	cp $2
 	jr nz, .asm_39c10
-	ld hl, wNumBagItems ; wNumBagItems
-	ld de, ItemNames ; $472b
-	ld a, $4
+	ld hl, wNumBagItems
+	ld de, ItemNames
+	ld a, ITEM_NAME
 	jr .asm_39c18
 .asm_39c10
 	ld hl, wStringBuffer2 + 11
-	ld de, ItemNames ; $472b
+	ld de, ItemNames
 	ld a, ITEM_NAME
 .asm_39c18
-	ld [W_LISTTYPE], a
+	ld [wNameListType], a
 	ld a, l
 	ld [wList], a
 	ld a, h
@@ -680,19 +684,20 @@
 	ld [wItemPrices + 1], a
 	ret
 
-Func_39c37: ; 39c37 (e:5c37)
+; get species of mon e in list [wcc49] for LoadMonData
+GetMonSpecies: ; 39c37 (e:5c37)
 	ld hl, wPartySpecies
 	ld a, [wcc49]
 	and a
-	jr z, .asm_39c4b
+	jr z, .getSpecies
 	dec a
-	jr z, .asm_39c48
+	jr z, .enemyParty
 	ld hl, wBoxSpecies
-	jr .asm_39c4b
-.asm_39c48
+	jr .getSpecies
+.enemyParty
 	ld hl, wEnemyPartyMons
-.asm_39c4b
-	ld d, $0
+.getSpecies
+	ld d, 0
 	add hl, de
 	ld a, [hl]
 	ld [wcf91], a
@@ -955,7 +960,7 @@
 JugglerAI: ; 3a5e9 (e:65e9)
 	cp $40
 	ret nc
-	jp Func_3a72a
+	jp AISwitchIfEnoughMons
 
 BlackbeltAI: ; 3a5ef (e:65ef)
 	cp $20
@@ -975,12 +980,12 @@
 CooltrainerFAI: ; 3a601 (e:6601)
 	cp $40
 	ld a,$A
-	call Func_3a7cf
+	call AICheckIfHPBelowFraction
 	jp c,AIUseHyperPotion
 	ld a,5
-	call Func_3a7cf
+	call AICheckIfHPBelowFraction
 	ret nc
-	jp Func_3a72a
+	jp AISwitchIfEnoughMons
 
 BrockAI: ; 3a614 (e:6614)
 ; if his active monster has a status condition, use a full heal
@@ -1003,7 +1008,7 @@
 	cp $80
 	ret nc
 	ld a,$A
-	call Func_3a7cf
+	call AICheckIfHPBelowFraction
 	ret nc
 	jp AIUseSuperPotion
 
@@ -1021,7 +1026,7 @@
 	cp $40
 	ret nc
 	ld a,$A
-	call Func_3a7cf
+	call AICheckIfHPBelowFraction
 	ret nc
 	jp AIUseHyperPotion
 
@@ -1029,7 +1034,7 @@
 	cp $20
 	ret nc
 	ld a,5
-	call Func_3a7cf
+	call AICheckIfHPBelowFraction
 	ret nc
 	jp AIUsePotion
 
@@ -1037,7 +1042,7 @@
 	cp $20
 	ret nc
 	ld a,5
-	call Func_3a7cf
+	call AICheckIfHPBelowFraction
 	ret nc
 	jp AIUseFullRestore
 
@@ -1045,7 +1050,7 @@
 	cp $80
 	ret nc
 	ld a,5
-	call Func_3a7cf
+	call AICheckIfHPBelowFraction
 	ret nc
 	jp AIUseSuperPotion
 
@@ -1056,11 +1061,11 @@
 
 AgathaAI: ; 3a676 (e:6676)
 	cp $14
-	jp c,Func_3a72a
+	jp c,AISwitchIfEnoughMons
 	cp $80
 	ret nc
 	ld a,4
-	call Func_3a7cf
+	call AICheckIfHPBelowFraction
 	ret nc
 	jp AIUseSuperPotion
 
@@ -1068,7 +1073,7 @@
 	cp $80
 	ret nc
 	ld a,5
-	call Func_3a7cf
+	call AICheckIfHPBelowFraction
 	ret nc
 	jp AIUseHyperPotion
 
@@ -1110,7 +1115,7 @@
 	ld [de],a
 	ld [wHPBarMaxHP+1],a
 	ld [wEnemyMonHP],a
-	jr Func_3a718
+	jr AIPrintItemUseAndUpdateHPBar
 
 AIUsePotion: ; 3a6ca (e:66ca)
 ; enemy trainer heals his monster with a potion
@@ -1160,7 +1165,7 @@
 	ld a,[de]
 	ld [wHPBarMaxHP+1],a
 	sbc b
-	jr nc,Func_3a718
+	jr nc,AIPrintItemUseAndUpdateHPBar
 	inc de
 	ld a,[de]
 	dec de
@@ -1171,7 +1176,7 @@
 	ld [wHPBarNewHP+1],a
 	; fallthrough
 
-Func_3a718: ; 3a718 (e:6718)
+AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718)
 	call AIPrintItemUse_
 	hlCoord 2, 2
 	xor a
@@ -1179,7 +1184,8 @@
 	predef UpdateHPBar2
 	jp DecrementAICount
 
-Func_3a72a: ; 3a72a (e:672a)
+AISwitchIfEnoughMons: ; 3a72a (e:672a)
+; enemy trainer switches if there are 3 or more unfainted mons in party
 	ld a,[wEnemyPartyCount]
 	ld c,a
 	ld hl,wEnemyMon1HP
@@ -1281,7 +1287,8 @@
 	ld a,DIRE_HIT
 	jp AIPrintItemUse
 
-Func_3a7cf: ; 3a7cf (e:67cf)
+AICheckIfHPBelowFraction: ; 3a7cf (e:67cf)
+; return carry if enemy trainer's current HP is below 1 / a of the maximum
 	ld [H_DIVISOR],a
 	ld hl,wEnemyMonMaxHP
 	ld a,[hli]
@@ -1395,7 +1402,7 @@
 	ld a, $8
 	ld [wTrainerEngageDistance], a
 	ld hl, wOAMBuffer
-	jp Func_3a8e1
+	jp WritePokeballOAMData
 
 SetupEnemyPartyPokeballs: ; 3a887 (e:6887)
 	call PlaceEnemyHUDTiles
@@ -1409,7 +1416,7 @@
 	ld a, $f8
 	ld [wTrainerEngageDistance], a
 	ld hl, wOAMBuffer + PARTY_LENGTH * 4
-	jp Func_3a8e1
+	jp WritePokeballOAMData
 
 SetupPokeballs: ; 0x3a8a6
 	ld a, [de]
@@ -1421,7 +1428,7 @@
 	ld [de], a
 	inc de
 	dec c
-	jr nz, .emptyloop ; 0x3a8b2 $fb
+	jr nz, .emptyloop
 	pop af
 	ld de, wBuffer
 .monloop
@@ -1461,10 +1468,10 @@
 	add hl, bc
 	ret
 
-Func_3a8e1: ; 3a8e1 (e:68e1)
-	ld de, wHPBarMaxHP
+WritePokeballOAMData: ; 3a8e1 (e:68e1)
+	ld de, wBuffer
 	ld c, PARTY_LENGTH
-.asm_3a8e6
+.loop
 	ld a, [W_BASECOORDY] ; wd082
 	ld [hli], a
 	ld a, [W_BASECOORDX] ; wd081
@@ -1480,7 +1487,7 @@
 	ld [W_BASECOORDX], a ; wd081
 	inc de
 	dec c
-	jr nz, .asm_3a8e6
+	jr nz, .loop
 	ret
 
 PlacePlayerHUDTiles: ; 3a902 (e:6902)
@@ -1542,7 +1549,7 @@
 	ld a, $8
 	ld [wTrainerEngageDistance], a
 	ld hl, wOAMBuffer
-	call Func_3a8e1
+	call WritePokeballOAMData
 	ld hl, wEnemyMons ; wEnemyMon1Species
 	ld de, wEnemyPartyCount ; wEnemyPartyCount
 	call SetupPokeballs
@@ -1551,7 +1558,7 @@
 	ld [hli], a
 	ld [hl], $68
 	ld hl, wOAMBuffer + $18
-	jp Func_3a8e1
+	jp WritePokeballOAMData
 
 ; four tiles: pokeball, black pokeball (status ailment), crossed out pokeball (faited) and pokeball slot (no mon)
 PokeballTileGraphics:: ; 3a97e (e:697e)
--- a/engine/evos_moves.asm
+++ b/engine/evos_moves.asm
@@ -139,7 +139,7 @@
 	ld [wLoadedMonSpecies], a
 	ld [wHPBarMaxHP + 1], a
 	ld a, MONSTER_NAME
-	ld [W_LISTTYPE], a
+	ld [wNameListType], a
 	ld a, BANK(TrainerNames) ; bank is not used for monster names
 	ld [wPredefBank], a
 	call GetName
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -777,7 +777,7 @@
 	ld de,wBattleMonMaxHP
 	ld bc,10
 	call CopyData ; copy party stats to in-battle stat data
-	predef Func_3ed02
+	predef DoubleOrHalveSelectedStats
 	jp .doneHealing
 .healHP
 	inc hl ; hl = address of current HP
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -101,7 +101,7 @@
 	xor a
 	ld [wccd3], a
 	inc a               ; MONSTER_NAME
-	ld [W_LISTTYPE], a
+	ld [wNameListType], a
 	call LoadHpBarAndStatusTilePatterns
 	ld a, [wListScrollOffset]
 	push af
@@ -332,7 +332,7 @@
 	ld [wcf93], a
 	ld [wListMenuID], a
 	inc a                ; MONSTER_NAME
-	ld [W_LISTTYPE], a
+	ld [wNameListType], a
 	ld a, [wcc2b]
 	ld [wCurrentMenuItem], a
 	call DisplayListMenuID
--- a/engine/menu/players_pc.asm
+++ b/engine/menu/players_pc.asm
@@ -2,7 +2,7 @@
 	ld hl, wd730
 	set 6, [hl]
 	ld a, ITEM_NAME
-	ld [W_LISTTYPE], a
+	ld [wNameListType], a
 	call SaveScreenTilesToBuffer1
 	xor a
 	ld [wcc2c], a
--- a/engine/predefs.asm
+++ b/engine/predefs.asm
@@ -92,7 +92,7 @@
 	add_predef UpdateHPBar
 	add_predef HPBarLength
 	add_predef Diploma_TextBoxBorder
-	add_predef Func_3ed02
+	add_predef DoubleOrHalveSelectedStats
 	add_predef ShowPokedexMenu
 	add_predef EvolutionAfterBattle
 	add_predef SaveSAVtoSRAM0
--- a/home.asm
+++ b/home.asm
@@ -1931,7 +1931,7 @@
 
 	ld [wd0b5],a
 	ld a,ITEM_NAME
-	ld [W_LISTTYPE],a
+	ld [wNameListType],a
 	ld a,BANK(ItemNames)
 	ld [wPredefBank],a
 	call GetName
@@ -2028,7 +2028,7 @@
 GetMoveName:: ; 3058 (0:3058)
 	push hl
 	ld a,MOVE_NAME
-	ld [W_LISTTYPE],a
+	ld [wNameListType],a
 	ld a,[wd11e]
 	ld [wd0b5],a
 	ld a,BANK(MoveNames)
@@ -3252,7 +3252,7 @@
 GetName:: ; 376b (0:376b)
 ; arguments:
 ; [wd0b5] = which name
-; [wd0b6] = which list (W_LISTTYPE)
+; [wNameListType] = which list
 ; [wPredefBank] = bank of list
 ;
 ; returns pointer to name in de
@@ -3269,7 +3269,7 @@
 	push hl
 	push bc
 	push de
-	ld a,[W_LISTTYPE]    ;List3759_entrySelector
+	ld a,[wNameListType]    ;List3759_entrySelector
 	dec a
 	jr nz,.otherEntries
 	;1 = MON_NAMES
@@ -3284,7 +3284,7 @@
 	ld a,[wPredefBank]
 	ld [H_LOADEDROMBANK],a
 	ld [$2000],a
-	ld a,[W_LISTTYPE]    ;VariousNames' entryID
+	ld a,[wNameListType]    ;VariousNames' entryID
 	dec a
 	add a
 	ld d,0
--- a/main.asm
+++ b/main.asm
@@ -96,7 +96,7 @@
 
 	ld a, [wWhichPokemon]
 	ld e, a
-	callab Func_39c37 ; get pokemon ID
+	callab GetMonSpecies
 
 .GetMonHeader
 	ld a, [wcf91]
--- a/wram.asm
+++ b/wram.asm
@@ -979,9 +979,14 @@
 W_MOVEMISSED:: ; d05f
 	ds 1
 
-wd060:: ds 1
-wd061:: ds 1
+wPlayerStatsToDouble:: ; d060
+; always 0
+	ds 1
 
+wPlayerStatsToHalve:: ; d061
+; always 0
+	ds 1
+
 W_PLAYERBATTSTATUS1:: ; d062
 ; bit 0 - bide
 ; bit 1 - thrash / petal dance
@@ -1010,9 +1015,14 @@
 ; bit 3 - tranformed
 	ds 1
 
-wd065:: ds 1
-wd066:: ds 1
+wEnemyStatsToDouble:: ; d065
+; always 0
+	ds 1
 
+wEnemyStatsToHalve:: ; d066
+; always 0
+	ds 1
+
 W_ENEMYBATTSTATUS1:: ; d067
 	ds 1
 W_ENEMYBATTSTATUS2:: ; d068
@@ -1213,7 +1223,7 @@
 
 wd0b5:: ds 1
 
-W_LISTTYPE:: ; d0b6
+wNameListType:: ; d0b6
 	ds 1
 
 wPredefBank:: ; d0b7