// File: ke6jjj[P]r-dat/DDSGroup1.cc
// Function: DDSGroup1::DDSGroup1(DDSGroup3&)
DDSGroup1::DDSGroup1(DDSGroup3& g3)
  : mBasicGroupID(g3.BasicGroupID()), mSubFrameID(g3.LogicalFrameID()),
    mIsECCFrame(g3.IsECC3Frame()), mIsLastFrame(g3.IsLastLogicalFrame())
{
  //
  // The data in the G3 is a G2 group wrapper with a header row. The G2
  // group is a G1 group with a data whitening LFSR stream added to it.
  // We need to remove that whitening as we write the data out.
  //
  
  //
  // Fetch a pointer to the data and validity arrays of the G3 frame.
  //
  const DATFrame::DataArray& data = g3.Frame().Data();
  const DATFrame::ValidityArray& valid = g3.Frame().Valid();
  
  uint16_t lfsr = 1;
  
  for (size_t i = 1; i < DATFrame::kUserDataRows; i++) {
    for (size_t j = 0; j < DATFrame::kBytesPerRow; j++) {
      //
      // Look up the data.
      //
      uint8_t byte = data[i][j];
      
      //
      // Dewhiten it.
      //
      byte ^= (lfsr & 0xff);
      
      //
      // Store it in our array.
      //
      mData[(i - 1) * 4 + j] = byte;
      mDataIsValid[(i - 1) * 4 + j] = valid[i][j];
       
      //
      // Crank the LFSR.
      //
      lfsr = (((uint16_t)(G2LFSR[lfsr & 0x1ff])) << 7) | ((lfsr >> 8) & 0xff);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x76c0
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x2cf8(%rax)
movq -0x10(%rbp), %rdi
callq 0x76e0
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, 0x2cfc(%rax)
movq -0x10(%rbp), %rdi
callq 0x7700
movb %al, %cl
movq -0x48(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x2cfd(%rax)
movq -0x10(%rbp), %rdi
callq 0x7720
movb %al, %cl
movq -0x48(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x2cfe(%rax)
movq -0x10(%rbp), %rdi
callq 0x7650
movq %rax, %rdi
callq 0x9170
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x7650
movq %rax, %rdi
callq 0x9180
movq %rax, -0x20(%rbp)
movw $0x1, -0x22(%rbp)
movq $0x1, -0x30(%rbp)
cmpq $0x5a0, -0x30(%rbp)     # imm = 0x5A0
jae 0xa9c5
movq $0x0, -0x38(%rbp)
cmpq $0x4, -0x38(%rbp)
jae 0xa9b2
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movq -0x38(%rbp), %rdx
movb (%rcx,%rdx), %cl
movb %cl, -0x39(%rbp)
movzwl -0x22(%rbp), %edx
andl $0xff, %edx
movzbl -0x39(%rbp), %ecx
xorl %edx, %ecx
movb %cl, -0x39(%rbp)
movb -0x39(%rbp), %dl
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
shlq $0x2, %rcx
addq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movq -0x38(%rbp), %rdx
movb (%rcx,%rdx), %dl
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
shlq $0x2, %rcx
addq -0x38(%rbp), %rcx
andb $0x1, %dl
movb %dl, 0x167c(%rax,%rcx)
movzwl -0x22(%rbp), %eax
andl $0x1ff, %eax            # imm = 0x1FF
movslq %eax, %rcx
leaq 0x4f6c(%rip), %rax      # 0xf8f0
movzbl (%rax,%rcx), %eax
movzwl %ax, %eax
shll $0x7, %eax
movzwl -0x22(%rbp), %ecx
sarl $0x8, %ecx
andl $0xff, %ecx
orl %ecx, %eax
movw %ax, -0x22(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xa8f0
jmp 0xa9b4
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xa8da
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)