summaryrefslogtreecommitdiff
path: root/engine/link
diff options
context:
space:
mode:
authorvulcandth <vulcandth@gmail.com>2022-03-12 17:34:04 -0600
committerGitHub <noreply@github.com>2022-03-12 18:34:04 -0500
commit31c3c94d64e1ac1e40c95acfda7de8b99b4f302b (patch)
tree274ec3a4fb4cacaa3d0f88c713085cfb5a3c85d1 /engine/link
parent775b5d046c7f42a3bd8034b92da92e25969bdbf7 (diff)
Build the Virtual Console patch with `make crystal11_vc` (#882)
Fixes #813
Diffstat (limited to 'engine/link')
-rw-r--r--engine/link/link.asm49
-rw-r--r--engine/link/mystery_gift.asm31
2 files changed, 80 insertions, 0 deletions
diff --git a/engine/link/link.asm b/engine/link/link.asm
index 7de939430..72bc6f368 100644
--- a/engine/link/link.asm
+++ b/engine/link/link.asm
@@ -67,7 +67,13 @@ Gen2ToGen1LinkComms:
.player_1
ld de, MUSIC_NONE
call PlayMusic
+ vc_patch NetworkDelay1
+if DEF(_CRYSTAL11_VC)
+ ld c, 26
+else
ld c, 3
+endc
+ vc_patch_end
call DelayFrames
xor a
ldh [rIF], a
@@ -77,6 +83,7 @@ Gen2ToGen1LinkComms:
ld hl, wLinkBattleRNPreamble
ld de, wEnemyMon
ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH
+ vc_hook Network358
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
ld [de], a
@@ -84,6 +91,7 @@ Gen2ToGen1LinkComms:
ld hl, wLinkData
ld de, wOTPartyData
ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + 1 + PARTY_LENGTH + 1 + (REDMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
+ vc_hook Network359
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
ld [de], a
@@ -91,6 +99,7 @@ Gen2ToGen1LinkComms:
ld hl, wPlayerPatchLists
ld de, wOTPatchLists
ld bc, 200
+ vc_hook Network364
call Serial_ExchangeBytes
xor a
@@ -224,7 +233,13 @@ Gen2ToGen2LinkComms:
.player_1
ld de, MUSIC_NONE
call PlayMusic
+ vc_patch NetworkDelay4
+if DEF(_CRYSTAL11_VC)
+ ld c, 26
+else
ld c, 3
+endc
+ vc_patch_end
call DelayFrames
xor a
ldh [rIF], a
@@ -234,6 +249,7 @@ Gen2ToGen2LinkComms:
ld hl, wLinkBattleRNPreamble
ld de, wEnemyMon
ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH
+ vc_hook Network360
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
ld [de], a
@@ -241,6 +257,7 @@ Gen2ToGen2LinkComms:
ld hl, wLinkData
ld de, wOTPartyData
ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + 1 + PARTY_LENGTH + 1 + 2 + (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
+ vc_hook Network361
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
ld [de], a
@@ -248,6 +265,7 @@ Gen2ToGen2LinkComms:
ld hl, wPlayerPatchLists
ld de, wOTPatchLists
ld bc, 200
+ vc_hook Network362
call Serial_ExchangeBytes
ld a, [wLinkMode]
@@ -256,6 +274,7 @@ Gen2ToGen2LinkComms:
ld hl, wLinkPlayerMail
ld de, wLinkOTMail
ld bc, wLinkPlayerMailEnd - wLinkPlayerMail
+ vc_hook Network363
call ExchangeBytes
.not_trading
@@ -1608,6 +1627,7 @@ ExitLinkCommunications:
ldh [rSC], a
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
ldh [rSC], a
+ vc_hook ret_heya
ret
GSPlaceTradeScreenFooter: ; unreferenced
@@ -2009,6 +2029,7 @@ LinkTrade:
ld de, String_TradeCompleted
call PlaceString
farcall Link_WaitBGMap
+ vc_hook save_game_end
ld c, 50
call DelayFrames
ld a, [wLinkMode]
@@ -2161,7 +2182,13 @@ GetIncompatibleMonName:
ret
EnterTimeCapsule:
+ vc_patch NetworkDelay2
+if DEF(_CRYSTAL11_VC)
+ ld c, 26
+else
ld c, 10
+endc
+ vc_patch_end
call DelayFrames
ld a, $4
call Link_EnsureSync
@@ -2218,6 +2245,7 @@ WaitForOtherPlayerToExit:
ld [hl], a
ldh [hVBlank], a
ld [wLinkMode], a
+ vc_hook term_exit
ret
SetBitsForLinkTradeRequest:
@@ -2282,6 +2310,7 @@ WaitForLinkedFriend:
ld a, (0 << rSC_ON) | (0 << rSC_CLOCK)
ldh [rSC], a
ld a, (1 << rSC_ON) | (0 << rSC_CLOCK)
+ vc_hook linkCable_fake_begin
ldh [rSC], a
ld a, [wLinkTimeoutFrames]
dec a
@@ -2374,7 +2403,13 @@ CheckLinkTimeout_Gen2:
ld a, $6
ld [wPlayerLinkAction], a
ld hl, wLinkTimeoutFrames
+ vc_patch NetworkDelay6
+if DEF(_CRYSTAL11_VC)
+ ld a, $3
+else
ld a, 1
+endc
+ vc_patch_end
ld [hli], a
ld [hl], 50
call Link_CheckCommunicationError
@@ -2395,6 +2430,7 @@ CheckLinkTimeout_Gen2:
Link_CheckCommunicationError:
xor a
ldh [hSerialReceivedNewData], a
+ vc_hook linkCable_fake_end
ld a, [wLinkTimeoutFrames]
ld h, a
ld a, [wLinkTimeoutFrames + 1]
@@ -2425,6 +2461,7 @@ Link_CheckCommunicationError:
.CheckConnected:
call WaitLinkTransfer
ld hl, wLinkTimeoutFrames
+ vc_hook Network_RECHECK
ld a, [hli]
inc a
ret nz
@@ -2433,7 +2470,13 @@ Link_CheckCommunicationError:
ret
.AcknowledgeSerial:
+ vc_patch NetworkDelay3
+if DEF(_CRYSTAL11_VC)
+ ld b, 26
+else
ld b, 10
+endc
+ vc_patch_end
.loop
call DelayFrame
call LinkDataReceived
@@ -2460,8 +2503,10 @@ TryQuickSave:
ld a, [wChosenCableClubRoom]
push af
farcall Link_SaveGame
+ vc_hook linkCable_block_input
ld a, TRUE
jr nc, .return_result
+ vc_hook linkCable_block_input2
xor a ; FALSE
.return_result
ld [wScriptVar], a
@@ -2498,6 +2543,7 @@ CheckBothSelectedSameRoom:
ret
TimeCapsule:
+ vc_hook to_play2_mons1
ld a, LINK_TIMECAPSULE
ld [wLinkMode], a
call DisableSpriteUpdates
@@ -2508,6 +2554,7 @@ TimeCapsule:
ret
TradeCenter:
+ vc_hook to_play2_trade
ld a, LINK_TRADECENTER
ld [wLinkMode], a
call DisableSpriteUpdates
@@ -2518,6 +2565,7 @@ TradeCenter:
ret
Colosseum:
+ vc_hook to_play2_battle
ld a, LINK_COLOSSEUM
ld [wLinkMode], a
call DisableSpriteUpdates
@@ -2532,6 +2580,7 @@ CloseLink:
ld [wLinkMode], a
ld c, 3
call DelayFrames
+ vc_hook room_check
jp Link_ResetSerialRegistersAfterLinkClosure
FailedLinkToPast:
diff --git a/engine/link/mystery_gift.asm b/engine/link/mystery_gift.asm
index 1bc26f6a4..f3cb4e790 100644
--- a/engine/link/mystery_gift.asm
+++ b/engine/link/mystery_gift.asm
@@ -37,14 +37,23 @@ DoMysteryGift:
; Prepare the first of two messages for wMysteryGiftPartnerData
farcall StageDataForMysteryGift
call ClearMysteryGiftTrainer
+ vc_patch infrared_fake_0
+if DEF(_CRYSTAL11_VC)
+ farcall StagePartyDataForMysteryGift
+ call ClearMysteryGiftTrainer
+ nop
+else
ld a, 2
ld [wMysteryGiftMessageCount], a
ld a, wMysteryGiftPartnerDataEnd - wMysteryGiftPartnerData
ld [wMysteryGiftStagedDataLength], a
+endc
+ vc_patch_end
ldh a, [rIE]
push af
call ExchangeMysteryGiftData
+ vc_hook infrared_fake_4
ld d, a
xor a
ldh [rIF], a
@@ -260,6 +269,26 @@ DoMysteryGift:
jp CloseSRAM
ExchangeMysteryGiftData:
+ vc_hook infrared_fake_2
+ vc_patch infrared_fake_1
+if DEF(_CRYSTAL11_VC)
+ ld d, $ef
+.loop
+ dec d
+ ld a, d
+ or a
+ jr nz, .loop
+ vc_hook infrared_fake_3
+ nop
+ cp MG_CANCELED
+.restart ; same location as unpatched .restart
+ ret z
+ nop
+ nop
+ cp MG_OKAY
+ jr nz, ExchangeMysteryGiftData
+ ret
+else
di
farcall ClearChannels
call InitializeIRCommunicationInterrupts
@@ -268,6 +297,8 @@ ExchangeMysteryGiftData:
call BeginIRCommunication
call InitializeIRCommunicationRoles
ldh a, [hMGStatusFlags]
+endc
+ vc_patch_end
cp MG_CANCELED
jp z, EndOrContinueMysteryGiftIRCommunication
cp MG_OKAY