'variables used for Manchester encoding
Dim B0 As Byte
Dim Man_word As Dword
Dim B4 As Byte At Man_word + 0 Overlay
Dim B3 As Byte At Man_word + 1 Overlay
Dim B2 As Byte At Man_word + 2 Overlay
Dim B1 As Byte At Man_word + 3 Overlay
Manchester_encode:
'B0 has the byte to encode
'b1..b4 overlay over man_word
'when man_word has been shifted left 16 times then B1=0, loop is done
'and B0's complement and B0 have been shifted interleaved into B2 and B3
'later decoding is done in a similar way
' B1 B2 B3 B4
Man_word = &B11111111_11111111_00000000_00000000
B4 = B0 Xor &B11111111 'C's complement
Do
Shift Man_word , Left , 1 'shift in a bit of B0's complement
Swap B0 , B4
Shift Man_word , Left , 1 'shift in a bit of B0
Swap B0 , B4
Loop Until B1 = 0 'Loop Until B1 = 0
Return
Manchester_decode:
'b1..b4 overlay over man_word
'manchester bytes placed in b2 and b3
'when man_word has been shifted right 16 times B1=0,b2=0
'B4 will have the original byte, B0 has it's complement
'After XOR B4 B0, If there were illegal bits, B1 will be <> 255
B1 = &B11111111
'B0 and B4 do not need initialising
Do
Shift Man_word , Right , 1 'shift 1 oiginal bit into B4
Swap B0 , B4
Shift Man_word , Right , 1 'shift 1 complement bit into B0
Swap B0 , B4
Loop Until B1 = 0 And B2 = 0
B1 = B4 Xor B0 'if errorbits, b1<>255
Return |