Resolve #471 (although link code still needs more cleanup, like its WRAM labels)

This commit is contained in:
Remy Oukaour 2018-01-19 14:49:43 -05:00
parent 52993d20ef
commit 0c6338836d
12 changed files with 279 additions and 253 deletions

View File

@ -6,7 +6,25 @@
const LINK_COLOSSEUM ; 3 const LINK_COLOSSEUM ; 3
const LINK_MOBILE ; 4 const LINK_MOBILE ; 4
; hSerialReceive high nybbles
SERIAL_TIMECAPSULE EQU $60 SERIAL_TIMECAPSULE EQU $60
SERIAL_TRADECENTER EQU $70 SERIAL_TRADECENTER EQU $70
SERIAL_BATTLE EQU $80 SERIAL_BATTLE EQU $80
ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK EQU $01
ESTABLISH_CONNECTION_WITH_EXTERNAL_CLOCK EQU $02
START_TRANSFER_EXTERNAL_CLOCK EQU $80 ; 1 << rSC_ON
START_TRANSFER_INTERNAL_CLOCK EQU $81 ; (1 << rSC_ON) | 1
; hSerialConnectionStatus
USING_EXTERNAL_CLOCK EQU $01
USING_INTERNAL_CLOCK EQU $02
CONNECTION_NOT_ESTABLISHED EQU $ff
; signals the start of an array of bytes transferred over the link cable
SERIAL_PREAMBLE_BYTE EQU $fd
; this byte is used when there is no data to send
SERIAL_NO_DATA_BYTE EQU $fe
; signals the end of one part of a patch list (there are two parts) for player/enemy party data
SERIAL_PATCH_LIST_PART_TERMINATOR EQU $ff

View File

@ -26,7 +26,7 @@ DoBattle: ; 3c000
and a and a
jr z, .not_linked jr z, .not_linked
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp $2
jr z, .player_2 jr z, .player_2
@ -97,7 +97,7 @@ DoBattle: ; 3c000
ld a, [wLinkMode] ld a, [wLinkMode]
and a and a
jr z, .not_linked_2 jr z, .not_linked_2
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp $2
jr nz, .not_linked_2 jr nz, .not_linked_2
xor a xor a
@ -251,7 +251,7 @@ Stubbed_Function3c1bf:
; 3c1d6 ; 3c1d6
HandleBetweenTurnEffects: ; 3c1d6 HandleBetweenTurnEffects: ; 3c1d6
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .CheckEnemyFirst jr z, .CheckEnemyFirst
call CheckFaint_PlayerThenEnemy call CheckFaint_PlayerThenEnemy
@ -350,7 +350,7 @@ CheckFaint_EnemyThenPlayer: ; 3c25c
; 3c27c ; 3c27c
HandleBerserkGene: ; 3c27c HandleBerserkGene: ; 3c27c
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .reverse jr z, .reverse
@ -458,7 +458,7 @@ DetermineMoveOrder: ; 3c314
ld a, [wPlayerAction] ld a, [wPlayerAction]
cp $2 cp $2
jr nz, .switch jr nz, .switch
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp $2
jr z, .player_2 jr z, .player_2
@ -515,7 +515,7 @@ DetermineMoveOrder: ; 3c314
jp .enemy_first jp .enemy_first
.both_have_quick_claw .both_have_quick_claw
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp $2
jr z, .player_2b jr z, .player_2b
call BattleRandom call BattleRandom
@ -545,7 +545,7 @@ DetermineMoveOrder: ; 3c314
jp .enemy_first jp .enemy_first
.speed_tie .speed_tie
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp $2
jr z, .player_2c jr z, .player_2c
call BattleRandom call BattleRandom
@ -709,7 +709,7 @@ ParsePlayerAction: ; 3c434
; 3c4df ; 3c4df
HandleEncore: ; 3c4df HandleEncore: ; 3c4df
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .player_1 jr z, .player_1
call .do_player call .do_player
@ -1161,7 +1161,7 @@ ResidualDamage: ; 3c716
; 3c801 ; 3c801
HandlePerishSong: ; 3c801 HandlePerishSong: ; 3c801
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .EnemyFirst jr z, .EnemyFirst
call SetPlayerTurn call SetPlayerTurn
@ -1230,7 +1230,7 @@ HandlePerishSong: ; 3c801
; 3c874 ; 3c874
HandleWrap: ; 3c874 HandleWrap: ; 3c874
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .EnemyFirst jr z, .EnemyFirst
call SetPlayerTurn call SetPlayerTurn
@ -1302,7 +1302,7 @@ SwitchTurnCore: ; 3c8e4
; 3c8eb ; 3c8eb
HandleLeftovers: ; 3c8eb HandleLeftovers: ; 3c8eb
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .DoEnemyFirst jr z, .DoEnemyFirst
call SetPlayerTurn call SetPlayerTurn
@ -1352,7 +1352,7 @@ HandleLeftovers: ; 3c8eb
; 3c93c ; 3c93c
HandleMysteryberry: ; 3c93c HandleMysteryberry: ; 3c93c
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .DoEnemyFirst jr z, .DoEnemyFirst
call SetPlayerTurn call SetPlayerTurn
@ -1491,7 +1491,7 @@ HandleMysteryberry: ; 3c93c
; 3ca26 ; 3ca26
HandleFutureSight: ; 3ca26 HandleFutureSight: ; 3ca26
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .enemy_first jr z, .enemy_first
call SetPlayerTurn call SetPlayerTurn
@ -1550,7 +1550,7 @@ HandleFutureSight: ; 3ca26
; 3ca8f ; 3ca8f
HanleDefrost: ; 3ca8f HanleDefrost: ; 3ca8f
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .enemy_first jr z, .enemy_first
call .do_player_turn call .do_player_turn
@ -1610,7 +1610,7 @@ HanleDefrost: ; 3ca8f
; 3cafb ; 3cafb
HandleSafeguard: ; 3cafb HandleSafeguard: ; 3cafb
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .player1 jr z, .player1
call .CheckPlayer call .CheckPlayer
@ -1647,7 +1647,7 @@ HandleSafeguard: ; 3cafb
jp StdBattleTextBox jp StdBattleTextBox
HandleScreens: ; 3cb36 HandleScreens: ; 3cb36
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp 1 cp 1
jr z, .Both jr z, .Both
call .CheckPlayer call .CheckPlayer
@ -1731,7 +1731,7 @@ HandleWeather: ; 3cb9e
cp WEATHER_SANDSTORM cp WEATHER_SANDSTORM
ret nz ret nz
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp 1 cp 1
jr z, .enemy_first jr z, .enemy_first
@ -2115,7 +2115,7 @@ HandleEnemyMonFaint: ; 3cd55
; 3cdca ; 3cdca
DoubleSwitch: ; 3cdca DoubleSwitch: ; 3cdca
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .player_1 jr z, .player_1
call ClearSprites call ClearSprites
@ -4350,7 +4350,7 @@ RecallPlayerMon: ; 3dce6
; 3dcf9 ; 3dcf9
HandleHealingItems: ; 3dcf9 HandleHealingItems: ; 3dcf9
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .player_1 jr z, .player_1
call SetPlayerTurn call SetPlayerTurn
@ -4595,7 +4595,7 @@ UseConfusionHealingItem: ; 3de51
HandleStatBoostingHeldItems: ; 3de97 HandleStatBoostingHeldItems: ; 3de97
; The effects handled here are not used in-game. ; The effects handled here are not used in-game.
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .player_1 jr z, .player_1
call .DoPlayer call .DoPlayer
@ -5374,7 +5374,7 @@ PlayerSwitch: ; 3e3ad
ret ret
.dont_run .dont_run
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp $1
jr z, .player_1 jr z, .player_1
call BattleMonEntrance call BattleMonEntrance

