Skip to content

Commit

Permalink
Verify that we match ddnet in 0.6 chunk header packing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Dec 22, 2024
1 parent 8f5a380 commit f3868c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/chunk_packer6.asm
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ pack_chunk_header6:
; if sequence is bigger than 8 bit
mov r8, 0
mov r8d, dword [connection_sequence]
shr r8, 2
and r8, 0b11110000
shr r8b, 2
and r8b, 0b11110000
; teeworlds uses 11110000
; and ddnet uses 11111100
or byte [rsi+1], r8b

; full 8 bit sequence into third byte
Expand Down
40 changes: 18 additions & 22 deletions tests/chunk6_test.asm
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,24 @@ test_pack_chunk_header6_size23_seq3:
mov al, [assert_actual_buf + 2]
assert_al_eq 0x03, __LINE__

test_pack_chunk_header6_size0_seqFF:
mov dword [connection_sequence], 255

; test_pack_chunk_header6_size6_seq65:
; mov dword [connection_sequence], 65
;
; ; tested with twnet_parser
; ; header: ChunkHeader = parser.parse_header6(b'\x40\x16\x01')
; ; assert header.flags.resend is False
; ; assert header.flags.vital is True
; ; assert header.size == 6
; ; assert header.seq == 65
;
; mov rax, 0
; set_rax_flag CHUNKFLAG_VITAL
; mov rdi, 6
; mov rsi, assert_actual_buf
; call pack_chunk_header6
;
; mov al, [assert_actual_buf]
; assert_al_eq 0x40, __LINE__
; mov al, [assert_actual_buf + 1]
; assert_al_eq 0x16, __LINE__
; mov al, [assert_actual_buf + 2]
; assert_al_eq 0x01, __LINE__
; does not match twnet_parser
; but twnet_parser might be "wrong" in that case
; see https://gitlab.com/teeworlds-network/twnet_parser/-/commit/52a66b5eebc0b337f2eb30cf4cffbe55af63c85f
mov rax, 0
set_rax_flag CHUNKFLAG_VITAL
mov rdi, 0 ; size
mov rsi, assert_actual_buf
call pack_chunk_header6

mov al, [assert_actual_buf]
assert_al_eq 0x40, __LINE__

mov al, [assert_actual_buf + 1]
assert_al_eq 0x30, __LINE__ ; this is weird but matches ddnet https://github.com/ddnet/ddnet/pull/9417
mov al, [assert_actual_buf + 2]
assert_al_eq 0xff, __LINE__

end_test __LINE__

0 comments on commit f3868c1

Please sign in to comment.