summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2020-11-02 19:32:12 -0500
committerRangi <remy.oukaour+rangi42@gmail.com>2020-11-02 19:32:12 -0500
commit980153ac472870602a51779dbff623ea0072ed98 (patch)
tree2b2dff050cd78bbab58e9f8af7d5baaada22e1ff
parent356aa1a0c394124579f5fbc80981260fa4fc5d5a (diff)
Group some link.asm code into "paragraphs"
-rw-r--r--engine/link/link.asm51
-rw-r--r--home/serial.asm1
2 files changed, 44 insertions, 8 deletions
diff --git a/engine/link/link.asm b/engine/link/link.asm
index 37338ea9..2a59e99d 100644
--- a/engine/link/link.asm
+++ b/engine/link/link.asm
@@ -71,27 +71,33 @@ Gen2ToGen1LinkComms:
ldh [rIF], a
ld a, 1 << SERIAL
ldh [rIE], a
+
ld hl, wLinkBattleRNPreamble
- ld de, wEnemyMonSpecies
+ ld de, wEnemyMon
ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
ld [de], a
+
ld hl, wLinkData
ld de, wOTPlayerName
ld bc, $1a8
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
ld [de], a
+
ld hl, wc508
ld de, wTrademons
ld bc, 200
call Serial_ExchangeBytes
+
xor a
ldh [rIF], a
ld a, (1 << JOYPAD) | (1 << SERIAL) | (1 << TIMER) | (1 << VBLANK)
ldh [rIE], a
+
call Link_CopyRandomNumbers
+
ld hl, wOTPlayerName
call Link_FindFirstNonControlCharacter_SkipZero
push hl
@@ -103,9 +109,11 @@ Gen2ToGen1LinkComms:
jp z, ExitLinkCommunications
cp $7
jp nc, ExitLinkCommunications
+
ld de, wLinkData
ld bc, $1a2
call Link_CopyOTData
+
ld de, wPlayerTrademon
ld hl, wTimeCapsulePlayerData
ld c, 2
@@ -136,10 +144,12 @@ Gen2ToGen1LinkComms:
ld hl, wc80f
dec c
jr nz, .loop
+
ld hl, wLinkPlayerName
ld de, wOTPlayerName
ld bc, NAME_LENGTH
call CopyBytes
+
ld de, wOTPartyCount
ld a, [hli]
ld [de], a
@@ -163,10 +173,12 @@ Gen2ToGen1LinkComms:
ld [de], a
ld hl, wTimeCapsulePlayerData
call Link_ConvertPartyStruct1to2
+
ld a, LOW(wOTPartyMonOT)
ld [wUnusedNamesPointer], a
ld a, HIGH(wOTPartyMonOT)
ld [wUnusedNamesPointer + 1], a
+
ld de, MUSIC_NONE
call PlayMusic
ldh a, [hSerialConnectionStatus]
@@ -187,7 +199,7 @@ Gen2ToGen2LinkComms:
jp z, LinkTimeout
ldh a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
- jr nz, .Player1
+ jr nz, .player_1
ld c, 3
call DelayFrames
@@ -206,7 +218,7 @@ Gen2ToGen2LinkComms:
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
ldh [rSC], a
-.Player1:
+.player_1
ld de, MUSIC_NONE
call PlayMusic
ld c, 3
@@ -215,22 +227,26 @@ Gen2ToGen2LinkComms:
ldh [rIF], a
ld a, 1 << SERIAL
ldh [rIE], a
+
ld hl, wLinkBattleRNPreamble
- ld de, wEnemyMonSpecies
+ ld de, wEnemyMon
ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
ld [de], a
+
ld hl, wLinkData
ld de, wOTPlayerName
ld bc, $1c2
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
ld [de], a
+
ld hl, wc508
ld de, wTrademons
ld bc, 200
call Serial_ExchangeBytes
+
ld a, [wLinkMode]
cp LINK_TRADECENTER
jr nz, .not_trading
@@ -246,12 +262,15 @@ Gen2ToGen2LinkComms:
ldh [rIE], a
ld de, MUSIC_NONE
call PlayMusic
+
call Link_CopyRandomNumbers
+
ld hl, wOTPlayerName
call Link_FindFirstNonControlCharacter_SkipZero
ld de, wLinkData
ld bc, $1b9
call Link_CopyOTData
+
ld de, wPlayerTrademon
ld hl, wLinkPlayerData
ld c, 2
@@ -282,6 +301,7 @@ Gen2ToGen2LinkComms:
ld hl, wc80f
dec c
jr nz, .loop1
+
ld a, [wLinkMode]
cp LINK_TRADECENTER
jr nz, .skip_mail
@@ -368,19 +388,24 @@ Gen2ToGen2LinkComms:
ld de, wOTPlayerName
ld bc, NAME_LENGTH
call CopyBytes
+
ld de, wOTPartyCount
ld bc, 1 + PARTY_LENGTH + 1
call CopyBytes
+
ld de, wOTPlayerID
ld bc, 2
call CopyBytes
+
ld de, wOTPartyMons
ld bc, wOTPartyDataEnd - wOTPartyMons
call CopyBytes
+
ld a, LOW(wOTPartyMonOT)
ld [wUnusedNamesPointer], a
ld a, HIGH(wOTPartyMonOT)
ld [wUnusedNamesPointer + 1], a
+
ld de, MUSIC_NONE
call PlayMusic
ldh a, [hSerialConnectionStatus]
@@ -587,9 +612,11 @@ Link_PrepPartyData_Gen1:
inc de
dec b
jr nz, .loop1
+
ld hl, wPlayerName
ld bc, NAME_LENGTH
call CopyBytes
+
push de
ld hl, wPartyCount
ld a, [hli]
@@ -609,12 +636,12 @@ Link_PrepPartyData_Gen1:
ld [de], a
inc de
jr .loop2
-
.done_party
ld [de], a
pop de
ld hl, 1 + PARTY_LENGTH + 1
add hl, de
+
ld d, h
ld e, l
ld hl, wPartyMon1Species
@@ -627,8 +654,10 @@ Link_PrepPartyData_Gen1:
pop bc
dec c
jr nz, .mon_loop
+
ld hl, wPartyMonOT
call .copy_ot_nicks
+
ld hl, wPartyMonNicknames
.copy_ot_nicks
ld bc, PARTY_LENGTH * NAME_LENGTH
@@ -753,21 +782,27 @@ Link_PrepPartyData_Gen2:
inc de
dec b
jr nz, .loop1
+
ld hl, wPlayerName
ld bc, NAME_LENGTH
call CopyBytes
+
ld hl, wPartyCount
ld bc, 1 + PARTY_LENGTH + 1
call CopyBytes
+
ld hl, wPlayerID
ld bc, 2
call CopyBytes
+
ld hl, wPartyMon1Species
ld bc, PARTY_LENGTH * PARTYMON_STRUCT_LENGTH
call CopyBytes
+
ld hl, wPartyMonOT
ld bc, PARTY_LENGTH * NAME_LENGTH
call CopyBytes
+
ld hl, wPartyMonNicknames
ld bc, PARTY_LENGTH * MON_NAME_LENGTH
call CopyBytes
@@ -808,8 +843,8 @@ Link_PrepPartyData_Gen2:
pop bc
dec b
jr nz, .loop3
-
call CloseSRAM
+
ld hl, wc8f9
ld bc, PARTY_LENGTH * (sPartyMon1MailAuthor - sPartyMon1Mail)
.loop4
@@ -817,13 +852,13 @@ Link_PrepPartyData_Gen2:
cp SERIAL_NO_DATA_BYTE
jr nz, .skip2
ld [hl], sPartyMon1MailAuthor - sPartyMon1Mail
-
.skip2
inc hl
dec bc
ld a, b
or c
jr nz, .loop4
+
ld hl, wc9bf
ld de, wca13
ld b, PARTY_LENGTH * (sPartyMon1MailEnd - sPartyMon1MailAuthor)
@@ -837,11 +872,11 @@ Link_PrepPartyData_Gen2:
ld a, c
ld [de], a
inc de
-
.skip3
inc hl
dec b
jr nz, .loop5
+
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a
ret
diff --git a/home/serial.asm b/home/serial.asm
index 0e42b9c0..808111d5 100644
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -81,6 +81,7 @@ Serial::
reti
Serial_ExchangeBytes::
+; send bc bytes from hl, receive bc bytes to de
ld a, TRUE
ldh [hSerialIgnoringInitialData], a