// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: get_ebolt_version()
void get_ebolt_version()
{   // ThunderBolt-E only
u08 rsvd1;
u08 major;
u08 minor;
u08 build;
u08 len;
int i;

   log_packet_id("Packet 0x1C (Tbolt-E version)");

   rev_month = rev_day = rev_hour = 0;
   rev_year = 0;

   subcode = tsip_byte();
   if(subcode == 0x81) {  // firmware version
      rsvd1 = tsip_byte();
      major = tsip_byte();
      minor = tsip_byte();
      build = tsip_byte();
      rev_month = tsip_byte();
      rev_day = tsip_byte();
      rev_year = tsip_word();
      len = tsip_byte();
  
      out[0] = 0;
      for(i=0; i<len; i++) {
         if(i >= MAX_TEXT_COLS) {
            tsip_byte();
            continue;
         }
         out[i] = tsip_byte();
         out[i+1] = 0;
      }
  
      strupr(out);
   }
   else if(subcode == 0x83) {  // hardware version
      ebolt_serno = tsip_dword();
      rev_day = tsip_byte();
      rev_month = tsip_byte();
      rev_year = tsip_word();
      rev_hour = tsip_byte();
      hw_code = tsip_word();
      len = tsip_byte();

      for(i=0; i<UNIT_LEN; i++) unit_name[i] = ' ';
      unit_name[UNIT_LEN] = 0;

      out[0] = 0;
      for(i=0; i<len; i++) {   // get hardware id
         if(i >= MAX_TEXT_COLS) {
            tsip_byte();
            continue;
         }
         out[i] = tsip_byte();  // string can have: ICM, RES SMT, RES360, ACUTIME
         out[i+1] = 0;
         if(i < UNIT_LEN) {
            unit_name[i] = out[i];
         }
      }

      strupr(out);
      if(ACU_GG) ;
      else if(ACU_360) ;       // ACUTIME GG/360 already detected
      else if(ACUTIME) ;  // ACUTIME already detected
      else if(PALISADE) ; // PALISADE already detected
      else if(res_t) ;    // res_t already detected
      else if(saw_icm) ;  // icm already detected
      else { // attempt to identify TSIP receiver type
         if(strstr(out, "ACUTIME")) {
            tsip_type = ACUTIME_TYPE;
            acu_type = '1';
            if(strstr(out, "360")) {  // Acutime 360
               acu_type = '3';
            }
            else if(strstr(out, "GG")) {  // Acutime GG
               acu_type = 'G';
            }

            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "ICM")) { // !!!!!! ICM RES SMT
            saw_icm = 1;
            saw_gpsdo = 2;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "PALISADE")) {  // PALISADE does not actually output 0x1C-83 messages
            tsip_type = PALISADE_TYPE;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "RESOLUTION")) {
            if(user_set_res_t) ;
            else if(strstr(out, "SMT")) res_t = RES_T_SMT;
            else                        res_t = RES_T;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "RES SMT")) {
            if(!user_set_res_t) res_t = RES_T_RES;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "RES360")) {
            if(!user_set_res_t) res_t = RES_T_360;
            config_msg_ofs();
            config_rcvr_plots();
         }
      }

      if(mini_t == 0) {
         if(strstr(out, "MINI")) {
            mini_t = 1;
            saw_mini = 1;
            config_msg_ofs();
            config_rcvr_plots();
         }
      }

      strncpy(unit_name, out, UNIT_LEN);
      unit_name[UNIT_LEN-1] = 0;
   }
   else {  // unknown
      //!!! process packet contents
   }

   check_tsip_end(1);   
   if(tsip_error) return;

   saw_ebolt();
   tbolt_e |= 0x08;
   saw_version |= 0x02;

   if(1) {  //!!!!!
      if(rev_month > 12) return;
      if(rev_month == 0) return;
      if(rev_day > 31) return;
      if(rev_day == 0) return;
      if(rev_year < 1990) return;
      if(rev_year > 2100) return;
      if(rev_hour > 24) return;
   }

   if(text_mode && first_key) return;
   if(zoom_screen) return;
   if(luxor) return;
   if(just_read) return;

   if(0 && (subcode == 0x83)) {  // !!! disabled since hw_code clashes with sn_prefix
      show_ebolt_info();
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0xaff85(%rip), %rdi     # 0x121a39
callq 0x58dc2
xorl %eax, %eax
movb %al, 0x2fa33f(%rip)     # 0x36be00
movb %al, 0x2fa336(%rip)     # 0x36bdfd
movb %al, 0x2fa32f(%rip)     # 0x36bdfc
movw $0x0, 0x2fa328(%rip)    # 0x36bdfe
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71aec
leaq 0x1cd487(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
leaq 0x1cd46b(%rip), %rcx    # 0x23ef5e
movb %al, (%rcx)
cmpb $-0x7d, %al
je 0x71c0f
movzbl %al, %eax
cmpl $0x81, %eax
jne 0x71e8f
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71b21
leaq 0x1cd452(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71b37
leaq 0x1cd43c(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71b4d
leaq 0x1cd426(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71b63
leaq 0x1cd410(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71b79
leaq 0x1cd3fa(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movb %al, 0x2fa27d(%rip)     # 0x36bdfc
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71b95
leaq 0x1cd3de(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movb %al, 0x2fa262(%rip)     # 0x36bdfd
callq 0x588d2
movw %ax, 0x2fa257(%rip)     # 0x36bdfe
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71bbd
leaq 0x1cd3b6(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
leaq 0x2ca65c(%rip), %rbx    # 0x33c220
movb $0x0, (%rbx)
andl $0xff, %eax
je 0x71bfe
movl %eax, %r14d
xorl %r15d, %r15d
leaq 0x1cd395(%rip), %r12    # 0x23ef70
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71bec
orb $0x8, (%r12)
movb %al, (%r15,%rbx)
movb $0x0, 0x1(%r15,%rbx)
incq %r15
cmpq %r15, %r14
jne 0x71bdb
leaq 0x2ca61b(%rip), %rdi    # 0x33c220
callq 0x9899
jmp 0x71e8f
callq 0x58964
movl %eax, 0x2fa1ea(%rip)    # 0x36be04
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71c30
leaq 0x1cd343(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movb %al, 0x2fa1c7(%rip)     # 0x36bdfd
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71c4c
leaq 0x1cd327(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movb %al, 0x2fa1aa(%rip)     # 0x36bdfc
callq 0x588d2
movw %ax, 0x2fa1a0(%rip)     # 0x36bdfe
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71c74
leaq 0x1cd2ff(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movb %al, 0x2fa186(%rip)     # 0x36be00
callq 0x588d2
leaq 0x29bd1c(%rip), %rcx    # 0x30d9a2
movw %ax, (%rcx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71c9f
leaq 0x1cd2d4(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movaps 0xacdfa(%rip), %xmm0    # 0x11eaa0
leaq 0x2ca993(%rip), %rbx    # 0x33c640
movaps %xmm0, (%rbx)
movw $0x2020, 0x10(%rbx)     # imm = 0x2020
xorl %ecx, %ecx
movb %cl, 0x12(%rbx)
leaq 0x2ca55e(%rip), %r14    # 0x33c220
movb %cl, (%r14)
andl $0xff, %eax
je 0x71d06
movl %eax, %r15d
xorl %r12d, %r12d
leaq 0x1cd297(%rip), %r13    # 0x23ef70
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x71cea
orb $0x8, (%r13)
movb %al, (%r12,%r14)
movb $0x0, 0x1(%r12,%r14)
cmpq $0x11, %r12
ja 0x71cfe
movb %al, (%rbx,%r12)
incq %r12
cmpq %r12, %r15
jne 0x71cd9
leaq 0x2ca513(%rip), %rdi    # 0x33c220
callq 0x9899
leaq 0x1a6bb7(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x1, %rax
sete %dl
leaq 0x1a92aa(%rip), %r15    # 0x21afd4
movl (%r15), %ecx
cmpl $0x41, %ecx
sete %sil
testb %sil, %dl
jne 0x71e3a
cmpq $0x1, %rax
sete %al
cmpl $0x50, %ecx
sete %cl
testb %cl, %al
jne 0x71e3a
leaq 0x1a6bab(%rip), %r14    # 0x218904
cmpb $0x0, (%r14)
jne 0x71e3a
leaq 0x1cd1c3(%rip), %r12    # 0x23ef2d
cmpb $0x0, (%r12)
jne 0x71e3a
leaq 0x2ca4a4(%rip), %rdi    # 0x33c220
leaq 0xafcd4(%rip), %rsi     # 0x121a57
callq 0x9090
testq %rax, %rax
je 0x71de1
movl $0x41, (%r15)
leaq 0x1a6b5d(%rip), %r14    # 0x2188f8
movl $0x31, (%r14)
leaq 0x2ca477(%rip), %rdi    # 0x33c220
leaq 0xbcfc7(%rip), %rsi     # 0x12ed77
callq 0x9090
movl $0x33, %ecx
testq %rax, %rax
jne 0x71ddc
leaq 0x2ca45a(%rip), %rdi    # 0x33c220
leaq 0xbcf84(%rip), %rsi     # 0x12ed51
callq 0x9090
movl $0x47, %ecx
testq %rax, %rax
je 0x71e30
movl %ecx, (%r14)
jmp 0x71e30
leaq 0x2ca438(%rip), %rdi    # 0x33c220
leaq 0xafc70(%rip), %rsi     # 0x121a5f
callq 0x9090
testq %rax, %rax
je 0x71e0d
movb $0x1, (%r12)
leaq 0x1a9233(%rip), %rax    # 0x21b038
movl $0x2, (%rax)
jmp 0x71e30
leaq 0x2ca40c(%rip), %rdi    # 0x33c220
leaq 0xafc48(%rip), %rsi     # 0x121a63
callq 0x9090
testq %rax, %rax
je 0x71eca
movl $0x50, (%r15)
callq 0x4771f
callq 0x47bae
leaq 0x1cd0f7(%rip), %r14    # 0x23ef38
cmpb $0x0, (%r14)
jne 0x71e77
leaq 0x2ca3d2(%rip), %rdi    # 0x33c220
leaq 0xafc31(%rip), %rsi     # 0x121a86
callq 0x9090
testq %rax, %rax
je 0x71e77
movb $0x1, %al
movb %al, (%r14)
leaq 0x1cd0d2(%rip), %rcx    # 0x23ef3d
movb %al, (%rcx)
callq 0x4771f
callq 0x47bae
leaq 0x2ca3a2(%rip), %rsi    # 0x33c220
movl $0x12, %edx
movq %rbx, %rdi
callq 0x9170
movb $0x0, 0x11(%rbx)
xorl %edi, %edi
callq 0x58e9b
leaq 0x1cd0d3(%rip), %rax    # 0x23ef70
cmpl $0x0, (%rax)
jne 0x71ebb
callq 0x5e140
leaq 0x1a6a52(%rip), %rax    # 0x218900
orb $0x8, (%rax)
leaq 0x29b550(%rip), %rax    # 0x30d408
orb $0x2, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2ca34f(%rip), %rdi    # 0x33c220
leaq 0xafb94(%rip), %rsi     # 0x121a6c
callq 0x9090
testq %rax, %rax
je 0x71f15
leaq 0x1cd043(%rip), %rax    # 0x23ef2c
cmpb $0x0, (%rax)
jne 0x71e30
leaq 0x2ca327(%rip), %rdi    # 0x33c220
leaq 0xafb7b(%rip), %rsi     # 0x121a7b
callq 0x9090
cmpq $0x1, %rax
movb $0x2, %al
sbbb $0x0, %al
movb %al, (%r14)
jmp 0x71e30
leaq 0x2ca304(%rip), %rdi    # 0x33c220
leaq 0xafb54(%rip), %rsi     # 0x121a77
callq 0x9090
testq %rax, %rax
je 0x71f46
leaq 0x1ccff8(%rip), %rax    # 0x23ef2c
cmpb $0x0, (%rax)
jne 0x71e30
movb $0x3, (%r14)
jmp 0x71e30
leaq 0x2ca2d3(%rip), %rdi    # 0x33c220
leaq 0xafb2b(%rip), %rsi     # 0x121a7f
callq 0x9090
testq %rax, %rax
je 0x71e3a
leaq 0x1ccfc3(%rip), %rax    # 0x23ef2c
cmpb $0x0, (%rax)
jne 0x71e30
movb $0x4, (%r14)
jmp 0x71e30