diff --git a/constants/item_data_constants.asm b/constants/item_data_constants.asm index 57b09456..fc2623aa 100644 --- a/constants/item_data_constants.asm +++ b/constants/item_data_constants.asm @@ -53,7 +53,7 @@ DEF MAX_ITEM_STACK EQU 99 ; mail DEF MAIL_LINE_LENGTH EQU $10 -DEF MAIL_MSG_LENGTH EQU $20 +DEF MAIL_MSG_LENGTH EQU 2 * MAIL_LINE_LENGTH DEF MAILBOX_CAPACITY EQU 10 DEF MAIL_STRUCT_LENGTH EQU $2f ; mailmsg struct diff --git a/constants/serial_constants.asm b/constants/serial_constants.asm index e3f5a2dc..81ed5d67 100644 --- a/constants/serial_constants.asm +++ b/constants/serial_constants.asm @@ -42,6 +42,8 @@ DEF SERIAL_RN_PREAMBLE_LENGTH EQU 7 DEF SERIAL_PATCH_PREAMBLE_LENGTH EQU 3 DEF SERIAL_RNS_LENGTH EQU 10 +DEF SERIAL_PADDING_LENGTH EQU 3 + DEF SERIAL_MAIL_PREAMBLE_BYTE EQU $20 DEF SERIAL_MAIL_PREAMBLE_LENGTH EQU 5 ; used to replace SERIAL_NO_DATA_BYTE diff --git a/engine/link/link.asm b/engine/link/link.asm index 8288ffdb..9206a74c 100644 --- a/engine/link/link.asm +++ b/engine/link/link.asm @@ -79,16 +79,16 @@ endc ldh [rIE], a ld hl, wLinkBattleRNPreamble - ld de, wEnemyMon + ld de, wOTLinkBattleRNData ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH vc_hook Wireless_ExchangeBytes_Gen2toGen1_RNG_state call Serial_ExchangeBytes ld a, SERIAL_NO_DATA_BYTE ld [de], a - 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 hl, wLinkSendTimeCapsuleParty + ld de, wLinkReceivedPartyData + ld bc, wLinkSendTimeCapsulePartyEnd - wLinkSendTimeCapsuleParty vc_hook Wireless_ExchangeBytes_Gen2toGen1_party_structs call Serial_ExchangeBytes ld a, SERIAL_NO_DATA_BYTE @@ -107,7 +107,8 @@ endc call Link_CopyRandomNumbers - ld hl, wOTPartyData +; check if we have received a valid party count + ld hl, wLinkReceivedPartyData call Link_FindFirstNonControlCharacter_SkipZero push hl ld bc, NAME_LENGTH @@ -116,16 +117,16 @@ endc pop hl and a jp z, ExitLinkCommunications - cp $7 + cp PARTY_LENGTH + 1 jp nc, ExitLinkCommunications - ld de, wLinkData - ld bc, NAME_LENGTH + (1 + PARTY_LENGTH + 1) + (REDMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3 + ld de, wLinkTimeCapsulePartyData + ld bc, wLinkTimeCapsulePartyDataEnd - wLinkTimeCapsulePartyData call Link_CopyOTData ld de, wOTPatchLists - ld hl, wTimeCapsulePlayerData - ld c, 2 + ld hl, wTimeCapsulePatchedData + ld c, 2 ; number of patch lists .loop ld a, [de] inc de @@ -136,7 +137,7 @@ endc cp SERIAL_NO_DATA_BYTE jr z, .loop cp SERIAL_PATCH_LIST_PART_TERMINATOR - jr z, .next + jr z, .next_patch_list push hl push bc ld b, 0 @@ -149,12 +150,12 @@ endc pop hl jr .loop -.next - ld hl, wTimeCapsulePlayerData + SERIAL_PATCH_DATA_SIZE +.next_patch_list + ld hl, wTimeCapsulePatchedData + SERIAL_PATCH_DATA_SIZE dec c jr nz, .loop - ld hl, wLinkData + ld hl, wLinkTimeCapsulePlayerName ld de, wOTPlayerName ld bc, NAME_LENGTH call CopyBytes @@ -164,10 +165,10 @@ endc ld [de], a inc de -.party_loop +.species_loop ld a, [hli] cp -1 - jr z, .done_party + jr z, .convert_party_struct ld [wTempSpecies], a push hl push de @@ -177,11 +178,11 @@ endc ld a, [wTempSpecies] ld [de], a inc de - jr .party_loop + jr .species_loop -.done_party - ld [de], a - ld hl, wTimeCapsulePlayerData +.convert_party_struct + ld [de], a ; write terminator + ld hl, wTimeCapsulePatchedData call Link_ConvertPartyStruct1to2 ld a, LOW(wOTPartyMonOTs) @@ -252,13 +253,13 @@ endc ld a, SERIAL_NO_DATA_BYTE ld [de], a - 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 hl, wLinkSendParty + ld de, wLinkReceivedPartyData + ld bc, wLinkSendPartyEnd - wLinkSendParty vc_hook Wireless_ExchangeBytes_party_structs call Serial_ExchangeBytes ld a, SERIAL_NO_DATA_BYTE - ld [de], a + ld [de], a ; wLinkReceivedPartyEnd ld hl, wPlayerPatchLists ld de, wOTPatchLists @@ -269,9 +270,9 @@ endc ld a, [wLinkMode] cp LINK_TRADECENTER jr nz, .not_trading - ld hl, wLinkPlayerMail - ld de, wLinkOTMail - ld bc, wLinkPlayerMailEnd - wLinkPlayerMail + ld hl, wLinkSendMail + ld de, wLinkReceivedMail + ld bc, wLinkSendMailEnd - wLinkSendMail vc_hook Wireless_ExchangeBytes_mail call ExchangeBytes .not_trading @@ -285,26 +286,26 @@ endc call Link_CopyRandomNumbers - ld hl, wOTPartyData + ld hl, wLinkReceivedPartyData call Link_FindFirstNonControlCharacter_SkipZero - ld de, wLinkData - ld bc, NAME_LENGTH + 1 + PARTY_LENGTH + 1 + 2 + (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + ld de, wLinkPlayerPartyData + ld bc, wLinkPlayerPartyDataEnd - wLinkPlayerPartyData call Link_CopyOTData ld de, wOTPatchLists - ld hl, wLinkPlayerData - ld c, 2 -.loop1 + ld hl, wLinkPlayerPatchedData + ld c, 2 ; number of patch lists +.party_patch_loop ld a, [de] inc de and a - jr z, .loop1 + jr z, .party_patch_loop cp SERIAL_PREAMBLE_BYTE - jr z, .loop1 + jr z, .party_patch_loop cp SERIAL_NO_DATA_BYTE - jr z, .loop1 + jr z, .party_patch_loop cp SERIAL_PATCH_LIST_PART_TERMINATOR - jr z, .next1 + jr z, .next_patch_list push hl push bc ld b, 0 @@ -315,66 +316,68 @@ endc ld [hl], a pop bc pop hl - jr .loop1 + jr .party_patch_loop -.next1 - ld hl, wLinkPlayerData + SERIAL_PATCH_DATA_SIZE +.next_patch_list + ld hl, wLinkPlayerPatchedData + SERIAL_PATCH_DATA_SIZE dec c - jr nz, .loop1 + jr nz, .party_patch_loop ld a, [wLinkMode] cp LINK_TRADECENTER jr nz, .skip_mail - ld hl, wLinkOTMail -.loop2 + +; if we're in Trade Center, process received raw mail data + ld hl, wLinkReceivedMail +.find_mail_preamble ld a, [hli] cp SERIAL_MAIL_PREAMBLE_BYTE - jr nz, .loop2 -.loop3 + jr nz, .find_mail_preamble +.skip_mail_preamble ld a, [hli] cp SERIAL_NO_DATA_BYTE - jr z, .loop3 + jr z, .skip_mail_preamble cp SERIAL_MAIL_PREAMBLE_BYTE - jr z, .loop3 + jr z, .skip_mail_preamble dec hl - ld de, wLinkOTMail - ld bc, wLinkDataEnd - wLinkOTMail ; should be wLinkOTMailEnd - wLinkOTMail + ld de, wLinkReceivedMailMessages + ld bc, wLinkDataEnd - wLinkReceivedMail ; should be wLinkReceivedMailEnd - wLinkReceivedMail call CopyBytes ; Replace SERIAL_MAIL_REPLACEMENT_BYTE with SERIAL_NO_DATA_BYTE across all mail ; message bodies. - ld hl, wLinkOTMailMessages + ld hl, wLinkReceivedMailMessages ld bc, (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH -.loop4 +.mail_body_patch_loop ld a, [hl] cp SERIAL_MAIL_REPLACEMENT_BYTE - jr nz, .okay1 + jr nz, .okay ld [hl], SERIAL_NO_DATA_BYTE -.okay1 +.okay inc hl dec bc ld a, b or c - jr nz, .loop4 + jr nz, .mail_body_patch_loop - ld de, wLinkOTMailPatchSet -.loop5 + ld de, wLinkReceivedMailPatchSet +.mail_metadata_patch_loop ld a, [de] inc de cp SERIAL_PATCH_LIST_PART_TERMINATOR jr z, .start_copying_mail - ld hl, wLinkOTMailMetadata + ld hl, wLinkReceivedMailMetadata dec a ld b, 0 ld c, a add hl, bc ld [hl], SERIAL_NO_DATA_BYTE - jr .loop5 + jr .mail_metadata_patch_loop .start_copying_mail - ld hl, wLinkOTMail - ld de, wLinkReceivedMail + ld hl, wLinkReceivedMailMessages + ld de, wLinkOTMail ld b, PARTY_LENGTH .copy_mail_loop push bc @@ -389,7 +392,8 @@ endc pop bc dec b jr nz, .copy_mail_loop - ld de, wLinkReceivedMail + + ld de, wLinkOTMail ld b, PARTY_LENGTH .copy_author_loop push bc @@ -404,12 +408,12 @@ endc pop bc dec b jr nz, .copy_author_loop - ld de, wLinkReceivedMailEnd + ld de, wLinkOTMailEnd xor a ld [de], a .skip_mail - ld hl, wLinkData + ld hl, wLinkPlayerName ld de, wOTPlayerName ld bc, NAME_LENGTH call CopyBytes @@ -587,20 +591,21 @@ endr jr nz, .clear_loop ; Loop through all the patchable link data - ld hl, wLinkData + SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + (1 + PARTY_LENGTH + 1) - 1 + ld hl, wLinkSendPartyPartyEnd + assert wLinkSendPartyPartyEnd == wLinkSendTimeCapsulePartyPartyEnd ld de, wPlayerPatchLists + SERIAL_RNS_LENGTH lb bc, 0, 0 .patch_loop -; Check if we've gone over the entire area +; If we're processing the first patch area, check if we've reached the end inc c ld a, c cp SERIAL_PATCH_DATA_SIZE + 1 jr z, .data1_done -; If we're processing the second patch area, check if we've reached the end ld a, b dec a jr nz, .process +; If we're processing the second patch area, check if we've reached the end push bc ld a, [wLinkMode] cp LINK_TIMECAPSULE @@ -638,14 +643,14 @@ endr ret Link_PrepPartyData_Gen1: - ld de, wLinkData + ld de, wLinkSendTimeCapsuleParty 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 @@ -656,10 +661,10 @@ Link_PrepPartyData_Gen1: ld a, [hli] ld [de], a inc de -.loop2 +.species_loop ld a, [hli] cp -1 - jr z, .done_party + jr z, .convert_party_struct ld [wTempSpecies], a push hl push de @@ -669,9 +674,10 @@ Link_PrepPartyData_Gen1: ld a, [wTempSpecies] ld [de], a inc de - jr .loop2 -.done_party - ld [de], a + jr .species_loop + +.convert_party_struct + ld [de], a ; write terminator pop de ld hl, 1 + PARTY_LENGTH + 1 add hl, de @@ -808,7 +814,7 @@ Link_PrepPartyData_Gen1: ret Link_PrepPartyData_Gen2: - ld de, wLinkData + ld de, wLinkSendParty ld a, SERIAL_PREAMBLE_BYTE ld b, SERIAL_PREAMBLE_LENGTH .preamble_loop @@ -846,12 +852,12 @@ Link_PrepPartyData_Gen2: cp LINK_TRADECENTER ret nz -; Fill 5 bytes at wLinkPlayerMailPreamble with $20 - ld de, wLinkPlayerMail +; Fill 5 bytes at wLinkSendMailPreamble with $20 + ld de, wLinkSendMail ld a, SERIAL_MAIL_PREAMBLE_BYTE call Link_CopyMailPreamble -; Copy all the mail messages to wLinkPlayerMailMessages +; Copy all the mail messages to wLinkSendMailMessages ld a, BANK(sPartyMail) call OpenSRAM ld hl, sPartyMail @@ -866,7 +872,7 @@ Link_PrepPartyData_Gen2: dec b jr nz, .message_loop -; Copy the mail data to wLinkPlayerMailMetadata +; Copy the mail data to wLinkSendMailMetadata ld hl, sPartyMail ld b, PARTY_LENGTH .metadata_loop @@ -881,7 +887,7 @@ Link_PrepPartyData_Gen2: call CloseSRAM ; The SERIAL_NO_DATA_BYTE value isn't allowed anywhere in message text - ld hl, wLinkPlayerMailMessages + ld hl, wLinkSendMailMessages ld bc, (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH .message_patch_loop ld a, [hl] @@ -896,8 +902,8 @@ Link_PrepPartyData_Gen2: jr nz, .message_patch_loop ; Calculate the patch offsets for the mail metadata - ld hl, wLinkPlayerMailMetadata - ld de, wLinkPlayerMailPatchSet + ld hl, wLinkSendMailMetadata + ld de, wLinkSendMailPatchSet ld b, (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)) * PARTY_LENGTH ld c, 0 .metadata_patch_loop @@ -1011,25 +1017,25 @@ Link_ConvertPartyStruct1to2: ld [de], a inc de pop bc - ld bc, $19 + ld bc, MON_HAPPINESS - MON_MOVES call CopyBytes pop bc ld d, h ld e, l - ld hl, $1f + ld hl, MON_LEVEL add hl, bc ld a, [de] inc de ld [hl], a ld [wCurPartyLevel], a push bc - ld hl, $24 + ld hl, MON_MAXHP add hl, bc push hl ld h, d ld l, e pop de - ld bc, 8 + ld bc, MON_SAT - MON_MAXHP call CopyBytes pop bc call GetBaseData @@ -1062,12 +1068,12 @@ Link_ConvertPartyStruct1to2: ldh a, [hQuotient + 3] ld [hli], a push hl - ld hl, $1b + ld hl, MON_HAPPINESS add hl, bc - ld a, $46 + ld a, BASE_HAPPINESS ld [hli], a xor a - ld [hli], a + ld [hli], a ; wOTPartyMon*PokerusStatus ld [hli], a ld [hl], a pop hl @@ -1119,7 +1125,7 @@ Link_CopyRandomNumbers: ld hl, wOTLinkBattleRNData call Link_FindFirstNonControlCharacter_AllowZero ld de, wLinkBattleRNs - ld c, 10 + ld c, SERIAL_RNS_LENGTH .loop ld a, [hli] cp SERIAL_NO_DATA_BYTE @@ -1674,7 +1680,7 @@ LinkTrade: ld bc, MAIL_STRUCT_LENGTH call AddNTimes push hl - ld hl, wLinkPlayerMail + ld hl, wLinkOTMail ld a, [wCurOTTradePartyMon] ld bc, MAIL_STRUCT_LENGTH call AddNTimes diff --git a/macros/ram.asm b/macros/ram.asm index 07229355..88d68ea2 100644 --- a/macros/ram.asm +++ b/macros/ram.asm @@ -180,12 +180,14 @@ MACRO channel_struct ENDM MACRO mailmsg -\1Message:: ds MAIL_MSG_LENGTH -\1MessageEnd:: db -\1Author:: ds NAME_LENGTH - 1 -\1AuthorID:: dw -\1Species:: db -\1Type:: db +\1Message:: +\1Line1:: ds MAIL_LINE_LENGTH +\1LineBreak:: db ; '' +\1Line2:: ds MAIL_LINE_LENGTH +\1Author:: ds NAME_LENGTH - 1 +\1AuthorID:: dw +\1Species:: db +\1Type:: db \1End:: ENDM diff --git a/ram/wram.asm b/ram/wram.asm index 513b1317..1022f3d9 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -489,22 +489,108 @@ wUnusedJigglypuffNoteXCoord:: db SECTION UNION "Overworld Map", WRAM0 -; raw link data -wLinkData:: ds 1300 +; This section union is 1300 bytes, the largest of all link data unions inside "Overworld Map" +wLinkData:: + +; player's party data, formatted for link transfer (Gen 2 link session) +wLinkSendParty:: +wLinkSendPartyPreamble:: ds SERIAL_PREAMBLE_LENGTH +wLinkSendPartyPlayerName:: ds NAME_LENGTH +wLinkSendPartyPartyCount:: db +wLinkSendPartyPartySpecies:: ds PARTY_LENGTH +wLinkSendPartyPartyEnd:: db ; older code doesn't check PartyCount +wLinkSendPartyPlayerID:: dw +; wLinkSendPartyPlayerPartyMon1 - wLinkSendPartyPlayerPartyMon6 +for n, 1, PARTY_LENGTH + 1 +wLinkSendPartyPlayerPartyMon{d:n}:: party_struct wLinkSendPartyPlayerPartyMon{d:n} +endr +; wLinkSendPartyPlayerPartyMon1OT - wLinkSendPartyPlayerPartyMon6OT +for n, 1, PARTY_LENGTH + 1 +wLinkSendPartyPlayerPartyMon{d:n}OT:: ds NAME_LENGTH +endr +; wLinkSendPartyPlayerPartyMon1Nickname - wLinkSendPartyPlayerPartyMon6Nickname +for n, 1, PARTY_LENGTH + 1 +wLinkSendPartyPlayerPartyMon{d:n}Nickname:: ds MON_NAME_LENGTH +endr +wLinkSendPartyPadding:: ds SERIAL_PADDING_LENGTH +wLinkSendPartyEnd:: + + ds 50 + +; player's party mail, formatted for link transfer, during a link session +wLinkSendMail:: +wLinkSendMailPreamble:: ds SERIAL_MAIL_PREAMBLE_LENGTH +wLinkSendMailMessages:: ds (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH +wLinkSendMailMetadata:: ds (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)) * PARTY_LENGTH +wLinkSendMailPatchSet:: ds (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1) + 3) * PARTY_LENGTH + 1 +wLinkSendMailEnd:: + + ds 10 + +UNION +wLinkReceivedMail:: +; during a link session, the other player's raw mail data is initially stored here + ds SERIAL_MAIL_PREAMBLE_LENGTH + ds MAIL_STRUCT_LENGTH * PARTY_LENGTH + ds (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1) + 3) * PARTY_LENGTH + 1 +wLinkReceivedMailEnd:: + +NEXTU +; it's then processed on location to align data start with wLinkReceivedMailMessages, +; before applying the mail patch +wLinkReceivedMailMessages:: ds (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH +wLinkReceivedMailMetadata:: ds (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)) * PARTY_LENGTH +wLinkReceivedMailPatchSet:: ds (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1) + 3) * PARTY_LENGTH + 1 +ENDU + + ds 10 ; unused but written to (see engine/link/link.asm) + wLinkDataEnd:: SECTION UNION "Overworld Map", WRAM0 -; link data members -wLinkPlayerName:: ds NAME_LENGTH -wLinkPartyCount:: db -wLinkPartySpecies:: ds PARTY_LENGTH -wLinkPartyEnd:: db ; older code doesn't check PartyCount +; player's party data, formatted for link transfer (Time Capsule link session) +wLinkSendTimeCapsuleParty:: +wLinkSendTimeCapsulePartyPreamble:: ds SERIAL_PREAMBLE_LENGTH +wLinkSendTimeCapsulePartyPlayerName:: ds NAME_LENGTH +wLinkSendTimeCapsulePartyPartyCount:: db +wLinkSendTimeCapsulePartyPartySpecies:: ds PARTY_LENGTH +wLinkSendTimeCapsulePartyPartyEnd:: db ; older code doesn't check PartyCount +; wLinkSendTimeCapsulePartyMon1 - wLinkSendTimeCapsulePartyMon6 +for n, 1, PARTY_LENGTH + 1 +wLinkSendTimeCapsulePartyMon{d:n}:: red_party_struct wLinkSendTimeCapsulePartyMon{d:n} +endr +wLinkSendTimeCapsulePartyMonOTs:: +; wLinkSendTimeCapsulePartyMon1OT - wLinkSendTimeCapsulePartyMon6OT +for n, 1, PARTY_LENGTH + 1 +wLinkSendTimeCapsulePartyMon{d:n}OT:: ds NAME_LENGTH +endr +wLinkSendTimeCapsulePartyMonNicknames:: +; wLinkSendTimeCapsulePartyMon1Nickname - wLinkSendTimeCapsulePartyMon6Nickname +for n, 1, PARTY_LENGTH + 1 +wLinkSendTimeCapsulePartyMon{d:n}Nickname:: ds MON_NAME_LENGTH +endr +wLinkSendTimeCapsulePartyPadding:: ds SERIAL_PADDING_LENGTH +wLinkSendTimeCapsulePartyEnd:: + + +SECTION UNION "Overworld Map", WRAM0 + +; after the initial link session (Gen 2), the other player's party data +; is temporarily stored here before applying patch data +wLinkPlayerPartyData:: + +; link player's name and party species are not patched, +; as they normally don't contain SERIAL_NO_DATA_BYTE +wLinkPlayerName:: ds NAME_LENGTH +wLinkPartyCount:: db +wLinkPartySpecies:: ds PARTY_LENGTH +wLinkPartyEnd:: db ; older code doesn't check PartyCount + +wLinkPlayerPatchedData:: +wLinkPlayerID:: dw -UNION -; link player data -wLinkPlayerData:: ; wLinkPlayerPartyMon1 - wLinkPlayerPartyMon6 for n, 1, PARTY_LENGTH + 1 wLinkPlayerPartyMon{d:n}:: party_struct wLinkPlayerPartyMon{d:n} @@ -522,9 +608,23 @@ for n, 1, PARTY_LENGTH + 1 wLinkPlayerPartyMon{d:n}Nickname:: ds MON_NAME_LENGTH endr -NEXTU -; time capsule party data -wTimeCapsulePlayerData:: +wLinkPlayerPartyDataEnd:: + + +SECTION UNION "Overworld Map", WRAM0 + +; after the initial link session (Gen 1), the other player's party data +; is temporarily stored here before applying patch data +wLinkTimeCapsulePartyData:: + +; link player's name and party species are not patched, +; as they normally don't contain SERIAL_NO_DATA_BYTE +wLinkTimeCapsulePlayerName:: ds NAME_LENGTH +wLinkTimeCapsulePartyCount:: db +wLinkTimeCapsulePartySpecies:: ds PARTY_LENGTH +wLinkTimeCapsulePartyEnd:: db ; older code doesn't check PartyCount + +wTimeCapsulePatchedData:: ; wTimeCapsulePartyMon1 - wTimeCapsulePartyMon6 for n, 1, PARTY_LENGTH + 1 wTimeCapsulePartyMon{d:n}:: red_party_struct wTimeCapsulePartyMon{d:n} @@ -542,12 +642,14 @@ for n, 1, PARTY_LENGTH + 1 wTimeCapsulePartyMon{d:n}Nickname:: ds MON_NAME_LENGTH endr -ENDU +wLinkTimeCapsulePartyPadding:: ds SERIAL_PADDING_LENGTH + +wLinkTimeCapsulePartyDataEnd:: SECTION UNION "Overworld Map", WRAM0 -; link data prep +; Time Capsule link data prep ds 1000 wCurLinkOTPartyMonTypePointer:: dw @@ -560,30 +662,14 @@ endr SECTION UNION "Overworld Map", WRAM0 -; link mail data +; other player's link mail data, patched and formatted to mailmsg structure ds 500 -wLinkPlayerMail:: -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 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 -wLinkOTMailPatchSet:: ds 100 + SERIAL_PATCH_PREAMBLE_LENGTH -wLinkOTMailPadding:: ds SERIAL_MAIL_PREAMBLE_LENGTH -wLinkOTMailEnd:: - ds 10 - - -SECTION UNION "Overworld Map", WRAM0 - -; received link mail data - ds 500 -wLinkReceivedMail:: ds MAIL_STRUCT_LENGTH * PARTY_LENGTH -wLinkReceivedMailEnd:: db +; wLinkOTMon1Mail - wLinkOTMon6Mail +for n, 1, PARTY_LENGTH + 1 +wLinkOTMon{d:n}Mail:: mailmsg wLinkOTMon{d:n}Mail +endr +wLinkOTMailEnd:: db SECTION UNION "Overworld Map", WRAM0 @@ -2753,10 +2839,33 @@ wBestMagikarpLengthFeet:: db wBestMagikarpLengthInches:: db wMagikarpRecordHoldersName:: ds NAME_LENGTH +; This union spans 451 bytes. UNION +; during a link session, other player's raw party data is initially stored here +; the actual data is contained between SERIAL_PREAMBLE_LENGTH and SERIAL_PADDING_LENGTH, +; allowing possible data shift due to hardware behavior +wLinkReceivedPartyData:: +UNION + ; Gen 2 link format + ds SERIAL_PREAMBLE_LENGTH + ds NAME_LENGTH + ds 1 + PARTY_LENGTH + 1 + ds 2 + ds (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + ds SERIAL_PADDING_LENGTH +NEXTU + ; Gen 1 link format + ds SERIAL_PREAMBLE_LENGTH + ds NAME_LENGTH + ds 1 + PARTY_LENGTH + 1 + ds (REDMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + ds SERIAL_PADDING_LENGTH +ENDU +wLinkReceivedPartyEnd:: db + +NEXTU wPokedexShowPointerAddr:: dw wPokedexShowPointerBank:: db - ds 3 NEXTU wUnusedEggHatchFlag:: db @@ -2770,7 +2879,6 @@ wOTPlayerID:: dw wOTPartyCount:: db wOTPartySpecies:: ds PARTY_LENGTH wOTPartyEnd:: db ; older code doesn't check PartyCount -ENDU UNION ; ot party mons @@ -2807,11 +2915,11 @@ ENDU wPokemonDataEnd:: wGameDataEnd:: +ENDU SECTION "Stack", WRAMX - ds 2 wStackBottom:: ds $fc wStackTop::