Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/link/cable_club_npc.asm
1271 views
1
CableClubNPC::
2
ld hl, CableClubNPCWelcomeText
3
call PrintText
4
CheckEvent EVENT_GOT_POKEDEX
5
jp nz, .receivedPokedex
6
; if the player hasn't received the pokedex
7
ld c, 60
8
call DelayFrames
9
ld hl, CableClubNPCMakingPreparationsText
10
call PrintText
11
jp .didNotConnect
12
.receivedPokedex
13
ld a, $1
14
ld [wMenuJoypadPollCount], a
15
ld a, 90
16
ld [wLinkTimeoutCounter], a
17
.establishConnectionLoop
18
ldh a, [hSerialConnectionStatus]
19
cp USING_INTERNAL_CLOCK
20
jr z, .establishedConnection
21
cp USING_EXTERNAL_CLOCK
22
jr z, .establishedConnection
23
ld a, CONNECTION_NOT_ESTABLISHED
24
ldh [hSerialConnectionStatus], a
25
ld a, ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK
26
ldh [rSB], a
27
xor a
28
ldh [hSerialReceiveData], a
29
ld a, SC_START | SC_EXTERNAL
30
; This vc_hook causes the Virtual Console to set [hSerialConnectionStatus] to
31
; USING_INTERNAL_CLOCK, which allows the player to proceed past the link
32
; receptionist's "Please wait." It assumes that hSerialConnectionStatus is at
33
; its original address.
34
vc_hook Link_fake_connection_status
35
vc_assert hSerialConnectionStatus == $ffaa, \
36
"hSerialConnectionStatus is no longer located at 00:ffaa"
37
vc_assert USING_INTERNAL_CLOCK == $02, \
38
"USING_INTERNAL_CLOCK is no longer equal to $02."
39
ldh [rSC], a
40
ld a, [wLinkTimeoutCounter]
41
dec a
42
ld [wLinkTimeoutCounter], a
43
jr z, .failedToEstablishConnection
44
ld a, ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK
45
ldh [rSB], a
46
ld a, SC_START | SC_INTERNAL
47
ldh [rSC], a
48
call DelayFrame
49
jr .establishConnectionLoop
50
.establishedConnection
51
call Serial_SendZeroByte
52
call DelayFrame
53
call Serial_SendZeroByte
54
ld c, 50
55
call DelayFrames
56
ld hl, CableClubNPCPleaseApplyHereHaveToSaveText
57
call PrintText
58
xor a
59
ld [wMenuJoypadPollCount], a
60
call YesNoChoice
61
ld a, $1
62
ld [wMenuJoypadPollCount], a
63
ld a, [wCurrentMenuItem]
64
and a
65
jr nz, .choseNo
66
vc_hook Wireless_TryQuickSave_block_input
67
callfar SaveGameData
68
call WaitForSoundToFinish
69
ld a, SFX_SAVE
70
call PlaySoundWaitForCurrent
71
ld hl, CableClubNPCPleaseWaitText
72
call PrintText
73
ld hl, wUnknownSerialCounter
74
ld a, $3
75
ld [hli], a
76
xor a
77
ld [hl], a
78
ldh [hSerialReceivedNewData], a
79
vc_hook Wireless_prompt
80
ld [wSerialExchangeNybbleSendData], a
81
call Serial_SyncAndExchangeNybble
82
vc_hook Wireless_net_recheck
83
ld hl, wUnknownSerialCounter
84
ld a, [hli]
85
inc a
86
jr nz, .connected
87
ld a, [hl]
88
inc a
89
jr nz, .connected
90
ld b, 10
91
.syncLoop
92
call DelayFrame
93
call Serial_SendZeroByte
94
dec b
95
jr nz, .syncLoop
96
call CloseLinkConnection
97
ld hl, CableClubNPCLinkClosedBecauseOfInactivityText
98
call PrintText
99
jr .didNotConnect
100
.failedToEstablishConnection
101
ld hl, CableClubNPCAreaReservedFor2FriendsLinkedByCableText
102
call PrintText
103
jr .didNotConnect
104
.choseNo
105
call CloseLinkConnection
106
ld hl, CableClubNPCPleaseComeAgainText
107
call PrintText
108
.didNotConnect
109
xor a
110
ld hl, wUnknownSerialCounter
111
ld [hli], a
112
ld [hl], a
113
ld hl, wStatusFlags4
114
res BIT_LINK_CONNECTED, [hl]
115
xor a
116
ld [wMenuJoypadPollCount], a
117
ret
118
.connected
119
xor a
120
ld [hld], a
121
ld [hl], a
122
jpfar LinkMenu
123
124
CableClubNPCAreaReservedFor2FriendsLinkedByCableText:
125
text_far _CableClubNPCAreaReservedFor2FriendsLinkedByCableText
126
text_end
127
128
CableClubNPCWelcomeText:
129
text_far _CableClubNPCWelcomeText
130
text_end
131
132
CableClubNPCPleaseApplyHereHaveToSaveText:
133
text_far _CableClubNPCPleaseApplyHereHaveToSaveText
134
text_end
135
136
CableClubNPCPleaseWaitText:
137
text_far _CableClubNPCPleaseWaitText
138
text_pause
139
text_end
140
141
CableClubNPCLinkClosedBecauseOfInactivityText:
142
text_far _CableClubNPCLinkClosedBecauseOfInactivityText
143
text_end
144
145
CableClubNPCPleaseComeAgainText:
146
text_far _CableClubNPCPleaseComeAgainText
147
text_end
148
149
CableClubNPCMakingPreparationsText:
150
text_far _CableClubNPCMakingPreparationsText
151
text_end
152
153
CloseLinkConnection:
154
call Delay3
155
ld a, CONNECTION_NOT_ESTABLISHED
156
ldh [hSerialConnectionStatus], a
157
ld a, ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK
158
ldh [rSB], a
159
xor a
160
ldh [hSerialReceiveData], a
161
ld a, SC_START | SC_EXTERNAL
162
ldh [rSC], a
163
ret
164
165