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 USING_INTERNAL_CLOCK EQU $02
DEF CONNECTION_NOT_ESTABLISHED EQU $ff DEF CONNECTION_NOT_ESTABLISHED EQU $ff
; length of a patch list (less than any of the signal bytes) ; length of a patch list
DEF SERIAL_PATCH_LIST_LENGTH EQU $fc 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 ; signals the start of an array of bytes transferred over the link cable
DEF SERIAL_PREAMBLE_BYTE EQU $fd DEF SERIAL_PREAMBLE_BYTE EQU $fd
; this byte is used when there is no data to send ; this byte is used when there is no data to send

View File

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

View File

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