// File: jkingan[P]ladyheather/heathgps.cpp
// Function: decode_x72_msg(int)
void decode_x72_msg(int why)
{
char c;
int i;

   start_msg_decode(0);

   nmea_msg[0] = 0;
   for(i=0; i<tsip_wptr; i++) {  // copy message from tsip buffer to nmea buffer
      c = tsip_byte();
      nmea_msg[i] = c;
      nmea_msg[i+1] = 0;
      if(i >= ((int)sizeof(nmea_msg)-12)) break;
   }

   tsip_wptr = tsip_rptr = 0;
   tsip_sync = 0;
tsip_error = 0;

   // get the response from the receiver and pass it to (HOPEFULLY) the routine
   // that expects it...

   strupr(nmea_msg);

if(debug_file) fprintf(debug_file, "Decode x72 msg %d:(%s)  why:%d\n", x72_msg_id, nmea_msg, why);

   if(strstr(nmea_msg, "R>")) {  // >r prompt
      x72_msg_id = 0;
      return;
   }
   else if(nmea_msg[0] == 0) {  // empty line
      return;
   }
   else if(x72_msg_id == 0) {
if(debug_file) fprintf(debug_file, "response to:(%s) (status msg:%d) is next\n", nmea_msg, scpi_status);
      if     (strstr(nmea_msg, "A")) x72_msg_id = X72_SET_FC_MSG;
      else if(strstr(nmea_msg, "F")) x72_msg_id = X72_SET_DDS_MSG;
      else if(strstr(nmea_msg, "G")) x72_msg_id = X72_SET_DMODE_MSG;
      else if(strstr(nmea_msg, "H")) x72_msg_id = X72_HELP_MSG;
      else if(strstr(nmea_msg, "I")) x72_msg_id = X72_INFO_MSG;
      else if(strstr(nmea_msg, "J")) x72_msg_id = X72_GET_PPS_MSG;
      else if(strstr(nmea_msg, "K")) x72_msg_id = X72_SET_TIC_MSG;
      else if(strstr(nmea_msg, "L")) x72_msg_id = X72_SET_SRVC_MSG;
      else if(strstr(nmea_msg, "O")) x72_msg_id = X72_SET_FREQ_MSG;
      else if(strstr(nmea_msg, "P")) x72_msg_id = X72_GET_CREG_MSG;
      else if(strstr(nmea_msg, "Q")) x72_msg_id = X72_SET_CREG_MSG;
      else if(strstr(nmea_msg, "R")) x72_msg_id = X72_RUNR_MSG;
      else if(strstr(nmea_msg, "T")) x72_msg_id = X72_SAVE_TUNE_MSG;
      else if(strstr(nmea_msg, "W")) x72_msg_id = X72_HEALTH_MSG;
      else if(strstr(nmea_msg, "X")) x72_msg_id = X72_RUNX_MSG;
      else if(strstr(nmea_msg, "Y")) x72_msg_id = X72_TC_MSG;         // !!!! Y1
      else if(strstr(nmea_msg, "Y")) x72_msg_id = X72_DAMPING_MSG;    // !!!! Y2
      else if(strstr(nmea_msg, "Z")) x72_msg_id = X72_SAVE_DMODE_MSG; // !!!! Y2
      return;
   }

   if(x72_msg_id == X72_INFO_MSG) {  // multi-line response to the query
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_HEALTH_MSG) {  // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_GET_PPS_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_GET_CREG_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_HELP_MSG) { // multi-line response to the query 
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_CREG_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_TIC_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_FREQ_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_DMODE_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SAVE_TUNE_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_DDS_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_SRVC_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_FC_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_RUNR_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_RUNX_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_TC_MSG) {   // multi-line response to the query  
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_DAMPING_MSG) { // multi-line response to the query  
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SAVE_DMODE_MSG) { // multi-line response to the query  
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == SCPI_USER_MSG) {
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else {
      x72_msg_id = 0;
      poll_next_x72();
   }


// if(debug_file) fprintf(debug_file, "x72 %d response:%s\n", x72_msg_id, nmea_msg);
   update_x72_screen();

   if(sim_file && sim_delay) {  // throttle sim file messages
      Sleep(sim_delay);
   }
   saw_rcvr_msg = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
xorl %edi, %edi
callq 0xae4a0
leaq 0x2d7047(%rip), %rax    # 0x39aa10
movb $0x0, (%rax)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
leaq 0x2d3a55(%rip), %rcx    # 0x397432
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xc3a29
callq 0x7a510
movb %al, -0x5(%rbp)
movb -0x5(%rbp), %dl
movslq -0xc(%rbp), %rcx
leaq 0x2d7016(%rip), %rax    # 0x39aa10
movb %dl, (%rax,%rcx)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2d7003(%rip), %rax    # 0x39aa10
movb $0x0, (%rax,%rcx)
cmpl $0x1f5, -0xc(%rbp)      # imm = 0x1F5
jl 0xc3a1c
jmp 0xc3a29
jmp 0xc3a1e
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xc39d3
leaq 0x2d3a04(%rip), %rax    # 0x397434
movw $0x0, (%rax)
leaq 0x2d39f6(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2d39ee(%rip), %rax    # 0x397436
movw $0x0, (%rax)
leaq 0x1da6fc(%rip), %rax    # 0x29e150
movl $0x0, (%rax)
leaq 0x2d6faf(%rip), %rdi    # 0x39aa10
callq 0x9890
leaq 0x1d9b03(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xc3a9c
leaq 0x1d9af6(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl 0x30832d(%rip), %edx    # 0x3cbdb0
movl -0x4(%rbp), %r8d
leaq 0xc3578(%rip), %rsi     # 0x187006
leaq 0x2d6f7b(%rip), %rcx    # 0x39aa10
movb $0x0, %al
callq 0x9550
leaq 0x2d6f6d(%rip), %rdi    # 0x39aa10
leaq 0xc357c(%rip), %rsi     # 0x187026
callq 0x9090
cmpq $0x0, %rax
je 0xc3ac4
movl $0x0, 0x3082f1(%rip)    # 0x3cbdb0
jmp 0xc412c
leaq 0x2d6f45(%rip), %rax    # 0x39aa10
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xc3ad8
jmp 0xc412c
cmpl $0x0, 0x3082d1(%rip)    # 0x3cbdb0
jne 0xc3e00
leaq 0x1d9a84(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xc3b17
leaq 0x1d9a77(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl 0x30b6b2(%rip), %ecx    # 0x3cf1b4
leaq 0xc3520(%rip), %rsi     # 0x187029
leaq 0x2d6f00(%rip), %rdx    # 0x39aa10
movb $0x0, %al
callq 0x9550
leaq 0x2d6ef2(%rip), %rdi    # 0x39aa10
leaq 0xc1b20(%rip), %rsi     # 0x185645
callq 0x9090
cmpq $0x0, %rax
je 0xc3b3f
movl $0x2bc, 0x308276(%rip)  # imm = 0x2BC
jmp 0xc3dfb
leaq 0x2d6eca(%rip), %rdi    # 0x39aa10
leaq 0xb58dc(%rip), %rsi     # 0x179429
callq 0x9090
cmpq $0x0, %rax
je 0xc3b67
movl $0x2bd, 0x30824e(%rip)  # imm = 0x2BD
jmp 0xc3df9
leaq 0x2d6ea2(%rip), %rdi    # 0x39aa10
leaq 0xc5a98(%rip), %rsi     # 0x18960d
callq 0x9090
cmpq $0x0, %rax
je 0xc3b8f
movl $0x2be, 0x308226(%rip)  # imm = 0x2BE
jmp 0xc3df7
leaq 0x2d6e7a(%rip), %rdi    # 0x39aa10
leaq 0xab7ac(%rip), %rsi     # 0x16f349
callq 0x9090
cmpq $0x0, %rax
je 0xc3bb7
movl $0x2bf, 0x3081fe(%rip)  # imm = 0x2BF
jmp 0xc3df5
leaq 0x2d6e52(%rip), %rdi    # 0x39aa10
leaq 0xb1678(%rip), %rsi     # 0x17523d
callq 0x9090
cmpq $0x0, %rax
je 0xc3bdf
movl $0x2c0, 0x3081d6(%rip)  # imm = 0x2C0
jmp 0xc3df3
leaq 0x2d6e2a(%rip), %rdi    # 0x39aa10
leaq 0xac38f(%rip), %rsi     # 0x16ff7c
callq 0x9090
cmpq $0x0, %rax
je 0xc3c07
movl $0x2c1, 0x3081ae(%rip)  # imm = 0x2C1
jmp 0xc3df1
leaq 0x2d6e02(%rip), %rdi    # 0x39aa10
leaq 0xb5834(%rip), %rsi     # 0x179449
callq 0x9090
cmpq $0x0, %rax
je 0xc3c2f
movl $0x2c2, 0x308186(%rip)  # imm = 0x2C2
jmp 0xc3def
leaq 0x2d6dda(%rip), %rdi    # 0x39aa10
leaq 0xc46fe(%rip), %rsi     # 0x18833b
callq 0x9090
cmpq $0x0, %rax
je 0xc3c57
movl $0x2c3, 0x30815e(%rip)  # imm = 0x2C3
jmp 0xc3ded
leaq 0x2d6db2(%rip), %rdi    # 0x39aa10
leaq 0xb5824(%rip), %rsi     # 0x179489
callq 0x9090
cmpq $0x0, %rax
je 0xc3c7f
movl $0x2c4, 0x308136(%rip)  # imm = 0x2C4
jmp 0xc3deb
leaq 0x2d6d8a(%rip), %rdi    # 0x39aa10
leaq 0xbdf5b(%rip), %rsi     # 0x181be8
callq 0x9090
cmpq $0x0, %rax
je 0xc3ca7
movl $0x2c5, 0x30810e(%rip)  # imm = 0x2C5
jmp 0xc3de9
leaq 0x2d6d62(%rip), %rdi    # 0x39aa10
leaq 0xc0352(%rip), %rsi     # 0x184007
callq 0x9090
cmpq $0x0, %rax
je 0xc3ccf
movl $0x2c6, 0x3080e6(%rip)  # imm = 0x2C6
jmp 0xc3de7
leaq 0x2d6d3a(%rip), %rdi    # 0x39aa10
leaq 0xb575c(%rip), %rsi     # 0x179439
callq 0x9090
cmpq $0x0, %rax
je 0xc3cf7
movl $0x2c7, 0x3080be(%rip)  # imm = 0x2C7
jmp 0xc3de5
leaq 0x2d6d12(%rip), %rdi    # 0x39aa10
leaq 0xae349(%rip), %rsi     # 0x17204e
callq 0x9090
cmpq $0x0, %rax
je 0xc3d1f
movl $0x2c8, 0x308096(%rip)  # imm = 0x2C8
jmp 0xc3de3
leaq 0x2d6cea(%rip), %rdi    # 0x39aa10
leaq 0xc1f6f(%rip), %rsi     # 0x185c9c
callq 0x9090
cmpq $0x0, %rax
je 0xc3d47
movl $0x2c9, 0x30806e(%rip)  # imm = 0x2C9
jmp 0xc3de1
leaq 0x2d6cc2(%rip), %rdi    # 0x39aa10
leaq 0xae2f0(%rip), %rsi     # 0x172045
callq 0x9090
cmpq $0x0, %rax
je 0xc3d6c
movl $0x2ca, 0x308046(%rip)  # imm = 0x2CA
jmp 0xc3ddf
leaq 0x2d6c9d(%rip), %rdi    # 0x39aa10
leaq 0xae2ce(%rip), %rsi     # 0x172048
callq 0x9090
cmpq $0x0, %rax
je 0xc3d91
movl $0x2cb, 0x308021(%rip)  # imm = 0x2CB
jmp 0xc3ddd
leaq 0x2d6c78(%rip), %rdi    # 0x39aa10
leaq 0xae2a9(%rip), %rsi     # 0x172048
callq 0x9090
cmpq $0x0, %rax
je 0xc3db6
movl $0x2cc, 0x307ffc(%rip)  # imm = 0x2CC
jmp 0xc3ddb
leaq 0x2d6c53(%rip), %rdi    # 0x39aa10
leaq 0xae287(%rip), %rsi     # 0x17204b
callq 0x9090
cmpq $0x0, %rax
je 0xc3dd9
movl $0x2cd, 0x307fd7(%rip)  # imm = 0x2CD
jmp 0xc3ddb
jmp 0xc3ddd
jmp 0xc3ddf
jmp 0xc3de1
jmp 0xc3de3
jmp 0xc3de5
jmp 0xc3de7
jmp 0xc3de9
jmp 0xc3deb
jmp 0xc3ded
jmp 0xc3def
jmp 0xc3df1
jmp 0xc3df3
jmp 0xc3df5
jmp 0xc3df7
jmp 0xc3df9
jmp 0xc3dfb
jmp 0xc412c
jmp 0xc3e02
jmp 0xc3e04
cmpl $0x2c0, 0x307fa2(%rip)  # imm = 0x2C0
jne 0xc3e2a
movl 0x307f9a(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307f8b(%rip)    # 0x3cbdb0
jmp 0xc40ef
cmpl $0x2c9, 0x307f7c(%rip)  # imm = 0x2C9
jne 0xc3e50
movl 0x307f74(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307f65(%rip)    # 0x3cbdb0
jmp 0xc40ed
cmpl $0x2c1, 0x307f56(%rip)  # imm = 0x2C1
jne 0xc3e76
movl 0x307f4e(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307f3f(%rip)    # 0x3cbdb0
jmp 0xc40eb
cmpl $0x2c5, 0x307f30(%rip)  # imm = 0x2C5
jne 0xc3e9c
movl 0x307f28(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307f19(%rip)    # 0x3cbdb0
jmp 0xc40e9
cmpl $0x2bf, 0x307f0a(%rip)  # imm = 0x2BF
jne 0xc3eb7
movl $0x0, 0x307efe(%rip)    # 0x3cbdb0
jmp 0xc40e7
cmpl $0x2c6, 0x307eef(%rip)  # imm = 0x2C6
jne 0xc3edd
movl 0x307ee7(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307ed8(%rip)    # 0x3cbdb0
jmp 0xc40e5
cmpl $0x2c2, 0x307ec9(%rip)  # imm = 0x2C2
jne 0xc3f03
movl 0x307ec1(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307eb2(%rip)    # 0x3cbdb0
jmp 0xc40e3
cmpl $0x2c4, 0x307ea3(%rip)  # imm = 0x2C4
jne 0xc3f29
movl 0x307e9b(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307e8c(%rip)    # 0x3cbdb0
jmp 0xc40e1
cmpl $0x2be, 0x307e7d(%rip)  # imm = 0x2BE
jne 0xc3f4f
movl 0x307e75(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307e66(%rip)    # 0x3cbdb0
jmp 0xc40df
cmpl $0x2c8, 0x307e57(%rip)  # imm = 0x2C8
jne 0xc3f75
movl 0x307e4f(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307e40(%rip)    # 0x3cbdb0
jmp 0xc40dd
cmpl $0x2bd, 0x307e31(%rip)  # imm = 0x2BD
jne 0xc3f9b
movl 0x307e29(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307e1a(%rip)    # 0x3cbdb0
jmp 0xc40db
cmpl $0x2c3, 0x307e0b(%rip)  # imm = 0x2C3
jne 0xc3fc1
movl 0x307e03(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307df4(%rip)    # 0x3cbdb0
jmp 0xc40d9
cmpl $0x2bc, 0x307de5(%rip)  # imm = 0x2BC
jne 0xc3fe7
movl 0x307ddd(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307dce(%rip)    # 0x3cbdb0
jmp 0xc40d7
cmpl $0x2c7, 0x307dbf(%rip)  # imm = 0x2C7
jne 0xc400d
movl 0x307db7(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307da8(%rip)    # 0x3cbdb0
jmp 0xc40d5
cmpl $0x2ca, 0x307d99(%rip)  # imm = 0x2CA
jne 0xc4033
movl 0x307d91(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307d82(%rip)    # 0x3cbdb0
jmp 0xc40d3
cmpl $0x2cb, 0x307d73(%rip)  # imm = 0x2CB
jne 0xc4056
movl 0x307d6b(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307d5c(%rip)    # 0x3cbdb0
jmp 0xc40d1
cmpl $0x2cc, 0x307d50(%rip)  # imm = 0x2CC
jne 0xc4079
movl 0x307d48(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307d39(%rip)    # 0x3cbdb0
jmp 0xc40cf
cmpl $0x2cd, 0x307d2d(%rip)  # imm = 0x2CD
jne 0xc409c
movl 0x307d25(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307d16(%rip)    # 0x3cbdb0
jmp 0xc40cd
cmpl $0x25, 0x307d0d(%rip)   # 0x3cbdb0
jne 0xc40bc
movl 0x307d05(%rip), %edi    # 0x3cbdb0
callq 0xc25d0
movl $0x0, 0x307cf6(%rip)    # 0x3cbdb0
jmp 0xc40cb
movl $0x0, 0x307cea(%rip)    # 0x3cbdb0
callq 0x990c0
jmp 0xc40cd
jmp 0xc40cf
jmp 0xc40d1
jmp 0xc40d3
jmp 0xc40d5
jmp 0xc40d7
jmp 0xc40d9
jmp 0xc40db
jmp 0xc40dd
jmp 0xc40df
jmp 0xc40e1
jmp 0xc40e3
jmp 0xc40e5
jmp 0xc40e7
jmp 0xc40e9
jmp 0xc40eb
jmp 0xc40ed
jmp 0xc40ef
callq 0xc23c0
leaq 0x1d94a5(%rip), %rax    # 0x29d5a0
cmpq $0x0, (%rax)
je 0xc411f
leaq 0x1be6d8(%rip), %rax    # 0x2827e0
cmpq $0x0, (%rax)
je 0xc411f
leaq 0x1be6cb(%rip), %rax    # 0x2827e0
movq (%rax), %rax
movl %eax, %edi
callq 0xb8b0
leaq 0x1da05a(%rip), %rax    # 0x29e180
movl $0x1, (%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)