ref: 3fdb8a0d8995746d5605136ece384516338489b0
parent: 9de54645c896cc57a79679aecd6174afc59762c8
author: YamaArashi <shadow962@live.com>
date: Fri Feb 6 21:43:08 EST 2015
serial/trade/misc
--- a/constants/hardware_constants.asm
+++ b/constants/hardware_constants.asm
@@ -30,6 +30,9 @@
OAM_Y_FLIP EQU 6
OAM_PRIORITY EQU 7 ; 0: OBJ above BG, 1: OBJ behind BG (colors 1-3)
+; serial
+START_TRANSFER_EXTERNAL_CLOCK EQU $80
+START_TRANSFER_INTERNAL_CLOCK EQU $81
; Hardware registers
rJOYP EQU $ff00 ; Joypad (R/W)
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -26,4 +26,40 @@
NPC_MOVEMENT_DOWN EQU $00
NPC_MOVEMENT_UP EQU $40
NPC_MOVEMENT_LEFT EQU $80
-NPC_MOVEMENT_RIGHT EQU $C0
\ No newline at end of file
+NPC_MOVEMENT_RIGHT EQU $C0
+
+; two option menu constants
+YES_NO_MENU EQU 0
+NORTH_WEST_MENU EQU 1
+SOUTH_EAST_MENU EQU 2
+WIDE_YES_NO_MENU EQU 3
+NORTH_EAST_MENU EQU 4
+TRADE_CANCEL_MENU EQU 5
+HEAL_CANCEL_MENU EQU 6
+NO_YES_MENU EQU 7
+
+; serial
+
+ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK EQU $01
+ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK EQU $02
+
+USING_EXTERNAL_CLOCK EQU $01
+USING_INTERNAL_CLOCK EQU $02
+CONNECTION_NOT_ESTABLISHED EQU $ff
+
+; signals the start of an array of bytes transferred over the link cable
+SERIAL_PREAMBLE_BYTE EQU $FD
+
+; this byte is used when there is no data to send
+SERIAL_NO_DATA_BYTE EQU $FE
+
+; signals the end of one part of a patch list (there are two parts) for player/enemy party data
+SERIAL_PATCH_LIST_PART_TERMINATOR EQU $FF
+
+LINK_STATE_NONE EQU $00 ; not using link
+LINK_STATE_IN_CABLE_CLUB EQU $01 ; in a cable club room (Colosseum or Trade Centre)
+LINK_STATE_START_TRADE EQU $02 ; pre-trade selection screen initialisation
+LINK_STATE_START_BATTLE EQU $03 ; pre-battle initialisation
+LINK_STATE_BATTLING EQU $04 ; in a link battle
+LINK_STATE_RESET EQU $05 ; reset game (unused)
+LINK_STATE_TRADING EQU $32 ; in a link trade
\ No newline at end of file
--- a/constants/move_constants.asm
+++ b/constants/move_constants.asm
@@ -175,10 +175,10 @@
const STATUS_AFFECTED_ANIM
const ANIM_A8
const ANIM_A9
- const ANIM_AA
- const ANIM_AB
- const ANIM_AC
- const ANIM_AD
+ const TRADE_BALL_DROP_ANIM
+ const TRADE_BALL_SHAKE_ANIM
+ const TRADE_BALL_TILT_ANIM
+ const TRADE_BALL_POOF_ANIM
const XSTATITEM_ANIM ; use X Attack/Defense/Speed/Special
const ANIM_AF
const ANIM_B0
--- a/constants/wram_constants.asm
+++ b/constants/wram_constants.asm
@@ -2,13 +2,9 @@
SPRITEBUFFERSIZE EQU 7*7 * 8 ; 7 * 7 (tiles) * 8 (bytes per tile)
; Overload W_GRASSMONS
-wd893 EQU $d893 ; W_GRASSMONS + 11
-wd896 EQU $d896 ; W_GRASSMONS + 14
+wSerialEnemyDataBlock EQU $d893 ; W_GRASSMONS + 11
; Overload enemy party data
W_WATERRATE EQU $d8a4 ; wEnemyMon1Species
W_WATERMONS EQU $d8a5 ; wEnemyMon1Species + 1
-
-; Overload enemy stat modifiers
-wTradeMonNick EQU $cd1e ; wPlayerMonAccuracyMod
--- a/data/hidden_objects.asm
+++ b/data/hidden_objects.asm
@@ -177,19 +177,19 @@
; format: y-coord, x-coord, text id/item id, object routine
BattleCenterHiddenObjects: ; 46b40 (11:6b40)
db $04,$05,$d0
- db BANK(PrintJustAMomentText2)
- dw PrintJustAMomentText2
+ db BANK(CableClubRightGameboy)
+ dw CableClubRightGameboy
db $04,$04,$d0
- db BANK(PrintJustAMomentText1)
- dw PrintJustAMomentText1
+ db BANK(CableClubLeftGameboy)
+ dw CableClubLeftGameboy
db $FF
TradeCenterHiddenObjects: ; 46b4d (11:6b4d)
db $04,$05,$d0
- db BANK(PrintJustAMomentText2)
- dw PrintJustAMomentText2
+ db BANK(CableClubRightGameboy)
+ dw CableClubRightGameboy
db $04,$04,$d0
- db BANK(PrintJustAMomentText1)
- dw PrintJustAMomentText1
+ db BANK(CableClubLeftGameboy)
+ dw CableClubLeftGameboy
db $FF
RedsHouse2FHiddenObjects: ; 46b5a (11:6b5a)
db $01,$00,$04
--- a/engine/battle/15.asm
+++ b/engine/battle/15.asm
@@ -1,6 +1,6 @@
GainExperience: ; 5524f (15:524f)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ret z ; return if link battle
call DivideExpDataByNumMonsGainingExp
ld hl, wPartyMon1
@@ -226,8 +226,8 @@
ld a, [W_PLAYERBATTSTATUS3]
bit 3, a ; is the mon transformed?
jr nz, .recalcStatChanges
-; the mon is transformed, so copy transformed data
- ld de, wcd0f
+; the mon is not transformed, so update the unmodified stats
+ ld de, wPlayerMonUnmodifiedLevel
ld bc, $b
call CopyData
.recalcStatChanges
--- a/engine/battle/1c.asm
+++ b/engine/battle/1c.asm
@@ -127,8 +127,8 @@
call Delay3
call LoadBattleTransitionTile
ld bc, $0
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr z, .linkBattle
call GetBattleTransitionID_WildOrTrainer
call GetBattleTransitionID_CompareLevels
--- a/engine/battle/4_2.asm
+++ b/engine/battle/4_2.asm
@@ -1,6 +1,6 @@
EndOfBattle: ; 137aa (4:77aa)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
; link battle
ld a, [wEnemyMonPartyPos]
@@ -110,7 +110,7 @@
jr z, .lastRepelStep
ld [wRepelRemainingSteps], a
.asm_1389e
-; determine if wild pokémon can appear in the half-block we’re standing
+; determine if wild pok�mon can appear in the half-block we�re standing
; is the bottom right tile (9,9) of the half-block are we standing a grass/water tile?
hlCoord 9, 9
ld c, [hl]
@@ -122,9 +122,9 @@
cp c
ld a, [W_WATERRATE]
jr z, .CanEncounter
-; even if not in grass/water, standing anywhere we can encounter pokémon
-; so long as the map is “indoor” and has wild pokémon defined.
-; …as long as it’s not Viridian Forest or Safari Zone.
+; even if not in grass/water, standing anywhere we can encounter pok�mon
+; so long as the map is �indoor� and has wild pok�mon defined.
+; �as long as it�s not Viridian Forest or Safari Zone.
ld a, [W_CURMAP]
cp REDS_HOUSE_1F ; is this an indoor map?
jr c, .CantEncounter
@@ -148,7 +148,7 @@
inc hl
jr .determineEncounterSlot
.gotEncounterSlot
-; determine which wild pokémon (grass or water) can appear in the half-block we’re standing
+; determine which wild pok�mon (grass or water) can appear in the half-block we�re standing
ld c, [hl]
ld hl, W_GRASSMONS
aCoord 8, 9
@@ -314,7 +314,7 @@
call Func_13a43
ld hl, wEnemyMonAttackMod
call Func_13a43
- ld hl, wcd12
+ ld hl, wPlayerMonUnmodifiedAttack
ld de, wBattleMonAttack
call Func_13a4a
ld hl, wEnemyMonUnmodifiedAttack
@@ -386,8 +386,8 @@
db "@"
GetTrainerName_: ; 13a58 (4:7a58)
- ld hl, W_GRASSRATE
- ld a, [W_ISLINKBATTLE]
+ ld hl, W_GRASSRATE
+ ld a, [wLinkState]
and a
jr nz, .rival
ld hl, W_RIVALNAME ; wd34a
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -528,9 +528,9 @@
ld [wcc79], a
ld b, $e4
ld a, [W_ANIMATIONID] ; W_ANIMATIONID
- cp ANIM_AA
+ cp TRADE_BALL_DROP_ANIM
jr c, .asm_78e3f
- cp ANIM_AD + 1
+ cp TRADE_BALL_POOF_ANIM + 1
jr nc, .asm_78e3f
ld b, $f0
.asm_78e3f
@@ -700,13 +700,13 @@
db ROCK_SLIDE
dw DoRockSlideSpecialEffects
- db ANIM_AA
+ db TRADE_BALL_DROP_ANIM
dw Func_79041
- db ANIM_AB
+ db TRADE_BALL_SHAKE_ANIM
dw Func_7904c
- db ANIM_AC
+ db TRADE_BALL_TILT_ANIM
dw Func_7907c
db TOSS_ANIM
@@ -960,9 +960,9 @@
ld c,5
call DelayFrames
pop bc
- ld a,[$ffae] ; background scroll X
+ ld a,[hSCX] ; background scroll X
sub a,8 ; scroll to the left
- ld [$ffae],a
+ ld [hSCX],a
pop de
jr .loop
@@ -1307,9 +1307,9 @@
AnimationSlideMonDown: ; 79297 (1e:5297)
; Slides the mon's sprite down out of the screen.
xor a
- call Func_79842
+ call GetTileIDList
.asm_7929b
- call Func_79820
+ call GetMonSpriteTileMapPointerFromRowCount
push bc
push de
call Func_79aae
@@ -1498,8 +1498,8 @@
AnimationShowMonPic: ; 7939e (1e:539e)
xor a
- call Func_79842
- call Func_79820
+ call GetTileIDList
+ call GetMonSpriteTileMapPointerFromRowCount
call Func_79aae
jp Delay3
@@ -1533,7 +1533,7 @@
push af
push hl
push hl
- call Func_79842
+ call GetTileIDList
pop hl
call Func_79aae
call Delay3
@@ -1541,7 +1541,7 @@
ld bc, $0709
call ClearScreenArea
pop af
- call Func_79842
+ call GetTileIDList
pop hl
call Func_79aae
call Delay3
@@ -1568,7 +1568,7 @@
.asm_79407
xor a
push hl
- call Func_79842
+ call GetTileIDList
pop hl
call Func_79aae
ld c, $3
@@ -1863,8 +1863,8 @@
call AnimationHideMonPic
pop af
push af
- call Func_79842
- call Func_79820
+ call GetTileIDList
+ call GetMonSpriteTileMapPointerFromRowCount
call Func_79aae
ld c, $8
call DelayFrames
@@ -2133,8 +2133,8 @@
call GetMonHeader
predef LoadMonBackPic
xor a
- call Func_79842
- call Func_79820
+ call GetTileIDList
+ call GetMonSpriteTileMapPointerFromRowCount
call Func_79aae
pop af
ld [wBattleMonSpecies2], a
@@ -2194,37 +2194,46 @@
pop hl
ret
-Func_79820: ; 79820 (1e:5820)
+; puts the tile map destination address of a mon sprite in hl, given the row count in b
+; The usual row count is 7, but it may be smaller when sliding a mon sprite in/out,
+; in order to show only a portion of the mon sprite.
+GetMonSpriteTileMapPointerFromRowCount: ; 79820 (1e:5820)
push de
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- jr nz, .asm_7982a
- ld a, $65
- jr .asm_7982c
-.asm_7982a
- ld a, $c
-.asm_7982c
+ jr nz, .enemyTurn
+ ld a, 20 * 5 + 1
+ jr .next
+.enemyTurn
+ ld a, 12
+.next
ld hl, wTileMap
ld e, a
- ld d, $0
+ ld d, 0
add hl, de
- ld a, $7
+ ld a, 7
sub b
and a
- jr z, .asm_79840
- ld de, $14
-.asm_7983c
+ jr z, .done
+ ld de, 20
+.loop
add hl, de
dec a
- jr nz, .asm_7983c
-.asm_79840
+ jr nz, .loop
+.done
pop de
ret
-Func_79842: ; 79842 (1e:5842)
- ld hl, PointerTable_79aea ; $5aea
+; Input:
+; a = tile ID list index
+; Output:
+; de = tile ID list pointer
+; b = number of rows
+; c = number of columns
+GetTileIDList: ; 79842 (1e:5842)
+ ld hl, TileIDListPointerTable
ld e, a
- ld d, $0
+ ld d, 0
add hl, de
add hl, de
add hl, de
@@ -2486,13 +2495,14 @@
db (SFX_08_4b - SFX_Headers_08) / 3,$00,$80
Func_79aae: ; 79aae (1e:5aae)
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- ld a, $31
+ ld a, $31 ; base tile ID of player mon sprite
jr z, .asm_79ab6
- xor a
+; enemy turn
+ xor a ; base tile ID of enemy mon sprite
.asm_79ab6
- ld [H_DOWNARROWBLINKCNT1], a ; $ff8b
+ ld [hBaseTileID], a
jr asm_79acb
Func_79aba: ; 79aba (1e:5aba)
@@ -2506,34 +2516,36 @@
ld de, Unknown_79b1b ; $5b1b
asm_79acb: ; 79acb (1e:5acb)
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
-Func_79ace: ; 79ace (1e:5ace)
+; b = number of rows
+; c = number of columns
+CopyTileIDs: ; 79ace (1e:5ace)
push hl
-.asm_79acf
+.rowLoop
push bc
push hl
- ld a, [H_DOWNARROWBLINKCNT1] ; $ff8b
+ ld a, [hBaseTileID]
ld b, a
-.asm_79ad4
+.columnLoop
ld a, [de]
add b
inc de
ld [hli], a
dec c
- jr nz, .asm_79ad4
+ jr nz, .columnLoop
pop hl
- ld bc, $14
+ ld bc, 20
add hl, bc
pop bc
dec b
- jr nz, .asm_79acf
+ jr nz, .rowLoop
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
pop hl
ret
-PointerTable_79aea: ; 79aea (1e:5aea)
+TileIDListPointerTable: ; 79aea (1e:5aea)
dw Unknown_79b24
db $77
dw Unknown_79b55
@@ -2552,34 +2564,79 @@
db $3C
Unknown_79b02: ; 79b02 (1e:5b02)
- db $31,$38,$46,$54,$5B,$32,$39,$47,$55,$5C,$34,$3B,$49,$57,$5E,$36,$3D,$4B,$59,$60,$37,$3E,$4C,$5A,$61
+ db $31,$38,$46,$54,$5B
+ db $32,$39,$47,$55,$5C
+ db $34,$3B,$49,$57,$5E
+ db $36,$3D,$4B,$59,$60
+ db $37,$3E,$4C,$5A,$61
Unknown_79b1b: ; 79b1b (1e:5b1b)
- db $31,$46,$5B,$34,$49,$5E,$37,$4C,$61
+ db $31,$46,$5B
+ db $34,$49,$5E
+ db $37,$4C,$61
Unknown_79b24: ; 79b24 (1e:5b24)
- db $00,$07,$0E,$15,$1C,$23,$2A,$01,$08,$0F,$16,$1D,$24,$2B,$02,$09,$10,$17,$1E,$25,$2C,$03,$0A,$11,$18,$1F,$26,$2D,$04,$0B,$12,$19,$20,$27,$2E,$05,$0C,$13,$1A,$21,$28,$2F,$06,$0D,$14,$1B,$22,$29,$30
+ db $00,$07,$0E,$15,$1C,$23,$2A
+ db $01,$08,$0F,$16,$1D,$24,$2B
+ db $02,$09,$10,$17,$1E,$25,$2C
+ db $03,$0A,$11,$18,$1F,$26,$2D
+ db $04,$0B,$12,$19,$20,$27,$2E
+ db $05,$0C,$13,$1A,$21,$28,$2F
+ db $06,$0D,$14,$1B,$22,$29,$30
Unknown_79b55: ; 79b55 (1e:5b55)
- db $00,$07,$0E,$15,$1C,$23,$2A,$01,$08,$0F,$16,$1D,$24,$2B,$03,$0A,$11,$18,$1F,$26,$2D,$04,$0B,$12,$19,$20,$27,$2E,$05,$0C,$13,$1A,$21,$28,$2F
+ db $00,$07,$0E,$15,$1C,$23,$2A
+ db $01,$08,$0F,$16,$1D,$24,$2B
+ db $03,$0A,$11,$18,$1F,$26,$2D
+ db $04,$0B,$12,$19,$20,$27,$2E
+ db $05,$0C,$13,$1A,$21,$28,$2F
Unknown_79b78: ; 79b78 (1e:5b78)
- db $00,$07,$0E,$15,$1C,$23,$2A,$02,$09,$10,$17,$1E,$25,$2C,$04,$0B,$12,$19,$20,$27,$2E
+ db $00,$07,$0E,$15,$1C,$23,$2A
+ db $02,$09,$10,$17,$1E,$25,$2C
+ db $04,$0B,$12,$19,$20,$27,$2E
Unknown_79b8d: ; 79b8d (1e:5b8d)
- db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$19,$00,$02,$06,$0B,$10,$14,$1A,$00,$00,$07,$0C,$11,$15,$1B,$00,$03,$08,$0D,$12,$16,$1C,$00,$04,$09,$0E,$13,$17,$1D,$1F,$05,$0A,$0F,$01,$18,$1E,$20
+ db $00,$00,$00,$00,$00,$00,$00
+ db $00,$00,$00,$00,$00,$19,$00
+ db $02,$06,$0B,$10,$14,$1A,$00
+ db $00,$07,$0C,$11,$15,$1B,$00
+ db $03,$08,$0D,$12,$16,$1C,$00
+ db $04,$09,$0E,$13,$17,$1D,$1F
+ db $05,$0A,$0F,$01,$18,$1E,$20
Unknown_79bbe: ; 79bbe (1e:5bbe)
- db $00,$00,$00,$30,$00,$37,$00,$00,$00,$2B,$31,$34,$38,$3D,$21,$26,$2C,$01,$35,$39,$3E,$22,$27,$2D,$32,$36,$01,$00,$23,$28,$2E,$33,$01,$3A,$00,$24,$29,$2F,$01,$01,$3B,$00,$25,$2A,$01,$01,$01,$3C,$00
+ db $00,$00,$00,$30,$00,$37,$00
+ db $00,$00,$2B,$31,$34,$38,$3D
+ db $21,$26,$2C,$01,$35,$39,$3E
+ db $22,$27,$2D,$32,$36,$01,$00
+ db $23,$28,$2E,$33,$01,$3A,$00
+ db $24,$29,$2F,$01,$01,$3B,$00
+ db $25,$2A,$01,$01,$01,$3C,$00
Unknown_79bef: ; 79bef (1e:5bef)
- db $00,$00,$00,$00,$00,$00,$00,$00,$00,$47,$4D,$00,$00,$00,$00,$00,$48,$4E,$52,$56,$5B,$3F,$43,$49,$4F,$53,$57,$5C,$40,$44,$4A,$50,$54,$58,$00,$41,$45,$4B,$51,$4C,$59,$5D,$42,$46,$4C,$4C,$55,$5A,$5E
+ db $00,$00,$00,$00,$00,$00,$00
+ db $00,$00,$47,$4D,$00,$00,$00
+ db $00,$00,$48,$4E,$52,$56,$5B
+ db $3F,$43,$49,$4F,$53,$57,$5C
+ db $40,$44,$4A,$50,$54,$58,$00
+ db $41,$45,$4B,$51,$4C,$59,$5D
+ db $42,$46,$4C,$4C,$55,$5A,$5E
Unknown_79c20: ; 79c20 (1e:5c20)
- db $31,$32,$32,$32,$32,$33,$34,$35,$36,$36,$37,$38,$34,$39,$3A,$3A,$3B,$38,$3C,$3D,$3E,$3E,$3F,$40,$41,$42,$43,$43,$44,$45,$46,$47,$43,$48,$49,$4A,$41,$43,$4B,$4C,$4D,$4E,$4F,$50,$50,$50,$51,$52
+ db $31,$32,$32,$32,$32,$33
+ db $34,$35,$36,$36,$37,$38
+ db $34,$39,$3A,$3A,$3B,$38
+ db $3C,$3D,$3E,$3E,$3F,$40
+ db $41,$42,$43,$43,$44,$45
+ db $46,$47,$43,$48,$49,$4A
+ db $41,$43,$4B,$4C,$4D,$4E
+ db $4F,$50,$50,$50,$51,$52
Unknown_79c50: ; 79c50 (1e:5c50)
- db $43,$55,$56,$53,$53,$53,$53,$53,$53,$53,$53,$53,$43,$57,$58,$54,$54,$54,$54,$54,$54,$54,$54,$54,$43,$59,$5A,$43,$43,$43,$43,$43,$43,$43,$43,$43
+ db $43,$55,$56,$53,$53,$53,$53,$53,$53,$53,$53,$53
+ db $43,$57,$58,$54,$54,$54,$54,$54,$54,$54,$54,$54
+ db $43,$59,$5A,$43,$43,$43,$43,$43,$43,$43,$43,$43
AnimationLeavesFalling: ; 79c74 (1e:5c74)
; Makes leaves float down from the top of the screen. This is used
@@ -2743,7 +2800,7 @@
ld bc, 7 * 7
call CopyVideoData
xor a
- ld [$ffae], a
+ ld [hSCX], a
ld hl, vBGMap0
call Func_79e0d
ld a, $90
@@ -2776,34 +2833,36 @@
ld hl, vBGMap1
jp Func_79e0d
-Func_79dda: ; 79dda (1e:5dda)
+; b = tile ID list index
+; c = base tile ID
+CopyTileIDsFromList: ; 79dda (1e:5dda)
call GetPredefRegisters
ld a, c
- ld [H_DOWNARROWBLINKCNT1], a ; $ff8b
+ ld [hBaseTileID], a
ld a, b
push hl
- call Func_79842
+ call GetTileIDList
pop hl
- jp Func_79ace
+ jp CopyTileIDs
Func_79de9: ; 79de9 (1e:5de9)
- ld a, [$ffae]
+ ld a, [hSCX]
ld [wTrainerSpriteOffset], a
.asm_79dee
ld a, [wTrainerSpriteOffset]
add d
- ld [$ffae], a
+ ld [hSCX], a
ld c, $2
call DelayFrames
ld a, [wTrainerSpriteOffset]
sub d
- ld [$ffae], a
+ ld [hSCX], a
ld c, $2
call DelayFrames
dec e
jr nz, .asm_79dee
ld a, [wTrainerSpriteOffset]
- ld [$ffae], a
+ ld [hSCX], a
ret
Func_79e0d: ; 79e0d (1e:5e0d)
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -99,7 +99,7 @@
SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c)
call LoadPlayerBackPic
ld a, $1 ; the usual text box at the bottom of the screen
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
hlCoord 1, 5
ld bc, $307
@@ -240,7 +240,7 @@
jr .findFirstAliveEnemyMonLoop
.foundFirstAliveEnemyMon
ld a, d
- ld [wcc3e], a
+ ld [wSerialExchangeNybbleReceiveData], a
ld a, [W_ISINBATTLE]
dec a ; is it a trainer battle?
call nz, EnemySendOutFirstMon ; if it is a trainer battle, send out enemy mon
@@ -345,8 +345,8 @@
; wild mon or link battle enemy ran from battle
EnemyRan: ; 3c202 (f:4202)
call LoadScreenTilesFromBuffer1
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ld hl, WildRanText
jr nz, .printText
; link battle
@@ -431,11 +431,11 @@
jr nz, MainInBattleLoop ; if the player didn't select a move, jump
.selectEnemyMove
call SelectEnemyMove
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .noLinkBattle
; link battle
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $f
jp z, EnemyRan
cp $e
@@ -838,7 +838,7 @@
ld hl, W_PLAYERBATTSTATUS1
res AttackingMultipleTimes, [hl]
xor a
- ld [W_NUMHITS], a
+ ld [wPlayerNumHits], a
ld hl, wd065 ; clear enemy statuses
ld [hli], a
ld [hli], a
@@ -976,12 +976,12 @@
ld e, $30
call GetBattleHealthBarColor
callab DrawEnemyPokeballs
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
; link battle
call LinkBattleExchangeData
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $f
ret z
call LoadScreenTilesFromBuffer1
@@ -1009,14 +1009,14 @@
ld hl, W_FLAGS_D733
set 1, [hl]
.notrival
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ld a, b
call nz, PlayBattleVictoryMusic
ld hl, TrainerDefeatedText
call PrintText
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ret z
call ScrollTrainerPicAfterBattle
ld c, $28
@@ -1096,7 +1096,7 @@
ld [wd083], a
call WaitForSoundToFinish
.skipWaitForSound
- ld hl, wcd05
+ ld hl, wEnemyNumHits
ld [hli], a
ld [hl], a
ld [wBattleMonStatus], a
@@ -1136,7 +1136,7 @@
hlCoord 13, 9
ld bc, $a0e
ld a, $14 ; yes/no text box
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
ld a, [wd12e]
cp $2 ; did the player choose NO?
@@ -1169,8 +1169,8 @@
.monChosen
call HasMonFainted
jr z, .goBackToPartyMenu ; if mon fainted, you have to choose another
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
inc a
ld [wcd6a], a
@@ -1204,8 +1204,8 @@
; called when player is out of usable mons.
; prints approriate lose message, sets carry flag if player blacked out (special case for initial rival fight)
HandlePlayerBlackOut: ; 3c837 (f:4837)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr z, .notSony1Battle
ld a, [W_CUROPPONENT]
cp $c8 + SONY1
@@ -1225,8 +1225,8 @@
ld b, $0
call GoPAL_SET
ld hl, PlayerBlackedOutText2
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .noLinkBattle
ld hl, LinkBattleLostText
.noLinkBattle
@@ -1385,10 +1385,10 @@
call SlideTrainerPicOffScreen
call PrintEmptyString
call SaveScreenTilesToBuffer1
- ld a,[W_ISLINKBATTLE]
- cp 4
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
jr nz,.next
- ld a,[wcc3e]
+ ld a,[wSerialExchangeNybbleReceiveData]
sub 4
ld [wWhichPokemon],a
jr .next3
@@ -1442,8 +1442,8 @@
ld a,[wPartyCount]
dec a
jr z,.next4
- ld a,[W_ISLINKBATTLE]
- cp 4
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
jr z,.next4
ld a,[W_OPTIONS]
bit 6,a
@@ -1453,7 +1453,7 @@
hlCoord 0, 7
ld bc,$0801
ld a,$14
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID
ld a,[wCurrentMenuItem]
and a
@@ -1572,8 +1572,8 @@
ld a, [W_BATTLETYPE]
cp $2
jp z, .canEscape ; jump if it's a safari battle
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jp z, .canEscape
ld a, [W_ISINBATTLE]
dec a
@@ -1654,8 +1654,8 @@
and a ; reset carry
ret
.canEscape
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ld a, $2
jr nz, .playSound
; link battle
@@ -1666,7 +1666,7 @@
ld [wPlayerMoveListIndex], a
call LinkBattleExchangeData
call LoadScreenTilesFromBuffer1
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $f
ld a, $2
jr z, .playSound
@@ -2082,7 +2082,7 @@
jr nz, .menuselected
ld a, $1b ; regular menu id
.menuselected
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
ld a, [W_BATTLETYPE]
dec a
@@ -2234,8 +2234,8 @@
jp nz, PartyMenuOrRockOrRun
; either the bag (normal battle) or bait (safari battle) was selected
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
; can't use items in link battles
@@ -2401,7 +2401,7 @@
jr .checkIfPartyMonWasSelected
.partyMonWasSelected
ld a, $c ; switch/stats/cancel menu
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
ld hl, wTopMenuItemY
ld a, $c
@@ -2620,8 +2620,8 @@
dec a
ld b, $c3
jr z, .matchedkeyspicked
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr z, .matchedkeyspicked
ld a, [W_FLAGS_D733]
bit 0, a
@@ -2974,7 +2974,7 @@
db "TYPE@"
SelectEnemyMove: ; 3d564 (f:5564)
- ld a, [W_ISLINKBATTLE]
+ ld a, [wLinkState]
sub $4
jr nz, .noLinkBattle
; link battle
@@ -2981,7 +2981,7 @@
call SaveScreenTilesToBuffer1
call LinkBattleExchangeData
call LoadScreenTilesFromBuffer1
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $e
jp z, .asm_3d601
cp $d
@@ -3068,7 +3068,7 @@
; this appears to exchange data with the other gameboy during link battles
LinkBattleExchangeData: ; 3d605 (f:5605)
ld a, $ff
- ld [wcc3e], a
+ ld [wSerialExchangeNybbleReceiveData], a
ld a, [wPlayerMoveListIndex]
cp $f ; is the player running from battle?
jr z, .asm_3d630
@@ -3091,24 +3091,24 @@
.asm_3d62f
ld a, b
.asm_3d630
- ld [wcc42], a
+ ld [wSerialExchangeNybbleSendData], a
callab PrintWaitingText
.asm_3d63b
- call Func_22c3
+ call Serial_ExchangeNybble
call DelayFrame
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
inc a
jr z, .asm_3d63b
ld b, $a
.asm_3d649
call DelayFrame
- call Func_22c3
+ call Serial_ExchangeNybble
dec b
jr nz, .asm_3d649
ld b, $a
.asm_3d654
call DelayFrame
- call Func_22ed
+ call Serial_SendZeroByte
dec b
jr nz, .asm_3d654
ret
@@ -3296,7 +3296,7 @@
ld hl,MultiHitText
call PrintText
xor a
- ld [W_NUMHITS],a
+ ld [wPlayerNumHits],a
.executeOtherEffects
ld a,[W_PLAYERMOVEEFFECT]
and a
@@ -3529,7 +3529,7 @@
ld a,[hli]
ld b,a
ld c,[hl]
- ld hl,wd075
+ ld hl,wPlayerBideAccumulatedDamage + 1
ld a,[hl]
add c ; acumulate damage taken
ld [hld],a
@@ -3548,7 +3548,7 @@
call PrintText
ld a,1
ld [W_PLAYERMOVEPOWER],a
- ld hl,wd075
+ ld hl,wPlayerBideAccumulatedDamage + 1
ld a,[hld]
add a
ld b,a
@@ -3998,8 +3998,8 @@
CheckForDisobedience: ; 3dc88 (f:5c88)
xor a
ld [wcced], a
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .checkIfMonIsTraded
ld a, $1
and a
@@ -4424,8 +4424,8 @@
GetEnemyMonStat: ; 3df1c (f:5f1c)
push de
push bc
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
ld hl, wEnemyMon1Stats
dec c
@@ -5627,11 +5627,11 @@
jp z, ExecuteEnemyMoveDone
call PrintGhostText
jp z, ExecuteEnemyMoveDone
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .executeEnemyMove
ld b, $1
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $e
jr z, .executeEnemyMove
cp $4
@@ -5819,7 +5819,7 @@
ld hl, HitXTimesText
call PrintText
xor a
- ld [wcd05], a
+ ld [wEnemyNumHits], a
.asm_3e873
ld a, [W_ENEMYMOVEEFFECT]
and a
@@ -6028,7 +6028,7 @@
ld a, [hli]
ld b, a
ld c, [hl]
- ld hl, wcd06
+ ld hl, wEnemyBideAccumulatedDamage + 1
ld a, [hl]
add c
ld [hld], a
@@ -6047,7 +6047,7 @@
call PrintText
ld a, $1
ld [W_ENEMYMOVEPOWER], a
- ld hl, wcd06
+ ld hl, wEnemyBideAccumulatedDamage + 1
ld a, [hld]
add a
ld b, a
@@ -6152,8 +6152,8 @@
jp CopyStringToCF4B
LoadEnemyMonData: ; 3eb01 (f:6b01)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jp z, LoadEnemyMonFromParty
ld a, [wEnemyMonSpecies2]
ld [wEnemyMonSpecies], a
@@ -6312,8 +6312,8 @@
; calls BattleTransition to show the battle transition animation and initializes some battle variables
DoBattleTransitionAndInitBattleVariables: ; 3ec32 (f:6c32)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .next
; link battle
xor a
@@ -6616,8 +6616,8 @@
ret
ApplyBadgeStatBoosts: ; 3ee19 (f:6e19)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ret z ; return if link battle
ld a, [W_OBTAINEDBADGES]
ld b, a
@@ -6706,19 +6706,19 @@
BattleRandom:
; Link battles use a shared PRNG.
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jp nz, Random
push hl
push bc
- ld a, [wLinkBattleRNCount]
+ ld a, [wLinkBattleRandomNumberListIndex]
ld c, a
ld b, 0
- ld hl, wd148
+ ld hl, wLinkBattleRandomNumberList
add hl, bc
inc a
- ld [wLinkBattleRNCount], a
+ ld [wLinkBattleRandomNumberListIndex], a
cp 9
ld a, [hl]
pop bc
@@ -6732,8 +6732,9 @@
; point to seed 0 so we pick the first number the next time
xor a
- ld [wLinkBattleRNCount], a
- ld hl, wd148
+ ld [wLinkBattleRandomNumberListIndex], a
+
+ ld hl, wLinkBattleRandomNumberList
ld b, 9
.loop
ld a, [hl]
@@ -6939,7 +6940,7 @@
ld e, a
ld a, [wd034]
ld d, a ; de contains pointer to trainer pic
- ld a, [W_ISLINKBATTLE]
+ ld a, [wLinkState]
and a
ld a, Bank(TrainerPics) ; this is where all the trainer pics are (not counting Red's)
jr z, .loadSprite
@@ -7698,8 +7699,8 @@
ld hl, wPlayerMonStatMods
ld de, W_ENEMYMOVEEFFECT
ld bc, W_PLAYERBATTSTATUS1
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr z, .statModifierDownEffect
call BattleRandom
cp $40 ; 1/4 chance to miss by in regular battle
@@ -7934,13 +7935,13 @@
BideEffect: ; 3f6e5 (f:76e5)
ld hl, W_PLAYERBATTSTATUS1
- ld de, W_NUMHITS
+ ld de, wPlayerBideAccumulatedDamage
ld bc, wPlayerNumAttacksLeft
ld a, [H_WHOSETURN]
and a
jr z, .bideEffect
ld hl, W_ENEMYBATTSTATUS1
- ld de, wcd05
+ ld de, wEnemyBideAccumulatedDamage
ld bc, wEnemyNumAttacksLeft
.bideEffect
set StoringEnergy, [hl] ; mon is now using bide
@@ -8096,13 +8097,13 @@
TwoToFiveAttacksEffect: ; 3f811 (f:7811)
ld hl, W_PLAYERBATTSTATUS1
ld de, wPlayerNumAttacksLeft
- ld bc, W_NUMHITS
+ ld bc, wPlayerNumHits
ld a, [H_WHOSETURN]
and a
jr z, .twoToFiveAttacksEffect
ld hl, W_ENEMYBATTSTATUS1
ld de, wEnemyNumAttacksLeft
- ld bc, wcd05
+ ld bc, wEnemyNumHits
.twoToFiveAttacksEffect
bit AttackingMultipleTimes, [hl] ; is mon attacking multiple times?
ret nz
@@ -8394,8 +8395,8 @@
ld hl, wBattleMonMoves
ld a, [W_PLAYERBATTSTATUS1]
jr nz, .asm_3fa13
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .asm_3fa3a
ld hl, wEnemyMonMoves
ld a, [W_ENEMYBATTSTATUS1]
@@ -8500,8 +8501,8 @@
and a
ld hl, wBattleMonPP
jr nz, .asm_3facf
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
pop hl
jr nz, .asm_3fae1
push hl
@@ -8629,7 +8630,7 @@
CheckTargetSubstitute: ; 3fb79 (f:7b79)
push hl
ld hl, W_ENEMYBATTSTATUS2
- ld a, [$fff3]
+ ld a, [H_WHOSETURN]
and a
jr z, .next1
ld hl, W_PLAYERBATTSTATUS2
--- a/engine/battle/d.asm
+++ b/engine/battle/d.asm
@@ -9,7 +9,7 @@
ld de, wPlayerName
call PlaceString
hlCoord 4, 10
- ld de, W_GRASSRATE ; enemy name
+ ld de, wLinkEnemyTrainerName
call PlaceString
; place bold "VS" tiles between the names
hlCoord 9, 8
--- a/engine/battle/e.asm
+++ b/engine/battle/e.asm
@@ -700,7 +700,7 @@
ReadTrainer: ; 39c53 (e:5c53)
; don't change any moves in a link battle
- ld a,[W_ISLINKBATTLE]
+ ld a,[wLinkState]
and a
ret nz
@@ -872,8 +872,8 @@
ld a,[W_ISINBATTLE]
dec a
ret z ; if not a trainer, we're done here
- ld a,[W_ISLINKBATTLE]
- cp 4
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
ret z
ld a,[W_TRAINERCLASS] ; what trainer class is this?
dec a
@@ -1230,8 +1230,8 @@
xor a
ld [wd11d],a
- ld a,[W_ISLINKBATTLE]
- cp 4
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
ret z
scf
ret
--- a/engine/cable_club.asm
+++ b/engine/cable_club.asm
@@ -1,4 +1,7 @@
-Func_5317: ; 5317 (1:5317)
+; performs the appropriate action when the player uses the gameboy on the table in the Colosseum or Trade Centre
+; In the Colosseum, it starts a battle. In the Trade Centre, it displays the trade selection screen.
+; Before doing either action, it swaps random numbers, trainer names and party data with the other gameboy.
+CableClub_DoBattleOrTrade: ; 5317 (1:5317)
ld c, $50
call DelayFrames
call ClearScreen
@@ -7,201 +10,207 @@
call LoadHpBarAndStatusTilePatterns
call LoadTrainerInfoTextBoxTiles
hlCoord 3, 8
- ld b, $2
- ld c, $c
- call Func_5ab3
+ ld b, 2
+ ld c, 12
+ call CableClub_TextBoxBorder
hlCoord 4, 10
- ld de, PleaseWaitString ; $550f
+ ld de, PleaseWaitString
call PlaceString
- ld hl, W_NUMHITS ; wd074
+ ld hl, wPlayerNumHits
xor a
ld [hli], a
ld [hl], $50
+ ; fall through
-Func_5345: ; 5345
- ld hl, wd152
- ld a, $fd
- ld b, $6
-.asm_534c
+; This is called after completing a trade.
+CableClub_DoBattleOrTradeAgain: ; 5345
+ ld hl, wSerialPlayerDataBlock
+ ld a, SERIAL_PREAMBLE_BYTE
+ ld b, 6
+.writePlayeDataBlockPreambleLoop
ld [hli], a
dec b
- jr nz, .asm_534c
- ld hl, wd141
- ld a, $fd
- ld b, $7
-.asm_5357
+ jr nz, .writePlayeDataBlockPreambleLoop
+ ld hl, wSerialRandomNumberListBlock
+ ld a, SERIAL_PREAMBLE_BYTE
+ ld b, 7
+.writeRandomNumberListPreambleLoop
ld [hli], a
dec b
- jr nz, .asm_5357
- ld b, $a
-.asm_535d
+ jr nz, .writeRandomNumberListPreambleLoop
+ ld b, 10
+.generateRandomNumberListLoop
call Random
- cp $fd
- jr nc, .asm_535d
+ cp SERIAL_PREAMBLE_BYTE ; all the random numbers have to be less than the preamble byte
+ jr nc, .generateRandomNumberListLoop
ld [hli], a
dec b
- jr nz, .asm_535d
- ld hl, wTileMapBackup
- ld a, $fd
+ jr nz, .generateRandomNumberListLoop
+ ld hl, wSerialPartyMonsPatchList
+ ld a, SERIAL_PREAMBLE_BYTE
ld [hli], a
ld [hli], a
ld [hli], a
ld b, $c8
xor a
-.asm_5373
+.zeroPlayerDataPatchListLoop
ld [hli], a
dec b
- jr nz, .asm_5373
- ld hl, W_GRASSRATE ; W_GRASSRATE
- ld bc, $1a9
-.asm_537d
+ jr nz, .zeroPlayerDataPatchListLoop
+ ld hl, W_GRASSRATE
+ ld bc, W_TRAINERHEADERPTR - W_GRASSRATE
+.zeroEnemyPartyLoop
xor a
ld [hli], a
dec bc
ld a, b
or c
- jr nz, .asm_537d
+ jr nz, .zeroEnemyPartyLoop
ld hl, wPartyMons - 1
- ld de, wTileMapBackup + 10
- ld bc, $0
-.asm_538d
+ ld de, wSerialPartyMonsPatchList + 10
+ ld bc, 0
+.patchPartyMonsLoop
inc c
ld a, c
- cp $fd
- jr z, .asm_53a9
+ cp SERIAL_PREAMBLE_BYTE
+ jr z, .startPatchListPart2
ld a, b
- dec a
- jr nz, .asm_539c
+ dec a ; are we in part 2 of the patch list?
+ jr nz, .checkPlayerDataByte ; jump if in part 1
+; if we're in part 2
ld a, c
- cp $d
- jr z, .asm_53b2
-.asm_539c
+ cp (wPartyMonOT - (wPartyMons - 1)) - (SERIAL_PREAMBLE_BYTE - 1)
+ jr z, .finishedPatchingPlayerData
+.checkPlayerDataByte
inc hl
ld a, [hl]
- cp $fe
- jr nz, .asm_538d
+ cp SERIAL_NO_DATA_BYTE
+ jr nz, .patchPartyMonsLoop
+; if the player data byte matches SERIAL_NO_DATA_BYTE, patch it with $FF and record the offset in the patch list
ld a, c
ld [de], a
inc de
ld [hl], $ff
- jr .asm_538d
-.asm_53a9
- ld a, $ff
- ld [de], a
+ jr .patchPartyMonsLoop
+.startPatchListPart2
+ ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
+ ld [de], a ; end of part 1
inc de
ld bc, $100
- jr .asm_538d
-.asm_53b2
- ld a, $ff
- ld [de], a
- call Func_227f
- ld a, [$ffaa]
- cp $2
- jr nz, .asm_53d2
+ jr .patchPartyMonsLoop
+.finishedPatchingPlayerData
+ ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
+ ld [de], a ; end of part 2
+ call Serial_SyncAndExchangeNybble
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr nz, .skipSendingTwoZeroBytes
+; if using internal clock
+; send two zero bytes for syncing purposes?
call Delay3
xor a
- ld [$ffac], a
- ld a, $81
- ld [$ff02], a
+ ld [hSerialSendData], a
+ ld a, START_TRANSFER_INTERNAL_CLOCK
+ ld [rSC], a
call DelayFrame
xor a
- ld [$ffac], a
- ld a, $81
- ld [$ff02], a
-.asm_53d2
+ ld [hSerialSendData], a
+ ld a, START_TRANSFER_INTERNAL_CLOCK
+ ld [rSC], a
+.skipSendingTwoZeroBytes
call Delay3
- ld a, $8
- ld [rIE], a ; $ffff
- ld hl, wd141
- ld de, wTileMapBackup2
+ ld a, (1 << SERIAL)
+ ld [rIE], a
+ ld hl, wSerialRandomNumberListBlock
+ ld de, wSerialOtherGameboyRandomNumberListBlock
ld bc, $11
- call Func_216f
- ld a, $fe
+ call Serial_ExchangeBytes
+ ld a, SERIAL_NO_DATA_BYTE
ld [de], a
- ld hl, wd152
- ld de, wd893
+ ld hl, wSerialPlayerDataBlock
+ ld de, wSerialEnemyDataBlock
ld bc, $1a8
- call Func_216f
- ld a, $fe
+ call Serial_ExchangeBytes
+ ld a, SERIAL_NO_DATA_BYTE
ld [de], a
- ld hl, wTileMapBackup
- ld de, wTileMapBackup + 200
+ ld hl, wSerialPartyMonsPatchList
+ ld de, wSerialEnemyMonsPatchList
ld bc, $c8
- call Func_216f
- ld a, $d
- ld [rIE], a ; $ffff
+ call Serial_ExchangeBytes
+ ld a, (1 << SERIAL) | (1 << TIMER) | (1 << VBLANK)
+ ld [rIE], a
ld a, $ff
call PlaySound
- ld a, [$ffaa]
- cp $2
- jr z, .asm_5431
- ld hl, wTileMapBackup2
-.asm_5415
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr z, .skipCopyingRandomNumberList ; the list generated by the gameboy clocking the connection is used by both gameboys
+ ld hl, wSerialOtherGameboyRandomNumberListBlock
+.findStartOfRandomNumberListLoop
ld a, [hli]
and a
- jr z, .asm_5415
- cp $fd
- jr z, .asm_5415
- cp $fe
- jr z, .asm_5415
+ jr z, .findStartOfRandomNumberListLoop
+ cp SERIAL_PREAMBLE_BYTE
+ jr z, .findStartOfRandomNumberListLoop
+ cp SERIAL_NO_DATA_BYTE
+ jr z, .findStartOfRandomNumberListLoop
dec hl
- ld de, wd148
- ld c, $a
-.asm_5427
+ ld de, wLinkBattleRandomNumberList
+ ld c, 10
+.copyRandomNumberListLoop
ld a, [hli]
- cp $fe
- jr z, .asm_5427
+ cp SERIAL_NO_DATA_BYTE
+ jr z, .copyRandomNumberListLoop
ld [de], a
inc de
dec c
- jr nz, .asm_5427
-.asm_5431
- ld hl, wd896
-.asm_5434
+ jr nz, .copyRandomNumberListLoop
+.skipCopyingRandomNumberList
+ ld hl, wSerialEnemyDataBlock + 3
+.findStartOfEnemyNameLoop
ld a, [hli]
and a
- jr z, .asm_5434
- cp $fd
- jr z, .asm_5434
- cp $fe
- jr z, .asm_5434
+ jr z, .findStartOfEnemyNameLoop
+ cp SERIAL_PREAMBLE_BYTE
+ jr z, .findStartOfEnemyNameLoop
+ cp SERIAL_NO_DATA_BYTE
+ jr z, .findStartOfEnemyNameLoop
dec hl
- ld de, W_GRASSRATE ; W_GRASSRATE
- ld c, $b
-.asm_5446
+ ld de, wLinkEnemyTrainerName
+ ld c, 11
+.copyEnemyNameLoop
ld a, [hli]
- cp $fe
- jr z, .asm_5446
+ cp SERIAL_NO_DATA_BYTE
+ jr z, .copyEnemyNameLoop
ld [de], a
inc de
dec c
- jr nz, .asm_5446
- ld de, wEnemyPartyCount ; wEnemyPartyCount
- ld bc, $194
-.asm_5456
+ jr nz, .copyEnemyNameLoop
+ ld de, wEnemyPartyCount
+ ld bc, W_TRAINERHEADERPTR - wEnemyPartyCount
+.copyEnemyPartyLoop
ld a, [hli]
- cp $fe
- jr z, .asm_5456
+ cp SERIAL_NO_DATA_BYTE
+ jr z, .copyEnemyPartyLoop
ld [de], a
inc de
dec bc
ld a, b
or c
- jr nz, .asm_5456
- ld de, wTileMapBackup
+ jr nz, .copyEnemyPartyLoop
+ ld de, wSerialPartyMonsPatchList
ld hl, wPartyMons
- ld c, $2
-.asm_546a
+ ld c, 2 ; patch list has 2 parts
+.unpatchPartyMonsLoop
ld a, [de]
inc de
and a
- jr z, .asm_546a
- cp $fd
- jr z, .asm_546a
- cp $fe
- jr z, .asm_546a
- cp $ff
- jr z, .asm_5489
+ jr z, .unpatchPartyMonsLoop
+ cp SERIAL_PREAMBLE_BYTE
+ jr z, .unpatchPartyMonsLoop
+ cp SERIAL_NO_DATA_BYTE
+ jr z, .unpatchPartyMonsLoop
+ cp SERIAL_PATCH_LIST_PART_TERMINATOR
+ jr z, .finishedPartyMonsPatchListPart
push hl
push bc
ld b, 0
@@ -208,85 +217,85 @@
dec a
ld c, a
add hl, bc
- ld a, $fe
+ ld a, SERIAL_NO_DATA_BYTE
ld [hl], a
pop bc
pop hl
- jr .asm_546a
-.asm_5489
- ld hl, wPartyMons + $fc ; wd267
- dec c
- jr nz, .asm_546a
- ld de, wTileMapBackup + 200
+ jr .unpatchPartyMonsLoop
+.finishedPartyMonsPatchListPart
+ ld hl, wPartyMons + (SERIAL_PREAMBLE_BYTE - 1)
+ dec c ; is there another part?
+ jr nz, .unpatchPartyMonsLoop
+ ld de, wSerialEnemyMonsPatchList
ld hl, wEnemyMons
- ld c, $2
-.asm_5497
+ ld c, 2 ; patch list has 2 parts
+.unpatchEnemyMonsLoop
ld a, [de]
inc de
and a
- jr z, .asm_5497
- cp $fd
- jr z, .asm_5497
- cp $fe
- jr z, .asm_5497
- cp $ff
- jr z, .asm_54b6
+ jr z, .unpatchEnemyMonsLoop
+ cp SERIAL_PREAMBLE_BYTE
+ jr z, .unpatchEnemyMonsLoop
+ cp SERIAL_NO_DATA_BYTE
+ jr z, .unpatchEnemyMonsLoop
+ cp SERIAL_PATCH_LIST_PART_TERMINATOR
+ jr z, .finishedEnemyMonsPatchListPart
push hl
push bc
- ld b, $0
+ ld b, 0
dec a
ld c, a
add hl, bc
- ld a, $fe
+ ld a, SERIAL_NO_DATA_BYTE
ld [hl], a
pop bc
pop hl
- jr .asm_5497
-.asm_54b6
- ld hl, wEnemyMons + $fc
+ jr .unpatchEnemyMonsLoop
+.finishedEnemyMonsPatchListPart
+ ld hl, wEnemyMons + (SERIAL_PREAMBLE_BYTE - 1)
dec c
- jr nz, .asm_5497
- ld a, $ac
+ jr nz, .unpatchEnemyMonsLoop
+ ld a, wEnemyMonOT % $100
ld [wcf8d], a
- ld a, $d9
+ ld a, wEnemyMonOT / $100
ld [wcf8e], a
xor a
- ld [wcc38], a
+ ld [wTradeCenterPointerTableIndex], a
ld a, $ff
call PlaySound
- ld a, [$ffaa]
- cp $2
- ld c, $42
- call z, DelayFrames
- ld a, [W_ISLINKBATTLE] ; W_ISLINKBATTLE
- cp $3
- ld a, $32
- ld [W_ISLINKBATTLE], a ; W_ISLINKBATTLE
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ ld c, 66
+ call z, DelayFrames ; delay if using internal clock
+ ld a, [wLinkState]
+ cp LINK_STATE_START_BATTLE
+ ld a, LINK_STATE_TRADING
+ ld [wLinkState], a
jr nz, .asm_5506
- ld a, $4
- ld [W_ISLINKBATTLE], a ; W_ISLINKBATTLE
+ ld a, LINK_STATE_BATTLING
+ ld [wLinkState], a
ld a, SONY1 + $c8
- ld [W_CUROPPONENT], a ; wd059
+ ld [W_CUROPPONENT], a
call ClearScreen
call Delay3
- ld hl, W_OPTIONS ; W_OPTIONS
+ ld hl, W_OPTIONS
res 7, [hl]
predef InitOpponent
predef HealParty
- jp Func_577d
+ jp ReturnToCableClubRoom
.asm_5506
ld c, BANK(Music_GameCorner)
ld a, MUSIC_GAME_CORNER
call PlayMusic
- jr Func_551c
+ jr CallCurrentTradeCenterFunction
PleaseWaitString: ; 550f (1:550f)
db "PLEASE WAIT!@"
-Func_551c:
- ld hl, PointerTable_5a5b ; $5a5b
- ld b, $0
- ld a, [wcc38]
+CallCurrentTradeCenterFunction:
+ ld hl, TradeCenterPointerTable
+ ld b, 0
+ ld a, [wTradeCenterPointerTableIndex]
cp $ff
jp z, LoadTitlescreenGraphics
add a
@@ -300,10 +309,10 @@
TradeCenter_SelectMon:
call ClearScreen
call LoadTrainerInfoTextBoxTiles
- call Func_57f2
- call Func_57a2
+ call TradeCenter_DrawPartyLists
+ call TradeCenter_DrawCancelBox
xor a
- ld hl, wcc3d
+ ld hl, wSerialSyncAndExchangeNybbleReceiveData
ld [hli], a
ld [hli], a
ld [hli], a
@@ -313,22 +322,22 @@
ld [wLastMenuItem], a
ld [wMenuJoypadPollCount], a
inc a
- ld [wcc42], a
- jp .asm_55dc
-.asm_5557
+ ld [wSerialExchangeNybbleSendData], a
+ jp .playerMonMenu
+.enemyMonMenu
xor a
ld [wcc37], a
inc a
- ld [wcc49], a
- ld a, $a1
+ ld [wWhichTradeMonSelectionMenu], a
+ ld a, D_DOWN | D_LEFT | A_BUTTON
ld [wMenuWatchedKeys], a
ld a, [wEnemyPartyCount]
ld [wMaxMenuItem], a
- ld a, $9
+ ld a, 9
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
-.asm_5574
+.enemyMonMenu_HandleInput
ld hl, $fff6
set 1, [hl]
call HandleMenuInput
@@ -335,29 +344,31 @@
ld hl, $fff6
res 1, [hl]
and a
- jp z, .asm_565b
- bit 0, a
- jr z, .asm_55b0 ; 0x5587 $27
+ jp z, .getNewInput
+ bit 0, a ; A button pressed?
+ jr z, .enemyMonMenu_ANotPressed
+; if A button pressed
ld a, [wMaxMenuItem]
ld c, a
ld a, [wCurrentMenuItem]
cp c
- jr c, .asm_559a ; 0x5591 $7
+ jr c, .displayEnemyMonStats
ld a, [wMaxMenuItem]
dec a
ld [wCurrentMenuItem], a
-.asm_559a
+.displayEnemyMonStats
ld a, $1
ld [wd11b], a
callab Func_39bd5
ld hl, wEnemyMons
- call Func_57d6
- jp .asm_565b
-.asm_55b0
- bit 5, a
- jr z, .asm_55d4 ; 0x55b2 $20
- xor a
- ld [wcc49], a
+ call TradeCenter_DisplayStats
+ jp .getNewInput
+.enemyMonMenu_ANotPressed
+ bit 5, a ; Left pressed?
+ jr z, .enemyMonMenu_LeftNotPressed
+; if Left pressed, switch back to the player mon menu
+ xor a ; player mon menu
+ ld [wWhichTradeMonSelectionMenu], a
ld a, [wMenuCursorLocation]
ld l, a
ld a, [wMenuCursorLocation + 1]
@@ -369,51 +380,53 @@
ld a, [wPartyCount]
dec a
cp b
- jr nc, .asm_55dc ; 0x55cd $d
+ jr nc, .playerMonMenu
ld [wCurrentMenuItem], a
- jr .asm_55dc ; 0x55d2 $8
-.asm_55d4
- bit 7, a
- jp z, .asm_565b
- jp .asm_572f
-.asm_55dc
- xor a
- ld [wcc49], a
+ jr .playerMonMenu
+.enemyMonMenu_LeftNotPressed
+ bit 7, a ; Down pressed?
+ jp z, .getNewInput
+ jp .selectedCancelMenuItem ; jump if Down pressed
+.playerMonMenu
+ xor a ; player mon menu
+ ld [wWhichTradeMonSelectionMenu], a
ld [wcc37], a
- ld a, $91
+ ld a, D_DOWN | D_RIGHT | A_BUTTON
ld [wMenuWatchedKeys], a
ld a, [wPartyCount]
ld [wMaxMenuItem], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
- ld hl, wTileMap + $15
+ hlCoord 1, 1
ld bc, $0601
call ClearScreenArea
-.asm_5601
+.playerMonMenu_HandleInput
ld hl, $fff6
set 1, [hl]
call HandleMenuInput
ld hl, $fff6
res 1, [hl]
- and a
- jr nz, .asm_5614 ; 0x560f $3
- jp .asm_565b
-.asm_5614
- bit 0, a
- jr z, .asm_562e ; 0x5616 $16
- jp .asm_5665
+ and a ; was anything pressed?
+ jr nz, .playerMonMenu_SomethingPressed
+ jp .getNewInput
+.playerMonMenu_SomethingPressed
+ bit 0, a ; A button pressed?
+ jr z, .playerMonMenu_ANotPressed
+ jp .chosePlayerMon ; jump if A button pressed
+; unreachable code
ld a, $4
ld [wd11b], a
callab Func_39bd5
- call Func_57d6
- jp .asm_565b
-.asm_562e
- bit 4, a
- jr z, .asm_5654 ; 0x5630 $22
- ld a, $1
- ld [wcc49], a
+ call TradeCenter_DisplayStats
+ jp .getNewInput
+.playerMonMenu_ANotPressed
+ bit 4, a ; Right pressed?
+ jr z, .playerMonMenu_RightNotPressed
+; if Right pressed, switch to the enemy mon menu
+ ld a, $1 ; enemy mon menu
+ ld [wWhichTradeMonSelectionMenu], a
ld a, [wMenuCursorLocation]
ld l, a
ld a, [wMenuCursorLocation + 1]
@@ -425,20 +438,21 @@
ld a, [wEnemyPartyCount]
dec a
cp b
- jr nc, .asm_5651 ; 0x564c $3
+ jr nc, .notPastLastEnemyMon
+; when switching to the enemy mon menu, if the menu selection would be past the last enemy mon, select the last enemy mon
ld [wCurrentMenuItem], a
-.asm_5651
- jp .asm_5557
-.asm_5654
- bit 7, a
- jr z, .asm_565b ; 0x5656 $3
- jp .asm_572f
-.asm_565b
- ld a, [wcc49]
+.notPastLastEnemyMon
+ jp .enemyMonMenu
+.playerMonMenu_RightNotPressed
+ bit 7, a ; Down pressed?
+ jr z, .getNewInput
+ jp .selectedCancelMenuItem ; jump if Down pressed
+.getNewInput
+ ld a, [wWhichTradeMonSelectionMenu]
and a
- jp z, .asm_5601
- jp .asm_5574
-.asm_5665
+ jp z, .playerMonMenu_HandleInput
+ jp .enemyMonMenu_HandleInput
+.chosePlayerMon
call SaveScreenTilesToBuffer1
call PlaceUnfilledArrowMenuCursor
ld a, [wMaxMenuItem]
@@ -445,16 +459,16 @@
ld c, a
ld a, [wCurrentMenuItem]
cp c
- jr c, .asm_5679 ; 0x5673 $4
+ jr c, .displayStatsTradeMenu
ld a, [wMaxMenuItem]
dec a
-.asm_5679
+.displayStatsTradeMenu
push af
- ld hl, wTileMap + $118
- ld b, $2
- ld c, $12
- call Func_5ab3
- ld hl, wTileMap + $142
+ hlCoord 0, 14
+ ld b, 2
+ ld c, 18
+ call CableClub_TextBoxBorder
+ hlCoord 2, 16
ld de, .statsTrade
call PlaceString
xor a
@@ -462,105 +476,107 @@
ld [wLastMenuItem], a
ld [wMenuJoypadPollCount], a
ld [wMaxMenuItem], a
- ld a, $10
+ ld a, 16
ld [wTopMenuItemY], a
-.asm_569f
- ld a, $7f
- ld [wTileMap + $14b], a
- ld a, $13
+.selectStatsMenuItem
+ ld a, " "
+ Coorda 11, 16
+ ld a, D_RIGHT | B_BUTTON | A_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
call HandleMenuInput
- bit 4, a
- jr nz, .asm_56c3 ; 0x56b3 $e
- bit 1, a
- jr z, .asm_56df ; 0x56b7 $26
-.asm_56b9
+ bit 4, a ; Right pressed?
+ jr nz, .selectTradeMenuItem
+ bit 1, a ; B button pressed?
+ jr z, .displayPlayerMonStats
+.cancelPlayerMonChoice
pop af
ld [wCurrentMenuItem], a
call LoadScreenTilesFromBuffer1
- jp .asm_55dc
-.asm_56c3
- ld a, $7f
- ld [wTileMap + $141], a
- ld a, $23
+ jp .playerMonMenu
+.selectTradeMenuItem
+ ld a, " "
+ Coorda 1, 16
+ ld a, D_LEFT | B_BUTTON | A_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $b
+ ld a, 11
ld [wTopMenuItemX], a
call HandleMenuInput
- bit 5, a
- jr nz, .asm_569f ; 0x56d7 $c6
- bit 1, a
- jr nz, .asm_56b9 ; 0x56db $dc
- jr .asm_56f9 ; 0x56dd $1a
-.asm_56df
+ bit 5, a ; Left pressed?
+ jr nz, .selectStatsMenuItem
+ bit 1, a ; B button pressed?
+ jr nz, .cancelPlayerMonChoice
+ jr .choseTrade
+.displayPlayerMonStats
pop af
ld [wCurrentMenuItem], a
ld a, $4
ld [wd11b], a
callab Func_39bd5
- call Func_57d6
+ call TradeCenter_DisplayStats
call LoadScreenTilesFromBuffer1
- jp .asm_55dc
-.asm_56f9
+ jp .playerMonMenu
+.choseTrade
call PlaceUnfilledArrowMenuCursor
pop af
ld [wCurrentMenuItem], a
- ld [wWhichTrade], a
- ld [wcc42], a
- call Func_226e
- ld a, [wcc3d]
+ ld [wTradingWhichPlayerMon], a
+ ld [wSerialExchangeNybbleSendData], a
+ call Serial_PrintWaitingTextAndSyncAndExchangeByte
+ ld a, [wSerialSyncAndExchangeNybbleReceiveData]
cp $f
- jp z, Func_551c
- ld [wTrainerEngageDistance], a
- call Func_57c7
- ld a, $1
- ld [wcc38], a
- jp Func_551c
+ jp z, CallCurrentTradeCenterFunction ; go back to the beginning of the trade selection menu if the other person cancelled
+ ld [wTradingWhichEnemyMon], a
+ call TradeCenter_PlaceSelectedEnemyMonMenuCursor
+ ld a, $1 ; TradeCenter_Trade
+ ld [wTradeCenterPointerTableIndex], a
+ jp CallCurrentTradeCenterFunction
.statsTrade
db "STATS TRADE@"
-.asm_572f
+.selectedCancelMenuItem
ld a, [wCurrentMenuItem]
ld b, a
ld a, [wMaxMenuItem]
cp b
- jp nz, .asm_565b
+ jp nz, .getNewInput
ld a, [wMenuCursorLocation]
ld l, a
ld a, [wMenuCursorLocation + 1]
ld h, a
- ld a, $7f
+ ld a, " "
ld [hl], a
-.asm_5745
- ld a, $ed
- ld [wTileMap + $141], a
-.asm_574a
+.cancelMenuItem_Loop
+ ld a, $ed ; filled arrow cursor
+ Coorda 1, 16
+.cancelMenuItem_JoypadLoop
call JoypadLowSensitivity
- ld a, [hJoy5]
- and a
- jr z, .asm_574a ; 0x5750 $f8
- bit 0, a
- jr nz, .asm_5769 ; 0x5754 $13
- bit 6, a
- jr z, .asm_574a ; 0x5758 $f0
- ld a, $7f
- ld [wTileMap + $141], a
+ ld a, [$ffb5]
+ and a ; pressed anything?
+ jr z, .cancelMenuItem_JoypadLoop
+ bit 0, a ; A button pressed?
+ jr nz, .cancelMenuItem_APressed
+ bit 6, a ; Up pressed?
+ jr z, .cancelMenuItem_JoypadLoop
+; if Up pressed
+ ld a, " "
+ Coorda 1, 16
ld a, [wPartyCount]
dec a
ld [wCurrentMenuItem], a
- jp .asm_55dc
-.asm_5769
- ld a, $ec
- ld [wTileMap + $141], a
+ jp .playerMonMenu
+.cancelMenuItem_APressed
+ ld a, $ec ; unfilled arrow cursor
+ Coorda 1, 16
ld a, $f
- ld [wcc42], a
- call Func_226e
- ld a, [wcc3d]
- cp $f
- jr nz, .asm_5745 ; 0x577b $c8
+ ld [wSerialExchangeNybbleSendData], a
+ call Serial_PrintWaitingTextAndSyncAndExchangeByte
+ ld a, [wSerialSyncAndExchangeNybbleReceiveData]
+ cp $f ; did the other person choose Cancel too?
+ jr nz, .cancelMenuItem_Loop
+ ; fall through
-Func_577d: ; 577d (1:577d)
+ReturnToCableClubRoom: ; 577d (1:577d)
call GBPalWhiteOutWithDelay3
ld hl, wcfc4
ld a, [hl]
@@ -579,16 +595,16 @@
call GBFadeInFromWhite
ret
-Func_57a2:
- ld hl, wTileMap + $137
+TradeCenter_DrawCancelBox:
+ hlCoord 11, 15
ld a, $7e
- ld bc, $0031
+ ld bc, 2 * 20 + 9
call FillMemory
- ld hl, wTileMap + $12c
- ld b, $1
- ld c, $9
- call Func_5ab3
- ld hl, wTileMap + $142
+ hlCoord 0, 15
+ ld b, 1
+ ld c, 9
+ call CableClub_TextBoxBorder
+ hlCoord 2, 16
ld de, CancelTextString
jp PlaceString
@@ -595,15 +611,15 @@
CancelTextString:
db "CANCEL@"
-Func_57c7:
- ld a, [wcc3d]
- ld hl, wTileMap + $b5
- ld bc, $0014
+TradeCenter_PlaceSelectedEnemyMonMenuCursor:
+ ld a, [wSerialSyncAndExchangeNybbleReceiveData]
+ hlCoord 1, 9
+ ld bc, 20
call AddNTimes
- ld [hl], $ec
+ ld [hl], $ec ; cursor
ret
-Func_57d6:
+TradeCenter_DisplayStats:
ld a, [wCurrentMenuItem]
ld [wWhichPokemon], a
predef StatusScreen
@@ -610,33 +626,34 @@
predef StatusScreen2
call GBPalNormal
call LoadTrainerInfoTextBoxTiles
- call Func_57f2
- jp Func_57a2
+ call TradeCenter_DrawPartyLists
+ jp TradeCenter_DrawCancelBox
-Func_57f2:
- ld hl, wTileMap
- ld b, $6
- ld c, $12
- call Func_5ab3
- ld hl, wTileMap + $a0
- ld b, $6
- ld c, $12
- call Func_5ab3
- ld hl, wTileMap + $5
+TradeCenter_DrawPartyLists:
+ hlCoord 0, 0
+ ld b, 6
+ ld c, 18
+ call CableClub_TextBoxBorder
+ hlCoord 0, 8
+ ld b, 6
+ ld c, 18
+ call CableClub_TextBoxBorder
+ hlCoord 5, 0
ld de, wPlayerName
call PlaceString
- ld hl, wTileMap + $a5
- ld de, W_GRASSRATE
+ hlCoord 5, 8
+ ld de, wLinkEnemyTrainerName
call PlaceString
- ld hl, wTileMap + $16
+ hlCoord 2, 1
ld de, wPartySpecies
- call Func_5827
- ld hl, wTileMap + $b6
+ call TradeCenter_PrintPartyListNames
+ hlCoord 2, 9
ld de, wEnemyPartyMons
+ ; fall through
-Func_5827:
+TradeCenter_PrintPartyListNames:
ld c, $0
-.asm_5829
+.loop
ld a, [de]
cp $ff
ret z
@@ -653,134 +670,136 @@
pop de
inc de
pop hl
- ld bc, $0014
+ ld bc, 20
add hl, bc
pop bc
inc c
- jr .asm_5829 ; 0x5847 $e0
+ jr .loop
TradeCenter_Trade:
- ld c, $64
+ ld c, 100
call DelayFrames
xor a
- ld [wcc43], a
- ld [wcc3e], a
+ ld [wSerialExchangeNybbleSendData + 1], a ; unnecessary
+ ld [wSerialExchangeNybbleReceiveData], a
ld [wcc37], a
ld [wMenuJoypadPollCount], a
- ld hl, wTileMap + $f0
- ld b, $4
- ld c, $12
- call Func_5ab3
- ld a, [wWhichTrade]
+ hlCoord 0, 12
+ ld b, 4
+ ld c, 18
+ call CableClub_TextBoxBorder
+ ld a, [wTradingWhichPlayerMon]
ld hl, wPartySpecies
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hl]
ld [wd11e], a
call GetMonName
ld hl, wcd6d
- ld de, wTrainerFacingDirection
- ld bc, $000b
+ ld de, wNameOfPlayerMonToBeTraded
+ ld bc, 11
call CopyData
- ld a, [wTrainerEngageDistance]
+ ld a, [wTradingWhichEnemyMon]
ld hl, wEnemyPartyMons
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hl]
ld [wd11e], a
call GetMonName
ld hl, WillBeTradedText
- ld bc, wTileMap + $119
+ bcCoord 1, 14
call TextCommandProcessor
call SaveScreenTilesToBuffer1
- ld hl, wTileMap + $96
+ hlCoord 10, 7
ld bc, $080b
- ld a, $5
- ld [wd12c], a
+ ld a, TRADE_CANCEL_MENU
+ ld [wTwoOptionMenuID], a
ld a, $14
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
call LoadScreenTilesFromBuffer1
ld a, [wCurrentMenuItem]
and a
- jr z, .asm_58d9 ; 0x58b9 $1e
+ jr z, .tradeConfirmed
+; if trade cancelled
ld a, $1
- ld [wcc42], a
- ld hl, wTileMap + $f0
- ld b, $4
- ld c, $12
- call Func_5ab3
- ld hl, wTileMap + $119
+ ld [wSerialExchangeNybbleSendData], a
+ hlCoord 0, 12
+ ld b, 4
+ ld c, 18
+ call CableClub_TextBoxBorder
+ hlCoord 1, 14
ld de, TradeCanceled
call PlaceString
- call Func_226e
- jp Func_5a18
-.asm_58d9
+ call Serial_PrintWaitingTextAndSyncAndExchangeByte
+ jp .tradeCancelled
+.tradeConfirmed
ld a, $2
- ld [wcc42], a
- call Func_226e
- ld a, [wcc3d]
- dec a
- jr nz, .asm_58fd ; 0x58e5 $16
- ld hl, wTileMap + $f0
- ld b, $4
- ld c, $12
- call Func_5ab3
- ld hl, wTileMap + $119
+ ld [wSerialExchangeNybbleSendData], a
+ call Serial_PrintWaitingTextAndSyncAndExchangeByte
+ ld a, [wSerialSyncAndExchangeNybbleReceiveData]
+ dec a ; did the other person cancel?
+ jr nz, .doTrade
+; if the other person cancelled
+ hlCoord 0, 12
+ ld b, 4
+ ld c, 18
+ call CableClub_TextBoxBorder
+ hlCoord 1, 14
ld de, TradeCanceled
call PlaceString
- jp Func_5a18
-.asm_58fd
- ld a, [wWhichTrade]
- ld hl, wPartyMonOT ; OT names of player
+ jp .tradeCancelled
+.doTrade
+ ld a, [wTradingWhichPlayerMon]
+ ld hl, wPartyMonOT
call SkipFixedLengthTextEntries
- ld de, wTrainerScreenX
- ld bc, $000b
+ ld de, wTradedPlayerMonOT
+ ld bc, 11
call CopyData
ld hl, wPartyMon1Species
- ld a, [wWhichTrade]
- ld bc, $002c
+ ld a, [wTradingWhichPlayerMon]
+ ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
- ld bc, $000c
+ ld bc, wPartyMon1OTID - wPartyMon1
add hl, bc
ld a, [hli]
- ld [wcd4c], a
+ ld [wTradedPlayerMonOTID], a
ld a, [hl]
- ld [wcd4d], a
- ld a, [wTrainerEngageDistance]
- ld hl, wEnemyMonOT ; OT names of other player
+ ld [wTradedPlayerMonOTID + 1], a
+ ld a, [wTradingWhichEnemyMon]
+ ld hl, wEnemyMonOT
call SkipFixedLengthTextEntries
- ld de, wcd4e
- ld bc, $000b
+ ld de, wTradedEnemyMonOT
+ ld bc, 11
call CopyData
ld hl, wEnemyMons
- ld a, [wTrainerEngageDistance]
- ld bc, $002c
+ ld a, [wTradingWhichEnemyMon]
+ ld bc, wEnemyMon2 - wEnemyMon1
call AddNTimes
- ld bc, $000c
+ ld bc, wEnemyMon1OTID - wEnemyMon1
add hl, bc
ld a, [hli]
- ld [wcd59], a
+ ld [wTradedEnemyMonOTID], a
ld a, [hl]
- ld [wcd5a], a
- ld a, [wWhichTrade]
+ ld [wTradedEnemyMonOTID + 1], a
+ ld a, [wTradingWhichPlayerMon]
ld [wWhichPokemon], a
ld hl, wPartySpecies
- ld b, $0
+ ld b, 0
ld c, a
add hl, bc
ld a, [hl]
- ld [wWhichTrade], a
+ ld [wTradedPlayerMonSpecies], a
xor a
ld [wcf95], a
call RemovePokemon
- ld a, [wTrainerEngageDistance]
+ ld a, [wTradingWhichEnemyMon]
ld c, a
ld [wWhichPokemon], a
ld hl, wEnemyPartyMons
- ld d, $0
+ ld d, 0
ld e, a
add hl, de
ld a, [hl]
@@ -787,10 +806,10 @@
ld [wcf91], a
ld hl, wEnemyMons
ld a, c
- ld bc, $002c
+ ld bc, wEnemyMon2 - wEnemyMon1
call AddNTimes
ld de, wcf98
- ld bc, $002c
+ ld bc, wEnemyMon2 - wEnemyMon1
call CopyData
call AddEnemyMonToPlayerParty
ld a, [wPartyCount]
@@ -798,13 +817,13 @@
ld [wWhichPokemon], a
ld a, $1
ld [wccd4], a
- ld a, [wTrainerEngageDistance]
+ ld a, [wTradingWhichEnemyMon]
ld hl, wEnemyPartyMons
- ld b, $0
+ ld b, 0
ld c, a
add hl, bc
ld a, [hl]
- ld [wTrainerEngageDistance], a
+ ld [wTradedEnemyMonSpecies], a
ld a, $a
ld [wMusicHeaderPointer], a
ld a, $2
@@ -812,46 +831,45 @@
ld a, MUSIC_SAFARI_ZONE
ld [wc0ee], a
call PlaySound
- ld c, $64
+ ld c, 100
call DelayFrames
call ClearScreen
call LoadHpBarAndStatusTilePatterns
xor a
ld [wcc5b], a
- ld a, [$ffaa]
- cp $1
- jr z, .asm_59d9 ; 0x59d0 $7
+ ld a, [hSerialConnectionStatus]
+ cp USING_EXTERNAL_CLOCK
+ jr z, .usingExternalClock
predef Func_410e2
- jr .asm_59de ; 0x59d7 $5
-.asm_59d9
+ jr .tradeCompleted
+.usingExternalClock
predef Func_410f3
-.asm_59de
+.tradeCompleted
callab TryEvolvingMon
call ClearScreen
call LoadTrainerInfoTextBoxTiles
- call Func_226e
- ld c, $28
+ call Serial_PrintWaitingTextAndSyncAndExchangeByte
+ ld c, 40
call DelayFrames
- ld hl, wTileMap + $f0
- ld b, $4
- ld c, $12
- call Func_5ab3
- ld hl, wTileMap + $119
+ hlCoord 0, 12
+ ld b, 4
+ ld c, 18
+ call CableClub_TextBoxBorder
+ hlCoord 1, 14
ld de, TradeCompleted
call PlaceString
predef SaveSAVtoSRAM2
- ld c, $32
+ ld c, 50
call DelayFrames
xor a
- ld [wcc38], a
- jp Func_5345
-
-Func_5a18:
- ld c, $64
+ ld [wTradeCenterPointerTableIndex], a
+ jp CableClub_DoBattleOrTradeAgain
+.tradeCancelled
+ ld c, 100
call DelayFrames
- xor a
- ld [wcc38], a
- jp Func_551c
+ xor a ; TradeCenter_SelectMon
+ ld [wTradeCenterPointerTableIndex], a
+ jp CallCurrentTradeCenterFunction
WillBeTradedText: ; 5a24 (1:5a24)
TX_FAR _WillBeTradedText
@@ -864,22 +882,22 @@
db "Too bad! The trade"
next "was canceled!@"
-PointerTable_5a5b: ; 5a5b (1:5a5b)
+TradeCenterPointerTable: ; 5a5b (1:5a5b)
dw TradeCenter_SelectMon
dw TradeCenter_Trade
-Func_5a5f: ; 5a5f (1:5a5f)
- ld a, [W_ISLINKBATTLE] ; W_ISLINKBATTLE
- cp $2
- jr z, .asm_5a75
- cp $3
- jr z, .asm_5a75
- cp $5
+CableClub_Run: ; 5a5f (1:5a5f)
+ ld a, [wLinkState]
+ cp LINK_STATE_START_TRADE
+ jr z, .doBattleOrTrade
+ cp LINK_STATE_START_BATTLE
+ jr z, .doBattleOrTrade
+ cp LINK_STATE_RESET ; this is never used
ret nz
- predef Func_5aaf
+ predef EmptyFunc3
jp Init
-.asm_5a75
- call Func_5317
+.doBattleOrTrade
+ call CableClub_DoBattleOrTrade
ld hl, Club_GFX
ld a, h
ld [W_TILESETGFXPTR + 1], a
@@ -893,10 +911,10 @@
ld a, l
ld [W_TILESETCOLLISIONPTR], a
xor a
- ld [W_GRASSRATE], a ; W_GRASSRATE
- inc a
- ld [W_ISLINKBATTLE], a ; W_ISLINKBATTLE
- ld [hJoy5], a
+ ld [W_GRASSRATE], a
+ inc a ; LINK_STATE_IN_CABLE_CLUB
+ ld [wLinkState], a
+ ld [$ffb5], a
ld a, $a
ld [wMusicHeaderPointer], a
ld a, BANK(Music_Celadon)
@@ -905,43 +923,46 @@
ld [wc0ee], a
jp PlaySound
-Func_5aaf: ; 5aaf (1:5aaf)
+EmptyFunc3: ; 5aaf (1:5aaf)
ret
-Func_5ab0:
+Diploma_TextBoxBorder: ; 5ab0 (1:5ab0)
call GetPredefRegisters
-Func_5ab3: ; 5ab3 (1:5ab3)
+; b = height
+; c = width
+CableClub_TextBoxBorder: ; 5ab3 (1:5ab3)
push hl
- ld a, $78
+ ld a, $78 ; border upper left corner tile
ld [hli], a
- inc a
- call Func_5ae0
- inc a
+ inc a ; border top horizontal line tile
+ call CableClub_DrawHorizontalLine
+ inc a ; border upper right corner tile
ld [hl], a
pop hl
- ld de, $14
+ ld de, 20
add hl, de
-.asm_5ac2
+.loop
push hl
- ld a, $7b
+ ld a, $7b ; border left vertical line tile
ld [hli], a
- ld a, $7f
- call Func_5ae0
- ld [hl], $77
+ ld a, " "
+ call CableClub_DrawHorizontalLine
+ ld [hl], $77 ; border right vertical line tile
pop hl
- ld de, $14
+ ld de, 20
add hl, de
dec b
- jr nz, .asm_5ac2
- ld a, $7c
+ jr nz, .loop
+ ld a, $7c ; border lower left corner tile
ld [hli], a
- ld a, $76
- call Func_5ae0
- ld [hl], $7d
+ ld a, $76 ; border bottom horizontal line tile
+ call CableClub_DrawHorizontalLine
+ ld [hl], $7d ; border lower right corner tile
ret
-Func_5ae0: ; 5ae0 (1:5ae0)
+; c = width
+CableClub_DrawHorizontalLine: ; 5ae0 (1:5ae0)
ld d, c
.asm_5ae1
ld [hli], a
--- a/engine/clear_save.asm
+++ b/engine/clear_save.asm
@@ -7,10 +7,10 @@
call PrintText
hlCoord 14, 7
ld bc, $80f
- ld a, $7
- ld [wd12c], a
+ ld a, NO_YES_MENU
+ ld [wTwoOptionMenuID], a
ld a, $14
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
ld a, [wCurrentMenuItem] ; wCurrentMenuItem
and a
--- a/engine/evolve_trade.asm
+++ b/engine/evolve_trade.asm
@@ -17,7 +17,7 @@
; This was fixed in Yellow.
- ld a, [wTradeMonNick]
+ ld a, [wInGameTradeReceiveMonName]
; GRAVELER
cp "G"
@@ -26,7 +26,7 @@
; "SPECTRE" (HAUNTER)
cp "S"
ret nz
- ld a, [wTradeMonNick + 1]
+ ld a, [wInGameTradeReceiveMonName + 1]
cp "P"
ret nz
@@ -36,9 +36,9 @@
ld [wWhichPokemon], a ; wWhichPokemon
ld a, $1
ld [wccd4], a
- ld a, $32
- ld [W_ISLINKBATTLE], a ; W_ISLINKBATTLE
+ ld a, LINK_STATE_TRADING
+ ld [wLinkState], a
callab TryEvolvingMon
- xor a
- ld [W_ISLINKBATTLE], a ; W_ISLINKBATTLE
+ xor a ; LINK_STATE_NONE
+ ld [wLinkState], a
jp PlayDefaultMusic
--- a/engine/evos_moves.asm
+++ b/engine/evos_moves.asm
@@ -70,9 +70,9 @@
cp EV_TRADE
jr z, .checkTradeEvo
; not trade evolution
- ld a, [W_ISLINKBATTLE]
- cp $32 ; in a trade?
- jr z, Evolution_PartyMonLoop ; if so, go the next mon
+ ld a, [wLinkState]
+ cp LINK_STATE_TRADING
+ jr z, Evolution_PartyMonLoop ; if trading, go the next mon
ld a, b
cp EV_ITEM
jr z, .checkItemEvo
@@ -83,9 +83,9 @@
cp EV_LEVEL
jr z, .checkLevel
.checkTradeEvo
- ld a, [W_ISLINKBATTLE]
- cp $32 ; in a trade?
- jp nz, .nextEvoEntry1 ; if not, go to the next evolution entry
+ ld a, [wLinkState]
+ cp LINK_STATE_TRADING
+ jp nz, .nextEvoEntry1 ; if not trading, go to the next evolution entry
ld a, [hli] ; level requirement
ld b, a
ld a, [wcfb9]
@@ -246,8 +246,8 @@
pop hl
pop af
ld [hTilesetType], a
- ld a, [W_ISLINKBATTLE]
- cp $32
+ ld a, [wLinkState]
+ cp LINK_STATE_TRADING
ret z
ld a, [W_ISINBATTLE]
and a
@@ -312,9 +312,9 @@
db "@"
Evolution_ReloadTilesetTilePatterns: ; 3af52 (e:6f52)
- ld a, [W_ISLINKBATTLE] ; W_ISLINKBATTLE
- cp $32 ; in a trade?
- ret z ; if so, return
+ ld a, [wLinkState]
+ cp LINK_STATE_TRADING
+ ret z
jp ReloadTilesetTilePatterns
LearnMoveFromLevelUp: ; 3af5b (e:6f5b)
--- a/engine/game_corner_slots.asm
+++ b/engine/game_corner_slots.asm
@@ -10,7 +10,7 @@
ld a, [wTrainerSpriteOffset]
and a
ret z
- ld a, [wcd05]
+ ld a, [wUnknownSlotVar]
ld b, a
ld a, [wTrainerFacingDirection]
inc a
--- a/engine/hall_of_fame.asm
+++ b/engine/hall_of_fame.asm
@@ -97,9 +97,9 @@
Func_70278: ; 70278 (1c:4278)
call ClearScreen
ld a, $d0
- ld [$ffaf], a
+ ld [hSCY], a
ld a, $c0
- ld [$ffae], a
+ ld [hSCX], a
ld a, [wWhichTrade] ; wWhichTrade
ld [wcf91], a
ld [wd0b5], a
@@ -132,7 +132,7 @@
.asm_702c7
call .asm_702d5
xor a
- ld [$ffaf], a
+ ld [hSCY], a
ld c, a
call Func_7036d
ld d, $0
@@ -139,9 +139,9 @@
ld e, $fc
.asm_702d5
call DelayFrame
- ld a, [$ffae]
+ ld a, [hSCX]
add e
- ld [$ffae], a
+ ld [hSCX], a
cp d
jr nz, .asm_702d5
ret
@@ -200,7 +200,7 @@
Func_7036d: ; 7036d (1c:436d)
ld b, $0
hlCoord 12, 5
- predef_jump Func_79dda
+ predef_jump CopyTileIDsFromList
Func_70377: ; 70377 (1c:4377)
ld hl, wd747
--- a/engine/hidden_object_functions17.asm
+++ b/engine/hidden_object_functions17.asm
@@ -67,7 +67,7 @@
ld [hWY], a
call SaveScreenTilesToBuffer1
ld a, $11
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
call UpdateSprites
ld a, [wcf91]
--- a/engine/in_game_trades.asm
+++ b/engine/in_game_trades.asm
@@ -1,4 +1,4 @@
-Predef54: ; 71ad9 (1c:5ad9)
+DoInGameTradeDialogue: ; 71ad9 (1c:5ad9)
; trigger the trade offer/action specified by wWhichTrade
call SaveScreenTilesToBuffer2
ld hl,TradeMons
@@ -8,15 +8,15 @@
sub b
sub b
ld c,a
- ld b,$0
+ ld b,0
add hl,bc
ld a,[hli]
- ld [wcd0f],a
+ ld [wInGameTradeGiveMonSpecies],a
ld a,[hli]
- ld [wcd34],a
+ ld [wInGameTradeReceiveMonSpecies],a
ld a,[hli]
push af
- ld de,wcd29
+ ld de,wInGameTradeMonNick
ld bc,$000b
call CopyData
pop af
@@ -26,16 +26,16 @@
add hl,hl
add hl,de
ld a,[hli]
- ld [wcd10],a
+ ld [wInGameTradeTextPointerTablePointer],a
ld a,[hl]
- ld [wcd11],a
- ld a,[wcd0f]
- ld de,wcd13
- call Func_71b6a
- ld a,[wcd34]
- ld de,wPlayerMonAccuracyMod
- call Func_71b6a
- ld hl,wd737
+ ld [wInGameTradeTextPointerTablePointer + 1],a
+ ld a,[wInGameTradeGiveMonSpecies]
+ ld de,wInGameTradeGiveMonName
+ call InGameTrade_GetMonName
+ ld a,[wInGameTradeReceiveMonSpecies]
+ ld de,wInGameTradeReceiveMonName
+ call InGameTrade_GetMonName
+ ld hl,wCompletedInGameTradeFlags
ld a,[wWhichTrade]
ld c,a
ld b,$2
@@ -43,28 +43,29 @@
ld a,c
and a
ld a,$4
- ld [wcd12],a
- jr nz,.asm_99bca ; 0x71b36 $20
+ ld [wInGameTradeTextPointerTableIndex],a
+ jr nz,.printText
+; if the trade hasn't been done yet
xor a
- ld [wcd12],a
- call .asm_99bca
+ ld [wInGameTradeTextPointerTableIndex],a
+ call .printText
ld a,$1
- ld [wcd12],a
+ ld [wInGameTradeTextPointerTableIndex],a
call YesNoChoice
ld a,[wCurrentMenuItem]
and a
- jr nz,.asm_99bca ; 0x71b4b $b
- call Func_71c07
- jr c,.asm_99bca ; 0x71b50 $6
+ jr nz,.printText
+ call InGameTrade_DoTrade
+ jr c,.printText
ld hl, TradedForText
call PrintText
-.asm_99bca ; 0x71b58
- ld hl,wcd12
- ld a,[hld]
+.printText
+ ld hl,wInGameTradeTextPointerTableIndex
+ ld a,[hld] ; wInGameTradeTextPointerTableIndex
ld e,a
- ld d,$0
- ld a,[hld]
- ld l,[hl]
+ ld d,0
+ ld a,[hld] ; wInGameTradeTextPointerTablePointer + 1
+ ld l,[hl] ; wInGameTradeTextPointerTablePointer
ld h,a
add hl,de
add hl,de
@@ -73,7 +74,8 @@
ld l,a
jp PrintText
-Func_71b6a: ; 71b6a (1c:5b6a)
+; copies name of species a to hl
+InGameTrade_GetMonName: ; 71b6a (1c:5b6a)
push de
ld [wd11e],a
call GetMonName
@@ -84,7 +86,7 @@
INCLUDE "data/trades.asm"
-Func_71c07: ; 71c07 (1c:5c07)
+InGameTrade_DoTrade: ; 71c07 (1c:5c07)
xor a
ld [wd07d],a
dec a
@@ -91,16 +93,16 @@
ld [wUpdateSpritesEnabled],a
call DisplayPartyMenu
push af
- call Func_71ca2
+ call InGameTrade_RestoreScreen
pop af
ld a,$1
- jp c,.asm_c4bc2
- ld a,[wcd0f]
+ jp c,.tradeFailed ; jump if the player didn't select a pokemon
+ ld a,[wInGameTradeGiveMonSpecies]
ld b,a
ld a,[wcf91]
cp b
ld a,$2
- jr nz,.asm_c4bc2 ; 0x71c26 $75
+ jr nz,.tradeFailed ; jump if the selected mon's species is not the required one
ld a,[wWhichPokemon]
ld hl,wPartyMon1Level
ld bc,$002c
@@ -107,7 +109,7 @@
call AddNTimes
ld a,[hl]
ld [W_CURENEMYLVL],a
- ld hl,wd737
+ ld hl,wCompletedInGameTradeFlags
ld a,[wWhichTrade]
ld c,a
ld b,$1
@@ -119,13 +121,13 @@
ld a,[W_CURENEMYLVL]
push af
call LoadHpBarAndStatusTilePatterns
- call Func_71cc1
+ call InGameTrade_PrepareTradeData
predef Func_410e2
pop af
ld [W_CURENEMYLVL],a
pop af
ld [wWhichPokemon],a
- ld a,[wcd34]
+ ld a,[wInGameTradeReceiveMonSpecies]
ld [wcf91],a
xor a
ld [wcc49],a
@@ -134,21 +136,21 @@
ld a,$80
ld [wcc49],a
call AddPartyMon
- call Func_71d19
+ call InGameTrade_CopyDataToReceivedMon
callab EvolveTradeMon
call ClearScreen
- call Func_71ca2
+ call InGameTrade_RestoreScreen
callba RedrawMapView
and a
ld a,$3
- jr .asm_ee803 ; 0x71c9b $1
-.asm_c4bc2 ; 0x71c9d
+ jr .tradeSucceeded
+.tradeFailed
scf
-.asm_ee803 ; 0x71c9e
- ld [wcd12],a
+.tradeSucceeded
+ ld [wInGameTradeTextPointerTableIndex],a
ret
-Func_71ca2: ; 71ca2 (1c:5ca2)
+InGameTrade_RestoreScreen: ; 71ca2 (1c:5ca2)
call GBPalWhiteOutWithDelay3
call RestoreScreenTilesAndReloadTilePatterns
call ReloadTilesetTilePatterns
@@ -155,43 +157,43 @@
call LoadScreenTilesFromBuffer2
call Delay3
call LoadGBPal
- ld c, $a
+ ld c, 10
call DelayFrames
ld b, BANK(LoadWildData)
ld hl, LoadWildData
jp Bankswitch
-Func_71cc1: ; 71cc1 (1c:5cc1)
- ld hl, wWhichTrade ; wWhichTrade
- ld a, [wcd0f]
- ld [hli], a
- ld a, [wcd34]
- ld [hl], a
- ld hl, wPartyMonOT ; wd273
+InGameTrade_PrepareTradeData: ; 71cc1 (1c:5cc1)
+ ld hl, wTradedPlayerMonSpecies
+ ld a, [wInGameTradeGiveMonSpecies]
+ ld [hli], a ; wTradedPlayerMonSpecies
+ ld a, [wInGameTradeReceiveMonSpecies]
+ ld [hl], a ; wTradedEnemyMonSpecies
+ ld hl, wPartyMonOT
ld bc, $b
- ld a, [wWhichPokemon] ; wWhichPokemon
+ ld a, [wWhichPokemon]
call AddNTimes
- ld de, wTrainerScreenX
+ ld de, wTradedPlayerMonOT
ld bc, $b
- call Func_71d11
- ld hl, String_71d59 ; $5d59
+ call InGameTrade_CopyData
+ ld hl, InGameTrade_TrainerString
ld de, wcd4e
- call Func_71d11
- ld de, W_GRASSRATE ; W_GRASSRATE
- call Func_71d11
- ld hl, wPartyMon1OTID ; wPartyMon1OTID
- ld bc, $2c
- ld a, [wWhichPokemon] ; wWhichPokemon
+ call InGameTrade_CopyData
+ ld de, W_GRASSRATE
+ call InGameTrade_CopyData
+ ld hl, wPartyMon1OTID
+ ld bc, wPartyMon2 - wPartyMon1
+ ld a, [wWhichPokemon]
call AddNTimes
- ld de, wcd4c
+ ld de, wTradedPlayerMonOTID
ld bc, $2
- call Func_71d11
+ call InGameTrade_CopyData
call Random
ld hl, hRandomAdd
- ld de, wcd59
+ ld de, wTradedEnemyMonOTID
jp CopyData
-Func_71d11: ; 71d11 (1c:5d11)
+InGameTrade_CopyData: ; 71d11 (1c:5d11)
push hl
push bc
call CopyData
@@ -199,28 +201,30 @@
pop hl
ret
-Func_71d19: ; 71d19 (1c:5d19)
- ld hl, wPartyMonNicks ; wPartyMonNicks
+InGameTrade_CopyDataToReceivedMon: ; 71d19 (1c:5d19)
+ ld hl, wPartyMonNicks
ld bc, $b
- call Func_71d4f
- ld hl, wcd29
+ call InGameTrade_GetReceivedMonPointer
+ ld hl, wInGameTradeMonNick
ld bc, $b
call CopyData
- ld hl, wPartyMonOT ; wd273
+ ld hl, wPartyMonOT
ld bc, $b
- call Func_71d4f
- ld hl, String_71d59 ; $5d59
+ call InGameTrade_GetReceivedMonPointer
+ ld hl, InGameTrade_TrainerString
ld bc, $b
call CopyData
- ld hl, wPartyMon1OTID ; wPartyMon1OTID
- ld bc, $2c
- call Func_71d4f
- ld hl, wcd59
+ ld hl, wPartyMon1OTID
+ ld bc, wPartyMon2 - wPartyMon1
+ call InGameTrade_GetReceivedMonPointer
+ ld hl, wTradedEnemyMonOTID
ld bc, $2
jp CopyData
-Func_71d4f: ; 71d4f (1c:5d4f)
- ld a, [wPartyCount] ; wPartyCount
+; the received mon's index is (partyCount - 1),
+; so this adds bc to hl (partyCount - 1) times and moves the result to de
+InGameTrade_GetReceivedMonPointer: ; 71d4f (1c:5d4f)
+ ld a, [wPartyCount]
dec a
call AddNTimes
ld e, l
@@ -227,7 +231,7 @@
ld d, h
ret
-String_71d59: ; 71d59 (1c:5d59)
+InGameTrade_TrainerString: ; 71d59 (1c:5d59)
; "TRAINER@@@@@@@@@@"
db $5d, "@@@@@@@@@@"
--- a/engine/intro.asm
+++ b/engine/intro.asm
@@ -7,7 +7,7 @@
call PlayIntroScene
call GBFadeOutToWhite
xor a
- ld [$ffae], a
+ ld [hSCX], a
ld [H_AUTOBGTRANSFERENABLED], a
call ClearSprites
call DelayFrame
@@ -21,7 +21,7 @@
ld [rOBP0], a
ld [rOBP1], a
xor a
- ld [$ffae], a
+ ld [hSCX], a
ld b, $3
call Func_4183f
ld a, 0
@@ -229,7 +229,7 @@
jr z, .asm_4181d
cp $1
jr z, .asm_4182d
- ld a, [$ffae]
+ ld a, [hSCX]
dec a
dec a
jr .asm_41831
@@ -243,11 +243,11 @@
call Func_417ae
pop de
.asm_4182d
- ld a, [$ffae]
+ ld a, [hSCX]
inc a
inc a
.asm_41831
- ld [$ffae], a
+ ld [hSCX], a
push de
ld c, $2
call CheckForUserInterruption
@@ -260,9 +260,9 @@
Func_4183f: ; 4183f (10:583f)
hlCoord 13, 7
-Func_41842: ; 41842 (10:5842)
+CopyTileIDsFromList_ZeroBaseTileID: ; 41842 (10:5842)
ld c, $0
- predef_jump Func_79dda
+ predef_jump CopyTileIDsFromList
Func_41849: ; 41849 (10:5849)
predef Func_79869
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -2098,7 +2098,7 @@
hlCoord 14, 7
ld bc,$080f
ld a,$14
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
ld a,[wCurrentMenuItem]
and a
@@ -2489,7 +2489,7 @@
hlCoord 14, 7
ld bc,$080f
ld a,$14
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
ld a,[wd12e]
cp a,2
--- a/engine/learn_move.asm
+++ b/engine/learn_move.asm
@@ -79,7 +79,7 @@
hlCoord 14, 7
ld bc, $80f
ld a, $14
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
ld a, [wCurrentMenuItem] ; wCurrentMenuItem
and a
@@ -102,7 +102,7 @@
hlCoord 14, 7
ld bc, $80f
ld a, $14
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
pop hl
ld a, [wCurrentMenuItem] ; wCurrentMenuItem
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -508,40 +508,40 @@
TX_FAR _MonWasReleasedText
db "@"
-PrintJustAMomentText1:: ; 5824 (8:5825)
- ld a, [$ffaa]
- cp $1
+CableClubLeftGameboy:: ; 5824 (8:5825)
+ ld a, [hSerialConnectionStatus]
+ cp USING_EXTERNAL_CLOCK
ret z
- ld a, [wSpriteStateData1 + 9]
- cp $c
+ ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ cp SPRITE_FACING_RIGHT
ret nz
ld a, [W_CURMAP]
cp BATTLE_CENTER
- ld a, $2
+ ld a, LINK_STATE_START_TRADE
jr z, .asm_2183a
- inc a
+ inc a ; LINK_STATE_START_BATTLE
.asm_2183a
- ld [W_ISLINKBATTLE], a
+ ld [wLinkState], a
call EnableAutoTextBoxDrawing
- ld a, $22
+ ld a, $22 ; JustAMomentText
jp PrintPredefTextID
-PrintJustAMomentText2:: ; 5845 (8:5845)
- ld a, [$ffaa]
- cp $2
+CableClubRightGameboy:: ; 5845 (8:5845)
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
ret z
- ld a, [wSpriteStateData1 + 9]
- cp $8
+ ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ cp SPRITE_FACING_LEFT
ret nz
ld a, [W_CURMAP]
cp BATTLE_CENTER
- ld a, $2
+ ld a, LINK_STATE_START_TRADE
jr z, .asm_2185a
- inc a
+ inc a ; LINK_STATE_START_BATTLE
.asm_2185a
- ld [W_ISLINKBATTLE], a
+ ld [wLinkState], a
call EnableAutoTextBoxDrawing
- ld a, $22
+ ld a, $22 ; JustAMomentText
jp PrintPredefTextID
JustAMomentText:: ; 21865 (8:5865)
@@ -548,8 +548,8 @@
TX_FAR _JustAMomentText
db "@"
- ld a, [wSpriteStateData1 + 9]
- cp $4
+ ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
ld a, $23
--- a/engine/menu/diploma.asm
+++ b/engine/menu/diploma.asm
@@ -14,7 +14,7 @@
call FarCopyData2
ld hl, wTileMap
ld bc, $1012
- predef Func_5ab0
+ predef Diploma_TextBoxBorder
ld hl, DiplomaTextPointersAndCoords ; $6784
ld c, $5
.asm_56715
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -14,8 +14,8 @@
.next0
ld c,20
call DelayFrames
- xor a
- ld [W_ISLINKBATTLE],a
+ xor a ; LINK_STATE_NONE
+ ld [wLinkState],a
ld hl,wcc2b
ld [hli],a
ld [hli],a
@@ -133,7 +133,7 @@
ld [wd358], a
ld hl, wd72e
set 6, [hl]
- ld hl, TextTerminator_6b20 ; $6b20
+ ld hl, TextTerminator_6b20
call PrintText
call SaveScreenTilesToBuffer1
ld hl, WhereWouldYouLikeText
@@ -149,7 +149,7 @@
xor a
ld [wcd37], a
ld [wd72d], a
- ld hl, wTopMenuItemY ; wTopMenuItemY
+ ld hl, wTopMenuItemY
ld a, $7
ld [hli], a
ld a, $6
@@ -163,74 +163,78 @@
ld [hli], a
xor a
ld [hl], a
-.asm_5c52
+.waitForInputLoop
call HandleMenuInput
- and $3
+ and A_BUTTON | B_BUTTON
add a
add a
ld b, a
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
add b
add $d0
- ld [wcc42], a
- ld [wcc43], a
-.asm_5c66
- call Func_2247
- ld a, [wcc3d]
+ ld [wLinkMenuSelectionSendBuffer], a
+ ld [wLinkMenuSelectionSendBuffer + 1], a
+.exchangeMenuSelectionLoop
+ call Serial_ExchangeLinkMenuSelection
+ ld a, [wLinkMenuSelectionReceiveBuffer]
ld b, a
and $f0
cp $d0
jr z, .asm_5c7d
- ld a, [wcc3e]
+ ld a, [wLinkMenuSelectionReceiveBuffer + 1]
ld b, a
and $f0
cp $d0
- jr nz, .asm_5c66
+ jr nz, .exchangeMenuSelectionLoop
.asm_5c7d
ld a, b
- and $c
- jr nz, .asm_5c8b
- ld a, [wcc42]
- and $c
- jr z, .asm_5c52
- jr .asm_5ca1
-.asm_5c8b
- ld a, [wcc42]
- and $c
- jr z, .asm_5c98
- ld a, [$ffaa]
- cp $2
- jr z, .asm_5ca1
-.asm_5c98
+ and $c ; did the enemy press A or B?
+ jr nz, .enemyPressedAOrB
+; the enemy didn't press A or B
+ ld a, [wLinkMenuSelectionSendBuffer]
+ and $c ; did the player press A or B?
+ jr z, .waitForInputLoop ; if neither the player nor the enemy pressed A or B, try again
+ jr .doneChoosingMenuSelection ; if the player pressed A or B but the enemy didn't, use the player's selection
+.enemyPressedAOrB
+ ld a, [wLinkMenuSelectionSendBuffer]
+ and $c ; did the player press A or B?
+ jr z, .useEnemyMenuSelection ; if the enemy pressed A or B but the player didn't, use the enemy's selection
+; the enemy and the player both pressed A or B
+; The gameboy that is clocking the connection wins.
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr z, .doneChoosingMenuSelection
+.useEnemyMenuSelection
ld a, b
- ld [wcc42], a
+ ld [wLinkMenuSelectionSendBuffer], a
and $3
ld [wCurrentMenuItem], a ; wCurrentMenuItem
-.asm_5ca1
- ld a, [$ffaa]
- cp $2
- jr nz, .asm_5cb1
+.doneChoosingMenuSelection
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr nz, .skipStartingTransfer
call DelayFrame
call DelayFrame
- ld a, $81
- ld [$ff02], a
-.asm_5cb1
+ ld a, START_TRANSFER_INTERNAL_CLOCK
+ ld [rSC], a
+.skipStartingTransfer
ld b, $7f
ld c, $7f
ld d, $ec
- ld a, [wcc42]
- and $8
- jr nz, .asm_5ccc
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wLinkMenuSelectionSendBuffer]
+ and (B_BUTTON << 2) ; was B button pressed?
+ jr nz, .updateCursorPosition
+; A button was pressed
+ ld a, [wCurrentMenuItem]
cp $2
- jr z, .asm_5ccc
+ jr z, .updateCursorPosition
ld c, d
ld d, b
dec a
- jr z, .asm_5ccc
+ jr z, .updateCursorPosition
ld b, c
ld c, d
-.asm_5ccc
+.updateCursorPosition
ld a, b
Coorda 6, 7
ld a, c
@@ -237,23 +241,23 @@
Coorda 6, 9
ld a, d
Coorda 6, 11
- ld c, $28
+ ld c, 40
call DelayFrames
call LoadScreenTilesFromBuffer1
- ld a, [wcc42]
- and $8
- jr nz, .asm_5d2d
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wLinkMenuSelectionSendBuffer]
+ and (B_BUTTON << 2) ; was B button pressed?
+ jr nz, .choseCancel ; cancel if B pressed
+ ld a, [wCurrentMenuItem]
cp $2
- jr z, .asm_5d2d
+ jr z, .choseCancel
xor a
- ld [wWalkBikeSurfState], a
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld [wWalkBikeSurfState], a ; start walking
+ ld a, [wCurrentMenuItem]
and a
ld a, TRADE_CENTER
- jr nz, .asm_5cfc
+ jr nz, .next
ld a, BATTLE_CENTER
-.asm_5cfc
+.next
ld [wd72d], a
ld hl, PleaseWaitText
call PrintText
@@ -261,23 +265,23 @@
call DelayFrames
ld hl, wd732
res 1, [hl]
- ld a, [W_ANIMATIONID] ; W_ANIMATIONID
+ ld a, [W_ANIMATIONID]
ld [wDestinationMap], a
call SpecialWarpIn
ld c, $14
call DelayFrames
xor a
- ld [wMenuJoypadPollCount], a ; wMenuJoypadPollCount
- ld [wcc42], a
- inc a
- ld [W_ISLINKBATTLE], a ; W_ISLINKBATTLE
+ ld [wMenuJoypadPollCount], a
+ ld [wSerialExchangeNybbleSendData], a
+ inc a ; LINK_STATE_IN_CABLE_CLUB
+ ld [wLinkState], a
ld [wcc47], a
jr SpecialEnterMap
-.asm_5d2d
+.choseCancel
xor a
- ld [wMenuJoypadPollCount], a ; wMenuJoypadPollCount
+ ld [wMenuJoypadPollCount], a
call Delay3
- call Func_72d7
+ call CloseLinkConnection
ld hl, LinkCanceledText
call PrintText
ld hl, wd72e
--- a/engine/menu/naming_screen.asm
+++ b/engine/menu/naming_screen.asm
@@ -16,7 +16,7 @@
hlCoord 14, 7
ld bc, $80f
ld a, $14
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
pop hl
ld a, [wCurrentMenuItem] ; wCurrentMenuItem
--- a/engine/menu/start_sub_menus.asm
+++ b/engine/menu/start_sub_menus.asm
@@ -31,7 +31,7 @@
.chosePokemon
call SaveScreenTilesToBuffer1 ; save screen
ld a,$04
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; display pokemon menu options
ld hl,wWhichTrade
ld bc,$020c ; max menu item ID, top menu item Y
@@ -300,13 +300,13 @@
call GoPAL_SET_CF1C
StartMenu_Item: ; 13302 (4:7302)
- ld a,[W_ISLINKBATTLE]
- dec a
- jr nz,.notInLinkBattle
+ ld a,[wLinkState]
+ dec a ; is the player in the Colosseum or Trade Centre?
+ jr nz,.notInCableClubRoom
ld hl,CannotUseItemsHereText
call PrintText
jr .exitMenu
-.notInLinkBattle
+.notInCableClubRoom
ld bc,wNumBagItems
ld hl,wcf8b
ld a,c
@@ -342,7 +342,7 @@
jp z,.useOrTossItem
.notBicycle1
ld a,$06 ; use/toss menu
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID
ld hl,wTopMenuItemY
ld a,11
--- a/engine/menu/vending_machine.asm
+++ b/engine/menu/vending_machine.asm
@@ -2,7 +2,7 @@
ld hl, VendingMachineText1
call PrintText
ld a, $13
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
xor a
ld [wCurrentMenuItem], a ; wCurrentMenuItem
@@ -70,7 +70,7 @@
ld c, $3
predef SubBCDPredef
ld a, $13
- ld [wd125], a
+ ld [wTextBoxID], a
jp DisplayTextBoxID
.BagFull
ld hl, VendingMachineText6
--- a/engine/mon_party_sprites.asm
+++ b/engine/mon_party_sprites.asm
@@ -382,7 +382,7 @@
ld c, a
dec a
srl a
- ld hl, MonPartyData ; $590d
+ ld hl, MonPartyData
ld e, a
ld d, $0
add hl, de
--- a/engine/overworld/cable_club_npc.asm
+++ b/engine/overworld/cable_club_npc.asm
@@ -1,51 +1,51 @@
CableClubNPC: ; 71c5 (1:71c5)
- ld hl, CableClubNPCText1
+ ld hl, CableClubNPCWelcomeText
call PrintText
ld a, [wd74b]
- bit 5, a
- jp nz, Func_71e1
+ bit 5, a ; received pokedex?
+ jp nz, .receivedPokedex
+; if the player hasn't received the pokedex
ld c, $3c
call DelayFrames
- ld hl, CableClubNPCText6
+ ld hl, CableClubNPCMakingPreparationsText
call PrintText
jp Func_7298
-
-Func_71e1: ; 71e1 (1:71e1)
+.receivedPokedex
ld a, $1
ld [wMenuJoypadPollCount], a
- ld a, $5a
- ld [wcc47], a
-.asm_71eb
- ld a, [$ffaa]
- cp $2
- jr z, .asm_721a ; 0x71ef $29
- cp $1
- jr z, .asm_721a ; 0x71f3 $25
- ld a, $ff
- ld [$ffaa], a
- ld a, $2
+ ld a, 90
+ ld [wLinkTimeoutCounter], a
+.establishConnectionLoop
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr z, .establishedConnection
+ cp USING_EXTERNAL_CLOCK
+ jr z, .establishedConnection
+ ld a, CONNECTION_NOT_ESTABLISHED
+ ld [hSerialConnectionStatus], a
+ ld a, ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK
ld [rSB], a
xor a
- ld [$ffad], a
- ld a, $80
- ld [$ff02], a
- ld a, [wcc47]
+ ld [hSerialReceiveData], a
+ ld a, START_TRANSFER_EXTERNAL_CLOCK
+ ld [rSC], a
+ ld a, [wLinkTimeoutCounter]
dec a
- ld [wcc47], a
- jr z, .asm_7287 ; 0x720b $7a
- ld a, $1
+ ld [wLinkTimeoutCounter], a
+ jr z, .failedToEstablishConnection
+ ld a, ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK
ld [rSB], a
- ld a, $81
- ld [$ff02], a
+ ld a, START_TRANSFER_INTERNAL_CLOCK
+ ld [rSC], a
call DelayFrame
- jr .asm_71eb ; 0x7218 $d1
-.asm_721a
- call Func_22ed
+ jr .establishConnectionLoop
+.establishedConnection
+ call Serial_SendZeroByte
call DelayFrame
- call Func_22ed
- ld c, $32
+ call Serial_SendZeroByte
+ ld c, 50
call DelayFrames
- ld hl, CableClubNPCText2
+ ld hl, CableClubNPCPleaseApplyHereHaveToSaveText
call PrintText
xor a
ld [wMenuJoypadPollCount], a
@@ -54,22 +54,22 @@
ld [wMenuJoypadPollCount], a
ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_728f ; 0x723e $4f
+ jr nz, .choseNo
callab SaveSAVtoSRAM
call WaitForSoundToFinish
ld a, (SFX_02_5d - SFX_Headers_02) / 3
call PlaySoundWaitForCurrent
- ld hl, CableClubNPCText3
+ ld hl, CableClubNPCPleaseWaitText
call PrintText
- ld hl, wcc47
+ ld hl, wUnknownSerialCounter
ld a, $3
ld [hli], a
xor a
ld [hl], a
- ld [$ffa9], a
- ld [wcc42], a
- call Func_227f
- ld hl, wcc47
+ ld [hSerialReceivedNewData], a
+ ld [wSerialExchangeNybbleSendData], a
+ call Serial_SyncAndExchangeNybble
+ ld hl, wUnknownSerialCounter
ld a, [hli]
inc a
jr nz, Func_72a8 ; 0x726b $3b
@@ -79,26 +79,26 @@
ld b, $a
.asm_7273
call DelayFrame
- call Func_22ed
+ call Serial_SendZeroByte
dec b
jr nz, .asm_7273 ; 0x727a $f7
- call Func_72d7
- ld hl, CableClubNPCText4
+ call CloseLinkConnection
+ ld hl, CableClubNPCLinkClosedBecauseOfInactivityText
call PrintText
jr Func_7298 ; 0x7285 $11
-.asm_7287
- ld hl, CableClubNPCText7
+.failedToEstablishConnection
+ ld hl, CableClubNPCAreaReservedFor2FriendsLinkedByCableText
call PrintText
jr Func_7298 ; 0x728d $9
-.asm_728f
- call Func_72d7
- ld hl, CableClubNPCText5
+.choseNo
+ call CloseLinkConnection
+ ld hl, CableClubNPCPleaseComeAgainText
call PrintText
; fall through
Func_7298: ; 7298 (1:7298)
xor a
- ld hl, wcc47
+ ld hl, wUnknownSerialCounter
ld [hli], a
ld [hl], a
ld hl, wd72e
@@ -115,42 +115,42 @@
ld b, BANK(LinkMenu)
jp Bankswitch
-CableClubNPCText7: ; 72b3 (1:72b3)
- TX_FAR _CableClubNPCText7
+CableClubNPCAreaReservedFor2FriendsLinkedByCableText: ; 72b3 (1:72b3)
+ TX_FAR _CableClubNPCAreaReservedFor2FriendsLinkedByCableText
db "@"
-CableClubNPCText1: ; 72b8 (1:72b8)
- TX_FAR _CableClubNPCText1
+CableClubNPCWelcomeText: ; 72b8 (1:72b8)
+ TX_FAR _CableClubNPCWelcomeText
db "@"
-CableClubNPCText2: ; 72bd (1:72bd)
- TX_FAR _CableClubNPCText2
+CableClubNPCPleaseApplyHereHaveToSaveText: ; 72bd (1:72bd)
+ TX_FAR _CableClubNPCPleaseApplyHereHaveToSaveText
db "@"
-CableClubNPCText3: ; 72c2 (1:72c2)
- TX_FAR _CableClubNPCText3
+CableClubNPCPleaseWaitText: ; 72c2 (1:72c2)
+ TX_FAR _CableClubNPCPleaseWaitText
db $a, "@"
-CableClubNPCText4: ; 72c8 (1:72c8)
- TX_FAR _CableClubNPCText4
+CableClubNPCLinkClosedBecauseOfInactivityText: ; 72c8 (1:72c8)
+ TX_FAR _CableClubNPCLinkClosedBecauseOfInactivityText
db "@"
-CableClubNPCText5: ; 72cd (1:72cd)
- TX_FAR _CableClubNPCText5
+CableClubNPCPleaseComeAgainText: ; 72cd (1:72cd)
+ TX_FAR _CableClubNPCPleaseComeAgainText
db "@"
-CableClubNPCText6: ; 72d2 (1:72d2)
- TX_FAR _CableClubNPCText6
+CableClubNPCMakingPreparationsText: ; 72d2 (1:72d2)
+ TX_FAR _CableClubNPCMakingPreparationsText
db "@"
-Func_72d7: ; 72d7 (1:72d7)
+CloseLinkConnection: ; 72d7 (1:72d7)
call Delay3
- ld a, $ff
- ld [$ffaa], a
- ld a, $2
+ ld a, CONNECTION_NOT_ESTABLISHED
+ ld [hSerialConnectionStatus], a
+ ld a, ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK
ld [rSB], a
xor a
- ld [$ffad], a
- ld a, $80
- ld [$ff02], a
+ ld [hSerialReceiveData], a
+ ld a, START_TRANSFER_EXTERNAL_CLOCK
+ ld [rSC], a
ret
--- a/engine/overworld/elevator.asm
+++ b/engine/overworld/elevator.asm
@@ -6,7 +6,7 @@
call Delay3
ld a, $ff
call PlaySound
- ld a, [$ffaf]
+ ld a, [hSCY]
ld d, a
ld e, $1
; number of times to play collision sfx
@@ -16,7 +16,7 @@
xor $fe
ld e, a
add d
- ld [$ffaf], a
+ ld [hSCY], a
push bc
ld c, BANK(SFX_02_5b)
ld a, (SFX_02_5b - SFX_Headers_02) / 3
@@ -27,7 +27,7 @@
dec b
jr nz, .asm_7bf30
ld a, d
- ld [$ffaf], a
+ ld [hSCY], a
ld a, $ff
call PlaySound
ld c, BANK(SFX_02_5f)
--- a/engine/overworld/pokemart.asm
+++ b/engine/overworld/pokemart.asm
@@ -12,10 +12,10 @@
inc a
ld [wcf93],a
ld a,$13
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; draw money text box
ld a,$15
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; do buy/sell/quit menu
ld hl,wd128 ; pointer to this pokemart's inventory
ld a,[hli]
@@ -46,7 +46,7 @@
.sellMenuLoop
call LoadScreenTilesFromBuffer1 ; restore saved screen
ld a,$13
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; draw money text box
ld hl,wNumBagItems
ld a,l
@@ -80,7 +80,7 @@
hlCoord 14, 7
ld bc,$080f
ld a,$14
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
ld a,[wd12e]
cp a,$02
@@ -120,7 +120,7 @@
.buyMenuLoop
call LoadScreenTilesFromBuffer1 ; restore saved screen
ld a,$13
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; draw money text box
ld hl,wStringBuffer2 + 11
ld a,l
@@ -151,7 +151,7 @@
hlCoord 14, 7
ld bc,$080f
ld a,$14
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
ld a,[wd12e]
cp a,$02
@@ -181,7 +181,7 @@
.returnToMainPokemartMenu
call LoadScreenTilesFromBuffer1
ld a,$13
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ; draw money text box
ld hl,PokemartAnythingElseText
call PrintText
--- a/engine/predefs.asm
+++ b/engine/predefs.asm
@@ -91,17 +91,17 @@
add_predef Func_48125
add_predef UpdateHPBar
add_predef HPBarLength
- add_predef Func_5ab0
+ add_predef Diploma_TextBoxBorder
add_predef Func_3ed02
add_predef ShowPokedexMenu
add_predef EvolutionAfterBattle
add_predef SaveSAVtoSRAM0
add_predef InitOpponent
- add_predef Func_5a5f
+ add_predef CableClub_Run
add_predef DrawBadges
add_predef Func_410f3
add_predef BattleTransition
- add_predef Func_79dda
+ add_predef CopyTileIDsFromList
add_predef PlayIntro
add_predef Func_79869
add_predef FlashScreen
@@ -129,7 +129,7 @@
add_predef LoadTownMap_Nest
add_predef Func_27d6b
add_predef EmotionBubble; 4C player exclamation
- add_predef Func_5aaf; return immediately
+ add_predef EmptyFunc3; return immediately
add_predef AskName
add_predef PewterGuys
add_predef SaveSAVtoSRAM2
@@ -136,7 +136,7 @@
add_predef LoadSAVCheckSum2
add_predef LoadSAV
add_predef SaveSAVtoSRAM1
- add_predef Predef54 ; 54 initiate trade
+ add_predef DoInGameTradeDialogue ; 54 initiate trade
add_predef HallOfFamePC
add_predef DisplayDexRating
dbw $1E, _LeaveMapAnim ; wrong bank
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -175,7 +175,7 @@
hlCoord 0, 7
ld bc,$0801 ;arrow's coordinates |b = Y|c = X|
ld a,$14 ;one line shifting ($28 = 2 lines)
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID ;handle Yes/No KeyPress
ld a,[wCurrentMenuItem]
ret
--- a/engine/slot_machine.asm
+++ b/engine/slot_machine.asm
@@ -135,10 +135,10 @@
call PrintText
ld hl, wTileMap + $fe
ld bc, $0d0f
- xor a
- ld [wd12c], a
+ xor a ; YES_NO_MENU
+ ld [wTwoOptionMenuID], a
ld a, $14
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
ld a, [wCurrentMenuItem]
and a
--- a/engine/titlescreen.asm
+++ b/engine/titlescreen.asm
@@ -27,9 +27,9 @@
ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
xor a
ld [hTilesetType], a
- ld [$ffae], a
+ ld [hSCX], a
ld a, $40
- ld [$ffaf], a
+ ld [hSCY], a
ld a, $90
ld [hWY], a
call ClearScreen
--- a/engine/trade.asm
+++ b/engine/trade.asm
@@ -1,13 +1,13 @@
Func_410e2: ; 410e2 (10:50e2)
- ld a, [wWhichTrade] ; wWhichTrade
+ ld a, [wTradedPlayerMonSpecies]
ld [wcd5e], a
- ld a, [wTrainerEngageDistance]
+ ld a, [wTradedEnemyMonSpecies]
ld [wcd5f], a
- ld de, PointerIDs_41138 ; $5138
+ ld de, PointerIDs_41138
jr Func_41102
Func_410f3: ; 410f3 (10:50f3)
- ld a, [wTrainerEngageDistance]
+ ld a, [wTradedEnemyMonSpecies]
ld [wcd5e], a
ld a, [wTrainerSpriteOffset]
ld [wcd5f], a
@@ -14,16 +14,16 @@
ld de, PointerIDs_41149
Func_41102: ; 41102 (10:5102)
- ld a, [W_OPTIONS] ; W_OPTIONS
+ ld a, [W_OPTIONS]
push af
- ld a, [$ffaf]
+ ld a, [hSCY]
push af
- ld a, [$ffae]
+ ld a, [hSCX]
push af
xor a
- ld [W_OPTIONS], a ; W_OPTIONS
- ld [$ffaf], a
- ld [$ffae], a
+ ld [W_OPTIONS], a
+ ld [hSCY], a
+ ld [hSCX], a
push de
.asm_41115
pop de
@@ -32,7 +32,7 @@
jr z, .asm_4112d
inc de
push de
- ld hl, PointerTable_4115f ; $515f
+ ld hl, PointerTable_4115f
add a
ld c, a
ld b, $0
@@ -40,16 +40,16 @@
ld a, [hli]
ld h, [hl]
ld l, a
- ld de, .asm_41115 ; $5115
+ ld de, .asm_41115
push de
jp [hl]
.asm_4112d
pop af
- ld [$ffae], a
+ ld [hSCX], a
pop af
- ld [$ffaf], a
+ ld [hSCY], a
pop af
- ld [W_OPTIONS], a ; W_OPTIONS
+ ld [W_OPTIONS], a
ret
; these bytes refer to the $00th through $10th pointer of PointerTable_4115f
@@ -61,13 +61,13 @@
PointerTable_4115f: ; 4115f (10:515f)
dw LoadTradingGFXAndMonNames
- dw Func_41245
- dw Func_41298
- dw Func_412d2
- dw Func_41336
+ dw Trade_ShowPlayerMon
+ dw Trade_DrawOpenEndOfLinkCable
+ dw Trade_AnimateBallEnteringLinkCable
+ dw Trade_ShowEnemyMon
dw Func_41376
dw Func_413c6
- dw Func_41181
+ dw Trade_Delay100
dw Func_415c8
dw PrintTradeWentToText
dw PrintTradeForSendsText
@@ -76,39 +76,39 @@
dw PrintTradeWillTradeText
dw Func_4123b
dw Func_415df
- dw Func_41217
+ dw Trade_SwapNames
-Func_41181: ; 41181 (10:5181)
- ld c, $64
+Trade_Delay100: ; 41181 (10:5181)
+ ld c, 100
jp DelayFrames
-Func_41186: ; 41186 (10:5186)
+Trade_CopyTileMapToVRAM: ; 41186 (10:5186)
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
ret
-Delay50: ; 41191 (10:5191)
- ld c, $50
+Trade_Delay80: ; 41191 (10:5191)
+ ld c, 80
jp DelayFrames
-Func_41196: ; 41196 (10:5196)
+Trade_ClearTileMap: ; 41196 (10:5196)
ld hl, wTileMap
- ld bc, $168
- ld a, $7f
+ ld bc, 20 * 18
+ ld a, " "
jp FillMemory
LoadTradingGFXAndMonNames: ; 411a1 (10:51a1)
- call Func_41196
+ call Trade_ClearTileMap
call DisableLCD
- ld hl, TradingAnimationGraphics ; $69be
+ ld hl, TradingAnimationGraphics
ld de, vChars2 + $310
ld bc, $310
ld a, BANK(TradingAnimationGraphics)
call FarCopyData2
- ld hl, TradingAnimationGraphics2 ; $6cce
+ ld hl, TradingAnimationGraphics2
ld de, vSprites + $7c0
ld bc, $40
ld a, BANK(TradingAnimationGraphics2)
@@ -115,7 +115,7 @@
call FarCopyData2
ld hl, vBGMap0
ld bc, $800
- ld a, $7f
+ ld a, " "
call FillMemory
call ClearSprites
ld a, $ff
@@ -128,11 +128,11 @@
jr z, .asm_411e5
ld a, $f0
.asm_411e5
- ld [rOBP0], a ; $ff48
+ ld [rOBP0], a
call EnableLCD
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld a, [wWhichTrade] ; wWhichTrade
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, [wTradedPlayerMonSpecies]
ld [wd11e], a
call GetMonName
ld hl, wcd6d
@@ -139,29 +139,29 @@
ld de, wcf4b
ld bc, $b
call CopyData
- ld a, [wTrainerEngageDistance]
+ ld a, [wTradedEnemyMonSpecies]
ld [wd11e], a
jp GetMonName
Func_4120b: ; 4120b (10:520b)
- ld a, $d0
- ld [rOBP1], a ; $ff49
+ ld a, %11010000
+ ld [rOBP1], a
ld b, BANK(Func_7176c)
ld hl, Func_7176c
jp Bankswitch
-Func_41217: ; 41217 (10:5217)
+Trade_SwapNames: ; 41217 (10:5217)
ld hl, wPlayerName
- ld de, wHPBarMaxHP
- ld bc, $000b
+ ld de, wBuffer
+ ld bc, 11
call CopyData
- ld hl, W_GRASSRATE
+ ld hl, wLinkEnemyTrainerName
ld de, wPlayerName
- ld bc, $000b
+ ld bc, 11
call CopyData
- ld hl, wHPBarMaxHP
- ld de, W_GRASSRATE
- ld bc, $000b
+ ld hl, wBuffer
+ ld de, wLinkEnemyTrainerName
+ ld bc, 11
jp CopyData
Func_4123b: ; 4123b (10:523b)
@@ -171,90 +171,90 @@
res 6, [hl]
ret
-Func_41245: ; 41245 (10:5245)
- ld a, $ab
- ld [rLCDC], a ; $ff40
+Trade_ShowPlayerMon: ; 41245 (10:5245)
+ ld a, %10101011
+ ld [rLCDC], a
ld a, $50
ld [hWY], a
ld a, $86
- ld [rWX], a ; $ff4b
- ld [$ffae], a
+ ld [rWX], a
+ ld [hSCX], a
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
hlCoord 4, 0
- ld b, $6
- ld c, $a
+ ld b, 6
+ ld c, 10
call TextBoxBorder
- call Func_42769
+ call Trade_PrintPlayerMonInfoText
ld b, $98
call CopyScreenTileBufferToVRAM
call ClearScreen
- ld a, [wWhichTrade] ; wWhichTrade
- call Func_415a4
+ ld a, [wTradedPlayerMonSpecies]
+ call Trade_LoadMonSprite
ld a, $7e
-.asm_41273
+.slideScreenLoop
push af
call DelayFrame
pop af
- ld [rWX], a ; $ff4b
- ld [$ffae], a
+ ld [rWX], a
+ ld [hSCX], a
dec a
dec a
and a
- jr nz, .asm_41273
- call Delay50
- ld a, ANIM_AD
- call Func_41676
- ld a, ANIM_AA
- call Func_41676
- ld a, [wWhichTrade] ; wWhichTrade
+ jr nz, .slideScreenLoop
+ call Trade_Delay80
+ ld a, TRADE_BALL_POOF_ANIM
+ call Trade_ShowAnimation
+ ld a, TRADE_BALL_DROP_ANIM
+ call Trade_ShowAnimation
+ ld a, [wTradedPlayerMonSpecies]
call PlayCry
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
ret
-Func_41298: ; 41298 (10:5298)
- call Func_41196
+Trade_DrawOpenEndOfLinkCable: ; 41298 (10:5298)
+ call Trade_ClearTileMap
ld b, $98
call CopyScreenTileBufferToVRAM
ld b, $8
call GoPAL_SET
ld hl, vBGMap1 + $8c
- call Func_414ae
+ call Trade_RedrawRows4And5
ld a, $a0
- ld [$ffae], a
+ ld [hSCX], a
call DelayFrame
- ld a, $8b
- ld [rLCDC], a ; $ff40
+ ld a, %10001011
+ ld [rLCDC], a
hlCoord 6, 2
- ld b, $7
- call Func_41842
- call Func_41186
+ ld b, $7 ; open end of link cable tile ID list index
+ call CopyTileIDsFromList_ZeroBaseTileID
+ call Trade_CopyTileMapToVRAM
ld a, (SFX_02_3d - SFX_Headers_02) / 3
call PlaySound
- ld c, $14
-.asm_412c8
- ld a, [$ffae]
- add $4
- ld [$ffae], a
+ ld c, 20
+.loop
+ ld a, [hSCX]
+ add 4
+ ld [hSCX], a
dec c
- jr nz, .asm_412c8
+ jr nz, .loop
ret
-Func_412d2: ; 412d2 (10:52d2)
- ld a, ANIM_AB
- call Func_41676
+Trade_AnimateBallEnteringLinkCable: ; 412d2 (10:52d2)
+ ld a, TRADE_BALL_SHAKE_ANIM
+ call Trade_ShowAnimation
ld c, 10
call DelayFrames
- ld a, $e4
- ld [rOBP0], a ; $ff48
+ ld a, %11100100
+ ld [rOBP0], a
xor a
ld [wd09f], a
ld bc, $2060
-.asm_412e7
+.moveBallInsideLinkCableLoop
push bc
xor a
- ld de, UnknownOAM_4132e ; $532e
+ ld de, Trade_BallInsideLinkCableOAM
call WriteOAMBlock
ld a, [wd09f]
xor $1
@@ -263,11 +263,11 @@
ld hl, wOAMBuffer + $02
ld de, $4
ld c, e
-.asm_41300
+.cycleSpriteFramesLoop
ld [hl], a
add hl, de
dec c
- jr nz, .asm_41300
+ jr nz, .cycleSpriteFramesLoop
call Delay3
pop bc
ld a, c
@@ -274,47 +274,47 @@
add $4
ld c, a
cp $a0
- jr nc, .asm_41318
+ jr nc, .ballSpriteReachedEdgeOfScreen
ld a, (SFX_02_3c - SFX_Headers_02) / 3
call PlaySound
- jr .asm_412e7
-.asm_41318
+ jr .moveBallInsideLinkCableLoop
+.ballSpriteReachedEdgeOfScreen
call ClearSprites
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call ClearScreen
ld b, $98
call CopyScreenTileBufferToVRAM
call Delay3
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
ret
-UnknownOAM_4132e: ; 4132e (10:532e)
+Trade_BallInsideLinkCableOAM: ; 4132e (10:532e)
db $7E,$00,$7E,$20
db $7E,$40,$7E,$60
-Func_41336: ; 41336 (10:5336)
- ld a, ANIM_AC
- call Func_41676
+Trade_ShowEnemyMon: ; 41336 (10:5336)
+ ld a, TRADE_BALL_TILT_ANIM
+ call Trade_ShowAnimation
call Func_415c8
hlCoord 4, 10
- ld b, $6
- ld c, $a
+ ld b, 6
+ ld c, 10
call TextBoxBorder
- call Func_427a7
- call Func_41186
+ call Trade_PrintEnemyMonInfoText
+ call Trade_CopyTileMapToVRAM
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld a, [wTrainerEngageDistance]
- call Func_415a4
- ld a, ANIM_AD
- call Func_41676
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, [wTradedEnemyMonSpecies]
+ call Trade_LoadMonSprite
+ ld a, TRADE_BALL_POOF_ANIM
+ call Trade_ShowAnimation
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld a, [wTrainerEngageDistance]
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, [wTradedEnemyMonSpecies]
call PlayCry
- call Func_41181
+ call Trade_Delay100
hlCoord 4, 10
ld bc, $80c
call ClearScreenArea
@@ -325,23 +325,23 @@
ld a, $1
ld [wd08a], a
ld a, $e4
- ld [rOBP0], a ; $ff48
+ ld [rOBP0], a
ld a, $54
- ld [W_BASECOORDX], a ; wd081
+ ld [W_BASECOORDX], a
ld a, $1c
- ld [W_BASECOORDY], a ; wd082
+ ld [W_BASECOORDY], a
ld a, [wcd5e]
ld [wcd5d], a
call Func_41505
call Func_4142d
- call Func_41186
+ call Trade_CopyTileMapToVRAM
call Func_4149f
ld hl, vBGMap1 + $8c
- call Func_414ae
+ call Trade_RedrawRows4And5
ld b, $6
call Func_414c5
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call Func_4149f
ld b, $4
call Func_414c5
@@ -349,7 +349,7 @@
ld b, $6
call Func_414c5
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call Func_41525
jp ClearSprites
@@ -358,22 +358,22 @@
xor a
ld [wd08a], a
ld a, $64
- ld [W_BASECOORDX], a ; wd081
+ ld [W_BASECOORDX], a
ld a, $44
- ld [W_BASECOORDY], a ; wd082
+ ld [W_BASECOORDY], a
ld a, [wcd5f]
ld [wcd5d], a
call Func_41505
call Func_4145c
- call Func_41186
+ call Trade_CopyTileMapToVRAM
call Func_4149f
ld hl, vBGMap1 + $94
- call Func_414ae
+ call Trade_RedrawRows4And5
call Func_41525
ld b, $6
call Func_414c5
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call Func_4149f
ld b, $4
call Func_414c5
@@ -381,27 +381,27 @@
ld b, $6
call Func_414c5
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
jp ClearSprites
Func_41411: ; 41411 (10:5411)
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call ClearScreen
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call Func_4120b
call DelayFrame
- ld a, $ab
- ld [rLCDC], a ; $ff40
+ ld a, %10101011
+ ld [rLCDC], a
xor a
- ld [$ffae], a
+ ld [hSCX], a
ld a, $90
ld [hWY], a
ret
Func_4142d: ; 4142d (10:542d)
- call Func_41196
+ call Trade_ClearTileMap
hlCoord 11, 4
ld a, $5d
ld [hli], a
@@ -413,18 +413,18 @@
jr nz, .asm_4143a
hlCoord 5, 3
ld b, $6
- call Func_41842
+ call CopyTileIDsFromList_ZeroBaseTileID
hlCoord 4, 12
- ld b, $2
- ld c, $7
+ ld b, 2
+ ld c, 7
call TextBoxBorder
hlCoord 5, 14
- ld de, wPlayerName ; wd158
+ ld de, wPlayerName
call PlaceString
jp DelayFrame
Func_4145c: ; 4145c (10:545c)
- call Func_41196
+ call Trade_ClearTileMap
hlCoord 0, 4
ld a, $5e
ld c, $e
@@ -451,18 +451,18 @@
ld [hl], a
hlCoord 7, 8
ld b, $6
- call Func_41842
+ call CopyTileIDsFromList_ZeroBaseTileID
hlCoord 6, 0
ld b, $2
ld c, $7
call TextBoxBorder
hlCoord 7, 2
- ld de, W_GRASSRATE ; W_GRASSRATE
+ ld de, wLinkEnemyTrainerName
call PlaceString
jp DelayFrame
Func_4149f: ; 4149f (10:549f)
- call Func_41196
+ call Trade_ClearTileMap
hlCoord 0, 4
ld a, $5e
ld c, $14
@@ -472,7 +472,7 @@
jr nz, .asm_414a9
ret
-Func_414ae: ; 414ae (10:54ae)
+Trade_RedrawRows4And5: ; 414ae (10:54ae)
push hl
hlCoord 0, 4
call CopyToScreenEdgeTiles
@@ -480,10 +480,10 @@
ld a, h
ld [H_SCREENEDGEREDRAWADDR + 1], a
ld a, l
- ld [H_SCREENEDGEREDRAWADDR], a ; $ffd1
- ld a, $2
- ld [H_SCREENEDGEREDRAW], a ; $ffd0
- ld c, $a
+ ld [H_SCREENEDGEREDRAWADDR], a
+ ld a, REDRAWROW
+ ld [H_SCREENEDGEREDRAW], a
+ ld c, 10
jp DelayFrames
Func_414c5: ; 414c5 (10:54c5)
@@ -494,14 +494,14 @@
ld a, e
dec a
jr z, .asm_414d5
- ld a, [$ffae]
+ ld a, [hSCX]
sub $2
jr .asm_414d9
.asm_414d5
- ld a, [$ffae]
+ ld a, [hSCX]
add $2
.asm_414d9
- ld [$ffae], a
+ ld [hSCX], a
call DelayFrame
dec d
jr nz, .asm_414cb
@@ -514,9 +514,9 @@
push de
push bc
push hl
- ld a, [rBGP] ; $ff47
+ ld a, [rBGP]
xor $3c
- ld [rBGP], a ; $ff47
+ ld [rBGP], a
ld hl, wOAMBuffer + $02
ld de, $4
ld c, $14
@@ -540,10 +540,10 @@
ld hl, wOAMBuffer
ld c, $14
.asm_41515
- ld a, [W_BASECOORDY] ; wd082
+ ld a, [W_BASECOORDY]
add [hl]
ld [hli], a
- ld a, [W_BASECOORDX] ; wd081
+ ld a, [W_BASECOORDX]
add [hl]
ld [hli], a
inc hl
@@ -566,9 +566,9 @@
ld bc, $fc00
.asm_4153f
ld a, b
- ld [W_BASECOORDX], a ; wd081
+ ld [W_BASECOORDX], a
ld a, c
- ld [W_BASECOORDY], a ; wd082
+ ld [W_BASECOORDY], a
ld d, $4
.asm_41549
call Func_41510
@@ -580,7 +580,7 @@
ret
Func_41558: ; 41558 (10:5558)
- ld hl, OAMPointers_41574 ; $5574
+ ld hl, OAMPointers_41574
ld c, $4
xor a
.asm_4155e
@@ -630,7 +630,8 @@
db $3B,$70,$3A,$70
db $39,$70,$38,$70
-Func_415a4: ; 415a4 (10:55a4)
+; a = species
+Trade_LoadMonSprite: ; 415a4 (10:55a4)
ld [wcf91], a
ld [wd0b5], a
ld [wcf1d], a
@@ -637,51 +638,51 @@
ld b, $b
ld c, $0
call GoPAL_SET
- ld a, [H_AUTOBGTRANSFERENABLED] ; $ffba
+ ld a, [H_AUTOBGTRANSFERENABLED]
xor $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call GetMonHeader
hlCoord 7, 2
call LoadFlippedFrontSpriteByMonIndex
- ld c, $a
+ ld c, 10
jp DelayFrames
Func_415c8: ; 415c8 (10:55c8)
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call ClearScreen
- ld a, $e3
- ld [rLCDC], a ; $ff40
+ ld a, %11100011
+ ld [rLCDC], a
ld a, $7
- ld [rWX], a ; $ff4b
+ ld [rWX], a
xor a
ld [hWY], a
ld a, $90
- ld [$ffae], a
+ ld [hSCX], a
ret
Func_415df: ; 415df (10:55df)
- ld c, $32
+ ld c, 50
call DelayFrames
-.asm_415e4
+.loop
call DelayFrame
- ld a, [rWX] ; $ff4b
+ ld a, [rWX]
inc a
inc a
- ld [rWX], a ; $ff4b
+ ld [rWX], a
cp $a1
- jr nz, .asm_415e4
- call Func_41196
- ld c, $a
+ jr nz, .loop
+ call Trade_ClearTileMap
+ ld c, 10
call DelayFrames
ld a, $7
- ld [rWX], a ; $ff4b
+ ld [rWX], a
ret
PrintTradeWentToText: ; 415fe (10:55fe)
ld hl, TradeWentToText
call PrintText
- ld c, $c8
+ ld c, 200
call DelayFrames
jp Func_415df
@@ -692,10 +693,10 @@
PrintTradeForSendsText: ; 41611 (10:5611)
ld hl, TradeForText
call PrintText
- call Delay50
+ call Trade_Delay80
ld hl, TradeSendsText
call PrintText
- jp Delay50
+ jp Trade_Delay80
TradeForText: ; 41623 (10:5623)
TX_FAR _TradeForText
@@ -708,10 +709,10 @@
PrintTradeFarewellText: ; 4162d (10:562d)
ld hl, TradeWavesFarewellText
call PrintText
- call Delay50
+ call Trade_Delay80
ld hl, TradeTransferredText
call PrintText
- call Delay50
+ call Trade_Delay80
jp Func_415df
TradeWavesFarewellText: ; 41642 (10:5642)
@@ -725,7 +726,7 @@
PrintTradeTakeCareText: ; 4164c (10:564c)
ld hl, TradeTakeCareText
call PrintText
- jp Delay50
+ jp Trade_Delay80
TradeTakeCareText: ; 41655 (10:5655)
TX_FAR _TradeTakeCareText
@@ -734,10 +735,10 @@
PrintTradeWillTradeText: ; 4165a (10:565a)
ld hl, TradeWillTradeText
call PrintText
- call Delay50
+ call Trade_Delay80
ld hl, TradeforText
call PrintText
- jp Delay50
+ jp Trade_Delay80
TradeWillTradeText: ; 4166c (10:566c)
TX_FAR _TradeWillTradeText
@@ -747,8 +748,8 @@
TX_FAR _TradeforText
db "@"
-Func_41676: ; 41676 (10:5676)
- ld [W_ANIMATIONID], a ; W_ANIMATIONID
+Trade_ShowAnimation: ; 41676 (10:5676)
+ ld [W_ANIMATIONID], a
xor a
ld [wcc5b], a
predef_jump MoveAnimation
--- a/engine/trade2.asm
+++ b/engine/trade2.asm
@@ -1,8 +1,8 @@
-Func_42769: ; 42769 (10:6769)
+Trade_PrintPlayerMonInfoText: ; 42769 (10:6769)
hlCoord 5, 0
- ld de,OTString67E5
+ ld de,Trade_MonInfoText
call PlaceString
- ld a,[wWhichTrade]
+ ld a,[wTradedPlayerMonSpecies]
ld [wd11e],a
predef IndexToPokedex
hlCoord 9, 0
@@ -13,18 +13,18 @@
ld de,wcf4b
call PlaceString
hlCoord 8, 4
- ld de,wTrainerScreenX
+ ld de,wTradedPlayerMonOT
call PlaceString
hlCoord 8, 6
- ld de,wcd4c
+ ld de,wTradedPlayerMonOTID
ld bc,$8205
jp PrintNumber
-Func_427a7: ; 427a7 (10:67a7)
+Trade_PrintEnemyMonInfoText: ; 427a7 (10:67a7)
hlCoord 5, 10
- ld de,OTString67E5
+ ld de,Trade_MonInfoText
call PlaceString
- ld a,[wTrainerEngageDistance]
+ ld a,[wTradedEnemyMonSpecies]
ld [wd11e],a
predef IndexToPokedex
hlCoord 9, 10
@@ -35,14 +35,14 @@
ld de,wcd6d
call PlaceString
hlCoord 8, 14
- ld de,wcd4e
+ ld de,wTradedEnemyMonOT
call PlaceString
hlCoord 8, 16
- ld de,wcd59
+ ld de,wTradedEnemyMonOTID
ld bc,$8205
jp PrintNumber
-OTString67E5: ; 427e5 (10:67e5)
+Trade_MonInfoText: ; 427e5 (10:67e5)
db "──",$74,$F2,$4E
db $4E
db "OT/",$4E