Document link patch lists a little bit better

This commit is contained in:
mid-kid 2023-03-30 21:05:07 +02:00
parent 2fc7d17851
commit 08cfbbb1d9
3 changed files with 42 additions and 34 deletions

View File

@ -19,8 +19,10 @@ DEF USING_EXTERNAL_CLOCK EQU $01
DEF USING_INTERNAL_CLOCK EQU $02
DEF CONNECTION_NOT_ESTABLISHED EQU $ff
; length of a patch list (less than any of the signal bytes)
DEF SERIAL_PATCH_LIST_LENGTH EQU $fc
; length of a patch list
DEF SERIAL_PATCH_LIST_LENGTH EQU 200
; size of the patch area (offsets into this area may not have special values)
DEF SERIAL_PATCH_DATA_SIZE EQU $fc
; signals the start of an array of bytes transferred over the link cable
DEF SERIAL_PREAMBLE_BYTE EQU $fd
; this byte is used when there is no data to send

View File

@ -98,7 +98,7 @@ endc
ld hl, wPlayerPatchLists
ld de, wOTPatchLists
ld bc, 200
ld bc, SERIAL_PATCH_LIST_LENGTH
vc_hook Wireless_ExchangeBytes_Gen2toGen1_patch_lists
call Serial_ExchangeBytes
@ -126,7 +126,7 @@ endc
call Link_CopyOTData
ld de, wOTPatchLists
ld hl, wLinkPatchList1
ld hl, wLinkPatchData1
ld c, 2
.loop
ld a, [de]
@ -152,7 +152,7 @@ endc
jr .loop
.next
ld hl, wLinkPatchList2
ld hl, wLinkPatchData2
dec c
jr nz, .loop
@ -264,7 +264,7 @@ endc
ld hl, wPlayerPatchLists
ld de, wOTPatchLists
ld bc, 200
ld bc, SERIAL_PATCH_LIST_LENGTH
vc_hook Wireless_ExchangeBytes_patch_lists
call Serial_ExchangeBytes
@ -294,7 +294,7 @@ endc
call Link_CopyOTData
ld de, wPlayerTrademon
ld hl, wLinkPatchList1
ld hl, wLinkPatchData1
ld c, 2
.loop1
ld a, [de]
@ -320,7 +320,7 @@ endc
jr .loop1
.next1
ld hl, wLinkPatchList2
ld hl, wLinkPatchData2
dec c
jr nz, .loop1
@ -615,6 +615,7 @@ FixDataForLinkTransfer:
dec b
jr nz, .preamble_loop
; Initialize random seed, making sure special bytes are omitted
assert wLinkBattleRNPreamble + SERIAL_RN_PREAMBLE_LENGTH == wLinkBattleRNs
ld b, SERIAL_RNS_LENGTH
.rn_loop
@ -625,60 +626,66 @@ FixDataForLinkTransfer:
dec b
jr nz, .rn_loop
; Clear the patch list
ld hl, wPlayerPatchLists
ld a, SERIAL_PREAMBLE_BYTE
ld [hli], a
ld [hli], a
ld [hli], a
ld b, 200
ld b, SERIAL_PATCH_LIST_LENGTH
xor a
.loop1
.clear_loop
ld [hli], a
dec b
jr nz, .loop1
jr nz, .clear_loop
ld hl, (wLinkData + SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + 1 + PARTY_LENGTH + 1) - 1
ld de, wPlayerPatchLists + 10 ; ???
; 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 ; ???
lb bc, 0, 0
.loop2
.patch_loop
; Check if we've gone over the entire area
inc c
ld a, c
cp SERIAL_PATCH_LIST_LENGTH + 1
jr z, .next1
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
ld a, b
dec a
jr nz, .next2
jr nz, .process
push bc
ld a, [wLinkMode]
cp LINK_TIMECAPSULE
ld b, REDMON_STRUCT_LENGTH * PARTY_LENGTH - SERIAL_PATCH_LIST_LENGTH + 1
jr z, .got_value
ld b, 2 + PARTYMON_STRUCT_LENGTH * PARTY_LENGTH - SERIAL_PATCH_LIST_LENGTH + 1
.got_value
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
ld a, c
cp b
pop bc
jr z, .done
.next2
jr z, .data2_done
.process
; Replace the "no data" byte, and record it in the array
inc hl
ld a, [hl]
cp SERIAL_NO_DATA_BYTE
jr nz, .loop2
jr nz, .patch_loop
ld a, c
ld [de], a
inc de
ld [hl], SERIAL_PATCH_REPLACEMENT_BYTE
jr .loop2
jr .patch_loop
.next1
.data1_done
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a
inc de
lb bc, 1, 0
jr .loop2
jr .patch_loop
.done
.data2_done
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a
ret
@ -994,7 +1001,6 @@ Link_PrepPartyData_Gen2:
inc hl
dec b
jr nz, .loop6
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a
ret

View File

@ -617,8 +617,8 @@ wBattleEnd::
SECTION UNION "Miscellaneous", WRAM0
; link patch lists
wPlayerPatchLists:: ds 200
wOTPatchLists:: ds 200
wPlayerPatchLists:: ds SERIAL_PATCH_LIST_LENGTH
wOTPatchLists:: ds SERIAL_PATCH_LIST_LENGTH
SECTION UNION "Miscellaneous", WRAM0
@ -1008,8 +1008,8 @@ endr
NEXTU
; link patch lists
wLinkPatchList1:: ds SERIAL_PATCH_LIST_LENGTH
wLinkPatchList2:: ds SERIAL_PATCH_LIST_LENGTH
wLinkPatchData1:: ds SERIAL_PATCH_DATA_SIZE
wLinkPatchData2:: ds SERIAL_PATCH_DATA_SIZE
ENDU