shithub: pokecrystal

Download patch

ref: 01d6e6c75843fdc0035499ce0214c19be74a9bda
parent: 1756a553f7563ddb419490fd1d583e3e215faf09
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Mon Nov 2 14:32:14 EST 2020

Group some link.asm code into "paragraphs"

--- a/engine/link/link.asm
+++ b/engine/link/link.asm
@@ -73,12 +73,14 @@
 	ldh [rIF], a
 	ld a, 1 << SERIAL
 	ldh [rIE], a
+
 	ld hl, wLinkBattleRNPreamble
-	ld de, wEnemyMonSpecies
+	ld de, wEnemyMon
 	ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH
 	call Serial_ExchangeBytes
 	ld a, SERIAL_NO_DATA_BYTE
 	ld [de], a
+
 	ld hl, wLinkData
 	ld de, wOTPlayerName
 	ld bc, $1a8
@@ -85,15 +87,19 @@
 	call Serial_ExchangeBytes
 	ld a, SERIAL_NO_DATA_BYTE
 	ld [de], a
+
 	ld hl, wLink_c608
 	ld de, wTrademons
 	ld bc, 200
 	call Serial_ExchangeBytes
+
 	xor a
 	ldh [rIF], a
 	ld a, (1 << JOYPAD) | (1 << SERIAL) | (1 << TIMER) | (1 << VBLANK)
 	ldh [rIE], a
+
 	call Link_CopyRandomNumbers
+
 	ld hl, wOTPlayerName
 	call Link_FindFirstNonControlCharacter_SkipZero
 	push hl
@@ -105,9 +111,11 @@
 	jp z, ExitLinkCommunications
 	cp $7
 	jp nc, ExitLinkCommunications
+
 	ld de, wLinkData
 	ld bc, $1a2
 	call Link_CopyOTData
+
 	ld de, wPlayerTrademon
 	ld hl, wTimeCapsulePlayerData
 	ld c, 2
@@ -138,10 +146,12 @@
 	ld hl, wc90f
 	dec c
 	jr nz, .loop
+
 	ld hl, wLinkPlayerName
 	ld de, wOTPlayerName
 	ld bc, NAME_LENGTH
 	call CopyBytes
+
 	ld de, wOTPartyCount
 	ld a, [hli]
 	ld [de], a
@@ -165,10 +175,12 @@
 	ld [de], a
 	ld hl, wTimeCapsulePlayerData
 	call Link_ConvertPartyStruct1to2
+
 	ld a, LOW(wOTPartyMonOT)
 	ld [wUnusedNamesPointer], a
 	ld a, HIGH(wOTPartyMonOT)
 	ld [wUnusedNamesPointer + 1], a
+
 	ld de, MUSIC_NONE
 	call PlayMusic
 	ldh a, [hSerialConnectionStatus]
@@ -189,7 +201,7 @@
 	jp z, LinkTimeout
 	ldh a, [hSerialConnectionStatus]
 	cp USING_INTERNAL_CLOCK
-	jr nz, .Player1
+	jr nz, .player_1
 
 	ld c, 3
 	call DelayFrames
@@ -208,7 +220,7 @@
 	ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
 	ldh [rSC], a
 
-.Player1:
+.player_1
 	ld de, MUSIC_NONE
 	call PlayMusic
 	ld c, 3
@@ -217,12 +229,14 @@
 	ldh [rIF], a
 	ld a, 1 << SERIAL
 	ldh [rIE], a
+
 	ld hl, wLinkBattleRNPreamble
-	ld de, wEnemyMonSpecies
+	ld de, wEnemyMon
 	ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH
 	call Serial_ExchangeBytes
 	ld a, SERIAL_NO_DATA_BYTE
 	ld [de], a
+
 	ld hl, wLinkData
 	ld de, wOTPlayerName
 	ld bc, $1c2
@@ -229,10 +243,12 @@
 	call Serial_ExchangeBytes
 	ld a, SERIAL_NO_DATA_BYTE
 	ld [de], a
+
 	ld hl, wLink_c608
 	ld de, wTrademons
 	ld bc, 200
 	call Serial_ExchangeBytes
+
 	ld a, [wLinkMode]
 	cp LINK_TRADECENTER
 	jr nz, .not_trading
@@ -248,12 +264,15 @@
 	ldh [rIE], a
 	ld de, MUSIC_NONE
 	call PlayMusic
+
 	call Link_CopyRandomNumbers
+
 	ld hl, wOTPlayerName
 	call Link_FindFirstNonControlCharacter_SkipZero
 	ld de, wLinkData
 	ld bc, $1b9
 	call Link_CopyOTData
+
 	ld de, wPlayerTrademon
 	ld hl, wLinkPlayerData
 	ld c, 2
