summaryrefslogtreecommitdiff
path: root/home
diff options
context:
space:
mode:
Diffstat (limited to 'home')
-rw-r--r--home/audio.asm144
-rw-r--r--home/battle.asm80
-rw-r--r--home/battle_vars.asm222
-rw-r--r--home/clear_sprites.asm23
-rw-r--r--home/copy.asm66
-rw-r--r--home/copy2.asm28
-rw-r--r--home/copy_name.asm13
-rw-r--r--home/copy_tilemap.asm35
-rw-r--r--home/cry.asm23
-rw-r--r--home/decompress.asm25
-rw-r--r--home/delay.asm7
-rw-r--r--home/double_speed.asm9
-rw-r--r--home/fade.asm24
-rw-r--r--home/farcall.asm13
-rw-r--r--home/flag.asm31
-rw-r--r--home/game_time.asm21
-rw-r--r--home/handshake.asm6
-rw-r--r--home/hm_moves.asm8
-rw-r--r--home/hp_pals.asm17
-rw-r--r--home/init.asm23
-rw-r--r--home/item.asm15
-rw-r--r--home/joypad.asm54
-rw-r--r--home/lcd.asm16
-rw-r--r--home/map.asm490
-rw-r--r--home/map_objects.asm138
-rw-r--r--home/math.asm22
-rw-r--r--home/menu.asm195
-rw-r--r--home/menu_window.asm242
-rw-r--r--home/mobile.asm42
-rw-r--r--home/mon_data.asm87
-rw-r--r--home/mon_data_2.asm34
-rw-r--r--home/mon_stats.asm104
-rw-r--r--home/movement.asm38
-rw-r--r--home/names.asm25
-rw-r--r--home/palettes.asm57
-rw-r--r--home/pokedex_flags.asm15
-rw-r--r--home/predef.asm3
-rw-r--r--home/print_bcd.asm79
-rw-r--r--home/print_level.asm28
-rw-r--r--home/print_text.asm120
-rw-r--r--home/random.asm10
-rw-r--r--home/region.asm32
-rw-r--r--home/rst.asm16
-rw-r--r--home/rtc.asm8
-rw-r--r--home/scrolling_menu.asm61
-rw-r--r--home/serial.asm39
-rw-r--r--home/sine.asm16
-rw-r--r--home/sprite_anims.asm50
-rw-r--r--home/sprite_updates.asm19
-rw-r--r--home/sram.asm9
-rw-r--r--home/stone_queue.asm138
-rw-r--r--home/string.asm8
-rw-r--r--home/text.asm361
-rw-r--r--home/tilemap.asm413
-rw-r--r--home/time.asm53
-rw-r--r--home/trainers.asm27
-rw-r--r--home/vblank.asm40
-rw-r--r--home/video.asm47
-rw-r--r--home/window.asm20
59 files changed, 2170 insertions, 1819 deletions
diff --git a/home/audio.asm b/home/audio.asm
index 2d6f27cda..dd115449d 100644
--- a/home/audio.asm
+++ b/home/audio.asm
@@ -1,7 +1,6 @@
; Audio interfaces.
-MapSetup_Sound_Off:: ; 3b4e
-
+MapSetup_Sound_Off::
push hl
push de
push bc
@@ -24,11 +23,8 @@ MapSetup_Sound_Off:: ; 3b4e
pop de
pop hl
ret
-; 3b6a
-
-
-UpdateSound:: ; 3b6a
+UpdateSound::
push hl
push de
push bc
@@ -51,13 +47,9 @@ UpdateSound:: ; 3b6a
pop de
pop hl
ret
-; 3b86
-
-_LoadMusicByte:: ; 3b86
+_LoadMusicByte::
; wCurMusicByte = [a:de]
-GLOBAL LoadMusicByte
-
ld [hROMBank], a
ld [MBC3RomBank], a
@@ -68,10 +60,8 @@ GLOBAL LoadMusicByte
ld [hROMBank], a
ld [MBC3RomBank], a
ret
-; 3b97
-
-PlayMusic:: ; 3b97
+PlayMusic::
; Play music de.
push hl
@@ -104,10 +94,8 @@ PlayMusic:: ; 3b97
pop de
pop hl
ret
-; 3bbc
-
-PlayMusic2:: ; 3bbc
+PlayMusic2::
; Stop playing music, then play music de.
push hl
@@ -138,11 +126,8 @@ PlayMusic2:: ; 3bbc
pop hl
ret
-; 3be3
-
-
-PlayCry:: ; 3be3
-; Play cry header de.
+PlayCry::
+; Play cry de.
push hl
push de
@@ -191,10 +176,8 @@ endr
pop de
pop hl
ret
-; 3c23
-
-PlaySFX:: ; 3c23
+PlaySFX::
; Play sound effect de.
; Sound effects are ordered by priority (highest to lowest)
@@ -233,54 +216,49 @@ PlaySFX:: ; 3c23
pop de
pop hl
ret
-; 3c4e
-
-WaitPlaySFX:: ; 3c4e
+WaitPlaySFX::
call WaitSFX
call PlaySFX
ret
-; 3c55
-
-WaitSFX:: ; 3c55
+WaitSFX::
; infinite loop until sfx is done playing
push hl
.wait
- ld hl, wChannel5Flags
+ ld hl, wChannel5Flags1
bit 0, [hl]
jr nz, .wait
- ld hl, wChannel6Flags
+ ld hl, wChannel6Flags1
bit 0, [hl]
jr nz, .wait
- ld hl, wChannel7Flags
+ ld hl, wChannel7Flags1
bit 0, [hl]
jr nz, .wait
- ld hl, wChannel8Flags
+ ld hl, wChannel8Flags1
bit 0, [hl]
jr nz, .wait
pop hl
ret
-; 3c74
-IsSFXPlaying:: ; 3c74
+IsSFXPlaying::
; Return carry if no sound effect is playing.
; The inverse of CheckSFX.
push hl
- ld hl, wChannel5Flags
+ ld hl, wChannel5Flags1
bit 0, [hl]
jr nz, .playing
- ld hl, wChannel6Flags
+ ld hl, wChannel6Flags1
bit 0, [hl]
jr nz, .playing
- ld hl, wChannel7Flags
+ ld hl, wChannel7Flags1
bit 0, [hl]
jr nz, .playing
- ld hl, wChannel8Flags
+ ld hl, wChannel8Flags1
bit 0, [hl]
jr nz, .playing
@@ -292,39 +270,33 @@ IsSFXPlaying:: ; 3c74
pop hl
and a
ret
-; 3c97
-MaxVolume:: ; 3c97
+MaxVolume::
ld a, MAX_VOLUME
ld [wVolume], a
ret
-; 3c9d
-LowVolume:: ; 3c9d
+LowVolume::
ld a, $33 ; 40%
ld [wVolume], a
ret
-; 3ca3
-VolumeOff:: ; 3ca3
+VolumeOff::
xor a
ld [wVolume], a
ret
-; 3ca8
-Unused_FadeOutMusic:: ; 3ca8
+Unused_FadeOutMusic::
ld a, 4
ld [wMusicFade], a
ret
-; 3cae
-FadeInMusic:: ; 3cae
+FadeInMusic::
ld a, 4 | (1 << MUSIC_FADE_IN_F)
ld [wMusicFade], a
ret
-; 3cb4
-SkipMusic:: ; 3cb4
+SkipMusic::
; Skip a frames of music.
.loop
and a
@@ -332,9 +304,8 @@ SkipMusic:: ; 3cb4
dec a
call UpdateSound
jr .loop
-; 3cbc
-FadeToMapMusic:: ; 3cbc
+FadeToMapMusic::
push hl
push de
push bc
@@ -360,9 +331,8 @@ FadeToMapMusic:: ; 3cbc
pop de
pop hl
ret
-; 3cdf
-PlayMapMusic:: ; 3cdf
+PlayMapMusic::
push hl
push de
push bc
@@ -388,9 +358,8 @@ PlayMapMusic:: ; 3cdf
pop de
pop hl
ret
-; 3d03
-EnterMapMusic:: ; 3d03
+EnterMapMusic::
push hl
push de
push bc
@@ -419,9 +388,8 @@ EnterMapMusic:: ; 3d03
pop de
pop hl
ret
-; 3d2f
-TryRestartMapMusic:: ; 3d2f
+TryRestartMapMusic::
ld a, [wDontPlayMapMusicOnReload]
and a
jr z, RestartMapMusic
@@ -433,9 +401,8 @@ TryRestartMapMusic:: ; 3d2f
xor a
ld [wDontPlayMapMusicOnReload], a
ret
-; 3d47
-RestartMapMusic:: ; 3d47
+RestartMapMusic::
push hl
push de
push bc
@@ -452,9 +419,8 @@ RestartMapMusic:: ; 3d47
pop de
pop hl
ret
-; 3d62
-SpecialMapMusic:: ; 3d62
+SpecialMapMusic::
ld a, [wPlayerState]
cp PLAYER_SURF
jr z, .surf
@@ -462,7 +428,7 @@ SpecialMapMusic:: ; 3d62
jr z, .surf
ld a, [wStatusFlags2]
- bit 2, a
+ bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, a
jr nz, .contest
.no
@@ -493,16 +459,14 @@ SpecialMapMusic:: ; 3d62
ld de, MUSIC_BUG_CATCHING_CONTEST_RANKING
scf
ret
-; 3d97
-GetMapMusic_MaybeSpecial:: ; 3d97
+GetMapMusic_MaybeSpecial::
call SpecialMapMusic
ret c
call GetMapMusic
ret
-; 3d9f
-Unreferenced_Function3d9f:: ; 3d9f
+Unreferenced_Function3d9f::
; Places a BCD number at the
; upper center of the screen.
ld a, 4 * TILE_WIDTH
@@ -536,20 +500,19 @@ Unreferenced_Function3d9f:: ; 3d9f
ld [wVirtualOAMSprite38TileID], a
ld [wVirtualOAMSprite39TileID], a
ret
-; 3dde
-CheckSFX:: ; 3dde
+CheckSFX::
; Return carry if any SFX channels are active.
- ld a, [wChannel5Flags]
+ ld a, [wChannel5Flags1]
bit 0, a
jr nz, .playing
- ld a, [wChannel6Flags]
+ ld a, [wChannel6Flags1]
bit 0, a
jr nz, .playing
- ld a, [wChannel7Flags]
+ ld a, [wChannel7Flags1]
bit 0, a
jr nz, .playing
- ld a, [wChannel8Flags]
+ ld a, [wChannel8Flags1]
bit 0, a
jr nz, .playing
and a
@@ -557,11 +520,10 @@ CheckSFX:: ; 3dde
.playing
scf
ret
-; 3dfe
-TerminateExpBarSound:: ; 3dfe
+TerminateExpBarSound::
xor a
- ld [wChannel5Flags], a
+ ld [wChannel5Flags1], a
ld [wSoundInput], a
ld [rNR10], a
ld [rNR11], a
@@ -569,27 +531,23 @@ TerminateExpBarSound:: ; 3dfe
ld [rNR13], a
ld [rNR14], a
ret
-; 3e10
-
-ChannelsOff:: ; 3e10
+ChannelsOff::
; Quickly turn off music channels
xor a
- ld [wChannel1Flags], a
- ld [wChannel2Flags], a
- ld [wChannel3Flags], a
- ld [wChannel4Flags], a
+ ld [wChannel1Flags1], a
+ ld [wChannel2Flags1], a
+ ld [wChannel3Flags1], a
+ ld [wChannel4Flags1], a
ld [wSoundInput], a
ret
-; 3e21
-SFXChannelsOff:: ; 3e21
+SFXChannelsOff::
; Quickly turn off sound effect channels
xor a
- ld [wChannel5Flags], a
- ld [wChannel6Flags], a
- ld [wChannel7Flags], a
- ld [wChannel8Flags], a
+ ld [wChannel5Flags1], a
+ ld [wChannel6Flags1], a
+ ld [wChannel7Flags1], a
+ ld [wChannel8Flags1], a
ld [wSoundInput], a
ret
-; 3e32
diff --git a/home/battle.asm b/home/battle.asm
index e59b1e3b4..e88adef02 100644
--- a/home/battle.asm
+++ b/home/battle.asm
@@ -1,4 +1,4 @@
-UserPartyAttr:: ; 3945
+UserPartyAttr::
push af
ld a, [hBattleTurn]
and a
@@ -8,10 +8,8 @@ UserPartyAttr:: ; 3945
.ot
pop af
jr OTPartyAttr
-; 3951
-
-OpponentPartyAttr:: ; 3951
+OpponentPartyAttr::
push af
ld a, [hBattleTurn]
and a
@@ -21,10 +19,8 @@ OpponentPartyAttr:: ; 3951
.ot
pop af
jr OTPartyAttr
-; 395d
-
-BattlePartyAttr:: ; 395d
+BattlePartyAttr::
; Get attribute a from the party struct of the active battle mon.
push bc
ld c, a
@@ -35,10 +31,8 @@ BattlePartyAttr:: ; 395d
call GetPartyLocation
pop bc
ret
-; 396d
-
-OTPartyAttr:: ; 396d
+OTPartyAttr::
; Get attribute a from the party struct of the active enemy mon.
push bc
ld c, a
@@ -49,49 +43,41 @@ OTPartyAttr:: ; 396d
call GetPartyLocation
pop bc
ret
-; 397d
-
-ResetDamage:: ; 397d
+ResetDamage::
xor a
ld [wCurDamage], a
ld [wCurDamage + 1], a
ret
-; 3985
-SetPlayerTurn:: ; 3985
+SetPlayerTurn::
xor a
ld [hBattleTurn], a
ret
-; 3989
-SetEnemyTurn:: ; 3989
+SetEnemyTurn::
ld a, 1
ld [hBattleTurn], a
ret
-; 398e
-
-UpdateOpponentInParty:: ; 398e
+UpdateOpponentInParty::
ld a, [hBattleTurn]
and a
jr z, UpdateEnemyMonInParty
jr UpdateBattleMonInParty
-; 3995
-UpdateUserInParty:: ; 3995
+UpdateUserInParty::
ld a, [hBattleTurn]
and a
jr z, UpdateBattleMonInParty
jr UpdateEnemyMonInParty
-; 399c
-UpdateBattleMonInParty:: ; 399c
+UpdateBattleMonInParty::
; Update level, status, current HP
ld a, [wCurBattleMon]
-UpdateBattleMon:: ; 399f
+UpdateBattleMon::
ld hl, wPartyMon1Level
call GetPartyLocation
@@ -100,9 +86,8 @@ UpdateBattleMon:: ; 399f
ld hl, wBattleMonLevel
ld bc, wBattleMonMaxHP - wBattleMonLevel
jp CopyBytes
-; 39b0
-UpdateEnemyMonInParty:: ; 39b0
+UpdateEnemyMonInParty::
; Update level, status, current HP
; No wildmons.
@@ -119,27 +104,21 @@ UpdateEnemyMonInParty:: ; 39b0
ld hl, wEnemyMonLevel
ld bc, wEnemyMonMaxHP - wEnemyMonLevel
jp CopyBytes
-; 39c9
-
-RefreshBattleHuds:: ; 39c9
+RefreshBattleHuds::
call UpdateBattleHuds
ld c, 3
call DelayFrames
jp WaitBGMap
-; 39d4
-UpdateBattleHuds:: ; 39d4
+UpdateBattleHuds::
farcall UpdatePlayerHUD
farcall UpdateEnemyHUD
ret
-; 39e1
-
INCLUDE "home/battle_vars.asm"
-
-FarCopyRadioText:: ; 3a90
+FarCopyRadioText::
inc hl
ld a, [hROMBank]
push af
@@ -161,14 +140,8 @@ FarCopyRadioText:: ; 3a90
ld [hROMBank], a
ld [MBC3RomBank], a
ret
-; 3ab2
-
-
-MobileTextBorder:: ; 3ab2
-
-CELL_PHONE_TOP EQU $5e
-CELL_PHONE_BOTTOM EQU $5f
+MobileTextBorder::
; For mobile link battles only.
ld a, [wLinkMode]
cp LINK_MOBILE
@@ -177,14 +150,12 @@ CELL_PHONE_BOTTOM EQU $5f
; Draw a cell phone icon at the
; top right corner of the border.
hlcoord 19, 12
- ld [hl], CELL_PHONE_TOP
+ ld [hl], $5e ; top
hlcoord 19, 13
- ld [hl], CELL_PHONE_BOTTOM
+ ld [hl], $5f ; bottom
ret
-; 3ac3
-
-BattleTextBox:: ; 3ac3
+BattleTextBox::
; Open a textbox and print text at hl.
push hl
call SpeechTextBox
@@ -194,10 +165,8 @@ BattleTextBox:: ; 3ac3
pop hl
call PrintTextBoxText
ret
-; 3ad5
-
-StdBattleTextBox:: ; 3ad5
+StdBattleTextBox::
; Open a textbox and print battle text at 20:hl.
ld a, [hROMBank]
@@ -211,10 +180,8 @@ StdBattleTextBox:: ; 3ad5
pop af
rst Bankswitch
ret
-; 3ae1
-
-GetBattleAnimPointer:: ; 3ae1
+GetBattleAnimPointer::
ld a, BANK(BattleAnimations)
rst Bankswitch
@@ -227,10 +194,8 @@ GetBattleAnimPointer:: ; 3ae1
rst Bankswitch
ret
-; 3af0
-
-GetBattleAnimByte:: ; 3af0
+GetBattleAnimByte::
push hl
push de
@@ -258,4 +223,3 @@ GetBattleAnimByte:: ; 3af0
ld a, [wBattleAnimByte]
ret
-; 3b0c
diff --git a/home/battle_vars.asm b/home/battle_vars.asm
index 44fc21d6d..a455fce20 100644
--- a/home/battle_vars.asm
+++ b/home/battle_vars.asm
@@ -1,111 +1,111 @@
-GetBattleVar:: ; 39e1
-; Preserves hl.
- push hl
- call GetBattleVarAddr
- pop hl
- ret
-; 39e7
-
-GetBattleVarAddr:: ; 39e7
-; Get variable from pair a, depending on whose turn it is.
-; There are 21 variable pairs.
-
- push bc
-
- ld hl, .BattleVarPairs
- ld c, a
- ld b, 0
- add hl, bc
- add hl, bc
-
- ld a, [hli]
- ld h, [hl]
- ld l, a
-
-; Enemy turn uses the second byte instead.
-; This lets battle variable calls be side-neutral.
- ld a, [hBattleTurn]
- and a
- jr z, .get_var
- inc hl
-
-.get_var
-; var id
- ld a, [hl]
- ld c, a
- ld b, 0
-
- ld hl, .BattleVarPointers
- add hl, bc
- add hl, bc
-
- ld a, [hli]
- ld h, [hl]
- ld l, a
-
- ld a, [hl]
-
- pop bc
- ret
-
-.BattleVarPairs:
- dw .Substatus1
- dw .Substatus2
- dw .Substatus3
- dw .Substatus4
- dw .Substatus5
- dw .Substatus1Opp
- dw .Substatus2Opp
- dw .Substatus3Opp
- dw .Substatus4Opp
- dw .Substatus5Opp
- dw .Status
- dw .StatusOpp
- dw .MoveAnim
- dw .MoveEffect
- dw .MovePower
- dw .MoveType
- dw .CurMove
- dw .LastCounter
- dw .LastCounterOpp
- dw .LastMove
- dw .LastMoveOpp
-
-; player enemy
-.Substatus1: db PLAYER_SUBSTATUS_1, ENEMY_SUBSTATUS_1
-.Substatus1Opp: db ENEMY_SUBSTATUS_1, PLAYER_SUBSTATUS_1
-.Substatus2: db PLAYER_SUBSTATUS_2, ENEMY_SUBSTATUS_2
-.Substatus2Opp: db ENEMY_SUBSTATUS_2, PLAYER_SUBSTATUS_2
-.Substatus3: db PLAYER_SUBSTATUS_3, ENEMY_SUBSTATUS_3
-.Substatus3Opp: db ENEMY_SUBSTATUS_3, PLAYER_SUBSTATUS_3
-.Substatus4: db PLAYER_SUBSTATUS_4, ENEMY_SUBSTATUS_4
-.Substatus4Opp: db ENEMY_SUBSTATUS_4, PLAYER_SUBSTATUS_4
-.Substatus5: db PLAYER_SUBSTATUS_5, ENEMY_SUBSTATUS_5
-.Substatus5Opp: db ENEMY_SUBSTATUS_5, PLAYER_SUBSTATUS_5
-.Status: db PLAYER_STATUS, ENEMY_STATUS
-.StatusOpp: db ENEMY_STATUS, PLAYER_STATUS
-.MoveAnim: db PLAYER_MOVE_ANIMATION, ENEMY_MOVE_ANIMATION
-.MoveEffect: db PLAYER_MOVE_EFFECT, ENEMY_MOVE_EFFECT
-.MovePower: db PLAYER_MOVE_POWER, ENEMY_MOVE_POWER
-.MoveType: db PLAYER_MOVE_TYPE, ENEMY_MOVE_TYPE
-.CurMove: db PLAYER_CUR_MOVE, ENEMY_CUR_MOVE
-.LastCounter: db PLAYER_COUNTER_MOVE, ENEMY_COUNTER_MOVE
-.LastCounterOpp: db ENEMY_COUNTER_MOVE, PLAYER_COUNTER_MOVE
-.LastMove: db PLAYER_LAST_MOVE, ENEMY_LAST_MOVE
-.LastMoveOpp: db ENEMY_LAST_MOVE, PLAYER_LAST_MOVE
-
-.BattleVarPointers:
- dw wPlayerSubStatus1, wEnemySubStatus1
- dw wPlayerSubStatus2, wEnemySubStatus2
- dw wPlayerSubStatus3, wEnemySubStatus3
- dw wPlayerSubStatus4, wEnemySubStatus4
- dw wPlayerSubStatus5, wEnemySubStatus5
- dw wBattleMonStatus, wEnemyMonStatus
- dw wPlayerMoveStructAnimation, wEnemyMoveStructAnimation
- dw wPlayerMoveStructEffect, wEnemyMoveStructEffect
- dw wPlayerMoveStructPower, wEnemyMoveStructPower
- dw wPlayerMoveStructType, wEnemyMoveStructType
- dw wCurPlayerMove, wCurEnemyMove
- dw wLastPlayerCounterMove, wLastEnemyCounterMove
- dw wLastPlayerMove, wLastEnemyMove
-; 3a90
+GetBattleVar::
+; Preserves hl.
+ push hl
+ call GetBattleVarAddr
+ pop hl
+ ret
+
+GetBattleVarAddr::
+; Get variable from pair a, depending on whose turn it is.
+; There are 21 variable pairs.
+
+ push bc
+
+ ld hl, BattleVarPairs
+ ld c, a
+ ld b, 0
+ add hl, bc
+ add hl, bc
+
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+
+; Enemy turn uses the second byte instead.
+; This lets battle variable calls be side-neutral.
+ ld a, [hBattleTurn]
+ and a
+ jr z, .getvar
+ inc hl
+
+.getvar
+; var id
+ ld a, [hl]
+ ld c, a
+ ld b, 0
+
+ ld hl, BattleVarLocations
+ add hl, bc
+ add hl, bc
+
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+
+ ld a, [hl]
+
+ pop bc
+ ret
+
+BattleVarPairs:
+; entries correspond to BATTLE_VARS_* constants
+ dw .Substatus1
+ dw .Substatus2
+ dw .Substatus3
+ dw .Substatus4
+ dw .Substatus5
+ dw .Substatus1Opp
+ dw .Substatus2Opp
+ dw .Substatus3Opp
+ dw .Substatus4Opp
+ dw .Substatus5Opp
+ dw .Status
+ dw .StatusOpp
+ dw .MoveAnim
+ dw .MoveEffect
+ dw .MovePower
+ dw .MoveType
+ dw .CurMove
+ dw .LastCounter
+ dw .LastCounterOpp
+ dw .LastMove
+ dw .LastMoveOpp
+
+; player enemy
+.Substatus1: db PLAYER_SUBSTATUS_1, ENEMY_SUBSTATUS_1
+.Substatus1Opp: db ENEMY_SUBSTATUS_1, PLAYER_SUBSTATUS_1
+.Substatus2: db PLAYER_SUBSTATUS_2, ENEMY_SUBSTATUS_2
+.Substatus2Opp: db ENEMY_SUBSTATUS_2, PLAYER_SUBSTATUS_2
+.Substatus3: db PLAYER_SUBSTATUS_3, ENEMY_SUBSTATUS_3
+.Substatus3Opp: db ENEMY_SUBSTATUS_3, PLAYER_SUBSTATUS_3
+.Substatus4: db PLAYER_SUBSTATUS_4, ENEMY_SUBSTATUS_4
+.Substatus4Opp: db ENEMY_SUBSTATUS_4, PLAYER_SUBSTATUS_4
+.Substatus5: db PLAYER_SUBSTATUS_5, ENEMY_SUBSTATUS_5
+.Substatus5Opp: db ENEMY_SUBSTATUS_5, PLAYER_SUBSTATUS_5
+.Status: db PLAYER_STATUS, ENEMY_STATUS
+.StatusOpp: db ENEMY_STATUS, PLAYER_STATUS
+.MoveAnim: db PLAYER_MOVE_ANIMATION, ENEMY_MOVE_ANIMATION
+.MoveEffect: db PLAYER_MOVE_EFFECT, ENEMY_MOVE_EFFECT
+.MovePower: db PLAYER_MOVE_POWER, ENEMY_MOVE_POWER
+.MoveType: db PLAYER_MOVE_TYPE, ENEMY_MOVE_TYPE
+.CurMove: db PLAYER_CUR_MOVE, ENEMY_CUR_MOVE
+.LastCounter: db PLAYER_COUNTER_MOVE, ENEMY_COUNTER_MOVE
+.LastCounterOpp: db ENEMY_COUNTER_MOVE, PLAYER_COUNTER_MOVE
+.LastMove: db PLAYER_LAST_MOVE, ENEMY_LAST_MOVE
+.LastMoveOpp: db ENEMY_LAST_MOVE, PLAYER_LAST_MOVE
+
+BattleVarLocations:
+; entries correspond to PLAYER_* and ENEMY_* constants
+ dw wPlayerSubStatus1, wEnemySubStatus1
+ dw wPlayerSubStatus2, wEnemySubStatus2
+ dw wPlayerSubStatus3, wEnemySubStatus3
+ dw wPlayerSubStatus4, wEnemySubStatus4
+ dw wPlayerSubStatus5, wEnemySubStatus5
+ dw wBattleMonStatus, wEnemyMonStatus
+ dw wPlayerMoveStructAnimation, wEnemyMoveStructAnimation
+ dw wPlayerMoveStructEffect, wEnemyMoveStructEffect
+ dw wPlayerMoveStructPower, wEnemyMoveStructPower
+ dw wPlayerMoveStructType, wEnemyMoveStructType
+ dw wCurPlayerMove, wCurEnemyMove
+ dw wLastPlayerCounterMove, wLastEnemyCounterMove
+ dw wLastPlayerMove, wLastEnemyMove
diff --git a/home/clear_sprites.asm b/home/clear_sprites.asm
new file mode 100644
index 000000000..699774612
--- /dev/null
+++ b/home/clear_sprites.asm
@@ -0,0 +1,23 @@
+ClearSprites::
+; Erase OAM data
+ ld hl, wVirtualOAM
+ ld b, wVirtualOAMEnd - wVirtualOAM
+ xor a
+.loop
+ ld [hli], a
+ dec b
+ jr nz, .loop
+ ret
+
+HideSprites::
+; Set all OAM y-positions to 160 to hide them offscreen
+ ld hl, wVirtualOAMSprite00YCoord
+ ld de, SPRITEOAMSTRUCT_LENGTH
+ ld b, NUM_SPRITE_OAM_STRUCTS
+ ld a, SCREEN_WIDTH_PX
+.loop
+ ld [hl], a ; y
+ add hl, de
+ dec b
+ jr nz, .loop
+ ret
diff --git a/home/copy.asm b/home/copy.asm
index 9bd79ce37..68ed240e3 100644
--- a/home/copy.asm
+++ b/home/copy.asm
@@ -1,7 +1,6 @@
; Functions to copy data from ROM.
-
-Get2bpp_2:: ; dc9
+Get2bpp_2::
ld a, [rLCDC]
bit rLCDC_ENABLE, a
jp z, Copy2bpp
@@ -9,9 +8,8 @@ Get2bpp_2:: ; dc9
homecall _Get2bpp
ret
-; ddc
-Get1bpp_2:: ; ddc
+Get1bpp_2::
ld a, [rLCDC]
bit rLCDC_ENABLE, a
jp z, Copy1bpp
@@ -19,9 +17,8 @@ Get1bpp_2:: ; ddc
homecall _Get1bpp
ret
-; def
-FarCopyBytesDouble_DoubleBankSwitch:: ; def
+FarCopyBytesDouble_DoubleBankSwitch::
ld [hBuffer], a
ld a, [hROMBank]
push af
@@ -33,9 +30,8 @@ FarCopyBytesDouble_DoubleBankSwitch:: ; def
pop af
rst Bankswitch
ret
-; dfd
-OldDMATransfer:: ; dfd
+OldDMATransfer::
dec c
ld a, [hBGMapMode]
push af
@@ -96,41 +92,29 @@ OldDMATransfer:: ; dfd
pop af
ld [hBGMapMode], a
ret
-; e4a
-
-
-ReplaceKrisSprite:: ; e4a
+ReplaceKrisSprite::
farcall _ReplaceKrisSprite
ret
-; e51
-
-
-LoadStandardFont:: ; e51
+LoadStandardFont::
farcall _LoadStandardFont
ret
-; e58
-LoadFontsBattleExtra:: ; e58
+LoadFontsBattleExtra::
farcall _LoadFontsBattleExtra
ret
-; e5f
-
-
-LoadFontsExtra:: ; e5f
+LoadFontsExtra::
farcall _LoadFontsExtra1
farcall _LoadFontsExtra2
ret
-; e6c
-LoadFontsExtra2:: ; e6c
+LoadFontsExtra2::
farcall _LoadFontsExtra2
ret
-; e73
-DecompressRequest2bpp:: ; e73
+DecompressRequest2bpp::
push de
ld a, BANK(sScratch)
call GetSRAMBank
@@ -147,11 +131,8 @@ DecompressRequest2bpp:: ; e73
call Request2bpp
call CloseSRAM
ret
-; e8d
-
-
-FarCopyBytes:: ; e8d
+FarCopyBytes::
; copy bc bytes from a:hl to de
ld [hBuffer], a
@@ -165,10 +146,8 @@ FarCopyBytes:: ; e8d
pop af
rst Bankswitch
ret
-; 0xe9b
-
-FarCopyBytesDouble:: ; e9b
+FarCopyBytesDouble::
; Copy bc bytes from a:hl to bc*2 bytes at de,
; doubling each byte in the process.
@@ -204,10 +183,8 @@ FarCopyBytesDouble:: ; e9b
pop af
rst Bankswitch
ret
-; 0xeba
-
-Request2bpp:: ; eba
+Request2bpp::
; Load 2bpp at b:de to occupy c tiles of hl.
ld a, [hBGMapMode]
push af
@@ -280,10 +257,8 @@ Request2bpp:: ; eba
sub [hl]
ld c, a
jr .loop
-; f1e
-
-Request1bpp:: ; f1e
+Request1bpp::
; Load 1bpp at b:de to occupy c tiles of hl.
ld a, [hBGMapMode]
push af
@@ -356,15 +331,13 @@ Request1bpp:: ; f1e
sub [hl]
ld c, a
jr .loop
-; f82
-
-Get2bpp:: ; f82
+Get2bpp::
ld a, [rLCDC]
bit rLCDC_ENABLE, a
jp nz, Request2bpp
-Copy2bpp:: ; f89
+Copy2bpp::
; copy c 2bpp tiles from b:de to hl
push hl
@@ -387,15 +360,13 @@ Copy2bpp:: ; f89
pop af
jp FarCopyBytes
-; f9d
-
-Get1bpp:: ; f9d
+Get1bpp::
ld a, [rLCDC]
bit rLCDC_ENABLE, a
jp nz, Request1bpp
-Copy1bpp:: ; fa4
+Copy1bpp::
; copy c 1bpp tiles from b:de to hl
push de
@@ -418,4 +389,3 @@ Copy1bpp:: ; fa4
pop hl
jp FarCopyBytesDouble
-; fb6
diff --git a/home/copy2.asm b/home/copy2.asm
index 23e1eca7f..fdf55b2e3 100644
--- a/home/copy2.asm
+++ b/home/copy2.asm
@@ -1,7 +1,7 @@
-CopyBytes:: ; 0x3026
+CopyBytes::
; copy bc bytes from hl to de
- inc b ; we bail the moment b hits 0, so include the last run
- inc c ; same thing; include last byte
+ inc b ; we bail the moment b hits 0, so include the last run
+ inc c ; same thing; include last byte
jr .HandleLoop
.CopyByte:
ld a, [hli]
@@ -14,7 +14,7 @@ CopyBytes:: ; 0x3026
jr nz, .CopyByte
ret
-SwapBytes:: ; 0x3034
+SwapBytes::
; swap bc bytes between hl and de
.Loop:
; stash [hl] away on the stack
@@ -37,10 +37,10 @@ SwapBytes:: ; 0x3034
jr nz, .Loop
ret
-ByteFill:: ; 0x3041
+ByteFill::
; fill bc bytes with the value of a, starting at hl
- inc b ; we bail the moment b hits 0, so include the last run
- inc c ; same thing; include last byte
+ inc b ; we bail the moment b hits 0, so include the last run
+ inc c ; same thing; include last byte
jr .HandleLoop
.PutByte:
ld [hli], a
@@ -51,7 +51,7 @@ ByteFill:: ; 0x3041
jr nz, .PutByte
ret
-GetFarByte:: ; 0x304d
+GetFarByte::
; retrieve a single byte from a:hl, and return it in a.
; bankswitch to new bank
ld [hBuffer], a
@@ -72,7 +72,7 @@ GetFarByte:: ; 0x304d
ld a, [hBuffer]
ret
-GetFarHalfword:: ; 0x305d
+GetFarHalfword::
; retrieve a halfword from a:hl, and return it in hl.
; bankswitch to new bank
ld [hBuffer], a
@@ -90,9 +90,8 @@ GetFarHalfword:: ; 0x305d
pop af
rst Bankswitch
ret
-; 0x306b
-FarCopyWRAM:: ; 306b
+FarCopyWRAM::
ld [hBuffer], a
ld a, [rSVBK]
push af
@@ -104,9 +103,8 @@ FarCopyWRAM:: ; 306b
pop af
ld [rSVBK], a
ret
-; 307b
-GetFarWRAMByte:: ; 307b
+GetFarWRAMByte::
ld [hBuffer], a
ld a, [rSVBK]
push af
@@ -118,9 +116,8 @@ GetFarWRAMByte:: ; 307b
ld [rSVBK], a
ld a, [hBuffer]
ret
-; 308d
-GetFarWRAMWord:: ; 308d
+GetFarWRAMWord::
ld [hBuffer], a
ld a, [rSVBK]
push af
@@ -132,4 +129,3 @@ GetFarWRAMWord:: ; 308d
pop af
ld [rSVBK], a
ret
-; 309d
diff --git a/home/copy_name.asm b/home/copy_name.asm
new file mode 100644
index 000000000..59c8cf6c8
--- /dev/null
+++ b/home/copy_name.asm
@@ -0,0 +1,13 @@
+CopyName1::
+; Copies the name from de to wStringBuffer2
+ ld hl, wStringBuffer2
+
+CopyName2::
+; Copies the name from de to hl
+.loop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ cp "@"
+ jr nz, .loop
+ ret
diff --git a/home/copy_tilemap.asm b/home/copy_tilemap.asm
new file mode 100644
index 000000000..2c6c47244
--- /dev/null
+++ b/home/copy_tilemap.asm
@@ -0,0 +1,35 @@
+LoadTileMapToTempTileMap::
+; Load wTileMap into wTempTileMap
+ ld a, [rSVBK]
+ push af
+ ld a, BANK(wTempTileMap)
+ ld [rSVBK], a
+ hlcoord 0, 0
+ decoord 0, 0, wTempTileMap
+ ld bc, wTileMapEnd - wTileMap
+ call CopyBytes
+ pop af
+ ld [rSVBK], a
+ ret
+
+Call_LoadTempTileMapToTileMap::
+ xor a
+ ld [hBGMapMode], a
+ call LoadTempTileMapToTileMap
+ ld a, 1
+ ld [hBGMapMode], a
+ ret
+
+LoadTempTileMapToTileMap::
+; Load wTempTileMap into wTileMap
+ ld a, [rSVBK]
+ push af
+ ld a, BANK(wTempTileMap)
+ ld [rSVBK], a
+ hlcoord 0, 0, wTempTileMap
+ decoord 0, 0
+ ld bc, wTileMapEnd - wTileMap
+ call CopyBytes
+ pop af
+ ld [rSVBK], a
+ ret
diff --git a/home/cry.asm b/home/cry.asm
index 93983a6ae..43f20b1af 100644
--- a/home/cry.asm
+++ b/home/cry.asm
@@ -1,4 +1,4 @@
-PlayStereoCry:: ; 37b6
+PlayStereoCry::
push af
ld a, 1
ld [wStereoPanningMask], a
@@ -6,9 +6,8 @@ PlayStereoCry:: ; 37b6
call _PlayMonCry
call WaitSFX
ret
-; 37c4
-PlayStereoCry2:: ; 37c4
+PlayStereoCry2::
; Don't wait for the cry to end.
; Used during pic animations.
push af
@@ -16,15 +15,13 @@ PlayStereoCry2:: ; 37c4
ld [wStereoPanningMask], a
pop af
jp _PlayMonCry
-; 37ce
-PlayMonCry:: ; 37ce
+PlayMonCry::
call PlayMonCry2
call WaitSFX
ret
-; 37d5
-PlayMonCry2:: ; 37d5
+PlayMonCry2::
; Don't wait for the cry to end.
push af
xor a
@@ -33,9 +30,8 @@ PlayMonCry2:: ; 37d5
pop af
call _PlayMonCry
ret
-; 37e2
-_PlayMonCry:: ; 37e2
+_PlayMonCry::
push hl
push de
push bc
@@ -52,10 +48,9 @@ _PlayMonCry:: ; 37e2
pop de
pop hl
ret
-; 37f3
-LoadCry:: ; 37f3
-; Load cry header bc.
+LoadCry::
+; Load cry bc.
call GetCryIndex
ret c
@@ -88,9 +83,8 @@ endr
rst Bankswitch
and a
ret
-; 381e
-GetCryIndex:: ; 381e
+GetCryIndex::
and a
jr z, .no
cp NUM_POKEMON + 1
@@ -105,4 +99,3 @@ GetCryIndex:: ; 381e
.no
scf
ret
-; 382d
diff --git a/home/decompress.asm b/home/decompress.asm
index 216b861f6..d4bab7a6a 100644
--- a/home/decompress.asm
+++ b/home/decompress.asm
@@ -1,4 +1,4 @@
-FarDecompress:: ; b40
+FarDecompress::
; Decompress graphics data from a:hl to de.
ld [wLZBank], a
@@ -12,19 +12,15 @@ FarDecompress:: ; b40
pop af
rst Bankswitch
ret
-; b50
-
-Decompress:: ; b50
+Decompress::
; Pokemon Crystal uses an lz variant for compression.
; This is mainly (but not necessarily) used for graphics.
; This function decompresses lz-compressed data from hl to de.
-
LZ_END EQU $ff ; Compressed data is terminated with $ff.
-
; A typical control command consists of:
LZ_CMD EQU %11100000 ; command id (bits 5-7)
@@ -32,7 +28,6 @@ LZ_LEN EQU %00011111 ; length n (bits 0-4)
; Additional parameters are read during command execution.
-
; Commands:
LZ_LITERAL EQU 0 << 5 ; Read literal data for n bytes.
@@ -40,7 +35,6 @@ LZ_ITERATE EQU 1 << 5 ; Write the same byte for n bytes.
LZ_ALTERNATE EQU 2 << 5 ; Alternate two bytes for n bytes.
LZ_ZERO EQU 3 << 5 ; Write 0 for n bytes.
-
; Another class of commands reuses data from the decompressed output.
LZ_RW EQU 2 + 5 ; bit
@@ -53,7 +47,6 @@ LZ_REPEAT EQU 4 << 5 ; Repeat n bytes from the offset.
LZ_FLIP EQU 5 << 5 ; Repeat n bitflipped bytes.
LZ_REVERSE EQU 6 << 5 ; Repeat n bytes in reverse.
-
; If the value in the count needs to be larger than 5 bits,
; LZ_LONG can be used to expand the count to 10 bits.
LZ_LONG EQU 7 << 5
@@ -68,10 +61,8 @@ LZ_LONG_HI EQU %00000011
; x: the new control command
; y: the length
-
; For more information, refer to the code below and in extras/gfx.py.
-
; Save the output address
; for rewrite commands.
ld a, e
@@ -113,7 +104,6 @@ LZ_LONG_HI EQU %00000011
inc bc
jr .command
-
.short
push af
@@ -125,7 +115,6 @@ LZ_LONG_HI EQU %00000011
; read at least 1 byte
inc c
-
.command
; Increment loop counts.
; We bail the moment they hit 0.
@@ -144,7 +133,6 @@ LZ_LONG_HI EQU %00000011
cp LZ_ZERO
jr z, .Zero
-
.Literal:
; Read literal data for bc bytes.
.lloop
@@ -159,7 +147,6 @@ LZ_LONG_HI EQU %00000011
inc de
jr .lloop
-
.Iter:
; Write the same byte for bc bytes.
ld a, [hli]
@@ -175,7 +162,6 @@ LZ_LONG_HI EQU %00000011
inc de
jr .iloop
-
.Alt:
; Alternate two bytes for bc bytes.
dec c
@@ -205,7 +191,6 @@ LZ_LONG_HI EQU %00000011
inc hl
jr .Main
-
.Zero:
; Write 0 for bc bytes.
xor a
@@ -221,7 +206,6 @@ LZ_LONG_HI EQU %00000011
inc de
jr .zloop
-
.rewrite
; Repeat decompressed data from output.
push hl
@@ -275,7 +259,6 @@ LZ_LONG_HI EQU %00000011
; More practically, LZ_LONG is not recursive.
; For now, it defaults to LZ_REPEAT.
-
.Repeat:
; Copy decompressed data for bc bytes.
dec c
@@ -289,7 +272,6 @@ LZ_LONG_HI EQU %00000011
inc de
jr .Repeat
-
.Flip:
; Copy bitflipped decompressed data for bc bytes.
dec c
@@ -315,7 +297,6 @@ LZ_LONG_HI EQU %00000011
inc de
jr .Flip
-
.Reverse:
; Copy reversed decompressed data for bc bytes.
dec c
@@ -330,7 +311,6 @@ LZ_LONG_HI EQU %00000011
inc de
jr .Reverse
-
.donerw
pop hl
@@ -340,4 +320,3 @@ LZ_LONG_HI EQU %00000011
.next
inc hl
jp .Main
-; c2f
diff --git a/home/delay.asm b/home/delay.asm
index 300f65c88..4ad25ef21 100644
--- a/home/delay.asm
+++ b/home/delay.asm
@@ -1,4 +1,4 @@
-DelayFrame:: ; 45a
+DelayFrame::
; Wait for one frame
ld a, 1
ld [wVBlankOccurred], a
@@ -10,13 +10,10 @@ DelayFrame:: ; 45a
and a
jr nz, .halt
ret
-; 468
-
-DelayFrames:: ; 468
+DelayFrames::
; Wait c frames
call DelayFrame
dec c
jr nz, DelayFrames
ret
-; 46f
diff --git a/home/double_speed.asm b/home/double_speed.asm
index c07dc9cee..de075e65e 100644
--- a/home/double_speed.asm
+++ b/home/double_speed.asm
@@ -5,20 +5,18 @@
; and double speed at any time, but LCD output
; collapses during the switch.
-DoubleSpeed:: ; 2fef
+DoubleSpeed::
ld hl, rKEY1
bit 7, [hl]
jr z, SwitchSpeed
ret
-; 2ff7
-NormalSpeed:: ; 2ff7
+NormalSpeed::
ld hl, rKEY1
bit 7, [hl]
ret z
-; 2ffd
-SwitchSpeed:: ; 2ffd
+SwitchSpeed::
set 0, [hl]
xor a
ld [rIF], a
@@ -27,4 +25,3 @@ SwitchSpeed:: ; 2ffd
ld [rJOYP], a
stop ; rgbasm adds a nop after this instruction by default
ret
-; 300b
diff --git a/home/fade.asm b/home/fade.asm
index 1a6f87c63..56f0197e6 100644
--- a/home/fade.asm
+++ b/home/fade.asm
@@ -1,7 +1,6 @@
; Functions to fade the screen in and out.
-
-Unreferenced_Function48c:: ; 48c
+Unreferenced_Function48c::
; TimeOfDayFade
ld a, [wTimeOfDayPal]
ld b, a
@@ -20,10 +19,8 @@ Unreferenced_Function48c:: ; 48c
ld a, [hli]
ld [rOBP1], a
ret
-; 4a3
-
-RotateFourPalettesRight:: ; 4a3
+RotateFourPalettesRight::
ld a, [hCGB]
and a
jr z, .dmg
@@ -35,9 +32,8 @@ RotateFourPalettesRight:: ; 4a3
ld hl, IncGradGBPalTable_08
ld b, 4
jr RotatePalettesRight
-; 4b6
-RotateThreePalettesRight:: ; 4b6
+RotateThreePalettesRight::
ld a, [hCGB]
and a
jr z, .dmg
@@ -48,7 +44,7 @@ RotateThreePalettesRight:: ; 4b6
.dmg
ld hl, IncGradGBPalTable_13
ld b, 3
-RotatePalettesRight:: ; 4c7
+RotatePalettesRight::
; Rotate palettes to the right and fill with loaded colors from the left
; If we're already at the leftmost color, fill with the leftmost color
push de
@@ -65,9 +61,8 @@ RotatePalettesRight:: ; 4c7
dec b
jr nz, RotatePalettesRight
ret
-; 4dd
-RotateFourPalettesLeft:: ; 4dd
+RotateFourPalettesLeft::
ld a, [hCGB]
and a
jr z, .dmg
@@ -79,9 +74,8 @@ RotateFourPalettesLeft:: ; 4dd
ld hl, IncGradGBPalTable_12 - 1
ld b, 4
jr RotatePalettesLeft
-; 4f0
-RotateThreePalettesLeft:: ; 4f0
+RotateThreePalettesLeft::
ld a, [hCGB]
and a
jr z, .dmg
@@ -92,7 +86,7 @@ RotateThreePalettesLeft:: ; 4f0
.dmg
ld hl, IncGradGBPalTable_15 - 1
ld b, 3
-RotatePalettesLeft:: ; 501
+RotatePalettesLeft::
; Rotate palettes to the left and fill with loaded colors from the right
; If we're already at the rightmost color, fill with the rightmost color
push de
@@ -109,10 +103,7 @@ RotatePalettesLeft:: ; 501
dec b
jr nz, RotatePalettesLeft
ret
-; 517
-
-; 517
IncGradGBPalTable_00:: db %11111111, %11111111, %11111111
IncGradGBPalTable_01:: db %11111110, %11111110, %11111110
IncGradGBPalTable_02:: db %11111001, %11111001, %11111001
@@ -134,4 +125,3 @@ IncGradGBPalTable_13:: db %10010000, %10000000, %10010000
IncGradGBPalTable_14:: db %01000000, %01000000, %01000000
IncGradGBPalTable_15:: db %00000000, %00000000, %00000000
-; 547
diff --git a/home/farcall.asm b/home/farcall.asm
index 27649f30e..cb87b1774 100644
--- a/home/farcall.asm
+++ b/home/farcall.asm
@@ -1,4 +1,4 @@
-FarCall_de:: ; 2d54
+FarCall_de::
; Call a:de.
; Preserves other registers.
@@ -13,10 +13,8 @@ FarCall_de:: ; 2d54
.de
push de
ret
-; 2d63
-
-FarCall_hl:: ; 2d63
+FarCall_hl::
; Call a:hl.
; Preserves other registers.
@@ -26,9 +24,8 @@ FarCall_hl:: ; 2d63
ld a, [hBuffer]
rst Bankswitch
call FarJump_hl
-; 2d6e
-ReturnFarCall:: ; 2d6e
+ReturnFarCall::
; We want to retain the contents of f.
; To do this, we can pop to bc instead of af.
@@ -47,8 +44,6 @@ ReturnFarCall:: ; 2d6e
ld a, [wFarCallBCBuffer + 1]
ld c, a
ret
-; 2d82
-FarJump_hl:: ; 2d82
+FarJump_hl::
jp hl
-; 2d83
diff --git a/home/flag.asm b/home/flag.asm
index 0b1390c99..411f04184 100644
--- a/home/flag.asm
+++ b/home/flag.asm
@@ -1,39 +1,35 @@
-ResetMapBufferEventFlags:: ; 2e50
+ResetMapBufferEventFlags::
xor a
ld hl, wEventFlags
ld [hli], a
ret
-; 2e56
-ResetBikeFlags:: ; 2e56
+ResetBikeFlags::
xor a
ld hl, wBikeFlags
ld [hli], a
ld [hl], a
ret
-; 2e5d
-ResetFlashIfOutOfCave:: ; 2e5d
+ResetFlashIfOutOfCave::
ld a, [wEnvironment]
- cp $2
- jr z, .asm_2e69
- cp $1
- jr z, .asm_2e69
+ cp ROUTE
+ jr z, .outdoors
+ cp TOWN
+ jr z, .outdoors
ret
-.asm_2e69
+.outdoors
ld hl, wStatusFlags
- res 2, [hl]
+ res STATUSFLAGS_FLASH_F, [hl]
ret
-; 2e6f
-
-EventFlagAction:: ; 0x2e6f
+EventFlagAction::
ld hl, wEventFlags
call FlagAction
ret
-FlagAction:: ; 0x2e76
+FlagAction::
; Perform action b on bit de in flag array hl.
; inputs:
@@ -99,14 +95,11 @@ FlagAction:: ; 0x2e76
and [hl]
ld [hl], a
ret
-; 0x2ead
-
-CheckReceivedDex:: ; 2ead
+CheckReceivedDex::
ld de, ENGINE_POKEDEX
ld b, CHECK_FLAG
farcall EngineFlagAction
ld a, c
and a
ret
-; 2ebb
diff --git a/home/game_time.asm b/home/game_time.asm
index feaa09608..0300db73d 100644
--- a/home/game_time.asm
+++ b/home/game_time.asm
@@ -1,4 +1,4 @@
-ResetGameTime:: ; 208a
+ResetGameTime::
xor a
ld [wGameTimeCap], a
ld [wGameTimeHours], a
@@ -7,11 +7,8 @@ ResetGameTime:: ; 208a
ld [wGameTimeSeconds], a
ld [wGameTimeFrames], a
ret
-; 209e
-
-
-GameTimer:: ; 209e
+GameTimer::
nop
ld a, [rSVBK]
@@ -24,14 +21,11 @@ GameTimer:: ; 209e
pop af
ld [rSVBK], a
ret
-; 20ad
-
-UpdateGameTimer:: ; 20ad
+UpdateGameTimer::
; Increment the game timer by one frame.
; The game timer is capped at 999:59:59.00.
-
; Don't update if game logic is paused.
ld a, [wGameLogicPaused]
and a
@@ -39,7 +33,7 @@ UpdateGameTimer:: ; 20ad
; Is the timer paused?
ld hl, wGameTimerPause
- bit 0, [hl]
+ bit GAMETIMERPAUSE_TIMER_PAUSED_F, [hl]
ret z
; Is the timer already capped?
@@ -47,7 +41,6 @@ UpdateGameTimer:: ; 20ad
bit 0, [hl]
ret nz
-
; +1 frame
ld hl, wGameTimeFrames
ld a, [hl]
@@ -59,7 +52,6 @@ UpdateGameTimer:: ; 20ad
ld [hl], a
ret
-
.second
xor a
ld [hl], a
@@ -75,7 +67,6 @@ UpdateGameTimer:: ; 20ad
ld [hl], a
ret
-
.minute
xor a
ld [hl], a
@@ -91,7 +82,6 @@ UpdateGameTimer:: ; 20ad
ld [hl], a
ret
-
.hour
xor a
ld [hl], a
@@ -103,7 +93,6 @@ UpdateGameTimer:: ; 20ad
ld l, a
inc hl
-
; Cap the timer after 1000 hours.
ld a, h
cp HIGH(1000)
@@ -121,11 +110,9 @@ UpdateGameTimer:: ; 20ad
ld [wGameTimeSeconds], a
ret
-
.ok
ld a, h
ld [wGameTimeHours], a
ld a, l
ld [wGameTimeHours + 1], a
ret
-; 210f
diff --git a/home/handshake.asm b/home/handshake.asm
index 14daf08a7..1d3f43d6a 100644
--- a/home/handshake.asm
+++ b/home/handshake.asm
@@ -1,10 +1,9 @@
-PrinterReceive:: ; 2057
+PrinterReceive::
homecall _PrinterReceive
ret
-; 2063
-AskSerial:: ; 2063
+AskSerial::
; send out a handshake while serial int is off
ld a, [wPrinterConnectionOpen]
bit 0, a
@@ -41,4 +40,3 @@ AskSerial:: ; 2063
ld [rSC], a
ret
-; 208a
diff --git a/home/hm_moves.asm b/home/hm_moves.asm
index c4233d094..30a9786a9 100644
--- a/home/hm_moves.asm
+++ b/home/hm_moves.asm
@@ -1,6 +1,6 @@
; HM moves can't be forgotten
-IsHM:: ; 34df
+IsHM::
cp HM01
jr c, .NotHM
scf
@@ -8,14 +8,13 @@ IsHM:: ; 34df
.NotHM:
and a
ret
-; 34e7
-IsHMMove:: ; 34e7
+IsHMMove::
ld hl, .HMMoves
ld de, 1
jp IsInArray
-.HMMoves: ; 34f0
+.HMMoves:
db CUT
db FLY
db SURF
@@ -24,4 +23,3 @@ IsHMMove:: ; 34e7
db WATERFALL
db WHIRLPOOL
db -1 ; end
-; 34f8
diff --git a/home/hp_pals.asm b/home/hp_pals.asm
new file mode 100644
index 000000000..9400d341f
--- /dev/null
+++ b/home/hp_pals.asm
@@ -0,0 +1,17 @@
+SetHPPal::
+; Set palette for hp bar pixel length e at hl.
+ call GetHPPal
+ ld [hl], d
+ ret
+
+GetHPPal::
+; Get palette for hp bar pixel length e in d.
+ ld d, HP_GREEN
+ ld a, e
+ cp (HP_BAR_LENGTH_PX * 50 / 100) ; 24
+ ret nc
+ inc d ; HP_YELLOW
+ cp (HP_BAR_LENGTH_PX * 21 / 100) ; 10
+ ret nc
+ inc d ; HP_RED
+ ret
diff --git a/home/init.asm b/home/init.asm
index ec541ad16..dc1f538be 100644
--- a/home/init.asm
+++ b/home/init.asm
@@ -1,4 +1,4 @@
-Reset:: ; 150
+Reset::
di
call MapSetup_Sound_Off
xor a
@@ -17,10 +17,8 @@ Reset:: ; 150
call DelayFrames
jr Init
-; 16e
-
-_Start:: ; 16e
+_Start::
cp $11
jr z, .cgb
xor a
@@ -33,11 +31,8 @@ _Start:: ; 16e
ld [hCGB], a
ld a, $1
ld [hSystemBooted], a
-; 17d
-
-
-Init:: ; 17d
+Init::
di
xor a
@@ -102,7 +97,6 @@ Init:: ; 17d
call ClearSprites
call ClearsScratch
-
ld a, BANK(WriteOAMDMACodeToHRAM)
rst Bankswitch
@@ -172,10 +166,8 @@ Init:: ; 17d
xor a
ld [wMapMusic], a
jp GameInit
-; 245
-
-ClearVRAM:: ; 245
+ClearVRAM::
; Wipe VRAM banks 0 and 1
ld a, 1
@@ -190,9 +182,8 @@ ClearVRAM:: ; 245
xor a
call ByteFill
ret
-; 25a
-ClearWRAM:: ; 25a
+ClearWRAM::
; Wipe swappable WRAM banks (1-7)
; Assumes CGB or AGB
@@ -209,9 +200,8 @@ ClearWRAM:: ; 25a
cp 8
jr nc, .bank_loop ; Should be jr c
ret
-; 270
-ClearsScratch:: ; 270
+ClearsScratch::
; Wipe the first 32 bytes of sScratch
ld a, BANK(sScratch)
@@ -222,4 +212,3 @@ ClearsScratch:: ; 270
call ByteFill
call CloseSRAM
ret
-; 283
diff --git a/home/item.asm b/home/item.asm
index 2f550a200..282157e55 100644
--- a/home/item.asm
+++ b/home/item.asm
@@ -1,9 +1,8 @@
-DoItemEffect:: ; 2f3f
+DoItemEffect::
farcall _DoItemEffect
ret
-; 2f46
-CheckTossableItem:: ; 2f46
+CheckTossableItem::
push hl
push de
push bc
@@ -12,9 +11,8 @@ CheckTossableItem:: ; 2f46
pop de
pop hl
ret
-; 2f53
-TossItem:: ; 2f53
+TossItem::
push hl
push de
push bc
@@ -32,9 +30,8 @@ TossItem:: ; 2f53
pop de
pop hl
ret
-; 2f66
-ReceiveItem:: ; 2f66
+ReceiveItem::
push bc
ld a, [hROMBank]
push af
@@ -52,9 +49,8 @@ ReceiveItem:: ; 2f66
rst Bankswitch
pop bc
ret
-; 2f79
-CheckItem:: ; 2f79
+CheckItem::
push hl
push de
push bc
@@ -72,4 +68,3 @@ CheckItem:: ; 2f79
pop de
pop hl
ret
-; 2f8c
diff --git a/home/joypad.asm b/home/joypad.asm
index f46ab5c98..87fc60d7e 100644
--- a/home/joypad.asm
+++ b/home/joypad.asm
@@ -1,21 +1,19 @@
-JoypadInt:: ; 92e
+JoypadInt::
; Replaced by Joypad, called from VBlank instead of the useless
; joypad interrupt.
; This is a placeholder in case the interrupt is somehow enabled.
reti
-; 92f
-ClearJoypad:: ; 92f
+ClearJoypad::
xor a
; Pressed this frame (delta)
ld [hJoyPressed], a
; Currently pressed
ld [hJoyDown], a
ret
-; 935
-Joypad:: ; 935
+Joypad::
; Read the joypad register and translate it to something more
; workable for use in-game. There are 8 buttons, so we can use
; one byte to contain all player input.
@@ -103,10 +101,8 @@ endr
jp z, Reset
ret
-; 984
-
-GetJoypad:: ; 984
+GetJoypad::
; Update mirror joypad input from hJoypadDown (real input)
; hJoyReleased: released this frame (delta)
@@ -193,7 +189,6 @@ GetJoypad:: ; 984
rst Bankswitch
jr .quit
-
.updateauto
; An input of $ff will end the stream.
ld a, [hli]
@@ -232,10 +227,8 @@ GetJoypad:: ; 984
ld [hJoyPressed], a ; pressed
ld [hJoyDown], a ; input
jr .quit
-; 9ee
-
-StartAutoInput:: ; 9ee
+StartAutoInput::
; Start reading automated input stream at a:hl.
ld [wAutoInputBank], a
@@ -255,10 +248,8 @@ StartAutoInput:: ; 9ee
ld a, AUTO_INPUT
ld [wInputType], a
ret
-; a0a
-
-StopAutoInput:: ; a0a
+StopAutoInput::
; Clear variables related to automated input.
xor a
ld [wAutoInputBank], a
@@ -268,10 +259,8 @@ StopAutoInput:: ; a0a
; Back to normal input.
ld [wInputType], a
ret
-; a1b
-
-JoyTitleScreenInput:: ; a1b
+JoyTitleScreenInput::
.loop
call DelayFrame
@@ -297,10 +286,8 @@ JoyTitleScreenInput:: ; a1b
.keycombo
scf
ret
-; a36
-
-JoyWaitAorB:: ; a36
+JoyWaitAorB::
.loop
call DelayFrame
call GetJoypad
@@ -309,9 +296,8 @@ JoyWaitAorB:: ; a36
ret nz
call RTC
jr .loop
-; a46
-WaitButton:: ; a46
+WaitButton::
ld a, [hOAMUpdate]
push af
ld a, 1
@@ -321,9 +307,8 @@ WaitButton:: ; a46
pop af
ld [hOAMUpdate], a
ret
-; a57
-JoyTextDelay:: ; a57
+JoyTextDelay::
call GetJoypad
ld a, [hInMenu]
and a
@@ -351,9 +336,8 @@ JoyTextDelay:: ; a57
ld a, 5
ld [wTextDelayFrames], a
ret
-; a80
-WaitPressAorB_BlinkCursor:: ; a80
+WaitPressAorB_BlinkCursor::
ld a, [hMapObjectIndexBuffer]
push af
ld a, [hObjectStructIndexBuffer]
@@ -379,18 +363,16 @@ WaitPressAorB_BlinkCursor:: ; a80
pop af
ld [hMapObjectIndexBuffer], a
ret
-; aa5
-SimpleWaitPressAorB:: ; aa5
+SimpleWaitPressAorB::
.loop
call JoyTextDelay
ld a, [hJoyLast]
and A_BUTTON | B_BUTTON
jr z, .loop
ret
-; aaf
-ButtonSound:: ; aaf
+ButtonSound::
ld a, [wLinkMode]
and a
jr nz, .link
@@ -404,9 +386,8 @@ ButtonSound:: ; aaf
.link
ld c, 65
jp DelayFrames
-; ac6
-.wait_input ; ac6
+.wait_input
ld a, [hOAMUpdate]
push af
ld a, $1
@@ -432,9 +413,8 @@ ButtonSound:: ; aaf
pop af
ld [hOAMUpdate], a
ret
-; af5
-.blink_cursor ; af5
+.blink_cursor
ld a, [hVBlankCounter]
and %00010000 ; bit 4, a
jr z, .cursor_off
@@ -447,9 +427,8 @@ ButtonSound:: ; aaf
.load_cursor_state
ldcoord_a 18, 17
ret
-; b06
-BlinkCursor:: ; b06
+BlinkCursor::
push bc
ld a, [hl]
ld b, a
@@ -491,4 +470,3 @@ BlinkCursor:: ; b06
ld a, "▼"
ld [hl], a
ret
-; b40
diff --git a/home/lcd.asm b/home/lcd.asm
index 3899f0816..7ea53d453 100644
--- a/home/lcd.asm
+++ b/home/lcd.asm
@@ -1,7 +1,6 @@
; LCD handling
-
-Unreferenced_Function547:: ; 547
+Unreferenced_Function547::
ld a, [hLCDCPointer]
cp rSCX - $ff00
ret nz
@@ -9,10 +8,8 @@ Unreferenced_Function547:: ; 547
ld a, [wLYOverrides]
ld [$ff00+c], a
ret
-; 552
-
-LCD:: ; 552
+LCD::
push af
ld a, [hLCDCPointer]
and a
@@ -34,10 +31,8 @@ LCD:: ; 552
.done
pop af
reti
-; 568
-
-DisableLCD:: ; 568
+DisableLCD::
; Turn the LCD off
; Don't need to do anything if the LCD is already off
@@ -69,12 +64,9 @@ DisableLCD:: ; 568
ld a, b
ld [rIE], a
ret
-; 58a
-
-EnableLCD:: ; 58a
+EnableLCD::
ld a, [rLCDC]
set rLCDC_ENABLE, a
ld [rLCDC], a
ret
-; 591
diff --git a/home/map.asm b/home/map.asm
index 252b68cbe..a38b791fb 100644
--- a/home/map.asm
+++ b/home/map.asm
@@ -1,14 +1,13 @@
; Functions dealing with rendering and interacting with maps.
-Clearwc7e8:: ; 210f
+Clearwc7e8::
ld hl, wc7e8
ld bc, wc7e8_End - wc7e8
ld a, 0
call ByteFill
ret
-; 211b
-CheckScenes:: ; 211b
+CheckScenes::
; Checks wCurrMapSceneScriptPointer. If it's empty, returns -1 in a. Otherwise, returns the active scene ID in a.
push hl
ld hl, wCurrMapSceneScriptPointer
@@ -23,9 +22,8 @@ CheckScenes:: ; 211b
.scene_exists
pop hl
ret
-; 212a
-GetCurrentMapSceneID:: ; 212a
+GetCurrentMapSceneID::
; Grabs the wram map scene script pointer for the current map and loads it into wCurrMapSceneScriptPointer.
; If there is no scene, both bytes of wCurrMapSceneScriptPointer are wiped clean.
; Copy the current map group and number into bc. This is needed for GetMapSceneID.
@@ -46,9 +44,8 @@ GetCurrentMapSceneID:: ; 212a
ld [wCurrMapSceneScriptPointer + 1], a
xor a
ret
-; 2147
-GetMapSceneID:: ; 2147
+GetMapSceneID::
; Searches the scene script table for the map group and number loaded in bc, and returns the wram pointer in de.
; If the map is not in the scene script table, returns carry.
push bc
@@ -93,15 +90,13 @@ GetMapSceneID:: ; 2147
pop bc
ret
-; 2173
-OverworldTextModeSwitch:: ; 2173
+OverworldTextModeSwitch::
call LoadMapPart
call FarCallSwapTextboxPalettes
ret
-; 217a
-LoadMapPart:: ; 217a
+LoadMapPart::
ld a, [hROMBank]
push af
@@ -109,7 +104,7 @@ LoadMapPart:: ; 217a
rst Bankswitch
call LoadMetatiles
- ld a, $60
+ ld a, "■"
hlcoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call ByteFill
@@ -121,21 +116,20 @@ LoadMapPart:: ; 217a
pop af
rst Bankswitch
ret
-; 2198
-LoadMetatiles:: ; 2198
+LoadMetatiles::
; de <- wOverworldMapAnchor
ld a, [wOverworldMapAnchor]
ld e, a
ld a, [wOverworldMapAnchor + 1]
ld d, a
- ld hl, wMisc
- ld b, WMISC_HEIGHT / 4 ; 5
+ ld hl, wSurroundingTiles
+ ld b, SURROUNDING_HEIGHT / METATILE_WIDTH ; 5
.row
push de
push hl
- ld c, WMISC_WIDTH / 4 ; 6
+ ld c, SURROUNDING_WIDTH / METATILE_WIDTH ; 6
.col
push de
@@ -148,7 +142,7 @@ LoadMetatiles:: ; 2198
ld a, [wMapBorderBlock]
.ok
- ; Load the current wMisc address into de.
+ ; Load the current wSurroundingTiles address into de.
ld e, l
ld d, h
; Set hl to the address of the current metatile data ([wTilesetBlocksAddress] + (a) tiles).
@@ -169,27 +163,27 @@ LoadMetatiles:: ; 2198
ld h, a
; copy the 4x4 metatile
-rept 3
-rept 4
+rept METATILE_WIDTH + -1
+rept METATILE_WIDTH
ld a, [hli]
ld [de], a
inc de
endr
ld a, e
- add WMISC_WIDTH - 4
+ add SURROUNDING_WIDTH - METATILE_WIDTH
ld e, a
jr nc, .next\@
inc d
.next\@
endr
-rept 4
+rept METATILE_WIDTH
ld a, [hli]
ld [de], a
inc de
endr
; Next metatile
pop hl
- ld de, 4
+ ld de, METATILE_WIDTH
add hl, de
pop de
inc de
@@ -197,7 +191,7 @@ endr
jp nz, .col
; Next metarow
pop hl
- ld de, WMISC_WIDTH * 4
+ ld de, SURROUNDING_WIDTH * METATILE_WIDTH
add hl, de
pop de
ld a, [wMapWidth]
@@ -210,18 +204,16 @@ endr
dec b
jp nz, .row
ret
-; 222a
-ReturnToMapFromSubmenu:: ; 222a
+ReturnToMapFromSubmenu::
ld a, MAPSETUP_SUBMENU
ld [hMapEntryMethod], a
farcall RunMapSetupScript
xor a
ld [hMapEntryMethod], a
ret
-; 2238
-CheckWarpTile:: ; 2238
+CheckWarpTile::
call GetDestinationWarpNumber
ret nc
@@ -233,16 +225,14 @@ CheckWarpTile:: ; 2238
call CopyWarpData
scf
ret
-; 224a
-WarpCheck:: ; 224a
+WarpCheck::
call GetDestinationWarpNumber
ret nc
call CopyWarpData
ret
-; 2252
-GetDestinationWarpNumber:: ; 2252
+GetDestinationWarpNumber::
farcall CheckWarpCollision
ret nc
@@ -256,14 +246,13 @@ GetDestinationWarpNumber:: ; 2252
ld a, d
rst Bankswitch
ret
-; 2266
-.GetDestinationWarpNumber: ; 2266
+.GetDestinationWarpNumber:
ld a, [wPlayerStandingMapY]
- sub $4
+ sub 4
ld e, a
ld a, [wPlayerStandingMapX]
- sub $4
+ sub 4
ld d, a
ld a, [wCurrMapWarpCount]
and a
@@ -315,9 +304,8 @@ GetDestinationWarpNumber:: ; 2252
inc hl
scf
ret
-; 22a7
-CopyWarpData:: ; 22a7
+CopyWarpData::
ld a, [hROMBank]
push af
@@ -328,9 +316,8 @@ CopyWarpData:: ; 22a7
rst Bankswitch
scf
ret
-; 22b4
-.CopyWarpData: ; 22b4
+.CopyWarpData:
push bc
ld hl, wCurrMapWarpsPointer
ld a, [hli]
@@ -364,16 +351,14 @@ CopyWarpData:: ; 22a7
ld [wPrevMapNumber], a
scf
ret
-; 22ee
-CheckOutdoorMap:: ; 22ee
+CheckOutdoorMap::
cp ROUTE
ret z
cp TOWN
ret
-; 22f4
-CheckIndoorMap:: ; 22f4
+CheckIndoorMap::
cp INDOOR
ret z
cp CAVE
@@ -382,7 +367,6 @@ CheckIndoorMap:: ; 22f4
ret z
cp GATE
ret
-; 2300
; unused
cp INDOOR
@@ -391,36 +375,32 @@ CheckIndoorMap:: ; 22f4
ret z
cp ENVIRONMENT_5
ret
-; 2309
-LoadMapAttributes:: ; 2309
- call CopyMapDefAndData
+LoadMapAttributes::
+ call CopyMapPartialAndAttributes
call SwitchToMapScriptsBank
call ReadMapScripts
xor a ; do not skip object_events
call ReadMapEvents
ret
-; 2317
-LoadMapAttributes_SkipPeople:: ; 2317
- call CopyMapDefAndData
+LoadMapAttributes_SkipPeople::
+ call CopyMapPartialAndAttributes
call SwitchToMapScriptsBank
call ReadMapScripts
ld a, TRUE ; skip object events
call ReadMapEvents
ret
-; 2326
-CopyMapDefAndData:: ; 2326
- call PartialCopyMapDef
- call SwitchToMapDataBank
- call GetMapDataPointer
- call CopyMapData
+CopyMapPartialAndAttributes::
+ call CopyMapPartial
+ call SwitchToMapAttributesBank
+ call GetMapAttributesPointer
+ call CopyMapAttributes
call GetMapConnections
ret
-; 2336
-ReadMapEvents:: ; 2336
+ReadMapEvents::
push af
ld hl, wMapEventsPointer
ld a, [hli]
@@ -438,9 +418,8 @@ ReadMapEvents:: ; 2336
call ReadObjectEvents
ret
-; 234f
-ReadMapScripts:: ; 234f
+ReadMapScripts::
ld hl, wMapScriptsPointer
ld a, [hli]
ld h, [hl]
@@ -448,11 +427,10 @@ ReadMapScripts:: ; 234f
call ReadMapSceneScripts
call ReadMapCallbacks
ret
-; 235c
-CopyMapData:: ; 235c
- ld de, wMapData
- ld c, wMapDataEnd - wMapData
+CopyMapAttributes::
+ ld de, wMapAttributes
+ ld c, wMapAttributesEnd - wMapAttributes
.loop
ld a, [hli]
ld [de], a
@@ -460,9 +438,8 @@ CopyMapData:: ; 235c
dec c
jr nz, .loop
ret
-; 2368
-GetMapConnections:: ; 2368
+GetMapConnections::
ld a, $ff
ld [wNorthConnectedMapGroup], a
ld [wSouthConnectedMapGroup], a
@@ -497,9 +474,8 @@ GetMapConnections:: ; 2368
.no_east
ret
-; 23a3
-GetMapConnection:: ; 23a3
+GetMapConnection::
; Load map connection struct at hl into de.
ld c, wSouthMapConnection - wNorthMapConnection
.loop
@@ -509,9 +485,8 @@ GetMapConnection:: ; 23a3
dec c
jr nz, .loop
ret
-; 23ac
-ReadMapSceneScripts:: ; 23ac
+ReadMapSceneScripts::
ld a, [hli] ; scene script count
ld c, a
ld [wCurrMapSceneScriptCount], a ; current map scene script count
@@ -526,9 +501,8 @@ ReadMapSceneScripts:: ; 23ac
ld bc, 4 ; scene_script size
call AddNTimes
ret
-; 23c3
-ReadMapCallbacks:: ; 23c3
+ReadMapCallbacks::
ld a, [hli]
ld c, a
ld [wCurrMapCallbackCount], a
@@ -543,9 +517,8 @@ ReadMapCallbacks:: ; 23c3
ld bc, 3
call AddNTimes
ret
-; 23da
-ReadWarps:: ; 23da
+ReadWarps::
ld a, [hli]
ld c, a
ld [wCurrMapWarpCount], a
@@ -559,9 +532,8 @@ ReadWarps:: ; 23da
ld bc, 5
call AddNTimes
ret
-; 23f1
-ReadCoordEvents:: ; 23f1
+ReadCoordEvents::
ld a, [hli]
ld c, a
ld [wCurrMapCoordEventCount], a
@@ -577,9 +549,8 @@ ReadCoordEvents:: ; 23f1
ld bc, 8
call AddNTimes
ret
-; 2408
-ReadBGEvents:: ; 2408
+ReadBGEvents::
ld a, [hli]
ld c, a
ld [wCurrMapBGEventCount], a
@@ -595,9 +566,8 @@ ReadBGEvents:: ; 2408
ld bc, 5
call AddNTimes
ret
-; 241f
-ReadObjectEvents:: ; 241f
+ReadObjectEvents::
push hl
call ClearObjectStructs
pop de
@@ -641,9 +611,8 @@ ReadObjectEvents:: ; 241f
ld h, d
ld l, e
ret
-; 2457
-CopyMapObjectEvents:: ; 2457
+CopyMapObjectEvents::
and a
ret z
@@ -668,9 +637,8 @@ CopyMapObjectEvents:: ; 2457
dec c
jr nz, .loop
ret
-; 2471
-ClearObjectStructs:: ; 2471
+ClearObjectStructs::
ld hl, wObject1Struct
ld bc, OBJECT_STRUCT_LENGTH * (NUM_OBJECT_STRUCTS - 1)
xor a
@@ -687,9 +655,8 @@ ClearObjectStructs:: ; 2471
dec c
jr nz, .loop
ret
-; 248a
-RestoreFacingAfterWarp:: ; 248a
+RestoreFacingAfterWarp::
call GetMapScriptsBank
rst Bankswitch
@@ -719,7 +686,6 @@ RestoreFacingAfterWarp:: ; 248a
.skip
farcall GetCoordOfUpperLeftCorner
ret
-; 24ba
.backup
ld a, [wPrevWarp]
@@ -729,11 +695,10 @@ RestoreFacingAfterWarp:: ; 248a
ld a, [wPrevMapNumber]
ld [wBackupMapNumber], a
ret
-; 24cd
-LoadBlockData:: ; 24cd
- ld hl, wOverworldMap
- ld bc, wOverworldMapEnd - wOverworldMap
+LoadBlockData::
+ ld hl, wOverworldMapBlocks
+ ld bc, wOverworldMapBlocksEnd - wOverworldMapBlocks
ld a, 0
call ByteFill
call ChangeMap
@@ -741,13 +706,12 @@ LoadBlockData:: ; 24cd
ld a, MAPCALLBACK_TILES
call RunMapCallback
ret
-; 24e4
-ChangeMap:: ; 24e4
+ChangeMap::
ld a, [hROMBank]
push af
- ld hl, wOverworldMap
+ ld hl, wOverworldMapBlocks
ld a, [wMapWidth]
ld [hConnectedMapWidth], a
add $6
@@ -791,10 +755,8 @@ ChangeMap:: ; 24e4
pop af
rst Bankswitch
ret
-; 2524
-
-FillMapConnections:: ; 2524
+FillMapConnections::
; North
ld a, [wNorthConnectedMapGroup]
cp $ff
@@ -889,11 +851,9 @@ FillMapConnections:: ; 2524
.Done:
ret
-; 25d3
FillNorthConnectionStrip::
-FillSouthConnectionStrip:: ; 25d3
-
+FillSouthConnectionStrip::
ld c, 3
.y
push de
@@ -925,11 +885,9 @@ FillSouthConnectionStrip:: ; 25d3
dec c
jr nz, .y
ret
-; 25f6
FillWestConnectionStrip::
-FillEastConnectionStrip:: ; 25f6
-
+FillEastConnectionStrip::
.loop
ld a, [wMapWidth]
add 6
@@ -964,14 +922,12 @@ FillEastConnectionStrip:: ; 25f6
dec b
jr nz, .loop
ret
-; 261b
-LoadMapStatus:: ; 261b
+LoadMapStatus::
ld [wMapStatus], a
ret
-; 261f
-CallScript:: ; 261f
+CallScript::
; Call a script at a:hl.
ld [wScriptBank], a
@@ -985,18 +941,16 @@ CallScript:: ; 261f
scf
ret
-; 2631
-CallMapScript:: ; 2631
+CallMapScript::
; Call a script at hl in the current bank if there isn't already a script running
ld a, [wScriptRunning]
and a
ret nz
call GetMapScriptsBank
jr CallScript
-; 263b
-RunMapCallback:: ; 263b
+RunMapCallback::
; Will run the first callback found with execution index equal to a.
ld b, a
ld a, [hROMBank]
@@ -1015,9 +969,8 @@ RunMapCallback:: ; 263b
pop af
rst Bankswitch
ret
-; 2653
-.FindCallback: ; 2653
+.FindCallback:
ld a, [wCurrMapCallbackCount]
ld c, a
and a
@@ -1046,9 +999,8 @@ RunMapCallback:: ; 263b
ld l, a
scf
ret
-; 2674
-ExecuteCallbackScript:: ; 2674
+ExecuteCallbackScript::
; Do map callback de and return to script bank b.
farcall CallCallback
ld a, [wScriptMode]
@@ -1064,9 +1016,8 @@ ExecuteCallbackScript:: ; 2674
pop af
ld [wScriptMode], a
ret
-; 269a
-MapTextbox:: ; 269a
+MapTextbox::
ld a, [hROMBank]
push af
@@ -1087,9 +1038,8 @@ MapTextbox:: ; 269a
pop af
rst Bankswitch
ret
-; 26b7
-Call_a_de:: ; 26b7
+Call_a_de::
; Call a:de.
ld [hBuffer], a
@@ -1107,9 +1057,8 @@ Call_a_de:: ; 26b7
.de
push de
ret
-; 26c7
-GetMovementData:: ; 26c7
+GetMovementData::
; Initialize the movement data for object c at b:hl
ld a, [hROMBank]
push af
@@ -1123,9 +1072,8 @@ GetMovementData:: ; 26c7
ld a, h
rst Bankswitch
ret
-; 26d4
-GetScriptByte:: ; 0x26d4
+GetScriptByte::
; Return byte at wScriptBank:wScriptPos in a.
push hl
@@ -1154,36 +1102,29 @@ GetScriptByte:: ; 0x26d4
pop bc
pop hl
ret
-; 0x26ef
-ObjectEvent:: ; 0x26ef
+ObjectEvent::
jumptextfaceplayer ObjectEventText
-; 0x26f2
ObjectEventText::
text_jump _ObjectEventText
db "@"
-; 0x26f7
-BGEvent:: ; 26f7
+BGEvent::
jumptext BGEventText
-; 26fa
-BGEventText:: ; 26fa
+BGEventText::
text_jump UnknownText_0x1c46fc
db "@"
-; 26ff
-CoordinatesEvent:: ; 26ff
+CoordinatesEvent::
jumptext CoordinatesEventText
-; 2702
-CoordinatesEventText:: ; 2702
+CoordinatesEventText::
text_jump UnknownText_0x1c4706
db "@"
-; 2707
-CheckObjectMask:: ; 2707
+CheckObjectMask::
ld a, [hMapObjectIndexBuffer]
ld e, a
ld d, $0
@@ -1191,9 +1132,8 @@ CheckObjectMask:: ; 2707
add hl, de
ld a, [hl]
ret
-; 2712
-MaskObject:: ; 2712
+MaskObject::
ld a, [hMapObjectIndexBuffer]
ld e, a
ld d, $0
@@ -1201,9 +1141,8 @@ MaskObject:: ; 2712
add hl, de
ld [hl], -1 ; , masked
ret
-; 271e
-UnmaskObject:: ; 271e
+UnmaskObject::
ld a, [hMapObjectIndexBuffer]
ld e, a
ld d, $0
@@ -1211,9 +1150,8 @@ UnmaskObject:: ; 271e
add hl, de
ld [hl], 0 ; unmasked
ret
-; 272a
-ScrollMapDown:: ; 272a
+ScrollMapDown::
hlcoord 0, 0
ld de, wBGMapBuffer
call BackupBGMapRow
@@ -1227,9 +1165,8 @@ ScrollMapDown:: ; 272a
ld a, $1
ld [hBGMapUpdate], a
ret
-; 2748
-ScrollMapUp:: ; 2748
+ScrollMapUp::
hlcoord 0, SCREEN_HEIGHT - 2
ld de, wBGMapBuffer
call BackupBGMapRow
@@ -1239,7 +1176,7 @@ ScrollMapUp:: ; 2748
ld l, a
ld a, [wBGMapAnchor + 1]
ld h, a
- ld bc, $0200
+ ld bc, BG_MAP_WIDTH tiles
add hl, bc
; cap d at HIGH(vBGMap0)
ld a, h
@@ -1251,9 +1188,8 @@ ScrollMapUp:: ; 2748
ld a, $1
ld [hBGMapUpdate], a
ret
-; 2771
-ScrollMapRight:: ; 2771
+ScrollMapRight::
hlcoord 0, 0
ld de, wBGMapBuffer
call BackupBGMapColumn
@@ -1267,9 +1203,8 @@ ScrollMapRight:: ; 2771
ld a, $1
ld [hBGMapUpdate], a
ret
-; 278f
-ScrollMapLeft:: ; 278f
+ScrollMapLeft::
hlcoord SCREEN_WIDTH - 2, 0
ld de, wBGMapBuffer
call BackupBGMapColumn
@@ -1290,9 +1225,8 @@ ScrollMapLeft:: ; 278f
ld a, $1
ld [hBGMapUpdate], a
ret
-; 27b7
-BackupBGMapRow:: ; 27b7
+BackupBGMapRow::
ld c, 2 * SCREEN_WIDTH
.loop
ld a, [hli]
@@ -1301,9 +1235,8 @@ BackupBGMapRow:: ; 27b7
dec c
jr nz, .loop
ret
-; 27c0
-BackupBGMapColumn:: ; 27c0
+BackupBGMapColumn::
ld c, SCREEN_HEIGHT
.loop
ld a, [hli]
@@ -1322,9 +1255,8 @@ BackupBGMapColumn:: ; 27c0
dec c
jr nz, .loop
ret
-; 27d3
-UpdateBGMapRow:: ; 27d3
+UpdateBGMapRow::
ld hl, wBGMapBufferPtrs
push de
call .iteration
@@ -1354,9 +1286,8 @@ UpdateBGMapRow:: ; 27d3
ld a, SCREEN_WIDTH
ld [hBGMapTileCount], a
ret
-; 27f8
-UpdateBGMapColumn:: ; 27f8
+UpdateBGMapColumn::
ld hl, wBGMapBufferPtrs
ld c, SCREEN_HEIGHT
.loop
@@ -1381,7 +1312,6 @@ UpdateBGMapColumn:: ; 27f8
ld a, SCREEN_HEIGHT
ld [hBGMapTileCount], a
ret
-; 2816
Unreferenced_Function2816::
ld hl, wBGMapBuffer
@@ -1389,9 +1319,8 @@ Unreferenced_Function2816::
xor a
call ByteFill
ret
-; 2821
-LoadTilesetGFX:: ; 2821
+LoadTilesetGFX::
ld hl, wTilesetAddress
ld a, [hli]
ld h, [hl]
@@ -1446,16 +1375,15 @@ LoadTilesetGFX:: ; 2821
xor a
ld [hTileAnimFrame], a
ret
-; 2879
-BufferScreen:: ; 2879
+BufferScreen::
ld hl, wOverworldMapAnchor
ld a, [hli]
ld h, [hl]
ld l, a
ld de, wScreenSave
- ld c, $5
- ld b, $6
+ ld c, SCREEN_META_HEIGHT
+ ld b, SCREEN_META_WIDTH
.row
push bc
push hl
@@ -1467,17 +1395,16 @@ BufferScreen:: ; 2879
jr nz, .col
pop hl
ld a, [wMapWidth]
- add $6
+ add 6
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
pop bc
dec c
jr nz, .row
ret
-; 289d
-SaveScreen:: ; 289d
+SaveScreen::
ld hl, wOverworldMapAnchor
ld a, [hli]
ld h, [hl]
@@ -1498,18 +1425,18 @@ SaveScreen:: ; 289d
ret
.up
- ld de, wScreenSave + 6
+ ld de, wScreenSave + SCREEN_META_WIDTH
ld a, [hMapObjectIndexBuffer]
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
jr .vertical
.down
ld de, wScreenSave
.vertical
- ld b, 6
- ld c, 4
+ ld b, SCREEN_META_WIDTH
+ ld c, SCREEN_META_HEIGHT - 1
jr SaveScreen_LoadNeighbor
.left
@@ -1520,11 +1447,11 @@ SaveScreen:: ; 289d
.right
ld de, wScreenSave
.horizontal
- ld b, 5
- ld c, 5
+ ld b, SCREEN_META_WIDTH - 1
+ ld c, SCREEN_META_HEIGHT
jr SaveScreen_LoadNeighbor
-LoadNeighboringBlockData:: ; 28e3
+LoadNeighboringBlockData::
ld hl, wOverworldMapAnchor
ld a, [hli]
ld h, [hl]
@@ -1533,10 +1460,10 @@ LoadNeighboringBlockData:: ; 28e3
add 6
ld [hConnectionStripLength], a
ld de, wScreenSave
- ld b, 6
- ld c, 5
+ ld b, SCREEN_META_WIDTH
+ ld c, SCREEN_META_HEIGHT
-SaveScreen_LoadNeighbor:: ; 28f7
+SaveScreen_LoadNeighbor::
.row
push bc
push hl
@@ -1564,9 +1491,8 @@ SaveScreen_LoadNeighbor:: ; 28f7
dec c
jr nz, .row
ret
-; 2914
-GetMovementPermissions:: ; 2914
+GetMovementPermissions::
xor a
ld [wTilePermissions], a
call .LeftRight
@@ -1594,9 +1520,8 @@ GetMovementPermissions:: ; 2914
or [hl]
ld [hl], a
ret
-; 2945
-.MovementPermissionsData: ; 2945
+.MovementPermissionsData:
db DOWN_MASK
db UP_MASK
db LEFT_MASK
@@ -1605,7 +1530,6 @@ GetMovementPermissions:: ; 2914
db UP_MASK | RIGHT_MASK
db DOWN_MASK | LEFT_MASK
db UP_MASK | LEFT_MASK
-; 294d
.UpDown:
ld a, [wPlayerStandingMapX]
@@ -1625,7 +1549,6 @@ GetMovementPermissions:: ; 2914
ld [wTileUp], a
call .Up
ret
-; 296c
.LeftRight:
ld a, [wPlayerStandingMapX]
@@ -1645,7 +1568,6 @@ GetMovementPermissions:: ; 2914
ld [wTileRight], a
call .Right
ret
-; 298b
.Down:
call .CheckHiNybble
@@ -1664,7 +1586,6 @@ GetMovementPermissions:: ; 2914
or FACE_DOWN
ld [wTilePermissions], a
ret
-; 29a8
.Up:
call .CheckHiNybble
@@ -1683,7 +1604,6 @@ GetMovementPermissions:: ; 2914
or FACE_UP
ld [wTilePermissions], a
ret
-; 29c5
.Right:
call .CheckHiNybble
@@ -1702,7 +1622,6 @@ GetMovementPermissions:: ; 2914
or FACE_RIGHT
ld [wTilePermissions], a
ret
-; 29e2
.Left:
call .CheckHiNybble
@@ -1721,17 +1640,15 @@ GetMovementPermissions:: ; 2914
or FACE_LEFT
ld [wTilePermissions], a
ret
-; 29ff
.CheckHiNybble:
and $f0
- cp $b0
+ cp HI_NYBBLE_SIDE_WALLS
ret z
- cp $c0
+ cp HI_NYBBLE_UNUSED_C0
ret
-; 2a07
-GetFacingTileCoord:: ; 2a07
+GetFacingTileCoord::
; Return map coordinates in (d, e) and tile id in a
; of the tile the player is facing.
@@ -1774,9 +1691,8 @@ GetFacingTileCoord:: ; 2a07
dw wTileLeft
db 1, 0
dw wTileRight
-; 2a3c
-GetCoordTile:: ; 2a3c
+GetCoordTile::
; Get the collision byte for tile d, e
call GetBlockLocation
ld a, [hl]
@@ -1809,14 +1725,13 @@ GetCoordTile:: ; 2a3c
.nope
ld a, -1
ret
-; 2a66
-GetBlockLocation:: ; 2a66
+GetBlockLocation::
ld a, [wMapWidth]
add 6
ld c, a
ld b, 0
- ld hl, wOverworldMap + 1
+ ld hl, wOverworldMapBlocks + 1
add hl, bc
ld a, e
srl a
@@ -1839,9 +1754,8 @@ GetBlockLocation:: ; 2a66
ld b, 0
add hl, bc
ret
-; 2a8b
-CheckFacingBGEvent:: ; 2a8b
+CheckFacingBGEvent::
call GetFacingTileCoord
; Load facing into b.
ld b, a
@@ -1866,9 +1780,8 @@ CheckFacingBGEvent:: ; 2a8b
ld a, h
rst Bankswitch
ret
-; 2aaa
-CheckIfFacingTileCoordIsBGEvent:: ; 2aaa
+CheckIfFacingTileCoordIsBGEvent::
; Checks to see if you are facing a BG event. If so, copies it into wEngineBuffer1 and sets carry.
ld hl, wCurrMapBGEventsPointer
ld a, [hli]
@@ -1905,9 +1818,8 @@ CheckIfFacingTileCoordIsBGEvent:: ; 2aaa
call CopyBytes
scf
ret
-; 2ad4
-CheckCurrentMapCoordEvents:: ; 2ad4
+CheckCurrentMapCoordEvents::
; If there are no coord events, we don't need to be here.
ld a, [wCurrMapCoordEventCount]
and a
@@ -1978,44 +1890,40 @@ CheckCurrentMapCoordEvents:: ; 2ad4
call CopyBytes
scf
ret
-; 2b29
-FadeToMenu:: ; 2b29
+FadeToMenu::
xor a
ld [hBGMapMode], a
- call LoadStandardMenuDataHeader
- farcall Special_FadeOutPalettes
+ call LoadStandardMenuHeader
+ farcall FadeOutPalettes
call ClearSprites
call DisableSpriteUpdates
ret
-; 2b3c
-CloseSubmenu:: ; 2b3c
+CloseSubmenu::
call ClearBGPalettes
call ReloadTilesetAndPalettes
call UpdateSprites
call Call_ExitMenu
call ret_d90
jr FinishExitMenu
-; 2b4d
-ExitAllMenus:: ; 2b4d
+ExitAllMenus::
call ClearBGPalettes
call Call_ExitMenu
call ReloadTilesetAndPalettes
call UpdateSprites
call ret_d90
-FinishExitMenu:: ; 2b5c
+FinishExitMenu::
ld b, SCGB_MAPPALS
call GetSGBLayout
farcall LoadOW_BGPal7
call WaitBGMap2
- farcall Special_FadeInPalettes
+ farcall FadeInPalettes
call EnableSpriteUpdates
ret
-; 2b74
-ReturnToMapWithSpeechTextbox:: ; 0x2b74
+ReturnToMapWithSpeechTextbox::
push af
ld a, $1
ld [wSpriteUpdatesEnabled], a
@@ -2038,12 +1946,11 @@ ReturnToMapWithSpeechTextbox:: ; 0x2b74
ld [hMapAnims], a
pop af
ret
-; 0x2bae
-ReloadTilesetAndPalettes:: ; 2bae
+ReloadTilesetAndPalettes::
call DisableLCD
call ClearSprites
- farcall Special_RefreshSprites
+ farcall RefreshSprites
call LoadStandardFont
call LoadFontsExtra
ld a, [hROMBank]
@@ -2052,7 +1959,7 @@ ReloadTilesetAndPalettes:: ; 2bae
ld b, a
ld a, [wMapNumber]
ld c, a
- call SwitchToAnyMapDataBank
+ call SwitchToAnyMapAttributesBank
farcall UpdateTimeOfDayPal
call OverworldTextModeSwitch
call LoadTilesetGFX
@@ -2063,14 +1970,13 @@ ReloadTilesetAndPalettes:: ; 2bae
call EnableLCD
ret
-; 2be5
-GetMapDefPointer:: ; 2be5
+GetMapPointer::
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
-GetAnyMapDefPointer:: ; 0x2bed
+GetAnyMapPointer::
; Prior to calling this function, you must have switched banks so that
; MapGroupPointers is visible.
@@ -2078,7 +1984,7 @@ GetAnyMapDefPointer:: ; 0x2bed
; b = map group, c = map number
; outputs:
-; hl points to the map_def
+; hl points to the map within its group
push bc ; save map number for later
; get pointer to map group
@@ -2094,36 +2000,35 @@ GetAnyMapDefPointer:: ; 0x2bed
ld l, a
pop bc ; restore map number
- ; find the cth map_def
+ ; find the cth map within the group
dec c
ld b, 0
ld a, 9
call AddNTimes
ret
-; 0x2c04
-GetMapDefField:: ; 0x2c04
-; Extract data from the current map's map_def.
+GetMapField::
+; Extract data from the current map's group entry.
; inputs:
-; de = offset of desired data within the map_def (a MAPDEF_* constant)
+; de = offset of desired data within the map (a MAP_* constant)
; outputs:
-; bc = data from the current map's map_def
-; (e.g., de = MAPDEF_TILESET would return a pointer to the tileset id)
+; bc = data from the current map's field
+; (e.g., de = MAP_TILESET would return a pointer to the tileset id)
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
-GetAnyMapDefField:: ; 0x2c0c
+GetAnyMapField::
; bankswitch
ld a, [hROMBank]
push af
ld a, BANK(MapGroupPointers)
rst Bankswitch
- call GetAnyMapDefPointer
+ call GetAnyMapPointer
add hl, de
ld c, [hl]
inc hl
@@ -2133,83 +2038,77 @@ GetAnyMapDefField:: ; 0x2c0c
pop af
rst Bankswitch
ret
-; 0x2c1c
-SwitchToMapDataBank:: ; 2c1c
+SwitchToMapAttributesBank::
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
-SwitchToAnyMapDataBank:: ; 2c24
- call GetAnyMapDataBank
+SwitchToAnyMapAttributesBank::
+ call GetAnyMapAttributesBank
rst Bankswitch
ret
-; 2c29
-GetMapDataBank:: ; 2c29
+GetMapAttributesBank::
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
-GetAnyMapDataBank:: ; 2c31
+GetAnyMapAttributesBank::
push hl
push de
- ld de, MAPDEF_MAPDATA_BANK
- call GetAnyMapDefField
+ ld de, MAP_MAPATTRIBUTES_BANK
+ call GetAnyMapField
ld a, c
pop de
pop hl
ret
-; 2c3d
-PartialCopyMapDef:: ; 2c3d
+CopyMapPartial::
; Copy map data bank, tileset, environment, and map data address
-; from the current map's map_def.
+; from the current map's entry within its group.
ld a, [hROMBank]
push af
ld a, BANK(MapGroupPointers)
rst Bankswitch
- call GetMapDefPointer
- ld de, wPartialMapDef
- ld bc, wPartialMapDefEnd - wPartialMapDef
+ call GetMapPointer
+ ld de, wMapPartial
+ ld bc, wMapPartialEnd - wMapPartial
call CopyBytes
pop af
rst Bankswitch
ret
-; 2c52
-SwitchToMapScriptsBank:: ; 2c52
+SwitchToMapScriptsBank::
ld a, [wMapScriptsBank]
rst Bankswitch
ret
-; 2c57
-GetMapScriptsBank:: ; 2c57
+GetMapScriptsBank::
ld a, [wMapScriptsBank]
ret
-; 2c5b
-GetAnyMapBlocksBank:: ; 2c5b
+GetAnyMapBlocksBank::
; Return the blockdata bank for group b map c.
push hl
push de
push bc
push bc
- ld de, MAPDEF_MAPDATA
- call GetAnyMapDefField
+ ld de, MAP_MAPATTRIBUTES
+ call GetAnyMapField
ld l, c
ld h, b
pop bc
push hl
- ld de, MAPDEF_MAPDATA_BANK
- call GetAnyMapDefField
+ ld de, MAP_MAPATTRIBUTES_BANK
+ call GetAnyMapField
pop hl
- ld de, MAPDEF_MAPDATA ; blockdata bank
+ ld de, MAP_MAPATTRIBUTES ; blockdata bank
add hl, de
ld a, c
call GetFarByte
@@ -2219,78 +2118,71 @@ GetAnyMapBlocksBank:: ; 2c5b
pop de
pop hl
ret
-; 2c7d
-GetMapDataPointer:: ; 0x2c7d
+GetMapAttributesPointer::
; returns the current map's data pointer in hl.
push bc
push de
- ld de, MAPDEF_MAPDATA
- call GetMapDefField
+ ld de, MAP_MAPATTRIBUTES
+ call GetMapField
ld l, c
ld h, b
pop de
pop bc
ret
-; 2c8a
-GetMapEnvironment:: ; 2c8a
+GetMapEnvironment::
push hl
push de
push bc
- ld de, MAPDEF_ENVIRONMENT
- call GetMapDefField
+ ld de, MAP_ENVIRONMENT
+ call GetMapField
ld a, c
pop bc
pop de
pop hl
ret
-; 2c98
ret ; unused
-; 2c99
-GetAnyMapEnvironment:: ; 2c99
+GetAnyMapEnvironment::
push hl
push de
push bc
- ld de, MAPDEF_ENVIRONMENT
- call GetAnyMapDefField
+ ld de, MAP_ENVIRONMENT
+ call GetAnyMapField
ld a, c
pop bc
pop de
pop hl
ret
-; 2ca7
-GetAnyMapTileset:: ; 2ca7
- ld de, MAPDEF_TILESET
- call GetAnyMapDefField
+GetAnyMapTileset::
+ ld de, MAP_TILESET
+ call GetAnyMapField
ld a, c
ret
-; 2caf
-GetWorldMapLocation:: ; 0x2caf
+GetWorldMapLocation::
; given a map group/id in bc, return its location on the Pokégear map.
push hl
push de
push bc
- ld de, MAPDEF_LOCATION
- call GetAnyMapDefField
+ ld de, MAP_LOCATION
+ call GetAnyMapField
ld a, c
pop bc
pop de
pop hl
ret
-; 0x2cbd
-GetMapMusic:: ; 2cbd
+GetMapMusic::
push hl
push bc
- ld de, MAPDEF_MUSIC
- call GetMapDefField
+ ld de, MAP_MUSIC
+ call GetMapField
ld a, c
cp MUSIC_MAHOGANY_MART
jr z, .mahoganymart
@@ -2306,7 +2198,7 @@ GetMapMusic:: ; 2cbd
.radiotower
ld a, [wStatusFlags2]
- bit 0, a
+ bit STATUSFLAGS2_ROCKETS_IN_RADIO_TOWER_F, a
jr z, .clearedradiotower
ld de, MUSIC_ROCKET_OVERTURE
jr .done
@@ -2321,7 +2213,7 @@ GetMapMusic:: ; 2cbd
.mahoganymart
ld a, [wStatusFlags2]
- bit 7, a
+ bit STATUSFLAGS2_ROCKETS_IN_MAHOGANY_F, a
jr z, .clearedmahogany
ld de, MUSIC_ROCKET_HIDEOUT
jr .done
@@ -2329,50 +2221,45 @@ GetMapMusic:: ; 2cbd
.clearedmahogany
ld de, MUSIC_CHERRYGROVE_CITY
jr .done
-; 2cff
-GetMapTimeOfDay:: ; 2cff
+GetMapTimeOfDay::
call GetPhoneServiceTimeOfDayByte
and $f
ret
-; 2d05
-GetMapPhoneService:: ; 2d05
+GetMapPhoneService::
call GetPhoneServiceTimeOfDayByte
and $f0
swap a
ret
-; 2d0d
-GetPhoneServiceTimeOfDayByte:: ; 2d0d
+GetPhoneServiceTimeOfDayByte::
push hl
push bc
- ld de, MAPDEF_PALETTE
- call GetMapDefField
+ ld de, MAP_PALETTE
+ call GetMapField
ld a, c
pop bc
pop hl
ret
-; 2d19
-GetFishingGroup:: ; 2d19
+GetFishingGroup::
push de
push hl
push bc
- ld de, MAPDEF_FISHGROUP
- call GetMapDefField
+ ld de, MAP_FISHGROUP
+ call GetMapField
ld a, c
pop bc
pop hl
pop de
ret
-; 2d27
-LoadTileset:: ; 2d27
+LoadTileset::
push hl
push bc
@@ -2390,4 +2277,3 @@ LoadTileset:: ; 2d27
pop bc
pop hl
ret
-; 2d43
diff --git a/home/map_objects.asm b/home/map_objects.asm
index 97e4bae37..6bc30d571 100644
--- a/home/map_objects.asm
+++ b/home/map_objects.asm
@@ -1,6 +1,6 @@
; Functions handling map objects.
-GetSpritePalette:: ; 17ff
+GetSpritePalette::
push hl
push de
push bc
@@ -13,9 +13,8 @@ GetSpritePalette:: ; 17ff
pop de
pop hl
ret
-; 180e
-GetSpriteVTile:: ; 180e
+GetSpriteVTile::
push hl
push bc
ld hl, wUsedSprites + 2
@@ -49,9 +48,8 @@ GetSpriteVTile:: ; 180e
pop bc
pop hl
ret
-; 1836
-DoesSpriteHaveFacings:: ; 1836
+DoesSpriteHaveFacings::
push de
push hl
@@ -72,25 +70,22 @@ DoesSpriteHaveFacings:: ; 1836
pop hl
pop de
ret
-; 184a
-GetPlayerStandingTile:: ; 184a
+GetPlayerStandingTile::
ld a, [wPlayerStandingTile]
call GetTileCollision
ld b, a
ret
-; 1852
-CheckOnWater:: ; 1852
+CheckOnWater::
ld a, [wPlayerStandingTile]
call GetTileCollision
sub WATERTILE
ret z
and a
ret
-; 185d
-GetTileCollision:: ; 185d
+GetTileCollision::
; Get the collision type of tile a.
push de
@@ -115,9 +110,8 @@ GetTileCollision:: ; 185d
pop hl
pop de
ret
-; 1875
-CheckGrassTile:: ; 1875
+CheckGrassTile::
ld d, a
and $f0
cp HI_NYBBLE_TALL_GRASS
@@ -140,53 +134,46 @@ CheckGrassTile:: ; 1875
ret z
scf
ret
-; 188e
-CheckSuperTallGrassTile:: ; 188e
+CheckSuperTallGrassTile::
cp COLL_LONG_GRASS
ret z
cp COLL_LONG_GRASS_1C
ret
-; 1894
-CheckCutTreeTile:: ; 1894
+CheckCutTreeTile::
cp COLL_CUT_TREE
ret z
cp COLL_CUT_TREE_1A
ret
-; 189a
-CheckHeadbuttTreeTile:: ; 189a
+CheckHeadbuttTreeTile::
cp COLL_HEADBUTT_TREE
ret z
cp COLL_HEADBUTT_TREE_1D
ret
-; 18a0
-CheckCounterTile:: ; 18a0
+CheckCounterTile::
cp COLL_COUNTER
ret z
cp COLL_COUNTER_98
ret
-; 18a6
-CheckPitTile:: ; 18a6
+CheckPitTile::
cp COLL_PIT
ret z
cp COLL_PIT_68
ret
-; 18ac
-CheckIceTile:: ; 18ac
+CheckIceTile::
cp COLL_ICE
ret z
cp COLL_ICE_2B
ret z
scf
ret
-; 18b4
-CheckWhirlpoolTile:: ; 18b4
+CheckWhirlpoolTile::
nop
cp COLL_WHIRLPOOL
ret z
@@ -194,16 +181,14 @@ CheckWhirlpoolTile:: ; 18b4
ret z
scf
ret
-; 18bd
-CheckWaterfallTile:: ; 18bd
+CheckWaterfallTile::
cp COLL_WATERFALL
ret z
cp COLL_CURRENT_DOWN
ret
-; 18c3
-CheckStandingOnEntrance:: ; 18c3
+CheckStandingOnEntrance::
ld a, [wPlayerStandingTile]
cp COLL_DOOR
ret z
@@ -213,9 +198,8 @@ CheckStandingOnEntrance:: ; 18c3
ret z
cp COLL_CAVE
ret
-; 18d2
-GetMapObject:: ; 18d2
+GetMapObject::
; Return the location of map object a in bc.
ld hl, wMapObjects
ld bc, OBJECT_LENGTH
@@ -223,9 +207,8 @@ GetMapObject:: ; 18d2
ld b, h
ld c, l
ret
-; 18de
-CheckObjectVisibility:: ; 18de
+CheckObjectVisibility::
; Sets carry if the object is not visible on the screen.
ld [hMapObjectIndexBuffer], a
call GetMapObject
@@ -242,9 +225,8 @@ CheckObjectVisibility:: ; 18de
.not_visible
scf
ret
-; 18f5
-CheckObjectTime:: ; 18f5
+CheckObjectTime::
ld hl, MAPOBJECT_HOUR
add hl, bc
ld a, [hl]
@@ -276,7 +258,10 @@ CheckObjectTime:: ; 18f5
ret
.TimeOfDayValues_191e:
- db MORN, DAY, NITE
+; entries correspond to TimeOfDay values
+ db MORN
+ db DAY
+ db NITE
.check_hour
ld hl, MAPOBJECT_HOUR
@@ -314,25 +299,22 @@ CheckObjectTime:: ; 18f5
.no
scf
ret
-; 194d
; unused
ld [hMapObjectIndexBuffer], a
call GetMapObject
call CopyObjectStruct
ret
-; 1956
-_CopyObjectStruct:: ; 1956
+_CopyObjectStruct::
ld [hMapObjectIndexBuffer], a
call UnmaskObject
ld a, [hMapObjectIndexBuffer]
call GetMapObject
farcall CopyObjectStruct
ret
-; 1967
-ApplyDeletionToMapObject:: ; 1967
+ApplyDeletionToMapObject::
ld [hMapObjectIndexBuffer], a
call GetMapObject
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
@@ -361,15 +343,13 @@ ApplyDeletionToMapObject:: ; 1967
ld [wObjectFollow_Leader], a
ld [wObjectFollow_Follower], a
ret
-; 199f
-DeleteObjectStruct:: ; 199f
+DeleteObjectStruct::
call ApplyDeletionToMapObject
call MaskObject
ret
-; 19a6
-CopyPlayerObjectTemplate:: ; 19a6
+CopyPlayerObjectTemplate::
push hl
call GetMapObject
ld d, b
@@ -381,7 +361,6 @@ CopyPlayerObjectTemplate:: ; 19a6
ld bc, OBJECT_LENGTH - 1
call CopyBytes
ret
-; 19b8
Unreferenced_Function19b8:
call GetMapObject
@@ -411,9 +390,8 @@ Unreferenced_Function19b8:
call GetObjectStruct
farcall DeleteMapObject
ret
-; 19e9
-LoadMovementDataPointer:: ; 19e9
+LoadMovementDataPointer::
; Load the movement data pointer for object a.
ld [wMovementObject], a
ld a, [hROMBank]
@@ -438,9 +416,8 @@ LoadMovementDataPointer:: ; 19e9
set 7, [hl]
and a
ret
-; 1a13
-FindFirstEmptyObjectStruct:: ; 1a13
+FindFirstEmptyObjectStruct::
; Returns the index of the first empty object struct in A and its address in HL, then sets carry.
; If all object structs are occupied, A = 0 and Z is set.
; Preserves BC and DE.
@@ -468,9 +445,8 @@ FindFirstEmptyObjectStruct:: ; 1a13
pop de
pop bc
ret
-; 1a2f
-GetSpriteMovementFunction:: ; 1a2f
+GetSpriteMovementFunction::
ld hl, OBJECT_MOVEMENTTYPE
add hl, bc
ld a, [hl]
@@ -479,36 +455,34 @@ GetSpriteMovementFunction:: ; 1a2f
xor a
.ok
- ld hl, SpriteMovementData
+ ld hl, SpriteMovementData + SPRITEMOVEATTR_MOVEMENT
ld e, a
ld d, 0
-rept SPRITEMOVEDATA_FIELDS
+rept NUM_SPRITEMOVEDATA_FIELDS
add hl, de
endr
ld a, [hl]
ret
-; 1a47
-GetInitialFacing:: ; 1a47
+GetInitialFacing::
push bc
push de
ld e, a
ld d, 0
- ld hl, SpriteMovementData + 1 ; init facing
-rept SPRITEMOVEDATA_FIELDS
+ ld hl, SpriteMovementData + SPRITEMOVEATTR_FACING
+rept NUM_SPRITEMOVEDATA_FIELDS
add hl, de
endr
ld a, BANK(SpriteMovementData)
call GetFarByte
add a
add a
- and $c
+ maskbits NUM_DIRECTIONS, 2
pop de
pop bc
ret
-; 1a61
-CopySpriteMovementData:: ; 1a61
+CopySpriteMovementData::
ld l, a
ld a, [hROMBank]
push af
@@ -524,9 +498,8 @@ CopySpriteMovementData:: ; 1a61
rst Bankswitch
ret
-; 1a71
-.CopyData: ; 1a71
+.CopyData:
ld hl, OBJECT_MOVEMENTTYPE
add hl, de
ld [hl], a
@@ -534,8 +507,8 @@ CopySpriteMovementData:: ; 1a61
push de
ld e, a
ld d, 0
- ld hl, SpriteMovementData + 1 ; init facing
-rept SPRITEMOVEDATA_FIELDS
+ ld hl, SpriteMovementData + SPRITEMOVEATTR_FACING
+rept NUM_SPRITEMOVEDATA_FIELDS
add hl, de
endr
ld b, h
@@ -546,7 +519,7 @@ endr
inc bc
rlca
rlca
- and %00001100
+ maskbits NUM_DIRECTIONS, 2
ld hl, OBJECT_FACING
add hl, de
ld [hl], a
@@ -575,9 +548,8 @@ endr
add hl, de
ld [hl], a
ret
-; 1aae
-_GetMovementByte:: ; 1aae
+_GetMovementByte::
; Switch to the movement data bank
ld a, [hROMBank]
push af
@@ -601,21 +573,18 @@ _GetMovementByte:: ; 1aae
ld a, h
ret
-; 1ac6
-SetVramState_Bit0:: ; 1ac6
+SetVramState_Bit0::
ld hl, wVramState
set 0, [hl]
ret
-; 1acc
-ResetVramState_Bit0:: ; 1acc
+ResetVramState_Bit0::
ld hl, wVramState
res 0, [hl]
ret
-; 1ad2
-UpdateSprites:: ; 1ad2
+UpdateSprites::
ld a, [wVramState]
bit 0, a
ret z
@@ -623,26 +592,23 @@ UpdateSprites:: ; 1ad2
farcall Function55e0
farcall _UpdateSprites
ret
-; 1ae5
-GetObjectStruct:: ; 1ae5
+GetObjectStruct::
ld bc, OBJECT_STRUCT_LENGTH
ld hl, wObjectStructs
call AddNTimes
ld b, h
ld c, l
ret
-; 1af1
-DoesObjectHaveASprite:: ; 1af1
+DoesObjectHaveASprite::
ld hl, OBJECT_SPRITE
add hl, bc
ld a, [hl]
and a
ret
-; 1af8
-SetSpriteDirection:: ; 1af8
+SetSpriteDirection::
; preserves other flags
push af
ld hl, OBJECT_FACING
@@ -651,16 +617,14 @@ SetSpriteDirection:: ; 1af8
and %11110011
ld e, a
pop af
- and %00001100
+ maskbits NUM_DIRECTIONS, 2
or e
ld [hl], a
ret
-; 1b07
-GetSpriteDirection:: ; 1b07
+GetSpriteDirection::
ld hl, OBJECT_FACING
add hl, bc
ld a, [hl]
- and %00001100
+ maskbits NUM_DIRECTIONS, 2
ret
-; 1b0f
diff --git a/home/math.asm b/home/math.asm
index 6a779e378..f385ccbf8 100644
--- a/home/math.asm
+++ b/home/math.asm
@@ -1,4 +1,4 @@
-AddNTimes:: ; 0x30fe
+AddNTimes::
; Add bc * a to hl.
and a
ret z
@@ -7,9 +7,8 @@ AddNTimes:: ; 0x30fe
dec a
jr nz, .loop
ret
-; 0x3105
-SimpleMultiply:: ; 3105
+SimpleMultiply::
; Return a * c.
and a
ret z
@@ -23,10 +22,8 @@ SimpleMultiply:: ; 3105
jr nz, .loop
pop bc
ret
-; 3110
-
-SimpleDivide:: ; 3110
+SimpleDivide::
; Divide a by c. Return quotient b and remainder a.
ld b, 0
.loop
@@ -36,10 +33,8 @@ SimpleDivide:: ; 3110
dec b
add c
ret
-; 3119
-
-Multiply:: ; 3119
+Multiply::
; Multiply hMultiplicand (3 bytes) by hMultiplier. Result in hProduct.
; All values are big endian.
push hl
@@ -50,10 +45,8 @@ Multiply:: ; 3119
pop bc
pop hl
ret
-; 3124
-
-Divide:: ; 3124
+Divide::
; Divide hDividend length b (max 4 bytes) by hDivisor. Result in hQuotient.
; All values are big endian.
push hl
@@ -64,10 +57,8 @@ Divide:: ; 3124
pop de
pop hl
ret
-; 3136
-
-SubtractSigned:: ; 3136
+SubtractSigned::
; Return a - b, sign in carry.
sub b
ret nc
@@ -75,4 +66,3 @@ SubtractSigned:: ; 3136
add 1
scf
ret
-; 313d
diff --git a/home/menu.asm b/home/menu.asm
index ae3252e96..d10b6e936 100644
--- a/home/menu.asm
+++ b/home/menu.asm
@@ -1,73 +1,61 @@
; Functions used in displaying and handling menus.
-
-LoadMenuDataHeader::
- call CopyMenuDataHeader
+LoadMenuHeader::
+ call CopyMenuHeader
call PushWindow
ret
-CopyMenuDataHeader::
- ld de, wMenuDataHeader
- ld bc, wMenuDataHeaderEnd - wMenuDataHeader
+CopyMenuHeader::
+ ld de, wMenuHeader
+ ld bc, wMenuHeaderEnd - wMenuHeader
call CopyBytes
ld a, [hROMBank]
ld [wMenuDataBank], a
ret
-; 0x1d4b
-StoreTo_wMenuCursorBuffer:: ; 1d4b
+StoreTo_wMenuCursorBuffer::
ld [wMenuCursorBuffer], a
ret
-; 1d4f
-
-MenuTextBox:: ; 1d4f
+MenuTextBox::
push hl
call LoadMenuTextBox
pop hl
jp PrintText
-; 1d57
; unused
ret
-; 1d58
-LoadMenuTextBox:: ; 1d58
- ld hl, .MenuDataHeader
- call LoadMenuDataHeader
+LoadMenuTextBox::
+ ld hl, .MenuHeader
+ call LoadMenuHeader
ret
-; 1d5f
-.MenuDataHeader: ; 1d5f
+.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 12, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw vTiles0
db 0 ; default option
-; 1d67
-MenuTextBoxBackup:: ; 1d67
+MenuTextBoxBackup::
call MenuTextBox
call CloseWindow
ret
-; 1d6e
-LoadStandardMenuDataHeader:: ; 1d6e
- ld hl, .MenuDataHeader
- call LoadMenuDataHeader
+LoadStandardMenuHeader::
+ ld hl, .MenuHeader
+ call LoadMenuHeader
ret
-; 1d75
-.MenuDataHeader: ; 1d75
+.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw 0
db 1 ; default option
-; 1d7d
-Call_ExitMenu:: ; 1d7d
+Call_ExitMenu::
call ExitMenu
ret
-; 1d81
VerticalMenu::
xor a
@@ -76,8 +64,8 @@ VerticalMenu::
call UpdateSprites
call PlaceVerticalMenuItems
call ApplyTilemap
- call CopyMenuData2
- ld a, [wMenuData2Flags]
+ call CopyMenuData
+ ld a, [wMenuDataFlags]
bit 7, a
jr z, .cancel
call InitVerticalMenuCursor
@@ -92,21 +80,19 @@ VerticalMenu::
.okay
and a
ret
-; 0x1dab
-GetMenu2:: ; 1dab
- call LoadMenuDataHeader
+GetMenu2::
+ call LoadMenuHeader
call VerticalMenu
call CloseWindow
ld a, [wMenuCursorY]
ret
-; 1db8
CopyNameFromMenu::
push hl
push bc
push af
- ld hl, wMenuData2Pointer
+ ld hl, wMenuDataPointer
ld a, [hli]
ld h, [hl]
ld l, a
@@ -120,24 +106,22 @@ CopyNameFromMenu::
pop bc
pop hl
ret
-; 0x1dcf
-
-YesNoBox:: ; 1dcf
+YesNoBox::
lb bc, SCREEN_WIDTH - 6, 7
-PlaceYesNoBox:: ; 1dd2
+PlaceYesNoBox::
jr _YesNoBox
-PlaceGenericTwoOptionBox:: ; 1dd4
- call LoadMenuDataHeader
+PlaceGenericTwoOptionBox::
+ call LoadMenuHeader
jr InterpretTwoOptionMenu
-_YesNoBox:: ; 1dd9
+_YesNoBox::
; Return nc (yes) or c (no).
push bc
- ld hl, YesNoMenuDataHeader
- call CopyMenuDataHeader
+ ld hl, YesNoMenuHeader
+ call CopyMenuHeader
pop bc
; This seems to be an overflow prevention, but
; it was coded wrong.
@@ -158,7 +142,7 @@ _YesNoBox:: ; 1dd9
ld [wMenuBorderBottomCoord], a
call PushWindow
-InterpretTwoOptionMenu:: ; 1dfe
+InterpretTwoOptionMenu::
call VerticalMenu
push af
ld c, $f
@@ -177,31 +161,27 @@ InterpretTwoOptionMenu:: ; 1dfe
ld [wMenuCursorY], a
scf
ret
-; 1e1d
-YesNoMenuDataHeader:: ; 1e1d
+YesNoMenuHeader::
db MENU_BACKUP_TILES ; flags
menu_coords 10, 5, 15, 9
- dw .MenuData2
+ dw .MenuData
db 1 ; default option
-; 1e25
-.MenuData2: ; 1e25
+.MenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 2
db "YES@"
db "NO@"
-; 1e2e
-OffsetMenuDataHeader:: ; 1e2e
- call _OffsetMenuDataHeader
+OffsetMenuHeader::
+ call _OffsetMenuHeader
call PushWindow
ret
-; 1e35
-_OffsetMenuDataHeader:: ; 1e35
+_OffsetMenuHeader::
push de
- call CopyMenuDataHeader
+ call CopyMenuHeader
pop de
ld a, [wMenuBorderLeftCoord]
ld h, a
@@ -222,9 +202,8 @@ _OffsetMenuDataHeader:: ; 1e35
add l
ld [wMenuBorderBottomCoord], a
ret
-; 1e5d
-DoNthMenu:: ; 1e5d
+DoNthMenu::
call DrawVariableLengthMenuBox
call MenuWriteText
call InitMenuCursorAndButtonPermissions
@@ -232,9 +211,8 @@ DoNthMenu:: ; 1e5d
call GetMenuJoypad
call MenuClickSound
ret
-; 1e70
-SetUpMenu:: ; 1e70
+SetUpMenu::
call DrawVariableLengthMenuBox ; ???
call MenuWriteText
call InitMenuCursorAndButtonPermissions ; set up selection pointer
@@ -243,7 +221,7 @@ SetUpMenu:: ; 1e70
ret
DrawVariableLengthMenuBox::
- call CopyMenuData2
+ call CopyMenuData
call GetMenuIndexSet
call AutomaticGetMenuBottomCoord
call MenuBox
@@ -263,15 +241,14 @@ MenuWriteText::
pop af
ld [hOAMUpdate], a
ret
-; 0x1ea6
-AutomaticGetMenuBottomCoord:: ; 1ea6
+AutomaticGetMenuBottomCoord::
ld a, [wMenuBorderLeftCoord]
ld c, a
ld a, [wMenuBorderRightCoord]
sub c
ld c, a
- ld a, [wMenuData2Items]
+ ld a, [wMenuDataItems]
add a
inc a
ld b, a
@@ -279,10 +256,9 @@ AutomaticGetMenuBottomCoord:: ; 1ea6
add b
ld [wMenuBorderBottomCoord], a
ret
-; 1ebd
-GetMenuIndexSet:: ; 1ebd
- ld hl, wMenuData2IndicesPointer
+GetMenuIndexSet::
+ ld hl, wMenuDataIndicesPointer
ld a, [hli]
ld h, [hl]
ld l, a
@@ -302,11 +278,10 @@ GetMenuIndexSet:: ; 1ebd
ld d, h
ld e, l
ld a, [hl]
- ld [wMenuData2Items], a
+ ld [wMenuDataItems], a
ret
-; 1eda
-RunMenuItemPrintingFunction:: ; 1eda
+RunMenuItemPrintingFunction::
call MenuBoxCoord2Tile
ld bc, 2 * SCREEN_WIDTH + 2
add hl, bc
@@ -320,32 +295,30 @@ RunMenuItemPrintingFunction:: ; 1eda
push hl
ld d, h
ld e, l
- ld hl, wMenuData2DisplayFunctionPointer
+ ld hl, wMenuDataDisplayFunctionPointer
call ._hl_
pop hl
ld de, 2 * SCREEN_WIDTH
add hl, de
pop de
jr .loop
-; 1efb
-._hl_ ; 1efb
+._hl_
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
-; 1eff
-InitMenuCursorAndButtonPermissions:: ; 1eff
+InitMenuCursorAndButtonPermissions::
call InitVerticalMenuCursor
ld hl, wMenuJoypadFilter
- ld a, [wMenuData2Flags]
+ ld a, [wMenuDataFlags]
bit 3, a
jr z, .disallow_select
set START_F, [hl]
.disallow_select
- ld a, [wMenuData2Flags]
+ ld a, [wMenuDataFlags]
bit 2, a
jr z, .disallow_left_right
set D_LEFT_F, [hl]
@@ -353,21 +326,17 @@ InitMenuCursorAndButtonPermissions:: ; 1eff
.disallow_left_right
ret
-; 1f1a
-
-GetScrollingMenuJoypad:: ; 1f1a
+GetScrollingMenuJoypad::
call ScrollingMenuJoypad
ld hl, wMenuJoypadFilter
and [hl]
jr ContinueGettingMenuJoypad
-; 1f23
-GetStaticMenuJoypad:: ; 1f23
+GetStaticMenuJoypad::
xor a
ld [wMenuJoypad], a
call StaticMenuJoypad
-; 1f2a
ContinueGettingMenuJoypad:
bit A_BUTTON_F, a
@@ -418,11 +387,10 @@ ContinueGettingMenuJoypad:
ld [wMenuSelection], a
scf
ret
-; 1f79
-PlaceMenuStrings:: ; 1f79
+PlaceMenuStrings::
push de
- ld hl, wMenuData2PointerTableAddr
+ ld hl, wMenuDataPointerTableAddr
ld a, [hli]
ld h, [hl]
ld l, a
@@ -433,9 +401,8 @@ PlaceMenuStrings:: ; 1f79
pop hl
call PlaceString
ret
-; 1f8d
-PlaceNthMenuStrings:: ; 1f8d
+PlaceNthMenuStrings::
push de
ld a, [wMenuSelection]
call GetMenuDataPointerTableEntry
@@ -447,9 +414,8 @@ PlaceNthMenuStrings:: ; 1f8d
pop hl
call PlaceString
ret
-; 1f9e
-Unreferenced_Function1f9e:: ; 1f9e
+Unreferenced_Function1f9e::
call GetMenuDataPointerTableEntry
inc hl
inc hl
@@ -457,21 +423,19 @@ Unreferenced_Function1f9e:: ; 1f9e
ld d, [hl]
ld e, a
ret
-; 1fa7
-MenuJumptable:: ; 1fa7
+MenuJumptable::
ld a, [wMenuSelection]
call GetMenuDataPointerTableEntry
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
-; 1fb1
-GetMenuDataPointerTableEntry:: ; 1fb1
+GetMenuDataPointerTableEntry::
ld e, a
ld d, $0
- ld hl, wMenuData2PointerTableAddr
+ ld hl, wMenuDataPointerTableAddr
ld a, [hli]
ld h, [hl]
ld l, a
@@ -480,14 +444,13 @@ GetMenuDataPointerTableEntry:: ; 1fb1
add hl, de
add hl, de
ret
-; 1fbf
-ClearWindowData:: ; 1fbf
+ClearWindowData::
ld hl, wWindowStackPointer
call .bytefill
- ld hl, wMenuDataHeader
+ ld hl, wMenuHeader
call .bytefill
- ld hl, wMenuData2Flags
+ ld hl, wMenuDataFlags
call .bytefill
ld hl, w2DMenuCursorInitY
call .bytefill
@@ -509,16 +472,14 @@ ClearWindowData:: ; 1fbf
pop af
ld [rSVBK], a
ret
-; 1ff0
-.bytefill ; 1ff0
+.bytefill
ld bc, $10
xor a
call ByteFill
ret
-; 1ff8
-MenuClickSound:: ; 1ff8
+MenuClickSound::
push af
and A_BUTTON | B_BUTTON
jr z, .nosound
@@ -529,25 +490,21 @@ MenuClickSound:: ; 1ff8
.nosound
pop af
ret
-; 2009
-
-PlayClickSFX:: ; 2009
+PlayClickSFX::
push de
ld de, SFX_READ_TEXT_2
call PlaySFX
pop de
ret
-; 0x2012
-MenuTextBoxWaitButton:: ; 2012
+MenuTextBoxWaitButton::
call MenuTextBox
call WaitButton
call ExitMenu
ret
-; 201c
-Place2DMenuItemName:: ; 201c
+Place2DMenuItemName::
ld [hBuffer], a
ld a, [hROMBank]
push af
@@ -559,28 +516,24 @@ Place2DMenuItemName:: ; 201c
rst Bankswitch
ret
-; 202a
-_2DMenu:: ; 202a
+_2DMenu::
ld a, [hROMBank]
- ld [wMenuData2_2DMenuItemStringsBank], a
+ ld [wMenuData_2DMenuItemStringsBank], a
farcall _2DMenu_
ld a, [wMenuCursorBuffer]
ret
-; 2039
-InterpretBattleMenu:: ; 2039
+InterpretBattleMenu::
ld a, [hROMBank]
- ld [wMenuData2_2DMenuItemStringsBank], a
+ ld [wMenuData_2DMenuItemStringsBank], a
farcall _InterpretBattleMenu
ld a, [wMenuCursorBuffer]
ret
-; 2048
-InterpretMobileMenu:: ; 2048
+InterpretMobileMenu::
ld a, [hROMBank]
- ld [wMenuData2_2DMenuItemStringsBank], a
+ ld [wMenuData_2DMenuItemStringsBank], a
farcall _InterpretMobileMenu
ld a, [wMenuCursorBuffer]
ret
-; 2057
diff --git a/home/menu_window.asm b/home/menu_window.asm
new file mode 100644
index 000000000..7c511097d
--- /dev/null
+++ b/home/menu_window.asm
@@ -0,0 +1,242 @@
+PushWindow::
+ callfar _PushWindow
+ ret
+
+ExitMenu::
+ push af
+ callfar _ExitMenu
+ pop af
+ ret
+
+InitVerticalMenuCursor::
+ callfar _InitVerticalMenuCursor
+ ret
+
+CloseWindow::
+ push af
+ call ExitMenu
+ call ApplyTilemap
+ call UpdateSprites
+ pop af
+ ret
+
+RestoreTileBackup::
+ call MenuBoxCoord2Tile
+ call .copy
+ call MenuBoxCoord2Attr
+ call .copy
+ ret
+
+.copy
+ call GetMenuBoxDims
+ inc b
+ inc c
+
+.row
+ push bc
+ push hl
+
+.col
+ ld a, [de]
+ ld [hli], a
+ dec de
+ dec c
+ jr nz, .col
+
+ pop hl
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ dec b
+ jr nz, .row
+
+ ret
+
+PopWindow::
+ ld b, $10
+ ld de, wMenuFlags
+.loop
+ ld a, [hld]
+ ld [de], a
+ inc de
+ dec b
+ jr nz, .loop
+ ret
+
+GetMenuBoxDims::
+ ld a, [wMenuBorderTopCoord] ; top
+ ld b, a
+ ld a, [wMenuBorderBottomCoord] ; bottom
+ sub b
+ ld b, a
+ ld a, [wMenuBorderLeftCoord] ; left
+ ld c, a
+ ld a, [wMenuBorderRightCoord] ; right
+ sub c
+ ld c, a
+ ret
+
+CopyMenuData::
+ push hl
+ push de
+ push bc
+ push af
+ ld hl, wMenuDataPointer
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, wMenuDataFlags
+ ld bc, wMenuDataEnd - wMenuDataFlags
+ call CopyBytes
+ pop af
+ pop bc
+ pop de
+ pop hl
+ ret
+
+GetWindowStackTop::
+ ld hl, wWindowStackPointer
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ inc hl
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ret
+
+PlaceVerticalMenuItems::
+ call CopyMenuData
+ ld hl, wMenuDataPointer
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ call GetMenuTextStartCoord
+ call Coord2Tile ; hl now contains the tilemap address where we will start printing text.
+ inc de
+ ld a, [de] ; Number of items
+ inc de
+ ld b, a
+.loop
+ push bc
+ call PlaceString
+ inc de
+ ld bc, 2 * SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ dec b
+ jr nz, .loop
+
+ ld a, [wMenuDataFlags]
+ bit 4, a
+ ret z
+
+ call MenuBoxCoord2Tile
+ ld a, [de]
+ ld c, a
+ inc de
+ ld b, $0
+ add hl, bc
+ jp PlaceString
+
+MenuBox::
+ call MenuBoxCoord2Tile
+ call GetMenuBoxDims
+ dec b
+ dec c
+ jp TextBox
+
+GetMenuTextStartCoord::
+ ld a, [wMenuBorderTopCoord]
+ ld b, a
+ inc b
+ ld a, [wMenuBorderLeftCoord]
+ ld c, a
+ inc c
+; bit 6: if not set, leave extra room on top
+ ld a, [wMenuDataFlags]
+ bit 6, a
+ jr nz, .bit_6_set
+ inc b
+
+.bit_6_set
+; bit 7: if set, leave extra room on the left
+ ld a, [wMenuDataFlags]
+ bit 7, a
+ jr z, .bit_7_clear
+ inc c
+
+.bit_7_clear
+ ret
+
+ClearMenuBoxInterior::
+ call MenuBoxCoord2Tile
+ ld bc, SCREEN_WIDTH + 1
+ add hl, bc
+ call GetMenuBoxDims
+ dec b
+ dec c
+ call ClearBox
+ ret
+
+ClearWholeMenuBox::
+ call MenuBoxCoord2Tile
+ call GetMenuBoxDims
+ inc c
+ inc b
+ call ClearBox
+ ret
+
+MenuBoxCoord2Tile::
+ ld a, [wMenuBorderLeftCoord]
+ ld c, a
+ ld a, [wMenuBorderTopCoord]
+ ld b, a
+
+Coord2Tile::
+; Return the address of wTileMap(c, b) in hl.
+ xor a
+ ld h, a
+ ld l, b
+ ld a, c
+ ld b, h
+ ld c, l
+ add hl, hl
+ add hl, hl
+ add hl, bc
+ add hl, hl
+ add hl, hl
+ ld c, a
+ xor a
+ ld b, a
+ add hl, bc
+ bccoord 0, 0
+ add hl, bc
+ ret
+
+MenuBoxCoord2Attr::
+ ld a, [wMenuBorderLeftCoord]
+ ld c, a
+ ld a, [wMenuBorderTopCoord]
+ ld b, a
+
+Coord2Attr::
+; Return the address of wAttrMap(c, b) in hl.
+ xor a
+ ld h, a
+ ld l, b
+ ld a, c
+ ld b, h
+ ld c, l
+ add hl, hl
+ add hl, hl
+ add hl, bc
+ add hl, hl
+ add hl, hl
+ ld c, a
+ xor a
+ ld b, a
+ add hl, bc
+ bccoord 0, 0, wAttrMap
+ add hl, bc
+ ret
diff --git a/home/mobile.asm b/home/mobile.asm
index 4be526bbc..21af7a73b 100644
--- a/home/mobile.asm
+++ b/home/mobile.asm
@@ -1,4 +1,4 @@
-Function3e32:: ; 3e32
+Function3e32::
; Mobile
cp $2
ld [$c988], a
@@ -27,9 +27,8 @@ Function3e32:: ; 3e32
rst Bankswitch
jp Function110030
-; 3e60
-Function3e60:: ; 3e60
+Function3e60::
; Return from Function110030
ld [$c986], a
ld a, l
@@ -50,9 +49,8 @@ Function3e60:: ; 3e60
ld l, a
ld a, [$c986]
ret
-; 3e80
-MobileReceive:: ; 3e80
+MobileReceive::
ld a, [hROMBank]
push af
ld a, BANK(_MobileReceive)
@@ -66,10 +64,8 @@ MobileReceive:: ; 3e80
rst Bankswitch
ret
-; 3e93
-
-Timer:: ; 3e93
+Timer::
push af
push bc
push de
@@ -125,9 +121,8 @@ Timer:: ; 3e93
pop bc
pop af
reti
-; 3ed7
-Unreferenced_Function3ed7:: ; 3ed7
+Unreferenced_Function3ed7::
ld [$dc02], a
ld a, [hROMBank]
push af
@@ -141,9 +136,8 @@ Unreferenced_Function3ed7:: ; 3ed7
ld a, [$dc02]
ret
-; 3eea
-Function3eea:: ; 3eea
+Function3eea::
push hl
push bc
ld de, wAttrMap - wTileMap
@@ -157,9 +151,8 @@ Function3eea:: ; 3eea
pop hl
call MobileHome_PlaceBox
ret
-; 3efd
-Unreferenced_Function3efd:: ; 3efd
+Unreferenced_Function3efd::
push hl
hlcoord 0, 12
ld b, 4
@@ -168,7 +161,6 @@ Unreferenced_Function3efd:: ; 3efd
pop hl
call PrintTextBoxText
ret
-; 3f0d
.fill_attr
push hl
@@ -184,9 +176,8 @@ Unreferenced_Function3efd:: ; 3efd
pop hl
call TextBoxBorder
ret
-; 3f20
-Function3f20:: ; 3f20
+Function3f20::
hlcoord 0, 0, wAttrMap
ld b, 6
ld c, 20
@@ -196,9 +187,8 @@ Function3f20:: ; 3f20
ld c, 18
call MobileHome_PlaceBox
ret
-; 3f35
-Function3f35:: ; 3f35
+Function3f35::
ld a, 6
ld de, SCREEN_WIDTH
.row
@@ -214,9 +204,8 @@ Function3f35:: ; 3f35
dec b
jr nz, .row
ret
-; 3f47
-MobileHome_PlaceBox: ; 3f47
+MobileHome_PlaceBox:
push bc
call .FillTop
pop bc
@@ -228,7 +217,6 @@ MobileHome_PlaceBox: ; 3f47
jr nz, .RowLoop
call .FillBottom
ret
-; 3f58
.FillTop:
ld a, $63
@@ -260,18 +248,16 @@ MobileHome_PlaceBox: ; 3f47
ld de, SCREEN_WIDTH
add hl, de
ret
-; 3f7c
-Function3f7c:: ; 3f7c
+Function3f7c::
call MenuBoxCoord2Tile
call GetMenuBoxDims
dec b
dec c
call Function3eea
ret
-; 3f88
-Function3f88:: ; 3f88
+Function3f88::
ld hl, wDecompressScratch
ld b, 0
.row
@@ -290,9 +276,8 @@ Function3f88:: ; 3f88
dec c
jr nz, .row
ret
-; 3f9f
-Function3f9f:: ; 3f9f
+Function3f9f::
ld hl, wDecompressScratch
.row
push bc
@@ -311,4 +296,3 @@ Function3f9f:: ; 3f9f
dec c
jr nz, .row
ret
-; 3fb5
diff --git a/home/mon_data.asm b/home/mon_data.asm
new file mode 100644
index 000000000..bcfe49ddb
--- /dev/null
+++ b/home/mon_data.asm
@@ -0,0 +1,87 @@
+Unreferenced_GetNthMove::
+ ld hl, wListMoves_MoveIndicesBuffer
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld a, [hl]
+ ret
+
+GetBaseData::
+ push bc
+ push de
+ push hl
+ ld a, [hROMBank]
+ push af
+ ld a, BANK(BaseData)
+ rst Bankswitch
+
+; Egg doesn't have BaseData
+ ld a, [wCurSpecies]
+ cp EGG
+ jr z, .egg
+
+; Get BaseData
+ dec a
+ ld bc, BASE_DATA_SIZE
+ ld hl, BaseData
+ call AddNTimes
+ ld de, wCurBaseData
+ ld bc, BASE_DATA_SIZE
+ call CopyBytes
+ jr .end
+
+.egg
+; ????
+ ld de, UnknownEggPic
+
+; Sprite dimensions
+ ld b, $55 ; 5x5
+ ld hl, wBasePicSize
+ ld [hl], b
+
+; ????
+ ld hl, wBasePadding
+ ld [hl], e
+ inc hl
+ ld [hl], d
+ inc hl
+ ld [hl], e
+ inc hl
+ ld [hl], d
+ jr .end
+
+.end
+; Replace Pokedex # with species
+ ld a, [wCurSpecies]
+ ld [wBaseDexNo], a
+
+ pop af
+ rst Bankswitch
+ pop hl
+ pop de
+ pop bc
+ ret
+
+GetCurNick::
+ ld a, [wCurPartyMon]
+ ld hl, wPartyMonNicknames
+
+GetNick::
+; Get nickname a from list hl.
+
+ push hl
+ push bc
+
+ call SkipNames
+ ld de, wStringBuffer1
+
+ push de
+ ld bc, MON_NAME_LENGTH
+ call CopyBytes
+ pop de
+
+ callfar CorrectNickErrors
+
+ pop bc
+ pop hl
+ ret
diff --git a/home/mon_data_2.asm b/home/mon_data_2.asm
new file mode 100644
index 000000000..99169eaa8
--- /dev/null
+++ b/home/mon_data_2.asm
@@ -0,0 +1,34 @@
+GetPartyParamLocation::
+; Get the location of parameter a from wCurPartyMon in hl
+ push bc
+ ld hl, wPartyMons
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld a, [wCurPartyMon]
+ call GetPartyLocation
+ pop bc
+ ret
+
+GetPartyLocation::
+; Add the length of a PartyMon struct to hl a times.
+ ld bc, PARTYMON_STRUCT_LENGTH
+ jp AddNTimes
+
+Unreferenced_GetDexNumber::
+; Probably used in gen 1 to convert index number to dex number
+; Not required in gen 2 because index number == dex number
+ push hl
+ ld a, b
+ dec a
+ ld b, 0
+ add hl, bc
+ ld hl, BaseData + BASE_DEX_NO
+ ld bc, BASE_DATA_SIZE
+ call AddNTimes
+ ld a, BANK(BaseData)
+ call GetFarHalfword
+ ld b, l
+ ld c, h
+ pop hl
+ ret
diff --git a/home/mon_stats.asm b/home/mon_stats.asm
new file mode 100644
index 000000000..318d32c9c
--- /dev/null
+++ b/home/mon_stats.asm
@@ -0,0 +1,104 @@
+IsAPokemon::
+; Return carry if species a is not a Pokemon.
+ and a
+ jr z, .NotAPokemon
+ cp EGG
+ jr z, .Pokemon
+ cp NUM_POKEMON + 1
+ jr c, .Pokemon
+
+.NotAPokemon:
+ scf
+ ret
+
+.Pokemon:
+ and a
+ ret
+
+DrawBattleHPBar::
+; Draw an HP bar d tiles long at hl
+; Fill it up to e pixels
+
+ push hl
+ push de
+ push bc
+
+; Place 'HP:'
+ ld a, $60
+ ld [hli], a
+ ld a, $61
+ ld [hli], a
+
+; Draw a template
+ push hl
+ ld a, $62 ; empty bar
+.template
+ ld [hli], a
+ dec d
+ jr nz, .template
+ ld a, $6b ; bar end
+ add b
+ ld [hl], a
+ pop hl
+
+; Safety check # pixels
+ ld a, e
+ and a
+ jr nz, .fill
+ ld a, c
+ and a
+ jr z, .done
+ ld e, 1
+
+.fill
+; Keep drawing tiles until pixel length is reached
+ ld a, e
+ sub TILE_WIDTH
+ jr c, .lastbar
+
+ ld e, a
+ ld a, $6a ; full bar
+ ld [hli], a
+ ld a, e
+ and a
+ jr z, .done
+ jr .fill
+
+.lastbar
+ ld a, $62 ; empty bar
+ add e ; + e
+ ld [hl], a
+
+.done
+ pop bc
+ pop de
+ pop hl
+ ret
+
+PrepMonFrontpic::
+ ld a, $1
+ ld [wBoxAlignment], a
+
+_PrepMonFrontpic::
+ ld a, [wCurPartySpecies]
+ call IsAPokemon
+ jr c, .not_pokemon
+
+ push hl
+ ld de, vTiles2
+ predef GetMonFrontpic
+ pop hl
+ xor a
+ ld [hGraphicStartTile], a
+ lb bc, 7, 7
+ predef PlaceGraphic
+ xor a
+ ld [wBoxAlignment], a
+ ret
+
+.not_pokemon
+ xor a
+ ld [wBoxAlignment], a
+ inc a
+ ld [wCurPartySpecies], a
+ ret
diff --git a/home/movement.asm b/home/movement.asm
index c2c45d12b..2c19b6355 100644
--- a/home/movement.asm
+++ b/home/movement.asm
@@ -1,4 +1,4 @@
-InitMovementBuffer:: ; 1b1e
+InitMovementBuffer::
ld [wMovementBufferObject], a
xor a
ld [wMovementBufferCount], a
@@ -9,18 +9,16 @@ InitMovementBuffer:: ; 1b1e
ld a, HIGH(wMovementBuffer)
ld [wUnusedMovementBufferPointer + 1], a
ret
-; 1b35
-DecrementMovementBufferCount:: ; 1b35
+DecrementMovementBufferCount::
ld a, [wMovementBufferCount]
and a
ret z
dec a
ld [wMovementBufferCount], a
ret
-; 1b3f
-AppendToMovementBuffer:: ; 1b3f
+AppendToMovementBuffer::
push hl
push de
ld hl, wMovementBufferCount
@@ -33,9 +31,8 @@ AppendToMovementBuffer:: ; 1b3f
pop de
pop hl
ret
-; 1b50
-AppendToMovementBufferNTimes:: ; 1b50
+AppendToMovementBufferNTimes::
push af
ld a, c
and a
@@ -50,9 +47,8 @@ AppendToMovementBufferNTimes:: ; 1b50
dec c
jr nz, .loop
ret
-; 1b5f
-ComputePathToWalkToPlayer:: ; 1b5f
+ComputePathToWalkToPlayer::
push af
; compare x coords, load left/right into h, and x distance into d
ld a, b
@@ -100,9 +96,8 @@ ComputePathToWalkToPlayer:: ; 1b5f
ld c, e
call AppendToMovementBufferNTimes
ret
-; 1b92
-.GetMovementData: ; 1b92
+.GetMovementData:
push de
push hl
ld l, b
@@ -118,7 +113,6 @@ ComputePathToWalkToPlayer:: ; 1b5f
pop hl
pop de
ret
-; 1ba5
.MovementData:
slow_step DOWN
@@ -133,9 +127,8 @@ ComputePathToWalkToPlayer:: ; 1b5f
big_step UP
big_step LEFT
big_step RIGHT
-; 1bb1
-SetMenuAttributes:: ; 1bb1
+SetMenuAttributes::
push hl
push bc
ld hl, w2DMenuCursorInitY
@@ -156,21 +149,18 @@ SetMenuAttributes:: ; 1bb1
pop bc
pop hl
ret
-; 1bc9
-StaticMenuJoypad:: ; 1bc9
+StaticMenuJoypad::
callfar _StaticMenuJoypad
call GetMenuJoypad
ret
-; 1bd3
-ScrollingMenuJoypad:: ; 1bd3
+ScrollingMenuJoypad::
callfar _ScrollingMenuJoypad
call GetMenuJoypad
ret
-; 1bdd
-GetMenuJoypad:: ; 1bdd
+GetMenuJoypad::
push bc
push af
ld a, [hJoyLast]
@@ -184,23 +174,19 @@ GetMenuJoypad:: ; 1bdd
ld a, b
pop bc
ret
-; 1bee
-PlaceHollowCursor:: ; 1bee
+PlaceHollowCursor::
ld hl, wCursorCurrentTile
ld a, [hli]
ld h, [hl]
ld l, a
ld [hl], "▷"
ret
-; 1bf7
-HideCursor:: ; 1bf7
+HideCursor::
ld hl, wCursorCurrentTile
ld a, [hli]
ld h, [hl]
ld l, a
ld [hl], " "
ret
-; 1c00
-
diff --git a/home/names.asm b/home/names.asm
index 90a15c093..e9c36fc1d 100644
--- a/home/names.asm
+++ b/home/names.asm
@@ -1,4 +1,4 @@
-NamesPointers:: ; 33ab
+NamesPointers::
; entries correspond to GetName constants (see constants/text_constants.asm)
dba PokemonNames ; MON_NAME (not used; jumps to GetPokemonName)
dba MoveNames ; MOVE_NAME
@@ -8,9 +8,8 @@ NamesPointers:: ; 33ab
dbw 0, wOTPartyMonOT ; ENEMY_OT_NAME
dba TrainerClassNames ; TRAINER_NAME
dbw 4, MoveDescriptions ; MOVE_DESC_NAME_BROKEN (wrong bank)
-; 33c3
-GetName:: ; 33c3
+GetName::
; Return name wCurSpecies from name list wNamedObjectTypeBuffer in wStringBuffer1.
ld a, [hROMBank]
@@ -67,9 +66,8 @@ GetName:: ; 33c3
pop af
rst Bankswitch
ret
-; 3411
-GetNthString:: ; 3411
+GetNthString::
; Return the address of the
; ath string starting from hl.
@@ -87,9 +85,8 @@ GetNthString:: ; 3411
jr nz, .readChar
pop bc
ret
-; 3420
-GetBasePokemonName:: ; 3420
+GetBasePokemonName::
; Discards gender (Nidoran).
push hl
@@ -112,9 +109,7 @@ GetBasePokemonName:: ; 3420
pop hl
ret
-; 343b
-
-GetPokemonName:: ; 343b
+GetPokemonName::
; Get Pokemon name wd265.
ld a, [hROMBank]
@@ -150,9 +145,8 @@ GetPokemonName:: ; 343b
pop af
rst Bankswitch
ret
-; 3468
-GetItemName:: ; 3468
+GetItemName::
; Get item name wd265.
push hl
@@ -174,9 +168,8 @@ GetItemName:: ; 3468
pop bc
pop hl
ret
-; 3487
-GetTMHMName:: ; 3487
+GetTMHMName::
; Get TM/HM name by item id wd265.
push hl
@@ -257,11 +250,10 @@ GetTMHMName:: ; 3487
db "HM"
.HMTextEnd:
db "@"
-; 34df
INCLUDE "home/hm_moves.asm"
-GetMoveName:: ; 34f8
+GetMoveName::
push hl
ld a, MOVE_NAME
@@ -275,4 +267,3 @@ GetMoveName:: ; 34f8
pop hl
ret
-; 350c
diff --git a/home/palettes.asm b/home/palettes.asm
index 9f10da118..d5b6abff5 100644
--- a/home/palettes.asm
+++ b/home/palettes.asm
@@ -1,7 +1,6 @@
; Functions dealing with palettes.
-
-UpdatePalsIfCGB:: ; c2f
+UpdatePalsIfCGB::
; update bgp data from wBGPals2
; update obp data from wOBPals2
; return carry if successful
@@ -11,17 +10,14 @@ UpdatePalsIfCGB:: ; c2f
and a
ret z
-
-UpdateCGBPals:: ; c33
+UpdateCGBPals::
; return carry if successful
; any pals to update?
ld a, [hCGBPalUpdate]
and a
ret z
-
-ForceUpdateCGBPals:: ; c37
-
+ForceUpdateCGBPals::
ld a, [rSVBK]
push af
ld a, BANK(wBGPals2)
@@ -68,10 +64,8 @@ endr
scf
ret
-; c9f
-
-DmgToCgbBGPals:: ; c9f
+DmgToCgbBGPals::
; exists to forego reinserting cgb-converted image data
; input: a -> bgp
@@ -114,10 +108,8 @@ DmgToCgbBGPals:: ; c9f
.end
pop af
ret
-; ccb
-
-DmgToCgbObjPals:: ; ccb
+DmgToCgbObjPals::
; exists to forego reinserting cgb-converted image data
; input: d -> obp1
@@ -160,10 +152,8 @@ DmgToCgbObjPals:: ; ccb
pop de
pop hl
ret
-; cf8
-
-DmgToCgbObjPal0:: ; cf8
+DmgToCgbObjPal0::
ld [rOBP0], a
push af
@@ -200,9 +190,8 @@ DmgToCgbObjPal0:: ; cf8
.dmg
pop af
ret
-; d24
-DmgToCgbObjPal1:: ; d24
+DmgToCgbObjPal1::
ld [rOBP1], a
push af
@@ -238,11 +227,8 @@ DmgToCgbObjPal1:: ; d24
.dmg
pop af
ret
-; d50
-
-
-CopyPals:: ; d50
+CopyPals::
; copy c palettes in order b from de to hl
push bc
@@ -253,7 +239,7 @@ CopyPals:: ; d50
; get pal color
ld a, b
- and %11 ; color
+ maskbits 1 << PAL_COLOR_SIZE
; 2 bytes per color
add a
ld l, a
@@ -271,8 +257,9 @@ CopyPals:: ; d50
ld [hl], d
inc hl
; next pal color
+rept PAL_COLOR_SIZE
srl b
- srl b
+endr
; source
pop de
; done pal?
@@ -280,7 +267,7 @@ CopyPals:: ; d50
jr nz, .loop
; de += 8 (next pal)
- ld a, NUM_PAL_COLORS * 2
+ ld a, PALETTE_SIZE
add e
jr nc, .ok
inc d
@@ -292,10 +279,8 @@ CopyPals:: ; d50
dec c
jr nz, CopyPals
ret
-; d79
-
-ClearVBank1:: ; d79
+ClearVBank1::
ld a, [hCGB]
and a
ret z
@@ -311,15 +296,11 @@ ClearVBank1:: ; d79
ld a, 0
ld [rVBK], a
ret
-; d90
-
-ret_d90:: ; d90
+ret_d90::
ret
-; d91
-
-ReloadSpritesNoPalettes:: ; d91
+ReloadSpritesNoPalettes::
ld a, [hCGB]
and a
ret z
@@ -337,15 +318,11 @@ ReloadSpritesNoPalettes:: ; d91
ld [hCGBPalUpdate], a
call DelayFrame
ret
-; db1
-
-FarCallSwapTextboxPalettes:: ; db1
+FarCallSwapTextboxPalettes::
homecall SwapTextboxPalettes
ret
-; dbd
-FarCallScrollBGMapPalettes:: ; dbd
+FarCallScrollBGMapPalettes::
homecall ScrollBGMapPalettes
ret
-; dc9
diff --git a/home/pokedex_flags.asm b/home/pokedex_flags.asm
index e9ca2163e..809341509 100644
--- a/home/pokedex_flags.asm
+++ b/home/pokedex_flags.asm
@@ -1,4 +1,4 @@
-SetSeenAndCaughtMon:: ; 3380
+SetSeenAndCaughtMon::
push af
ld c, a
ld hl, wPokedexCaught
@@ -6,33 +6,28 @@ SetSeenAndCaughtMon:: ; 3380
call PokedexFlagAction
pop af
; fallthrough
-; 338b
-SetSeenMon:: ; 338b
+SetSeenMon::
ld c, a
ld hl, wPokedexSeen
ld b, SET_FLAG
jr PokedexFlagAction
-; 3393
-CheckCaughtMon:: ; 3393
+CheckCaughtMon::
ld c, a
ld hl, wPokedexCaught
ld b, CHECK_FLAG
jr PokedexFlagAction
-; 339b
-CheckSeenMon:: ; 339b
+CheckSeenMon::
ld c, a
ld hl, wPokedexSeen
ld b, CHECK_FLAG
; fallthrough
-; 33a1
-PokedexFlagAction:: ; 33a1
+PokedexFlagAction::
ld d, 0
predef SmallFarFlagAction
ld a, c
and a
ret
-; 33ab
diff --git a/home/predef.asm b/home/predef.asm
index f03bdaa94..e829bdc00 100644
--- a/home/predef.asm
+++ b/home/predef.asm
@@ -1,4 +1,4 @@
-Predef:: ; 2d83
+Predef::
; Call predefined function a.
; Preserves bc, de, hl and f.
@@ -50,4 +50,3 @@ Predef:: ; 2d83
ld a, [wPredefTemp + 1]
ld l, a
ret
-; 2dba
diff --git a/home/print_bcd.asm b/home/print_bcd.asm
new file mode 100644
index 000000000..4f93c866f
--- /dev/null
+++ b/home/print_bcd.asm
@@ -0,0 +1,79 @@
+PrintBCDNumber::
+; function to print a BCD (Binary-coded decimal) number
+; de = address of BCD number
+; hl = destination address
+; c = flags and length
+; bit 7: if set, do not print leading zeroes
+; if unset, print leading zeroes
+; bit 6: if set, left-align the string (do not pad empty digits with spaces)
+; if unset, right-align the string
+; bit 5: if set, print currency symbol at the beginning of the string
+; if unset, do not print the currency symbol
+; bits 0-4: length of BCD number in bytes
+; Note that bits 5 and 7 are modified during execution. The above reflects
+; their meaning at the beginning of the functions's execution.
+ ld b, c ; save flags in b
+ res 7, c
+ res 6, c
+ res 5, c ; c now holds the length
+ bit 5, b
+ jr z, .loop
+ bit 7, b
+ jr nz, .loop ; skip currency symbol
+ ld [hl], "¥"
+ inc hl
+.loop
+ ld a, [de]
+ swap a
+ call PrintBCDDigit ; print upper digit
+ ld a, [de]
+ call PrintBCDDigit ; print lower digit
+ inc de
+ dec c
+ jr nz, .loop
+ bit 7, b ; were any non-zero digits printed?
+ jr z, .done ; if so, we are done
+.numberEqualsZero ; if every digit of the BCD number is zero
+ bit 6, b ; left or right alignment?
+ jr nz, .skipRightAlignmentAdjustment
+ dec hl ; if the string is right-aligned, it needs to be moved back one space
+.skipRightAlignmentAdjustment
+ bit 5, b
+ jr z, .skipCurrencySymbol
+ ld [hl], "¥" ; currency symbol
+ inc hl
+.skipCurrencySymbol
+ ld [hl], "0"
+ call PrintLetterDelay
+ inc hl
+.done
+ ret
+
+PrintBCDDigit::
+ and %00001111
+ and a
+ jr z, .zeroDigit
+.nonzeroDigit
+ bit 7, b ; have any non-space characters been printed?
+ jr z, .outputDigit
+; if bit 7 is set, then no numbers have been printed yet
+ bit 5, b ; print the currency symbol?
+ jr z, .skipCurrencySymbol
+ ld [hl], "¥"
+ inc hl
+ res 5, b
+.skipCurrencySymbol
+ res 7, b ; unset 7 to indicate that a nonzero digit has been reached
+.outputDigit
+ add "0"
+ ld [hli], a
+ jp PrintLetterDelay
+
+.zeroDigit
+ bit 7, b ; either printing leading zeroes or already reached a nonzero digit?
+ jr z, .outputDigit ; if so, print a zero digit
+ bit 6, b ; left or right alignment?
+ ret nz
+ ld a, " "
+ ld [hli], a ; if right-aligned, "print" a space by advancing the pointer
+ ret
diff --git a/home/print_level.asm b/home/print_level.asm
new file mode 100644
index 000000000..2ebbbf980
--- /dev/null
+++ b/home/print_level.asm
@@ -0,0 +1,28 @@
+PrintLevel::
+; Print wTempMonLevel at hl
+
+ ld a, [wTempMonLevel]
+ ld [hl], "<LV>"
+ inc hl
+
+; How many digits?
+ ld c, 2
+ cp 100 ; This is distinct from MAX_LEVEL.
+ jr c, Print8BitNumRightAlign
+
+; 3-digit numbers overwrite the :L.
+ dec hl
+ inc c
+ jr Print8BitNumRightAlign
+
+PrintLevel_Force3Digits::
+; Print :L and all 3 digits
+ ld [hl], "<LV>"
+ inc hl
+ ld c, 3
+
+Print8BitNumRightAlign::
+ ld [wd265], a
+ ld de, wd265
+ ld b, PRINTNUM_RIGHTALIGN | 1
+ jp PrintNum
diff --git a/home/print_text.asm b/home/print_text.asm
new file mode 100644
index 000000000..8a8a7dd9f
--- /dev/null
+++ b/home/print_text.asm
@@ -0,0 +1,120 @@
+PrintLetterDelay::
+; Wait before printing the next letter.
+
+; The text speed setting in wOptions is actually a frame count:
+; fast: 1 frame
+; mid: 3 frames
+; slow: 5 frames
+
+; wTextBoxFlags[!0] and A or B override text speed with a one-frame delay.
+; wOptions[4] and wTextBoxFlags[!1] disable the delay.
+
+ ld a, [wOptions]
+ bit NO_TEXT_SCROLL, a
+ ret nz
+
+; non-scrolling text?
+ ld a, [wTextBoxFlags]
+ bit NO_TEXT_DELAY_F, a
+ ret z
+
+ push hl
+ push de
+ push bc
+
+ ld hl, hOAMUpdate
+ ld a, [hl]
+ push af
+
+; orginally turned oam update off...
+; ld a, 1
+ ld [hl], a
+
+; force fast scroll?
+ ld a, [wTextBoxFlags]
+ bit FAST_TEXT_DELAY_F, a
+ jr z, .fast
+
+; text speed
+ ld a, [wOptions]
+ and %111
+ jr .updatedelay
+
+.fast
+ ld a, TEXT_DELAY_FAST
+
+.updatedelay
+ ld [wTextDelayFrames], a
+
+.checkjoypad
+ call GetJoypad
+
+; input override
+ ld a, [wDisableTextAcceleration]
+ and a
+ jr nz, .wait
+
+; Wait one frame if holding A or B.
+ ld a, [hJoyDown]
+ bit A_BUTTON_F, a
+ jr z, .checkb
+ jr .delay
+.checkb
+ bit B_BUTTON_F, a
+ jr z, .wait
+
+.delay
+ call DelayFrame
+ jr .end
+
+.wait
+ ld a, [wTextDelayFrames]
+ and a
+ jr nz, .checkjoypad
+
+.end
+ pop af
+ ld [hOAMUpdate], a
+ pop bc
+ pop de
+ pop hl
+ ret
+
+CopyDataUntil::
+; Copy [hl .. bc) to de.
+
+; In other words, the source data is
+; from hl up to but not including bc,
+; and the destination is de.
+
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, h
+ cp b
+ jr nz, CopyDataUntil
+ ld a, l
+ cp c
+ jr nz, CopyDataUntil
+ ret
+
+PrintNum::
+ homecall _PrintNum
+ ret
+
+MobilePrintNum::
+ homecall _MobilePrintNum
+ ret
+
+FarPrintText::
+ ld [hBuffer], a
+ ld a, [hROMBank]
+ push af
+ ld a, [hBuffer]
+ rst Bankswitch
+
+ call PrintText
+
+ pop af
+ rst Bankswitch
+ ret
diff --git a/home/random.asm b/home/random.asm
index ceefdce6f..e436e4ff6 100644
--- a/home/random.asm
+++ b/home/random.asm
@@ -1,4 +1,4 @@
-Random:: ; 2f8c
+Random::
; A simple hardware-based random number generator (RNG).
; Two random numbers are generated by adding and subtracting
@@ -27,9 +27,8 @@ Random:: ; 2f8c
pop bc
ret
-; 2f9f
-BattleRandom:: ; 2f9f
+BattleRandom::
; _BattleRandom lives in another bank.
; It handles all RNG calls in the battle engine, allowing
@@ -47,10 +46,8 @@ BattleRandom:: ; 2f9f
rst Bankswitch
ld a, [wPredefTemp + 1]
ret
-; 2fb1
-
-RandomRange:: ; 2fb1
+RandomRange::
; Return a random number between 0 and a (non-inclusive).
push bc
@@ -81,4 +78,3 @@ RandomRange:: ; 2fb1
pop bc
ret
-; 2fcb
diff --git a/home/region.asm b/home/region.asm
new file mode 100644
index 000000000..4cb3d4768
--- /dev/null
+++ b/home/region.asm
@@ -0,0 +1,32 @@
+IsInJohto::
+; Return 0 if the player is in Johto, and 1 in Kanto.
+
+ ld a, [wMapGroup]
+ ld b, a
+ ld a, [wMapNumber]
+ ld c, a
+ call GetWorldMapLocation
+
+ cp FAST_SHIP
+ jr z, .Johto
+
+ cp SPECIAL_MAP
+ jr nz, .CheckRegion
+
+ ld a, [wBackupMapGroup]
+ ld b, a
+ ld a, [wBackupMapNumber]
+ ld c, a
+ call GetWorldMapLocation
+
+.CheckRegion:
+ cp KANTO_LANDMARK
+ jr nc, .Kanto
+
+.Johto:
+ xor a
+ ret
+
+.Kanto:
+ ld a, 1
+ ret
diff --git a/home/rst.asm b/home/rst.asm
index 1c9b5f6e4..c3abae80d 100644
--- a/home/rst.asm
+++ b/home/rst.asm
@@ -1,24 +1,24 @@
; rst vectors
-SECTION "rst0",ROM0
+SECTION "rst0", ROM0
di
jp Start
-SECTION "rst8",ROM0
+SECTION "rst8", ROM0 ; rst FarCall
jp FarCall_hl
-SECTION "rst10",ROM0
+SECTION "rst10", ROM0 ; rst Bankswitch
ld [hROMBank], a
ld [MBC3RomBank], a
ret
-SECTION "rst18",ROM0
+SECTION "rst18", ROM0
rst $38
-SECTION "rst20",ROM0
+SECTION "rst20", ROM0
rst $38
-SECTION "rst28",ROM0
+SECTION "rst28", ROM0 ; rst JumpTable
push de
ld e, a
ld d, 0
@@ -30,8 +30,8 @@ SECTION "rst28",ROM0
pop de
jp hl
-; SECTION "rst30",ROM0
+; SECTION "rst30", ROM0
; rst30 is midst rst28
-SECTION "rst38",ROM0
+SECTION "rst38", ROM0
rst $38
diff --git a/home/rtc.asm b/home/rtc.asm
index 9b8bc4ac3..0e5550485 100644
--- a/home/rtc.asm
+++ b/home/rtc.asm
@@ -1,4 +1,4 @@
-RTC:: ; 46f
+RTC::
; update time and time-sensitive palettes
; rtc enabled?
@@ -13,12 +13,10 @@ RTC:: ; 46f
bit 0, a ; obj update
ret z
-TimeOfDayPals:: ; 47e
+TimeOfDayPals::
callfar _TimeOfDayPals
ret
-; 485
-UpdateTimePals:: ; 485
+UpdateTimePals::
callfar _UpdateTimePals
ret
-; 48c
diff --git a/home/scrolling_menu.asm b/home/scrolling_menu.asm
new file mode 100644
index 000000000..cf8e02fa8
--- /dev/null
+++ b/home/scrolling_menu.asm
@@ -0,0 +1,61 @@
+ScrollingMenu::
+ call CopyMenuData
+ ld a, [hROMBank]
+ push af
+
+ ld a, BANK(_ScrollingMenu)
+ rst Bankswitch
+
+ call _InitScrollingMenu
+ call .UpdatePalettes
+ call _ScrollingMenu
+
+ pop af
+ rst Bankswitch
+
+ ld a, [wMenuJoypad]
+ ret
+
+.UpdatePalettes:
+ ld hl, wVramState
+ bit 0, [hl]
+ jp nz, UpdateTimePals
+ jp SetPalettes
+
+InitScrollingMenu::
+ ld a, [wMenuBorderTopCoord]
+ dec a
+ ld b, a
+ ld a, [wMenuBorderBottomCoord]
+ sub b
+ ld d, a
+ ld a, [wMenuBorderLeftCoord]
+ dec a
+ ld c, a
+ ld a, [wMenuBorderRightCoord]
+ sub c
+ ld e, a
+ push de
+ call Coord2Tile
+ pop bc
+ jp TextBox
+
+JoyTextDelay_ForcehJoyDown::
+ call DelayFrame
+
+ ld a, [hInMenu]
+ push af
+ ld a, $1
+ ld [hInMenu], a
+ call JoyTextDelay
+ pop af
+ ld [hInMenu], a
+
+ ld a, [hJoyLast]
+ and D_RIGHT + D_LEFT + D_UP + D_DOWN
+ ld c, a
+ ld a, [hJoyPressed]
+ and A_BUTTON + B_BUTTON + SELECT + START
+ or c
+ ld c, a
+ ret
diff --git a/home/serial.asm b/home/serial.asm
index c32e559dd..663f74d3b 100644
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -1,4 +1,4 @@
-Serial:: ; 6ef
+Serial::
; The serial interrupt.
push af
@@ -87,9 +87,8 @@ Serial:: ; 6ef
pop bc
pop af
reti
-; 75f
-Serial_ExchangeBytes:: ; 75f
+Serial_ExchangeBytes::
ld a, $1
ld [hSerialIgnoringInitialData], a
.loop
@@ -123,9 +122,8 @@ Serial_ExchangeBytes:: ; 75f
or c
jr nz, .loop
ret
-; 78a
-Serial_ExchangeByte:: ; 78a
+Serial_ExchangeByte::
.loop
xor a
ld [hSerialReceivedNewData], a
@@ -232,27 +230,24 @@ Serial_ExchangeByte:: ; 78a
dec a
jr nz, .delay_cycles
ret
-; 82b
-CheckwLinkTimeoutFramesNonzero:: ; 82b
+CheckwLinkTimeoutFramesNonzero::
push hl
ld hl, wLinkTimeoutFrames
ld a, [hli]
or [hl]
pop hl
ret
-; 833
-SerialDisconnected:: ; 833
+SerialDisconnected::
dec a ; a is always 0 when this is called
ld [wLinkTimeoutFrames], a
ld [wLinkTimeoutFrames + 1], a
ret
-; 83b
; This is used to exchange the button press and selected menu item on the link menu.
; The data is sent thrice and read twice to increase reliability.
-Serial_ExchangeLinkMenuSelection:: ; 83b
+Serial_ExchangeLinkMenuSelection::
ld hl, wPlayerLinkAction
ld de, wOtherPlayerLinkMode
ld c, 2
@@ -276,24 +271,21 @@ Serial_ExchangeLinkMenuSelection:: ; 83b
dec c
jr nz, .asm_847
ret
-; 862
-Serial_PrintWaitingTextAndSyncAndExchangeNybble:: ; 862
+Serial_PrintWaitingTextAndSyncAndExchangeNybble::
call LoadTileMapToTempTileMap
callfar PlaceWaitingText
call WaitLinkTransfer
jp Call_LoadTempTileMapToTileMap
-; 871
-Serial_SyncAndExchangeNybble:: ; 871
+Serial_SyncAndExchangeNybble::
call LoadTileMapToTempTileMap
callfar PlaceWaitingText
jp WaitLinkTransfer
-; 87d
; One "giant" leap for machinekind
-WaitLinkTransfer:: ; 87d
+WaitLinkTransfer::
ld a, $ff
ld [wOtherPlayerLinkAction], a
.loop
@@ -338,9 +330,8 @@ WaitLinkTransfer:: ; 87d
ld a, [wOtherPlayerLinkAction]
ld [wOtherPlayerLinkMode], a
ret
-; 8c1
-LinkTransfer:: ; 8c1
+LinkTransfer::
push bc
ld b, SERIAL_TIMECAPSULE
ld a, [wLinkMode]
@@ -370,9 +361,8 @@ LinkTransfer:: ; 8c1
call .Receive
pop bc
ret
-; 8f3
-.Receive: ; 8f3
+.Receive:
ld a, [hSerialReceive]
ld [wOtherPlayerLinkMode], a
and $f0
@@ -384,9 +374,8 @@ LinkTransfer:: ; 8c1
and $f
ld [wOtherPlayerLinkAction], a
ret
-; 908
-LinkDataReceived:: ; 908
+LinkDataReceived::
; Let the other system know that the data has been received.
xor a
ld [hSerialSend], a
@@ -398,9 +387,8 @@ LinkDataReceived:: ; 908
ld a, (1 << rSC_ON) | 1
ld [rSC], a
ret
-; 919
-Unreferenced_Function919:: ; 919
+Unreferenced_Function919::
ld a, [wLinkMode]
and a
ret nz
@@ -413,4 +401,3 @@ Unreferenced_Function919:: ; 919
ld a, 1 << rSC_ON
ld [rSC], a
ret
-; 92e
diff --git a/home/sine.asm b/home/sine.asm
index eff5ed299..821f7c47d 100644
--- a/home/sine.asm
+++ b/home/sine.asm
@@ -1,13 +1,9 @@
-Cosine:: ; 1b0f
-; Return d * cos(a) in hl
- add %010000 ; 90 degrees
-
-Sine:: ; 1b11
-; Return d * sin(a) in hl
-; a is a signed 6-bit value.
-
+Cosine::
+; a = d * cos(a * pi/32)
+ add %010000 ; cos(x) = sin(x + pi/2)
+ ; fallthrough
+Sine::
+; a = d * sin(a * pi/32)
ld e, a
-
homecall _Sine
ret
-; 1b1e
diff --git a/home/sprite_anims.asm b/home/sprite_anims.asm
new file mode 100644
index 000000000..5f3ef82d2
--- /dev/null
+++ b/home/sprite_anims.asm
@@ -0,0 +1,50 @@
+PushLYOverrides::
+ ld a, [hLCDCPointer]
+ and a
+ ret z
+
+ ld a, LOW(wLYOverridesBackup)
+ ld [wRequested2bppSource], a
+ ld a, HIGH(wLYOverridesBackup)
+ ld [wRequested2bppSource + 1], a
+
+ ld a, LOW(wLYOverrides)
+ ld [wRequested2bppDest], a
+ ld a, HIGH(wLYOverrides)
+ ld [wRequested2bppDest + 1], a
+
+ ld a, (wLYOverridesEnd - wLYOverrides) / 16
+ ld [wRequested2bpp], a
+ ret
+
+_InitSpriteAnimStruct::
+ ld [wSpriteAnimIDBuffer], a
+ ld a, [hROMBank]
+ push af
+
+ ld a, BANK(InitSpriteAnimStruct)
+ rst Bankswitch
+ ld a, [wSpriteAnimIDBuffer]
+
+ call InitSpriteAnimStruct
+
+ pop af
+ rst Bankswitch
+
+ ret
+
+ReinitSpriteAnimFrame::
+ ld [wSpriteAnimIDBuffer], a
+ ld a, [hROMBank]
+ push af
+
+ ld a, BANK(_ReinitSpriteAnimFrame)
+ rst Bankswitch
+ ld a, [wSpriteAnimIDBuffer]
+
+ call _ReinitSpriteAnimFrame
+
+ pop af
+ rst Bankswitch
+
+ ret
diff --git a/home/sprite_updates.asm b/home/sprite_updates.asm
new file mode 100644
index 000000000..d263363a6
--- /dev/null
+++ b/home/sprite_updates.asm
@@ -0,0 +1,19 @@
+DisableSpriteUpdates::
+ xor a
+ ld [hMapAnims], a
+ ld a, [wVramState]
+ res 0, a
+ ld [wVramState], a
+ ld a, $0
+ ld [wSpriteUpdatesEnabled], a
+ ret
+
+EnableSpriteUpdates::
+ ld a, $1
+ ld [wSpriteUpdatesEnabled], a
+ ld a, [wVramState]
+ set 0, a
+ ld [wVramState], a
+ ld a, $1
+ ld [hMapAnims], a
+ ret
diff --git a/home/sram.asm b/home/sram.asm
index 4cfe14cf9..1b1a4f318 100644
--- a/home/sram.asm
+++ b/home/sram.asm
@@ -1,12 +1,11 @@
-GetSRAMBank:: ; 2fcb
+GetSRAMBank::
; load sram bank a
; if invalid bank, sram is disabled
cp NUM_SRAM_BANKS
jr c, OpenSRAM
jr CloseSRAM
-; 2fd1
-OpenSRAM:: ; 2fd1
+OpenSRAM::
; switch to sram bank a
push af
; latch clock data
@@ -19,9 +18,8 @@ OpenSRAM:: ; 2fd1
pop af
ld [MBC3SRamBank], a
ret
-; 2fe1
-CloseSRAM:: ; 2fe1
+CloseSRAM::
push af
ld a, SRAM_DISABLE
; reset clock latch for next time
@@ -30,4 +28,3 @@ CloseSRAM:: ; 2fe1
ld [MBC3SRamEnable], a
pop af
ret
-; 2fec
diff --git a/home/stone_queue.asm b/home/stone_queue.asm
new file mode 100644
index 000000000..b635cee16
--- /dev/null
+++ b/home/stone_queue.asm
@@ -0,0 +1,138 @@
+HandleStoneQueue::
+ ld a, [hROMBank]
+ push af
+
+ call SwitchToMapScriptsBank
+ call .WarpAction
+
+ pop bc
+ ld a, b
+ rst Bankswitch
+ ret
+
+.WarpAction:
+ ld hl, OBJECT_MAP_OBJECT_INDEX
+ add hl, de
+ ld a, [hl]
+ cp $ff
+ jr z, .nope
+
+ ld l, a
+ push hl
+ call .IsObjectOnWarp
+ pop hl
+ jr nc, .nope
+ ld d, a
+ ld e, l
+ call .IsObjectInStoneTable
+ jr nc, .nope
+ call CallMapScript
+ farcall EnableScriptMode
+ scf
+ ret
+
+.nope
+ and a
+ ret
+
+.IsObjectOnWarp:
+ push de
+
+ ld hl, OBJECT_NEXT_MAP_X
+ add hl, de
+ ld a, [hl]
+ ld hl, OBJECT_NEXT_MAP_Y
+ add hl, de
+ ld e, [hl]
+
+ sub 4
+ ld d, a
+ ld a, e
+ sub 4
+ ld e, a
+ call .check_on_warp
+
+ pop de
+ ret
+
+.check_on_warp
+ ld hl, wCurrMapWarpsPointer
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld a, [wCurrMapWarpCount]
+ and a
+ jr z, .nope2
+
+.loop
+ push af
+ ld a, [hl]
+ cp e
+ jr nz, .not_on_warp
+ inc hl
+ ld a, [hld]
+ cp d
+ jr nz, .not_on_warp
+ jr .found_warp
+
+.not_on_warp
+ ld a, 5
+ add l
+ ld l, a
+ jr nc, .no_carry
+ inc h
+.no_carry
+
+ pop af
+ dec a
+ jr nz, .loop
+
+.nope2
+ and a
+ ret
+
+.found_warp
+ pop af
+ ld d, a
+ ld a, [wCurrMapWarpCount]
+ sub d
+ inc a
+ scf
+ ret
+
+.IsObjectInStoneTable:
+ inc e
+ ld hl, CMDQUEUE_ADDR
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+.loop2
+ ld a, [hli]
+ cp $ff
+ jr z, .nope3
+ cp d
+ jr nz, .next_inc3
+ ld a, [hli]
+ cp e
+ jr nz, .next_inc2
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jr .yes
+
+.next_inc3
+ inc hl
+
+.next_inc2
+ inc hl
+ inc hl
+ jr .loop2
+
+.nope3
+ and a
+ ret
+
+.yes
+ scf
+ ret
diff --git a/home/string.asm b/home/string.asm
index 492246832..702ab50ff 100644
--- a/home/string.asm
+++ b/home/string.asm
@@ -1,14 +1,13 @@
-InitString:: ; 2ef6
+InitString::
; Init a string of length c.
push hl
jr _InitString
-; 2ef9
-InitName:: ; 2ef9
+InitName::
; Intended for names, so this function is limited to ten characters.
push hl
ld c, 10
-_InitString:: ; 2efc
+_InitString::
; if the string pointed to by hl is empty (defined as "zero or more spaces
; followed by a null"), then initialize it to the string pointed to by de.
push bc
@@ -34,4 +33,3 @@ _InitString:: ; 2efc
pop bc
pop hl
ret
-; 2f17
diff --git a/home/text.asm b/home/text.asm
index 5e7e66d43..ef952942d 100644
--- a/home/text.asm
+++ b/home/text.asm
@@ -1,4 +1,4 @@
-ClearBox:: ; fb6
+ClearBox::
; Fill a c*b box at hl with blank tiles.
ld a, " "
; fallthrough
@@ -18,10 +18,8 @@ FillBoxWithByte::
dec b
jr nz, .row
ret
-; fc8
-
-ClearTileMap:: ; fc8
+ClearTileMap::
; Fill wTileMap with blank tiles.
hlcoord 0, 0
@@ -34,19 +32,15 @@ ClearTileMap:: ; fc8
bit rLCDC_ENABLE, a
ret z
jp WaitBGMap
-; fdb
-
-ClearScreen:: ; fdb
+ClearScreen::
ld a, PAL_BG_TEXT
hlcoord 0, 0, wAttrMap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call ByteFill
jr ClearTileMap
-; fe8
-
-TextBox:: ; fe8
+TextBox::
; Draw a text box at hl with room for b lines of c characters each.
; Places a border around the textbox, then switches the palette to the
; text black-and-white scheme.
@@ -56,11 +50,8 @@ TextBox:: ; fe8
pop hl
pop bc
jr TextBoxPalette
-; ff1
-
-
-TextBoxBorder:: ; ff1
+TextBoxBorder::
; Top
push hl
ld a, "┌"
@@ -96,9 +87,8 @@ TextBoxBorder:: ; ff1
ld [hl], "┘"
ret
-; 101e
-.PlaceChars: ; 101e
+.PlaceChars:
; Place char a c times.
ld d, c
.loop
@@ -106,10 +96,8 @@ TextBoxBorder:: ; ff1
dec d
jr nz, .loop
ret
-; 1024
-
-TextBoxPalette:: ; 1024
+TextBoxPalette::
; Fill text box width c height b at hl with pal 7
ld de, wAttrMap - wTileMap
add hl, de
@@ -132,58 +120,49 @@ TextBoxPalette:: ; 1024
dec b
jr nz, .col
ret
-; 103e
-
-SpeechTextBox:: ; 103e
+SpeechTextBox::
; Standard textbox.
hlcoord TEXTBOX_X, TEXTBOX_Y
ld b, TEXTBOX_INNERH
ld c, TEXTBOX_INNERW
jp TextBox
-; 1048
-TestText:: ; 1048
+TestText::
text "ゲームフりーク!"
done
-; 1052
-RadioTerminator:: ; 1052
+RadioTerminator::
ld hl, .stop
ret
.stop db "@"
-; 1057
-
-PrintText:: ; 1057
+PrintText::
call SetUpTextBox
-BuenaPrintText:: ; 105a
+BuenaPrintText::
push hl
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
lb bc, TEXTBOX_INNERH - 1, TEXTBOX_INNERW
call ClearBox
pop hl
-PrintTextBoxText:: ; 1065
+PrintTextBoxText::
bccoord TEXTBOX_INNERX, TEXTBOX_INNERY
call PlaceHLTextAtBC
ret
-; 106c
-SetUpTextBox:: ; 106c
+SetUpTextBox::
push hl
call SpeechTextBox
call UpdateSprites
call ApplyTilemap
pop hl
ret
-; 1078
-
-PlaceString:: ; 1078
+PlaceString::
push hl
-PlaceNextChar:: ; 1079
+PlaceNextChar::
ld a, [de]
cp "@"
jr nz, CheckDict
@@ -193,32 +172,36 @@ PlaceNextChar:: ; 1079
ret
pop de
-NextChar:: ; 1083
+NextChar::
inc de
jp PlaceNextChar
-CheckDict:: ; 1087
+CheckDict::
dict: MACRO
-if \1 == 0
+if \1 == "<NULL>"
and a
else
cp \1
endc
- jp z, \2
-ENDM
-dict2: MACRO
- cp \1
+if STRSUB("\2", 1, 1) == "\""
+; Replace a character with another one
jr nz, ._\@
ld a, \2
._\@:
+elif STRSUB("\2", 1, 1) == "."
+; Locals can use a short jump
+ jr z, \2
+else
+ jp z, \2
+endc
ENDM
- dict TX_DAY, DayOfWeekChar
+ dict "<MOBILE>", MobileScriptChar
dict "<LINE>", LineChar
dict "<NEXT>", NextLineChar
- dict TX_FAR, TextFar
- dict TX_START, NullChar
+ dict "<CR>", CarriageReturnChar
+ dict "<NULL>", NullChar
dict "<SCROLL>", _ContTextNoPause
dict "<_CONT>", _ContText
dict "<PARA>", Paragraph
@@ -236,7 +219,7 @@ ENDM
dict "<TM>", TMChar
dict "<TRAINER>", TrainerChar
dict "<KOUGEKI>", PlaceKougeki
- dict "<LNBRK>", LineBreakChar
+ dict "<LF>", LineFeedChar
dict "<CONT>", ContText
dict "<……>", SixDotsChar
dict "<DONE>", DoneText
@@ -244,17 +227,14 @@ ENDM
dict "<PKMN>", PlacePKMN
dict "<POKE>", PlacePOKE
dict "%", NextChar
- dict2 "¯", " "
+ dict "¯", " "
dict "<DEXEND>", PlaceDexEnd
dict "<TARGET>", PlaceMoveTargetsName
dict "<USER>", PlaceMoveUsersName
dict "<ENEMY>", PlaceEnemysName
dict "<PLAY_G>", PlaceGenderedPlayerName
-
- cp "゚"
- jr z, .place ; should be .diacritic
- cp "゙"
- jr z, .place ; should be .diacritic
+ dict "゚", .place ; should be .diacritic
+ dict "゙", .place ; should be .diacritic
jr .not_diacritic
.diacritic
@@ -296,16 +276,12 @@ ENDM
ld [hli], a
call PrintLetterDelay
jp NextChar
-; 0x117b
-
-DayOfWeekChar:: ; 117b
+MobileScriptChar::
ld c, l
ld b, h
- farcall Function17f036
+ farcall RunMobileScript
jp PlaceNextChar
-; 1186
-
print_name: MACRO
push de
@@ -313,35 +289,34 @@ print_name: MACRO
jp PlaceCommandCharacter
ENDM
-PrintMomsName: print_name wMomsName ; 1186
-PrintPlayerName: print_name wPlayerName ; 118d
-PrintRivalName: print_name wRivalName ; 1194
-PrintRedsName: print_name wRedsName ; 119b
-PrintGreensName: print_name wGreensName ; 11a2
-
-TrainerChar: print_name TrainerCharText ; 11a9
-TMChar: print_name TMCharText ; 11b0
-PCChar: print_name PCCharText ; 11b7
-RocketChar: print_name RocketCharText ; 11be
-PlacePOKe: print_name PlacePOKeText ; 11c5
-PlaceKougeki: print_name KougekiText ; 11cc
-SixDotsChar: print_name SixDotsCharText ; 11d3
-PlacePKMN: print_name PlacePKMNText ; 11da
-PlacePOKE: print_name PlacePOKEText ; 11e1
-PlaceJPRoute: print_name PlaceJPRouteText ; 11e8
-PlaceWatashi: print_name PlaceWatashiText ; 11ef
-PlaceKokoWa: print_name PlaceKokoWaText ; 11f6
-
-
-PlaceMoveTargetsName:: ; 11fd
+PrintMomsName: print_name wMomsName
+PrintPlayerName: print_name wPlayerName
+PrintRivalName: print_name wRivalName
+PrintRedsName: print_name wRedsName
+PrintGreensName: print_name wGreensName
+
+TrainerChar: print_name TrainerCharText
+TMChar: print_name TMCharText
+PCChar: print_name PCCharText
+RocketChar: print_name RocketCharText
+PlacePOKe: print_name PlacePOKeText
+PlaceKougeki: print_name KougekiText
+SixDotsChar: print_name SixDotsCharText
+PlacePKMN: print_name PlacePKMNText
+PlacePOKE: print_name PlacePOKEText
+PlaceJPRoute: print_name PlaceJPRouteText
+PlaceWatashi: print_name PlaceWatashiText
+PlaceKokoWa: print_name PlaceKokoWaText
+
+PlaceMoveTargetsName::
ld a, [hBattleTurn]
xor 1
jr PlaceMoveUsersName.place
-PlaceMoveUsersName:: ; 1203
+PlaceMoveUsersName::
ld a, [hBattleTurn]
-.place: ; 1205
+.place:
push de
and a
jr nz, .enemy
@@ -357,8 +332,7 @@ PlaceMoveUsersName:: ; 1203
ld de, wEnemyMonNick
jr PlaceCommandCharacter
-
-PlaceEnemysName:: ; 121b
+PlaceEnemysName::
push de
ld a, [wLinkMode]
@@ -391,28 +365,25 @@ PlaceEnemysName:: ; 121b
ld de, wOTClassName
jr PlaceCommandCharacter
-
-PlaceGenderedPlayerName:: ; 1252
+PlaceGenderedPlayerName::
push de
ld de, wPlayerName
call PlaceString
ld h, b
ld l, c
ld a, [wPlayerGender]
- bit 0, a
+ bit PLAYERGENDER_FEMALE_F, a
ld de, KunSuffixText
jr z, PlaceCommandCharacter
ld de, ChanSuffixText
jr PlaceCommandCharacter
-
-PlaceCommandCharacter:: ; 126a
+PlaceCommandCharacter::
call PlaceString
ld h, b
ld l, c
pop de
jp NextChar
-; 0x1273
TMCharText:: db "TM@"
TrainerCharText:: db "TRAINER@"
@@ -431,25 +402,22 @@ PlaceWatashiText::
PlaceKokoWaText:: db "@"
KunSuffixText:: db "@"
ChanSuffixText:: db "@"
-; 12a7
-NextLineChar:: ; 12a7
+NextLineChar::
pop hl
ld bc, SCREEN_WIDTH * 2
add hl, bc
push hl
jp NextChar
-; 12b0
-LineBreakChar:: ; 12b0
+LineFeedChar::
pop hl
ld bc, SCREEN_WIDTH
add hl, bc
push hl
jp NextChar
-; 12b9
-TextFar:: ; 12b9
+CarriageReturnChar::
pop hl
push de
ld bc, -wTileMap + $10000
@@ -489,17 +457,14 @@ TextFar:: ; 12b9
add hl, bc
push hl
jp NextChar
-; 12ea
-
-LineChar:: ; 12ea
+LineChar::
pop hl
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
push hl
jp NextChar
-; 0x12f2
-Paragraph:: ; 12f2
+Paragraph::
push de
ld a, [wLinkMode]
@@ -521,10 +486,8 @@ Paragraph:: ; 12f2
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
pop de
jp NextChar
-; 131f
-
-_ContText:: ; 131f
+_ContText::
ld a, [wLinkMode]
or a
jr nz, .communication
@@ -542,17 +505,15 @@ _ContText:: ; 131f
call z, UnloadBlinkingCursor
; fallthrough
-_ContTextNoPause:: ; 1337
+_ContTextNoPause::
push de
call TextScroll
call TextScroll
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
pop de
jp NextChar
-; 1345
-
-ContText:: ; 1345
+ContText::
push de
ld de, .cont
ld b, h
@@ -564,18 +525,15 @@ ContText:: ; 1345
jp NextChar
.cont: db "<_CONT>@"
-; 1356
-
-PlaceDexEnd:: ; 1356
-; Legacy: ends a Pokédex entry (Red).
+PlaceDexEnd::
+; Ends a Pokédex entry in Gen 1.
; Dex entries are now regular strings.
ld [hl], "."
pop hl
ret
-; 135a
-PromptText:: ; 135a
+PromptText::
ld a, [wLinkMode]
cp LINK_COLOSSEUM
jr z, .ok
@@ -593,23 +551,21 @@ PromptText:: ; 135a
jr z, DoneText
call UnloadBlinkingCursor
-DoneText:: ; 137c
+DoneText::
pop hl
ld de, .stop
dec de
ret
.stop: db "@"
-; 1383
-NullChar:: ; 1383
+NullChar::
ld a, "?"
ld [hli], a
call PrintLetterDelay
jp NextChar
-; 138c
-TextScroll:: ; 138c
+TextScroll::
hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
decoord TEXTBOX_INNERX, TEXTBOX_INNERY - 1
ld a, TEXTBOX_INNERH - 1
@@ -640,9 +596,8 @@ TextScroll:: ; 138c
ld c, 5
call DelayFrames
ret
-; 13b6
-Text_WaitBGMap:: ; 13b6
+Text_WaitBGMap::
push bc
ld a, [hOAMUpdate]
push af
@@ -655,25 +610,21 @@ Text_WaitBGMap:: ; 13b6
ld [hOAMUpdate], a
pop bc
ret
-; 13c6
-Diacritic:: ; 13c6
+Diacritic::
ret
-; 13c7
-LoadBlinkingCursor:: ; 13c7
+LoadBlinkingCursor::
ld a, "▼"
ldcoord_a 18, 17
ret
-; 13cd
-UnloadBlinkingCursor:: ; 13cd
+UnloadBlinkingCursor::
lda_coord 17, 17
ldcoord_a 18, 17
ret
-; 13d4
-FarString:: ; 13d4
+FarString::
ld b, a
ld a, [hROMBank]
push af
@@ -685,17 +636,14 @@ FarString:: ; 13d4
pop af
rst Bankswitch
ret
-; 13e0
-PokeFluteTerminatorCharacter:: ; 13e0
+PokeFluteTerminatorCharacter::
ld hl, .stop
ret
.stop: db "@"
-; 13e5
-
-PlaceHLTextAtBC:: ; 13e5
+PlaceHLTextAtBC::
ld a, [wTextBoxFlags]
push af
set NO_TEXT_DELAY_F, a
@@ -706,9 +654,8 @@ PlaceHLTextAtBC:: ; 13e5
pop af
ld [wTextBoxFlags], a
ret
-; 13f6
-DoTextUntilTerminator:: ; 13f6
+DoTextUntilTerminator::
ld a, [hli]
cp "@"
ret z
@@ -732,37 +679,35 @@ DoTextUntilTerminator:: ; 13f6
; jp de
push de
ret
-; 1410
-TextCommands:: ; 1410
+TextCommands::
; entries correspond to TX_* constants (see macros/scripts/text.asm)
- dw Text_TX ; TX_START
- dw Text_TX_RAM ; TX_RAM
- dw Text_TX_BCD ; TX_BCD
- dw Text_TX_MOVE ; TX_MOVE
- dw Text_TX_BOX ; TX_BOX
- dw Text_TX_LOW ; TX_LOW
- dw Text_WAIT_BUTTON ; WAIT_BUTTON
- dw Text_TX_SCROLL ; TX_SCROLL
- dw Text_START_ASM ; START_ASM
- dw Text_TX_NUM ; TX_NUM
- dw Text_TX_EXIT ; TX_EXIT
- dw Text_PlaySound ; TX_SOUND_DEX_FANFARE_50_79
- dw Text_TX_DOTS ; TX_DOTS
- dw Text_LINK_WAIT_BUTTON ; TX_LINK_WAIT_BUTTON
- dw Text_PlaySound ; TX_SOUND_DEX_FANFARE_20_49
- dw Text_PlaySound ; TX_SOUND_ITEM
- dw Text_PlaySound ; TX_SOUND_CAUGHT_MON
- dw Text_PlaySound ; TX_SOUND_DEX_FANFARE_80_109
- dw Text_PlaySound ; TX_SOUND_FANFARE
- dw Text_PlaySound ; TX_SOUND_SLOT_MACHINE_START
- dw Text_TX_STRINGBUFFER ; TX_STRINGBUFFER
- dw Text_TX_DAY ; TX_DAY
- dw Text_TX_FAR ; TX_FAR
-; 143e
-
-Text_TX:: ; 143e
-; TX
+ dw TextCommand_START ; TX_START
+ dw TextCommand_RAM ; TX_RAM
+ dw TextCommand_BCD ; TX_BCD
+ dw TextCommand_MOVE ; TX_MOVE
+ dw TextCommand_BOX ; TX_BOX
+ dw TextCommand_LOW ; TX_LOW
+ dw TextCommand_WAIT_BUTTON ; TX_WAIT_BUTTON
+ dw TextCommand_SCROLL ; TX_SCROLL
+ dw TextCommand_START_ASM ; TX_START_ASM
+ dw TextCommand_NUM ; TX_NUM
+ dw TextCommand_EXIT ; TX_EXIT
+ dw TextCommand_SOUND ; TX_SOUND_DEX_FANFARE_50_79
+ dw TextCommand_DOTS ; TX_DOTS
+ dw TextCommand_LINK_WAIT_BUTTON ; TX_LINK_WAIT_BUTTON
+ dw TextCommand_SOUND ; TX_SOUND_DEX_FANFARE_20_49
+ dw TextCommand_SOUND ; TX_SOUND_ITEM
+ dw TextCommand_SOUND ; TX_SOUND_CAUGHT_MON
+ dw TextCommand_SOUND ; TX_SOUND_DEX_FANFARE_80_109
+ dw TextCommand_SOUND ; TX_SOUND_FANFARE
+ dw TextCommand_SOUND ; TX_SOUND_SLOT_MACHINE_START
+ dw TextCommand_STRINGBUFFER ; TX_STRINGBUFFER
+ dw TextCommand_DAY ; TX_DAY
+ dw TextCommand_FAR ; TX_FAR
+
+TextCommand_START::
+; text_start
; write text until "@"
; [$00]["...@"]
@@ -775,9 +720,8 @@ Text_TX:: ; 143e
ld l, e
inc hl
ret
-; 1449
-Text_TX_RAM:: ; 1449
+TextCommand_RAM::
; text_from_ram
; write text from a ram address
; little endian
@@ -793,9 +737,8 @@ Text_TX_RAM:: ; 1449
call PlaceString
pop hl
ret
-; 1455
-Text_TX_FAR:: ; 1455
+TextCommand_FAR::
; text_jump
; write text from a different bank
; little endian
@@ -823,10 +766,9 @@ Text_TX_FAR:: ; 1455
ld [hROMBank], a
ld [MBC3RomBank], a
ret
-; 1470
-Text_TX_BCD:: ; 1470
-; TX_BCD
+TextCommand_BCD::
+; text_bcd
; write bcd from address, typically ram
; [$02][addr][flags]
; flags: see PrintBCDNumber
@@ -845,10 +787,9 @@ Text_TX_BCD:: ; 1470
ld c, l
pop hl
ret
-; 1480
-Text_TX_MOVE:: ; 1480
-; TX_MOVE
+TextCommand_MOVE::
+; text_move
; move to a new tile
; [$03][addr]
@@ -859,10 +800,9 @@ Text_TX_MOVE:: ; 1480
ld [wMenuScrollPosition + 2 + 1], a
ld b, a
ret
-; 148b
-Text_TX_BOX:: ; 148b
-; TX_BOX
+TextCommand_BOX::
+; text_box
; draw a box
; little endian
; [$04][addr][height][width]
@@ -881,28 +821,26 @@ Text_TX_BOX:: ; 148b
call TextBox
pop hl
ret
-; 149b
-Text_TX_LOW:: ; 149b
-; TX_LOW
+TextCommand_LOW::
+; text_low
; write text at (1,16)
; [$05]
bccoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
ret
-; 149f
-Text_WAIT_BUTTON:: ; 149f
-; TX_WAITBUTTON
+TextCommand_WAIT_BUTTON::
+; text_waitbutton
; wait for button press
; show arrow
; [06]
ld a, [wLinkMode]
cp LINK_COLOSSEUM
- jp z, Text_LINK_WAIT_BUTTON
+ jp z, TextCommand_LINK_WAIT_BUTTON
cp LINK_MOBILE
- jp z, Text_LINK_WAIT_BUTTON
+ jp z, TextCommand_LINK_WAIT_BUTTON
push hl
call LoadBlinkingCursor
@@ -912,9 +850,9 @@ Text_WAIT_BUTTON:: ; 149f
call UnloadBlinkingCursor
pop hl
ret
-; 14ba
-Text_TX_SCROLL:: ; 14ba
+TextCommand_SCROLL::
+; text_scroll
; pushes text up two lines and sets the BC cursor to the border tile
; below the first character column of the text box.
push hl
@@ -924,10 +862,9 @@ Text_TX_SCROLL:: ; 14ba
pop hl
bccoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
ret
-; 14c9
-Text_START_ASM:: ; 14c9
-; TX_ASM
+TextCommand_START_ASM::
+; start_asm
bit 7, h
jr nz, .not_rom
@@ -937,10 +874,9 @@ Text_START_ASM:: ; 14c9
ld a, "@"
ld [hl], a
ret
-; 14d2
-Text_TX_NUM:: ; 14d2
-; TX_NUM
+TextCommand_NUM::
+; deciram
; [$09][addr][hi:bytes lo:digits]
ld a, [hli]
ld e, a
@@ -963,9 +899,9 @@ Text_TX_NUM:: ; 14d2
ld c, l
pop hl
ret
-; 14ed
-Text_TX_EXIT:: ; 14ed
+TextCommand_EXIT::
+; interpret_data
push hl
push bc
call GetJoypad
@@ -978,9 +914,8 @@ Text_TX_EXIT:: ; 14ed
pop bc
pop hl
ret
-; 1500
-Text_PlaySound:: ; 1500
+TextCommand_SOUND::
; chars:
; $0b, $0e, $0f, $10, $11, $12, $13
; see TextSFX
@@ -1014,10 +949,9 @@ Text_PlaySound:: ; 1500
pop hl
pop bc
ret
-; 1522
-Unreferenced_Function1522:: ; 1522
-; TX_CRY
+Unreferenced_Function1522::
+; play_cry
push de
ld e, [hl]
inc hl
@@ -1027,9 +961,8 @@ Unreferenced_Function1522:: ; 1522
pop hl
pop bc
ret
-; 152d
-TextSFX:: ; 152d
+TextSFX::
dbw TX_SOUND_DEX_FANFARE_50_79, SFX_DEX_FANFARE_50_79
dbw TX_SOUND_FANFARE, SFX_FANFARE
dbw TX_SOUND_DEX_FANFARE_20_49, SFX_DEX_FANFARE_20_49
@@ -1038,9 +971,9 @@ TextSFX:: ; 152d
dbw TX_SOUND_DEX_FANFARE_80_109, SFX_DEX_FANFARE_80_109
dbw TX_SOUND_SLOT_MACHINE_START, SFX_SLOT_MACHINE_START
db -1
-; 1543
-Text_TX_DOTS:: ; 1543
+TextCommand_DOTS::
+; limited_interpret_data
; [$0C][num]
ld a, [hli]
ld d, a
@@ -1067,9 +1000,9 @@ Text_TX_DOTS:: ; 1543
ld c, l
pop hl
ret
-; 1562
-Text_LINK_WAIT_BUTTON:: ; 1562
+TextCommand_LINK_WAIT_BUTTON::
+; link_wait_button
; wait for key down
; display arrow
push hl
@@ -1078,9 +1011,9 @@ Text_LINK_WAIT_BUTTON:: ; 1562
pop bc
pop hl
ret
-; 156a
-Text_TX_STRINGBUFFER:: ; 156a
+TextCommand_STRINGBUFFER::
+; text_buffer
; Print a string from one of the following:
; 0: wStringBuffer3
; 1: wStringBuffer4
@@ -1107,10 +1040,9 @@ Text_TX_STRINGBUFFER:: ; 156a
call PlaceString
pop hl
ret
-; 1582
-Text_TX_DAY:: ; 1582
-; TX_DAY
+TextCommand_DAY::
+; current_day
call GetWeekday
push hl
@@ -1134,7 +1066,7 @@ Text_TX_DAY:: ; 1582
pop hl
ret
-.Days: ; 15a2
+.Days:
dw .Sun
dw .Mon
dw .Tues
@@ -1151,4 +1083,3 @@ Text_TX_DAY:: ; 1582
.Fri: db "FRI@"
.Satur: db "SATUR@"
.Day: db "DAY@"
-; 15d8
diff --git a/home/tilemap.asm b/home/tilemap.asm
index 4bbd16102..711118ae0 100644
--- a/home/tilemap.asm
+++ b/home/tilemap.asm
@@ -1,257 +1,218 @@
-PushWindow:: ; 1c00
- callfar _PushWindow
+ClearBGPalettes::
+ call ClearPalettes
+WaitBGMap::
+; Tell VBlank to update BG Map
+ ld a, 1 ; BG Map 0 tiles
+ ld [hBGMapMode], a
+; Wait for it to do its magic
+ ld c, 4
+ call DelayFrames
ret
-; 1c07
-ExitMenu:: ; 0x1c07
- push af
- callfar _ExitMenu
- pop af
+WaitBGMap2::
+ ld a, [hCGB]
+ and a
+ jr z, .bg0
+
+ ld a, 2
+ ld [hBGMapMode], a
+ ld c, 4
+ call DelayFrames
+
+.bg0
+ ld a, 1
+ ld [hBGMapMode], a
+ ld c, 4
+ call DelayFrames
ret
-InitVerticalMenuCursor:: ; 0x1c10
- callfar _InitVerticalMenuCursor
+IsCGB::
+ ld a, [hCGB]
+ and a
ret
-CloseWindow:: ; 0x1c17
- push af
- call ExitMenu
- call ApplyTilemap
- call UpdateSprites
- pop af
+ApplyTilemap::
+ ld a, [hCGB]
+ and a
+ jr z, .dmg
+
+ ld a, [wSpriteUpdatesEnabled]
+ cp 0
+ jr z, .dmg
+
+ ld a, 1
+ ld [hBGMapMode], a
+ jr CopyTilemapAtOnce
+
+.dmg
+; WaitBGMap
+ ld a, 1
+ ld [hBGMapMode], a
+ ld c, 4
+ call DelayFrames
ret
-RestoreTileBackup:: ; 0x1c23
- call MenuBoxCoord2Tile
- call .copy
- call MenuBoxCoord2Attr
- call .copy
- ret
-; 0x1c30
-
-.copy ; 0x1c30
- call GetMenuBoxDims
- inc b
- inc c
-
-.row
- push bc
- push hl
-
-.col
- ld a, [de]
- ld [hli], a
- dec de
- dec c
- jr nz, .col ; 0x1c3b $fa
-
- pop hl
- ld bc, SCREEN_WIDTH
- add hl, bc
- pop bc
- dec b
- jr nz, .row ; 0x1c44 $ef
+CGBOnly_CopyTilemapAtOnce::
+ ld a, [hCGB]
+ and a
+ jr z, WaitBGMap
- ret
+CopyTilemapAtOnce::
+ jr .CopyTilemapAtOnce
-PopWindow:: ; 0x1c47
- ld b, $10
- ld de, wMenuFlags
-.loop
- ld a, [hld]
- ld [de], a
- inc de
- dec b
- jr nz, .loop ; 0x1c50 $fa
+; unused
+ farcall HDMATransferAttrMapAndTileMapToWRAMBank3
ret
-GetMenuBoxDims:: ; 0x1c53
- ld a, [wMenuBorderTopCoord] ; top
- ld b, a
- ld a, [wMenuBorderBottomCoord] ; bottom
- sub b
- ld b, a
- ld a, [wMenuBorderLeftCoord] ; left
- ld c, a
- ld a, [wMenuBorderRightCoord] ; right
- sub c
- ld c, a
- ret
-; 0x1c66
+.CopyTilemapAtOnce:
+ ld a, [hBGMapMode]
+ push af
+ xor a
+ ld [hBGMapMode], a
-CopyMenuData2:: ; 1c66
- push hl
- push de
- push bc
+ ld a, [hMapAnims]
push af
- ld hl, wMenuData2Pointer
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ld de, wMenuData2Flags
- ld bc, wMenuData2End - wMenuData2Flags
- call CopyBytes
+ xor a
+ ld [hMapAnims], a
+
+.wait
+ ld a, [rLY]
+ cp $7f
+ jr c, .wait
+
+ di
+ ld a, BANK(vTiles3)
+ ld [rVBK], a
+ hlcoord 0, 0, wAttrMap
+ call .StackPointerMagic
+ ld a, BANK(vTiles0)
+ ld [rVBK], a
+ hlcoord 0, 0
+ call .StackPointerMagic
+
+.wait2
+ ld a, [rLY]
+ cp $7f
+ jr c, .wait2
+ ei
+
pop af
- pop bc
- pop de
- pop hl
+ ld [hMapAnims], a
+ pop af
+ ld [hBGMapMode], a
ret
-; 1c7e
-GetWindowStackTop:: ; 1c7e
- ld hl, wWindowStackPointer
- ld a, [hli]
- ld h, [hl]
- ld l, a
- inc hl
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ret
-; 1c89
-
-PlaceVerticalMenuItems:: ; 1c89
- call CopyMenuData2
- ld hl, wMenuData2Pointer
- ld e, [hl]
- inc hl
- ld d, [hl]
- call GetMenuTextStartCoord
- call Coord2Tile ; hl now contains the tilemap address where we will start printing text.
- inc de
- ld a, [de] ; Number of items
- inc de
- ld b, a
+.StackPointerMagic:
+; Copy all tiles to vBGMap
+ ld [hSPBuffer], sp
+ ld sp, hl
+ ld a, [hBGMapAddress + 1]
+ ld h, a
+ ld l, 0
+ ld a, SCREEN_HEIGHT
+ ld [hTilesPerCycle], a
+ ld b, 1 << 1 ; not in v/hblank
+ ld c, LOW(rSTAT)
+
.loop
- push bc
- call PlaceString
- inc de
- ld bc, 2 * SCREEN_WIDTH
- add hl, bc
- pop bc
- dec b
+rept SCREEN_WIDTH / 2
+ pop de
+; if in v/hblank, wait until not in v/hblank
+.loop\@
+ ld a, [$ff00+c]
+ and b
+ jr nz, .loop\@
+; load BGMap0
+ ld [hl], e
+ inc l
+ ld [hl], d
+ inc l
+endr
+
+ ld de, BG_MAP_WIDTH - SCREEN_WIDTH
+ add hl, de
+ ld a, [hTilesPerCycle]
+ dec a
+ ld [hTilesPerCycle], a
jr nz, .loop
- ld a, [wMenuData2Flags]
- bit 4, a
- ret z
-
- call MenuBoxCoord2Tile
- ld a, [de]
- ld c, a
- inc de
- ld b, $0
- add hl, bc
- jp PlaceString
-; 1cbb
-
-MenuBox:: ; 1cbb
- call MenuBoxCoord2Tile
- call GetMenuBoxDims
- dec b
- dec c
- jp TextBox
-; 1cc6
-
-GetMenuTextStartCoord:: ; 1cc6
- ld a, [wMenuBorderTopCoord]
- ld b, a
- inc b
- ld a, [wMenuBorderLeftCoord]
- ld c, a
- inc c
-; bit 6: if not set, leave extra room on top
- ld a, [wMenuData2Flags]
- bit 6, a
- jr nz, .bit_6_set
- inc b
-
-.bit_6_set
-; bit 7: if set, leave extra room on the left
- ld a, [wMenuData2Flags]
- bit 7, a
- jr z, .bit_7_clear
- inc c
-
-.bit_7_clear
- ret
-; 1ce1
-
-ClearMenuBoxInterior:: ; 1ce1
- call MenuBoxCoord2Tile
- ld bc, SCREEN_WIDTH + 1
- add hl, bc
- call GetMenuBoxDims
- dec b
- dec c
- call ClearBox
+ ld a, [hSPBuffer]
+ ld l, a
+ ld a, [hSPBuffer + 1]
+ ld h, a
+ ld sp, hl
ret
-; 1cf1
-
-ClearWholeMenuBox:: ; 1cf1
- call MenuBoxCoord2Tile
- call GetMenuBoxDims
- inc c
- inc b
- call ClearBox
+
+SetPalettes::
+; Inits the Palettes
+; depending on the system the monochromes palettes or color palettes
+ ld a, [hCGB]
+ and a
+ jr nz, .SetPalettesForGameBoyColor
+ ld a, %11100100
+ ld [rBGP], a
+ ld a, %11010000
+ ld [rOBP0], a
+ ld [rOBP1], a
ret
-; 1cfd
+.SetPalettesForGameBoyColor:
+ push de
+ ld a, %11100100
+ call DmgToCgbBGPals
+ lb de, %11100100, %11100100
+ call DmgToCgbObjPals
+ pop de
+ ret
-MenuBoxCoord2Tile:: ; 1cfd
- ld a, [wMenuBorderLeftCoord]
- ld c, a
- ld a, [wMenuBorderTopCoord]
- ld b, a
-; 1d05
+ClearPalettes::
+; Make all palettes white
+; CGB: make all the palette colors white
+ ld a, [hCGB]
+ and a
+ jr nz, .cgb
-Coord2Tile:: ; 1d05
-; Return the address of wTileMap(c, b) in hl.
- xor a
- ld h, a
- ld l, b
- ld a, c
- ld b, h
- ld c, l
- add hl, hl
- add hl, hl
- add hl, bc
- add hl, hl
- add hl, hl
- ld c, a
+; DMG: just change palettes to 0 (white)
xor a
- ld b, a
- add hl, bc
- bccoord 0, 0
- add hl, bc
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld [rOBP1], a
ret
-; 1d19
-MenuBoxCoord2Attr:: ; 1d19
- ld a, [wMenuBorderLeftCoord]
- ld c, a
- ld a, [wMenuBorderTopCoord]
- ld b, a
+.cgb
+ ld a, [rSVBK]
+ push af
-Coord2Attr:: ; 1d21
-; Return the address of wAttrMap(c, b) in hl.
- xor a
- ld h, a
- ld l, b
- ld a, c
- ld b, h
- ld c, l
- add hl, hl
- add hl, hl
- add hl, bc
- add hl, hl
- add hl, hl
- ld c, a
- xor a
- ld b, a
- add hl, bc
- bccoord 0, 0, wAttrMap
- add hl, bc
+ ld a, BANK(wBGPals2)
+ ld [rSVBK], a
+
+; Fill wBGPals2 and wOBPals2 with $ffff (white)
+ ld hl, wBGPals2
+ ld bc, 16 palettes
+ ld a, $ff
+ call ByteFill
+
+ pop af
+ ld [rSVBK], a
+
+; Request palette update
+ ld a, 1
+ ld [hCGBPalUpdate], a
ret
-; 1d35
+
+GetMemSGBLayout::
+ ld b, SCGB_RAM
+GetSGBLayout::
+; load sgb packets unless dmg
+
+ ld a, [hCGB]
+ and a
+ jr nz, .sgb
+
+ ld a, [hSGB]
+ and a
+ ret z
+
+.sgb
+ predef_jump LoadSGBLayout
diff --git a/home/time.asm b/home/time.asm
index 5ede49173..caf857a68 100644
--- a/home/time.asm
+++ b/home/time.asm
@@ -1,7 +1,6 @@
; Functions relating to the timer interrupt and the real-time-clock.
-
-AskTimer:: ; 591
+AskTimer::
push af
ld a, [hMobile]
and a
@@ -11,29 +10,23 @@ AskTimer:: ; 591
.not_mobile
pop af
reti
-; 59c
-
-LatchClock:: ; 59c
+LatchClock::
; latch clock counter data
ld a, 0
ld [MBC3LatchClock], a
ld a, 1
ld [MBC3LatchClock], a
ret
-; 5a7
-
-UpdateTime:: ; 5a7
+UpdateTime::
call GetClock
call FixDays
call FixTime
farcall GetTimeOfDay
ret
-; 5b7
-
-GetClock:: ; 5b7
+GetClock::
; store clock data in hRTCDayHi-hRTCSeconds
; enable clock r/w
@@ -72,10 +65,8 @@ GetClock:: ; 5b7
; unlatch clock / disable clock r/w
call CloseSRAM
ret
-; 5e8
-
-FixDays:: ; 5e8
+FixDays::
; fix day count
; mod by 140
@@ -134,10 +125,8 @@ FixDays:: ; 5e8
.quit
xor a
ret
-; 61d
-
-FixTime:: ; 61d
+FixTime::
; add ingame time (set at newgame) to current time
; day hr min sec
; store time in wCurDay, hHours, hMinutes, hSeconds
@@ -185,16 +174,15 @@ FixTime:: ; 61d
adc c
ld [wCurDay], a
ret
-; 658
-SetTimeOfDay:: ; 658
+InitTimeOfDay::
xor a
ld [wStringBuffer2], a
ld a, $0 ; useless
ld [wStringBuffer2 + 3], a
jr InitTime
-SetDayOfWeek:: ; 663
+InitDayOfWeek::
call UpdateTime
ld a, [hHours]
ld [wStringBuffer2 + 1], a
@@ -204,20 +192,16 @@ SetDayOfWeek:: ; 663
ld [wStringBuffer2 + 3], a
jr InitTime ; useless
-InitTime:: ; 677
+InitTime::
farcall _InitTime
ret
-; 67e
-
-
-PanicResetClock:: ; 67e
+PanicResetClock::
call .ClearhRTC
call SetClock
ret
-; 685
-.ClearhRTC: ; 685
+.ClearhRTC:
xor a
ld [hRTCSeconds], a
ld [hRTCMinutes], a
@@ -225,10 +209,8 @@ PanicResetClock:: ; 67e
ld [hRTCDayLo], a
ld [hRTCDayHi], a
ret
-; 691
-
-SetClock:: ; 691
+SetClock::
; set clock data from hram
; enable clock r/w
@@ -274,10 +256,8 @@ SetClock:: ; 691
; cleanup
call CloseSRAM ; unlatch clock, disable clock r/w
ret
-; 6c4
-
-ClearRTCStatus:: ; 6c4
+ClearRTCStatus::
; clear sRTCStatusFlags
xor a
push af
@@ -287,9 +267,8 @@ ClearRTCStatus:: ; 6c4
ld [sRTCStatusFlags], a
call CloseSRAM
ret
-; 6d3
-RecordRTCStatus:: ; 6d3
+RecordRTCStatus::
; append flags to sRTCStatusFlags
ld hl, sRTCStatusFlags
push af
@@ -300,13 +279,11 @@ RecordRTCStatus:: ; 6d3
ld [hl], a
call CloseSRAM
ret
-; 6e3
-CheckRTCStatus:: ; 6e3
+CheckRTCStatus::
; check sRTCStatusFlags
ld a, BANK(sRTCStatusFlags)
call GetSRAMBank
ld a, [sRTCStatusFlags]
call CloseSRAM
ret
-; 6ef
diff --git a/home/trainers.asm b/home/trainers.asm
index 575af65a7..5def6cf17 100644
--- a/home/trainers.asm
+++ b/home/trainers.asm
@@ -1,4 +1,4 @@
-CheckTrainerBattle2:: ; 3600
+CheckTrainerBattle2::
ld a, [hROMBank]
push af
@@ -9,9 +9,8 @@ CheckTrainerBattle2:: ; 3600
ld a, b
rst Bankswitch
ret
-; 360d
-CheckTrainerBattle:: ; 360d
+CheckTrainerBattle::
; Check if any trainer on the map sees the player and wants to battle.
; Skip the player object.
@@ -21,7 +20,6 @@ CheckTrainerBattle:: ; 360d
.loop
; Start a battle if the object:
-
push af
push de
@@ -101,15 +99,14 @@ CheckTrainerBattle:: ; 360d
ld a, c
ld [wEngineBuffer3], a
jr LoadTrainer_continue
-; 3674
-TalkToTrainer:: ; 3674
+TalkToTrainer::
ld a, 1
ld [wEngineBuffer2], a
ld a, -1
ld [wEngineBuffer3], a
-LoadTrainer_continue:: ; 367e
+LoadTrainer_continue::
call GetMapScriptsBank
ld [wEngineBuffer1], a
@@ -128,19 +125,16 @@ LoadTrainer_continue:: ; 367e
ld [wRunningTrainerBattleScript], a
scf
ret
-; 36a5
-
-FacingPlayerDistance_bc:: ; 36a5
+FacingPlayerDistance_bc::
push de
call FacingPlayerDistance
ld b, d
ld c, e
pop de
ret
-; 36ad
-FacingPlayerDistance:: ; 36ad
+FacingPlayerDistance::
; Return carry if the sprite at bc is facing the player,
; and its distance in d.
@@ -208,9 +202,8 @@ FacingPlayerDistance:: ; 36ad
.NotFacing:
and a
ret
-; 36f5
-CheckTrainerFlag:: ; 36f5
+CheckTrainerFlag::
push bc
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, bc
@@ -233,9 +226,8 @@ CheckTrainerFlag:: ; 36f5
and a
pop bc
ret
-; 3718
-PrintWinLossText:: ; 3718
+PrintWinLossText::
ld a, [wBattleType]
cp BATTLETYPE_CANLOSE
jr .canlose ; ??????????
@@ -247,7 +239,7 @@ PrintWinLossText:: ; 3718
.canlose
ld a, [wBattleResult]
ld hl, wWinTextPointer
- and $f
+ and $f ; WIN?
jr z, .ok
ld hl, wLossTextPointer
@@ -260,4 +252,3 @@ PrintWinLossText:: ; 3718
call WaitBGMap
call WaitPressAorB_BlinkCursor
ret
-; 3741
diff --git a/home/vblank.asm b/home/vblank.asm
index 3b33b1ec5..5e87dbcdf 100644
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -6,8 +6,7 @@
; This prevents the display and audio output from lagging.
-
-VBlank:: ; 283
+VBlank::
push af
push bc
push de
@@ -34,9 +33,8 @@ VBlank:: ; 283
pop bc
pop af
reti
-; 2a1
-.VBlanks: ; 2a1
+.VBlanks:
dw VBlank0
dw VBlank1
dw VBlank2
@@ -45,10 +43,8 @@ VBlank:: ; 283
dw VBlank5
dw VBlank6
dw VBlank0 ; just in case
-; 2b1
-
-VBlank0:: ; 2b1
+VBlank0::
; normal operation
; rng
@@ -116,7 +112,6 @@ VBlank0:: ; 2b1
call hTransferVirtualOAM
.done_oam
-
; vblank-sensitive operations are done
xor a
@@ -148,10 +143,8 @@ VBlank0:: ; 2b1
ld [hSecondsBackup], a
ret
-; 325
-
-VBlank2:: ; 325
+VBlank2::
; sound only
ld a, [hROMBank]
@@ -167,10 +160,8 @@ VBlank2:: ; 325
xor a
ld [wVBlankOccurred], a
ret
-; 337
-
-VBlank1:: ; 337
+VBlank1::
; scx, scy
; palettes
; bg map
@@ -235,10 +226,8 @@ VBlank1:: ; 337
ld a, b
ld [rIF], a
ret
-; 37f
-
-UpdatePals:: ; 37f
+UpdatePals::
; update pals for either dmg or cgb
ld a, [hCGB]
@@ -255,10 +244,8 @@ UpdatePals:: ; 37f
and a
ret
-; 396
-
-VBlank3:: ; 396
+VBlank3::
; scx, scy
; palettes
; bg map
@@ -321,10 +308,8 @@ VBlank3:: ; 396
ld a, b
ld [rIF], a
ret
-; 3df
-
-VBlank4:: ; 3df
+VBlank4::
; bg map
; tiles
; oam
@@ -354,10 +339,8 @@ VBlank4:: ; 3df
ld a, [hROMBankBackup]
rst Bankswitch
ret
-; 400
-
-VBlank5:: ; 400
+VBlank5::
; scx
; palettes
; bg map
@@ -404,10 +387,8 @@ VBlank5:: ; 400
ld a, %1111 ; serial timer lcdstat vblank
ld [rIE], a
ret
-; 436
-
-VBlank6:: ; 436
+VBlank6::
; palettes
; tiles
; dma transfer
@@ -438,4 +419,3 @@ VBlank6:: ; 436
ld a, [hROMBankBackup]
rst Bankswitch
ret
-; 45a
diff --git a/home/video.asm b/home/video.asm
index 1066197ff..4b519fca0 100644
--- a/home/video.asm
+++ b/home/video.asm
@@ -1,6 +1,6 @@
; Functions dealing with VRAM.
-DMATransfer:: ; 15d8
+DMATransfer::
; Return carry if the transfer is completed.
ld a, [hDMATransfer]
@@ -16,10 +16,8 @@ DMATransfer:: ; 15d8
ld [hDMATransfer], a
scf
ret
-; 15e3
-
-UpdateBGMapBuffer:: ; 15e3
+UpdateBGMapBuffer::
; Copy [hBGMapTileCount] 16x8 tiles from wBGMapBuffer
; to bg map addresses in wBGMapBufferPtrs.
@@ -43,7 +41,6 @@ UpdateBGMapBuffer:: ; 15e3
ld hl, wBGMapPalBuffer
ld de, wBGMapBuffer
-
.next
; Copy a pair of 16x8 blocks (one 16x16 block)
@@ -83,7 +80,6 @@ endr
jr nz, .next
-
ld a, [hSPBuffer]
ld l, a
ld a, [hSPBuffer + 1]
@@ -97,10 +93,8 @@ endr
ld [hBGMapUpdate], a
scf
ret
-; 163a
-
-WaitTop:: ; 163a
+WaitTop::
; Wait until the top third of the BG Map is being updated.
ld a, [hBGMapMode]
@@ -118,10 +112,8 @@ WaitTop:: ; 163a
xor a
ld [hBGMapMode], a
ret
-; 164c
-
-UpdateBGMap:: ; 164c
+UpdateBGMap::
; Update the BG Map, in thirds, from wTileMap and wAttrMap.
ld a, [hBGMapMode]
@@ -163,7 +155,6 @@ UpdateBGMap:: ; 164c
ld [hBGMapAddress + 1], a
ret
-
.Attr:
ld a, 1
ld [rVBK], a
@@ -175,11 +166,9 @@ UpdateBGMap:: ; 164c
ld [rVBK], a
ret
-
.Tiles:
hlcoord 0, 0
-
.update
ld [hSPBuffer], sp
@@ -191,10 +180,8 @@ UpdateBGMap:: ; 164c
jr z, .middle
; 2
-
THIRD_HEIGHT EQU SCREEN_HEIGHT / 3
-
.bottom
ld de, 2 * THIRD_HEIGHT * SCREEN_WIDTH
add hl, de
@@ -212,7 +199,6 @@ THIRD_HEIGHT EQU SCREEN_HEIGHT / 3
xor a
jr .start
-
.middle
ld de, THIRD_HEIGHT * SCREEN_WIDTH
add hl, de
@@ -230,7 +216,6 @@ THIRD_HEIGHT EQU SCREEN_HEIGHT / 3
ld a, 2
jr .start
-
.top
ld sp, hl
@@ -242,7 +227,6 @@ THIRD_HEIGHT EQU SCREEN_HEIGHT / 3
; Next time: middle third
ld a, 1
-
.start
; Which third to update next time
ld [hBGMapThird], a
@@ -253,7 +237,6 @@ THIRD_HEIGHT EQU SCREEN_HEIGHT / 3
; Discrepancy between wTileMap and BGMap
ld bc, BG_MAP_WIDTH - (SCREEN_WIDTH - 1)
-
.row
; Copy a row of 20 tiles
rept SCREEN_WIDTH / 2 - 1
@@ -272,17 +255,14 @@ endr
dec a
jr nz, .row
-
ld a, [hSPBuffer]
ld l, a
ld a, [hSPBuffer + 1]
ld h, a
ld sp, hl
ret
-; 170a
-
-Serve1bppRequest:: ; 170a
+Serve1bppRequest::
; Only call during the first fifth of VBlank
ld a, [wRequested1bpp]
@@ -346,7 +326,6 @@ endr
dec b
jr nz, .next
-
ld a, l
ld [wRequested1bppDest], a
ld a, h
@@ -360,10 +339,8 @@ endr
ld h, a
ld sp, hl
ret
-; 1769
-
-Serve2bppRequest:: ; 1769
+Serve2bppRequest::
; Only call during the first fifth of VBlank
ld a, [wRequested2bpp]
@@ -378,14 +355,12 @@ Serve2bppRequest:: ; 1769
ret nc
jr _Serve2bppRequest
-
-Serve2bppRequest_VBlank:: ; 1778
-
+Serve2bppRequest_VBlank::
ld a, [wRequested2bpp]
and a
ret z
-_Serve2bppRequest:: ; 177d
+_Serve2bppRequest::
; Copy [wRequested2bpp] 2bpp tiles from [wRequested2bppSource] to [wRequested2bppDest]
ld [hSPBuffer], sp
@@ -428,7 +403,6 @@ endr
dec b
jr nz, .next
-
ld a, l
ld [wRequested2bppDest], a
ld a, h
@@ -442,10 +416,8 @@ endr
ld h, a
ld sp, hl
ret
-; 17d3
-
-AnimateTileset:: ; 17d3
+AnimateTileset::
; Only call during the first fifth of VBlank
ld a, [hMapAnims]
@@ -483,4 +455,3 @@ AnimateTileset:: ; 17d3
pop af
rst Bankswitch
ret
-; 17ff
diff --git a/home/window.asm b/home/window.asm
index 2d7c22569..6d9bd5311 100644
--- a/home/window.asm
+++ b/home/window.asm
@@ -1,5 +1,4 @@
-RefreshScreen:: ; 2dba
-
+RefreshScreen::
call ClearWindowData
ld a, [hROMBank]
push af
@@ -13,10 +12,8 @@ RefreshScreen:: ; 2dba
pop af
rst Bankswitch
ret
-; 2dcf
-
-CloseText:: ; 2dcf
+CloseText::
ld a, [hOAMUpdate]
push af
ld a, $1
@@ -29,9 +26,8 @@ CloseText:: ; 2dcf
ld hl, wVramState
res 6, [hl]
ret
-; 2de2
-.CloseText: ; 2de2
+.CloseText:
call ClearWindowData
xor a
ld [hBGMapMode], a
@@ -46,9 +42,8 @@ CloseText:: ; 2dcf
farcall ReturnFromMapSetupScript
farcall LoadOverworldFont
ret
-; 2e08
-OpenText:: ; 2e08
+OpenText::
call ClearWindowData
ld a, [hROMBank]
push af
@@ -63,9 +58,8 @@ OpenText:: ; 2e08
rst Bankswitch
ret
-; 2e20
-_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap:: ; 2e20
+_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap::
ld a, [hOAMUpdate]
push af
ld a, $1
@@ -76,9 +70,8 @@ _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap:: ; 2e20
pop af
ld [hOAMUpdate], a
ret
-; 2e31
-SafeUpdateSprites:: ; 2e31
+SafeUpdateSprites::
ld a, [hOAMUpdate]
push af
ld a, [hBGMapMode]
@@ -102,4 +95,3 @@ SafeUpdateSprites:: ; 2e31
; unused
scf
ret
-; 2e50