shithub: pokecrystal

Download patch

ref: f76dabedcc8af56c871e06a4721de4c79bd30908
parent: c552390a15ae27a24109f369264f1caa6b9f8295
author: Rangi <[email protected]>
date: Tue Jun 16 15:32:36 EDT 2020

Harmonize engine/{battle, battle_anims, events, games} with pokegold

--- a/engine/battle/battle_transition.asm
+++ b/engine/battle/battle_transition.asm
@@ -55,7 +55,7 @@
 	ldh [hLYOverrideEnd], a
 	ldh [hSCY], a
 
-	ld a, 1 ; unnecessary bankswitch?
+	ld a, $1 ; unnecessary bankswitch?
 	ldh [rSVBK], a
 	pop af
 	ldh [hVBlank], a
@@ -313,7 +313,6 @@
 	farcall Function5602
 	ld a, BANK(wLYOverrides)
 	ldh [rSVBK], a
-
 	call StartTrainerBattle_NextScene
 
 	ld a, LOW(rSCX)
@@ -349,7 +348,7 @@
 	ld [hl], a
 	ld a, wLYOverridesEnd - wLYOverrides
 	ld bc, wLYOverrides
-	ld e, $0
+	ld e, 0
 
 .loop
 	push af
@@ -360,7 +359,7 @@
 	inc bc
 	pop de
 	ld a, e
-	add $2
+	add 2
 	ld e, a
 	pop af
 	dec a
@@ -391,7 +390,7 @@
 	jr z, .end
 	ld [wcf65], a
 	call .load
-	ld a, $1
+	ld a, 1
 	ldh [hBGMapMode], a
 	call DelayFrame
 	call DelayFrame
@@ -400,7 +399,7 @@
 	ret
 
 .end
-	ld a, $1
+	ld a, 1
 	ldh [hBGMapMode], a
 	call DelayFrame
 	call DelayFrame
@@ -516,7 +515,7 @@
 	call StartTrainerBattle_NextScene
 	ld a, $10
 	ld [wcf64], a
-	ld a, $1
+	ld a, 1
 	ldh [hBGMapMode], a
 	ret
 
@@ -585,6 +584,7 @@
 
 	xor a
 	ldh [hBGMapMode], a
+
 	hlcoord 0, 0, wAttrmap
 	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
 	inc b
@@ -591,29 +591,29 @@
 	inc c
 	jr .enter_loop_midway
 
-.loop
+.pal_loop
 ; set all pals to 7
 	ld a, [hl]
-	or %00000111
+	or PAL_BG_TEXT
 	ld [hli], a
 .enter_loop_midway
 	dec c
-	jr nz, .loop
+	jr nz, .pal_loop
 	dec b
-	jr nz, .loop
+	jr nz, .pal_loop
 
 	call .loadpokeballgfx
 	hlcoord 2, 1
 
 	ld b, SCREEN_WIDTH - 4
-.loop2
+.tile_loop
 	push hl
 	ld c, 2
-.loop3
+.row_loop
 	push hl
 	ld a, [de]
 	inc de
-.loop4
+.col_loop
 ; Loading is done bit by bit
 	and a
 	jr z, .done
@@ -622,7 +622,7 @@
 	ld [hl], BATTLETRANSITION_SQUARE
 .no_load
 	inc hl
-	jr .loop4
+	jr .col_loop
 
 .done
 	pop hl
@@ -631,7 +631,7 @@
 	add hl, bc
 	pop bc
 	dec c
-	jr nz, .loop3
+	jr nz, .row_loop
 
 	pop hl
 	push bc
@@ -639,12 +639,12 @@
 	add hl, bc
 	pop bc
 	dec b
-	jr nz, .loop2
+	jr nz, .tile_loop
 
 	ldh a, [hCGB]
 	and a
 	jr nz, .cgb
-	ld a, $1
+	ld a, 1
 	ldh [hBGMapMode], a
 	call DelayFrame
 	call DelayFrame
@@ -673,7 +673,7 @@
 	call CopyBytes
 	pop af
 	ldh [rSVBK], a
-	ld a, $1
+	ld a, 1
 	ldh [hCGBPalUpdate], a
 	call DelayFrame
 	call BattleStart_CopyTilemapAtOnce
@@ -827,7 +827,7 @@
 	ret
 
 Unreferenced_Function8c7c9:
