shithub: pokecrystal

Download patch

ref: 7991db972b5892c36a7b004404c16f28f6b65bad
parent: 8a73bb9ab2ed8dd7ee7d5583efd5a7488687c29c
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Fri Oct 23 09:36:54 EDT 2020

Identify some more link.asm labels (syncing to pokegold)

--- a/data/events/special_pointers.asm
+++ b/data/events/special_pointers.asm
@@ -12,7 +12,7 @@
 ; Communications
 	add_special SetBitsForLinkTradeRequest
 	add_special WaitForLinkedFriend
-	add_special CheckLinkTimeout
+	add_special CheckLinkTimeout_Receptionist
 	add_special TryQuickSave
 	add_special CheckBothSelectedSameRoom
 	add_special FailedLinkToPast
--- a/engine/link/link.asm
+++ b/engine/link/link.asm
@@ -182,7 +182,7 @@
 	call ClearLinkData
 	call Link_PrepPartyData_Gen2
 	call FixDataForLinkTransfer
-	call Function29dba
+	call CheckLinkTimeout_Gen2
 	ld a, [wScriptVar]
 	and a
 	jp z, LinkTimeout
@@ -1170,7 +1170,7 @@
 
 InitTradeMenuDisplay:
 	call ClearScreen
-	call LoadTradeScreenBorder
+	call LoadTradeScreenBorderGFX
 	farcall InitTradeSpeciesList
 	xor a
 	ld hl, wOtherPlayerLinkMode
@@ -1879,7 +1879,7 @@
 	ld [wCurPartyMon], a
 	callfar EvolvePokemon
 	call ClearScreen
-	call LoadTradeScreenBorder
+	call LoadTradeScreenBorderGFX
 	call SetTradeRoomBGPals
 	farcall Link_WaitBGMap
 
@@ -1969,8 +1969,8 @@
 	farcall LinkTextbox
 	ret
 
-LoadTradeScreenBorder:
-	farcall _LoadTradeScreenBorder
+LoadTradeScreenBorderGFX:
+	farcall _LoadTradeScreenBorderGFX
 	ret
 
 SetTradeRoomBGPals:
@@ -1978,7 +1978,7 @@
 	call SetPalettes
 	ret
 
-Function28f09: ; unreferenced
+PlaceTradeScreenTextbox: ; unreferenced
 	hlcoord 0, 0
 	ld b, 6
 	ld c, 18
@@ -2061,12 +2061,12 @@
 	call GetMoveName
 	call CopyName1
 	pop bc
-	call Function29c67
+	call GetIncompatibleMonName
 	ld a, $2
 	jr .done
 
 .mon_has_mail
-	call Function29c67
+	call GetIncompatibleMonName
 	ld a, $3
 
 .done
@@ -2073,7 +2073,8 @@
 	ld [wScriptVar], a
 	ret
 
-Function29c67:
+GetIncompatibleMonName:
+; Calulate which pokemon is incompatible, and get that pokemon's name
 	ld a, [wPartyCount]
 	sub b
 	ld c, a
@@ -2243,7 +2244,7 @@
 	ld [wScriptVar], a
 	ret
 
-CheckLinkTimeout:
+CheckLinkTimeout_Receptionist:
 	ld a, $1
 	ld [wPlayerLinkAction], a
 	ld hl, wLinkTimeoutFrames
@@ -2264,11 +2265,12 @@
 	ret nz
 	jp Link_ResetSerialRegistersAfterLinkClosure
 
-Function29dba:
+CheckLinkTimeout_Gen2:
+; if wScriptVar = 0 on exit, link connection is closed
 	ld a, $5
 	ld [wPlayerLinkAction], a
 	ld hl, wLinkTimeoutFrames
-	ld a, $3
+	ld a, 3
 	ld [hli], a
 	xor a
 	ld [hl], a
@@ -2280,33 +2282,39 @@
 	call Link_CheckCommunicationError
 	ld a, [wScriptVar]
 	and a
-	jr z, .vblank
-	ld bc, -1
+	jr z, .exit
+
+; Wait for ~$70000 cycles to give the other GB time to be ready
+	ld bc, $ffff
 .wait
 	dec bc
 	ld a, b
 	or c
 	jr nz, .wait
+
+; If other GB is not ready at this point, disconnect due to timeout
 	ld a, [wOtherPlayerLinkMode]
 	cp $5
-	jr nz, .script_var
+	jr nz, .timeout
+
+; Another check to increase reliability
 	ld a, $6
 	ld [wPlayerLinkAction], a
 	ld hl, wLinkTimeoutFrames
-	ld a, $1
+	ld a, 1
 	ld [hli], a
-	ld [hl], $32
+	ld [hl], 50
 	call Link_CheckCommunicationError
 	ld a, [wOtherPlayerLinkMode]
 	cp $6
-	jr z, .vblank
+	jr z, .exit
 
