// File: jkingan[P]ladyheather/heathgps.cpp
// Function: decode_moto_status(int)
void decode_moto_status(int r_status)
{
int ant;
int mode;

   // convert status word into tbolt equivalents

   // Bit fields:
   //    0x0006 = antenna status
   //    0x0008 = no sats
   //    0x0010 = survey mode
   //    0x0020 = posn lock
   //    0x0040 = differential mode
   //    0x0080 = cold start
   //    0x0100 - unfiltered GPS
   //    0x0200 - fast acquisition mode
   //    0x0400 - narrow band filter
   //    0xE000 = rcvr mode
   //             7=3d  6=2d  5=propogeate 4=posn hold  3=acquiring 2=bad geom

   ant = (r_status >> 1) & 0x03;

   minor_alarms &= (~MINOR_ANT_NO_PWR);  // antenna state
   if     (ant == 3) minor_alarms |= MINOR_ANT_NO_PWR;  // unbiased
   else if(ant == 2) minor_alarms |= MINOR_ANT_OPEN;    // open
   else if(ant == 1) minor_alarms |= MINOR_ANT_SHORT;   // short
   have_antenna = 1;

   if(r_status & 0x0008) {
      minor_alarms |= MINOR_NO_TRACK;    // no sats
      gps_status = GPS_NO_SATS;
   }
   else { 
      minor_alarms &= (~MINOR_NO_TRACK);
      gps_status = GPS_FIXES;
   }
   have_gps_status = 1;
   have_tracking = 1;

   set_survey_status(r_status & 0x0010);

   if(r_status & 0x0080) minor_alarms |= MINOR_ALMANAC;   // cold start/no almanac
   else                  minor_alarms &= (~MINOR_ALMANAC);
   have_almanac = 1;

   //  mode: 7=3d  6=2d  5=propogate 4=posn hold  3=acquiring 2=bad geom
   mode = (r_status >> 13) & 0x07;  

   if(mode == 3) discipline_mode = DIS_MODE_RECOVERY;
   else          discipline_mode = DIS_MODE_NORMAL;

   if     (mode == 7) rcvr_mode = RCVR_MODE_3D;
   else if(mode == 6) rcvr_mode = RCVR_MODE_2D;
   else if(mode == 5) rcvr_mode = RCVR_MODE_PROP;
   else if(mode == 4) rcvr_mode = RCVR_MODE_HOLD;
   else if(mode == 3) rcvr_mode = RCVR_MODE_ACQUIRE;
   else if(mode == 2) rcvr_mode = RCVR_MODE_BAD_GEOM;
   else               rcvr_mode = RCVR_MODE_UNKNOWN;
   have_rcvr_mode = 5;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl -0x4(%rbp), %eax
sarl %eax
andl $0x3, %eax
movl %eax, -0x8(%rbp)
leaq 0x29a61b(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
andl $-0x7, %ecx
leaq 0x29a60f(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
cmpl $0x3, -0x8(%rbp)
jne 0xd1dc8
leaq 0x29a600(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x6, %ecx
leaq 0x29a5f4(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xd1e04
cmpl $0x2, -0x8(%rbp)
jne 0xd1de5
leaq 0x29a5e3(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x29a5d7(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xd1e02
cmpl $0x1, -0x8(%rbp)
jne 0xd1e00
leaq 0x29a5c6(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x4, %ecx
leaq 0x29a5ba(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xd1e02
jmp 0xd1e04
leaq 0x29a601(%rip), %rax    # 0x36c40c
movl $0x1, (%rax)
movl -0x4(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xd1e40
leaq 0x29a595(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x8, %ecx
leaq 0x29a589(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
leaq 0x29a844(%rip), %rax    # 0x36c67c
movl $0x8, (%rax)
jmp 0xd1e62
leaq 0x29a571(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
andl $-0x9, %ecx
leaq 0x29a565(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
leaq 0x29a820(%rip), %rax    # 0x36c67c
movl $0x0, (%rax)
leaq 0x29a627(%rip), %rax    # 0x36c490
movl $0x1, (%rax)
leaq 0x29a5fa(%rip), %rax    # 0x36c470
movl $0x1, (%rax)
movl -0x4(%rbp), %edi
andl $0x10, %edi
callq 0xd1cc0
movl -0x4(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xd1eae
leaq 0x29a51d(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x800, %ecx            # imm = 0x800
leaq 0x29a50e(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xd1ec6
leaq 0x29a503(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
andl $0xfffff7ff, %ecx       # imm = 0xFFFFF7FF
leaq 0x29a4f4(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
leaq 0x29a5b7(%rip), %rax    # 0x36c484
movl $0x1, (%rax)
movl -0x4(%rbp), %eax
sarl $0xd, %eax
andl $0x7, %eax
movl %eax, -0xc(%rbp)
cmpl $0x3, -0xc(%rbp)
jne 0xd1ef1
leaq 0x29a78b(%rip), %rax    # 0x36c677
movb $0x4, (%rax)
jmp 0xd1efb
leaq 0x29a77f(%rip), %rax    # 0x36c677
movb $0x0, (%rax)
cmpl $0x7, -0xc(%rbp)
jne 0xd1f0d
leaq 0x29a3a8(%rip), %rax    # 0x36c2b0
movb $0x4, (%rax)
jmp 0xd1f7b
cmpl $0x6, -0xc(%rbp)
jne 0xd1f1f
leaq 0x29a396(%rip), %rax    # 0x36c2b0
movb $0x3, (%rax)
jmp 0xd1f79
cmpl $0x5, -0xc(%rbp)
jne 0xd1f31
leaq 0x29a384(%rip), %rax    # 0x36c2b0
movb $0x8, (%rax)
jmp 0xd1f77
cmpl $0x4, -0xc(%rbp)
jne 0xd1f43
leaq 0x29a372(%rip), %rax    # 0x36c2b0
movb $0x7, (%rax)
jmp 0xd1f75
cmpl $0x3, -0xc(%rbp)
jne 0xd1f55
leaq 0x29a360(%rip), %rax    # 0x36c2b0
movb $0x9, (%rax)
jmp 0xd1f73
cmpl $0x2, -0xc(%rbp)
jne 0xd1f67
leaq 0x29a34e(%rip), %rax    # 0x36c2b0
movb $0xa, (%rax)
jmp 0xd1f71
leaq 0x29a342(%rip), %rax    # 0x36c2b0
movb $0x63, (%rax)
jmp 0xd1f73
jmp 0xd1f75
jmp 0xd1f77
jmp 0xd1f79
jmp 0xd1f7b
leaq 0x29a66b(%rip), %rax    # 0x36c5ed
movb $0x5, (%rax)
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)