-	ld a, $1
+	ld a, 1
 	ldh [hBGMapMode], a
 	call WaitBGMap
 	xor a
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -1963,7 +1963,7 @@
 	ld b, a
 	ld a, [hl]
 	sbc b
-	jr c, .asm_3cd2d
+	jr c, .overflow
 	ld a, b
 	ld [hli], a
 	ld [wBuffer6], a
@@ -1970,7 +1970,7 @@
 	ld a, c
 	ld [hl], a
 	ld [wBuffer5], a
-.asm_3cd2d
+.overflow
 
 	call SwitchTurnCore
 	call UpdateHPBarBattleHuds
@@ -5958,7 +5958,7 @@
 	jp nz, InitEnemyMon
 
 ; and also not in a BattleTower-Battle
-	ld a, [wInBattleTowerBattle] ; ????
+	ld a, [wInBattleTowerBattle]
 	bit 0, a
 	jp nz, InitEnemyMon
 
@@ -7764,7 +7764,6 @@
 	text_end
 
 Unreferenced_TextJump_ComeBack:
-; this function doesn't seem to be used
 	ld hl, ComeBackText
 	ret
 
@@ -8127,8 +8126,8 @@
 	jr nz, .ok
 	xor a
 	ld [wOTPartyMon1Item], a
-.ok
 
+.ok
 	ld de, vTiles2
 	callfar GetTrainerPic
 	xor a
@@ -8374,21 +8373,21 @@
 	ld a, [wBattleResult]
 	and $f
 	cp LOSE
-	jr c, .victory ; WIN
-	jr z, .loss ; LOSE
+	jr c, .win ; WIN
+	jr z, .lose ; LOSE
 	; DRAW
 	farcall StubbedTrainerRankings_ColosseumDraws
 	ld de, .Draw
 	jr .store_result
 
-.victory
+.win
 	farcall StubbedTrainerRankings_ColosseumWins
-	ld de, .Win
+	ld de, .YouWin
 	jr .store_result
 
-.loss
+.lose
 	farcall StubbedTrainerRankings_ColosseumLosses
-	ld de, .Lose
+	ld de, .YouLose
 	jr .store_result
 
 .store_result
@@ -8418,9 +8417,9 @@
 	call ClearTilemap
 	ret
 
-.Win:
+.YouWin:
 	db "YOU WIN@"
-.Lose:
+.YouLose:
 	db "YOU LOSE@"
 .Draw:
 	db "  DRAW@"
@@ -8427,7 +8426,7 @@
 
 .Mobile_InvalidBattle:
 	hlcoord 6, 8
-	ld de, .Invalid
+	ld de, .InvalidBattle
 	call PlaceString
 	ld c, 200
 	call DelayFrames
@@ -8434,7 +8433,7 @@
 	call ClearTilemap
 	ret
 
-.Invalid:
+.InvalidBattle:
 	db "INVALID BATTLE@"
 
 IsMobileBattle2:
@@ -9013,7 +9012,7 @@
 	ld de, vTiles2 tile $31
 	ldh a, [hROMBank]
 	ld b, a
-	ld c, $31
+	ld c, 7 * 7
 	call Get2bpp
 	pop af
 	ldh [rSVBK], a
--- a/engine/battle/effect_commands.asm
+++ b/engine/battle/effect_commands.asm
@@ -5079,7 +5079,7 @@
 	call UpdateBattleMonInParty
 	xor a
 	ld [wNumHits], a
-	inc a
+	inc a ; TRUE
 	ld [wForcedSwitch], a
 	call SetBattleDraw
 	ld a, [wPlayerMoveStructAnimation]
@@ -5172,7 +5172,7 @@
 	call UpdateBattleMonInParty
 	xor a
 	ld [wNumHits], a
-	inc a
+	inc a ; TRUE
 	ld [wForcedSwitch], a
 	call SetBattleDraw
 	ld a, [wEnemyMoveStructAnimation]
--- a/engine/battle/read_trainer_party.asm
+++ b/engine/battle/read_trainer_party.asm
@@ -380,8 +380,7 @@
 	pop de
 	ret
 
-Function39990:
-; This function is useless.
+Unreferenced_Function39990:
 	ld de, wStringBuffer1
 	push de
 	ld bc, NAME_LENGTH
--- a/engine/battle_anims/anim_commands.asm
+++ b/engine/battle_anims/anim_commands.asm
@@ -41,7 +41,7 @@
 	pop af
 	ldh [hVBlank], a
 