-.script_var
+.timeout
 	xor a
 	ld [wScriptVar], a
 	ret
 
-.vblank
+.exit
 	xor a
 	ldh [hVBlank], a
 	ret
@@ -2327,13 +2335,13 @@
 	call .CheckConnected
 	jr nz, .load_true
 	call .AcknowledgeSerial
-	xor a
-	jr .load_scriptvar
+	xor a ; FALSE
+	jr .done
 
 .load_true
-	ld a, $1
+	ld a, TRUE
 
-.load_scriptvar
+.done
 	ld [wScriptVar], a
 	ld hl, wLinkTimeoutFrames
 	xor a
@@ -2513,10 +2521,11 @@
 GSLinkCommsBorderGFX: ; unreferenced
 INCBIN "gfx/trade/unused_gs_border_tiles.2bpp"
 
-Function29fe4: ; unreferenced
-	ld a, BANK(sPartyMail)
+CheckSRAM0Flag: ; unreferenced
+; input: hl = unknown flag array in "SRAM Bank 0"
+	ld a, BANK("SRAM Bank 0")
 	call OpenSRAM
-	ld d, FALSE
+	ld d, 0
 	ld b, CHECK_FLAG
 	predef SmallFarFlagAction
 	call CloseSRAM
--- a/engine/link/link_2.asm
+++ b/engine/link/link_2.asm
@@ -10,7 +10,7 @@
 	call ClearScreen
 	call ClearBGPalettes
 	call MaxVolume
-	farcall LoadTradeScreenBorder
+	farcall LoadTradeScreenBorderGFX
 	farcall Link_WaitBGMap
 	farcall InitTradeSpeciesList
 	farcall SetTradeRoomBGPals
--- a/engine/link/link_trade.asm
+++ b/engine/link/link_trade.asm
@@ -1,7 +1,7 @@
 LinkCommsBorderGFX:
 INCBIN "gfx/trade/border_tiles.2bpp"
 
-__LoadTradeScreenBorder:
+__LoadTradeScreenBorderGFX:
 	ld de, LinkCommsBorderGFX
 	ld hl, vTiles2
 	lb bc, BANK(LinkCommsBorderGFX), 70
@@ -20,7 +20,7 @@
 	call ClearBGPalettes
 	call ClearTilemap
 	call ClearSprites
-	farcall __LoadTradeScreenBorder ; useless to farcall
+	farcall __LoadTradeScreenBorderGFX ; useless to farcall
 	farcall Function16d42e ; useless to farcall
 	ld b, SCGB_DIPLOMA
 	call GetSGBLayout
@@ -110,7 +110,7 @@
 	ret
 
 InitTradeSpeciesList:
-	call _LoadTradeScreenBorder
+	call _LoadTradeScreenBorderGFX
 	call Function16d6ae
 	farcall InitMG_Mobile_LinkTradePalMap
 	farcall PlaceTradePartnerNamesAndParty
@@ -122,8 +122,8 @@
 .CancelString:
 	db "CANCEL@"
 
-_LoadTradeScreenBorder:
-	call __LoadTradeScreenBorder
+_LoadTradeScreenBorderGFX:
+	call __LoadTradeScreenBorderGFX
 	ret
 
 LinkComms_LoadPleaseWaitTextboxBorderGFX:
--- a/maps/Pokecenter2F.asm
+++ b/maps/Pokecenter2F.asm
@@ -91,7 +91,7 @@
 	special TryQuickSave
 	iffalse .DidNotSave
 	writetext Text_PleaseWait
-	special CheckLinkTimeout
+	special CheckLinkTimeout_Receptionist
 	iffalse .LinkTimedOut
 	readmem wOtherPlayerLinkMode
 	iffalse .LinkedToFirstGen
@@ -193,7 +193,7 @@
 	special TryQuickSave
 	iffalse .DidNotSave
 	writetext Text_PleaseWait
-	special CheckLinkTimeout
+	special CheckLinkTimeout_Receptionist
 	iffalse .LinkTimedOut
 	readmem wOtherPlayerLinkMode
 	iffalse .LinkedToFirstGen
@@ -320,7 +320,7 @@
 	special TryQuickSave
 	iffalse .DidNotSave
 	writetext Text_PleaseWait
-	special CheckLinkTimeout
+	special CheckLinkTimeout_Receptionist
 	iffalse .LinkTimedOut
 	readmem wOtherPlayerLinkMode
 	iffalse .OK
--- a/mobile/mobile_40.asm
+++ b/mobile/mobile_40.asm
@@ -6443,7 +6443,7 @@
 	ld hl, vTiles0
 	lb bc, BANK(MobileTradeLightsGFX), 4
 	call Get2bpp
-	farcall __LoadTradeScreenBorder
+	farcall __LoadTradeScreenBorderGFX
 	call EnableLCD
 	ret