// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_rftg_message()
void get_rftg_message()
{
u08 c;
int i;
static int colon = 0;
char s[3];  // used to calculate message cksum

   // this routine buffers up an incoming TSIP message and then parses it
   // when it is complete.

   if(SERIAL_DATA_AVAILABLE(RCVR_PORT) == 0) {
      check_com_timer(RCVR_PORT);
      return;
   }
   else {
      reset_com_timer(RCVR_PORT);
   }

   c = get_com_char();
   if(com[RCVR_PORT].rcv_error) {      // parity/framing/overrun errors
      com[RCVR_PORT].rcv_error = 0;
//!!!!!qqqq    goto rst_msg;
   }

   if(tsip_sync == 0) {         // syncing to start of message, search for a DLE
      if(c == DLE) {
         tsip_sync = 1;
         get_sync_time();
         colon = 0;
      }
      else if(c == ':') {
         tsip_sync = 1;
         get_sync_time();
         colon = 1;
      }

      nmea_vfy_cksum = 0;
      nmea_msg_cksum = 0;
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) {    // DLE had been seen, now checking next byte
      if(c == DLE) {            // DLE DLE is a 0x10 data byte
         goto rst_msg;
      }
      else if(c == ETX) {       // DLE ETX is end-of-message
         goto rst_msg;          // ... should never happen here
      }
      else if(colon) {
         if((c == '0') || (c == '1')) {
            goto get_msg;
         }
         else goto rst_msg;
      }
      else {                    // DLE xx is message start
         get_msg:
         tsip_sync = 2;         // ... so accumulate the message
         if(tsip_wptr < (MAX_TSIP-1)) {
            tsip_buf[tsip_wptr++] = c;
            tsip_buf[tsip_wptr] = 0;
         }
         else {                 // buffer overlow
            tsip_error |= OVFL_ERROR;
            goto rst_msg;
         }
      }
   }
   else if(tsip_sync == 2) {    // buffer up the message
      if(colon && (c == 0x0D)) {
         tsip_sync = 3;
         if(tsip_wptr < (MAX_TSIP-1)) {
            tsip_buf[tsip_wptr++] = 0;
            tsip_buf[tsip_wptr] = 0;
         }
         else {
            goto rst_msg;
         }
      }
      else if(c == DLE) {
         tsip_sync = 3;
      }
      else if(tsip_wptr < (MAX_TSIP-1)) {
         tsip_buf[tsip_wptr++] = c;
         tsip_buf[tsip_wptr] = 0;
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else if(tsip_sync == 3) {   // last char was a DLE
      if(colon) {
         nmea_vfy_cksum = 0;
         for(i=0; i<22; i+=2) {
            s[0] = tsip_buf[i];
            s[1] = tsip_buf[i+1];
            s[2] = 0;
            nmea_vfy_cksum += atohex(s);
         }
         nmea_vfy_cksum &= 0xFF;

         i = atohex((char *) &tsip_buf[22]) & 0xFF;
         if(nmea_vfy_cksum == i) {
            parse_rftg_time();
         }
         goto rst_msg;
      }
      else if(c == ETX) {           // DLE ETX is end-of-message
         decode_rftg_message(); // so process the buffered message
         packet_end = 1;

         rst_msg:
         tsip_wptr = 0;
         tsip_sync = 0;
      }
      else {                   // DLE DLE is a DLE data byte and DLE xx is message ID
         if(tsip_wptr < (MAX_TSIP-1)) {  // so add it to the message buffer
            tsip_buf[tsip_wptr++] = c;
            tsip_buf[tsip_wptr] = 0;
         }
         else {
            tsip_error |= OVFL_ERROR;
            goto rst_msg;
         }
         tsip_sync = 2;
      }
   }
   else {     // should never happen
      goto rst_msg;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xbbf16
movl $0xa, %edi
callq 0x2b610
jmp 0xbc353
movl $0xa, %edi
callq 0x2bd30
callq 0x79fc0
movb %al, -0x1(%rbp)
leaq 0x2b1591(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xbbf46
leaq 0x2b1581(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
leaq 0x2db4e9(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xbbfcc
movzbl -0x1(%rbp), %eax
cmpl $0x10, %eax
jne 0xbbf7b
leaq 0x2db4d1(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
movl $0x0, 0x3150ef(%rip)    # 0x3d1068
jmp 0xbbfa1
movzbl -0x1(%rbp), %eax
cmpl $0x3a, %eax
jne 0xbbf9f
leaq 0x2db4ab(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
movl $0x1, 0x3150c9(%rip)    # 0x3d1068
jmp 0xbbfa1
movb $0x0, 0x30fcec(%rip)    # 0x3cbc94
movb $0x0, 0x30fce6(%rip)    # 0x3cbc95
leaq 0x2db47c(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2db472(%rip), %rax    # 0x397434
movw $0x0, (%rax)
jmp 0xbc353
leaq 0x2db463(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xbc0aa
movzbl -0x1(%rbp), %eax
cmpl $0x10, %eax
jne 0xbbfed
jmp 0xbc2a7
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0xbbffb
jmp 0xbc2a7
cmpl $0x0, 0x315066(%rip)    # 0x3d1068
je 0xbc01d
movzbl -0x1(%rbp), %eax
cmpl $0x30, %eax
je 0xbc016
movzbl -0x1(%rbp), %eax
cmpl $0x31, %eax
jne 0xbc018
jmp 0xbc01f
jmp 0xbc2a7
jmp 0xbc01f
leaq 0x2db410(%rip), %rax    # 0x397436
movw $0x2, (%rax)
leaq 0x2db400(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
jge 0xbc082
movb -0x1(%rbp), %dl
leaq 0x2db3ec(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2db3db(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2da3ca(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2db3c2(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2da3b4(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xbc09f
leaq 0x1e20c7(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1e20b8(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xbc2a7
jmp 0xbc0a1
jmp 0xbc0a3
jmp 0xbc0a5
jmp 0xbc351
leaq 0x2db385(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xbc1ce
cmpl $0x0, 0x314fa4(%rip)    # 0x3d1068
je 0xbc13a
movzbl -0x1(%rbp), %eax
cmpl $0xd, %eax
jne 0xbc13a
leaq 0x2db360(%rip), %rax    # 0x397436
movw $0x3, (%rax)
leaq 0x2db350(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
jge 0xbc130
leaq 0x2db33f(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %dx
addw $0x1, %dx
leaq 0x2db32e(%rip), %rcx    # 0x397432
movw %dx, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2da31d(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
leaq 0x2db314(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2da306(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xbc135
jmp 0xbc2a7
jmp 0xbc1c9
movzbl -0x1(%rbp), %eax
cmpl $0x10, %eax
jne 0xbc151
leaq 0x2db2ec(%rip), %rax    # 0x397436
movw $0x3, (%rax)
jmp 0xbc1c7
leaq 0x2db2da(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
jge 0xbc1a8
movb -0x1(%rbp), %dl
leaq 0x2db2c6(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2db2b5(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2da2a4(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2db29c(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2da28e(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xbc1c5
leaq 0x1e1fa1(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1e1f92(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xbc2a7
jmp 0xbc1c7
jmp 0xbc1c9
jmp 0xbc34f
leaq 0x2db261(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0xbc348
cmpl $0x0, 0x314e80(%rip)    # 0x3d1068
je 0xbc28f
movb $0x0, 0x30fa9f(%rip)    # 0x3cbc94
movl $0x0, -0x8(%rbp)
cmpl $0x16, -0x8(%rbp)
jge 0xbc252
movslq -0x8(%rbp), %rcx
leaq 0x2da223(%rip), %rax    # 0x396430
movb (%rax,%rcx), %al
movb %al, -0xb(%rbp)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2da20d(%rip), %rax    # 0x396430
movb (%rax,%rcx), %al
movb %al, -0xa(%rbp)
movb $0x0, -0x9(%rbp)
leaq -0xb(%rbp), %rdi
callq 0x98d0
movl %eax, %ecx
movzbl 0x30fa55(%rip), %eax    # 0x3cbc94
addl %ecx, %eax
movb %al, 0x30fa4d(%rip)     # 0x3cbc94
movl -0x8(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x8(%rbp)
jmp 0xbc1fc
movzbl 0x30fa3b(%rip), %eax    # 0x3cbc94
andl $0xff, %eax
movb %al, 0x30fa30(%rip)     # 0x3cbc94
leaq 0x2da1c5(%rip), %rdi    # 0x396430
addq $0x16, %rdi
callq 0x98d0
andl $0xff, %eax
movl %eax, -0x8(%rbp)
movzbl 0x30fa11(%rip), %eax    # 0x3cbc94
cmpl -0x8(%rbp), %eax
jne 0xbc28d
callq 0xbb560
jmp 0xbc2a7
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0xbc2c4
callq 0xbbbd0
movl $0x1, 0x30ebcd(%rip)    # 0x3cae74
leaq 0x2db184(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2db17c(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xbc344
leaq 0x2db167(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
jge 0xbc31b
movb -0x1(%rbp), %dl
leaq 0x2db153(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2db142(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2da131(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2db129(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2da11b(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xbc338
leaq 0x1e1e2e(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1e1e1f(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xbc2a7
leaq 0x2db0f7(%rip), %rax    # 0x397436
movw $0x2, (%rax)
jmp 0xbc346
jmp 0xbc34d
jmp 0xbc2a7
jmp 0xbc34f
jmp 0xbc351
jmp 0xbc353
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)