summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rwxr-xr-xengine/items/items.asm34
-rw-r--r--engine/joypad.asm37
-rwxr-xr-xengine/overworld/map_sprites.asm2
-rw-r--r--engine/overworld/oam.asm16
-rwxr-xr-xengine/random.asm2
-rwxr-xr-xengine/save.asm116
-rw-r--r--home.asm443
-rw-r--r--home/audio.asm3
-rw-r--r--home/copy.asm74
-rw-r--r--home/copy2.asm143
-rw-r--r--home/init.asm3
-rw-r--r--home/joypad.asm39
-rw-r--r--home/overworld.asm1361
-rw-r--r--[-rwxr-xr-x]home/play_time.asm (renamed from engine/play_time.asm)0
-rw-r--r--home/vblank.asm46
-rw-r--r--home/vcopy.asm68
-rw-r--r--hram.asm7
-rw-r--r--macros.asm47
-rwxr-xr-xmain.asm19
-rwxr-xr-xscripts/celadongamecorner.asm42
-rwxr-xr-xscripts/ceruleangym.asm4
-rwxr-xr-xscripts/copycatshouse2f.asm2
-rwxr-xr-xscripts/fuchsiahouse2.asm4
-rwxr-xr-xscripts/mtmoonpokecenter.asm6
-rwxr-xr-xscripts/pewtercity.asm10
-rwxr-xr-xscripts/pewtergym.asm4
-rwxr-xr-xscripts/rockethideout4.asm4
-rwxr-xr-xscripts/route2gate.asm6
-rwxr-xr-xscripts/ssanne6.asm2
-rw-r--r--sram.asm33
-rwxr-xr-xwram.asm28
-rw-r--r--yellow/audio.asm2
-rw-r--r--yellow/bank3c/main.asm116
-rw-r--r--yellow/bank3c/overworld.asm242
-rw-r--r--yellow/bank3d/random.asm15
-rw-r--r--[-rwxr-xr-x]yellow/bank3f/data/map_header_banks.asm (renamed from data/map_header_banks.asm)4
-rw-r--r--[-rwxr-xr-x]yellow/bank3f/data/map_header_pointers.asm (renamed from data/map_header_pointers.asm)4
-rw-r--r--[-rwxr-xr-x]yellow/bank3f/data/map_songs.asm (renamed from data/map_songs.asm)2
-rw-r--r--yellow/bank3f/main.asm217
-rw-r--r--yellow/main.asm2
-rw-r--r--yellow/text.asm2
-rw-r--r--yellow/wram.asm2
43 files changed, 1999 insertions, 1222 deletions
diff --git a/README.md b/README.md
index abaaa653..b411e29d 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,11 @@
+# Pokémon Yellow
+
+This is not a buildable disassembly of Pokémon Yellow. This is here so I can put all Yellow differences that I find, that can't be specified by "IF(DEF)"s.
+
+Expect this to be completed in 3000 years.
+
+Original readme below.
+
# Pokémon Red and Blue
This is a disassembly of Pokémon Red and Blue.
diff --git a/engine/items/items.asm b/engine/items/items.asm
index 21e6e924..c6f098dc 100755
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -2740,31 +2740,35 @@ IsNextTileShoreOrWater: ; e8b8 (3:68b8)
ld a, [W_CURMAPTILESET]
ld hl, WaterTilesets
ld de,1
- call IsInArray
- jr nc, .notShoreOrWater
+ call IsInArray ; does the current map allow surfing?
+ ret nc ; if not, return
+ ld hl,WaterTile
ld a, [W_CURMAPTILESET]
cp SHIP_PORT ; Vermilion Dock tileset
- ld a, [wTileInFrontOfPlayer] ; tile in front of player
jr z, .skipShoreTiles ; if it's the Vermilion Dock tileset
- cp $48 ; eastern shore tile in Safari Zone
- jr z, .shoreOrWater
- cp $32 ; usual eastern shore tile
- jr z, .shoreOrWater
+ cp GYM ; eastern shore tile in Safari Zone
+ jr z, .skipShoreTiles
+ cp DOJO ; usual eastern shore tile
+ jr z, .skipShoreTiles
+ ld hl,ShoreTiles
.skipShoreTiles
- cp $14 ; water tile
- jr z, .shoreOrWater
-.notShoreOrWater
- scf
- ret
-.shoreOrWater
- and a
+ ld a,[wTileInFrontOfPlayer]
+ ld de,$1
+ call IsInArray
ret
; tilesets with water
-WaterTilesets: ; e8e0 (3:68e0)
+WaterTilesets: ; e834 (3:6834)
db OVERWORLD, FOREST, DOJO, GYM, SHIP, SHIP_PORT, CAVERN, FACILITY, PLATEAU
db $ff ; terminator
+; shore tiles
+ShoreTiles: ; e83e (3:683e)
+ db $48, $32
+WaterTile: ; e840 (3:6840)
+ db $14
+ db $ff ; terminator
+
ReadSuperRodData: ; e8ea (3:68ea)
; return e = 2 if no fish on this map
; return e = 1 if a bite, bc = level,species
diff --git a/engine/joypad.asm b/engine/joypad.asm
index 31e197e2..791056ca 100644
--- a/engine/joypad.asm
+++ b/engine/joypad.asm
@@ -1,8 +1,43 @@
-_Joypad::
+ReadJoypad_:: ; c000 (3:4000)
+; Poll joypad input.
+; Unlike the hardware register, button
+; presses are indicated by a set bit.
+
+ ld a, 1 << 5 ; select direction keys
+ ld c, 0
+
+ ld [rJOYP], a
+ rept 6
+ ld a, [rJOYP]
+ endr
+ cpl
+ and %1111
+ swap a
+ ld b, a
+
+ ld a, 1 << 4 ; select button keys
+ ld [rJOYP], a
+ rept 10
+ ld a, [rJOYP]
+ endr
+ cpl
+ and %1111
+ or b
+
+ ld [hJoyInput], a
+
+ ld a, 1 << 4 + 1 << 5 ; deselect keys
+ ld [rJOYP], a
+ ret
+
+
+_Joypad:: ; c02d (3:402d)
; hJoyReleased: (hJoyLast ^ hJoyInput) & hJoyLast
; hJoyPressed: (hJoyLast ^ hJoyInput) & hJoyInput
ld a, [hJoyInput]
+ ld b,a
+ and $4F
cp A_BUTTON + B_BUTTON + SELECT + START ; soft reset
jp z, TrySoftReset
diff --git a/engine/overworld/map_sprites.asm b/engine/overworld/map_sprites.asm
index df39d112..747a0a45 100755
--- a/engine/overworld/map_sprites.asm
+++ b/engine/overworld/map_sprites.asm
@@ -8,7 +8,7 @@
; fields, respectively, within loops. The X is the loop index.
; If there is an inner loop, Y is the inner loop index, i.e. $C1Y* and $C2Y*
; denote fields of the sprite slots interated over in the inner loop.
-InitMapSprites: ; 1785b (5:785b)
+_InitMapSprites: ; 1785b (5:785b)
call InitOutsideMapSprites
ret c ; return if the map is an outside map (already handled by above call)
; if the map is an inside map (i.e. mapID >= $25)
diff --git a/engine/overworld/oam.asm b/engine/overworld/oam.asm
index b4247257..71eb297c 100644
--- a/engine/overworld/oam.asm
+++ b/engine/overworld/oam.asm
@@ -176,3 +176,19 @@ Func_4bd1: ; 4bd1 (1:4bd1)
and $f0
ld [de], a ; c1xb (x)
ret
+
+_IsTilePassable:: ; 4aaa (1:4aaa)
+ ld hl,W_TILESETCOLLISIONPTR ; pointer to list of passable tiles
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a ; hl now points to passable tiles
+.loop
+ ld a,[hli]
+ cp a,$ff
+ jr z,.tileNotPassable
+ cp c
+ ret z
+ jr .loop
+.tileNotPassable
+ scf
+ ret \ No newline at end of file
diff --git a/engine/random.asm b/engine/random.asm
index 2fc83f6f..b7fb0edd 100755
--- a/engine/random.asm
+++ b/engine/random.asm
@@ -1,3 +1,5 @@
+SECTION "bank3d",ROMX[$67DC],BANK[$3D]
+
Random_::
; Generate a random 16-bit value.
ld a, [rDIV]
diff --git a/engine/save.asm b/engine/save.asm
index d3127f04..93b70be4 100755
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -37,39 +37,39 @@ LoadSAVCheckSum: ; 73623 (1c:7623)
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, $a598 ; hero name located in SRAM
+ ld hl, S_SAVEDPLAYERNAME ; hero name located in SRAM
ld bc, $f8b ; but here checks the full SAV
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum
cp c
jp z, .Func_73652
- ld hl, $a598
+ ld hl, S_SAVEDPLAYERNAME
ld bc, $f8b
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum
cp c
jp nz, SAVBadCheckSum
.Func_73652 ; 73652 (1c:7652)
- ld hl, $a598
+ ld hl, S_SAVEDPLAYERNAME
ld de, wPlayerName ; wd158
ld bc, $b
call CopyData
- ld hl, $a5a3
+ ld hl, S_SAVEDMAINDATA
ld de, wPokedexOwned
ld bc, $789
call CopyData
ld hl, W_CURMAPTILESET
set 7, [hl]
- ld hl, $ad2c
+ ld hl, S_SAVEDSPRITEDATA
ld de, wSpriteStateData1
ld bc, $200
call CopyData
- ld a, [$b522]
+ ld a, [S_SAVEDhTilesetType]
ld [hTilesetType], a
- ld hl, $b0c0
+ ld hl, S_SAVEDCURBOXDATA
ld de, W_NUMINBOX
ld bc, wBoxMonNicksEnd - W_NUMINBOX
call CopyData
@@ -82,14 +82,14 @@ LoadSAVCheckSum1: ; 73690 (1c:7690)
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, $a598 ; hero name located in SRAM
+ ld hl, S_SAVEDPLAYERNAME ; hero name located in SRAM
ld bc, $f8b ; but here checks the full SAV
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum
cp c
jr nz, SAVBadCheckSum
- ld hl, $b0c0
+ ld hl, S_SAVEDCURBOXDATA
ld de, W_NUMINBOX
ld bc, wBoxMonNicksEnd - W_NUMINBOX
call CopyData
@@ -102,18 +102,18 @@ LoadSAVCheckSum2: ; 736bd (1c:76bd)
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, $a598 ; hero name located in SRAM
+ ld hl, S_SAVEDPLAYERNAME ; hero name located in SRAM
ld bc, $f8b ; but here checks the full SAV
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum
cp c
jp nz, SAVBadCheckSum
- ld hl, $af2c
+ ld hl, S_SAVEDPARTYDATA
ld de, wPartyCount ; wPartyCount
- ld bc, $194
+ ld bc, wPokedexOwned - wPartyCount
call CopyData
- ld hl, $a5a3
+ ld hl, S_SAVEDMAINDATA
ld de, wPokedexOwned ; wPokedexOwned
ld bc, wPokedexSeenEnd - wPokedexOwned
call CopyData
@@ -199,27 +199,27 @@ SaveSAVtoSRAM0: ; 7378c (1c:778c)
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, wPlayerName
- ld de, $a598
+ ld de, S_SAVEDPLAYERNAME
ld bc, $b
call CopyData
ld hl, wPokedexOwned
- ld de, $a5a3
+ ld de, S_SAVEDMAINDATA
ld bc, W_NUMINBOX - wPokedexOwned
call CopyData
ld hl, wSpriteStateData1
- ld de, $ad2c
+ ld de, S_SAVEDSPRITEDATA
ld bc, $200
call CopyData
ld hl, W_NUMINBOX
- ld de, $b0c0
+ ld de, S_SAVEDCURBOXDATA
ld bc, wBoxMonNicksEnd - W_NUMINBOX
call CopyData
ld a, [hTilesetType]
- ld [$b522], a
- ld hl, $a598
+ ld [S_SAVEDhTilesetType], a
+ ld hl, S_SAVEDPLAYERNAME
ld bc, $f8b
call SAVCheckSum
- ld [$b523], a
+ ld [S_SAVEDMAINDATACHECKSUM], a
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
@@ -233,13 +233,13 @@ SaveSAVtoSRAM1: ; 737e2 (1c:77e2)
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, W_NUMINBOX
- ld de, $b0c0
+ ld de, S_SAVEDCURBOXDATA
ld bc, wBoxMonNicksEnd - W_NUMINBOX
call CopyData
- ld hl, $a598
+ ld hl, S_SAVEDPLAYERNAME
ld bc, $f8b
call SAVCheckSum
- ld [$b523], a
+ ld [S_SAVEDMAINDATACHECKSUM], a
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
@@ -252,17 +252,17 @@ SaveSAVtoSRAM2: ; 7380f (1c:780f)
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, wPartyCount
- ld de, $af2c
+ ld de, S_SAVEDPARTYDATA
ld bc, wPokedexOwned - wPartyCount
call CopyData
ld hl, wPokedexOwned ; pokédex only
- ld de, $a5a3
+ ld de, S_SAVEDMAINDATA
ld bc, wPokedexSeenEnd - wPokedexOwned
call CopyData
- ld hl, $a598
+ ld hl, S_SAVEDPLAYERNAME
ld bc, $f8b
call SAVCheckSum
- ld [$b523], a
+ ld [S_SAVEDMAINDATACHECKSUM], a
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
@@ -292,7 +292,7 @@ SAVCheckSum: ; 73856 (1c:7856)
Func_73863: ; 73863 (1c:7863)
ld hl, $a000
- ld de, $ba4d
+ ld de, S_SAVEDBOXESCHECKSUM2 ; $ba4d
ld b, $6
.asm_7386b
push bc
@@ -327,12 +327,12 @@ Func_7387b: ; 7387b (1c:787b)
ret
PointerTable_73895: ; 73895 (1c:7895)
- dw $A000
- dw $A462
- dw $A8C4
- dw $AD26
- dw $B188
- dw $B5EA
+ dw S_SAVEDBOX1
+ dw S_SAVEDBOX2
+ dw S_SAVEDBOX3
+ dw S_SAVEDBOX4
+ dw S_SAVEDBOX5
+ dw S_SAVEDBOX6
ChangeBox:: ; 738a1 (1c:78a1)
ld hl, WhenYouChangeBoxText
@@ -402,7 +402,7 @@ Func_7390e: ; 7390e (1c:790e)
ld hl, $a000
ld bc, $1a4c
call SAVCheckSum
- ld [$ba4c], a
+ ld [S_SAVEDBOXESCHECKSUM], a
call Func_73863
xor a
ld [MBC1SRamBankingMode], a
@@ -518,22 +518,22 @@ Func_73a29: ; 73a29 (1c:7a29)
ret
Func_73a4b: ; 73a4b (1c:7a4b)
- ld hl, $a000
+ ld hl, S_SAVEDBOX1
call Func_73a7f
- ld hl, $a462
+ ld hl, S_SAVEDBOX2
call Func_73a7f
- ld hl, $a8c4
+ ld hl, S_SAVEDBOX3
call Func_73a7f
- ld hl, $ad26
+ ld hl, S_SAVEDBOX4
call Func_73a7f
- ld hl, $b188
+ ld hl, S_SAVEDBOX5
call Func_73a7f
- ld hl, $b5ea
+ ld hl, S_SAVEDBOX6
call Func_73a7f
- ld hl, $a000
- ld bc, $1a4c
+ ld hl, S_SAVEDBOX1
+ ld bc, $6 * (S_SAVEDBOX2 - S_SAVEDBOX1) ; $1a4c
call SAVCheckSum
- ld [$ba4c], a
+ ld [S_SAVEDBOXESCHECKSUM], a
call Func_73863
ret
@@ -571,17 +571,17 @@ Func_73a84: ; 73a84 (1c:7a84)
ret
Func_73ab8: ; 73ab8 (1c:7ab8)
- ld a, [$a000]
+ ld a, [S_SAVEDBOX1]
ld [hli], a
- ld a, [$a462]
+ ld a, [S_SAVEDBOX2]
ld [hli], a
- ld a, [$a8c4]
+ ld a, [S_SAVEDBOX3]
ld [hli], a
- ld a, [$ad26]
+ ld a, [S_SAVEDBOX4]
ld [hli], a
- ld a, [$b188]
+ ld a, [S_SAVEDBOX5]
ld [hli], a
- ld a, [$b5ea]
+ ld a, [S_SAVEDBOX6]
ld [hli], a
ret
@@ -594,17 +594,17 @@ SAVCheckRandomID: ;$7ad1
ld a,$01
ld [MBC1SRamBankingMode],a
ld [MBC1SRamBank],a
- ld a,[$a598]
+ ld a,[S_SAVEDPLAYERNAME]
and a
jr z,.next
- ld hl,$a598
+ ld hl,S_SAVEDPLAYERNAME
ld bc,$0f8b
call SAVCheckSum
ld c,a
- ld a,[$b523]
+ ld a,[S_SAVEDMAINDATACHECKSUM]
cp c
jr nz,.next
- ld hl,$a605
+ ld hl,S_SAVEDMAINDATA + 98 ; player ID
ld a,[hli]
ld h,[hl]
ld l,a
diff --git a/home.asm b/home.asm
index 53d08d64..f66a098a 100644
--- a/home.asm
+++ b/home.asm
@@ -87,7 +87,7 @@ INCLUDE "home/copy.asm"
SECTION "Entry", ROM0 [$100]
nop
- jp Start
+ jp Start ; 01ab
SECTION "Header", ROM0 [$104]
@@ -101,24 +101,75 @@ SECTION "Header", ROM0 [$104]
SECTION "Main", ROM0
+Func_150:: ; 0150 (0:0150)
+ ld a,[H_LOADEDROMBANK]
+ push af
+ ld a,b
+ call BankswitchCommon
+ ld a,[hli]
+ ld c,a
+ ld a,[hli]
+ ld b,a
+.loop
+ ld a,[hli]
+ ld d,a
+ ld a,$3
+.unknownloop
+ dec a
+ jr nz,.unknownloop
+
+ rept 7
+ call Func_199
+ call Func_1a5
+ endr
+
+ call Func_199
+ dec bc
+ ld a,c
+ or b
+ jr nz,.loop
+ pop af
+ call BankswitchCommon
+ ret
+
+Func_199:: ; 0199 (0:0199)
+ ld a,d
+ and $80
+ srl a
+ srl a
+ ld [rNR32],a
+ sla d
+ ret
+
+Func_1a5:: ; 01a5 (0:01a5)
+ ld a,$3
+.unknownloop2
+ dec a
+ jr nz,.unknownloop2
+ ret
+
Start::
cp GBC
jr z, .gbc
xor a
jr .ok
.gbc
- ld a, 0
+ ld a, $1
.ok
- ld [wGBC], a
+ ld [hGBC], a
jp Init
+Joypad:: ; 01b9
+ homecall_jump _Joypad
-INCLUDE "home/joypad.asm"
+ReadJoypad:: ; 01c8 (0:01c8)
+ homecall_jump ReadJoypad_
+
INCLUDE "data/map_header_pointers.asm"
INCLUDE "home/overworld.asm"
-CheckForUserInterruption:: ; 12f8 (0:12f8)
+CheckForUserInterruption:: ; 10ba (0:10ba)
; Return carry if Up+Select+B, Start or A are pressed in c frames.
; Used only in the intro and title screen.
call DelayFrame
@@ -148,7 +199,7 @@ CheckForUserInterruption:: ; 12f8 (0:12f8)
; function to load position data for destination warp when switching maps
; INPUT:
; a = ID of destination warp within destination map
-LoadDestinationWarpPosition:: ; 1313 (0:1313)
+LoadDestinationWarpPosition:: ; 10d5 (0:10d5)
ld b,a
ld a,[H_LOADEDROMBANK]
push af
@@ -170,14 +221,14 @@ LoadDestinationWarpPosition:: ; 1313 (0:1313)
ret
-DrawHPBar:: ; 1336 (0:1336)
+DrawHPBar:: ; 10f8 (0:10f8)
; Draw an HP bar d tiles long, and fill it to e pixels.
; If c is nonzero, show at least a sliver regardless.
; The right end of the bar changes with [wHPBarType].
push hl
push de
- push bc
+ ;push bc
; Left
ld a, $71 ; "HP:"
@@ -233,7 +284,7 @@ DrawHPBar:: ; 1336 (0:1336)
add e
ld [hl], a
.done
- pop bc
+ ;pop bc
pop de
pop hl
ret
@@ -252,13 +303,13 @@ DrawHPBar:: ; 1336 (0:1336)
; [wcf91] = pokemon ID
; wLoadedMon = base address of pokemon data
; W_MONHDEXNUM = base address of base stats
-LoadMonData:: ; 1372 (0:1372)
+LoadMonData:: ; 1132 (0:1132)
ld hl, LoadMonData_
- ld b, BANK(LoadMonData_)
+ ld b, BANK(LoadMonData_) ; 1:442b
jp Bankswitch
-Func_137a:: ; 137a (0:137a)
+Func_137a:: ; 113a (0:113a)
; Write c to [wMoves + b]. Unused.
ld hl, wMoves
ld e, b
@@ -268,11 +319,11 @@ Func_137a:: ; 137a (0:137a)
ld [hl], a
ret
-LoadFlippedFrontSpriteByMonIndex:: ; 1384 (0:1384)
+LoadFlippedFrontSpriteByMonIndex:: ; 1144 (0:1144)
ld a, 1
ld [W_SPRITEFLIPPED], a
-LoadFrontSpriteByMonIndex:: ; 1389 (0:1389)
+LoadFrontSpriteByMonIndex:: ; 1149 (0:1149)
push hl
ld a, [wd11e]
push af
@@ -299,27 +350,34 @@ LoadFrontSpriteByMonIndex:: ; 1389 (0:1389)
pop hl
ld a, [H_LOADEDROMBANK]
push af
- ld a, Bank(asm_3f0d0)
- ld [H_LOADEDROMBANK], a
- ld [$2000], a
+ ld a, BANK(Func_f6203)
+ call BankswitchCommon
xor a
ld [$ffe1], a
- call asm_3f0d0
+ call Func_f6203
xor a
ld [W_SPRITEFLIPPED], a
pop af
- ld [H_LOADEDROMBANK], a
- ld [$2000], a
- ret
-
+ jp BankswitchCommon
-PlayCry:: ; 13d0 (0:13d0)
+PlayCry:: ; 118b (0:118b)
; Play monster a's cry.
- call GetCryData
+ push bc
+ ld b,a
+ ld a,[wLowHealthAlarm]
+ push af
+ xor a
+ ld [wLowHealthAlarm],a
+ ld a,b
+ call Func_11a5
call PlaySound
- jp WaitForSoundToFinish
+ call WaitForSoundToFinish
+ pop af
+ ld [wLowHealthAlarm],a
+ pop bc
+ ret
-GetCryData:: ; 13d9 (0:13d9)
+GetCryData:: ; 11a5 (0:11a5)
; Load cry data for monster a.
dec a
ld c, a
@@ -349,8 +407,7 @@ GetCryData:: ; 13d9 (0:13d9)
add c
ret
-
-DisplayPartyMenu:: ; 13fc (0:13fc)
+DisplayPartyMenu:: ; 11c8 (0:11c8)
ld a,[hTilesetType]
push af
xor a
@@ -360,8 +417,8 @@ DisplayPartyMenu:: ; 13fc (0:13fc)
call PartyMenuInit
call DrawPartyMenu
jp HandlePartyMenuInput
-
-GoBackToPartyMenu:: ; 1411 (0:1411)
+
+GoBackToPartyMenu:: ; 11dd (0:11dd)
ld a,[hTilesetType]
push af
xor a
@@ -370,7 +427,7 @@ GoBackToPartyMenu:: ; 1411 (0:1411)
call RedrawPartyMenu
jp HandlePartyMenuInput
-PartyMenuInit:: ; 1420 (0:1420)
+PartyMenuInit:: ; 11ec (0:11ec)
ld a, 1 ; hardcoded bank
call BankswitchHome
call LoadHpBarAndStatusTilePatterns
@@ -409,24 +466,35 @@ PartyMenuInit:: ; 1420 (0:1420)
ld [hl], a ; old menu item ID
ret
-HandlePartyMenuInput:: ; 145a (0:145a)
+HandlePartyMenuInput:: ; 1226 (0:1226)
ld a,1
ld [wMenuWrappingEnabled],a
ld a,$40
ld [wd09b],a
call HandleMenuInputPokemonSelection
- call PlaceUnfilledArrowMenuCursor
- ld b,a
- xor a
+ push af ; save hJoy5 OR wMenuWrapping enabled, if no inputs were selected within a certain period of time
+ bit 1,a ; was B button pressed?
+ ld a,$0
ld [wd09b],a
ld a,[wCurrentMenuItem]
ld [wcc2b],a
+ jr nz,.asm_1258
+ ld a,[wCurrentMenuItem]
+ ld [wWhichPokemon],a
+ callab Func_fce18 ; 3f:4e18
+ jr nc,.asm_1258
+ call Func_154a
+ jr nz,.asm_128f
+.asm_1258
+ pop af
+ call PlaceUnfilledArrowMenuCursor
+ ld b,a
ld hl,wd730
res 6,[hl] ; turn on letter printing delay
ld a,[wMenuItemToSwap]
and a
jp nz,.swappingPokemon
- pop af
+ pop af ; double pop af?
ld [hTilesetType],a
bit 1,b
jr nz,.noPokemonChosen
@@ -445,6 +513,14 @@ HandlePartyMenuInput:: ; 145a (0:145a)
call BankswitchBack
and a
ret
+.asm_128f
+ pop af
+ ld hl,PartyMenuText_12cc
+ call PrintText
+ xor a
+ ld [wMenuItemToSwap],a
+ pop af
+ ld [hTilesetType],a
.noPokemonChosen
call BankswitchBack
scf
@@ -453,26 +529,30 @@ HandlePartyMenuInput:: ; 145a (0:145a)
bit 1,b ; was the B button pressed?
jr z,.handleSwap ; if not, handle swapping the pokemon
.cancelSwap ; if the B button was pressed
- callba ErasePartyMenuCursors
+ callba ErasePartyMenuCursors ; 4:5e98
xor a
ld [wMenuItemToSwap],a
ld [wd07d],a
call RedrawPartyMenu
- jr HandlePartyMenuInput
+ jp HandlePartyMenuInput
.handleSwap
ld a,[wCurrentMenuItem]
ld [wWhichPokemon],a
- callba SwitchPartyMon
- jr HandlePartyMenuInput
+ callba SwitchPartyMon ; 4:61c5
+ jp HandlePartyMenuInput
-DrawPartyMenu:: ; 14d4 (0:14d4)
- ld hl, DrawPartyMenu_
+PartyMenuText_12cc:: ; 12cc (0:12cc)
+ TX_FAR _PartyMenuText_12cc ; 28:411b
+ db "@"
+
+DrawPartyMenu:: ; 12d1 (0:12d1)
+ ld hl, DrawPartyMenu_ ; 4:5875
jr DrawPartyMenuCommon
-RedrawPartyMenu:: ; 14d9 (0:14d9)
- ld hl, RedrawPartyMenu_
+RedrawPartyMenu:: ; 12d6 (0:12d6)
+ ld hl, RedrawPartyMenu_ ; 4:5886
-DrawPartyMenuCommon:: ; 14dc (0:14dc)
+DrawPartyMenuCommon:: ; 12d9 (0:12d9)
ld b, BANK(RedrawPartyMenu_)
jp Bankswitch
@@ -480,7 +560,7 @@ DrawPartyMenuCommon:: ; 14dc (0:14dc)
; INPUT:
; de = address of status condition
; hl = destination address
-PrintStatusCondition:: ; 14e1 (0:14e1)
+PrintStatusCondition:: ; 12de (0:12de)
push de
dec de
dec de ; de = address of current HP
@@ -499,24 +579,14 @@ PrintStatusCondition:: ; 14e1 (0:14e1)
ld [hl],"T"
and a
ret
-PrintStatusConditionNotFainted ; 14f6
- ld a,[H_LOADEDROMBANK]
- push af
- ld a,BANK(PrintStatusAilment)
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
- call PrintStatusAilment ; print status condition
- pop bc
- ld a,b
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
- ret
+PrintStatusConditionNotFainted: ; 12f3 (0:12f3)
+ homecall_jump_sf PrintStatusAilment
; function to print pokemon level, leaving off the ":L" if the level is at least 100
; INPUT:
; hl = destination address
; [wLoadedMonLevel] = level
-PrintLevel:: ; 150b (0:150b)
+PrintLevel:: ; 1303 (0:1303)
ld a,$6e ; ":L" tile ID
ld [hli],a
ld c,2 ; number of digits
@@ -532,19 +602,19 @@ PrintLevel:: ; 150b (0:150b)
; INPUT:
; hl = destination address
; [wLoadedMonLevel] = level
-PrintLevelFull:: ; 151b (0:151b)
+PrintLevelFull:: ; 1313 (0:1313)
ld a,$6e ; ":L" tile ID
ld [hli],a
ld c,3 ; number of digits
ld a,[wLoadedMonLevel] ; level
-PrintLevelCommon:: ; 1523 (0:1523)
+PrintLevelCommon:: ; 131b (0:131b)
ld [wd11e],a
ld de,wd11e
ld b,$41 ; no leading zeroes, left-aligned, one byte
jp PrintNumber
-Func_152e:: ; 152e (0:152e)
+Func_1326:: ; 1326 (0:132)
; Unused.
ld hl,wMoves
ld c,a
@@ -556,12 +626,10 @@ Func_152e:: ; 152e (0:152e)
; copies the base stat data of a pokemon to W_MONHDEXNUM (W_MONHEADER)
; INPUT:
; [wd0b5] = pokemon ID
-GetMonHeader:: ; 1537 (0:1537)
+GetMonHeader:: ; 132f (0:132f)
ld a,[H_LOADEDROMBANK]
push af
- ld a,BANK(BaseStats)
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ switchbank BaseStats
push bc
push de
push hl
@@ -580,8 +648,8 @@ GetMonHeader:: ; 1537 (0:1537)
ld b,$77 ; size of Aerodactyl fossil sprite
cp a,FOSSIL_AERODACTYL ; Aerodactyl fossil
jr z,.specialID
- cp a,MEW
- jr z,.mew
+ ;cp a,MEW
+ ;jr z,.mew
predef IndexToPokedex ; convert pokemon ID in [wd11e] to pokedex number
ld a,[wd11e]
dec a
@@ -599,13 +667,6 @@ GetMonHeader:: ; 1537 (0:1537)
ld [hl],e ; write front sprite pointer
inc hl
ld [hl],d
- jr .done
-.mew
- ld hl,MewBaseStats
- ld de,W_MONHEADER
- ld bc,28
- ld a,BANK(MewBaseStats)
- call FarCopyData
.done
ld a,[wd0b5]
ld [W_MONHDEXNUM],a
@@ -615,17 +676,16 @@ GetMonHeader:: ; 1537 (0:1537)
pop de
pop bc
pop af
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ call BankswitchCommon
ret
; copy party pokemon's name to wcd6d
-GetPartyMonName2:: ; 15b4 (0:15b4)
+GetPartyMonName2:: ; 1394 (0:1394)
ld a,[wWhichPokemon] ; index within party
ld hl,wPartyMonNicks
; this is called more often
-GetPartyMonName:: ; 15ba (0:15ba)
+GetPartyMonName:: ; 139a (0:139a)
push hl
push bc
call SkipFixedLengthTextEntries ; add 11 to hl, a times
@@ -651,7 +711,7 @@ GetPartyMonName:: ; 15ba (0:15ba)
; bits 0-4: length of BCD number in bytes
; Note that bits 5 and 7 are modified during execution. The above reflects
; their meaning at the beginning of the functions's execution.
-PrintBCDNumber:: ; 15cd (0:15cd)
+PrintBCDNumber:: ; 13ad (0:13ad)
ld b,c ; save flags in b
res 7,c
res 6,c
@@ -689,7 +749,7 @@ PrintBCDNumber:: ; 15cd (0:15cd)
.done
ret
-PrintBCDDigit:: ; 1604 (0:1604)
+PrintBCDDigit:: ; 13e4 (0:13e4)
and $f
and a
jr z,.zeroDigit
@@ -719,7 +779,7 @@ PrintBCDDigit:: ; 1604 (0:1604)
; uncompresses the front or back sprite of the specified mon
; assumes the corresponding mon header is already loaded
; hl contains offset to sprite pointer ($b for front or $d for back)
-UncompressMonSprite:: ; 1627 (0:1627)
+UncompressMonSprite:: ; 1407 (0:1407)
ld bc,W_MONHEADER
add hl,bc
ld a,[hli]
@@ -736,10 +796,10 @@ UncompressMonSprite:: ; 1627 (0:1627)
; $99 ≤ index, bank $D
ld a,[wcf91] ; XXX name for this ram location
ld b,a
- cp MEW
- ld a,BANK(MewPicFront)
- jr z,.GotBank
- ld a,b
+ ;cp MEW
+ ;ld a,BANK(MewPicFront)
+ ;jr z,.GotBank
+ ;ld a,b
cp FOSSIL_KABUTOPS
ld a,BANK(FossilKabutopsPic)
jr z,.GotBank
@@ -761,10 +821,10 @@ UncompressMonSprite:: ; 1627 (0:1627)
jr c,.GotBank
ld a,BANK(VictreebelPicFront)
.GotBank
- jp UncompressSpriteData
+ jp UncompressSpriteData ; 23f8
; de: destination location
-LoadMonFrontSprite:: ; 1665 (0:1665)
+LoadMonFrontSprite:: ; 143e (0:143e)
push de
ld hl, W_MONHFRONTSPRITE - W_MONHEADER
call UncompressMonSprite
@@ -810,8 +870,8 @@ LoadUncompressedSpriteData:: ; 1672 (0:1672)
add a
add a ; 8*(7*((8-w)/2) + 7-h) ; combined overall offset (in bytes)
ld [H_SPRITEOFFSET], a
- xor a
- ld [$4000], a
+ ld a,$0
+ call SwitchSRAMBankAndLatchClockData
ld hl, S_SPRITEBUFFER0
call ZeroSpriteBuffer ; zero buffer 0
ld de, S_SPRITEBUFFER1
@@ -822,12 +882,13 @@ LoadUncompressedSpriteData:: ; 1672 (0:1672)
ld de, S_SPRITEBUFFER2
ld hl, S_SPRITEBUFFER1
call AlignSpriteDataCentered ; copy and align buffer 2 to 1 (containing the LSB of the 2bpp sprite)
+ call PrepareRTCDataAndDisableSRAM
pop de
- jp InterlaceMergeSpriteBuffers
+ jp InterlaceMergeSpriteBuffers ; 14c7
; copies and aligns the sprite data properly inside the sprite buffer
; sprite buffers are 7*7 tiles in size, the loaded sprite is centered within this area
-AlignSpriteDataCentered:: ; 16c2 (0:16c2)
+AlignSpriteDataCentered:: ; 149f (0:149f)
ld a, [H_SPRITEOFFSET]
ld b, $0
ld c, a
@@ -853,7 +914,7 @@ AlignSpriteDataCentered:: ; 16c2 (0:16c2)
ret
; fills the sprite buffer (pointed to in hl) with zeros
-ZeroSpriteBuffer:: ; 16df (0:16df)
+ZeroSpriteBuffer:: ; 14bc (0:14bc)
ld bc, SPRITEBUFFERSIZE
.nextByteLoop
xor a
@@ -867,8 +928,8 @@ ZeroSpriteBuffer:: ; 16df (0:16df)
; combines the (7*7 tiles, 1bpp) sprite chunks in buffer 0 and 1 into a 2bpp sprite located in buffer 1 through 2
; in the resulting sprite, the rows of the two source sprites are interlaced
; de: output address
-InterlaceMergeSpriteBuffers:: ; 16ea (0:16ea)
- xor a
+InterlaceMergeSpriteBuffers:: ; 14c7 (0:14c7)
+ ld a,$0
ld [$4000], a
push de
ld hl, S_SPRITEBUFFER2 + (SPRITEBUFFERSIZE - 1) ; destination: end of buffer 2
@@ -911,10 +972,121 @@ InterlaceMergeSpriteBuffers:: ; 16ea (0:16ea)
ld c, (2*SPRITEBUFFERSIZE)/16 ; $31, number of 16 byte chunks to be copied
ld a, [H_LOADEDROMBANK]
ld b, a
- jp CopyVideoData
+ call CopyVideoDataLCDEnabled
+ jp PrepareRTCDataAndDisableSRAM
+Func_1510:: ; 1510 (0:1510)
+ push hl
+ ld hl,wd430
+ set 7,[hl]
+ ld hl,wSpriteStateData1 + $f2 ; pikachu data?
+ ld [hl],$ff
+ pop hl
+ ret
+Func_151d:: ; 151d (0:151d)
+ push hl
+ ld hl,wd430
+ res 7,[hl]
+ pop hl
+ ret
+
+Func_1525:: ; 1525 (0:1525)
+ push hl
+ ld hl,wd430
+ res 3,[hl]
+ pop hl
+ ret
+
+Func_152d:: ; 152d (0:152d)
+ push hl
+ ld hl,wd430
+ set 3,[hl]
+ ld hl,wSpriteStateData1 + $f2 ; pikachu data?
+ ld [hl],$ff
+ pop hl
+ ret
+
+Func_153a:: ; 153a (0:153a)
+ push hl
+ ld hl,wd430
+ set 1,[hl]
+ pop hl
+ ret
+
+Func_1542:: ; 1542 (0:1542)
+ push hl
+ ld hl,wd430
+ res 1,[hl]
+ pop hl
+ ret
+
+Func_154a:: ; 154a (0:154a)
+ push hl
+ ld hl,wd430
+ bit 1,[hl]
+ pop hl
+ ret
+
+Func_1552:: ; 1552 (0:1552)
+ ld a,[hl]
+ dec a
+ swap a
+ ld [$ff93],a
+ homecall Func_fc6d5 ; 3f:46d5
+ ret
+
+Func_1568:: ; 1568 (0:1568)
+ ld b,$0
+ ld c,a
+.asm_156b
+ inc b
+ ld a,[hli]
+ cp $ff
+ jr z,.asm_1578
+ cp c
+ jr nz,.asm_156b
+ dec b
+ dec hl
+ scf
+ ret
+.asm_1578
+ dec b
+ dec hl
+ and a
+ ret
+
+Func_157c:: ; 157c (0:157c)
+ push hl
+ push bc
+ ld a,[H_LOADEDROMBANK]
+ push af
+ ld a,[wd44a]
+ call BankswitchCommon
+ ld hl,wd44b
+ ld c,[hl]
+ inc hl
+ ld b,[hl]
+ ld a,[bc]
+ inc bc
+ ld [hl],b
+ dec hl
+ ld [hl],c
+ ld c,a
+ pop af
+ call BankswitchCommon
+ ld a,c
+ pop bc
+ pop hl
+ ret
+
INCLUDE "data/collision.asm"
+
+IsTilePassable:: ; 15c3 (0:15c3)
+; sets carry if tile is passable, resets carry otherwise
+ homecall_sf _IsTilePassable ; 1:4aaa
+ ret
+
INCLUDE "home/copy2.asm"
INCLUDE "home/text.asm"
INCLUDE "home/vcopy.asm"
@@ -2935,7 +3107,7 @@ GetTrainerName:: ; 359e (0:359e)
jp Bankswitch
-HasEnoughMoney::
+HasEnoughMoney:: ; 35c3 (0:35c3)
; Check if the player has at least as much
; money as the 3-byte BCD value at $ff9f.
ld de, wPlayerMoney
@@ -2952,25 +3124,28 @@ HasEnoughCoins::
jp StringCmp
-BankswitchHome:: ; 35bc (0:35bc)
+BankswitchHome:: ; 35d9 (0:35d9)
; switches to bank # in a
; Only use this when in the home bank!
ld [wcf09],a
ld a,[H_LOADEDROMBANK]
ld [wcf08],a
ld a,[wcf09]
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ call BankswitchCommon
ret
-BankswitchBack:: ; 35cd (0:35cd)
+BankswitchBack:: ; 35e8 (0:35e8)
; returns from BankswitchHome
ld a,[wcf08]
+ call BankswitchCommon
+ ret
+
+BankswitchCommon:: ; 3e7e (0:3e7e)
ld [H_LOADEDROMBANK],a
ld [$2000],a
ret
-Bankswitch:: ; 35d6 (0:35d6)
+Bankswitch:: ; 3e84 (0:3e84)
; self-contained bankswitch, use this when not in the home bank
; switches to the bank in b
ld a,[H_LOADEDROMBANK]
@@ -2978,16 +3153,33 @@ Bankswitch:: ; 35d6 (0:35d6)
ld a,b
ld [H_LOADEDROMBANK],a
ld [$2000],a
- ld bc,.Return
- push bc
- jp [hl]
-.Return
+ call .jumptoaddress
pop bc
ld a,b
ld [H_LOADEDROMBANK],a
ld [$2000],a
ret
+.jumptoaddress
+ jp [hl]
+SwitchSRAMBankAndLatchClockData:: ; 3e99 (0:3e99)
+ push af
+ ld a,$1
+ ld [$6000],a
+ ld a,SRAM_ENABLE
+ ld [$0],a
+ pop af
+ ld [$4000],a
+ ret
+
+PrepareRTCDataAndDisableSRAM:: ; 3eac (0:3eac)
+ push af
+ ld a,$0
+ ld [$6000],a
+ ld [$0],a
+ pop af
+ ret
+
; displays yes/no choice
; yes -> set carry
YesNoChoice:: ; 35ec (0:35ec)
@@ -3144,21 +3336,6 @@ LoadHpBarAndStatusTilePatterns::
jp CopyVideoData ; if LCD is on, transfer during V-blank
-FillMemory::
-; Fill bc bytes at hl with a.
- push de
- ld d, a
-.loop
- ld a, d
- ld [hli], a
- dec bc
- ld a, b
- or c
- jr nz, .loop
- pop de
- ret
-
-
UncompressSpriteFromDE:: ; 36eb (0:36eb)
; Decompress pic at a:de.
ld hl, W_SPRITEINPUTPTR
@@ -3960,6 +4137,8 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2)
ld [wcc4b],a
ld a,[hJoy5]
ld b,a
+ bit 0,a ; pressed A key?
+ jr z,.checkOtherKeys
bit 6,a ; pressed Up key?
jr z,.checkIfDownPressed
.upPressed
@@ -4026,7 +4205,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2)
jr z,.checkOtherKeys
jr .checkIfAButtonOrBButtonPressed
-PlaceMenuCursor:: ; 3b7c (0:3b7c)
+PlaceMenuCursor:: ; 3b6d (0:3b6d)
ld a,[wTopMenuItemY]
and a ; is the y coordinate 0?
jr z,.adjustForXCoord
@@ -4045,15 +4224,13 @@ PlaceMenuCursor:: ; 3b7c (0:3b7c)
ld a,[wLastMenuItem]
and a ; was the previous menu id 0?
jr z,.checkForArrow1
+ ld bc,40
push af
- ld a,[hFlags_0xFFF6]
+ ld a,[hFlags_0xFFFA]
bit 1,a ; is the menu double spaced?
jr z,.doubleSpaced1
ld bc,20
- jr .getOldMenuItemScreenPosition
.doubleSpaced1
- ld bc,40
-.getOldMenuItemScreenPosition
pop af
.oldMenuItemLoop
add hl,bc
@@ -4071,15 +4248,13 @@ PlaceMenuCursor:: ; 3b7c (0:3b7c)
ld a,[wCurrentMenuItem]
and a
jr z,.checkForArrow2
+ ld bc,40
push af
- ld a,[hFlags_0xFFF6]
+ ld a,[hFlags_0xFFFA]
bit 1,a ; is the menu double spaced?
jr z,.doubleSpaced2
ld bc,20
- jr .getCurrentMenuItemScreenPosition
.doubleSpaced2
- ld bc,40
-.getCurrentMenuItemScreenPosition
pop af
.currentMenuItemLoop
add hl,bc
@@ -4105,7 +4280,7 @@ PlaceMenuCursor:: ; 3b7c (0:3b7c)
; manipulated. In the case of submenus, this is used to show the location of
; the menu cursor in the parent menu. In the case of swapping items in list,
; this is used to mark the item that was first chosen to be swapped.
-PlaceUnfilledArrowMenuCursor:: ; 3bec (0:3bec)
+PlaceUnfilledArrowMenuCursor:: ; 3bd9 (0:3bd9)
ld b,a
ld a,[wMenuCursorLocation]
ld l,a
@@ -4116,7 +4291,7 @@ PlaceUnfilledArrowMenuCursor:: ; 3bec (0:3bec)
ret
; Replaces the menu cursor with a blank space.
-EraseMenuCursor:: ; 3bf9 (0:3bf9)
+EraseMenuCursor:: ; 3be6 (0:3be6)
ld a,[wMenuCursorLocation]
ld l,a
ld a,[wMenuCursorLocation + 1]
@@ -4476,6 +4651,10 @@ IsInRestOfArray::
scf
ret
+InitMapSprites:: ; 3dba (0:3dba)
+ ld hl, _InitMapSprites ; 1401b (5:401b)
+ ld b,BANK(_InitMapSprites)
+ jp Bankswitch
RestoreScreenTilesAndReloadTilePatterns:: ; 3dbe (0:3dbe)
call ClearSprites
diff --git a/home/audio.asm b/home/audio.asm
index 9210924c..abdfec54 100644
--- a/home/audio.asm
+++ b/home/audio.asm
@@ -111,6 +111,9 @@ PlayMusic:: ; 23a1 (0:23a1)
ld [wc0f0], a
ld a, b
+StopAllMusic:: ; 2233 (0:2233)
+ ld a,$FF
+ ld [wc0ee],a
; plays music specified by a. If value is $ff, music is stopped
PlaySound:: ; 23b1 (0:23b1)
push hl
diff --git a/home/copy.asm b/home/copy.asm
index be9c8c0c..074c1556 100644
--- a/home/copy.asm
+++ b/home/copy.asm
@@ -1,24 +1,74 @@
-FarCopyData::
+FarCopyData:: ; 009d (0:009d)
; Copy bc bytes from a:hl to de.
- ld [wBuffer], a
+ ld [wd122+1], a
ld a, [H_LOADEDROMBANK]
push af
- ld a, [wBuffer]
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ ld a, [wd122+1]
+ call BankswitchCommon
call CopyData
pop af
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ call BankswitchCommon
ret
-CopyData::
+CopyData:: ; 00b1 (0:00b1)
; Copy bc bytes from hl to de.
+ ld a,b
+ and a
+ jr z, .copybytes
+ ld a,c
+ and a ; is lower byte 0
+ jr z, .loop
+ inc b ; if not, increment b as there are <$100 bytes to copy
+.loop
+ call .copybytes
+ dec b
+ jr nz,.loop
+ ret
+
+.copybytes ; 00c1
ld a, [hli]
ld [de], a
inc de
- dec bc
- ld a, c
- or b
- jr nz, CopyData
+ dec c
+ jr nz, .copybytes
ret
+
+CopyVideoData:: ; 00c8 (0:00c8)
+ ld a, [rLCDC]
+ bit 7,a ; LCD enabled?
+ jp nz, CopyVideoDataLCDEnabled ; if yes, then copy video data
+ push hl
+ ld h,d
+ ld l,e
+ pop de
+ ld a,b ; save bank
+ push af
+ swap c
+ ld a,$f
+ and c
+ ld b,a
+ ld a,$f0
+ and c
+ ld c,a
+ pop af
+ jp FarCopyData
+
+CopyVideoDataDouble:: ; 00e3 (0:00e3)
+ ld a, [rLCDC]
+ bit 7,a ; LCD enabled?
+ jp nz, CopyVideoDataDoubleLCDEnabled ; if yes, then copy video data
+ push de
+ ld d,h
+ ld e,l
+ ld a,b
+ push af ; save bank to switch to
+ ld h,$0
+ ld l,c
+ add hl,hl ; get raw length of bytes to copy
+ add hl,hl
+ add hl,hl
+ ld b,h
+ ld c,l
+ pop af
+ pop hl
+ jp FarCopyDataDouble
diff --git a/home/copy2.asm b/home/copy2.asm
index 7b407cdc..318ed882 100644
--- a/home/copy2.asm
+++ b/home/copy2.asm
@@ -1,65 +1,40 @@
-FarCopyData2::
-; Identical to FarCopyData, but uses $ff8b
-; as temp space instead of wBuffer.
- ld [$ff8b],a
- ld a,[H_LOADEDROMBANK]
- push af
- ld a,[$ff8b]
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
- call CopyData
- pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
- ret
-
-FarCopyData3::
-; Copy bc bytes from a:de to hl.
- ld [$ff8b],a
- ld a,[H_LOADEDROMBANK]
- push af
- ld a,[$ff8b]
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
- push hl
- push de
- push de
- ld d,h
- ld e,l
- pop hl
- call CopyData
- pop de
- pop hl
- pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
- ret
-
-FarCopyDataDouble::
+FarCopyDataDouble:: ; 15d4 (0:15d4)
; Expand bc bytes of 1bpp image data
-; from a:hl to 2bpp data at de.
- ld [$ff8b],a
+; from a:de to 2bpp data at hl.
+ ld [wd122+1],a
ld a,[H_LOADEDROMBANK]
push af
- ld a,[$ff8b]
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
-.loop
- ld a,[hli]
- ld [de],a
+ ld a,[wd122+1]
+ call BankswitchCommon
+ ld a,h ; swap hl and de
+ ld h,d
+ ld d,a
+ ld a,l
+ ld l,e
+ ld e,a
+ ld a,b
+ and a
+ jr z,.8bitcopyamount
+ ld a,c
+ and a ; multiple of $100
+ jr z, .expandloop ; if so, do not increment b because the first instance of dec c results in underflow
+.8bitcopyamount
+ inc b
+.expandloop
+ ld a,[de]
inc de
- ld [de],a
+ ld [hli],a
+ ld [hli],a
inc de
- dec bc
- ld a,c
- or b
- jr nz,.loop
+ dec c
+ jr nz, .expandloop
+ dec b
+ jr nz, .expandloop
pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ call BankswitchCommon
ret
-CopyVideoData::
+CopyVideoDataLCDEnabled:: ;
; Wait for the next VBlank, then copy c 2bpp
; tiles from b:de to hl, 8 tiles at a time.
; This takes c/8 frames.
@@ -70,11 +45,10 @@ CopyVideoData::
ld [H_AUTOBGTRANSFERENABLED], a
ld a, [H_LOADEDROMBANK]
- ld [$ff8b], a
+ push af
ld a, b
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ call BankswitchCommon
ld a, e
ld [H_VBCOPYSRC], a
@@ -94,9 +68,8 @@ CopyVideoData::
.done
ld [H_VBCOPYSIZE], a
call DelayFrame
- ld a, [$ff8b]
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ pop af
+ call CommonBankswitch
pop af
ld [H_AUTOBGTRANSFERENABLED], a
ret
@@ -110,7 +83,7 @@ CopyVideoData::
ld c, a
jr .loop
-CopyVideoDataDouble::
+CopyVideoDataDoubleLCDEnabled::
; Wait for the next VBlank, then copy c 1bpp
; tiles from b:de to hl, 8 tiles at a time.
; This takes c/8 frames.
@@ -119,11 +92,10 @@ CopyVideoDataDouble::
xor a ; disable auto-transfer while copying
ld [H_AUTOBGTRANSFERENABLED], a
ld a, [H_LOADEDROMBANK]
- ld [$ff8b], a
+ push af
ld a, b
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ call BankswitchCommon
ld a, e
ld [H_VBCOPYDOUBLESRC], a
@@ -143,9 +115,8 @@ CopyVideoDataDouble::
.done
ld [H_VBCOPYDOUBLESIZE], a
call DelayFrame
- ld a, [$ff8b]
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ pop af
+ call BankswitchCommon
pop af
ld [H_AUTOBGTRANSFERENABLED], a
ret
@@ -159,7 +130,41 @@ CopyVideoDataDouble::
ld c, a
jr .loop
-ClearScreenArea::
+FillMemory:: ; 166e (0:166e)
+ push af
+ ld a,b
+ and a
+ jr z, .8bitcopyamount
+ ld a,c
+ and a
+ jr z, .mulitpleof$100
+.8bitcopyamount
+ inc b
+.multipleof$100
+ pop af
+.loop
+ ld [hli],a
+ dec c
+ jr nz, .loop
+ dec b
+ jr nz, .loop
+ ret
+
+Func_1681:: ; 1681 (0:1681)
+ push bc
+ ld b,a
+ ld a, [H_LOADEDROMBANK]
+ push af
+ ld a,b
+ call BankswitchCommon
+ ld b,[hl]
+ pop af
+ call BankswitchCommon
+ ld a,b
+ pop bc
+ ret
+
+ClearScreenArea:: ; 1692 (0:1692)
; Clear tilemap area cxb at hl.
ld a, $7f ; blank tile
ld de, 20 ; screen width
@@ -177,7 +182,7 @@ ClearScreenArea::
jr nz, .y
ret
-CopyScreenTileBufferToVRAM::
+CopyScreenTileBufferToVRAM:: ; 16a4
; Copy wTileMap to the BG Map starting at b * $100.
; This is done in thirds of 6 rows, so it takes 3 frames.
diff --git a/home/init.asm b/home/init.asm
index cc89ad34..202bd110 100644
--- a/home/init.asm
+++ b/home/init.asm
@@ -133,5 +133,4 @@ StopAllSounds::
ld [wMusicHeaderPointer], a
ld [wc0ee], a
ld [wcfca], a
- dec a
- jp PlaySound
+ jp StopAllMusic
diff --git a/home/joypad.asm b/home/joypad.asm
deleted file mode 100644
index 2002bb29..00000000
--- a/home/joypad.asm
+++ /dev/null
@@ -1,39 +0,0 @@
-ReadJoypad::
-; Poll joypad input.
-; Unlike the hardware register, button
-; presses are indicated by a set bit.
-
- ld a, 1 << 5 ; select direction keys
- ld c, 0
-
- ld [rJOYP], a
- rept 6
- ld a, [rJOYP]
- endr
- cpl
- and %1111
- swap a
- ld b, a
-
- ld a, 1 << 4 ; select button keys
- ld [rJOYP], a
- rept 10
- ld a, [rJOYP]
- endr
- cpl
- and %1111
- or b
-
- ld [hJoyInput], a
-
- ld a, 1 << 4 + 1 << 5 ; deselect keys
- ld [rJOYP], a
- ret
-
-Joypad::
-; Update the joypad state variables:
-; [hJoyReleased] keys released since last time
-; [hJoyPressed] keys pressed since last time
-; [hJoyHeld] currently pressed keys
- homecall _Joypad
- ret
diff --git a/home/overworld.asm b/home/overworld.asm
index c5c180c7..b3008903 100644
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -1,11 +1,4 @@
-HandleMidJump::
-; Handle the player jumping down
-; a ledge in the overworld.
- ld b, BANK(_HandleMidJump)
- ld hl, _HandleMidJump
- jp Bankswitch
-
-EnterMap::
+EnterMap:: ; 01d7 (0:01d7)
; Load a new map.
ld a, $ff
ld [wJoyIgnore], a
@@ -26,11 +19,18 @@ EnterMap::
ld a, [hl]
and 1 << 4 | 1 << 3 ; fly warp or dungeon warp
jr z, .didNotEnterUsingFlyWarpOrDungeonWarp
- res 3, [hl]
callba EnterMapAnim
call UpdateSprites
+ ld hl, wd732
+ res 3, [hl]
+ ld hl, wd72e
+ res 4, [hl]
+ call Func_342a
.didNotEnterUsingFlyWarpOrDungeonWarp
callba CheckForceBikeOrSurf ; handle currents in SF islands and forced bike riding in cycling road
+ ld hl, wd732
+ bit 4, [hl]
+ res 4, [hl]
ld hl, wd72d
res 5, [hl]
call UpdateSprites
@@ -40,14 +40,12 @@ EnterMap::
xor a
ld [wJoyIgnore], a
-OverworldLoop::
+OverworldLoop:: ; 0242 (0:0242)
call DelayFrame
-OverworldLoopLessDelay::
+OverworldLoopLessDelay:: ; 0245 (0:0245)
call DelayFrame
+ call Func_342a
call LoadGBPal
- ld a,[wd736]
- bit 6,a ; jumping down a ledge?
- call nz, HandleMidJump
ld a,[wWalkCounter]
and a
jp nz,.moveAhead ; if the player sprite has not yet completed the walking animation
@@ -93,7 +91,10 @@ OverworldLoopLessDelay::
ld a,[$ffeb]
and a
jp z,OverworldLoop ; jump if a hidden object or bookshelf was found, but not if a card key door was found
+ xor a
+ ld [wd436],a ; new yellow address
call IsSpriteOrSignInFrontOfPlayer
+ call Func_0ffe
ld a,[hSpriteIndexOrTextID]
and a
jp z,OverworldLoop
@@ -111,38 +112,39 @@ OverworldLoopLessDelay::
ld a,[wcc47]
and a
jr z,.checkForOpponent
- dec a
- ld a,$00
+ xor a
ld [wcc47],a
- jr z,.changeMap
- predef LoadSAV
- ld a,[W_CURMAP]
- ld [wDestinationMap],a
- call SpecialWarpIn
- ld a,[W_CURMAP]
- call SwitchToMapRomBank ; switch to the ROM bank of the current map
- ld hl,W_CURMAPTILESET
- set 7,[hl]
-.changeMap
jp EnterMap
+; predef LoadSAV
+; ld a,[W_CURMAP]
+; ld [wDestinationMap],a
+; call SpecialWarpIn
+; ld a,[W_CURMAP]
+; call SwitchToMapRomBank ; switch to the ROM bank of the current map
+; ld hl,W_CURMAPTILESET
+; set 7,[hl]
.checkForOpponent
ld a,[W_CUROPPONENT]
and a
jp nz,.newBattle
jp OverworldLoop
.noDirectionButtonsPressed
+ call UpdateSprites ; 231c
ld hl,wFlags_0xcd60
res 2,[hl]
- call UpdateSprites
+ xor a
+ ld [wd435], a
+ ld a, $1
ld a,$01
ld [wcc4b],a
ld a,[wd528] ; the direction that was pressed last time
and a
- jp z,OverworldLoop
+ jr z, .overworldloop
; if a direction was pressed last time
ld [wd529],a ; save the last direction
xor a
ld [wd528],a ; zero the direction
+.overworldloop
jp OverworldLoop
.checkIfDownButtonIsPressed
ld a,[hJoyHeld] ; current joypad state
@@ -184,39 +186,13 @@ OverworldLoopLessDelay::
ld a,[wd529] ; 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
- 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
- jr nz,.notDownToUp
- ld a,$02
- ld [wd528],a
- jr .oddLoop
-.notDownToUp
- cp a,$84 ; change dir from up to down
- jr nz,.notUpToDown
- ld a,$01
- ld [wd528],a
- jr .oddLoop
-.notUpToDown
- cp a,$12 ; change dir from right to left
- jr nz,.notRightToLeft
- ld a,$04
- ld [wd528],a
- jr .oddLoop
-.notRightToLeft
- cp a,$21 ; change dir from left to right
- jr nz,.oddLoop
- ld a,$08
- ld [wd528],a
-.oddLoop
+ ld a,$8
+ ld [wd434],a
+; unlike in red/blue, yellow does not have the 180 degrees odd code
ld hl,wFlags_0xcd60
set 2,[hl]
- ld hl,wcc4b
- dec [hl]
- jr nz,.oddLoop
+ xor a
+ ld [wcc4b],a
ld a,[wd52a]
ld [wd528],a
call NewBattle
@@ -250,45 +226,23 @@ OverworldLoopLessDelay::
.noCollision
ld a,$08
ld [wWalkCounter],a
+ callab Func_fcc08
jr .moveAhead2
.moveAhead
- ld a,[wd736]
- bit 7,a
- jr z,.noSpinning
- callba LoadSpinnerArrowTiles ; spin while moving
-.noSpinning
+ call IsSpinning
call UpdateSprites ; move sprites
.moveAhead2
ld hl,wFlags_0xcd60
res 2,[hl]
- ld a,[wWalkBikeSurfState]
- dec a ; riding a bike?
- jr nz,.normalPlayerSpriteAdvancement
- ld a,[wd736]
- bit 6,a ; jumping a ledge?
- jr nz,.normalPlayerSpriteAdvancement
- call BikeSpeedup ; if riding a bike and not jumping a ledge
-.normalPlayerSpriteAdvancement
+ xor a
+ ld [wd435],a
+ call DoBikeSpeedup
call AdvancePlayerSprite
ld a,[wWalkCounter]
and a
jp nz,CheckMapConnections ; it seems like this check will never succeed (the other place where CheckMapConnections is run works)
; walking animation finished
- ld a,[wd730]
- bit 7,a
- jr nz,.doneStepCounting ; if button presses are being simulated, don't count steps
-; step counting
- ld hl,wStepCounter
- dec [hl]
- ld a,[wd72c]
- bit 0,a
- jr z,.doneStepCounting
- ld hl,wNumberOfNoRandomBattleStepsLeft
- dec [hl]
- jr nz,.doneStepCounting
- ld hl,wd72c
- res 0,[hl] ; indicate that the player has stepped thrice since the last battle
-.doneStepCounting
+ call StepCountCheck
ld a,[wd790]
bit 7,a ; in the safari zone?
jr z,.notSafariZone
@@ -338,15 +292,33 @@ OverworldLoopLessDelay::
ld c,$0a
call DelayFrames
jp EnterMap
-.allPokemonFainted
- ld a,$ff
- ld [W_ISINBATTLE],a
- call RunMapScript
- jp HandleBlackOut
+;.allPokemonFainted
+; ld a,$ff
+; ld [W_ISINBATTLE],a
+; call RunMapScript
+; jp HandleBlackOut
+
+StepCountCheck:: ; 0457 (0:0457)
+ ld a,[wd730]
+ bit 7,a
+ jr nz,.doneStepCounting ; if button presses are being simulated, don't count steps
+; step counting
+ ld hl,wStepCounter
+ dec [hl]
+ ld a,[wd72c]
+ bit 0,a
+ jr z,.doneStepCounting
+ ld hl,wNumberOfNoRandomBattleStepsLeft
+ dec [hl]
+ jr nz,.doneStepCounting
+ ld hl,wd72c
+ res 0,[hl] ; indicate that the player has stepped thrice since the last battle
+.doneStepCounting
+ ret
; 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:: ; 0480 (0:0480)
ld a,[wd72d]
bit 4,a
jr nz,.noBattle
@@ -356,40 +328,46 @@ NewBattle:: ; 0683 (0:0683)
bit 4,a
jr nz,.noBattle
ld b, BANK(InitBattle)
- ld hl, InitBattle
+ ld hl, InitBattle ; 3d:5ff2
jp Bankswitch
.noBattle
and a
ret
-; function to make bikes twice as fast as walking
-BikeSpeedup:: ; 06a0 (0:06a0)
+DoBikeSpeedup:: ; 049d (0:049d)
+ ld a,[wWalkBikeSurfState]
+ dec a ; riding a bike?
+ ret nz
+ ld a,[wd736]
+ bit 6,a
+ ret nz
ld a,[wNPCMovementScriptPointerTableNum]
and a
ret nz
ld a,[W_CURMAP]
- cp a,ROUTE_17 ; Cycling Road
+ cp ROUTE_17 ; cycling road
jr nz,.goFaster
ld a,[hJoyHeld]
and a,D_UP | D_LEFT | D_RIGHT
ret nz
.goFaster
- jp AdvancePlayerSprite
+ call AdvancePlayerSprite
+ ret
; check if the player has stepped onto a warp after having not collided
-CheckWarpsNoCollision:: ; 06b4 (0:06b4)
+CheckWarpsNoCollision:: ; 04bd (0:04bd)
ld a,[wNumberOfWarps]
and a
jp z,CheckMapConnections
- ld a,[wNumberOfWarps]
ld b,0
+ ld a,[wNumberOfWarps]
ld c,a
ld a,[W_YCOORD]
ld d,a
ld a,[W_XCOORD]
ld e,a
ld hl,wWarpEntries
-CheckWarpsNoCollisionLoop:: ; 06cc (0:06cc)
+CheckWarpsNoCollisionLoop:: ; 04d5 (0:04d5)
ld a,[hli] ; check if the warp's Y position matches
cp d
jr nz,CheckWarpsNoCollisionRetry1
@@ -424,9 +402,20 @@ CheckWarpsNoCollisionLoop:: ; 06cc (0:06cc)
and a,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
-
+
+CheckWarpsNoCollisionRetry1:: ; 050f (0:050f)
+ inc hl
+CheckWarpsNoCollisionRetry2:: ; 0510 (0:0510)
+ inc hl
+ inc hl
+ContinueCheckWarpsNoCollisionLoop:: ; 0512 (0:0512)
+ inc b ; increment warp number
+ dec c ; decrement number of warps
+ jp nz,CheckWarpsNoCollisionLoop
+ jp CheckMapConnections
+
; check if the player has stepped onto a warp after having collided
-CheckWarpsCollision:: ; 0706 (0:0706)
+CheckWarpsCollision:: ; 051a (0:051a)
ld a,[wNumberOfWarps]
ld c,a
ld hl,wWarpEntries
@@ -455,20 +444,13 @@ CheckWarpsCollision:: ; 0706 (0:0706)
jr nz,.loop
jp OverworldLoop
-CheckWarpsNoCollisionRetry1:: ; 072f (0:072f)
- inc hl
-CheckWarpsNoCollisionRetry2:: ; 0730 (0:0730)
- inc hl
- inc hl
- jp ContinueCheckWarpsNoCollisionLoop
-
-WarpFound1:: ; 0735 (0:0735)
+WarpFound1:: ; 0543 (0:0543)
ld a,[hli]
ld [wDestinationWarpID],a
ld a,[hli]
ld [$ff8b],a ; save target map
-WarpFound2:: ; 073c (0:073c)
+WarpFound2:: ; 054a (0:054a)
ld a,[wNumberOfWarps]
sub c
ld [wd73b],a ; save ID of used warp
@@ -489,6 +471,7 @@ WarpFound2:: ; 073c (0:073c)
ld [wMapPalOffset],a
call GBFadeOutToBlack
.notRockTunnel
+ callab Func_fc5fa ; 3f:45fa
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
@@ -503,9 +486,9 @@ WarpFound2:: ; 073c (0:073c)
dec a ; is the player on a warp pad?
jr nz,.notWarpPad
; if the player is on a warp pad
+ call LeaveMapAnim
ld hl,wd732
set 3,[hl]
- call LeaveMapAnim
jr .skipMapChangeSound
.notWarpPad
call PlayMapChangeSound
@@ -513,8 +496,10 @@ WarpFound2:: ; 073c (0:073c)
ld hl,wd736
res 0,[hl]
res 1,[hl]
+ callab Func_fc65b ; 3f:465b
jr .done
.goBackOutside
+ callab Func_fc69a ; 3f:469a
ld a,[wLastMap]
ld [W_CURMAP],a
call PlayMapChangeSound
@@ -526,13 +511,8 @@ WarpFound2:: ; 073c (0:073c)
call IgnoreInputForHalfSecond
jp EnterMap
-ContinueCheckWarpsNoCollisionLoop:: ; 07b5 (0:07b5)
- 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:: ; 05db (0:05db)
.checkWestMap
ld a,[W_XCOORD]
cp a,$ff
@@ -656,21 +636,33 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld [wCurrentTileBlockMapViewPointer],a ; pointer to upper left corner of current tile block map section
ld a,h
ld [wCurrentTileBlockMapViewPointer + 1],a
-.loadNewMap ; load the connected map that was entered
- call LoadMapHeader
+.loadNewMap ; 06ce (0:06ce)
+; load the connected map that was entered
+ ld hl,[wd430]
+ set 4,[hl]
+ ld a,$2
+ ld [wd431],a
+ call LoadMapHeader ; 0dab (0:0dab)
call Func_2312 ; music
ld b,$09
call GoPAL_SET
; Since the sprite set shouldn't change, this will just update VRAM slots at
; $C2XE without loading any tile patterns.
- callba InitMapSprites
+ call InitMapSprites
call LoadTileBlockMap
jp OverworldLoopLessDelay
.didNotEnterConnectedMap
jp OverworldLoop
; function to play a sound when changing maps
-PlayMapChangeSound:: ; 08c9 (0:08c9)
+PlayMapChangeSound:: ; 06ef (0:06ef)
+ ld a,[W_CURMAPTILESET]
+ cp FACILITY
+ jr z,.didNotGoThroughDoor
+ cp CEMETERY
+ jr z,.didNotGoThroughDoor
+ cp UNDERGROUND
+ jr nz,.didNotGoThroughDoor
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
jr nz,.didNotGoThroughDoor
@@ -685,7 +677,7 @@ PlayMapChangeSound:: ; 08c9 (0:08c9)
ret nz
jp GBFadeOutToBlack
-CheckIfInOutsideMap:: ; 08e1 (0:08e1)
+CheckIfInOutsideMap:: ; 0712 (0:0712)
; If the player is in an outside map (a town or route), set the z flag
ld a, [W_CURMAPTILESET]
and a ; most towns/routes have tileset 0 (OVERWORLD)
@@ -699,7 +691,7 @@ 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)
+ExtraWarpCheck:: ; 071a (0:071a)
ld a, [W_CURMAP]
cp SS_ANNE_3
jr z, .useFunction1
@@ -729,14 +721,14 @@ ExtraWarpCheck:: ; 08e9 (0:08e9)
ld b, BANK(IsWarpTileInFrontOfPlayer)
jp Bankswitch
-MapEntryAfterBattle:: ; 091f (0:091f)
+MapEntryAfterBattle:: ; 0750 (0:0750)
callba IsPlayerStandingOnWarp ; for enabling warp testing after collisions
ld a,[wMapPalOffset]
and a
jp z,GBFadeInFromWhite
jp LoadGBPal
-HandleBlackOut::
+HandleBlackOut:: ; 0762 (0:0762)
; For when all the player's pokemon faint.
; Does not print the "blacked out" message.
@@ -745,26 +737,22 @@ HandleBlackOut::
call StopMusic
ld hl, wd72e
res 5, [hl]
- ld a, Bank(ResetStatusAndHalveMoneyOnBlackout) ; also Bank(SpecialWarpIn) and Bank(SpecialEnterMap)
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
- call ResetStatusAndHalveMoneyOnBlackout
+ switchbank SpecialWarpIn ; also Bank(SpecialEnterMap)
+ callab ResetStatusAndHalveMoneyOnBlackout ; 3c:4274
call SpecialWarpIn
call Func_2312
jp SpecialEnterMap
-StopMusic::
+StopMusic:: ; 0788 (0:0788)
ld [wMusicHeaderPointer], a
- ld a, $ff
- ld [wc0ee], a
- call PlaySound
+ call StopAllMusic
.wait
ld a, [wMusicHeaderPointer]
and a
jr nz, .wait
jp StopAllSounds
-HandleFlyWarpOrDungeonWarp::
+HandleFlyWarpOrDungeonWarp:: ; 0794 (0:0794)
call UpdateSprites
call Delay3
xor a
@@ -776,18 +764,28 @@ HandleFlyWarpOrDungeonWarp::
set 2, [hl] ; fly warp or dungeon warp
res 5, [hl] ; forced to ride bike
call LeaveMapAnim
- ld a, Bank(SpecialWarpIn)
- ld [H_LOADEDROMBANK], a
- ld [$2000], a
- call SpecialWarpIn
+ call LoadPlayerSpriteGraphics
+ callsb SpecialWarpIn
jp SpecialEnterMap
-LeaveMapAnim::
+LeaveMapAnim:: ; 07bc (0:07bc)
ld b, BANK(_LeaveMapAnim)
ld hl, _LeaveMapAnim
jp Bankswitch
-LoadPlayerSpriteGraphics::
+Func_07c4:: ; 07c4 (0:07c4)
+ ld a, [wWalkBikeSurfState]
+ and a
+ ret z
+ xor a
+ ld [wWalkBikeSurfState],a
+ ld hl,wd732
+ bit 4,[hl]
+ ret z
+ call PlayDefaultMusic
+ ret
+
+LoadPlayerSpriteGraphics:: ; 07d7 (0:07d7)
; Load sprite graphics based on whether the player is standing, biking, or surfing.
; 0: standing
@@ -825,7 +823,7 @@ LoadPlayerSpriteGraphics::
jp z, LoadSurfingPlayerSpriteGraphics
jp LoadWalkingPlayerSpriteGraphics
-IsBikeRidingAllowed::
+IsBikeRidingAllowed:: ; 0805 (0:0805)
; The bike can be used on Route 23 and Indigo Plateau,
; or maps with tilesets in BikeRidingTilesets.
; Return carry if biking is allowed.
@@ -855,7 +853,7 @@ IsBikeRidingAllowed::
INCLUDE "data/bike_riding_tilesets.asm"
; load the tile pattern data of the current tileset into VRAM
-LoadTilesetTilePatternData:: ; 09e8 (0:09e8)
+LoadTilesetTilePatternData:: ; 0828 (0:0828)
ld a,[W_TILESETGFXPTR]
ld l,a
ld a,[W_TILESETGFXPTR + 1]
@@ -867,19 +865,12 @@ LoadTilesetTilePatternData:: ; 09e8 (0:09e8)
; 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:: ; 083c (0:083c)
; fill C6E8-CBFB with the background tile
ld hl,wOverworldMap
- ld a,[wd3ad] ; background tile number
- ld d,a
ld bc,$0514
-.backgroundTileLoop
- ld a,d
- ld [hli],a
- dec bc
- ld a,c
- or b
- jr nz,.backgroundTileLoop
+ ld a,[wd3ad] ; background tile number
+ call FillMemory
; 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
@@ -996,7 +987,7 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
.done
ret
-LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
+LoadNorthSouthConnectionsTileMap:: ; 0919 (0:0919)
ld c,$03
.loop
push de
@@ -1028,7 +1019,7 @@ LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
jr nz,.loop
ret
-LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
+LoadEastWestConnectionsTileMap:: ; 093d (0:093d)
push hl
push de
ld c,$03
@@ -1058,9 +1049,8 @@ LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
ret
; 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)
+; if so, carry is set. otherwise, carry is cleared
+IsSpriteOrSignInFrontOfPlayer:: ; 095e (0:095e)
xor a
ld [hSpriteIndexOrTextID],a
ld a,[wd4b0] ; number of signs in the map
@@ -1068,39 +1058,10 @@ IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
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 b,a
- ld c,$00
-.signLoop
- inc c
- ld a,[hli] ; sign Y
- cp d
- jr z,.yCoordMatched
- inc hl
- jr .retry
-.yCoordMatched
- ld a,[hli] ; sign X
- cp e
- jr nz,.retry
-.xCoordMatched
-; found sign
- push hl
- push bc
- ld hl,wd4d1 ; start of sign text ID's
- ld b,$00
- dec c
- add hl,bc
- ld a,[hl]
- ld [hSpriteIndexOrTextID],a ; store sign text ID
- pop bc
- pop hl
- ret
-.retry
- dec b
- jr nz,.signLoop
-; 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
+ call SignLoop
+ ret c
.extendRangeOverCounter
+; 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
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
@@ -1112,11 +1073,10 @@ IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
dec b
jr nz,.counterTilesLoop
-; 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)
+; sets carry flag if a sprite is in front of the player, resets if not
+IsSpriteInFrontOfPlayer:: ; 0983 (0:0983)
ld d,$10 ; talking range in pixels (normal range)
-IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
+IsSpriteInFrontOfPlayer2:: ; 0985 (0:0985)
ld bc,$3c40 ; Y and X position of player sprite
ld a,[wSpriteStateData1 + 9] ; direction the player is facing
.checkIfPlayerFacingUp
@@ -1154,13 +1114,10 @@ IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
ld a,$02
.doneCheckingDirection
ld [wd52a],a
- ld a,[W_NUMSPRITES] ; number of sprites
- and a
- ret z
-; if there are sprites
ld hl,wSpriteStateData1 + $10
- ld d,a
+; yellow does not have the "if sprites are existant" check
ld e,$01
+ ld d,$f
.spriteLoop
push hl
ld a,[hli] ; image (0 if no sprite)
@@ -1186,6 +1143,7 @@ IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
inc e
dec d
jr nz,.spriteLoop
+ xor a
ret
.foundSpriteInFrontOfPlayer
pop hl
@@ -1196,11 +1154,55 @@ IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
set 7,[hl]
ld a,e
ld [hSpriteIndexOrTextID],a
+ ld a,[hSpriteIndexOrTextID] ; possible useless read because a already has the value of the read address
+ cp a,$f
+ jr nz,.dontwritetowd436
+ ld a,$FF
+ ld [wd436],a
+.dontwritetowd436
+ scf
+ ret
+
+SignLoop:: ; 09f2 (0:09f2)
+; search if a player is facing a sign
+ ld hl,wd4b1 ; start of sign coordinates
+ ld a,[wd4b0] ; number of signs in the map
+ ld b,a
+ ld c,$00
+.signLoop
+ inc c
+ ld a,[hli] ; sign Y
+ cp d
+ jr z,.yCoordMatched
+ inc hl
+ jr .retry
+.yCoordMatched
+ ld a,[hli] ; sign X
+ cp e
+ jr nz,.retry
+.xCoordMatched
+; found sign
+ push hl
+ push bc
+ ld hl,wd4d1 ; start of sign text ID's
+ ld b,$00
+ dec c
+ add hl,bc
+ ld a,[hl]
+ ld [hSpriteIndexOrTextID],a ; store sign text ID
+ pop bc
+ pop hl
+ scf
+ ret
+.retry
+ dec b
+ jr nz,.signLoop
+ xor 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:: ; 0a1c (0:0a1c)
ld a,[wd736]
bit 6,a ; is the player jumping?
jr nz,.noCollision
@@ -1212,14 +1214,31 @@ CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
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
+ nop ; ??? why is this in the code
jr nz,.collision
xor a
ld [hSpriteIndexOrTextID],a
call IsSpriteInFrontOfPlayer ; check for sprite collisions again? when does the above check fail to detect a sprite collision?
+ jr nc,.asm_0a5c
+ res 7,[hl]
ld a,[hSpriteIndexOrTextID]
and a ; was there a sprite collision?
- jr nz,.collision
+ jr z,.asm_0a5c
; if no sprite collision
+ cp $f
+ jr nz,.collision
+ call CheckForJumpingAndTilePairCollisions
+ jr nz,.collision
+ ld a,[hJoyHeld]
+ and $2
+ jr nz,.asm_0a5c
+ ld hl,wd435
+ ld a,[hl]
+ and a
+ jr z,.asm_0a5c
+ dec [hl]
+ jr nz,.collision
+.asm_0a5c
ld hl,TilePairCollisionsLand
call CheckForJumpingAndTilePairCollisions
jr c,.collision
@@ -1240,30 +1259,18 @@ 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:: ; 0a79 (0:0a79)
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 a,[hli]
- ld h,[hl]
- ld l,a ; hl now points to passable tiles
-.loop
- ld a,[hli]
- cp a,$ff
- jr z,.tileNotPassable
- cp c
- ret z
- jr .loop
-.tileNotPassable
- scf
+ call IsTilePassable
ret
; check if the player is going to jump down a small ledge
; 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:: ; 0a86 (0:0a86)
push hl
predef GetTileAndCoordsInFrontOfPlayer ; get the tile in front of the player
push de
@@ -1278,11 +1285,11 @@ CheckForJumpingAndTilePairCollisions:: ; 0c2a (0:0c2a)
ret nz
; if not jumping
-CheckForTilePairCollisions2:: ; 0c44 (0:0c44)
+CheckForTilePairCollisions2:: ; 0aa0 (0:0aa0)
aCoord 8, 9 ; tile the player is on
ld [wcf0e],a
-CheckForTilePairCollisions:: ; 0c4a (0:0c4a)
+CheckForTilePairCollisions:: ; 0aa6 (0:0aa6)
ld a,[wTileInFrontOfPlayer]
ld c,a
.tilePairCollisionLoop
@@ -1332,7 +1339,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:: ; 0ada (0:0ada)
db CAVERN, $20, $05
db CAVERN, $41, $05
db FOREST, $30, $2E
@@ -1346,19 +1353,18 @@ TilePairCollisionsLand:: ; 0c7e (0:0c7e)
db FOREST, $5F, $2E
db $FF
-TilePairCollisionsWater:: ; 0ca0 (0:0ca0)
+TilePairCollisionsWater:: ; 0afc (0:0afc)
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:: ; 0b06 (0:0b06)
ld a,[H_LOADEDROMBANK]
push af
ld a,[W_TILESETBANK] ; tile data ROM bank
- ld [H_LOADEDROMBANK],a
- ld [$2000],a ; switch to ROM bank that contains tile data
+ call BankswitchCommon ; 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]
@@ -1439,260 +1445,25 @@ LoadCurrentMapView:: ; 0caa (0:0caa)
dec b
jr nz,.rowLoop2
pop af
- ld [H_LOADEDROMBANK],a
- ld [$2000],a ; restore previous ROM bank
- ret
-
-AdvancePlayerSprite:: ; 0d27 (0:0d27)
- ld a,[wSpriteStateData1 + 3] ; delta Y
- ld b,a
- ld a,[wSpriteStateData1 + 5] ; delta X
- ld c,a
- ld hl,wWalkCounter ; walking animation counter
- dec [hl]
- jr nz,.afterUpdateMapCoords
-; if it's the end of the animation, update the player's map coordinates
- ld a,[W_YCOORD]
- add b
- ld [W_YCOORD],a
- ld a,[W_XCOORD]
- add c
- ld [W_XCOORD],a
-.afterUpdateMapCoords
- ld a,[wWalkCounter] ; walking animation counter
- cp a,$07
- jp nz,.scrollBackgroundAndSprites
-; if this is the first iteration of the animation
- ld a,c
- cp a,$01
- jr nz,.checkIfMovingWest
-; moving east
- ld a,[wMapViewVRAMPointer]
- ld e,a
- and a,$e0
- ld d,a
- ld a,e
- add a,$02
- and a,$1f
- or d
- ld [wMapViewVRAMPointer],a
- jr .adjustXCoordWithinBlock
-.checkIfMovingWest
- cp a,$ff
- jr nz,.checkIfMovingSouth
-; moving west
- ld a,[wMapViewVRAMPointer]
- ld e,a
- and a,$e0
- ld d,a
- ld a,e
- sub a,$02
- and a,$1f
- or d
- ld [wMapViewVRAMPointer],a
- jr .adjustXCoordWithinBlock
-.checkIfMovingSouth
- ld a,b
- cp a,$01
- jr nz,.checkIfMovingNorth
-; moving south
- ld a,[wMapViewVRAMPointer]
- add a,$40
- ld [wMapViewVRAMPointer],a
- jr nc,.adjustXCoordWithinBlock
- ld a,[wMapViewVRAMPointer + 1]
- inc a
- and a,$03
- or a,$98
- ld [wMapViewVRAMPointer + 1],a
- jr .adjustXCoordWithinBlock
-.checkIfMovingNorth
- cp a,$ff
- jr nz,.adjustXCoordWithinBlock
-; moving north
- ld a,[wMapViewVRAMPointer]
- sub a,$40
- ld [wMapViewVRAMPointer],a
- jr nc,.adjustXCoordWithinBlock
- ld a,[wMapViewVRAMPointer + 1]
- dec a
- and a,$03
- or a,$98
- ld [wMapViewVRAMPointer + 1],a
-.adjustXCoordWithinBlock
- ld a,c
- and a
- jr z,.pointlessJump ; mistake?
-.pointlessJump
- ld hl,W_XBLOCKCOORD
- ld a,[hl]
- add c
- ld [hl],a
- cp a,$02
- jr nz,.checkForMoveToWestBlock
-; moved into the tile block to the east
- xor a
- ld [hl],a
- ld hl,wXOffsetSinceLastSpecialWarp
- inc [hl]
- ld de,wCurrentTileBlockMapViewPointer
- call MoveTileBlockMapPointerEast
- jr .updateMapView
-.checkForMoveToWestBlock
- cp a,$ff
- jr nz,.adjustYCoordWithinBlock
-; moved into the tile block to the west
- ld a,$01
- ld [hl],a
- ld hl,wXOffsetSinceLastSpecialWarp
- dec [hl]
- ld de,wCurrentTileBlockMapViewPointer
- call MoveTileBlockMapPointerWest
- jr .updateMapView
-.adjustYCoordWithinBlock
- ld hl,W_YBLOCKCOORD
- ld a,[hl]
- add b
- ld [hl],a
- cp a,$02
- jr nz,.checkForMoveToNorthBlock
-; moved into the tile block to the south
- xor a
- ld [hl],a
- ld hl,wYOffsetSinceLastSpecialWarp
- inc [hl]
- ld de,wCurrentTileBlockMapViewPointer
- ld a,[W_CURMAPWIDTH]
- call MoveTileBlockMapPointerSouth
- jr .updateMapView
-.checkForMoveToNorthBlock
- cp a,$ff
- jr nz,.updateMapView
-; moved into the tile block to the north
- ld a,$01
- ld [hl],a
- ld hl,wYOffsetSinceLastSpecialWarp
- dec [hl]
- ld de,wCurrentTileBlockMapViewPointer
- ld a,[W_CURMAPWIDTH]
- call MoveTileBlockMapPointerNorth
-.updateMapView
- call LoadCurrentMapView
- ld a,[wSpriteStateData1 + 3] ; delta Y
- cp a,$01
- jr nz,.checkIfMovingNorth2
-; if moving south
- call ScheduleSouthRowRedraw
- jr .scrollBackgroundAndSprites
-.checkIfMovingNorth2
- cp a,$ff
- jr nz,.checkIfMovingEast2
-; if moving north
- call ScheduleNorthRowRedraw
- jr .scrollBackgroundAndSprites
-.checkIfMovingEast2
- ld a,[wSpriteStateData1 + 5] ; delta X
- cp a,$01
- jr nz,.checkIfMovingWest2
-; if moving east
- call ScheduleEastColumnRedraw
- jr .scrollBackgroundAndSprites
-.checkIfMovingWest2
- cp a,$ff
- jr nz,.scrollBackgroundAndSprites
-; if moving west
- call ScheduleWestColumnRedraw
-.scrollBackgroundAndSprites
- ld a,[wSpriteStateData1 + 3] ; delta Y
- ld b,a
- ld a,[wSpriteStateData1 + 5] ; delta X
- ld c,a
- sla b
- sla c
- ld a,[hSCY]
- add b
- ld [hSCY],a ; update background scroll Y
- ld a,[hSCX]
- add c
- ld [hSCX],a ; update background scroll X
-; 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
- and a ; are there any sprites?
- jr z,.done
- ld e,a
-.spriteShiftLoop
- ld a,[hl]
- sub b
- ld [hli],a
- inc l
- ld a,[hl]
- sub c
- ld [hl],a
- ld a,$0e
- add l
- ld l,a
- dec e
- jr nz,.spriteShiftLoop
-.done
+ call BankswitchCommon ; restore previous ROM bank
ret
-; 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)
- ld a,[de]
- add a,$01
- ld [de],a
- ret nc
- inc de
- ld a,[de]
- inc a
- ld [de],a
- ret
-
-MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f)
- ld a,[de]
- sub a,$01
- ld [de],a
- ret nc
- inc de
- ld a,[de]
- dec a
- ld [de],a
- ret
-
-MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
- add a,$06
- ld b,a
- ld a,[de]
- add b
- ld [de],a
- ret nc
- inc de
- ld a,[de]
- inc a
- ld [de],a
- ret
-
-MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
- add a,$06
- ld b,a
- ld a,[de]
- sub b
- ld [de],a
- ret nc
- inc de
- ld a,[de]
- dec a
- ld [de],a
+AdvancePlayerSprite:: ; 0b7f (0:0b7f)
+ ld a,[wUpdateSpritesEnabled]
+ push af
+ ld a,$FF
+ ld [wUpdateSpritesEnabled],a
+ ld hl, _AdvancePlayerSprite ; 3c:410c
+ ld b, BANK(_AdvancePlayerSprite)
+ call Bankswitch
+ pop af
+ ld [wUpdateSpritesEnabled],a
ret
; 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)
+ScheduleNorthRowRedraw:: ; 0b95 (0:0b95)
hlCoord 0, 0
call CopyToScreenEdgeTiles
ld a,[wMapViewVRAMPointer]
@@ -1703,7 +1474,7 @@ ScheduleNorthRowRedraw:: ; 0e91 (0:0e91)
ld [H_SCREENEDGEREDRAW],a
ret
-CopyToScreenEdgeTiles:: ; 0ea6 (0:0ea6)
+CopyToScreenEdgeTiles:: ; 0baa (0:0baa)
ld de,wScreenEdgeTiles
ld c,2 * 20
.loop
@@ -1713,8 +1484,8 @@ CopyToScreenEdgeTiles:: ; 0ea6 (0:0ea6)
dec c
jr nz,.loop
ret
-
-ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2)
+
+ScheduleSouthRowRedraw:: ; 0bb6 (0:0bb6)
hlCoord 0, 16
call CopyToScreenEdgeTiles
ld a,[wMapViewVRAMPointer]
@@ -1733,7 +1504,7 @@ ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2)
ld [H_SCREENEDGEREDRAW],a
ret
-ScheduleEastColumnRedraw:: ; 0ed3 (0:0ed3)
+ScheduleEastColumnRedraw:: ; 0bd6 (0:0bd7)
hlCoord 18, 0
call ScheduleColumnRedrawHelper
ld a,[wMapViewVRAMPointer]
@@ -1751,7 +1522,7 @@ ScheduleEastColumnRedraw:: ; 0ed3 (0:0ed3)
ld [H_SCREENEDGEREDRAW],a
ret
-ScheduleColumnRedrawHelper:: ; 0ef2 (0:0ef2)
+ScheduleColumnRedrawHelper:: ; 0bf6 (0:0bf6)
ld de,wScreenEdgeTiles
ld c,$12
.loop
@@ -1771,7 +1542,7 @@ ScheduleColumnRedrawHelper:: ; 0ef2 (0:0ef2)
jr nz,.loop
ret
-ScheduleWestColumnRedraw:: ; 0f08 (0:0f08)
+ScheduleWestColumnRedraw:: ; 0c0c (0:0c0c)
hlCoord 0, 0
call ScheduleColumnRedrawHelper
ld a,[wMapViewVRAMPointer]
@@ -1784,7 +1555,7 @@ ScheduleWestColumnRedraw:: ; 0f08 (0:0f08)
; 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:: ; 0c21 (0:0c21)
push hl
ld a,[W_TILESETBLOCKSPTR] ; pointer to tiles
ld l,a
@@ -1825,24 +1596,31 @@ DrawTileBlock:: ; 0f1d (0:0f1d)
ret
; function to update joypad state and simulate button presses
-JoypadOverworld:: ; 0f4d (0:0f4d)
+JoypadOverworld:: ; 0c51 (0:0c51)
xor a
ld [wSpriteStateData1 + 3],a
ld [wSpriteStateData1 + 5],a
call RunMapScript
call Joypad
+ call ForceBikeDown
+ call AreInputsSimulated
+ ret
+
+ForceBikeDown:: ; 0c65 (0:0c65)
ld a,[W_FLAGS_D733]
bit 3,a ; check if a trainer wants a challenge
- jr nz,.notForcedDownwards
+ ret nz
ld a,[W_CURMAP]
cp a,ROUTE_17 ; Cycling Road
- jr nz,.notForcedDownwards
+ ret nz
ld a,[hJoyHeld]
and a,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
-.notForcedDownwards
+ ret
+
+AreInputsSimulated:: ; 0c7b (0:0c7b)
ld a,[wd730]
bit 7,a
ret z
@@ -1852,24 +1630,15 @@ JoypadOverworld:: ; 0f4d (0:0f4d)
ld a,[wOverrideSimulatedJoypadStatesMask] ; bit mask for button presses that override simulated ones
and b
ret nz ; return if the simulated button presses are overridden
- ld hl,wSimulatedJoypadStatesIndex
- dec [hl]
- ld a,[hl]
- cp a,$ff
- jr z,.doneSimulating ; if the end of the simulated button presses has been reached
- ld hl,wSimulatedJoypadStatesEnd
- add l
- ld l,a
- jr nc,.noCarry
- inc h
-.noCarry
- ld a,[hl]
+ call GetSimulatedInput
+ jr nc,.doneSimulating
ld [hJoyHeld],a ; store simulated button press in joypad state
and a
ret nz
ld [hJoyPressed],a
ld [hJoyReleased],a
ret
+
; if done simulating button presses
.doneSimulating
xor a
@@ -1885,6 +1654,26 @@ JoypadOverworld:: ; 0f4d (0:0f4d)
ld hl,wd730
res 7,[hl]
ret
+
+GetSimulatedInput:: ; 0cb3 (0:0cb3)
+ ld hl,wSimulatedJoypadStatesIndex
+ dec [hl]
+ ld a,[hl]
+ cp a,$ff
+ jr z,.endofsimulatedinputs ; if the end of the simulated button presses has been reached
+ push de
+ ld e,a
+ ld d,$0
+ ld hl,wSimulatedJoypadStatesEnd
+ add hl,de
+ ld a,[hl]
+ pop de
+ scf
+ ret
+.endofsimulatedinputs
+ and a
+ ret
+
; function to check the tile ahead to determine if the character should get on land or keep surfing
; sets carry if there is a collision and clears carry otherwise
@@ -1895,7 +1684,7 @@ 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:: ; 0cca (0:0cca)
ld a,[wd730]
bit 7,a
jp nz,.noCollision ; return and clear carry if button presses are being simulated
@@ -1908,26 +1697,12 @@ CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
call CheckForJumpingAndTilePairCollisions
jr c,.collision
predef GetTileAndCoordsInFrontOfPlayer ; get tile in front of player (puts it in c and [wTileInFrontOfPlayer])
+ callab IsNextTileShoreOrWater ; 3:6808
+ jr c,.noCollsion
ld a,[wTileInFrontOfPlayer] ; tile in front of player
- cp a,$14 ; water tile
- jr z,.noCollision ; keep surfing if it's a water tile
- cp a,$32 ; either the left tile of the S.S. Anne boarding platform or the tile on eastern coastlines (depending on the current tileset)
- jr z,.checkIfVermilionDockTileset
- cp a,$48 ; tile on right on coast lines in Safari Zone
- 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 a,[hli]
- ld h,[hl]
- ld l,a
-.loop
- ld a,[hli]
- cp a,$ff
- jr z,.collision
- cp c
- jr z,.stopSurfing ; stop surfing if the tile is passable
- jr .loop
+ ld c,a
+ call IsTilePassable
+ jr nc,.stopSurfing
.collision
ld a,[wc02a]
cp a,(SFX_02_5b - SFX_Headers_02) / 3 ; check if collision sound is already playing
@@ -1937,24 +1712,28 @@ CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
.setCarry
scf
jr .done
-.noCollision
- and a
-.done
- ret
-.stopSurfing
- xor a
- ld [wWalkBikeSurfState],a
- call LoadPlayerSpriteGraphics
- call PlayDefaultMusic
- jr .noCollision
.checkIfVermilionDockTileset
ld a, [W_CURMAPTILESET] ; 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
+.stopSurfing ; based game freak
+ ld a,$3
+ ld [wd431],a
+ ld hl,wd430
+ set 5,[hl]
+ xor a
+ ld [wWalkBikeSurfState],a
+ call LoadPlayerSpriteGraphics
+ call PlayDefaultMusic
+ jr .noCollision
+.noCollision ; ...and they do the same mistake twice
+ and a
+.done
+ ret
; function to run the current map's script
-RunMapScript:: ; 101b (0:101b)
+RunMapScript:: ; 0d2c (0:0d2c)
push hl
push de
push bc
@@ -1980,24 +1759,43 @@ RunMapScript:: ; 101b (0:101b)
.return
ret
-LoadWalkingPlayerSpriteGraphics:: ; 104d (0:104d)
+Func_0d5e:: ; 0d5e (0:0d5e)
+; new sprite copy stuff
+ xor a
+ ld [wd473],a
+ ld b,BANK(RedSprite)
ld de,RedSprite ; $4180
- ld hl,vNPCSprites
jr LoadPlayerSpriteGraphicsCommon
-
-LoadSurfingPlayerSpriteGraphics:: ; 1055 (0:1055)
+
+Func_0d69:: ; 0d69 (0:0d69)
+ ld a,[wd473]
+ and a
+ jr z,.asm_0d75
+ dec a
+ jr z,.asm_0d83
+ dec a
+ jr z,.asm_0d7c
+.asm_0d75
+ ld a,[wd472]
+ bit 6,a
+ jr z,LoadSurfingPlayerSpriteGraphics
+.asm_0d7c
+ ld b,BANK(Pointer_fedef)
+ ld de,Pointer_fedef ; 3f:6def
+ jr LoadPlayerSpriteGraphicsCommon
+
+LoadSurfingPlayerSpriteGraphics:: ; 0d83 (0:0d83)
+ ld b,BANK(RedSprite) ; not sure, but probably same bank (5)
ld de,SeelSprite
- ld hl,vNPCSprites
jr LoadPlayerSpriteGraphicsCommon
-LoadBikePlayerSpriteGraphics:: ; 105d (0:105d)
+LoadBikePlayerSpriteGraphics:: ; 0d8a (0:0d8a)
ld de,RedCyclingSprite
+LoadPlayerSpriteGraphicsCommon:: ; 0d8f (0:0d8f)
ld hl,vNPCSprites
-
-LoadPlayerSpriteGraphicsCommon:: ; 1063 (0:1063)
push de
push hl
- ld bc,(BANK(RedSprite) << 8) + $0c
+ ld c, $c
call CopyVideoData
pop hl
pop de
@@ -2008,12 +1806,15 @@ LoadPlayerSpriteGraphicsCommon:: ; 1063 (0:1063)
inc d
.noCarry
set 3,h
- ld bc,$050c
+ ld c,$c
jp CopyVideoData
; function to load data from the map header
-LoadMapHeader:: ; 107c (0:107c)
+LoadMapHeader:: ; 0dab (0:0dab)
callba MarkTownVisitedAndLoadMissableObjects
+ jr .asm_0dbd
+ callba Func_f0a55 ; 3c:4a55
+.asm_0dbd
ld a,[W_CURMAPTILESET]
ld [wd119],a
ld a,[W_CURMAP]
@@ -2025,20 +1826,7 @@ LoadMapHeader:: ; 107c (0:107c)
ld [$ff8b],a
bit 7,b
ret nz
- ld hl,MapHeaderPointers
- ld a,[W_CURMAP]
- sla a
- jr nc,.noCarry1
- inc h
-.noCarry1
- add l
- ld l,a
- jr nc,.noCarry2
- inc h
-.noCarry2
- ld a,[hli]
- ld h,[hl]
- ld l,a ; hl = base of map header
+ call GetMapHeaderPointer
; copy the first 10 bytes (the fixed area) of the map data to D367-D370
ld de,W_CURMAPTILESET
ld c,$0a
@@ -2112,155 +1900,18 @@ LoadMapHeader:: ; 107c (0:107c)
ld [wd4b0],a ; save the number of signs
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 a,d
- ld [$ff95],a
- ld a,e
- ld [$ff96],a
- ld de,wd4b1 ; base address of sign coordinates
-.signLoop
- ld a,[hli]
- ld [de],a
- inc de
- ld a,[hli]
- ld [de],a
- inc de
- push de
- ld a,[$ff95]
- ld d,a
- ld a,[$ff96]
- ld e,a
- ld a,[hli]
- ld [de],a
- inc de
- ld a,d
- ld [$ff95],a
- ld a,e
- ld [$ff96],a
- pop de
- dec c
- jr nz,.signLoop
+ call CopySignData ; 0eb3 (0:0eb3)
.loadSpriteData
ld a,[wd72e]
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
- push hl
-; zero C110-C1FF and C210-C2FF
- ld hl,wSpriteStateData1 + $10
- ld de,wSpriteStateData2 + $10
- xor a
- ld b,$f0
-.zeroSpriteDataLoop
- ld [hli],a
- ld [de],a
- inc e
- dec b
- jr nz,.zeroSpriteDataLoop
-; initialize all C100-C1FF sprite entries to disabled (other than player's)
- ld hl,wSpriteStateData1 + $12
- ld de,$0010
- ld c,$0f
-.disableSpriteEntriesLoop
- ld [hl],$ff
- add hl,de
- dec c
- jr nz,.disableSpriteEntriesLoop
- pop hl
- ld de,wSpriteStateData1 + $10
- ld a,[W_NUMSPRITES] ; number of sprites
- and a ; are there any sprites?
- jp z,.finishUp ; if there are no sprites, skip the rest
- ld b,a
- ld c,$00
-.loadSpriteLoop
- ld a,[hli]
- ld [de],a ; store picture ID at C1X0
- inc d
- ld a,$04
- add e
- ld e,a
- ld a,[hli]
- ld [de],a ; store Y position at C2X4
- inc e
- ld a,[hli]
- ld [de],a ; store X position at C2X5
- inc e
- ld a,[hli]
- ld [de],a ; store movement byte 1 at C2X6
- ld a,[hli]
- ld [$ff8d],a ; save movement byte 2
- ld a,[hli]
- ld [$ff8e],a ; save text ID and flags byte
- push bc
- push hl
- ld b,$00
- ld hl,W_MAPSPRITEDATA
- add hl,bc
- ld a,[$ff8d]
- ld [hli],a ; store movement byte 2 in byte 0 of sprite entry
- ld a,[$ff8e]
- ld [hl],a ; this appears pointless, since the value is overwritten immediately after
- ld a,[$ff8e]
- ld [$ff8d],a
- and a,$3f
- ld [hl],a ; store text ID in byte 1 of sprite entry
- pop hl
- ld a,[$ff8d]
- bit 6,a
- jr nz,.trainerSprite
- bit 7,a
- jr nz,.itemBallSprite
- jr .regularSprite
-.trainerSprite
- ld a,[hli]
- ld [$ff8d],a ; save trainer class
- ld a,[hli]
- ld [$ff8e],a ; save trainer number (within class)
- push hl
- ld hl,W_MAPSPRITEEXTRADATA
- add hl,bc
- ld a,[$ff8d]
- ld [hli],a ; store trainer class in byte 0 of the entry
- ld a,[$ff8e]
- 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
- push hl
- ld hl,W_MAPSPRITEEXTRADATA
- add hl,bc
- ld a,[$ff8d]
- 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
- pop hl
- jr .nextSprite
-.regularSprite
- push hl
- ld hl,W_MAPSPRITEEXTRADATA
- add hl,bc
-; zero both bytes, since regular sprites don't use this extra space
- xor a
- ld [hli],a
- ld [hl],a
- pop hl
-.nextSprite
- pop bc
- dec d
- ld a,$0a
- add e
- ld e,a
- inc c
- inc c
- dec b
- jp nz,.loadSpriteLoop
+ call InitSprites
.finishUp
predef LoadTilesetHeader
+ ld a,[wd72e]
+ bit 5,a ; did a battle happen immediately before this?
+ jr nz,.asm_0e73
+ callab Func_fc4fa ; 3f:44fa
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
@@ -2274,10 +1925,8 @@ LoadMapHeader:: ; 107c (0:107c)
ld b,$00
ld a,[H_LOADEDROMBANK]
push af
- ld a, BANK(MapSongBanks)
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
- ld hl, MapSongBanks
+ switchbank MapSongBanks
+ ld hl, MapSongBanks ; 3f:4000
add hl,bc
add hl,bc
ld a,[hli]
@@ -2285,8 +1934,7 @@ LoadMapHeader:: ; 107c (0:107c)
ld a,[hl]
ld [wd35c],a ; music 2
pop af
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ call BankswitchCommon
ret
; function to copy map connection data from ROM to WRAM
@@ -2301,11 +1949,94 @@ CopyMapConnectionHeader:: ; 1238 (0:1238)
jr nz,.loop
ret
+CopySignData:: ; 0eb3 (0:0eb3)
+ ld de,wd4b1 ; start of sign coords
+ ld bc,wd4d1 ; start of sign text ids
+ ld a,[wd4b0] ; number of signs
+.signcopyloop
+ push af
+ ld a,[hli]
+ ld [de],a ; copy y coord
+ inc de
+ ld a,[hli]
+ ld [de],a ; copy x coord
+ inc de
+ ld a,[hli]
+ ld [bc],a ; copy sign text id
+ inc bc
+ pop af
+ dec a
+ jr nz,.signcopyloop
+ ret
+
; function to load map data
LoadMapData:: ; 1241 (0:1241)
ld a,[H_LOADEDROMBANK]
push af
call DisableLCD
+ call ResetMapVariables
+ call LoadTextBoxTilePatterns
+ call LoadMapHeader
+ call InitMapSprites ; load tile pattern data for sprites
+ call LoadScreenRelatedData
+ call CopyMapViewToVRAM
+ ld a,$01
+ ld [wUpdateSpritesEnabled],a
+ call EnableLCD
+ ld b,$09
+ call GoPAL_SET
+ call LoadPlayerSpriteGraphics
+ ld a,[wd732]
+ and a,1 << 4 | 1 << 3 ; fly warp or dungeon warp
+ jr nz,.restoreRomBank
+ ld a,[W_FLAGS_D733]
+ bit 1,a
+ jr nz,.restoreRomBank
+ call Func_235f ; music related
+ call Func_2312 ; music related
+.restoreRomBank
+ pop af
+ ld [H_LOADEDROMBANK],a
+ ld [$2000],a
+ ret
+
+LoadScreenRelatedData:: ; 0f0c (0:0f0c)
+ call LoadTileBlockMap
+ call LoadTilesetTilePatternData
+ call LoadCurrentMapView
+ ret
+
+Func_0f16:: ; 0f16 (0:0f16)
+ ld a,[H_LOADEDROMBANK]
+ push af
+ call DisableLCD
+ call ResetMapVariables
+ ld a,[W_CURMAP]
+ call SwitchToMapRomBank
+ call LoadScreenRelatedData
+ call CopyMapViewToVRAM
+ ld de,vBGMap1
+ call CopyMapViewToVRAM2
+ call EnableLCD
+ call ReloadMapSpriteTilePatterns
+ pop af
+ call BankswitchCommon
+ jr .asm_0f4d
+Func_0f3d:: ; 0f3d (0:0f3d)
+ ld a,[H_LOADEDROMBANK]
+ push af
+ ld a,[W_CURMAP]
+ call SwitchToMapRomBank
+ call LoadTileBlockMap
+ pop af
+ call BankswitchCommon
+.asm_0f4d
+ ld hl, Func_f02da
+ ld b,BANK(Func_f02da) ; 3c:42da
+ jp Bankswitch
+ ret ; useless?
+
+ResetMapVariables:: ; 0f56 (0:0f56)
ld a,$98
ld [wMapViewVRAMPointer + 1],a
xor a
@@ -2314,17 +2045,15 @@ LoadMapData:: ; 1241 (0:1241)
ld [hSCX],a
ld [wWalkCounter],a
ld [wd119],a
- ld [wWalkBikeSurfStateCopy],a
ld [W_SPRITESETID],a
- call LoadTextBoxTilePatterns
- call LoadMapHeader
- callba InitMapSprites ; load tile pattern data for sprites
- call LoadTileBlockMap
- call LoadTilesetTilePatternData
- call LoadCurrentMapView
+ ld [wWalkBikeSurfStateCopy],a
+ ret
+
+CopyMapViewToVRAM:: ; 0f70 (0:0f70)
; copy current map view to VRAM
- ld hl,wTileMap
ld de,vBGMap0
+CopyMapViewToVRAM2: ; 0f73 (0:0f73)
+ ld hl,wTileMap
ld b,18
.vramCopyLoop
ld c,20
@@ -2334,7 +2063,7 @@ LoadMapData:: ; 1241 (0:1241)
inc e
dec c
jr nz,.vramCopyInnerLoop
- ld a,32 - 20
+ ld a,32 - 20 ; total vram map width in tiles - screen width in tiles
add e
ld e,a
jr nc,.noCarry
@@ -2342,48 +2071,45 @@ LoadMapData:: ; 1241 (0:1241)
.noCarry
dec b
jr nz,.vramCopyLoop
- ld a,$01
- ld [wUpdateSpritesEnabled],a
- call EnableLCD
- ld b,$09
- call GoPAL_SET
- call LoadPlayerSpriteGraphics
- ld a,[wd732]
- and a,1 << 4 | 1 << 3 ; fly warp or dungeon warp
- jr nz,.restoreRomBank
- ld a,[W_FLAGS_D733]
- bit 1,a
- jr nz,.restoreRomBank
- call Func_235f ; music related
- call Func_2312 ; music related
-.restoreRomBank
- pop af
- ld [H_LOADEDROMBANK],a
- ld [$2000],a
ret
; function to switch to the ROM bank that a map is stored in
; Input: a = map number
-SwitchToMapRomBank:: ; 12bc (0:12bc)
+SwitchToMapRomBank:: ; 0f8b (0:0f8b)
push hl
push bc
ld c,a
ld b,$00
- ld a,Bank(MapHeaderBanks)
- call BankswitchHome ; switch to ROM bank 3
+ ld a,BANK(MapHeaderBanks)
+ call BankswitchHome ; switch to ROM bank 3F
ld hl,MapHeaderBanks
add hl,bc
ld a,[hl]
ld [$ffe8],a ; save map ROM bank
- call BankswitchBack
- ld a,[$ffe8]
- ld [H_LOADEDROMBANK],a
- ld [$2000],a ; switch to map ROM bank
+ call BankswitchCommon
pop bc
pop hl
ret
-IgnoreInputForHalfSecond: ; 12da (0:12da)
+GetMapHeaderPointer:: ; 0fa7 (0:0fa7)
+ ld a,[H_LOADEDROMBANK]
+ push af
+ switchbank MapHeaderPointers ; 3f:41f2
+ push de
+ ld a,[W_CURMAP]
+ ld e,a
+ ld d,$0
+ ld hl,MapHeaderPointers
+ add hl,de
+ add hl,de
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ pop de
+ pop af
+ jp BankswitchCommon
+
+IgnoreInputForHalfSecond: ; 0fc3 (0:0fc3)
ld a, 30
ld [wIgnoreInputCounter], a
ld hl, wd730
@@ -2392,13 +2118,176 @@ IgnoreInputForHalfSecond: ; 12da (0:12da)
ld [hl], a ; set ignore input bit
ret
-ResetUsingStrengthOutOfBattleBit: ; 12e7 (0:12e7)
+ResetUsingStrengthOutOfBattleBit: ; 0fd0 (0:0fd0)
ld hl, wd728
res 0, [hl]
ret
-ForceBikeOrSurf:: ; 12ed (0:12ed)
+ForceBikeOrSurf:: ; 0fd6 (0:0fd6)
ld b, BANK(RedSprite)
ld hl, LoadPlayerSpriteGraphics
call Bankswitch
jp PlayDefaultMusic ; update map/player state?
+
+; Handle the player jumping down
+; a ledge in the overworld.
+HandleMidJump:: ; 0fe1 (0:0fe1)
+ ld a,[wd736]
+ bit 7,a ; jumping down a ledge?
+ ret z
+ ld b, BANK(_HandleMidJump)
+ ld hl, _HandleMidJump
+ jp Bankswitch
+
+IsSpinning:: ; 0ff0 (0:0ff0)
+ ld a,[wd736]
+ bit 7,a
+ ret z ; no spinning
+ ld b, BANK(LoadSpinnerArrowTiles); spin while moving
+ ld hl,LoadSpinnerArrowTiles ; 11:5077
+ jp Bankswitch
+
+Func_0ffe:: ; 0ffe (0:0ffe)
+ ld hl, Func_fcf0c ; 3f:4f0c
+ ld b, BANK(Func_fcf0c)
+ jp Bankswitch
+
+InitSprites:: ; 1006 (0:1006)
+ ld a,[hli]
+ ld [W_NUMSPRITES],a ; save the number of sprites
+ push hl
+ push hl
+ push de
+ push bc
+ call ZeroSpriteStateData
+ call DisableRegularSprites
+ ld hl,W_MAPSPRITEDATA
+ ld bc,$20
+ xor a
+ call FillMemory
+ pop bc
+ pop de
+ pop hl
+ ld a,[W_NUMSPRITES]
+ and a ; are sprites existant?
+ ret z ; don't copy sprite data if not
+ ld b,a
+ ld c,$0
+ ld de,wSpriteStateData1 + $10
+; copy sprite stuff?
+.loadSpriteLoop
+ ld a,[hli]
+ ld [de],a ; store picture ID at C1X0
+ inc d
+ ld a,$04
+ add e
+ ld e,a
+ ld a,[hli]
+ ld [de],a ; store Y position at C2X4
+ inc e
+ ld a,[hli]
+ ld [de],a ; store X position at C2X5
+ inc e
+ ld a,[hli]
+ ld [de],a ; store movement byte 1 at C2X6
+ ld a,[hli]
+ ld [$ff8d],a ; save movement byte 2
+ ld a,[hli]
+ ld [$ff8e],a ; save text ID and flags byte
+ push bc
+ call LoadSprite
+ pop bc
+ dec d
+ ld a,e
+ add a,$a
+ ld e,a
+ inc c
+ inc c
+ dec b
+ jr nz,.loadSpriteLoop
+ ret
+
+ZeroSpriteStateData:: ; 1050 (0:1050)
+; zero C110-C1EF and C210-C2EF
+; C1F0-C1FF and C2F0-C2FF is probably used for Pikachu
+ ld hl,wSpriteStateData1 + $10
+ ld de,wSpriteStateData2 + $10
+ xor a
+ ld b,$e0
+.loop
+ ld [hli],a
+ ld [de],a
+ inc e
+ dec b
+ jr nz,.loop
+ ret
+
+DisableRegularSprites:: ; 1060 (0:1060)
+; initialize all C100-C1FF sprite entries to disabled (other than player's and pikachu)
+ ld hl,wSpriteStateData1 + $12
+ ld de,$10
+ ld c,$e
+.loop
+ ld [hl],$ff
+ add hl,de
+ dec c
+ jr nz,.loop
+ ret
+
+LoadSprite:: ; 106f (0:106f)
+ push hl
+ ld b,$0
+ ld hl,W_MAPSPRITEDATA
+ add hl,bc
+ ld a,[$ff8d]
+ ld [hli],a ; store movement byte 2 in byte 0 of sprite entry
+ ld a,[$ff8e]
+ ld [hl],a ; this appears pointless, since the value is overwritten immediately after
+ ld a,[$ff8e]
+ ld [$ff8d],a
+ and a,$3f
+ ld [hl],a ; store text ID in byte 1 of sprite entry
+ pop hl
+ ld a,[$ff8d]
+ bit 6,a
+ jr nz,.trainerSprite
+ bit 7,a
+ jr nz,.itemBallSprite
+; for regular sprites
+ push hl
+ ld hl,W_MAPSPRITEEXTRADATA
+ add hl,bc
+; zero both bytes, since regular sprites don't use this extra space
+ xor a
+ ld [hli],a
+ ld [hl],a
+ pop hl
+ ret
+
+.trainerSprite
+ ld a,[hli]
+ ld [$ff8d],a ; save trainer class
+ ld a,[hli]
+ ld [$ff8e],a ; save trainer number (within class)
+ push hl
+ ld hl,W_MAPSPRITEEXTRADATA
+ add hl,bc
+ ld a,[$ff8d]
+ ld [hli],a ; store trainer class in byte 0 of the entry
+ ld a,[$ff8e]
+ ld [hl],a ; store trainer number in byte 1 of the entry
+ pop hl
+ ret
+
+.itemBallSprite
+ ld a,[hli]
+ ld [$ff8d],a ; save item number
+ push hl
+ ld hl,W_MAPSPRITEEXTRADATA
+ add hl,bc
+ ld a,[$ff8d]
+ 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
+ pop hl
+ ret ; end of home/overworld.asm = 10b9 (0:10b9) \ No newline at end of file
diff --git a/engine/play_time.asm b/home/play_time.asm
index 74da9c59..74da9c59 100755..100644
--- a/engine/play_time.asm
+++ b/home/play_time.asm
diff --git a/home/vblank.asm b/home/vblank.asm
index d8288187..08348f79 100644
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -5,6 +5,11 @@ VBlank::
push de
push hl
+ ld a, [rVBK] ; vram bank
+ push af
+ xor a
+ ld [rVBK], a ; reset vram bank to 0
+
ld a, [H_LOADEDROMBANK]
ld [wd122], a
@@ -33,8 +38,10 @@ VBlank::
call PrepareOAMData
; VBlank-sensitive operations end.
-
+ call TrackPlayTime ; keep track of time played
+
call Random
+ call ReadJoypad
ld a, [H_VBLANKOCCURRED]
and a
@@ -51,37 +58,24 @@ VBlank::
.decced
call Func_28cb
-
- ld a, [wc0ef] ; music ROM bank
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
-
- cp BANK(Music2_UpdateMusic)
- jr nz, .notbank2
-.bank2
- call Music2_UpdateMusic
- jr .afterMusic
-.notbank2
- cp BANK(Music8_UpdateMusic)
- jr nz, .bank1F
-.bank8
+
+ ld a, $8
+ call BankswitchCommon
call Music_DoLowHealthAlarm
- call Music8_UpdateMusic
- jr .afterMusic
-.bank1F
- call Music1f_UpdateMusic
-.afterMusic
-
- callba TrackPlayTime ; keep track of time played
-
- ld a, [$fff9]
- and a
- call z, ReadJoypad
+
+ ld a, $2
+ call BankswitchCommon
+ call Music2_UpdateMusic
+
+ call SerialFunction ; add this
ld a, [wd122]
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
+ pop af
+ ld [rVBK],a
+
pop hl
pop de
pop bc
diff --git a/home/vcopy.asm b/home/vcopy.asm
index d42293d9..33262b85 100644
--- a/home/vcopy.asm
+++ b/home/vcopy.asm
@@ -36,7 +36,7 @@ ClearBgMap:: ; 1cf0 (0:1cf0)
; 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)
+RedrawExposedScreenEdge:: ; 1ada (0:1ada)
ld a,[H_SCREENEDGEREDRAW]
and a
ret z
@@ -115,15 +115,11 @@ RedrawExposedScreenEdge:: ; 1d01 (0:1d01)
; on when talking to sprites, battling, using menus, etc. This is because
; the above function, RedrawExposedScreenEdge, is used when walking to
; improve efficiency.
-AutoBgMapTransfer:: ; 1d57 (0:1d57)
+AutoBgMapTransfer:: ; 1b30 (0:1b30)
ld a,[H_AUTOBGTRANSFERENABLED]
and a
ret z
- ld hl,[sp + 0]
- ld a,h
- ld [H_SPTEMP],a
- ld a,l
- ld [H_SPTEMP + 1],a ; save stack pinter
+ ld [H_SPTEMP],sp ; save stack pinter
ld a,[H_AUTOBGTRANSFERPORTION]
and a
jr z,.transferTopThird
@@ -197,15 +193,11 @@ 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:: ; 1bb5 (0:1bb5)
ld a,[H_VBCOPYBGSRC] ; doubles as enabling byte
and a
ret z
- ld hl,[sp + 0]
- ld a,h
- ld [H_SPTEMP],a
- ld a,l
- ld [H_SPTEMP + 1],a ; save stack pointer
+ ld [H_SPTEMP],sp ; save stack pointer
ld a,[H_VBCOPYBGSRC]
ld l,a
ld a,[H_VBCOPYBGSRC + 1]
@@ -222,7 +214,7 @@ VBlankCopyBgMap:: ; 1de1 (0:1de1)
jr TransferBgRows
-VBlankCopyDouble::
+VBlankCopyDouble:: ; 1bd1 (0:1bd1)
; Copy [H_VBCOPYDOUBLESIZE] 1bpp tiles
; from H_VBCOPYDOUBLESRC to H_VBCOPYDOUBLEDEST.
@@ -234,11 +226,7 @@ VBlankCopyDouble::
and a
ret z
- ld hl, [sp + 0]
- ld a, h
- ld [H_SPTEMP], a
- ld a, l
- ld [H_SPTEMP + 1], a
+ ld [H_SPTEMP],sp ; save stack pointer
ld a, [H_VBCOPYDOUBLESRC]
ld l, a
@@ -281,16 +269,9 @@ VBlankCopyDouble::
dec b
jr nz, .loop
- ld a, l
- ld [H_VBCOPYDOUBLEDEST], a
- ld a, h
- ld [H_VBCOPYDOUBLEDEST + 1], a
-
- ld hl, [sp + 0]
- ld a, l
- ld [H_VBCOPYDOUBLESRC], a
- ld a, h
- ld [H_VBCOPYDOUBLESRC + 1], a
+ ld [H_VBCOPYDOUBLESRC],sp
+ ld sp,hl ; load destination into sp to save time with ld [$xxxx],sp
+ ld [H_VBCOPYDOUBLEDEST], sp
ld a, [H_SPTEMP]
ld h, a
@@ -301,7 +282,7 @@ VBlankCopyDouble::
ret
-VBlankCopy::
+VBlankCopy:: ; 1c21 (0:1c21)
; Copy [H_VBCOPYSIZE] 2bpp tiles
; from H_VBCOPYSRC to H_VBCOPYDEST.
@@ -313,11 +294,7 @@ VBlankCopy::
and a
ret z
- ld hl, [sp + 0]
- ld a, h
- ld [H_SPTEMP], a
- ld a, l
- ld [H_SPTEMP + 1], a
+ ld [H_SPTEMP],sp
ld a, [H_VBCOPYSRC]
ld l, a
@@ -352,17 +329,10 @@ VBlankCopy::
dec b
jr nz, .loop
- ld a, l
- ld [H_VBCOPYDEST], a
- ld a, h
- ld [H_VBCOPYDEST + 1], a
-
- ld hl, [sp + 0]
- ld a, l
- ld [H_VBCOPYSRC], a
- ld a, h
- ld [H_VBCOPYSRC + 1], a
-
+ ld [H_VBCOPYSRC],sp
+ ld sp,hl
+ ld [H_VBCOPYDEST],sp
+
ld a, [H_SPTEMP]
ld h, a
ld a, [H_SPTEMP + 1]
@@ -372,7 +342,7 @@ VBlankCopy::
ret
-UpdateMovingBgTiles::
+UpdateMovingBgTiles:: ; 1c75 (0:1c75)
; Animate water and flower
; tiles in the overworld.
@@ -380,6 +350,10 @@ UpdateMovingBgTiles::
and a
ret z ; no animations if indoors (or if a menu set this to 0)
+ ld a,[rLY]
+ cp $90 ; check if not in vblank period??? (maybe if vblank is too long)
+ ret c
+
ld a, [$ffd8]
inc a
ld [$ffd8], a
diff --git a/hram.asm b/hram.asm
index a6035b59..d203a727 100644
--- a/hram.asm
+++ b/hram.asm
@@ -155,9 +155,12 @@ H_CURRENTSPRITEOFFSET EQU $FFDA ; multiple of $10
H_WHOSETURN EQU $FFF3 ; 0 on player’s turn, 1 on enemy’s turn
+hJoyInput EQU $FFF5
+
; bit 0: draw HP fraction to the right of bar instead of below (for party menu)
; bit 1: menu is double spaced
-hFlags_0xFFF6 EQU $FFF6
+hFlags_0xFFF6 EQU $FFFA
-hJoyInput EQU $FFF8
+hFlags_0xFFFA EQU $FFFA
+hGBC EQU $FFFE ; 0 if DMG, 1 if GBC
diff --git a/macros.asm b/macros.asm
index b80f1442..1a7aae56 100644
--- a/macros.asm
+++ b/macros.asm
@@ -25,18 +25,57 @@ const_value = const_value + 1
ENDM
+homecall_jump: MACRO
+ ld a, [H_LOADEDROMBANK]
+ push af
+ ld a, BANK(\1)
+ call BankswitchCommon
+ call \1
+ pop af
+ jp BankswitchCommon
+ ENDM
+
+homecall_jump_sf: MACRO
+ ld a, [H_LOADEDROMBANK]
+ push af
+ ld a, BANK(\1)
+ call BankswitchCommon
+ call \1
+ pop bc
+ jp BankswitchCommon
+ ENDM
+
homecall: MACRO
ld a, [H_LOADEDROMBANK]
push af
ld a, BANK(\1)
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ call BankswitchCommon
call \1
pop af
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
+ call BankswitchCommon
ENDM
+homecall_sf: MACRO ; homecall but save flags by popping into bc instead of af
+ ld a, [H_LOADEDROMBANK]
+ push af
+ ld a, BANK(\1)
+ call BankswitchCommon
+ call \1
+ pop bc
+ ld a,b
+ call BankswitchCommon
+ ENDM
+
+switchbank: MACRO
+ ld a, BANK(\1)
+ call BankswitchCommon
+ ENDM
+
+callsb: MACRO
+ ld a, BANK(\1)
+ call BankswitchCommon
+ call \1
+
callba: MACRO
ld b, BANK(\1)
ld hl, \1
diff --git a/main.asm b/main.asm
index a3088c40..96b22a64 100755
--- a/main.asm
+++ b/main.asm
@@ -4772,7 +4772,6 @@ INCLUDE "engine/battle/moveEffects/recoil_effect.asm"
INCLUDE "engine/battle/moveEffects/conversion_effect.asm"
INCLUDE "engine/battle/moveEffects/haze_effect.asm"
INCLUDE "engine/battle/get_trainer_name.asm"
-INCLUDE "engine/random.asm"
SECTION "NPC Sprites 2", ROMX, BANK[NPC_SPRITES_2]
@@ -6670,12 +6669,16 @@ INCLUDE "engine/overworld/elevator.asm"
INCLUDE "engine/items/tm_prices.asm"
-IF DEF(_OPTION_BEACH_HOUSE)
-SECTION "bank3C",ROMX[$4314],BANK[$3C]
+SECTION "bank3c",ROMX,BANK[$3C]
-BeachHouse_GFX:
- INCBIN "gfx/tilesets/beachhouse.2bpp"
+INCLUDE "yellow/bank3c/main.asm"
-BeachHouse_Block:
- INCBIN "gfx/blocksets/beachhouse.bst"
-ENDC
+SECTION "bank3d",ROMX,BANK[$3D]
+
+INCLUDE "yellow/bank3d/random.asm"
+
+SECTION "bank3e",ROMX,BANK[$3E]
+
+SECTION "bank3f",ROMX,BANK[$3F]
+
+INCLUDE "yellow/bank3f/main.asm" \ No newline at end of file
diff --git a/scripts/celadongamecorner.asm b/scripts/celadongamecorner.asm
index 91d6742d..5dbbd06a 100755
--- a/scripts/celadongamecorner.asm
+++ b/scripts/celadongamecorner.asm
@@ -138,29 +138,29 @@ CeladonGameCornerText2: ; 48ca9 (12:4ca9)
call Has9990Coins
jr nc, .asm_31338 ; 0x48cc6
xor a
- ldh [$9f], a
- ldh [$a1], a
+ ld [$ff9f], a
+ ld [$ffa1], a
ld a, $10
- ldh [$a0], a
+ ld [$ffa0], a
call HasEnoughMoney
jr nc, .asm_b6ef0 ; 0x48cd4
ld hl, CeladonGameCornerText_48d31 ; $4d31
jr .asm_e2afd ; 0x48cd9
.asm_b6ef0 ; 0x48cdb
xor a
- ldh [$9f], a
- ldh [$a1], a
+ ld [$ff9f], a
+ ld [$ffa1], a
ld a, $10
- ldh [$a0], a
+ ld [$fa0], a
ld hl, $ffa1
ld de, wPlayerMoney + 2
ld c, $3
predef SubBCDPredef
xor a
- ldh [$9f], a
- ldh [$a0], a
+ ld [$ff9f], a
+ ld [$ffa0], a
ld a, $50
- ldh [$a1], a
+ ld [$ffa1], a
ld de, wPlayerCoins + 1
ld hl, $ffa1
ld c, $2
@@ -225,10 +225,10 @@ CeladonGameCornerText5: ; 48d4a (12:4d4a)
call Has9990Coins
jr nc, .asm_98546 ; 0x48d62
xor a
- ldh [$9f], a
- ldh [$a0], a
+ ld [$ff9f], a
+ ld [$ffa0], a
ld a, $10
- ldh [$a1], a
+ ld [$ffa1], a
ld de, wPlayerCoins + 1
ld hl, $ffa1
ld c, $2
@@ -307,10 +307,10 @@ CeladonGameCornerText9: ; 48dd9 (12:4dd9)
call Has9990Coins
jr nc, .asm_f17c3 ; 0x48df1
xor a
- ldh [$9f], a
- ldh [$a0], a
+ ld [$ff9f], a
+ ld [$ffa0], a
ld a, $20
- ldh [$a1], a
+ ld [$ffa1], a
ld de, wPlayerCoins + 1
ld hl, $ffa1
ld c, $2
@@ -360,10 +360,10 @@ CeladonGameCornerText10: ; 48e3b (12:4e3b)
call Has9990Coins
jr z, .asm_9505a ; 0x48e53
xor a
- ldh [$9f], a
- ldh [$a0], a
+ ld [$ff9f], a
+ ld [$ffa0], a
ld a, $20
- ldh [$a1], a
+ ld [$ffa1], a
ld de, wPlayerCoins + 1
ld hl, $ffa1
ld c, $2
@@ -415,9 +415,9 @@ CeladonGameCornerText11: ; 48e9d (12:4e9d)
call EngageMapTrainer
call InitBattleEnemyParameters
xor a
- ldh [$b4], a
- ldh [$b3], a
- ldh [$b2], a
+ ld [hJoyHeld], a
+ ldh [hJoyPressed], a
+ ldh [hJoyReleased], a
ld a, $1
ld [W_CELADONGAMECORNERCURSCRIPT], a
jp TextScriptEnd
diff --git a/scripts/ceruleangym.asm b/scripts/ceruleangym.asm
index 079844f3..f643e264 100755
--- a/scripts/ceruleangym.asm
+++ b/scripts/ceruleangym.asm
@@ -127,14 +127,14 @@ CeruleanGymText1: ; 5c771 (17:4771)
ld hl, CeruleanGymText_5c7d8
ld de, CeruleanGymText_5c7d8
call SaveEndBattleTextPointers
- ldh a, [$8c]
+ ld a, [H_SPRITEINDEX]
ld [wSpriteIndex], a
call EngageMapTrainer
call InitBattleEnemyParameters
ld a, $2
ld [W_GYMLEADERNO], a
xor a
- ldh [$b4], a
+ ld [hJoyHeld], a
ld a, $3
ld [W_CERULEANGYMCURSCRIPT], a
.asm_95b04 ; 0x5c7bb
diff --git a/scripts/copycatshouse2f.asm b/scripts/copycatshouse2f.asm
index b7a1255c..ed4e9a4f 100755
--- a/scripts/copycatshouse2f.asm
+++ b/scripts/copycatshouse2f.asm
@@ -30,7 +30,7 @@ CopycatsHouse2FText1: ; 5cc82 (17:4c82)
ld hl, ReceivedTM31Text
call PrintText
ld a, POKE_DOLL
- ldh [$db], a
+ ld [$ffdb], a
callba RemoveItemByID
ld hl, wd7af
set 0, [hl]
diff --git a/scripts/fuchsiahouse2.asm b/scripts/fuchsiahouse2.asm
index 33bae7e4..c8c250ab 100755
--- a/scripts/fuchsiahouse2.asm
+++ b/scripts/fuchsiahouse2.asm
@@ -34,7 +34,7 @@ FuchsiaHouse2Text1: ; 750c2 (1d:50c2)
ld hl, WardenTeethText1
call PrintText
ld a, GOLD_TEETH
- ldh [$db], a
+ ld [$ffdb], a
callba RemoveItemByID
ld hl, wd78e
set 1, [hl]
@@ -98,7 +98,7 @@ HM04NoRoomText: ; 7515e (1d:515e)
FuchsiaHouse2Text5: ; 75163 (1d:5163)
FuchsiaHouse2Text4: ; 75163 (1d:5163)
db $08 ; asm
- ldh a, [$8c]
+ ld a, [hSpriteIndexOrTextID]
cp $4
ld hl, FuchsiaHouse2Text_7517b
jr nz, .asm_4c9a2 ; 0x7516b
diff --git a/scripts/mtmoonpokecenter.asm b/scripts/mtmoonpokecenter.asm
index bfe9add8..080a64fe 100755
--- a/scripts/mtmoonpokecenter.asm
+++ b/scripts/mtmoonpokecenter.asm
@@ -35,10 +35,10 @@ MtMoonPokecenterText4: ; 492ec (12:52ec)
ld a, [wCurrentMenuItem]
and a
jp nz, .asm_4934e
- ldh [$9f], a
- ldh [$a1], a
+ ld [$ff9f], a
+ ld [$ffa1], a
ld a, $5
- ldh [$a0], a
+ ld [$ffa0], a
call HasEnoughMoney
jr nc, .asm_faa09 ; 0x49317
ld hl, MtMoonPokecenterText_49366
diff --git a/scripts/pewtercity.asm b/scripts/pewtercity.asm
index 55369df9..bd6872a1 100755
--- a/scripts/pewtercity.asm
+++ b/scripts/pewtercity.asm
@@ -208,12 +208,12 @@ PewterCityText3: ; 193b1 (6:53b1)
ld hl, PewterCityText_193fb
call PrintText
xor a
- ldh [$b3], a
- ldh [$b4], a
+ ld [hJoyPressed], a
+ ld [hJoyHeld], a
ld [wNPCMovementScriptFunctionNum], a
ld a, $2
ld [wNPCMovementScriptPointerTableNum], a
- ldh a, [$b8]
+ ld a, [H_LOADEDROMBANK]
ld [wNPCMovementScriptBank], a
ld a, $3
ld [wSpriteIndex], a
@@ -273,11 +273,11 @@ PewterCityText5: ; 19436 (6:5436)
ld hl, PewterCityText_1945d
call PrintText
xor a
- ldh [$b4], a
+ ld [hJoyHeld], a
ld [wNPCMovementScriptFunctionNum], a
ld a, $3
ld [wNPCMovementScriptPointerTableNum], a
- ldh a, [$b8]
+ ld a, [H_LOADEDROMBANK]
ld [wNPCMovementScriptBank], a
ld a, $5
ld [wSpriteIndex], a
diff --git a/scripts/pewtergym.asm b/scripts/pewtergym.asm
index 9f9c7c3b..8cb6696c 100755
--- a/scripts/pewtergym.asm
+++ b/scripts/pewtergym.asm
@@ -127,14 +127,14 @@ PewterGymText1: ; 5c44e (17:444e)
ld hl, PewterGymText_5c4bc
ld de, PewterGymText_5c4bc
call SaveEndBattleTextPointers
- ldh a, [$8c]
+ ld a, [H_SPRITEINDEX]
ld [wSpriteIndex], a
call EngageMapTrainer
call InitBattleEnemyParameters
ld a, $1
ld [W_GYMLEADERNO], a
xor a
- ldh [$b4], a
+ ld [hJoyHeld], a
ld a, $3
ld [W_PEWTERGYMCURSCRIPT], a
ld [W_CURMAPSCRIPT], a
diff --git a/scripts/rockethideout4.asm b/scripts/rockethideout4.asm
index f1b46653..845b7730 100755
--- a/scripts/rockethideout4.asm
+++ b/scripts/rockethideout4.asm
@@ -131,12 +131,12 @@ RocketHideout4Text1: ; 4553a (11:553a)
ld hl, RocketHideout4Text_4557f
ld de, RocketHideout4Text_4557f
call SaveEndBattleTextPointers
- ldh a, [$8c]
+ ld a, [H_SPRITEINDEX]
ld [wSpriteIndex], a
call EngageMapTrainer
call InitBattleEnemyParameters
xor a
- ldh [$b4], a
+ ld [hJoyHeld], a
ld a, $3
ld [W_ROCKETHIDEOUT4CURSCRIPT], a
ld [W_CURMAPSCRIPT], a
diff --git a/scripts/route2gate.asm b/scripts/route2gate.asm
index 8ee087c8..97067e70 100755
--- a/scripts/route2gate.asm
+++ b/scripts/route2gate.asm
@@ -11,9 +11,9 @@ Route2GateText1: ; 5d5db (17:55db)
bit 0, a
jr nz, .asm_6592c ; 0x5d5e1
ld a, 10 ; pokemon needed
- ldh [$db], a
+ ld [$ffdb], a
ld a, HM_05 ; oak's aide reward
- ldh [$dc], a
+ ld [$ffdc], a
ld [wd11e], a
call GetItemName ; $2fcf
ld hl, wcd6d
@@ -21,7 +21,7 @@ Route2GateText1: ; 5d5db (17:55db)
ld bc, $000d
call CopyData
predef OaksAideScript ; call oak's aide script
- ldh a, [$db]
+ ld a, [$ffdb]
cp $1
jr nz, .asm_ad646 ; 0x5d606
ld hl, wd7c2
diff --git a/scripts/ssanne6.asm b/scripts/ssanne6.asm
index d3ec191f..ded8e719 100755
--- a/scripts/ssanne6.asm
+++ b/scripts/ssanne6.asm
@@ -39,7 +39,7 @@ SSAnne6Text7: ; 617e3 (18:57e3)
db $08 ; asm
ld hl, SSAnne6Text_61807
call PrintText
- ldh a, [$d3]
+ ld a, [hRandomAdd]
bit 7, a
jr z, .asm_93eb1 ; 0x617ee
ld hl, SSAnne6Text_6180c
diff --git a/sram.asm b/sram.asm
new file mode 100644
index 00000000..26255d6b
--- /dev/null
+++ b/sram.asm
@@ -0,0 +1,33 @@
+SECTION "Sprite Buffers", SRAM, BANK[0]
+
+S_SPRITEBUFFER0:: ds SPRITEBUFFERSIZE ; a000
+S_SPRITEBUFFER1:: ds SPRITEBUFFERSIZE ; a188
+S_SPRITEBUFFER2:: ds SPRITEBUFFERSIZE ; a310
+
+ ds $100
+
+sHallOfFame:: ds HOF_TEAM * NUM_HOF_TEAMS ; a598
+
+SECTION "Save Data", SRAM, BANK[1]
+
+SECTION "Save Data Start", SRAM1[$a598]
+S_SAVEDPLAYERNAME:: ds 11 ; a598
+S_SAVEDMAINDATA:: ds W_NUMINBOX - wPokedexOwned ; a5a3
+S_SAVEDSPRITEDATA:: ds wOAMBuffer - wSpriteStateData1 ; ad2c
+S_SAVEDPARTYDATA:: ds wPokedexOwned - wPartyCount ; af2c
+S_SAVEDCURBOXDATA:: ds wBoxMonNicksEnd - W_NUMINBOX ; b0c0
+S_SAVEDhTilesetType:: ds 1 ; b522
+S_SAVEDMAINDATACHECKSUM:: ds 1 ; b523
+
+SECTION "Saved Boxes", SRAM, BANK[2] ; pointers used for bank 3 too
+
+S_BOXLENGTH EQU $462
+
+S_SAVEDBOX1:: ds S_BOXLENGTH ; a000
+S_SAVEDBOX2:: ds S_BOXLENGTH ; a462
+S_SAVEDBOX3:: ds S_BOXLENGTH ; a8c4
+S_SAVEDBOX4:: ds S_BOXLENGTH ; ad26
+S_SAVEDBOX5:: ds S_BOXLENGTH ; b188
+S_SAVEDBOX6:: ds S_BOXLENGTH ; b5ea
+S_SAVEDBOXESCHECKSUM:: ds 1 ; ba4c
+S_SAVEDBOXESCHECKSUM2:: ds 6 ; ba4d
diff --git a/wram.asm b/wram.asm
index 20da6231..f498297a 100755
--- a/wram.asm
+++ b/wram.asm
@@ -783,9 +783,6 @@ wNPCMovementScriptSpriteOffset:: ; cf17
wcf18:: ds 2 ; used with overworld movement
-wGBC:: ; cf1a
- ds 1
-
wOnSGB:: ; cf1b
; if running on SGB, it's 1, else it's 0
ds 1
@@ -1634,7 +1631,20 @@ wDestinationWarpID:: ; d42f
; if $ff, the player's coordinates are not updated when entering the map
ds 1
- ds 128
+wd430:: ds 1 ; d430
+wd431:: ds 1 ; d431
+
+ ds 3
+
+wd435:: ds 1
+wd436:: ds 1
+
+ ds 60
+
+wd472:: ds 1
+wd473:: ds 1
+
+ ds 61
wd4b0:: ds 1 ; number of signs on the map
wd4b1:: ds 32 ; starting address for sign coords
@@ -2296,12 +2306,4 @@ wStack:: ; dfff
ds -$100
-SECTION "Sprite Buffers", SRAM, BANK[0]
-
-S_SPRITEBUFFER0:: ds SPRITEBUFFERSIZE ; a000
-S_SPRITEBUFFER1:: ds SPRITEBUFFERSIZE ; a188
-S_SPRITEBUFFER2:: ds SPRITEBUFFERSIZE ; a310
-
- ds $100
-
-sHallOfFame:: ds HOF_TEAM * NUM_HOF_TEAMS ; a598
+INCLUDE "sram.asm"
diff --git a/yellow/audio.asm b/yellow/audio.asm
deleted file mode 100644
index e94c7db5..00000000
--- a/yellow/audio.asm
+++ /dev/null
@@ -1,2 +0,0 @@
-INCLUDE "yellow.asm"
-INCLUDE "audio.asm"
diff --git a/yellow/bank3c/main.asm b/yellow/bank3c/main.asm
new file mode 100644
index 00000000..c05f46f5
--- /dev/null
+++ b/yellow/bank3c/main.asm
@@ -0,0 +1,116 @@
+INCLUDE "yellow/bank3c/overworld.asm"
+
+ResetStatusAndHalveMoneyOnBlackout:: ; f0274 (3c:4274)
+; Reset player status on blackout.
+ xor a
+ ld [wd435],a
+ xor a ; gamefreak copypasting functions (double xor a)
+ ld [wBattleResult], a
+ ld [wWalkBikeSurfState], a
+ ld [W_ISINBATTLE], a
+ ld [wMapPalOffset], a
+ ld [wNPCMovementScriptFunctionNum], a
+ ld [hJoyHeld], a
+ ld [wNPCMovementScriptPointerTableNum], a
+ ld [wFlags_0xcd60], a
+
+ ld [$ff9f], a
+ ld [$ff9f + 1], a
+ ld [$ff9f + 2], a
+ call HasEnoughMoney
+ jr c, .lostmoney ; never happens
+
+ ; Halve the player's money.
+ ld a, [wPlayerMoney]
+ ld [$ff9f], a
+ ld a, [wPlayerMoney + 1]
+ ld [$ff9f + 1], a
+ ld a, [wPlayerMoney + 2]
+ ld [$ff9f + 2], a
+ xor a
+ ld [$ffa2], a
+ ld [$ffa3], a
+ ld a, 2
+ ld [$ffa4], a
+ predef DivideBCDPredef3
+ ld a, [$ffa2]
+ ld [wPlayerMoney], a
+ ld a, [$ffa2 + 1]
+ ld [wPlayerMoney + 1], a
+ ld a, [$ffa2 + 2]
+ ld [wPlayerMoney + 2], a
+
+.lostmoney
+ ld hl, wd732
+ set 2, [hl]
+ res 3, [hl]
+ set 6, [hl]
+ ld a, %11111111
+ ld [wJoyIgnore], a
+ predef_jump HealParty
+
+Func_f02da:: ; f02da (3c:42da)
+ ld a,[W_CURMAP]
+ cp VERMILION_GYM ; ??? new thing about verm gym?
+ jr z,.asm_f02ee
+ ld c,a
+ ld hl,Pointer_f02fa
+.asm_f02e5
+ ld a,[hli]
+ cp c
+ jr z,.asm_f02f4
+ cp a,$ff
+ jr nz,.asm_f02e5
+ ret
+.asm_f02ee
+ ld hl,wd126
+ set 6,[hl]
+ ret
+.asm_f02f4
+ ld hl,wd126
+ set 5,[hl]
+ ret
+
+Pointer_f02fa:: ; f02fa (3c:42fa)
+ db $cf,$d0,$d1,$d2,$d3,$d4
+ db $d5,$e9,$ea,$eb,$d6,$d7
+ db $d8,$a5,$a6,$87,$c7,$ca
+ db $c6,$6c,$c2,$71,$f5,$f6
+ db $f7,$ff
+
+BeachHouse_GFX:: ; f0314 (3c:4314)
+ INCBIN "gfx/tilesets/beachhouse.2bpp"
+
+BeachHouse_Block:: ; f0914 (3c:4914)
+ INCBIN "gfx/blocksets/beachhouse.bst"
+
+Func_f0a55:: ; f0a55 (3c:4a55)
+ ld hl,Pointer_f0a76 ; 3c:4a76
+.loop
+ ld a,[hli]
+ cp a,$ff
+ ret z
+ ld b,a
+ ld a,[W_CURMAP]
+ cp b
+ jr z,.asm_f0a68
+ inc hl
+ inc hl
+ inc hl
+ jr .loop
+
+.asm_f0a68
+ ld a,[hli]
+ ld c,a
+ ld b,$0
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ ld de,W_MISSABLEOBJECTLIST
+ call CopyData
+ ret
+
+Pointer_f0a76:: ; f0a76 (3c:4a76)
+ db $27,$07,$7b,$4a,$ff
+ db $01,$ec,$02,$ed,$03,$ee,$ff
+
diff --git a/yellow/bank3c/overworld.asm b/yellow/bank3c/overworld.asm
new file mode 100644
index 00000000..778244d6
--- /dev/null
+++ b/yellow/bank3c/overworld.asm
@@ -0,0 +1,242 @@
+_AdvancePlayerSprite:: ; f010c (3c:410c)
+ ld a,[wSpriteStateData1 + 3] ; delta Y
+ ld b,a
+ ld a,[wSpriteStateData1 + 5] ; delta X
+ ld c,a
+ ld hl,wWalkCounter ; walking animation counter
+ dec [hl]
+ jr nz,.afterUpdateMapCoords
+; if it's the end of the animation, update the player's map coordinates
+ ld a,[W_YCOORD]
+ add b
+ ld [W_YCOORD],a
+ ld a,[W_XCOORD]
+ add c
+ ld [W_XCOORD],a
+.afterUpdateMapCoords
+ ld a,[wWalkCounter] ; walking animation counter
+ cp a,$07
+ jp nz,.scrollBackgroundAndSprites
+; if this is the first iteration of the animation
+ ld a,c
+ cp a,$01
+ jr nz,.checkIfMovingWest
+; moving east
+ ld a,[wMapViewVRAMPointer]
+ ld e,a
+ and a,$e0
+ ld d,a
+ ld a,e
+ add a,$02
+ and a,$1f
+ or d
+ ld [wMapViewVRAMPointer],a
+ jr .adjustXCoordWithinBlock
+.checkIfMovingWest
+ cp a,$ff
+ jr nz,.checkIfMovingSouth
+; moving west
+ ld a,[wMapViewVRAMPointer]
+ ld e,a
+ and a,$e0
+ ld d,a
+ ld a,e
+ sub a,$02
+ and a,$1f
+ or d
+ ld [wMapViewVRAMPointer],a
+ jr .adjustXCoordWithinBlock
+.checkIfMovingSouth
+ ld a,b
+ cp a,$01
+ jr nz,.checkIfMovingNorth
+; moving south
+ ld a,[wMapViewVRAMPointer]
+ add a,$40
+ ld [wMapViewVRAMPointer],a
+ jr nc,.adjustXCoordWithinBlock
+ ld a,[wMapViewVRAMPointer + 1]
+ inc a
+ and a,$03
+ or a,$98
+ ld [wMapViewVRAMPointer + 1],a
+ jr .adjustXCoordWithinBlock
+.checkIfMovingNorth
+ cp a,$ff
+ jr nz,.adjustXCoordWithinBlock
+; moving north
+ ld a,[wMapViewVRAMPointer]
+ sub a,$40
+ ld [wMapViewVRAMPointer],a
+ jr nc,.adjustXCoordWithinBlock
+ ld a,[wMapViewVRAMPointer + 1]
+ dec a
+ and a,$03
+ or a,$98
+ ld [wMapViewVRAMPointer + 1],a
+.adjustXCoordWithinBlock
+ ld a,c
+ and a
+ jr z,.pointlessJump ; mistake?
+.pointlessJump
+ ld hl,W_XBLOCKCOORD
+ ld a,[hl]
+ add c
+ ld [hl],a
+ cp a,$02
+ jr nz,.checkForMoveToWestBlock
+; moved into the tile block to the east
+ xor a
+ ld [hl],a
+ ld hl,wXOffsetSinceLastSpecialWarp
+ inc [hl]
+ ld de,wCurrentTileBlockMapViewPointer
+ call MoveTileBlockMapPointerEast
+ jr .updateMapView
+.checkForMoveToWestBlock
+ cp a,$ff
+ jr nz,.adjustYCoordWithinBlock
+; moved into the tile block to the west
+ ld a,$01
+ ld [hl],a
+ ld hl,wXOffsetSinceLastSpecialWarp
+ dec [hl]
+ ld de,wCurrentTileBlockMapViewPointer
+ call MoveTileBlockMapPointerWest
+ jr .updateMapView
+.adjustYCoordWithinBlock
+ ld hl,W_YBLOCKCOORD
+ ld a,[hl]
+ add b
+ ld [hl],a
+ cp a,$02
+ jr nz,.checkForMoveToNorthBlock
+; moved into the tile block to the south
+ xor a
+ ld [hl],a
+ ld hl,wYOffsetSinceLastSpecialWarp
+ inc [hl]
+ ld de,wCurrentTileBlockMapViewPointer
+ ld a,[W_CURMAPWIDTH]
+ call MoveTileBlockMapPointerSouth
+ jr .updateMapView
+.checkForMoveToNorthBlock
+ cp a,$ff
+ jr nz,.updateMapView
+; moved into the tile block to the north
+ ld a,$01
+ ld [hl],a
+ ld hl,wYOffsetSinceLastSpecialWarp
+ dec [hl]
+ ld de,wCurrentTileBlockMapViewPointer
+ ld a,[W_CURMAPWIDTH]
+ call MoveTileBlockMapPointerNorth
+.updateMapView
+ call LoadCurrentMapView
+ ld a,[wSpriteStateData1 + 3] ; delta Y
+ cp a,$01
+ jr nz,.checkIfMovingNorth2
+; if moving south
+ call ScheduleSouthRowRedraw
+ jr .scrollBackgroundAndSprites
+.checkIfMovingNorth2
+ cp a,$ff
+ jr nz,.checkIfMovingEast2
+; if moving north
+ call ScheduleNorthRowRedraw
+ jr .scrollBackgroundAndSprites
+.checkIfMovingEast2
+ ld a,[wSpriteStateData1 + 5] ; delta X
+ cp a,$01
+ jr nz,.checkIfMovingWest2
+; if moving east
+ call ScheduleEastColumnRedraw
+ jr .scrollBackgroundAndSprites
+.checkIfMovingWest2
+ cp a,$ff
+ jr nz,.scrollBackgroundAndSprites
+; if moving west
+ call ScheduleWestColumnRedraw
+.scrollBackgroundAndSprites
+ ld a,[wSpriteStateData1 + 3] ; delta Y
+ ld b,a
+ ld a,[wSpriteStateData1 + 5] ; delta X
+ ld c,a
+ sla b
+ sla c
+ ld a,[hSCY]
+ add b
+ ld [hSCY],a ; update background scroll Y
+ ld a,[hSCX]
+ add c
+ ld [hSCX],a ; update background scroll X
+; 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
+ and a ; are there any sprites?
+ jr z,.done
+ ld e,a
+.spriteShiftLoop
+ ld a,[hl]
+ sub b
+ ld [hli],a
+ inc l
+ ld a,[hl]
+ sub c
+ ld [hl],a
+ ld a,$0e
+ add l
+ ld l,a
+ dec e
+ jr nz,.spriteShiftLoop
+.done
+ ret
+
+MoveTileBlockMapPointerEast:: ; 0e65 (0:0e65)
+ ld a,[de]
+ add a,$01
+ ld [de],a
+ ret nc
+ inc de
+ ld a,[de]
+ inc a
+ ld [de],a
+ ret
+
+MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f)
+ ld a,[de]
+ sub a,$01
+ ld [de],a
+ ret nc
+ inc de
+ ld a,[de]
+ dec a
+ ld [de],a
+ ret
+
+MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
+ add a,$06
+ ld b,a
+ ld a,[de]
+ add b
+ ld [de],a
+ ret nc
+ inc de
+ ld a,[de]
+ inc a
+ ld [de],a
+ ret
+
+MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
+ add a,$06
+ ld b,a
+ ld a,[de]
+ sub b
+ ld [de],a
+ ret nc
+ inc de
+ ld a,[de]
+ dec a
+ ld [de],a
+ ret \ No newline at end of file
diff --git a/yellow/bank3d/random.asm b/yellow/bank3d/random.asm
new file mode 100644
index 00000000..b7fb0edd
--- /dev/null
+++ b/yellow/bank3d/random.asm
@@ -0,0 +1,15 @@
+SECTION "bank3d",ROMX[$67DC],BANK[$3D]
+
+Random_::
+; Generate a random 16-bit value.
+ ld a, [rDIV]
+ ld b, a
+ ld a, [hRandomAdd]
+ adc b
+ ld [hRandomAdd], a
+ ld a, [rDIV]
+ ld b, a
+ ld a, [hRandomSub]
+ sbc b
+ ld [hRandomSub], a
+ ret
diff --git a/data/map_header_banks.asm b/yellow/bank3f/data/map_header_banks.asm
index f6bd8d99..94a13510 100755..100644
--- a/data/map_header_banks.asm
+++ b/yellow/bank3f/data/map_header_banks.asm
@@ -1,5 +1,5 @@
; see also MapHeaderPointers
-MapHeaderBanks: ; c23d (3:423d)
+MapHeaderBanks:: ; fc3e4 (3f:43e4)
db BANK(PalletTown_h) ;PALLET_TOWN
db BANK(ViridianCity_h) ; VIRIDIAN_CITY
db BANK(PewterCity_h) ; PEWTER_CITY
@@ -248,6 +248,4 @@ MapHeaderBanks: ; c23d (3:423d)
db BANK(Lorelei_h)
db BANK(Bruno_h)
db BANK(Agatha_h)
-IF DEF(_OPTION_BEACH_HOUSE)
db BANK(BeachHouse_h)
-ENDC
diff --git a/data/map_header_pointers.asm b/yellow/bank3f/data/map_header_pointers.asm
index 771989a5..5431727e 100755..100644
--- a/data/map_header_pointers.asm
+++ b/yellow/bank3f/data/map_header_pointers.asm
@@ -1,5 +1,5 @@
; see also MapHeaderBanks
-MapHeaderPointers:: ; 01ae (0:01ae)
+MapHeaderPointers:: ; fc1f2 (3f:41f2)
dw PalletTown_h
dw ViridianCity_h
dw PewterCity_h
@@ -248,6 +248,4 @@ MapHeaderPointers:: ; 01ae (0:01ae)
dw Lorelei_h
dw Bruno_h
dw Agatha_h ;247
-IF DEF(_OPTION_BEACH_HOUSE)
dw BeachHouse_h
-ENDC
diff --git a/data/map_songs.asm b/yellow/bank3f/data/map_songs.asm
index 1d7ab269..4a84aebb 100755..100644
--- a/data/map_songs.asm
+++ b/yellow/bank3f/data/map_songs.asm
@@ -1,4 +1,4 @@
-MapSongBanks: ; c04d (3:404d)
+MapSongBanks: ; fc000 (3f:4000)
db MUSIC_PALLET_TOWN, BANK(Music_PalletTown) ;PALLET_TOWN
db MUSIC_CITIES1, BANK(Music_Cities1) ; VIRIDIAN_CITY
db MUSIC_CITIES1, BANK(Music_Cities1) ; PEWTER_CITY
diff --git a/yellow/bank3f/main.asm b/yellow/bank3f/main.asm
new file mode 100644
index 00000000..b51d19b1
--- /dev/null
+++ b/yellow/bank3f/main.asm
@@ -0,0 +1,217 @@
+INCLUDE "yellow/bank3f/data/map_songs.asm"
+INCLUDE "yellow/bank3f/data/map_header_pointers.asm"
+INCLUDE "yellow/bank3f/data/map_header_banks.asm"
+
+Func_fc4dd:: ; fc4dd (3f:44dd)
+; possibly to test if pika should be out?
+ ld a,[wd430]
+ bit 5,a
+ jr nz,.asm_fc4f8 ; 3f:44f8
+ ld a,[wd430]
+ bit 7,a
+ jr nz,.asm_fc4f8
+ call Func_fcdb8
+ jr nc,.asm_fc4f8
+ ld a,[wWalkBikeSurfState]
+ and a
+ jr nz,.asm_fc4f8
+ scf
+ ret
+.asm_fc4f8
+ and a
+ ret
+
+Func_fc5fa:: ; fc5fa (3f:44fa)
+ ld hl,wd430
+ bit 4,[hl]
+ res 4,[hl]
+ jr nz,.asm_fc515
+ call Func_1542
+ call Func_fc523
+ ld a,$ff
+ ld [wSpriteStateData1 + $f2],a
+ call Func_fcb84
+ call Func_fc5bc
+ ret
+
+.asm_fc515
+ call Func_fc53f
+ xor a
+ ld [wd431],a
+ ld a,[wSpriteStateData1 + $9]
+ ld [wSpriteStateData1 + $f9],a
+ ret
+
+Func_fc523:: ; fc523 (3f:4523)
+ ld hl,wSpriteStateData1 + $f0
+ call Func_fc52c
+ ld hl,wSpriteStateData2 + $f0
+Func_fc52c:: ; fc52c (3f:4523)
+ ld bc,$10
+ xor a
+ call FillMemory
+ ret
+
+Func_fc534:: ; fc534 (3f:4534)
+ call Func_fc53f
+ call Func_fc5bc
+ xor a
+ ld [wd431],a
+ ret
+
+Func_fc53f:: ; fc53f (3f:453f)
+ ld bc,wSpriteStateData1 + $10
+ ld a,[W_YCOORD]
+ add $4
+ ld e,a
+ ld a,[W_XCOORD]
+ add $4
+ ld d,a
+ ld a,[wd431]
+ and a
+ jr z,.asm_fc5aa
+ cp $1
+ jr z,.asm_fc59e
+ cp $2
+ jr z,.asm_fc584
+ cp $3
+ jr z,.asm_fc5aa
+ cp $4
+ jr z,.asm_fc5a4
+ cp $5
+ jr z,.asm_fc5a7
+ cp $6
+ jr z,.asm_fc5a1
+ cp $7
+ jr z,.asm_fc572
+ jr .asm_fc59e
+
+.asm_fc572
+ ld a,[wSpriteStateData1 + $9]
+ and a ; SPRITE_FACING_DOWN
+ jr z,.asm_fc5a4
+ cp SPRITE_FACING_UP
+ jr z,.asm_fc5a7
+ cp SPRITE_FACING_LEFT
+ jr z,.asm_fc5a1
+ cp SPRITE_FACING_RIGHT
+ jr z,.asm_fc59e
+.asm_fc584
+ ld a,[wSpriteStateData1 + $9]
+ and a
+ jr nz,.asm_fc58d
+ dec e
+ jr .asm_fc5aa
+.asm_fc58d
+ cp SPRITE_FACING_UP
+ jr nz,.asm_fc594
+ inc e
+ jr .asm_fc5aa
+.asm_fc594
+ cp SPRITE_FACING_LEFT
+ jr nz,.asm_fc59b
+ inc d
+ jr .asm_fc5aa
+.asm_fc59b
+ dec d
+ jr .asm_fc5aa
+.asm_fc59e
+ inc d
+ jr .asm_fc5aa
+.asm_fc5a1
+ dec d
+ jr .asm_fc5aa
+.asm_fc5a4
+ inc e
+ jr .asm_fc5aa
+.asm_fc5a7
+ dec e
+ jr .asm_fc5aa ; useless jr
+.asm_fc5aa
+ ld hl,$104
+ add hl,bc
+ ld [hl],e
+ inc hl
+ ld [hl],d
+ inc hl
+Func_fc4b2:: ; fc4b2 (3f:44b2)
+ ld [hl],$fe
+ push hl
+ ld hl,wd472
+ set 5,[hl]
+ pop hl
+ ret
+
+Func_fc5bc:: ; fc5bc (3f:45bc)
+ ld a,$49
+ ld [wSpriteStateData1 + $f0],a
+ ld a,$ff
+ ld [wSpriteStateData1 + $f2],a
+ ld a,[wd431]
+ and a
+ jr z,.asm_fc5e4
+ cp $1
+ jr z,.asm_fc5e4
+ cp $3
+ jr z,.asm_fc5eb
+ cp $4
+ jr z,.asm_fc5e4
+ cp $6
+ jr z,.asm_fc5e4
+ cp $7
+ jr z,.asm_fc5f1
+ call Func_fc4b2
+ ret
+
+.asm_fc5e4
+ ld a,[wSpriteStateData1 + $9]
+ ld [wSpriteStateData1 + $f9],a
+ ret
+.asm_fc5eb
+ ld a,$0
+ ld [wSpriteStateData1 + $f9],a
+ ret
+.asm_fc5f1
+ ld a,[wSpriteStateData1 + $9]
+ xor $4
+ ld [wSpriteStateData1 + $f9],a
+ ret
+
+Func_fc5fa:: ; fc5fa (3f:45fa)
+ ld a,[W_CURMAP]
+ cp OAKS_LAB
+ jr z,.asm_fc63d
+ cp ROUTE_22_GATE
+ jr z,.asm_fc62d
+ cp MT_MOON_2
+ jr z,.asm_fc635
+ cp ROCK_TUNNEL_1
+ jr z,.asm_fc645
+ ld a,[W_CURMAP]
+ ld hl,Pointer_fc46b
+ call Func_1568 ; similar to IsInArray, but not the same
+ jr c,.asm_fc639
+ ld a,[W_CURMAP]
+ ld hl,Pointer_fc653
+ call Func_1568
+ jr nc,.asm_fc641
+ ld a,[wSpriteStateData1 + $9]
+ and a
+ jr nz,.asm_fc641
+ ld a,$3
+ jr .asm_fc647
+
+.asm_fc62d
+ ld a,[wSpriteStateData1 + $9]
+ and a
+ jr z,.asm_fc645
+ jr .asm_fc641
+.asm_fc635
+
+Func_fc65b:: ; fc65b (3f:465b)
+
+Func_fc69a:: ; fc69a (3f:469a)
+
+Func_fcc08:: ; fcc08 (3f:4c08)
+
+Func_fcf0c:: ; fcf0c (3f:4f0c)
diff --git a/yellow/main.asm b/yellow/main.asm
deleted file mode 100644
index 36c88720..00000000
--- a/yellow/main.asm
+++ /dev/null
@@ -1,2 +0,0 @@
-INCLUDE "yellow.asm"
-INCLUDE "main.asm"
diff --git a/yellow/text.asm b/yellow/text.asm
deleted file mode 100644
index a84a633d..00000000
--- a/yellow/text.asm
+++ /dev/null
@@ -1,2 +0,0 @@
-INCLUDE "yellow.asm"
-INCLUDE "text.asm"
diff --git a/yellow/wram.asm b/yellow/wram.asm
deleted file mode 100644
index c0b7f781..00000000
--- a/yellow/wram.asm
+++ /dev/null
@@ -1,2 +0,0 @@
-INCLUDE "yellow.asm"
-INCLUDE "wram.asm"