From a6ac67dea2ea7a1a35fce63a8bd10deb7147c3ed Mon Sep 17 00:00:00 2001 From: mid-kid Date: Thu, 30 Mar 2023 04:51:49 +0200 Subject: [PATCH] =?UTF-8?q?IsMailEuropean=20=E2=86=92=20ParseMailLanguage?= =?UTF-8?q?=20(and=20give=20it=20constants)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constants/item_data_constants.asm | 8 ++++++++ constants/serial_constants.asm | 17 +++++++++-------- engine/link/link.asm | 17 +++++++++++------ engine/pokemon/european_mail.asm | 19 +++++++------------ engine/pokemon/mail_2.asm | 6 +++--- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/constants/item_data_constants.asm b/constants/item_data_constants.asm index af6b8478c..faf201dda 100644 --- a/constants/item_data_constants.asm +++ b/constants/item_data_constants.asm @@ -59,6 +59,14 @@ DEF MAILBOX_CAPACITY EQU 10 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 diff --git a/constants/serial_constants.asm b/constants/serial_constants.asm index 791fad245..0035071b0 100644 --- a/constants/serial_constants.asm +++ b/constants/serial_constants.asm @@ -30,15 +30,16 @@ DEF SERIAL_PATCH_LIST_PART_TERMINATOR EQU $ff ; 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 diff --git a/engine/link/link.asm b/engine/link/link.asm index 9998fb63f..d66b5e176 100644 --- a/engine/link/link.asm +++ b/engine/link/link.asm @@ -406,7 +406,7 @@ endc .fix_mail_loop push bc push de - farcall IsMailEuropean + farcall ParseMailLanguage ld a, c or a jr z, .next @@ -893,7 +893,7 @@ Link_PrepPartyData_Gen2: 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 @@ Link_PrepPartyData_Gen2: pop bc dec b jr nz, .loop2 + ; Copy the mail data to wLinkPlayerMailMetadata ld hl, sPartyMail ld b, PARTY_LENGTH @@ -923,6 +924,8 @@ Link_PrepPartyData_Gen2: 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 @@ Link_PrepPartyData_Gen2: 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 @@ Link_PrepPartyData_Gen2: 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 @@ Link_PrepPartyData_Gen2: 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 diff --git a/engine/pokemon/european_mail.asm b/engine/pokemon/european_mail.asm index 2ba5e6c97..85b7a2649 100644 --- a/engine/pokemon/european_mail.asm +++ b/engine/pokemon/european_mail.asm @@ -1,29 +1,24 @@ -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] 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. diff --git a/engine/pokemon/mail_2.asm b/engine/pokemon/mail_2.asm index 59c42715b..f0b870130 100644 --- a/engine/pokemon/mail_2.asm +++ b/engine/pokemon/mail_2.asm @@ -31,14 +31,14 @@ ReadAnyMail: 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