summaryrefslogtreecommitdiff
path: root/home
diff options
context:
space:
mode:
Diffstat (limited to 'home')
-rw-r--r--home/audio.asm269
-rw-r--r--home/copy2.asm34
-rw-r--r--home/fade.asm2
-rw-r--r--home/init.asm46
-rw-r--r--home/overworld.asm959
-rw-r--r--home/pic.asm298
-rw-r--r--home/predef.asm6
-rw-r--r--home/serial.asm624
-rw-r--r--home/text.asm373
-rw-r--r--home/timer.asm2
-rw-r--r--home/vblank.asm46
-rw-r--r--home/vcopy.asm89
12 files changed, 1400 insertions, 1348 deletions
diff --git a/home/audio.asm b/home/audio.asm
index 9210924c..c982d9d6 100644
--- a/home/audio.asm
+++ b/home/audio.asm
@@ -1,182 +1,217 @@
-PlayDefaultMusic:: ; 2307 (0:2307)
+PlayDefaultMusic::
call WaitForSoundToFinish
xor a
ld c, a
ld d, a
- ld [wcfca], a
- jr asm_2324
+ ld [wLastMusicSoundID], a
+ jr PlayDefaultMusicCommon
-Func_2312:: ; 2312 (0:2312)
- ld c, $a
- ld d, $0
+PlayDefaultMusicFadeOutCurrent::
+; Fade out the current music and then play the default music.
+ ld c, 10
+ ld d, 0
ld a, [wd72e]
- bit 5, a
- jr z, asm_2324
+ bit 5, a ; has a battle just ended?
+ jr z, PlayDefaultMusicCommon
xor a
- ld [wcfca], a
- ld c, $8
+ ld [wLastMusicSoundID], a
+ ld c, 8
ld d, c
-asm_2324:: ; 2324 (0:2324)
+
+PlayDefaultMusicCommon::
ld a, [wWalkBikeSurfState]
and a
- jr z, .asm_2343
+ jr z, .walking
cp $2
- jr z, .asm_2332
+ jr z, .surfing
ld a, MUSIC_BIKE_RIDING
- jr .asm_2334
-.asm_2332
+ jr .next
+
+.surfing
ld a, MUSIC_SURFING
-.asm_2334
+
+.next
ld b, a
ld a, d
- and a
+ and a ; should current music be faded out first?
ld a, BANK(Music_BikeRiding)
- jr nz, .asm_233e
- ld [wc0ef], a
-.asm_233e
- ld [wc0f0], a
- jr .asm_234c
-.asm_2343
- ld a, [wd35b]
+ jr nz, .next2
+
+; Only change the audio ROM bank if the current music isn't going to be faded
+; out before the default music begins.
+ ld [wAudioROMBank], a
+
+.next2
+; [wAudioSavedROMBank] will be copied to [wAudioROMBank] after fading out the
+; current music (if the current music is faded out).
+ ld [wAudioSavedROMBank], a
+ jr .next3
+
+.walking
+ ld a, [wMapMusicSoundID]
ld b, a
- call Func_2385
- jr c, .asm_2351
-.asm_234c
- ld a, [wcfca]
- cp b
- ret z
-.asm_2351
+ call CompareMapMusicBankWithCurrentBank
+ jr c, .next4
+
+.next3
+ ld a, [wLastMusicSoundID]
+ cp b ; is the default music already playing?
+ ret z ; if so, do nothing
+
+.next4
ld a, c
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, b
- ld [wcfca], a
- ld [wc0ee], a
+ ld [wLastMusicSoundID], a
+ ld [wNewSoundID], a
jp PlaySound
-Func_235f:: ; 235f (0:235f)
- ld a, [wc0ef]
+UpdateMusic6Times::
+; This is called when entering a map, before fading out the current music and
+; playing the default music (i.e. the map's music or biking/surfing music).
+ ld a, [wAudioROMBank]
ld b, a
- cp BANK(Music2_UpdateMusic)
- jr nz, .checkForBank08
-.bank02
- ld hl, Music2_UpdateMusic
- jr .asm_2378
-.checkForBank08
- cp BANK(Music8_UpdateMusic)
- jr nz, .bank1F
-.bank08
- ld hl, Music8_UpdateMusic
- jr .asm_2378
-.bank1F
- ld hl, Music1f_UpdateMusic
-.asm_2378
- ld c, $6
-.asm_237a
+ cp BANK(Audio1_UpdateMusic)
+ jr nz, .checkForAudio2
+
+; audio 1
+ ld hl, Audio1_UpdateMusic
+ jr .next
+
+.checkForAudio2
+ cp BANK(Audio2_UpdateMusic)
+ jr nz, .audio3
+
+; audio 2
+ ld hl, Audio2_UpdateMusic
+ jr .next
+
+.audio3
+ ld hl, Audio3_UpdateMusic
+
+.next
+ ld c, 6
+.loop
push bc
push hl
call Bankswitch
pop hl
pop bc
dec c
- jr nz, .asm_237a
+ jr nz, .loop
ret
-Func_2385:: ; 2385 (0:2385)
- ld a, [wd35c]
+CompareMapMusicBankWithCurrentBank::
+; Compares the map music's audio ROM bank with the current audio ROM bank
+; and updates the audio ROM bank variables.
+; Returns whether the banks are different in carry.
+ ld a, [wMapMusicROMBank]
ld e, a
- ld a, [wc0ef]
+ ld a, [wAudioROMBank]
cp e
- jr nz, .asm_2394
- ld [wc0f0], a
+ jr nz, .differentBanks
+ ld [wAudioSavedROMBank], a
and a
ret
-.asm_2394
- ld a, c
+.differentBanks
+ ld a, c ; this is a fade-out counter value and it's always non-zero
and a
ld a, e
- jr nz, .asm_239c
- ld [wc0ef], a
-.asm_239c
- ld [wc0f0], a
+ jr nz, .next
+; If the fade-counter is non-zero, we don't change the audio ROM bank because
+; it's needed to keep playing the music as it fades out. The FadeOutAudio
+; routine will take care of copying [wAudioSavedROMBank] to [wAudioROMBank]
+; when the music has faded out.
+ ld [wAudioROMBank], a
+.next
+ ld [wAudioSavedROMBank], a
scf
ret
-PlayMusic:: ; 23a1 (0:23a1)
+PlayMusic::
ld b, a
- ld [wc0ee], a
+ ld [wNewSoundID], a
xor a
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, c
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, b
; plays music specified by a. If value is $ff, music is stopped
-PlaySound:: ; 23b1 (0:23b1)
+PlaySound::
push hl
push de
push bc
ld b, a
- ld a, [wc0ee]
+ ld a, [wNewSoundID]
and a
- jr z, .asm_23c8
+ jr z, .next
xor a
- ld [wc02a], a
- ld [wc02b], a
- ld [wc02c], a
- ld [wc02d], a
-.asm_23c8
- ld a, [wMusicHeaderPointer]
- and a
- jr z, .asm_23e3
- ld a, [wc0ee]
- and a
- jr z, .asm_2425
+ ld [wChannelSoundIDs + Ch4], a
+ ld [wChannelSoundIDs + Ch5], a
+ ld [wChannelSoundIDs + Ch6], a
+ ld [wChannelSoundIDs + Ch7], a
+.next
+ ld a, [wAudioFadeOutControl]
+ and a ; has a fade-out length been specified?
+ jr z, .noFadeOut
+ ld a, [wNewSoundID]
+ and a ; is the new sound ID 0?
+ jr z, .done ; if so, do nothing
xor a
- ld [wc0ee], a
- ld a, [wcfca]
- cp $ff
- jr nz, .asm_2414
+ ld [wNewSoundID], a
+ ld a, [wLastMusicSoundID]
+ cp $ff ; has the music been stopped?
+ jr nz, .fadeOut ; if not, fade out the current music
+; If it has been stopped, start playing the new music immediately.
xor a
- ld [wMusicHeaderPointer], a
-.asm_23e3
+ ld [wAudioFadeOutControl], a
+.noFadeOut
xor a
- ld [wc0ee], a
+ ld [wNewSoundID], a
ld a, [H_LOADEDROMBANK]
- ld [$ffb9], a
- ld a, [wc0ef]
+ ld [hSavedROMBank], a
+ ld a, [wAudioROMBank]
ld [H_LOADEDROMBANK], a
- ld [$2000], a
- cp BANK(Func_9876)
- jr nz, .checkForBank08
-.bank02
+ ld [MBC1RomBank], a
+ cp BANK(Audio1_PlaySound)
+ jr nz, .checkForAudio2
+
+; audio 1
ld a, b
- call Func_9876
- jr .asm_240b
-.checkForBank08
- cp BANK(Func_22035)
- jr nz, .bank1F
-.bank08
+ call Audio1_PlaySound
+ jr .next2
+
+.checkForAudio2
+ cp BANK(Audio2_PlaySound)
+ jr nz, .audio3
+
+; audio 2
ld a, b
- call Func_22035
- jr .asm_240b
-.bank1F
+ call Audio2_PlaySound
+ jr .next2
+
+.audio3
ld a, b
- call Func_7d8ea
-.asm_240b
- ld a, [$ffb9]
+ call Audio3_PlaySound
+
+.next2
+ ld a, [hSavedROMBank]
ld [H_LOADEDROMBANK], a
- ld [$2000], a
- jr .asm_2425
-.asm_2414
+ ld [MBC1RomBank], a
+ jr .done
+
+.fadeOut
ld a, b
- ld [wcfca], a
- ld a, [wMusicHeaderPointer]
- ld [wcfc8], a
- ld [wcfc9], a
+ ld [wLastMusicSoundID], a
+ ld a, [wAudioFadeOutControl]
+ ld [wAudioFadeOutCounterReloadValue], a
+ ld [wAudioFadeOutCounter], a
ld a, b
- ld [wMusicHeaderPointer], a
-.asm_2425
+ ld [wAudioFadeOutControl], a
+
+.done
pop bc
pop de
pop hl
diff --git a/home/copy2.asm b/home/copy2.asm
index 7b407cdc..830440b0 100644
--- a/home/copy2.asm
+++ b/home/copy2.asm
@@ -1,10 +1,10 @@
FarCopyData2::
-; Identical to FarCopyData, but uses $ff8b
+; Identical to FarCopyData, but uses hROMBankTemp
; as temp space instead of wBuffer.
- ld [$ff8b],a
+ ld [hROMBankTemp],a
ld a,[H_LOADEDROMBANK]
push af
- ld a,[$ff8b]
+ ld a,[hROMBankTemp]
ld [H_LOADEDROMBANK],a
ld [MBC1RomBank],a
call CopyData
@@ -15,10 +15,10 @@ FarCopyData2::
FarCopyData3::
; Copy bc bytes from a:de to hl.
- ld [$ff8b],a
+ ld [hROMBankTemp],a
ld a,[H_LOADEDROMBANK]
push af
- ld a,[$ff8b]
+ ld a,[hROMBankTemp]
ld [H_LOADEDROMBANK],a
ld [MBC1RomBank],a
push hl
@@ -38,10 +38,10 @@ FarCopyData3::
FarCopyDataDouble::
; Expand bc bytes of 1bpp image data
; from a:hl to 2bpp data at de.
- ld [$ff8b],a
+ ld [hROMBankTemp],a
ld a,[H_LOADEDROMBANK]
push af
- ld a,[$ff8b]
+ ld a,[hROMBankTemp]
ld [H_LOADEDROMBANK],a
ld [MBC1RomBank],a
.loop
@@ -70,7 +70,7 @@ CopyVideoData::
ld [H_AUTOBGTRANSFERENABLED], a
ld a, [H_LOADEDROMBANK]
- ld [$ff8b], a
+ ld [hROMBankTemp], a
ld a, b
ld [H_LOADEDROMBANK], a
@@ -94,7 +94,7 @@ CopyVideoData::
.done
ld [H_VBCOPYSIZE], a
call DelayFrame
- ld a, [$ff8b]
+ ld a, [hROMBankTemp]
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
pop af
@@ -119,7 +119,7 @@ CopyVideoDataDouble::
xor a ; disable auto-transfer while copying
ld [H_AUTOBGTRANSFERENABLED], a
ld a, [H_LOADEDROMBANK]
- ld [$ff8b], a
+ ld [hROMBankTemp], a
ld a, b
ld [H_LOADEDROMBANK], a
@@ -143,7 +143,7 @@ CopyVideoDataDouble::
.done
ld [H_VBCOPYDOUBLESIZE], a
call DelayFrame
- ld a, [$ff8b]
+ ld a, [hROMBankTemp]
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
pop af
@@ -161,7 +161,7 @@ CopyVideoDataDouble::
ClearScreenArea::
; Clear tilemap area cxb at hl.
- ld a, $7f ; blank tile
+ ld a, " " ; blank tile
ld de, 20 ; screen width
.y
push hl
@@ -184,17 +184,17 @@ CopyScreenTileBufferToVRAM::
ld c, 6
ld hl, $600 * 0
- ld de, wTileMap + 20 * 6 * 0
+ coord de, 0, 6 * 0
call .setup
call DelayFrame
ld hl, $600 * 1
- ld de, wTileMap + 20 * 6 * 1
+ coord de, 0, 6 * 1
call .setup
call DelayFrame
ld hl, $600 * 2
- ld de, wTileMap + 20 * 6 * 2
+ coord de, 0, 6 * 2
call .setup
jp DelayFrame
@@ -217,8 +217,8 @@ ClearScreen::
; for the bg map to update.
ld bc, 20 * 18
inc b
- ld hl, wTileMap
- ld a, $7f
+ coord hl, 0, 0
+ ld a, " "
.loop
ld [hli], a
dec c
diff --git a/home/fade.asm b/home/fade.asm
index 08e087b4..9482fcb0 100644
--- a/home/fade.asm
+++ b/home/fade.asm
@@ -1,7 +1,7 @@
; These routines manage gradual fading
; (e.g., entering a doorway)
LoadGBPal::
- ld a, [wMapPalOffset] ;tells if cur.map is dark (requires HM5_FLASH?)
+ ld a, [wMapPalOffset] ;tells if wCurMap is dark (requires HM5_FLASH?)
ld b, a
ld hl, FadePal4
ld a, l
diff --git a/home/init.asm b/home/init.asm
index cc89ad34..cb5c6583 100644
--- a/home/init.asm
+++ b/home/init.asm
@@ -1,7 +1,7 @@
SoftReset::
call StopAllSounds
call GBPalWhiteOut
- ld c, $20
+ ld c, 32
call DelayFrames
; fallthrough
@@ -23,17 +23,17 @@ rLCDC_DEFAULT EQU %11100011
xor a
ld [rIF], a
ld [rIE], a
- ld [$ff43], a
- ld [$ff42], a
+ ld [rSCX], a
+ ld [rSCY], a
ld [rSB], a
ld [rSC], a
- ld [$ff4b], a
- ld [$ff4a], a
- ld [$ff06], a
- ld [$ff07], a
- ld [$ff47], a
- ld [$ff48], a
- ld [$ff49], a
+ ld [rWX], a
+ ld [rWY], a
+ ld [rTMA], a
+ ld [rTAC], a
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld [rOBP1], a
ld a, rLCDC_ENABLE_MASK
ld [rLCDC], a
@@ -66,10 +66,10 @@ rLCDC_DEFAULT EQU %11100011
xor a
ld [hTilesetType], a
- ld [$ff41], a
+ ld [rSTAT], a
ld [hSCX], a
ld [hSCY], a
- ld [$ff0f], a
+ ld [rIF], a
ld a, 1 << VBLANK + 1 << TIMER + 1 << SERIAL
ld [rIE], a
@@ -97,13 +97,13 @@ rLCDC_DEFAULT EQU %11100011
predef LoadSGB
- ld a, BANK(SFX_1f_67)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld a, BANK(SFX_Shooting_Star)
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, $9c
- ld [$ffbd], a
+ ld [H_AUTOBGTRANSFERDEST + 1], a
xor a
- ld [$ffbc], a
+ ld [H_AUTOBGTRANSFERDEST], a
dec a
ld [wUpdateSpritesEnabled], a
@@ -126,12 +126,12 @@ ClearVram:
StopAllSounds::
- ld a, BANK(Music2_UpdateMusic)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld a, BANK(Audio1_UpdateMusic)
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
xor a
- ld [wMusicHeaderPointer], a
- ld [wc0ee], a
- ld [wcfca], a
+ ld [wAudioFadeOutControl], a
+ ld [wNewSoundID], a
+ ld [wLastMusicSoundID], a
dec a
jp PlaySound
diff --git a/home/overworld.asm b/home/overworld.asm
index c5c180c7..ec8f1925 100644
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -1,16 +1,14 @@
HandleMidJump::
; Handle the player jumping down
; a ledge in the overworld.
- ld b, BANK(_HandleMidJump)
- ld hl, _HandleMidJump
- jp Bankswitch
+ jpba _HandleMidJump
EnterMap::
; Load a new map.
ld a, $ff
ld [wJoyIgnore], a
call LoadMapData
- callba ClearVariablesAfterLoadingMapData
+ callba ClearVariablesOnEnterMap
ld hl, wd72c
bit 0, [hl] ; has the player already made 3 steps since the last battle?
jr z, .skipGivingThreeStepsOfNoRandomBattles
@@ -34,7 +32,7 @@ EnterMap::
ld hl, wd72d
res 5, [hl]
call UpdateSprites
- ld hl, wd126
+ ld hl, wCurrentMapScriptFlags
set 5, [hl]
set 6, [hl]
xor a
@@ -61,9 +59,9 @@ OverworldLoopLessDelay::
res 3,[hl]
jp nz,WarpFound2
ld a,[wd732]
- and a,1 << 4 | 1 << 3 ; fly warp or dungeon warp
+ and 1 << 4 | 1 << 3 ; fly warp or dungeon warp
jp nz,HandleFlyWarpOrDungeonWarp
- ld a,[W_CUROPPONENT]
+ ld a,[wCurOpponent]
and a
jp nz,.newBattle
ld a,[wd730]
@@ -106,27 +104,28 @@ OverworldLoopLessDelay::
bit 0,a
jr nz,.checkForOpponent
aCoord 8, 9
- ld [wcf0e],a
+ ld [wTilePlayerStandingOn],a ; unused?
call DisplayTextID ; display either the start menu or the NPC/sign text
- ld a,[wcc47]
+ ld a,[wEnteringCableClub]
and a
jr z,.checkForOpponent
dec a
- ld a,$00
- ld [wcc47],a
+ ld a,0
+ ld [wEnteringCableClub],a
jr z,.changeMap
+; XXX can this code be reached?
predef LoadSAV
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
ld [wDestinationMap],a
call SpecialWarpIn
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
call SwitchToMapRomBank ; switch to the ROM bank of the current map
- ld hl,W_CURMAPTILESET
+ ld hl,wCurMapTileset
set 7,[hl]
.changeMap
jp EnterMap
.checkForOpponent
- ld a,[W_CUROPPONENT]
+ ld a,[wCurOpponent]
and a
jp nz,.newBattle
jp OverworldLoop
@@ -134,100 +133,112 @@ OverworldLoopLessDelay::
ld hl,wFlags_0xcd60
res 2,[hl]
call UpdateSprites
- ld a,$01
- ld [wcc4b],a
- ld a,[wd528] ; the direction that was pressed last time
+ ld a, 1
+ ld [wCheckFor180DegreeTurn],a
+ ld a,[wPlayerMovingDirection] ; the direction that was pressed last time
and a
jp z,OverworldLoop
; if a direction was pressed last time
- ld [wd529],a ; save the last direction
+ ld [wPlayerLastStopDirection],a ; save the last direction
xor a
- ld [wd528],a ; zero the direction
+ ld [wPlayerMovingDirection],a ; zero the direction
jp OverworldLoop
+
.checkIfDownButtonIsPressed
ld a,[hJoyHeld] ; current joypad state
bit 7,a ; down button
jr z,.checkIfUpButtonIsPressed
- ld a,$01
- ld [wSpriteStateData1 + 3],a
- ld a,$04
+ ld a,1
+ ld [wSpriteStateData1 + 3],a ; delta Y
+ ld a,PLAYER_DIR_DOWN
jr .handleDirectionButtonPress
+
.checkIfUpButtonIsPressed
bit 6,a ; up button
jr z,.checkIfLeftButtonIsPressed
- ld a,$ff
- ld [wSpriteStateData1 + 3],a
- ld a,$08
+ ld a,-1
+ ld [wSpriteStateData1 + 3],a ; delta Y
+ ld a,PLAYER_DIR_UP
jr .handleDirectionButtonPress
+
.checkIfLeftButtonIsPressed
bit 5,a ; left button
jr z,.checkIfRightButtonIsPressed
- ld a,$ff
- ld [wSpriteStateData1 + 5],a
- ld a,$02
+ ld a,-1
+ ld [wSpriteStateData1 + 5],a ; delta X
+ ld a,PLAYER_DIR_LEFT
jr .handleDirectionButtonPress
+
.checkIfRightButtonIsPressed
bit 4,a ; right button
jr z,.noDirectionButtonsPressed
- ld a,$01
- ld [wSpriteStateData1 + 5],a
+ ld a, 1
+ ld [wSpriteStateData1 + 5],a ; delta X
+
+
.handleDirectionButtonPress
- ld [wd52a],a ; new direction
+ ld [wPlayerDirection],a ; new direction
ld a,[wd730]
bit 7,a ; are we simulating button presses?
jr nz,.noDirectionChange ; ignore direction changes if we are
- ld a,[wcc4b]
+ ld a,[wCheckFor180DegreeTurn]
and a
jr z,.noDirectionChange
- ld a,[wd52a] ; new direction
+ ld a,[wPlayerDirection] ; new direction
ld b,a
- ld a,[wd529] ; old direction
+ ld a,[wPlayerLastStopDirection] ; old direction
cp b
jr z,.noDirectionChange
-; the code below is strange
-; it computes whether or not the player did a 180 degree turn, but then overwrites the result
-; also, it does a seemingly pointless loop afterwards
+; Check whether the player did a 180-degree turn.
+; It appears that this code was supposed to show the player rotate by having
+; the player's sprite face an intermediate direction before facing the opposite
+; direction (instead of doing an instantaneous about-face), but the intermediate
+; direction is only set for a short period of time. It is unlikely for it to
+; ever be visible because DelayFrame is called at the start of OverworldLoop and
+; normally not enough cycles would be executed between then and the time the
+; direction is set for V-blank to occur while the direction is still set.
swap a ; put old direction in upper half
or b ; put new direction in lower half
- cp a,$48 ; change dir from down to up
+ cp a,(PLAYER_DIR_DOWN << 4) | PLAYER_DIR_UP ; change dir from down to up
jr nz,.notDownToUp
- ld a,$02
- ld [wd528],a
- jr .oddLoop
+ ld a,PLAYER_DIR_LEFT
+ ld [wPlayerMovingDirection],a
+ jr .holdIntermediateDirectionLoop
.notDownToUp
- cp a,$84 ; change dir from up to down
+ cp a,(PLAYER_DIR_UP << 4) | PLAYER_DIR_DOWN ; change dir from up to down
jr nz,.notUpToDown
- ld a,$01
- ld [wd528],a
- jr .oddLoop
+ ld a,PLAYER_DIR_RIGHT
+ ld [wPlayerMovingDirection],a
+ jr .holdIntermediateDirectionLoop
.notUpToDown
- cp a,$12 ; change dir from right to left
+ cp a,(PLAYER_DIR_RIGHT << 4) | PLAYER_DIR_LEFT ; change dir from right to left
jr nz,.notRightToLeft
- ld a,$04
- ld [wd528],a
- jr .oddLoop
+ ld a,PLAYER_DIR_DOWN
+ ld [wPlayerMovingDirection],a
+ jr .holdIntermediateDirectionLoop
.notRightToLeft
- cp a,$21 ; change dir from left to right
- jr nz,.oddLoop
- ld a,$08
- ld [wd528],a
-.oddLoop
+ cp a,(PLAYER_DIR_LEFT << 4) | PLAYER_DIR_RIGHT ; change dir from left to right
+ jr nz,.holdIntermediateDirectionLoop
+ ld a,PLAYER_DIR_UP
+ ld [wPlayerMovingDirection],a
+.holdIntermediateDirectionLoop
ld hl,wFlags_0xcd60
set 2,[hl]
- ld hl,wcc4b
+ ld hl,wCheckFor180DegreeTurn
dec [hl]
- jr nz,.oddLoop
- ld a,[wd52a]
- ld [wd528],a
+ jr nz,.holdIntermediateDirectionLoop
+ ld a,[wPlayerDirection]
+ ld [wPlayerMovingDirection],a
call NewBattle
jp c,.battleOccurred
jp OverworldLoop
+
.noDirectionChange
- ld a,[wd52a] ; current direction
- ld [wd528],a ; save direction
+ ld a,[wPlayerDirection] ; current direction
+ ld [wPlayerMovingDirection],a ; save direction
call UpdateSprites
ld a,[wWalkBikeSurfState]
- cp a,$02 ; surfing
+ cp $02 ; surfing
jr z,.surfing
; not surfing
call CollisionCheckOnLand
@@ -244,20 +255,24 @@ OverworldLoopLessDelay::
pop hl
jp c,CheckWarpsCollision
jp OverworldLoop
+
.surfing
call CollisionCheckOnWater
jp c,OverworldLoop
+
.noCollision
ld a,$08
ld [wWalkCounter],a
jr .moveAhead2
+
.moveAhead
ld a,[wd736]
bit 7,a
jr z,.noSpinning
- callba LoadSpinnerArrowTiles ; spin while moving
+ callba LoadSpinnerArrowTiles
.noSpinning
- call UpdateSprites ; move sprites
+ call UpdateSprites
+
.moveAhead2
ld hl,wFlags_0xcd60
res 2,[hl]
@@ -267,7 +282,7 @@ OverworldLoopLessDelay::
ld a,[wd736]
bit 6,a ; jumping a ledge?
jr nz,.normalPlayerSpriteAdvancement
- call BikeSpeedup ; if riding a bike and not jumping a ledge
+ call DoBikeSpeedup
.normalPlayerSpriteAdvancement
call AdvancePlayerSprite
ld a,[wWalkCounter]
@@ -289,19 +304,18 @@ OverworldLoopLessDelay::
ld hl,wd72c
res 0,[hl] ; indicate that the player has stepped thrice since the last battle
.doneStepCounting
- ld a,[wd790]
- bit 7,a ; in the safari zone?
+ CheckEvent EVENT_IN_SAFARI_ZONE
jr z,.notSafariZone
callba SafariZoneCheckSteps
ld a,[wSafariZoneGameOver]
and a
jp nz,WarpFound2
.notSafariZone
- ld a,[W_ISINBATTLE]
+ ld a,[wIsInBattle]
and a
jp nz,CheckWarpsNoCollision
predef ApplyOutOfBattlePoisonDamage ; also increment daycare mon exp
- ld a,[wd12d]
+ ld a,[wOutOfBattleBlackout]
and a
jp nz,HandleBlackOut ; if all pokemon fainted
.newBattle
@@ -312,41 +326,40 @@ OverworldLoopLessDelay::
.battleOccurred
ld hl,wd72d
res 6,[hl]
- ld hl,W_FLAGS_D733
+ ld hl,wFlags_D733
res 3,[hl]
- ld hl,wd126
+ ld hl,wCurrentMapScriptFlags
set 5,[hl]
set 6,[hl]
xor a
ld [hJoyHeld],a
- ld a,[W_CURMAP]
- cp a,CINNABAR_GYM
+ ld a,[wCurMap]
+ cp CINNABAR_GYM
jr nz,.notCinnabarGym
- ld hl,wd79b
- set 7,[hl]
+ SetEvent EVENT_2A7
.notCinnabarGym
ld hl,wd72e
set 5,[hl]
- ld a,[W_CURMAP]
- cp a,OAKS_LAB
+ ld a,[wCurMap]
+ cp OAKS_LAB
jp z,.noFaintCheck ; no blacking out if the player lost to the rival in Oak's lab
callab AnyPartyAlive
ld a,d
and a
jr z,.allPokemonFainted
.noFaintCheck
- ld c,$0a
+ ld c,10
call DelayFrames
jp EnterMap
.allPokemonFainted
ld a,$ff
- ld [W_ISINBATTLE],a
+ ld [wIsInBattle],a
call RunMapScript
jp HandleBlackOut
; function to determine if there will be a battle and execute it (either a trainer battle or wild battle)
; sets carry if a battle occurred and unsets carry if not
-NewBattle:: ; 0683 (0:0683)
+NewBattle::
ld a,[wd72d]
bit 4,a
jr nz,.noBattle
@@ -355,41 +368,39 @@ NewBattle:: ; 0683 (0:0683)
ld a,[wd72e]
bit 4,a
jr nz,.noBattle
- ld b, BANK(InitBattle)
- ld hl, InitBattle
- jp Bankswitch
+ jpba InitBattle
.noBattle
and a
ret
; function to make bikes twice as fast as walking
-BikeSpeedup:: ; 06a0 (0:06a0)
+DoBikeSpeedup::
ld a,[wNPCMovementScriptPointerTableNum]
and a
ret nz
- ld a,[W_CURMAP]
- cp a,ROUTE_17 ; Cycling Road
+ ld a,[wCurMap]
+ cp ROUTE_17 ; Cycling Road
jr nz,.goFaster
ld a,[hJoyHeld]
- and a,D_UP | D_LEFT | D_RIGHT
+ and D_UP | D_LEFT | D_RIGHT
ret nz
.goFaster
jp AdvancePlayerSprite
; check if the player has stepped onto a warp after having not collided
-CheckWarpsNoCollision:: ; 06b4 (0:06b4)
+CheckWarpsNoCollision::
ld a,[wNumberOfWarps]
and a
jp z,CheckMapConnections
ld a,[wNumberOfWarps]
ld b,0
ld c,a
- ld a,[W_YCOORD]
+ ld a,[wYCoord]
ld d,a
- ld a,[W_XCOORD]
+ ld a,[wXCoord]
ld e,a
ld hl,wWarpEntries
-CheckWarpsNoCollisionLoop:: ; 06cc (0:06cc)
+CheckWarpsNoCollisionLoop::
ld a,[hli] ; check if the warp's Y position matches
cp d
jr nz,CheckWarpsNoCollisionRetry1
@@ -412,7 +423,7 @@ CheckWarpsNoCollisionLoop:: ; 06cc (0:06cc)
pop hl
jr nc,CheckWarpsNoCollisionRetry2
; if the extra check passed
- ld a,[W_FLAGS_D733]
+ ld a,[wFlags_D733]
bit 2,a
jr nz,WarpFound1
push de
@@ -421,30 +432,30 @@ CheckWarpsNoCollisionLoop:: ; 06cc (0:06cc)
pop bc
pop de
ld a,[hJoyHeld]
- and a,D_DOWN | D_UP | D_LEFT | D_RIGHT
+ and D_DOWN | D_UP | D_LEFT | D_RIGHT
jr z,CheckWarpsNoCollisionRetry2 ; if directional buttons aren't being pressed, do not pass through the warp
jr WarpFound1
; check if the player has stepped onto a warp after having collided
-CheckWarpsCollision:: ; 0706 (0:0706)
+CheckWarpsCollision::
ld a,[wNumberOfWarps]
ld c,a
ld hl,wWarpEntries
.loop
ld a,[hli] ; Y coordinate of warp
ld b,a
- ld a,[W_YCOORD]
+ ld a,[wYCoord]
cp b
jr nz,.retry1
ld a,[hli] ; X coordinate of warp
ld b,a
- ld a,[W_XCOORD]
+ ld a,[wXCoord]
cp b
jr nz,.retry2
ld a,[hli]
ld [wDestinationWarpID],a
ld a,[hl]
- ld [$ff8b],a ; save target map
+ ld [hWarpDestinationMap],a
jr WarpFound2
.retry1
inc hl
@@ -455,35 +466,35 @@ CheckWarpsCollision:: ; 0706 (0:0706)
jr nz,.loop
jp OverworldLoop
-CheckWarpsNoCollisionRetry1:: ; 072f (0:072f)
+CheckWarpsNoCollisionRetry1::
inc hl
-CheckWarpsNoCollisionRetry2:: ; 0730 (0:0730)
+CheckWarpsNoCollisionRetry2::
inc hl
inc hl
jp ContinueCheckWarpsNoCollisionLoop
-WarpFound1:: ; 0735 (0:0735)
+WarpFound1::
ld a,[hli]
ld [wDestinationWarpID],a
ld a,[hli]
- ld [$ff8b],a ; save target map
+ ld [hWarpDestinationMap],a
-WarpFound2:: ; 073c (0:073c)
+WarpFound2::
ld a,[wNumberOfWarps]
sub c
- ld [wd73b],a ; save ID of used warp
- ld a,[W_CURMAP]
- ld [wd73c],a
+ ld [wWarpedFromWhichWarp],a ; save ID of used warp
+ ld a,[wCurMap]
+ ld [wWarpedFromWhichMap],a
call CheckIfInOutsideMap
jr nz,.indoorMaps
; this is for handling "outside" maps that can't have the 0xFF destination map
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
ld [wLastMap],a
- ld a,[W_CURMAPWIDTH]
- ld [wd366],a
- ld a,[$ff8b] ; destination map number
- ld [W_CURMAP],a ; change current map to destination map
- cp a,ROCK_TUNNEL_1
+ ld a,[wCurMapWidth]
+ ld [wUnusedD366],a ; not read
+ ld a,[hWarpDestinationMap]
+ ld [wCurMap],a
+ cp ROCK_TUNNEL_1
jr nz,.notRockTunnel
ld a,$06
ld [wMapPalOffset],a
@@ -491,15 +502,17 @@ WarpFound2:: ; 073c (0:073c)
.notRockTunnel
call PlayMapChangeSound
jr .done
-; for maps that can have the 0xFF destination map, which means to return to the outside map; not all these maps are necessarily indoors, though
+
+; for maps that can have the 0xFF destination map, which means to return to the outside map
+; not all these maps are necessarily indoors, though
.indoorMaps
- ld a,[$ff8b] ; destination map
- cp a,$ff
+ ld a,[hWarpDestinationMap] ; destination map
+ cp $ff
jr z,.goBackOutside
; if not going back to the previous map
- ld [W_CURMAP],a ; current map number
+ ld [wCurMap],a
callba IsPlayerStandingOnWarpPadOrHole
- ld a,[wcd5b]
+ ld a,[wStandingOnWarpPadOrHole]
dec a ; is the player on a warp pad?
jr nz,.notWarpPad
; if the player is on a warp pad
@@ -516,7 +529,7 @@ WarpFound2:: ; 073c (0:073c)
jr .done
.goBackOutside
ld a,[wLastMap]
- ld [W_CURMAP],a
+ ld [wCurMap],a
call PlayMapChangeSound
xor a
ld [wMapPalOffset],a
@@ -526,39 +539,39 @@ WarpFound2:: ; 073c (0:073c)
call IgnoreInputForHalfSecond
jp EnterMap
-ContinueCheckWarpsNoCollisionLoop:: ; 07b5 (0:07b5)
+ContinueCheckWarpsNoCollisionLoop::
inc b ; increment warp number
dec c ; decrement number of warps
jp nz,CheckWarpsNoCollisionLoop
; if no matching warp was found
-CheckMapConnections:: ; 07ba (0:07ba)
+CheckMapConnections::
.checkWestMap
- ld a,[W_XCOORD]
- cp a,$ff
+ ld a,[wXCoord]
+ cp $ff
jr nz,.checkEastMap
- ld a,[W_MAPCONN3PTR]
- ld [W_CURMAP],a
- ld a,[wd38f] ; new X coordinate upon entering west map
- ld [W_XCOORD],a
- ld a,[W_YCOORD]
+ ld a,[wMapConn3Ptr]
+ ld [wCurMap],a
+ ld a,[wWestConnectedMapXAlignment] ; new X coordinate upon entering west map
+ ld [wXCoord],a
+ ld a,[wYCoord]
ld c,a
- ld a,[wd38e] ; Y adjustment upon entering west map
+ ld a,[wWestConnectedMapYAlignment] ; Y adjustment upon entering west map
add c
ld c,a
- ld [W_YCOORD],a
- ld a,[wd390] ; pointer to upper left corner of map without adjustment for Y position
+ ld [wYCoord],a
+ ld a,[wWestConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for Y position
ld l,a
- ld a,[wd391]
+ ld a,[wWestConnectedMapViewPointer + 1]
ld h,a
srl c
jr z,.savePointer1
.pointerAdjustmentLoop1
- ld a,[wd38d] ; width of connected map
- add a,$06
+ ld a,[wWestConnectedMapWidth] ; width of connected map
+ add MAP_BORDER * 2
ld e,a
- ld d,$00
- ld b,$00
+ ld d,0
+ ld b,0
add hl,de
dec c
jr nz,.pointerAdjustmentLoop1
@@ -568,33 +581,34 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld a,h
ld [wCurrentTileBlockMapViewPointer + 1],a
jp .loadNewMap
+
.checkEastMap
ld b,a
- ld a,[wd525] ; map width
+ ld a,[wCurrentMapWidth2] ; map width
cp b
jr nz,.checkNorthMap
- ld a,[W_MAPCONN4PTR]
- ld [W_CURMAP],a
- ld a,[wd39a] ; new X coordinate upon entering east map
- ld [W_XCOORD],a
- ld a,[W_YCOORD]
+ ld a,[wMapConn4Ptr]
+ ld [wCurMap],a
+ ld a,[wEastConnectedMapXAlignment] ; new X coordinate upon entering east map
+ ld [wXCoord],a
+ ld a,[wYCoord]
ld c,a
- ld a,[wd399] ; Y adjustment upon entering east map
+ ld a,[wEastConnectedMapYAlignment] ; Y adjustment upon entering east map
add c
ld c,a
- ld [W_YCOORD],a
- ld a,[wd39b] ; pointer to upper left corner of map without adjustment for Y position
+ ld [wYCoord],a
+ ld a,[wEastConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for Y position
ld l,a
- ld a,[wd39c]
+ ld a,[wEastConnectedMapViewPointer + 1]
ld h,a
srl c
jr z,.savePointer2
.pointerAdjustmentLoop2
- ld a,[wd398]
- add a,$06
+ ld a,[wEastConnectedMapWidth]
+ add MAP_BORDER * 2
ld e,a
- ld d,$00
- ld b,$00
+ ld d,0
+ ld b,0
add hl,de
dec c
jr nz,.pointerAdjustmentLoop2
@@ -604,25 +618,26 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld a,h
ld [wCurrentTileBlockMapViewPointer + 1],a
jp .loadNewMap
+
.checkNorthMap
- ld a,[W_YCOORD]
- cp a,$ff
+ ld a,[wYCoord]
+ cp $ff
jr nz,.checkSouthMap
- ld a,[W_MAPCONN1PTR]
- ld [W_CURMAP],a
- ld a,[wd378] ; new Y coordinate upon entering north map
- ld [W_YCOORD],a
- ld a,[W_XCOORD]
+ ld a,[wMapConn1Ptr]
+ ld [wCurMap],a
+ ld a,[wNorthConnectedMapYAlignment] ; new Y coordinate upon entering north map
+ ld [wYCoord],a
+ ld a,[wXCoord]
ld c,a
- ld a,[wd379] ; X adjustment upon entering north map
+ ld a,[wNorthConnectedMapXAlignment] ; X adjustment upon entering north map
add c
ld c,a
- ld [W_XCOORD],a
- ld a,[wd37a] ; pointer to upper left corner of map without adjustment for X position
+ ld [wXCoord],a
+ ld a,[wNorthConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for X position
ld l,a
- ld a,[wd37b]
+ ld a,[wNorthConnectedMapViewPointer + 1]
ld h,a
- ld b,$00
+ ld b,0
srl c
add hl,bc
ld a,l
@@ -630,26 +645,27 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld a,h
ld [wCurrentTileBlockMapViewPointer + 1],a
jp .loadNewMap
+
.checkSouthMap
ld b,a
- ld a,[wd524]
+ ld a,[wCurrentMapHeight2]
cp b
jr nz,.didNotEnterConnectedMap
- ld a,[W_MAPCONN2PTR]
- ld [W_CURMAP],a
- ld a,[wd383] ; new Y coordinate upon entering south map
- ld [W_YCOORD],a
- ld a,[W_XCOORD]
+ ld a,[wMapConn2Ptr]
+ ld [wCurMap],a
+ ld a,[wSouthConnectedMapYAlignment] ; new Y coordinate upon entering south map
+ ld [wYCoord],a
+ ld a,[wXCoord]
ld c,a
- ld a,[wd384] ; X adjustment upon entering south map
+ ld a,[wSouthConnectedMapXAlignment] ; X adjustment upon entering south map
add c
ld c,a
- ld [W_XCOORD],a
- ld a,[wd385] ; pointer to upper left corner of map without adjustment for X position
+ ld [wXCoord],a
+ ld a,[wSouthConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for X position
ld l,a
- ld a,[wd386]
+ ld a,[wSouthConnectedMapViewPointer + 1]
ld h,a
- ld b,$00
+ ld b,0
srl c
add hl,bc
ld a,l
@@ -658,26 +674,27 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld [wCurrentTileBlockMapViewPointer + 1],a
.loadNewMap ; load the connected map that was entered
call LoadMapHeader
- call Func_2312 ; music
- ld b,$09
- call GoPAL_SET
+ call PlayDefaultMusicFadeOutCurrent
+ ld b, SET_PAL_OVERWORLD
+ call RunPaletteCommand
; Since the sprite set shouldn't change, this will just update VRAM slots at
; $C2XE without loading any tile patterns.
callba InitMapSprites
call LoadTileBlockMap
jp OverworldLoopLessDelay
+
.didNotEnterConnectedMap
jp OverworldLoop
; function to play a sound when changing maps
-PlayMapChangeSound:: ; 08c9 (0:08c9)
+PlayMapChangeSound::
aCoord 8, 8 ; upper left tile of the 4x4 square the player's sprite is standing on
- cp a,$0b ; door tile in tileset 0
+ cp $0b ; door tile in tileset 0
jr nz,.didNotGoThroughDoor
- ld a,(SFX_02_57 - SFX_Headers_02) / 3
+ ld a,SFX_GO_INSIDE
jr .playSound
.didNotGoThroughDoor
- ld a,(SFX_02_5c - SFX_Headers_02) / 3
+ ld a,SFX_GO_OUTSIDE
.playSound
call PlaySound
ld a,[wMapPalOffset]
@@ -685,9 +702,9 @@ PlayMapChangeSound:: ; 08c9 (0:08c9)
ret nz
jp GBFadeOutToBlack
-CheckIfInOutsideMap:: ; 08e1 (0:08e1)
+CheckIfInOutsideMap::
; If the player is in an outside map (a town or route), set the z flag
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
and a ; most towns/routes have tileset 0 (OVERWORLD)
ret z
cp PLATEAU ; Route 23 / Indigo Plateau
@@ -699,8 +716,8 @@ CheckIfInOutsideMap:: ; 08e1 (0:08e1)
; "function 1" passes when the player is at the edge of the map and is facing towards the outside of the map
; "function 2" passes when the the tile in front of the player is among a certain set
; sets carry if the check passes, otherwise clears carry
-ExtraWarpCheck:: ; 08e9 (0:08e9)
- ld a, [W_CURMAP]
+ExtraWarpCheck::
+ ld a, [wCurMap]
cp SS_ANNE_3
jr z, .useFunction1
cp ROCKET_HIDEOUT_1
@@ -711,7 +728,7 @@ ExtraWarpCheck:: ; 08e9 (0:08e9)
jr z, .useFunction2
cp ROCK_TUNNEL_1
jr z, .useFunction2
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
and a ; outside tileset (OVERWORLD)
jr z, .useFunction2
cp SHIP ; S.S. Anne tileset
@@ -729,7 +746,7 @@ ExtraWarpCheck:: ; 08e9 (0:08e9)
ld b, BANK(IsWarpTileInFrontOfPlayer)
jp Bankswitch
-MapEntryAfterBattle:: ; 091f (0:091f)
+MapEntryAfterBattle::
callba IsPlayerStandingOnWarp ; for enabling warp testing after collisions
ld a,[wMapPalOffset]
and a
@@ -750,16 +767,16 @@ HandleBlackOut::
ld [MBC1RomBank], a
call ResetStatusAndHalveMoneyOnBlackout
call SpecialWarpIn
- call Func_2312
+ call PlayDefaultMusicFadeOutCurrent
jp SpecialEnterMap
StopMusic::
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
.wait
- ld a, [wMusicHeaderPointer]
+ ld a, [wAudioFadeOutControl]
and a
jr nz, .wait
jp StopAllSounds
@@ -770,7 +787,7 @@ HandleFlyWarpOrDungeonWarp::
xor a
ld [wBattleResult], a
ld [wWalkBikeSurfState], a
- ld [W_ISINBATTLE], a
+ ld [wIsInBattle], a
ld [wMapPalOffset], a
ld hl, wd732
set 2, [hl] ; fly warp or dungeon warp
@@ -778,14 +795,12 @@ HandleFlyWarpOrDungeonWarp::
call LeaveMapAnim
ld a, Bank(SpecialWarpIn)
ld [H_LOADEDROMBANK], a
- ld [$2000], a
+ ld [MBC1RomBank], a
call SpecialWarpIn
jp SpecialEnterMap
LeaveMapAnim::
- ld b, BANK(_LeaveMapAnim)
- ld hl, _LeaveMapAnim
- jp Bankswitch
+ jpba _LeaveMapAnim
LoadPlayerSpriteGraphics::
; Load sprite graphics based on whether the player is standing, biking, or surfing.
@@ -830,13 +845,13 @@ IsBikeRidingAllowed::
; or maps with tilesets in BikeRidingTilesets.
; Return carry if biking is allowed.
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
cp ROUTE_23
jr z, .allowed
cp INDIGO_PLATEAU
jr z, .allowed
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld b, a
ld hl, BikeRidingTilesets
.loop
@@ -855,22 +870,22 @@ IsBikeRidingAllowed::
INCLUDE "data/bike_riding_tilesets.asm"
; load the tile pattern data of the current tileset into VRAM
-LoadTilesetTilePatternData:: ; 09e8 (0:09e8)
- ld a,[W_TILESETGFXPTR]
+LoadTilesetTilePatternData::
+ ld a,[wTilesetGfxPtr]
ld l,a
- ld a,[W_TILESETGFXPTR + 1]
+ ld a,[wTilesetGfxPtr + 1]
ld h,a
ld de,vTileset
ld bc,$600
- ld a,[W_TILESETBANK]
+ ld a,[wTilesetBank]
jp FarCopyData2
; this loads the current maps complete tile map (which references blocks, not individual tiles) to C6E8
; it can also load partial tile maps of connected maps into a border of length 3 around the current map
-LoadTileBlockMap:: ; 09fc (0:09fc)
+LoadTileBlockMap::
; fill C6E8-CBFB with the background tile
ld hl,wOverworldMap
- ld a,[wd3ad] ; background tile number
+ ld a,[wMapBackgroundTile]
ld d,a
ld bc,$0514
.backgroundTileLoop
@@ -883,27 +898,27 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
; load tile map of current map (made of tile block IDs)
; a 3-byte border at the edges of the map is kept so that there is space for map connections
ld hl,wOverworldMap
- ld a,[W_CURMAPWIDTH]
- ld [$ff8c],a
- add a,$06 ; border (east and west)
- ld [$ff8b],a ; map width + border
- ld b,$00
+ ld a,[wCurMapWidth]
+ ld [hMapWidth],a
+ add MAP_BORDER * 2 ; east and west
+ ld [hMapStride],a ; map width + border
+ ld b,0
ld c,a
; make space for north border (next 3 lines)
add hl,bc
add hl,bc
add hl,bc
- ld c,$03
+ ld c,MAP_BORDER
add hl,bc ; this puts us past the (west) border
- ld a,[W_MAPDATAPTR] ; tile map pointer
+ ld a,[wMapDataPtr] ; tile map pointer
ld e,a
- ld a,[W_MAPDATAPTR + 1]
+ ld a,[wMapDataPtr + 1]
ld d,a ; de = tile map pointer
- ld a,[W_CURMAPHEIGHT]
+ ld a,[wCurMapHeight]
ld b,a
.rowLoop ; copy one row each iteration
push hl
- ld a,[$ff8c] ; map width (without border)
+ ld a,[hMapWidth] ; map width (without border)
ld c,a
.rowInnerLoop
ld a,[de]
@@ -913,7 +928,7 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
jr nz,.rowInnerLoop
; add the map width plus the border to the base address of the current row to get the next row's address
pop hl
- ld a,[$ff8b] ; map width + border
+ ld a,[hMapStride] ; map width + border
add l
ld l,a
jr nc,.noCarry
@@ -922,86 +937,86 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
dec b
jr nz,.rowLoop
.northConnection
- ld a,[W_MAPCONN1PTR]
- cp a,$ff
+ ld a,[wMapConn1Ptr]
+ cp $ff
jr z,.southConnection
call SwitchToMapRomBank
- ld a,[wd372]
+ ld a,[wNorthConnectionStripSrc]
ld l,a
- ld a,[wd373]
+ ld a,[wNorthConnectionStripSrc + 1]
ld h,a
- ld a,[wd374]
+ ld a,[wNorthConnectionStripDest]
ld e,a
- ld a,[wd375]
+ ld a,[wNorthConnectionStripDest + 1]
ld d,a
- ld a,[wd376]
- ld [$ff8b],a
- ld a,[wd377]
- ld [$ff8c],a
+ ld a,[wNorthConnectionStripWidth]
+ ld [hNorthSouthConnectionStripWidth],a
+ ld a,[wNorthConnectedMapWidth]
+ ld [hNorthSouthConnectedMapWidth],a
call LoadNorthSouthConnectionsTileMap
.southConnection
- ld a,[W_MAPCONN2PTR]
- cp a,$ff
+ ld a,[wMapConn2Ptr]
+ cp $ff
jr z,.westConnection
call SwitchToMapRomBank
- ld a,[wd37d]
+ ld a,[wSouthConnectionStripSrc]
ld l,a
- ld a,[wd37e]
+ ld a,[wSouthConnectionStripSrc + 1]
ld h,a
- ld a,[wd37f]
+ ld a,[wSouthConnectionStripDest]
ld e,a
- ld a,[wd380]
+ ld a,[wSouthConnectionStripDest + 1]
ld d,a
- ld a,[wd381]
- ld [$ff8b],a
- ld a,[wd382]
- ld [$ff8c],a
+ ld a,[wSouthConnectionStripWidth]
+ ld [hNorthSouthConnectionStripWidth],a
+ ld a,[wSouthConnectedMapWidth]
+ ld [hNorthSouthConnectedMapWidth],a
call LoadNorthSouthConnectionsTileMap
.westConnection
- ld a,[W_MAPCONN3PTR]
- cp a,$ff
+ ld a,[wMapConn3Ptr]
+ cp $ff
jr z,.eastConnection
call SwitchToMapRomBank
- ld a,[wd388]
+ ld a,[wWestConnectionStripSrc]
ld l,a
- ld a,[wd389]
+ ld a,[wWestConnectionStripSrc + 1]
ld h,a
- ld a,[wd38a]
+ ld a,[wWestConnectionStripDest]
ld e,a
- ld a,[wd38b]
+ ld a,[wWestConnectionStripDest + 1]
ld d,a
- ld a,[wd38c]
+ ld a,[wWestConnectionStripHeight]
ld b,a
- ld a,[wd38d]
- ld [$ff8b],a
+ ld a,[wWestConnectedMapWidth]
+ ld [hEastWestConnectedMapWidth],a
call LoadEastWestConnectionsTileMap
.eastConnection
- ld a,[W_MAPCONN4PTR]
- cp a,$ff
+ ld a,[wMapConn4Ptr]
+ cp $ff
jr z,.done
call SwitchToMapRomBank
- ld a,[wd393]
+ ld a,[wEastConnectionStripSrc]
ld l,a
- ld a,[wd394]
+ ld a,[wEastConnectionStripSrc + 1]
ld h,a
- ld a,[wd395]
+ ld a,[wEastConnectionStripDest]
ld e,a
- ld a,[wd396]
+ ld a,[wEastConnectionStripDest + 1]
ld d,a
- ld a,[wd397]
+ ld a,[wEastConnectionStripHeight]
ld b,a
- ld a,[wd398]
- ld [$ff8b],a
+ ld a,[wEastConnectedMapWidth]
+ ld [hEastWestConnectedMapWidth],a
call LoadEastWestConnectionsTileMap
.done
ret
-LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
- ld c,$03
+LoadNorthSouthConnectionsTileMap::
+ ld c,MAP_BORDER
.loop
push de
push hl
- ld a,[$ff8b] ; width of connection
+ ld a,[hNorthSouthConnectionStripWidth]
ld b,a
.innerLoop
ld a,[hli]
@@ -1011,14 +1026,14 @@ LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
jr nz,.innerLoop
pop hl
pop de
- ld a,[$ff8c] ; width of connected map
+ ld a,[hNorthSouthConnectedMapWidth]
add l
ld l,a
jr nc,.noCarry1
inc h
.noCarry1
- ld a,[W_CURMAPWIDTH]
- add a,$06
+ ld a,[wCurMapWidth]
+ add MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry2
@@ -1028,10 +1043,10 @@ LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
jr nz,.loop
ret
-LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
+LoadEastWestConnectionsTileMap::
push hl
push de
- ld c,$03
+ ld c,MAP_BORDER
.innerLoop
ld a,[hli]
ld [de],a
@@ -1040,14 +1055,14 @@ LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
jr nz,.innerLoop
pop de
pop hl
- ld a,[$ff8b] ; width of connected map
+ ld a,[hEastWestConnectedMapWidth]
add l
ld l,a
jr nc,.noCarry1
inc h
.noCarry1
- ld a,[W_CURMAPWIDTH]
- add a,$06
+ ld a,[wCurMapWidth]
+ add MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry2
@@ -1060,18 +1075,18 @@ LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
; function to check if there is a sign or sprite in front of the player
; if so, it is stored in [hSpriteIndexOrTextID]
; if not, [hSpriteIndexOrTextID] is set to 0
-IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
+IsSpriteOrSignInFrontOfPlayer::
xor a
ld [hSpriteIndexOrTextID],a
- ld a,[wd4b0] ; number of signs in the map
+ ld a,[wNumSigns]
and a
jr z,.extendRangeOverCounter
; if there are signs
predef GetTileAndCoordsInFrontOfPlayer ; get the coordinates in front of the player in de
- ld hl,wd4b1 ; start of sign coordinates
- ld a,[wd4b0] ; number of signs in the map
+ ld hl,wSignCoords
+ ld a,[wNumSigns]
ld b,a
- ld c,$00
+ ld c,0
.signLoop
inc c
ld a,[hli] ; sign Y
@@ -1087,8 +1102,8 @@ IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
; found sign
push hl
push bc
- ld hl,wd4d1 ; start of sign text ID's
- ld b,$00
+ ld hl,wSignTextIDs
+ ld b,0
dec c
add hl,bc
ld a,[hl]
@@ -1102,8 +1117,8 @@ IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
; check if the player is front of a counter in a pokemon center, pokemart, etc. and if so, extend the range at which he can talk to the NPC
.extendRangeOverCounter
predef GetTileAndCoordsInFrontOfPlayer ; get the tile in front of the player in c
- ld hl,W_TILESETTALKINGOVERTILES ; list of tiles that extend talking range (counter tiles)
- ld b,$03
+ ld hl,wTilesetTalkingOverTiles ; list of tiles that extend talking range (counter tiles)
+ ld b,3
ld d,$20 ; talking range in pixels (long range)
.counterTilesLoop
ld a,[hli]
@@ -1114,47 +1129,50 @@ IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
; part of the above function, but sometimes its called on its own, when signs are irrelevant
; the caller must zero [hSpriteIndexOrTextID]
-IsSpriteInFrontOfPlayer:: ; 0b6b (0:0b6b)
+IsSpriteInFrontOfPlayer::
ld d,$10 ; talking range in pixels (normal range)
-IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
- ld bc,$3c40 ; Y and X position of player sprite
+IsSpriteInFrontOfPlayer2::
+ lb bc, $3c, $40 ; Y and X position of player sprite
ld a,[wSpriteStateData1 + 9] ; direction the player is facing
.checkIfPlayerFacingUp
- cp a,$04
+ cp SPRITE_FACING_UP
jr nz,.checkIfPlayerFacingDown
; facing up
ld a,b
sub d
ld b,a
- ld a,$08
+ ld a,PLAYER_DIR_UP
jr .doneCheckingDirection
+
.checkIfPlayerFacingDown
- cp a,$00
+ cp SPRITE_FACING_DOWN
jr nz,.checkIfPlayerFacingRight
; facing down
ld a,b
add d
ld b,a
- ld a,$04
+ ld a,PLAYER_DIR_DOWN
jr .doneCheckingDirection
+
.checkIfPlayerFacingRight
- cp a,$0c
+ cp SPRITE_FACING_RIGHT
jr nz,.playerFacingLeft
; facing right
ld a,c
add d
ld c,a
- ld a,$01
+ ld a,PLAYER_DIR_RIGHT
jr .doneCheckingDirection
+
.playerFacingLeft
; facing left
ld a,c
sub d
ld c,a
- ld a,$02
+ ld a,PLAYER_DIR_LEFT
.doneCheckingDirection
- ld [wd52a],a
- ld a,[W_NUMSPRITES] ; number of sprites
+ ld [wPlayerDirection],a
+ ld a,[wNumSprites] ; number of sprites
and a
ret z
; if there are sprites
@@ -1192,15 +1210,15 @@ IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
ld a,l
and a,$f0
inc a
- ld l,a
- set 7,[hl]
+ ld l,a ; hl = $c1x1
+ set 7,[hl] ; set flag to make the sprite face the player
ld a,e
ld [hSpriteIndexOrTextID],a
ret
; function to check if the player will jump down a ledge and check if the tile ahead is passable (when not surfing)
; sets the carry flag if there is a collision, and unsets it if there isn't a collision
-CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
+CollisionCheckOnLand::
ld a,[wd736]
bit 6,a ; is the player jumping?
jr nz,.noCollision
@@ -1208,7 +1226,7 @@ CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
ld a,[wSimulatedJoypadStatesIndex]
and a
jr nz,.noCollision ; no collisions when the player's movements are being controlled by the game
- ld a,[wd52a] ; the direction that the player is trying to go in
+ ld a,[wPlayerDirection] ; the direction that the player is trying to go in
ld d,a
ld a,[wSpriteStateData1 + 12] ; the player sprite's collision data (bit field) (set in the sprite movement code)
and d ; check if a sprite is in the direction the player is trying to go
@@ -1226,10 +1244,10 @@ CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
call CheckTilePassable
jr nc,.noCollision
.collision
- ld a,[wc02a]
- cp a,(SFX_02_5b - SFX_Headers_02) / 3 ; check if collision sound is already playing
+ ld a,[wChannelSoundIDs + Ch4]
+ cp SFX_COLLISION ; check if collision sound is already playing
jr z,.setCarry
- ld a,(SFX_02_5b - SFX_Headers_02) / 3
+ ld a,SFX_COLLISION
call PlaySound ; play collision sound (if it's not already playing)
.setCarry
scf
@@ -1240,11 +1258,11 @@ CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
; function that checks if the tile in front of the player is passable
; clears carry if it is, sets carry if not
-CheckTilePassable:: ; 0c10 (0:0c10)
+CheckTilePassable::
predef GetTileAndCoordsInFrontOfPlayer ; get tile in front of player
ld a,[wTileInFrontOfPlayer] ; tile in front of player
ld c,a
- ld hl,W_TILESETCOLLISIONPTR ; pointer to list of passable tiles
+ ld hl,wTilesetCollisionPtr ; pointer to list of passable tiles
ld a,[hli]
ld h,[hl]
ld l,a ; hl now points to passable tiles
@@ -1263,7 +1281,7 @@ CheckTilePassable:: ; 0c10 (0:0c10)
; and check for collisions that only occur between certain pairs of tiles
; Input: hl - address of directional collision data
; sets carry if there is a collision and unsets carry if not
-CheckForJumpingAndTilePairCollisions:: ; 0c2a (0:0c2a)
+CheckForJumpingAndTilePairCollisions::
push hl
predef GetTileAndCoordsInFrontOfPlayer ; get the tile in front of the player
push de
@@ -1278,18 +1296,18 @@ CheckForJumpingAndTilePairCollisions:: ; 0c2a (0:0c2a)
ret nz
; if not jumping
-CheckForTilePairCollisions2:: ; 0c44 (0:0c44)
+CheckForTilePairCollisions2::
aCoord 8, 9 ; tile the player is on
- ld [wcf0e],a
+ ld [wTilePlayerStandingOn],a
-CheckForTilePairCollisions:: ; 0c4a (0:0c4a)
+CheckForTilePairCollisions::
ld a,[wTileInFrontOfPlayer]
ld c,a
.tilePairCollisionLoop
- ld a,[W_CURMAPTILESET] ; tileset number
+ ld a,[wCurMapTileset] ; tileset number
ld b,a
ld a,[hli]
- cp a,$ff
+ cp $ff
jr z,.noMatch
cp b
jr z,.tilesetMatches
@@ -1298,7 +1316,7 @@ CheckForTilePairCollisions:: ; 0c4a (0:0c4a)
inc hl
jr .tilePairCollisionLoop
.tilesetMatches
- ld a,[wcf0e] ; tile the player is on
+ ld a,[wTilePlayerStandingOn] ; tile the player is on
ld b,a
ld a,[hl]
cp b
@@ -1332,7 +1350,7 @@ CheckForTilePairCollisions:: ; 0c4a (0:0c4a)
; these entries indicate that the player may not cross between tile 1 and tile 2
; it's mainly used to simulate differences in elevation
-TilePairCollisionsLand:: ; 0c7e (0:0c7e)
+TilePairCollisionsLand::
db CAVERN, $20, $05
db CAVERN, $41, $05
db FOREST, $30, $2E
@@ -1346,19 +1364,19 @@ TilePairCollisionsLand:: ; 0c7e (0:0c7e)
db FOREST, $5F, $2E
db $FF
-TilePairCollisionsWater:: ; 0ca0 (0:0ca0)
+TilePairCollisionsWater::
db FOREST, $14, $2E
db FOREST, $48, $2E
db CAVERN, $14, $05
db $FF
; this builds a tile map from the tile block map based on the current X/Y coordinates of the player's character
-LoadCurrentMapView:: ; 0caa (0:0caa)
+LoadCurrentMapView::
ld a,[H_LOADEDROMBANK]
push af
- ld a,[W_TILESETBANK] ; tile data ROM bank
+ ld a,[wTilesetBank] ; tile data ROM bank
ld [H_LOADEDROMBANK],a
- ld [$2000],a ; switch to ROM bank that contains tile data
+ ld [MBC1RomBank],a ; switch to ROM bank that contains tile data
ld a,[wCurrentTileBlockMapViewPointer] ; address of upper left corner of current map view
ld e,a
ld a,[wCurrentTileBlockMapViewPointer + 1]
@@ -1388,8 +1406,8 @@ LoadCurrentMapView:: ; 0caa (0:0caa)
jr nz,.rowInnerLoop
; update tile block map pointer to next row's address
pop de
- ld a,[W_CURMAPWIDTH]
- add a,$06
+ ld a,[wCurMapWidth]
+ add MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry
@@ -1408,22 +1426,22 @@ LoadCurrentMapView:: ; 0caa (0:0caa)
ld hl,wTileMapBackup
ld bc,$0000
.adjustForYCoordWithinTileBlock
- ld a,[W_YBLOCKCOORD]
+ ld a,[wYBlockCoord]
and a
jr z,.adjustForXCoordWithinTileBlock
ld bc,$0030
add hl,bc
.adjustForXCoordWithinTileBlock
- ld a,[W_XBLOCKCOORD]
+ ld a,[wXBlockCoord]
and a
jr z,.copyToVisibleAreaBuffer
ld bc,$0002
add hl,bc
.copyToVisibleAreaBuffer
- ld de,wTileMap ; base address for the tiles that are directly transfered to VRAM during V-blank
- ld b,$12
+ coord de, 0, 0 ; base address for the tiles that are directly transferred to VRAM during V-blank
+ ld b, SCREEN_HEIGHT
.rowLoop2
- ld c,$14
+ ld c, SCREEN_WIDTH
.rowInnerLoop2
ld a,[hli]
ld [de],a
@@ -1440,10 +1458,10 @@ LoadCurrentMapView:: ; 0caa (0:0caa)
jr nz,.rowLoop2
pop af
ld [H_LOADEDROMBANK],a
- ld [$2000],a ; restore previous ROM bank
+ ld [MBC1RomBank],a ; restore previous ROM bank
ret
-AdvancePlayerSprite:: ; 0d27 (0:0d27)
+AdvancePlayerSprite::
ld a,[wSpriteStateData1 + 3] ; delta Y
ld b,a
ld a,[wSpriteStateData1 + 5] ; delta X
@@ -1452,12 +1470,12 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
dec [hl]
jr nz,.afterUpdateMapCoords
; if it's the end of the animation, update the player's map coordinates
- ld a,[W_YCOORD]
+ ld a,[wYCoord]
add b
- ld [W_YCOORD],a
- ld a,[W_XCOORD]
+ ld [wYCoord],a
+ ld a,[wXCoord]
add c
- ld [W_XCOORD],a
+ ld [wXCoord],a
.afterUpdateMapCoords
ld a,[wWalkCounter] ; walking animation counter
cp a,$07
@@ -1524,7 +1542,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
and a
jr z,.pointlessJump ; mistake?
.pointlessJump
- ld hl,W_XBLOCKCOORD
+ ld hl,wXBlockCoord
ld a,[hl]
add c
ld [hl],a
@@ -1550,7 +1568,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
call MoveTileBlockMapPointerWest
jr .updateMapView
.adjustYCoordWithinBlock
- ld hl,W_YBLOCKCOORD
+ ld hl,wYBlockCoord
ld a,[hl]
add b
ld [hl],a
@@ -1562,7 +1580,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
ld hl,wYOffsetSinceLastSpecialWarp
inc [hl]
ld de,wCurrentTileBlockMapViewPointer
- ld a,[W_CURMAPWIDTH]
+ ld a,[wCurMapWidth]
call MoveTileBlockMapPointerSouth
jr .updateMapView
.checkForMoveToNorthBlock
@@ -1574,7 +1592,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
ld hl,wYOffsetSinceLastSpecialWarp
dec [hl]
ld de,wCurrentTileBlockMapViewPointer
- ld a,[W_CURMAPWIDTH]
+ ld a,[wCurMapWidth]
call MoveTileBlockMapPointerNorth
.updateMapView
call LoadCurrentMapView
@@ -1618,7 +1636,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
; shift all the sprites in the direction opposite of the player's motion
; so that the player appears to move relative to them
ld hl,wSpriteStateData1 + $14
- ld a,[W_NUMSPRITES] ; number of sprites
+ ld a,[wNumSprites] ; number of sprites
and a ; are there any sprites?
jr z,.done
ld e,a
@@ -1641,7 +1659,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
; the following four functions are used to move the pointer to the upper left
; corner of the tile block map in the direction of motion
-MoveTileBlockMapPointerEast:: ; 0e65 (0:0e65)
+MoveTileBlockMapPointerEast::
ld a,[de]
add a,$01
ld [de],a
@@ -1652,7 +1670,7 @@ MoveTileBlockMapPointerEast:: ; 0e65 (0:0e65)
ld [de],a
ret
-MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f)
+MoveTileBlockMapPointerWest::
ld a,[de]
sub a,$01
ld [de],a
@@ -1663,8 +1681,8 @@ MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f)
ld [de],a
ret
-MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
- add a,$06
+MoveTileBlockMapPointerSouth::
+ add a,MAP_BORDER * 2
ld b,a
ld a,[de]
add b
@@ -1676,8 +1694,8 @@ MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
ld [de],a
ret
-MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
- add a,$06
+MoveTileBlockMapPointerNorth::
+ add a,MAP_BORDER * 2
ld b,a
ld a,[de]
sub b
@@ -1692,20 +1710,20 @@ MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
; the following 6 functions are used to tell the V-blank handler to redraw
; the portion of the map that was newly exposed due to the player's movement
-ScheduleNorthRowRedraw:: ; 0e91 (0:0e91)
- hlCoord 0, 0
- call CopyToScreenEdgeTiles
+ScheduleNorthRowRedraw::
+ coord hl, 0, 0
+ call CopyToRedrawRowOrColumnSrcTiles
ld a,[wMapViewVRAMPointer]
- ld [H_SCREENEDGEREDRAWADDR],a
+ ld [hRedrawRowOrColumnDest],a
ld a,[wMapViewVRAMPointer + 1]
- ld [H_SCREENEDGEREDRAWADDR + 1],a
- ld a,REDRAWROW
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnDest + 1],a
+ ld a,REDRAW_ROW
+ ld [hRedrawRowOrColumnMode],a
ret
-CopyToScreenEdgeTiles:: ; 0ea6 (0:0ea6)
- ld de,wScreenEdgeTiles
- ld c,2 * 20
+CopyToRedrawRowOrColumnSrcTiles::
+ ld de,wRedrawRowOrColumnSrcTiles
+ ld c,2 * SCREEN_WIDTH
.loop
ld a,[hli]
ld [de],a
@@ -1714,9 +1732,9 @@ CopyToScreenEdgeTiles:: ; 0ea6 (0:0ea6)
jr nz,.loop
ret
-ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2)
- hlCoord 0, 16
- call CopyToScreenEdgeTiles
+ScheduleSouthRowRedraw::
+ coord hl, 0, 16
+ call CopyToRedrawRowOrColumnSrcTiles
ld a,[wMapViewVRAMPointer]
ld l,a
ld a,[wMapViewVRAMPointer + 1]
@@ -1724,36 +1742,36 @@ ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2)
ld bc,$0200
add hl,bc
ld a,h
- and a,$03
- or a,$98
- ld [H_SCREENEDGEREDRAWADDR + 1],a
+ and $03
+ or $98
+ ld [hRedrawRowOrColumnDest + 1],a
ld a,l
- ld [H_SCREENEDGEREDRAWADDR],a
- ld a,REDRAWROW
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnDest],a
+ ld a,REDRAW_ROW
+ ld [hRedrawRowOrColumnMode],a
ret
-ScheduleEastColumnRedraw:: ; 0ed3 (0:0ed3)
- hlCoord 18, 0
+ScheduleEastColumnRedraw::
+ coord hl, 18, 0
call ScheduleColumnRedrawHelper
ld a,[wMapViewVRAMPointer]
ld c,a
- and a,$e0
+ and $e0
ld b,a
ld a,c
- add a,18
- and a,$1f
+ add 18
+ and $1f
or b
- ld [H_SCREENEDGEREDRAWADDR],a
+ ld [hRedrawRowOrColumnDest],a
ld a,[wMapViewVRAMPointer + 1]
- ld [H_SCREENEDGEREDRAWADDR + 1],a
- ld a,REDRAWCOL
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnDest + 1],a
+ ld a,REDRAW_COL
+ ld [hRedrawRowOrColumnMode],a
ret
-ScheduleColumnRedrawHelper:: ; 0ef2 (0:0ef2)
- ld de,wScreenEdgeTiles
- ld c,$12
+ScheduleColumnRedrawHelper::
+ ld de,wRedrawRowOrColumnSrcTiles
+ ld c,SCREEN_HEIGHT
.loop
ld a,[hli]
ld [de],a
@@ -1771,32 +1789,32 @@ ScheduleColumnRedrawHelper:: ; 0ef2 (0:0ef2)
jr nz,.loop
ret
-ScheduleWestColumnRedraw:: ; 0f08 (0:0f08)
- hlCoord 0, 0
+ScheduleWestColumnRedraw::
+ coord hl, 0, 0
call ScheduleColumnRedrawHelper
ld a,[wMapViewVRAMPointer]
- ld [H_SCREENEDGEREDRAWADDR],a
+ ld [hRedrawRowOrColumnDest],a
ld a,[wMapViewVRAMPointer + 1]
- ld [H_SCREENEDGEREDRAWADDR + 1],a
- ld a,REDRAWCOL
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnDest + 1],a
+ ld a,REDRAW_COL
+ ld [hRedrawRowOrColumnMode],a
ret
; function to write the tiles that make up a tile block to memory
; Input: c = tile block ID, hl = destination address
-DrawTileBlock:: ; 0f1d (0:0f1d)
+DrawTileBlock::
push hl
- ld a,[W_TILESETBLOCKSPTR] ; pointer to tiles
+ ld a,[wTilesetBlocksPtr] ; pointer to tiles
ld l,a
- ld a,[W_TILESETBLOCKSPTR + 1]
+ ld a,[wTilesetBlocksPtr + 1]
ld h,a
ld a,c
swap a
ld b,a
- and a,$f0
+ and $f0
ld c,a
ld a,b
- and a,$0f
+ and $0f
ld b,a ; bc = tile block ID * 0x10
add hl,bc
ld d,h
@@ -1825,20 +1843,20 @@ DrawTileBlock:: ; 0f1d (0:0f1d)
ret
; function to update joypad state and simulate button presses
-JoypadOverworld:: ; 0f4d (0:0f4d)
+JoypadOverworld::
xor a
ld [wSpriteStateData1 + 3],a
ld [wSpriteStateData1 + 5],a
call RunMapScript
call Joypad
- ld a,[W_FLAGS_D733]
+ ld a,[wFlags_D733]
bit 3,a ; check if a trainer wants a challenge
jr nz,.notForcedDownwards
- ld a,[W_CURMAP]
- cp a,ROUTE_17 ; Cycling Road
+ ld a,[wCurMap]
+ cp ROUTE_17 ; Cycling Road
jr nz,.notForcedDownwards
ld a,[hJoyHeld]
- and a,D_DOWN | D_UP | D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
+ and D_DOWN | D_UP | D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
jr nz,.notForcedDownwards
ld a,D_DOWN
ld [hJoyHeld],a ; on the cycling road, if there isn't a trainer and the player isn't pressing buttons, simulate a down press
@@ -1870,6 +1888,7 @@ JoypadOverworld:: ; 0f4d (0:0f4d)
ld [hJoyPressed],a
ld [hJoyReleased],a
ret
+
; if done simulating button presses
.doneSimulating
xor a
@@ -1880,7 +1899,7 @@ JoypadOverworld:: ; 0f4d (0:0f4d)
ld [hJoyHeld],a
ld hl,wd736
ld a,[hl]
- and a,$f8
+ and $f8
ld [hl],a
ld hl,wd730
res 7,[hl]
@@ -1895,11 +1914,11 @@ JoypadOverworld:: ; 0f4d (0:0f4d)
; so the old value of c is used. 2429 is always called before this function,
; and 2429 always sets c to 0xF0. There is no 0xF0 background tile, so it
; is considered impassable and it is detected as a collision.
-CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
+CollisionCheckOnWater::
ld a,[wd730]
bit 7,a
jp nz,.noCollision ; return and clear carry if button presses are being simulated
- ld a,[wd52a] ; the direction that the player is trying to go in
+ ld a,[wPlayerDirection] ; the direction that the player is trying to go in
ld d,a
ld a,[wSpriteStateData1 + 12] ; the player sprite's collision data (bit field) (set in the sprite movement code)
and d ; check if a sprite is in the direction the player is trying to go
@@ -1917,7 +1936,7 @@ CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
jr z,.noCollision ; keep surfing
; check if the [land] tile in front of the player is passable
.checkIfNextTileIsPassable
- ld hl,W_TILESETCOLLISIONPTR ; pointer to list of passable tiles
+ ld hl,wTilesetCollisionPtr ; pointer to list of passable tiles
ld a,[hli]
ld h,[hl]
ld l,a
@@ -1929,10 +1948,10 @@ CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
jr z,.stopSurfing ; stop surfing if the tile is passable
jr .loop
.collision
- ld a,[wc02a]
- cp a,(SFX_02_5b - SFX_Headers_02) / 3 ; check if collision sound is already playing
+ ld a,[wChannelSoundIDs + Ch4]
+ cp SFX_COLLISION ; check if collision sound is already playing
jr z,.setCarry
- ld a,(SFX_02_5b - SFX_Headers_02) / 3
+ ld a,SFX_COLLISION
call PlaySound ; play collision sound (if it's not already playing)
.setCarry
scf
@@ -1948,13 +1967,13 @@ CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
call PlayDefaultMusic
jr .noCollision
.checkIfVermilionDockTileset
- ld a, [W_CURMAPTILESET] ; tileset
+ ld a, [wCurMapTileset] ; tileset
cp SHIP_PORT ; Vermilion Dock tileset
jr nz, .noCollision ; keep surfing if it's not the boarding platform tile
jr .stopSurfing ; if it is the boarding platform tile, stop surfing
; function to run the current map's script
-RunMapScript:: ; 101b (0:101b)
+RunMapScript::
push hl
push de
push bc
@@ -1968,9 +1987,9 @@ RunMapScript:: ; 101b (0:101b)
pop de
pop hl
call RunNPCMovementScript
- ld a,[W_CURMAP] ; current map number
+ ld a,[wCurMap] ; current map number
call SwitchToMapRomBank ; change to the ROM bank the map's data is in
- ld hl,W_MAPSCRIPTPTR
+ ld hl,wMapScriptPtr
ld a,[hli]
ld h,[hl]
ld l,a
@@ -1980,24 +1999,24 @@ RunMapScript:: ; 101b (0:101b)
.return
ret
-LoadWalkingPlayerSpriteGraphics:: ; 104d (0:104d)
- ld de,RedSprite ; $4180
+LoadWalkingPlayerSpriteGraphics::
+ ld de,RedSprite
ld hl,vNPCSprites
jr LoadPlayerSpriteGraphicsCommon
-LoadSurfingPlayerSpriteGraphics:: ; 1055 (0:1055)
+LoadSurfingPlayerSpriteGraphics::
ld de,SeelSprite
ld hl,vNPCSprites
jr LoadPlayerSpriteGraphicsCommon
-LoadBikePlayerSpriteGraphics:: ; 105d (0:105d)
+LoadBikePlayerSpriteGraphics::
ld de,RedCyclingSprite
ld hl,vNPCSprites
-LoadPlayerSpriteGraphicsCommon:: ; 1063 (0:1063)
+LoadPlayerSpriteGraphicsCommon::
push de
push hl
- ld bc,(BANK(RedSprite) << 8) + $0c
+ lb bc, BANK(RedSprite), $0c
call CopyVideoData
pop hl
pop de
@@ -2008,25 +2027,25 @@ LoadPlayerSpriteGraphicsCommon:: ; 1063 (0:1063)
inc d
.noCarry
set 3,h
- ld bc,$050c
+ lb bc, BANK(RedSprite), $0c
jp CopyVideoData
; function to load data from the map header
-LoadMapHeader:: ; 107c (0:107c)
+LoadMapHeader::
callba MarkTownVisitedAndLoadMissableObjects
- ld a,[W_CURMAPTILESET]
- ld [wd119],a
- ld a,[W_CURMAP]
+ ld a,[wCurMapTileset]
+ ld [wUnusedD119],a
+ ld a,[wCurMap]
call SwitchToMapRomBank
- ld a,[W_CURMAPTILESET]
+ ld a,[wCurMapTileset]
ld b,a
res 7,a
- ld [W_CURMAPTILESET],a
- ld [$ff8b],a
+ ld [wCurMapTileset],a
+ ld [hPreviousTileset],a
bit 7,b
ret nz
ld hl,MapHeaderPointers
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
sla a
jr nc,.noCarry1
inc h
@@ -2040,7 +2059,7 @@ LoadMapHeader:: ; 107c (0:107c)
ld h,[hl]
ld l,a ; hl = base of map header
; copy the first 10 bytes (the fixed area) of the map data to D367-D370
- ld de,W_CURMAPTILESET
+ ld de,wCurMapTileset
ld c,$0a
.copyFixedHeaderLoop
ld a,[hli]
@@ -2050,46 +2069,46 @@ LoadMapHeader:: ; 107c (0:107c)
jr nz,.copyFixedHeaderLoop
; initialize all the connected maps to disabled at first, before loading the actual values
ld a,$ff
- ld [W_MAPCONN1PTR],a
- ld [W_MAPCONN2PTR],a
- ld [W_MAPCONN3PTR],a
- ld [W_MAPCONN4PTR],a
+ ld [wMapConn1Ptr],a
+ ld [wMapConn2Ptr],a
+ ld [wMapConn3Ptr],a
+ ld [wMapConn4Ptr],a
; copy connection data (if any) to WRAM
- ld a,[W_MAPCONNECTIONS]
+ ld a,[wMapConnections]
ld b,a
.checkNorth
bit 3,b
jr z,.checkSouth
- ld de,W_MAPCONN1PTR
+ ld de,wMapConn1Ptr
call CopyMapConnectionHeader
.checkSouth
bit 2,b
jr z,.checkWest
- ld de,W_MAPCONN2PTR
+ ld de,wMapConn2Ptr
call CopyMapConnectionHeader
.checkWest
bit 1,b
jr z,.checkEast
- ld de,W_MAPCONN3PTR
+ ld de,wMapConn3Ptr
call CopyMapConnectionHeader
.checkEast
bit 0,b
jr z,.getObjectDataPointer
- ld de,W_MAPCONN4PTR
+ ld de,wMapConn4Ptr
call CopyMapConnectionHeader
.getObjectDataPointer
ld a,[hli]
- ld [wd3a9],a
+ ld [wObjectDataPointerTemp],a
ld a,[hli]
- ld [wd3aa],a
+ ld [wObjectDataPointerTemp + 1],a
push hl
- ld a,[wd3a9]
+ ld a,[wObjectDataPointerTemp]
ld l,a
- ld a,[wd3aa]
+ ld a,[wObjectDataPointerTemp + 1]
ld h,a ; hl = base of object data
- ld de,wd3ad ; background tile ID
+ ld de,wMapBackgroundTile
ld a,[hli]
- ld [de],a ; save background tile ID
+ ld [de],a
.loadWarpData
ld a,[hli]
ld [wNumberOfWarps],a
@@ -2109,16 +2128,16 @@ LoadMapHeader:: ; 107c (0:107c)
jr nz,.warpLoop
.loadSignData
ld a,[hli] ; number of signs
- ld [wd4b0],a ; save the number of signs
+ ld [wNumSigns],a
and a ; are there any signs?
jr z,.loadSpriteData ; if not, skip this
ld c,a
- ld de,wd4d1 ; base address of sign text IDs
+ ld de,wSignTextIDs
ld a,d
- ld [$ff95],a
+ ld [hSignCoordPointer],a
ld a,e
- ld [$ff96],a
- ld de,wd4b1 ; base address of sign coordinates
+ ld [hSignCoordPointer + 1],a
+ ld de,wSignCoords
.signLoop
ld a,[hli]
ld [de],a
@@ -2127,17 +2146,17 @@ LoadMapHeader:: ; 107c (0:107c)
ld [de],a
inc de
push de
- ld a,[$ff95]
+ ld a,[hSignCoordPointer]
ld d,a
- ld a,[$ff96]
+ ld a,[hSignCoordPointer + 1]
ld e,a
ld a,[hli]
ld [de],a
inc de
ld a,d
- ld [$ff95],a
+ ld [hSignCoordPointer],a
ld a,e
- ld [$ff96],a
+ ld [hSignCoordPointer + 1],a
pop de
dec c
jr nz,.signLoop
@@ -2146,7 +2165,7 @@ LoadMapHeader:: ; 107c (0:107c)
bit 5,a ; did a battle happen immediately before this?
jp nz,.finishUp ; if so, skip this because battles don't destroy this data
ld a,[hli]
- ld [W_NUMSPRITES],a ; save the number of sprites
+ ld [wNumSprites],a ; save the number of sprites
push hl
; zero C110-C1FF and C210-C2FF
ld hl,wSpriteStateData1 + $10
@@ -2170,7 +2189,7 @@ LoadMapHeader:: ; 107c (0:107c)
jr nz,.disableSpriteEntriesLoop
pop hl
ld de,wSpriteStateData1 + $10
- ld a,[W_NUMSPRITES] ; number of sprites
+ ld a,[wNumSprites] ; number of sprites
and a ; are there any sprites?
jp z,.finishUp ; if there are no sprites, skip the rest
ld b,a
@@ -2191,24 +2210,24 @@ LoadMapHeader:: ; 107c (0:107c)
ld a,[hli]
ld [de],a ; store movement byte 1 at C2X6
ld a,[hli]
- ld [$ff8d],a ; save movement byte 2
+ ld [hLoadSpriteTemp1],a ; save movement byte 2
ld a,[hli]
- ld [$ff8e],a ; save text ID and flags byte
+ ld [hLoadSpriteTemp2],a ; save text ID and flags byte
push bc
push hl
ld b,$00
- ld hl,W_MAPSPRITEDATA
+ ld hl,wMapSpriteData
add hl,bc
- ld a,[$ff8d]
+ ld a,[hLoadSpriteTemp1]
ld [hli],a ; store movement byte 2 in byte 0 of sprite entry
- ld a,[$ff8e]
+ ld a,[hLoadSpriteTemp2]
ld [hl],a ; this appears pointless, since the value is overwritten immediately after
- ld a,[$ff8e]
- ld [$ff8d],a
+ ld a,[hLoadSpriteTemp2]
+ ld [hLoadSpriteTemp1],a
and a,$3f
ld [hl],a ; store text ID in byte 1 of sprite entry
pop hl
- ld a,[$ff8d]
+ ld a,[hLoadSpriteTemp1]
bit 6,a
jr nz,.trainerSprite
bit 7,a
@@ -2216,25 +2235,25 @@ LoadMapHeader:: ; 107c (0:107c)
jr .regularSprite
.trainerSprite
ld a,[hli]
- ld [$ff8d],a ; save trainer class
+ ld [hLoadSpriteTemp1],a ; save trainer class
ld a,[hli]
- ld [$ff8e],a ; save trainer number (within class)
+ ld [hLoadSpriteTemp2],a ; save trainer number (within class)
push hl
- ld hl,W_MAPSPRITEEXTRADATA
+ ld hl,wMapSpriteExtraData
add hl,bc
- ld a,[$ff8d]
+ ld a,[hLoadSpriteTemp1]
ld [hli],a ; store trainer class in byte 0 of the entry
- ld a,[$ff8e]
+ ld a,[hLoadSpriteTemp2]
ld [hl],a ; store trainer number in byte 1 of the entry
pop hl
jr .nextSprite
.itemBallSprite
ld a,[hli]
- ld [$ff8d],a ; save item number
+ ld [hLoadSpriteTemp1],a ; save item number
push hl
- ld hl,W_MAPSPRITEEXTRADATA
+ ld hl,wMapSpriteExtraData
add hl,bc
- ld a,[$ff8d]
+ ld a,[hLoadSpriteTemp1]
ld [hli],a ; store item number in byte 0 of the entry
xor a
ld [hl],a ; zero byte 1, since it is not used
@@ -2242,7 +2261,7 @@ LoadMapHeader:: ; 107c (0:107c)
jr .nextSprite
.regularSprite
push hl
- ld hl,W_MAPSPRITEEXTRADATA
+ ld hl,wMapSpriteExtraData
add hl,bc
; zero both bytes, since regular sprites don't use this extra space
xor a
@@ -2263,35 +2282,35 @@ LoadMapHeader:: ; 107c (0:107c)
predef LoadTilesetHeader
callab LoadWildData
pop hl ; restore hl from before going to the warp/sign/sprite data (this value was saved for seemingly no purpose)
- ld a,[W_CURMAPHEIGHT] ; map height in 4x4 tile blocks
+ ld a,[wCurMapHeight] ; map height in 4x4 tile blocks
add a ; double it
- ld [wd524],a ; store map height in 2x2 tile blocks
- ld a,[W_CURMAPWIDTH] ; map width in 4x4 tile blocks
+ ld [wCurrentMapHeight2],a ; store map height in 2x2 tile blocks
+ ld a,[wCurMapWidth] ; map width in 4x4 tile blocks
add a ; double it
- ld [wd525],a ; map width in 2x2 tile blocks
- ld a,[W_CURMAP]
+ ld [wCurrentMapWidth2],a ; map width in 2x2 tile blocks
+ ld a,[wCurMap]
ld c,a
ld b,$00
ld a,[H_LOADEDROMBANK]
push af
ld a, BANK(MapSongBanks)
ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [MBC1RomBank],a
ld hl, MapSongBanks
add hl,bc
add hl,bc
ld a,[hli]
- ld [wd35b],a ; music 1
+ ld [wMapMusicSoundID],a ; music 1
ld a,[hl]
- ld [wd35c],a ; music 2
+ ld [wMapMusicROMBank],a ; music 2
pop af
ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [MBC1RomBank],a
ret
; function to copy map connection data from ROM to WRAM
; Input: hl = source, de = destination
-CopyMapConnectionHeader:: ; 1238 (0:1238)
+CopyMapConnectionHeader::
ld c,$0b
.loop
ld a,[hli]
@@ -2302,7 +2321,7 @@ CopyMapConnectionHeader:: ; 1238 (0:1238)
ret
; function to load map data
-LoadMapData:: ; 1241 (0:1241)
+LoadMapData::
ld a,[H_LOADEDROMBANK]
push af
call DisableLCD
@@ -2313,9 +2332,9 @@ LoadMapData:: ; 1241 (0:1241)
ld [hSCY],a
ld [hSCX],a
ld [wWalkCounter],a
- ld [wd119],a
+ ld [wUnusedD119],a
ld [wWalkBikeSurfStateCopy],a
- ld [W_SPRITESETID],a
+ ld [wSpriteSetID],a
call LoadTextBoxTilePatterns
call LoadMapHeader
callba InitMapSprites ; load tile pattern data for sprites
@@ -2323,7 +2342,7 @@ LoadMapData:: ; 1241 (0:1241)
call LoadTilesetTilePatternData
call LoadCurrentMapView
; copy current map view to VRAM
- ld hl,wTileMap
+ coord hl, 0, 0
ld de,vBGMap0
ld b,18
.vramCopyLoop
@@ -2345,26 +2364,26 @@ LoadMapData:: ; 1241 (0:1241)
ld a,$01
ld [wUpdateSpritesEnabled],a
call EnableLCD
- ld b,$09
- call GoPAL_SET
+ ld b, SET_PAL_OVERWORLD
+ call RunPaletteCommand
call LoadPlayerSpriteGraphics
ld a,[wd732]
and a,1 << 4 | 1 << 3 ; fly warp or dungeon warp
jr nz,.restoreRomBank
- ld a,[W_FLAGS_D733]
+ ld a,[wFlags_D733]
bit 1,a
jr nz,.restoreRomBank
- call Func_235f ; music related
- call Func_2312 ; music related
+ call UpdateMusic6Times
+ call PlayDefaultMusicFadeOutCurrent
.restoreRomBank
pop af
ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [MBC1RomBank],a
ret
; function to switch to the ROM bank that a map is stored in
; Input: a = map number
-SwitchToMapRomBank:: ; 12bc (0:12bc)
+SwitchToMapRomBank::
push hl
push bc
ld c,a
@@ -2378,26 +2397,26 @@ SwitchToMapRomBank:: ; 12bc (0:12bc)
call BankswitchBack
ld a,[$ffe8]
ld [H_LOADEDROMBANK],a
- ld [$2000],a ; switch to map ROM bank
+ ld [MBC1RomBank],a ; switch to map ROM bank
pop bc
pop hl
ret
-IgnoreInputForHalfSecond: ; 12da (0:12da)
+IgnoreInputForHalfSecond:
ld a, 30
ld [wIgnoreInputCounter], a
ld hl, wd730
ld a, [hl]
- or $26
+ or %00100110
ld [hl], a ; set ignore input bit
ret
-ResetUsingStrengthOutOfBattleBit: ; 12e7 (0:12e7)
+ResetUsingStrengthOutOfBattleBit:
ld hl, wd728
res 0, [hl]
ret
-ForceBikeOrSurf:: ; 12ed (0:12ed)
+ForceBikeOrSurf::
ld b, BANK(RedSprite)
ld hl, LoadPlayerSpriteGraphics
call Bankswitch
diff --git a/home/pic.asm b/home/pic.asm
index 6aa2e5c0..a1c18e8a 100644
--- a/home/pic.asm
+++ b/home/pic.asm
@@ -1,69 +1,69 @@
; bankswitches and runs _UncompressSpriteData
-; bank is given in a, sprite input stream is pointed to in W_SPRITEINPUTPTR
-UncompressSpriteData:: ; 24fd (0:24fd)
+; bank is given in a, sprite input stream is pointed to in wSpriteInputPtr
+UncompressSpriteData::
ld b, a
ld a, [H_LOADEDROMBANK]
push af
ld a, b
ld [H_LOADEDROMBANK], a
- ld [$2000], a
- ld a, $a
- ld [$0], a
+ ld [MBC1RomBank], a
+ ld a, SRAM_ENABLE
+ ld [MBC1SRamEnable], a
xor a
- ld [$4000], a
+ ld [MBC1SRamBank], a
call _UncompressSpriteData
pop af
ld [H_LOADEDROMBANK], a
- ld [$2000], a
+ ld [MBC1RomBank], a
ret
; initializes necessary data to load a sprite and runs UncompressSpriteDataLoop
-_UncompressSpriteData:: ; 251a (0:251a)
- ld hl, S_SPRITEBUFFER1
+_UncompressSpriteData::
+ ld hl, sSpriteBuffer1
ld c, (2*SPRITEBUFFERSIZE) % $100
ld b, (2*SPRITEBUFFERSIZE) / $100
xor a
call FillMemory ; clear sprite buffer 1 and 2
ld a, $1
- ld [W_SPRITEINPUTBITCOUNTER], a
+ ld [wSpriteInputBitCounter], a
ld a, $3
- ld [W_SPRITEOUTPUTBITOFFSET], a
+ ld [wSpriteOutputBitOffset], a
xor a
- ld [W_SPRITECURPOSX], a
- ld [W_SPRITECURPOSY], a
- ld [W_SPRITELOADFLAGS], a ; wd0a8
+ ld [wSpriteCurPosX], a
+ ld [wSpriteCurPosY], a
+ ld [wSpriteLoadFlags], a
call ReadNextInputByte ; first byte of input determines sprite width (high nybble) and height (low nybble) in tiles (8x8 pixels)
ld b, a
and $f
add a
add a
add a
- ld [W_SPRITEHEIGHT], a
+ ld [wSpriteHeight], a
ld a, b
swap a
and $f
add a
add a
add a
- ld [W_SPRITEWITDH], a
+ ld [wSpriteWidth], a
call ReadNextInputBit
- ld [W_SPRITELOADFLAGS], a ; initialite bit1 to 0 and bit0 to the first input bit
- ; this will load two chunks of data to S_SPRITEBUFFER1 and S_SPRITEBUFFER2
- ; bit 0 decides in which one the first chunk is placed
+ ld [wSpriteLoadFlags], a ; initialite bit1 to 0 and bit0 to the first input bit
+ ; this will load two chunks of data to sSpriteBuffer1 and sSpriteBuffer2
+ ; bit 0 decides in which one the first chunk is placed
; fall through
-; uncompresses a chunk from the sprite input data stream (pointed to at wd0da) into S_SPRITEBUFFER1 or S_SPRITEBUFFER2
+; uncompresses a chunk from the sprite input data stream (pointed to at wd0da) into sSpriteBuffer1 or sSpriteBuffer2
; each chunk is a 1bpp sprite. A 2bpp sprite consist of two chunks which are merged afterwards
; note that this is an endless loop which is terminated during a call to MoveToNextBufferPosition by manipulating the stack
-UncompressSpriteDataLoop:: ; 2556 (0:2556)
- ld hl, S_SPRITEBUFFER1
- ld a, [W_SPRITELOADFLAGS] ; wd0a8
+UncompressSpriteDataLoop::
+ ld hl, sSpriteBuffer1
+ ld a, [wSpriteLoadFlags]
bit 0, a
jr z, .useSpriteBuffer1 ; check which buffer to use
- ld hl, S_SPRITEBUFFER2
+ ld hl, sSpriteBuffer2
.useSpriteBuffer1
call StoreSpriteOutputPointer
- ld a, [W_SPRITELOADFLAGS] ; wd0a8
+ ld a, [wSpriteLoadFlags]
bit 1, a
jr z, .startDecompression ; check if last iteration
call ReadNextInputBit ; if last chunk, read 1-2 bit unpacking mode
@@ -72,7 +72,7 @@ UncompressSpriteDataLoop:: ; 2556 (0:2556)
call ReadNextInputBit ; 1 0 -> mode 1
inc a ; 1 1 -> mode 2
.unpackingMode0
- ld [W_SPRITEUNPACKMODE], a
+ ld [wSpriteUnpackMode], a
.startDecompression
call ReadNextInputBit
and a
@@ -145,70 +145,70 @@ UncompressSpriteDataLoop:: ; 2556 (0:2556)
; moves output pointer to next position
; also cancels the calling function if the all output is done (by removing the return pointer from stack)
; and calls postprocessing functions according to the unpack mode
-MoveToNextBufferPosition:: ; 25d8 (0:25d8)
- ld a, [W_SPRITEHEIGHT]
+MoveToNextBufferPosition::
+ ld a, [wSpriteHeight]
ld b, a
- ld a, [W_SPRITECURPOSY]
+ ld a, [wSpriteCurPosY]
inc a
cp b
jr z, .curColumnDone
- ld [W_SPRITECURPOSY], a
- ld a, [W_SPRITEOUTPUTPTR]
+ ld [wSpriteCurPosY], a
+ ld a, [wSpriteOutputPtr]
inc a
- ld [W_SPRITEOUTPUTPTR], a
+ ld [wSpriteOutputPtr], a
ret nz
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
inc a
- ld [W_SPRITEOUTPUTPTR+1], a
+ ld [wSpriteOutputPtr+1], a
ret
.curColumnDone
xor a
- ld [W_SPRITECURPOSY], a
- ld a, [W_SPRITEOUTPUTBITOFFSET]
+ ld [wSpriteCurPosY], a
+ ld a, [wSpriteOutputBitOffset]
and a
jr z, .bitOffsetsDone
dec a
- ld [W_SPRITEOUTPUTBITOFFSET], a
- ld hl, W_SPRITEOUTPUTPTRCACHED
+ ld [wSpriteOutputBitOffset], a
+ ld hl, wSpriteOutputPtrCached
ld a, [hli]
- ld [W_SPRITEOUTPUTPTR], a
+ ld [wSpriteOutputPtr], a
ld a, [hl]
- ld [W_SPRITEOUTPUTPTR+1], a
+ ld [wSpriteOutputPtr+1], a
ret
.bitOffsetsDone
ld a, $3
- ld [W_SPRITEOUTPUTBITOFFSET], a
- ld a, [W_SPRITECURPOSX]
+ ld [wSpriteOutputBitOffset], a
+ ld a, [wSpriteCurPosX]
add $8
- ld [W_SPRITECURPOSX], a
+ ld [wSpriteCurPosX], a
ld b, a
- ld a, [W_SPRITEWITDH]
+ ld a, [wSpriteWidth]
cp b
jr z, .allColumnsDone
- ld a, [W_SPRITEOUTPUTPTR]
+ ld a, [wSpriteOutputPtr]
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
inc hl
jp StoreSpriteOutputPointer
.allColumnsDone
pop hl
xor a
- ld [W_SPRITECURPOSX], a
- ld a, [W_SPRITELOADFLAGS] ; wd0a8
+ ld [wSpriteCurPosX], a
+ ld a, [wSpriteLoadFlags]
bit 1, a
jr nz, .done ; test if there is one more sprite to go
xor $1
set 1, a
- ld [W_SPRITELOADFLAGS], a ; wd0a8
+ ld [wSpriteLoadFlags], a
jp UncompressSpriteDataLoop
.done
jp UnpackSprite
-; writes 2 bits (from a) to the output buffer (pointed to from W_SPRITEOUTPUTPTR)
-WriteSpriteBitsToBuffer:: ; 2649 (0:2649)
+; writes 2 bits (from a) to the output buffer (pointed to from wSpriteOutputPtr)
+WriteSpriteBitsToBuffer::
ld e, a
- ld a, [W_SPRITEOUTPUTBITOFFSET]
+ ld a, [wSpriteOutputBitOffset]
and a
jr z, .offset0
cp $2
@@ -224,9 +224,9 @@ WriteSpriteBitsToBuffer:: ; 2649 (0:2649)
.offset2
swap e
.offset0
- ld a, [W_SPRITEOUTPUTPTR]
+ ld a, [wSpriteOutputPtr]
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
ld a, [hl]
or e
@@ -234,38 +234,38 @@ WriteSpriteBitsToBuffer:: ; 2649 (0:2649)
ret
; reads next bit from input stream and returns it in a
-ReadNextInputBit:: ; 2670 (0:2670)
- ld a, [W_SPRITEINPUTBITCOUNTER]
+ReadNextInputBit::
+ ld a, [wSpriteInputBitCounter]
dec a
jr nz, .curByteHasMoreBitsToRead
call ReadNextInputByte
- ld [W_SPRITEINPUTCURBYTE], a
+ ld [wSpriteInputCurByte], a
ld a, $8
.curByteHasMoreBitsToRead
- ld [W_SPRITEINPUTBITCOUNTER], a
- ld a, [W_SPRITEINPUTCURBYTE]
+ ld [wSpriteInputBitCounter], a
+ ld a, [wSpriteInputCurByte]
rlca
- ld [W_SPRITEINPUTCURBYTE], a
+ ld [wSpriteInputCurByte], a
and $1
ret
; reads next byte from input stream and returns it in a
-ReadNextInputByte:: ; 268b (0:268b)
- ld a, [W_SPRITEINPUTPTR]
+ReadNextInputByte::
+ ld a, [wSpriteInputPtr]
ld l, a
- ld a, [W_SPRITEINPUTPTR+1]
+ ld a, [wSpriteInputPtr+1]
ld h, a
ld a, [hli]
ld b, a
ld a, l
- ld [W_SPRITEINPUTPTR], a
+ ld [wSpriteInputPtr], a
ld a, h
- ld [W_SPRITEINPUTPTR+1], a
+ ld [wSpriteInputPtr+1], a
ld a, b
ret
; the nth item is 2^n - 1
-LengthEncodingOffsetList:: ; 269f (0:269f)
+LengthEncodingOffsetList::
dw %0000000000000001
dw %0000000000000011
dw %0000000000000111
@@ -284,25 +284,25 @@ LengthEncodingOffsetList:: ; 269f (0:269f)
dw %1111111111111111
; unpacks the sprite data depending on the unpack mode
-UnpackSprite:: ; 26bf (0:26bf)
- ld a, [W_SPRITEUNPACKMODE]
+UnpackSprite::
+ ld a, [wSpriteUnpackMode]
cp $2
jp z, UnpackSpriteMode2
and a
jp nz, XorSpriteChunks
- ld hl, S_SPRITEBUFFER1
+ ld hl, sSpriteBuffer1
call SpriteDifferentialDecode
- ld hl, S_SPRITEBUFFER2
+ ld hl, sSpriteBuffer2
; fall through
; decodes differential encoded sprite data
; input bit value 0 preserves the current bit value and input bit value 1 toggles it (starting from initial value 0).
-SpriteDifferentialDecode:: ; 26d4 (0:26d4)
+SpriteDifferentialDecode::
xor a
- ld [W_SPRITECURPOSX], a
- ld [W_SPRITECURPOSY], a
+ ld [wSpriteCurPosX], a
+ ld [wSpriteCurPosY], a
call StoreSpriteOutputPointer
- ld a, [W_SPRITEFLIPPED]
+ ld a, [wSpriteFlipped]
and a
jr z, .notFlipped
ld hl, DecodeNybble0TableFlipped
@@ -313,18 +313,18 @@ SpriteDifferentialDecode:: ; 26d4 (0:26d4)
ld de, DecodeNybble1Table
.storeDecodeTablesPointers
ld a, l
- ld [W_SPRITEDECODETABLE0PTR], a
+ ld [wSpriteDecodeTable0Ptr], a
ld a, h
- ld [W_SPRITEDECODETABLE0PTR+1], a
+ ld [wSpriteDecodeTable0Ptr+1], a
ld a, e
- ld [W_SPRITEDECODETABLE1PTR], a
+ ld [wSpriteDecodeTable1Ptr], a
ld a, d
- ld [W_SPRITEDECODETABLE1PTR+1], a
+ ld [wSpriteDecodeTable1Ptr+1], a
ld e, $0 ; last decoded nybble, initialized to 0
.decodeNextByteLoop
- ld a, [W_SPRITEOUTPUTPTR]
+ ld a, [wSpriteOutputPtr]
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
ld a, [hl]
ld b, a
@@ -338,58 +338,58 @@ SpriteDifferentialDecode:: ; 26d4 (0:26d4)
call DifferentialDecodeNybble ; decode low nybble
or d
ld b, a
- ld a, [W_SPRITEOUTPUTPTR]
+ ld a, [wSpriteOutputPtr]
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
ld a, b
ld [hl], a ; write back decoded data
- ld a, [W_SPRITEHEIGHT]
+ ld a, [wSpriteHeight]
add l ; move on to next column
jr nc, .noCarry
inc h
.noCarry
- ld [W_SPRITEOUTPUTPTR], a
+ ld [wSpriteOutputPtr], a
ld a, h
- ld [W_SPRITEOUTPUTPTR+1], a
- ld a, [W_SPRITECURPOSX]
+ ld [wSpriteOutputPtr+1], a
+ ld a, [wSpriteCurPosX]
add $8
- ld [W_SPRITECURPOSX], a
+ ld [wSpriteCurPosX], a
ld b, a
- ld a, [W_SPRITEWITDH]
+ ld a, [wSpriteWidth]
cp b
jr nz, .decodeNextByteLoop ; test if current row is done
xor a
ld e, a
- ld [W_SPRITECURPOSX], a
- ld a, [W_SPRITECURPOSY] ; move on to next row
+ ld [wSpriteCurPosX], a
+ ld a, [wSpriteCurPosY] ; move on to next row
inc a
- ld [W_SPRITECURPOSY], a
+ ld [wSpriteCurPosY], a
ld b, a
- ld a, [W_SPRITEHEIGHT]
+ ld a, [wSpriteHeight]
cp b
jr z, .done ; test if all rows finished
- ld a, [W_SPRITEOUTPUTPTRCACHED]
+ ld a, [wSpriteOutputPtrCached]
ld l, a
- ld a, [W_SPRITEOUTPUTPTRCACHED+1]
+ ld a, [wSpriteOutputPtrCached+1]
ld h, a
inc hl
call StoreSpriteOutputPointer
jr .decodeNextByteLoop
.done
xor a
- ld [W_SPRITECURPOSY], a
+ ld [wSpriteCurPosY], a
ret
; decodes the nybble stored in a. Last decoded data is assumed to be in e (needed to determine if initial value is 0 or 1)
-DifferentialDecodeNybble:: ; 276d (0:276d)
+DifferentialDecodeNybble::
srl a ; c=a%2, a/=2
ld c, $0
jr nc, .evenNumber
ld c, $1
.evenNumber
ld l, a
- ld a, [W_SPRITEFLIPPED]
+ ld a, [wSpriteFlipped]
and a
jr z, .notFlipped ; determine if initial value is 0 or one
bit 3, e ; if flipped, consider MSB of last data
@@ -399,14 +399,14 @@ DifferentialDecodeNybble:: ; 276d (0:276d)
.selectLookupTable
ld e, l
jr nz, .initialValue1 ; load the appropriate table
- ld a, [W_SPRITEDECODETABLE0PTR]
+ ld a, [wSpriteDecodeTable0Ptr]
ld l, a
- ld a, [W_SPRITEDECODETABLE0PTR+1]
+ ld a, [wSpriteDecodeTable0Ptr+1]
jr .tableLookup
.initialValue1
- ld a, [W_SPRITEDECODETABLE1PTR]
+ ld a, [wSpriteDecodeTable1Ptr]
ld l, a
- ld a, [W_SPRITEDECODETABLE1PTR+1]
+ ld a, [wSpriteDecodeTable1Ptr+1]
.tableLookup
ld h, a
ld a, e
@@ -424,7 +424,7 @@ DifferentialDecodeNybble:: ; 276d (0:276d)
ld e, a ; update last decoded data
ret
-DecodeNybble0Table:: ; 27a7 (0:27a7)
+DecodeNybble0Table::
dn $0, $1
dn $3, $2
dn $7, $6
@@ -433,7 +433,7 @@ DecodeNybble0Table:: ; 27a7 (0:27a7)
dn $c, $d
dn $8, $9
dn $b, $a
-DecodeNybble1Table:: ; 27af (0:27af)
+DecodeNybble1Table::
dn $f, $e
dn $c, $d
dn $8, $9
@@ -442,7 +442,7 @@ DecodeNybble1Table:: ; 27af (0:27af)
dn $3, $2
dn $7, $6
dn $4, $5
-DecodeNybble0TableFlipped:: ; 27b7 (0:27b7)
+DecodeNybble0TableFlipped::
dn $0, $8
dn $c, $4
dn $e, $6
@@ -451,7 +451,7 @@ DecodeNybble0TableFlipped:: ; 27b7 (0:27b7)
dn $3, $b
dn $1, $9
dn $d, $5
-DecodeNybble1TableFlipped:: ; 27bf (0:27bf)
+DecodeNybble1TableFlipped::
dn $f, $7
dn $3, $b
dn $1, $9
@@ -462,27 +462,27 @@ DecodeNybble1TableFlipped:: ; 27bf (0:27bf)
dn $2, $a
; combines the two loaded chunks with xor (the chunk loaded second is the destination). The source chunk is differeintial decoded beforehand.
-XorSpriteChunks:: ; 27c7 (0:27c7)
+XorSpriteChunks::
xor a
- ld [W_SPRITECURPOSX], a
- ld [W_SPRITECURPOSY], a
+ ld [wSpriteCurPosX], a
+ ld [wSpriteCurPosY], a
call ResetSpriteBufferPointers
- ld a, [W_SPRITEOUTPUTPTR] ; points to buffer 1 or 2, depending on flags
+ ld a, [wSpriteOutputPtr] ; points to buffer 1 or 2, depending on flags
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
call SpriteDifferentialDecode ; decode buffer 1 or 2, depending on flags
call ResetSpriteBufferPointers
- ld a, [W_SPRITEOUTPUTPTR] ; source buffer, points to buffer 1 or 2, depending on flags
+ ld a, [wSpriteOutputPtr] ; source buffer, points to buffer 1 or 2, depending on flags
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
- ld a, [W_SPRITEOUTPUTPTRCACHED] ; destination buffer, points to buffer 2 or 1, depending on flags
+ ld a, [wSpriteOutputPtrCached] ; destination buffer, points to buffer 2 or 1, depending on flags
ld e, a
- ld a, [W_SPRITEOUTPUTPTRCACHED+1]
+ ld a, [wSpriteOutputPtrCached+1]
ld d, a
.xorChunksLoop
- ld a, [W_SPRITEFLIPPED]
+ ld a, [wSpriteFlipped]
and a
jr z, .notFlipped
push de
@@ -506,86 +506,86 @@ XorSpriteChunks:: ; 27c7 (0:27c7)
xor b
ld [de], a
inc de
- ld a, [W_SPRITECURPOSY]
+ ld a, [wSpriteCurPosY]
inc a
- ld [W_SPRITECURPOSY], a ; go to next row
+ ld [wSpriteCurPosY], a ; go to next row
ld b, a
- ld a, [W_SPRITEHEIGHT]
+ ld a, [wSpriteHeight]
cp b
jr nz, .xorChunksLoop ; test if column finished
xor a
- ld [W_SPRITECURPOSY], a
- ld a, [W_SPRITECURPOSX]
+ ld [wSpriteCurPosY], a
+ ld a, [wSpriteCurPosX]
add $8
- ld [W_SPRITECURPOSX], a ; go to next column
+ ld [wSpriteCurPosX], a ; go to next column
ld b, a
- ld a, [W_SPRITEWITDH]
+ ld a, [wSpriteWidth]
cp b
jr nz, .xorChunksLoop ; test if all columns finished
xor a
- ld [W_SPRITECURPOSX], a
+ ld [wSpriteCurPosX], a
ret
; reverses the bits in the nybble given in register a
-ReverseNybble:: ; 2837 (0:2837)
+ReverseNybble::
ld de, NybbleReverseTable
add e
ld e, a
- jr nc, .asm_283f
+ jr nc, .noCarry
inc d
-.asm_283f
+.noCarry
ld a, [de]
ret
-; resets sprite buffer pointers to buffer 1 and 2, depending on W_SPRITELOADFLAGS
-ResetSpriteBufferPointers:: ; 2841 (0:2841)
- ld a, [W_SPRITELOADFLAGS] ; wd0a8
+; resets sprite buffer pointers to buffer 1 and 2, depending on wSpriteLoadFlags
+ResetSpriteBufferPointers::
+ ld a, [wSpriteLoadFlags]
bit 0, a
jr nz, .buffer2Selected
- ld de, S_SPRITEBUFFER1
- ld hl, S_SPRITEBUFFER2
+ ld de, sSpriteBuffer1
+ ld hl, sSpriteBuffer2
jr .storeBufferPointers
.buffer2Selected
- ld de, S_SPRITEBUFFER2
- ld hl, S_SPRITEBUFFER1
+ ld de, sSpriteBuffer2
+ ld hl, sSpriteBuffer1
.storeBufferPointers
ld a, l
- ld [W_SPRITEOUTPUTPTR], a
+ ld [wSpriteOutputPtr], a
ld a, h
- ld [W_SPRITEOUTPUTPTR+1], a
+ ld [wSpriteOutputPtr+1], a
ld a, e
- ld [W_SPRITEOUTPUTPTRCACHED], a
+ ld [wSpriteOutputPtrCached], a
ld a, d
- ld [W_SPRITEOUTPUTPTRCACHED+1], a
+ ld [wSpriteOutputPtrCached+1], a
ret
; maps each nybble to its reverse
-NybbleReverseTable:: ; 2867 (0:2867)
+NybbleReverseTable::
db $0, $8, $4, $c, $2, $a, $6 ,$e, $1, $9, $5, $d, $3, $b, $7 ,$f
; combines the two loaded chunks with xor (the chunk loaded second is the destination). Both chunks are differeintial decoded beforehand.
-UnpackSpriteMode2:: ; 2877 (0:2877)
+UnpackSpriteMode2::
call ResetSpriteBufferPointers
- ld a, [W_SPRITEFLIPPED]
+ ld a, [wSpriteFlipped]
push af
xor a
- ld [W_SPRITEFLIPPED], a ; temporarily clear flipped flag for decoding the destination chunk
- ld a, [W_SPRITEOUTPUTPTRCACHED]
+ ld [wSpriteFlipped], a ; temporarily clear flipped flag for decoding the destination chunk
+ ld a, [wSpriteOutputPtrCached]
ld l, a
- ld a, [W_SPRITEOUTPUTPTRCACHED+1]
+ ld a, [wSpriteOutputPtrCached+1]
ld h, a
call SpriteDifferentialDecode
call ResetSpriteBufferPointers
pop af
- ld [W_SPRITEFLIPPED], a
+ ld [wSpriteFlipped], a
jp XorSpriteChunks
; stores hl into the output pointers
-StoreSpriteOutputPointer:: ; 2897 (0:2897)
+StoreSpriteOutputPointer::
ld a, l
- ld [W_SPRITEOUTPUTPTR], a
- ld [W_SPRITEOUTPUTPTRCACHED], a
+ ld [wSpriteOutputPtr], a
+ ld [wSpriteOutputPtrCached], a
ld a, h
- ld [W_SPRITEOUTPUTPTR+1], a
- ld [W_SPRITEOUTPUTPTRCACHED+1], a
+ ld [wSpriteOutputPtr+1], a
+ ld [wSpriteOutputPtrCached+1], a
ret
diff --git a/home/predef.asm b/home/predef.asm
index 8efe3000..2fac9aca 100644
--- a/home/predef.asm
+++ b/home/predef.asm
@@ -14,13 +14,13 @@ Predef::
push af
ld a, BANK(GetPredefPointer)
ld [H_LOADEDROMBANK], a
- ld [$2000], a
+ ld [MBC1RomBank], a
call GetPredefPointer
ld a, [wPredefBank]
ld [H_LOADEDROMBANK], a
- ld [$2000], a
+ ld [MBC1RomBank], a
ld de, .done
push de
@@ -29,7 +29,7 @@ Predef::
pop af
ld [H_LOADEDROMBANK], a
- ld [$2000], a
+ ld [MBC1RomBank], a
ret
GetPredefRegisters::
diff --git a/home/serial.asm b/home/serial.asm
index 86d74040..6c412239 100644
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -1,312 +1,312 @@
-Serial:: ; 2125 (0:2125)
- push af
- push bc
- push de
- push hl
- ld a, [hSerialConnectionStatus]
- inc a
- jr z, .connectionNotYetEstablished
- ld a, [rSB]
- ld [hSerialReceiveData], a
- ld a, [hSerialSendData]
- ld [rSB], a
- ld a, [hSerialConnectionStatus]
- cp USING_INTERNAL_CLOCK
- jr z, .done
-; using external clock
- ld a, START_TRANSFER_EXTERNAL_CLOCK
- ld [rSC], a
- jr .done
-.connectionNotYetEstablished
- ld a, [rSB]
- ld [hSerialReceiveData], a
- ld [hSerialConnectionStatus], a
- cp USING_INTERNAL_CLOCK
- jr z, .usingInternalClock
-; using external clock
- xor a
- ld [rSB], a
- ld a, $3
- ld [rDIV], a
-.waitLoop
- ld a, [rDIV]
- bit 7, a
- jr nz, .waitLoop
- ld a, START_TRANSFER_EXTERNAL_CLOCK
- ld [rSC], a
- jr .done
-.usingInternalClock
- xor a
- ld [rSB], a
-.done
- ld a, $1
- ld [hSerialReceivedNewData], a
- ld a, SERIAL_NO_DATA_BYTE
- ld [hSerialSendData], a
- pop hl
- pop de
- pop bc
- pop af
- reti
-
-; hl = send data
-; de = receive data
-; bc = length of data
-Serial_ExchangeBytes:: ; 216f (0:216f)
- ld a, 1
- ld [hSerialIgnoringInitialData], a
-.loop
- ld a, [hl]
- ld [hSerialSendData], a
- call Serial_ExchangeByte
- push bc
- ld b, a
- inc hl
- ld a, 48
-.waitLoop
- dec a
- jr nz, .waitLoop
- ld a, [hSerialIgnoringInitialData]
- and a
- ld a, b
- pop bc
- jr z, .storeReceivedByte
- dec hl
- cp SERIAL_PREAMBLE_BYTE
- jr nz, .loop
- xor a
- ld [hSerialIgnoringInitialData], a
- jr .loop
-.storeReceivedByte
- ld [de], a
- inc de
- dec bc
- ld a, b
- or c
- jr nz, .loop
- ret
-
-Serial_ExchangeByte:: ; 219a (0:219a)
- xor a
- ld [hSerialReceivedNewData], a
- ld a, [hSerialConnectionStatus]
- cp USING_INTERNAL_CLOCK
- jr nz, .asm_21a7
- ld a, START_TRANSFER_INTERNAL_CLOCK
- ld [rSC], a
-.asm_21a7
- ld a, [hSerialReceivedNewData]
- and a
- jr nz, .asm_21f1
- ld a, [hSerialConnectionStatus]
- cp USING_EXTERNAL_CLOCK
- jr nz, .asm_21cc
- call IsUnknownCounterZero
- jr z, .asm_21cc
- call WaitLoop_15Iterations
- push hl
- ld hl, wUnknownSerialCounter + 1
- inc [hl]
- jr nz, .asm_21c3
- dec hl
- inc [hl]
-.asm_21c3
- pop hl
- call IsUnknownCounterZero
- jr nz, .asm_21a7
- jp SetUnknownCounterToFFFF
-.asm_21cc
- ld a, [rIE]
- and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
- cp (1 << SERIAL)
- jr nz, .asm_21a7
- ld a, [wUnknownSerialCounter2]
- dec a
- ld [wUnknownSerialCounter2], a
- jr nz, .asm_21a7
- ld a, [wUnknownSerialCounter2 + 1]
- dec a
- ld [wUnknownSerialCounter2 + 1], a
- jr nz, .asm_21a7
- ld a, [hSerialConnectionStatus]
- cp USING_EXTERNAL_CLOCK
- jr z, .asm_21f1
- ld a, 255
-.waitLoop
- dec a
- jr nz, .waitLoop
-.asm_21f1
- xor a
- ld [hSerialReceivedNewData], a
- ld a, [rIE]
- and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
- sub (1 << SERIAL)
- jr nz, .asm_2204
- ld [wUnknownSerialCounter2], a
- ld a, $50
- ld [wUnknownSerialCounter2 + 1], a
-.asm_2204
- ld a, [hSerialReceiveData]
- cp SERIAL_NO_DATA_BYTE
- ret nz
- call IsUnknownCounterZero
- jr z, .asm_221f
- push hl
- ld hl, wUnknownSerialCounter + 1
- ld a, [hl]
- dec a
- ld [hld], a
- inc a
- jr nz, .asm_2219
- dec [hl]
-.asm_2219
- pop hl
- call IsUnknownCounterZero
- jr z, SetUnknownCounterToFFFF
-.asm_221f
- ld a, [rIE]
- and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
- cp (1 << SERIAL)
- ld a, SERIAL_NO_DATA_BYTE
- ret z
- ld a, [hl]
- ld [hSerialSendData], a
- call DelayFrame
- jp Serial_ExchangeByte
-
-WaitLoop_15Iterations:: ; 2231 (0:2231)
- ld a, 15
-.waitLoop
- dec a
- jr nz, .waitLoop
- ret
-
-IsUnknownCounterZero:: ; 2237 (0:2237)
- push hl
- ld hl, wUnknownSerialCounter
- ld a, [hli]
- or [hl]
- pop hl
- ret
-
-; a is always 0 when this is called
-SetUnknownCounterToFFFF:: ; 223f (0:223f)
- dec a
- ld [wUnknownSerialCounter], a
- ld [wUnknownSerialCounter + 1], a
- ret
-
-; 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:: ; 2247 (0:2247)
- ld hl, wLinkMenuSelectionSendBuffer
- ld de, wLinkMenuSelectionReceiveBuffer
- ld c, 2 ; number of bytes to save
- ld a, 1
- ld [hSerialIgnoringInitialData], a
-.loop
- call DelayFrame
- ld a, [hl]
- ld [hSerialSendData], a
- call Serial_ExchangeByte
- ld b, a
- inc hl
- ld a, [hSerialIgnoringInitialData]
- and a
- ld a, 0
- ld [hSerialIgnoringInitialData], a
- jr nz, .loop
- ld a, b
- ld [de], a
- inc de
- dec c
- jr nz, .loop
- ret
-
-Serial_PrintWaitingTextAndSyncAndExchangeNybble:: ; 226e (0:226e)
- call SaveScreenTilesToBuffer1
- callab PrintWaitingText
- call Serial_SyncAndExchangeNybble
- jp LoadScreenTilesFromBuffer1
-
-Serial_SyncAndExchangeNybble:: ; 227f (0:227f)
- ld a, $ff
- ld [wSerialExchangeNybbleReceiveData], a
-.loop1
- call Serial_ExchangeNybble
- call DelayFrame
- call IsUnknownCounterZero
- jr z, .next1
- push hl
- ld hl, wUnknownSerialCounter + 1
- dec [hl]
- jr nz, .next2
- dec hl
- dec [hl]
- jr nz, .next2
- pop hl
- xor a
- jp SetUnknownCounterToFFFF
-.next2
- pop hl
-.next1
- ld a, [wSerialExchangeNybbleReceiveData]
- inc a
- jr z, .loop1
- ld b, 10
-.loop2
- call DelayFrame
- call Serial_ExchangeNybble
- dec b
- jr nz, .loop2
- ld b, 10
-.loop3
- call DelayFrame
- call Serial_SendZeroByte
- dec b
- jr nz, .loop3
- ld a, [wSerialExchangeNybbleReceiveData]
- ld [wSerialSyncAndExchangeNybbleReceiveData], a
- ret
-
-Serial_ExchangeNybble:: ; 22c3 (0:22c3)
- call .doExchange
- ld a, [wSerialExchangeNybbleSendData]
- add $60
- ld [hSerialSendData], a
- ld a, [hSerialConnectionStatus]
- cp USING_INTERNAL_CLOCK
- jr nz, .doExchange
- ld a, START_TRANSFER_INTERNAL_CLOCK
- ld [rSC], a
-.doExchange
- ld a, [hSerialReceiveData]
- ld [wSerialExchangeNybbleTempReceiveData], a
- and $f0
- cp $60
- ret nz
- xor a
- ld [hSerialReceiveData], a
- ld a, [wSerialExchangeNybbleTempReceiveData]
- and $f
- ld [wSerialExchangeNybbleReceiveData], a
- ret
-
-Serial_SendZeroByte:: ; 22ed (0:22ed)
- xor a
- ld [hSerialSendData], a
- ld a, [hSerialConnectionStatus]
- cp USING_INTERNAL_CLOCK
- ret nz
- ld a, START_TRANSFER_INTERNAL_CLOCK
- ld [rSC], a
- ret
-
-Serial_TryEstablishingExternallyClockedConnection:: ; 22fa (0:22fa)
- ld a, ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK
- ld [rSB], a
- xor a
- ld [hSerialReceiveData], a
- ld a, START_TRANSFER_EXTERNAL_CLOCK
- ld [rSC], a
- ret \ No newline at end of file
+Serial::
+ push af
+ push bc
+ push de
+ push hl
+ ld a, [hSerialConnectionStatus]
+ inc a
+ jr z, .connectionNotYetEstablished
+ ld a, [rSB]
+ ld [hSerialReceiveData], a
+ ld a, [hSerialSendData]
+ ld [rSB], a
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr z, .done
+; using external clock
+ ld a, START_TRANSFER_EXTERNAL_CLOCK
+ ld [rSC], a
+ jr .done
+.connectionNotYetEstablished
+ ld a, [rSB]
+ ld [hSerialReceiveData], a
+ ld [hSerialConnectionStatus], a
+ cp USING_INTERNAL_CLOCK
+ jr z, .usingInternalClock
+; using external clock
+ xor a
+ ld [rSB], a
+ ld a, $3
+ ld [rDIV], a
+.waitLoop
+ ld a, [rDIV]
+ bit 7, a
+ jr nz, .waitLoop
+ ld a, START_TRANSFER_EXTERNAL_CLOCK
+ ld [rSC], a
+ jr .done
+.usingInternalClock
+ xor a
+ ld [rSB], a
+.done
+ ld a, $1
+ ld [hSerialReceivedNewData], a
+ ld a, SERIAL_NO_DATA_BYTE
+ ld [hSerialSendData], a
+ pop hl
+ pop de
+ pop bc
+ pop af
+ reti
+
+; hl = send data
+; de = receive data
+; bc = length of data
+Serial_ExchangeBytes::
+ ld a, 1
+ ld [hSerialIgnoringInitialData], a
+.loop
+ ld a, [hl]
+ ld [hSerialSendData], a
+ call Serial_ExchangeByte
+ push bc
+ ld b, a
+ inc hl
+ ld a, 48
+.waitLoop
+ dec a
+ jr nz, .waitLoop
+ ld a, [hSerialIgnoringInitialData]
+ and a
+ ld a, b
+ pop bc
+ jr z, .storeReceivedByte
+ dec hl
+ cp SERIAL_PREAMBLE_BYTE
+ jr nz, .loop
+ xor a
+ ld [hSerialIgnoringInitialData], a
+ jr .loop
+.storeReceivedByte
+ ld [de], a
+ inc de
+ dec bc
+ ld a, b
+ or c
+ jr nz, .loop
+ ret
+
+Serial_ExchangeByte::
+ xor a
+ ld [hSerialReceivedNewData], a
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr nz, .loop
+ ld a, START_TRANSFER_INTERNAL_CLOCK
+ ld [rSC], a
+.loop
+ ld a, [hSerialReceivedNewData]
+ and a
+ jr nz, .ok
+ ld a, [hSerialConnectionStatus]
+ cp USING_EXTERNAL_CLOCK
+ jr nz, .doNotIncrementUnknownCounter
+ call IsUnknownCounterZero
+ jr z, .doNotIncrementUnknownCounter
+ call WaitLoop_15Iterations
+ push hl
+ ld hl, wUnknownSerialCounter + 1
+ inc [hl]
+ jr nz, .noCarry
+ dec hl
+ inc [hl]
+.noCarry
+ pop hl
+ call IsUnknownCounterZero
+ jr nz, .loop
+ jp SetUnknownCounterToFFFF
+.doNotIncrementUnknownCounter
+ ld a, [rIE]
+ and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
+ cp (1 << SERIAL)
+ jr nz, .loop
+ ld a, [wUnknownSerialCounter2]
+ dec a
+ ld [wUnknownSerialCounter2], a
+ jr nz, .loop
+ ld a, [wUnknownSerialCounter2 + 1]
+ dec a
+ ld [wUnknownSerialCounter2 + 1], a
+ jr nz, .loop
+ ld a, [hSerialConnectionStatus]
+ cp USING_EXTERNAL_CLOCK
+ jr z, .ok
+ ld a, 255
+.waitLoop
+ dec a
+ jr nz, .waitLoop
+.ok
+ xor a
+ ld [hSerialReceivedNewData], a
+ ld a, [rIE]
+ and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
+ sub (1 << SERIAL)
+ jr nz, .skipReloadingUnknownCounter2
+ ld [wUnknownSerialCounter2], a
+ ld a, $50
+ ld [wUnknownSerialCounter2 + 1], a
+.skipReloadingUnknownCounter2
+ ld a, [hSerialReceiveData]
+ cp SERIAL_NO_DATA_BYTE
+ ret nz
+ call IsUnknownCounterZero
+ jr z, .done
+ push hl
+ ld hl, wUnknownSerialCounter + 1
+ ld a, [hl]
+ dec a
+ ld [hld], a
+ inc a
+ jr nz, .noBorrow
+ dec [hl]
+.noBorrow
+ pop hl
+ call IsUnknownCounterZero
+ jr z, SetUnknownCounterToFFFF
+.done
+ ld a, [rIE]
+ and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
+ cp (1 << SERIAL)
+ ld a, SERIAL_NO_DATA_BYTE
+ ret z
+ ld a, [hl]
+ ld [hSerialSendData], a
+ call DelayFrame
+ jp Serial_ExchangeByte
+
+WaitLoop_15Iterations::
+ ld a, 15
+.waitLoop
+ dec a
+ jr nz, .waitLoop
+ ret
+
+IsUnknownCounterZero::
+ push hl
+ ld hl, wUnknownSerialCounter
+ ld a, [hli]
+ or [hl]
+ pop hl
+ ret
+
+; a is always 0 when this is called
+SetUnknownCounterToFFFF::
+ dec a
+ ld [wUnknownSerialCounter], a
+ ld [wUnknownSerialCounter + 1], a
+ ret
+
+; 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::
+ ld hl, wLinkMenuSelectionSendBuffer
+ ld de, wLinkMenuSelectionReceiveBuffer
+ ld c, 2 ; number of bytes to save
+ ld a, 1
+ ld [hSerialIgnoringInitialData], a
+.loop
+ call DelayFrame
+ ld a, [hl]
+ ld [hSerialSendData], a
+ call Serial_ExchangeByte
+ ld b, a
+ inc hl
+ ld a, [hSerialIgnoringInitialData]
+ and a
+ ld a, 0
+ ld [hSerialIgnoringInitialData], a
+ jr nz, .loop
+ ld a, b
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .loop
+ ret
+
+Serial_PrintWaitingTextAndSyncAndExchangeNybble::
+ call SaveScreenTilesToBuffer1
+ callab PrintWaitingText
+ call Serial_SyncAndExchangeNybble
+ jp LoadScreenTilesFromBuffer1
+
+Serial_SyncAndExchangeNybble::
+ ld a, $ff
+ ld [wSerialExchangeNybbleReceiveData], a
+.loop1
+ call Serial_ExchangeNybble
+ call DelayFrame
+ call IsUnknownCounterZero
+ jr z, .next1
+ push hl
+ ld hl, wUnknownSerialCounter + 1
+ dec [hl]
+ jr nz, .next2
+ dec hl
+ dec [hl]
+ jr nz, .next2
+ pop hl
+ xor a
+ jp SetUnknownCounterToFFFF
+.next2
+ pop hl
+.next1
+ ld a, [wSerialExchangeNybbleReceiveData]
+ inc a
+ jr z, .loop1
+ ld b, 10
+.loop2
+ call DelayFrame
+ call Serial_ExchangeNybble
+ dec b
+ jr nz, .loop2
+ ld b, 10
+.loop3
+ call DelayFrame
+ call Serial_SendZeroByte
+ dec b
+ jr nz, .loop3
+ ld a, [wSerialExchangeNybbleReceiveData]
+ ld [wSerialSyncAndExchangeNybbleReceiveData], a
+ ret
+
+Serial_ExchangeNybble::
+ call .doExchange
+ ld a, [wSerialExchangeNybbleSendData]
+ add $60
+ ld [hSerialSendData], a
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr nz, .doExchange
+ ld a, START_TRANSFER_INTERNAL_CLOCK
+ ld [rSC], a
+.doExchange
+ ld a, [hSerialReceiveData]
+ ld [wSerialExchangeNybbleTempReceiveData], a
+ and $f0
+ cp $60
+ ret nz
+ xor a
+ ld [hSerialReceiveData], a
+ ld a, [wSerialExchangeNybbleTempReceiveData]
+ and $f
+ ld [wSerialExchangeNybbleReceiveData], a
+ ret
+
+Serial_SendZeroByte::
+ xor a
+ ld [hSerialSendData], a
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ ret nz
+ ld a, START_TRANSFER_INTERNAL_CLOCK
+ ld [rSC], a
+ ret
+
+Serial_TryEstablishingExternallyClockedConnection::
+ ld a, ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK
+ ld [rSB], a
+ xor a
+ ld [hSerialReceiveData], a
+ ld a, START_TRANSFER_EXTERNAL_CLOCK
+ ld [rSC], a
+ ret
diff --git a/home/text.asm b/home/text.asm
index 276b652e..b983f609 100644
--- a/home/text.asm
+++ b/home/text.asm
@@ -1,5 +1,5 @@
TextBoxBorder::
-; Draw a cxb text box at hl.
+; Draw a c×b text box at hl.
; top row
push hl
@@ -11,7 +11,7 @@ TextBoxBorder::
ld [hl], a
pop hl
- ld de, 20
+ ld de, SCREEN_WIDTH
add hl, de
; middle rows
@@ -24,7 +24,7 @@ TextBoxBorder::
ld [hl], "│"
pop hl
- ld de, 20
+ ld de, SCREEN_WIDTH
add hl, de
dec b
jr nz, .next
@@ -46,88 +46,78 @@ NPlaceChar::
jr nz, .loop
ret
-PlaceString:: ; 1955 (0:1955)
+PlaceString::
push hl
-PlaceNextChar:: ; 1956 (0:1956)
+PlaceNextChar::
ld a,[de]
cp "@"
- jr nz,.PlaceText
+ jr nz, Char4ETest
ld b,h
ld c,l
pop hl
ret
-.PlaceText
- cp $4E
- jr nz,.next
- ld bc,$0028
+Char4ETest::
+ cp $4E ; next
+ jr nz, .char4FTest
+ ld bc, 2 * SCREEN_WIDTH
ld a,[hFlags_0xFFF6]
bit 2,a
- jr z,.next2
- ld bc,$14
-.next2
+ jr z,.ok
+ ld bc,SCREEN_WIDTH
+.ok
pop hl
add hl,bc
push hl
- jp Next19E8
+ jp PlaceNextChar_inc
-.next
- cp $4F
+.char4FTest
+ cp $4F ; line
jr nz,.next3
pop hl
- hlCoord 1, 16
+ coord hl, 1, 16
push hl
- jp Next19E8
+ jp PlaceNextChar_inc
.next3 ; Check against a dictionary
+dict: macro
+if \1 == 0
and a
- jp z,Char00
- cp $4C
- jp z,Char4C
- cp $4B
- jp z,Char4B
- cp $51
- jp z,Char51
- cp $49
- jp z,Char49
- cp $52
- jp z,Char52
- cp $53
- jp z,Char53
- cp $54
- jp z,Char54
- cp $5B
- jp z,Char5B
- cp $5E
- jp z,Char5E
- cp $5C
- jp z,Char5C
- cp $5D
- jp z,Char5D
- cp $55
- jp z,Char55
- cp $56
- jp z,Char56
- cp $57
- jp z,Char57
- cp $58
- jp z,Char58
- cp $4A
- jp z,Char4A
- cp $5F
- jp z,Char5F
- cp $59
- jp z,Char59
- cp $5A
- jp z,Char5A
+else
+ cp \1
+endc
+ jp z, \2
+endm
+
+ dict $00, Char00 ; error
+ dict $4C, Char4C ; autocont
+ dict $4B, Char4B ; cont_
+ dict $51, Char51 ; para
+ dict $49, Char49 ; page
+ dict $52, Char52 ; player
+ dict $53, Char53 ; rival
+ dict $54, Char54 ; POKé
+ dict $5B, Char5B ; PC
+ dict $5E, Char5E ; ROCKET
+ dict $5C, Char5C ; TM
+ dict $5D, Char5D ; TRAINER
+ dict $55, Char55 ; cont
+ dict $56, Char56 ; 6 dots
+ dict $57, Char57 ; done
+ dict $58, Char58 ; prompt
+ dict $4A, Char4A ; PKMN
+ dict $5F, Char5F ; dex
+ dict $59, Char59 ; TARGET
+ dict $5A, Char5A ; USER
+
ld [hli],a
call PrintLetterDelay
-Next19E8:: ; 19e8 (0:19e8)
+PlaceNextChar_inc::
inc de
jp PlaceNextChar
-Char00:: ; 19ec (0:19ec)
+Char00::
ld b,h
ld c,l
pop hl
@@ -135,56 +125,56 @@ Char00:: ; 19ec (0:19ec)
dec de
ret
-Char00Text:: ; 0x19f4 “%d ERROR.”
+Char00Text:: ; “%d ERROR.”
TX_FAR _Char00Text
db "@"
-Char52:: ; 0x19f9 player’s name
+Char52:: ; player’s name
push de
ld de,wPlayerName
jr FinishDTE
-Char53:: ; 19ff (0:19ff) ; rival’s name
+Char53:: ; rival’s name
push de
- ld de,W_RIVALNAME
+ ld de,wRivalName
jr FinishDTE
-Char5D:: ; 1a05 (0:1a05) ; TRAINER
+Char5D:: ; TRAINER
push de
ld de,Char5DText
jr FinishDTE
-Char5C:: ; 1a0b (0:1a0b) ; TM
+Char5C:: ; TM
push de
ld de,Char5CText
jr FinishDTE
-Char5B:: ; 1a11 (0:1a11) ; PC
+Char5B:: ; PC
push de
ld de,Char5BText
jr FinishDTE
-Char5E:: ; 1a17 (0:1a17) ; ROCKET
+Char5E:: ; ROCKET
push de
ld de,Char5EText
jr FinishDTE
-Char54:: ; 1a1d (0:1a1d) ; POKé
+Char54:: ; POKé
push de
ld de,Char54Text
jr FinishDTE
-Char56:: ; 1a23 (0:1a23) ; ……
+Char56:: ; ……
push de
ld de,Char56Text
jr FinishDTE
-Char4A:: ; 1a29 (0:1a29) ; PKMN
+Char4A:: ; PKMN
push de
ld de,Char4AText
jr FinishDTE
-Char59:: ; 1a2f (0:1a2f)
+Char59::
; depending on whose turn it is, print
; enemy active monster’s name, prefixed with “Enemy ”
; or
@@ -194,29 +184,28 @@ Char59:: ; 1a2f (0:1a2f)
xor 1
jr MonsterNameCharsCommon
-Char5A:: ; 1a35 (0:1a35)
+Char5A::
; depending on whose turn it is, print
; player active monster’s name
; or
; enemy active monster’s name, prefixed with “Enemy ”
ld a,[H_WHOSETURN]
-MonsterNameCharsCommon:: ; 1a37 (0:1a37)
+MonsterNameCharsCommon::
push de
and a
jr nz,.Enemy
ld de,wBattleMonNick ; player active monster name
jr FinishDTE
-.Enemy ; 1A40
+.Enemy
; print “Enemy ”
ld de,Char5AText
call PlaceString
-
ld h,b
ld l,c
ld de,wEnemyMonNick ; enemy active monster name
-FinishDTE:: ; 1a4b (0:1a4b)
+FinishDTE::
call PlaceString
ld h,b
ld l,c
@@ -224,24 +213,24 @@ FinishDTE:: ; 1a4b (0:1a4b)
inc de
jp PlaceNextChar
-Char5CText:: ; 1a55 (0:1a55)
+Char5CText::
db "TM@"
-Char5DText:: ; 1a58 (0:1a58)
+Char5DText::
db "TRAINER@"
-Char5BText:: ; 1a60 (0:1a60)
+Char5BText::
db "PC@"
-Char5EText:: ; 1a63 (0:1a63)
+Char5EText::
db "ROCKET@"
-Char54Text:: ; 1a6a (0:1a6a)
+Char54Text::
db "POKé@"
-Char56Text:: ; 1a6f (0:1a6f)
+Char56Text::
db "……@"
-Char5AText:: ; 1a72 (0:1a72)
+Char5AText::
db "Enemy @"
-Char4AText:: ; 1a79 (0:1a79)
+Char4AText::
db $E1,$E2,"@" ; PKMN
-Char55:: ; 1a7c (0:1a7c)
+Char55::
push de
ld b,h
ld c,l
@@ -253,104 +242,108 @@ Char55:: ; 1a7c (0:1a7c)
inc de
jp PlaceNextChar
-Char55Text:: ; 1a8c (0:1a8c)
+Char55Text::
; equivalent to Char4B
TX_FAR _Char55Text
db "@"
-Char5F:: ; 1a91 (0:1a91)
+Char5F::
; ends a Pokédex entry
ld [hl],"."
pop hl
ret
-Char58:: ; 1a95 (0:1a95)
+Char58:: ; prompt
ld a,[wLinkState]
cp LINK_STATE_BATTLING
- jp z,Next1AA2
- ld a,$EE
+ jp z, .ok
+ ld a, "▼"
Coorda 18, 16
-Next1AA2:: ; 1aa2 (0:1aa2)
+.ok
call ProtectedDelay3
call ManualTextScroll
- ld a,$7F
+ ld a, " "
Coorda 18, 16
-Char57:: ; 1aad (0:1aad)
+Char57:: ; done
pop hl
- ld de,Char58Text
+ ld de, Char58Text
dec de
ret
-Char58Text:: ; 1ab3 (0:1ab3)
+Char58Text::
db "@"
-Char51:: ; 1ab4 (0:1ab4)
+Char51:: ; para
push de
- ld a,$EE
+ ld a, "▼"
Coorda 18, 16
call ProtectedDelay3
call ManualTextScroll
- hlCoord 1, 13
- ld bc,$0412
+ coord hl, 1, 13
+ lb bc, 4, 18
call ClearScreenArea
- ld c,$14
+ ld c, 20
call DelayFrames
pop de
- hlCoord 1, 14
- jp Next19E8
+ coord hl, 1, 14
+ jp PlaceNextChar_inc
-Char49:: ; 1ad5 (0:1ad5)
+Char49::
push de
- ld a,$EE
+ ld a,"▼"
Coorda 18, 16
call ProtectedDelay3
call ManualTextScroll
- hlCoord 1, 10
- ld bc,$0712
+ coord hl, 1, 10
+ lb bc, 7, 18
call ClearScreenArea
- ld c,$14
+ ld c,20
call DelayFrames
pop de
pop hl
- hlCoord 1, 11
+ coord hl, 1, 11
push hl
- jp Next19E8
+ jp PlaceNextChar_inc
-Char4B:: ; 1af8 (0:1af8)
- ld a,$EE
+Char4B::
+ ld a,"▼"
Coorda 18, 16
call ProtectedDelay3
push de
call ManualTextScroll
pop de
- ld a,$7F
+ ld a, " "
Coorda 18, 16
;fall through
-Char4C:: ; 1b0a (0:1b0a)
+Char4C::
push de
- call Next1B18
- call Next1B18
- hlCoord 1, 16
+ call ScrollTextUpOneLine
+ call ScrollTextUpOneLine
+ coord hl, 1, 16
pop de
- jp Next19E8
-
-Next1B18:: ; 1b18 (0:1b18)
- hlCoord 0, 14
- deCoord 0, 13
- ld b,$3C
-.next
+ jp PlaceNextChar_inc
+
+; move both rows of text in the normal text box up one row
+; always called twice in a row
+; first time, copy the two rows of text to the "in between" rows that are usually emtpy
+; second time, copy the bottom row of text into the top row of text
+ScrollTextUpOneLine::
+ coord hl, 0, 14 ; top row of text
+ coord de, 0, 13 ; empty line above text
+ ld b, SCREEN_WIDTH * 3
+.copyText
ld a,[hli]
ld [de],a
inc de
dec b
- jr nz,.next
- hlCoord 1, 16
- ld a,$7F
- ld b,$12
-.next2
+ jr nz,.copyText
+ coord hl, 1, 16
+ ld a, " "
+ ld b,SCREEN_WIDTH - 2
+.clearText
ld [hli],a
dec b
- jr nz,.next2
+ jr nz,.clearText
; wait five frames
ld b,5
@@ -361,57 +354,57 @@ Next1B18:: ; 1b18 (0:1b18)
ret
-ProtectedDelay3:: ; 1b3a (0:1b3a)
+ProtectedDelay3::
push bc
call Delay3
pop bc
ret
-TextCommandProcessor:: ; 1b40 (0:1b40)
- ld a,[wd358]
+TextCommandProcessor::
+ ld a,[wLetterPrintingDelayFlags]
push af
set 1,a
ld e,a
- ld a,[$fff4]
+ ld a, [$fff4]
xor e
- ld [wd358],a
+ ld [wLetterPrintingDelayFlags],a
ld a,c
- ld [wcc3a],a
+ ld [wTextDest],a
ld a,b
- ld [wcc3b],a
+ ld [wTextDest + 1],a
-NextTextCommand:: ; 1b55 (0:1b55)
+NextTextCommand::
ld a,[hli]
cp a, "@" ; terminator
jr nz,.doTextCommand
pop af
- ld [wd358],a
+ ld [wLetterPrintingDelayFlags],a
ret
.doTextCommand
push hl
- cp a,$17
- jp z,TextCommand17
- cp a,$0e
+ cp a, $17
+ jp z, TextCommand17
+ cp a, $0e
jp nc,TextCommand0B ; if a != 0x17 and a >= 0xE, go to command 0xB
; if a < 0xE, use a jump table
ld hl,TextCommandJumpTable
push bc
add a
- ld b,$00
- ld c,a
- add hl,bc
+ ld b, 0
+ ld c, a
+ add hl, bc
pop bc
- ld a,[hli]
- ld h,[hl]
- ld l,a
- jp [hl]
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp hl
; draw box
; 04AAAABBCC
; AAAA = address of upper left corner
; BB = height
; CC = width
-TextCommand04:: ; 1b78 (0:1b78)
+TextCommand04::
pop hl
ld a,[hli]
ld e,a
@@ -430,7 +423,7 @@ TextCommand04:: ; 1b78 (0:1b78)
; place string inline
; 00{string}
-TextCommand00:: ; 1b8a (0:1b8a)
+TextCommand00::
pop hl
ld d,h
ld e,l
@@ -445,7 +438,7 @@ TextCommand00:: ; 1b8a (0:1b8a)
; place string from RAM
; 01AAAA
; AAAA = address of string
-TextCommand01:: ; 1b97 (0:1b97)
+TextCommand01::
pop hl
ld a,[hli]
ld e,a
@@ -464,7 +457,7 @@ TextCommand01:: ; 1b97 (0:1b97)
; BB
; bits 0-4 = length in bytes
; bits 5-7 = unknown flags
-TextCommand02:: ; 1ba5 (0:1ba5)
+TextCommand02::
pop hl
ld a,[hli]
ld e,a
@@ -484,32 +477,32 @@ TextCommand02:: ; 1ba5 (0:1ba5)
; repoint destination address
; 03AAAA
; AAAA = new destination address
-TextCommand03:: ; 1bb7 (0:1bb7)
+TextCommand03::
pop hl
ld a,[hli]
- ld [wcc3a],a
+ ld [wTextDest],a
ld c,a
ld a,[hli]
- ld [wcc3b],a
+ ld [wTextDest + 1],a
ld b,a
jp NextTextCommand
; repoint destination to second line of dialogue text box
; 05
; (no arguments)
-TextCommand05:: ; 1bc5 (0:1bc5)
+TextCommand05::
pop hl
- bcCoord 1, 16 ; address of second line of dialogue text box
+ coord bc, 1, 16 ; address of second line of dialogue text box
jp NextTextCommand
; blink arrow and wait for A or B to be pressed
; 06
; (no arguments)
-TextCommand06:: ; 1bcc (0:1bcc)
+TextCommand06::
ld a,[wLinkState]
cp a,LINK_STATE_BATTLING
jp z,TextCommand0D
- ld a,$ee ; down arrow
+ ld a,"▼"
Coorda 18, 16 ; place down arrow in lower right corner of dialogue text box
push bc
call ManualTextScroll ; blink arrow and wait for A or B to be pressed
@@ -522,22 +515,22 @@ TextCommand06:: ; 1bcc (0:1bcc)
; scroll text up one line
; 07
; (no arguments)
-TextCommand07:: ; 1be7 (0:1be7)
- ld a," "
+TextCommand07::
+ ld a, " "
Coorda 18, 16 ; place blank space in lower right corner of dialogue text box
- call Next1B18 ; scroll up text
- call Next1B18
+ call ScrollTextUpOneLine
+ call ScrollTextUpOneLine
pop hl
- bcCoord 1, 16 ; address of second line of dialogue text box
+ coord bc, 1, 16 ; address of second line of dialogue text box
jp NextTextCommand
; execute asm inline
; 08{code}
-TextCommand08:: ; 1bf9 (0:1bf9)
+TextCommand08::
pop hl
ld de,NextTextCommand
push de ; return address
- jp [hl]
+ jp hl
; print decimal number (converted from binary number)
; 09AAAABB
@@ -545,7 +538,7 @@ TextCommand08:: ; 1bf9 (0:1bf9)
; BB
; bits 0-3 = how many digits to display
; bits 4-7 = how long the number is in bytes
-TextCommand09:: ; 1bff (0:1bff)
+TextCommand09::
pop hl
ld a,[hli]
ld e,a
@@ -561,7 +554,7 @@ TextCommand09:: ; 1bff (0:1bff)
ld a,b
and a,$f0
swap a
- set 6,a
+ set BIT_LEFT_ALIGN,a
ld b,a
call PrintNumber
ld b,h
@@ -572,11 +565,11 @@ TextCommand09:: ; 1bff (0:1bff)
; wait half a second if the user doesn't hold A or B
; 0A
; (no arguments)
-TextCommand0A:: ; 1c1d (0:1c1d)
+TextCommand0A::
push bc
call Joypad
ld a,[hJoyHeld]
- and a,%00000011 ; A and B buttons
+ and a,A_BUTTON | B_BUTTON
jr nz,.skipDelay
ld c,30
call DelayFrames
@@ -588,7 +581,7 @@ TextCommand0A:: ; 1c1d (0:1c1d)
; plays sounds
; this actually handles various command ID's, not just 0B
; (no arguments)
-TextCommand0B:: ; 1c31 (0:1c31)
+TextCommand0B::
pop hl
push bc
dec hl
@@ -625,22 +618,22 @@ TextCommand0B:: ; 1c31 (0:1c31)
jp NextTextCommand
; format: text command ID, sound ID or cry ID
-TextCommandSounds:: ; 1c64 (0:1c64)
- db $0B,(SFX_02_3a - SFX_Headers_02) / 3
- db $12,(SFX_08_46 - SFX_Headers_08) / 3
- db $0E,(SFX_02_41 - SFX_Headers_02) / 3
- db $0F,(SFX_02_3a - SFX_Headers_02) / 3
- db $10,(SFX_02_3b - SFX_Headers_02) / 3
- db $11,(SFX_02_42 - SFX_Headers_02) / 3
- db $13,(SFX_08_45 - SFX_Headers_08) / 3
- db $14,NIDORINA ; used in OakSpeech
- db $15,PIDGEOT ; used in SaffronCityText12
- db $16,DEWGONG ; unused?
+TextCommandSounds::
+ db $0B, SFX_GET_ITEM_1 ; actually plays SFX_LEVEL_UP when the battle music engine is loaded
+ db $12, SFX_CAUGHT_MON
+ db $0E, SFX_POKEDEX_RATING ; unused?
+ db $0F, SFX_GET_ITEM_1 ; unused?
+ db $10, SFX_GET_ITEM_2
+ db $11, SFX_GET_KEY_ITEM
+ db $13, SFX_DEX_PAGE_ADDED
+ db $14, NIDORINA ; used in OakSpeech
+ db $15, PIDGEOT ; used in SaffronCityText12
+ db $16, DEWGONG ; unused?
; draw ellipses
; 0CAA
; AA = number of ellipses to draw
-TextCommand0C:: ; 1c78 (0:1c78)
+TextCommand0C::
pop hl
ld a,[hli]
ld d,a
@@ -648,13 +641,13 @@ TextCommand0C:: ; 1c78 (0:1c78)
ld h,b
ld l,c
.loop
- ld a,$75 ; ellipsis
+ ld a,"…"
ld [hli],a
push de
call Joypad
pop de
ld a,[hJoyHeld] ; joypad state
- and a,%00000011 ; is A or B button pressed?
+ and a,A_BUTTON | B_BUTTON
jr nz,.skipDelay ; if so, skip the delay
ld c,10
call DelayFrames
@@ -669,7 +662,7 @@ TextCommand0C:: ; 1c78 (0:1c78)
; wait for A or B to be pressed
; 0D
; (no arguments)
-TextCommand0D:: ; 1c9a (0:1c9a)
+TextCommand0D::
push bc
call ManualTextScroll ; wait for A or B to be pressed
pop bc
@@ -680,7 +673,7 @@ TextCommand0D:: ; 1c9a (0:1c9a)
; 17AAAABB
; AAAA = address of text commands
; BB = bank
-TextCommand17:: ; 1ca3 (0:1ca3)
+TextCommand17::
pop hl
ld a,[H_LOADEDROMBANK]
push af
@@ -690,7 +683,7 @@ TextCommand17:: ; 1ca3 (0:1ca3)
ld d,a
ld a,[hli]
ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [MBC1RomBank],a
push hl
ld l,e
ld h,d
@@ -698,10 +691,10 @@ TextCommand17:: ; 1ca3 (0:1ca3)
pop hl
pop af
ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [MBC1RomBank],a
jp NextTextCommand
-TextCommandJumpTable:: ; 1cc1 (0:1cc1)
+TextCommandJumpTable::
dw TextCommand00
dw TextCommand01
dw TextCommand02
diff --git a/home/timer.asm b/home/timer.asm
index 8578df1a..05e307bd 100644
--- a/home/timer.asm
+++ b/home/timer.asm
@@ -1,3 +1,3 @@
; timer interrupt is apparently not invoked anyway
-Timer:: ; 2306 (0:2306)
+Timer::
reti
diff --git a/home/vblank.asm b/home/vblank.asm
index d8288187..e80fba75 100644
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -6,14 +6,14 @@ VBlank::
push hl
ld a, [H_LOADEDROMBANK]
- ld [wd122], a
+ ld [wVBlankSavedROMBank], a
ld a, [hSCX]
ld [rSCX], a
ld a, [hSCY]
ld [rSCY], a
- ld a, [wd0a0]
+ ld a, [wDisableVBlankWYUpdate]
and a
jr nz, .ok
ld a, [hWY]
@@ -22,12 +22,12 @@ VBlank::
call AutoBgMapTransfer
call VBlankCopyBgMap
- call RedrawExposedScreenEdge
+ call RedrawRowOrColumn
call VBlankCopy
call VBlankCopyDouble
call UpdateMovingBgTiles
call $ff80 ; hOAMDMA
- ld a, Bank(PrepareOAMData)
+ ld a, BANK(PrepareOAMData)
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
call PrepareOAMData
@@ -38,47 +38,47 @@ VBlank::
ld a, [H_VBLANKOCCURRED]
and a
- jr z, .vblanked
+ jr z, .skipZeroing
xor a
ld [H_VBLANKOCCURRED], a
-.vblanked
+.skipZeroing
ld a, [H_FRAMECOUNTER]
and a
- jr z, .decced
+ jr z, .skipDec
dec a
ld [H_FRAMECOUNTER], a
-.decced
- call Func_28cb
+.skipDec
+ call FadeOutAudio
- ld a, [wc0ef] ; music ROM bank
+ ld a, [wAudioROMBank] ; music ROM bank
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
- cp BANK(Music2_UpdateMusic)
- jr nz, .notbank2
-.bank2
- call Music2_UpdateMusic
+ cp BANK(Audio1_UpdateMusic)
+ jr nz, .checkForAudio2
+.audio1
+ call Audio1_UpdateMusic
jr .afterMusic
-.notbank2
- cp BANK(Music8_UpdateMusic)
- jr nz, .bank1F
-.bank8
+.checkForAudio2
+ cp BANK(Audio2_UpdateMusic)
+ jr nz, .audio3
+.audio2
call Music_DoLowHealthAlarm
- call Music8_UpdateMusic
+ call Audio2_UpdateMusic
jr .afterMusic
-.bank1F
- call Music1f_UpdateMusic
+.audio3
+ call Audio3_UpdateMusic
.afterMusic
callba TrackPlayTime ; keep track of time played
- ld a, [$fff9]
+ ld a, [hDisableJoypadPolling]
and a
call z, ReadJoypad
- ld a, [wd122]
+ ld a, [wVBlankSavedROMBank]
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
diff --git a/home/vcopy.asm b/home/vcopy.asm
index d42293d9..3fe19745 100644
--- a/home/vcopy.asm
+++ b/home/vcopy.asm
@@ -1,7 +1,7 @@
; this function seems to be used only once
; it store the address of a row and column of the VRAM background map in hl
; INPUT: h - row, l - column, b - high byte of background tile map address in VRAM
-GetRowColAddressBgMap:: ; 1cdd (0:1cdd)
+GetRowColAddressBgMap::
xor a
srl h
rr a
@@ -18,7 +18,7 @@ GetRowColAddressBgMap:: ; 1cdd (0:1cdd)
; clears a VRAM background map with blank space tiles
; INPUT: h - high byte of background tile map address in VRAM
-ClearBgMap:: ; 1cf0 (0:1cf0)
+ClearBgMap::
ld a," "
jr .next
ld a,l
@@ -33,32 +33,35 @@ ClearBgMap:: ; 1cf0 (0:1cf0)
jr nz,.loop
ret
-; When the player takes a step, a row or column of 2x2 tile blocks at the edge
-; of the screen toward which they moved is exposed and has to be redrawn.
-; This function does the redrawing.
-RedrawExposedScreenEdge:: ; 1d01 (0:1d01)
- ld a,[H_SCREENEDGEREDRAW]
+; This function redraws a BG row of height 2 or a BG column of width 2.
+; One of its main uses is redrawing the row or column that will be exposed upon
+; scrolling the BG when the player takes a step. Redrawing only the exposed
+; row or column is more efficient than redrawing the entire screen.
+; However, this function is also called repeatedly to redraw the whole screen
+; when necessary. It is also used in trade animation and elevator code.
+RedrawRowOrColumn::
+ ld a,[hRedrawRowOrColumnMode]
and a
ret z
ld b,a
xor a
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnMode],a
dec b
jr nz,.redrawRow
.redrawColumn
- ld hl,wScreenEdgeTiles
- ld a,[H_SCREENEDGEREDRAWADDR]
+ ld hl,wRedrawRowOrColumnSrcTiles
+ ld a,[hRedrawRowOrColumnDest]
ld e,a
- ld a,[H_SCREENEDGEREDRAWADDR + 1]
+ ld a,[hRedrawRowOrColumnDest + 1]
ld d,a
- ld c,18 ; screen height
+ ld c,SCREEN_HEIGHT
.loop1
ld a,[hli]
ld [de],a
inc de
ld a,[hli]
ld [de],a
- ld a,31
+ ld a,BG_MAP_WIDTH - 1
add e
ld e,a
jr nc,.noCarry
@@ -72,23 +75,24 @@ RedrawExposedScreenEdge:: ; 1d01 (0:1d01)
dec c
jr nz,.loop1
xor a
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnMode],a
ret
.redrawRow
- ld hl,wScreenEdgeTiles
- ld a,[H_SCREENEDGEREDRAWADDR]
+ ld hl,wRedrawRowOrColumnSrcTiles
+ ld a,[hRedrawRowOrColumnDest]
ld e,a
- ld a,[H_SCREENEDGEREDRAWADDR + 1]
+ ld a,[hRedrawRowOrColumnDest + 1]
ld d,a
push de
- call .drawHalf ; draw upper half
+ call .DrawHalf ; draw upper half
pop de
- ld a,32 ; width of VRAM background map
+ ld a,BG_MAP_WIDTH ; width of VRAM background map
add e
ld e,a
- ; draw lower half
-.drawHalf
- ld c,10
+ ; fall through and draw lower half
+
+.DrawHalf
+ ld c,SCREEN_WIDTH / 2
.loop2
ld a,[hli]
ld [de],a
@@ -113,9 +117,9 @@ RedrawExposedScreenEdge:: ; 1d01 (0:1d01)
; background per V-blank. It cycles through which third it draws.
; This transfer is turned off when walking around the map, but is turned
; on when talking to sprites, battling, using menus, etc. This is because
-; the above function, RedrawExposedScreenEdge, is used when walking to
+; the above function, RedrawRowOrColumn, is used when walking to
; improve efficiency.
-AutoBgMapTransfer:: ; 1d57 (0:1d57)
+AutoBgMapTransfer::
ld a,[H_AUTOBGTRANSFERENABLED]
and a
ret z
@@ -130,7 +134,7 @@ AutoBgMapTransfer:: ; 1d57 (0:1d57)
dec a
jr z,.transferMiddleThird
.transferBottomThird
- hlCoord 0, 12
+ coord hl, 0, 12
ld sp,hl
ld a,[H_AUTOBGTRANSFERDEST + 1]
ld h,a
@@ -141,7 +145,7 @@ AutoBgMapTransfer:: ; 1d57 (0:1d57)
xor a ; TRANSFERTOP
jr .doTransfer
.transferTopThird
- hlCoord 0, 0
+ coord hl, 0, 0
ld sp,hl
ld a,[H_AUTOBGTRANSFERDEST + 1]
ld h,a
@@ -150,7 +154,7 @@ AutoBgMapTransfer:: ; 1d57 (0:1d57)
ld a,TRANSFERMIDDLE
jr .doTransfer
.transferMiddleThird
- hlCoord 0, 6
+ coord hl, 0, 6
ld sp,hl
ld a,[H_AUTOBGTRANSFERDEST + 1]
ld h,a
@@ -163,7 +167,7 @@ AutoBgMapTransfer:: ; 1d57 (0:1d57)
ld [H_AUTOBGTRANSFERPORTION],a ; store next portion
ld b,6
-TransferBgRows:: ; 1d9e (0:1d9e)
+TransferBgRows::
; unrolled loop and using pop for speed
rept 20 / 2 - 1
@@ -197,7 +201,7 @@ TransferBgRows:: ; 1d9e (0:1d9e)
; Copies [H_VBCOPYBGNUMROWS] rows from H_VBCOPYBGSRC to H_VBCOPYBGDEST.
; If H_VBCOPYBGSRC is XX00, the transfer is disabled.
-VBlankCopyBgMap:: ; 1de1 (0:1de1)
+VBlankCopyBgMap::
ld a,[H_VBCOPYBGSRC] ; doubles as enabling byte
and a
ret z
@@ -302,12 +306,11 @@ VBlankCopyDouble::
VBlankCopy::
-; Copy [H_VBCOPYSIZE] 2bpp tiles
+; Copy [H_VBCOPYSIZE] 2bpp tiles (or 16 * [H_VBCOPYSIZE] tile map entries)
; from H_VBCOPYSRC to H_VBCOPYDEST.
-; Source and destination addresses
-; are updated, so transfer can
-; continue in subsequent calls.
+; Source and destination addresses are updated,
+; so transfer can continue in subsequent calls.
ld a, [H_VBCOPYSIZE]
and a
@@ -380,21 +383,23 @@ UpdateMovingBgTiles::
and a
ret z ; no animations if indoors (or if a menu set this to 0)
- ld a, [$ffd8]
+ ld a, [hMovingBGTilesCounter1]
inc a
- ld [$ffd8], a
- cp $14
+ ld [hMovingBGTilesCounter1], a
+ cp 20
ret c
- cp $15
+ cp 21
jr z, .flower
+; water
+
ld hl, vTileset + $14 * $10
ld c, $10
- ld a, [wd085]
+ ld a, [wMovingBGTilesCounter2]
inc a
and 7
- ld [wd085], a
+ ld [wMovingBGTilesCounter2], a
and 4
jr nz, .left
@@ -417,14 +422,14 @@ UpdateMovingBgTiles::
ret nc
; if in a cave, no flower animations
xor a
- ld [$ffd8], a
+ ld [hMovingBGTilesCounter1], a
ret
.flower
xor a
- ld [$ffd8], a
+ ld [hMovingBGTilesCounter1], a
- ld a, [wd085]
+ ld a, [wMovingBGTilesCounter2]
and 3
cp 2
ld hl, FlowerTile1