shithub: pokecrystal

Download patch

ref: 4401d24074913b227ed246da02343cd875ee9fc0
parent: 3c3d87e765ffa17926b6a94bc061bb2dafc859e2
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Mon Feb 22 07:00:53 EST 2021

Identify link sync buffers, separate from link action bytes

Fixes #803

--- a/engine/link/link.asm
+++ b/engine/link/link.asm
@@ -2554,20 +2554,20 @@
 
 Link_EnsureSync:
 	add $d0
-	ld [wPlayerLinkAction], a
-	ld [wUnusedLinkAction], a
+	ld [wLinkPlayerSyncBuffer], a
+	ld [wLinkPlayerSyncBuffer + 1], a
 	ld a, $2
 	ldh [hVBlank], a
 	call DelayFrame
 	call DelayFrame
 .receive_loop
-	call Serial_ExchangeLinkMenuSelection
-	ld a, [wOtherPlayerLinkMode]
+	call Serial_ExchangeSyncBytes
+	ld a, [wLinkReceivedSyncBuffer]
 	ld b, a
 	and $f0
 	cp $d0
 	jr z, .done
-	ld a, [wOtherPlayerLinkAction]
+	ld a, [wLinkReceivedSyncBuffer + 1]
 	ld b, a
 	and $f0
 	cp $d0
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -252,11 +252,10 @@
 	ld [wLinkTimeoutFrames + 1], a
 	ret
 
-; This is used to exchange the button press and selected menu item on the link menu.
-; The data is sent thrice and read twice to increase reliability.
-Serial_ExchangeLinkMenuSelection::
-	ld hl, wPlayerLinkAction
-	ld de, wOtherPlayerLinkMode
+; This is used to check that both players entered the same Cable Club room.
+Serial_ExchangeSyncBytes::
+	ld hl, wLinkPlayerSyncBuffer
+	ld de, wLinkReceivedSyncBuffer
 	ld c, 2
 	ld a, TRUE
 	ldh [hSerialIgnoringInitialData], a
--- a/wram.asm
+++ b/wram.asm
@@ -1357,6 +1357,7 @@
 ENDU
 
 ; link data
+UNION
 wOtherPlayerLinkMode:: db
 wOtherPlayerLinkAction:: db
 	ds 3
@@ -1363,6 +1364,10 @@
 wPlayerLinkAction:: db
 wUnusedLinkAction:: db
 	ds 3
+NEXTU
+wLinkReceivedSyncBuffer:: ds 5
+wLinkPlayerSyncBuffer:: ds 5
+ENDU
 wLinkTimeoutFrames:: dw
 wLinkByteTimeout:: dw