@@ -284,6 +303,7 @@
 	ld hl, wc90f
 	dec c
 	jr nz, .loop1
+
 	ld a, [wLinkMode]
 	cp LINK_TRADECENTER
 	jp nz, .skip_mail
@@ -398,19 +418,24 @@
 	ld de, wOTPlayerName
 	ld bc, NAME_LENGTH
 	call CopyBytes
+
 	ld de, wOTPartyCount
 	ld bc, 1 + PARTY_LENGTH + 1
 	call CopyBytes
+
 	ld de, wOTPlayerID
 	ld bc, 2
 	call CopyBytes
+
 	ld de, wOTPartyMons
 	ld bc, wOTPartyDataEnd - wOTPartyMons
 	call CopyBytes
+
 	ld a, LOW(wOTPartyMonOT)
 	ld [wUnusedNamesPointer], a
 	ld a, HIGH(wOTPartyMonOT)
 	ld [wUnusedNamesPointer + 1], a
+
 	ld de, MUSIC_NONE
 	call PlayMusic
 	ldh a, [hSerialConnectionStatus]
@@ -646,9 +671,11 @@
 	inc de
 	dec b
 	jr nz, .loop1
+
 	ld hl, wPlayerName
 	ld bc, NAME_LENGTH
 	call CopyBytes
+
 	push de
 	ld hl, wPartyCount
 	ld a, [hli]
@@ -668,12 +695,12 @@
 	ld [de], a
 	inc de
 	jr .loop2
-
 .done_party
 	ld [de], a
 	pop de
 	ld hl, 1 + PARTY_LENGTH + 1
 	add hl, de
+
 	ld d, h
 	ld e, l
 	ld hl, wPartyMon1Species
@@ -686,8 +713,10 @@
 	pop bc
 	dec c
 	jr nz, .mon_loop
+
 	ld hl, wPartyMonOT
 	call .copy_ot_nicks
+
 	ld hl, wPartyMonNicknames
 .copy_ot_nicks
 	ld bc, PARTY_LENGTH * NAME_LENGTH
@@ -812,21 +841,27 @@
 	inc de
 	dec b
 	jr nz, .loop1
+
 	ld hl, wPlayerName
 	ld bc, NAME_LENGTH
 	call CopyBytes
+
 	ld hl, wPartyCount
 	ld bc, 1 + PARTY_LENGTH + 1
 	call CopyBytes
+
 	ld hl, wPlayerID
 	ld bc, 2
 	call CopyBytes
+
 	ld hl, wPartyMon1Species
 	ld bc, PARTY_LENGTH * PARTYMON_STRUCT_LENGTH
 	call CopyBytes
+
 	ld hl, wPartyMonOT
 	ld bc, PARTY_LENGTH * NAME_LENGTH
 	call CopyBytes
+
 	ld hl, wPartyMonNicknames
 	ld bc, PARTY_LENGTH * MON_NAME_LENGTH
 	call CopyBytes
@@ -867,7 +902,6 @@
 	pop bc
 	dec b
 	jr nz, .loop3
-
 	ld b, PARTY_LENGTH
 	ld de, sPartyMail
 	ld hl, wc9f9
@@ -885,12 +919,10 @@
 	jr nc, .italian_spanish
 	farcall ConvertFrenchGermanMailToEnglish
 	jr .next
-
 .italian_spanish
 	cp $2
 	jr nc, .next
 	farcall ConvertSpanishItalianMailToEnglish
-
 .next
 	pop de
 	ld hl, MAIL_STRUCT_LENGTH
@@ -904,6 +936,7 @@
 	dec b
 	jr nz, .loop4
 	call CloseSRAM
+
 	ld hl, wc9f9
 	ld bc, PARTY_LENGTH * (sPartyMon1MailAuthor - sPartyMon1Mail)
 .loop5
@@ -911,7 +944,6 @@
 	cp SERIAL_NO_DATA_BYTE
 	jr nz, .skip2
 	ld [hl], sPartyMon1MailAuthor - sPartyMon1Mail
-
 .skip2
 	inc hl
 	dec bc
@@ -918,6 +950,7 @@
 	ld a, b
 	or c
 	jr nz, .loop5
+
 	ld hl, wcabf
 	ld de, wcb13
 	ld b, PARTY_LENGTH * (sPartyMon1MailEnd - sPartyMon1MailAuthor)
@@ -931,11 +964,11 @@
 	ld a, c
 	ld [de], a
 	inc de
-
 .skip3
 	inc hl
 	dec b
 	jr nz, .loop6
+
 	ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
 	ld [de], a
 	ret
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -89,6 +89,7 @@
 	reti
 
 Serial_ExchangeBytes::
+; send bc bytes from hl, receive bc bytes to de
 	ld a, TRUE
 	ldh [hSerialIgnoringInitialData], a