ref: a6ac67dea2ea7a1a35fce63a8bd10deb7147c3ed
parent: 1674b6ca5a8b7ae9a2d4e34a8c846f2ee88cb85d
author: mid-kid <[email protected]>
date: Thu Mar 30 00:51:49 EDT 2023
IsMailEuropean → ParseMailLanguage (and give it constants)
--- a/constants/item_data_constants.asm
+++ b/constants/item_data_constants.asm
@@ -59,6 +59,14 @@
DEF MAIL_STRUCT_LENGTH EQU $2f ; mailmsg struct
DEF MAIL_STRUCT_LENGTH_JP EQU $2a ; mailmsg_jp struct
+; mail languages
+ const_def
+ const MAIL_LANG_ENGLISH
+ const MAIL_LANG_FRENCH
+ const MAIL_LANG_GERMAN
+ const MAIL_LANG_ITALIAN
+ const MAIL_LANG_SPANISH
+
; held item effects
const_def
const HELD_NONE
--- a/constants/serial_constants.asm
+++ b/constants/serial_constants.asm
@@ -30,15 +30,16 @@
; 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_RNS_LENGTH EQU 10
-DEF SERIAL_MAIL_PREAMBLE_BYTE EQU $20
-DEF SERIAL_MAIL_REPLACEMENT_BYTE EQU $21
-DEF SERIAL_MAIL_PREAMBLE_LENGTH EQU 5
+DEF SERIAL_MAIL_PREAMBLE_BYTE EQU $20
+DEF SERIAL_MAIL_PREAMBLE_LENGTH EQU 5
+; used to replace SERIAL_NO_DATA_BYTE
+DEF SERIAL_MAIL_REPLACEMENT_BYTE EQU $21
; timeout duration after exchanging a byte
-DEF SERIAL_LINK_BYTE_TIMEOUT EQU $5000
+DEF SERIAL_LINK_BYTE_TIMEOUT EQU $5000
-DEF MAX_MYSTERY_GIFT_PARTNERS EQU 5
+DEF MAX_MYSTERY_GIFT_PARTNERS EQU 5
--- a/engine/link/link.asm
+++ b/engine/link/link.asm
@@ -406,7 +406,7 @@
.fix_mail_loop
push bc
push de
- farcall IsMailEuropean
+ farcall ParseMailLanguage
ld a, c
or a
jr z, .next
@@ -893,7 +893,7 @@
ret nz
; Fill 5 bytes at wLinkPlayerMailPreamble with $20
- ld de, wLinkPlayerMailPreamble
+ ld de, wLinkPlayerMail
ld a, SERIAL_MAIL_PREAMBLE_BYTE
call Link_CopyMailPreamble
@@ -911,6 +911,7 @@
pop bc
dec b
jr nz, .loop2
+
; Copy the mail data to wLinkPlayerMailMetadata
ld hl, sPartyMail
ld b, PARTY_LENGTH
@@ -923,6 +924,8 @@
pop bc
dec b
jr nz, .loop3
+
+; Translate the messages if necessary
ld b, PARTY_LENGTH
ld de, sPartyMail
ld hl, wLinkPlayerMailMessages
@@ -931,17 +934,17 @@
push hl
push de
push hl
- farcall IsMailEuropean
+ farcall ParseMailLanguage
pop de
ld a, c
- or a
+ or a ; MAIL_LANG_ENGLISH
jr z, .next
- sub $3
+ sub MAIL_LANG_ITALIAN
jr nc, .italian_spanish
farcall ConvertFrenchGermanMailToEnglish
jr .next
.italian_spanish
- cp $2
+ cp (MAIL_LANG_SPANISH + 1) - MAIL_LANG_ITALIAN
jr nc, .next
farcall ConvertSpanishItalianMailToEnglish
.next
@@ -958,6 +961,7 @@
jr nz, .loop4
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
@@ -972,6 +976,7 @@
or c
jr nz, .loop5
+; Calculate the patch offsets for the mail metadata
ld hl, wLinkPlayerMailMetadata
ld de, wLinkPlayerMailPatchSet
ld b, (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)) * PARTY_LENGTH
--- a/engine/pokemon/european_mail.asm
+++ b/engine/pokemon/european_mail.asm
@@ -1,10 +1,5 @@
-IsMailEuropean:
-; return 1 if French
-; return 2 if German
-; return 3 if Italian
-; return 4 if Spanish
-; return 0 if none of the above
- ld c, $0
+ParseMailLanguage:
+ ld c, MAIL_LANG_ENGLISH
ld hl, sPartyMon1MailNationality - sPartyMon1Mail
add hl, de
ld a, [hli]
@@ -11,19 +6,19 @@
cp "E"
ret nz
ld a, [hli]
- inc c
+ inc c ; MAIL_LANG_FRENCH
cp "F"
ret z
- inc c
+ inc c ; MAIL_LANG_GERMAN
cp "G"
ret z
- inc c
+ inc c ; MAIL_LANG_ITALIAN
cp "I"
ret z
- inc c
+ inc c ; MAIL_LANG_SPANISH
cp "S"
ret z
- ld c, $0
+ ld c, MAIL_LANG_ENGLISH
ret
; The regular font.
--- a/engine/pokemon/mail_2.asm
+++ b/engine/pokemon/mail_2.asm
@@ -31,14 +31,14 @@
push de
ld a, BANK(sPartyMail)
call OpenSRAM
- farcall IsMailEuropean
+ farcall ParseMailLanguage
call CloseSRAM
ld a, c
ld de, StandardEnglishFont
- or a
+ or a ; MAIL_LANG_ENGLISH
jr z, .got_font
ld de, FrenchGermanFont
- sub $3
+ sub MAIL_LANG_ITALIAN
jr c, .got_font
ld de, SpanishItalianFont