-	ld a, $1
+	ld a, 1
 	ldh [hBGMapMode], a
 
 	call BattleAnimDelayFrame
@@ -155,9 +155,10 @@
 	ld a, BANK(wCurBattleMon) ; aka BANK(wTempMon), BANK(wPartyMon1), and several others
 	ldh [rSVBK], a
 
+; this block should just be "call UpdateBattleHuds"
 	ld hl, UpdateBattleHuds
 	ld a, BANK(UpdatePlayerHUD)
-	rst FarCall ; Why not "call UpdateBattleHuds"?
+	rst FarCall
 
 	pop af
 	ldh [rSVBK], a
@@ -891,7 +892,8 @@
 	push af
 	ld a, BANK(wCurPartySpecies)
 	ldh [rSVBK], a
-	ld a, [wCurPartySpecies] ; CurPartySpecies
+
+	ld a, [wCurPartySpecies]
 	push af
 
 	ldh a, [hBattleTurn]
@@ -898,9 +900,9 @@
 	and a
 	jr z, .player
 
-	ld a, [wTempBattleMonSpecies] ; TempBattleMonSpecies
-	ld [wCurPartySpecies], a ; CurPartySpecies
-	ld hl, wBattleMonDVs ; BattleMonDVs
+	ld a, [wTempBattleMonSpecies]
+	ld [wCurPartySpecies], a
+	ld hl, wBattleMonDVs
 	predef GetUnownLetter
 	ld de, vTiles0 tile $00
 	predef GetMonFrontpic
@@ -907,9 +909,9 @@
 	jr .done
 
 .player
-	ld a, [wTempEnemyMonSpecies] ; TempEnemyMonSpecies
-	ld [wCurPartySpecies], a ; CurPartySpecies
-	ld hl, wEnemyMonDVs ; EnemyMonDVs
+	ld a, [wTempEnemyMonSpecies]
+	ld [wCurPartySpecies], a
+	ld hl, wEnemyMonDVs
 	predef GetUnownLetter
 	ld de, vTiles0 tile $00
 	predef GetMonBackpic
@@ -916,7 +918,8 @@
 
 .done
 	pop af
-	ld [wCurPartySpecies], a ; CurPartySpecies
+	ld [wCurPartySpecies], a
+
 	pop af
 	ldh [rSVBK], a
 	ret
@@ -945,11 +948,11 @@
 	push af
 	ld a, 1 ; unnecessary bankswitch?
 	ldh [rSVBK], a
-	xor a ; sScratch
+
+	xor a ; BANK(sScratch)
 	call GetSRAMBank
 
 GetSubstitutePic: ; used only for BANK(GetSubstitutePic)
-
 	ld hl, sScratch
 	ld bc, (7 * 7) tiles
 .loop
@@ -1004,6 +1007,7 @@
 
 .done
 	call CloseSRAM
+
 	pop af
 	ldh [rSVBK], a
 	ret
@@ -1019,11 +1023,13 @@
 	push af
 	ld a, 1 ; unnecessary bankswitch?
 	ldh [rSVBK], a
-	xor a ; sScratch
+
+	xor a ; BANK(sScratch)
 	call GetSRAMBank
 	call GetMinimizePic
 	call Request2bpp
 	call CloseSRAM
+
 	pop af
 	ldh [rSVBK], a
 	ret
@@ -1073,12 +1079,14 @@
 	push af
 	ld a, 1 ; unnecessary bankswitch?
 	ldh [rSVBK], a
-	xor a ; sScratch
+
+	xor a ; BANK(sScratch)
 	call GetSRAMBank
 	call GetMinimizePic
 	ld hl, vTiles0 tile $00
 	call Request2bpp
 	call CloseSRAM
+
 	pop af
 	ldh [rSVBK], a
 	ret
@@ -1089,7 +1097,7 @@
 	ld a, BANK(wCurPartySpecies)
 	ldh [rSVBK], a
 
-	ld a, [wCurPartySpecies] ; CurPartySpecies
+	ld a, [wCurPartySpecies]
 	push af
 	ldh a, [hBattleTurn]
 	and a
@@ -1103,7 +1111,8 @@
 
 .done
 	pop af
-	ld [wCurPartySpecies], a ; CurPartySpecies
+	ld [wCurPartySpecies], a
+
 	pop af
 	ldh [rSVBK], a
 	ret