View File

@ -28,9 +28,9 @@ LinkCommunications: ; 28000
call SetTradeRoomBGPals call SetTradeRoomBGPals
call WaitBGMap2 call WaitBGMap2
ld hl, wcf5d ld hl, wcf5d
xor a xor a ; LOW($5000)
ld [hli], a ld [hli], a
ld [hl], $50 ld [hl], HIGH($5000)
ld a, [wLinkMode] ld a, [wLinkMode]
cp LINK_TIMECAPSULE cp LINK_TIMECAPSULE
jp nz, Gen2ToGen2LinkComms jp nz, Gen2ToGen2LinkComms
@ -42,29 +42,31 @@ TimeCapsule: ; 2805d
xor a xor a
ld [wPlayerLinkAction], a ld [wPlayerLinkAction], a
call WaitLinkTransfer call WaitLinkTransfer
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
jr nz, .player_1 jr nz, .player_1
ld c, 3 ld c, 3
call DelayFrames call DelayFrames
xor a xor a
ld [hSerialSend], a ld [hSerialSend], a
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
call DelayFrame call DelayFrame
xor a xor a
ld [hSerialSend], a ld [hSerialSend], a
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
.player_1 .player_1
ld de, MUSIC_NONE ld de, MUSIC_NONE
call PlayMusic call PlayMusic
ld c, $3 ld c, 3
call DelayFrames call DelayFrames
xor a xor a
ld [rIF], a ld [rIF], a
@ -73,19 +75,19 @@ TimeCapsule: ; 2805d
ld hl, wd1f3 ld hl, wd1f3
ld de, EnemyMonSpecies ld de, EnemyMonSpecies
ld bc, $11 ld bc, $11
call Function75f call Serial_ExchangeBytes
ld a, $fe ld a, SERIAL_NO_DATA_BYTE
ld [de], a ld [de], a
ld hl, wLinkData ld hl, wLinkData
ld de, OTPlayerName ld de, OTPlayerName
ld bc, $1a8 ld bc, $1a8
call Function75f call Serial_ExchangeBytes
ld a, $fe ld a, SERIAL_NO_DATA_BYTE
ld [de], a ld [de], a
ld hl, wMisc ld hl, wMisc
ld de, wPlayerTrademonSpecies ld de, wPlayerTrademonSpecies
ld bc, wPlayerTrademonSpecies - wMisc ld bc, wPlayerTrademonSpecies - wMisc
call Function75f call Serial_ExchangeBytes
xor a xor a
ld [rIF], a ld [rIF], a
ld a, $1d ld a, $1d
@ -107,25 +109,25 @@ TimeCapsule: ; 2805d
call Link_CopyOTData call Link_CopyOTData
ld de, wPlayerTrademonSpecies ld de, wPlayerTrademonSpecies
ld hl, wTimeCapsulePartyMon1Species ld hl, wTimeCapsulePartyMon1Species
ld c, $2 ld c, 2
.loop .loop
ld a, [de] ld a, [de]
inc de inc de
and a and a
jr z, .loop jr z, .loop
cp $fd cp SERIAL_PREAMBLE_BYTE
jr z, .loop jr z, .loop
cp $fe cp SERIAL_NO_DATA_BYTE
jr z, .loop jr z, .loop
cp $ff cp SERIAL_PATCH_LIST_PART_TERMINATOR
jr z, .next jr z, .next
push hl push hl
push bc push bc
ld b, $0 ld b, 0
dec a dec a
ld c, a ld c, a
add hl, bc add hl, bc
ld a, $fe ld a, SERIAL_NO_DATA_BYTE
ld [hl], a ld [hl], a
pop bc pop bc
pop hl pop hl
@ -168,8 +170,8 @@ TimeCapsule: ; 2805d
ld [wUnusedD102 + 1], a ld [wUnusedD102 + 1], a
ld de, MUSIC_NONE ld de, MUSIC_NONE
call PlayMusic call PlayMusic
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
ld c, 66 ld c, 66
call z, DelayFrames call z, DelayFrames
ld de, MUSIC_ROUTE_30 ld de, MUSIC_ROUTE_30
@ -185,23 +187,25 @@ Gen2ToGen2LinkComms: ; 28177
ld a, [ScriptVar] ld a, [ScriptVar]
and a and a
jp z, LinkTimeout jp z, LinkTimeout
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
jr nz, .Player1 jr nz, .Player1
ld c, 3 ld c, 3
call DelayFrames call DelayFrames
xor a xor a
ld [hSerialSend], a ld [hSerialSend], a
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
call DelayFrame call DelayFrame
xor a xor a
ld [hSerialSend], a ld [hSerialSend], a
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
.Player1: .Player1:
@ -216,26 +220,26 @@ Gen2ToGen2LinkComms: ; 28177
ld hl, wd1f3 ld hl, wd1f3
ld de, EnemyMonSpecies ld de, EnemyMonSpecies
ld bc, $11 ld bc, $11
call Function75f call Serial_ExchangeBytes
ld a, $fe ld a, SERIAL_NO_DATA_BYTE
ld [de], a ld [de], a
ld hl, wLinkData ld hl, wLinkData
ld de, OTPlayerName ld de, OTPlayerName
ld bc, $1c2 ld bc, $1c2
call Function75f call Serial_ExchangeBytes
ld a, $fe ld a, SERIAL_NO_DATA_BYTE
ld [de], a ld [de], a
ld hl, wMisc ld hl, wMisc
ld de, wPlayerTrademonSpecies ld de, wPlayerTrademonSpecies
ld bc, $c8 ld bc, $c8
call Function75f call Serial_ExchangeBytes
ld a, [wLinkMode] ld a, [wLinkMode]
cp LINK_TRADECENTER cp LINK_TRADECENTER
jr nz, .not_trading jr nz, .not_trading
ld hl, wc9f4 ld hl, wc9f4
ld de, wcb84 ld de, wcb84
ld bc, $186 ld bc, $186
call Function283f2 call ExchangeBytes
.not_trading .not_trading
xor a xor a
@ -252,25 +256,25 @@ Gen2ToGen2LinkComms: ; 28177
call Link_CopyOTData call Link_CopyOTData
ld de, wPlayerTrademonSpecies ld de, wPlayerTrademonSpecies
ld hl, wLinkPlayerPartyMon1Species ld hl, wLinkPlayerPartyMon1Species
ld c, $2 ld c, 2
.loop1 .loop1
ld a, [de] ld a, [de]
inc de inc de
and a and a
jr z, .loop1 jr z, .loop1
cp $fd cp SERIAL_PREAMBLE_BYTE
jr z, .loop1 jr z, .loop1
cp $fe cp SERIAL_NO_DATA_BYTE
jr z, .loop1 jr z, .loop1
cp $ff cp SERIAL_PATCH_LIST_PART_TERMINATOR
jr z, .next1 jr z, .next1
push hl push hl
push bc push bc
ld b, $0 ld b, 0
dec a dec a
ld c, a ld c, a
add hl, bc add hl, bc
ld a, $fe ld a, SERIAL_NO_DATA_BYTE
ld [hl], a ld [hl], a
pop bc pop bc
pop hl pop hl
@ -286,13 +290,13 @@ Gen2ToGen2LinkComms: ; 28177
ld hl, wcb84 ld hl, wcb84
.loop2 .loop2
ld a, [hli] ld a, [hli]
cp $20 cp MAIL_MSG_LENGTH
jr nz, .loop2 jr nz, .loop2
.loop3 .loop3
ld a, [hli] ld a, [hli]
cp $fe cp SERIAL_NO_DATA_BYTE
jr z, .loop3 jr z, .loop3
cp $20 cp MAIL_MSG_LENGTH
jr z, .loop3 jr z, .loop3
dec hl dec hl
ld de, wcb84 ld de, wcb84
@ -302,9 +306,9 @@ Gen2ToGen2LinkComms: ; 28177
ld bc, $c6 ; 198 ld bc, $c6 ; 198
.loop4 .loop4
ld a, [hl] ld a, [hl]
cp $21 cp MAIL_MSG_LENGTH + 1
jr nz, .okay1 jr nz, .okay1
ld [hl], $fe ld [hl], SERIAL_NO_DATA_BYTE
.okay1 .okay1
inc hl inc hl
dec bc dec bc
@ -315,14 +319,14 @@ Gen2ToGen2LinkComms: ; 28177
.loop5 .loop5
ld a, [de] ld a, [de]
inc de inc de
cp $ff cp SERIAL_PATCH_LIST_PART_TERMINATOR
jr z, .start_copying_mail jr z, .start_copying_mail
ld hl, wcc4a ld hl, wcc4a
dec a dec a
ld b, $0 ld b, $0
ld c, a ld c, a
add hl, bc add hl, bc
ld [hl], $fe ld [hl], SERIAL_NO_DATA_BYTE
jr .loop5 jr .loop5
.start_copying_mail .start_copying_mail
@ -395,7 +399,7 @@ Gen2ToGen2LinkComms: ; 28177
ld bc, NAME_LENGTH ld bc, NAME_LENGTH
call CopyBytes call CopyBytes
ld de, OTPartyCount ld de, OTPartyCount
ld bc, 8 ld bc, 1 + PARTY_LENGTH + 1
call CopyBytes call CopyBytes
ld de, OTPlayerID ld de, OTPlayerID
ld bc, 2 ld bc, 2
@ -409,8 +413,8 @@ Gen2ToGen2LinkComms: ; 28177
ld [wUnusedD102 + 1], a ld [wUnusedD102 + 1], a
ld de, MUSIC_NONE ld de, MUSIC_NONE
call PlayMusic call PlayMusic
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
ld c, 66 ld c, 66
call z, DelayFrames call z, DelayFrames
ld a, [wLinkMode] ld a, [wLinkMode]
@ -423,8 +427,8 @@ Gen2ToGen2LinkComms: ; 28177
ld hl, Options ld hl, Options
ld a, [hl] ld a, [hl]
push af push af
and $20 and 1 << STEREO
or $3 or TEXT_DELAY_MED
ld [hl], a ld [hl], a
ld hl, OTPlayerName ld hl, OTPlayerName
ld de, OTClassName ld de, OTClassName
@ -510,28 +514,28 @@ LinkTimeout: ; 283b2
db "@" db "@"
; 0x283f2 ; 0x283f2
Function283f2: ; 283f2 ExchangeBytes: ; 283f2
ld a, $1 ld a, TRUE
ld [hFFCC], a ld [hSerialIgnoringInitialData], a
.loop .loop
ld a, [hl] ld a, [hl]
ld [hSerialSend], a ld [hSerialSend], a
call Function78a call Serial_ExchangeByte
push bc push bc
ld b, a ld b, a
inc hl inc hl
ld a, $30 ld a, 48
.delay_cycles .delay_cycles
dec a dec a
jr nz, .delay_cycles jr nz, .delay_cycles
ld a, [hFFCC] ld a, [hSerialIgnoringInitialData]
and a and a
ld a, b ld a, b
pop bc pop bc
jr z, .load jr z, .load
dec hl dec hl
xor a xor a
ld [hFFCC], a ld [hSerialIgnoringInitialData], a
jr .loop jr .loop
.load .load
@ -563,7 +567,7 @@ ClearLinkData: ; 28426
FixDataForLinkTransfer: ; 28434 FixDataForLinkTransfer: ; 28434
ld hl, wd1f3 ld hl, wd1f3
ld a, $fd ld a, SERIAL_PREAMBLE_BYTE
ld b, LinkBattleRNs - wd1f3 ld b, LinkBattleRNs - wd1f3
.loop1 .loop1
ld [hli], a ld [hli], a
@ -572,13 +576,13 @@ FixDataForLinkTransfer: ; 28434
ld b, TempEnemyMonSpecies - LinkBattleRNs ld b, TempEnemyMonSpecies - LinkBattleRNs
.loop2 .loop2
call Random call Random
cp $fd cp SERIAL_PREAMBLE_BYTE
jr nc, .loop2 jr nc, .loop2
ld [hli], a ld [hli], a
dec b dec b
jr nz, .loop2 jr nz, .loop2
ld hl, wMisc ld hl, wMisc
ld a, $fd ld a, SERIAL_PREAMBLE_BYTE
ld [hli], a ld [hli], a
ld [hli], a ld [hli], a
ld [hli], a ld [hli], a
@ -594,7 +598,7 @@ FixDataForLinkTransfer: ; 28434
.loop4 .loop4
inc c inc c
ld a, c ld a, c
cp $fd cp SERIAL_PREAMBLE_BYTE
jr z, .next1 jr z, .next1
ld a, b ld a, b
dec a dec a
@ -613,31 +617,31 @@ FixDataForLinkTransfer: ; 28434
.next2 .next2
inc hl inc hl
ld a, [hl] ld a, [hl]
cp $fe cp SERIAL_NO_DATA_BYTE
jr nz, .loop4 jr nz, .loop4
ld a, c ld a, c
ld [de], a ld [de], a
inc de inc de
ld [hl], $ff ld [hl], SERIAL_PATCH_LIST_PART_TERMINATOR
jr .loop4 jr .loop4
.next1 .next1
ld a, $ff ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a ld [de], a
inc de inc de
lb bc, 1, 0 lb bc, 1, 0
jr .loop4 jr .loop4
.done .done
ld a, $ff ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a ld [de], a
ret ret
; 28499 ; 28499
Link_PrepPartyData_Gen1: ; 28499 Link_PrepPartyData_Gen1: ; 28499
ld de, wLinkData ld de, wLinkData
ld a, $fd ld a, SERIAL_PREAMBLE_BYTE
ld b, 6 ld b, PARTY_LENGTH
.loop1 .loop1
ld [de], a ld [de], a
inc de inc de
@ -804,8 +808,8 @@ Link_PrepPartyData_Gen1: ; 28499
Link_PrepPartyData_Gen2: ; 28595 Link_PrepPartyData_Gen2: ; 28595
ld de, wLinkData ld de, wLinkData
ld a, $fd ld a, SERIAL_PREAMBLE_BYTE
ld b, 6 ld b, PARTY_LENGTH
.loop1 .loop1
ld [de], a ld [de], a
inc de inc de
@ -907,7 +911,7 @@ Link_PrepPartyData_Gen2: ; 28595
ld bc, PARTY_LENGTH * (sPartyMon1MailAuthor - sPartyMon1Mail) ld bc, PARTY_LENGTH * (sPartyMon1MailAuthor - sPartyMon1Mail)
.loop5 .loop5
ld a, [hl] ld a, [hl]
cp $fe cp SERIAL_NO_DATA_BYTE
jr nz, .skip2 jr nz, .skip2
ld [hl], sPartyMon1MailAuthor - sPartyMon1Mail ld [hl], sPartyMon1MailAuthor - sPartyMon1Mail
@ -924,9 +928,9 @@ Link_PrepPartyData_Gen2: ; 28595
.loop6 .loop6
inc c inc c
ld a, [hl] ld a, [hl]
cp $fe cp SERIAL_NO_DATA_BYTE
jr nz, .skip3 jr nz, .skip3
ld [hl], $ff ld [hl], SERIAL_PATCH_LIST_PART_TERMINATOR
ld a, c ld a, c
ld [de], a ld [de], a
inc de inc de
@ -935,13 +939,13 @@ Link_PrepPartyData_Gen2: ; 28595
inc hl inc hl
dec b dec b
jr nz, .loop6 jr nz, .loop6
ld a, $ff ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a ld [de], a
ret ret
; 28682 ; 28682
Function28682: ; 28682 Function28682: ; 28682
ld c, $5 ld c, 5
.loop .loop
ld [de], a ld [de], a
inc de inc de
@ -1129,7 +1133,7 @@ INCLUDE "data/items/catch_rate_items.asm"
Link_CopyOTData: ; 2879e Link_CopyOTData: ; 2879e
.loop .loop
ld a, [hli] ld a, [hli]
cp $fe cp SERIAL_NO_DATA_BYTE
jr z, .loop jr z, .loop
ld [de], a ld [de], a
inc de inc de
@ -1141,8 +1145,8 @@ Link_CopyOTData: ; 2879e
; 287ab ; 287ab
Link_CopyRandomNumbers: ; 287ab Link_CopyRandomNumbers: ; 287ab
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
ret z ret z
ld hl, EnemyMonSpecies ld hl, EnemyMonSpecies
call Link_FindFirstNonControlCharacter_AllowZero call Link_FindFirstNonControlCharacter_AllowZero
@ -1150,9 +1154,9 @@ Link_CopyRandomNumbers: ; 287ab
ld c, 10 ld c, 10
.loop .loop
ld a, [hli] ld a, [hli]
cp $fe cp SERIAL_NO_DATA_BYTE
jr z, .loop jr z, .loop
cp $fd cp SERIAL_PREAMBLE_BYTE
jr z, .loop jr z, .loop
ld [de], a ld [de], a
inc de inc de
@ -1166,9 +1170,9 @@ Link_FindFirstNonControlCharacter_SkipZero: ; 287ca
ld a, [hli] ld a, [hli]
and a and a
jr z, .loop jr z, .loop
cp $fd cp SERIAL_PREAMBLE_BYTE
jr z, .loop jr z, .loop
cp $fe cp SERIAL_NO_DATA_BYTE
jr z, .loop jr z, .loop
dec hl dec hl
ret ret
@ -1177,9 +1181,9 @@ Link_FindFirstNonControlCharacter_SkipZero: ; 287ca
Link_FindFirstNonControlCharacter_AllowZero: ; 287d8 Link_FindFirstNonControlCharacter_AllowZero: ; 287d8
.loop .loop
ld a, [hli] ld a, [hli]
cp $fd cp SERIAL_PREAMBLE_BYTE
jr z, .loop jr z, .loop
cp $fe cp SERIAL_NO_DATA_BYTE
jr z, .loop jr z, .loop
dec hl dec hl
ret ret
@ -1219,7 +1223,7 @@ LinkTrade_OTPartyMenu: ; 28803
ld [wMenuCursorX], a ld [wMenuCursorX], a
ln a, 1, 0 ln a, 1, 0
ld [w2DMenuCursorOffsets], a ld [w2DMenuCursorOffsets], a
ld a, $20 ld a, MENU_UNUSED_3
ld [w2DMenuFlags1], a ld [w2DMenuFlags1], a
xor a xor a
ld [w2DMenuFlags2], a ld [w2DMenuFlags2], a
@ -1231,7 +1235,7 @@ LinkTradeOTPartymonMenuLoop: ; 28835
jp z, LinkTradePartiesMenuMasterLoop jp z, LinkTradePartiesMenuMasterLoop
bit A_BUTTON_F, a bit A_BUTTON_F, a
jr z, .not_a_button jr z, .not_a_button
ld a, $1 ld a, INIT_ENEMYOT_LIST
ld [wInitListType], a ld [wInitListType], a
callfar InitList callfar InitList
ld hl, OTPartyMon1Species ld hl, OTPartyMon1Species
@ -1284,7 +1288,7 @@ LinkTrade_PlayerPartyMenu: ; 2888b
ld [wMenuCursorX], a ld [wMenuCursorX], a
ln a, 1, 0 ln a, 1, 0
ld [w2DMenuCursorOffsets], a ld [w2DMenuCursorOffsets], a
ld a, $20 ld a, MENU_UNUSED_3
ld [w2DMenuFlags1], a ld [w2DMenuFlags1], a
xor a xor a
ld [w2DMenuFlags2], a ld [w2DMenuFlags2], a
@ -1424,7 +1428,7 @@ Function28926: ; 28926
.show_stats .show_stats
pop af pop af
ld [wMenuCursorY], a ld [wMenuCursorY], a
ld a, $4 ld a, INIT_PLAYEROT_LIST
ld [wInitListType], a ld [wInitListType], a
callfar InitList callfar InitList
farcall LinkMonStatsScreen farcall LinkMonStatsScreen
@ -1478,7 +1482,7 @@ Function28926: ; 28926
ld a, [wd003] ld a, [wd003]
ld hl, OTPartySpecies ld hl, OTPartySpecies
ld c, a ld c, a
ld b, $0 ld b, 0
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
ld [wd265], a ld [wd265], a
@ -1583,9 +1587,9 @@ Function28b22: ; 28b22
xor a xor a
ld [rSB], a ld [rSB], a
ld [hSerialSend], a ld [hSerialSend], a
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ret ret
; 28b42 ; 28b42
@ -1639,14 +1643,14 @@ LinkTrade: ; 28b87
ld [wcf57], a ld [wcf57], a
ld [wOtherPlayerLinkAction], a ld [wOtherPlayerLinkAction], a
hlcoord 0, 12 hlcoord 0, 12
ld b, $4 ld b, 4
ld c, $12 ld c, 18
call LinkTextboxAtHL call LinkTextboxAtHL
farcall Link_WaitBGMap farcall Link_WaitBGMap
ld a, [wd002] ld a, [wd002]
ld hl, PartySpecies ld hl, PartySpecies
ld c, a ld c, a
ld b, $0 ld b, 0
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
ld [wd265], a ld [wd265], a
@ -1658,7 +1662,7 @@ LinkTrade: ; 28b87
ld a, [wd003] ld a, [wd003]
ld hl, OTPartySpecies ld hl, OTPartySpecies
ld c, a ld c, a
ld b, $0 ld b, 0
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
ld [wd265], a ld [wd265], a
@ -1749,7 +1753,7 @@ LinkTrade: ; 28b87
.asm_28c96 .asm_28c96
inc c inc c
ld a, c ld a, c
cp $6 cp PARTY_LENGTH
jr z, .asm_28ca6 jr z, .asm_28ca6
push bc push bc
ld bc, MAIL_STRUCT_LENGTH ld bc, MAIL_STRUCT_LENGTH
@ -1778,7 +1782,7 @@ LinkTrade: ; 28b87
call CopyBytes call CopyBytes
ld a, [wd002] ld a, [wd002]
ld hl, PartySpecies ld hl, PartySpecies
ld b, $0 ld b, 0
ld c, a ld c, a
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
@ -1818,7 +1822,7 @@ LinkTrade: ; 28b87
call CopyBytes call CopyBytes
ld a, [wd003] ld a, [wd003]
ld hl, OTPartySpecies ld hl, OTPartySpecies
ld b, $0 ld b, 0
ld c, a ld c, a
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
@ -1854,7 +1858,7 @@ LinkTrade: ; 28b87
ld a, [wd002] ld a, [wd002]
ld [CurPartyMon], a ld [CurPartyMon], a
ld hl, PartySpecies ld hl, PartySpecies
ld b, $0 ld b, 0
ld c, a ld c, a
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
@ -1865,12 +1869,12 @@ LinkTrade: ; 28b87
ld a, [PartyCount] ld a, [PartyCount]
dec a dec a
ld [CurPartyMon], a ld [CurPartyMon], a
ld a, $1 ld a, TRUE
ld [wForceEvolution], a ld [wForceEvolution], a
ld a, [wd003] ld a, [wd003]
push af push af
ld hl, OTPartySpecies ld hl, OTPartySpecies
ld b, $0 ld b, 0
ld c, a ld c, a
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
@ -1881,8 +1885,8 @@ LinkTrade: ; 28b87
call LoadFontsBattleExtra call LoadFontsBattleExtra
ld b, SCGB_DIPLOMA ld b, SCGB_DIPLOMA
call GetSGBLayout call GetSGBLayout
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp USING_EXTERNAL_CLOCK
jr z, .player_2 jr z, .player_2
predef TradeAnimation predef TradeAnimation
jr .done_animation jr .done_animation
@ -1895,7 +1899,7 @@ LinkTrade: ; 28b87
ld c, a ld c, a
ld [CurPartyMon], a ld [CurPartyMon], a
ld hl, OTPartySpecies ld hl, OTPartySpecies
ld d, $0 ld d, 0
ld e, a ld e, a
add hl, de add hl, de
ld a, [hl] ld a, [hl]
@ -1936,7 +1940,7 @@ LinkTrade: ; 28b87
ld a, b ld a, b
ld [wPlayerLinkAction], a ld [wPlayerLinkAction], a
push bc push bc
call Function862 call Serial_PrintWaitingTextAndSyncAndExchangeNybble
pop bc pop bc
ld a, [wLinkMode] ld a, [wLinkMode]
cp LINK_TIMECAPSULE cp LINK_TIMECAPSULE
@ -2113,7 +2117,7 @@ Function29c67: ; 29c67
sub b sub b
ld c, a ld c, a
inc c inc c
ld b, $0 ld b, 0
ld hl, PartyCount ld hl, PartyCount
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
@ -2140,24 +2144,24 @@ Special_WaitForOtherPlayerToExit: ; 29c92
ld c, 3 ld c, 3
call DelayFrames call DelayFrames
ld a, -1 ld a, -1
ld [hLinkPlayerNumber], a ld [hSerialConnectionStatus], a
xor a xor a
ld [rSB], a ld [rSB], a
ld [hSerialReceive], a ld [hSerialReceive], a
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld c, 3 ld c, 3
call DelayFrames call DelayFrames
xor a xor a
ld [rSB], a ld [rSB], a
ld [hSerialReceive], a ld [hSerialReceive], a
ld a, $0 ld a, (0 << rSC_ON) | 0
ld [rSC], a ld [rSC], a
ld a, $80 ld a, (1 << rSC_ON) | 0
ld [rSC], a ld [rSC], a
ld c, $3 ld c, 3
call DelayFrames call DelayFrames
xor a xor a
ld [rSB], a ld [rSB], a
@ -2166,7 +2170,7 @@ Special_WaitForOtherPlayerToExit: ; 29c92
ld c, 3 ld c, 3
call DelayFrames call DelayFrames
ld a, -1 ld a, -1
ld [hLinkPlayerNumber], a ld [hSerialConnectionStatus], a
ld a, [rIF] ld a, [rIF]
push af push af
xor a xor a
@ -2203,9 +2207,9 @@ Special_SetBitsForTimeCapsuleRequest: ; 29cfa
ld [rSB], a ld [rSB], a
xor a xor a
ld [hSerialReceive], a ld [hSerialReceive], a
ld a, $0 ld a, (0 << rSC_ON) | 0
ld [rSC], a ld [rSC], a
ld a, $80 ld a, (1 << rSC_ON) | 0
ld [rSC], a ld [rSC], a
xor a ; LINK_TIMECAPSULE - 1 xor a ; LINK_TIMECAPSULE - 1
ld [wPlayerLinkAction], a ld [wPlayerLinkAction], a
@ -2221,9 +2225,9 @@ Special_WaitForLinkedFriend: ; 29d11
ld [rSB], a ld [rSB], a
xor a xor a
ld [hSerialReceive], a ld [hSerialReceive], a
ld a, $0 ld a, (0 << rSC_ON) | 0
ld [rSC], a ld [rSC], a
ld a, $80 ld a, (1 << rSC_ON) | 0
ld [rSC], a ld [rSC], a
call DelayFrame call DelayFrame
call DelayFrame call DelayFrame
@ -2235,20 +2239,20 @@ Special_WaitForLinkedFriend: ; 29d11
ld a, $ff ld a, $ff
ld [wLinkTimeoutFrames], a ld [wLinkTimeoutFrames], a
.loop .loop
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
jr z, .connected jr z, .connected
cp $1 cp USING_EXTERNAL_CLOCK
jr z, .connected jr z, .connected
ld a, -1 ld a, CONNECTION_NOT_ESTABLISHED
ld [hLinkPlayerNumber], a ld [hSerialConnectionStatus], a
ld a, $2 ld a, $2
ld [rSB], a ld [rSB], a
xor a xor a
ld [hSerialReceive], a ld [hSerialReceive], a
ld a, $0 ld a, (0 << rSC_ON) | 0
ld [rSC], a ld [rSC], a
ld a, $80 ld a, (1 << rSC_ON) | 0
ld [rSC], a ld [rSC], a
ld a, [wLinkTimeoutFrames] ld a, [wLinkTimeoutFrames]
dec a dec a
@ -2262,9 +2266,9 @@ Special_WaitForLinkedFriend: ; 29d11
.not_done .not_done
ld a, $1 ld a, $1
ld [rSB], a ld [rSB], a
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
call DelayFrame call DelayFrame
jr .loop jr .loop
@ -2357,7 +2361,7 @@ Function29dba: ; 29dba
Link_CheckCommunicationError: ; 29e0c Link_CheckCommunicationError: ; 29e0c
xor a xor a
ld [hFFCA], a ld [hSerialReceivedNewData], a
ld a, [wLinkTimeoutFrames] ld a, [wLinkTimeoutFrames]
ld h, a ld h, a
ld a, [wLinkTimeoutFrames + 1] ld a, [wLinkTimeoutFrames + 1]
@ -2427,9 +2431,9 @@ Special_TryQuickSave: ; 29e66
ld a, [wd265] ld a, [wd265]
push af push af
farcall Link_SaveGame farcall Link_SaveGame
ld a, $1 ld a, TRUE
jr nc, .return_result jr nc, .return_result
xor a xor a ; FALSE
.return_result .return_result
ld [ScriptVar], a ld [ScriptVar], a
ld c, 30 ld c, 30
@ -2456,12 +2460,12 @@ Special_CheckBothSelectedSameRoom: ; 29e82
ld [wLinkMode], a ld [wLinkMode], a
xor a xor a
ld [hVBlank], a ld [hVBlank], a
ld a, $1 ld a, TRUE
ld [ScriptVar], a ld [ScriptVar], a
ret ret
.fail .fail
xor a xor a ; FALSE
ld [ScriptVar], a ld [ScriptVar], a
ret ret
; 29eaf ; 29eaf
@ -2517,8 +2521,8 @@ Special_FailedLinkToPast: ; 29efa
Link_ResetSerialRegistersAfterLinkClosure: ; 29f04 Link_ResetSerialRegistersAfterLinkClosure: ; 29f04
ld c, 3 ld c, 3
call DelayFrames call DelayFrames
ld a, -1 ld a, CONNECTION_NOT_ESTABLISHED
ld [hLinkPlayerNumber], a ld [hSerialConnectionStatus], a
ld a, $2 ld a, $2
ld [rSB], a ld [rSB], a
xor a xor a
@ -2536,7 +2540,7 @@ Link_EnsureSync: ; 29f17
call DelayFrame call DelayFrame
call DelayFrame call DelayFrame
.receive_loop .receive_loop
call Function83b call Serial_ExchangeLinkMenuSelection
ld a, [wOtherPlayerLinkMode] ld a, [wOtherPlayerLinkMode]
ld b, a ld b, a
and $f0 and $f0
@ -2557,11 +2561,11 @@ Link_EnsureSync: ; 29f17
; 29f47 ; 29f47
Special_CableClubCheckWhichChris: ; 29f47 Special_CableClubCheckWhichChris: ; 29f47
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp USING_EXTERNAL_CLOCK
ld a, $1 ld a, TRUE
jr z, .yes jr z, .yes
dec a dec a ; FALSE
.yes .yes
ld [ScriptVar], a ld [ScriptVar], a
@ -2575,7 +2579,7 @@ INCBIN "gfx/trade/unused_gen_1_border_tiles.2bpp"
Unreferenced_Function29fe4: Unreferenced_Function29fe4:
ld a, BANK(sPartyMail) ld a, BANK(sPartyMail)
call GetSRAMBank call GetSRAMBank
ld d, $0 ld d, FALSE
ld b, CHECK_FLAG ld b, CHECK_FLAG
predef SmallFarFlagAction predef SmallFarFlagAction
call CloseSRAM call CloseSRAM

