shithub: pokecrystal

Download patch

ref: 4c4fd7258c0c0bc289af2af0658c12bf96f75032
parent: 5ae35e57702a17f118d53c35e13772b140fd37f9
author: mid-kid <[email protected]>
date: Fri Mar 31 09:13:52 EDT 2023

Define SERIAL_PATCH_PREAMBLE_LENGTH

--- a/constants/serial_constants.asm
+++ b/constants/serial_constants.asm
@@ -32,9 +32,10 @@
 ; used to replace SERIAL_NO_DATA_BYTE
 DEF SERIAL_PATCH_REPLACEMENT_BYTE     EQU $ff
 
-DEF SERIAL_PREAMBLE_LENGTH    EQU 6
-DEF SERIAL_RN_PREAMBLE_LENGTH EQU 7
-DEF SERIAL_RNS_LENGTH         EQU 10
+DEF SERIAL_PREAMBLE_LENGTH       EQU 6
+DEF SERIAL_RN_PREAMBLE_LENGTH    EQU 7
+DEF SERIAL_PATCH_PREAMBLE_LENGTH EQU 3
+DEF SERIAL_RNS_LENGTH            EQU 10
 
 DEF SERIAL_MAIL_PREAMBLE_BYTE    EQU $20
 DEF SERIAL_MAIL_PREAMBLE_LENGTH  EQU 5
--- a/engine/link/link.asm
+++ b/engine/link/link.asm
@@ -90,7 +90,7 @@
 
 	ld hl, wLinkData
 	ld de, wOTPartyData