@@ -1113,11 +1122,12 @@
 	push af
 	ld a, BANK(wCurPartySpecies)
 	ldh [rSVBK], a
-	ld a, [wCurPartySpecies] ; CurPartySpecies
+
+	ld a, [wCurPartySpecies]
 	push af
 
 	ld a, [wBattleAnimParam]
-	ld [wCurPartySpecies], a ; CurPartySpecies
+	ld [wCurPartySpecies], a
 
 	ldh a, [hBattleTurn]
 	and a
@@ -1137,9 +1147,10 @@
 
 .done
 	pop af
-	ld [wCurPartySpecies], a ; CurPartySpecies
+	ld [wCurPartySpecies], a
 	ld b, SCGB_BATTLE_COLORS
 	call GetSGBLayout
+
 	pop af
 	ldh [rSVBK], a
 	ret
@@ -1176,7 +1187,7 @@
 	ld [wSFXDuration], a
 	call .GetCryTrack
 	maskbits NUM_NOISE_CHANS
-	ld [wCryTracks], a ; CryTracks
+	ld [wCryTracks], a
 
 	ld e, a
 	ld d, 0
@@ -1220,7 +1231,7 @@
 
 	ldh a, [rSVBK]
 	push af
-	ld a, BANK(wEnemyMon) ; wBattleMon is in WRAM0, but EnemyMon is in WRAMX
+	ld a, BANK(wEnemyMon) ; wBattleMon is in WRAM0, but wEnemyMon is in WRAMX
 	ldh [rSVBK], a
 
 	ldh a, [hBattleTurn]
@@ -1263,7 +1274,7 @@
 	ld a, [hli]
 	ld c, a
 	ld b, [hl]
-	ld hl, wCryLength ; CryLength
+	ld hl, wCryLength
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -1270,7 +1281,7 @@
 	add hl, bc
 
 	ld a, l
-	ld [wCryLength], a ; CryLength
+	ld [wCryLength], a
 	ld a, h
 	ld [wCryLength + 1], a
 	ld a, 1
@@ -1347,7 +1358,7 @@
 	ld hl, wLYOverrides
 	ld bc, wBattleAnimEnd - wLYOverrides
 .loop
-	ld [hl], $0
+	ld [hl], 0
 	inc hl
 	dec bc
 	ld a, c
--- a/engine/battle_anims/bg_effects.asm
+++ b/engine/battle_anims/bg_effects.asm
@@ -2839,7 +2839,8 @@
 	ret
 
 BGEffect_DisplaceLYOverridesBackup:
-	; e = a; d = [hLYOverrideEnd] - [hLYOverrideStart] - a
+	; e = a
+	; d = [hLYOverrideEnd] - [hLYOverrideStart] - a
 	push af
 	ld e, a
 	ldh a, [hLYOverrideStart]
--- a/engine/events/daycare.asm
+++ b/engine/events/daycare.asm
@@ -1,9 +1,9 @@
 ; PrintDayCareText.TextTable indexes
 	const_def
 	const DAYCARETEXT_MAN_INTRO
-	const DAYCARETEXT_MAN_EGG
+	const DAYCARETEXT_MAN_ODD_EGG
 	const DAYCARETEXT_LADY_INTRO
-	const DAYCARETEXT_LADY_EGG
+	const DAYCARETEXT_LADY_ODD_EGG
 	const DAYCARETEXT_WHICH_ONE
 	const DAYCARETEXT_DEPOSIT
 	const DAYCARETEXT_CANT_BREED_EGG
--- a/engine/events/field_moves.asm
+++ b/engine/events/field_moves.asm
@@ -204,7 +204,7 @@
 	ret
 
 Cut_StartWaiting:
-	ld a, $1
+	ld a, 1
 	ldh [hBGMapMode], a
 ; Cut_WaitAnimSFX
 	ld hl, wJumptableIndex
@@ -445,8 +445,8 @@
 	sla a
 	add 8 * 8 ; gives a number in [$40, $50, $60, $70]
 	ld d, a
-	ld e, $0
-	ld a, SPRITE_ANIM_INDEX_FLY_LEAF ; fly land
+	ld e, 0
+	ld a, SPRITE_ANIM_INDEX_FLY_LEAF
 	call InitSpriteAnimStruct
 	ld hl, SPRITEANIMSTRUCT_TILE_ID
 	add hl, bc