View File

@ -56,7 +56,7 @@ LinkTextbox2: ; 4d35b
.PlaceBorder: ; 4d37e .PlaceBorder: ; 4d37e
push hl push hl
ld a, $76 ld a, "ぁ" ; $76
ld [hli], a ld [hli], a
inc a inc a
call .PlaceRow call .PlaceRow

View File

@ -139,7 +139,7 @@ _LoadTradeScreenBorder: ; 16d696
LinkComms_LoadPleaseWaitTextboxBorderGFX: ; 16d69a LinkComms_LoadPleaseWaitTextboxBorderGFX: ; 16d69a
ld de, LinkCommsBorderGFX + $30 tiles ld de, LinkCommsBorderGFX + $30 tiles
ld hl, vTiles2 tile $76 ld hl, vTiles2 tile "ぁ"
lb bc, BANK(LinkCommsBorderGFX), 8 lb bc, BANK(LinkCommsBorderGFX), 8
call Get2bpp call Get2bpp
ret ret

View File

@ -32,7 +32,7 @@ _Start:: ; 16e
.load .load
ld [hCGB], a ld [hCGB], a
ld a, $1 ld a, $1
ld [hFFEA], a ld [hSystemBooted], a
; 17d ; 17d
@ -84,14 +84,14 @@ Init:: ; 17d
; Clear HRAM ; Clear HRAM
ld a, [hCGB] ld a, [hCGB]
push af push af
ld a, [hFFEA] ld a, [hSystemBooted]
push af push af
xor a xor a
ld hl, HRAM_Begin ld hl, HRAM_Begin
ld bc, HRAM_End - HRAM_Begin ld bc, HRAM_End - HRAM_Begin
call ByteFill call ByteFill
pop af pop af
ld [hFFEA], a ld [hSystemBooted], a
pop af pop af
ld [hCGB], a ld [hCGB], a
@ -137,7 +137,7 @@ Init:: ; 17d
ld [rLCDC], a ld [rLCDC], a
ld a, -1 ld a, -1
ld [hLinkPlayerNumber], a ld [hSerialConnectionStatus], a
farcall InitCGBPals farcall InitCGBPals

