// File: ke6jjj[P]r-dat/DATTrackFramer.cc
// Function: DATTrackFramer::TrackDetected(bool)
void
DATTrackFramer::TrackDetected(bool up)
{
  mTracking = up;
  
  //
  // Wait until tracking is complete (goes down).
  //
  if (up)
    return;

  //
  // Our current track is complete. Give it a chance to perform
  // all error correction.
  //
  mCurrentTrack->Complete();
  
  //
  // If there were any ATF tones detected, use the majority count to
  // determine whether this was a negative azimuth track or a positive
  // azimuth track.
  //
  // Currently only ATF3 (negative azimuth signal) is likely to be detected,
  // so if its count is high enough, assume that the track is an A track.
  //
  printf("Track ATF3 Count: %d\n", mATF3Count);
  if (mATF3Count > mATF3Threshold) {
    mCurrentTrack->SetHead(Track::HEAD_A);
  }

  //
  // See if this track completes a frame (a pair of tracks).
  //
  if (mLastTrack == NULL) {
    //
    // There is no previous track. Just stash this one away.
    //
    mLastTrack = mCurrentTrack;
  } else {
    //
    // We have a previous track. Are these two a pair or are they
    // separate?
    //
    if (mReceiver.IsFrame(*mLastTrack, *mCurrentTrack)) {
      //
      // According to the downstream frame receiver, these two
      // tracks pair into a full frame. Give them to the
      // receiver as such.
      //
      mReceiver.ReceiveFrame(*mLastTrack, *mCurrentTrack);
      
      //
      // The pair have been shipped off. Prepare for a new set.
      //
      delete mLastTrack;
      delete mCurrentTrack;
      mLastTrack = NULL;
    } else {
      //
      // These two don't pair. Dump the last track and continue
      // searching.
      //
      delete mLastTrack;
      mLastTrack = mCurrentTrack;
    }
  }

  //
  // Reset the automatic track finding tone counts.
  //
  mATF2Count = 0;
  mATF3Count = 0;

  //
  // Prepare a new track.
  //
  mCurrentTrack = new Track(Track::HEAD_UNKNOWN);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movb -0x9(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x8(%rax)
testb $0x1, -0x9(%rbp)
je 0x3ba0
jmp 0x3d00
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x4780
movq -0x28(%rbp), %rax
movl 0x14(%rax), %esi
leaq 0xafd0(%rip), %rdi      # 0xeb8b
movb $0x0, %al
callq 0x2040
movq -0x28(%rbp), %rcx
movl 0x14(%rcx), %eax
cmpl 0xc(%rcx), %eax
jle 0x3bdd
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %esi, %esi
callq 0x4390
movq -0x28(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x3bf9
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x20(%rax)
jmp 0x3cc2
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rdi
movq 0x20(%rax), %rsi
movq 0x18(%rax), %rdx
movq (%rdi), %rax
callq *0x10(%rax)
testb $0x1, %al
jne 0x3c15
jmp 0x3c8b
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rdi
movq 0x20(%rax), %rsi
movq 0x18(%rax), %rdx
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x3c54
movq -0x30(%rbp), %rdi
callq 0x4370
movq -0x30(%rbp), %rdi
movl $0x25d0, %esi           # imm = 0x25D0
callq 0x2100
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x3c7d
movq -0x38(%rbp), %rdi
callq 0x4370
movq -0x38(%rbp), %rdi
movl $0x25d0, %esi           # imm = 0x25D0
callq 0x2100
movq -0x28(%rbp), %rax
movq $0x0, 0x20(%rax)
jmp 0x3cc0
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x3cb4
movq -0x40(%rbp), %rdi
callq 0x4370
movq -0x40(%rbp), %rdi
movl $0x25d0, %esi           # imm = 0x25D0
callq 0x2100
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x20(%rax)
jmp 0x3cc2
movq -0x28(%rbp), %rax
movl $0x0, 0x10(%rax)
movl $0x0, 0x14(%rax)
movl $0x25d0, %edi           # imm = 0x25D0
callq 0x20f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x48(%rbp)
movl $0x2, %esi
callq 0x4250
jmp 0x3cf4
movq -0x28(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, 0x18(%rax)
addq $0x50, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x25d0, %esi           # imm = 0x25D0
callq 0x2100
movq -0x18(%rbp), %rdi
callq 0x21d0
nopl (%rax)