2018-06-24 07:09:41 -07:00
|
|
|
LinkCommunications:
|
2015-11-11 20:38:57 -08:00
|
|
|
call ClearBGPalettes
|
|
|
|
ld c, 80
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
call ClearScreen
|
|
|
|
call ClearSprites
|
|
|
|
call UpdateSprites
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSCX], a
|
|
|
|
ldh [hSCY], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ld c, 80
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
call ClearScreen
|
|
|
|
call UpdateSprites
|
|
|
|
call LoadStandardFont
|
|
|
|
call LoadFontsBattleExtra
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall LinkComms_LoadPleaseWaitTextboxBorderGFX
|
2015-12-11 13:59:40 -08:00
|
|
|
call WaitBGMap2
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 3, 8
|
2015-12-20 09:54:08 -08:00
|
|
|
ld b, 2
|
|
|
|
ld c, 12
|
2015-11-09 20:55:39 -08:00
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall LinkTextbox2
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 4, 10
|
2015-12-20 09:54:08 -08:00
|
|
|
ld de, String_PleaseWait
|
2015-11-09 20:55:39 -08:00
|
|
|
call PlaceString
|
2016-05-15 18:50:31 -07:00
|
|
|
call SetTradeRoomBGPals
|
2015-12-11 13:59:40 -08:00
|
|
|
call WaitBGMap2
|
2020-10-29 11:45:40 -07:00
|
|
|
ld hl, wLinkByteTimeout
|
2020-10-29 13:43:28 -07:00
|
|
|
assert LOW(SERIAL_LINK_BYTE_TIMEOUT) == 0
|
|
|
|
xor a ; LOW(SERIAL_LINK_BYTE_TIMEOUT)
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
2020-10-29 13:43:28 -07:00
|
|
|
ld [hl], HIGH(SERIAL_LINK_BYTE_TIMEOUT)
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_TIMECAPSULE
|
2015-12-20 09:54:08 -08:00
|
|
|
jp nz, Gen2ToGen2LinkComms
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Gen2ToGen1LinkComms:
|
2015-12-20 09:54:08 -08:00
|
|
|
call ClearLinkData
|
|
|
|
call Link_PrepPartyData_Gen1
|
2015-12-22 15:03:00 -08:00
|
|
|
call FixDataForLinkTransfer
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2016-05-15 18:50:31 -07:00
|
|
|
call WaitLinkTransfer
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSerialConnectionStatus]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp USING_INTERNAL_CLOCK
|
2015-12-21 11:10:16 -08:00
|
|
|
jr nz, .player_1
|
2018-01-19 11:49:43 -08:00
|
|
|
|
2015-12-22 15:03:00 -08:00
|
|
|
ld c, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialSend], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2018-01-19 11:49:43 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialSend], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.player_1
|
2015-11-09 20:55:39 -08:00
|
|
|
ld de, MUSIC_NONE
|
|
|
|
call PlayMusic
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_patch Wireless_net_delay_5
|
2022-03-12 15:34:04 -08:00
|
|
|
if DEF(_CRYSTAL11_VC)
|
|
|
|
ld c, 26
|
|
|
|
else
|
2018-01-19 11:49:43 -08:00
|
|
|
ld c, 3
|
2022-03-12 15:34:04 -08:00
|
|
|
endc
|
|
|
|
vc_patch_end
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, 1 << SERIAL
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIE], a
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2020-11-01 10:42:12 -08:00
|
|
|
ld hl, wLinkBattleRNPreamble
|
2020-11-02 16:32:14 -08:00
|
|
|
ld de, wEnemyMon
|
2020-11-01 10:42:12 -08:00
|
|
|
ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH
|
2022-06-19 19:28:39 -07:00
|
|
|
vc_hook Wireless_ExchangeBytes_Gen2toGen1_RNG_state
|
2018-01-19 11:49:43 -08:00
|
|
|
call Serial_ExchangeBytes
|
|
|
|
ld a, SERIAL_NO_DATA_BYTE
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, wLinkData
|
2020-12-08 18:24:48 -08:00
|
|
|
ld de, wOTPartyData
|
2023-03-31 04:13:52 -07:00
|
|
|
ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + (1 + PARTY_LENGTH + 1) + (REDMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
|
2022-06-19 19:28:39 -07:00
|
|
|
vc_hook Wireless_ExchangeBytes_Gen2toGen1_party_structs
|
2018-01-19 11:49:43 -08:00
|
|
|
call Serial_ExchangeBytes
|
|
|
|
ld a, SERIAL_NO_DATA_BYTE
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wPlayerPatchLists
|
|
|
|
ld de, wOTPatchLists
|
2023-03-30 12:05:07 -07:00
|
|
|
ld bc, SERIAL_PATCH_LIST_LENGTH
|
2022-06-19 19:28:39 -07:00
|
|
|
vc_hook Wireless_ExchangeBytes_Gen2toGen1_patch_lists
|
2018-01-19 11:49:43 -08:00
|
|
|
call Serial_ExchangeBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
2024-03-19 11:49:36 -07:00
|
|
|
ld a, (1 << JOYPAD) | (1 << SERIAL) | (1 << VBLANK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIE], a
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-12-22 15:03:00 -08:00
|
|
|
call Link_CopyRandomNumbers
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wOTPartyData
|
2015-12-21 11:10:16 -08:00
|
|
|
call Link_FindFirstNonControlCharacter_SkipZero
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
pop hl
|
|
|
|
and a
|
2020-10-29 12:15:14 -07:00
|
|
|
jp z, ExitLinkCommunications
|
2015-11-09 20:55:39 -08:00
|
|
|
cp $7
|
2020-10-29 12:15:14 -07:00
|
|
|
jp nc, ExitLinkCommunications
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
ld de, wLinkData
|
2023-03-31 18:29:33 -07:00
|
|
|
ld bc, NAME_LENGTH + (1 + PARTY_LENGTH + 1) + (REDMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
|
2015-12-21 11:10:16 -08:00
|
|
|
call Link_CopyOTData
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
ld de, wOTPatchLists
|
2023-03-31 18:29:33 -07:00
|
|
|
ld hl, wTimeCapsulePlayerData
|
2018-01-19 11:49:43 -08:00
|
|
|
ld c, 2
|
2015-12-21 11:10:16 -08:00
|
|
|
.loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
and a
|
2015-12-21 11:10:16 -08:00
|
|
|
jr z, .loop
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_PREAMBLE_BYTE
|
2015-12-21 11:10:16 -08:00
|
|
|
jr z, .loop
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2015-12-21 11:10:16 -08:00
|
|
|
jr z, .loop
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_PATCH_LIST_PART_TERMINATOR
|
2015-12-21 11:10:16 -08:00
|
|
|
jr z, .next
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
push bc
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, SERIAL_NO_DATA_BYTE
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hl], a
|
|
|
|
pop bc
|
|
|
|
pop hl
|
2015-12-21 11:10:16 -08:00
|
|
|
jr .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.next
|
2023-03-31 18:29:33 -07:00
|
|
|
ld hl, wTimeCapsulePlayerData + SERIAL_PATCH_DATA_SIZE
|
2015-11-09 20:55:39 -08:00
|
|
|
dec c
|
2015-12-21 11:10:16 -08:00
|
|
|
jr nz, .loop
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2023-03-31 17:58:53 -07:00
|
|
|
ld hl, wLinkData
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wOTPlayerName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wOTPartyCount
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
2020-12-08 18:24:48 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.party_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
2015-12-21 11:10:16 -08:00
|
|
|
cp -1
|
|
|
|
jr z, .done_party
|
2018-07-28 16:27:34 -07:00
|
|
|
ld [wTempSpecies], a
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
push de
|
2018-01-16 11:30:10 -08:00
|
|
|
callfar ConvertMon_1to2
|
2015-11-09 20:55:39 -08:00
|
|
|
pop de
|
|
|
|
pop hl
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, [wTempSpecies]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
2015-12-21 11:10:16 -08:00
|
|
|
jr .party_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.done_party
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
2020-10-26 12:45:57 -07:00
|
|
|
ld hl, wTimeCapsulePlayerData
|
2020-10-29 12:15:14 -07:00
|
|
|
call Link_ConvertPartyStruct1to2
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2021-03-17 13:16:02 -07:00
|
|
|
ld a, LOW(wOTPartyMonOTs)
|
2020-10-28 10:35:39 -07:00
|
|
|
ld [wUnusedNamesPointer], a
|
2021-03-17 13:16:02 -07:00
|
|
|
ld a, HIGH(wOTPartyMonOTs)
|
2020-10-28 10:35:39 -07:00
|
|
|
ld [wUnusedNamesPointer + 1], a
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
ld de, MUSIC_NONE
|
|
|
|
call PlayMusic
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSerialConnectionStatus]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp USING_INTERNAL_CLOCK
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, 66
|
|
|
|
call z, DelayFrames
|
|
|
|
ld de, MUSIC_ROUTE_30
|
|
|
|
call PlayMusic
|
2015-12-21 11:10:16 -08:00
|
|
|
jp InitTradeMenuDisplay
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Gen2ToGen2LinkComms:
|
2015-12-20 09:54:08 -08:00
|
|
|
call ClearLinkData
|
|
|
|
call Link_PrepPartyData_Gen2
|
2015-12-22 15:03:00 -08:00
|
|
|
call FixDataForLinkTransfer
|
2020-10-23 10:36:54 -07:00
|
|
|
call CheckLinkTimeout_Gen2
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh a, [hScriptVar]
|
2015-11-09 20:55:39 -08:00
|
|
|
and a
|
2016-01-04 05:43:55 -08:00
|
|
|
jp z, LinkTimeout
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSerialConnectionStatus]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp USING_INTERNAL_CLOCK
|
2020-11-02 16:32:14 -08:00
|
|
|
jr nz, .player_1
|
2018-01-19 11:49:43 -08:00
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
ld c, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialSend], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2018-01-19 11:49:43 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialSend], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-11-02 16:32:14 -08:00
|
|
|
.player_1
|
2015-11-09 20:55:39 -08:00
|
|
|
ld de, MUSIC_NONE
|
|
|
|
call PlayMusic
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_patch Wireless_net_delay_8
|
2022-03-12 15:34:04 -08:00
|
|
|
if DEF(_CRYSTAL11_VC)
|
|
|
|
ld c, 26
|
|
|
|
else
|
2015-12-20 09:54:08 -08:00
|
|
|
ld c, 3
|
2022-03-12 15:34:04 -08:00
|
|
|
endc
|
|
|
|
vc_patch_end
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, 1 << SERIAL
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIE], a
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2020-11-01 10:42:12 -08:00
|
|
|
ld hl, wLinkBattleRNPreamble
|
2023-03-30 12:23:46 -07:00
|
|
|
ld de, wOTLinkBattleRNData
|
2020-11-01 10:42:12 -08:00
|
|
|
ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH
|
2022-06-19 19:28:39 -07:00
|
|
|
vc_hook Wireless_ExchangeBytes_RNG_state
|
2018-01-19 11:49:43 -08:00
|
|
|
call Serial_ExchangeBytes
|
|
|
|
ld a, SERIAL_NO_DATA_BYTE
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, wLinkData
|
2020-12-08 18:24:48 -08:00
|
|
|
ld de, wOTPartyData
|
2023-03-31 04:13:52 -07:00
|
|
|
ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + (1 + PARTY_LENGTH + 1) + 2 + (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
|
2022-06-19 19:28:39 -07:00
|
|
|
vc_hook Wireless_ExchangeBytes_party_structs
|
2018-01-19 11:49:43 -08:00
|
|
|
call Serial_ExchangeBytes
|
|
|
|
ld a, SERIAL_NO_DATA_BYTE
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wPlayerPatchLists
|
|
|
|
ld de, wOTPatchLists
|
2023-03-30 12:05:07 -07:00
|
|
|
ld bc, SERIAL_PATCH_LIST_LENGTH
|
2022-06-19 19:28:39 -07:00
|
|
|
vc_hook Wireless_ExchangeBytes_patch_lists
|
2018-01-19 11:49:43 -08:00
|
|
|
call Serial_ExchangeBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_TRADECENTER
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .not_trading
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wLinkPlayerMail
|
|
|
|
ld de, wLinkOTMail
|
|
|
|
ld bc, wLinkPlayerMailEnd - wLinkPlayerMail
|
2022-06-19 19:28:39 -07:00
|
|
|
vc_hook Wireless_ExchangeBytes_mail
|
2018-01-19 11:49:43 -08:00
|
|
|
call ExchangeBytes
|
2015-12-22 15:03:00 -08:00
|
|
|
.not_trading
|
2023-03-31 04:13:52 -07:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
2024-03-19 11:49:36 -07:00
|
|
|
ld a, (1 << JOYPAD) | (1 << SERIAL) | (1 << VBLANK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIE], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld de, MUSIC_NONE
|
|
|
|
call PlayMusic
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-12-22 15:03:00 -08:00
|
|
|
call Link_CopyRandomNumbers
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wOTPartyData
|
2015-12-21 11:10:16 -08:00
|
|
|
call Link_FindFirstNonControlCharacter_SkipZero
|
2015-12-20 09:54:08 -08:00
|
|
|
ld de, wLinkData
|
2020-12-08 18:24:48 -08:00
|
|
|
ld bc, NAME_LENGTH + 1 + PARTY_LENGTH + 1 + 2 + (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH
|
2015-12-21 11:10:16 -08:00
|
|
|
call Link_CopyOTData
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2023-03-31 17:58:53 -07:00
|
|
|
ld de, wOTPatchLists
|
|
|
|
ld hl, wLinkPlayerData
|
2018-01-19 11:49:43 -08:00
|
|
|
ld c, 2
|
2015-12-22 15:03:00 -08:00
|
|
|
.loop1
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
and a
|
2015-12-22 15:03:00 -08:00
|
|
|
jr z, .loop1
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_PREAMBLE_BYTE
|
2015-12-22 15:03:00 -08:00
|
|
|
jr z, .loop1
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2015-12-22 15:03:00 -08:00
|
|
|
jr z, .loop1
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_PATCH_LIST_PART_TERMINATOR
|
2015-12-22 15:03:00 -08:00
|
|
|
jr z, .next1
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
push bc
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, SERIAL_NO_DATA_BYTE
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hl], a
|
|
|
|
pop bc
|
|
|
|
pop hl
|
2015-12-22 15:03:00 -08:00
|
|
|
jr .loop1
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-22 15:03:00 -08:00
|
|
|
.next1
|
2023-03-31 17:58:53 -07:00
|
|
|
ld hl, wLinkPlayerData + SERIAL_PATCH_DATA_SIZE
|
2015-11-09 20:55:39 -08:00
|
|
|
dec c
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .loop1
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_TRADECENTER
|
2015-12-22 15:03:00 -08:00
|
|
|
jp nz, .skip_mail
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wLinkOTMail
|
2015-12-22 15:03:00 -08:00
|
|
|
.loop2
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
2020-12-08 18:24:48 -08:00
|
|
|
cp SERIAL_MAIL_PREAMBLE_BYTE
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .loop2
|
|
|
|
.loop3
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2015-12-22 15:03:00 -08:00
|
|
|
jr z, .loop3
|
2020-12-08 18:24:48 -08:00
|
|
|
cp SERIAL_MAIL_PREAMBLE_BYTE
|
2015-12-22 15:03:00 -08:00
|
|
|
jr z, .loop3
|
2015-11-09 20:55:39 -08:00
|
|
|
dec hl
|
2023-03-31 17:58:53 -07:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
ld de, wLinkOTMail
|
|
|
|
ld bc, wLinkDataEnd - wLinkOTMail ; should be wLinkOTMailEnd - wLinkOTMail
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2023-03-31 17:58:53 -07:00
|
|
|
|
|
|
|
; Replace SERIAL_MAIL_REPLACEMENT_BYTE with SERIAL_NO_DATA_BYTE across all mail
|
|
|
|
; message bodies.
|
|
|
|
ld hl, wLinkOTMailMessages
|
2020-12-08 18:24:48 -08:00
|
|
|
ld bc, (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH
|
2015-12-22 15:03:00 -08:00
|
|
|
.loop4
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hl]
|
2020-12-08 18:24:48 -08:00
|
|
|
cp SERIAL_MAIL_REPLACEMENT_BYTE
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .okay1
|
2018-01-19 11:49:43 -08:00
|
|
|
ld [hl], SERIAL_NO_DATA_BYTE
|
2015-12-22 15:03:00 -08:00
|
|
|
.okay1
|
2015-11-09 20:55:39 -08:00
|
|
|
inc hl
|
|
|
|
dec bc
|
|
|
|
ld a, b
|
|
|
|
or c
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .loop4
|
2023-03-31 17:58:53 -07:00
|
|
|
|
2023-03-31 04:13:52 -07:00
|
|
|
ld de, wLinkOTMailPatchSet
|
2015-12-22 15:03:00 -08:00
|
|
|
.loop5
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [de]
|
|
|
|
inc de
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_PATCH_LIST_PART_TERMINATOR
|
2015-12-22 15:03:00 -08:00
|
|
|
jr z, .start_copying_mail
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wLinkOTMailMetadata
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2020-11-09 12:17:03 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
2018-01-19 11:49:43 -08:00
|
|
|
ld [hl], SERIAL_NO_DATA_BYTE
|
2015-12-22 15:03:00 -08:00
|
|
|
jr .loop5
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-22 15:03:00 -08:00
|
|
|
.start_copying_mail
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wLinkOTMail
|
|
|
|
ld de, wLinkReceivedMail
|
2015-12-22 15:03:00 -08:00
|
|
|
ld b, PARTY_LENGTH
|
|
|
|
.copy_mail_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
2015-12-22 15:03:00 -08:00
|
|
|
ld bc, MAIL_MSG_LENGTH + 1
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, LOW(MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1))
|
2015-11-09 20:55:39 -08:00
|
|
|
add e
|
|
|
|
ld e, a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, HIGH(MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1))
|
2015-11-09 20:55:39 -08:00
|
|
|
adc d
|
|
|
|
ld d, a
|
|
|
|
pop bc
|
|
|
|
dec b
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .copy_mail_loop
|
2020-12-08 18:24:48 -08:00
|
|
|
ld de, wLinkReceivedMail
|
2015-12-22 15:03:00 -08:00
|
|
|
ld b, PARTY_LENGTH
|
|
|
|
.copy_author_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, LOW(MAIL_MSG_LENGTH + 1)
|
2015-11-09 20:55:39 -08:00
|
|
|
add e
|
|
|
|
ld e, a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, HIGH(MAIL_MSG_LENGTH + 1)
|
2015-11-09 20:55:39 -08:00
|
|
|
adc d
|
|
|
|
ld d, a
|
2015-12-22 15:03:00 -08:00
|
|
|
ld bc, MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
|
|
|
pop bc
|
|
|
|
dec b
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .copy_author_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
ld de, wLinkReceivedMailEnd
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
|
|
|
ld [de], a
|
|
|
|
|
2015-12-22 15:03:00 -08:00
|
|
|
.skip_mail
|
2023-03-31 17:58:53 -07:00
|
|
|
ld hl, wLinkData
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wOTPlayerName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wOTPartyCount
|
2018-01-19 11:49:43 -08:00
|
|
|
ld bc, 1 + PARTY_LENGTH + 1
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wOTPlayerID
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, 2
|
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wOTPartyMons
|
|
|
|
ld bc, wOTPartyDataEnd - wOTPartyMons
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2021-03-17 13:16:02 -07:00
|
|
|
ld a, LOW(wOTPartyMonOTs)
|
2020-10-28 10:35:39 -07:00
|
|
|
ld [wUnusedNamesPointer], a
|
2021-03-17 13:16:02 -07:00
|
|
|
ld a, HIGH(wOTPartyMonOTs)
|
2020-10-28 10:35:39 -07:00
|
|
|
ld [wUnusedNamesPointer + 1], a
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
ld de, MUSIC_NONE
|
|
|
|
call PlayMusic
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSerialConnectionStatus]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp USING_INTERNAL_CLOCK
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, 66
|
|
|
|
call z, DelayFrames
|
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_COLOSSEUM
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .ready_to_trade
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, CAL
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wOtherTrainerClass], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call ClearScreen
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall Link_WaitBGMap
|
2020-11-03 16:53:07 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOptions
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hl]
|
|
|
|
push af
|
2018-01-19 11:49:43 -08:00
|
|
|
and 1 << STEREO
|
|
|
|
or TEXT_DELAY_MED
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hl], a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPlayerName
|
|
|
|
ld de, wOTClassName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
2015-11-11 20:38:57 -08:00
|
|
|
call ReturnToMapFromSubmenu
|
2016-05-05 12:07:37 -07:00
|
|
|
ld a, [wDisableTextAcceleration]
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
2023-10-02 08:39:10 -07:00
|
|
|
ld a, TRUE
|
2016-05-05 12:07:37 -07:00
|
|
|
ld [wDisableTextAcceleration], a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rIE]
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rIF]
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
|
|
|
ldh a, [rIE]
|
2019-05-05 09:14:46 -07:00
|
|
|
set LCD_STAT, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIE], a
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
2016-05-05 12:07:37 -07:00
|
|
|
|
2020-11-03 16:53:07 -08:00
|
|
|
; LET'S DO THIS
|
2018-01-16 11:30:10 -08:00
|
|
|
predef StartBattle
|
2016-05-05 12:07:37 -07:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rIF]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld h, a
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIE], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, h
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
2016-05-05 12:07:37 -07:00
|
|
|
ld [wDisableTextAcceleration], a
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wOptions], a
|
2020-11-03 16:53:07 -08:00
|
|
|
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall LoadPokemonData
|
2020-10-29 12:15:14 -07:00
|
|
|
jp ExitLinkCommunications
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-22 15:03:00 -08:00
|
|
|
.ready_to_trade
|
2015-11-09 20:55:39 -08:00
|
|
|
ld de, MUSIC_ROUTE_30
|
|
|
|
call PlayMusic
|
2015-12-21 11:10:16 -08:00
|
|
|
jp InitTradeMenuDisplay
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LinkTimeout:
|
2019-10-20 15:24:17 -07:00
|
|
|
ld de, .LinkTimeoutText
|
2016-01-04 05:43:55 -08:00
|
|
|
ld b, 10
|
2015-12-20 09:54:08 -08:00
|
|
|
.loop
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
2015-12-01 18:54:11 -08:00
|
|
|
call LinkDataReceived
|
2015-11-09 20:55:39 -08:00
|
|
|
dec b
|
2015-12-20 09:54:08 -08:00
|
|
|
jr nz, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
|
|
|
ld [hld], a
|
|
|
|
ld [hl], a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
push de
|
|
|
|
hlcoord 0, 12
|
2015-12-20 09:54:08 -08:00
|
|
|
ld b, 4
|
|
|
|
ld c, 18
|
2015-11-09 20:55:39 -08:00
|
|
|
push de
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall LinkTextbox2
|
2015-11-09 20:55:39 -08:00
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
bccoord 1, 14
|
2024-02-10 15:16:00 -08:00
|
|
|
call PrintTextboxTextAt
|
2015-11-20 08:47:52 -08:00
|
|
|
call RotateThreePalettesRight
|
2015-11-09 20:55:39 -08:00
|
|
|
call ClearScreen
|
2023-07-26 08:01:20 -07:00
|
|
|
ld b, CGB_DIPLOMA
|
|
|
|
call GetCGBLayout
|
2015-12-11 13:59:40 -08:00
|
|
|
call WaitBGMap2
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2019-10-20 15:24:17 -07:00
|
|
|
.LinkTimeoutText:
|
|
|
|
text_far _LinkTimeoutText
|
2018-11-17 10:33:03 -08:00
|
|
|
text_end
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ExchangeBytes:
|
2020-10-29 11:45:40 -07:00
|
|
|
; This is similar to Serial_ExchangeBytes,
|
|
|
|
; but without a SERIAL_PREAMBLE_BYTE check.
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, TRUE
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialIgnoringInitialData], a
|
2015-12-22 15:03:00 -08:00
|
|
|
.loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hl]
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialSend], a
|
2018-01-19 11:49:43 -08:00
|
|
|
call Serial_ExchangeByte
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
|
|
|
ld b, a
|
|
|
|
inc hl
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, 48
|
2020-10-29 11:45:40 -07:00
|
|
|
.wait
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2020-10-29 11:45:40 -07:00
|
|
|
jr nz, .wait
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSerialIgnoringInitialData]
|
2015-11-09 20:55:39 -08:00
|
|
|
and a
|
|
|
|
ld a, b
|
|
|
|
pop bc
|
2015-12-22 15:03:00 -08:00
|
|
|
jr z, .load
|
2015-11-09 20:55:39 -08:00
|
|
|
dec hl
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialIgnoringInitialData], a
|
2015-12-22 15:03:00 -08:00
|
|
|
jr .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-22 15:03:00 -08:00
|
|
|
.load
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
dec bc
|
|
|
|
ld a, b
|
|
|
|
or c
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
String_PleaseWait:
|
2015-11-09 20:55:39 -08:00
|
|
|
db "PLEASE WAIT!@"
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ClearLinkData:
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, wLinkData
|
|
|
|
ld bc, wLinkDataEnd - wLinkData
|
|
|
|
.loop
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
|
|
|
ld [hli], a
|
|
|
|
dec bc
|
|
|
|
ld a, b
|
|
|
|
or c
|
2015-12-20 09:54:08 -08:00
|
|
|
jr nz, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
FixDataForLinkTransfer:
|
2020-11-01 10:42:12 -08:00
|
|
|
ld hl, wLinkBattleRNPreamble
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, SERIAL_PREAMBLE_BYTE
|
2020-11-01 10:42:12 -08:00
|
|
|
ld b, SERIAL_RN_PREAMBLE_LENGTH
|
|
|
|
.preamble_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
|
|
|
dec b
|
2020-11-01 10:42:12 -08:00
|
|
|
jr nz, .preamble_loop
|
|
|
|
|
2023-03-30 12:05:07 -07:00
|
|
|
; Initialize random seed, making sure special bytes are omitted
|
2020-11-01 10:42:12 -08:00
|
|
|
assert wLinkBattleRNPreamble + SERIAL_RN_PREAMBLE_LENGTH == wLinkBattleRNs
|
|
|
|
ld b, SERIAL_RNS_LENGTH
|
|
|
|
.rn_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
call Random
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_PREAMBLE_BYTE
|
2020-11-01 10:42:12 -08:00
|
|
|
jr nc, .rn_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
|
|
|
dec b
|
2020-11-01 10:42:12 -08:00
|
|
|
jr nz, .rn_loop
|
|
|
|
|
2023-03-30 12:05:07 -07:00
|
|
|
; Clear the patch list
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wPlayerPatchLists
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, SERIAL_PREAMBLE_BYTE
|
2023-03-31 04:13:52 -07:00
|
|
|
rept SERIAL_PATCH_PREAMBLE_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
2023-03-31 04:13:52 -07:00
|
|
|
endr
|
2023-03-30 12:05:07 -07:00
|
|
|
ld b, SERIAL_PATCH_LIST_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2023-03-30 12:05:07 -07:00
|
|
|
.clear_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
|
|
|
dec b
|
2023-03-30 12:05:07 -07:00
|
|
|
jr nz, .clear_loop
|
2020-11-01 10:42:12 -08:00
|
|
|
|
2023-03-30 12:05:07 -07:00
|
|
|
; Loop through all the patchable link data
|
|
|
|
ld hl, wLinkData + SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + (1 + PARTY_LENGTH + 1) - 1
|
|
|
|
ld de, wPlayerPatchLists + SERIAL_RNS_LENGTH ; ???
|
2015-12-21 11:10:16 -08:00
|
|
|
lb bc, 0, 0
|
2023-03-30 12:05:07 -07:00
|
|
|
.patch_loop
|
|
|
|
; Check if we've gone over the entire area
|
2015-11-09 20:55:39 -08:00
|
|
|
inc c
|
|
|
|
ld a, c
|
2023-03-30 12:05:07 -07:00
|
|
|
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
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, b
|
|
|
|
dec a
|
2023-03-30 12:05:07 -07:00
|
|
|
jr nz, .process
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_TIMECAPSULE
|
2023-03-30 12:05:07 -07:00
|
|
|
ld b, REDMON_STRUCT_LENGTH * PARTY_LENGTH - SERIAL_PATCH_DATA_SIZE + 1
|
|
|
|
jr z, .got_size
|
|
|
|
ld b, 2 + PARTYMON_STRUCT_LENGTH * PARTY_LENGTH - SERIAL_PATCH_DATA_SIZE + 1
|
|
|
|
.got_size
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, c
|
|
|
|
cp b
|
|
|
|
pop bc
|
2023-03-30 12:05:07 -07:00
|
|
|
jr z, .data2_done
|
|
|
|
|
|
|
|
.process
|
|
|
|
; Replace the "no data" byte, and record it in the array
|
2015-11-09 20:55:39 -08:00
|
|
|
inc hl
|
|
|
|
ld a, [hl]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2023-03-30 12:05:07 -07:00
|
|
|
jr nz, .patch_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, c
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
2020-12-08 18:24:48 -08:00
|
|
|
ld [hl], SERIAL_PATCH_REPLACEMENT_BYTE
|
2023-03-30 12:05:07 -07:00
|
|
|
jr .patch_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2023-03-30 12:05:07 -07:00
|
|
|
.data1_done
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
lb bc, 1, 0
|
2023-03-30 12:05:07 -07:00
|
|
|
jr .patch_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2023-03-30 12:05:07 -07:00
|
|
|
.data2_done
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Link_PrepPartyData_Gen1:
|
2015-12-20 09:54:08 -08:00
|
|
|
ld de, wLinkData
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, SERIAL_PREAMBLE_BYTE
|
2020-07-06 12:49:01 -07:00
|
|
|
ld b, SERIAL_PREAMBLE_LENGTH
|
2015-12-20 09:54:08 -08:00
|
|
|
.loop1
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
dec b
|
2015-12-20 09:54:08 -08:00
|
|
|
jr nz, .loop1
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPlayerName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
push de
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyCount
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
2015-12-20 09:54:08 -08:00
|
|
|
.loop2
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
2015-12-20 09:54:08 -08:00
|
|
|
cp -1
|
|
|
|
jr z, .done_party
|
2018-07-28 16:27:34 -07:00
|
|
|
ld [wTempSpecies], a
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
push de
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar ConvertMon_2to1
|
2015-11-09 20:55:39 -08:00
|
|
|
pop de
|
|
|
|
pop hl
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, [wTempSpecies]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
2015-12-20 09:54:08 -08:00
|
|
|
jr .loop2
|
|
|
|
.done_party
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
pop de
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, 1 + PARTY_LENGTH + 1
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, de
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1Species
|
2015-12-20 09:54:08 -08:00
|
|
|
ld c, PARTY_LENGTH
|
|
|
|
.mon_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
2015-12-20 09:54:08 -08:00
|
|
|
call .ConvertPartyStruct2to1
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
dec c
|
2015-12-20 09:54:08 -08:00
|
|
|
jr nz, .mon_loop
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2021-03-17 13:16:02 -07:00
|
|
|
ld hl, wPartyMonOTs
|
2015-12-20 09:54:08 -08:00
|
|
|
call .copy_ot_nicks
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMonNicknames
|
2015-12-20 09:54:08 -08:00
|
|
|
.copy_ot_nicks
|
|
|
|
ld bc, PARTY_LENGTH * NAME_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
jp CopyBytes
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.ConvertPartyStruct2to1:
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
ld a, [hl]
|
2018-07-28 16:27:34 -07:00
|
|
|
ld [wTempSpecies], a
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar ConvertMon_2to1
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
pop de
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, [wTempSpecies]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, MON_HP
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
ld a, [hl]
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
xor a
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, MON_STATUS
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
ld a, [bc]
|
2015-12-20 09:54:08 -08:00
|
|
|
cp MAGNEMITE
|
|
|
|
jr z, .steel_type
|
|
|
|
cp MAGNETON
|
|
|
|
jr nz, .skip_steel
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
.steel_type
|
|
|
|
ld a, ELECTRIC
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
2015-12-20 09:54:08 -08:00
|
|
|
jr .done_steel
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
.skip_steel
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
|
|
|
dec a
|
2017-12-11 14:35:35 -08:00
|
|
|
ld hl, BaseData + BASE_TYPES
|
|
|
|
ld bc, BASE_DATA_SIZE
|
2015-11-09 20:55:39 -08:00
|
|
|
call AddNTimes
|
2017-12-19 12:28:06 -08:00
|
|
|
ld bc, BASE_CATCH_RATE - BASE_TYPES
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, BANK(BaseData)
|
|
|
|
call FarCopyBytes
|
|
|
|
pop bc
|
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
.done_steel
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, MON_ITEM
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
2015-12-20 09:54:08 -08:00
|
|
|
ld bc, MON_HAPPINESS - MON_ITEM
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
|
|
|
pop bc
|
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, MON_LEVEL
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
ld [de], a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurPartyLevel], a
|
2015-11-09 20:55:39 -08:00
|
|
|
inc de
|
|
|
|
|
|
|
|
push bc
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, MON_MAXHP
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
2015-12-20 09:54:08 -08:00
|
|
|
ld bc, MON_SAT - MON_MAXHP
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
|
|
|
|
ld a, [bc]
|
|
|
|
dec a
|
|
|
|
push bc
|
|
|
|
ld b, 0
|
|
|
|
ld c, a
|
|
|
|
ld hl, KantoMonSpecials
|
|
|
|
add hl, bc
|
|
|
|
ld a, BANK(KantoMonSpecials)
|
|
|
|
call GetFarByte
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wBaseSpecialAttack], a
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
ld hl, MON_STAT_EXP - 1
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
2015-12-20 09:54:08 -08:00
|
|
|
ld c, STAT_SATK
|
|
|
|
ld b, TRUE
|
2018-02-22 08:13:29 -08:00
|
|
|
predef CalcMonStatC
|
2015-11-09 20:55:39 -08:00
|
|
|
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh a, [hQuotient + 2]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh a, [hQuotient + 3]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
ld h, b
|
|
|
|
ld l, c
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Link_PrepPartyData_Gen2:
|
2015-12-20 09:54:08 -08:00
|
|
|
ld de, wLinkData
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, SERIAL_PREAMBLE_BYTE
|
2020-07-06 12:49:01 -07:00
|
|
|
ld b, SERIAL_PREAMBLE_LENGTH
|
2023-03-31 04:13:52 -07:00
|
|
|
.preamble_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
dec b
|
2023-03-31 04:13:52 -07:00
|
|
|
jr nz, .preamble_loop
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPlayerName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyCount
|
2015-11-22 09:01:58 -08:00
|
|
|
ld bc, 1 + PARTY_LENGTH + 1
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPlayerID
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, 2
|
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1Species
|
2015-11-22 09:01:58 -08:00
|
|
|
ld bc, PARTY_LENGTH * PARTYMON_STRUCT_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2021-03-17 13:16:02 -07:00
|
|
|
ld hl, wPartyMonOTs
|
2015-11-22 09:01:58 -08:00
|
|
|
ld bc, PARTY_LENGTH * NAME_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMonNicknames
|
2018-01-20 09:25:55 -08:00
|
|
|
ld bc, PARTY_LENGTH * MON_NAME_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2015-11-22 09:01:58 -08:00
|
|
|
|
|
|
|
; Okay, we did all that. Now, are we in the trade center?
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_TRADECENTER
|
|
|
|
ret nz
|
2015-11-22 09:01:58 -08:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
; Fill 5 bytes at wLinkPlayerMailPreamble with $20
|
2023-03-29 19:51:49 -07:00
|
|
|
ld de, wLinkPlayerMail
|
2020-12-08 18:24:48 -08:00
|
|
|
ld a, SERIAL_MAIL_PREAMBLE_BYTE
|
2020-10-29 12:15:14 -07:00
|
|
|
call Link_CopyMailPreamble
|
2015-11-22 09:01:58 -08:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
; Copy all the mail messages to wLinkPlayerMailMessages
|
2015-11-17 14:56:49 -08:00
|
|
|
ld a, BANK(sPartyMail)
|
2020-06-17 14:03:38 -07:00
|
|
|
call OpenSRAM
|
2015-11-17 14:56:49 -08:00
|
|
|
ld hl, sPartyMail
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, PARTY_LENGTH
|
2023-03-31 04:13:52 -07:00
|
|
|
.message_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
2015-11-22 09:01:58 -08:00
|
|
|
ld bc, MAIL_MSG_LENGTH + 1
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2020-12-08 18:24:48 -08:00
|
|
|
ld bc, MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
dec b
|
2023-03-31 04:13:52 -07:00
|
|
|
jr nz, .message_loop
|
2023-03-29 19:51:49 -07:00
|
|
|
|
2020-12-08 18:24:48 -08:00
|
|
|
; Copy the mail data to wLinkPlayerMailMetadata
|
2015-11-17 14:56:49 -08:00
|
|
|
ld hl, sPartyMail
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, PARTY_LENGTH
|
2023-03-31 04:13:52 -07:00
|
|
|
.metadata_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
2015-11-22 09:01:58 -08:00
|
|
|
ld bc, MAIL_MSG_LENGTH + 1
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
2020-12-08 18:24:48 -08:00
|
|
|
ld bc, MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
|
|
|
pop bc
|
|
|
|
dec b
|
2023-03-31 04:13:52 -07:00
|
|
|
jr nz, .metadata_loop
|
2023-03-29 19:51:49 -07:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
call CloseSRAM
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2023-03-29 19:51:49 -07:00
|
|
|
; The SERIAL_NO_DATA_BYTE value isn't allowed anywhere in message text
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wLinkPlayerMailMessages
|
|
|
|
ld bc, (MAIL_MSG_LENGTH + 1) * PARTY_LENGTH
|
2023-03-31 04:13:52 -07:00
|
|
|
.message_patch_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hl]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2023-03-31 04:13:52 -07:00
|
|
|
jr nz, .message_patch_skip
|
2020-12-08 18:24:48 -08:00
|
|
|
ld [hl], SERIAL_MAIL_REPLACEMENT_BYTE
|
2023-03-31 04:13:52 -07:00
|
|
|
.message_patch_skip
|
2015-11-09 20:55:39 -08:00
|
|
|
inc hl
|
|
|
|
dec bc
|
|
|
|
ld a, b
|
|
|
|
or c
|
2023-03-31 04:13:52 -07:00
|
|
|
jr nz, .message_patch_loop
|
2020-11-02 16:32:14 -08:00
|
|
|
|
2023-03-29 19:51:49 -07:00
|
|
|
; Calculate the patch offsets for the mail metadata
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wLinkPlayerMailMetadata
|
|
|
|
ld de, wLinkPlayerMailPatchSet
|
|
|
|
ld b, (MAIL_STRUCT_LENGTH - (MAIL_MSG_LENGTH + 1)) * PARTY_LENGTH
|
|
|
|
ld c, 0
|
2023-03-31 04:13:52 -07:00
|
|
|
.metadata_patch_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
inc c
|
|
|
|
ld a, [hl]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2023-03-31 04:13:52 -07:00
|
|
|
jr nz, .metadata_patch_skip
|
2020-12-08 18:24:48 -08:00
|
|
|
ld [hl], SERIAL_PATCH_REPLACEMENT_BYTE
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, c
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
2023-03-31 04:13:52 -07:00
|
|
|
.metadata_patch_skip
|
2015-11-09 20:55:39 -08:00
|
|
|
inc hl
|
|
|
|
dec b
|
2023-03-31 04:13:52 -07:00
|
|
|
jr nz, .metadata_patch_loop
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
ret
|
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
Link_CopyMailPreamble:
|
|
|
|
; fill 5 bytes with the value of a, starting at de
|
2020-12-08 18:24:48 -08:00
|
|
|
ld c, SERIAL_MAIL_PREAMBLE_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
.loop
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
dec c
|
|
|
|
jr nz, .loop
|
|
|
|
ret
|
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
Link_ConvertPartyStruct1to2:
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2015-12-21 11:10:16 -08:00
|
|
|
ld bc, wLinkOTPartyMonTypes
|
2020-12-23 13:29:30 -08:00
|
|
|
ld hl, wCurLinkOTPartyMonTypePointer
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, c
|
|
|
|
ld [hli], a
|
|
|
|
ld [hl], b
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPartyMon1Species
|
2015-12-20 09:54:08 -08:00
|
|
|
ld c, PARTY_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
.loop
|
|
|
|
push bc
|
2015-12-21 11:10:16 -08:00
|
|
|
call .ConvertToGen2
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
dec c
|
|
|
|
jr nz, .loop
|
|
|
|
pop hl
|
2015-12-21 11:10:16 -08:00
|
|
|
ld bc, PARTY_LENGTH * REDMON_STRUCT_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
2021-03-17 13:16:02 -07:00
|
|
|
ld de, wOTPartyMonOTs
|
2015-12-20 09:54:08 -08:00
|
|
|
ld bc, PARTY_LENGTH * NAME_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wOTPartyMonNicknames
|
2018-01-20 09:25:55 -08:00
|
|
|
ld bc, PARTY_LENGTH * MON_NAME_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
jp CopyBytes
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.ConvertToGen2:
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
push bc
|
|
|
|
push de
|
2018-07-28 16:27:34 -07:00
|
|
|
ld [wTempSpecies], a
|
2018-01-16 11:30:10 -08:00
|
|
|
callfar ConvertMon_1to2
|
2015-11-09 20:55:39 -08:00
|
|
|
pop de
|
|
|
|
pop bc
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, [wTempSpecies]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [bc], a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurSpecies], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld hl, MON_HP
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hli], a
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hl], a
|
|
|
|
inc de
|
2015-12-21 11:10:16 -08:00
|
|
|
ld hl, MON_STATUS
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hl], a
|
2020-12-23 13:29:30 -08:00
|
|
|
ld hl, wCurLinkOTPartyMonTypePointer
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
|
|
|
inc de
|
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
|
|
|
inc de
|
|
|
|
ld a, l
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wCurLinkOTPartyMonTypePointer], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, h
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wCurLinkOTPartyMonTypePointer + 1], a
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
2015-12-21 11:10:16 -08:00
|
|
|
ld hl, MON_ITEM
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
push hl
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
pop de
|
|
|
|
push bc
|
|
|
|
ld a, [hli]
|
|
|
|
ld b, a
|
2015-12-21 11:10:16 -08:00
|
|
|
call TimeCapsule_ReplaceTeruSama
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, b
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
pop bc
|
|
|
|
ld bc, $19
|
|
|
|
call CopyBytes
|
|
|
|
pop bc
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
ld hl, $1f
|
|
|
|
add hl, bc
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hl], a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurPartyLevel], a
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
|
|
|
ld hl, $24
|
|
|
|
add hl, bc
|
|
|
|
push hl
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
pop de
|
|
|
|
ld bc, 8
|
|
|
|
call CopyBytes
|
|
|
|
pop bc
|
|
|
|
call GetBaseData
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2015-12-21 11:10:16 -08:00
|
|
|
ld hl, MON_STAT_EXP - 1
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
2015-12-20 09:54:08 -08:00
|
|
|
ld c, STAT_SATK
|
|
|
|
ld b, TRUE
|
2018-02-22 08:13:29 -08:00
|
|
|
predef CalcMonStatC
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
pop hl
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hQuotient + 2]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh a, [hQuotient + 3]
|
|
|
|
ld [hli], a
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
push bc
|
2015-12-21 11:10:16 -08:00
|
|
|
ld hl, MON_STAT_EXP - 1
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
2015-12-20 09:54:08 -08:00
|
|
|
ld c, STAT_SDEF
|
|
|
|
ld b, TRUE
|
2018-02-22 08:13:29 -08:00
|
|
|
predef CalcMonStatC
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
pop hl
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hQuotient + 2]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh a, [hQuotient + 3]
|
|
|
|
ld [hli], a
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
ld hl, $1b
|
|
|
|
add hl, bc
|
|
|
|
ld a, $46
|
|
|
|
ld [hli], a
|
|
|
|
xor a
|
|
|
|
ld [hli], a
|
2016-05-04 08:46:23 -07:00
|
|
|
ld [hli], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hl], a
|
|
|
|
pop hl
|
|
|
|
inc de
|
2016-05-04 08:46:23 -07:00
|
|
|
inc de
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
TimeCapsule_ReplaceTeruSama:
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, b
|
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
push hl
|
2017-12-11 19:59:30 -08:00
|
|
|
ld hl, TimeCapsule_CatchRateItems
|
2015-11-09 20:55:39 -08:00
|
|
|
.loop
|
|
|
|
ld a, [hli]
|
|
|
|
and a
|
|
|
|
jr z, .end
|
|
|
|
cp b
|
|
|
|
jr z, .found
|
|
|
|
inc hl
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
.found
|
|
|
|
ld b, [hl]
|
|
|
|
|
|
|
|
.end
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-01-02 23:23:54 -08:00
|
|
|
INCLUDE "data/items/catch_rate_items.asm"
|
2017-12-11 19:59:30 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Link_CopyOTData:
|
2015-12-20 09:54:08 -08:00
|
|
|
.loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2015-12-20 09:54:08 -08:00
|
|
|
jr z, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
dec bc
|
|
|
|
ld a, b
|
|
|
|
or c
|
2015-12-20 09:54:08 -08:00
|
|
|
jr nz, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Link_CopyRandomNumbers:
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSerialConnectionStatus]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp USING_INTERNAL_CLOCK
|
2015-11-09 20:55:39 -08:00
|
|
|
ret z
|
2023-03-30 12:23:46 -07:00
|
|
|
ld hl, wOTLinkBattleRNData
|
2015-12-21 11:10:16 -08:00
|
|
|
call Link_FindFirstNonControlCharacter_AllowZero
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wLinkBattleRNs
|
2015-12-21 11:10:16 -08:00
|
|
|
ld c, 10
|
2015-12-20 09:54:08 -08:00
|
|
|
.loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2015-12-20 09:54:08 -08:00
|
|
|
jr z, .loop
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_PREAMBLE_BYTE
|
2015-12-20 09:54:08 -08:00
|
|
|
jr z, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
dec c
|
2015-12-20 09:54:08 -08:00
|
|
|
jr nz, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Link_FindFirstNonControlCharacter_SkipZero:
|
2015-12-20 09:54:08 -08:00
|
|
|
.loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
|
|
|
and a
|
2015-12-20 09:54:08 -08:00
|
|
|
jr z, .loop
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_PREAMBLE_BYTE
|
2015-12-20 09:54:08 -08:00
|
|
|
jr z, .loop
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2015-12-20 09:54:08 -08:00
|
|
|
jr z, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
dec hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Link_FindFirstNonControlCharacter_AllowZero:
|
2015-12-20 09:54:08 -08:00
|
|
|
.loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_PREAMBLE_BYTE
|
2015-12-20 09:54:08 -08:00
|
|
|
jr z, .loop
|
2018-01-19 11:49:43 -08:00
|
|
|
cp SERIAL_NO_DATA_BYTE
|
2015-12-20 09:54:08 -08:00
|
|
|
jr z, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
dec hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
InitTradeMenuDisplay:
|
2015-11-09 20:55:39 -08:00
|
|
|
call ClearScreen
|
2020-10-23 10:36:54 -07:00
|
|
|
call LoadTradeScreenBorderGFX
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall InitTradeSpeciesList
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2015-11-23 13:04:53 -08:00
|
|
|
ld hl, wOtherPlayerLinkMode
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
2016-05-10 09:31:49 -07:00
|
|
|
ld [hli], a
|
|
|
|
ld [hli], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hl], a
|
2015-12-21 11:10:16 -08:00
|
|
|
ld a, 1
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
2015-11-09 20:55:39 -08:00
|
|
|
inc a
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2015-12-21 11:10:16 -08:00
|
|
|
jp LinkTrade_PlayerPartyMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LinkTrade_OTPartyMenu:
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, OTPARTYMON
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wMonType], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, A_BUTTON | D_UP | D_DOWN
|
|
|
|
ld [wMenuJoypadFilter], a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wOTPartyCount]
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumRows], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumCols], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 9
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitY], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 6
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitX], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorX], a
|
2015-12-21 11:10:16 -08:00
|
|
|
ln a, 1, 0
|
|
|
|
ld [w2DMenuCursorOffsets], a
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, MENU_UNUSED_3
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuFlags1], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuFlags2], a
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LinkTradeOTPartymonMenuLoop:
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall LinkTradeMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, d
|
|
|
|
and a
|
2015-12-21 11:10:16 -08:00
|
|
|
jp z, LinkTradePartiesMenuMasterLoop
|
|
|
|
bit A_BUTTON_F, a
|
|
|
|
jr z, .not_a_button
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, INIT_ENEMYOT_LIST
|
2016-06-13 19:53:33 -07:00
|
|
|
ld [wInitListType], a
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar InitList
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPartyMon1Species
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall LinkMonStatsScreen
|
2015-12-21 11:10:16 -08:00
|
|
|
jp LinkTradePartiesMenuMasterLoop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.not_a_button
|
|
|
|
bit D_UP_F, a
|
|
|
|
jr z, .not_d_up
|
2015-12-15 15:59:49 -08:00
|
|
|
ld a, [wMenuCursorY]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wOTPartyCount]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp b
|
2015-12-21 11:10:16 -08:00
|
|
|
jp nz, LinkTradePartiesMenuMasterLoop
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wMonType], a
|
2015-12-17 19:31:16 -08:00
|
|
|
call HideCursor
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
push bc
|
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
add hl, bc
|
2015-12-17 10:49:26 -08:00
|
|
|
ld [hl], " "
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
pop hl
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
2015-12-21 11:10:16 -08:00
|
|
|
jr LinkTrade_PlayerPartyMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.not_d_up
|
|
|
|
bit D_DOWN_F, a
|
|
|
|
jp z, LinkTradePartiesMenuMasterLoop
|
2020-11-01 09:36:38 -08:00
|
|
|
jp LinkTradeOTPartymonMenuCheckCancel
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LinkTrade_PlayerPartyMenu:
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall InitMG_Mobile_LinkTradePalMap
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wMonType], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, A_BUTTON | D_UP | D_DOWN
|
|
|
|
ld [wMenuJoypadFilter], a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumRows], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumCols], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitY], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 6
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitX], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorX], a
|
2015-12-21 11:10:16 -08:00
|
|
|
ln a, 1, 0
|
|
|
|
ld [w2DMenuCursorOffsets], a
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, MENU_UNUSED_3
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuFlags1], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuFlags2], a
|
2015-12-11 13:59:40 -08:00
|
|
|
call WaitBGMap2
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LinkTradePartymonMenuLoop:
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall LinkTradeMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, d
|
|
|
|
and a
|
2015-12-21 11:10:16 -08:00
|
|
|
jr nz, .check_joypad
|
|
|
|
jp LinkTradePartiesMenuMasterLoop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.check_joypad
|
|
|
|
bit A_BUTTON_F, a
|
|
|
|
jr z, .not_a_button
|
2020-10-29 12:15:14 -07:00
|
|
|
jp LinkTrade_TradeStatsMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.not_a_button
|
|
|
|
bit D_DOWN_F, a
|
|
|
|
jr z, .not_d_down
|
2015-12-15 15:59:49 -08:00
|
|
|
ld a, [wMenuCursorY]
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2015-12-21 11:10:16 -08:00
|
|
|
jp nz, LinkTradePartiesMenuMasterLoop
|
|
|
|
ld a, OTPARTYMON
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wMonType], a
|
2015-12-17 19:31:16 -08:00
|
|
|
call HideCursor
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
push bc
|
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
add hl, bc
|
2015-12-21 11:10:16 -08:00
|
|
|
ld [hl], " "
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
pop hl
|
2015-12-21 11:10:16 -08:00
|
|
|
ld a, 1
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
2015-12-21 11:10:16 -08:00
|
|
|
jp LinkTrade_OTPartyMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.not_d_down
|
|
|
|
bit D_UP_F, a
|
|
|
|
jr z, LinkTradePartiesMenuMasterLoop
|
2015-12-15 15:59:49 -08:00
|
|
|
ld a, [wMenuCursorY]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp b
|
2015-12-21 11:10:16 -08:00
|
|
|
jr nz, LinkTradePartiesMenuMasterLoop
|
2015-12-17 19:31:16 -08:00
|
|
|
call HideCursor
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
push bc
|
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
add hl, bc
|
2015-12-21 11:10:16 -08:00
|
|
|
ld [hl], " "
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
pop hl
|
2020-11-01 09:36:38 -08:00
|
|
|
jp LinkTradePartymonMenuCheckCancel
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LinkTradePartiesMenuMasterLoop:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMonType]
|
2015-11-09 20:55:39 -08:00
|
|
|
and a
|
2015-12-21 11:10:16 -08:00
|
|
|
jp z, LinkTradePartymonMenuLoop ; PARTYMON
|
|
|
|
jp LinkTradeOTPartymonMenuLoop ; OTPARTYMON
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
LinkTrade_TradeStatsMenu:
|
2020-02-13 09:30:13 -08:00
|
|
|
call LoadTilemapToTempTilemap
|
2015-12-15 15:59:49 -08:00
|
|
|
ld a, [wMenuCursorY]
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
|
|
|
hlcoord 0, 15
|
2015-12-20 09:54:08 -08:00
|
|
|
ld b, 1
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 2, 16
|
2015-12-21 11:10:16 -08:00
|
|
|
ld de, .String_Stats_Trade
|
2015-11-09 20:55:39 -08:00
|
|
|
call PlaceString
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall Link_WaitBGMap
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.joy_loop
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, " "
|
2015-11-09 20:55:39 -08:00
|
|
|
ldcoord_a 11, 16
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, A_BUTTON | B_BUTTON | D_RIGHT
|
|
|
|
ld [wMenuJoypadFilter], a
|
|
|
|
ld a, 1
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumRows], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumCols], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 16
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitY], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitX], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
|
|
|
ld [wMenuCursorX], a
|
2015-12-21 11:10:16 -08:00
|
|
|
ln a, 2, 0
|
|
|
|
ld [w2DMenuCursorOffsets], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuFlags1], a
|
|
|
|
ld [w2DMenuFlags2], a
|
2015-12-15 15:59:49 -08:00
|
|
|
call ScrollingMenuJoypad
|
2015-12-20 09:54:08 -08:00
|
|
|
bit D_RIGHT_F, a
|
2015-12-21 11:10:16 -08:00
|
|
|
jr nz, .d_right
|
2015-12-20 09:54:08 -08:00
|
|
|
bit B_BUTTON_F, a
|
2015-12-21 11:10:16 -08:00
|
|
|
jr z, .show_stats
|
|
|
|
.b_button
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
2020-02-13 09:30:13 -08:00
|
|
|
call SafeLoadTempTilemapToTilemap
|
2015-12-21 11:10:16 -08:00
|
|
|
jp LinkTrade_PlayerPartyMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.d_right
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, " "
|
2015-11-09 20:55:39 -08:00
|
|
|
ldcoord_a 1, 16
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, A_BUTTON | B_BUTTON | D_LEFT
|
|
|
|
ld [wMenuJoypadFilter], a
|
|
|
|
ld a, 1
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumRows], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumCols], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 16
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitY], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 11
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitX], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
|
|
|
ld [wMenuCursorX], a
|
2015-12-21 11:10:16 -08:00
|
|
|
ln a, 2, 0
|
|
|
|
ld [w2DMenuCursorOffsets], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuFlags1], a
|
|
|
|
ld [w2DMenuFlags2], a
|
2015-12-15 15:59:49 -08:00
|
|
|
call ScrollingMenuJoypad
|
2015-12-20 09:54:08 -08:00
|
|
|
bit D_LEFT_F, a
|
2015-12-21 11:10:16 -08:00
|
|
|
jp nz, .joy_loop
|
2015-12-20 09:54:08 -08:00
|
|
|
bit B_BUTTON_F, a
|
2015-12-21 11:10:16 -08:00
|
|
|
jr nz, .b_button
|
|
|
|
jr .try_trade
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.show_stats
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, INIT_PLAYEROT_LIST
|
2016-06-13 19:53:33 -07:00
|
|
|
ld [wInitListType], a
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar InitList
|
|
|
|
farcall LinkMonStatsScreen
|
2020-02-13 09:30:13 -08:00
|
|
|
call SafeLoadTempTilemapToTilemap
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 6, 1
|
|
|
|
lb bc, 6, 1
|
|
|
|
ld a, " "
|
2015-12-21 11:10:16 -08:00
|
|
|
call LinkEngine_FillBox
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 17, 1
|
|
|
|
lb bc, 6, 1
|
|
|
|
ld a, " "
|
2015-12-21 11:10:16 -08:00
|
|
|
call LinkEngine_FillBox
|
|
|
|
jp LinkTrade_PlayerPartyMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.try_trade
|
2015-12-17 19:31:16 -08:00
|
|
|
call PlaceHollowCursor
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2020-10-29 11:45:40 -07:00
|
|
|
ld [wCurTradePartyMon], a
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2024-02-10 15:16:00 -08:00
|
|
|
farcall PlaceWaitingTextAndSyncAndExchangeNybble
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, [wOtherPlayerLinkMode]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp $f
|
2015-12-21 11:10:16 -08:00
|
|
|
jp z, InitTradeMenuDisplay
|
2020-10-29 11:45:40 -07:00
|
|
|
ld [wCurOTTradePartyMon], a
|
2020-10-29 12:15:14 -07:00
|
|
|
call LinkTradePlaceArrow
|
2015-12-21 11:10:16 -08:00
|
|
|
ld c, 100
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall ValidateOTTrademon
|
2015-12-21 11:10:16 -08:00
|
|
|
jr c, .abnormal
|
2020-10-04 16:43:28 -07:00
|
|
|
farcall CheckAnyOtherAliveMonsForTrade
|
2015-12-21 11:10:16 -08:00
|
|
|
jp nc, LinkTrade
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2020-12-08 18:24:48 -08:00
|
|
|
ld [wUnusedLinkAction], a
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wOtherPlayerLinkAction], a
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 0, 12
|
2015-12-20 09:54:08 -08:00
|
|
|
ld b, 4
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall Link_WaitBGMap
|
2019-10-20 15:24:17 -07:00
|
|
|
ld hl, .LinkTradeCantBattleText
|
2015-11-09 20:55:39 -08:00
|
|
|
bccoord 1, 14
|
2024-02-10 15:16:00 -08:00
|
|
|
call PrintTextboxTextAt
|
2015-12-21 11:10:16 -08:00
|
|
|
jr .cancel_trade
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.abnormal
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2020-12-08 18:24:48 -08:00
|
|
|
ld [wUnusedLinkAction], a
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wOtherPlayerLinkAction], a
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurOTTradePartyMon]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPartySpecies
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, a
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wNamedObjectIndex], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPokemonName
|
|
|
|
hlcoord 0, 12
|
2015-12-21 11:10:16 -08:00
|
|
|
ld b, 4
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall Link_WaitBGMap
|
2019-10-20 15:24:17 -07:00
|
|
|
ld hl, .LinkAbnormalMonText
|
2015-11-09 20:55:39 -08:00
|
|
|
bccoord 1, 14
|
2024-02-10 15:16:00 -08:00
|
|
|
call PrintTextboxTextAt
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-21 11:10:16 -08:00
|
|
|
.cancel_trade
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 0, 12
|
2015-12-20 09:54:08 -08:00
|
|
|
ld b, 4
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 1, 14
|
2015-12-21 11:10:16 -08:00
|
|
|
ld de, String_TooBadTheTradeWasCanceled
|
2015-11-09 20:55:39 -08:00
|
|
|
call PlaceString
|
|
|
|
ld a, $1
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2024-02-10 15:16:00 -08:00
|
|
|
farcall PlaceWaitingTextAndSyncAndExchangeNybble
|
2015-12-20 09:54:08 -08:00
|
|
|
ld c, 100
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
2015-12-21 11:10:16 -08:00
|
|
|
jp InitTradeMenuDisplay
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2019-10-20 15:24:17 -07:00
|
|
|
.LinkTradeCantBattleText:
|
|
|
|
text_far _LinkTradeCantBattleText
|
2018-11-17 10:33:03 -08:00
|
|
|
text_end
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.String_Stats_Trade:
|
2015-11-09 20:55:39 -08:00
|
|
|
db "STATS TRADE@"
|
|
|
|
|
2019-10-20 15:24:17 -07:00
|
|
|
.LinkAbnormalMonText:
|
|
|
|
text_far _LinkAbnormalMonText
|
2018-11-17 10:33:03 -08:00
|
|
|
text_end
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-11-01 09:36:38 -08:00
|
|
|
LinkTradeOTPartymonMenuCheckCancel:
|
2015-12-15 15:59:49 -08:00
|
|
|
ld a, [wMenuCursorY]
|
2015-12-21 11:10:16 -08:00
|
|
|
cp 1
|
|
|
|
jp nz, LinkTradePartiesMenuMasterLoop
|
2015-12-17 19:31:16 -08:00
|
|
|
call HideCursor
|
2020-11-01 09:36:38 -08:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
push hl
|
|
|
|
push bc
|
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
add hl, bc
|
2015-12-20 09:54:08 -08:00
|
|
|
ld [hl], " "
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
pop hl
|
2020-11-01 09:36:38 -08:00
|
|
|
; fallthrough
|
|
|
|
|
|
|
|
LinkTradePartymonMenuCheckCancel:
|
2015-12-20 09:54:08 -08:00
|
|
|
.loop1
|
|
|
|
ld a, "▶"
|
2015-11-09 20:55:39 -08:00
|
|
|
ldcoord_a 9, 17
|
2015-12-20 09:54:08 -08:00
|
|
|
.loop2
|
2015-11-09 20:55:39 -08:00
|
|
|
call JoyTextDelay
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hJoyLast]
|
2015-11-09 20:55:39 -08:00
|
|
|
and a
|
2015-12-20 09:54:08 -08:00
|
|
|
jr z, .loop2
|
|
|
|
bit A_BUTTON_F, a
|
|
|
|
jr nz, .a_button
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
|
|
|
ld a, " "
|
|
|
|
ldcoord_a 9, 17
|
|
|
|
pop af
|
2015-12-20 09:54:08 -08:00
|
|
|
bit D_UP_F, a
|
|
|
|
jr z, .d_up
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wOTPartyCount]
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
2015-12-21 11:10:16 -08:00
|
|
|
jp LinkTrade_OTPartyMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
.d_up
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $1
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
2015-12-21 11:10:16 -08:00
|
|
|
jp LinkTrade_PlayerPartyMenu
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-12-20 09:54:08 -08:00
|
|
|
.a_button
|
|
|
|
ld a, "▷"
|
2015-11-09 20:55:39 -08:00
|
|
|
ldcoord_a 9, 17
|
|
|
|
ld a, $f
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2024-02-10 15:16:00 -08:00
|
|
|
farcall PlaceWaitingTextAndSyncAndExchangeNybble
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, [wOtherPlayerLinkMode]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp $f
|
2015-12-20 09:54:08 -08:00
|
|
|
jr nz, .loop1
|
2020-11-01 09:36:38 -08:00
|
|
|
; fallthrough
|
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
ExitLinkCommunications:
|
2015-11-20 08:47:52 -08:00
|
|
|
call RotateThreePalettesRight
|
2015-11-09 20:55:39 -08:00
|
|
|
call ClearScreen
|
2023-07-26 08:01:20 -07:00
|
|
|
ld b, CGB_DIPLOMA
|
|
|
|
call GetCGBLayout
|
2015-12-11 13:59:40 -08:00
|
|
|
call WaitBGMap2
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSB], a
|
|
|
|
ldh [hSerialSend], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook ExitLinkCommunications_ret
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
GSPlaceTradeScreenFooter: ; unreferenced
|
|
|
|
; Fill the screen footer with pattern tile
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 0, 16
|
2020-10-29 12:15:14 -07:00
|
|
|
ld a, $7e
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, 2 * SCREEN_WIDTH
|
|
|
|
call ByteFill
|
2020-10-29 12:15:14 -07:00
|
|
|
; Clear out area for cancel string
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 1, 16
|
|
|
|
ld a, " "
|
|
|
|
ld bc, SCREEN_WIDTH - 2
|
|
|
|
call ByteFill
|
2020-10-29 12:15:14 -07:00
|
|
|
; Place the string
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 2, 16
|
2020-05-29 04:16:49 -07:00
|
|
|
ld de, .CancelString
|
2015-11-09 20:55:39 -08:00
|
|
|
jp PlaceString
|
|
|
|
|
2020-05-29 04:16:49 -07:00
|
|
|
.CancelString:
|
2015-11-09 20:55:39 -08:00
|
|
|
db "CANCEL@"
|
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
LinkTradePlaceArrow:
|
|
|
|
; Indicates which pokemon the other player has selected to trade
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, [wOtherPlayerLinkMode]
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 6, 9
|
|
|
|
ld bc, SCREEN_WIDTH
|
|
|
|
call AddNTimes
|
2015-12-21 11:10:16 -08:00
|
|
|
ld [hl], "▷"
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LinkEngine_FillBox:
|
2015-12-21 11:10:16 -08:00
|
|
|
.row
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
|
|
|
push hl
|
2015-12-21 11:10:16 -08:00
|
|
|
.col
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
|
|
|
dec c
|
2015-12-21 11:10:16 -08:00
|
|
|
jr nz, .col
|
2015-11-09 20:55:39 -08:00
|
|
|
pop hl
|
|
|
|
ld bc, SCREEN_WIDTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
dec b
|
2015-12-21 11:10:16 -08:00
|
|
|
jr nz, .row
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LinkTrade:
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2020-12-08 18:24:48 -08:00
|
|
|
ld [wUnusedLinkAction], a
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wOtherPlayerLinkAction], a
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 0, 12
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 4
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall Link_WaitBGMap
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurTradePartyMon]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartySpecies
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, a
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wNamedObjectIndex], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPokemonName
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wStringBuffer1
|
2021-03-17 13:16:02 -07:00
|
|
|
ld de, wBufferTrademonNickname
|
2018-01-20 09:25:55 -08:00
|
|
|
ld bc, MON_NAME_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurOTTradePartyMon]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPartySpecies
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, a
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wNamedObjectIndex], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPokemonName
|
2019-10-20 15:24:17 -07:00
|
|
|
ld hl, LinkAskTradeForText
|
2015-11-09 20:55:39 -08:00
|
|
|
bccoord 1, 14
|
2024-02-10 15:16:00 -08:00
|
|
|
call PrintTextboxTextAt
|
2018-01-23 13:08:43 -08:00
|
|
|
call LoadStandardMenuHeader
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 10, 7
|
2015-12-20 09:54:08 -08:00
|
|
|
ld b, 3
|
|
|
|
ld c, 7
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2020-10-29 12:15:14 -07:00
|
|
|
ld de, String_TradeCancel
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 12, 8
|
|
|
|
call PlaceString
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 8
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitY], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 11
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuCursorInitX], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 1
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumCols], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, 2
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuNumRows], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2015-12-19 11:48:30 -08:00
|
|
|
ld [w2DMenuFlags1], a
|
|
|
|
ld [w2DMenuFlags2], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $20
|
2015-12-21 11:10:16 -08:00
|
|
|
ld [w2DMenuCursorOffsets], a
|
2015-12-20 09:54:08 -08:00
|
|
|
ld a, A_BUTTON | B_BUTTON
|
|
|
|
ld [wMenuJoypadFilter], a
|
|
|
|
ld a, 1
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [wMenuCursorY], a
|
|
|
|
ld [wMenuCursorX], a
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall Link_WaitBGMap
|
2015-12-15 15:59:49 -08:00
|
|
|
call ScrollingMenuJoypad
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
|
|
|
call Call_ExitMenu
|
2015-12-11 13:59:40 -08:00
|
|
|
call WaitBGMap2
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
|
|
|
bit 1, a
|
2020-10-29 12:15:14 -07:00
|
|
|
jr nz, .canceled
|
2015-12-15 15:59:49 -08:00
|
|
|
ld a, [wMenuCursorY]
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2020-10-29 12:15:14 -07:00
|
|
|
jr z, .try_trade
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
.canceled
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $1
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 0, 12
|
|
|
|
ld b, 4
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 1, 14
|
2015-12-21 11:10:16 -08:00
|
|
|
ld de, String_TooBadTheTradeWasCanceled
|
2015-11-09 20:55:39 -08:00
|
|
|
call PlaceString
|
2024-02-10 15:16:00 -08:00
|
|
|
farcall PlaceWaitingTextAndSyncAndExchangeNybble
|
2020-10-29 12:15:14 -07:00
|
|
|
jp InitTradeMenuDisplay_Delay
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
.try_trade
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $2
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2024-02-10 15:16:00 -08:00
|
|
|
farcall PlaceWaitingTextAndSyncAndExchangeNybble
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, [wOtherPlayerLinkMode]
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2020-10-29 12:15:14 -07:00
|
|
|
jr nz, .do_trade
|
|
|
|
; If we're here, the other player canceled the trade
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 0, 12
|
|
|
|
ld b, 4
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 1, 14
|
2015-12-21 11:10:16 -08:00
|
|
|
ld de, String_TooBadTheTradeWasCanceled
|
2015-11-09 20:55:39 -08:00
|
|
|
call PlaceString
|
2020-10-29 12:15:14 -07:00
|
|
|
jp InitTradeMenuDisplay_Delay
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
.do_trade
|
2015-11-17 14:56:49 -08:00
|
|
|
ld hl, sPartyMail
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurTradePartyMon]
|
2015-11-17 14:56:49 -08:00
|
|
|
ld bc, MAIL_STRUCT_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call AddNTimes
|
2015-11-17 14:56:49 -08:00
|
|
|
ld a, BANK(sPartyMail)
|
2020-06-17 14:03:38 -07:00
|
|
|
call OpenSRAM
|
2015-11-09 20:55:39 -08:00
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2015-11-17 14:56:49 -08:00
|
|
|
ld bc, MAIL_STRUCT_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurTradePartyMon]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, a
|
2020-10-29 12:15:14 -07:00
|
|
|
.copy_mail
|
2015-11-09 20:55:39 -08:00
|
|
|
inc c
|
|
|
|
ld a, c
|
2018-01-19 11:49:43 -08:00
|
|
|
cp PARTY_LENGTH
|
2020-10-29 12:15:14 -07:00
|
|
|
jr z, .copy_player_data
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
2015-11-17 14:56:49 -08:00
|
|
|
ld bc, MAIL_STRUCT_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
|
|
|
pop bc
|
2020-10-29 12:15:14 -07:00
|
|
|
jr .copy_mail
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
.copy_player_data
|
2015-11-17 14:56:49 -08:00
|
|
|
ld hl, sPartyMail
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2015-11-17 14:56:49 -08:00
|
|
|
ld bc, MAIL_STRUCT_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call AddNTimes
|
|
|
|
push hl
|
2020-12-08 18:24:48 -08:00
|
|
|
ld hl, wLinkPlayerMail
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurOTTradePartyMon]
|
2015-11-17 14:56:49 -08:00
|
|
|
ld bc, MAIL_STRUCT_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call AddNTimes
|
|
|
|
pop de
|
2015-11-17 14:56:49 -08:00
|
|
|
ld bc, MAIL_STRUCT_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
call CopyBytes
|
|
|
|
call CloseSRAM
|
2020-10-29 12:15:14 -07:00
|
|
|
|
|
|
|
; Buffer player data
|
|
|
|
; nickname
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPlayerName
|
2015-11-22 21:21:21 -08:00
|
|
|
ld de, wPlayerTrademonSenderName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
2020-10-29 12:15:14 -07:00
|
|
|
; species
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurTradePartyMon]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartySpecies
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wPlayerTrademonSpecies], a
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
2020-10-29 12:15:14 -07:00
|
|
|
; OT name
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurTradePartyMon]
|
2021-03-17 13:16:02 -07:00
|
|
|
ld hl, wPartyMonOTs
|
2015-11-09 20:55:39 -08:00
|
|
|
call SkipNames
|
2015-11-22 21:21:21 -08:00
|
|
|
ld de, wPlayerTrademonOTName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
2020-10-29 12:15:14 -07:00
|
|
|
; ID
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1ID
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurTradePartyMon]
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPartyLocation
|
|
|
|
ld a, [hli]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wPlayerTrademonID], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hl]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wPlayerTrademonID + 1], a
|
2020-10-29 12:15:14 -07:00
|
|
|
; DVs
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1DVs
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurTradePartyMon]
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPartyLocation
|
|
|
|
ld a, [hli]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wPlayerTrademonDVs], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hl]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wPlayerTrademonDVs + 1], a
|
2020-10-29 12:15:14 -07:00
|
|
|
; caught data
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurTradePartyMon]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1Species
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPartyLocation
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall GetCaughtGender
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, c
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wPlayerTrademonCaughtData], a
|
2020-10-29 12:15:14 -07:00
|
|
|
|
|
|
|
; Buffer other player data
|
|
|
|
; nickname
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPlayerName
|
2015-11-22 21:21:21 -08:00
|
|
|
ld de, wOTTrademonSenderName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
2020-10-29 12:15:14 -07:00
|
|
|
; species
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurOTTradePartyMon]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPartySpecies
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wOTTrademonSpecies], a
|
2020-10-29 12:15:14 -07:00
|
|
|
; OT name
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurOTTradePartyMon]
|
2021-03-17 13:16:02 -07:00
|
|
|
ld hl, wOTPartyMonOTs
|
2015-11-09 20:55:39 -08:00
|
|
|
call SkipNames
|
2015-11-22 21:21:21 -08:00
|
|
|
ld de, wOTTrademonOTName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, NAME_LENGTH
|
|
|
|
call CopyBytes
|
2020-10-29 12:15:14 -07:00
|
|
|
; ID
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPartyMon1ID
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurOTTradePartyMon]
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPartyLocation
|
|
|
|
ld a, [hli]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wOTTrademonID], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hl]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wOTTrademonID + 1], a
|
2020-10-29 12:15:14 -07:00
|
|
|
; DVs
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPartyMon1DVs
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurOTTradePartyMon]
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPartyLocation
|
|
|
|
ld a, [hli]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wOTTrademonDVs], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hl]
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wOTTrademonDVs + 1], a
|
2020-10-29 12:15:14 -07:00
|
|
|
; caught data
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurOTTradePartyMon]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPartyMon1Species
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPartyLocation
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall GetCaughtGender
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, c
|
2015-11-22 21:21:21 -08:00
|
|
|
ld [wOTTrademonCaughtData], a
|
2020-10-29 12:15:14 -07:00
|
|
|
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurTradePartyMon]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurPartyMon], a
|
|
|
|
ld hl, wPartySpecies
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2020-10-29 11:45:40 -07:00
|
|
|
ld [wCurTradePartyMon], a
|
2020-10-29 12:15:14 -07:00
|
|
|
|
2018-02-22 12:35:11 -08:00
|
|
|
xor a ; REMOVE_PARTY
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [wPokemonWithdrawDepositParameter], a
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar RemoveMonFromPartyOrBox
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurPartyMon], a
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, TRUE
|
2015-11-28 12:13:40 -08:00
|
|
|
ld [wForceEvolution], a
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, [wCurOTTradePartyMon]
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wOTPartySpecies
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, a
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2020-10-29 11:45:40 -07:00
|
|
|
ld [wCurOTTradePartyMon], a
|
2020-10-29 12:15:14 -07:00
|
|
|
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, 100
|
|
|
|
call DelayFrames
|
2020-02-13 09:30:13 -08:00
|
|
|
call ClearTilemap
|
2015-11-09 20:55:39 -08:00
|
|
|
call LoadFontsBattleExtra
|
2023-07-26 08:01:20 -07:00
|
|
|
ld b, CGB_DIPLOMA
|
|
|
|
call GetCGBLayout
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSerialConnectionStatus]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp USING_EXTERNAL_CLOCK
|
2015-11-22 21:21:21 -08:00
|
|
|
jr z, .player_2
|
2018-01-16 11:30:10 -08:00
|
|
|
predef TradeAnimation
|
2015-11-22 21:21:21 -08:00
|
|
|
jr .done_animation
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-11-22 21:21:21 -08:00
|
|
|
.player_2
|
2018-01-16 11:30:10 -08:00
|
|
|
predef TradeAnimationPlayer2
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-11-22 21:21:21 -08:00
|
|
|
.done_animation
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
|
|
|
ld c, a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurPartyMon], a
|
|
|
|
ld hl, wOTPartySpecies
|
2018-01-19 11:49:43 -08:00
|
|
|
ld d, 0
|
2015-11-09 20:55:39 -08:00
|
|
|
ld e, a
|
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurPartySpecies], a
|
|
|
|
ld hl, wOTPartyMon1Species
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, c
|
|
|
|
call GetPartyLocation
|
2018-01-23 14:39:09 -08:00
|
|
|
ld de, wTempMonSpecies
|
2015-11-09 20:55:39 -08:00
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
|
|
|
call CopyBytes
|
2018-01-16 11:30:10 -08:00
|
|
|
predef AddTempmonToParty
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurPartyMon], a
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar EvolvePokemon
|
2015-11-09 20:55:39 -08:00
|
|
|
call ClearScreen
|
2020-10-23 10:36:54 -07:00
|
|
|
call LoadTradeScreenBorderGFX
|
2016-05-15 18:50:31 -07:00
|
|
|
call SetTradeRoomBGPals
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall Link_WaitBGMap
|
2020-08-19 04:32:11 -07:00
|
|
|
|
|
|
|
; Check if either of the Pokémon sent was a Mew or Celebi, and send a different
|
|
|
|
; byte depending on that. Presumably this would've been some prevention against
|
|
|
|
; illicit trade machines, but it doesn't seem like a very effective one.
|
|
|
|
; Removing this code breaks link compatibility with the vanilla gen2 games, but
|
|
|
|
; has otherwise no consequence.
|
|
|
|
ld b, 1
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
|
|
|
ld c, a
|
|
|
|
cp MEW
|
2020-08-19 04:32:11 -07:00
|
|
|
jr z, .send_checkbyte
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wCurPartySpecies]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp MEW
|
2020-08-19 04:32:11 -07:00
|
|
|
jr z, .send_checkbyte
|
|
|
|
ld b, 2
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, c
|
|
|
|
cp CELEBI
|
2020-08-19 04:32:11 -07:00
|
|
|
jr z, .send_checkbyte
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wCurPartySpecies]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp CELEBI
|
2020-08-19 04:32:11 -07:00
|
|
|
jr z, .send_checkbyte
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-08-19 04:32:11 -07:00
|
|
|
; Send the byte in a loop until the desired byte has been received.
|
|
|
|
ld b, 0
|
|
|
|
.send_checkbyte
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, b
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2015-11-09 20:55:39 -08:00
|
|
|
push bc
|
2024-02-10 15:16:00 -08:00
|
|
|
call Serial_PlaceWaitingTextAndSyncAndExchangeNybble
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_TIMECAPSULE
|
2016-05-11 18:19:52 -07:00
|
|
|
jr z, .save
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, b
|
|
|
|
and a
|
2016-05-11 18:19:52 -07:00
|
|
|
jr z, .save
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, [wOtherPlayerLinkAction]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp b
|
2020-08-19 04:32:11 -07:00
|
|
|
jr nz, .send_checkbyte
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2016-05-11 18:19:52 -07:00
|
|
|
.save
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall SaveAfterLinkTrade
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, 40
|
|
|
|
call DelayFrames
|
|
|
|
hlcoord 0, 12
|
|
|
|
ld b, 4
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 1, 14
|
2020-10-29 12:15:14 -07:00
|
|
|
ld de, String_TradeCompleted
|
2015-11-09 20:55:39 -08:00
|
|
|
call PlaceString
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall Link_WaitBGMap
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Trade_save_game_end
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, 50
|
|
|
|
call DelayFrames
|
|
|
|
ld a, [wLinkMode]
|
|
|
|
cp LINK_TIMECAPSULE
|
2018-01-24 08:12:02 -08:00
|
|
|
jp z, Gen2ToGen1LinkComms
|
2015-12-20 09:54:08 -08:00
|
|
|
jp Gen2ToGen2LinkComms
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
InitTradeMenuDisplay_Delay:
|
2015-11-09 20:55:39 -08:00
|
|
|
ld c, 100
|
|
|
|
call DelayFrames
|
2015-12-21 11:10:16 -08:00
|
|
|
jp InitTradeMenuDisplay
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
String_TradeCancel:
|
2015-11-09 20:55:39 -08:00
|
|
|
db "TRADE"
|
|
|
|
next "CANCEL@"
|
|
|
|
|
2019-10-20 15:24:17 -07:00
|
|
|
LinkAskTradeForText:
|
|
|
|
text_far _LinkAskTradeForText
|
2018-11-17 10:33:03 -08:00
|
|
|
text_end
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-29 12:15:14 -07:00
|
|
|
String_TradeCompleted:
|
2015-11-09 20:55:39 -08:00
|
|
|
db "Trade completed!@"
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
String_TooBadTheTradeWasCanceled:
|
2015-11-09 20:55:39 -08:00
|
|
|
db "Too bad! The trade"
|
|
|
|
next "was canceled!@"
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LinkTextboxAtHL:
|
2015-11-09 20:55:39 -08:00
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall LinkTextbox
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2020-10-23 10:36:54 -07:00
|
|
|
LoadTradeScreenBorderGFX:
|
|
|
|
farcall _LoadTradeScreenBorderGFX
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
SetTradeRoomBGPals:
|
2018-07-22 21:13:43 -07:00
|
|
|
farcall LoadTradeRoomBGPals ; just a nested farcall; so wasteful
|
2024-02-10 15:16:00 -08:00
|
|
|
call SetDefaultBGPAndOBP
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2020-10-23 10:36:54 -07:00
|
|
|
PlaceTradeScreenTextbox: ; unreferenced
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 0, 0
|
|
|
|
ld b, 6
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2015-11-09 20:55:39 -08:00
|
|
|
hlcoord 0, 8
|
|
|
|
ld b, 6
|
|
|
|
ld c, 18
|
2018-01-16 11:30:10 -08:00
|
|
|
call LinkTextboxAtHL
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall PlaceTradePartnerNamesAndParty
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-03-25 07:18:33 -07:00
|
|
|
INCLUDE "engine/movie/trade_animation.asm"
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckTimeCapsuleCompatibility:
|
2018-02-03 15:21:53 -08:00
|
|
|
; Checks to see if your party is compatible with the Gen 1 games.
|
2023-09-30 10:12:57 -07:00
|
|
|
; Returns the following in hScriptVar:
|
2015-11-09 20:55:39 -08:00
|
|
|
; 0: Party is okay
|
2018-02-03 15:21:53 -08:00
|
|
|
; 1: At least one Pokémon was introduced in Gen 2
|
|
|
|
; 2: At least one Pokémon has a move that was introduced in Gen 2
|
|
|
|
; 3: At least one Pokémon is holding mail
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-02-03 15:21:53 -08:00
|
|
|
; If any party Pokémon was introduced in the Gen 2 games, don't let it in.
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartySpecies
|
2018-01-10 14:30:27 -08:00
|
|
|
ld b, PARTY_LENGTH
|
2015-11-09 20:55:39 -08:00
|
|
|
.loop
|
|
|
|
ld a, [hli]
|
2015-12-21 11:10:16 -08:00
|
|
|
cp -1
|
2015-11-09 20:55:39 -08:00
|
|
|
jr z, .checkitem
|
2018-01-14 17:58:49 -08:00
|
|
|
cp JOHTO_POKEMON
|
2015-11-09 20:55:39 -08:00
|
|
|
jr nc, .mon_too_new
|
|
|
|
dec b
|
|
|
|
jr nz, .loop
|
|
|
|
|
2018-02-03 15:21:53 -08:00
|
|
|
; If any party Pokémon is holding mail, don't let it in.
|
2015-11-09 20:55:39 -08:00
|
|
|
.checkitem
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1Item
|
2015-11-09 20:55:39 -08:00
|
|
|
.itemloop
|
|
|
|
push hl
|
|
|
|
push bc
|
|
|
|
ld d, [hl]
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall ItemIsMail
|
2015-11-09 20:55:39 -08:00
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
jr c, .mon_has_mail
|
|
|
|
ld de, PARTYMON_STRUCT_LENGTH
|
|
|
|
add hl, de
|
|
|
|
dec b
|
|
|
|
jr nz, .itemloop
|
|
|
|
|
2018-02-03 15:21:53 -08:00
|
|
|
; If any party Pokémon has a move that was introduced in the Gen 2 games, don't let it in.
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1Moves
|
|
|
|
ld a, [wPartyCount]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, a
|
|
|
|
.move_loop
|
|
|
|
ld c, NUM_MOVES
|
|
|
|
.move_next
|
|
|
|
ld a, [hli]
|
|
|
|
cp STRUGGLE + 1
|
|
|
|
jr nc, .move_too_new
|
|
|
|
dec c
|
|
|
|
jr nz, .move_next
|
2018-07-16 12:58:07 -07:00
|
|
|
ld de, PARTYMON_STRUCT_LENGTH - NUM_MOVES
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, de
|
|
|
|
dec b
|
|
|
|
jr nz, .move_loop
|
|
|
|
xor a
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.mon_too_new
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wNamedObjectIndex], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPokemonName
|
|
|
|
ld a, $1
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.move_too_new
|
|
|
|
push bc
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wNamedObjectIndex], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetMoveName
|
|
|
|
call CopyName1
|
|
|
|
pop bc
|
2020-10-23 10:36:54 -07:00
|
|
|
call GetIncompatibleMonName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $2
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.mon_has_mail
|
2020-10-23 10:36:54 -07:00
|
|
|
call GetIncompatibleMonName
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $3
|
|
|
|
|
|
|
|
.done
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2020-10-23 10:36:54 -07:00
|
|
|
GetIncompatibleMonName:
|
|
|
|
; Calulate which pokemon is incompatible, and get that pokemon's name
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2015-11-09 20:55:39 -08:00
|
|
|
sub b
|
|
|
|
ld c, a
|
|
|
|
inc c
|
2018-01-19 11:49:43 -08:00
|
|
|
ld b, 0
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyCount
|
2015-11-09 20:55:39 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wNamedObjectIndex], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call GetPokemonName
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
EnterTimeCapsule:
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_patch Wireless_net_delay_6
|
2022-03-12 15:34:04 -08:00
|
|
|
if DEF(_CRYSTAL11_VC)
|
|
|
|
ld c, 26
|
|
|
|
else
|
2015-11-23 13:04:53 -08:00
|
|
|
ld c, 10
|
2022-03-12 15:34:04 -08:00
|
|
|
endc
|
|
|
|
vc_patch_end
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
ld a, $4
|
2016-05-15 18:50:31 -07:00
|
|
|
call Link_EnsureSync
|
2015-11-23 13:04:53 -08:00
|
|
|
ld c, 40
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2019-11-08 13:03:08 -08:00
|
|
|
inc a ; LINK_TIMECAPSULE
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [wLinkMode], a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
WaitForOtherPlayerToExit:
|
2015-12-22 15:03:00 -08:00
|
|
|
ld c, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
2018-01-19 16:31:45 -08:00
|
|
|
ld a, CONNECTION_NOT_ESTABLISHED
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialConnectionStatus], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSB], a
|
|
|
|
ldh [hSerialReceive], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2015-12-22 15:03:00 -08:00
|
|
|
ld c, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSB], a
|
|
|
|
ldh [hSerialReceive], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (0 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (0 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2018-01-19 11:49:43 -08:00
|
|
|
ld c, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSB], a
|
|
|
|
ldh [hSerialReceive], a
|
|
|
|
ldh [rSC], a
|
2015-12-22 15:03:00 -08:00
|
|
|
ld c, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
2018-01-19 16:31:45 -08:00
|
|
|
ld a, CONNECTION_NOT_ESTABLISHED
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialConnectionStatus], a
|
|
|
|
ldh a, [rIF]
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, IE_DEFAULT
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIE], a
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rIF], a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld hl, wLinkTimeoutFrames
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
|
|
|
ld [hli], a
|
|
|
|
ld [hl], a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [wLinkMode], a
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Wireless_term_exit
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
SetBitsForLinkTradeRequest:
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, LINK_TRADECENTER - 1
|
|
|
|
ld [wPlayerLinkAction], a
|
2018-07-28 16:27:34 -07:00
|
|
|
ld [wChosenCableClubRoom], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
SetBitsForBattleRequest:
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, LINK_COLOSSEUM - 1
|
|
|
|
ld [wPlayerLinkAction], a
|
2018-07-28 16:27:34 -07:00
|
|
|
ld [wChosenCableClubRoom], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
SetBitsForTimeCapsuleRequest:
|
2020-10-21 21:53:54 -07:00
|
|
|
ld a, USING_INTERNAL_CLOCK
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSB], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialReceive], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (0 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (0 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2015-11-23 13:04:53 -08:00
|
|
|
xor a ; LINK_TIMECAPSULE - 1
|
|
|
|
ld [wPlayerLinkAction], a
|
2018-07-28 16:27:34 -07:00
|
|
|
ld [wChosenCableClubRoom], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
WaitForLinkedFriend:
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, [wPlayerLinkAction]
|
2015-11-09 20:55:39 -08:00
|
|
|
and a
|
2016-05-15 18:50:31 -07:00
|
|
|
jr z, .no_link_action
|
2020-10-21 21:53:54 -07:00
|
|
|
ld a, USING_INTERNAL_CLOCK
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSB], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialReceive], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (0 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (0 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
|
|
|
call DelayFrame
|
|
|
|
call DelayFrame
|
|
|
|
|
2016-05-15 18:50:31 -07:00
|
|
|
.no_link_action
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $2
|
2016-05-15 18:50:31 -07:00
|
|
|
ld [wLinkTimeoutFrames + 1], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $ff
|
2016-05-15 18:50:31 -07:00
|
|
|
ld [wLinkTimeoutFrames], a
|
|
|
|
.loop
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSerialConnectionStatus]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp USING_INTERNAL_CLOCK
|
2016-05-15 18:50:31 -07:00
|
|
|
jr z, .connected
|
2018-01-19 11:49:43 -08:00
|
|
|
cp USING_EXTERNAL_CLOCK
|
2016-05-15 18:50:31 -07:00
|
|
|
jr z, .connected
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, CONNECTION_NOT_ESTABLISHED
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialConnectionStatus], a
|
2020-10-21 21:53:54 -07:00
|
|
|
ld a, USING_INTERNAL_CLOCK
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSB], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialReceive], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (0 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (0 << rSC_CLOCK)
|
2022-04-16 17:42:06 -07:00
|
|
|
; This vc_hook causes the Virtual Console to set [hSerialConnectionStatus] to
|
|
|
|
; USING_INTERNAL_CLOCK, which allows the player to proceed past the link
|
|
|
|
; receptionist's "Please wait." It assumes that hSerialConnectionStatus is at
|
|
|
|
; its original address.
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Link_fake_connection_status
|
2022-04-16 17:42:06 -07:00
|
|
|
vc_assert hSerialConnectionStatus == $ffcb, \
|
|
|
|
"hSerialConnectionStatus is no longer located at 00:ffcb."
|
|
|
|
vc_assert USING_INTERNAL_CLOCK == $02, \
|
|
|
|
"USING_INTERNAL_CLOCK is no longer equal to $02."
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld a, [wLinkTimeoutFrames]
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld [wLinkTimeoutFrames], a
|
|
|
|
jr nz, .not_done
|
|
|
|
ld a, [wLinkTimeoutFrames + 1]
|
2015-11-09 20:55:39 -08:00
|
|
|
dec a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld [wLinkTimeoutFrames + 1], a
|
|
|
|
jr z, .done
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2016-05-15 18:50:31 -07:00
|
|
|
.not_done
|
2020-10-21 21:53:54 -07:00
|
|
|
ld a, USING_EXTERNAL_CLOCK
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSB], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2019-05-05 09:14:46 -07:00
|
|
|
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSC], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
2016-05-15 18:50:31 -07:00
|
|
|
jr .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2016-05-15 18:50:31 -07:00
|
|
|
.connected
|
2015-12-01 18:54:11 -08:00
|
|
|
call LinkDataReceived
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
2015-12-01 18:54:11 -08:00
|
|
|
call LinkDataReceived
|
2016-05-15 18:50:31 -07:00
|
|
|
ld c, 50
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
ld a, $1
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2016-05-15 18:50:31 -07:00
|
|
|
.done
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2020-10-23 10:36:54 -07:00
|
|
|
CheckLinkTimeout_Receptionist:
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $1
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld hl, wLinkTimeoutFrames
|
2020-10-29 11:45:40 -07:00
|
|
|
ld a, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
|
|
|
xor a
|
|
|
|
ld [hl], a
|
|
|
|
call WaitBGMap
|
|
|
|
ld a, $2
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
|
|
|
call DelayFrame
|
2016-05-15 18:50:31 -07:00
|
|
|
call Link_CheckCommunicationError
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh a, [hScriptVar]
|
2015-11-09 20:55:39 -08:00
|
|
|
and a
|
|
|
|
ret nz
|
2016-05-15 18:50:31 -07:00
|
|
|
jp Link_ResetSerialRegistersAfterLinkClosure
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-23 10:36:54 -07:00
|
|
|
CheckLinkTimeout_Gen2:
|
2023-09-30 10:12:57 -07:00
|
|
|
; if hScriptVar = 0 on exit, link connection is closed
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $5
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld hl, wLinkTimeoutFrames
|
2020-10-23 10:36:54 -07:00
|
|
|
ld a, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
|
|
|
xor a
|
|
|
|
ld [hl], a
|
|
|
|
call WaitBGMap
|
|
|
|
ld a, $2
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
|
|
|
call DelayFrame
|
2016-05-15 18:50:31 -07:00
|
|
|
call Link_CheckCommunicationError
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh a, [hScriptVar]
|
2015-11-09 20:55:39 -08:00
|
|
|
and a
|
2020-10-23 10:36:54 -07:00
|
|
|
jr z, .exit
|
|
|
|
|
|
|
|
; Wait for ~$70000 cycles to give the other GB time to be ready
|
|
|
|
ld bc, $ffff
|
2015-12-22 15:03:00 -08:00
|
|
|
.wait
|
2015-11-09 20:55:39 -08:00
|
|
|
dec bc
|
|
|
|
ld a, b
|
|
|
|
or c
|
2015-12-22 15:03:00 -08:00
|
|
|
jr nz, .wait
|
2020-10-23 10:36:54 -07:00
|
|
|
|
|
|
|
; If other GB is not ready at this point, disconnect due to timeout
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, [wOtherPlayerLinkMode]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp $5
|
2020-10-23 10:36:54 -07:00
|
|
|
jr nz, .timeout
|
|
|
|
|
|
|
|
; Another check to increase reliability
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $6
|
2015-11-23 13:04:53 -08:00
|
|
|
ld [wPlayerLinkAction], a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld hl, wLinkTimeoutFrames
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_patch Wireless_net_delay_9
|
2022-03-12 15:34:04 -08:00
|
|
|
if DEF(_CRYSTAL11_VC)
|
|
|
|
ld a, $3
|
|
|
|
else
|
2020-10-23 10:36:54 -07:00
|
|
|
ld a, 1
|
2022-03-12 15:34:04 -08:00
|
|
|
endc
|
|
|
|
vc_patch_end
|
2015-11-09 20:55:39 -08:00
|
|
|
ld [hli], a
|
2020-10-23 10:36:54 -07:00
|
|
|
ld [hl], 50
|
2016-05-15 18:50:31 -07:00
|
|
|
call Link_CheckCommunicationError
|
2015-11-23 13:04:53 -08:00
|
|
|
ld a, [wOtherPlayerLinkMode]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp $6
|
2020-10-23 10:36:54 -07:00
|
|
|
jr z, .exit
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-23 10:36:54 -07:00
|
|
|
.timeout
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2020-10-23 10:36:54 -07:00
|
|
|
.exit
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Link_CheckCommunicationError:
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialReceivedNewData], a
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Wireless_prompt
|
2016-05-15 18:50:31 -07:00
|
|
|
ld a, [wLinkTimeoutFrames]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld h, a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld a, [wLinkTimeoutFrames + 1]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld l, a
|
|
|
|
push hl
|
2016-05-11 18:19:52 -07:00
|
|
|
call .CheckConnected
|
2015-11-09 20:55:39 -08:00
|
|
|
pop hl
|
2016-05-11 18:19:52 -07:00
|
|
|
jr nz, .load_true
|
|
|
|
call .AcknowledgeSerial
|
|
|
|
call .ConvertDW
|
|
|
|
call .CheckConnected
|
|
|
|
jr nz, .load_true
|
|
|
|
call .AcknowledgeSerial
|
2020-10-23 10:36:54 -07:00
|
|
|
xor a ; FALSE
|
|
|
|
jr .done
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2016-05-11 18:19:52 -07:00
|
|
|
.load_true
|
2020-10-23 10:36:54 -07:00
|
|
|
ld a, TRUE
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2020-10-23 10:36:54 -07:00
|
|
|
.done
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld hl, wLinkTimeoutFrames
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
|
|
|
ld [hli], a
|
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.CheckConnected:
|
2016-05-15 18:50:31 -07:00
|
|
|
call WaitLinkTransfer
|
|
|
|
ld hl, wLinkTimeoutFrames
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Wireless_net_recheck
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, [hli]
|
|
|
|
inc a
|
|
|
|
ret nz
|
|
|
|
ld a, [hl]
|
|
|
|
inc a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.AcknowledgeSerial:
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_patch Wireless_net_delay_7
|
2022-03-12 15:34:04 -08:00
|
|
|
if DEF(_CRYSTAL11_VC)
|
|
|
|
ld b, 26
|
|
|
|
else
|
2016-05-11 18:19:52 -07:00
|
|
|
ld b, 10
|
2022-03-12 15:34:04 -08:00
|
|
|
endc
|
|
|
|
vc_patch_end
|
2016-05-11 18:19:52 -07:00
|
|
|
.loop
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
2015-12-01 18:54:11 -08:00
|
|
|
call LinkDataReceived
|
2015-11-09 20:55:39 -08:00
|
|
|
dec b
|
2016-05-11 18:19:52 -07:00
|
|
|
jr nz, .loop
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.ConvertDW:
|
2016-05-15 18:50:31 -07:00
|
|
|
; [wLinkTimeoutFrames] = ((hl - $100) / 4) + $100
|
2018-01-19 11:49:43 -08:00
|
|
|
; = (hl / 4) + $c0
|
2015-11-09 20:55:39 -08:00
|
|
|
dec h
|
|
|
|
srl h
|
|
|
|
rr l
|
|
|
|
srl h
|
|
|
|
rr l
|
|
|
|
inc h
|
|
|
|
ld a, h
|
2016-05-15 18:50:31 -07:00
|
|
|
ld [wLinkTimeoutFrames], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, l
|
2016-05-15 18:50:31 -07:00
|
|
|
ld [wLinkTimeoutFrames + 1], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
TryQuickSave:
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, [wChosenCableClubRoom]
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall Link_SaveGame
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Wireless_TryQuickSave_block_input_1
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, TRUE
|
2016-05-15 18:50:31 -07:00
|
|
|
jr nc, .return_result
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Wireless_TryQuickSave_block_input_2
|
2018-01-19 11:49:43 -08:00
|
|
|
xor a ; FALSE
|
2016-05-15 18:50:31 -07:00
|
|
|
.return_result
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld c, 30
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
pop af
|
2018-07-28 16:27:34 -07:00
|
|
|
ld [wChosenCableClubRoom], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckBothSelectedSameRoom:
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, [wChosenCableClubRoom]
|
2016-05-15 18:50:31 -07:00
|
|
|
call Link_EnsureSync
|
2015-11-09 20:55:39 -08:00
|
|
|
push af
|
2015-12-01 18:54:11 -08:00
|
|
|
call LinkDataReceived
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
2015-12-01 18:54:11 -08:00
|
|
|
call LinkDataReceived
|
2015-11-09 20:55:39 -08:00
|
|
|
pop af
|
|
|
|
ld b, a
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, [wChosenCableClubRoom]
|
2015-11-09 20:55:39 -08:00
|
|
|
cp b
|
2015-11-23 13:04:53 -08:00
|
|
|
jr nz, .fail
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, [wChosenCableClubRoom]
|
2015-11-09 20:55:39 -08:00
|
|
|
inc a
|
|
|
|
ld [wLinkMode], a
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, TRUE
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2015-11-23 13:04:53 -08:00
|
|
|
.fail
|
2018-01-19 11:49:43 -08:00
|
|
|
xor a ; FALSE
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
TimeCapsule:
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Wireless_TimeCapsule
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, LINK_TIMECAPSULE
|
|
|
|
ld [wLinkMode], a
|
|
|
|
call DisableSpriteUpdates
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar LinkCommunications
|
2015-11-09 20:55:39 -08:00
|
|
|
call EnableSpriteUpdates
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
TradeCenter:
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Wireless_TradeCenter
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, LINK_TRADECENTER
|
|
|
|
ld [wLinkMode], a
|
|
|
|
call DisableSpriteUpdates
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar LinkCommunications
|
2015-11-09 20:55:39 -08:00
|
|
|
call EnableSpriteUpdates
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Colosseum:
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Wireless_Colosseum
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, LINK_COLOSSEUM
|
|
|
|
ld [wLinkMode], a
|
|
|
|
call DisableSpriteUpdates
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar LinkCommunications
|
2015-11-09 20:55:39 -08:00
|
|
|
call EnableSpriteUpdates
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CloseLink:
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
|
|
|
ld [wLinkMode], a
|
2016-05-15 18:50:31 -07:00
|
|
|
ld c, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
2022-06-06 14:22:48 -07:00
|
|
|
vc_hook Wireless_room_check
|
2016-05-15 18:50:31 -07:00
|
|
|
jp Link_ResetSerialRegistersAfterLinkClosure
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
FailedLinkToPast:
|
2015-11-23 13:04:53 -08:00
|
|
|
ld c, 40
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
|
|
|
ld a, $e
|
2016-05-15 18:50:31 -07:00
|
|
|
jp Link_EnsureSync
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Link_ResetSerialRegistersAfterLinkClosure:
|
2015-11-23 13:04:53 -08:00
|
|
|
ld c, 3
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrames
|
2018-01-19 11:49:43 -08:00
|
|
|
ld a, CONNECTION_NOT_ESTABLISHED
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialConnectionStatus], a
|
2020-10-21 21:53:54 -07:00
|
|
|
ld a, USING_INTERNAL_CLOCK
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSB], a
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSerialReceive], a
|
|
|
|
ldh [rSC], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
Link_EnsureSync:
|
2015-11-09 20:55:39 -08:00
|
|
|
add $d0
|
2021-02-22 09:00:53 -08:00
|
|
|
ld [wLinkPlayerSyncBuffer], a
|
|
|
|
ld [wLinkPlayerSyncBuffer + 1], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, $2
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
call DelayFrame
|
|
|
|
call DelayFrame
|
2015-11-23 13:04:53 -08:00
|
|
|
.receive_loop
|
2021-02-22 09:00:53 -08:00
|
|
|
call Serial_ExchangeSyncBytes
|
|
|
|
ld a, [wLinkReceivedSyncBuffer]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, a
|
|
|
|
and $f0
|
|
|
|
cp $d0
|
2015-11-23 13:04:53 -08:00
|
|
|
jr z, .done
|
2021-02-22 09:00:53 -08:00
|
|
|
ld a, [wLinkReceivedSyncBuffer + 1]
|
2015-11-09 20:55:39 -08:00
|
|
|
ld b, a
|
|
|
|
and $f0
|
|
|
|
cp $d0
|
2015-11-23 13:04:53 -08:00
|
|
|
jr nz, .receive_loop
|
2015-11-09 20:55:39 -08:00
|
|
|
|
2015-11-23 13:04:53 -08:00
|
|
|
.done
|
2015-11-09 20:55:39 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hVBlank], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ld a, b
|
|
|
|
and $f
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CableClubCheckWhichChris:
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSerialConnectionStatus]
|
2018-01-19 11:49:43 -08:00
|
|
|
cp USING_EXTERNAL_CLOCK
|
|
|
|
ld a, TRUE
|
2015-11-09 20:55:39 -08:00
|
|
|
jr z, .yes
|
2018-01-19 11:49:43 -08:00
|
|
|
dec a ; FALSE
|
2015-11-09 20:55:39 -08:00
|
|
|
|
|
|
|
.yes
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-11-09 20:55:39 -08:00
|
|
|
ret
|
|
|
|
|
2020-06-21 13:27:43 -07:00
|
|
|
GSLinkCommsBorderGFX: ; unreferenced
|
2020-06-16 08:28:52 -07:00
|
|
|
INCBIN "gfx/trade/unused_gs_border_tiles.2bpp"
|
2017-12-15 18:22:26 -08:00
|
|
|
|
2020-10-23 10:36:54 -07:00
|
|
|
CheckSRAM0Flag: ; unreferenced
|
|
|
|
; input: hl = unknown flag array in "SRAM Bank 0"
|
|
|
|
ld a, BANK("SRAM Bank 0")
|
2020-06-17 14:03:38 -07:00
|
|
|
call OpenSRAM
|
2020-10-23 10:36:54 -07:00
|
|
|
ld d, 0
|
2017-12-15 18:22:26 -08:00
|
|
|
ld b, CHECK_FLAG
|
2018-01-16 11:30:10 -08:00
|
|
|
predef SmallFarFlagAction
|
2017-12-15 18:22:26 -08:00
|
|
|
call CloseSRAM
|
|
|
|
ld a, c
|
|
|
|
and a
|
|
|
|
ret
|