-	ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + 1 + PARTY_LENGTH + 1 + (REDMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
+	ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + (1 + PARTY_LENGTH + 1) + (REDMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
 	vc_hook Wireless_ExchangeBytes_Gen2toGen1_party_structs
 	call Serial_ExchangeBytes
 	ld a, SERIAL_NO_DATA_BYTE
@@ -256,7 +256,7 @@
 
 	ld hl, wLinkData
 	ld de, wOTPartyData
-	ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + 1 + PARTY_LENGTH + 1 + 2 + (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
+	ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + (1 + PARTY_LENGTH + 1) + 2 + (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
 	vc_hook Wireless_ExchangeBytes_party_structs
 	call Serial_ExchangeBytes
 	ld a, SERIAL_NO_DATA_BYTE
@@ -276,8 +276,8 @@
 	ld bc, wLinkPlayerMailEnd - wLinkPlayerMail
 	vc_hook Wireless_ExchangeBytes_mail
 	call ExchangeBytes
-
 .not_trading
+
 	xor a
 	ldh [rIF], a
 	ld a, (1 << JOYPAD) | (1 << SERIAL) | (1 << TIMER) | (1 << VBLANK)
@@ -355,7 +355,7 @@
 	ld a, b
 	or c
 	jr nz, .loop4
-	ld de, wOTPlayerMailPatchSet
+	ld de, wLinkOTMailPatchSet
 .loop5
 	ld a, [de]
 	inc de
@@ -629,9 +629,9 @@
 ; Clear the patch list
 	ld hl, wPlayerPatchLists
 	ld a, SERIAL_PREAMBLE_BYTE
+rept SERIAL_PATCH_PREAMBLE_LENGTH
 	ld [hli], a
-	ld [hli], a
-	ld [hli], a
+endr
 	ld b, SERIAL_PATCH_LIST_LENGTH
 	xor a
 .clear_loop
@@ -864,11 +864,11 @@
 	ld de, wLinkData
 	ld a, SERIAL_PREAMBLE_BYTE
 	ld b, SERIAL_PREAMBLE_LENGTH
-.loop1
+.preamble_loop
 	ld [de], a
 	inc de
 	dec b
-	jr nz, .loop1
+	jr nz, .preamble_loop
 
 	ld hl, wPlayerName
 	ld bc, NAME_LENGTH
@@ -909,7 +909,7 @@
 	call OpenSRAM
 	ld hl, sPartyMail
 	ld b, PARTY_LENGTH
-.loop2
+.message_loop
 	push bc
 	ld bc, MAIL_MSG_LENGTH + 1
 	call CopyBytes
@@ -917,12 +917,12 @@
 	add hl, bc
 	pop bc
 	dec b
-	jr nz, .loop2
+	jr nz, .message_loop
 
 ; Copy the mail data to wLinkPlayerMailMetadata
 	ld hl, sPartyMail
 	ld b, PARTY_LENGTH
-.loop3
+.metadata_loop
 	push bc
 	ld bc, MAIL_MSG_LENGTH + 1
 	add hl, bc
@@ -930,13 +930,13 @@
 	call CopyBytes
 	pop bc
 	dec b
-	jr nz, .loop3
+	jr nz, .metadata_loop
 
 ; Translate the messages if necessary
 	ld b, PARTY_LENGTH
 	ld de, sPartyMail
 	ld hl, wLinkPlayerMailMessages
-.loop4
+.translate_loop
 	push bc
 	push hl
 	push de
@@ -945,16 +945,16 @@
 	pop de
 	ld a, c
 	or a ; MAIL_LANG_ENGLISH
-	jr z, .next
+	jr z, .translate_next
 	sub MAIL_LANG_ITALIAN
 	jr nc, .italian_spanish
 	farcall ConvertFrenchGermanMailToEnglish
-	jr .next
+	jr .translate_next
 .italian_spanish
 	cp (MAIL_LANG_SPANISH + 1) - MAIL_LANG_ITALIAN
-	jr nc, .next
+	jr nc, .translate_next
 	farcall ConvertSpanishItalianMailToEnglish
-.next
+.translate_next
 	pop de
 	ld hl, MAIL_STRUCT_LENGTH
 	add hl, de
@@ -965,23 +965,23 @@
 	add hl, bc
 	pop bc
 	dec b
-	jr nz, .loop4
+	jr nz, .translate_loop
 	call CloseSRAM
 
 ; The SERIAL_NO_DATA_BYTE value isn't allowed anywhere in message text
 	ld hl, wLinkPlayerMailMessages
 	ld bc, (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH
-.loop5
+.message_patch_loop
 	ld a, [hl]
 	cp SERIAL_NO_DATA_BYTE
-	jr nz, .skip2
+	jr nz, .message_patch_skip
 	ld [hl], SERIAL_MAIL_REPLACEMENT_BYTE
-.skip2
+.message_patch_skip
 	inc hl
 	dec bc
 	ld a, b
 	or c
-	jr nz, .loop5
+	jr nz, .message_patch_loop
 
 ; Calculate the patch offsets for the mail metadata
 	ld hl, wLinkPlayerMailMetadata
@@ -988,19 +988,19 @@
 	ld de, wLinkPlayerMailPatchSet
 	ld b, (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)) * PARTY_LENGTH
 	ld c, 0
-.loop6
+.metadata_patch_loop
 	inc c
 	ld a, [hl]
 	cp SERIAL_NO_DATA_BYTE
-	jr nz, .skip3
+	jr nz, .metadata_patch_skip
 	ld [hl], SERIAL_PATCH_REPLACEMENT_BYTE
 	ld a, c
 	ld [de], a
 	inc de
-.skip3
+.metadata_patch_skip
 	inc hl
 	dec b
-	jr nz, .loop6
+	jr nz, .metadata_patch_loop
 	ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
 	ld [de], a
 	ret
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -114,7 +114,7 @@
 	dec hl
 	cp SERIAL_PREAMBLE_BYTE
 	jr nz, .loop
-	xor a
+	xor a ; FALSE
 	ldh [hSerialIgnoringInitialData], a
 	jr .loop
 
--- a/ram/wram.asm
+++ b/ram/wram.asm
@@ -1034,13 +1034,14 @@
 wLinkPlayerMailPreamble:: ds SERIAL_MAIL_PREAMBLE_LENGTH
 wLinkPlayerMailMessages:: ds (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH
 wLinkPlayerMailMetadata:: ds (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)) * PARTY_LENGTH
-wLinkPlayerMailPatchSet:: ds 103
+wLinkPlayerMailPatchSet:: ds 100 + SERIAL_PATCH_PREAMBLE_LENGTH
 wLinkPlayerMailEnd::
 	ds 10
 wLinkOTMail::
 wLinkOTMailMessages:: ds (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH
 wLinkOTMailMetadata:: ds (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)) * PARTY_LENGTH
-wOTPlayerMailPatchSet:: ds 103 + SERIAL_MAIL_PREAMBLE_LENGTH
+wLinkOTMailPatchSet:: ds 100 + SERIAL_PATCH_PREAMBLE_LENGTH
+wLinkOTMailPadding:: ds SERIAL_MAIL_PREAMBLE_LENGTH
 wLinkOTMailEnd::
 	ds 10