--- a/engine/events/halloffame.asm
+++ b/engine/events/halloffame.asm
@@ -278,7 +278,7 @@
 	ldh a, [hSCX]
 	cp $70
 	ret z
-	add $4
+	add 4
 	ldh [hSCX], a
 	call DelayFrame
 	jr .backpicloop
--- a/engine/events/lucky_number.asm
+++ b/engine/events/lucky_number.asm
@@ -103,6 +103,7 @@
 	ld a, [wScriptVar]
 	and a
 	ret z ; found nothing
+
 	farcall StubbedTrainerRankings_LuckyNumberShow
 	ld a, [wTempByteValue]
 	and a
--- a/engine/events/magnet_train.asm
+++ b/engine/events/magnet_train.asm
@@ -78,6 +78,7 @@
 	ldh [hSCX], a
 	xor a
 	ldh [hBGMapMode], a
+
 	pop af
 	ldh [rSVBK], a
 	ret
@@ -127,7 +128,7 @@
 	ldh [hSCX], a
 	ldh [hSCY], a
 
-	; Load the player sprite
+	; Load the player sprite's standing frames
 	ldh a, [rSVBK]
 	push af
 	ld a, BANK(wPlayerGender)
@@ -139,7 +140,7 @@
 	ld c, 4
 	call Request2bpp
 
-	; Load the trainer walking frame
+	; Load the player sprite's walking frames
 	ld hl, 12 tiles
 	add hl, de
 	ld d, h
--- a/engine/events/overworld.asm
+++ b/engine/events/overworld.asm
@@ -349,7 +349,7 @@
 .TrySurf:
 	ld de, ENGINE_FOGBADGE
 	call CheckBadge
-	jr c, .asm_c956
+	jr c, .nofogbadge
 	ld hl, wBikeFlags
 	bit BIKEFLAGS_ALWAYS_ON_BIKE_F, [hl]
 	jr nz, .cannotsurf
@@ -368,7 +368,7 @@
 	jr c, .cannotsurf
 	ld a, $1
 	ret
-.asm_c956
+.nofogbadge
 	ld a, $80
 	ret
 .alreadyfail
@@ -407,7 +407,7 @@
 	waitbutton
 	closetext
 
-	callasm .empty_fn ; empty function
+	callasm .stubbed_fn
 
 	readmem wBuffer2
 	writevar VAR_MOVEMENT
@@ -419,7 +419,7 @@
 	applymovement PLAYER, wMovementBuffer
 	end
 
-.empty_fn
+.stubbed_fn
 	farcall StubbedTrainerRankings_Surf
 	ret
 
@@ -1369,7 +1369,7 @@
 	special WaitSFX
 	playsound SFX_STRENGTH
 	earthquake 84
-	applymovementlasttalked MovementData_0xcf55
+	applymovementlasttalked MovementData_RockSmash
 	disappear -2
 
 	callasm RockMonEncounter
@@ -1381,7 +1381,7 @@
 .done
 	end
 
-MovementData_0xcf55:
+MovementData_RockSmash:
 	rock_smash 10
 	step_end
 
@@ -1591,11 +1591,11 @@
 	loademote EMOTE_ROD
 	callasm LoadFishingGFX
 	loademote EMOTE_SHOCK
-	applymovement PLAYER, MovementData_0xd093
+	applymovement PLAYER, MovementData_CastRod
 	pause 40
 	end
 
-MovementData_0xd093:
+MovementData_CastRod:
 	fish_cast_rod
 	step_end
 
@@ -1787,10 +1787,10 @@
 	opentext
 	writetext AskCutText
 	yesorno
-	iffalse .script_d1b8
+	iffalse .declined
 	callasm .CheckMap
 	iftrue Script_Cut
-.script_d1b8
+.declined
 	closetext
 	end
 
--- a/engine/games/dummy_game.asm
+++ b/engine/games/dummy_game.asm
@@ -11,7 +11,7 @@
 	ld b, SCGB_DIPLOMA
 	call GetSGBLayout
 	callfar ClearSpriteAnims
-	ld hl, LZ_e2221
+	ld hl, DummyGameLZ
 	ld de, vTiles2 tile $00
 	call Decompress
 	ld hl, Unknown_e00ed
@@ -586,5 +586,5 @@
 	ld [hl], a
 	ret
 
-LZ_e2221:
+DummyGameLZ:
 INCBIN "gfx/dummy_game/dummy_game.2bpp.lz"