diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-12-08 21:24:45 -0500 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-12-08 21:24:45 -0500 |
commit | 348c5caea719db66cacfee3e0432808b8d4368c9 (patch) | |
tree | 4f91b82243df8b87e25eff665328bc368bb575ea | |
parent | 2a65aa843187284195e5d3b8bbff77461f966af9 (diff) |
Identify link.asm WRAM labels based on ax6's research notes <https://pastebin.com/NTxjzKGQ>
-rw-r--r-- | constants/serial_constants.asm | 8 | ||||
-rw-r--r-- | engine/link/link.asm | 145 | ||||
-rw-r--r-- | wram.asm | 86 |
3 files changed, 135 insertions, 104 deletions
diff --git a/constants/serial_constants.asm b/constants/serial_constants.asm index d3bc5e60..5086ae37 100644 --- a/constants/serial_constants.asm +++ b/constants/serial_constants.asm @@ -21,17 +21,25 @@ USING_EXTERNAL_CLOCK EQU $01 USING_INTERNAL_CLOCK EQU $02 CONNECTION_NOT_ESTABLISHED EQU $ff +; length of a patch list (less than any of the signal bytes) +SERIAL_PATCH_LIST_LENGTH EQU $fc ; signals the start of an array of bytes transferred over the link cable SERIAL_PREAMBLE_BYTE EQU $fd ; this byte is used when there is no data to send SERIAL_NO_DATA_BYTE EQU $fe ; signals the end of one part of a patch list (there are two parts) for player/enemy party data SERIAL_PATCH_LIST_PART_TERMINATOR EQU $ff +; used to replace SERIAL_NO_DATA_BYTE +SERIAL_PATCH_REPLACEMENT_BYTE EQU $ff SERIAL_PREAMBLE_LENGTH EQU 6 SERIAL_RN_PREAMBLE_LENGTH EQU 7 SERIAL_RNS_LENGTH EQU 10 +SERIAL_MAIL_PREAMBLE_BYTE EQU $20 +SERIAL_MAIL_REPLACEMENT_BYTE EQU $21 +SERIAL_MAIL_PREAMBLE_LENGTH EQU 5 + ; timeout duration after exchanging a byte SERIAL_LINK_BYTE_TIMEOUT EQU $5000 diff --git a/engine/link/link.asm b/engine/link/link.asm index 6784dde8..90dda4b9 100644 --- a/engine/link/link.asm +++ b/engine/link/link.asm @@ -80,14 +80,14 @@ Gen2ToGen1LinkComms: ld [de], a ld hl, wLinkData - ld de, wOTPlayerName - ld bc, $1a8 + ld de, wOTPartyData + ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + 1 + PARTY_LENGTH + 1 + (REDMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3 call Serial_ExchangeBytes ld a, SERIAL_NO_DATA_BYTE ld [de], a - ld hl, wc508 - ld de, wTrademons + ld hl, wPlayerPatchLists + ld de, wOTPatchLists ld bc, 200 call Serial_ExchangeBytes @@ -98,7 +98,7 @@ Gen2ToGen1LinkComms: call Link_CopyRandomNumbers - ld hl, wOTPlayerName + ld hl, wOTPartyData call Link_FindFirstNonControlCharacter_SkipZero push hl ld bc, NAME_LENGTH @@ -111,11 +111,11 @@ Gen2ToGen1LinkComms: jp nc, ExitLinkCommunications ld de, wLinkData - ld bc, $1a2 + ld bc, NAME_LENGTH + 1 + PARTY_LENGTH + 1 + (REDMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3 call Link_CopyOTData - ld de, wPlayerTrademon - ld hl, wTimeCapsulePlayerData + ld de, wOTPatchLists + ld hl, wLinkPatchList1 ld c, 2 .loop ld a, [de] @@ -141,7 +141,7 @@ Gen2ToGen1LinkComms: jr .loop .next - ld hl, wc80f + ld hl, wLinkPatchList2 dec c jr nz, .loop @@ -154,6 +154,7 @@ Gen2ToGen1LinkComms: ld a, [hli] ld [de], a inc de + .party_loop ld a, [hli] cp -1 @@ -236,23 +237,23 @@ Gen2ToGen2LinkComms: ld [de], a ld hl, wLinkData - ld de, wOTPlayerName - ld bc, $1c2 + ld de, wOTPartyData + ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + 1 + PARTY_LENGTH + 1 + 2 + (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3 call Serial_ExchangeBytes ld a, SERIAL_NO_DATA_BYTE ld [de], a - ld hl, wc508 - ld de, wTrademons + ld hl, wPlayerPatchLists + ld de, wOTPatchLists ld bc, 200 call Serial_ExchangeBytes ld a, [wLinkMode] cp LINK_TRADECENTER jr nz, .not_trading - ld hl, wc8f4 - ld de, wca84 - ld bc, $186 + ld hl, wLinkPlayerMail + ld de, wLinkOTMail + ld bc, wLinkPlayerMailEnd - wLinkPlayerMail call ExchangeBytes .not_trading @@ -265,14 +266,14 @@ Gen2ToGen2LinkComms: call Link_CopyRandomNumbers - ld hl, wOTPlayerName + ld hl, wOTPartyData call Link_FindFirstNonControlCharacter_SkipZero ld de, wLinkData - ld bc, $1b9 + ld bc, NAME_LENGTH + 1 + PARTY_LENGTH + 1 + 2 + (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH call Link_CopyOTData ld de, wPlayerTrademon - ld hl, wLinkPlayerData + ld hl, wLinkPatchList1 ld c, 2 .loop1 ld a, [de] @@ -298,33 +299,33 @@ Gen2ToGen2LinkComms: jr .loop1 .next1 - ld hl, wc80f + ld hl, wLinkPatchList2 dec c jr nz, .loop1 ld a, [wLinkMode] cp LINK_TRADECENTER jr nz, .skip_mail - ld hl, wca84 + ld hl, wLinkOTMail .loop2 ld a, [hli] - cp MAIL_MSG_LENGTH + cp SERIAL_MAIL_PREAMBLE_BYTE jr nz, .loop2 .loop3 ld a, [hli] cp SERIAL_NO_DATA_BYTE jr z, .loop3 - cp MAIL_MSG_LENGTH + cp SERIAL_MAIL_PREAMBLE_BYTE jr z, .loop3 dec hl - ld de, wca84 - ld bc, $190 ; 400 + ld de, wLinkOTMail + ld bc, wLinkDataEnd - wLinkOTMail ; should be wLinkOTMailEnd - wLinkOTMail call CopyBytes - ld hl, wca84 - ld bc, $c6 ; 198 + ld hl, wLinkOTMail + ld bc, (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH .loop4 ld a, [hl] - cp MAIL_MSG_LENGTH + 1 + cp SERIAL_MAIL_REPLACEMENT_BYTE jr nz, .okay1 ld [hl], SERIAL_NO_DATA_BYTE .okay1 @@ -333,13 +334,13 @@ Gen2ToGen2LinkComms: ld a, b or c jr nz, .loop4 - ld de, wcb9e + ld de, wOTPlayerMailPatchSet .loop5 ld a, [de] inc de cp SERIAL_PATCH_LIST_PART_TERMINATOR jr z, .start_copying_mail - ld hl, wcb4a + ld hl, wLinkOTMailMetadata dec a ld b, 0 ld c, a @@ -348,8 +349,8 @@ Gen2ToGen2LinkComms: jr .loop5 .start_copying_mail - ld hl, wca84 - ld de, wc8f4 + ld hl, wLinkOTMail + ld de, wLinkReceivedMail ld b, PARTY_LENGTH .copy_mail_loop push bc @@ -364,7 +365,7 @@ Gen2ToGen2LinkComms: pop bc dec b jr nz, .copy_mail_loop - ld de, wc8f4 + ld de, wLinkReceivedMail ld b, PARTY_LENGTH .fix_mail_loop push bc @@ -379,7 +380,7 @@ Gen2ToGen2LinkComms: pop bc dec b jr nz, .fix_mail_loop - ld de, wca0e + ld de, wLinkReceivedMailEnd xor a ld [de], a @@ -546,7 +547,7 @@ FixDataForLinkTransfer: dec b jr nz, .rn_loop - ld hl, wc508 + ld hl, wPlayerPatchLists ld a, SERIAL_PREAMBLE_BYTE ld [hli], a ld [hli], a @@ -559,13 +560,13 @@ FixDataForLinkTransfer: dec b jr nz, .loop1 - ld hl, wTimeCapsulePlayerData - 1 + PARTY_LENGTH - ld de, wc512 + ld hl, (wLinkData + SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + 1 + PARTY_LENGTH + 1) - 1 + ld de, wPlayerPatchLists + 10 ; ??? lb bc, 0, 0 .loop2 inc c ld a, c - cp SERIAL_PREAMBLE_BYTE + cp SERIAL_PATCH_LIST_LENGTH + 1 jr z, .next1 ld a, b dec a @@ -573,9 +574,9 @@ FixDataForLinkTransfer: push bc ld a, [wLinkMode] cp LINK_TIMECAPSULE - ld b, $d + ld b, REDMON_STRUCT_LENGTH * PARTY_LENGTH - SERIAL_PATCH_LIST_LENGTH + 1 jr z, .got_value - ld b, $27 + ld b, 2 + PARTYMON_STRUCT_LENGTH * PARTY_LENGTH - SERIAL_PATCH_LIST_LENGTH + 1 .got_value ld a, c cp b @@ -589,7 +590,7 @@ FixDataForLinkTransfer: ld a, c ld [de], a inc de - ld [hl], SERIAL_PATCH_LIST_PART_TERMINATOR + ld [hl], SERIAL_PATCH_REPLACEMENT_BYTE jr .loop2 .next1 @@ -813,12 +814,12 @@ Link_PrepPartyData_Gen2: cp LINK_TRADECENTER ret nz -; Fill 5 bytes at wc8f4 with $20 - ld de, wc8f4 - ld a, $20 +; Fill 5 bytes at wLinkPlayerMailPreamble with $20 + ld de, wLinkPlayerMailPreamble + ld a, SERIAL_MAIL_PREAMBLE_BYTE call Link_CopyMailPreamble -; Copy all the mail messages to wc8f9 +; Copy all the mail messages to wLinkPlayerMailMessages ld a, BANK(sPartyMail) call OpenSRAM ld hl, sPartyMail @@ -827,32 +828,32 @@ Link_PrepPartyData_Gen2: push bc ld bc, MAIL_MSG_LENGTH + 1 call CopyBytes - ld bc, sPartyMon1MailEnd - sPartyMon1MailAuthor + ld bc, MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1) add hl, bc pop bc dec b jr nz, .loop2 -; Copy the mail data to wc9bf +; Copy the mail data to wLinkPlayerMailMetadata ld hl, sPartyMail ld b, PARTY_LENGTH .loop3 push bc ld bc, MAIL_MSG_LENGTH + 1 add hl, bc - ld bc, sPartyMon1MailEnd - sPartyMon1MailAuthor + ld bc, MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1) call CopyBytes pop bc dec b jr nz, .loop3 call CloseSRAM - ld hl, wc8f9 - ld bc, PARTY_LENGTH * (sPartyMon1MailAuthor - sPartyMon1Mail) + ld hl, wLinkPlayerMailMessages + ld bc, (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH .loop4 ld a, [hl] cp SERIAL_NO_DATA_BYTE jr nz, .skip2 - ld [hl], sPartyMon1MailAuthor - sPartyMon1Mail + ld [hl], SERIAL_MAIL_REPLACEMENT_BYTE .skip2 inc hl dec bc @@ -860,16 +861,16 @@ Link_PrepPartyData_Gen2: or c jr nz, .loop4 - ld hl, wc9bf - ld de, wca13 - ld b, PARTY_LENGTH * (sPartyMon1MailEnd - sPartyMon1MailAuthor) - ld c, $0 + ld hl, wLinkPlayerMailMetadata + ld de, wLinkPlayerMailPatchSet + ld b, (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)) * PARTY_LENGTH + ld c, 0 .loop5 inc c ld a, [hl] cp SERIAL_NO_DATA_BYTE jr nz, .skip3 - ld [hl], SERIAL_PATCH_LIST_PART_TERMINATOR + ld [hl], SERIAL_PATCH_REPLACEMENT_BYTE ld a, c ld [de], a inc de @@ -884,7 +885,7 @@ Link_PrepPartyData_Gen2: Link_CopyMailPreamble: ; fill 5 bytes with the value of a, starting at de - ld c, 5 + ld c, SERIAL_MAIL_PREAMBLE_LENGTH .loop ld [de], a inc de @@ -897,7 +898,7 @@ Link_ConvertPartyStruct1to2: ld d, h ld e, l ld bc, wLinkOTPartyMonTypes - ld hl, wcae8 + ld hl, wCurLinkOTPartyMonTypePtr ld a, c ld [hli], a ld [hl], b @@ -947,7 +948,7 @@ Link_ConvertPartyStruct1to2: ld a, [de] inc de ld [hl], a - ld hl, wcae8 + ld hl, wCurLinkOTPartyMonTypePtr ld a, [hli] ld h, [hl] ld l, a @@ -958,9 +959,9 @@ Link_ConvertPartyStruct1to2: ld [hli], a inc de ld a, l - ld [wcae8], a + ld [wCurLinkOTPartyMonTypePtr], a ld a, h - ld [wcae8 + 1], a + ld [wCurLinkOTPartyMonTypePtr + 1], a push bc ld hl, MON_ITEM add hl, bc @@ -1360,7 +1361,7 @@ LinkTrade_TradeStatsMenu: farcall CheckAnyOtherAliveMonsForTrade jp nc, LinkTrade xor a - ld [wce57], a + ld [wUnusedLinkAction], a ld [wOtherPlayerLinkAction], a hlcoord 0, 12 ld b, 4 @@ -1373,7 +1374,7 @@ LinkTrade_TradeStatsMenu: .abnormal xor a - ld [wce57], a + ld [wUnusedLinkAction], a ld [wOtherPlayerLinkAction], a ld a, [wCurOTTradePartyMon] ld hl, wOTPartySpecies @@ -1512,7 +1513,7 @@ LinkMonStatsScreen: LinkTrade: xor a - ld [wce57], a + ld [wUnusedLinkAction], a ld [wOtherPlayerLinkAction], a hlcoord 0, 12 ld b, 4 @@ -1638,7 +1639,7 @@ LinkTrade: ld bc, MAIL_STRUCT_LENGTH call AddNTimes push hl - ld hl, wc8f4 + ld hl, wLinkPlayerMail ld a, [wCurOTTradePartyMon] ld bc, MAIL_STRUCT_LENGTH call AddNTimes @@ -2251,7 +2252,7 @@ Link_CheckCommunicationError: xor a ldh [hSerialReceivedNewData], a call WaitLinkTransfer - + ld hl, wLinkTimeoutFrames ld a, [hli] inc a @@ -2259,23 +2260,23 @@ Link_CheckCommunicationError: ld a, [hl] inc a jr nz, .load_true - + ld b, 10 .loop call DelayFrame call LinkDataReceived dec b jr nz, .loop - + xor a ; FALSE jr .done - + .load_true ld a, TRUE - + .done ld [wScriptVar], a - + ld hl, wLinkTimeoutFrames xor a ld [hli], a @@ -2379,7 +2380,7 @@ Link_ResetSerialRegistersAfterLinkClosure: Link_EnsureSync: add $d0 ld [wPlayerLinkAction], a - ld [wce57], a + ld [wUnusedLinkAction], a ld a, $2 ldh [hVBlank], a call DelayFrame @@ -240,6 +240,11 @@ wPuzzlePieces:: ds 6 * 6 wUnownPuzzleEnd:: NEXTU +; link patch lists +wPlayerPatchLists:: ds 200 +wOTPatchLists:: ds 200 + +NEXTU ; This union spans 200 bytes. UNION @@ -303,11 +308,6 @@ NEXTU wHallOfFameTemp:: hall_of_fame wHallOfFameTemp NEXTU -; link engine data -wc508:: ds 10 -wc512:: ds 10 - -NEXTU ; debug mon color picker wDebugMiddleColors:: wDebugLightColor:: ds 2 @@ -372,7 +372,6 @@ wPokegearRadioMusicPlaying:: db NEXTU ; trade -wTrademons:: wPlayerTrademon:: trademon wPlayerTrademon wOTTrademon:: trademon wOTTrademon wTradeAnimAddress:: dw @@ -537,19 +536,7 @@ wUnusedJigglypuffNoteXCoord:: db NEXTU ; raw link data -wLinkData:: ds 271 -wc80f:: ds 229 -wc8f4:: ds 5 -wc8f9:: ds 198 -wc9bf:: ds 79 -wca0e:: ds 5 -wca13:: ds 113 -wca84:: ds 100 -wcae8:: dw -wLinkOTPartyMonTypes:: ds 2 * PARTY_LENGTH - ds 84 -wcb4a:: ds 84 -wcb9e:: ds 118 +wLinkData:: ds 1300 wLinkDataEnd:: NEXTU @@ -560,6 +547,18 @@ wLinkPartySpecies:: ds PARTY_LENGTH wLinkPartyEnd:: db ; older code doesn't check PartyCount UNION +; link player data +wLinkPlayerData:: +wLinkPlayerPartyMon1:: party_struct wLinkPlayerPartyMon1 +wLinkPlayerPartyMon2:: party_struct wLinkPlayerPartyMon2 +wLinkPlayerPartyMon3:: party_struct wLinkPlayerPartyMon3 +wLinkPlayerPartyMon4:: party_struct wLinkPlayerPartyMon4 +wLinkPlayerPartyMon5:: party_struct wLinkPlayerPartyMon5 +wLinkPlayerPartyMon6:: party_struct wLinkPlayerPartyMon6 +wLinkPlayerPartyMonOTNames:: ds NAME_LENGTH * PARTY_LENGTH +wLinkPlayerPartyMonNicks:: ds MON_NAME_LENGTH * PARTY_LENGTH + +NEXTU ; time capsule party data wTimeCapsulePlayerData:: wTimeCapsulePartyMon1:: red_party_struct wTimeCapsulePartyMon1 @@ -568,23 +567,45 @@ wTimeCapsulePartyMon3:: red_party_struct wTimeCapsulePartyMon3 wTimeCapsulePartyMon4:: red_party_struct wTimeCapsulePartyMon4 wTimeCapsulePartyMon5:: red_party_struct wTimeCapsulePartyMon5 wTimeCapsulePartyMon6:: red_party_struct wTimeCapsulePartyMon6 -wTimeCapsulePartyMonOTNames:: ds PARTY_LENGTH * NAME_LENGTH -wTimeCapsulePartyMonNicks:: ds PARTY_LENGTH * MON_NAME_LENGTH +wTimeCapsulePartyMonOTNames:: ds NAME_LENGTH * PARTY_LENGTH +wTimeCapsulePartyMonNicks:: ds MON_NAME_LENGTH * PARTY_LENGTH NEXTU -; link player data -wLinkPlayerData:: -wLinkPlayerPartyMon1:: party_struct wLinkPlayerPartyMon1 -wLinkPlayerPartyMon2:: party_struct wLinkPlayerPartyMon2 -wLinkPlayerPartyMon3:: party_struct wLinkPlayerPartyMon3 -wLinkPlayerPartyMon4:: party_struct wLinkPlayerPartyMon4 -wLinkPlayerPartyMon5:: party_struct wLinkPlayerPartyMon5 -wLinkPlayerPartyMon6:: party_struct wLinkPlayerPartyMon6 -wLinkPlayerPartyMonOTNames:: ds PARTY_LENGTH * NAME_LENGTH -wLinkPlayerPartyMonNicks:: ds PARTY_LENGTH * MON_NAME_LENGTH +; link patch lists +wLinkPatchList1:: ds SERIAL_PATCH_LIST_LENGTH +wLinkPatchList2:: ds SERIAL_PATCH_LIST_LENGTH ENDU NEXTU +; link data prep + ds 1000 +wCurLinkOTPartyMonTypePtr:: dw +wLinkOTPartyMonTypes:: ds 2 * PARTY_LENGTH + +NEXTU +; link mail data + 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 103 +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 +wLinkOTMailEnd:: + ds 10 + +NEXTU +; received link mail data + ds 500 +wLinkReceivedMail:: ds MAIL_STRUCT_LENGTH * PARTY_LENGTH +wLinkReceivedMailEnd:: db + +NEXTU ; mystery gift data wMysteryGiftStaging:: ds 80 @@ -1084,7 +1105,7 @@ wOtherPlayerLinkAction:: wBattleAction:: db ds 3 wPlayerLinkAction:: db -wce57:: db +wUnusedLinkAction:: db ds 3 wLinkTimeoutFrames:: dw wLinkByteTimeout:: dw @@ -2746,6 +2767,7 @@ wUnusedEggHatchFlag:: db NEXTU ; enemy party +wOTPartyData:: wOTPlayerName:: ds NAME_LENGTH wOTPlayerID:: dw ds 8 |