View File

@ -1352,7 +1352,7 @@ UpdateBGMapRow:: ; 27d3
dec c dec c
jr nz, .loop jr nz, .loop
ld a, SCREEN_WIDTH ld a, SCREEN_WIDTH
ld [hFFDC], a ld [hBGMapTileCount], a
ret ret
; 27f8 ; 27f8
@ -1379,7 +1379,7 @@ UpdateBGMapColumn:: ; 27f8
dec c dec c
jr nz, .loop jr nz, .loop
ld a, SCREEN_HEIGHT ld a, SCREEN_HEIGHT
ld [hFFDC], a ld [hBGMapTileCount], a
ret ret
; 2816 ; 2816

View File

@ -14,9 +14,9 @@ Serial:: ; 6ef
bit 0, a bit 0, a
jr nz, .printer jr nz, .printer
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
inc a ; is it equal to -1? inc a ; is it equal to CONNECTION_NOT_ESTABLISHED?
jr z, .init_player_number jr z, .establish_connection
ld a, [rSB] ld a, [rSB]
ld [hSerialReceive], a ld [hSerialReceive], a
@ -24,8 +24,8 @@ Serial:: ; 6ef
ld a, [hSerialSend] ld a, [hSerialSend]
ld [rSB], a ld [rSB], a
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
jr z, .player2 jr z, .player2
ld a, 0 << rSC_ON ld a, 0 << rSC_ON
@ -42,22 +42,22 @@ Serial:: ; 6ef
call PrinterReceive call PrinterReceive
jr .end jr .end
.init_player_number .establish_connection
ld a, [rSB] ld a, [rSB]
cp $1 cp USING_EXTERNAL_CLOCK
jr z, .player1 jr z, .player1
cp $2 cp USING_INTERNAL_CLOCK
jr nz, .player2 jr nz, .player2
.player1 .player1
ld [hSerialReceive], a ld [hSerialReceive], a
ld [hLinkPlayerNumber], a ld [hSerialConnectionStatus], a
cp $2 cp USING_INTERNAL_CLOCK
jr z, ._player2 jr z, ._player2
xor a xor a
ld [rSB], a ld [rSB], a
ld a, $3 ld a, 3
ld [rDIV], a ld [rDIV], a
.wait_bit_7 .wait_bit_7
@ -76,9 +76,9 @@ Serial:: ; 6ef
ld [rSB], a ld [rSB], a
.player2 .player2
ld a, $1 ld a, TRUE
ld [hFFCA], a ld [hSerialReceivedNewData], a
ld a, $fe ld a, SERIAL_NO_DATA_BYTE
ld [hSerialSend], a ld [hSerialSend], a
.end .end
@ -89,13 +89,13 @@ Serial:: ; 6ef
reti reti
; 75f ; 75f
Function75f:: ; 75f Serial_ExchangeBytes:: ; 75f
ld a, $1 ld a, $1
ld [hFFCC], a ld [hSerialIgnoringInitialData], a
.loop .loop
ld a, [hl] ld a, [hl]
ld [hSerialSend], a ld [hSerialSend], a
call Function78a call Serial_ExchangeByte
push bc push bc
ld b, a ld b, a
inc hl inc hl
@ -103,16 +103,16 @@ Function75f:: ; 75f
.wait .wait
dec a dec a
jr nz, .wait jr nz, .wait
ld a, [hFFCC] ld a, [hSerialIgnoringInitialData]
and a and a
ld a, b ld a, b
pop bc pop bc
jr z, .load jr z, .load
dec hl dec hl
cp $fd cp SERIAL_PREAMBLE_BYTE
jr nz, .loop jr nz, .loop
xor a xor a
ld [hFFCC], a ld [hSerialIgnoringInitialData], a
jr .loop jr .loop
.load .load
@ -125,24 +125,24 @@ Function75f:: ; 75f
ret ret
; 78a ; 78a
Function78a:: ; 78a Serial_ExchangeByte:: ; 78a
.loop .loop
xor a xor a
ld [hFFCA], a ld [hSerialReceivedNewData], a
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
jr nz, .not_player_2 jr nz, .not_player_2
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
.not_player_2 .not_player_2
.loop2 .loop2
ld a, [hFFCA] ld a, [hSerialReceivedNewData]
and a and a
jr nz, .reset_ffca jr nz, .reset_ffca
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp USING_EXTERNAL_CLOCK
jr nz, .not_player_1_or_wLinkTimeoutFrames_zero jr nz, .not_player_1_or_wLinkTimeoutFrames_zero
call CheckwLinkTimeoutFramesNonzero call CheckwLinkTimeoutFramesNonzero
jr z, .not_player_1_or_wLinkTimeoutFrames_zero jr z, .not_player_1_or_wLinkTimeoutFrames_zero
@ -162,8 +162,8 @@ Function78a:: ; 78a
.not_player_1_or_wLinkTimeoutFrames_zero .not_player_1_or_wLinkTimeoutFrames_zero
ld a, [rIE] ld a, [rIE]
and $f and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
cp $8 cp 1 << SERIAL
jr nz, .loop2 jr nz, .loop2
ld a, [wcf5d] ld a, [wcf5d]
dec a dec a
@ -173,8 +173,8 @@ Function78a:: ; 78a
dec a dec a
ld [wcf5d + 1], a ld [wcf5d + 1], a
jr nz, .loop2 jr nz, .loop2
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $1 cp USING_EXTERNAL_CLOCK
jr z, .reset_ffca jr z, .reset_ffca
ld a, 255 ld a, 255
@ -184,19 +184,20 @@ Function78a:: ; 78a
.reset_ffca .reset_ffca
xor a xor a
ld [hFFCA], a ld [hSerialReceivedNewData], a
ld a, [rIE] ld a, [rIE]
and $f and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
sub $8 sub 1 << SERIAL
jr nz, .rIE_not_equal_8 jr nz, .rIE_not_equal_8
; LOW($5000)
ld [wcf5d], a ld [wcf5d], a
ld a, $50 ld a, HIGH($5000)
ld [wcf5d + 1], a ld [wcf5d + 1], a
.rIE_not_equal_8 .rIE_not_equal_8
ld a, [hSerialReceive] ld a, [hSerialReceive]
cp $fe cp SERIAL_NO_DATA_BYTE
ret nz ret nz
call CheckwLinkTimeoutFramesNonzero call CheckwLinkTimeoutFramesNonzero
jr z, .wLinkTimeoutFrames_zero jr z, .wLinkTimeoutFrames_zero
@ -216,9 +217,9 @@ Function78a:: ; 78a
.wLinkTimeoutFrames_zero .wLinkTimeoutFrames_zero
ld a, [rIE] ld a, [rIE]
and $f and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
cp $8 cp 1 << SERIAL
ld a, $fe ld a, SERIAL_NO_DATA_BYTE
ret z ret z
ld a, [hl] ld a, [hl]
ld [hSerialSend], a ld [hSerialSend], a
@ -243,29 +244,31 @@ CheckwLinkTimeoutFramesNonzero:: ; 82b
; 833 ; 833
SerialDisconnected:: ; 833 SerialDisconnected:: ; 833
dec a dec a ; a is always 0 when this is called
ld [wLinkTimeoutFrames], a ld [wLinkTimeoutFrames], a
ld [wLinkTimeoutFrames + 1], a ld [wLinkTimeoutFrames + 1], a
ret ret
; 83b ; 83b
Function83b:: ; 83b ; This is used to exchange the button press and selected menu item on the link menu.
; The data is sent thrice and read twice to increase reliability.
Serial_ExchangeLinkMenuSelection:: ; 83b
ld hl, wPlayerLinkAction ld hl, wPlayerLinkAction
ld de, wOtherPlayerLinkMode ld de, wOtherPlayerLinkMode
ld c, $2 ld c, 2
ld a, $1 ld a, TRUE
ld [hFFCC], a ld [hSerialIgnoringInitialData], a
.asm_847 .asm_847
call DelayFrame call DelayFrame
ld a, [hl] ld a, [hl]
ld [hSerialSend], a ld [hSerialSend], a
call Function78a call Serial_ExchangeByte
ld b, a ld b, a
inc hl inc hl
ld a, [hFFCC] ld a, [hSerialIgnoringInitialData]
and a and a
ld a, $0 ld a, FALSE
ld [hFFCC], a ld [hSerialIgnoringInitialData], a
jr nz, .asm_847 jr nz, .asm_847
ld a, b ld a, b
ld [de], a ld [de], a
@ -275,15 +278,14 @@ Function83b:: ; 83b
ret ret
; 862 ; 862
Function862:: ; 862 Serial_PrintWaitingTextAndSyncAndExchangeNybble:: ; 862
call LoadTileMapToTempTileMap call LoadTileMapToTempTileMap
callfar PlaceWaitingText callfar PlaceWaitingText
call WaitLinkTransfer call WaitLinkTransfer
jp Call_LoadTempTileMapToTileMap jp Call_LoadTempTileMapToTileMap
; 871 ; 871
Serial_SyncAndExchangeNybble:: ; 871
Function871:: ; 871
call LoadTileMapToTempTileMap call LoadTileMapToTempTileMap
callfar PlaceWaitingText callfar PlaceWaitingText
jp WaitLinkTransfer jp WaitLinkTransfer
@ -356,12 +358,12 @@ LinkTransfer:: ; 8c1
ld a, [wPlayerLinkAction] ld a, [wPlayerLinkAction]
add b add b
ld [hSerialSend], a ld [hSerialSend], a
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
jr nz, .player_1 jr nz, .player_1
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
.player_1 .player_1
@ -388,12 +390,12 @@ LinkDataReceived:: ; 908
; Let the other system know that the data has been received. ; Let the other system know that the data has been received.
xor a xor a
ld [hSerialSend], a ld [hSerialSend], a
ld a, [hLinkPlayerNumber] ld a, [hSerialConnectionStatus]
cp $2 cp USING_INTERNAL_CLOCK
ret nz ret nz
ld a, $1 ld a, (0 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ld a, $81 ld a, (1 << rSC_ON) | 1
ld [rSC], a ld [rSC], a
ret ret
; 919 ; 919
@ -402,13 +404,13 @@ Unreferenced_Function919:: ; 919
ld a, [wLinkMode] ld a, [wLinkMode]
and a and a
ret nz ret nz
ld a, $2 ld a, USING_INTERNAL_CLOCK
ld [rSB], a ld [rSB], a
xor a xor a
ld [hSerialReceive], a ld [hSerialReceive], a
ld a, $0 ld a, 0 << rSC_ON
ld [rSC], a ld [rSC], a
ld a, $80 ld a, 1 << rSC_ON
ld [rSC], a ld [rSC], a
ret ret
; 92e ; 92e

View File

@ -20,10 +20,10 @@ DMATransfer:: ; 15d8
UpdateBGMapBuffer:: ; 15e3 UpdateBGMapBuffer:: ; 15e3
; Copy [hFFDC] 16x8 tiles from BGMapBuffer ; Copy [hBGMapTileCount] 16x8 tiles from BGMapBuffer
; to bg map addresses in BGMapBufferPtrs. ; to bg map addresses in BGMapBufferPtrs.
; [hFFDC] must be even since this is done in pairs. ; [hBGMapTileCount] must be even since this is done in pairs.
; Return carry on success. ; Return carry on success.
@ -76,10 +76,10 @@ rept 2
endr endr
; We've done 2 16x8 blocks ; We've done 2 16x8 blocks
ld a, [hFFDC] ld a, [hBGMapTileCount]
dec a dec a
dec a dec a
ld [hFFDC], a ld [hBGMapTileCount], a
jr nz, .next jr nz, .next

View File

@ -39,6 +39,7 @@ hInMenu EQU $ffaa
hPrinter EQU $ffac hPrinter EQU $ffac
hGraphicStartTile EQU $ffad hGraphicStartTile EQU $ffad
hMoveMon EQU $ffae hMoveMon EQU $ffae
hMapObjectIndexBuffer EQU $ffaf hMapObjectIndexBuffer EQU $ffaf
hObjectStructIndexBuffer EQU $ffb0 hObjectStructIndexBuffer EQU $ffb0
@ -88,10 +89,11 @@ hMGJoypadReleased EQU $ffc4
hLCDCPointer EQU $ffc6 hLCDCPointer EQU $ffc6
hLYOverrideStart EQU $ffc7 hLYOverrideStart EQU $ffc7
hLYOverrideEnd EQU $ffc8 hLYOverrideEnd EQU $ffc8
hMobileReceive EQU $ffc9 hMobileReceive EQU $ffc9
hFFCA EQU $ffca hSerialReceivedNewData EQU $ffca
hLinkPlayerNumber EQU $ffcb hSerialConnectionStatus EQU $ffcb
hFFCC EQU $ffcc hSerialIgnoringInitialData EQU $ffcc
hSerialSend EQU $ffcd hSerialSend EQU $ffcd
hSerialReceive EQU $ffce hSerialReceive EQU $ffce
@ -108,7 +110,7 @@ hOAMUpdate EQU $ffd8
hSPBuffer EQU $ffd9 hSPBuffer EQU $ffd9
hBGMapUpdate EQU $ffdb hBGMapUpdate EQU $ffdb
hFFDC EQU $ffdc hBGMapTileCount EQU $ffdc
hMapAnims EQU $ffde hMapAnims EQU $ffde
hTileAnimFrame EQU $ffdf hTileAnimFrame EQU $ffdf
@ -125,5 +127,5 @@ hCGB EQU $ffe6
hSGB EQU $ffe7 hSGB EQU $ffe7
hDMATransfer EQU $ffe8 hDMATransfer EQU $ffe8
hMobile EQU $ffe9 hMobile EQU $ffe9
hFFEA EQU $ffea hSystemBooted EQU $ffea
hClockResetTrigger EQU $ffeb hClockResetTrigger EQU $ffeb

View File

@ -4056,7 +4056,7 @@ _StartMobileBattle: ; 1019ab
jr z, .got_link_player_number jr z, .got_link_player_number
ld a, 1 ld a, 1
.got_link_player_number .got_link_player_number
ld [hLinkPlayerNumber], a ld [hSerialConnectionStatus], a
ret ret
; 101a21 ; 101a21
@ -4076,7 +4076,7 @@ StartMobileBattle: ; 101a21
xor a xor a
ld [wDisableTextAcceleration], a ld [wDisableTextAcceleration], a
ld a, $ff ld a, $ff
ld [hLinkPlayerNumber], a ld [hSerialConnectionStatus], a
pop af pop af
ld [Options], a ld [Options], a
ret ret

View File

@ -4,7 +4,7 @@ Unreferenced_Function16c000: ; 16c000
and a and a
ret z ret z
; Only do this once per boot cycle ; Only do this once per boot cycle
ld a, [hFFEA] ld a, [hSystemBooted]
and a and a
ret z ret z
; Set some flag, preserving the old state ; Set some flag, preserving the old state
@ -19,9 +19,9 @@ Unreferenced_Function16c000: ; 16c000
call .RunJumptable call .RunJumptable
farcall DisableMobile farcall DisableMobile
; Prevent this routine from running again ; Prevent this routine from running again
; until the next time the syatem is turned on ; until the next time the system is turned on
xor a xor a
ld [hFFEA], a ld [hSystemBooted], a
; Restore the flag state ; Restore the flag state
pop af pop af
ld [wcfbe], a ld [wcfbe], a